9
0
Fork 0

driver: search device and driver based on the bus instead of all

This will allow reduce the number of driver and device to search on.

Signed-off-by: Jean-Christophe PLAGNIOL-VILLARD <plagnioj@jcrosoft.com>
Signed-off-by: Sascha Hauer <s.hauer@pengutronix.de>
This commit is contained in:
Jean-Christophe PLAGNIOL-VILLARD 2012-09-20 07:36:45 +02:00 committed by Sascha Hauer
parent 72b0a6503f
commit ed942bc085
3 changed files with 21 additions and 5 deletions

View File

@ -28,6 +28,9 @@ int bus_register(struct bus_type *bus)
if (get_bus_by_name(bus->name))
return -EEXIST;
INIT_LIST_HEAD(&bus->device_list);
INIT_LIST_HEAD(&bus->driver_list);
list_add_tail(&bus->list, &bus_list);
return 0;

View File

@ -85,8 +85,6 @@ static int match(struct driver_d *drv, struct device_d *dev)
dev->driver = drv;
if (dev->bus != drv->bus)
goto err_out;
if (dev->bus->match(dev, drv))
goto err_out;
if (dev->bus->probe(dev))
@ -122,7 +120,7 @@ int register_device(struct device_d *new_device)
if (new_device->bus == &platform_bus && new_device->resource) {
struct device_d *dev;
for_each_device(dev) {
bus_for_each_device(new_device->bus, dev) {
if (!dev->resource)
continue;
if (dev->resource->start == new_device->resource->start) {
@ -132,12 +130,13 @@ int register_device(struct device_d *new_device)
}
list_add_tail(&new_device->list, &device_list);
list_add_tail(&new_device->bus_list, &new_device->bus->device_list);
INIT_LIST_HEAD(&new_device->children);
INIT_LIST_HEAD(&new_device->cdevs);
INIT_LIST_HEAD(&new_device->parameters);
INIT_LIST_HEAD(&new_device->active);
for_each_driver(drv) {
bus_for_each_driver(new_device->bus, drv) {
if (!match(drv, new_device))
break;
}
@ -169,6 +168,7 @@ int unregister_device(struct device_d *old_dev)
}
list_del(&old_dev->list);
list_del(&old_dev->bus_list);
list_del(&old_dev->active);
/* remove device from parents child list */
@ -222,13 +222,14 @@ int register_driver(struct driver_d *drv)
}
list_add_tail(&drv->list, &driver_list);
list_add_tail(&drv->bus_list, &drv->bus->driver_list);
if (!drv->info)
drv->info = noinfo;
if (!drv->shortinfo)
drv->shortinfo = noshortinfo;
for_each_device(dev)
bus_for_each_device(drv->bus, dev)
match(drv, dev);
return 0;

View File

@ -92,6 +92,7 @@ struct device_d {
struct driver_d *driver; /*! The driver for this device */
struct list_head list; /* The list of all devices */
struct list_head bus_list; /* our bus */
struct list_head children; /* our children */
struct list_head sibling;
struct list_head active; /* The list of all devices which have a driver */
@ -119,6 +120,7 @@ struct driver_d {
const char *name;
struct list_head list;
struct list_head bus_list; /* our bus */
/*! Called if an instance of a device is found */
int (*probe) (struct device_d *);
@ -381,6 +383,8 @@ struct bus_type {
void (*remove)(struct device_d *dev);
struct list_head list;
struct list_head device_list;
struct list_head driver_list;
};
int bus_register(struct bus_type *bus);
@ -391,6 +395,14 @@ extern struct list_head bus_list;
*/
#define for_each_bus(bus) list_for_each_entry(bus, &bus_list, list)
/* Iterate over all devices of a bus
*/
#define bus_for_each_device(bus, dev) list_for_each_entry(dev, &bus->device_list, bus_list)
/* Iterate over all drivers of a bus
*/
#define bus_for_each_driver(bus, drv) list_for_each_entry(drv, &bus->driver_list, bus_list)
extern struct bus_type platform_bus;
struct file_operations {