From nobody Mon Apr 08 19:04:30 2024 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 4VCz6R2p8Jz5HYXs; Mon, 8 Apr 2024 19:04: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 4VCz6Q737sz4gLY; Mon, 8 Apr 2024 19:04:30 +0000 (UTC) (envelope-from git@FreeBSD.org) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=freebsd.org; s=dkim; t=1712603071; 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=dZm3DLTZ97+XbWco/Upxf6i480DvSp9Gor3BfoPkg9w=; b=mkLY2zmT3fn21CRypBB6S9gLs0IsEwL4O3azHWLZe0mArnqK2JyyG9RJswW8/OieEWPcAg umi92bm8H20rSH++E43wxnnsgI3+kVZU+SHE1pQ7kYbu3q6gdlza2qicSg7RGrebHo7csp vitwH33VHX/tLK6B8vCNFedrU1ML1mHd480v7aH7QxeYs/qH9rKCCQy8F3dlTCrjQ8wXqr QTA2geDnq2XcdEPwCvWLmnTWS9489lP8P5KDV/wukXH3dCbT6wD/V16aNFbYP5wWqkFycP lLEUPY3dPecHZR+Px2kbVTah2BcbncZ+gw2o6lHfkXPZoggOjjZyDm5M8ekTmg== ARC-Seal: i=1; s=dkim; d=freebsd.org; t=1712603071; a=rsa-sha256; cv=none; b=wKy0NWqfyOBqBw76grSpveMrOec+JJw/oA5CKHO14Ns6FrM9DkFB12TBPOqMP/pSh7UV4L QmPYwmYvMYjjNRNcBuT+Poz0qT+E3DRtW4h6Mh2cFnlf9RqHUwqVczDwtdDDmS/9uSfIdC SUGgO/T1aAt9L08Ie5t8s7eSeGByOp38jUbj2gfYOvOhz8LL2aH9xRFHf2J8MVy5CcsDID KU3M/sq/8wMMCvEsVhu01mwm8BLaVc2DL/U2gc68Lx034kZywHhI0l6aOCsatlTgTvlIg/ 9nm0+ggfiIkFXhA9EQRJJ8Jo4cGN9Wsmgfd81pMOhdQaDIfKeEbekpC1rnqD3A== ARC-Authentication-Results: i=1; mx1.freebsd.org; none ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=freebsd.org; s=dkim; t=1712603071; 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=dZm3DLTZ97+XbWco/Upxf6i480DvSp9Gor3BfoPkg9w=; b=IUJBMp6wfE2VSL6ygcdkaJiFilt0ei7M6fG7OgBwamjXV5mAx28A9nGIiPhRHzO/O+Rk8K sWtzlWuefthWm04vI1bEQoIkX0Np2sXuVRFDq3WJ3ykbZ/gydI/jplv7urP48IBRpXf2a3 gs8SLfeYp16r46+sZLxSuXQ4k1W2c4tVwzXXPLIjsxj5+j6DHygc2CxTFe5/tFcXGOiBXD /HR84OxgaKbNvE3ETWaA91Ci25Kmqq3rJeK2qDMqbcsOax4FSvHCB23aRkxxCf26Ce+Sd6 7h+dtAS1chrXk9tpQJGmCV/W95C4arLL+y74Y/XSboc6z3CLehuzVdv3jqOoTQ== 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 4VCz6Q6fy0zNQD; Mon, 8 Apr 2024 19:04:30 +0000 (UTC) (envelope-from git@FreeBSD.org) Received: from gitrepo.freebsd.org ([127.0.1.44]) by gitrepo.freebsd.org (8.17.1/8.17.1) with ESMTP id 438J4U8h094354; Mon, 8 Apr 2024 19:04:30 GMT (envelope-from git@gitrepo.freebsd.org) Received: (from git@localhost) by gitrepo.freebsd.org (8.17.1/8.17.1/Submit) id 438J4UOg094351; Mon, 8 Apr 2024 19:04:30 GMT (envelope-from git) Date: Mon, 8 Apr 2024 19:04:30 GMT Message-Id: <202404081904.438J4UOg094351@gitrepo.freebsd.org> To: src-committers@FreeBSD.org, dev-commits-src-all@FreeBSD.org, dev-commits-src-branches@FreeBSD.org From: John Baldwin Subject: git: 75a63c968af9 - stable/14 - acpi: Allow child drivers to use bus_set_resource for more resources 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: jhb X-Git-Repository: src X-Git-Refname: refs/heads/stable/14 X-Git-Reftype: branch X-Git-Commit: 75a63c968af999918fd2d6ba98ba5d86c0ea6188 Auto-Submitted: auto-generated The branch stable/14 has been updated by jhb: URL: https://cgit.FreeBSD.org/src/commit/?id=75a63c968af999918fd2d6ba98ba5d86c0ea6188 commit 75a63c968af999918fd2d6ba98ba5d86c0ea6188 Author: John Baldwin AuthorDate: 2024-02-14 22:07:32 +0000 Commit: John Baldwin CommitDate: 2024-04-08 17:54:35 +0000 acpi: Allow child drivers to use bus_set_resource for more resources acpi_set_resource excludes certain types of resources for certain devices. The intention of this is to avoid adding resource entries for bogus resources enumerated via _CRS. However, this also prevents drivers from adding those resources explicitly if needed. To fix this, move the logic to exclude these resources into an ignore hook used when parsing _CRS to create the initial set of resources for each device. Reviewed by: imp Differential Revision: https://reviews.freebsd.org/D43892 (cherry picked from commit 055c1fe230ce5a2997c03a3cc2431baea1594566) --- sys/dev/acpica/acpi.c | 34 --------------------- sys/dev/acpica/acpi_resource.c | 69 ++++++++++++++++++++++++++++++++++++++++-- 2 files changed, 67 insertions(+), 36 deletions(-) diff --git a/sys/dev/acpica/acpi.c b/sys/dev/acpica/acpi.c index 2e0a8a24610d..955c2b71b5ec 100644 --- a/sys/dev/acpica/acpi.c +++ b/sys/dev/acpica/acpi.c @@ -97,7 +97,6 @@ struct acpi_interface { }; static char *sysres_ids[] = { "PNP0C01", "PNP0C02", NULL }; -static char *pcilink_ids[] = { "PNP0C0F", NULL }; /* Global mutex for locking access to the ACPI subsystem. */ struct mtx acpi_mutex; @@ -1423,40 +1422,7 @@ acpi_set_resource(device_t dev, device_t child, int type, int rid, { struct acpi_device *ad = device_get_ivars(child); struct resource_list *rl = &ad->ad_rl; - ACPI_DEVICE_INFO *devinfo; rman_res_t end; - int allow; - - /* Ignore IRQ resources for PCI link devices. */ - if (type == SYS_RES_IRQ && - ACPI_ID_PROBE(dev, child, pcilink_ids, NULL) <= 0) - return (0); - - /* - * Ignore most resources for PCI root bridges. Some BIOSes - * incorrectly enumerate the memory ranges they decode as plain - * memory resources instead of as ResourceProducer ranges. Other - * BIOSes incorrectly list system resource entries for I/O ranges - * under the PCI bridge. Do allow the one known-correct case on - * x86 of a PCI bridge claiming the I/O ports used for PCI config - * access. - */ - if (type == SYS_RES_MEMORY || type == SYS_RES_IOPORT) { - if (ACPI_SUCCESS(AcpiGetObjectInfo(ad->ad_handle, &devinfo))) { - if ((devinfo->Flags & ACPI_PCI_ROOT_BRIDGE) != 0) { -#if defined(__i386__) || defined(__amd64__) - allow = (type == SYS_RES_IOPORT && start == CONF1_ADDR_PORT); -#else - allow = 0; -#endif - if (!allow) { - AcpiOsFree(devinfo); - return (0); - } - } - AcpiOsFree(devinfo); - } - } #ifdef INTRNG /* map with default for now */ diff --git a/sys/dev/acpica/acpi_resource.c b/sys/dev/acpica/acpi_resource.c index 373cc6da9820..e17b891d7974 100644 --- a/sys/dev/acpica/acpi_resource.c +++ b/sys/dev/acpica/acpi_resource.c @@ -34,6 +34,9 @@ #include #include +#if defined(__i386__) || defined(__amd64__) +#include +#endif #include #include #include @@ -62,6 +65,8 @@ struct lookup_irq_request { int pol; }; +static char *pcilink_ids[] = { "PNP0C0F", NULL }; + static ACPI_STATUS acpi_lookup_irq_handler(ACPI_RESOURCE *res, void *context) { @@ -575,6 +580,52 @@ struct acpi_res_context { void *ar_parent; }; +/* + * Some resources reported via _CRS should not be added as bus + * resources. This function returns true if a resource reported via + * _CRS should be ignored. + */ +static bool +acpi_res_ignore(device_t dev, int type, rman_res_t start, rman_res_t count) +{ + struct acpi_device *ad = device_get_ivars(dev); + ACPI_DEVICE_INFO *devinfo; + bool allow; + + /* Ignore IRQ resources for PCI link devices. */ + if (type == SYS_RES_IRQ && + ACPI_ID_PROBE(device_get_parent(dev), dev, pcilink_ids, NULL) <= 0) + return (true); + + /* + * Ignore most resources for PCI root bridges. Some BIOSes + * incorrectly enumerate the memory ranges they decode as plain + * memory resources instead of as ResourceProducer ranges. Other + * BIOSes incorrectly list system resource entries for I/O ranges + * under the PCI bridge. Do allow the one known-correct case on + * x86 of a PCI bridge claiming the I/O ports used for PCI config + * access. + */ + if (type == SYS_RES_MEMORY || type == SYS_RES_IOPORT) { + if (ACPI_SUCCESS(AcpiGetObjectInfo(ad->ad_handle, &devinfo))) { + if ((devinfo->Flags & ACPI_PCI_ROOT_BRIDGE) != 0) { +#if defined(__i386__) || defined(__amd64__) + allow = (type == SYS_RES_IOPORT && start == CONF1_ADDR_PORT); +#else + allow = false; +#endif + if (!allow) { + AcpiOsFree(devinfo); + return (true); + } + } + AcpiOsFree(devinfo); + } + } + + return (false); +} + static void acpi_res_set_init(device_t dev, void *arg, void **context) { @@ -605,6 +656,8 @@ acpi_res_set_ioport(device_t dev, void *context, uint64_t base, if (cp == NULL) return; + if (acpi_res_ignore(dev, SYS_RES_IOPORT, base, length)) + return; bus_set_resource(dev, SYS_RES_IOPORT, cp->ar_nio++, base, length); } @@ -630,6 +683,8 @@ acpi_res_set_iorange(device_t dev, void *context, uint64_t low, device_printf(dev, "_CRS has fixed I/O port range defined as relocatable\n"); + if (acpi_res_ignore(dev, SYS_RES_IOPORT, low, length)) + return; bus_set_resource(dev, SYS_RES_IOPORT, cp->ar_nio++, low, length); return; } @@ -645,6 +700,8 @@ acpi_res_set_memory(device_t dev, void *context, uint64_t base, if (cp == NULL) return; + if (acpi_res_ignore(dev, SYS_RES_MEMORY, base, length)) + return; bus_set_resource(dev, SYS_RES_MEMORY, cp->ar_nmem++, base, length); } @@ -669,8 +726,11 @@ acpi_res_set_irq(device_t dev, void *context, uint8_t *irq, int count, if (cp == NULL || irq == NULL) return; - for (i = 0; i < count; i++) + for (i = 0; i < count; i++) { + if (acpi_res_ignore(dev, SYS_RES_IRQ, irq[i], 1)) + continue; bus_set_resource(dev, SYS_RES_IRQ, cp->ar_nirq++, irq[i], 1); + } } static void @@ -683,8 +743,11 @@ acpi_res_set_ext_irq(device_t dev, void *context, uint32_t *irq, int count, if (cp == NULL || irq == NULL) return; - for (i = 0; i < count; i++) + for (i = 0; i < count; i++) { + if (acpi_res_ignore(dev, SYS_RES_IRQ, irq[i], 1)) + continue; bus_set_resource(dev, SYS_RES_IRQ, cp->ar_nirq++, irq[i], 1); + } } static void @@ -699,6 +762,8 @@ acpi_res_set_drq(device_t dev, void *context, uint8_t *drq, int count) if (count != 1) return; + if (acpi_res_ignore(dev, SYS_RES_DRQ, *drq, 1)) + return; bus_set_resource(dev, SYS_RES_DRQ, cp->ar_ndrq++, *drq, 1); }