mirror of https://lore.kernel.org/lkml/
 help / color / mirror / Atom feed
From: Wei Huang <wei.huang2@amd.com>
To: <bhelgaas@google.com>
Cc: <linux-pci@vger.kernel.org>, <linux-doc@vger.kernel.org>,
	<linux-kernel@vger.kernel.org>, <skhan@linuxfoundation.org>,
	<corbet@lwn.net>, <rdunlap@infradead.org>,
	<fengchengwen@huawei.com>, <wei.huang2@amd.com>
Subject: [PATCH RFC 1/3] PCI/TPH: Factor out the ST _DSM evaluation
Date: Thu, 1 Oct 2026 10:55:49 -0500	[thread overview]
Message-ID: <20261001155551.4182899-2-wei.huang2@amd.com> (raw)
In-Reply-To: <20261001155551.4182899-1-wei.huang2@amd.com>

The ACPI _DSM that returns the CPU to Steering Tag (ST) mapping is
evaluated in one place today, with the lookup of the ACPI device providing
it open coded in pcie_tph_get_cpu_st().

Factor the handle lookup and the per-CPU query into tph_dsm_handle() and
tph_get_cpu_st_info() so other callers can reuse them, name the _DSM
revision instead of repeating the bare number, and constify the ST info
passed to tph_extract_tag().

No functional change introduced.

Signed-off-by: Wei Huang <wei.huang2@amd.com>
---
 drivers/pci/tph.c | 65 ++++++++++++++++++++++++++++++++---------------
 1 file changed, 45 insertions(+), 20 deletions(-)

diff --git a/drivers/pci/tph.c b/drivers/pci/tph.c
index 655ffd60e62f..d2c6d3dda202 100644
--- a/drivers/pci/tph.c
+++ b/drivers/pci/tph.c
@@ -18,6 +18,9 @@
 static bool pci_tph_disabled;
 
 #ifdef CONFIG_ACPI
+#define TPH_ST_DSM_REV		7
+#define TPH_ST_DSM_FUNC_INDEX	0xF
+
 /*
  * The st_info struct defines the Steering Tag (ST) info returned by the
  * firmware PCI ACPI _DSM method (rev=0x7, func=0xF, "_DSM to Query Cache
@@ -54,7 +57,7 @@ union st_info {
 };
 
 static u16 tph_extract_tag(enum tph_mem_type mem_type, u8 req_type,
-			   union st_info *info)
+			   const union st_info *info)
 {
 	switch (req_type) {
 	case PCI_TPH_REQ_TPH_ONLY: /* 8-bit tag */
@@ -88,13 +91,12 @@ static u16 tph_extract_tag(enum tph_mem_type mem_type, u8 req_type,
 	return 0;
 }
 
-#define TPH_ST_DSM_FUNC_INDEX	0xF
 static acpi_status tph_invoke_dsm(acpi_handle handle, u32 cpu_uid,
 				  union st_info *st_out)
 {
 	union acpi_object arg3[3], in_obj, *out_obj;
 
-	if (!acpi_check_dsm(handle, &pci_acpi_dsm_guid, 7,
+	if (!acpi_check_dsm(handle, &pci_acpi_dsm_guid, TPH_ST_DSM_REV,
 			    BIT(TPH_ST_DSM_FUNC_INDEX)))
 		return AE_ERROR;
 
@@ -114,7 +116,7 @@ static acpi_status tph_invoke_dsm(acpi_handle handle, u32 cpu_uid,
 	in_obj.package.count = ARRAY_SIZE(arg3);
 	in_obj.package.elements = arg3;
 
-	out_obj = acpi_evaluate_dsm(handle, &pci_acpi_dsm_guid, 7,
+	out_obj = acpi_evaluate_dsm(handle, &pci_acpi_dsm_guid, TPH_ST_DSM_REV,
 				    TPH_ST_DSM_FUNC_INDEX, &in_obj);
 	if (!out_obj)
 		return AE_ERROR;
@@ -130,6 +132,43 @@ static acpi_status tph_invoke_dsm(acpi_handle handle, u32 cpu_uid,
 
 	return AE_OK;
 }
+
+/*
+ * The ST _DSM is provided by the ACPI device of the Root Port's host bridge,
+ * so all Root Ports below the same host bridge share one ST mapping.
+ */
+static acpi_handle tph_dsm_handle(struct pci_dev *pdev)
+{
+	struct pci_dev *rp;
+
+	rp = pcie_find_root_port(pdev);
+	if (!rp || !rp->bus || !rp->bus->bridge)
+		return NULL;
+
+	return ACPI_HANDLE(rp->bus->bridge);
+}
+
+/* Query the firmware for the ST info of @cpu - Return 0 if OK, else -errno */
+static int tph_get_cpu_st_info(struct pci_dev *pdev, unsigned int cpu,
+			       union st_info *info)
+{
+	acpi_handle handle;
+	u32 cpu_uid;
+	int ret;
+
+	handle = tph_dsm_handle(pdev);
+	if (!handle)
+		return -ENODEV;
+
+	ret = acpi_get_cpu_uid(cpu, &cpu_uid);
+	if (ret)
+		return ret;
+
+	if (tph_invoke_dsm(handle, cpu_uid, info) != AE_OK)
+		return -EINVAL;
+
+	return 0;
+}
 #endif
 
 /* Update the TPH Requester Enable field of TPH Control Register */
@@ -247,27 +286,13 @@ int pcie_tph_get_cpu_st(struct pci_dev *pdev, enum tph_mem_type mem_type,
 			unsigned int cpu, u16 *tag)
 {
 #ifdef CONFIG_ACPI
-	struct pci_dev *rp;
-	acpi_handle rp_acpi_handle;
 	union st_info info;
-	u32 cpu_uid;
 	int ret;
 
-	ret = acpi_get_cpu_uid(cpu, &cpu_uid);
-	if (ret != 0)
+	ret = tph_get_cpu_st_info(pdev, cpu, &info);
+	if (ret)
 		return ret;
 
-	rp = pcie_find_root_port(pdev);
-	if (!rp || !rp->bus || !rp->bus->bridge)
-		return -ENODEV;
-
-	rp_acpi_handle = ACPI_HANDLE(rp->bus->bridge);
-
-	if (tph_invoke_dsm(rp_acpi_handle, cpu_uid, &info) != AE_OK) {
-		*tag = 0;
-		return -EINVAL;
-	}
-
 	*tag = tph_extract_tag(mem_type, pdev->tph_req_type, &info);
 
 	pci_dbg(pdev, "get steering tag: mem_type=%s, cpu=%d, tag=%#04x\n",
-- 
2.55.0


  reply	other threads:[~2026-10-01 15:56 UTC|newest]

Thread overview: 4+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2026-10-01 15:55 [PATCH RFC 0/3] PCI/TPH: Expose CPU-to-Steering Tag mappings via debugfs Wei Huang
2026-10-01 15:55 ` Wei Huang [this message]
2026-10-01 15:55 ` [PATCH RFC 2/3] PCI: Add per-device debugfs directories Wei Huang
2026-10-01 15:55 ` [PATCH RFC 3/3] Expose the CPU/Steering Tag mapping via debugfs Wei Huang

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20261001155551.4182899-2-wei.huang2@amd.com \
    --to=wei.huang2@amd.com \
    --cc=bhelgaas@google.com \
    --cc=corbet@lwn.net \
    --cc=fengchengwen@huawei.com \
    --cc=linux-doc@vger.kernel.org \
    --cc=linux-kernel@vger.kernel.org \
    --cc=linux-pci@vger.kernel.org \
    --cc=rdunlap@infradead.org \
    --cc=skhan@linuxfoundation.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox

all inboxes | Powered by JetHome®