Browse Source

Add device description fields to struct device.

tags/v0.9.3
Michael Brown 17 years ago
parent
commit
fdc97499bf

+ 2
- 2
src/arch/i386/core/pcibios.c View File

@@ -72,7 +72,7 @@ int pcibios_read ( struct pci_device *pci, uint32_t command, uint32_t *value ){
72 72
 			       : "=a" ( status ), "=b" ( discard_b ),
73 73
 				 "=c" ( *value ), "=D" ( discard_D )
74 74
 			       : "a" ( command >> 16 ), "D" ( command ),
75
-				 "b" ( ( pci->bus << 8 ) | pci->devfn )
75
+			         "b" ( PCI_BUSDEVFN ( pci->bus, pci->devfn ) )
76 76
 			       : "edx" );
77 77
 
78 78
 	return ( ( status >> 8 ) & 0xff );
@@ -98,7 +98,7 @@ int pcibios_write ( struct pci_device *pci, uint32_t command, uint32_t value ){
98 98
 			       : "=a" ( status ), "=b" ( discard_b ),
99 99
 				 "=c" ( discard_c ), "=D" ( discard_D )
100 100
 			       : "a" ( command >> 16 ),	"D" ( command ),
101
-				 "b" ( ( pci->bus << 8 ) | pci->devfn ),
101
+			         "b" ( PCI_BUSDEVFN ( pci->bus, pci->devfn ) ),
102 102
 				 "c" ( value )
103 103
 			       : "edx" );
104 104
 	

+ 2
- 1
src/arch/i386/drivers/net/undi.c View File

@@ -64,7 +64,7 @@ static int undipci_probe ( struct pci_device *pci,
64 64
 			   const struct pci_device_id *id __unused ) {
65 65
 	struct undi_device *undi;
66 66
 	struct undi_rom *undirom;
67
-	unsigned int busdevfn = ( ( pci->bus << 8 ) | pci->devfn );
67
+	unsigned int busdevfn = PCI_BUSDEVFN ( pci->bus, pci->devfn );
68 68
 	int rc;
69 69
 
70 70
 	/* Ignore non-network devices */
@@ -99,6 +99,7 @@ static int undipci_probe ( struct pci_device *pci,
99 99
 	/* Add to device hierarchy */
100 100
 	snprintf ( undi->dev.name, sizeof ( undi->dev.name ),
101 101
 		   "UNDI-%s", pci->dev.name );
102
+	memcpy ( &undi->dev.desc, &pci->dev.desc, sizeof ( undi->dev.desc ) );
102 103
 	undi->dev.parent = &pci->dev;
103 104
 	INIT_LIST_HEAD ( &undi->dev.children );
104 105
 	list_add ( &undi->dev.siblings, &pci->dev.children );

+ 2
- 2
src/arch/i386/drivers/net/undiload.c View File

@@ -76,13 +76,13 @@ int undi_load ( struct undi_device *undi, struct undi_rom *undirom ) {
76 76
 	/* Debug info */
77 77
 	DBGC ( undi, "UNDI %p loading UNDI ROM %p to CS %04x DS %04x for ",
78 78
 	       undi, undirom, undi_loader.UNDI_CS, undi_loader.UNDI_DS );
79
-	if ( undi->pci_busdevfn != 0xffff ) {
79
+	if ( undi->pci_busdevfn != UNDI_NO_PCI_BUSDEVFN ) {
80 80
 		unsigned int bus = ( undi->pci_busdevfn >> 8 );
81 81
 		unsigned int devfn = ( undi->pci_busdevfn & 0xff );
82 82
 		DBGC ( undi, "PCI %02x:%02x.%x\n",
83 83
 		       bus, PCI_SLOT ( devfn ), PCI_FUNC ( devfn ) );
84 84
 	}
85
-	if ( undi->isapnp_csn != 0xffff ) {
85
+	if ( undi->isapnp_csn != UNDI_NO_ISAPNP_CSN ) {
86 86
 		DBGC ( undi, "ISAPnP(%04x) CSN %04x\n",
87 87
 		       undi->isapnp_read_port, undi->isapnp_csn );
88 88
 	}

+ 24
- 10
src/arch/i386/drivers/net/undionly.c View File

@@ -49,29 +49,41 @@
49 49
  * find.
50 50
  */
51 51
 static int undibus_probe ( struct root_device *rootdev ) {
52
+	struct undi_device *undi = &preloaded_undi;
52 53
 	int rc;
53 54
 
54 55
 	/* Check for a valie preloaded UNDI device */
55
-	if ( ! preloaded_undi.entry.segment ) {
56
+	if ( ! undi->entry.segment ) {
56 57
 		DBG ( "No preloaded UNDI device found!\n" );
57 58
 		return -ENODEV;
58 59
 	}
59 60
 
60 61
 	/* Add to device hierarchy */
61
-	strncpy ( preloaded_undi.dev.name, "UNDI",
62
-		  ( sizeof ( preloaded_undi.dev.name ) - 1 ) );
63
-	preloaded_undi.dev.parent = &rootdev->dev;
64
-	list_add ( &preloaded_undi.dev.siblings, &rootdev->dev.children);
65
-	INIT_LIST_HEAD ( &preloaded_undi.dev.children );
62
+	strncpy ( undi->dev.name, "UNDI",
63
+		  ( sizeof ( undi->dev.name ) - 1 ) );
64
+	if ( undi->pci_busdevfn != UNDI_NO_PCI_BUSDEVFN ) {
65
+		struct pci_device_description *pcidesc = &undi->dev.desc.pci;
66
+		pcidesc->bus_type = BUS_TYPE_PCI;
67
+		pcidesc->busdevfn = undi->pci_busdevfn;
68
+		pcidesc->vendor = undi->pci_vendor;
69
+		pcidesc->device = undi->pci_device;
70
+	} else if ( undi->isapnp_csn != UNDI_NO_ISAPNP_CSN ) {
71
+		struct isapnp_device_description *isapnpdesc
72
+			= &undi->dev.desc.isapnp;
73
+		isapnpdesc->bus_type = BUS_TYPE_ISAPNP;
74
+	}
75
+	undi->dev.parent = &rootdev->dev;
76
+	list_add ( &undi->dev.siblings, &rootdev->dev.children);
77
+	INIT_LIST_HEAD ( &undi->dev.children );
66 78
 
67 79
 	/* Create network device */
68
-	if ( ( rc = undinet_probe ( &preloaded_undi ) ) != 0 )
80
+	if ( ( rc = undinet_probe ( undi ) ) != 0 )
69 81
 		goto err;
70 82
 
71 83
 	return 0;
72 84
 
73 85
  err:
74
-	list_del ( &preloaded_undi.dev.siblings );
86
+	list_del ( &undi->dev.siblings );
75 87
 	return rc;
76 88
 }
77 89
 
@@ -81,8 +93,10 @@ static int undibus_probe ( struct root_device *rootdev ) {
81 93
  * @v rootdev		UNDI bus root device
82 94
  */
83 95
 static void undibus_remove ( struct root_device *rootdev __unused ) {
84
-	undinet_remove ( &preloaded_undi );
85
-	list_del ( &preloaded_undi.dev.siblings );
96
+	struct undi_device *undi = &preloaded_undi;
97
+
98
+	undinet_remove ( undi );
99
+	list_del ( &undi->dev.siblings );
86 100
 }
87 101
 
88 102
 /** UNDI bus root device driver */

+ 22
- 3
src/arch/i386/include/undi.h View File

@@ -26,12 +26,22 @@ struct undi_device {
26 26
 	UINT16_t fbms;
27 27
 	/** Free base memory prior to load */
28 28
 	UINT16_t restore_fbms;
29
-	/** PCI bus:dev.fn, or 0xffff */
29
+	/** PCI bus:dev.fn, or @c UNDI_NO_PCI_BUSDEVFN */
30 30
 	UINT16_t pci_busdevfn;
31
-	/** ISAPnP card select number, or 0xffff */
31
+	/** ISAPnP card select number, or @c UNDI_NO_ISAPNP_CSN */
32 32
 	UINT16_t isapnp_csn;
33
-	/** ISAPnP read port, or 0xffff */
33
+	/** ISAPnP read port, or @c UNDI_NO_ISAPNP_READ_PORT */
34 34
 	UINT16_t isapnp_read_port;
35
+	/** PCI vendor ID
36
+	 *
37
+	 * Filled in only for the preloaded UNDI device by pxeprefix.S
38
+	 */
39
+	UINT16_t pci_vendor;
40
+	/** PCI device ID 
41
+	 *
42
+	 * Filled in only for the preloaded UNDI device by pxeprefix.S
43
+	 */
44
+	UINT16_t pci_device;
35 45
 	/** Padding */
36 46
 	UINT16_t pad;
37 47
 
@@ -45,6 +55,15 @@ struct undi_device {
45 55
 	void *priv;
46 56
 } __attribute__ (( packed ));
47 57
 
58
+/** PCI bus:dev.fn field is invalid */
59
+#define UNDI_NO_PCI_BUSDEVFN 0xffff
60
+
61
+/** ISAPnP card select number field is invalid */
62
+#define UNDI_NO_ISAPNP_CSN 0xffff
63
+
64
+/** ISAPnP read port field is invalid */
65
+#define UNDI_NO_ISAPNP_READ_PORT 0xffff
66
+
48 67
 /**
49 68
  * Set UNDI driver-private data
50 69
  *

+ 2
- 2
src/arch/i386/include/undiload.h View File

@@ -25,8 +25,8 @@ static inline int undi_load_pci ( struct undi_device *undi,
25 25
 				  struct undi_rom *undirom,
26 26
 				  unsigned int pci_busdevfn ) {
27 27
 	undi->pci_busdevfn = pci_busdevfn;
28
-	undi->isapnp_csn = 0xffff;
29
-	undi->isapnp_read_port = 0xffff;
28
+	undi->isapnp_csn = UNDI_NO_ISAPNP_CSN;
29
+	undi->isapnp_read_port = UNDI_NO_ISAPNP_READ_PORT;
30 30
 	return undi_load ( undi, undirom );
31 31
 }
32 32
 

+ 6
- 1
src/arch/i386/prefix/pxeprefix.S View File

@@ -220,7 +220,9 @@ get_physical_device:
220 220
 	jmp	no_physical_device
221 221
 
222 222
 pci_physical_device:
223
-	/* Record PCI bus:dev.fn */
223
+	/* Record PCI bus:dev.fn and vendor/device IDs */
224
+	movl	( pxe_parameter_structure + 0x03 ), %eax
225
+	movl	%eax, pci_vendor
224 226
 	movw	( pxe_parameter_structure + 0x0b ), %ax
225 227
 	movw	%ax, pci_busdevfn
226 228
 	movw	$10f, %si
@@ -680,6 +682,9 @@ pci_busdevfn:		.word 0xffff
680 682
 isapnp_csn:		.word 0xffff
681 683
 isapnp_read_port:	.word 0xffff
682 684
 
685
+pci_vendor:		.word 0
686
+pci_device:		.word 0
687
+
683 688
 	.equ undi_device_size, ( . - undi_device )
684 689
 
685 690
 /*****************************************************************************

+ 4
- 0
src/drivers/bus/pci.c View File

@@ -282,6 +282,10 @@ static int pcibus_probe ( struct root_device *rootdev ) {
282 282
 			snprintf ( pci->dev.name, sizeof ( pci->dev.name ),
283 283
 				   "PCI%02x:%02x.%x", bus,
284 284
 				   PCI_SLOT ( devfn ), PCI_FUNC ( devfn ) );
285
+			pci->dev.desc.bus_type = BUS_TYPE_PCI;
286
+			pci->dev.desc.pci.busdevfn = PCI_BUSDEVFN (bus, devfn);
287
+			pci->dev.desc.pci.vendor = pci->vendor;
288
+			pci->dev.desc.pci.device = pci->device;
285 289
 			pci->dev.parent = &rootdev->dev;
286 290
 			list_add ( &pci->dev.siblings, &rootdev->dev.children);
287 291
 			INIT_LIST_HEAD ( &pci->dev.children );

+ 48
- 0
src/include/gpxe/device.h View File

@@ -11,10 +11,58 @@
11 11
 #include <gpxe/list.h>
12 12
 #include <gpxe/tables.h>
13 13
 
14
+/** A PCI device description */
15
+struct pci_device_description {
16
+	/** Bus type
17
+	 *
18
+	 * Must be @c BUS_TYPE_PCI.
19
+	 */
20
+	unsigned int bus_type;
21
+	/** Bus:dev.fn address
22
+	 *
23
+	 * As constructed by PCI_BUSDEVFN().
24
+	 */
25
+	unsigned int busdevfn;
26
+	/** Vendor ID */
27
+	unsigned int vendor;
28
+	/** Device ID */
29
+	unsigned int device;
30
+};
31
+
32
+/** PCI bus type */
33
+#define BUS_TYPE_PCI 1
34
+
35
+/** An ISAPnP device description */
36
+struct isapnp_device_description {
37
+	/** Bus type
38
+	 *
39
+	 * Must be @c BUS_TYPE_ISAPNP.
40
+	 */
41
+	unsigned int bus_type;
42
+};
43
+
44
+/** PCI bus type */
45
+#define BUS_TYPE_ISAPNP 2
46
+
47
+/** A hardware device description */
48
+union device_description {
49
+	/** Bus type
50
+	 *
51
+	 * This must be a BUS_TYPE_XXX constant.
52
+	 */
53
+	unsigned int bus_type;
54
+	/** PCI device description */
55
+	struct pci_device_description pci;
56
+	/** ISAPnP device description */
57
+	struct isapnp_device_description isapnp;
58
+};
59
+
14 60
 /** A hardware device */
15 61
 struct device {
16 62
 	/** Name */
17 63
 	char name[16];
64
+	/** Device description */
65
+	union device_description desc;
18 66
 	/** Devices on the same bus */
19 67
 	struct list_head siblings;
20 68
 	/** Devices attached to this device */

+ 4
- 3
src/include/gpxe/pci.h View File

@@ -307,9 +307,10 @@ struct pci_driver {
307 307
 /** Declare a PCI driver */
308 308
 #define __pci_driver __table ( struct pci_driver, pci_drivers, 01 )
309 309
 
310
-#define PCI_DEVFN( slot, func )	( ( (slot) << 3 ) | (func) )
311
-#define PCI_SLOT( devfn )	( ( (devfn) >> 3 ) & 0x1f )
312
-#define PCI_FUNC( devfn )	( (devfn) & 0x07 )
310
+#define PCI_DEVFN( slot, func )		( ( (slot) << 3 ) | (func) )
311
+#define PCI_SLOT( devfn )		( ( (devfn) >> 3 ) & 0x1f )
312
+#define PCI_FUNC( devfn )		( (devfn) & 0x07 )
313
+#define PCI_BUSDEVFN( bus, devfn )	( ( (bus) << 8 ) | (devfn) )
313 314
 
314 315
 #define PCI_BASE_CLASS( class )	( (class) >> 16 )
315 316
 

Loading…
Cancel
Save