2
0
mirror of https://github.com/xcat2/xNBA.git synced 2024-12-14 15:21:32 +00:00

Speed up PCI bus scanning by skipping fns 1-7 if fn 0 is not present.

This commit is contained in:
Michael Brown 2005-04-16 11:42:56 +00:00
parent 6e5a3858bf
commit e29be5e342
2 changed files with 23 additions and 1 deletions

View File

@ -23,18 +23,39 @@ unsigned int pci_max_bus = 0xff;
* Returns 1 if a device was found, 0 for no device present.
*/
static int fill_pci_device ( struct pci_device *pci ) {
static struct {
uint16_t devfn0;
int is_present;
} cache = { 0, 1 };
uint32_t l;
int reg;
/* Check bus is within range */
if ( PCI_BUS ( pci->busdevfn ) > pci_max_bus )
return 0;
/* Check to see if we've cached the result that this is a
* non-zero function on a non-existent card. This is done to
* increase scan speed by a factor of 8.
*/
if ( ( PCI_FUNC ( pci->busdevfn ) != 0 ) &&
( PCI_FN0 ( pci->busdevfn ) == cache.devfn0 ) &&
( ! cache.is_present ) ) {
return 0;
}
/* Check to see if there's anything physically present.
*/
pci_read_config_dword ( pci, PCI_VENDOR_ID, &l );
/* some broken boards return 0 if a slot is empty: */
if ( ( l == 0xffffffff ) || ( l == 0x00000000 ) ) {
if ( PCI_FUNC ( pci->busdevfn ) == 0 ) {
/* Don't look for subsequent functions if the
* card itself is not present.
*/
cache.devfn0 = pci->busdevfn;
cache.is_present = 0;
}
return 0;
}
pci->vendor = l & 0xffff;
@ -47,7 +68,7 @@ static int fill_pci_device ( struct pci_device *pci ) {
uint16_t save_busdevfn = pci->busdevfn;
uint8_t header_type;
pci->busdevfn &= ~PCI_FUNC ( 0xffff );
pci->busdevfn &= PCI_FN0 ( pci->busdevfn );
pci_read_config_byte ( pci, PCI_HEADER_TYPE, &header_type );
pci->busdevfn = save_busdevfn;

View File

@ -252,6 +252,7 @@ struct pci_device {
#define PCI_BUS(busdevfn) ( ( (busdevfn) >> 8 ) & 0xff )
#define PCI_DEV(busdevfn) ( ( (busdevfn) >> 3 ) & 0x1f )
#define PCI_FUNC(busdevfn) ( (busdevfn) & 0x07 )
#define PCI_FN0(busdevfn) ( (busdevfn) & 0xfff8 )
/*
* An individual PCI device identified by vendor and device IDs