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

Tweak API to allow separation of bus-scanning and device-probing logic.

This commit is contained in:
Michael Brown 2005-04-14 13:44:07 +00:00
parent ce8dea0dff
commit 104880ca19
6 changed files with 89 additions and 94 deletions

View File

@ -47,23 +47,6 @@ static int fill_eisa_device ( struct eisa_device *eisa ) {
return 1;
}
/*
* Obtain a struct eisa * from a struct dev *
*
* If dev has not previously been used for an EISA device scan, blank
* out struct eisa
*/
struct eisa_device * eisa_device ( struct dev *dev ) {
struct eisa_device *eisa = dev->bus;;
if ( eisa->magic != eisa_magic ) {
memset ( eisa, 0, sizeof ( *eisa ) );
eisa->magic = eisa_magic;
}
eisa->dev = dev;
return eisa;
}
/*
* Find an EISA device matching the specified driver
*
@ -71,14 +54,16 @@ struct eisa_device * eisa_device ( struct dev *dev ) {
int find_eisa_device ( struct eisa_device *eisa, struct eisa_driver *driver ) {
unsigned int i;
/* Iterate through all possible EISA slots, starting where we
* left off. If eisa->slot is zero (which it will be if we
* have a zeroed structure), start from slot EISA_MIN_SLOT,
* since slot 0 doesn't exist.
*/
if ( ! eisa->slot ) {
/* Initialise struct eisa if it's the first time it's been used. */
if ( eisa->magic != eisa_magic ) {
memset ( eisa, 0, sizeof ( *eisa ) );
eisa->magic = eisa_magic;
eisa->slot = EISA_MIN_SLOT;
}
/* Iterate through all possible EISA slots, starting where we
* left off.
*/
for ( ; eisa->slot <= EISA_MAX_SLOT ; eisa->slot++ ) {
/* If we've already used this device, skip it */
if ( eisa->already_tried ) {
@ -102,15 +87,7 @@ int find_eisa_device ( struct eisa_device *eisa, struct eisa_driver *driver ) {
id->name, driver->name,
isa_id_string ( eisa->mfg_id,
eisa->prod_id ) );
if ( eisa->dev ) {
eisa->dev->name = driver->name;
eisa->dev->devid.bus_type
= ISA_BUS_TYPE;
eisa->dev->devid.vendor_id
= eisa->mfg_id;
eisa->dev->devid.device_id
= eisa->prod_id;
}
eisa->name = id->name;
eisa->already_tried = 1;
return 1;
}
@ -122,6 +99,25 @@ int find_eisa_device ( struct eisa_device *eisa, struct eisa_driver *driver ) {
return 0;
}
/*
* Find the next EISA device that can be used to boot using the
* specified driver.
*
*/
int find_eisa_boot_device ( struct dev *dev, struct eisa_driver *driver ) {
struct eisa_device *eisa = ( struct eisa_device * )dev->bus;
if ( ! find_eisa_device ( eisa, driver ) )
return 0;
dev->name = eisa->name;
dev->devid.bus_type = ISA_BUS_TYPE;
dev->devid.vendor_id = eisa->mfg_id;
dev->devid.device_id = eisa->prod_id;
return 1;
}
/*
* Reset and enable an EISA device
*

View File

@ -48,23 +48,6 @@ static int fill_mca_device ( struct mca_device *mca ) {
return 1;
}
/*
* Obtain a struct mca * from a struct dev *
*
* If dev has not previously been used for an MCA device scan, blank
* out struct mca
*/
struct mca_device * mca_device ( struct dev *dev ) {
struct mca_device *mca = dev->bus;
if ( mca->magic != mca_magic ) {
memset ( mca, 0, sizeof ( *mca ) );
mca->magic = mca_magic;
}
mca->dev = dev;
return mca;
}
/*
* Find an MCA device matching the specified driver
*
@ -72,8 +55,14 @@ struct mca_device * mca_device ( struct dev *dev ) {
int find_mca_device ( struct mca_device *mca, struct mca_driver *driver ) {
unsigned int i;
/* Initialise struct mca if it's the first time it's been used. */
if ( mca->magic != mca_magic ) {
memset ( mca, 0, sizeof ( *mca ) );
mca->magic = mca_magic;
}
/* Iterate through all possible MCA slots, starting where we
* left off/
* left off
*/
for ( ; mca->slot < MCA_MAX_SLOT_NR ; mca->slot++ ) {
/* If we've already used this device, skip it */
@ -94,14 +83,7 @@ int find_mca_device ( struct mca_device *mca, struct mca_driver *driver ) {
if ( MCA_ID ( mca ) == id->id ) {
DBG ( "Device %s (driver %s) matches ID %hx\n",
id->name, driver->name, id->id );
if ( mca->dev ) {
mca->dev->name = driver->name;
mca->dev->devid.bus_type
= MCA_BUS_TYPE;
mca->dev->devid.vendor_id
= GENERIC_MCA_VENDOR;
mca->dev->devid.device_id = id->id;
}
mca->name = id->name;
mca->already_tried = 1;
return 1;
}
@ -112,3 +94,22 @@ int find_mca_device ( struct mca_device *mca, struct mca_driver *driver ) {
mca->slot = 0;
return 0;
}
/*
* Find the next MCA device that can be used to boot using the
* specified driver.
*
*/
int find_mca_boot_device ( struct dev *dev, struct mca_driver *driver ) {
struct mca_device *mca = ( struct mca_device * )dev->bus;
if ( ! find_mca_device ( mca, driver ) )
return 0;
dev->name = mca->name;
dev->devid.bus_type = MCA_BUS_TYPE;
dev->devid.vendor_id = GENERIC_MCA_VENDOR;
dev->devid.device_id = MCA_ID ( mca );
return 1;
}

View File

@ -109,23 +109,6 @@ void adjust_pci_device ( struct pci_device *pci ) {
}
}
/*
* Obtain a struct pci * from a struct dev *
*
* If dev has not previously been used for a PCI device scan, blank
* out struct pci
*/
struct pci_device * pci_device ( struct dev *dev ) {
struct pci_device *pci = dev->bus;
if ( pci->magic != pci_magic ) {
memset ( pci, 0, sizeof ( *pci ) );
pci->magic = pci_magic;
}
pci->dev = dev;
return pci;
}
/*
* Set PCI device to use.
*
@ -148,6 +131,12 @@ int find_pci_device ( struct pci_device *pci,
struct pci_driver *driver ) {
int i;
/* Initialise struct pci if it's the first time it's been used. */
if ( pci->magic != pci_magic ) {
memset ( pci, 0, sizeof ( *pci ) );
pci->magic = pci_magic;
}
/* Iterate through all possible PCI bus:dev.fn combinations,
* starting where we left off.
*/
@ -166,19 +155,12 @@ int find_pci_device ( struct pci_device *pci,
/* Fix up PCI device */
adjust_pci_device ( pci );
/* Fill in dev structure, if present */
if ( pci->dev ) {
pci->dev->name = driver->name;
pci->dev->devid.bus_type = PCI_BUS_TYPE;
pci->dev->devid.vendor_id = pci->vendor;
pci->dev->devid.device_id = pci->dev_id;
}
/* If driver has a class, and class matches, use it */
if ( driver->class &&
( driver->class == pci->class ) ) {
DBG ( "Driver %s matches class %hx\n",
driver->name, driver->class );
pci->name = driver->name;
pci->already_tried = 1;
return 1;
}
@ -192,8 +174,7 @@ int find_pci_device ( struct pci_device *pci,
DBG ( "Device %s (driver %s) matches "
"ID %hx:%hx\n", id->name, driver->name,
id->vendor, id->dev_id );
if ( pci->dev )
pci->dev->name = id->name;
pci->name = id->name;
pci->already_tried = 1;
return 1;
}
@ -206,6 +187,25 @@ int find_pci_device ( struct pci_device *pci,
return 0;
}
/*
* Find the next PCI device that can be used to boot using the
* specified driver.
*
*/
int find_pci_boot_device ( struct dev *dev, struct pci_driver *driver ) {
struct pci_device *pci = ( struct pci_device * )dev->bus;
if ( ! find_pci_device ( pci, driver ) )
return 0;
dev->name = pci->name;
dev->devid.bus_type = PCI_BUS_TYPE;
dev->devid.vendor_id = pci->vendor;
dev->devid.device_id = pci->dev_id;
return 1;
}
/*
* Find the start of a pci resource.
*/

View File

@ -25,10 +25,9 @@
* A physical EISA device
*
*/
struct dev;
struct eisa_device {
char *magic; /* must be first */
struct dev *dev;
const char *name;
unsigned int slot;
uint16_t ioaddr;
uint16_t mfg_id;
@ -69,9 +68,10 @@ struct eisa_driver {
* Functions in eisa.c
*
*/
extern struct eisa_device * eisa_device ( struct dev *dev );
extern int find_eisa_device ( struct eisa_device *eisa,
struct eisa_driver *driver );
extern int find_eisa_boot_device ( struct dev *dev,
struct eisa_driver *driver );
extern void enable_eisa_device ( struct eisa_device *eisa );
#endif /* EISA_H */

View File

@ -26,10 +26,9 @@
* A physical MCA device
*
*/
struct dev;
struct mca_device {
char *magic; /* must be first */
struct dev *dev;
const char *name;
unsigned int slot;
unsigned char pos[8];
int already_tried;
@ -69,8 +68,8 @@ struct mca_driver {
* Functions in mca.c
*
*/
extern struct mca_device * mca_device ( struct dev *dev );
extern int find_mca_device ( struct mca_device *mca,
struct mca_driver *driver );
extern int find_mca_boot_device ( struct dev *dev, struct mca_driver *driver );
#endif

View File

@ -236,10 +236,9 @@
* A physical PCI device
*
*/
struct dev;
struct pci_device {
char * magic; /* must be first */
struct dev * dev;
const char * name;
uint32_t membase; /* BAR 1 */
uint32_t ioaddr; /* first IO BAR */
uint16_t vendor, dev_id;
@ -322,9 +321,9 @@ extern unsigned long pci_bus_base ( struct pci_device *dev );
* Functions in pci.c
*
*/
extern struct pci_device * pci_device ( struct dev *dev );
extern int find_pci_device ( struct pci_device *pci,
struct pci_driver *driver );
extern int find_pci_boot_device ( struct dev *dev, struct pci_driver *driver );
extern void adjust_pci_device ( struct pci_device *pci );
extern unsigned long pci_bar_start ( struct pci_device *pci,
unsigned int bar );