Przeglądaj źródła

[pci] Allow drivers to specify a PCI class

Allow drivers to specify a supported PCI class code.  To save space in
the final binary, make this an attribute of the driver rather than an
attribute of a PCI device ID list entry.

Signed-off-by: Michael Brown <mcb30@ipxe.org>
tags/v1.20.1
Michael Brown 9 lat temu
rodzic
commit
072d656a2f

+ 2
- 5
src/arch/i386/drivers/net/undi.c Wyświetl plik

@@ -68,10 +68,6 @@ static int undipci_probe ( struct pci_device *pci ) {
68 68
 	struct undi_rom *undirom;
69 69
 	int rc;
70 70
 
71
-	/* Ignore non-network devices */
72
-	if ( PCI_BASE_CLASS ( pci->class ) != PCI_BASE_CLASS_NETWORK )
73
-		return -ENOTTY;
74
-
75 71
 	/* Allocate UNDI device structure */
76 72
 	undi = zalloc ( sizeof ( *undi ) );
77 73
 	if ( ! undi )
@@ -138,12 +134,13 @@ static void undipci_remove ( struct pci_device *pci ) {
138 134
 }
139 135
 
140 136
 static struct pci_device_id undipci_nics[] = {
141
-PCI_ROM ( 0xffff, 0xffff, "undipci", "UNDI (PCI)", 0 ),
137
+	PCI_ROM ( 0xffff, 0xffff, "undipci", "UNDI (PCI)", 0 ),
142 138
 };
143 139
 
144 140
 struct pci_driver undipci_driver __pci_driver_fallback = {
145 141
 	.ids = undipci_nics,
146 142
 	.id_count = ( sizeof ( undipci_nics ) / sizeof ( undipci_nics[0] ) ),
143
+	.class = PCI_CLASS ( PCI_CLASS_NETWORK, PCI_ANY_ID, PCI_ANY_ID ),
147 144
 	.probe = undipci_probe,
148 145
 	.remove = undipci_remove,
149 146
 };

+ 6
- 3
src/drivers/bus/pci.c Wyświetl plik

@@ -253,6 +253,8 @@ int pci_find_driver ( struct pci_device *pci ) {
253 253
 	unsigned int i;
254 254
 
255 255
 	for_each_table_entry ( driver, PCI_DRIVERS ) {
256
+		if ( ( driver->class.class ^ pci->class ) & driver->class.mask )
257
+			continue;
256 258
 		for ( i = 0 ; i < driver->id_count ; i++ ) {
257 259
 			id = &driver->ids[i];
258 260
 			if ( ( id->vendor != PCI_ANY_ID ) &&
@@ -334,14 +336,15 @@ static int pcibus_probe ( struct root_device *rootdev ) {
334 336
 
335 337
 		/* Look for a driver */
336 338
 		if ( ( rc = pci_find_driver ( pci ) ) != 0 ) {
337
-			DBGC ( pci, PCI_FMT " (%04x:%04x) has no driver\n",
338
-			       PCI_ARGS ( pci ), pci->vendor, pci->device );
339
+			DBGC ( pci, PCI_FMT " (%04x:%04x class %06x) has no "
340
+			       "driver\n", PCI_ARGS ( pci ), pci->vendor,
341
+			       pci->device, pci->class );
339 342
 			continue;
340 343
 		}
341 344
 
342 345
 		/* Add to device hierarchy */
343 346
 		pci->dev.parent = &rootdev->dev;
344
-		list_add ( &pci->dev.siblings, &rootdev->dev.children);
347
+		list_add ( &pci->dev.siblings, &rootdev->dev.children );
345 348
 
346 349
 		/* Look for a driver */
347 350
 		if ( ( rc = pci_probe ( pci ) ) == 0 ) {

+ 25
- 0
src/include/ipxe/pci.h Wyświetl plik

@@ -279,6 +279,29 @@ struct pci_device_id {
279 279
 /** Match-anything ID */
280 280
 #define PCI_ANY_ID 0xffff
281 281
 
282
+/** A PCI class ID */
283
+struct pci_class_id {
284
+	/** Class */
285
+	uint32_t class;
286
+	/** Class mask */
287
+	uint32_t mask;
288
+};
289
+
290
+/** Construct PCI class ID
291
+ *
292
+ * @v base		Base class (or PCI_ANY_ID)
293
+ * @v sub		Subclass (or PCI_ANY_ID)
294
+ * @v progif		Programming interface (or PCI_ANY_ID)
295
+ */
296
+#define PCI_CLASS(base,sub,progif) {					   \
297
+	.class = ( ( ( (base) & 0xff ) << 16 ) |			   \
298
+		   ( ( (sub) & 0xff ) << 8 ) |				   \
299
+		   ( ( (progif) & 0xff) << 0 ) ),			   \
300
+	.mask = ( ( ( ( (base) == PCI_ANY_ID ) ? 0x00 : 0xff ) << 16 ) |   \
301
+		  ( ( ( (sub) == PCI_ANY_ID ) ? 0x00 : 0xff ) << 8 ) |	   \
302
+		  ( ( ( (progif) == PCI_ANY_ID ) ? 0x00 : 0xff ) << 0 ) ), \
303
+	}
304
+
282 305
 /** A PCI device */
283 306
 struct pci_device {
284 307
 	/** Generic device */
@@ -322,6 +345,8 @@ struct pci_driver {
322 345
 	struct pci_device_id *ids;
323 346
 	/** Number of entries in PCI ID table */
324 347
 	unsigned int id_count;
348
+	/** PCI class ID */
349
+	struct pci_class_id class;
325 350
 	/**
326 351
 	 * Probe device
327 352
 	 *

+ 30
- 93
src/include/ipxe/pci_ids.h Wyświetl plik

@@ -11,116 +11,53 @@ FILE_LICENCE ( GPL2_ONLY );
11 11
 
12 12
 /* Device classes and subclasses */
13 13
 
14
-#define PCI_CLASS_NOT_DEFINED		0x0000
15
-#define PCI_CLASS_NOT_DEFINED_VGA	0x0001
14
+#define PCI_CLASS_NONE			0x00
16 15
 
17
-#define PCI_BASE_CLASS_STORAGE		0x01
18
-#define PCI_CLASS_STORAGE_SCSI		0x0100
19
-#define PCI_CLASS_STORAGE_IDE		0x0101
20
-#define PCI_CLASS_STORAGE_FLOPPY	0x0102
21
-#define PCI_CLASS_STORAGE_IPI		0x0103
22
-#define PCI_CLASS_STORAGE_RAID		0x0104
23
-#define PCI_CLASS_STORAGE_OTHER		0x0180
16
+#define PCI_CLASS_STORAGE		0x01
24 17
 
25
-#define PCI_BASE_CLASS_NETWORK		0x02
26
-#define PCI_CLASS_NETWORK_ETHERNET	0x0200
27
-#define PCI_CLASS_NETWORK_TOKEN_RING	0x0201
28
-#define PCI_CLASS_NETWORK_FDDI		0x0202
29
-#define PCI_CLASS_NETWORK_ATM		0x0203
30
-#define PCI_CLASS_NETWORK_OTHER		0x0280
18
+#define PCI_CLASS_NETWORK		0x02
19
+#define PCI_CLASS_NETWORK_ETHERNET	0x00
20
+#define PCI_CLASS_NETWORK_TOKENRING	0x01
21
+#define PCI_CLASS_NETWORK_FDDI		0x02
22
+#define PCI_CLASS_NETWORK_ATM		0x03
23
+#define PCI_CLASS_NETWORK_ISDN		0x04
24
+#define PCI_CLASS_NETWORK_WORLDFIP	0x05
25
+#define PCI_CLASS_NETWORK_PICMG		0x06
31 26
 
32
-#define PCI_BASE_CLASS_DISPLAY		0x03
33
-#define PCI_CLASS_DISPLAY_VGA		0x0300
34
-#define PCI_CLASS_DISPLAY_XGA		0x0301
35
-#define PCI_CLASS_DISPLAY_3D		0x0302
36
-#define PCI_CLASS_DISPLAY_OTHER		0x0380
27
+#define PCI_CLASS_DISPLAY		0x03
37 28
 
38
-#define PCI_BASE_CLASS_MULTIMEDIA	0x04
39
-#define PCI_CLASS_MULTIMEDIA_VIDEO	0x0400
40
-#define PCI_CLASS_MULTIMEDIA_AUDIO	0x0401
41
-#define PCI_CLASS_MULTIMEDIA_PHONE	0x0402
42
-#define PCI_CLASS_MULTIMEDIA_OTHER	0x0480
29
+#define PCI_CLASS_MEDIA			0x04
43 30
 
44
-#define PCI_BASE_CLASS_MEMORY		0x05
45
-#define PCI_CLASS_MEMORY_RAM		0x0500
46
-#define PCI_CLASS_MEMORY_FLASH		0x0501
47
-#define PCI_CLASS_MEMORY_OTHER		0x0580
31
+#define PCI_CLASS_MEMORY		0x05
48 32
 
49
-#define PCI_BASE_CLASS_BRIDGE		0x06
50
-#define PCI_CLASS_BRIDGE_HOST		0x0600
51
-#define PCI_CLASS_BRIDGE_ISA		0x0601
52
-#define PCI_CLASS_BRIDGE_EISA		0x0602
53
-#define PCI_CLASS_BRIDGE_MC		0x0603
54
-#define PCI_CLASS_BRIDGE_PCI		0x0604
55
-#define PCI_CLASS_BRIDGE_PCMCIA		0x0605
56
-#define PCI_CLASS_BRIDGE_NUBUS		0x0606
57
-#define PCI_CLASS_BRIDGE_CARDBUS	0x0607
58
-#define PCI_CLASS_BRIDGE_RACEWAY	0x0608
59
-#define PCI_CLASS_BRIDGE_OTHER		0x0680
33
+#define PCI_CLASS_BRIDGE		0x06
60 34
 
61
-#define PCI_BASE_CLASS_COMMUNICATION	0x07
62
-#define PCI_CLASS_COMMUNICATION_SERIAL	0x0700
63
-#define PCI_CLASS_COMMUNICATION_PARALLEL 0x0701
64
-#define PCI_CLASS_COMMUNICATION_MULTISERIAL 0x0702
65
-#define PCI_CLASS_COMMUNICATION_MODEM	0x0703
66
-#define PCI_CLASS_COMMUNICATION_OTHER	0x0780
35
+#define PCI_CLASS_COMMS			0x07
67 36
 
68
-#define PCI_BASE_CLASS_SYSTEM		0x08
69
-#define PCI_CLASS_SYSTEM_PIC		0x0800
70
-#define PCI_CLASS_SYSTEM_DMA		0x0801
71
-#define PCI_CLASS_SYSTEM_TIMER		0x0802
72
-#define PCI_CLASS_SYSTEM_RTC		0x0803
73
-#define PCI_CLASS_SYSTEM_PCI_HOTPLUG	0x0804
74
-#define PCI_CLASS_SYSTEM_OTHER		0x0880
37
+#define PCI_CLASS_GENERIC		0x08
75 38
 
76
-#define PCI_BASE_CLASS_INPUT		0x09
77
-#define PCI_CLASS_INPUT_KEYBOARD	0x0900
78
-#define PCI_CLASS_INPUT_PEN		0x0901
79
-#define PCI_CLASS_INPUT_MOUSE		0x0902
80
-#define PCI_CLASS_INPUT_SCANNER		0x0903
81
-#define PCI_CLASS_INPUT_GAMEPORT	0x0904
82
-#define PCI_CLASS_INPUT_OTHER		0x0980
39
+#define PCI_CLASS_INPUT			0x09
83 40
 
84
-#define PCI_BASE_CLASS_DOCKING		0x0a
85
-#define PCI_CLASS_DOCKING_GENERIC	0x0a00
86
-#define PCI_CLASS_DOCKING_OTHER		0x0a80
41
+#define PCI_CLASS_DOCK			0x0a
87 42
 
88
-#define PCI_BASE_CLASS_PROCESSOR	0x0b
89
-#define PCI_CLASS_PROCESSOR_386		0x0b00
90
-#define PCI_CLASS_PROCESSOR_486		0x0b01
91
-#define PCI_CLASS_PROCESSOR_PENTIUM	0x0b02
92
-#define PCI_CLASS_PROCESSOR_ALPHA	0x0b10
93
-#define PCI_CLASS_PROCESSOR_POWERPC	0x0b20
94
-#define PCI_CLASS_PROCESSOR_MIPS	0x0b30
95
-#define PCI_CLASS_PROCESSOR_CO		0x0b40
43
+#define PCI_CLASS_CPU			0x0b
96 44
 
97
-#define PCI_BASE_CLASS_SERIAL		0x0c
98
-#define PCI_CLASS_SERIAL_FIREWIRE	0x0c00
99
-#define PCI_CLASS_SERIAL_ACCESS		0x0c01
100
-#define PCI_CLASS_SERIAL_SSA		0x0c02
101
-#define PCI_CLASS_SERIAL_USB		0x0c03
102
-#define PCI_CLASS_SERIAL_FIBER		0x0c04
103
-#define PCI_CLASS_SERIAL_SMBUS		0x0c05
45
+#define PCI_CLASS_SERIAL		0x0c
46
+#define PCI_CLASS_SERIAL_USB		0x03
47
+#define PCI_CLASS_SERIAL_USB_UHCI	0x00
48
+#define PCI_CLASS_SERIAL_USB_OHCI	0x10
49
+#define PCI_CLASS_SERIAL_USB_EHCI	0x20
50
+#define PCI_CLASS_SERIAL_USB_XHCI	0x30
104 51
 
105
-#define PCI_BASE_CLASS_INTELLIGENT	0x0e
106
-#define PCI_CLASS_INTELLIGENT_I2O	0x0e00
52
+#define PCI_CLASS_WIFI			0x0d
107 53
 
108
-#define PCI_BASE_CLASS_SATELLITE	0x0f
109
-#define PCI_CLASS_SATELLITE_TV		0x0f00
110
-#define PCI_CLASS_SATELLITE_AUDIO	0x0f01
111
-#define PCI_CLASS_SATELLITE_VOICE	0x0f03
112
-#define PCI_CLASS_SATELLITE_DATA	0x0f04
54
+#define PCI_CLASS_IO			0x0e
113 55
 
114
-#define PCI_BASE_CLASS_CRYPT		0x10
115
-#define PCI_CLASS_CRYPT_NETWORK		0x1000
116
-#define PCI_CLASS_CRYPT_ENTERTAINMENT	0x1001
117
-#define PCI_CLASS_CRYPT_OTHER		0x1080
56
+#define PCI_CLASS_SATELLITE		0x0f
118 57
 
119
-#define PCI_BASE_CLASS_SIGNAL_PROCESSING 0x11
120
-#define PCI_CLASS_SP_DPIO		0x1100
121
-#define PCI_CLASS_SP_OTHER		0x1180
58
+#define PCI_CLASS_CRYPTO		0x10
122 59
 
123
-#define PCI_CLASS_OTHERS		0xff
60
+#define PCI_CLASS_DATA			0x11
124 61
 
125 62
 /* Vendors */
126 63
 

Ładowanie…
Anuluj
Zapisz