8 #define MAX_PCI_DEVICES 32
9 #define MAX_PCI_BUSES 256
10 #define LINUX_KERNEL_MODULE_SIZE 64
11 #define PCI_VENDOR_NAME_SIZE 256
12 #define PCI_PRODUCT_NAME_SIZE 256
13 #define PCI_CLASS_NAME_SIZE 256
14 #define MAX_KERNEL_MODULES_PER_PCI_DEVICE 10
15 #define MAX_PCI_CLASSES 256
17 typedef uint32_t pciaddr_t
;
25 /* a structure for extended pci information */
26 /* XXX: use pointers for these? */
28 char vendor_name
[PCI_VENDOR_NAME_SIZE
];
29 char product_name
[PCI_PRODUCT_NAME_SIZE
];
30 char linux_kernel_module
[LINUX_KERNEL_MODULE_SIZE
]
31 [MAX_KERNEL_MODULES_PER_PCI_DEVICE
];
32 int linux_kernel_module_count
;
33 char class_name
[PCI_CLASS_NAME_SIZE
]; /* The most precise class name */
34 char category_name
[PCI_CLASS_NAME_SIZE
]; /*The general category */
39 /* PCI device (really, function) */
56 struct pci_dev_info
*dev_info
;
57 struct pci_device
*next
;
60 /* PCI device ("slot") structure */
62 struct pci_device
*func
[MAX_PCI_FUNC
];
65 /* PCI bus structure */
67 struct pci_slot
*slot
[MAX_PCI_DEVICES
];
70 /* PCI domain structure */
72 struct pci_bus
*bus
[MAX_PCI_BUSES
];
75 /* Iterate over a PCI domain */
76 #define for_each_pci_func(funcp, domain) \
77 for (int __pci_bus = 0; __pci_bus < MAX_PCI_BUSES; __pci_bus++) \
78 if ((domain)->bus[__pci_bus]) \
79 for (int __pci_slot = 0; __pci_slot < MAX_PCI_DEVICES; __pci_slot++) \
80 if ((domain)->bus[__pci_bus]->slot[__pci_slot]) \
81 for (int __pci_func = 0; __pci_func < MAX_PCI_FUNC; __pci_func++) \
82 if (((funcp) = (domain)->bus[__pci_bus]->slot[__pci_slot]-> \
85 #define for_each_pci_func3(funcp, domain, addr) \
86 for (int __pci_bus = 0; __pci_bus < MAX_PCI_BUSES; __pci_bus++) \
87 if ((domain)->bus[__pci_bus]) \
88 for (int __pci_slot = 0; __pci_slot < MAX_PCI_DEVICES; __pci_slot++) \
89 if ((domain)->bus[__pci_bus]->slot[__pci_slot]) \
90 for (int __pci_func = 0; __pci_func < MAX_PCI_FUNC; __pci_func++) \
91 if (((addr) = pci_mkaddr(__pci_bus, __pci_slot, __pci_func, 0)), \
92 ((funcp) = (domain)->bus[__pci_bus]->slot[__pci_slot]-> \
101 uint8_t rid_min
, rid_max
;
105 static inline pciaddr_t
pci_mkaddr(uint32_t bus
, uint32_t dev
,
106 uint32_t func
, uint32_t reg
)
108 return 0x80000000 | ((bus
& 0xff) << 16) | ((dev
& 0x1f) << 11) |
109 ((func
& 0x07) << 8) | (reg
& 0xff);
112 static inline int pci_bus(pciaddr_t addr
)
114 return (addr
>> 16) & 0xff;
117 static inline int pci_dev(pciaddr_t addr
)
119 return (addr
>> 11) & 0x1f;
122 static inline int pci_func(pciaddr_t addr
)
124 return (addr
>> 8) & 0x07;
127 enum pci_config_type
{
128 PCI_CFG_NONE
= -1, /* badness */
129 PCI_CFG_AUTO
= 0, /* autodetect */
135 enum pci_config_type
pci_set_config_type(enum pci_config_type
);
137 uint8_t pci_readb(pciaddr_t
);
138 uint16_t pci_readw(pciaddr_t
);
139 uint32_t pci_readl(pciaddr_t
);
140 void pci_writeb(uint8_t, pciaddr_t
);
141 void pci_writew(uint16_t, pciaddr_t
);
142 void pci_writel(uint32_t, pciaddr_t
);
144 struct pci_domain
*pci_scan(void);
145 void free_pci_domain(struct pci_domain
*domain
);
146 struct match
*find_pci_device(const struct pci_domain
*pci_domain
,
148 int get_name_from_pci_ids(struct pci_domain
*pci_domain
, char *pciids_path
);
149 int get_module_name_from_pcimap(struct pci_domain
*pci_domain
, char *modules_pcimap_path
);
150 int get_module_name_from_alias(struct pci_domain
*pci_domain
, char *modules_alias_path
);
151 int get_class_name_from_pci_ids(struct pci_domain
*pci_domain
, char *pciids_path
);
152 void gather_additional_pci_config(struct pci_domain
*domain
);
153 #endif /* _SYS_PCI_H */