summaryrefslogtreecommitdiffstats
path: root/src
diff options
context:
space:
mode:
authorMichael Brown2005-04-14 15:33:03 +0200
committerMichael Brown2005-04-14 15:33:03 +0200
commitce8dea0dffea9076879bb0d38510c1f5f790820c (patch)
tree27985a7005db6b1a3b39f7fde4538e5790b537c9 /src
parentSplit 3c509.c into 3c509.9 and 3c529.c, with shared code in 3c5x9.c. (diff)
downloadipxe-ce8dea0dffea9076879bb0d38510c1f5f790820c.tar.gz
ipxe-ce8dea0dffea9076879bb0d38510c1f5f790820c.tar.xz
ipxe-ce8dea0dffea9076879bb0d38510c1f5f790820c.zip
Separate out bus-scanning and device-probing logic.
Diffstat (limited to 'src')
-rw-r--r--src/core/dev.c35
-rw-r--r--src/core/main.c15
-rw-r--r--src/include/dev.h24
3 files changed, 62 insertions, 12 deletions
diff --git a/src/core/dev.c b/src/core/dev.c
index 0f9936a0f..002fa7aa4 100644
--- a/src/core/dev.c
+++ b/src/core/dev.c
@@ -2,6 +2,20 @@
#include "stddef.h"
#include "dev.h"
+/*
+ * Each driver specifies a name, the bus-scanning function
+ * (find_bus_boot_device) that it wants to use, a driver information
+ * structure (bus_driver) containing e.g. device IDs to be passed to
+ * find_bus_boot_device, and a probe function (probe) to be called
+ * whenever a suitable device is found.
+ *
+ * The generic device-probing code knows nothing about particular bus
+ * types; it simply passes the driver information structure
+ * (bus_driver) to the bus-scanning function (find_bus_boot_device),
+ * then passes the result of that function (if not NULL) to the probe
+ * function (probe).
+ */
+
/* Defined by linker */
extern struct boot_driver boot_drivers[];
extern struct boot_driver boot_drivers_end[];
@@ -19,19 +33,30 @@ void print_drivers ( void ) {
}
/* Get the next available boot device */
-int probe ( struct dev *dev ) {
-
+int find_boot_device ( struct dev *dev ) {
for ( ; boot_driver < boot_drivers_end ; boot_driver++ ) {
- dev->name = "unknown";
- if ( boot_driver->probe ( dev ) )
+ dev->driver = boot_driver;
+ dev->name = boot_driver->name;
+ DBG ( "Probing driver %s...\n", dev->name );
+ if ( boot_driver->find_bus_boot_device ( dev,
+ boot_driver->bus_driver ) ) {
+ DBG ( "Found device %s (ID %hhx:%hx:%hx)\n",
+ dev->name, dev->devid->bus_type,
+ dev->devid->vendor_id, dev->devid->device_id );
return 1;
+ }
}
-
+
/* No more boot devices found */
boot_driver = boot_drivers;
return 0;
}
+/* Probe the boot device */
+int probe ( struct dev *dev ) {
+ return dev->driver->probe ( dev, dev->bus );
+}
+
/* Disable a device */
void disable ( struct dev *dev ) {
if ( dev->dev_op ) {
diff --git a/src/core/main.c b/src/core/main.c
index 3cc777a8e..bf0a4b0e3 100644
--- a/src/core/main.c
+++ b/src/core/main.c
@@ -144,7 +144,7 @@ static int initialized;
/* Global instance of the current boot device */
-DEV_BUS(struct {}, dev_bus);
+DEV_BUS(struct bus_device, dev_bus);
struct dev dev = {
.bus = &dev_bus,
};
@@ -181,8 +181,17 @@ int main ( void ) {
for ( ; ; disable ( &dev ), call_reset_fns() ) {
/* Get next boot device */
- if ( ! probe ( &dev ) ) {
+ if ( ! find_boot_device ( &dev ) ) {
/* Reached end of device list */
+ printf ( "No more boot devices\n" );
+ continue;
+ }
+
+ /* Probe boot device */
+ if ( ! probe ( &dev ) ) {
+ /* Device found on bus, but probe failed */
+ printf ( "Probe failed on %s, trying next device\n",
+ dev.name );
continue;
}
@@ -192,12 +201,14 @@ int main ( void ) {
/* Load configuration (e.g. DHCP) */
if ( ! load_configuration ( &dev ) ) {
/* DHCP failed */
+ printf ( "Could not configure device %s\n", dev.name );
continue;
}
/* Load image */
if ( ! load ( &dev ) )
/* Load failed */
+ printf ( "Could not boot from device %s\n", dev.name );
continue;
}
diff --git a/src/include/dev.h b/src/include/dev.h
index 73a4ca65e..9ade0e1fe 100644
--- a/src/include/dev.h
+++ b/src/include/dev.h
@@ -23,11 +23,12 @@ struct dev {
struct dev_operations *dev_op;
const char *name;
struct dev_id devid; /* device ID string (sent to DHCP server) */
+ struct boot_driver *driver; /* driver being used for boot */
/* Pointer to bus information for device. Whatever sets up
* the struct dev must make sure that this points to a buffer
* large enough for the required struct <bus>_device.
*/
- void *bus;
+ struct bus_device *bus;
/* All possible device types */
union {
struct nic nic;
@@ -49,20 +50,33 @@ struct dev_operations {
int ( *load ) ( struct dev * );
};
+/*
+ * Table to describe a bootable device driver. See comments in dev.c
+ * for an explanation.
+ *
+ */
+struct bus_device {};
+struct bus_driver {};
struct boot_driver {
char *name;
- int (*probe) ( struct dev * );
+ struct bus_device * ( *find_bus_boot_device ) ( struct dev *dev,
+ struct bus_driver *driver );
+ struct bus_driver *bus_driver;
+ int ( *probe ) ( struct dev *dev, struct bus_device *bus_device );
};
-#define BOOT_DRIVER( driver_name, probe_func ) \
+#define BOOT_DRIVER( _name, _find_bus_boot_device, _bus_driver, _probe ) \
static struct boot_driver boot_driver_ ## probe_func \
__attribute__ ((used,__section__(".boot_drivers"))) = { \
- .name = driver_name, \
- .probe = probe_func, \
+ .name = _name, \
+ .find_bus_boot_device = ( void * ) _find_bus_boot_device, \
+ .bus_driver = ( void * ) _bus_driver, \
+ .probe = ( void * ) _probe, \
};
/* Functions in dev.c */
extern void print_drivers ( void );
+extern int find_boot_device ( struct dev *dev );
extern int probe ( struct dev *dev );
extern void disable ( struct dev *dev );
static inline void print_info ( struct dev *dev ) {