From nobody Thu Dec 12 18:19:01 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 4Y8LMV02F2z5gZnG; Thu, 12 Dec 2024 18:19:02 +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 "R10" (verified OK)) by mx1.freebsd.org (Postfix) with ESMTPS id 4Y8LMT6QFHz3xML; Thu, 12 Dec 2024 18:19:01 +0000 (UTC) (envelope-from git@FreeBSD.org) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=freebsd.org; s=dkim; t=1734027541; 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=dtqtAmuAv40AxfLbt4DZuDDpEyfSxmyJbiCxKW/9zVk=; b=RBSbS9WkA3RBRIzJEe1zu7ltP4EA9MgC5YcTdC7PP60pEmrmTg4tbZyVzoVB9CzL+QkgdL h0RZxq6FR1hlXEaV+fwIArBkDWKA7iGTqctQHxlhh6hOa6ywBDkoESRIt+YzzCvr4nWTqO OP3tP+39BhxVEmquE7Mj4nfv0UvsaMfqFs2wc/zq8VoffRs2cPg1wF3OxOc9dZlkyHliu+ assyrmMkr89C+vHr4jBAhfPIpXnu2A8eYTafAIxqymbvN3xJngdc60gIVxqWA7mSJ1Tl96 oGl8304GKN2gEeLG6xM8p2BRZMnA64cmRl8LJ3bjDYMsT5qGsI+Jj+gMITF7LQ== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=freebsd.org; s=dkim; t=1734027541; 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=dtqtAmuAv40AxfLbt4DZuDDpEyfSxmyJbiCxKW/9zVk=; b=eZyFf6rJUOobgJ2+q7uOYLvDUssrhwS7Z//2I2eeGgZjzapK/GgegQIXh1QyNCHzdfMvUF 06JUrSEPjNE5Hz8i4EZa3FInzONV2qggzHNcZXFn0+a256HURf5AwuSce+U7BVzekR341m 3H57GbuX/Bl8gRMybdqtJ3wueIywkzPI7BRvVeUFHX4EryO3Ad/yt2n62E+otcK0AImxx1 JhWQPMbmwSV7inJ9OjsQKsfZD/OdMer+/U4x4ANJC8VOXaCXRLAW5IL6J0uvdsCgdxQgeP Bmt+DehqtUU/9JojiADhHvPzax1/NBiPE/qYLMpxyYkkDuDnIwF4e07KXKE7Sg== ARC-Authentication-Results: i=1; mx1.freebsd.org; none ARC-Seal: i=1; s=dkim; d=freebsd.org; t=1734027541; a=rsa-sha256; cv=none; b=Pv2j+7rvEzLzdZ9PSFArE0PDVo6gv/L7+LZ25ur5BE3HbKWDUFzNXpA5+BjnDStg2dDsVB rOVBTG+hYgSfPpW4TbaUuREPhxpupVOP06w5AXKh7AktOByTivYRqtOVByVSTEtp/j6+Qm Xa4WMpuzI3esGJAVhZ3Ny7vgOEmYsKfUwumXRk2vIEVq/hVBSqgI7E3AXC4iAwKpR0OL+b koCRiwQ89ot4WypdCQcEJzNMskXjhEAiVYd6l+KkghESetXowXBKO5ChuwnOQnoyOOhdaJ 6Tf10Wt1STlzfnH9zVvrBIXp9N1Nxf1x3ucxHFMKecQetIlx7QNIggHhmBge1g== 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 4Y8LMT61dpz13WK; Thu, 12 Dec 2024 18:19:01 +0000 (UTC) (envelope-from git@FreeBSD.org) Received: from gitrepo.freebsd.org ([127.0.1.44]) by gitrepo.freebsd.org (8.18.1/8.18.1) with ESMTP id 4BCIJ1id097193; Thu, 12 Dec 2024 18:19:01 GMT (envelope-from git@gitrepo.freebsd.org) Received: (from git@localhost) by gitrepo.freebsd.org (8.18.1/8.18.1/Submit) id 4BCIJ1KW097190; Thu, 12 Dec 2024 18:19:01 GMT (envelope-from git) Date: Thu, 12 Dec 2024 18:19:01 GMT Message-Id: <202412121819.4BCIJ1KW097190@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: ba1904937d9a - main - acpica: Extract _OSC parsing to a common file 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: X-BeenThere: dev-commits-src-all@freebsd.org Sender: owner-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: ba1904937d9ae0539e39001467a1519b17177118 Auto-Submitted: auto-generated The branch main has been updated by andrew: URL: https://cgit.FreeBSD.org/src/commit/?id=ba1904937d9ae0539e39001467a1519b17177118 commit ba1904937d9ae0539e39001467a1519b17177118 Author: Andrew Turner AuthorDate: 2024-12-12 16:29:45 +0000 Commit: Andrew Turner CommitDate: 2024-12-12 18:00:22 +0000 acpica: Extract _OSC parsing to a common file This will be used by pci_host_generic_acpi.c so needs to be in a common location. Reviewed by: imp, jhb Sponsored by: Arm Ltd Differential Revision: https://reviews.freebsd.org/D48044 --- sys/dev/acpica/acpi_pcib.c | 59 ++++++++++++++++++++++++++++++++++++++++ sys/dev/acpica/acpi_pcib_acpi.c | 60 ++--------------------------------------- sys/dev/acpica/acpi_pcibvar.h | 1 + 3 files changed, 62 insertions(+), 58 deletions(-) diff --git a/sys/dev/acpica/acpi_pcib.c b/sys/dev/acpica/acpi_pcib.c index b16457ec853d..dfb4f143d5c4 100644 --- a/sys/dev/acpica/acpi_pcib.c +++ b/sys/dev/acpica/acpi_pcib.c @@ -38,6 +38,7 @@ #include #include +#include #include #include "pcib_if.h" @@ -277,3 +278,61 @@ acpi_pcib_get_cpus(device_t pcib, device_t dev, enum cpu_sets op, return (bus_get_cpus(pcib, op, setsize, cpuset)); } + +int +acpi_pcib_osc(device_t pcib, uint32_t *ap_osc_ctl, uint32_t osc_ctl) +{ + ACPI_STATUS status; + ACPI_HANDLE handle; + uint32_t cap_set[3]; + + static uint8_t pci_host_bridge_uuid[ACPI_UUID_LENGTH] = { + 0x5b, 0x4d, 0xdb, 0x33, 0xf7, 0x1f, 0x1c, 0x40, + 0x96, 0x57, 0x74, 0x41, 0xc0, 0x3d, 0xd7, 0x66 + }; + + /* + * Don't invoke _OSC if a control is already granted. + * However, always invoke _OSC during attach when 0 is passed. + */ + if (osc_ctl != 0 && (*ap_osc_ctl & osc_ctl) == osc_ctl) + return (0); + + /* Support Field: Extended PCI Config Space, PCI Segment Groups, MSI */ + cap_set[PCI_OSC_SUPPORT] = PCIM_OSC_SUPPORT_EXT_PCI_CONF | + PCIM_OSC_SUPPORT_SEG_GROUP | PCIM_OSC_SUPPORT_MSI; + /* Active State Power Management, Clock Power Management Capability */ + if (pci_enable_aspm) + cap_set[PCI_OSC_SUPPORT] |= PCIM_OSC_SUPPORT_ASPM | + PCIM_OSC_SUPPORT_CPMC; + + /* Control Field */ + cap_set[PCI_OSC_CTL] = *ap_osc_ctl | osc_ctl; + + handle = acpi_get_handle(pcib); + status = acpi_EvaluateOSC(handle, pci_host_bridge_uuid, 1, + nitems(cap_set), cap_set, cap_set, false); + if (ACPI_FAILURE(status)) { + if (status == AE_NOT_FOUND) { + *ap_osc_ctl |= osc_ctl; + return (0); + } + device_printf(pcib, "_OSC failed: %s\n", + AcpiFormatException(status)); + return (EIO); + } + + /* + * _OSC may return an error in the status word, but will + * update the control mask always. _OSC should not revoke + * previously-granted controls. + */ + if ((cap_set[PCI_OSC_CTL] & *ap_osc_ctl) != *ap_osc_ctl) + device_printf(pcib, "_OSC revoked %#x\n", + (cap_set[PCI_OSC_CTL] & *ap_osc_ctl) ^ *ap_osc_ctl); + *ap_osc_ctl = cap_set[PCI_OSC_CTL]; + if ((*ap_osc_ctl & osc_ctl) != osc_ctl) + return (EIO); + + return (0); +} diff --git a/sys/dev/acpica/acpi_pcib_acpi.c b/sys/dev/acpica/acpi_pcib_acpi.c index bd005aed8fdc..e4cff4639a93 100644 --- a/sys/dev/acpica/acpi_pcib_acpi.c +++ b/sys/dev/acpica/acpi_pcib_acpi.c @@ -286,62 +286,6 @@ get_decoded_bus_range(struct acpi_hpcib_softc *sc, rman_res_t *startp, return (true); } -static int -acpi_pcib_osc(struct acpi_hpcib_softc *sc, uint32_t osc_ctl) -{ - ACPI_STATUS status; - uint32_t cap_set[3]; - - static uint8_t pci_host_bridge_uuid[ACPI_UUID_LENGTH] = { - 0x5b, 0x4d, 0xdb, 0x33, 0xf7, 0x1f, 0x1c, 0x40, - 0x96, 0x57, 0x74, 0x41, 0xc0, 0x3d, 0xd7, 0x66 - }; - - /* - * Don't invoke _OSC if a control is already granted. - * However, always invoke _OSC during attach when 0 is passed. - */ - if (osc_ctl != 0 && (sc->ap_osc_ctl & osc_ctl) == osc_ctl) - return (0); - - /* Support Field: Extended PCI Config Space, PCI Segment Groups, MSI */ - cap_set[PCI_OSC_SUPPORT] = PCIM_OSC_SUPPORT_EXT_PCI_CONF | - PCIM_OSC_SUPPORT_SEG_GROUP | PCIM_OSC_SUPPORT_MSI; - /* Active State Power Management, Clock Power Management Capability */ - if (pci_enable_aspm) - cap_set[PCI_OSC_SUPPORT] |= PCIM_OSC_SUPPORT_ASPM | - PCIM_OSC_SUPPORT_CPMC; - - /* Control Field */ - cap_set[PCI_OSC_CTL] = sc->ap_osc_ctl | osc_ctl; - - status = acpi_EvaluateOSC(sc->ap_handle, pci_host_bridge_uuid, 1, - nitems(cap_set), cap_set, cap_set, false); - if (ACPI_FAILURE(status)) { - if (status == AE_NOT_FOUND) { - sc->ap_osc_ctl |= osc_ctl; - return (0); - } - device_printf(sc->ap_dev, "_OSC failed: %s\n", - AcpiFormatException(status)); - return (EIO); - } - - /* - * _OSC may return an error in the status word, but will - * update the control mask always. _OSC should not revoke - * previously-granted controls. - */ - if ((cap_set[PCI_OSC_CTL] & sc->ap_osc_ctl) != sc->ap_osc_ctl) - device_printf(sc->ap_dev, "_OSC revoked %#x\n", - (cap_set[PCI_OSC_CTL] & sc->ap_osc_ctl) ^ sc->ap_osc_ctl); - sc->ap_osc_ctl = cap_set[PCI_OSC_CTL]; - if ((sc->ap_osc_ctl & osc_ctl) != osc_ctl) - return (EIO); - - return (0); -} - static int acpi_pcib_acpi_attach(device_t dev) { @@ -367,7 +311,7 @@ acpi_pcib_acpi_attach(device_t dev) if (!acpi_DeviceIsPresent(dev)) return (ENXIO); - acpi_pcib_osc(sc, 0); + acpi_pcib_osc(dev, &sc->ap_osc_ctl, 0); /* * Get our segment number by evaluating _SEG. @@ -759,7 +703,7 @@ acpi_pcib_request_feature(device_t pcib, device_t dev, enum pci_feature feature) return (EINVAL); } - return (acpi_pcib_osc(sc, osc_ctl)); + return (acpi_pcib_osc(dev, &sc->ap_osc_ctl, osc_ctl)); } static bus_dma_tag_t diff --git a/sys/dev/acpica/acpi_pcibvar.h b/sys/dev/acpica/acpi_pcibvar.h index 2b75c276f9d1..c763eeea1941 100644 --- a/sys/dev/acpica/acpi_pcibvar.h +++ b/sys/dev/acpica/acpi_pcibvar.h @@ -40,6 +40,7 @@ int acpi_pcib_route_interrupt(device_t pcib, device_t dev, int pin, ACPI_BUFFER *prtbuf); int acpi_pcib_power_for_sleep(device_t pcib, device_t dev, int *pstate); +int acpi_pcib_osc(device_t pcib, uint32_t *ap_osc_ctl, uint32_t osc_ctl); #endif /* _KERNEL */