From nobody Mon May 15 15:45:54 2023 X-Original-To: dev-commits-src-branches@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 4QKkH82GSWz4BlZL; Mon, 15 May 2023 15:45:56 +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 4QKkH71ktCz3J4F; Mon, 15 May 2023 15:45:55 +0000 (UTC) (envelope-from git@FreeBSD.org) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=freebsd.org; s=dkim; t=1684165555; 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=EeQ806GyX7p+tiwAF3EXDpslzAfNU2siecyPqKKAtCA=; b=PvC6ZNV4faZFxJUFZXkGd0hKTo2jTSfh+wDiLuQEgQzjrO73isyMcoN4ME5Aj40TJZadv0 yuPKa32mFZqMD/0Bm9++ibftxWgT4TUef01H3W0rCu95rO40CDmCgZZm+gXM+u0/fpeJDN PSPgj5Qo0WyBJQiSSEPYY0soP3Q5cW9fDTb45Ka45Qu/+CWgwO2NWwdVe/X2ELketcEQo7 OwsPmchNZur9ryK1bSSxrn4POPkHT2iTP1liNmb7wQHiO0h/3ozxbHj7b9RzW7uq6nOABV /psqOD3JefoBrSIHjej5xYk14h7ro9ZoF01bS1QJ+2EhmyKoVmNpvIXSiAjhSw== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=freebsd.org; s=dkim; t=1684165555; 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=EeQ806GyX7p+tiwAF3EXDpslzAfNU2siecyPqKKAtCA=; b=oN599/4SX9yT2P0XCsZIaacBVSPcSBB2nnBXGXHXyU6Y+drehqmSCp7uxCdgRRXVW6hfzG Y4yBctgNxL+iAmzzdcFfS5XmPGeoqbJq/Vi44YnK1YMCXxDP7hDEV1X9gATmu676el/PB3 ZqUPkPMPr0Z3pHxhhlN0db53yQJY0WQcnkz+TcdgtMRS+rxLYIdvC9zuG4eXJ8omAVvEZQ F+lVOC4nDZCeuMbG0ofQEVyoKAoX7ifGL3mLPFY21U8t8iPJeuknyRIfSIdwOusKW4rkNi 2n77k8lY+fpSLgwMiCTz8uHJ7yQbY5GtLAE2VGM0y9xlGCh67mugWe7EiUjbVQ== ARC-Authentication-Results: i=1; mx1.freebsd.org; none ARC-Seal: i=1; s=dkim; d=freebsd.org; t=1684165555; a=rsa-sha256; cv=none; b=icmWSc9X04ioS/NuYiwy/MxwR5mgVgFeRW+Xg8JBUY7RMo/F4zRNmgWA9N4D1O6TG6f/+2 0/132i7gaFR+cZubHa2hXYQV+3aXlUSL1aiFnX5Oaz1Ep7lbZPXBiDBEVzzVfWwnt16/v4 lJ0WYCvJn6mLY2AjTXttV20UwasGLzNqe5CEhvU83bKKlemjc+h2yBUvARQypvb1/eN+r+ yUxj4weLSQ+wX1j427KJEOmSou+iX0RZV7mpqv8olDpgBZWKml4F8/3xE2XkPYlY4rwZCM Jckod87N2Ij8qzcacU3/tX3prXcE+VUNS727WGjePGd02BkHybXrZHn+ecW6/Q== 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 4QKkH66s6yzmJ5; Mon, 15 May 2023 15:45:54 +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 34FFjsAe073370; Mon, 15 May 2023 15:45:54 GMT (envelope-from git@gitrepo.freebsd.org) Received: (from git@localhost) by gitrepo.freebsd.org (8.16.1/8.16.1/Submit) id 34FFjskN073369; Mon, 15 May 2023 15:45:54 GMT (envelope-from git) Date: Mon, 15 May 2023 15:45:54 GMT Message-Id: <202305151545.34FFjskN073369@gitrepo.freebsd.org> To: src-committers@FreeBSD.org, dev-commits-src-all@FreeBSD.org, dev-commits-src-branches@FreeBSD.org From: Andrew Turner Subject: git: 9afca1eb3277 - stable/13 - arm: generic_timer: use interrupt-names when available List-Id: Commits to the stable branches of the FreeBSD src repository List-Archive: https://lists.freebsd.org/archives/dev-commits-src-branches List-Help: List-Post: List-Subscribe: List-Unsubscribe: Sender: owner-dev-commits-src-branches@freebsd.org X-BeenThere: dev-commits-src-branches@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/stable/13 X-Git-Reftype: branch X-Git-Commit: 9afca1eb3277047de623c91e500f6ec319f82f4b Auto-Submitted: auto-generated X-ThisMailContainsUnwantedMimeParts: N The branch stable/13 has been updated by andrew: URL: https://cgit.FreeBSD.org/src/commit/?id=9afca1eb3277047de623c91e500f6ec319f82f4b commit 9afca1eb3277047de623c91e500f6ec319f82f4b Author: Kyle Evans AuthorDate: 2023-03-05 00:49:04 +0000 Commit: Andrew Turner CommitDate: 2023-05-15 07:59:43 +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 (cherry picked from commit 91b2da13702fb3cfb40a3219feed6e5af651039d) --- 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 cdc60ba469a4..cba354909100 100644 --- a/sys/arm/arm/generic_timer.c +++ b/sys/arm/arm/generic_timer.c @@ -75,8 +75,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) @@ -103,13 +104,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); @@ -338,6 +375,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 @@ -390,12 +529,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; @@ -436,9 +594,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__ @@ -467,6 +628,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); } } @@ -504,7 +667,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 } }; @@ -523,7 +686,7 @@ EARLY_DRIVER_MODULE(timer, ofwbus, arm_tmr_fdt_driver, arm_tmr_fdt_devclass, 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 } };