summaryrefslogtreecommitdiffstats
path: root/src
diff options
context:
space:
mode:
authorMichael Brown2005-04-14 15:44:07 +0200
committerMichael Brown2005-04-14 15:44:07 +0200
commit104880ca19e230ebbe6a4f46fa17e32ff05324f2 (patch)
treed99a776582dfb278218299f88c3ee8fd8203e631 /src
parentSeparate out bus-scanning and device-probing logic. (diff)
downloadipxe-104880ca19e230ebbe6a4f46fa17e32ff05324f2.tar.gz
ipxe-104880ca19e230ebbe6a4f46fa17e32ff05324f2.tar.xz
ipxe-104880ca19e230ebbe6a4f46fa17e32ff05324f2.zip
Tweak API to allow separation of bus-scanning and device-probing logic.
Diffstat (limited to 'src')
-rw-r--r--src/drivers/bus/eisa.c56
-rw-r--r--src/drivers/bus/mca.c49
-rw-r--r--src/drivers/bus/pci.c54
-rw-r--r--src/include/eisa.h6
-rw-r--r--src/include/mca.h5
-rw-r--r--src/include/pci.h5
6 files changed, 85 insertions, 90 deletions
diff --git a/src/drivers/bus/eisa.c b/src/drivers/bus/eisa.c
index 29d1d83d..1cd53c9b 100644
--- a/src/drivers/bus/eisa.c
+++ b/src/drivers/bus/eisa.c
@@ -48,37 +48,22 @@ static int fill_eisa_device ( struct eisa_device *eisa ) {
}
/*
- * Obtain a struct eisa * from a struct dev *
+ * Find an EISA device matching the specified driver
*
- * 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;;
+int find_eisa_device ( struct eisa_device *eisa, struct eisa_driver *driver ) {
+ unsigned int i;
+ /* 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;
}
- eisa->dev = dev;
- return eisa;
-}
-
-/*
- * Find an EISA device matching the specified driver
- *
- */
-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.
+ * left off.
*/
- if ( ! eisa->slot ) {
- eisa->slot = EISA_MIN_SLOT;
- }
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;
}
@@ -123,6 +100,25 @@ int find_eisa_device ( struct eisa_device *eisa, struct eisa_driver *driver ) {
}
/*
+ * 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
*
*/
diff --git a/src/drivers/bus/mca.c b/src/drivers/bus/mca.c
index 1d20a665..f87da8d2 100644
--- a/src/drivers/bus/mca.c
+++ b/src/drivers/bus/mca.c
@@ -49,31 +49,20 @@ static int fill_mca_device ( struct mca_device *mca ) {
}
/*
- * Obtain a struct mca * from a struct dev *
+ * Find an MCA device matching the specified driver
*
- * 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;
+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;
}
- mca->dev = dev;
- return mca;
-}
-
-/*
- * Find an MCA device matching the specified driver
- *
- */
-int find_mca_device ( struct mca_device *mca, struct mca_driver *driver ) {
- unsigned int i;
/* 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;
+}
diff --git a/src/drivers/bus/pci.c b/src/drivers/bus/pci.c
index 034ef114..e9831913 100644
--- a/src/drivers/bus/pci.c
+++ b/src/drivers/bus/pci.c
@@ -110,23 +110,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.
*
* This routine can be called by e.g. the ROM prefix to specify that
@@ -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;
}
@@ -207,6 +188,25 @@ int find_pci_device ( struct pci_device *pci,
}
/*
+ * 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.
*/
unsigned long pci_bar_start ( struct pci_device *pci, unsigned int index ) {
diff --git a/src/include/eisa.h b/src/include/eisa.h
index ed0ccef3..081ce47e 100644
--- a/src/include/eisa.h
+++ b/src/include/eisa.h
@@ -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 */
diff --git a/src/include/mca.h b/src/include/mca.h
index c12b1cab..9115b98d 100644
--- a/src/include/mca.h
+++ b/src/include/mca.h
@@ -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
diff --git a/src/include/pci.h b/src/include/pci.h
index 988259a3..e7ac084b 100644
--- a/src/include/pci.h
+++ b/src/include/pci.h
@@ -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 );