Refactor pcie_tph_get_cpu_st() and add pcie_tph_get_cpu_st_ext() extended variant with explicit requester type parameter. - Preserve original pcie_tph_get_cpu_st() as a compatibility wrapper, using the default negotiated tph_max_type automatically, so existing callers require no modification. - Add exported pcie_tph_get_cpu_st_ext() to accept an explicit requester type argument for ST namespace selection, used by upcoming VFIO TPH support. - Add requester type validation to reject invalid values and enforce the hardware negotiated tph_max_type capability limit. Update pci-tph.h header and CONFIG_PCIE_TPH stub inline definitions to match the new function signatures. Signed-off-by: Chengwen Feng --- drivers/pci/tph.c | 45 ++++++++++++++++++++++++++++++++--------- include/linux/pci-tph.h | 10 +++++++-- 2 files changed, 44 insertions(+), 11 deletions(-) diff --git a/drivers/pci/tph.c b/drivers/pci/tph.c index 1239a919b9a4..633dc6308b68 100644 --- a/drivers/pci/tph.c +++ b/drivers/pci/tph.c @@ -276,20 +276,22 @@ static int write_tag_to_st_table(struct pci_dev *pdev, int index, u16 tag) } /** - * pcie_tph_get_cpu_st() - Retrieve Steering Tag for a target memory associated - * with a specific CPU + * pcie_tph_get_cpu_st_ext() - Retrieve Steering Tag for a target memory + * associated with a specific CPU, with explicit requester type selection * @pdev: PCI device * @mem_type: target memory type (volatile or persistent RAM) + * @req_type: TPH requester type to select ST namespace * @cpu: associated CPU id * @tag: Steering Tag to be returned * - * Return the Steering Tag for a target memory that is associated with a - * specific CPU as indicated by cpu. + * Return the Steering Tag for a target memory associated with a specific CPU, + * using the specified TPH requester type to select the correct ST namespace. + * Validates requester type against hardware negotiated capability limits. * * Return: 0 if success, otherwise negative value (-errno) */ -int pcie_tph_get_cpu_st(struct pci_dev *pdev, enum tph_mem_type mem_type, - unsigned int cpu, u16 *tag) +int pcie_tph_get_cpu_st_ext(struct pci_dev *pdev, enum tph_mem_type mem_type, + u8 req_type, unsigned int cpu, u16 *tag) { #ifdef CONFIG_ACPI struct pci_dev *rp; @@ -298,6 +300,10 @@ int pcie_tph_get_cpu_st(struct pci_dev *pdev, enum tph_mem_type mem_type, u32 cpu_uid; int ret; + if (req_type == PCI_TPH_REQ_DISABLE || req_type == 2 || + req_type > pdev->tph_max_type) + return -EINVAL; + ret = acpi_get_cpu_uid(cpu, &cpu_uid); if (ret != 0) return ret; @@ -313,17 +319,38 @@ int pcie_tph_get_cpu_st(struct pci_dev *pdev, enum tph_mem_type mem_type, return -EINVAL; } - *tag = tph_extract_tag(mem_type, pdev->tph_req_type, &info); + *tag = tph_extract_tag(mem_type, req_type, &info); - pci_dbg(pdev, "get steering tag: mem_type=%s, cpu=%d, tag=%#04x\n", + pci_dbg(pdev, "get steering tag: mem_type=%s, req_type=%u, cpu=%d, tag=%#04x\n", (mem_type == TPH_MEM_TYPE_VM) ? "volatile" : "persistent", - cpu, *tag); + req_type, cpu, *tag); return 0; #else return -ENODEV; #endif } +EXPORT_SYMBOL(pcie_tph_get_cpu_st_ext); + +/** + * pcie_tph_get_cpu_st() - Retrieve Steering Tag for a target memory associated + * with a specific CPU + * @pdev: PCI device + * @mem_type: target memory type (volatile or persistent RAM) + * @cpu: associated CPU id + * @tag: Steering Tag to be returned + * + * Return the Steering Tag for a target memory associated with a specific CPU, + * using the default negotiated TPH requester type. + * + * Return: 0 if success, otherwise negative value (-errno) + */ +int pcie_tph_get_cpu_st(struct pci_dev *pdev, enum tph_mem_type mem_type, + unsigned int cpu, u16 *tag) +{ + return pcie_tph_get_cpu_st_ext(pdev, mem_type, pdev->tph_max_type, + cpu, tag); +} EXPORT_SYMBOL(pcie_tph_get_cpu_st); /** diff --git a/include/linux/pci-tph.h b/include/linux/pci-tph.h index 3055776495c1..6901f6e2f8c7 100644 --- a/include/linux/pci-tph.h +++ b/include/linux/pci-tph.h @@ -25,8 +25,9 @@ enum tph_mem_type { #ifdef CONFIG_PCIE_TPH int pcie_tph_set_st_entry(struct pci_dev *pdev, unsigned int index, u16 tag); -int pcie_tph_get_cpu_st(struct pci_dev *dev, - enum tph_mem_type mem_type, +int pcie_tph_get_cpu_st_ext(struct pci_dev *dev, enum tph_mem_type mem_type, + u8 req_type, unsigned int cpu, u16 *tag); +int pcie_tph_get_cpu_st(struct pci_dev *dev, enum tph_mem_type mem_type, unsigned int cpu, u16 *tag); void pcie_disable_tph(struct pci_dev *pdev); int pcie_enable_tph_ext(struct pci_dev *pdev, u8 mode, u8 req_type); @@ -39,6 +40,11 @@ u8 pcie_tph_completer_type(struct pci_dev *pdev); static inline int pcie_tph_set_st_entry(struct pci_dev *pdev, unsigned int index, u16 tag) { return -EINVAL; } +static inline int pcie_tph_get_cpu_st_ext(struct pci_dev *dev, + enum tph_mem_type mem_type, + u8 req_type, unsigned int cpu, + u16 *tag) +{ return -EINVAL; } static inline int pcie_tph_get_cpu_st(struct pci_dev *dev, enum tph_mem_type mem_type, unsigned int cpu, u16 *tag) -- 2.17.1