Add new helper pcie_tph_supported() with want_ext parameter: - want_ext = false: Check if device has valid TPH capability; - want_ext = true: Check hardware Extended TPH support. This helper is prepared for follow-up VFIO TPH virtualization patches to uniformly query basic TPH existence and Extended TPH capability. Signed-off-by: Chengwen Feng --- drivers/pci/tph.c | 19 +++++++++++++++++++ include/linux/pci-tph.h | 3 +++ 2 files changed, 22 insertions(+) diff --git a/drivers/pci/tph.c b/drivers/pci/tph.c index 6c4623cacc85..95280aab4fb5 100644 --- a/drivers/pci/tph.c +++ b/drivers/pci/tph.c @@ -600,3 +600,22 @@ void pci_tph_init(struct pci_dev *pdev) save_size = sizeof(u32) + num_entries * sizeof(u16); pci_add_ext_cap_save_buffer(pdev, PCI_EXT_CAP_ID_TPH, save_size); } + +/** + * pcie_tph_supported - Check TPH capability attribute + * @pdev: PCI device to query + * @want_ext: false - check TPH cap exists; true - check EXT_TPH support + * + * Return: true on matched condition, false otherwise + */ +bool pcie_tph_supported(struct pci_dev *pdev, bool want_ext) +{ + if (!pdev->tph_cap) + return false; + + if (!want_ext) + return true; + + return pdev->tph_ext_support; +} +EXPORT_SYMBOL(pcie_tph_supported); diff --git a/include/linux/pci-tph.h b/include/linux/pci-tph.h index e4f7045fc152..5917a0694c1d 100644 --- a/include/linux/pci-tph.h +++ b/include/linux/pci-tph.h @@ -36,6 +36,7 @@ int pcie_enable_tph_explicit(struct pci_dev *pdev, int mode, bool extended); u8 pcie_tph_enabled_req_type(struct pci_dev *pdev); u16 pcie_tph_get_st_table_size(struct pci_dev *pdev); u32 pcie_tph_get_st_table_loc(struct pci_dev *pdev); +bool pcie_tph_supported(struct pci_dev *pdev, bool want_ext); #else static inline int pcie_tph_set_st_entry(struct pci_dev *pdev, unsigned int index, u16 tag) @@ -60,6 +61,8 @@ static inline u16 pcie_tph_get_st_table_size(struct pci_dev *pdev) { return 0; } static inline u32 pcie_tph_get_st_table_loc(struct pci_dev *pdev) { return PCI_TPH_LOC_NONE; } +static inline bool pcie_tph_supported(struct pci_dev *pdev, bool want_ext) +{ return false; } #endif #endif /* LINUX_PCI_TPH_H */ -- 2.17.1