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.
This commit is contained in:
Augustin Cavalier 2019-01-08 17:18:43 -05:00
parent 4947d1a8c7
commit 3001575d60
3 changed files with 19 additions and 7 deletions

View File

@ -347,26 +347,29 @@ device_is_alive(device_t device)
device_t 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; device_t child = NULL;
if (name != NULL) { if (_driver == NULL && name != NULL) {
if (strcmp(name, "miibus") == 0) if (strcmp(name, "miibus") == 0)
child = new_device(&miibus_driver); child = new_device(&miibus_driver);
else { else {
// find matching driver structure // find matching driver structure
driver_t **driver; driver_t** driver;
char symbol[128]; char symbol[128];
snprintf(symbol, sizeof(symbol), "__fbsd_%s_%s", name, snprintf(symbol, sizeof(symbol), "__fbsd_%s_%s", name,
parent->driver->name); parent->driver->name);
if (get_image_symbol(find_own_image(), symbol, B_SYMBOL_TYPE_DATA, if (get_image_symbol(find_own_image(), symbol, B_SYMBOL_TYPE_DATA,
(void **)&driver) == B_OK) { (void**)&driver) == B_OK) {
child = new_device(*driver); child = new_device(*driver);
} else } else
device_printf(parent, "couldn't find symbol %s\n", symbol); device_printf(parent, "couldn't find symbol %s\n", symbol);
} }
} else if (_driver != NULL) {
child = new_device(_driver);
} else } else
child = new_device(NULL); 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. /*! Delete the child and all of its children. Detach as necessary.
*/ */
int int

View File

@ -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_set_ivars(device_t dev, void *);
void *device_get_ivars(device_t dev); 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_delete_child(device_t dev, device_t child);
int device_is_attached(device_t dev); int device_is_attached(device_t dev);
int device_attach(device_t dev); int device_attach(device_t dev);

View File

@ -78,9 +78,9 @@ init_root_device(device_t *_root)
static status_t 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) { if (child == NULL) {
return B_ERROR; return B_ERROR;
} }