mirror of
https://github.com/ipxe/ipxe
synced 2025-12-23 21:41:43 +03:00
[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>
This commit is contained in:
@@ -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 );
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user