Commit a0fbd4b2 authored by Patrick Mochel's avatar Patrick Mochel

Small driver model/driverfs update.

parent 0a67f33c
......@@ -18,7 +18,10 @@
# define DBG(x...)
#endif
static struct device * device_root;
static struct device device_root = {
bus_id: "root",
name: "System Root",
};
int (*platform_notify)(struct device * dev) = NULL;
int (*platform_notify_remove)(struct device * dev) = NULL;
......@@ -49,9 +52,9 @@ int device_register(struct device *dev)
spin_lock_init(&dev->lock);
atomic_set(&dev->refcount,2);
if (dev != device_root) {
if (dev != &device_root) {
if (!dev->parent)
dev->parent = device_root;
dev->parent = &device_root;
get_device(dev->parent);
list_add_tail(&dev->node,&dev->parent->children);
}
......@@ -117,16 +120,10 @@ void put_device(struct device * dev)
static int __init device_init_root(void)
{
device_root = kmalloc(sizeof(*device_root),GFP_KERNEL);
if (!device_root)
return -ENOMEM;
memset(device_root,0,sizeof(*device_root));
strcpy(device_root->bus_id,"root");
strcpy(device_root->name,"System Root");
return device_register(device_root);
return device_register(&device_root);
}
static int __init device_driver_init(void)
static int __init device_init(void)
{
int error = 0;
......@@ -141,17 +138,12 @@ static int __init device_driver_init(void)
return error;
}
error = device_init_root();
if (error) {
if ((error = device_init_root()))
printk(KERN_ERR "%s: device root init failed!\n", __FUNCTION__);
return error;
}
DBG("DEV: Done Initialising\n");
return error;
}
subsys_initcall(device_driver_init);
subsys_initcall(device_init);
EXPORT_SYMBOL(device_register);
EXPORT_SYMBOL(put_device);
......@@ -279,6 +279,12 @@ int cb_alloc(socket_info_t * s)
pci_readw(dev, PCI_DEVICE_ID, &dev->device);
dev->hdr_type = hdr & 0x7f;
dev->dev.parent = bus->device;
dev->dev.sysdata = bus->sysdata;
strcpy(dev->dev.name, dev->name);
strcpy(dev->dev.bus_id, dev->slot_name);
device_register(&dev->dev);
pci_setup_device(dev);
/* FIXME: Do we need to enable the expansion ROM? */
......
......@@ -245,6 +245,9 @@ driverfs_read_file(struct file *file, char *buf, size_t count, loff_t *ppos)
if (!entry->show)
return 0;
if (count > PAGE_SIZE)
count = PAGE_SIZE;
dev = list_entry(entry->parent,struct device, dir);
page = (unsigned char*)__get_free_page(GFP_KERNEL);
......@@ -260,7 +263,8 @@ driverfs_read_file(struct file *file, char *buf, size_t count, loff_t *ppos)
if (len < 0)
retval = len;
break;
}
} else if (len > count)
len = count;
if (copy_to_user(buf,page,len)) {
retval = -EFAULT;
......
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