Commit 8f1640cb authored by Patrick Mochel's avatar Patrick Mochel

deivce model: actually compile and use bus drivers

parent cfff1d8f
O_TARGET := base.o O_TARGET := base.o
obj-y := core.o sys.o interface.o fs.o power.o obj-y := core.o sys.o interface.o fs.o power.o bus.o
export-objs := core.o fs.o power.o sys.o export-objs := core.o fs.o power.o sys.o bus.o
include $(TOPDIR)/Rules.make include $(TOPDIR)/Rules.make
...@@ -9,6 +9,10 @@ ...@@ -9,6 +9,10 @@
extern struct device device_root; extern struct device device_root;
extern spinlock_t device_lock; extern spinlock_t device_lock;
extern int bus_add_device(struct device * dev);
extern void bus_remove_device(struct device * dev);
extern int device_create_dir(struct driver_dir_entry * dir, struct driver_dir_entry * parent);
extern int device_make_dir(struct device * dev); extern int device_make_dir(struct device * dev);
extern void device_remove_dir(struct device * dev); extern void device_remove_dir(struct device * dev);
...@@ -10,7 +10,8 @@ ...@@ -10,7 +10,8 @@
#include <linux/device.h> #include <linux/device.h>
#include <linux/module.h> #include <linux/module.h>
#include <linux/errno.h> #include <linux/errno.h>
#include <linux/stat.h>
#include "base.h"
static LIST_HEAD(bus_driver_list); static LIST_HEAD(bus_driver_list);
...@@ -103,10 +104,6 @@ void put_bus(struct bus_type * bus) ...@@ -103,10 +104,6 @@ void put_bus(struct bus_type * bus)
driverfs_remove_dir(&bus->driver_dir); driverfs_remove_dir(&bus->driver_dir);
driverfs_remove_dir(&bus->device_dir); driverfs_remove_dir(&bus->device_dir);
driverfs_remove_dir(&bus->dir); driverfs_remove_dir(&bus->dir);
/* tell the driver it can go away now */
if (bus->release)
bus->release();
} }
static int __init bus_init(void) static int __init bus_init(void)
...@@ -117,7 +114,6 @@ static int __init bus_init(void) ...@@ -117,7 +114,6 @@ static int __init bus_init(void)
subsys_initcall(bus_init); subsys_initcall(bus_init);
EXPORT_SYMBOL(bus_for_each_dev);
EXPORT_SYMBOL(bus_add_device); EXPORT_SYMBOL(bus_add_device);
EXPORT_SYMBOL(bus_remove_device); EXPORT_SYMBOL(bus_remove_device);
EXPORT_SYMBOL(bus_register); EXPORT_SYMBOL(bus_register);
......
...@@ -70,6 +70,8 @@ int device_register(struct device *dev) ...@@ -70,6 +70,8 @@ int device_register(struct device *dev)
if ((error = device_make_dir(dev))) if ((error = device_make_dir(dev)))
goto register_done; goto register_done;
bus_add_device(dev);
/* notify platform of device entry */ /* notify platform of device entry */
if (platform_notify) if (platform_notify)
platform_notify(dev); platform_notify(dev);
...@@ -102,6 +104,8 @@ void put_device(struct device * dev) ...@@ -102,6 +104,8 @@ void put_device(struct device * dev)
if (platform_notify_remove) if (platform_notify_remove)
platform_notify_remove(dev); platform_notify_remove(dev);
bus_remove_device(dev);
/* Tell the driver to clean up after itself. /* Tell the driver to clean up after itself.
* Note that we likely didn't allocate the device, * Note that we likely didn't allocate the device,
* so this is the driver's chance to free that up... * so this is the driver's chance to free that up...
......
...@@ -68,6 +68,13 @@ void device_remove_dir(struct device * dev) ...@@ -68,6 +68,13 @@ void device_remove_dir(struct device * dev)
driverfs_remove_dir(&dev->dir); driverfs_remove_dir(&dev->dir);
} }
int device_create_dir(struct driver_dir_entry * dir, struct driver_dir_entry * parent)
{
INIT_LIST_HEAD(&dir->files);
dir->mode = (S_IFDIR| S_IRWXU | S_IRUGO | S_IXUGO);
return driverfs_create_dir(dir,parent);
}
/** /**
* device_make_dir - create a driverfs directory * device_make_dir - create a driverfs directory
* @name: name of directory * @name: name of directory
...@@ -87,23 +94,20 @@ int device_make_dir(struct device * dev) ...@@ -87,23 +94,20 @@ int device_make_dir(struct device * dev)
int error; int error;
int i; int i;
INIT_LIST_HEAD(&dev->dir.files);
dev->dir.mode = (S_IFDIR| S_IRWXU | S_IRUGO | S_IXUGO);
dev->dir.name = dev->bus_id;
if (dev->parent) if (dev->parent)
parent = &dev->parent->dir; parent = &dev->parent->dir;
dev->dir.name = dev->bus_id;
if ((error = driverfs_create_dir(&dev->dir,parent))) if ((error = device_create_dir(&dev->dir,parent)))
return error; return error;
for (i = 0; (entry = *(device_default_files + i)); i++) { for (i = 0; (entry = *(device_default_files + i)); i++) {
if ((error = device_create_file(dev,entry))) { if ((error = device_create_file(dev,entry))) {
device_remove_dir(dev); device_remove_dir(dev);
return error; break;
} }
} }
return 0; return error;
} }
EXPORT_SYMBOL(device_create_file); EXPORT_SYMBOL(device_create_file);
......
...@@ -63,6 +63,11 @@ struct bus_type { ...@@ -63,6 +63,11 @@ struct bus_type {
list_t node; list_t node;
list_t devices; list_t devices;
list_t drivers;
struct driver_dir_entry dir;
struct driver_dir_entry device_dir;
struct driver_dir_entry driver_dir;
}; };
...@@ -102,6 +107,7 @@ struct device { ...@@ -102,6 +107,7 @@ struct device {
atomic_t refcount; /* refcount to make sure the device atomic_t refcount; /* refcount to make sure the device
* persists for the right amount of time */ * persists for the right amount of time */
struct bus_type * bus; /* type of bus device is on */
struct driver_dir_entry dir; struct driver_dir_entry dir;
struct device_driver *driver; /* which driver has allocated this struct device_driver *driver; /* which driver has allocated this
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment