Skip to content

Commit 0b7bcd6

Browse files
amerritt-intelwenlingz
authored andcommitted
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. Tracked-On: #4134 Signed-off-by: Alexander Merritt <alex.merritt@intel.com> Signed-off-by: Sainath Grandhi <sainath.grandhi@intel.com> Reviewed-by: Eddie Dong <eddie.dong@intel.com> Reviewed-by: Jason Chen CJ <jason.cj.chen@intel.com>
1 parent 9af4a62 commit 0b7bcd6

File tree

1 file changed

+31
-0
lines changed
  • hypervisor/include/hw

1 file changed

+31
-0
lines changed

hypervisor/include/hw/pci.h

Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -236,5 +236,36 @@ void enable_disable_pci_intx(union pci_bdf bdf, bool enable);
236236

237237
void init_pci_pdev_list(void);
238238

239+
static inline bool is_pci_vendor_valid(uint32_t vendor_id)
240+
{
241+
return !((vendor_id == 0xFFFFFFFFU) || (vendor_id == 0U) ||
242+
(vendor_id == 0xFFFF0000U) || (vendor_id == 0xFFFFU));
243+
}
244+
245+
static inline uint32_t read_pci_pdev_cfg_vendor(union pci_bdf pbdf)
246+
{
247+
return pci_pdev_read_cfg(pbdf, PCIR_VENDOR, 2U);
248+
}
249+
250+
static inline uint8_t read_pci_pdev_cfg_headertype(union pci_bdf pbdf)
251+
{
252+
return (uint8_t)pci_pdev_read_cfg(pbdf, PCIR_HDRTYPE, 1U);
253+
}
254+
255+
static inline uint8_t read_pci_pdev_cfg_secbus(union pci_bdf pbdf)
256+
{
257+
return (uint8_t)pci_pdev_read_cfg(pbdf, PCIR_SECBUS_1, 1U);
258+
}
259+
260+
static inline bool is_pci_cfg_multifunction(uint8_t header_type)
261+
{
262+
return ((header_type & PCIM_MFDEV) == PCIM_MFDEV);
263+
}
264+
265+
static inline bool is_pci_cfg_bridge(uint8_t header_type)
266+
{
267+
return ((header_type & PCIM_HDRTYPE) == PCIM_HDRTYPE_BRIDGE);
268+
}
269+
239270

240271
#endif /* PCI_H_ */

0 commit comments

Comments
 (0)