From b0acad338e61d3d4837e651d213161cd0f1271b4 Mon Sep 17 00:00:00 2001 From: Alexander Merritt Date: Thu, 31 Oct 2019 23:51:38 -0700 Subject: [PATCH] HV: extra methods for extracting header fields Add some encapsulation of utilities which read PCI header space using wrapper functions. Also contain verification of PCI vendor to its own function, rather than having hard-coded integrals exposed among other code. v3->v2 Changed the return type of pci_pdev_read_cfg_secbus from 32-bit to 8-bit v2->v1 Function names changed to follow Coding guidelines Tracked-On: #4134 Signed-off-by: Alexander Merritt Signed-off-by: Sainath Grandhi --- hypervisor/include/hw/pci.h | 31 +++++++++++++++++++++++++++++++ 1 file changed, 31 insertions(+) diff --git a/hypervisor/include/hw/pci.h b/hypervisor/include/hw/pci.h index ff02a2fa7..101f14c6f 100644 --- a/hypervisor/include/hw/pci.h +++ b/hypervisor/include/hw/pci.h @@ -285,5 +285,36 @@ void enable_disable_pci_intx(union pci_bdf bdf, bool enable); void init_pci_pdev_list(void); +static inline bool is_pci_vendor_valid(uint32_t vendor_id) +{ + return !((vendor_id == 0xFFFFFFFFU) || (vendor_id == 0U) || + (vendor_id == 0xFFFF0000U) || (vendor_id == 0xFFFFU)); +} + +static inline uint32_t read_pci_pdev_cfg_vendor(union pci_bdf pbdf) +{ + return pci_pdev_read_cfg(pbdf, PCIR_VENDOR, 2U); +} + +static inline uint8_t read_pci_pdev_cfg_headertype(union pci_bdf pbdf) +{ + return (uint8_t)pci_pdev_read_cfg(pbdf, PCIR_HDRTYPE, 1U); +} + +static inline uint8_t read_pci_pdev_cfg_secbus(union pci_bdf pbdf) +{ + return (uint8_t)pci_pdev_read_cfg(pbdf, PCIR_SECBUS_1, 1U); +} + +static inline bool is_pci_cfg_multifunction(uint8_t header_type) +{ + return ((header_type & PCIM_MFDEV) == PCIM_MFDEV); +} + +static inline bool is_pci_cfg_bridge(uint8_t header_type) +{ + return ((header_type & PCIM_HDRTYPE) == PCIM_HDRTYPE_BRIDGE); +} + #endif /* PCI_H_ */