From nobody Wed Feb 14 22:52:43 2024 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 4TZtkh1RQNz53xWX; Wed, 14 Feb 2024 22:52:44 +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 4TZtkh0dDMz4FNx; Wed, 14 Feb 2024 22:52:44 +0000 (UTC) (envelope-from git@FreeBSD.org) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=freebsd.org; s=dkim; t=1707951164; 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=JkQkIwkLUMWjHSLQzFwIWZyw6QcqcM2CeDm67LZfzOg=; b=rH2FPnCeeraMjqE1HgtnzY+EiV/ShwUVYCaQf6FeEuD3+0/5xC/PWCL1NtULdhxTVmhdEg Lx7HmZTYSU/ImcH7N79x5Li7z44ns/jf2OfnujQ8IufIypXmhlCEKfH7pueFMyhnhuAh+S 8hzO4BZJ4LSpp7eXICnII71ZkMVK/6dQn6uqiLh5c7lAFuXN3QAILlkBYS8ZR4sSJWYGtQ 5CfJxlXcaSKn02NXsau526HAuv8sl7NIYQOnx4CD5I5gsEoG4kMCt5NhhDXBM3Tsv+HZpq mAxrE3YXM1EoRGaFiQqZY18Kg7p07qwaZb39RulrousptPH08hb4Y6z1g8V9dg== ARC-Seal: i=1; s=dkim; d=freebsd.org; t=1707951164; a=rsa-sha256; cv=none; b=wW6B3I6JwCG2+Km8heO6TAEvtyH+D9m3zY6ZCgaUsr/tszYc4hq1pZJoz2Akj7xFud9zkp kBAKCnEpIp0IN26hS3SDKE4HspyjipbaeMbDIvYYSJ8zkFOm/R2zRUeWFC6WrFJglmokMU lfXnGR9cN6a3yBcIDP+JOMpAxOvRzMvGFuGvXo31PMZU77NtULLRGooku/+I9B63W0SRI6 RJR/pM9zfQjo+D4a5jMcf/cyEtr/70CcOllnE/JgtlWTmM4gAgXyyM5YLWwjVNkrAq/qDO FoDv/Zpe/bucaLtE0La17YLj5on2bMNYel+0foQGM5oLI+WGr8r82U+KOEng1Q== 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=1707951164; 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=JkQkIwkLUMWjHSLQzFwIWZyw6QcqcM2CeDm67LZfzOg=; b=lQaHWJaRGs5rud672P5DlBdIyK3ju6YN9WK+d1ZmpS5u7K1nEnwk/iYf+dbttEuJe852Va 81GwdcXyAlLWC+uTMuzOn5OPfF1a3+lSaEW5dhJqL/cj4C7FVfZ6abRlT3oMVO1SgcZ99i 7f9Vvc1E2N+z9jiRjsNDv4zTLjpHhgHmWsUWiI0JKcV8Iz4LQiv4fO1WvYeOuhhXGm8mEB BeOd1VwvbvgQJNdcxjNazFIlaRCMEHY4ZvCueFev198FByk8BV/ty+LdfIWn4wFcDxt3Pu pHYt5ycllfBApfs8W3DUMNqCx37h8KWRPzNS+qpY9OaMKTLXcUrdAd9exgK/Vw== 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 4TZtkg6bYHzGwD; Wed, 14 Feb 2024 22:52:43 +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 41EMqhNX086337; Wed, 14 Feb 2024 22:52:43 GMT (envelope-from git@gitrepo.freebsd.org) Received: (from git@localhost) by gitrepo.freebsd.org (8.17.1/8.17.1/Submit) id 41EMqhAD086334; Wed, 14 Feb 2024 22:52:43 GMT (envelope-from git) Date: Wed, 14 Feb 2024 22:52:43 GMT Message-Id: <202402142252.41EMqhAD086334@gitrepo.freebsd.org> To: src-committers@FreeBSD.org, dev-commits-src-all@FreeBSD.org, dev-commits-src-main@FreeBSD.org From: John Baldwin Subject: git: 055c1fe230ce - main - acpi: Allow child drivers to use bus_set_resource for more resources 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: jhb X-Git-Repository: src X-Git-Refname: refs/heads/main X-Git-Reftype: branch X-Git-Commit: 055c1fe230ce5a2997c03a3cc2431baea1594566 Auto-Submitted: auto-generated The branch main has been updated by jhb: URL: https://cgit.FreeBSD.org/src/commit/?id=055c1fe230ce5a2997c03a3cc2431baea1594566 commit 055c1fe230ce5a2997c03a3cc2431baea1594566 Author: John Baldwin AuthorDate: 2024-02-14 22:07:32 +0000 Commit: John Baldwin CommitDate: 2024-02-14 22:07:32 +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 --- 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 46e9fe084fce..43aed279ab35 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; @@ -1431,40 +1430,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 6b77e74d95f1..87b82a574beb 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) { @@ -582,6 +587,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) { @@ -612,6 +663,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); } @@ -637,6 +690,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; } @@ -652,6 +707,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); } @@ -676,8 +733,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 @@ -690,8 +750,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 @@ -706,6 +769,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); }