Parcourir la 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 il y a 13 ans
Parent
révision
f9b3fae8d4

+ 4
- 3
src/arch/i386/drivers/net/undi.c Voir le fichier

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

+ 2
- 3
src/arch/i386/interface/pcbios/pcibios.c Voir le fichier

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

+ 2
- 2
src/arch/x86/core/pcidirect.c Voir le fichier

@@ -34,8 +34,8 @@ FILE_LICENCE ( GPL2_OR_LATER );
34 34
  * @v where	Location within PCI configuration space
35 35
  */
36 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 41
 PROVIDE_PCIAPI_INLINE ( direct, pci_max_bus );

+ 57
- 60
src/drivers/bus/pci.c Voir le fichier

@@ -228,75 +228,72 @@ static void pci_remove ( struct pci_device *pci ) {
228 228
  */
229 229
 static int pcibus_probe ( struct root_device *rootdev ) {
230 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 233
 	uint8_t hdrtype = 0;
235 234
 	uint32_t tmp;
236 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 Voir le fichier

@@ -1792,9 +1792,8 @@ static int phantom_map_crb ( struct phantom_nic *phantom,
1792 1792
 
1793 1793
 	bar0_start = pci_bar_start ( pci, PCI_BASE_ADDRESS_0 );
1794 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 1798
 	if ( ! bar0_start ) {
1800 1799
 		DBGC ( phantom, "Phantom %p BAR not assigned; ignoring\n",
@@ -2057,7 +2056,7 @@ static int phantom_probe ( struct pci_device *pci,
2057 2056
 	pci_set_drvdata ( pci, netdev );
2058 2057
 	netdev->dev = &pci->dev;
2059 2058
 	memset ( phantom, 0, sizeof ( *phantom ) );
2060
-	phantom->port = PCI_FUNC ( pci->devfn );
2059
+	phantom->port = PCI_FUNC ( pci->busdevfn );
2061 2060
 	assert ( phantom->port < PHN_MAX_NUM_PORTS );
2062 2061
 	settings_init ( &phantom->settings,
2063 2062
 			&phantom_settings_operations,
@@ -2074,16 +2073,19 @@ static int phantom_probe ( struct pci_device *pci,
2074 2073
 	 * B2 will have this fixed; remove this hack when B1 is no
2075 2074
 	 * longer in use.
2076 2075
 	 */
2077
-	if ( PCI_FUNC ( pci->devfn ) == 0 ) {
2076
+	if ( PCI_FUNC ( pci->busdevfn ) == 0 ) {
2078 2077
 		unsigned int i;
2079 2078
 		for ( i = 0 ; i < 8 ; i++ ) {
2080 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 2083
 			pci_read_config_dword ( pci, 0xc8, &temp );
2083 2084
 			pci_read_config_dword ( pci, 0xc8, &temp );
2084 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 2091
 	/* Initialise the command PEG */

+ 1
- 1
src/drivers/net/tg3.c Voir le fichier

@@ -2909,7 +2909,7 @@ static int  tg3_get_device_address(struct tg3 *tp)
2909 2909
 	struct nic *nic = tp->nic;
2910 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 2913
 		mac_offset = 0x7c;
2914 2914
 	else
2915 2915
 		mac_offset = 0xcc;

+ 2
- 3
src/drivers/net/vxge/vxge_main.c Voir le fichier

@@ -511,9 +511,8 @@ vxge_probe(struct pci_device *pdev, const struct pci_device_id *id __unused)
511 511
 	struct vxge_hw_device_hw_info hw_info;
512 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 517
 	pci_read_config_byte(pdev, PCI_REVISION_ID, &revision);
519 518
 	titan1 = is_titan1(pdev->device, revision);

+ 10
- 11
src/include/ipxe/pci.h Voir le fichier

@@ -302,10 +302,8 @@ struct pci_device {
302 302
 	uint32_t class;
303 303
 	/** Interrupt number */
304 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 307
 	/** Driver for this device */
310 308
 	struct pci_driver *driver;
311 309
 	/** Driver-private data
@@ -347,11 +345,11 @@ struct pci_driver {
347 345
 /** Declare a PCI driver */
348 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 354
 #define PCI_BASE_CLASS( class )		( (class) >> 16 )
357 355
 #define PCI_SUB_CLASS( class )		( ( (class) >> 8 ) & 0xff )
@@ -378,8 +376,9 @@ struct pci_driver {
378 376
 #define PCI_FMT "PCI %02x:%02x.%x"
379 377
 
380 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 383
 extern void adjust_pci_device ( struct pci_device *pci );
385 384
 extern unsigned long pci_bar_start ( struct pci_device *pci,

+ 9
- 10
src/interface/efi/efi_pci.c Voir le fichier

@@ -35,8 +35,9 @@ EFI_REQUIRE_PROTOCOL ( EFI_PCI_ROOT_BRIDGE_IO_PROTOCOL, &efipci );
35 35
 
36 36
 static unsigned long efipci_address ( struct pci_device *pci,
37 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 41
 				 EFIPCI_OFFSET ( location ) );
41 42
 }
42 43
 
@@ -47,10 +48,9 @@ int efipci_read ( struct pci_device *pci, unsigned long location,
47 48
 	if ( ( efirc = efipci->Pci.Read ( efipci, EFIPCI_WIDTH ( location ),
48 49
 					  efipci_address ( pci, location ), 1,
49 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 54
 		return -EIO;
55 55
 	}
56 56
 
@@ -64,10 +64,9 @@ int efipci_write ( struct pci_device *pci, unsigned long location,
64 64
 	if ( ( efirc = efipci->Pci.Write ( efipci, EFIPCI_WIDTH ( location ),
65 65
 					   efipci_address ( pci, location ), 1,
66 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 70
 		return -EIO;
72 71
 	}
73 72
 

+ 1
- 1
src/interface/efi/efi_snp.c Voir le fichier

@@ -794,7 +794,7 @@ efi_snp_netdev ( EFI_DRIVER_BINDING_PROTOCOL *driver, EFI_HANDLE device ) {
794 794
 		( ( unsigned long ) pci_fn ) );
795 795
 
796 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 798
 	if ( ( netdev = find_netdev_by_location ( BUS_TYPE_PCI,
799 799
 						  pci_busdevfn ) ) == NULL ) {
800 800
 		DBGCP ( driver, "SNPDRV %p device %p is not a iPXE network "

Chargement…
Annuler
Enregistrer