From nobody Tue Mar 14 00:31:31 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 4PbDwg5PZKz3yPbx; Tue, 14 Mar 2023 00:31:31 +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 4PbDwg4rSgz3mFT; Tue, 14 Mar 2023 00:31:31 +0000 (UTC) (envelope-from git@FreeBSD.org) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=freebsd.org; s=dkim; t=1678753891; 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=TlLKwoiDtDXRZayD8pfVmMmI3vjJentkOH8rvA3yZbQ=; b=eQEJU4VwjoODcXA5viJ+8TueJxRKoF46OCehqFXAnVZLSW5hinpuzPE6opolmzThDIOhXJ C5Mn6iwbh7TpAoOPirE0SoAn2ZqRkh68OfvJeK0pihemzWbvu7OojZtmPJf/Yu3bWtnk1D /XLdCeiw03XdBkUTdee46yWpq2Kyd/7uLLCGLHwq6yydRyQmN9xZmXM+7a6Corx25yzZcN kkvwivQlLNd1pEBD165f8GaS8itzcRVYofR9QGtdz4nSq2zgrWD6qnLeLaa0V3p/kJdKgm AyBpCYUvo+W8BngoOd0FNMLiVaFnjP/pkH1TjfWBSyyEaEF2vEffXyQds65jwA== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=freebsd.org; s=dkim; t=1678753891; 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=TlLKwoiDtDXRZayD8pfVmMmI3vjJentkOH8rvA3yZbQ=; b=bGgF93iuwiHzgK+jbiY/0DcqaQUABgtpNrCqWmXZ4tkRDKClBGpe4wumaHdT14hk8wqF8n IRUXYMUmKJ7snWGHKQX559cGMj5yGo77DULmhQnsue9FBnH9GGC9fo6mkeOTN4JPLZNghD ZWG7WZEPwIpFrHuOUQHCsd+4/p7UmCXm5dGevGd6eVDvJxOi6EKIZIzJG4kr9139pfbBDz zY3vYkGrFaPReUJeyfKjW4XT1TMZ2nIRTPVmKpkwDiHGdcaRGe9xsf08jrn1he/GC4sULz OSMRUoZD+vQVcv4l2DZh+JYl2TRO2aSgkKq1h4tIy0WWYILQA2/IFdvps523Mw== ARC-Authentication-Results: i=1; mx1.freebsd.org; none ARC-Seal: i=1; s=dkim; d=freebsd.org; t=1678753891; a=rsa-sha256; cv=none; b=L6D62BTgsiqRkrffqQ4r48XKCmUv9UrZ2yV5orCskcgSrkRCRlzjFWJo+vdTR/0iq+XLTI gOtXXvhmfYFKF7Bbgrob8cC9OynV1GkO9x7Z/T9qpLnJolL0fddTq/5qN3iF5Cs+XzAwxY VCE2lLnv7KfGS/RW8Hz7mnFobvW7srZ31movGXV3/TBIzFIcqx8QKs9rUoOpG1IuzO4U38 g+BP4XLaGGoVfwO/x1sT6YODKsj8kC0eKBTrOdgzX261/VGEV8EPSJe/nJyIHZ52QOlabT 0QvUZc72/0LnKSyoNzxHCojAEZK049zBDOI1UxemJosykOPF7duErVOiyGLvuw== 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 4PbDwg3vt8zFNs; Tue, 14 Mar 2023 00:31:31 +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 32E0VVU2092130; Tue, 14 Mar 2023 00:31:31 GMT (envelope-from git@gitrepo.freebsd.org) Received: (from git@localhost) by gitrepo.freebsd.org (8.16.1/8.16.1/Submit) id 32E0VVKx092129; Tue, 14 Mar 2023 00:31:31 GMT (envelope-from git) Date: Tue, 14 Mar 2023 00:31:31 GMT Message-Id: <202303140031.32E0VVKx092129@gitrepo.freebsd.org> To: src-committers@FreeBSD.org, dev-commits-src-all@FreeBSD.org, dev-commits-src-main@FreeBSD.org From: Kyle Evans Subject: git: 91b2da13702f - main - arm: generic_timer: use interrupt-names when available 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: kevans X-Git-Repository: src X-Git-Refname: refs/heads/main X-Git-Reftype: branch X-Git-Commit: 91b2da13702fb3cfb40a3219feed6e5af651039d Auto-Submitted: auto-generated X-ThisMailContainsUnwantedMimeParts: N The branch main has been updated by kevans: URL: https://cgit.FreeBSD.org/src/commit/?id=91b2da13702fb3cfb40a3219feed6e5af651039d commit 91b2da13702fb3cfb40a3219feed6e5af651039d Author: Kyle Evans AuthorDate: 2023-03-05 00:49:04 +0000 Commit: Kyle Evans CommitDate: 2023-03-14 00:30:28 +0000 arm: generic_timer: use interrupt-names when available Offsets for all of thse can be a bit complicated as not all interrupts will be present, only phys and virt are actually required, and sec-phys could optionally be specified before phys. Push idx/name pairs into a new config struct and maintain the old indices while still getting the correct timers. Split fdt/acpi attach out independently and allocate interrupts before we head into the common attach(). The secure physical timer is also optional there, so mark it so to avoid erroring out if we run into problems. Reviewed by: andrew Differential Revision: https://reviews.freebsd.org/D38911 --- sys/arm/arm/generic_timer.c | 185 +++++++++++++++++++++++++++++++++++++++++--- 1 file changed, 174 insertions(+), 11 deletions(-) diff --git a/sys/arm/arm/generic_timer.c b/sys/arm/arm/generic_timer.c index b19248327683..5d694e8e9660 100644 --- a/sys/arm/arm/generic_timer.c +++ b/sys/arm/arm/generic_timer.c @@ -79,8 +79,9 @@ __FBSDID("$FreeBSD$"); #define GT_PHYS_SECURE 0 #define GT_PHYS_NONSECURE 1 #define GT_VIRT 2 -#define GT_HYP 3 -#define GT_IRQ_COUNT 4 +#define GT_HYP_PHYS 3 +#define GT_HYP_VIRT 4 +#define GT_IRQ_COUNT 5 #define GT_CTRL_ENABLE (1 << 0) #define GT_CTRL_INT_MASK (1 << 1) @@ -107,13 +108,49 @@ struct arm_tmr_softc { static struct arm_tmr_softc *arm_tmr_sc = NULL; -static struct resource_spec timer_spec[] = { - { SYS_RES_IRQ, GT_PHYS_SECURE, RF_ACTIVE }, +#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 | RF_OPTIONAL }, - { SYS_RES_IRQ, GT_HYP, RF_ACTIVE | RF_OPTIONAL }, + { 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; + int flags; +} arm_tmr_irq_defs[] = { + { + .idx = GT_PHYS_SECURE, + .name = "sec-phys", + .flags = RF_ACTIVE | RF_OPTIONAL, + }, + { + .idx = GT_PHYS_NONSECURE, + .name = "phys", + .flags = RF_ACTIVE, + }, + { + .idx = GT_VIRT, + .name = "virt", + .flags = RF_ACTIVE, + }, + { + .idx = GT_HYP_PHYS, + .name = "hyp-phys", + .flags = RF_ACTIVE | RF_OPTIONAL, + }, + { + .idx = GT_HYP_VIRT, + .name = "hyp-virt", + .flags = RF_ACTIVE | RF_OPTIONAL, + }, +}; + +static int arm_tmr_attach(device_t); static uint32_t arm_tmr_fill_vdso_timehands(struct vdso_timehands *vdso_th, struct timecounter *tc); @@ -384,6 +421,108 @@ arm_tmr_fdt_probe(device_t dev) return (ENXIO); } + +static int +arm_tmr_fdt_attach(device_t dev) +{ + struct arm_tmr_softc *sc; + const struct arm_tmr_irq_defs *irq_def; + size_t i; + phandle_t node; + int error, rid; + bool has_names; + + sc = device_get_softc(dev); + node = ofw_bus_get_node(dev); + + has_names = OF_hasprop(node, "interrupt-names"); + for (i = 0; i < nitems(arm_tmr_irq_defs); i++) { + int flags; + + /* + * If we don't have names to go off of, we assume that they're + * in the "usual" order with sec-phys first and allocate by idx. + */ + irq_def = &arm_tmr_irq_defs[i]; + rid = irq_def->idx; + flags = irq_def->flags; + if (has_names) { + error = ofw_bus_find_string_index(node, + "interrupt-names", irq_def->name, &rid); + + /* + * If we have names, missing a name means we don't + * have it. + */ + if (error != 0) { + /* + * Could be noisy on a lot of platforms for no + * good cause. + */ + if (bootverbose || (flags & RF_OPTIONAL) == 0) { + device_printf(dev, + "could not find irq for %s interrupt '%s'\n", + (flags & RF_OPTIONAL) != 0 ? + "optional" : "required", + irq_def->name); + } + + if ((flags & RF_OPTIONAL) == 0) + goto out; + + continue; + } + + /* + * Warn about failing to activate if we did actually + * have the name present. + */ + 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(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. + */ + bus_release_resource(dev, SYS_RES_IRQ, + rman_get_rid(sc->res[i]), sc->res[i]); + } + } + } + + return (error); + +} #endif #ifdef DEV_ACPI @@ -436,12 +575,31 @@ arm_tmr_acpi_probe(device_t dev) device_set_desc(dev, "ARM Generic Timer"); return (BUS_PROBE_NOWILDCARD); } + +static int +arm_tmr_acpi_attach(device_t dev) +{ + 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); + } + + error = arm_tmr_attach(dev); + if (error != 0) + bus_release_resources(dev, timer_acpi_spec, sc->res); + return (error); +} #endif static int arm_tmr_attach(device_t dev) { struct arm_tmr_softc *sc; + const struct arm_tmr_irq_defs *irq_def; #ifdef FDT phandle_t node; pcell_t clock; @@ -482,9 +640,12 @@ arm_tmr_attach(device_t dev) return (ENXIO); } - if (bus_alloc_resources(dev, timer_spec, sc->res)) { - device_printf(dev, "could not allocate resources\n"); - return (ENXIO); + /* Confirm that non-optional irqs were allocated before coming in. */ + for (i = 0; i < nitems(arm_tmr_irq_defs); i++) { + irq_def = &arm_tmr_irq_defs[i]; + + MPASS(sc->res[irq_def->idx] != NULL || + (irq_def->flags & RF_OPTIONAL) != 0); } #ifdef __aarch64__ @@ -513,6 +674,8 @@ arm_tmr_attach(device_t dev) arm_tmr_intr, NULL, sc, &sc->ihl[i]); 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]); return (ENXIO); } } @@ -550,7 +713,7 @@ arm_tmr_attach(device_t dev) #ifdef FDT static device_method_t arm_tmr_fdt_methods[] = { DEVMETHOD(device_probe, arm_tmr_fdt_probe), - DEVMETHOD(device_attach, arm_tmr_attach), + DEVMETHOD(device_attach, arm_tmr_fdt_attach), { 0, 0 } }; @@ -567,7 +730,7 @@ EARLY_DRIVER_MODULE(timer, ofwbus, arm_tmr_fdt_driver, 0, 0, static device_method_t arm_tmr_acpi_methods[] = { DEVMETHOD(device_identify, arm_tmr_acpi_identify), DEVMETHOD(device_probe, arm_tmr_acpi_probe), - DEVMETHOD(device_attach, arm_tmr_attach), + DEVMETHOD(device_attach, arm_tmr_acpi_attach), { 0, 0 } };