Commit d7dce5e3 authored by Patrick Mochel's avatar Patrick Mochel

driver model: remove remaining driverfs glue.

parent 99af1a94
......@@ -10,44 +10,15 @@ extern struct list_head global_device_list;
extern spinlock_t device_lock;
extern struct semaphore device_sem;
extern struct device * get_device_locked(struct device *);
extern int bus_add_device(struct device * dev);
extern void bus_remove_device(struct device * dev);
extern int device_make_dir(struct device * dev);
extern void device_remove_dir(struct device * dev);
extern int bus_make_dir(struct bus_type * bus);
extern void bus_remove_dir(struct bus_type * bus);
extern int bus_add_driver(struct device_driver *);
extern void bus_remove_driver(struct device_driver *);
extern int driver_make_dir(struct device_driver * drv);
extern void driver_remove_dir(struct device_driver * drv);
extern int device_bus_link(struct device * dev);
extern void device_remove_symlink(struct driver_dir_entry * dir, const char * name);
extern int devclass_make_dir(struct device_class *);
extern void devclass_remove_dir(struct device_class *);
extern int devclass_drv_link(struct device_driver *);
extern void devclass_drv_unlink(struct device_driver *);
extern int devclass_dev_link(struct device_class *, struct device *);
extern void devclass_dev_unlink(struct device_class *, struct device *);
extern int devclass_add_device(struct device *);
extern void devclass_remove_device(struct device *);
extern int intf_make_dir(struct device_interface *);
extern void intf_remove_dir(struct device_interface *);
extern int intf_dev_link(struct intf_data *);
extern void intf_dev_unlink(struct intf_data *);
extern int interface_add(struct device_class *, struct device *);
extern void interface_remove(struct device_class *, struct device *);
......
......@@ -380,7 +380,6 @@ void put_bus(struct bus_type * bus)
list_del_init(&bus->node);
spin_unlock(&device_lock);
WARN_ON(bus->present);
bus_remove_dir(bus);
}
int bus_register(struct bus_type * bus)
......@@ -409,11 +408,7 @@ int bus_register(struct bus_type * bus)
spin_unlock(&device_lock);
pr_debug("bus type '%s' registered\n",bus->name);
/* give it some driverfs entities */
bus_make_dir(bus);
put_bus(bus);
return 0;
}
......@@ -424,6 +419,9 @@ void bus_unregister(struct bus_type * bus)
spin_unlock(&device_lock);
pr_debug("bus %s: unregistering\n",bus->name);
subsystem_unregister(&bus->drvsubsys);
subsystem_unregister(&bus->devsubsys);
subsystem_unregister(&bus->subsys);
put_bus(bus);
}
......
......@@ -49,28 +49,28 @@ static struct subsystem class_subsys = {
};
int devclass_dev_link(struct device_class * cls, struct device * dev)
static int devclass_dev_link(struct device_class * cls, struct device * dev)
{
char linkname[16];
snprintf(linkname,16,"%u",dev->class_num);
return sysfs_create_link(&cls->devsubsys.kobj,&dev->kobj,linkname);
}
void devclass_dev_unlink(struct device_class * cls, struct device * dev)
static void devclass_dev_unlink(struct device_class * cls, struct device * dev)
{
char linkname[16];
snprintf(linkname,16,"%u",dev->class_num);
sysfs_remove_link(&cls->devsubsys.kobj,linkname);
}
int devclass_drv_link(struct device_driver * drv)
static int devclass_drv_link(struct device_driver * drv)
{
char name[KOBJ_NAME_LEN * 3];
snprintf(name,KOBJ_NAME_LEN * 3,"%s:%s",drv->bus->name,drv->name);
return sysfs_create_link(&drv->devclass->drvsubsys.kobj,&drv->kobj,name);
}
void devclass_drv_unlink(struct device_driver * drv)
static void devclass_drv_unlink(struct device_driver * drv)
{
char name[KOBJ_NAME_LEN * 3];
snprintf(name,KOBJ_NAME_LEN * 3,"%s:%s",drv->bus->name,drv->name);
......@@ -224,7 +224,6 @@ void put_devclass(struct device_class * cls)
if (atomic_dec_and_lock(&cls->refcount,&device_lock)) {
list_del_init(&cls->node);
spin_unlock(&device_lock);
devclass_remove_dir(cls);
}
}
......@@ -242,18 +241,17 @@ int devclass_register(struct device_class * cls)
cls->subsys.parent = &class_subsys;
subsystem_register(&cls->subsys);
snprintf(cls->devsubsys.kobj.name,"devices",KOBJ_NAME_LEN);
snprintf(cls->devsubsys.kobj.name,KOBJ_NAME_LEN,"devices");
cls->devsubsys.parent = &cls->subsys;
subsystem_register(&cls->devsubsys);
snprintf(cls->drvsubsys.kobj.name,"drivers",KOBJ_NAME_LEN);
snprintf(cls->drvsubsys.kobj.name,KOBJ_NAME_LEN,"drivers");
cls->drvsubsys.parent = &cls->subsys;
subsystem_register(&cls->drvsubsys);
spin_lock(&device_lock);
list_add_tail(&cls->node,&class_list);
spin_unlock(&device_lock);
devclass_make_dir(cls);
put_devclass(cls);
return 0;
}
......@@ -264,6 +262,9 @@ void devclass_unregister(struct device_class * cls)
cls->present = 0;
spin_unlock(&device_lock);
pr_debug("device class '%s': unregistering\n",cls->name);
subsystem_unregister(&cls->drvsubsys);
subsystem_unregister(&cls->devsubsys);
subsystem_unregister(&cls->subsys);
put_devclass(cls);
}
......
......@@ -23,8 +23,6 @@ DECLARE_MUTEX(device_sem);
spinlock_t device_lock = SPIN_LOCK_UNLOCKED;
struct subsystem device_subsys;
#define to_dev(obj) container_of(obj,struct device,kobj)
......@@ -117,9 +115,7 @@ int device_add(struct device *dev)
if (dev->parent)
dev->kobj.parent = &dev->parent->kobj;
dev->kobj.subsys = &device_subsys;
kobject_register(&dev->kobj);
if ((error = device_make_dir(dev)))
if ((error = kobject_register(&dev->kobj)))
goto register_done;
bus_add_device(dev);
......@@ -233,9 +229,6 @@ void device_del(struct device * dev)
bus_remove_device(dev);
/* remove the driverfs directory */
device_remove_dir(dev);
if (dev->release)
dev->release(dev);
......@@ -275,3 +268,6 @@ EXPORT_SYMBOL(device_register);
EXPORT_SYMBOL(device_unregister);
EXPORT_SYMBOL(get_device);
EXPORT_SYMBOL(put_device);
EXPORT_SYMBOL(device_create_file);
EXPORT_SYMBOL(device_remove_file);
obj-y := device.o bus.o driver.o class.o intf.o
obj-y := device.o
export-objs := device.o bus.o driver.o class.o
export-objs := device.o
include $(TOPDIR)/Rules.make
#include <linux/module.h>
#include <linux/device.h>
#include <linux/init.h>
#include <linux/stat.h>
#include "fs.h"
static struct driver_dir_entry bus_dir;
int bus_make_dir(struct bus_type * bus)
{
int error;
bus->dir.name = bus->name;
error = device_create_dir(&bus->dir,&bus_dir);
if (!error) {
bus->device_dir.name = "devices";
device_create_dir(&bus->device_dir,&bus->dir);
bus->driver_dir.name = "drivers";
device_create_dir(&bus->driver_dir,&bus->dir);
}
return error;
}
void bus_remove_dir(struct bus_type * bus)
{
/* remove driverfs entries */
driverfs_remove_dir(&bus->driver_dir);
driverfs_remove_dir(&bus->device_dir);
driverfs_remove_dir(&bus->dir);
}
static struct driver_dir_entry bus_dir = {
.name = "bus",
.mode = (S_IFDIR| S_IRWXU | S_IRUGO | S_IXUGO),
};
static int __init bus_init(void)
{
/* make 'bus' driverfs directory */
return driverfs_create_dir(&bus_dir,NULL);
}
core_initcall(bus_init);
/*
* class.c - driverfs bindings for device classes.
*/
#include <linux/device.h>
#include <linux/module.h>
#include <linux/init.h>
#include <linux/slab.h>
#include <linux/err.h>
#include "fs.h"
static struct driver_dir_entry class_dir;
void devclass_remove_dir(struct device_class * dc)
{
driverfs_remove_dir(&dc->device_dir);
driverfs_remove_dir(&dc->driver_dir);
driverfs_remove_dir(&dc->dir);
}
int devclass_make_dir(struct device_class * dc)
{
int error;
dc->dir.name = dc->name;
error = device_create_dir(&dc->dir,&class_dir);
if (!error) {
dc->driver_dir.name = "drivers";
error = device_create_dir(&dc->driver_dir,&dc->dir);
if (!error) {
dc->device_dir.name = "devices";
error = device_create_dir(&dc->device_dir,&dc->dir);
}
if (error)
driverfs_remove_dir(&dc->dir);
}
return error;
}
static struct driver_dir_entry class_dir = {
name: "class",
mode: (S_IRWXU | S_IRUGO | S_IXUGO),
};
static int __init devclass_driverfs_init(void)
{
return driverfs_create_dir(&class_dir,NULL);
}
core_initcall(devclass_driverfs_init);
EXPORT_SYMBOL(devclass_create_file);
EXPORT_SYMBOL(devclass_remove_file);
......@@ -16,21 +16,6 @@
#include <linux/stat.h>
#include <linux/limits.h>
static struct driver_dir_entry device_root_dir = {
.name = "root",
.mode = (S_IRWXU | S_IRUGO | S_IXUGO),
};
/**
* device_remove_dir - remove a device's directory
* @dev: device in question
*/
void device_remove_dir(struct device * dev)
{
if (dev)
driverfs_remove_dir(&dev->dir);
}
int get_devpath_length(struct device * dev)
{
int length = 1;
......@@ -62,80 +47,8 @@ void fill_devpath(struct device * dev, char * path, int length)
pr_debug("%s: path = '%s'\n",__FUNCTION__,path);
}
int device_bus_link(struct device * dev)
{
char * path;
int length;
int error = 0;
if (!dev->bus)
return 0;
length = get_devpath_length(dev);
/* now add the path from the bus directory
* It should be '../../..' (one to get to the bus's directory,
* one to get to the 'bus' directory, and one to get to the root
* of the fs.)
*/
length += strlen("../../../root");
if (length > PATH_MAX)
return -ENAMETOOLONG;
if (!(path = kmalloc(length,GFP_KERNEL)))
return -ENOMEM;
memset(path,0,length);
/* our relative position */
strcpy(path,"../../../root");
fill_devpath(dev,path,length);
error = driverfs_create_symlink(&dev->bus->device_dir,dev->bus_id,path);
kfree(path);
return error;
}
void device_remove_symlink(struct driver_dir_entry * dir, const char * name)
{
driverfs_remove_file(dir,name);
}
int device_create_dir(struct driver_dir_entry * dir, struct driver_dir_entry * parent)
{
dir->mode = (S_IFDIR| S_IRWXU | S_IRUGO | S_IXUGO);
return driverfs_create_dir(dir,parent);
}
/**
* device_make_dir - create a driverfs directory
* @name: name of directory
* @parent: dentry for the parent directory
*
* Do the initial creation of the device's driverfs directory
* and populate it with the one default file.
*
* This is just a helper for device_register(), as we
* don't export this function. (Yes, that means we don't allow
* devices to create subdirectories).
*/
int device_make_dir(struct device * dev)
{
struct driver_dir_entry * parent;
int error;
parent = dev->parent ? &dev->parent->dir : &device_root_dir;
dev->dir.name = dev->bus_id;
return device_create_dir(&dev->dir,parent);
}
static int device_driverfs_init(void)
{
return driverfs_create_dir(&device_root_dir,NULL);
}
core_initcall(device_driverfs_init);
EXPORT_SYMBOL(device_create_file);
EXPORT_SYMBOL(device_remove_file);
#include <linux/device.h>
#include <linux/module.h>
#include <linux/stat.h>
#include <linux/err.h>
#include "fs.h"
/**
* driver_make_dir - create a driverfs directory for a driver
* @drv: driver in question
*/
int driver_make_dir(struct device_driver * drv)
{
drv->dir.name = drv->name;
return device_create_dir(&drv->dir,&drv->bus->driver_dir);
}
void driver_remove_dir(struct device_driver * drv)
{
driverfs_remove_dir(&drv->dir);
}
/*
* intf.c - driverfs glue for device interfaces
*/
#include <linux/device.h>
#include <linux/slab.h>
#include "fs.h"
void intf_remove_dir(struct device_interface * intf)
{
driverfs_remove_dir(&intf->dir);
}
int intf_make_dir(struct device_interface * intf)
{
intf->dir.name = intf->name;
return device_create_dir(&intf->dir,&intf->devclass->dir);
}
......@@ -15,7 +15,7 @@
* intf_dev_link - symlink from interface's directory to device's directory
*
*/
int intf_dev_link(struct intf_data * data)
static int intf_dev_link(struct intf_data * data)
{
char linkname[16];
......@@ -23,7 +23,7 @@ int intf_dev_link(struct intf_data * data)
return sysfs_create_link(&data->intf->kobj,&data->dev->kobj,linkname);
}
void intf_dev_unlink(struct intf_data * data)
static void intf_dev_unlink(struct intf_data * data)
{
char linkname[16];
snprintf(linkname,16,"%u",data->intf_num);
......@@ -38,8 +38,6 @@ int interface_register(struct device_interface * intf)
if (cls) {
pr_debug("register interface '%s' with class '%s\n",
intf->name,cls->name);
intf_make_dir(intf);
kobject_init(&intf->kobj);
strncpy(intf->kobj.name,intf->name,KOBJ_NAME_LEN);
intf->kobj.subsys = &cls->subsys;
......@@ -61,8 +59,6 @@ void interface_unregister(struct device_interface * intf)
spin_lock(&device_lock);
list_del_init(&intf->node);
spin_unlock(&device_lock);
intf_remove_dir(intf);
}
int interface_add(struct device_class * cls, struct device * dev)
......
......@@ -73,10 +73,6 @@ struct bus_type {
struct list_head devices;
struct list_head drivers;
struct driver_dir_entry dir;
struct driver_dir_entry device_dir;
struct driver_dir_entry driver_dir;
int (*match)(struct device * dev, struct device_driver * drv);
struct device * (*add) (struct device * parent, char * bus_id);
int (*hotplug) (struct device *dev, char **envp,
......@@ -128,8 +124,6 @@ struct device_driver {
struct list_head class_list;
struct list_head devices;
struct driver_dir_entry dir;
int (*probe) (struct device * dev);
int (*remove) (struct device * dev);
void (*shutdown) (struct device * dev);
......@@ -189,10 +183,6 @@ struct device_class {
struct list_head drivers;
struct list_head intf_list;
struct driver_dir_entry dir;
struct driver_dir_entry driver_dir;
struct driver_dir_entry device_dir;
int (*add_device)(struct device *);
void (*remove_device)(struct device *);
int (*hotplug)(struct device *dev, char **envp,
......@@ -243,7 +233,6 @@ struct device_interface {
struct kobject kobj;
struct list_head node;
struct list_head devices;
struct driver_dir_entry dir;
u32 devnum;
......
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