File indexing completed on 2025-05-11 08:24:11
0001
0002
0003
0004
0005
0006
0007
0008
0009
0010
0011
0012
0013
0014
0015
0016
0017
0018
0019
0020
0021
0022
0023
0024
0025
0026
0027
0028
0029
0030
0031
0032
0033
0034
0035
0036
0037
0038
0039
0040
0041
0042
0043
0044
0045
0046 #ifndef __PCI_BUS_H__
0047 #define __PCI_BUS_H__
0048
0049 #include <drvmgr/drvmgr.h>
0050 #include <pci.h>
0051 #include <pci/access.h>
0052
0053 #ifdef __cplusplus
0054 extern "C" {
0055 #endif
0056
0057
0058 #define DRIVER_PCI_ID(vendor, device) \
0059 DRIVER_ID(DRVMGR_BUS_TYPE_PCI, \
0060 ((((vendor) & 0xffff) << 16) | ((device) & 0xffff)))
0061
0062
0063 #define DRIVER_PCI_CLASS(class) \
0064 DRIVER_ID(DRVMGR_BUS_TYPE_PCI, ((1 << 32) | ((class) & 0xffffff)))
0065
0066
0067 #define DRIVER_PCI_GAISLER_RASTAIO_ID DRIVER_PCI_ID(PCIID_VENDOR_GAISLER, PCIID_DEVICE_GR_RASTA_IO)
0068 #define DRIVER_PCI_GAISLER_RASTATMTC_ID DRIVER_PCI_ID(PCIID_VENDOR_GAISLER, PCIID_DEVICE_GR_RASTA_TMTC)
0069 #define DRIVER_PCI_GAISLER_GR701_ID DRIVER_PCI_ID(PCIID_VENDOR_GAISLER, PCIID_DEVICE_GR_701)
0070 #define DRIVER_PCI_GAISLER_RASTAADCDAC_ID DRIVER_PCI_ID(PCIID_VENDOR_GAISLER, PCIID_DEVICE_GR_RASTA_ADCDAC)
0071 #define DRIVER_PCI_GAISLER_TMTC_1553_ID DRIVER_PCI_ID(PCIID_VENDOR_GAISLER, PCIID_DEVICE_GR_TMTC_1553)
0072 #define DRIVER_PCI_GAISLER_RASTA_SPW_ROUTER_ID DRIVER_PCI_ID(PCIID_VENDOR_GAISLER, PCIID_DEVICE_GR_RASTA_SPW_RTR)
0073 #define DRIVER_PCI_GAISLER_LEON4_N2X_ID DRIVER_PCI_ID(PCIID_VENDOR_GAISLER, PCIID_DEVICE_GR_LEON4_N2X)
0074 #define DRIVER_PCI_GAISLER_CPCI_GR740_ID DRIVER_PCI_ID(PCIID_VENDOR_GAISLER, PCIID_DEVICE_GR_CPCI_GR740)
0075
0076 struct pci_dev_id {
0077 uint16_t vendor;
0078 uint16_t device;
0079 uint16_t subvendor;
0080 uint16_t subdevice;
0081 uint32_t class;
0082 };
0083
0084 struct pci_dev_id_match {
0085 uint16_t vendor;
0086 uint16_t device;
0087 uint16_t subvendor;
0088 uint16_t subdevice;
0089 uint32_t class;
0090 uint32_t class_mask;
0091 };
0092 #define PCIID_DEVVEND(vendor, device) \
0093 {vendor, device, PCI_ID_ANY, PCI_ID_ANY, 0, 0}
0094 #define PCIID_END_TABLE {0, 0, 0, 0, 0, 0}
0095
0096 enum {
0097
0098 PCIDEV_RES_BAR1 = 0,
0099 PCIDEV_RES_BAR2 = 1,
0100 PCIDEV_RES_BAR3 = 2,
0101 PCIDEV_RES_BAR4 = 3,
0102 PCIDEV_RES_BAR5 = 4,
0103 PCIDEV_RES_BAR6 = 5,
0104 PCIDEV_RES_ROM = 6,
0105 };
0106
0107 #define PCIDEV_RES_CNT (PCIDEV_RES_ROM + 1)
0108
0109
0110 struct pcibus_res {
0111 uint32_t address;
0112 uint32_t size;
0113 struct pci_res *res;
0114 };
0115
0116 struct pci_dev_info {
0117 struct pci_dev_id id;
0118 uint8_t rev;
0119 uint8_t irq;
0120 pci_dev_t pcidev;
0121 struct pcibus_res resources[PCIDEV_RES_CNT];
0122 struct pci_dev *pci_device;
0123 };
0124
0125 struct pci_drv_info {
0126 struct drvmgr_drv general;
0127
0128 struct pci_dev_id_match *ids;
0129 };
0130
0131
0132 struct pcibus_regmem_ops {
0133 drvmgr_r8 r8;
0134 drvmgr_r16 r16;
0135 drvmgr_r32 r32;
0136 drvmgr_r64 r64;
0137 drvmgr_w8 w8;
0138 drvmgr_w16 w16;
0139 drvmgr_w32 w32;
0140 drvmgr_w64 w64;
0141 };
0142
0143
0144 struct pcibus_config {
0145 struct drvmgr_map_entry *maps_up;
0146 struct drvmgr_map_entry *maps_down;
0147 };
0148
0149
0150 #define PCI_FUNC_CFG_R8 DRVMGR_RWFUNC(RW_SIZE_1|RW_READ|RW_CFG)
0151 #define PCI_FUNC_CFG_R16 DRVMGR_RWFUNC(RW_SIZE_2|RW_READ|RW_CFG)
0152 #define PCI_FUNC_CFG_R32 DRVMGR_RWFUNC(RW_SIZE_4|RW_READ|RW_CFG)
0153 #define PCI_FUNC_CFG_W8 DRVMGR_RWFUNC(RW_SIZE_1|RW_WRITE|RW_CFG)
0154 #define PCI_FUNC_CFG_W16 DRVMGR_RWFUNC(RW_SIZE_2|RW_WRITE|RW_CFG)
0155 #define PCI_FUNC_CFG_W32 DRVMGR_RWFUNC(RW_SIZE_4|RW_WRITE|RW_CFG)
0156
0157
0158 #define PCI_FUNC_IO_R8 DRVMGR_RWFUNC(RW_SIZE_1|RW_READ|RW_IO)
0159 #define PCI_FUNC_IO_R16 DRVMGR_RWFUNC(RW_SIZE_2|RW_READ|RW_IO)
0160 #define PCI_FUNC_IO_R32 DRVMGR_RWFUNC(RW_SIZE_4|RW_READ|RW_IO)
0161 #define PCI_FUNC_IO_W8 DRVMGR_RWFUNC(RW_SIZE_1|RW_WRITE|RW_IO)
0162 #define PCI_FUNC_IO_W16 DRVMGR_RWFUNC(RW_SIZE_2|RW_WRITE|RW_IO)
0163 #define PCI_FUNC_IO_W32 DRVMGR_RWFUNC(RW_SIZE_4|RW_WRITE|RW_IO)
0164
0165
0166 #define PCI_FUNC_MREG_R8 DRVMGR_RWFUNC(RW_SIZE_1|RW_READ|RW_MEMREG)
0167 #define PCI_FUNC_MREG_R16 DRVMGR_RWFUNC(RW_SIZE_2|RW_READ|RW_MEMREG|RW_LITTLE)
0168 #define PCI_FUNC_MREG_R32 DRVMGR_RWFUNC(RW_SIZE_4|RW_READ|RW_MEMREG|RW_LITTLE)
0169 #define PCI_FUNC_MREG_W8 DRVMGR_RWFUNC(RW_SIZE_1|RW_WRITE|RW_MEMREG)
0170 #define PCI_FUNC_MREG_W16 DRVMGR_RWFUNC(RW_SIZE_2|RW_WRITE|RW_MEMREG|RW_LITTLE)
0171 #define PCI_FUNC_MREG_W32 DRVMGR_RWFUNC(RW_SIZE_4|RW_WRITE|RW_MEMREG|RW_LITTLE)
0172
0173
0174
0175
0176 extern struct drvmgr_bus_res pcibus_drv_resources;
0177
0178
0179 extern int pcibus_register(struct drvmgr_dev *dev, struct pcibus_config *cfg);
0180
0181 #ifdef __cplusplus
0182 }
0183 #endif
0184
0185 #endif