diff options
author | Michael Brown <mcb30@ipxe.org> | 2011-02-09 00:32:58 +0000 |
---|---|---|
committer | Michael Brown <mcb30@ipxe.org> | 2011-02-17 01:25:11 +0000 |
commit | f9b3fae8d46a6b1862b3f5b02490e5a8c224286f (patch) | |
tree | 1862f41cd2b7ab031780881ed953acc647d38114 /src/drivers/bus | |
parent | 00f5ba701fe1e43a28a15c5ffc626ce671ec65cb (diff) | |
download | ipxe-f9b3fae8d46a6b1862b3f5b02490e5a8c224286f.tar.gz |
[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>
Diffstat (limited to 'src/drivers/bus')
-rw-r--r-- | src/drivers/bus/pci.c | 117 |
1 files changed, 57 insertions, 60 deletions
diff --git a/src/drivers/bus/pci.c b/src/drivers/bus/pci.c index 3ff544401..e92f11b2f 100644 --- a/src/drivers/bus/pci.c +++ b/src/drivers/bus/pci.c @@ -228,75 +228,72 @@ static void pci_remove ( struct pci_device *pci ) { */ static int pcibus_probe ( struct root_device *rootdev ) { struct pci_device *pci = NULL; - unsigned int max_bus; - unsigned int bus; - unsigned int devfn; + unsigned int num_bus; + unsigned int busdevfn; uint8_t hdrtype = 0; uint32_t tmp; int rc; - max_bus = pci_max_bus(); - for ( bus = 0 ; bus <= max_bus ; bus++ ) { - for ( devfn = 0 ; devfn <= 0xff ; devfn++ ) { + num_bus = ( pci_max_bus() + 1 ); + for ( busdevfn = 0 ; busdevfn < PCI_BUSDEVFN ( num_bus, 0, 0 ) ; + busdevfn++ ) { - /* Allocate struct pci_device */ - if ( ! pci ) - pci = malloc ( sizeof ( *pci ) ); - if ( ! pci ) { - rc = -ENOMEM; - goto err; - } - memset ( pci, 0, sizeof ( *pci ) ); - pci->bus = bus; - pci->devfn = devfn; + /* Allocate struct pci_device */ + if ( ! pci ) + pci = malloc ( sizeof ( *pci ) ); + if ( ! pci ) { + rc = -ENOMEM; + goto err; + } + memset ( pci, 0, sizeof ( *pci ) ); + pci->busdevfn = busdevfn; - /* Skip all but the first function on - * non-multifunction cards - */ - if ( PCI_FUNC ( devfn ) == 0 ) { - pci_read_config_byte ( pci, PCI_HEADER_TYPE, - &hdrtype ); - } else if ( ! ( hdrtype & 0x80 ) ) { - continue; - } + /* Skip all but the first function on + * non-multifunction cards + */ + if ( PCI_FUNC ( busdevfn ) == 0 ) { + pci_read_config_byte ( pci, PCI_HEADER_TYPE, + &hdrtype ); + } else if ( ! ( hdrtype & 0x80 ) ) { + continue; + } - /* Check for physical device presence */ - pci_read_config_dword ( pci, PCI_VENDOR_ID, &tmp ); - if ( ( tmp == 0xffffffff ) || ( tmp == 0 ) ) - continue; + /* Check for physical device presence */ + pci_read_config_dword ( pci, PCI_VENDOR_ID, &tmp ); + if ( ( tmp == 0xffffffff ) || ( tmp == 0 ) ) + continue; - /* Populate struct pci_device */ - pci->vendor = ( tmp & 0xffff ); - pci->device = ( tmp >> 16 ); - pci_read_config_dword ( pci, PCI_REVISION, &tmp ); - pci->class = ( tmp >> 8 ); - pci_read_config_byte ( pci, PCI_INTERRUPT_LINE, - &pci->irq ); - pci_read_bases ( pci ); + /* Populate struct pci_device */ + pci->vendor = ( tmp & 0xffff ); + pci->device = ( tmp >> 16 ); + pci_read_config_dword ( pci, PCI_REVISION, &tmp ); + pci->class = ( tmp >> 8 ); + pci_read_config_byte ( pci, PCI_INTERRUPT_LINE, + &pci->irq ); + pci_read_bases ( pci ); - /* Add to device hierarchy */ - snprintf ( pci->dev.name, sizeof ( pci->dev.name ), - "PCI%02x:%02x.%x", bus, - PCI_SLOT ( devfn ), PCI_FUNC ( devfn ) ); - pci->dev.desc.bus_type = BUS_TYPE_PCI; - pci->dev.desc.location = PCI_BUSDEVFN (bus, devfn); - pci->dev.desc.vendor = pci->vendor; - pci->dev.desc.device = pci->device; - pci->dev.desc.class = pci->class; - pci->dev.desc.ioaddr = pci->ioaddr; - pci->dev.desc.irq = pci->irq; - pci->dev.parent = &rootdev->dev; - list_add ( &pci->dev.siblings, &rootdev->dev.children); - INIT_LIST_HEAD ( &pci->dev.children ); - - /* Look for a driver */ - if ( pci_probe ( pci ) == 0 ) { - /* pcidev registered, we can drop our ref */ - pci = NULL; - } else { - /* Not registered; re-use struct pci_device */ - list_del ( &pci->dev.siblings ); - } + /* Add to device hierarchy */ + snprintf ( pci->dev.name, sizeof ( pci->dev.name ), + "PCI%02x:%02x.%x", PCI_BUS ( busdevfn ), + PCI_SLOT ( busdevfn ), PCI_FUNC ( busdevfn ) ); + pci->dev.desc.bus_type = BUS_TYPE_PCI; + pci->dev.desc.location = pci->busdevfn; + pci->dev.desc.vendor = pci->vendor; + pci->dev.desc.device = pci->device; + pci->dev.desc.class = pci->class; + pci->dev.desc.ioaddr = pci->ioaddr; + pci->dev.desc.irq = pci->irq; + pci->dev.parent = &rootdev->dev; + list_add ( &pci->dev.siblings, &rootdev->dev.children); + INIT_LIST_HEAD ( &pci->dev.children ); + + /* Look for a driver */ + if ( pci_probe ( pci ) == 0 ) { + /* pcidev registered, we can drop our ref */ + pci = NULL; + } else { + /* Not registered; re-use struct pci_device */ + list_del ( &pci->dev.siblings ); } } |