|
@@ -11,9 +11,6 @@
|
11
|
11
|
#define DBG(...)
|
12
|
12
|
#endif
|
13
|
13
|
|
14
|
|
-static struct pci_device current;
|
15
|
|
-static char used_current;
|
16
|
|
-
|
17
|
14
|
/*
|
18
|
15
|
* Fill in parameters (vendor & device ids, class, membase etc.) for a
|
19
|
16
|
* PCI device based on bus & devfn.
|
|
@@ -114,77 +111,76 @@ static void adjust_pci_device ( struct pci_device *pci ) {
|
114
|
111
|
}
|
115
|
112
|
|
116
|
113
|
/*
|
117
|
|
- * Set PCI device to use.
|
118
|
|
- *
|
119
|
|
- * This routine can be called by e.g. the ROM prefix to specify that
|
120
|
|
- * the first device to be tried should be the device on which the ROM
|
121
|
|
- * was physically located.
|
|
114
|
+ * Obtain a struct pci * from a struct dev *
|
122
|
115
|
*
|
|
116
|
+ * If dev has not previously been used for a PCI device scan, blank
|
|
117
|
+ * out dev.pci
|
123
|
118
|
*/
|
124
|
|
-void set_pci_device ( uint16_t busdevfn ) {
|
125
|
|
- current.busdevfn = busdevfn;
|
126
|
|
- used_current = 0;
|
|
119
|
+struct pci_device * pci_device ( struct dev *dev ) {
|
|
120
|
+ struct pci_device *pci = &dev->pci;
|
|
121
|
+
|
|
122
|
+ if ( dev->devid.bus_type != PCI_BUS_TYPE ) {
|
|
123
|
+ memset ( pci, 0, sizeof ( *pci ) );
|
|
124
|
+ }
|
|
125
|
+ pci->dev = dev;
|
|
126
|
+ return pci;
|
127
|
127
|
}
|
128
|
128
|
|
129
|
129
|
/*
|
130
|
130
|
* Find a PCI device matching the specified driver
|
131
|
131
|
*
|
132
|
|
- * If "dev" is non-NULL, the struct dev will be filled in with any
|
133
|
|
- * relevant information.
|
134
|
|
- *
|
135
|
132
|
*/
|
136
|
|
-struct pci_device * find_pci_device ( struct pci_driver *driver,
|
137
|
|
- struct dev *dev ) {
|
|
133
|
+int find_pci_device ( struct pci_device *pci,
|
|
134
|
+ struct pci_driver *driver ) {
|
138
|
135
|
int i;
|
139
|
136
|
|
140
|
137
|
/* Iterate through all possible PCI bus:dev.fn combinations,
|
141
|
138
|
* starting where we left off.
|
142
|
139
|
*/
|
143
|
|
- for ( ; current.busdevfn <= 0xffff ; current.busdevfn++ ) {
|
|
140
|
+ for ( ; pci->busdevfn <= 0xffff ; pci->busdevfn++ ) {
|
144
|
141
|
/* If we've already used this device, skip it */
|
145
|
|
- if ( used_current ) {
|
146
|
|
- used_current = 0;
|
|
142
|
+ if ( pci->already_tried ) {
|
|
143
|
+ pci->already_tried = 0;
|
147
|
144
|
continue;
|
148
|
145
|
}
|
149
|
146
|
|
150
|
147
|
/* Fill in device parameters, if device present */
|
151
|
|
- if ( ! fill_pci_device ( ¤t ) ) {
|
|
148
|
+ if ( ! fill_pci_device ( pci ) ) {
|
152
|
149
|
continue;
|
153
|
150
|
}
|
154
|
151
|
|
155
|
152
|
/* Fix up PCI device */
|
156
|
|
- adjust_pci_device ( ¤t );
|
|
153
|
+ adjust_pci_device ( pci );
|
157
|
154
|
|
158
|
155
|
/* Fill in dev structure, if present */
|
159
|
|
- if ( dev ) {
|
160
|
|
- dev->name = driver->name;
|
161
|
|
- dev->devid.vendor_id = current.vendor;
|
162
|
|
- dev->devid.device_id = current.dev_id;
|
163
|
|
- dev->devid.bus_type = PCI_BUS_TYPE;
|
|
156
|
+ if ( pci->dev ) {
|
|
157
|
+ pci->dev->name = driver->name;
|
|
158
|
+ pci->dev->devid.vendor_id = pci->vendor;
|
|
159
|
+ pci->dev->devid.device_id = pci->dev_id;
|
164
|
160
|
}
|
165
|
161
|
|
166
|
162
|
/* If driver has a class, and class matches, use it */
|
167
|
163
|
if ( driver->class &&
|
168
|
|
- ( driver->class == current.class ) ) {
|
|
164
|
+ ( driver->class == pci->class ) ) {
|
169
|
165
|
DBG ( "Driver %s matches class %hx\n",
|
170
|
166
|
driver->name, driver->class );
|
171
|
|
- used_current = 1;
|
172
|
|
- return ¤t;
|
|
167
|
+ pci->already_tried = 1;
|
|
168
|
+ return 1;
|
173
|
169
|
}
|
174
|
170
|
|
175
|
171
|
/* If any of driver's IDs match, use it */
|
176
|
172
|
for ( i = 0 ; i < driver->id_count; i++ ) {
|
177
|
173
|
struct pci_id *id = &driver->ids[i];
|
178
|
174
|
|
179
|
|
- if ( ( current.vendor == id->vendor ) &&
|
180
|
|
- ( current.dev_id == id->dev_id ) ) {
|
|
175
|
+ if ( ( pci->vendor == id->vendor ) &&
|
|
176
|
+ ( pci->dev_id == id->dev_id ) ) {
|
181
|
177
|
DBG ( "Device %s (driver %s) matches "
|
182
|
178
|
"ID %hx:%hx\n", id->name, driver->name,
|
183
|
179
|
id->vendor, id->dev_id );
|
184
|
|
- if ( dev )
|
185
|
|
- dev->name = id->name;
|
186
|
|
- used_current = 1;
|
187
|
|
- return ¤t;
|
|
180
|
+ if ( pci->dev )
|
|
181
|
+ pci->dev->name = id->name;
|
|
182
|
+ pci->already_tried = 1;
|
|
183
|
+ return 1;
|
188
|
184
|
}
|
189
|
185
|
}
|
190
|
186
|
|
|
@@ -192,8 +188,7 @@ struct pci_device * find_pci_device ( struct pci_driver *driver,
|
192
|
188
|
}
|
193
|
189
|
|
194
|
190
|
/* No device found */
|
195
|
|
- memset ( ¤t, 0, sizeof ( current ) );
|
196
|
|
- return NULL;
|
|
191
|
+ return 0;
|
197
|
192
|
}
|
198
|
193
|
|
199
|
194
|
/*
|