Browse Source

[pci] Use single "busdevfn" field in struct pci_device

Merge the "bus" and "devfn" fields into a single "busdevfn" field, to
match the format used by the majority of external code.

Signed-off-by: Michael Brown <mcb30@ipxe.org>
tags/v1.20.1
Michael Brown 13 years ago
parent
commit
f9b3fae8d4

+ 4
- 3
src/arch/i386/drivers/net/undi.c View File

66
 			   const struct pci_device_id *id __unused ) {
66
 			   const struct pci_device_id *id __unused ) {
67
 	struct undi_device *undi;
67
 	struct undi_device *undi;
68
 	struct undi_rom *undirom;
68
 	struct undi_rom *undirom;
69
-	unsigned int busdevfn = PCI_BUSDEVFN ( pci->bus, pci->devfn );
70
 	int rc;
69
 	int rc;
71
 
70
 
72
 	/* Ignore non-network devices */
71
 	/* Ignore non-network devices */
80
 	pci_set_drvdata ( pci, undi );
79
 	pci_set_drvdata ( pci, undi );
81
 
80
 
82
 	/* Find/create our pixie */
81
 	/* Find/create our pixie */
83
-	if ( preloaded_undi.pci_busdevfn == busdevfn ) {
82
+	if ( preloaded_undi.pci_busdevfn == pci->busdevfn ) {
84
 		/* Claim preloaded UNDI device */
83
 		/* Claim preloaded UNDI device */
85
 		DBGC ( undi, "UNDI %p using preloaded UNDI device\n", undi );
84
 		DBGC ( undi, "UNDI %p using preloaded UNDI device\n", undi );
86
 		memcpy ( undi, &preloaded_undi, sizeof ( *undi ) );
85
 		memcpy ( undi, &preloaded_undi, sizeof ( *undi ) );
93
 		}
92
 		}
94
 
93
 
95
 		/* Call UNDI ROM loader to create pixie */
94
 		/* Call UNDI ROM loader to create pixie */
96
-		if ( ( rc = undi_load_pci ( undi, undirom, busdevfn ) ) != 0 )
95
+		if ( ( rc = undi_load_pci ( undi, undirom,
96
+					    pci->busdevfn ) ) != 0 ) {
97
 			goto err_load_pci;
97
 			goto err_load_pci;
98
+		}
98
 	}
99
 	}
99
 
100
 
100
 	/* Add to device hierarchy */
101
 	/* Add to device hierarchy */

+ 2
- 3
src/arch/i386/interface/pcbios/pcibios.c View File

73
 			       : "=a" ( status ), "=b" ( discard_b ),
73
 			       : "=a" ( status ), "=b" ( discard_b ),
74
 				 "=c" ( *value ), "=D" ( discard_D )
74
 				 "=c" ( *value ), "=D" ( discard_D )
75
 			       : "a" ( command >> 16 ), "D" ( command ),
75
 			       : "a" ( command >> 16 ), "D" ( command ),
76
-			         "b" ( PCI_BUSDEVFN ( pci->bus, pci->devfn ) )
76
+				 "b" ( pci->busdevfn )
77
 			       : "edx" );
77
 			       : "edx" );
78
 
78
 
79
 	return ( ( status >> 8 ) & 0xff );
79
 	return ( ( status >> 8 ) & 0xff );
99
 			       : "=a" ( status ), "=b" ( discard_b ),
99
 			       : "=a" ( status ), "=b" ( discard_b ),
100
 				 "=c" ( discard_c ), "=D" ( discard_D )
100
 				 "=c" ( discard_c ), "=D" ( discard_D )
101
 			       : "a" ( command >> 16 ),	"D" ( command ),
101
 			       : "a" ( command >> 16 ),	"D" ( command ),
102
-			         "b" ( PCI_BUSDEVFN ( pci->bus, pci->devfn ) ),
103
-				 "c" ( value )
102
+			         "b" ( pci->busdevfn ), "c" ( value )
104
 			       : "edx" );
103
 			       : "edx" );
105
 	
104
 	
106
 	return ( ( status >> 8 ) & 0xff );
105
 	return ( ( status >> 8 ) & 0xff );

+ 2
- 2
src/arch/x86/core/pcidirect.c View File

34
  * @v where	Location within PCI configuration space
34
  * @v where	Location within PCI configuration space
35
  */
35
  */
36
 void pcidirect_prepare ( struct pci_device *pci, int where ) {
36
 void pcidirect_prepare ( struct pci_device *pci, int where ) {
37
-	outl ( ( 0x80000000 | ( pci->bus << 16 ) | ( pci->devfn << 8 ) |
38
-		 ( where & ~3 ) ), PCIDIRECT_CONFIG_ADDRESS );
37
+	outl ( ( 0x80000000 | ( pci->busdevfn << 8 ) | ( where & ~3 ) ),
38
+	       PCIDIRECT_CONFIG_ADDRESS );
39
 }
39
 }
40
 
40
 
41
 PROVIDE_PCIAPI_INLINE ( direct, pci_max_bus );
41
 PROVIDE_PCIAPI_INLINE ( direct, pci_max_bus );

+ 57
- 60
src/drivers/bus/pci.c View File

228
  */
228
  */
229
 static int pcibus_probe ( struct root_device *rootdev ) {
229
 static int pcibus_probe ( struct root_device *rootdev ) {
230
 	struct pci_device *pci = NULL;
230
 	struct pci_device *pci = NULL;
231
-	unsigned int max_bus;
232
-	unsigned int bus;
233
-	unsigned int devfn;
231
+	unsigned int num_bus;
232
+	unsigned int busdevfn;
234
 	uint8_t hdrtype = 0;
233
 	uint8_t hdrtype = 0;
235
 	uint32_t tmp;
234
 	uint32_t tmp;
236
 	int rc;
235
 	int rc;
237
 
236
 
238
-	max_bus = pci_max_bus();
239
-	for ( bus = 0 ; bus <= max_bus ; bus++ ) {
240
-		for ( devfn = 0 ; devfn <= 0xff ; devfn++ ) {
237
+	num_bus = ( pci_max_bus() + 1 );
238
+	for ( busdevfn = 0 ; busdevfn < PCI_BUSDEVFN ( num_bus, 0, 0 ) ;
239
+	      busdevfn++ ) {
241
 
240
 
242
-			/* Allocate struct pci_device */
243
-			if ( ! pci )
244
-				pci = malloc ( sizeof ( *pci ) );
245
-			if ( ! pci ) {
246
-				rc = -ENOMEM;
247
-				goto err;
248
-			}
249
-			memset ( pci, 0, sizeof ( *pci ) );
250
-			pci->bus = bus;
251
-			pci->devfn = devfn;
241
+		/* Allocate struct pci_device */
242
+		if ( ! pci )
243
+			pci = malloc ( sizeof ( *pci ) );
244
+		if ( ! pci ) {
245
+			rc = -ENOMEM;
246
+			goto err;
247
+		}
248
+		memset ( pci, 0, sizeof ( *pci ) );
249
+		pci->busdevfn = busdevfn;
252
 			
250
 			
253
-			/* Skip all but the first function on
254
-			 * non-multifunction cards
255
-			 */
256
-			if ( PCI_FUNC ( devfn ) == 0 ) {
257
-				pci_read_config_byte ( pci, PCI_HEADER_TYPE,
258
-						       &hdrtype );
259
-			} else if ( ! ( hdrtype & 0x80 ) ) {
260
-					continue;
261
-			}
251
+		/* Skip all but the first function on
252
+		 * non-multifunction cards
253
+		 */
254
+		if ( PCI_FUNC ( busdevfn ) == 0 ) {
255
+			pci_read_config_byte ( pci, PCI_HEADER_TYPE,
256
+					       &hdrtype );
257
+		} else if ( ! ( hdrtype & 0x80 ) ) {
258
+			continue;
259
+		}
262
 
260
 
263
-			/* Check for physical device presence */
264
-			pci_read_config_dword ( pci, PCI_VENDOR_ID, &tmp );
265
-			if ( ( tmp == 0xffffffff ) || ( tmp == 0 ) )
266
-				continue;
261
+		/* Check for physical device presence */
262
+		pci_read_config_dword ( pci, PCI_VENDOR_ID, &tmp );
263
+		if ( ( tmp == 0xffffffff ) || ( tmp == 0 ) )
264
+			continue;
267
 			
265
 			
268
-			/* Populate struct pci_device */
269
-			pci->vendor = ( tmp & 0xffff );
270
-			pci->device = ( tmp >> 16 );
271
-			pci_read_config_dword ( pci, PCI_REVISION, &tmp );
272
-			pci->class = ( tmp >> 8 );
273
-			pci_read_config_byte ( pci, PCI_INTERRUPT_LINE,
274
-					       &pci->irq );
275
-			pci_read_bases ( pci );
266
+		/* Populate struct pci_device */
267
+		pci->vendor = ( tmp & 0xffff );
268
+		pci->device = ( tmp >> 16 );
269
+		pci_read_config_dword ( pci, PCI_REVISION, &tmp );
270
+		pci->class = ( tmp >> 8 );
271
+		pci_read_config_byte ( pci, PCI_INTERRUPT_LINE,
272
+				       &pci->irq );
273
+		pci_read_bases ( pci );
276
 
274
 
277
-			/* Add to device hierarchy */
278
-			snprintf ( pci->dev.name, sizeof ( pci->dev.name ),
279
-				   "PCI%02x:%02x.%x", bus,
280
-				   PCI_SLOT ( devfn ), PCI_FUNC ( devfn ) );
281
-			pci->dev.desc.bus_type = BUS_TYPE_PCI;
282
-			pci->dev.desc.location = PCI_BUSDEVFN (bus, devfn);
283
-			pci->dev.desc.vendor = pci->vendor;
284
-			pci->dev.desc.device = pci->device;
285
-			pci->dev.desc.class = pci->class;
286
-			pci->dev.desc.ioaddr = pci->ioaddr;
287
-			pci->dev.desc.irq = pci->irq;
288
-			pci->dev.parent = &rootdev->dev;
289
-			list_add ( &pci->dev.siblings, &rootdev->dev.children);
290
-			INIT_LIST_HEAD ( &pci->dev.children );
291
-			
292
-			/* Look for a driver */
293
-			if ( pci_probe ( pci ) == 0 ) {
294
-				/* pcidev registered, we can drop our ref */
295
-				pci = NULL;
296
-			} else {
297
-				/* Not registered; re-use struct pci_device */
298
-				list_del ( &pci->dev.siblings );
299
-			}
275
+		/* Add to device hierarchy */
276
+		snprintf ( pci->dev.name, sizeof ( pci->dev.name ),
277
+			   "PCI%02x:%02x.%x", PCI_BUS ( busdevfn ),
278
+			   PCI_SLOT ( busdevfn ), PCI_FUNC ( busdevfn ) );
279
+		pci->dev.desc.bus_type = BUS_TYPE_PCI;
280
+		pci->dev.desc.location = pci->busdevfn;
281
+		pci->dev.desc.vendor = pci->vendor;
282
+		pci->dev.desc.device = pci->device;
283
+		pci->dev.desc.class = pci->class;
284
+		pci->dev.desc.ioaddr = pci->ioaddr;
285
+		pci->dev.desc.irq = pci->irq;
286
+		pci->dev.parent = &rootdev->dev;
287
+		list_add ( &pci->dev.siblings, &rootdev->dev.children);
288
+		INIT_LIST_HEAD ( &pci->dev.children );
289
+
290
+		/* Look for a driver */
291
+		if ( pci_probe ( pci ) == 0 ) {
292
+			/* pcidev registered, we can drop our ref */
293
+			pci = NULL;
294
+		} else {
295
+			/* Not registered; re-use struct pci_device */
296
+			list_del ( &pci->dev.siblings );
300
 		}
297
 		}
301
 	}
298
 	}
302
 
299
 

+ 9
- 7
src/drivers/net/phantom/phantom.c View File

1792
 
1792
 
1793
 	bar0_start = pci_bar_start ( pci, PCI_BASE_ADDRESS_0 );
1793
 	bar0_start = pci_bar_start ( pci, PCI_BASE_ADDRESS_0 );
1794
 	bar0_size = pci_bar_size ( pci, PCI_BASE_ADDRESS_0 );
1794
 	bar0_size = pci_bar_size ( pci, PCI_BASE_ADDRESS_0 );
1795
-	DBGC ( phantom, "Phantom %p is PCI %02x:%02x.%x with BAR0 at "
1796
-	       "%08lx+%lx\n", phantom, pci->bus, PCI_SLOT ( pci->devfn ),
1797
-	       PCI_FUNC ( pci->devfn ), bar0_start, bar0_size );
1795
+	DBGC ( phantom, "Phantom %p is " PCI_FMT " with BAR0 at %08lx+%lx\n",
1796
+	       phantom, PCI_ARGS ( pci ), bar0_start, bar0_size );
1798
 
1797
 
1799
 	if ( ! bar0_start ) {
1798
 	if ( ! bar0_start ) {
1800
 		DBGC ( phantom, "Phantom %p BAR not assigned; ignoring\n",
1799
 		DBGC ( phantom, "Phantom %p BAR not assigned; ignoring\n",
2057
 	pci_set_drvdata ( pci, netdev );
2056
 	pci_set_drvdata ( pci, netdev );
2058
 	netdev->dev = &pci->dev;
2057
 	netdev->dev = &pci->dev;
2059
 	memset ( phantom, 0, sizeof ( *phantom ) );
2058
 	memset ( phantom, 0, sizeof ( *phantom ) );
2060
-	phantom->port = PCI_FUNC ( pci->devfn );
2059
+	phantom->port = PCI_FUNC ( pci->busdevfn );
2061
 	assert ( phantom->port < PHN_MAX_NUM_PORTS );
2060
 	assert ( phantom->port < PHN_MAX_NUM_PORTS );
2062
 	settings_init ( &phantom->settings,
2061
 	settings_init ( &phantom->settings,
2063
 			&phantom_settings_operations,
2062
 			&phantom_settings_operations,
2074
 	 * B2 will have this fixed; remove this hack when B1 is no
2073
 	 * B2 will have this fixed; remove this hack when B1 is no
2075
 	 * longer in use.
2074
 	 * longer in use.
2076
 	 */
2075
 	 */
2077
-	if ( PCI_FUNC ( pci->devfn ) == 0 ) {
2076
+	if ( PCI_FUNC ( pci->busdevfn ) == 0 ) {
2078
 		unsigned int i;
2077
 		unsigned int i;
2079
 		for ( i = 0 ; i < 8 ; i++ ) {
2078
 		for ( i = 0 ; i < 8 ; i++ ) {
2080
 			uint32_t temp;
2079
 			uint32_t temp;
2081
-			pci->devfn = PCI_DEVFN ( PCI_SLOT ( pci->devfn ), i );
2080
+			pci->busdevfn =
2081
+				PCI_BUSDEVFN ( PCI_BUS ( pci->busdevfn ),
2082
+					       PCI_SLOT ( pci->busdevfn ), i );
2082
 			pci_read_config_dword ( pci, 0xc8, &temp );
2083
 			pci_read_config_dword ( pci, 0xc8, &temp );
2083
 			pci_read_config_dword ( pci, 0xc8, &temp );
2084
 			pci_read_config_dword ( pci, 0xc8, &temp );
2084
 			pci_write_config_dword ( pci, 0xc8, 0xf1000 );
2085
 			pci_write_config_dword ( pci, 0xc8, 0xf1000 );
2085
 		}
2086
 		}
2086
-		pci->devfn = PCI_DEVFN ( PCI_SLOT ( pci->devfn ), 0 );
2087
+		pci->busdevfn = PCI_BUSDEVFN ( PCI_BUS ( pci->busdevfn ),
2088
+					       PCI_SLOT ( pci->busdevfn ), 0 );
2087
 	}
2089
 	}
2088
 
2090
 
2089
 	/* Initialise the command PEG */
2091
 	/* Initialise the command PEG */

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

2909
 	struct nic *nic = tp->nic;
2909
 	struct nic *nic = tp->nic;
2910
 	uint32_t hi, lo, mac_offset;
2910
 	uint32_t hi, lo, mac_offset;
2911
 
2911
 
2912
-	if (PCI_FUNC(tp->pdev->devfn) == 0)
2912
+	if (PCI_FUNC(tp->pdev->busdevfn) == 0)
2913
 		mac_offset = 0x7c;
2913
 		mac_offset = 0x7c;
2914
 	else
2914
 	else
2915
 		mac_offset = 0xcc;
2915
 		mac_offset = 0xcc;

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

511
 	struct vxge_hw_device_hw_info hw_info;
511
 	struct vxge_hw_device_hw_info hw_info;
512
 	struct vxge_hw_device_version *fw_version;
512
 	struct vxge_hw_device_version *fw_version;
513
 
513
 
514
-	vxge_debug(VXGE_INFO, "vxge_probe for device %02X:%02X.%X\n",
515
-			pdev->bus, PCI_SLOT(pdev->devfn),
516
-			PCI_FUNC(pdev->devfn));
514
+	vxge_debug(VXGE_INFO, "vxge_probe for device " PCI_FMT "\n",
515
+			PCI_ARGS(pdev));
517
 
516
 
518
 	pci_read_config_byte(pdev, PCI_REVISION_ID, &revision);
517
 	pci_read_config_byte(pdev, PCI_REVISION_ID, &revision);
519
 	titan1 = is_titan1(pdev->device, revision);
518
 	titan1 = is_titan1(pdev->device, revision);

+ 10
- 11
src/include/ipxe/pci.h View File

302
 	uint32_t class;
302
 	uint32_t class;
303
 	/** Interrupt number */
303
 	/** Interrupt number */
304
 	uint8_t irq;
304
 	uint8_t irq;
305
-	/** Bus number */
306
-	uint8_t bus;
307
-	/** Device and function number */
308
-	uint8_t devfn;
305
+	/** Bus, device, and function (bus:dev.fn) number */
306
+	uint16_t busdevfn;
309
 	/** Driver for this device */
307
 	/** Driver for this device */
310
 	struct pci_driver *driver;
308
 	struct pci_driver *driver;
311
 	/** Driver-private data
309
 	/** Driver-private data
347
 /** Declare a PCI driver */
345
 /** Declare a PCI driver */
348
 #define __pci_driver __table_entry ( PCI_DRIVERS, 01 )
346
 #define __pci_driver __table_entry ( PCI_DRIVERS, 01 )
349
 
347
 
350
-#define PCI_DEVFN( slot, func )		( ( (slot) << 3 ) | (func) )
351
-#define PCI_SLOT( devfn )		( ( (devfn) >> 3 ) & 0x1f )
352
-#define PCI_FUNC( devfn )		( (devfn) & 0x07 )
353
-#define PCI_BUS( busdevfn )		( (busdevfn) >> 8 )
354
-#define PCI_BUSDEVFN( bus, devfn )	( ( (bus) << 8 ) | (devfn) )
348
+#define PCI_BUS( busdevfn )		( ( (busdevfn) >> 8 ) & 0xff )
349
+#define PCI_SLOT( busdevfn )		( ( (busdevfn) >> 3 ) & 0x1f )
350
+#define PCI_FUNC( busdevfn )		( ( (busdevfn) >> 0 ) & 0x07 )
351
+#define PCI_BUSDEVFN( bus, slot, func )	\
352
+	( ( (bus) << 8 ) | ( (slot) << 3 ) | ( (func) << 0 ) )
355
 
353
 
356
 #define PCI_BASE_CLASS( class )		( (class) >> 16 )
354
 #define PCI_BASE_CLASS( class )		( (class) >> 16 )
357
 #define PCI_SUB_CLASS( class )		( ( (class) >> 8 ) & 0xff )
355
 #define PCI_SUB_CLASS( class )		( ( (class) >> 8 ) & 0xff )
378
 #define PCI_FMT "PCI %02x:%02x.%x"
376
 #define PCI_FMT "PCI %02x:%02x.%x"
379
 
377
 
380
 /** PCI device debug message arguments */
378
 /** PCI device debug message arguments */
381
-#define PCI_ARGS( pci ) \
382
-	(pci)->bus, PCI_SLOT ( (pci)->devfn ), PCI_FUNC ( (pci)->devfn )
379
+#define PCI_ARGS( pci )							\
380
+	PCI_BUS ( (pci)->busdevfn ), PCI_SLOT ( (pci)->busdevfn ),	\
381
+	PCI_FUNC ( (pci)->busdevfn )
383
 
382
 
384
 extern void adjust_pci_device ( struct pci_device *pci );
383
 extern void adjust_pci_device ( struct pci_device *pci );
385
 extern unsigned long pci_bar_start ( struct pci_device *pci,
384
 extern unsigned long pci_bar_start ( struct pci_device *pci,

+ 9
- 10
src/interface/efi/efi_pci.c View File

35
 
35
 
36
 static unsigned long efipci_address ( struct pci_device *pci,
36
 static unsigned long efipci_address ( struct pci_device *pci,
37
 				      unsigned long location ) {
37
 				      unsigned long location ) {
38
-	return EFI_PCI_ADDRESS ( pci->bus, PCI_SLOT ( pci->devfn ),
39
-				 PCI_FUNC ( pci->devfn ),
38
+	return EFI_PCI_ADDRESS ( PCI_BUS ( pci->busdevfn ),
39
+				 PCI_SLOT ( pci->busdevfn ),
40
+				 PCI_FUNC ( pci->busdevfn ),
40
 				 EFIPCI_OFFSET ( location ) );
41
 				 EFIPCI_OFFSET ( location ) );
41
 }
42
 }
42
 
43
 
47
 	if ( ( efirc = efipci->Pci.Read ( efipci, EFIPCI_WIDTH ( location ),
48
 	if ( ( efirc = efipci->Pci.Read ( efipci, EFIPCI_WIDTH ( location ),
48
 					  efipci_address ( pci, location ), 1,
49
 					  efipci_address ( pci, location ), 1,
49
 					  value ) ) != 0 ) {
50
 					  value ) ) != 0 ) {
50
-		DBG ( "EFIPCI config read from %02x:%02x.%x offset %02lx "
51
-		      "failed: %s\n", pci->bus, PCI_SLOT ( pci->devfn ),
52
-		      PCI_FUNC ( pci->devfn ), EFIPCI_OFFSET ( location ),
53
-		      efi_strerror ( efirc ) );
51
+		DBG ( "EFIPCI config read from " PCI_FMT " offset %02lx "
52
+		      "failed: %s\n", PCI_ARGS ( pci ),
53
+		      EFIPCI_OFFSET ( location ), efi_strerror ( efirc ) );
54
 		return -EIO;
54
 		return -EIO;
55
 	}
55
 	}
56
 
56
 
64
 	if ( ( efirc = efipci->Pci.Write ( efipci, EFIPCI_WIDTH ( location ),
64
 	if ( ( efirc = efipci->Pci.Write ( efipci, EFIPCI_WIDTH ( location ),
65
 					   efipci_address ( pci, location ), 1,
65
 					   efipci_address ( pci, location ), 1,
66
 					   &value ) ) != 0 ) {
66
 					   &value ) ) != 0 ) {
67
-		DBG ( "EFIPCI config write to %02x:%02x.%x offset %02lx "
68
-		      "failed: %s\n", pci->bus, PCI_SLOT ( pci->devfn ),
69
-		      PCI_FUNC ( pci->devfn ), EFIPCI_OFFSET ( location ),
70
-		      efi_strerror ( efirc ) );
67
+		DBG ( "EFIPCI config write to " PCI_FMT " offset %02lx "
68
+		      "failed: %s\n", PCI_ARGS ( pci ),
69
+		      EFIPCI_OFFSET ( location ), efi_strerror ( efirc ) );
71
 		return -EIO;
70
 		return -EIO;
72
 	}
71
 	}
73
 
72
 

+ 1
- 1
src/interface/efi/efi_snp.c View File

794
 		( ( unsigned long ) pci_fn ) );
794
 		( ( unsigned long ) pci_fn ) );
795
 
795
 
796
 	/* Look up corresponding network device */
796
 	/* Look up corresponding network device */
797
-	pci_busdevfn = PCI_BUSDEVFN ( pci_bus, PCI_DEVFN ( pci_dev, pci_fn ) );
797
+	pci_busdevfn = PCI_BUSDEVFN ( pci_bus, pci_dev, pci_fn );
798
 	if ( ( netdev = find_netdev_by_location ( BUS_TYPE_PCI,
798
 	if ( ( netdev = find_netdev_by_location ( BUS_TYPE_PCI,
799
 						  pci_busdevfn ) ) == NULL ) {
799
 						  pci_busdevfn ) ) == NULL ) {
800
 		DBGCP ( driver, "SNPDRV %p device %p is not a iPXE network "
800
 		DBGCP ( driver, "SNPDRV %p device %p is not a iPXE network "

Loading…
Cancel
Save