From nobody Wed Mar 15 15:49:18 2023 X-Original-To: dev-commits-src-all@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 4PcFFB6gZqz3ygK2; Wed, 15 Mar 2023 15:49:18 +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 4PcFFB5nywz4ZVZ; Wed, 15 Mar 2023 15:49:18 +0000 (UTC) (envelope-from git@FreeBSD.org) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=freebsd.org; s=dkim; t=1678895358; 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=DYUvwToTJRFijBW6vL+DkOAeMf/3KE3UTAUh5d55ciw=; b=BweSqGI4/l6HcUHd8ITD1yWEVjGRPjsOX0E7HEVFLsFqZk9uE7PjUqVFFIAujaprK6W7zh vnzwzDA7Pn+4sAGZvdiNHGjKC0SFdOQfhegm7MPtbssNXWqJu3rRCnRrjlSHmcOvI6Jmob ihiB3wgxY3HBf9GuPh7wl7i8NlOZczAD/gSlLREYoQ8h9LykONlYq3xjPanxkNkc/Xma3f cSvZbajruUFvGBhLQvseejsbioVf83haBEGqBDRbdsBMRsL39toGz1A+ks+6aQ9mDmdi3y f0XXpQ8EwWOBCp9MgkG5GvBVoD4frzSZs5Wpot/+1NfbtIrTONjEKWpuUDXo/w== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=freebsd.org; s=dkim; t=1678895358; 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=DYUvwToTJRFijBW6vL+DkOAeMf/3KE3UTAUh5d55ciw=; b=sscZfJ08F+sTgOoWRWc0QErsW+477mwcUj0OrNA3chcf4JNLAQC3UDvfxhqJiQ9qr611y4 UnUjulRV7mwiW9a4Xtq9kDesxZKSI9ri0B7ekqFC0X6g3rQIDLvPLFE1fF9pjKK/SoJVSI kcmwMiEtsIbb+5+kLGEtfVvcRYhnUsbvgVUBNSjUW9Qs16sC8ILV/lTLJyFF5ssvxlOC5q zQ1n7COzDnrATTK5FquCSaFE5Gtp9VoIQ7L/zCKyqqOVYA7ug4Ewc+FEuCJw2NEQO3VF7B Ha5ce9vY3rxZ0SIDk3Er/CEN4e7ZvA08Fz2rtmeSr92sahDq5UxEIeGBa8AHHA== ARC-Authentication-Results: i=1; mx1.freebsd.org; none ARC-Seal: i=1; s=dkim; d=freebsd.org; t=1678895358; a=rsa-sha256; cv=none; b=OS2VWDCcSsFhoG4iVpEWpCB4EKoy4HN4AIiHxu9i2uWuEqFM5fT5qmAiJrylyFtmI8tirR ptgX+JIqGbMsqa44p8YdKoR/SkqgiZGB9hY1GEGdFLKEtydOqiuEb+3mMphedlDHgemZEj IAO7jpZNyzJ/b95TC9HZ/YB8My8pg7F3Ynh2HJ3HI0NPMwe2ZB3TyW5MgAhb4TGvW9AO13 A1I/nCWuBNHqiFT0BRqIzvFjmf2rKeOTJmn5ipCBjn+iuoiQDTkuU1HPvXK9yjarEbP7QP l2tPJZCoebbrlU4l6Zls2YjwRJBDsbXyeyNOrUTgVojwAD+ew2WVnq9smi4v7A== 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 4PcFFB4nJKz1M4m; Wed, 15 Mar 2023 15:49:18 +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 32FFnIQN058812; Wed, 15 Mar 2023 15:49:18 GMT (envelope-from git@gitrepo.freebsd.org) Received: (from git@localhost) by gitrepo.freebsd.org (8.16.1/8.16.1/Submit) id 32FFnIfa058811; Wed, 15 Mar 2023 15:49:18 GMT (envelope-from git) Date: Wed, 15 Mar 2023 15:49:18 GMT Message-Id: <202303151549.32FFnIfa058811@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: 5c4bd8756fbc - main - Stop using the rid as an index in the arm timer List-Id: Commit messages for all branches of the src repository List-Archive: https://lists.freebsd.org/archives/dev-commits-src-all List-Help: List-Post: List-Subscribe: List-Unsubscribe: Sender: owner-dev-commits-src-all@freebsd.org X-BeenThere: dev-commits-src-all@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: 5c4bd8756fbc23a48ddd8976df0b8429311fba83 Auto-Submitted: auto-generated X-ThisMailContainsUnwantedMimeParts: N The branch main has been updated by andrew: URL: https://cgit.FreeBSD.org/src/commit/?id=5c4bd8756fbc23a48ddd8976df0b8429311fba83 commit 5c4bd8756fbc23a48ddd8976df0b8429311fba83 Author: Andrew Turner AuthorDate: 2023-03-15 13:35:04 +0000 Commit: Andrew Turner CommitDate: 2023-03-15 15:49:00 +0000 Stop using the rid as an index in the arm timer The order of the interrupt array doesn't matter. Store the described interrupts at the start of the array to simplify iterating over them. Reviewed by: imp, kevans Sponsored by: Arm Ltd Differential Revision: https://reviews.freebsd.org/D39094 --- sys/arm/arm/generic_timer.c | 61 ++++++++++++++++++++++++++++++--------------- 1 file changed, 41 insertions(+), 20 deletions(-) diff --git a/sys/arm/arm/generic_timer.c b/sys/arm/arm/generic_timer.c index b36fbdf8dcbe..b1f42cbc5b34 100644 --- a/sys/arm/arm/generic_timer.c +++ b/sys/arm/arm/generic_timer.c @@ -103,12 +103,14 @@ struct arm_tmr_irq { struct resource *res; void *ihl; int rid; + int idx; }; struct arm_tmr_softc { struct arm_tmr_irq irqs[GT_IRQ_COUNT]; uint64_t (*get_cntxct)(bool); uint32_t clkfreq; + int irq_count; struct eventtimer et; bool physical; }; @@ -403,9 +405,12 @@ 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, + struct arm_tmr_irq *irq; + + irq = &sc->irqs[sc->irq_count]; + irq->res = bus_alloc_resource_any(dev, SYS_RES_IRQ, &rid, flags); - if (sc->irqs[irq_def->idx].res == NULL) { + if (irq->res == NULL) { if (bootverbose || (flags & RF_OPTIONAL) == 0) { device_printf(dev, "could not allocate irq for %s interrupt '%s'\n", @@ -415,8 +420,13 @@ arm_tmr_attach_irq(device_t dev, struct arm_tmr_softc *sc, if ((flags & RF_OPTIONAL) == 0) return (ENXIO); - } else if (bootverbose) { - device_printf(dev, "allocated irq for '%s'\n", irq_def->name); + } else { + if (bootverbose) + device_printf(dev, "allocated irq for '%s'\n", + irq_def->name); + irq->rid = rid; + irq->idx = irq_def->idx; + sc->irq_count++; } return (0); @@ -507,11 +517,9 @@ arm_tmr_fdt_attach(device_t dev) error = arm_tmr_attach(dev); out: if (error != 0) { - for (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); - } + for (i = 0; i < sc->irq_count; i++) { + bus_release_resource(dev, SYS_RES_IRQ, sc->irqs[i].rid, + sc->irqs[i].res); } } @@ -590,11 +598,9 @@ arm_tmr_acpi_attach(device_t dev) error = arm_tmr_attach(dev); 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); - } + for (int i = 0; i < sc->irq_count; i++) { + bus_release_resource(dev, SYS_RES_IRQ, + sc->irqs[i].rid, sc->irqs[i].res); } } return (error); @@ -605,7 +611,9 @@ static int arm_tmr_attach(device_t dev) { struct arm_tmr_softc *sc; +#ifdef INVARIANTS const struct arm_tmr_irq_defs *irq_def; +#endif #ifdef FDT phandle_t node; pcell_t clock; @@ -646,13 +654,25 @@ arm_tmr_attach(device_t dev) return (ENXIO); } +#ifdef INVARIANTS /* Confirm that non-optional irqs were allocated before coming in. */ for (i = 0; i < nitems(arm_tmr_irq_defs); i++) { + int j; + irq_def = &arm_tmr_irq_defs[i]; - MPASS(sc->irqs[irq_def->idx].res != NULL || - (irq_def->flags & RF_OPTIONAL) != 0); + /* Skip optional interrupts */ + if ((irq_def->flags & RF_OPTIONAL) != 0) + continue; + + for (j = 0; j < sc->irq_count; j++) { + if (sc->irqs[j].idx == irq_def->idx) + break; + } + KASSERT(j < sc->irq_count, ("%s: Missing required interrupt %s", + __func__, irq_def->name)); } +#endif #ifdef __aarch64__ /* @@ -677,15 +697,16 @@ arm_tmr_attach(device_t dev) arm_tmr_sc = sc; /* 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->irqs[i].res == NULL) + for (i = 0; i < sc->irq_count; i++) { + /* Only enable IRQs on timers we expect to use */ + if (sc->irqs[i].idx < first_timer || + sc->irqs[i].idx > last_timer) continue; 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++) + for (int j = 0; j < i; j++) bus_teardown_intr(dev, sc->irqs[j].res, &sc->irqs[j].ihl); return (ENXIO);