a66ac76f14718aaa8ac6bf954399509040e14492
[pintos-anon] / src / devices / pci.h
1 #ifndef DEVICES_PCI_H
2 #define DEVICES_PCI_H
3
4 #include "devices/resource.h"
5 #include "lib/kernel/list.h"
6
7 #define PCI_BAD_DEVICE 0xffff
8
9 /* PCI-to-PCI bridge related numbers */
10 #define PCI_BRIDGE_BASE_CLASS 0x06
11 #define PCI_BRIDGE_SUB_CLASS 0x04
12 #define PCI_BRIDGE_REG_SBUS 0x19
13 #define PCI_BRIDGE_HEADER_TYPE 0x01
14
15 /* Locations of registers in the configuration space */
16 #define PCI_REG_CLASS_INTERFACE 0x09
17 #define PCI_REG_CLASS_SUB 0x0a
18 #define PCI_REG_CLASS_BASE 0x0b
19 #define PCI_REG_HEADER_TYPE 0x0e
20 #define PCI_REGNUM_BASE_ADDRESS 4
21
22 /* Base address related numbers */
23 #define PCI_NUM_BARS 6
24 #define PCI_BAR_TYPE_MASK 0x1
25 #define PCI_BAR_TYPE_MEM 0x0
26 #define PCI_BAR_TYPE_IO 0x1
27 #define PCI_BAR_MASK_MEM 0xfffffff0
28 #define PCI_BAR_MASK_IO 0xfffffffc
29
30 struct pci_dev 
31 {
32   struct list_elem elem;
33
34   /* <Bus, Device, Function> logically identify a unique PCI device */
35   uint8_t bus_id;
36   uint8_t devfn;
37
38   /* Vendor and Device ID */
39   uint16_t ven_id;
40   uint16_t dev_id;
41
42   /* Class code */
43   uint8_t base_class;
44   uint8_t sub_class;
45   uint8_t interface;
46
47   /* Resource space */
48   struct resource resources[PCI_NUM_BARS];
49 };
50
51 void pci_init (void);
52 void pci_dump (void);
53
54 #endif /* devices/pci.h */