root / lab4 / .minix-src / include / ddekit / pci.h @ 14
History | View | Annotate | Download (4.91 KB)
1 | 13 | up20180614 | #ifndef _DDEKIT_PCI_H
|
---|---|---|---|
2 | #define _DDEKIT_PCI_H
|
||
3 | #include <ddekit/ddekit.h> |
||
4 | |||
5 | #include <ddekit/types.h> |
||
6 | |||
7 | /** \defgroup DDEKit_pci */
|
||
8 | |||
9 | /** Our version of PCI_ANY_ID */
|
||
10 | #define DDEKIT_PCI_ANY_ID (~0) |
||
11 | |||
12 | /** Copy of L4IO_PCIDEV_RES */
|
||
13 | #define DDEKIT_PCIDEV_RES 12 |
||
14 | |||
15 | struct ddekit_pci_dev;
|
||
16 | |||
17 | /** PCI resource descriptor. Copied from generic_io.
|
||
18 | *
|
||
19 | * XXX!
|
||
20 | */
|
||
21 | typedef struct ddekit_pci_resource { |
||
22 | unsigned long start; |
||
23 | unsigned long end; |
||
24 | unsigned long flags; |
||
25 | } ddekit_pci_res_t; |
||
26 | |||
27 | void ddekit_pci_init(void); |
||
28 | |||
29 | int ddekit_pci_get_device(int nr, int *bus, int *slot, int *func); |
||
30 | |||
31 | int ddekit_pci_read(int bus, int slot, int func, int pos, int len, |
||
32 | ddekit_uint32_t *val); |
||
33 | int ddekit_pci_write(int bus, int slot, int func, int pos, int len, |
||
34 | ddekit_uint32_t val); |
||
35 | |||
36 | /** Read byte from PCI config space.
|
||
37 | *
|
||
38 | * \ingroup DDEKit_pci
|
||
39 | *
|
||
40 | * \param bus bus ID
|
||
41 | * \param slot slot #
|
||
42 | * \param func function #
|
||
43 | * \param pos offset in config space
|
||
44 | * \retval val read value
|
||
45 | *
|
||
46 | * \return 0 success
|
||
47 | */
|
||
48 | int ddekit_pci_readb(int bus, int slot, int func, int pos, |
||
49 | ddekit_uint8_t *val); |
||
50 | |||
51 | /** Read word from PCI config space.
|
||
52 | *
|
||
53 | * \ingroup DDEKit_pci
|
||
54 | *
|
||
55 | * \param bus bus ID
|
||
56 | * \param slot slot #
|
||
57 | * \param func function #
|
||
58 | * \param pos offset in config space
|
||
59 | * \retval val read value
|
||
60 | *
|
||
61 | * \return 0 success
|
||
62 | */
|
||
63 | int ddekit_pci_readw(int bus, int slot, int func, int pos, |
||
64 | ddekit_uint16_t *val); |
||
65 | |||
66 | /** Read dword from PCI config space.
|
||
67 | *
|
||
68 | * \ingroup DDEKit_pci
|
||
69 | *
|
||
70 | * \param bus bus ID
|
||
71 | * \param slot slot #
|
||
72 | * \param func function #
|
||
73 | * \param pos offset in config space
|
||
74 | * \retval val read value
|
||
75 | *
|
||
76 | * \return 0 success
|
||
77 | */
|
||
78 | int ddekit_pci_readl(int bus, int slot, int func, int pos, |
||
79 | ddekit_uint32_t *val); |
||
80 | |||
81 | /** Write byte to PCI config space.
|
||
82 | *
|
||
83 | * \ingroup DDEKit_pci
|
||
84 | *
|
||
85 | * \param bus bus ID
|
||
86 | * \param slot slot #
|
||
87 | * \param func function #
|
||
88 | * \param pos offset in config space
|
||
89 | * \retval val value to write
|
||
90 | *
|
||
91 | * \return 0 success
|
||
92 | */
|
||
93 | int ddekit_pci_writeb(int bus, int slot, int func, int pos, |
||
94 | ddekit_uint8_t val); |
||
95 | |||
96 | /** Write word to PCI config space.
|
||
97 | *
|
||
98 | * \ingroup DDEKit_pci
|
||
99 | *
|
||
100 | * \param bus bus ID
|
||
101 | * \param slot slot #
|
||
102 | * \param func function #
|
||
103 | * \param pos offset in config space
|
||
104 | * \retval val value to write
|
||
105 | *
|
||
106 | * \return 0 success
|
||
107 | */
|
||
108 | int ddekit_pci_writew(int bus, int slot, int func, int pos, |
||
109 | ddekit_uint16_t val); |
||
110 | |||
111 | /** Write word to PCI config space.
|
||
112 | *
|
||
113 | * \ingroup DDEKit_pci
|
||
114 | *
|
||
115 | * \param bus bus ID
|
||
116 | * \param slot slot #
|
||
117 | * \param func function #
|
||
118 | * \param pos offset in config space
|
||
119 | * \retval val value to write
|
||
120 | *
|
||
121 | * \return 0 success
|
||
122 | */
|
||
123 | int ddekit_pci_writel(int bus, int slot, int func, int pos, |
||
124 | ddekit_uint32_t val); |
||
125 | |||
126 | /** Find a PCI device.
|
||
127 | *
|
||
128 | * \ingroup DDEKit_pci
|
||
129 | *
|
||
130 | * \param bus pointer to bus number or \ref DDEKIT_PCI_ANY_ID
|
||
131 | * \param slot pointer to slot number (devfn >> DEVFN_SLOTSHIFT) or \ref DDEKIT_PCI_ANY_ID
|
||
132 | * \param func pointer to func number (devfc & DEVFN_FUNCMASK) or \ref DDEKIT_PCI_ANY_ID
|
||
133 | * \param start search device list only behind this device (excluding it!), NULL
|
||
134 | * searches whole device list
|
||
135 | *
|
||
136 | * \retval bus bus number
|
||
137 | * \retval slot slot number
|
||
138 | * \retval func function number
|
||
139 | *
|
||
140 | * \return device a valid PCI device
|
||
141 | * \return NULL if no device found
|
||
142 | */
|
||
143 | struct ddekit_pci_dev * ddekit_pci_find_device(int *bus, int *slot, int |
||
144 | *func, struct ddekit_pci_dev *start);
|
||
145 | |||
146 | /** Enable PCI device
|
||
147 | * \ingroup DDEKit_pci
|
||
148 | */
|
||
149 | int ddekit_pci_enable_device(struct ddekit_pci_dev *dev); |
||
150 | |||
151 | /** Disable PCI device
|
||
152 | * \ingroup DDEKit_pci
|
||
153 | */
|
||
154 | int ddekit_pci_disable_device(struct ddekit_pci_dev *dev); |
||
155 | |||
156 | /** Enable bus-mastering for device.
|
||
157 | * \ingroup DDEKit_pci
|
||
158 | */
|
||
159 | void ddekit_pci_set_master(struct ddekit_pci_dev *dev); |
||
160 | |||
161 | /** Get device vendor ID.
|
||
162 | * \ingroup DDEKit_pci
|
||
163 | */
|
||
164 | unsigned short ddekit_pci_get_vendor(struct ddekit_pci_dev *dev); |
||
165 | |||
166 | /** Get device ID.
|
||
167 | * \ingroup DDEKit_pci
|
||
168 | */
|
||
169 | unsigned short ddekit_pci_get_device_id(struct ddekit_pci_dev *dev); |
||
170 | |||
171 | /** Get device subvendor ID.
|
||
172 | * \ingroup DDEKit_pci
|
||
173 | */
|
||
174 | unsigned short ddekit_pci_get_sub_vendor(struct ddekit_pci_dev *dev); |
||
175 | |||
176 | /** Get subdevice ID.
|
||
177 | * \ingroup DDEKit_pci
|
||
178 | */
|
||
179 | unsigned short ddekit_pci_get_sub_device(struct ddekit_pci_dev *dev); |
||
180 | |||
181 | /** Get device class ID.
|
||
182 | * \ingroup DDEKit_pci
|
||
183 | */
|
||
184 | unsigned ddekit_pci_get_dev_class(struct ddekit_pci_dev *dev); |
||
185 | |||
186 | /** Get device's IRQ number.
|
||
187 | * \ingroup DDEKit_pci
|
||
188 | */
|
||
189 | unsigned long ddekit_pci_get_irq(struct ddekit_pci_dev *dev); |
||
190 | |||
191 | /** Get device name.
|
||
192 | * \ingroup DDEKit_pci
|
||
193 | */
|
||
194 | char *ddekit_pci_get_name(struct ddekit_pci_dev *dev); |
||
195 | |||
196 | /** Get device's slot name.
|
||
197 | * \ingroup DDEKit_pci
|
||
198 | */
|
||
199 | char *ddekit_pci_get_slot_name(struct ddekit_pci_dev *dev); |
||
200 | |||
201 | /** Get one of the device's resources.
|
||
202 | * \ingroup DDEKit_pci
|
||
203 | */
|
||
204 | ddekit_pci_res_t *ddekit_pci_get_resource(struct ddekit_pci_dev *dev,
|
||
205 | unsigned int idx); |
||
206 | |||
207 | int ddekit_pci_irq_enable(int bus, int slot, int func, int pin, int |
||
208 | *irq); |
||
209 | |||
210 | #endif |