Rev 4399 | Go to most recent revision | Details | Compare with Previous | Last modification | View Log | RSS feed
Rev | Author | Line No. | Line |
---|---|---|---|
4399 | trochtova | 1 | #ifndef PCI_H |
2 | #define PCI_H |
||
3 | |||
4 | //#include <arch/types.h> |
||
5 | #include <libadt/list.h> |
||
6 | #include <stdio.h> |
||
4438 | trochtova | 7 | #include <stdlib.h> |
4399 | trochtova | 8 | |
9 | struct pci_drv; |
||
10 | struct pci_dev; |
||
11 | struct pci_bus; |
||
12 | struct pci_drv_ops; |
||
13 | |||
14 | typedef struct pci_drv pci_drv_t; |
||
15 | typedef struct pci_dev pci_dev_t; |
||
16 | typedef struct pci_bus pci_bus_t; |
||
17 | typedef struct pci_drv_ops pci_drv_ops_t; |
||
18 | |||
19 | struct pci_drv { |
||
20 | link_t link; |
||
21 | int vendor_id; |
||
22 | int device_id; |
||
23 | pci_drv_ops_t *ops; |
||
24 | }; |
||
25 | |||
26 | struct pci_dev{ |
||
27 | link_t link; |
||
28 | pci_bus_t *bus; |
||
29 | int dev; |
||
30 | int fn; |
||
31 | |||
32 | int vendor_id; |
||
33 | int device_id; |
||
34 | pci_drv_t *driver; |
||
35 | }; |
||
36 | |||
37 | struct pci_drv_ops { |
||
38 | int (*add_device)(pci_dev_t *dev); |
||
39 | |||
40 | }; |
||
41 | |||
42 | struct pci_bus { |
||
43 | link_t link; |
||
44 | int num; |
||
45 | // architecture-specific usage |
||
46 | void *data; |
||
47 | }; |
||
48 | |||
49 | void pci_bus_register(pci_bus_t *bus); |
||
50 | void pci_device_register(pci_dev_t *dev); |
||
51 | void pci_driver_register(pci_drv_t *drv); |
||
52 | |||
53 | void pci_bus_scan(pci_bus_t *bus); |
||
54 | |||
55 | static inline pci_bus_t* pci_alloc_bus() |
||
56 | { |
||
57 | pci_bus_t *bus = (pci_bus_t *)malloc(sizeof(pci_bus_t)); |
||
58 | link_initialize(&bus->link); |
||
59 | bus->num = 0; |
||
60 | bus->data = NULL; |
||
61 | return bus; |
||
62 | } |
||
63 | |||
64 | // arch. spec. initialization of pci bus structure - of its data member |
||
65 | void pci_init_bus_data(pci_bus_t *bus, pci_bus_t *parent); |
||
66 | |||
67 | static inline void pci_init_bus(pci_bus_t *bus, pci_bus_t *parent, int bus_num) |
||
68 | { |
||
69 | bus->num = bus_num; |
||
70 | pci_init_bus_data(bus, parent); |
||
71 | } |
||
72 | |||
73 | static inline void pci_free_bus(pci_bus_t *bus) |
||
74 | { |
||
75 | free(bus); |
||
76 | } |
||
77 | |||
78 | static inline pci_dev_t* pci_alloc_dev() |
||
79 | { |
||
80 | pci_dev_t *dev = (pci_dev_t *)malloc(sizeof(pci_dev_t)); |
||
81 | bzero(dev, sizeof(pci_dev_t)); |
||
82 | link_initialize(&dev->link); |
||
83 | return dev; |
||
84 | } |
||
85 | |||
86 | static inline void pci_init_dev(pci_dev_t *dev, pci_bus_t *bus, int devnum, int fn) |
||
87 | { |
||
88 | dev->bus = bus; |
||
89 | dev->dev = devnum; |
||
90 | dev->fn = fn; |
||
91 | } |
||
92 | |||
93 | static inline void pci_free_dev(pci_dev_t *dev) |
||
94 | { |
||
95 | free(dev); |
||
96 | } |
||
97 | |||
98 | #endif |