Browse Source

Restructured PCI subsystem to fit the new device model.

Generic PCI code now handles 64-bit BARs correctly when setting
"membase"; drivers should need to call pci_bar_start() only if they want
to use BARs other than the first memory or I/O BAR.

Split rarely-used PCI functions out into pciextra.c.

Core PCI code is now 662 bytes (down from 1308 bytes in Etherboot 5.4).
284 bytes of this saving comes from the pci/pciextra split.

Cosmetic changes to lots of drivers (e.g. vendor_id->vendor in order to
match the names used in Linux).
tags/v0.9.3
Michael Brown 18 years ago
parent
commit
15ee09ed10

+ 6
- 4
src/arch/i386/core/pci_io.c View File

@@ -21,8 +21,9 @@
21 21
 /* Macros for direct PCI access */
22 22
 #define CONFIG_ADDRESS	0xcf8
23 23
 #define CONFIG_DATA	0xcfc
24
-#define CONFIG_CMD( pci, where ) \
25
-	( 0x80000000 | (pci->busdevfn << 8) | (where & ~3) )
24
+#define CONFIG_CMD( pci, where )					\
25
+	( 0x80000000 | ( pci->bus << 16 ) | ( pci->devfn << 8 ) |	\
26
+	  ( where & ~3 ) )
26 27
 
27 28
 /* Signatures for PCI BIOS */
28 29
 #define BIOS_SIG(a,b,c,d)	( ( a<<0 ) + ( b<<8 ) + ( c<<16 ) + ( d<<24 ) )
@@ -343,8 +344,9 @@ INIT_FN ( INIT_PCIBIOS, find_pcibios32, NULL, NULL );
343 344
 			    "=S" ( discard_S ), "=D" ( discard_D )	\
344 345
 			  : "a" ( ( PCIBIOS_PCI_FUNCTION_ID << 8 )	\
345 346
 				  + command ),			       	\
346
-			    "b" ( pci->busdevfn ), "c" ( value ),	\
347
-			    "D" ( where ), "S" ( pcibios32_entry )	\
347
+			    "b" ( ( pci->bus << 8 ) | pci->devfn ),	\
348
+			    "c" ( value ), "D" ( where ),		\
349
+			    "S" ( pcibios32_entry )			\
348 350
 			  : "edx", "ebp" );				\
349 351
 									\
350 352
 		( ret >> 8 );						\

+ 0
- 28
src/arch/i386/prefix/select_pci.c View File

@@ -1,28 +0,0 @@
1
-#include "dev.h"
2
-#include <gpxe/pci.h>
3
-#include "registers.h"
4
-
5
-/*
6
- * Register a device as the default PCI boot device.  This code is
7
- * called by the PCI ROM prefix.
8
- *
9
- * Do not move this code to drivers/bus/pci.c, because it is
10
- * i386-specific, and don't merge it with select_isapnp.c, because
11
- * that would cause linker symbol pollution.
12
- *
13
- */
14
-void i386_select_pci_device ( struct i386_all_regs *ix86 ) {
15
-	/*
16
-	 * PCI BIOS passes busdevfn in %ax
17
-	 *
18
-	 */
19
-	union {
20
-		struct bus_loc bus_loc;
21
-		struct pci_loc pci_loc;
22
-	} u;
23
-	
24
-	/* Select PCI bus and specified busdevfn as first boot device */
25
-	memset ( &u, 0, sizeof ( u ) );
26
-	u.pci_loc.busdevfn = ix86->regs.ax;
27
-	select_device ( &dev, &pci_driver, &u.bus_loc );
28
-}

+ 1
- 1
src/core/btext.c View File

@@ -408,7 +408,7 @@ static void btext_init(void)
408 408
 
409 409
     #warning "pci_find_device_x no longer exists; use find_pci_device instead"
410 410
     /*    pci_find_device_x(0x1002, 0x4752, 0, &dev); */
411
-    if(dev.vendor_id==0) return; // no fb
411
+    if(dev.vendor==0) return; // no fb
412 412
 
413 413
     frame_buffer = (uint32_t)dev.membase;
414 414
 #else

+ 270
- 298
src/drivers/bus/pci.c View File

@@ -1,367 +1,339 @@
1
-#include "stdint.h"
2
-#include "string.h"
3
-#include "console.h"
4
-#include "nic.h"
5
-#include <gpxe/pci.h>
6
-
7 1
 /*
8
- * pci_io.c may know how many buses we have, in which case it can
9
- * overwrite this value.
2
+ * Copyright (C) 2006 Michael Brown <mbrown@fensystems.co.uk>.
10 3
  *
11
- */
12
-unsigned int pci_max_bus = 0xff;
13
-
14
-/*
15
- * Increment a bus_loc structure to the next possible PCI location.
16
- * Leave the structure zeroed and return 0 if there are no more valid
17
- * locations.
4
+ * Based in part on pci.c from Etherboot 5.4, by Ken Yap and David
5
+ * Munro, in turn based on the Linux kernel's PCI implementation.
6
+ *
7
+ * This program is free software; you can redistribute it and/or
8
+ * modify it under the terms of the GNU General Public License as
9
+ * published by the Free Software Foundation; either version 2 of the
10
+ * License, or any later version.
18 11
  *
12
+ * This program is distributed in the hope that it will be useful, but
13
+ * WITHOUT ANY WARRANTY; without even the implied warranty of
14
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
15
+ * General Public License for more details.
16
+ *
17
+ * You should have received a copy of the GNU General Public License
18
+ * along with this program; if not, write to the Free Software
19
+ * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
19 20
  */
20
-static int pci_next_location ( struct bus_loc *bus_loc ) {
21
-	struct pci_loc *pci_loc = ( struct pci_loc * ) bus_loc;
22
-	
23
-	/*
24
-	 * Ensure that there is sufficient space in the shared bus
25
-	 * structures for a struct pci_loc and a struct
26
-	 * pci_dev, as mandated by bus.h.
27
-	 *
28
-	 */
29
-	BUS_LOC_CHECK ( struct pci_loc );
30
-	BUS_DEV_CHECK ( struct pci_device );
31 21
 
32
-	return ( ++pci_loc->busdevfn );
33
-}
22
+#include <stdint.h>
23
+#include <string.h>
24
+#include <errno.h>
25
+#include <malloc.h>
26
+#include <gpxe/tables.h>
27
+#include <gpxe/device.h>
28
+#include <gpxe/pci.h>
34 29
 
35
-/*
36
- * Fill in parameters (vendor & device ids, class, membase etc.) for a
37
- * PCI device based on bus & devfn.
30
+/** @file
38 31
  *
39
- * Returns 1 if a device was found, 0 for no device present.
32
+ * PCI bus
40 33
  *
41 34
  */
42
-static int pci_fill_device ( struct bus_dev *bus_dev,
43
-			     struct bus_loc *bus_loc ) {
44
-	struct pci_loc *pci_loc = ( struct pci_loc * ) bus_loc;
45
-	struct pci_device *pci = ( struct pci_device * ) bus_dev;
46
-	uint16_t busdevfn = pci_loc->busdevfn;
47
-	static struct {
48
-		uint16_t busdevfn0;
49
-		int is_present;
50
-	} cache = { 0, 1 };
51
-	uint32_t l;
52
-	int reg;
53 35
 
54
-	/* Store busdevfn in struct pci_device and set default values */
55
-	pci->busdevfn = busdevfn;
56
-	pci->name = "?";
36
+static struct pci_driver pci_drivers[0] __table_start ( pci_drivers );
37
+static struct pci_driver pci_drivers_end[0] __table_end ( pci_drivers );
57 38
 
58
-	/* Check bus is within range */
59
-	if ( PCI_BUS ( busdevfn ) > pci_max_bus ) {
60
-		return 0;
61
-	}
39
+static void pcibus_remove ( struct root_device *rootdev );
62 40
 
63
-	/* Check to see if we've cached the result that this is a
64
-	 * non-zero function on a non-existent card.  This is done to
65
-	 * increase scan speed by a factor of 8.
66
-	 */
67
-	if ( ( PCI_FUNC ( busdevfn ) != 0 ) &&
68
-	     ( PCI_FN0 ( busdevfn ) == cache.busdevfn0 ) &&
69
-	     ( ! cache.is_present ) ) {
70
-		return 0;
71
-	}
72
-	
73
-	/* Check to see if there's anything physically present.
74
-	 */
75
-	pci_read_config_dword ( pci, PCI_VENDOR_ID, &l );
76
-	/* some broken boards return 0 if a slot is empty: */
77
-	if ( ( l == 0xffffffff ) || ( l == 0x00000000 ) ) {
78
-		if ( PCI_FUNC ( busdevfn ) == 0 ) {
79
-			/* Don't look for subsequent functions if the
80
-			 * card itself is not present.
81
-			 */
82
-			cache.busdevfn0 = busdevfn;
83
-			cache.is_present = 0;
84
-		}
85
-		return 0;
86
-	}
87
-	pci->vendor_id = l & 0xffff;
88
-	pci->device_id = ( l >> 16 ) & 0xffff;
89
-	
90
-	/* Check that we're not a duplicate function on a
91
-	 * non-multifunction device.
92
-	 */
93
-	if ( PCI_FUNC ( busdevfn ) != 0 ) {
94
-		uint8_t header_type;
95
-
96
-		pci->busdevfn &= PCI_FN0 ( busdevfn );
97
-		pci_read_config_byte ( pci, PCI_HEADER_TYPE, &header_type );
98
-		pci->busdevfn = busdevfn;
99
-
100
-		if ( ! ( header_type & 0x80 ) ) {
101
-			return 0;
102
-		}
103
-	}
104
-	
105
-	/* Get device class */
106
-	pci_read_config_word ( pci, PCI_SUBCLASS_CODE, &pci->class );
107
-
108
-	/* Get revision */
109
-	pci_read_config_byte ( pci, PCI_REVISION, &pci->revision );
41
+/**
42
+ * Maximum PCI bus number
43
+ *
44
+ * Architecture-specific code may know how many buses we have, in
45
+ * which case it can overwrite this value.
46
+ *
47
+ */
48
+unsigned int pci_max_bus = 0xff;
110 49
 
111
-	/* Get the "membase" */
112
-	pci_read_config_dword ( pci, PCI_BASE_ADDRESS_1, &pci->membase );
113
-				
114
-	/* Get the "ioaddr" */
115
-	pci->ioaddr = 0;
116
-	for ( reg = PCI_BASE_ADDRESS_0; reg <= PCI_BASE_ADDRESS_5; reg += 4 ) {
117
-		pci_read_config_dword ( pci, reg, &pci->ioaddr );
118
-		if ( pci->ioaddr & PCI_BASE_ADDRESS_SPACE_IO ) {
119
-			pci->ioaddr &= PCI_BASE_ADDRESS_IO_MASK;
120
-			if ( pci->ioaddr ) {
121
-				break;
50
+/**
51
+ * Read PCI BAR
52
+ *
53
+ * @v pci		PCI device
54
+ * @v reg		PCI register number
55
+ * @ret bar		Base address register
56
+ *
57
+ * Reads the specified PCI base address register, including the flags
58
+ * portion.  64-bit BARs will be handled automatically.  If the value
59
+ * of the 64-bit BAR exceeds the size of an unsigned long (i.e. if the
60
+ * high dword is non-zero on a 32-bit platform), then the value
61
+ * returned will be zero plus the flags for a 64-bit BAR.  Unreachable
62
+ * 64-bit BARs are therefore returned as uninitialised 64-bit BARs.
63
+ */
64
+static unsigned long pci_bar ( struct pci_device *pci, unsigned int reg ) {
65
+	uint32_t low;
66
+	uint32_t high;
67
+
68
+	pci_read_config_dword ( pci, reg, &low );
69
+	if ( ( low & (PCI_BASE_ADDRESS_SPACE|PCI_BASE_ADDRESS_MEM_TYPE_MASK) )
70
+	     == (PCI_BASE_ADDRESS_SPACE_MEMORY|PCI_BASE_ADDRESS_MEM_TYPE_64) ){
71
+		pci_read_config_dword ( pci, reg + 4, &high );
72
+		if ( high ) {
73
+			if ( sizeof ( unsigned long ) > sizeof ( uint32_t ) ) {
74
+				return ( ( ( uint64_t ) high << 32 ) | low );
75
+			} else {
76
+				DBG ( "Unhandled 64-bit BAR %08x%08x\n",
77
+				      high, low );
78
+				return PCI_BASE_ADDRESS_MEM_TYPE_64;
122 79
 			}
123 80
 		}
124
-		pci->ioaddr = 0;
125
-	}
126
-
127
-	/* Get the irq */
128
-	pci_read_config_byte ( pci, PCI_INTERRUPT_PIN, &pci->irq );
129
-	if ( pci->irq ) {
130
-		pci_read_config_byte ( pci, PCI_INTERRUPT_LINE, &pci->irq );
131 81
 	}
132
-
133
-	DBG ( "PCI found device %hhx:%hhx.%d Class %hx: %hx:%hx (rev %hhx)\n",
134
-	      PCI_BUS ( pci->busdevfn ), PCI_DEV ( pci->busdevfn ),
135
-	      PCI_FUNC ( pci->busdevfn ), pci->class, pci->vendor_id,
136
-	      pci->device_id, pci->revision );
137
-
138
-	return 1;
82
+	return low;
139 83
 }
140 84
 
141
-/*
142
- * Test whether or not a driver is capable of driving the device.
85
+/**
86
+ * Find the start of a PCI BAR
87
+ *
88
+ * @v pci		PCI device
89
+ * @v reg		PCI register number
90
+ * @ret start		BAR start address
91
+ *
92
+ * Reads the specified PCI base address register, and returns the
93
+ * address portion of the BAR (i.e. without the flags).
143 94
  *
95
+ * If the address exceeds the size of an unsigned long (i.e. if a
96
+ * 64-bit BAR has a non-zero high dword on a 32-bit machine), the
97
+ * return value will be zero.
144 98
  */
145
-static int pci_check_driver ( struct bus_dev *bus_dev,
146
-			      struct device_driver *device_driver ) {
147
-	struct pci_device *pci = ( struct pci_device * ) bus_dev;
148
-	struct pci_driver *pci_driver
149
-		= ( struct pci_driver * ) device_driver->bus_driver_info;
150
-	unsigned int i;
99
+unsigned long pci_bar_start ( struct pci_device *pci, unsigned int reg ) {
100
+	unsigned long bar;
151 101
 
152
-	/* If driver has a class, and class matches, use it */
153
-	if ( pci_driver->class && 
154
-	     ( pci_driver->class == pci->class ) ) {
155
-		DBG ( "PCI driver %s matches class %hx\n",
156
-		      device_driver->name, pci_driver->class );
157
-		pci->name = device_driver->name;
158
-		return 1;
159
-	}
160
-		
161
-	/* If any of driver's IDs match, use it */
162
-	for ( i = 0 ; i < pci_driver->id_count; i++ ) {
163
-		struct pci_id *id = &pci_driver->ids[i];
164
-		
165
-		if ( ( pci->vendor_id == id->vendor_id ) &&
166
-		     ( pci->device_id == id->device_id ) ) {
167
-			DBG ( "PCI driver %s device %s matches ID %hx:%hx\n",
168
-			      device_driver->name, id->name,
169
-			      id->vendor_id, id->device_id );
170
-			pci->name = id->name;
171
-			return 1;
172
-		}
102
+	bar = pci_bar ( pci, reg );
103
+	if ( (bar & PCI_BASE_ADDRESS_SPACE) == PCI_BASE_ADDRESS_SPACE_MEMORY ){
104
+		return ( bar & PCI_BASE_ADDRESS_MEM_MASK );
105
+	} else {
106
+		return ( bar & PCI_BASE_ADDRESS_IO_MASK );
173 107
 	}
174
-
175
-	return 0;
176 108
 }
177 109
 
178
-/*
179
- * Describe a PCI device
110
+/**
111
+ * Read membase and ioaddr for a PCI device
180 112
  *
113
+ * @v pci		PCI device
114
+ *
115
+ * This scans through all PCI BARs on the specified device.  The first
116
+ * valid memory BAR is recorded as pci_device::membase, and the first
117
+ * valid IO BAR is recorded as pci_device::ioaddr.
118
+ *
119
+ * 64-bit BARs are handled automatically.  On a 32-bit platform, if a
120
+ * 64-bit BAR has a non-zero high dword, it will be regarded as
121
+ * invalid.
181 122
  */
182
-static char * pci_describe_device ( struct bus_dev *bus_dev ) {
183
-	struct pci_device *pci = ( struct pci_device * ) bus_dev;
184
-	static char pci_description[] = "PCI 00:00.0";
123
+static void pci_read_bases ( struct pci_device *pci ) {
124
+	unsigned long bar;
125
+	int reg;
185 126
 
186
-	sprintf ( pci_description + 4, "%hhx:%hhx.%d",
187
-		  PCI_BUS ( pci->busdevfn ), PCI_DEV ( pci->busdevfn ),
188
-		  PCI_FUNC ( pci->busdevfn ) );
189
-	return pci_description;
127
+	for ( reg = PCI_BASE_ADDRESS_0; reg <= PCI_BASE_ADDRESS_5; reg += 4 ) {
128
+		bar = pci_bar ( pci, reg );
129
+		if ( bar & PCI_BASE_ADDRESS_SPACE_IO ) {
130
+			if ( ! pci->ioaddr )
131
+				pci->ioaddr = 
132
+					( bar & PCI_BASE_ADDRESS_IO_MASK );
133
+		} else {
134
+			if ( ! pci->membase )
135
+				pci->membase =
136
+					( bar & PCI_BASE_ADDRESS_MEM_MASK );
137
+			/* Skip next BAR if 64-bit */
138
+			if ( bar & PCI_BASE_ADDRESS_MEM_TYPE_64 )
139
+				reg += 4;
140
+		}
141
+	}
190 142
 }
191 143
 
192
-/*
193
- * Name a PCI device
144
+/**
145
+ * Enable PCI device
194 146
  *
195
- */
196
-static const char * pci_name_device ( struct bus_dev *bus_dev ) {
197
-	struct pci_device *pci = ( struct pci_device * ) bus_dev;
198
-	
199
-	return pci->name;
200
-}
201
-
202
-/*
203
- * PCI bus operations table
147
+ * @v pci		PCI device
204 148
  *
205
- */
206
-struct bus_driver pci_driver __bus_driver = {
207
-	.name			= "PCI",
208
-	.next_location		= pci_next_location,
209
-	.fill_device		= pci_fill_device,
210
-	.check_driver		= pci_check_driver,
211
-	.describe_device	= pci_describe_device,
212
-	.name_device		= pci_name_device,
213
-};
214
-
215
-/*
216 149
  * Set device to be a busmaster in case BIOS neglected to do so.  Also
217 150
  * adjust PCI latency timer to a reasonable value, 32.
218 151
  */
219 152
 void adjust_pci_device ( struct pci_device *pci ) {
220
-	unsigned short	new_command, pci_command;
221
-	unsigned char	pci_latency;
153
+	unsigned short new_command, pci_command;
154
+	unsigned char pci_latency;
222 155
 
223 156
 	pci_read_config_word ( pci, PCI_COMMAND, &pci_command );
224 157
 	new_command = pci_command | PCI_COMMAND_MASTER | PCI_COMMAND_IO;
225 158
 	if ( pci_command != new_command ) {
226
-		DBG ( "PCI BIOS has not enabled device %hhx:%hhx.%d! "
227
-		      "Updating PCI command %hX->%hX\n",
228
-		      PCI_BUS ( pci->busdevfn ), PCI_DEV ( pci->busdevfn ),
229
-		      PCI_FUNC ( pci->busdevfn ), pci_command, new_command );
159
+		DBG ( "PCI BIOS has not enabled device %02x:%02x.%x! "
160
+		      "Updating PCI command %04x->%04x\n", pci->bus,
161
+		      PCI_SLOT ( pci->devfn ), PCI_FUNC ( pci->devfn ),
162
+		      pci_command, new_command );
230 163
 		pci_write_config_word ( pci, PCI_COMMAND, new_command );
231 164
 	}
165
+
232 166
 	pci_read_config_byte ( pci, PCI_LATENCY_TIMER, &pci_latency);
233 167
 	if ( pci_latency < 32 ) {
234
-		DBG ( "PCI device %hhx:%hhx.%d latency timer is "
235
-		      "unreasonably low at %d. Setting to 32.\n",
236
-		      PCI_BUS ( pci->busdevfn ), PCI_DEV ( pci->busdevfn ),
237
-		      PCI_FUNC ( pci->busdevfn ), pci_latency );
168
+		DBG ( "PCI device %02x:%02x.%x latency timer is unreasonably "
169
+		      "low at %d. Setting to 32.\n", pci->bus,
170
+		      PCI_SLOT ( pci->devfn ), PCI_FUNC ( pci->devfn ),
171
+		      pci_latency );
238 172
 		pci_write_config_byte ( pci, PCI_LATENCY_TIMER, 32);
239 173
 	}
240 174
 }
241 175
 
242
-/*
243
- * Find the start of a pci resource.
176
+/**
177
+ * Register PCI device
178
+ *
179
+ * @v pci		PCI device
180
+ * @ret rc		Return status code
181
+ *
182
+ * Searches for a driver for the PCI device.  If a driver is found,
183
+ * its probe() routine is called, and the device is added to the
184
+ * device hierarchy.
244 185
  */
245
-unsigned long pci_bar_start ( struct pci_device *pci, unsigned int index ) {
246
-	uint32_t lo, hi;
247
-	unsigned long bar;
248
-
249
-	pci_read_config_dword ( pci, index, &lo );
250
-	if ( lo & PCI_BASE_ADDRESS_SPACE_IO ) {
251
-		bar = lo & PCI_BASE_ADDRESS_IO_MASK;
252
-	} else {
253
-		bar = 0;
254
-		if ( ( lo & PCI_BASE_ADDRESS_MEM_TYPE_MASK ) ==
255
-		     PCI_BASE_ADDRESS_MEM_TYPE_64) {
256
-			pci_read_config_dword ( pci, index + 4, &hi );
257
-			if ( hi ) {
258
-#if ULONG_MAX > 0xffffffff
259
-				bar = hi;
260
-				bar <<= 32;
261
-#else
262
-				printf ( "Unhandled 64bit BAR %08x:%08x\n",
263
-					 hi, lo );
264
-				return -1UL;
265
-#endif
186
+static int register_pcidev ( struct pci_device *pci ) {
187
+	struct pci_driver *driver;
188
+	struct pci_device_id *id;
189
+	unsigned int i;
190
+	int rc;
191
+
192
+	DBG ( "Registering PCI device %02x:%02x.%x (%04x:%04x mem %lx "
193
+	      "io %lx irq %d)\n", pci->bus, PCI_SLOT ( pci->devfn ),
194
+	      PCI_FUNC ( pci->devfn ), pci->vendor, pci->device,
195
+	      pci->membase, pci->ioaddr, pci->irq );
196
+
197
+	for ( driver = pci_drivers ; driver < pci_drivers_end ; driver++ ) {
198
+		for ( i = 0 ; i < driver->id_count ; i++ ) {
199
+			id = &driver->ids[i];
200
+			if ( ( id->vendor != pci->vendor ) ||
201
+			     ( id->device != pci->device ) )
202
+				continue;
203
+			pci->driver = driver;
204
+			pci->name = id->name;
205
+			DBG ( "...using driver %s\n", pci->name );
206
+			if ( ( rc = driver->probe ( pci, id ) ) != 0 ) {
207
+				DBG ( "......probe failed\n" );
208
+				continue;
266 209
 			}
210
+			list_add ( &pci->dev.siblings,
211
+				   &pci->dev.parent->children );
212
+			return 0;
267 213
 		}
268
-		bar |= lo & PCI_BASE_ADDRESS_MEM_MASK;
269 214
 	}
270
-	return bar + pci_bus_base ( pci );
271
-}
272
-
273
-/*
274
- * Find the size of a pci resource.
275
- */
276
-unsigned long pci_bar_size ( struct pci_device *pci, unsigned int bar ) {
277
-	uint32_t start, size;
278 215
 
279
-	/* Save the original bar */
280
-	pci_read_config_dword ( pci, bar, &start );
281
-	/* Compute which bits can be set */
282
-	pci_write_config_dword ( pci, bar, ~0 );
283
-	pci_read_config_dword ( pci, bar, &size );
284
-	/* Restore the original size */
285
-	pci_write_config_dword ( pci, bar, start );
286
-	/* Find the significant bits */
287
-	if ( start & PCI_BASE_ADDRESS_SPACE_IO ) {
288
-		size &= PCI_BASE_ADDRESS_IO_MASK;
289
-	} else {
290
-		size &= PCI_BASE_ADDRESS_MEM_MASK;
291
-	}
292
-	/* Find the lowest bit set */
293
-	size = size & ~( size - 1 );
294
-	return size;
216
+	DBG ( "...no driver found\n" );
217
+	return -ENOTTY;
295 218
 }
296 219
 
297 220
 /**
298
- * pci_find_capability - query for devices' capabilities 
299
- * @pci: PCI device to query
300
- * @cap: capability code
301
- *
302
- * Tell if a device supports a given PCI capability.
303
- * Returns the address of the requested capability structure within the
304
- * device's PCI configuration space or 0 in case the device does not
305
- * support it.  Possible values for @cap:
306
- *
307
- *  %PCI_CAP_ID_PM           Power Management 
308
- *
309
- *  %PCI_CAP_ID_AGP          Accelerated Graphics Port 
221
+ * Unregister a PCI device
310 222
  *
311
- *  %PCI_CAP_ID_VPD          Vital Product Data 
223
+ * @v pci		PCI device
312 224
  *
313
- *  %PCI_CAP_ID_SLOTID       Slot Identification 
225
+ * Calls the device's driver's remove() routine, and removes the
226
+ * device from the device hierarchy.
227
+ */
228
+static void unregister_pcidev ( struct pci_device *pci ) {
229
+	pci->driver->remove ( pci );
230
+	list_del ( &pci->dev.siblings );
231
+	DBG ( "Unregistered PCI device %02x:%02x.%x\n", pci->bus,
232
+	      PCI_SLOT ( pci->devfn ), PCI_FUNC ( pci->devfn ) );
233
+}
234
+
235
+/**
236
+ * Probe PCI root bus
314 237
  *
315
- *  %PCI_CAP_ID_MSI          Message Signalled Interrupts
238
+ * @v rootdev		PCI bus root device
316 239
  *
317
- *  %PCI_CAP_ID_CHSWP        CompactPCI HotSwap 
240
+ * Scans the PCI bus for devices and registers all devices it can
241
+ * find.
318 242
  */
319
-int pci_find_capability ( struct pci_device *pci, int cap ) {
320
-	uint16_t status;
321
-	uint8_t pos, id;
322
-	uint8_t hdr_type;
323
-	int ttl = 48;
324
-
325
-	pci_read_config_word ( pci, PCI_STATUS, &status );
326
-	if ( ! ( status & PCI_STATUS_CAP_LIST ) )
327
-		return 0;
243
+static int pcibus_probe ( struct root_device *rootdev ) {
244
+	struct pci_device *pci = NULL;
245
+	unsigned int bus;
246
+	unsigned int devfn;
247
+	uint8_t hdrtype;
248
+	uint32_t tmp;
249
+	int rc;
250
+
251
+	for ( bus = 0 ; bus <= pci_max_bus ; bus++ ) {
252
+		for ( devfn = 0 ; devfn <= 0xff ; devfn++ ) {
253
+
254
+			/* Allocate struct pci_device */
255
+			if ( ! pci )
256
+				pci = malloc ( sizeof ( *pci ) );
257
+			if ( ! pci ) {
258
+				rc = -ENOMEM;
259
+				goto err;
260
+			}
261
+			memset ( pci, 0, sizeof ( *pci ) );
262
+			pci->bus = bus;
263
+			pci->devfn = devfn;
264
+			
265
+			/* Skip all but the first function on
266
+			 * non-multifunction cards
267
+			 */
268
+			if ( PCI_FUNC ( devfn ) == 0 ) {
269
+				pci_read_config_byte ( pci, PCI_HEADER_TYPE,
270
+						       &hdrtype );
271
+			} else if ( ! ( hdrtype & 0x80 ) ) {
272
+					continue;
273
+			}
328 274
 
329
-	pci_read_config_byte ( pci, PCI_HEADER_TYPE, &hdr_type );
330
-	switch ( hdr_type & 0x7F ) {
331
-	case PCI_HEADER_TYPE_NORMAL:
332
-	case PCI_HEADER_TYPE_BRIDGE:
333
-	default:
334
-		pci_read_config_byte ( pci, PCI_CAPABILITY_LIST, &pos );
335
-		break;
336
-	case PCI_HEADER_TYPE_CARDBUS:
337
-		pci_read_config_byte ( pci, PCI_CB_CAPABILITY_LIST, &pos );
338
-		break;
339
-	}
340
-	while ( ttl-- && pos >= 0x40 ) {
341
-		pos &= ~3;
342
-		pci_read_config_byte ( pci, pos + PCI_CAP_LIST_ID, &id );
343
-		DBG ( "PCI Capability: %d\n", id );
344
-		if ( id == 0xff )
345
-			break;
346
-		if ( id == cap )
347
-			return pos;
348
-		pci_read_config_byte ( pci, pos + PCI_CAP_LIST_NEXT, &pos );
275
+			/* Check for physical device presence */
276
+			pci_read_config_dword ( pci, PCI_VENDOR_ID, &tmp );
277
+			if ( ( tmp == 0xffffffff ) || ( tmp == 0 ) )
278
+				continue;
279
+			
280
+			/* Populate struct pci_device */
281
+			pci->vendor = ( tmp & 0xffff );
282
+			pci->device = ( tmp >> 16 );
283
+			pci_read_config_dword ( pci, PCI_REVISION, &tmp );
284
+			pci->class = ( tmp >> 8 );
285
+			pci_read_config_byte ( pci, PCI_INTERRUPT_LINE,
286
+					       &pci->irq );
287
+			pci_read_bases ( pci );
288
+			INIT_LIST_HEAD ( &pci->dev.children );
289
+			pci->dev.parent = &rootdev->dev;
290
+			
291
+			/* Look for a driver */
292
+			if ( register_pcidev ( pci ) == 0 ) {
293
+				/* pcidev registered, we can drop our ref */
294
+				pci = NULL;
295
+			} else {
296
+				/* Not registered; re-use struct pci_device */
297
+			}
298
+		}
349 299
 	}
300
+
301
+	free ( pci );
350 302
 	return 0;
303
+
304
+ err:
305
+	free ( pci );
306
+	pcibus_remove ( rootdev );
307
+	return rc;
351 308
 }
352 309
 
353
-/*
354
- * Fill in a nic structure
310
+/**
311
+ * Remove PCI root bus
355 312
  *
313
+ * @v rootdev		PCI bus root device
356 314
  */
357
-void pci_fill_nic ( struct nic *nic, struct pci_device *pci ) {
315
+static void pcibus_remove ( struct root_device *rootdev ) {
316
+	struct pci_device *pci;
317
+	struct pci_device *tmp;
318
+
319
+	list_for_each_entry_safe ( pci, tmp, &rootdev->dev.children,
320
+				   dev.siblings ) {
321
+		unregister_pcidev ( pci );
322
+		free ( pci );
323
+	}
324
+}
358 325
 
359
-	/* Fill in ioaddr and irqno */
360
-	nic->ioaddr = pci->ioaddr;
361
-	nic->irqno = pci->irq;
326
+/** PCI bus root device driver */
327
+static struct root_driver pci_root_driver = {
328
+	.probe = pcibus_probe,
329
+	.remove = pcibus_remove,
330
+};
362 331
 
363
-	/* Fill in DHCP device ID structure */
364
-	nic->dhcp_dev_id.bus_type = PCI_BUS_TYPE;
365
-	nic->dhcp_dev_id.vendor_id = htons ( pci->vendor_id );
366
-	nic->dhcp_dev_id.device_id = htons ( pci->device_id );
367
-}
332
+/** PCI bus root device */
333
+struct root_device pci_root_device __root_device = {
334
+	.name = "PCI",
335
+	.driver = &pci_root_driver,
336
+	.dev = {
337
+		.children = LIST_HEAD_INIT ( pci_root_device.dev.children ),
338
+	},
339
+};

+ 79
- 0
src/drivers/bus/pciextra.c View File

@@ -0,0 +1,79 @@
1
+#include <stdint.h>
2
+#include <gpxe/pci.h>
3
+
4
+/**
5
+ * Look for a PCI capability
6
+ *
7
+ * @v pci		PCI device to query
8
+ * @v cap		Capability code
9
+ * @ret address		Address of capability, or 0 if not found
10
+ *
11
+ * Determine whether or not a device supports a given PCI capability.
12
+ * Returns the address of the requested capability structure within
13
+ * the device's PCI configuration space, or 0 if the device does not
14
+ * support it.
15
+ */
16
+int pci_find_capability ( struct pci_device *pci, int cap ) {
17
+	uint16_t status;
18
+	uint8_t pos, id;
19
+	uint8_t hdr_type;
20
+	int ttl = 48;
21
+
22
+	pci_read_config_word ( pci, PCI_STATUS, &status );
23
+	if ( ! ( status & PCI_STATUS_CAP_LIST ) )
24
+		return 0;
25
+
26
+	pci_read_config_byte ( pci, PCI_HEADER_TYPE, &hdr_type );
27
+	switch ( hdr_type & 0x7F ) {
28
+	case PCI_HEADER_TYPE_NORMAL:
29
+	case PCI_HEADER_TYPE_BRIDGE:
30
+	default:
31
+		pci_read_config_byte ( pci, PCI_CAPABILITY_LIST, &pos );
32
+		break;
33
+	case PCI_HEADER_TYPE_CARDBUS:
34
+		pci_read_config_byte ( pci, PCI_CB_CAPABILITY_LIST, &pos );
35
+		break;
36
+	}
37
+	while ( ttl-- && pos >= 0x40 ) {
38
+		pos &= ~3;
39
+		pci_read_config_byte ( pci, pos + PCI_CAP_LIST_ID, &id );
40
+		DBG ( "PCI Capability: %d\n", id );
41
+		if ( id == 0xff )
42
+			break;
43
+		if ( id == cap )
44
+			return pos;
45
+		pci_read_config_byte ( pci, pos + PCI_CAP_LIST_NEXT, &pos );
46
+	}
47
+	return 0;
48
+}
49
+
50
+/**
51
+ * Find the size of a PCI BAR
52
+ *
53
+ * @v pci		PCI device
54
+ * @v reg		PCI register number
55
+ * @ret size		BAR size
56
+ *
57
+ * It should not be necessary for any Etherboot code to call this
58
+ * function.
59
+ */
60
+unsigned long pci_bar_size ( struct pci_device *pci, unsigned int reg ) {
61
+	uint32_t start, size;
62
+
63
+	/* Save the original bar */
64
+	pci_read_config_dword ( pci, reg, &start );
65
+	/* Compute which bits can be set */
66
+	pci_write_config_dword ( pci, reg, ~0 );
67
+	pci_read_config_dword ( pci, reg, &size );
68
+	/* Restore the original size */
69
+	pci_write_config_dword ( pci, reg, start );
70
+	/* Find the significant bits */
71
+	if ( start & PCI_BASE_ADDRESS_SPACE_IO ) {
72
+		size &= PCI_BASE_ADDRESS_IO_MASK;
73
+	} else {
74
+		size &= PCI_BASE_ADDRESS_MEM_MASK;
75
+	}
76
+	/* Find the lowest bit set */
77
+	size = size & ~( size - 1 );
78
+	return size;
79
+}

+ 1
- 1
src/drivers/net/3c595.c View File

@@ -522,7 +522,7 @@ static struct nic_operations t595_operations = {
522 522
 
523 523
 };
524 524
 
525
-static struct pci_id t595_nics[] = {
525
+static struct pci_device_id t595_nics[] = {
526 526
 PCI_ROM(0x10b7, 0x5900, "3c590",           "3Com590"),		/* Vortex 10Mbps */
527 527
 PCI_ROM(0x10b7, 0x5950, "3c595",           "3Com595"),		/* Vortex 100baseTx */
528 528
 PCI_ROM(0x10b7, 0x5951, "3c595-1",         "3Com595"),		/* Vortex 100baseT4 */

+ 2
- 2
src/drivers/net/3c90x.c View File

@@ -719,7 +719,7 @@ static int a3c90x_probe ( struct nic *nic, struct pci_device *pci ) {
719 719
     nic->ioaddr = pci->ioaddr;
720 720
     nic->irqno = 0;
721 721
 
722
-    INF_3C90X.is3c556 = (pci->device_id == 0x6055);
722
+    INF_3C90X.is3c556 = (pci->device == 0x6055);
723 723
     INF_3C90X.IOAddr = pci->ioaddr & ~3;
724 724
     INF_3C90X.CurrentWindow = 255;
725 725
     switch (a3c90x_internal_ReadEeprom(INF_3C90X.IOAddr, 0x03))
@@ -984,7 +984,7 @@ static struct nic_operations a3c90x_operations = {
984 984
 
985 985
 };
986 986
 
987
-static struct pci_id a3c90x_nics[] = {
987
+static struct pci_device_id a3c90x_nics[] = {
988 988
 /* Original 90x revisions: */
989 989
 PCI_ROM(0x10b7, 0x6055, "3c556",	 "3C556"),		/* Huricane */
990 990
 PCI_ROM(0x10b7, 0x9000, "3c905-tpo",     "3Com900-TPO"),	/* 10 Base TPO */

+ 1
- 1
src/drivers/net/amd8111e.c View File

@@ -671,7 +671,7 @@ static int amd8111e_probe(struct nic *nic, struct pci_device *pdev)
671 671
 	return 1;
672 672
 }
673 673
 
674
-static struct pci_id amd8111e_nics[] = {
674
+static struct pci_device_id amd8111e_nics[] = {
675 675
 	PCI_ROM(0x1022, 0x7462, "amd8111e",	"AMD8111E"),
676 676
 };
677 677
 

+ 3
- 3
src/drivers/net/davicom.c View File

@@ -662,8 +662,8 @@ static int davicom_probe ( struct nic *nic, struct pci_device *pci ) {
662 662
   if (pci->ioaddr == 0)
663 663
     return 0;
664 664
 
665
-  vendor  = pci->vendor_id;
666
-  dev_id  = pci->device_id;
665
+  vendor  = pci->vendor;
666
+  dev_id  = pci->device;
667 667
   ioaddr  = pci->ioaddr;
668 668
 
669 669
   pci_fill_nic ( nic, pci );
@@ -703,7 +703,7 @@ static struct nic_operations davicom_operations = {
703 703
 
704 704
 };
705 705
 
706
-static struct pci_id davicom_nics[] = {
706
+static struct pci_device_id davicom_nics[] = {
707 707
 PCI_ROM(0x1282, 0x9100, "davicom9100", "Davicom 9100"),
708 708
 PCI_ROM(0x1282, 0x9102, "davicom9102", "Davicom 9102"),
709 709
 PCI_ROM(0x1282, 0x9009, "davicom9009", "Davicom 9009"),

+ 3
- 3
src/drivers/net/dmfe.c View File

@@ -457,7 +457,7 @@ static int dmfe_probe ( struct nic *nic, struct pci_device *pci ) {
457 457
 
458 458
 	BASE = pci->ioaddr;
459 459
 	printf("dmfe.c: Found %s Vendor=0x%hX Device=0x%hX\n",
460
-	       pci->name, pci->vendor_id, pci->device_id);
460
+	       pci->name, pci->vendor, pci->device);
461 461
 
462 462
 	/* Read Chip revision */
463 463
 	pci_read_config_dword(pci, PCI_REVISION_ID, &dev_rev);
@@ -466,7 +466,7 @@ static int dmfe_probe ( struct nic *nic, struct pci_device *pci ) {
466 466
 	/* point to private storage */
467 467
 	db = &dfx;
468 468
 
469
-	db->chip_id = ((u32) pci->device_id << 16) | pci->vendor_id;
469
+	db->chip_id = ((u32) pci->device << 16) | pci->vendor;
470 470
 	BASE = pci_bar_start(pci, PCI_BASE_ADDRESS_0);
471 471
 	db->chip_revision = dev_rev;
472 472
 
@@ -1205,7 +1205,7 @@ static struct nic_operations dmfe_operations = {
1205 1205
 
1206 1206
 };
1207 1207
 
1208
-static struct pci_id dmfe_nics[] = {
1208
+static struct pci_device_id dmfe_nics[] = {
1209 1209
 	PCI_ROM(0x1282, 0x9100, "dmfe9100", "Davicom 9100"),
1210 1210
 	PCI_ROM(0x1282, 0x9102, "dmfe9102", "Davicom 9102"),
1211 1211
 	PCI_ROM(0x1282, 0x9009, "dmfe9009", "Davicom 9009"),

+ 1
- 1
src/drivers/net/e1000.c View File

@@ -3707,7 +3707,7 @@ static struct nic_operations e1000_operations = {
3707 3707
 
3708 3708
 };
3709 3709
 
3710
-static struct pci_id e1000_nics[] = {
3710
+static struct pci_device_id e1000_nics[] = {
3711 3711
 PCI_ROM(0x8086, 0x1000, "e1000-82542",               "Intel EtherExpressPro1000"),
3712 3712
 PCI_ROM(0x8086, 0x1001, "e1000-82543gc-fiber",       "Intel EtherExpressPro1000 82543GC Fiber"),
3713 3713
 PCI_ROM(0x8086, 0x1004, "e1000-82543gc-copper",	     "Intel EtherExpressPro1000 82543GC Copper"),

+ 1
- 1
src/drivers/net/eepro100.c View File

@@ -791,7 +791,7 @@ static struct nic_operations eepro100_operations = {
791 791
 
792 792
 };
793 793
 
794
-static struct pci_id eepro100_nics[] = {
794
+static struct pci_device_id eepro100_nics[] = {
795 795
 PCI_ROM(0x8086, 0x1029, "id1029",        "Intel EtherExpressPro100 ID1029"),
796 796
 PCI_ROM(0x8086, 0x1030, "id1030",        "Intel EtherExpressPro100 ID1030"),
797 797
 PCI_ROM(0x8086, 0x1031, "82801cam",      "Intel 82801CAM (ICH3) Chipset Ethernet Controller"),

+ 1
- 1
src/drivers/net/epic100.c View File

@@ -517,7 +517,7 @@ static struct nic_operations epic100_operations = {
517 517
 
518 518
 };
519 519
 
520
-static struct pci_id epic100_nics[] = {
520
+static struct pci_device_id epic100_nics[] = {
521 521
 PCI_ROM(0x10b8, 0x0005, "epic100",    "SMC EtherPowerII"),		/* SMC 83c170 EPIC/100 */
522 522
 PCI_ROM(0x10b8, 0x0006, "smc-83c175", "SMC EPIC/C 83c175"),
523 523
 };

+ 2
- 2
src/drivers/net/etherfabric.c View File

@@ -2975,7 +2975,7 @@ static int etherfabric_probe ( struct dev *dev, struct pci_device *pci ) {
2975 2975
 	memset ( &efab_buffers, 0, sizeof ( efab_buffers ) );
2976 2976
 
2977 2977
 	/* Hook in appropriate operations table.  Do this early. */
2978
-	if ( pci->device_id == EF1002_DEVID ) {
2978
+	if ( pci->device == EF1002_DEVID ) {
2979 2979
 		efab.op = &ef1002_operations;
2980 2980
 	} else {
2981 2981
 		efab.op = &falcon_operations;
@@ -3021,7 +3021,7 @@ static int etherfabric_probe ( struct dev *dev, struct pci_device *pci ) {
3021 3021
 	return 1;
3022 3022
 }
3023 3023
 
3024
-static struct pci_id etherfabric_nics[] = {
3024
+static struct pci_device_id etherfabric_nics[] = {
3025 3025
 PCI_ROM(0x1924, 0xC101, "ef1002", "EtherFabric EF1002"),
3026 3026
 PCI_ROM(0x1924, 0x0703, "falcon", "EtherFabric Falcon"),
3027 3027
 };

+ 6
- 6
src/drivers/net/forcedeth.c View File

@@ -1245,7 +1245,7 @@ static int forcedeth_probe ( struct nic *nic, struct pci_device *pci ) {
1245 1245
 		return 0;
1246 1246
 
1247 1247
 	printf("forcedeth.c: Found %s, vendor=0x%hX, device=0x%hX\n",
1248
-	       pci->name, pci->vendor_id, pci->device_id);
1248
+	       pci->name, pci->vendor, pci->device);
1249 1249
 
1250 1250
 	pci_fill_nic ( nic, pci );
1251 1251
 
@@ -1263,9 +1263,9 @@ static int forcedeth_probe ( struct nic *nic, struct pci_device *pci ) {
1263 1263
 		return 0;
1264 1264
 
1265 1265
 	/* handle different descriptor versions */
1266
-	if (pci->device_id == PCI_DEVICE_ID_NVIDIA_NVENET_1 ||
1267
-	    pci->device_id == PCI_DEVICE_ID_NVIDIA_NVENET_2 ||
1268
-	    pci->device_id == PCI_DEVICE_ID_NVIDIA_NVENET_3)
1266
+	if (pci->device == PCI_DEVICE_ID_NVIDIA_NVENET_1 ||
1267
+	    pci->device == PCI_DEVICE_ID_NVIDIA_NVENET_2 ||
1268
+	    pci->device == PCI_DEVICE_ID_NVIDIA_NVENET_3)
1269 1269
 		np->desc_ver = DESC_VER_1;
1270 1270
 	else
1271 1271
 		np->desc_ver = DESC_VER_2;
@@ -1316,7 +1316,7 @@ static int forcedeth_probe ( struct nic *nic, struct pci_device *pci ) {
1316 1316
  		np->tx_flags = NV_TX2_LASTPACKET | NV_TX2_VALID;
1317 1317
  	}
1318 1318
 
1319
-  	switch (pci->device_id) {
1319
+  	switch (pci->device) {
1320 1320
   	case 0x01C3:		// nforce
1321 1321
  		// DEV_IRQMASK_1|DEV_NEED_TIMERIRQ|DEV_NEED_LINKTIMER,
1322 1322
  		np->irqmask = NVREG_IRQMASK_WANTED_2 | NVREG_IRQ_TIMER;
@@ -1406,7 +1406,7 @@ static int forcedeth_probe ( struct nic *nic, struct pci_device *pci ) {
1406 1406
 	return 1;
1407 1407
 }
1408 1408
 
1409
-static struct pci_id forcedeth_nics[] = {
1409
+static struct pci_device_id forcedeth_nics[] = {
1410 1410
 PCI_ROM(0x10de, 0x01C3, "nforce", "nForce NVENET_1 Ethernet Controller"),
1411 1411
 PCI_ROM(0x10de, 0x0066, "nforce2", "nForce NVENET_2 Ethernet Controller"),
1412 1412
 PCI_ROM(0x10de, 0x00D6, "nforce3", "nForce NVENET_3 Ethernet Controller"),

+ 2
- 2
src/drivers/net/mtd80x.c View File

@@ -653,7 +653,7 @@ static struct nic_operations mtd_operations = {
653 653
 
654 654
 };
655 655
 
656
-static struct pci_id mtd80x_nics[] = {
656
+static struct pci_device_id mtd80x_nics[] = {
657 657
         PCI_ROM(0x1516, 0x0800, "MTD800", "Myson MTD800"),
658 658
         PCI_ROM(0x1516, 0x0803, "MTD803", "Surecom EP-320X"),
659 659
         PCI_ROM(0x1516, 0x0891, "MTD891", "Myson MTD891"),
@@ -676,7 +676,7 @@ static int mtd_probe ( struct nic *nic, struct pci_device *pci ) {
676 676
     adjust_pci_device(pci);
677 677
 
678 678
     mtdx.nic_name = pci->name;
679
-    mtdx.dev_id = pci->device_id;
679
+    mtdx.dev_id = pci->device;
680 680
     mtdx.ioaddr = nic->ioaddr;
681 681
 
682 682
     /* read ethernet id */

+ 3
- 3
src/drivers/net/natsemi.c View File

@@ -259,8 +259,8 @@ natsemi_probe ( struct nic *nic, struct pci_device *pci ) {
259 259
     nic->ioaddr = pci->ioaddr;
260 260
 
261 261
     ioaddr     = pci->ioaddr;
262
-    vendor     = pci->vendor_id;
263
-    dev_id     = pci->device_id;
262
+    vendor     = pci->vendor;
263
+    dev_id     = pci->device;
264 264
     nic_name   = pci->name;
265 265
 
266 266
     /* natsemi has a non-standard PM control register
@@ -770,7 +770,7 @@ static struct nic_operations natsemi_operations = {
770 770
 
771 771
 };
772 772
 
773
-static struct pci_id natsemi_nics[] = {
773
+static struct pci_device_id natsemi_nics[] = {
774 774
 PCI_ROM(0x100b, 0x0020, "dp83815", "DP83815"),
775 775
 };
776 776
 

+ 2
- 2
src/drivers/net/ns83820.c View File

@@ -800,7 +800,7 @@ static struct nic_operations ns83820_operations = {
800 800
 
801 801
 };
802 802
 
803
-static struct pci_id ns83820_nics[] = {
803
+static struct pci_device_id ns83820_nics[] = {
804 804
 	PCI_ROM(0x100b, 0x0022, "ns83820", "National Semiconductor 83820"),
805 805
 };
806 806
 
@@ -822,7 +822,7 @@ static int ns83820_probe ( struct nic *nic, struct pci_device *pci ) {
822 822
 		return 0;
823 823
 
824 824
 	printf("ns83820.c: Found %s, vendor=0x%hX, device=0x%hX\n",
825
-	       pci->name, pci->vendor_id, pci->device_id);
825
+	       pci->name, pci->vendor, pci->device);
826 826
 
827 827
 	/* point to private storage */
828 828
 	ns = &nsx;

+ 1
- 1
src/drivers/net/ns8390.c View File

@@ -991,7 +991,7 @@ ISA_ROM("ne","NE1000/2000 and clones");
991 991
 #endif
992 992
 
993 993
 #ifdef	INCLUDE_NS8390
994
-static struct pci_id nepci_nics[] = {
994
+static struct pci_device_id nepci_nics[] = {
995 995
 /* A few NE2000 PCI clones, list not exhaustive */
996 996
 PCI_ROM(0x10ec, 0x8029, "rtl8029",      "Realtek 8029"),
997 997
 PCI_ROM(0x1186, 0x0300, "dlink-528",    "D-Link DE-528"),

+ 2
- 2
src/drivers/net/pcnet32.c View File

@@ -680,7 +680,7 @@ static int pcnet32_probe ( struct nic *nic, struct pci_device *pci ) {
680 680
 	/* BASE is used throughout to address the card */
681 681
 	ioaddr = pci->ioaddr;
682 682
 	printf("pcnet32.c: Found %s, Vendor=0x%hX Device=0x%hX\n",
683
-	       pci->name, pci->vendor_id, pci->device_id);
683
+	       pci->name, pci->vendor, pci->device);
684 684
 
685 685
 	nic->irqno  = 0;
686 686
 	pci_fill_nic ( nic, pci );
@@ -1000,7 +1000,7 @@ static struct nic_operations pcnet32_operations = {
1000 1000
 
1001 1001
 };
1002 1002
 
1003
-static struct pci_id pcnet32_nics[] = {
1003
+static struct pci_device_id pcnet32_nics[] = {
1004 1004
 	PCI_ROM(0x1022, 0x2000, "pcnet32", "AMD PCnet/PCI"),
1005 1005
 	PCI_ROM(0x1022, 0x2625, "pcnetfastiii", "AMD PCNet FAST III"),
1006 1006
 	PCI_ROM(0x1022, 0x2001, "amdhomepna", "AMD PCnet/HomePNA"),

+ 9
- 23
src/drivers/net/pnic.c View File

@@ -199,13 +199,17 @@ static void pnic_remove ( struct pci_device *pci ) {
199 199
 /**************************************************************************
200 200
 PROBE - Look for an adapter, this routine's visible to the outside
201 201
 ***************************************************************************/
202
-static int pnic_probe ( struct pci_device *pci ) {
202
+static int pnic_probe ( struct pci_device *pci,
203
+			const struct pci_device_id *id __unused ) {
203 204
 	struct net_device *netdev;
204 205
 	struct pnic *pnic;
205 206
 	uint16_t api_version;
206 207
 	uint16_t status;
207 208
 	int rc;
208 209
 
210
+	/* Fix up PCI device */
211
+	adjust_pci_device ( pci );
212
+	
209 213
 	/* Allocate net device */
210 214
 	netdev = alloc_etherdev ( sizeof ( *pnic ) );
211 215
 	if ( ! netdev ) {
@@ -248,32 +252,14 @@ static int pnic_probe ( struct pci_device *pci ) {
248 252
 	return rc;
249 253
 }
250 254
 
251
-static struct pci_id pnic_nics[] = {
255
+static struct pci_device_id pnic_nics[] = {
252 256
 /* genrules.pl doesn't let us use macros for PCI IDs...*/
253 257
 PCI_ROM ( 0xfefe, 0xefef, "pnic", "Bochs Pseudo NIC Adaptor" ),
254 258
 };
255 259
 
256
-static struct pci_driver pnic_driver = {
260
+struct pci_driver pnic_driver __pci_driver = {
257 261
 	.ids = pnic_nics,
258 262
 	.id_count = ( sizeof ( pnic_nics ) / sizeof ( pnic_nics[0] ) ),
259
-	.class = PCI_NO_CLASS,
260
-	//	.probe = pnic_probe,
261
-	//	.remove = pnic_remove,
263
+	.probe = pnic_probe,
264
+	.remove = pnic_remove,
262 265
 };
263
-
264
-// PCI_DRIVER ( pnic_driver );
265
-
266
-
267
-static int pnic_hack_probe ( void *dummy, struct pci_device *pci ) {
268
-	return ( pnic_probe ( pci ) == 0 );
269
-}
270
-
271
-static void pnic_hack_disable ( void *dummy, struct pci_device *pci ) {
272
-	pnic_remove ( pci );
273
-}
274
-
275
-#include "dev.h"
276
-extern struct type_driver test_driver;
277
-
278
-DRIVER ( "PNIC", test_driver, pci_driver, pnic_driver,
279
-	 pnic_hack_probe, pnic_hack_disable );

+ 1
- 1
src/drivers/net/prism2_pci.c View File

@@ -39,7 +39,7 @@ static void prism2_pci_disable ( struct nic *nic,
39 39
   prism2_disable ( nic );
40 40
 }
41 41
 
42
-static struct pci_id prism2_pci_nics[] = {
42
+static struct pci_device_id prism2_pci_nics[] = {
43 43
 PCI_ROM(0x1260, 0x3873, "prism2_pci",	"Harris Semiconductor Prism2.5 clone"),
44 44
 PCI_ROM(0x1260, 0x3873, "hwp01170",	"ActionTec HWP01170"),
45 45
 PCI_ROM(0x1260, 0x3873, "dwl520",	"DLink DWL-520"),

+ 1
- 1
src/drivers/net/prism2_plx.c View File

@@ -95,7 +95,7 @@ static void prism2_plx_disable ( struct nic *nic,
95 95
   prism2_disable ( nic );
96 96
 }
97 97
 
98
-static struct pci_id prism2_plx_nics[] = {
98
+static struct pci_device_id prism2_plx_nics[] = {
99 99
 PCI_ROM(0x1385, 0x4100, "ma301",         "Netgear MA301"),
100 100
 PCI_ROM(0x10b7, 0x7770, "3c-airconnect", "3Com AirConnect"),
101 101
 PCI_ROM(0x111a, 0x1023, "ss1023",        "Siemens SpeedStream SS1023"),

+ 2
- 2
src/drivers/net/r8169.c View File

@@ -868,7 +868,7 @@ static struct nic_operations r8169_operations = {
868 868
 
869 869
 };
870 870
 
871
-static struct pci_id r8169_nics[] = {
871
+static struct pci_device_id r8169_nics[] = {
872 872
 	PCI_ROM(0x10ec, 0x8169, "r8169", "RealTek RTL8169 Gigabit Ethernet"),
873 873
         PCI_ROM(0x16ec, 0x0116, "usr-r8169", "US Robotics RTL8169 Gigabit Ethernet"),
874 874
         PCI_ROM(0x1186, 0x4300, "dlink-r8169", "D-Link RTL8169 Gigabit Ethernet"),
@@ -890,7 +890,7 @@ static int r8169_probe ( struct nic *nic, struct pci_device *pci ) {
890 890
 	int option = -1, Cap10_100 = 0, Cap1000 = 0;
891 891
 
892 892
 	printf("r8169.c: Found %s, Vendor=%hX Device=%hX\n",
893
-	       pci->name, pci->vendor_id, pci->device_id);
893
+	       pci->name, pci->vendor, pci->device);
894 894
 
895 895
 	board_idx++;
896 896
 

+ 1
- 1
src/drivers/net/rtl8139.c View File

@@ -528,7 +528,7 @@ static struct nic_operations rtl_operations = {
528 528
 
529 529
 };
530 530
 
531
-static struct pci_id rtl8139_nics[] = {
531
+static struct pci_device_id rtl8139_nics[] = {
532 532
 PCI_ROM(0x10ec, 0x8129, "rtl8129",       "Realtek 8129"),
533 533
 PCI_ROM(0x10ec, 0x8139, "rtl8139",       "Realtek 8139"),
534 534
 PCI_ROM(0x10ec, 0x8138, "rtl8139b",      "Realtek 8139B"),

+ 10
- 6
src/drivers/net/sis900.c View File

@@ -121,18 +121,20 @@ static struct mii_phy {
121 121
 
122 122
 
123 123
 // PCI to ISA bridge for SIS640E access
124
-static struct pci_id   pci_isa_bridge_list[] = {
125
-	{ 0x1039, 0x0008,
126
-		"SIS 85C503/5513 PCI to ISA bridge"},
124
+static struct pci_device_id pci_isa_bridge_list[] = {
125
+	{ .vendor = 0x1039, .device = 0x0008,
126
+		.name = "SIS 85C503/5513 PCI to ISA bridge"},
127 127
 };
128 128
 
129 129
 PCI_DRIVER ( sis_bridge_pci_driver, pci_isa_bridge_list, PCI_NO_CLASS );
130 130
 
131
+#if 0
131 132
 static struct device_driver sis_bridge_driver = {
132 133
     .name = "SIS ISA bridge",
133 134
     .bus_driver = &pci_driver,
134 135
     .bus_driver_info = ( struct bus_driver_info * ) &sis_bridge_pci_driver,
135 136
 };
137
+#endif
136 138
 
137 139
 /* Function Prototypes */
138 140
 
@@ -254,10 +256,12 @@ static int sis630e_get_mac_addr(struct pci_device * pci_dev __unused, struct nic
254 256
 	    struct pci_device isa_bridge;
255 257
 	} u;
256 258
 
259
+#if 0
257 260
 	/* find PCI to ISA bridge */
258 261
 	memset(&bus_loc, 0, sizeof(bus_loc));
259 262
 	if ( ! find_by_driver ( &bus_loc, &u.bus_dev, &sis_bridge_driver, 0 ) )
260 263
 	    return 0;
264
+#endif
261 265
 
262 266
 	pci_read_config_byte(&u.isa_bridge, 0x48, &reg);
263 267
 	pci_write_config_byte(&u.isa_bridge, 0x48, reg | 0x40);
@@ -337,8 +341,8 @@ static int sis900_probe ( struct nic *nic, struct pci_device *pci ) {
337 341
     pci_fill_nic ( nic, pci );
338 342
     nic->ioaddr = pci->ioaddr;
339 343
     ioaddr  = pci->ioaddr;
340
-    vendor  = pci->vendor_id;
341
-    dev_id  = pci->device_id;
344
+    vendor  = pci->vendor;
345
+    dev_id  = pci->device;
342 346
 
343 347
     /* wakeup chip */
344 348
     pci_write_config_dword(pci, 0x40, 0x00000000);
@@ -1266,7 +1270,7 @@ static struct nic_operations sis900_operations = {
1266 1270
 	.irq		= sis900_irq,
1267 1271
 };
1268 1272
 
1269
-static struct pci_id sis900_nics[] = {
1273
+static struct pci_device_id sis900_nics[] = {
1270 1274
 PCI_ROM(0x1039, 0x0900, "sis900",  "SIS900"),
1271 1275
 PCI_ROM(0x1039, 0x7016, "sis7016", "SIS7016"),
1272 1276
 };

+ 1
- 1
src/drivers/net/skel.c View File

@@ -218,7 +218,7 @@ static void skel_pci_disable ( struct nic *nic __unused,
218 218
 	 */
219 219
 }
220 220
 
221
-static struct pci_id skel_pci_nics[] = {
221
+static struct pci_device_id skel_pci_nics[] = {
222 222
 PCI_ROM ( 0x0000, 0x0000, "skel-pci", "Skeleton PCI Adapter" ),
223 223
 };
224 224
 

+ 2
- 2
src/drivers/net/sundance.c View File

@@ -590,7 +590,7 @@ static int sundance_probe ( struct nic *nic, struct pci_device *pci ) {
590 590
 	/* BASE is used throughout to address the card */
591 591
 	BASE = pci->ioaddr;
592 592
 	printf(" sundance.c: Found %s Vendor=0x%hX Device=0x%hX\n",
593
-	       pci->name, pci->vendor_id, pci->device_id);
593
+	       pci->name, pci->vendor, pci->device);
594 594
 
595 595
 	/* Get the MAC Address by reading the EEPROM */
596 596
 	for (i = 0; i < 3; i++) {
@@ -873,7 +873,7 @@ static void set_rx_mode(struct nic *nic __unused)
873 873
 	return;
874 874
 }
875 875
 
876
-static struct pci_id sundance_nics[] = {
876
+static struct pci_device_id sundance_nics[] = {
877 877
 	PCI_ROM(0x13f0, 0x0201, "sundance", "ST201 Sundance 'Alta' based Adaptor"),
878 878
 	PCI_ROM(0x1186, 0x1002, "dfe530txs", "D-Link DFE530TXS (Sundance ST201 Alta)"),
879 879
 };

+ 5
- 5
src/drivers/net/tg3.c View File

@@ -2852,9 +2852,9 @@ static int tg3_get_invariants(struct tg3 *tp)
2852 2852
 	if (((GET_ASIC_REV(tp->pci_chip_rev_id) == ASIC_REV_5703) &&
2853 2853
 		    ((grc_misc_cfg == 0x8000) || (grc_misc_cfg == 0x4000))) ||
2854 2854
 		((GET_ASIC_REV(tp->pci_chip_rev_id) == ASIC_REV_5705) &&
2855
-			(tp->pdev->vendor_id == PCI_VENDOR_ID_BROADCOM) &&
2856
-			((tp->pdev->device_id == PCI_DEVICE_ID_TIGON3_5901) ||
2857
-				(tp->pdev->device_id == PCI_DEVICE_ID_TIGON3_5901_2)))) {
2855
+			(tp->pdev->vendor == PCI_VENDOR_ID_BROADCOM) &&
2856
+			((tp->pdev->device == PCI_DEVICE_ID_TIGON3_5901) ||
2857
+				(tp->pdev->device == PCI_DEVICE_ID_TIGON3_5901_2)))) {
2858 2858
 		tp->tg3_flags |= TG3_FLAG_10_100_ONLY;
2859 2859
 	}
2860 2860
 
@@ -2886,7 +2886,7 @@ static int  tg3_get_device_address(struct tg3 *tp)
2886 2886
 	struct nic *nic = tp->nic;
2887 2887
 	uint32_t hi, lo, mac_offset;
2888 2888
 
2889
-	if (PCI_FUNC(tp->pdev->busdevfn) == 0)
2889
+	if (PCI_FUNC(tp->pdev->devfn) == 0)
2890 2890
 		mac_offset = 0x7c;
2891 2891
 	else
2892 2892
 		mac_offset = 0xcc;
@@ -3362,7 +3362,7 @@ static int tg3_probe ( struct nic *nic, struct pci_device *pdev ) {
3362 3362
 }
3363 3363
 
3364 3364
 
3365
-static struct pci_id tg3_nics[] = {
3365
+static struct pci_device_id tg3_nics[] = {
3366 3366
 PCI_ROM(0x14e4, 0x1644, "tg3-5700",        "Broadcom Tigon 3 5700"),
3367 3367
 PCI_ROM(0x14e4, 0x1645, "tg3-5701",        "Broadcom Tigon 3 5701"),
3368 3368
 PCI_ROM(0x14e4, 0x1646, "tg3-5702",        "Broadcom Tigon 3 5702"),

+ 4
- 4
src/drivers/net/tlan.c View File

@@ -811,7 +811,7 @@ static int tlan_probe ( struct nic *nic, struct pci_device *pci ) {
811 811
 	i = 0;
812 812
 	chip_idx = -1;
813 813
 	while (tlan_pci_tbl[i].name) {
814
-		if ((((u32) pci->device_id << 16) | pci->vendor_id) ==
814
+		if ((((u32) pci->device << 16) | pci->vendor) ==
815 815
 		    (tlan_pci_tbl[i].id.pci & 0xffffffff)) {
816 816
 			chip_idx = i;
817 817
 			break;
@@ -819,8 +819,8 @@ static int tlan_probe ( struct nic *nic, struct pci_device *pci ) {
819 819
 		i++;
820 820
 	}
821 821
 
822
-	priv->vendor_id = pci->vendor_id;
823
-	priv->dev_id = pci->device_id;
822
+	priv->vendor_id = pci->vendor;
823
+	priv->dev_id = pci->device;
824 824
 	priv->nic_name = pci->name;
825 825
 	priv->eoc = 0;
826 826
 
@@ -1704,7 +1704,7 @@ void TLan_PhyMonitor(struct net_device *dev)
1704 1704
 
1705 1705
 #endif				/* MONITOR */
1706 1706
 
1707
-static struct pci_id tlan_nics[] = {
1707
+static struct pci_device_id tlan_nics[] = {
1708 1708
 	PCI_ROM(0x0e11, 0xae34, "netel10", "Compaq Netelligent 10 T PCI UTP"),
1709 1709
 	PCI_ROM(0x0e11, 0xae32, "netel100","Compaq Netelligent 10/100 TX PCI UTP"),
1710 1710
 	PCI_ROM(0x0e11, 0xae35, "netflex3i", "Compaq Integrated NetFlex-3/P"),

+ 4
- 4
src/drivers/net/tulip.c View File

@@ -1249,8 +1249,8 @@ static int tulip_probe ( struct nic *nic, struct pci_device *pci ) {
1249 1249
     /* point to private storage */
1250 1250
     tp = &tulip_bss.tpx;
1251 1251
 
1252
-    tp->vendor_id  = pci->vendor_id;
1253
-    tp->dev_id     = pci->device_id;
1252
+    tp->vendor_id  = pci->vendor;
1253
+    tp->dev_id     = pci->device;
1254 1254
     tp->nic_name   = pci->name;
1255 1255
 
1256 1256
     tp->if_port = 0;
@@ -1275,7 +1275,7 @@ static int tulip_probe ( struct nic *nic, struct pci_device *pci ) {
1275 1275
 #ifdef TULIP_DEBUG
1276 1276
     if (tulip_debug > 1)
1277 1277
 	printf ("%s: Looking for Tulip Chip: Vendor=%hX  Device=%hX\n", tp->nic_name,
1278
-		tp->vendor_id, tp->dev_id);
1278
+		tp->vendor, tp->dev_id);
1279 1279
 #endif
1280 1280
 
1281 1281
     /* Figure out which chip we're dealing with */
@@ -2042,7 +2042,7 @@ static int tulip_check_duplex(struct nic *nic)
2042 2042
         return 0;
2043 2043
 }
2044 2044
 
2045
-static struct pci_id tulip_nics[] = {
2045
+static struct pci_device_id tulip_nics[] = {
2046 2046
 PCI_ROM(0x1011, 0x0002, "dc21040",     "Digital Tulip"),
2047 2047
 PCI_ROM(0x1011, 0x0009, "ds21140",     "Digital Tulip Fast"),
2048 2048
 PCI_ROM(0x1011, 0x0014, "dc21041",     "Digital Tulip+"),

+ 2
- 2
src/drivers/net/via-rhine.c View File

@@ -966,7 +966,7 @@ rhine_probe ( struct nic *nic, struct pci_device *pci ) {
966 966
 
967 967
     if (!pci->ioaddr)
968 968
 	return 0;
969
-    rhine_probe1 (nic, pci, pci->ioaddr, pci->device_id, -1);
969
+    rhine_probe1 (nic, pci, pci->ioaddr, pci->device, -1);
970 970
 
971 971
     adjust_pci_device ( pci );
972 972
     rhine_reset (nic);
@@ -1412,7 +1412,7 @@ static struct nic_operations rhine_operations = {
1412 1412
 
1413 1413
 };
1414 1414
 
1415
-static struct pci_id rhine_nics[] = {
1415
+static struct pci_device_id rhine_nics[] = {
1416 1416
 PCI_ROM(0x1106, 0x3065, "dlink-530tx",     "VIA 6102"),
1417 1417
 PCI_ROM(0x1106, 0x3106, "via-rhine-6105",  "VIA 6105"),
1418 1418
 PCI_ROM(0x1106, 0x3043, "dlink-530tx-old", "VIA 3043"),		/* Rhine-I 86c100a */

+ 2
- 2
src/drivers/net/via-velocity.c View File

@@ -676,7 +676,7 @@ static int velocity_probe(struct dev *dev, struct pci_device *pci)
676 676
 	struct mac_regs *regs;
677 677
 
678 678
 	printf("via-velocity.c: Found %s Vendor=0x%hX Device=0x%hX\n",
679
-	       pci->name, pci->vendor_id, pci->device_id);
679
+	       pci->name, pci->vendor, pci->device);
680 680
 
681 681
 	/* point to private storage */
682 682
 	vptr = &vptx;
@@ -1930,7 +1930,7 @@ int pci_set_power_state(struct pci_device *dev, int state)
1930 1930
 	return 0;
1931 1931
 }
1932 1932
 
1933
-static struct pci_id velocity_nics[] = {
1933
+static struct pci_device_id velocity_nics[] = {
1934 1934
 	PCI_ROM(0x1106, 0x3119, "via-velocity", "VIA Networking Velocity Family Gigabit Ethernet Adapter"),
1935 1935
 };
1936 1936
 

+ 6
- 6
src/drivers/net/w89c840.c View File

@@ -609,7 +609,7 @@ static struct nic_operations w89c840_operations = {
609 609
 
610 610
 };
611 611
 
612
-static struct pci_id w89c840_nics[] = {
612
+static struct pci_device_id w89c840_nics[] = {
613 613
 PCI_ROM(0x1050, 0x0840, "winbond840",     "Winbond W89C840F"),
614 614
 PCI_ROM(0x11f6, 0x2011, "compexrl100atx", "Compex RL100ATX"),
615 615
 };
@@ -643,20 +643,20 @@ static int w89c840_probe ( struct nic *nic, struct pci_device *p ) {
643 643
 #define PCI_DEVICE_ID_COMPEX_RL100ATX   0x2011
644 644
 
645 645
     /* From Matt Hortman <mbhortman@acpthinclient.com> */
646
-    if (p->vendor_id == PCI_VENDOR_ID_WINBOND2
647
-        && p->device_id == PCI_DEVICE_ID_WINBOND2_89C840) {
646
+    if (p->vendor == PCI_VENDOR_ID_WINBOND2
647
+        && p->device == PCI_DEVICE_ID_WINBOND2_89C840) {
648 648
 
649 649
         /* detected "Winbond W89c840 Fast Ethernet PCI NIC" */
650 650
 
651
-    } else if ( p->vendor_id == PCI_VENDOR_ID_COMPEX
652
-                && p->device_id == PCI_DEVICE_ID_COMPEX_RL100ATX) {
651
+    } else if ( p->vendor == PCI_VENDOR_ID_COMPEX
652
+                && p->device == PCI_DEVICE_ID_COMPEX_RL100ATX) {
653 653
 
654 654
         /* detected "Compex RL100ATX Fast Ethernet PCI NIC" */
655 655
 
656 656
     } else {
657 657
         /* Gee, guess what? They missed again. */
658 658
         printf("device ID : %X - is not a Compex RL100ATX NIC.\n",
659
-	       p->device_id);
659
+	       p->device);
660 660
         return 0;
661 661
     }
662 662
 

+ 107
- 112
src/include/gpxe/pci.h View File

@@ -1,18 +1,13 @@
1
-#ifndef	_GPXEPCI_H
2
-#define _GPXEPCI_H
1
+#ifndef	_GPXE_PCI_H
2
+#define _GPXE_PCI_H
3 3
 
4 4
 /*
5
-** Support for NE2000 PCI clones added David Monro June 1997
6
-** Generalised for other PCI NICs by Ken Yap July 1997
7
-**
8
-** Most of this is taken from:
9
-**
10
-** /usr/src/linux/drivers/pci/pci.c
11
-** /usr/src/linux/include/linux/pci.h
12
-** /usr/src/linux/arch/i386/bios32.c
13
-** /usr/src/linux/include/linux/bios32.h
14
-** /usr/src/linux/drivers/net/ne.c
15
-*/
5
+ * Support for NE2000 PCI clones added David Monro June 1997
6
+ * Generalised for other PCI NICs by Ken Yap July 1997
7
+ * PCI support rewritten by Michael Brown 2006
8
+ *
9
+ * Most of this is taken from /usr/src/linux/include/linux/pci.h.
10
+ */
16 11
 
17 12
 /*
18 13
  * This program is free software; you can redistribute it and/or
@@ -22,10 +17,10 @@
22 17
  */
23 18
 
24 19
 #include <stdint.h>
20
+#include <gpxe/device.h>
21
+#include <gpxe/tables.h>
25 22
 #include "pci_ids.h"
26 23
 
27
-#define	PCI_BUS_TYPE	1
28
-
29 24
 /*
30 25
  * PCI constants
31 26
  *
@@ -87,18 +82,16 @@
87 82
 #define PCI_BASE_ADDRESS_4      0x20    /* 32 bits */
88 83
 #define PCI_BASE_ADDRESS_5      0x24    /* 32 bits */
89 84
 
90
-#define PCI_BASE_ADDRESS_MEM_TYPE_MASK 0x06
85
+#define PCI_BASE_ADDRESS_SPACE		0x01    /* 0 = memory, 1 = I/O */
86
+#define PCI_BASE_ADDRESS_SPACE_IO	0x01
87
+#define PCI_BASE_ADDRESS_SPACE_MEMORY	0x00
88
+
89
+#define PCI_BASE_ADDRESS_MEM_TYPE_MASK	0x06
91 90
 #define PCI_BASE_ADDRESS_MEM_TYPE_32	0x00	/* 32 bit address */
92 91
 #define PCI_BASE_ADDRESS_MEM_TYPE_1M	0x02	/* Below 1M [obsolete] */
93 92
 #define PCI_BASE_ADDRESS_MEM_TYPE_64	0x04	/* 64 bit address */
94
-
95
-#ifndef	PCI_BASE_ADDRESS_IO_MASK
96
-#define	PCI_BASE_ADDRESS_IO_MASK       (~0x03)
97
-#endif
98
-#ifndef	PCI_BASE_ADDRESS_MEM_MASK
99
-#define	PCI_BASE_ADDRESS_MEM_MASK       (~0x0f)
100
-#endif
101
-#define	PCI_BASE_ADDRESS_SPACE_IO	0x01
93
+#define	PCI_BASE_ADDRESS_MEM_MASK	(~0x0f)
94
+#define	PCI_BASE_ADDRESS_IO_MASK	(~0x03)
102 95
 #define	PCI_ROM_ADDRESS		0x30	/* 32 bits */
103 96
 #define	PCI_ROM_ADDRESS_ENABLE	0x01	/* Write 1 to enable ROM,
104 97
 					   bits 31..11 are address,
@@ -234,90 +227,98 @@
234 227
 #define PCI_MSI_ADDRESS_HI	8	/* Upper 32 bits (if PCI_MSI_FLAGS_64BIT set) */
235 228
 #define PCI_MSI_DATA_32		8	/* 16 bits of data for 32-bit devices */
236 229
 #define PCI_MSI_DATA_64		12	/* 16 bits of data for 64-bit devices */
237
-/*
238
- * A location on a PCI bus
239
- *
240
- */
241
-struct pci_loc {
242
-	uint16_t		busdevfn;
230
+
231
+/** A PCI device ID list entry */
232
+struct pci_device_id {
233
+	/** Name */
234
+	const char *name;
235
+	/** PCI vendor ID */
236
+	uint16_t vendor;
237
+	/** PCI device ID */
238
+	uint16_t device;
243 239
 };
244 240
 
245
-/*
246
- * A physical PCI device
247
- *
248
- */
241
+/** A PCI device */
249 242
 struct pci_device {
250
-	const char *	name;
251
-	uint32_t	membase;	/* BAR 1 */
252
-	uint32_t	ioaddr;		/* first IO BAR */
253
-	uint16_t	vendor_id, device_id;
254
-	uint16_t	class;
255
-	uint16_t	busdevfn;
256
-	uint8_t		revision;
257
-	uint8_t		irq;
243
+	/** Generic device */
244
+	struct device dev;
245
+	/** Memory base
246
+	 *
247
+	 * This is the physical address of the first valid memory BAR.
248
+	 */
249
+	unsigned long membase;
250
+	/**
251
+	 * I/O address
252
+	 *
253
+	 * This is the physical address of the first valid I/O BAR.
254
+	 */
255
+	unsigned long ioaddr;
256
+	/** Vendor ID */
257
+	uint16_t vendor;
258
+	/** Device ID */
259
+	uint16_t device;
260
+	/** Device class */
261
+	uint32_t class;
262
+	/** Interrupt number */
263
+	uint8_t irq;
264
+	/** Bus number */
265
+	uint8_t bus;
266
+	/** Device and function number */
267
+	uint8_t devfn;
268
+	/** Driver for this device */
269
+	struct pci_driver *driver;
270
+	/** Driver-private data
271
+	 *
272
+	 * Use pci_set_drvdata() and pci_get_drvdata() to access this
273
+	 * field.
274
+	 */
258 275
 	void *priv;
276
+	/** Device name */
277
+	const char *name;
259 278
 };
260 279
 
261
-/*
262
- * Useful busdevfn calculations
263
- *
264
- */
265
-#define PCI_BUS(busdevfn)	( ( uint8_t ) ( ( (busdevfn) >> 8 ) & 0xff ) )
266
-#define PCI_DEV(busdevfn)	( ( uint8_t ) ( ( (busdevfn) >> 3 ) & 0x1f ) )
267
-#define PCI_FUNC(busdevfn)      ( ( uint8_t ) ( (busdevfn) & 0x07 ) )
268
-#define PCI_FN0(busdevfn)	( ( uint16_t ) ( (busdevfn) & 0xfff8 ) )
269
-#define PCI_MAX_BUSDEVFN	0xffff
270
-
271
-/*
272
- * An individual PCI device identified by vendor and device IDs
273
- *
274
- */
275
-struct pci_id {
276
-	unsigned short vendor_id, device_id;
277
-	const char *name;
280
+/** A PCI driver */
281
+struct pci_driver {
282
+	/** PCI ID table */
283
+	struct pci_device_id *ids;
284
+	/** Number of entries in PCI ID table */
285
+	unsigned int id_count;
286
+	/**
287
+	 * Probe device
288
+	 *
289
+	 * @v pci	PCI device
290
+	 * @v id	Matching entry in ID table
291
+	 * @ret rc	Return status code
292
+	 */
293
+	int ( * probe ) ( struct pci_device *pci,
294
+			  const struct pci_device_id *id );
295
+	/**
296
+	 * Remove device
297
+	 *
298
+	 * @v pci	PCI device
299
+	 */
300
+	void ( * remove ) ( struct pci_device *pci );
278 301
 };
279 302
 
303
+/** Declare a PCI driver */
304
+#define __pci_driver __table ( pci_drivers, 01 )
305
+
306
+#define PCI_DEVFN( slot, func )	( ( (slot) << 3 ) | (func) )
307
+#define PCI_SLOT( devfn )	( ( (devfn) >> 3 ) & 0x1f )
308
+#define PCI_FUNC( devfn )	( (devfn) & 0x07 )
309
+
280 310
 /*
281 311
  * PCI_ROM is used to build up entries in a struct pci_id array.  It
282 312
  * is also parsed by parserom.pl to generate Makefile rules and files
283 313
  * for rom-o-matic.
284 314
  */
285
-#define PCI_ROM( _vendor_id, _device_id, _name, _description ) {	\
286
-	.vendor_id = _vendor_id,					\
287
-	.device_id = _device_id,					\
288
-	.name = _name,							\
315
+#define PCI_ROM( _vendor, _device, _name, _description ) {	\
316
+	.vendor = _vendor,					\
317
+	.device = _device,					\
318
+	.name = _name,						\
289 319
 }
290 320
 
291
-/*
292
- * A PCI driver information table, with a device ID (struct pci_id)
293
- * table and an optional class.
294
- *
295
- * Set the class to something other than PCI_NO_CLASS if the driver
296
- * can handle an entire class of devices.
297
- *
298
- */
299
-struct pci_driver {
300
-	struct pci_id *ids;
301
-	unsigned int id_count;
302
-	uint16_t class;
303
-};
304
-#define PCI_NO_CLASS 0
305
-
306
-/*
307
- * Define a PCI driver.
308
- *
309
- */
310
-#define PCI_DRIVER( _name, _ids, _class ) 				\
311
-	static struct pci_driver _name = {				\
312
-		.ids = _ids,						\
313
-		.id_count = sizeof ( _ids ) / sizeof ( _ids[0] ),	\
314
-		.class = _class,					\
315
-	}
316
-
317
-/*
318
- * These are the functions we expect pci_io.c to provide.
319
- *
320
- */
321
+extern unsigned int pci_max_bus;
321 322
 extern int pci_read_config_byte	( struct pci_device *pci, unsigned int where,
322 323
 				  uint8_t *value );
323 324
 extern int pci_write_config_byte ( struct pci_device *pci, unsigned int where,
@@ -330,35 +331,29 @@ extern int pci_read_config_dword ( struct pci_device *pci, unsigned int where,
330 331
 				   uint32_t *value );
331 332
 extern int pci_write_config_dword ( struct pci_device *pci, unsigned int where,
332 333
 				    uint32_t value );
333
-extern unsigned long pci_bus_base ( struct pci_device *pci );
334
-
335
-/*
336
- * pci_io.c is allowed to overwrite pci_max_bus if it knows what the
337
- * highest bus in the system will be.
338
- *
339
- */
340
-extern unsigned int pci_max_bus;
341
-
342
-/*
343
- * Functions in pci.c
344
- *
345
- */
346 334
 extern void adjust_pci_device ( struct pci_device *pci );
347 335
 extern unsigned long pci_bar_start ( struct pci_device *pci,
348
-				     unsigned int bar );
349
-extern unsigned long pci_bar_size ( struct pci_device *pci, unsigned int bar );
336
+				     unsigned int reg );
350 337
 extern int pci_find_capability ( struct pci_device *pci, int capability );
338
+extern __attribute__ (( deprecated )) unsigned long
339
+pci_bar_size ( struct pci_device *pci, unsigned int reg );
351 340
 
352
-/*
353
- * PCI bus global definition
341
+/**
342
+ * Set PCI driver-private data
354 343
  *
344
+ * @v pci		PCI device
345
+ * @v priv		Private data
355 346
  */
356
-extern struct bus_driver pci_driver;
357
-
358 347
 static inline void pci_set_drvdata ( struct pci_device *pci, void *priv ) {
359 348
 	pci->priv = priv;
360 349
 }
361 350
 
351
+/**
352
+ * Get PCI driver-private data
353
+ *
354
+ * @v pci		PCI device
355
+ * @ret priv		Private data
356
+ */
362 357
 static inline void * pci_get_drvdata ( struct pci_device *pci ) {
363 358
 	return pci->priv;
364 359
 }

Loading…
Cancel
Save