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