diff options
Diffstat (limited to 'src/include')
-rw-r--r-- | src/include/device/pci.h | 15 | ||||
-rw-r--r-- | src/include/device/pci_ops.h | 32 | ||||
-rw-r--r-- | src/include/device/pci_type.h | 11 |
3 files changed, 39 insertions, 19 deletions
diff --git a/src/include/device/pci.h b/src/include/device/pci.h index 2cfcb60244..14c4693459 100644 --- a/src/include/device/pci.h +++ b/src/include/device/pci.h @@ -35,14 +35,17 @@ struct pci_operations { /* Common pci bus operations */ struct pci_bus_operations { - uint8_t (*read8)(const struct device *dev, uint16_t reg); - uint16_t (*read16)(const struct device *dev, uint16_t reg); - uint32_t (*read32)(const struct device *dev, uint16_t reg); - void (*write8)(const struct device *dev, uint16_t reg, uint8_t val); - void (*write16)(const struct device *dev, uint16_t reg, uint16_t val); - void (*write32)(const struct device *dev, uint16_t reg, uint32_t val); + uint8_t (*read8)(pci_devfn_t dev, uint16_t reg); + uint16_t (*read16)(pci_devfn_t dev, uint16_t reg); + uint32_t (*read32)(pci_devfn_t dev, uint16_t reg); + void (*write8)(pci_devfn_t dev, uint16_t reg, uint8_t val); + void (*write16)(pci_devfn_t dev, uint16_t reg, uint16_t val); + void (*write32)(pci_devfn_t dev, uint16_t reg, uint32_t val); }; +// FIXME: Needs complete pci_bus_operations +#include <device/pci_ops.h> + struct pci_driver { const struct device_operations *ops; unsigned short vendor; diff --git a/src/include/device/pci_ops.h b/src/include/device/pci_ops.h index 82f96584de..bb77754cb6 100644 --- a/src/include/device/pci_ops.h +++ b/src/include/device/pci_ops.h @@ -48,52 +48,58 @@ static __always_inline const struct pci_bus_operations *pci_bus_ops(void) void __noreturn pcidev_die(void); -static __always_inline void pcidev_assert(const struct device *dev) +static __always_inline pci_devfn_t pcidev_bdf(const struct device *dev) +{ + return (dev->path.pci.devfn << 12) | (dev->bus->secondary << 20); +} + +static __always_inline pci_devfn_t pcidev_assert(const struct device *dev) { if (!dev) pcidev_die(); + return pcidev_bdf(dev); } static __always_inline u8 pci_read_config8(const struct device *dev, u16 reg) { - pcidev_assert(dev); - return pci_bus_ops()->read8(dev, reg); + pci_devfn_t bdf = PCI_BDF(dev); + return pci_bus_ops()->read8(bdf, reg); } static __always_inline u16 pci_read_config16(const struct device *dev, u16 reg) { - pcidev_assert(dev); - return pci_bus_ops()->read16(dev, reg); + pci_devfn_t bdf = PCI_BDF(dev); + return pci_bus_ops()->read16(bdf, reg); } static __always_inline u32 pci_read_config32(const struct device *dev, u16 reg) { - pcidev_assert(dev); - return pci_bus_ops()->read32(dev, reg); + pci_devfn_t bdf = PCI_BDF(dev); + return pci_bus_ops()->read32(bdf, reg); } static __always_inline void pci_write_config8(const struct device *dev, u16 reg, u8 val) { - pcidev_assert(dev); - pci_bus_ops()->write8(dev, reg, val); + pci_devfn_t bdf = PCI_BDF(dev); + pci_bus_ops()->write8(bdf, reg, val); } static __always_inline void pci_write_config16(const struct device *dev, u16 reg, u16 val) { - pcidev_assert(dev); - pci_bus_ops()->write16(dev, reg, val); + pci_devfn_t bdf = PCI_BDF(dev); + pci_bus_ops()->write16(bdf, reg, val); } static __always_inline void pci_write_config32(const struct device *dev, u16 reg, u32 val) { - pcidev_assert(dev); - pci_bus_ops()->write32(dev, reg, val); + pci_devfn_t bdf = PCI_BDF(dev); + pci_bus_ops()->write32(bdf, reg, val); } #endif diff --git a/src/include/device/pci_type.h b/src/include/device/pci_type.h index 3f72c5f167..27d35589cc 100644 --- a/src/include/device/pci_type.h +++ b/src/include/device/pci_type.h @@ -25,4 +25,15 @@ typedef u32 pci_devfn_t; #define PCI_DEV_INVALID (0xffffffffU) +#if 1 +/* FIXME: For most of the time in ramstage, we get valid device pointer + * from calling the driver entry points. The assert should only be used + * with searches like pcidev_behind(), and only if caller does not make + * the check themselves. + */ +#define PCI_BDF(dev) pcidev_assert((dev)) +#else +#define PCI_BDF(dev) pcidev_bdf((dev)) +#endif + #endif /* DEVICE_PCI_TYPE_H */ |