Commit a0fbd4b2 authored by Patrick Mochel's avatar Patrick Mochel

Small driver model/driverfs update.

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