From 3001575d6007159aabb7b25853a579f961b85b0d Mon Sep 17 00:00:00 2001 From: Augustin Cavalier Date: Tue, 8 Jan 2019 17:18:43 -0500 Subject: [PATCH] freebsd_network: Add child drivers directly rather than finding symbols. This method is much less error-prone than the prior one, as that required the driver structure to have an exported symbol identical to its "name" field, a fact that is usually true but not always (we've had an ifdef in the atheroswifi driver for a while now due to this.) So when we have it, we now just use the driver_t* directly, which should push any of these problems from the run-time stage to the compile-time stage. It's also a significant performance improvement. --- src/libs/compat/freebsd_network/compat.c | 18 ++++++++++++++---- .../compat/freebsd_network/compat/sys/bus.h | 4 +++- src/libs/compat/freebsd_network/driver.c | 4 ++-- 3 files changed, 19 insertions(+), 7 deletions(-) diff --git a/src/libs/compat/freebsd_network/compat.c b/src/libs/compat/freebsd_network/compat.c index 5e07396d82..0d5b6385c3 100644 --- a/src/libs/compat/freebsd_network/compat.c +++ b/src/libs/compat/freebsd_network/compat.c @@ -347,26 +347,29 @@ device_is_alive(device_t device) device_t -device_add_child(device_t parent, const char *name, int unit) +device_add_child_driver(device_t parent, const char* name, driver_t* _driver, + int unit) { device_t child = NULL; - if (name != NULL) { + if (_driver == NULL && name != NULL) { if (strcmp(name, "miibus") == 0) child = new_device(&miibus_driver); else { // find matching driver structure - driver_t **driver; + driver_t** driver; char symbol[128]; snprintf(symbol, sizeof(symbol), "__fbsd_%s_%s", name, parent->driver->name); if (get_image_symbol(find_own_image(), symbol, B_SYMBOL_TYPE_DATA, - (void **)&driver) == B_OK) { + (void**)&driver) == B_OK) { child = new_device(*driver); } else device_printf(parent, "couldn't find symbol %s\n", symbol); } + } else if (_driver != NULL) { + child = new_device(_driver); } else child = new_device(NULL); @@ -391,6 +394,13 @@ device_add_child(device_t parent, const char *name, int unit) } +device_t +device_add_child(device_t parent, const char* name, int unit) +{ + return device_add_child_driver(parent, name, NULL, unit); +} + + /*! Delete the child and all of its children. Detach as necessary. */ int diff --git a/src/libs/compat/freebsd_network/compat/sys/bus.h b/src/libs/compat/freebsd_network/compat/sys/bus.h index 029cc831f9..a327ce4a5a 100644 --- a/src/libs/compat/freebsd_network/compat/sys/bus.h +++ b/src/libs/compat/freebsd_network/compat/sys/bus.h @@ -136,7 +136,9 @@ int device_get_children(device_t dev, device_t **devlistp, int *devcountp); void device_set_ivars(device_t dev, void *); void *device_get_ivars(device_t dev); -device_t device_add_child(device_t dev, const char *name, int unit); +device_t device_add_child(device_t dev, const char* name, int unit); +device_t device_add_child_driver(device_t dev, const char* name, driver_t* driver, + int unit); int device_delete_child(device_t dev, device_t child); int device_is_attached(device_t dev); int device_attach(device_t dev); diff --git a/src/libs/compat/freebsd_network/driver.c b/src/libs/compat/freebsd_network/driver.c index 938334c113..d6ca7ce082 100644 --- a/src/libs/compat/freebsd_network/driver.c +++ b/src/libs/compat/freebsd_network/driver.c @@ -78,9 +78,9 @@ init_root_device(device_t *_root) static status_t -add_child_device(driver_t *driver, device_t root, device_t *_child) +add_child_device(driver_t* driver, device_t root, device_t* _child) { - device_t child = device_add_child(root, driver->name, 0); + device_t child = device_add_child_driver(root, driver->name, driver, 0); if (child == NULL) { return B_ERROR; }