VM: simplify slab allocator
[minix.git] / include / ddekit / pci.h
blobdea424dc44c405e942d5bbb0c887a211c10638b8
1 #ifndef _DDEKIT_PCI_H
2 #define _DDEKIT_PCI_H
3 #include <ddekit/ddekit.h>
5 #include <ddekit/types.h>
7 /** \defgroup DDEKit_pci */
9 /** Our version of PCI_ANY_ID */
10 #define DDEKIT_PCI_ANY_ID (~0)
12 /** Copy of L4IO_PCIDEV_RES */
13 #define DDEKIT_PCIDEV_RES 12
15 struct ddekit_pci_dev;
17 /** PCI resource descriptor. Copied from generic_io.
19 * XXX!
21 typedef struct ddekit_pci_resource {
22 unsigned long start;
23 unsigned long end;
24 unsigned long flags;
25 } ddekit_pci_res_t;
27 void ddekit_pci_init(void);
29 int ddekit_pci_get_device(int nr, int *bus, int *slot, int *func);
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);
36 /** Read byte from PCI config space.
38 * \ingroup DDEKit_pci
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
46 * \return 0 success
48 int ddekit_pci_readb(int bus, int slot, int func, int pos,
49 ddekit_uint8_t *val);
51 /** Read word from PCI config space.
53 * \ingroup DDEKit_pci
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
61 * \return 0 success
63 int ddekit_pci_readw(int bus, int slot, int func, int pos,
64 ddekit_uint16_t *val);
66 /** Read dword from PCI config space.
68 * \ingroup DDEKit_pci
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
76 * \return 0 success
78 int ddekit_pci_readl(int bus, int slot, int func, int pos,
79 ddekit_uint32_t *val);
81 /** Write byte to PCI config space.
83 * \ingroup DDEKit_pci
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
91 * \return 0 success
93 int ddekit_pci_writeb(int bus, int slot, int func, int pos,
94 ddekit_uint8_t val);
96 /** Write word to PCI config space.
98 * \ingroup DDEKit_pci
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
106 * \return 0 success
108 int ddekit_pci_writew(int bus, int slot, int func, int pos,
109 ddekit_uint16_t val);
111 /** Write word to PCI config space.
113 * \ingroup DDEKit_pci
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
121 * \return 0 success
123 int ddekit_pci_writel(int bus, int slot, int func, int pos,
124 ddekit_uint32_t val);
126 /** Find a PCI device.
128 * \ingroup DDEKit_pci
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
136 * \retval bus bus number
137 * \retval slot slot number
138 * \retval func function number
140 * \return device a valid PCI device
141 * \return NULL if no device found
143 struct ddekit_pci_dev * ddekit_pci_find_device(int *bus, int *slot, int
144 *func, struct ddekit_pci_dev *start);
146 /** Enable PCI device
147 * \ingroup DDEKit_pci
149 int ddekit_pci_enable_device(struct ddekit_pci_dev *dev);
151 /** Disable PCI device
152 * \ingroup DDEKit_pci
154 int ddekit_pci_disable_device(struct ddekit_pci_dev *dev);
156 /** Enable bus-mastering for device.
157 * \ingroup DDEKit_pci
159 void ddekit_pci_set_master(struct ddekit_pci_dev *dev);
161 /** Get device vendor ID.
162 * \ingroup DDEKit_pci
164 unsigned short ddekit_pci_get_vendor(struct ddekit_pci_dev *dev);
166 /** Get device ID.
167 * \ingroup DDEKit_pci
169 unsigned short ddekit_pci_get_device_id(struct ddekit_pci_dev *dev);
171 /** Get device subvendor ID.
172 * \ingroup DDEKit_pci
174 unsigned short ddekit_pci_get_sub_vendor(struct ddekit_pci_dev *dev);
176 /** Get subdevice ID.
177 * \ingroup DDEKit_pci
179 unsigned short ddekit_pci_get_sub_device(struct ddekit_pci_dev *dev);
181 /** Get device class ID.
182 * \ingroup DDEKit_pci
184 unsigned ddekit_pci_get_dev_class(struct ddekit_pci_dev *dev);
186 /** Get device's IRQ number.
187 * \ingroup DDEKit_pci
189 unsigned long ddekit_pci_get_irq(struct ddekit_pci_dev *dev);
191 /** Get device name.
192 * \ingroup DDEKit_pci
194 char *ddekit_pci_get_name(struct ddekit_pci_dev *dev);
196 /** Get device's slot name.
197 * \ingroup DDEKit_pci
199 char *ddekit_pci_get_slot_name(struct ddekit_pci_dev *dev);
201 /** Get one of the device's resources.
202 * \ingroup DDEKit_pci
204 ddekit_pci_res_t *ddekit_pci_get_resource(struct ddekit_pci_dev *dev,
205 unsigned int idx);
207 int ddekit_pci_irq_enable(int bus, int slot, int func, int pin, int
208 *irq);
210 #endif