From nobody Wed Mar 15 12:01:16 2023 X-Original-To: dev-commits-src-main@mlmmj.nyi.freebsd.org Received: from mx1.freebsd.org (mx1.freebsd.org [IPv6:2610:1c1:1:606c::19:1]) by mlmmj.nyi.freebsd.org (Postfix) with ESMTP id 4Pc8B46rVNz3yRHx; Wed, 15 Mar 2023 12:01:16 +0000 (UTC) (envelope-from git@FreeBSD.org) Received: from mxrelay.nyi.freebsd.org (mxrelay.nyi.freebsd.org [IPv6:2610:1c1:1:606c::19:3]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (4096 bits) server-digest SHA256 client-signature RSA-PSS (4096 bits) client-digest SHA256) (Client CN "mxrelay.nyi.freebsd.org", Issuer "R3" (verified OK)) by mx1.freebsd.org (Postfix) with ESMTPS id 4Pc8B46K75z4F4f; Wed, 15 Mar 2023 12:01:16 +0000 (UTC) (envelope-from git@FreeBSD.org) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=freebsd.org; s=dkim; t=1678881676; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:mime-version:mime-version:content-type:content-type: content-transfer-encoding:content-transfer-encoding; bh=BUbdZvDYki2ZDOxq8D948NJeioTizcDGrmcl/EMVfd8=; b=jsvOBkwa8bX+Jw+daOH8g0gx0m0mcialIabx7I2AB+eCvCddH/XKeso+n/W/30/f7wqwaX MTz6QYVKoBUz7JtU5UrGUMElw1y71zf/bwPMD5TY3vfX9qSWuHvZsN7F5HaX87hiUbUwPl vLlEuzkZaEXyUVLKAGirz+NwmuhAKykuTwujK1JgSqdUiKR/U7PoayzVJHoVNgrCrHEodb NY7E4tToC93jS/PSgjhd1fat/lc3RrUvyGloHqxPWFXwqw05f5Lk+6co966nBmjw8Z5SBv a4pHbIi5aHZaQGgTYVGVuuZSe1nQIWmFGK20+giWQyzVOPiXPbqfEHBKjrE9og== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=freebsd.org; s=dkim; t=1678881676; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:mime-version:mime-version:content-type:content-type: content-transfer-encoding:content-transfer-encoding; bh=BUbdZvDYki2ZDOxq8D948NJeioTizcDGrmcl/EMVfd8=; b=kLQHIuOvmH9smTmSfImdgWKejI6hVhk2y7jHg87W2mBYSmIe3bcg3JVaxsVBnsv3XW/763 0is0dNBuYPiiuPex43h2uW+9qj3IipTx/BK5pw9EmM+xeMhIVtKDI1SopAI+rjnKeMP23i +EHhne4w+OP4x5lx8afNOV+/uJK7uUzx/u0AhAmy9IBeZ9dd/qwbf82YtXSNTWsPOpum6T 5o/2S5zJP3X6eunwK32dBG5MpQaPmoEDPXR7OGHmv02mjtTf2gWQQEz4GwOJuqgMuraEhe j6vblVsq2pAeg0fGK9AdygTy+YTc9HjY7yGjJAkL/nLT7/FkhQYTbhJUd9KCxw== ARC-Authentication-Results: i=1; mx1.freebsd.org; none ARC-Seal: i=1; s=dkim; d=freebsd.org; t=1678881676; a=rsa-sha256; cv=none; b=v40GCC9Zpg2CKwxid0Lx9ToCPHcdOw4qqDk4Tbhsto2mTb1YEm20e2ow/SFy8gGUPqUYsN BG5nXyO6Sqr5JBANtYpgSI8+C9U8oGiQWcNfGKCF/2rHEkBBqFqXlC+GTKRIKR0lz0Zdar aWYx6trNCJCNCIpemASafYZZiUvkd6HwJgSaI7PlN3urk7cOxkusMbnGH6OIYY7TfudJ9+ C8tu1qvqwJ2HFIrK2gPfCYaGsopvuXeP081R29SvSKNzw5VNGhuMHswyXCgqZNttXDu5hm uhgPV0Ksr+qURLy2cvRL1wgp+M9LgPncRR9Wntsai4VvhoVP8isMvYly9DAloQ== Received: from gitrepo.freebsd.org (gitrepo.freebsd.org [IPv6:2610:1c1:1:6068::e6a:5]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (4096 bits) server-digest SHA256) (Client did not present a certificate) by mxrelay.nyi.freebsd.org (Postfix) with ESMTPS id 4Pc8B45N0cz1G5X; Wed, 15 Mar 2023 12:01:16 +0000 (UTC) (envelope-from git@FreeBSD.org) Received: from gitrepo.freebsd.org ([127.0.1.44]) by gitrepo.freebsd.org (8.16.1/8.16.1) with ESMTP id 32FC1Gv6096752; Wed, 15 Mar 2023 12:01:16 GMT (envelope-from git@gitrepo.freebsd.org) Received: (from git@localhost) by gitrepo.freebsd.org (8.16.1/8.16.1/Submit) id 32FC1GjR096751; Wed, 15 Mar 2023 12:01:16 GMT (envelope-from git) Date: Wed, 15 Mar 2023 12:01:16 GMT Message-Id: <202303151201.32FC1GjR096751@gitrepo.freebsd.org> To: src-committers@FreeBSD.org, dev-commits-src-all@FreeBSD.org, dev-commits-src-main@FreeBSD.org From: Andrew Turner Subject: git: b71ef90ec28f - main - Keep per-timer interrupt data together List-Id: Commit messages for the main branch of the src repository List-Archive: https://lists.freebsd.org/archives/dev-commits-src-main List-Help: List-Post: List-Subscribe: List-Unsubscribe: Sender: owner-dev-commits-src-main@freebsd.org X-BeenThere: dev-commits-src-main@freebsd.org MIME-Version: 1.0 Content-Type: text/plain; charset=utf-8 Content-Transfer-Encoding: 8bit X-Git-Committer: andrew X-Git-Repository: src X-Git-Refname: refs/heads/main X-Git-Reftype: branch X-Git-Commit: b71ef90ec28fdb731733afde495ac74ae59d6196 Auto-Submitted: auto-generated X-ThisMailContainsUnwantedMimeParts: N The branch main has been updated by andrew: URL: https://cgit.FreeBSD.org/src/commit/?id=b71ef90ec28fdb731733afde495ac74ae59d6196 commit b71ef90ec28fdb731733afde495ac74ae59d6196 Author: Andrew Turner AuthorDate: 2023-03-14 09:27:23 +0000 Commit: Andrew Turner CommitDate: 2023-03-15 11:34:31 +0000 Keep per-timer interrupt data together Eliminate a redundant resource array allow possible use by bhyve later. Reviewed by: kevans Sponsored by: Arm Ltd Sponsored by: The FreeBSD Foundation Differential Revision: https://reviews.freebsd.org/D37424 --- sys/arm/arm/generic_timer.c | 118 +++++++++++++++++++++++--------------------- 1 file changed, 63 insertions(+), 55 deletions(-) diff --git a/sys/arm/arm/generic_timer.c b/sys/arm/arm/generic_timer.c index 0b48841c9960..36747441ec88 100644 --- a/sys/arm/arm/generic_timer.c +++ b/sys/arm/arm/generic_timer.c @@ -97,9 +97,16 @@ __FBSDID("$FreeBSD$"); #define GT_CNTKCTL_PL0VCTEN (1 << 1) /* PL0 CNTVCT and CNTFRQ access */ #define GT_CNTKCTL_PL0PCTEN (1 << 0) /* PL0 CNTPCT and CNTFRQ access */ +struct arm_tmr_softc; + +struct arm_tmr_irq { + struct resource *res; + void *ihl; + int rid; +}; + struct arm_tmr_softc { - struct resource *res[GT_IRQ_COUNT]; - void *ihl[GT_IRQ_COUNT]; + struct arm_tmr_irq irqs[GT_IRQ_COUNT]; uint64_t (*get_cntxct)(bool); uint32_t clkfreq; struct eventtimer et; @@ -108,16 +115,6 @@ struct arm_tmr_softc { static struct arm_tmr_softc *arm_tmr_sc = NULL; -#ifdef DEV_ACPI -static struct resource_spec timer_acpi_spec[] = { - { SYS_RES_IRQ, GT_PHYS_SECURE, RF_ACTIVE | RF_OPTIONAL }, - { SYS_RES_IRQ, GT_PHYS_NONSECURE, RF_ACTIVE }, - { SYS_RES_IRQ, GT_VIRT, RF_ACTIVE }, - { SYS_RES_IRQ, GT_HYP_PHYS, RF_ACTIVE | RF_OPTIONAL }, - { -1, 0 } -}; -#endif - static const struct arm_tmr_irq_defs { int idx; const char *name; @@ -402,6 +399,29 @@ arm_tmr_intr(void *arg) return (FILTER_HANDLED); } +static int +arm_tmr_attach_irq(device_t dev, struct arm_tmr_softc *sc, + const struct arm_tmr_irq_defs *irq_def, int rid, int flags) +{ + sc->irqs[irq_def->idx].res = bus_alloc_resource_any(dev, SYS_RES_IRQ, + &rid, flags); + if (sc->irqs[irq_def->idx].res == NULL) { + if (bootverbose || (flags & RF_OPTIONAL) == 0) { + device_printf(dev, + "could not allocate irq for %s interrupt '%s'\n", + (flags & RF_OPTIONAL) != 0 ? "optional" : + "required", irq_def->name); + } + + if ((flags & RF_OPTIONAL) == 0) + return (ENXIO); + } else if (bootverbose) { + device_printf(dev, "allocated irq for '%s'\n", irq_def->name); + } + + return (0); +} + #ifdef FDT static int arm_tmr_fdt_probe(device_t dev) @@ -479,42 +499,18 @@ arm_tmr_fdt_attach(device_t dev) flags &= ~RF_OPTIONAL; } - sc->res[irq_def->idx] = bus_alloc_resource_any(dev, - SYS_RES_IRQ, &rid, flags); - - if (sc->res[irq_def->idx] == NULL) { - device_printf(dev, - "could not allocate irq for %s interrupt '%s'\n", - (flags & RF_OPTIONAL) != 0 ? "optional" : - "required", irq_def->name); - - if ((flags & RF_OPTIONAL) == 0) { - error = ENXIO; - goto out; - } - - continue; - } - - if (bootverbose) { - device_printf(dev, - "allocated irq for '%s'\n", irq_def->name); - } + error = arm_tmr_attach_irq(dev, sc, irq_def, rid, flags); + if (error != 0) + goto out; } error = arm_tmr_attach(dev); out: if (error != 0) { for (i = 0; i < GT_IRQ_COUNT; i++) { - if (sc->res[i] != NULL) { - /* - * rid may not match the index into sc->res in - * a number of cases; e.g., optional sec-phys or - * interrupt-names specifying them in a - * different order than expected. - */ + if (sc->irqs[i].res != NULL) { bus_release_resource(dev, SYS_RES_IRQ, - rman_get_rid(sc->res[i]), sc->res[i]); + sc->irqs[i].rid, sc->irqs[i].res); } } } @@ -578,18 +574,29 @@ arm_tmr_acpi_probe(device_t dev) static int arm_tmr_acpi_attach(device_t dev) { + const struct arm_tmr_irq_defs *irq_def; struct arm_tmr_softc *sc; int error; sc = device_get_softc(dev); - if (bus_alloc_resources(dev, timer_acpi_spec, sc->res)) { - device_printf(dev, "could not allocate resources\n"); - return (ENXIO); + for (int i = 0; i < nitems(arm_tmr_irq_defs); i++) { + irq_def = &arm_tmr_irq_defs[i]; + error = arm_tmr_attach_irq(dev, sc, irq_def, irq_def->idx, + irq_def->flags); + if (error != 0) + goto out; } error = arm_tmr_attach(dev); - if (error != 0) - bus_release_resources(dev, timer_acpi_spec, sc->res); +out: + if (error != 0) { + for (int i = 0; i < GT_IRQ_COUNT; i++) { + if (sc->irqs[i].res != NULL) { + bus_release_resource(dev, SYS_RES_IRQ, + sc->irqs[i].rid, sc->irqs[i].res); + } + } + } return (error); } #endif @@ -643,13 +650,13 @@ arm_tmr_attach(device_t dev) for (i = 0; i < nitems(arm_tmr_irq_defs); i++) { irq_def = &arm_tmr_irq_defs[i]; - MPASS(sc->res[irq_def->idx] != NULL || + MPASS(sc->irqs[irq_def->idx].res != NULL || (irq_def->flags & RF_OPTIONAL) != 0); } #ifdef __aarch64__ /* Use the virtual timer if we have one. */ - if (sc->res[GT_VIRT] != NULL) { + if (sc->irqs[GT_VIRT].res != NULL) { sc->physical = false; first_timer = GT_VIRT; last_timer = GT_VIRT; @@ -667,24 +674,25 @@ arm_tmr_attach(device_t dev) /* Setup secure, non-secure and virtual IRQs handler */ for (i = first_timer; i <= last_timer; i++) { /* If we do not have the interrupt, skip it. */ - if (sc->res[i] == NULL) + if (sc->irqs[i].res == NULL) continue; - error = bus_setup_intr(dev, sc->res[i], INTR_TYPE_CLK, - arm_tmr_intr, NULL, sc, &sc->ihl[i]); + error = bus_setup_intr(dev, sc->irqs[i].res, INTR_TYPE_CLK, + arm_tmr_intr, NULL, sc, &sc->irqs[i].ihl); if (error) { device_printf(dev, "Unable to alloc int resource.\n"); for (int j = first_timer; j < i; j++) - bus_teardown_intr(dev, sc->res[j], &sc->ihl[j]); + bus_teardown_intr(dev, sc->irqs[j].res, + &sc->irqs[j].ihl); return (ENXIO); } } /* Disable the virtual timer until we are ready */ - if (sc->res[GT_VIRT] != NULL) + if (sc->irqs[GT_VIRT].res != NULL) arm_tmr_disable(false); /* And the physical */ - if ((sc->res[GT_PHYS_SECURE] != NULL || - sc->res[GT_PHYS_NONSECURE] != NULL) && HAS_PHYS) + if ((sc->irqs[GT_PHYS_SECURE].res != NULL || + sc->irqs[GT_PHYS_NONSECURE].res != NULL) && HAS_PHYS) arm_tmr_disable(true); arm_tmr_timecount.tc_frequency = sc->clkfreq;