Refactor pcie_tph_get_cpu_st(): extract core logic into static internal get_cpu_st() helper accepting explicit requester type parameter. - Preserve original pcie_tph_get_cpu_st() unchanged as auto wrapper; it uses existing pdev->tph_req_type automatically, existing callers require no change. - Add exported pcie_tph_get_cpu_st_explicit() with bool 'extended' parameter for manual STD/EXT requester selection, consumed by upcoming VFIO TPH code. - Add capability check: reject explicit EXT request when device does not support extended TPH requester. Signed-off-by: Chengwen Feng --- drivers/pci/tph.c | 68 ++++++++++++++++++++++++++++++----------- include/linux/pci-tph.h | 7 +++++ 2 files changed, 57 insertions(+), 18 deletions(-) diff --git a/drivers/pci/tph.c b/drivers/pci/tph.c index 51009ac9b379..aca08671fdfe 100644 --- a/drivers/pci/tph.c +++ b/drivers/pci/tph.c @@ -231,21 +231,8 @@ static int write_tag_to_st_table(struct pci_dev *pdev, int index, u16 tag) return pci_write_config_word(pdev, offset, tag); } -/** - * 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 that is associated with a - * specific CPU as indicated by cpu. - * - * 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) +static int get_cpu_st(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; @@ -269,19 +256,64 @@ 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 } + +/** + * 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 that is associated with a + * specific CPU as indicated by cpu. + * + * 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 get_cpu_st(pdev, mem_type, pdev->tph_req_type, cpu, tag); +} EXPORT_SYMBOL(pcie_tph_get_cpu_st); +/** + * pcie_tph_get_cpu_st_explicit - Get ST with explicit requester type + * @pdev: PCI device + * @mem_type: target memory type (volatile or persistent RAM) + * @extended: true=EXT_TPH, false=standard TPH only + * @cpu: associated CPU id + * @tag: output steering tag pointer + * + * Unlike auto pcie_tph_get_cpu_st(), caller manually picks requester type. + * Rejects EXT request if device lacks extended requester capability. + * + * Return: 0 on success, negative errno on failure. + */ +int pcie_tph_get_cpu_st_explicit(struct pci_dev *pdev, + enum tph_mem_type mem_type, + bool extended, unsigned int cpu, u16 *tag) +{ + u8 req_type = extended ? PCI_TPH_REQ_EXT_TPH : PCI_TPH_REQ_TPH_ONLY; + + if (extended && !pdev->tph_ext_support) + return -EINVAL; + + return get_cpu_st(pdev, mem_type, req_type, cpu, tag); +} +EXPORT_SYMBOL(pcie_tph_get_cpu_st_explicit); + /** * pcie_tph_set_st_entry() - Set Steering Tag in the ST table entry * @pdev: PCI device diff --git a/include/linux/pci-tph.h b/include/linux/pci-tph.h index ca0faa98afac..1a508b3d511f 100644 --- a/include/linux/pci-tph.h +++ b/include/linux/pci-tph.h @@ -27,6 +27,9 @@ int pcie_tph_set_st_entry(struct pci_dev *pdev, int pcie_tph_get_cpu_st(struct pci_dev *dev, enum tph_mem_type mem_type, unsigned int cpu, u16 *tag); +int pcie_tph_get_cpu_st_explicit(struct pci_dev *pdev, + enum tph_mem_type mem_type, + bool extended, unsigned int cpu, u16 *tag); void pcie_disable_tph(struct pci_dev *pdev); int pcie_enable_tph(struct pci_dev *pdev, int mode); int pcie_enable_tph_explicit(struct pci_dev *pdev, int mode, bool extended); @@ -40,6 +43,10 @@ static inline int pcie_tph_get_cpu_st(struct pci_dev *dev, enum tph_mem_type mem_type, unsigned int cpu, u16 *tag) { return -EINVAL; } +static inline int pcie_tph_get_cpu_st_explicit(struct pci_dev *pdev, + enum tph_mem_type mem_type, + bool extended, unsigned int cpu, u16 *tag) +{ return -EINVAL; } static inline void pcie_disable_tph(struct pci_dev *pdev) { } static inline int pcie_enable_tph(struct pci_dev *pdev, int mode) { return -EINVAL; } -- 2.17.1