Driver Core patches for 2.6.17
Subsystems (10)
PATCH 1/1 Driver Core patches for 2.6.17
Here are some driver core patches and fixes for 2.6.17. They contain the following changes:
- documentation update
- add ABI documentation as discussed on lkml
- add ISA driver core framework
- add ability for devices to work like class devices
- let drivers get to tty class device pointer
- add /sys/hypervisor when needed
- some mutex conversions
- some MODALIAS and uevent fixes
- remove some unused exports
- make the dev_printk() messags be a bit more informative when we do not have a driver attached to a device yet.
All of these patches have been in the -mm tree for a number of months.
Please pull from:
git://git.kernel.org/pub/scm/linux/kernel/git/gregkh/driver-2.6.git/
or if master.kernel.org hasn't synced up yet:
master.kernel.org:/pub/scm/linux/kernel/git/gregkh/driver-2.6.git/
Patches will be sent as a follow-on to this message to lkml for people to see.
thanks,
greg k-h
Documentation/ABI/README | 77 ++++++++++++ Documentation/ABI/obsolete/devfs | 13 ++ Documentation/ABI/stable/syscalls | 10 + Documentation/ABI/stable/sysfs-module | 30 ++++ Documentation/ABI/testing/sysfs-class | 16 ++ Documentation/ABI/testing/sysfs-devices | 25 ++++ Documentation/isdn/README.gigaset | 7 - Documentation/power/devices.txt | 90 -------------- block/genhd.c | 7 - drivers/base/Kconfig | 4 drivers/base/Makefile | 2 drivers/base/attribute_container.c | 8 - drivers/base/base.h | 9 + drivers/base/bus.c | 28 +++- drivers/base/class.c | 112 ++++++++++++------ drivers/base/core.c | 197 +++++++++++++++++++++++++++++++- drivers/base/firmware_class.c | 22 +-- drivers/base/hypervisor.c | 19 +++ drivers/base/init.c | 1 drivers/base/isa.c | 180 +++++++++++++++++++++++++++++ drivers/base/platform.c | 35 +++++ drivers/base/power/Makefile | 3 drivers/base/power/suspend.c | 17 ++ drivers/base/sys.c | 51 ++++++++ drivers/block/cciss.c | 1 drivers/char/tty_io.c | 11 + drivers/isdn/gigaset/common.c | 13 +- drivers/isdn/gigaset/gigaset.h | 1 drivers/isdn/gigaset/interface.c | 10 + drivers/isdn/gigaset/proc.c | 21 ++- fs/partitions/check.c | 4 include/linux/device.h | 25 ++-- include/linux/isa.h | 28 ++++ include/linux/kobject.h | 2 include/linux/sysdev.h | 18 ++ include/linux/tty.h | 4 lib/kobject.c | 6 37 files changed, 907 insertions(+), 200 deletions(-)
---------------
Alan Stern:
Driver Core: Make dev_info and friends print the bus name if there is no driver
David Brownell:
Driver Core: CONFIG_DEBUG_PM covers drivers/base/power too platform_bus learns about modalias
remove duplication from Documentation/power/devices.txt Driver core: PM_DEBUG device suspend() messages become informative
Greg Kroah-Hartman:
kobject: make people pay attention to kobject_add errors Add kernel<->userspace ABI stability documentation
CCISS: add device symlink to the block cciss block devices in sysfs Driver Core: remove unused exports
Driver core: change make_class_name() to take kobjects Driver core: allow struct device to have a dev_t
Driver core: add proper symlinks for devices
Hansjoerg Lipp:
TTY: return class device pointer from tty_register_device() i4l gigaset: move sysfs entry to tty class device
Kay Sievers:
Driver core: bus device event delay
Driver core: add generic "subsystem" link to all devices
Laura Garcia:
firmware_class: s/semaphores/mutexes
Michael Holzheu:
Driver Core: Add /sys/hypervisor when needed
Rene Herman:
Driver model: add ISA bus
Russell King:
Driver Core: Fix platform_device_add to use device_add
Shaohua Li:
Driver Core: Allow sysdev_class have attributes
Stephen Hemminger:
Driver core: class_device_add needs error checks
PATCH 1/22 kobject: make people pay attention to kobject_add errors
From: Greg Kroah-Hartman <[email protected]>
These really need to be fixed, shout it out to the world.
--- lib/kobject.c | 6 +++--- 1 files changed, 3 insertions(+), 3 deletions(-)
lib/kobject.c +3 -3
@@ -198,14 +198,14 @@ int kobject_add(struct kobject * kobj)/* be noisy on error issues */ if (error == -EEXIST ) -pr_debug ("kobject_add failed for %s with -EEXIST, " +printk ("kobject_add failed for %s with -EEXIST, " "don't try to register things with the " "same name in the same directory.\n" ,kobject_name (kobj));else -pr_debug ("kobject_add failed for %s (%d)\n" , +printk ("kobject_add failed for %s (%d)\n" ,kobject_name (kobj), error); -/* dump_stack(); */ +dump_stack (); }return error;
Signature · 1 line
1.4.0
PATCH 2/22 Add kernel<->userspace ABI stability documentation
From: Greg Kroah-Hartman <[email protected]>
--- Documentation/ABI/README | 77 +++++++++++++++++++++++++++++++ Documentation/ABI/obsolete/devfs | 13 +++++ Documentation/ABI/stable/syscalls | 10 ++++ Documentation/ABI/stable/sysfs-module | 30 ++++++++++++ Documentation/ABI/testing/sysfs-class | 16 ++++++ Documentation/ABI/testing/sysfs-devices | 25 ++++++++++ 6 files changed, 171 insertions(+), 0 deletions(-)
Documentation/ABI/README new file +77 -0
@@ -0,0 +1,77 @@ +This directory attempts to document the ABI between the Linux kernel and +userspace, and the relative stability of these interfaces. Due to the +everchanging nature of Linux, and the differing maturity levels, these +interfaces should be used by userspace programs in different ways. + +We have four different levels of ABI stability, as shown by the four +different subdirectories in this location. Interfaces may change levels +of stability according to the rules described below. + +The different levels of stability are: + + stable/ + This directory documents the interfaces that the developer has + defined to be stable. Userspace programs are free to use these + interfaces with no restrictions, and backward compatibility for + them will be guaranteed for at least 2 years. Most interfaces + (like syscalls) are expected to never change and always be + available. + + testing/ + This directory documents interfaces that are felt to be stable, + as the main development of this interface has been completed. + The interface can be changed to add new features, but the + current interface will not break by doing this, unless grave + errors or security problems are found in them. Userspace + programs can start to rely on these interfaces, but they must be + aware of changes that can occur before these interfaces move to + be marked stable. Programs that use these interfaces are + strongly encouraged to add their name to the description of + these interfaces, so that the kernel developers can easily + notify them if any changes occur (see the description of the + layout of the files below for details on how to do this.) + + obsolete/ + This directory documents interfaces that are still remaining in + the kernel, but are marked to be removed at some later point in + time. The description of the interface will document the reason + why it is obsolete and when it can be expected to be removed. + The file Documentation/feature-removal-schedule.txt may describe + some of these interfaces, giving a schedule for when they will + be removed. + + removed/ + This directory contains a list of the old interfaces that have + been removed from the kernel. + +Every file in these directories will contain the following information: + +What: Short description of the interface +Date: Date created +KernelVersion: Kernel version this feature first showed up in. +Contact: Primary contact for this interface (may be a mailing list) +Description: Long description of the interface and how to use it. +Users: All users of this interface who wish to be notified when + it changes. This is very important for interfaces in + the "testing" stage, so that kernel developers can work + with userspace developers to ensure that things do not + break in ways that are unacceptable. It is also + important to get feedback for these interfaces to make + sure they are working in a proper way and do not need to + be changed further. + + +How things move between levels: + +Interfaces in stable may move to obsolete, as long as the proper +notification is given. + +Interfaces may be removed from obsolete and the kernel as long as the +documented amount of time has gone by. + +Interfaces in the testing state can move to the stable state when the +developers feel they are finished. They cannot be removed from the +kernel tree without going through the obsolete state first. + +It's up to the developer to place their interfaces in the category they +wish for it to start out in.
Documentation/ABI/obsolete/devfs new file +13 -0
@@ -0,0 +1,13 @@ +What: devfs +Date: July 2005 +Contact: Greg Kroah-Hartman <[email protected]> +Description: + devfs has been unmaintained for a number of years, has unfixable + races, contains a naming policy within the kernel that is + against the LSB, and can be replaced by using udev. + The files fs/devfs/*, include/linux/devfs_fs*.h will be removed, + along with the the assorted devfs function calls throughout the + kernel tree. + +Users: +
Documentation/ABI/stable/syscalls new file +10 -0
@@ -0,0 +1,10 @@ +What: The kernel syscall interface +Description: + This interface matches much of the POSIX interface and is based + on it and other Unix based interfaces. It will only be added to + over time, and not have things removed from it. + + Note that this interface is different for every architecture + that Linux supports. Please see the architecture-specific + documentation for details on the syscall numbers that are to be + mapped to each syscall.
Documentation/ABI/stable/sysfs-module new file +30 -0
@@ -0,0 +1,30 @@ +What: /sys/module +Description: + The /sys/module tree consists of the following structure: + + /sys/module/MODULENAME + The name of the module that is in the kernel. This + module name will show up either if the module is built + directly into the kernel, or if it is loaded as a + dyanmic module. + + /sys/module/MODULENAME/parameters + This directory contains individual files that are each + individual parameters of the module that are able to be + changed at runtime. See the individual module + documentation as to the contents of these parameters and + what they accomplish. + + Note: The individual parameter names and values are not + considered stable, only the fact that they will be + placed in this location within sysfs. See the + individual driver documentation for details as to the + stability of the different parameters. + + /sys/module/MODULENAME/refcnt + If the module is able to be unloaded from the kernel, this file + will contain the current reference count of the module. + + Note: If the module is built into the kernel, or if the + CONFIG_MODULE_UNLOAD kernel configuration value is not enabled, + this file will not be present.
Documentation/ABI/testing/sysfs-class new file +16 -0
@@ -0,0 +1,16 @@ +What: /sys/class/ +Date: Febuary 2006 +Contact: Greg Kroah-Hartman <[email protected]> +Description: + The /sys/class directory will consist of a group of + subdirectories describing individual classes of devices + in the kernel. The individual directories will consist + of either subdirectories, or symlinks to other + directories. + + All programs that use this directory tree must be able + to handle both subdirectories or symlinks in order to + work properly. + +Users: + udev <[email protected]>
Documentation/ABI/testing/sysfs-devices new file +25 -0
@@ -0,0 +1,25 @@ +What: /sys/devices +Date: February 2006 +Contact: Greg Kroah-Hartman <[email protected]> +Description: + The /sys/devices tree contains a snapshot of the + internal state of the kernel device tree. Devices will + be added and removed dynamically as the machine runs, + and between different kernel versions, the layout of the + devices within this tree will change. + + Please do not rely on the format of this tree because of + this. If a program wishes to find different things in + the tree, please use the /sys/class structure and rely + on the symlinks there to point to the proper location + within the /sys/devices tree of the individual devices. + Or rely on the uevent messages to notify programs of + devices being added and removed from this tree to find + the location of those devices. + + Note that sometimes not all devices along the directory + chain will have emitted uevent messages, so userspace + programs must be able to handle such occurrences. + +Users: + udev <[email protected]>
Signature · 1 line
1.4.0
PATCH 3/22 CCISS: add device symlink to the block cciss block devices in sysfs
From: Greg Kroah-Hartman <[email protected]>
--- drivers/block/cciss.c | 1 + 1 files changed, 1 insertions(+), 0 deletions(-)
drivers/block/cciss.c +1 -0
@@ -3237,6 +3237,7 @@ #endif /* CCISS_DEBUG */ disk->fops = &cciss_fops; disk->queue = q; disk->private_data = drv; + disk->driverfs_dev = &pdev->dev;/* we must register the controller even if no disks exist */ /* this is for the online array utilities */ if (!drv->heads && j)
Signature · 1 line
1.4.0
PATCH 4/22 Driver core: bus device event delay
From: Kay Sievers <[email protected]>
split bus_add_device() and send device uevents after sysfs population
--- drivers/base/base.h | 1 + drivers/base/bus.c | 22 ++++++++++++++++++---- drivers/base/core.c | 3 ++- 3 files changed, 21 insertions(+), 5 deletions(-)
drivers/base/base.h +1 -0
@@ -11,6 +11,7 @@ extern int cpu_dev_init(void);extern int attribute_container_init (void );extern int bus_add_device (struct device * dev); +extern void bus_attach_device (struct device * dev);extern void bus_remove_device (struct device * dev);extern int bus_add_driver (struct device_driver *);
drivers/base/bus.c +18 -4
@@ -362,8 +362,7 @@ static void device_remove_attrs(struct b* @dev: device being added * * - Add the device to its bus's list of devices. -* - Try to attach to driver. -* - Create link to device's physical location. +* - Create link to device's bus. */ int bus_add_device (struct device * dev) {
@@ -372,8 +371,6 @@ int bus_add_device(struct device * dev)if (bus) {pr_debug ("bus %s: add device %s\n" , bus->name, dev->bus_id); -device_attach (dev); -klist_add_tail (&dev->knode_bus, &bus->klist_devices); error =device_add_attrs (bus, dev);if (!error) {sysfs_create_link (&bus->devices.kobj, &dev->kobj, dev->bus_id);
@@ -384,6 +381,22 @@ int bus_add_device(struct device * dev) }/** +* bus_attach_device - add device to bus +* @dev: device tried to attach to a driver +* +* - Try to attach to driver. +*/ +void bus_attach_device (struct device * dev) +{ +struct bus_type * bus = dev->bus; + +if (bus) { +device_attach (dev); +klist_add_tail (&dev->knode_bus, &bus->klist_devices); + } +} + +/** * bus_remove_device - remove device from bus * @dev: device to be removed *
@@ -733,6 +746,7 @@ EXPORT_SYMBOL_GPL(bus_find_device);EXPORT_SYMBOL_GPL (bus_for_each_drv);EXPORT_SYMBOL_GPL (bus_add_device); +EXPORT_SYMBOL_GPL (bus_attach_device);EXPORT_SYMBOL_GPL (bus_remove_device);EXPORT_SYMBOL_GPL (bus_register);EXPORT_SYMBOL_GPL (bus_unregister);
drivers/base/core.c +2 -1
@@ -274,11 +274,12 @@ int device_add(struct device *dev) dev->uevent_attr.store = store_uevent;device_create_file (dev, &dev->uevent_attr); -kobject_uevent (&dev->kobj,KOBJ_ADD );if ((error =device_pm_add (dev))) goto PMError;if ((error =bus_add_device (dev))) goto BusError; +kobject_uevent (&dev->kobj,KOBJ_ADD ); +bus_attach_device (dev);if (parent)klist_add_tail (&dev->knode_parent, &parent->klist_children);
Signature · 1 line
1.4.0
PATCH 5/22 TTY: return class device pointer from tty_register_device()
From: Hansjoerg Lipp <[email protected]>
Let tty_register_device() return a pointer to the class device it creates. This allows registrants to add their own sysfs files under the class device node.
--- drivers/char/tty_io.c | 11 +++++++---- include/linux/tty.h | 4 +++- 2 files changed, 10 insertions(+), 5 deletions(-)
drivers/char/tty_io.c +7 -4
@@ -2961,12 +2961,14 @@ static struct class *tty_class;* This field is optional, if there is no known struct device for this * tty device it can be set to NULL safely. * +* Returns a pointer to the class device (or ERR_PTR(-EFOO) on error). +* * This call is required to be made to register an individual tty device if * the tty driver's flags have the TTY_DRIVER_NO_DEVFS bit set. If that * bit is not set, this function should not be called. */ -void tty_register_device (struct tty_driver *driver,unsigned index, -struct device *device) +struct class_device *tty_register_device (struct tty_driver *driver, +unsigned index,struct device *device) {char name[64 ];dev_t dev =MKDEV (driver->major, driver->minor_start) + index;
@@ -2974,7 +2976,7 @@ void tty_register_device(struct tty_drivif (index >= driver->num) {printk (KERN_ERR "Attempt to register invalid tty line number " " (%d).\n" , index); -return ; +return ERR_PTR (-EINVAL ); } devfs_mk_cdev(dev, S_IFCHR | S_IRUSR | S_IWUSR,
@@ -2984,7 +2986,8 @@ void tty_register_device(struct tty_drivpty_line_name (driver, index, name); elsetty_line_name (driver ,index ,name ); -class_device_create (tty_class,NULL , dev, device,"%s" , name); + +return class_device_create (tty_class,NULL , dev, device,"%s" , name); }/**
include/linux/tty.h +3 -1
@@ -290,7 +290,9 @@ extern int tty_register_ldisc(int disc,extern int tty_unregister_ldisc (int disc);extern int tty_register_driver (struct tty_driver *driver);extern int tty_unregister_driver (struct tty_driver *driver); -extern void tty_register_device (struct tty_driver *driver,unsigned index,struct device *dev); +extern struct class_device *tty_register_device (struct tty_driver *driver, +unsigned index, +struct device *dev);extern void tty_unregister_device (struct tty_driver *driver,unsigned index);extern int tty_read_raw_data (struct tty_struct *tty,unsigned char *bufp,int buflen);
Signature · 1 line
1.4.0
PATCH 6/22 i4l gigaset: move sysfs entry to tty class device
From: Hansjoerg Lipp <[email protected]>
Using the class device pointer returned by tty_register_device() with part 1 of the patch, attach the Gigaset drivers' "cidmode" sysfs entry to its tty class device, where it can be found more easily by users who do not know nor care which USB port the device is attached to.
--- Documentation/isdn/README.gigaset | 7 ++++--- drivers/isdn/gigaset/common.c | 13 +++++++------ drivers/isdn/gigaset/gigaset.h | 1 + drivers/isdn/gigaset/interface.c | 10 +++++++++- drivers/isdn/gigaset/proc.c | 21 +++++++++++++-------- 5 files changed, 34 insertions(+), 18 deletions(-)
Documentation/isdn/README.gigaset +4 -3
@@ -124,7 +124,8 @@ GigaSet 307x Device Driver You can use some configuration tool of your distribution to configure this "modem" or configure pppd/wvdial manually. There are some example ppp - configuration files and chat scripts in the gigaset-VERSION/ppp directory. + configuration files and chat scripts in the gigaset-VERSION/ppp directory + in the driver packages from http://sourceforge.net/projects/gigaset307x/. Please note that the USB drivers are not able to change the state of the control lines (the M105 driver can be configured to use some undocumented control requests, if you really need the control lines, though). This means
@@ -164,8 +165,8 @@ GigaSet 307x Device Driver If you want both of these at once, you are out of luck. - You can also use /sys/module/<name>/parameters/cidmode for changing - the CID mode setting (<name> is usb_gigaset or bas_gigaset). + You can also use /sys/class/tty/ttyGxy/cidmode for changing the CID mode + setting (ttyGxy is ttyGU0 or ttyGB0). 3. Troubleshooting
drivers/isdn/gigaset/common.c +7 -6
@@ -460,6 +460,9 @@ void gigaset_freecs(struct cardstate *csswitch (cs->cs_init) {default : +/* clear device sysfs */ +gigaset_free_dev_sysfs (cs); +gigaset_if_free (cs);gig_dbg (DEBUG_INIT ,"clearing hw" );
@@ -699,6 +702,7 @@ struct cardstate *gigaset_initcs(struct cs->open_count =0 ; cs->dev =NULL ; cs->tty =NULL ; + cs->class =NULL ; cs->cidmode = cidmode !=0 ;//if(onechannel) { //FIXME
@@ -760,6 +764,9 @@ struct cardstate *gigaset_initcs(structgigaset_if_init (cs); +/* set up device sysfs */ +gigaset_init_dev_sysfs (cs); +spin_lock_irqsave (&cs->lock, flags); cs->running =1 ;spin_unlock_irqrestore (&cs->lock, flags);
@@ -902,9 +909,6 @@ int gigaset_start(struct cardstate *cs)wait_event (cs->waitqueue, !cs->waiting); -/* set up device sysfs */ -gigaset_init_dev_sysfs (cs); -mutex_unlock (&cs->mutex);return 1 ;
@@ -969,9 +973,6 @@ void gigaset_stop(struct cardstate *cs)//FIXME } -/* clear device sysfs */ -gigaset_free_dev_sysfs (cs); -cleanup_cs (cs); exit:
drivers/isdn/gigaset/gigaset.h +1 -0
@@ -445,6 +445,7 @@ struct cardstate {struct gigaset_driver *driver;unsigned minor_index;struct device *dev; +struct class_device *class;const struct gigaset_ops *ops;
drivers/isdn/gigaset/interface.c +9 -1
@@ -625,7 +625,14 @@ void gigaset_if_init(struct cardstate *creturn ;tasklet_init (&cs->if_wake_tasklet, &if_wake, (unsigned long ) cs); -tty_register_device (drv->tty, cs->minor_index,NULL ); + cs->class =tty_register_device (drv->tty, cs->minor_index,NULL ); + +if (!IS_ERR (cs->class)) +class_set_devdata (cs->class, cs); +else { +warn ("could not register device to the tty subsystem" ); + cs->class =NULL ; + } }void gigaset_if_free (struct cardstate *cs)
@@ -638,6 +645,7 @@ void gigaset_if_free(struct cardstate *ctasklet_disable (&cs->if_wake_tasklet);tasklet_kill (&cs->if_wake_tasklet); + cs->class =NULL ;tty_unregister_device (drv->tty, cs->minor_index); }
drivers/isdn/gigaset/proc.c +13 -8
@@ -16,12 +16,11 @@#include "gigaset.h" #include <linux/ctype.h> -static ssize_t show_cidmode (struct device *dev,struct device_attribute *attr, -char *buf) +static ssize_t show_cidmode (struct class_device *class,char *buf) {int ret;unsigned long flags; -struct cardstate *cs =dev_get_drvdata (dev); +struct cardstate *cs =class_get_devdata (class);spin_lock_irqsave (&cs->lock, flags); ret =sprintf (buf,"%u\n" , cs->cidmode);
@@ -30,10 +29,10 @@ static ssize_t show_cidmode(struct devicreturn ret; } -static ssize_t set_cidmode (struct device *dev,struct device_attribute *attr, +static ssize_t set_cidmode (struct class_device *class,const char *buf,size_t count) { -struct cardstate *cs =dev_get_drvdata (dev); +struct cardstate *cs =class_get_devdata (class);long int value;char *end;
@@ -65,18 +64,24 @@ static ssize_t set_cidmode(struct devicereturn count; } -static DEVICE_ATTR(cidmode, S_IRUGO|S_IWUSR, show_cidmode, set_cidmode); +static CLASS_DEVICE_ATTR(cidmode, S_IRUGO|S_IWUSR, show_cidmode, set_cidmode);/* free sysfs for device */ void gigaset_free_dev_sysfs (struct cardstate *cs) { +if (!cs->class) +return ; +gig_dbg (DEBUG_INIT ,"removing sysfs entries" ); -device_remove_file (cs->dev, &dev_attr_cidmode); +class_device_remove_file (cs->class, &class_device_attr_cidmode); }/* initialize sysfs for device */ void gigaset_init_dev_sysfs (struct cardstate *cs) { +if (!cs->class) +return ; +gig_dbg (DEBUG_INIT ,"setting up sysfs" ); -device_create_file (cs->dev, &dev_attr_cidmode); +class_device_create_file (cs->class, &class_device_attr_cidmode); }
Signature · 1 line
1.4.0
PATCH 7/22 Driver core: class_device_add needs error checks
From: Stephen Hemminger <[email protected]>
class_device_add needs to check the return value of all the setup it does. It doesn't handle out of memory well. This is not complete, probably more needs to be done.
--- drivers/base/class.c | 72 ++++++++++++++++++++++++++++++++++++++------------ 1 files changed, 54 insertions(+), 18 deletions(-)
drivers/base/class.c +54 -18
@@ -535,18 +535,22 @@ int class_device_add(struct class_devicereturn -EINVAL ;if (!strlen (class_dev->class_id)) - goto register_done; + goto out1; parent_class =class_get (class_dev->class);if (!parent_class) - goto register_done; + goto out1; + parent_class_dev =class_device_get (class_dev->parent);pr_debug ("CLASS: registering class device: ID = '%s'\n" , class_dev->class_id);/* first, register with generic layer. */ -kobject_set_name (&class_dev->kobj,"%s" , class_dev->class_id); + error =kobject_set_name (&class_dev->kobj,"%s" , class_dev->class_id); +if (error) + goto out2; +if (parent_class_dev) class_dev->kobj.parent = &parent_class_dev->kobj;else
@@ -554,41 +558,56 @@ int class_device_add(struct class_device error =kobject_add (&class_dev->kobj);if (error) - goto register_done; + goto out2;/* add the needed attributes to this device */ class_dev->uevent_attr.attr.name ="uevent" ; class_dev->uevent_attr.attr.mode =S_IWUSR ; class_dev->uevent_attr.attr.owner = parent_class->owner; class_dev->uevent_attr.store = store_uevent; -class_device_create_file (class_dev, &class_dev->uevent_attr); + error =class_device_create_file (class_dev, &class_dev->uevent_attr); +if (error) + goto out3;if (MAJOR (class_dev->devt)) {struct class_device_attribute *attr; attr =kzalloc (sizeof (*attr),GFP_KERNEL );if (!attr) { error = -ENOMEM ; -kobject_del (&class_dev->kobj); - goto register_done; + goto out4; } attr->attr.name ="dev" ; attr->attr.mode =S_IRUGO ; attr->attr.owner = parent_class->owner; attr->show = show_dev; -class_device_create_file (class_dev, attr); + error =class_device_create_file (class_dev, attr); +if (error) { +kfree (attr); + goto out4; + } + class_dev->devt_attr = attr; } -class_device_add_attrs (class_dev); + error =class_device_add_attrs (class_dev); +if (error) + goto out5; +if (class_dev->dev) { class_name =make_class_name (class_dev); -sysfs_create_link (&class_dev->kobj, - &class_dev->dev->kobj,"device" ); -sysfs_create_link (&class_dev->dev->kobj, &class_dev->kobj, - class_name); + error =sysfs_create_link (&class_dev->kobj, + &class_dev->dev->kobj,"device" ); +if (error) + goto out6; + error =sysfs_create_link (&class_dev->dev->kobj, &class_dev->kobj, + class_name); +if (error) + goto out7; } -class_device_add_groups (class_dev); + error =class_device_add_groups (class_dev); +if (error) + goto out8;kobject_uevent (&class_dev->kobj,KOBJ_ADD );
@@ -601,11 +620,28 @@ int class_device_add(struct class_device }up (&parent_class->sem); - register_done: -if (error) { -class_put (parent_class); + goto out1; + + out8: +if (class_dev->dev) +sysfs_remove_link (&class_dev->kobj, class_name); + out7: +if (class_dev->dev) +sysfs_remove_link (&class_dev->kobj,"device" ); + out6: +class_device_remove_attrs (class_dev); + out5: +if (class_dev->devt_attr) +class_device_remove_file (class_dev, class_dev->devt_attr); + out4: +class_device_remove_file (class_dev, &class_dev->uevent_attr); + out3: +kobject_del (&class_dev->kobj); + out2: +if (parent_class_dev)class_device_put (parent_class_dev); - } +class_put (parent_class); + out1:class_device_put (class_dev);kfree (class_name);return error;
Signature · 1 line
1.4.0
PATCH 8/22 Driver Core: CONFIG_DEBUG_PM covers drivers/base/power too
From: David Brownell <[email protected]>
The drivers/base/power PM debug messages should appear when either PM or driver model debug are enabled.
--- drivers/base/power/Makefile | 3 +++ 1 files changed, 3 insertions(+), 0 deletions(-)
drivers/base/power/Makefile +3 -0
@@ -4,3 +4,6 @@ obj-$(CONFIG_PM) += main.o suspend.o res ifeq ($(CONFIG_DEBUG_DRIVER),y) EXTRA_CFLAGS += -DDEBUG endif +ifeq ($(CONFIG_PM_DEBUG),y) +EXTRA_CFLAGS += -DDEBUG +endif
Signature · 1 line
1.4.0
PATCH 9/22 platform_bus learns about modalias
From: David Brownell <[email protected]>
This patch adds modalias support to platform devices, for simpler hotplug/coldplug driven driver setup.
--- drivers/base/platform.c | 33 +++++++++++++++++++++++++++++++++ 1 files changed, 33 insertions(+), 0 deletions(-)
drivers/base/platform.c +33 -0
@@ -452,6 +452,37 @@ void platform_driver_unregister(struct pEXPORT_SYMBOL_GPL (platform_driver_unregister); +/* modalias support enables more hands-off userspace setup: +* (a) environment variable lets new-style hotplug events work once system is +* fully running: "modprobe $MODALIAS" +* (b) sysfs attribute lets new-style coldplug recover from hotplug events +* mishandled before system is fully running: "modprobe $(cat modalias)" +*/ +static ssize_t +modalias_show (struct device *dev,struct device_attribute *a,char *buf) +{ +struct platform_device *pdev =to_platform_device (dev); +int len =snprintf (buf,PAGE_SIZE ,"%s\n" , pdev->name); + +return (len >=PAGE_SIZE ) ? (PAGE_SIZE -1 ) : len; +} + +static struct device_attribute platform_dev_attrs[] = { +__ATTR_RO (modalias), + __ATTR_NULL, +}; + +static int platform_uevent (struct device *dev,char **envp,int num_envp, +char *buffer,int buffer_size) +{ +struct platform_device *pdev =to_platform_device (dev); + + envp[0 ] = buffer; +snprintf (buffer, buffer_size,"MODALIAS=%s" , pdev->name); +return 0 ; +} + +/** * platform_match - bind platform device to platform driver. * @dev: device.
@@ -496,7 +527,9 @@ static int platform_resume(struct devicestruct bus_type platform_bus_type = { .name ="platform" , + .dev_attrs = platform_dev_attrs, .match = platform_match, + .uevent = platform_uevent, .suspend = platform_suspend, .resume = platform_resume, };
Signature · 1 line
1.4.0
PATCH 10/22 Driver Core: remove unused exports
From: Greg Kroah-Hartman <[email protected]>
--- drivers/base/attribute_container.c | 8 -------- drivers/base/base.h | 2 ++ drivers/base/bus.c | 6 ------ drivers/base/class.c | 6 ++---- include/linux/device.h | 8 -------- 5 files changed, 4 insertions(+), 26 deletions(-)
drivers/base/attribute_container.c +0 -8
@@ -236,7 +236,6 @@ attribute_container_remove_device(struct }up (&attribute_container_mutex); } -EXPORT_SYMBOL_GPL (attribute_container_remove_device);/** * attribute_container_device_trigger - execute a trigger for each matching classdev
@@ -276,7 +275,6 @@ attribute_container_device_trigger(struc }up (&attribute_container_mutex); } -EXPORT_SYMBOL_GPL (attribute_container_device_trigger);/** * attribute_container_trigger - trigger a function for each matching container
@@ -304,7 +302,6 @@ attribute_container_trigger(struct devic }up (&attribute_container_mutex); } -EXPORT_SYMBOL_GPL (attribute_container_trigger);/** * attribute_container_add_attrs - add attributes
@@ -333,7 +330,6 @@ attribute_container_add_attrs(struct clareturn 0 ; } -EXPORT_SYMBOL_GPL (attribute_container_add_attrs);/** * attribute_container_add_class_device - same function as class_device_add
@@ -352,7 +348,6 @@ attribute_container_add_class_device(strreturn error;return attribute_container_add_attrs (classdev); } -EXPORT_SYMBOL_GPL (attribute_container_add_class_device);/** * attribute_container_add_class_device_adapter - simple adapter for triggers
@@ -367,7 +362,6 @@ attribute_container_add_class_device_ada {return attribute_container_add_class_device (classdev); } -EXPORT_SYMBOL_GPL (attribute_container_add_class_device_adapter);/** * attribute_container_remove_attrs - remove any attribute files
@@ -389,7 +383,6 @@ attribute_container_remove_attrs(structfor (i =0 ; attrs[i]; i++)class_device_remove_file (classdev, attrs[i]); } -EXPORT_SYMBOL_GPL (attribute_container_remove_attrs);/** * attribute_container_class_device_del - equivalent of class_device_del
@@ -405,7 +398,6 @@ attribute_container_class_device_del(strattribute_container_remove_attrs (classdev);class_device_del (classdev); } -EXPORT_SYMBOL_GPL (attribute_container_class_device_del);/** * attribute_container_find_class_device - find the corresponding class_device
drivers/base/base.h +2 -0
@@ -13,6 +13,8 @@ extern int attribute_container_init(voidextern int bus_add_device (struct device * dev);extern void bus_attach_device (struct device * dev);extern void bus_remove_device (struct device * dev); +extern struct bus_type *get_bus (struct bus_type * bus); +extern void put_bus (struct bus_type * bus);extern int bus_add_driver (struct device_driver *);extern void bus_remove_driver (struct device_driver *);
drivers/base/bus.c +0 -6
@@ -745,15 +745,9 @@ EXPORT_SYMBOL_GPL(bus_for_each_dev);EXPORT_SYMBOL_GPL (bus_find_device);EXPORT_SYMBOL_GPL (bus_for_each_drv); -EXPORT_SYMBOL_GPL (bus_add_device); -EXPORT_SYMBOL_GPL (bus_attach_device); -EXPORT_SYMBOL_GPL (bus_remove_device);EXPORT_SYMBOL_GPL (bus_register);EXPORT_SYMBOL_GPL (bus_unregister);EXPORT_SYMBOL_GPL (bus_rescan_devices); -EXPORT_SYMBOL_GPL (get_bus); -EXPORT_SYMBOL_GPL (put_bus); -EXPORT_SYMBOL_GPL (find_bus);EXPORT_SYMBOL_GPL (bus_create_file);EXPORT_SYMBOL_GPL (bus_remove_file);
drivers/base/class.c +2 -4
@@ -91,14 +91,14 @@ void class_remove_file(struct class * clsysfs_remove_file (&cls->subsys.kset.kobj, &attr->attr); } -struct class *class_get (struct class * cls) +static struct class *class_get (struct class *cls) {if (cls) return container_of(subsys_get(&cls->subsys), struct class, subsys);return NULL ; } -void class_put (struct class * cls) +static void class_put (struct class * cls) {if (cls)subsys_put (&cls->subsys);
@@ -894,8 +894,6 @@ EXPORT_SYMBOL_GPL(class_create_file);EXPORT_SYMBOL_GPL (class_remove_file);EXPORT_SYMBOL_GPL (class_register);EXPORT_SYMBOL_GPL (class_unregister); -EXPORT_SYMBOL_GPL (class_get); -EXPORT_SYMBOL_GPL (class_put);EXPORT_SYMBOL_GPL (class_create);EXPORT_SYMBOL_GPL (class_destroy);
include/linux/device.h +0 -8
@@ -60,11 +60,6 @@ extern void bus_unregister(struct bus_tyextern void bus_rescan_devices (struct bus_type * bus); -extern struct bus_type *get_bus (struct bus_type * bus); -extern void put_bus (struct bus_type * bus); - -extern struct bus_type *find_bus (char * name); -/* iterator helpers for buses */ int bus_for_each_dev(struct bus_type * bus, struct device * start, void * data,
@@ -163,9 +158,6 @@ struct class {extern int class_register (struct class *);extern void class_unregister (struct class *); -extern struct class *class_get (struct class *); -extern void class_put (struct class *); -struct class_attribute {struct attribute attr;
Signature · 1 line
1.4.0
PATCH 11/22 Driver Core: Allow sysdev_class have attributes
From: Shaohua Li <[email protected]>
allow sysdev_class adding attribute. Next patch will use the new API to add an attribute under /sys/device/system/cpu/.
--- drivers/base/sys.c | 51 +++++++++++++++++++++++++++++++++++++++++++++++- include/linux/sysdev.h | 18 ++++++++++++++++- 2 files changed, 67 insertions(+), 2 deletions(-)
drivers/base/sys.c +50 -1
@@ -80,10 +80,59 @@ void sysdev_remove_file(struct sys_devicEXPORT_SYMBOL_GPL (sysdev_create_file);EXPORT_SYMBOL_GPL (sysdev_remove_file); +#define to_sysdev_class (k) container_of(k, struct sysdev_class, kset.kobj) +#define to_sysdev_class_attr (a) container_of(a, \ + struct sysdev_class_attribute, attr) + +static ssize_t sysdev_class_show (struct kobject *kobj,struct attribute *attr, +char *buffer) +{ +struct sysdev_class * class =to_sysdev_class (kobj); +struct sysdev_class_attribute *class_attr =to_sysdev_class_attr (attr); + +if (class_attr->show) +return class_attr->show (class, buffer); +return -EIO ; +} + +static ssize_t sysdev_class_store (struct kobject *kobj,struct attribute *attr, +const char *buffer,size_t count) +{ +struct sysdev_class * class =to_sysdev_class (kobj); +struct sysdev_class_attribute * class_attr =to_sysdev_class_attr (attr); + +if (class_attr->store) +return class_attr->store (class, buffer, count); +return -EIO ; +} + +static struct sysfs_ops sysfs_class_ops = { + .show = sysdev_class_show, + .store = sysdev_class_store, +}; + +static struct kobj_type ktype_sysdev_class = { + .sysfs_ops = &sysfs_class_ops, +}; + +int sysdev_class_create_file (struct sysdev_class *c, +struct sysdev_class_attribute *a) +{ +return sysfs_create_file (&c->kset.kobj, &a->attr); +} +EXPORT_SYMBOL_GPL (sysdev_class_create_file); + +void sysdev_class_remove_file (struct sysdev_class *c, +struct sysdev_class_attribute *a) +{ +sysfs_remove_file (&c->kset.kobj, &a->attr); +} +EXPORT_SYMBOL_GPL (sysdev_class_remove_file); +/* * declare system_subsys */ -static decl_subsys(system, &ktype_sysdev, NULL); +static decl_subsys(system, &ktype_sysdev_class, NULL);int sysdev_class_register (struct sysdev_class * cls) {
include/linux/sysdev.h +17 -1
@@ -37,11 +37,27 @@ struct sysdev_class {struct kset kset; }; +struct sysdev_class_attribute { +struct attribute attr; +ssize_t (*show)(struct sysdev_class *,char *); +ssize_t (*store)(struct sysdev_class *,const char *,size_t ); +}; + +#define SYSDEV_CLASS_ATTR (_name,_mode,_show,_store) \ +struct sysdev_class_attribute attr_##_name = { \ + .attr = {.name = __stringify(_name), .mode = _mode }, \ + .show = _show, \ + .store = _store, \ +}; +extern int sysdev_class_register (struct sysdev_class *);extern void sysdev_class_unregister (struct sysdev_class *); - +extern int sysdev_class_create_file (struct sysdev_class *, +struct sysdev_class_attribute *); +extern void sysdev_class_remove_file (struct sysdev_class *, +struct sysdev_class_attribute *);/** * Auxillary system device drivers. */
Signature · 1 line
1.4.0
PATCH 12/22 Driver Core: Fix platform_device_add to use device_add
From: Russell King <[email protected]>
platform_device_add() should be using device_add() rather than device_register() - any platform device passed to platform_device_add() should have already been initialised, either by platform_device_alloc() or platform_device_register().
--- drivers/base/platform.c | 2 +- 1 files changed, 1 insertions(+), 1 deletions(-)
drivers/base/platform.c +1 -1
@@ -275,7 +275,7 @@ int platform_device_add(struct platform_pr_debug ("Registering platform device '%s'. Parent at %s\n" , pdev->dev.bus_id, pdev->dev.parent->bus_id); - ret =device_register (&pdev->dev); + ret =device_add (&pdev->dev);if (ret ==0 )return ret;
Signature · 1 line
1.4.0
PATCH 13/22 Driver Core: Add /sys/hypervisor when needed
From: Michael Holzheu <[email protected]>
To have a home for all hypervisors, this patch creates /sys/hypervisor. A new config option SYS_HYPERVISOR is introduced, which should to be set by architecture dependent hypervisors (e.g. s390 or Xen).
--- drivers/base/Kconfig | 4 ++++ drivers/base/Makefile | 1 + drivers/base/base.h | 5 +++++ drivers/base/hypervisor.c | 19 +++++++++++++++++++ drivers/base/init.c | 1 + include/linux/kobject.h | 2 ++ 6 files changed, 32 insertions(+), 0 deletions(-)
drivers/base/Kconfig +4 -0
@@ -38,3 +38,7 @@ config DEBUG_DRIVER If you are unsure about this, say N here. endmenu + +config SYS_HYPERVISOR + bool + default n
drivers/base/Makefile +1 -0
@@ -9,6 +9,7 @@ obj-$(CONFIG_FW_LOADER) += firmware_clas obj-$(CONFIG_NUMA) += node.o obj-$(CONFIG_MEMORY_HOTPLUG) += memory.o obj-$(CONFIG_SMP) += topology.o +obj-$(CONFIG_SYS_HYPERVISOR) += hypervisor.o ifeq ($(CONFIG_DEBUG_DRIVER),y) EXTRA_CFLAGS += -DDEBUG
drivers/base/base.h +5 -0
@@ -5,6 +5,11 @@ extern int devices_init(void);extern int buses_init (void );extern int classes_init (void );extern int firmware_init (void ); +#ifdef CONFIG_SYS_HYPERVISOR +extern int hypervisor_init (void ); +#else +static inline int hypervisor_init (void ) {return 0 ; } +#endif extern int platform_bus_init (void );extern int system_bus_init (void );extern int cpu_dev_init (void );
drivers/base/hypervisor.c new file +19 -0
@@ -0,0 +1,19 @@ +/* +* hypervisor.c - /sys/hypervisor subsystem. +* +* This file is released under the GPLv2 +* +*/ + +#include <linux/kobject.h> +#include <linux/device.h> + +#include "base.h" + +decl_subsys (hypervisor,NULL ,NULL ); +EXPORT_SYMBOL_GPL (hypervisor_subsys); + +int __init hypervisor_init (void ) +{ +return subsystem_register (&hypervisor_subsys); +}
drivers/base/init.c +1 -0
@@ -27,6 +27,7 @@ void __init driver_init(void)buses_init ();classes_init ();firmware_init (); +hypervisor_init ();/* These are also core pieces, but must come after the * core core pieces.
include/linux/kobject.h +2 -0
@@ -190,6 +190,8 @@ struct subsystem _varname##_subsys = { \/* The global /sys/kernel/ subsystem for people to chain off of */ extern struct subsystem kernel_subsys; +/* The global /sys/hypervisor/ subsystem */ +extern struct subsystem hypervisor_subsys;/** * Helpers for setting the kset of registered objects.
Signature · 1 line
1.4.0
PATCH 14/22 remove duplication from Documentation/power/devices.txt
From: David Brownell <[email protected]>
Remove a chunk of duplicated documentation text.
--- Documentation/power/devices.txt | 90 --------------------------------------- 1 files changed, 0 insertions(+), 90 deletions(-)
Documentation/power/devices.txt +0 -90
@@ -135,96 +135,6 @@ # NOTIFICATION -- pretty much same as ON FREEZE -- stop DMA and interrupts, and be prepared to reinit HW from scratch. That probably means stop accepting upstream requests, the -actual policy of what to do with them beeing specific to a given -driver. It's acceptable for a network driver to just drop packets -while a block driver is expected to block the queue so no request is -lost. (Use IDE as an example on how to do that). FREEZE requires no -power state change, and it's expected for drivers to be able to -quickly transition back to operating state. - -SUSPEND -- like FREEZE, but also put hardware into low-power state. If -there's need to distinguish several levels of sleep, additional flag -is probably best way to do that. - -Transitions are only from a resumed state to a suspended state, never -between 2 suspended states. (ON -> FREEZE or ON -> SUSPEND can happen, -FREEZE -> SUSPEND or SUSPEND -> FREEZE can not). - -All events are: - -[NOTE NOTE NOTE: If you are driver author, you should not care; you -should only look at event, and ignore flags.] - -#Prepare for suspend -- userland is still running but we are going to -#enter suspend state. This gives drivers chance to load firmware from -#disk and store it in memory, or do other activities taht require -#operating userland, ability to kmalloc GFP_KERNEL, etc... All of these -#are forbiden once the suspend dance is started.. event = ON, flags = -#PREPARE_TO_SUSPEND - -Apm standby -- prepare for APM event. Quiesce devices to make life -easier for APM BIOS. event = FREEZE, flags = APM_STANDBY - -Apm suspend -- same as APM_STANDBY, but it we should probably avoid -spinning down disks. event = FREEZE, flags = APM_SUSPEND - -System halt, reboot -- quiesce devices to make life easier for BIOS. event -= FREEZE, flags = SYSTEM_HALT or SYSTEM_REBOOT - -System shutdown -- at least disks need to be spun down, or data may be -lost. Quiesce devices, just to make life easier for BIOS. event = -FREEZE, flags = SYSTEM_SHUTDOWN - -Kexec -- turn off DMAs and put hardware into some state where new -kernel can take over. event = FREEZE, flags = KEXEC - -Powerdown at end of swsusp -- very similar to SYSTEM_SHUTDOWN, except wake -may need to be enabled on some devices. This actually has at least 3 -subtypes, system can reboot, enter S4 and enter S5 at the end of -swsusp. event = FREEZE, flags = SWSUSP and one of SYSTEM_REBOOT, -SYSTEM_SHUTDOWN, SYSTEM_S4 - -Suspend to ram -- put devices into low power state. event = SUSPEND, -flags = SUSPEND_TO_RAM - -Freeze for swsusp snapshot -- stop DMA and interrupts. No need to put -devices into low power mode, but you must be able to reinitialize -device from scratch in resume method. This has two flavors, its done -once on suspending kernel, once on resuming kernel. event = FREEZE, -flags = DURING_SUSPEND or DURING_RESUME - -Device detach requested from /sys -- deinitialize device; proably same as -SYSTEM_SHUTDOWN, I do not understand this one too much. probably event -= FREEZE, flags = DEV_DETACH. - -#These are not really events sent: -# -#System fully on -- device is working normally; this is probably never -#passed to suspend() method... event = ON, flags = 0 -# -#Ready after resume -- userland is now running, again. Time to free any -#memory you ate during prepare to suspend... event = ON, flags = -#READY_AFTER_RESUME -# - - -pm_message_t meaning - -pm_message_t has two fields. event ("major"), and flags. If driver -does not know event code, it aborts the request, returning error. Some -drivers may need to deal with special cases based on the actual type -of suspend operation being done at the system level. This is why -there are flags. - -Event codes are: - -ON -- no need to do anything except special cases like broken -HW. - -# NOTIFICATION -- pretty much same as ON? - -FREEZE -- stop DMA and interrupts, and be prepared to reinit HW from -scratch. That probably means stop accepting upstream requests, the actual policy of what to do with them being specific to a given driver. It's acceptable for a network driver to just drop packets while a block driver is expected to block the queue so no request is
Signature · 1 line
1.4.0
PATCH 15/22 Driver core: PM_DEBUG device suspend() messages become informative
From: David Brownell <[email protected]>
This makes the driver model PM suspend debug messages more useful, by
(a) explaining what event is being sent, since not all suspend()
requests mean the same thing;
(b) reporting when a PM_EVENT_SUSPEND call is allowing the device to issue wakeup events.
--- drivers/base/power/suspend.c | 17 ++++++++++++++++- 1 files changed, 16 insertions(+), 1 deletions(-)
drivers/base/power/suspend.c +16 -1
@@ -29,6 +29,15 @@ #include "power.h"* lists. This way, the ancestors will be accessed before their descendents. */ +static inline char *suspend_verb (u32 event) +{ +switch (event) { +case PM_EVENT_SUSPEND :return "suspend" ; +case PM_EVENT_FREEZE :return "freeze" ; +default :return "(unknown suspend event)" ; + } +} +/** * suspend_device - Save state of one device.
@@ -57,7 +66,13 @@ int suspend_device(struct device * dev, dev->power.prev_state = dev->power.power_state;if (dev->bus && dev->bus->suspend && !dev->power.power_state.event) { -dev_dbg (dev,"suspending\n" ); +dev_dbg (dev,"%s%s\n" , +suspend_verb (state.event), + ((state.event ==PM_EVENT_SUSPEND ) + &&device_may_wakeup (dev)) + ?", may wakeup" + :"" + ); error = dev->bus->suspend (dev, state);suspend_report_result (dev->bus->suspend, error); }
Signature · 1 line
1.4.0
PATCH 16/22 firmware_class: s/semaphores/mutexes
From: Laura Garcia <[email protected]>
Hi, this patch converts semaphores to mutexes for Randy's firmware_class.
--- drivers/base/firmware_class.c | 22 +++++++++++----------- 1 files changed, 11 insertions(+), 11 deletions(-)
drivers/base/firmware_class.c +11 -11
@@ -15,7 +15,7 @@ #include <linux/timer.h>#include <linux/vmalloc.h> #include <linux/interrupt.h> #include <linux/bitops.h> -#include <asm/semaphore.h> +#include <linux/mutex.h> #include <linux/firmware.h> #include "base.h"
@@ -36,7 +36,7 @@ static int loading_timeout = 10; /* In s/* fw_lock could be moved to 'struct firmware_priv' but since it is just * guarding for corner cases a global lock should be OK */ -static DECLARE_MUTEX (fw_lock); +static DEFINE_MUTEX (fw_lock);struct firmware_priv {char fw_id[FIRMWARE_NAME_MAX ];
@@ -142,9 +142,9 @@ firmware_loading_store(struct class_deviswitch (loading) {case 1 : -down (&fw_lock); +mutex_lock (&fw_lock);if (!fw_priv->fw) { -up (&fw_lock); +mutex_unlock (&fw_lock);break ; }vfree (fw_priv->fw->data);
@@ -152,7 +152,7 @@ firmware_loading_store(struct class_devi fw_priv->fw->size =0 ; fw_priv->alloc_size =0 ;set_bit (FW_STATUS_LOADING , &fw_priv->status); -up (&fw_lock); +mutex_unlock (&fw_lock);break ;case 0 :if (test_bit (FW_STATUS_LOADING , &fw_priv->status)) {
@@ -185,7 +185,7 @@ firmware_data_read(struct kobject *kobj,struct firmware *fw;ssize_t ret_count = count; -down (&fw_lock); +mutex_lock (&fw_lock); fw = fw_priv->fw;if (!fw ||test_bit (FW_STATUS_DONE , &fw_priv->status)) { ret_count = -ENODEV ;
@@ -200,7 +200,7 @@ firmware_data_read(struct kobject *kobj,memcpy (buffer, fw->data + offset, ret_count); out: -up (&fw_lock); +mutex_unlock (&fw_lock);return ret_count; }
@@ -253,7 +253,7 @@ firmware_data_write(struct kobject *kobjif (!capable (CAP_SYS_RAWIO ))return -EPERM ; -down (&fw_lock); +mutex_lock (&fw_lock); fw = fw_priv->fw;if (!fw ||test_bit (FW_STATUS_DONE , &fw_priv->status)) { retval = -ENODEV ;
@@ -268,7 +268,7 @@ firmware_data_write(struct kobject *kobj fw->size =max_t (size_t, offset + count, fw->size); retval = count; out: -up (&fw_lock); +mutex_unlock (&fw_lock);return retval; }
@@ -436,14 +436,14 @@ _request_firmware(const struct firmware }else wait_for_completion (&fw_priv->completion); -down (&fw_lock); +mutex_lock (&fw_lock);if (!fw_priv->fw->size ||test_bit (FW_STATUS_ABORT , &fw_priv->status)) { retval = -ENOENT ;release_firmware (fw_priv->fw); *firmware_p =NULL ; } fw_priv->fw =NULL ; -up (&fw_lock); +mutex_unlock (&fw_lock);class_device_unregister (class_dev); goto out;
Signature · 1 line
1.4.0
PATCH 17/22 Driver core: change make_class_name() to take kobjects
From: Greg Kroah-Hartman <[email protected]>
This is needed for a future patch for the device code to create the proper symlinks for devices that are "class devices".
--- drivers/base/base.h | 1 + drivers/base/class.c | 31 +++++++++++++++++-------------- 2 files changed, 18 insertions(+), 14 deletions(-)
drivers/base/base.h +1 -0
@@ -42,4 +42,5 @@ struct class_device_attribute *to_class_ return container_of(_attr, struct class_device_attribute, attr); } +extern char *make_class_name (const char *name,struct kobject *kobj);
drivers/base/class.c +17 -14
@@ -504,22 +504,21 @@ void class_device_initialize(struct clasINIT_LIST_HEAD (&class_dev->node); } -static char *make_class_name (struct class_device *class_dev) +char *make_class_name (const char *name,struct kobject *kobj) { -char *name; +char *class_name;int size; - size =strlen (class_dev->class->name) + -strlen (kobject_name (&class_dev->kobj)) +2 ; + size =strlen (name) +strlen (kobject_name (kobj)) +2 ; - name =kmalloc (size,GFP_KERNEL ); -if (!name) + class_name =kmalloc (size,GFP_KERNEL ); +if (!class_name)return ERR_PTR (-ENOMEM ); -strcpy (name, class_dev->class->name); -strcat (name,":" ); -strcat (name,kobject_name (&class_dev->kobj)); -return name; +strcpy (class_name, name); +strcat (class_name,":" ); +strcat (class_name,kobject_name (kobj)); +return class_name; }int class_device_add (struct class_device *class_dev)
@@ -594,7 +593,8 @@ int class_device_add(struct class_device goto out5;if (class_dev->dev) { - class_name =make_class_name (class_dev); + class_name =make_class_name (class_dev->class->name, + &class_dev->kobj); error =sysfs_create_link (&class_dev->kobj, &class_dev->dev->kobj,"device" );if (error)
@@ -731,7 +731,8 @@ void class_device_del(struct class_devic }if (class_dev->dev) { - class_name =make_class_name (class_dev); + class_name =make_class_name (class_dev->class->name, + &class_dev->kobj);sysfs_remove_link (&class_dev->kobj,"device" );sysfs_remove_link (&class_dev->dev->kobj, class_name); }
@@ -796,14 +797,16 @@ int class_device_rename(struct class_dev new_name);if (class_dev->dev) - old_class_name =make_class_name (class_dev); + old_class_name =make_class_name (class_dev->class->name, + &class_dev->kobj);strlcpy (class_dev->class_id, new_name,KOBJ_NAME_LEN ); error =kobject_rename (&class_dev->kobj, new_name);if (class_dev->dev) { - new_class_name =make_class_name (class_dev); + new_class_name =make_class_name (class_dev->class->name, + &class_dev->kobj);sysfs_create_link (&class_dev->dev->kobj, &class_dev->kobj, new_class_name);sysfs_remove_link (&class_dev->dev->kobj, old_class_name);
Signature · 1 line
1.4.0
PATCH 18/22 Driver core: allow struct device to have a dev_t
From: Greg Kroah-Hartman <[email protected]>
This is the first step in moving class_device to being replaced by struct device. It allows struct device to export a dev_t and makes it easy to dynamically create and destroy struct device as long as they are associated with a specific class.
--- drivers/base/class.c | 1 drivers/base/core.c | 162 ++++++++++++++++++++++++++++++++++++++++++++++++ include/linux/device.h | 14 ++++ 3 files changed, 176 insertions(+), 1 deletions(-)
drivers/base/class.c +1 -0
@@ -142,6 +142,7 @@ int class_register(struct class * cls)pr_debug ("device class '%s': registering\n" , cls->name);INIT_LIST_HEAD (&cls->children); +INIT_LIST_HEAD (&cls->devices);INIT_LIST_HEAD (&cls->interfaces);init_MUTEX (&cls->sem); error =kobject_set_name (&cls->subsys.kset.kobj,"%s" , cls->name);
drivers/base/core.c +161 -1
219 lines not on this page · raw message
include/linux/device.h +14 -0
@@ -142,6 +142,7 @@ struct class {struct subsystem subsys;struct list_head children; +struct list_head devices;struct list_head interfaces;struct semaphore sem;/* locks both the children and interfaces lists */
@@ -305,6 +306,7 @@ struct device {struct kobject kobj;char bus_id[BUS_ID_SIZE ];/* position on parent bus */ struct device_attribute uevent_attr; +struct device_attribute *devt_attr;struct semaphore sem;/* semaphore to synchronize calls to * its driver.
@@ -332,6 +334,11 @@ struct device {struct dma_coherent_mem *dma_mem;/* internal for coherent mem override */ +/* class_device migration path */ +struct list_head node; +struct class *class;/* optional*/ +dev_t devt;/* dev_t, creates the sysfs "dev" */ +void (*release)(struct device * dev); };
@@ -373,6 +380,13 @@ extern int device_attach(struct deviceextern void driver_attach (struct device_driver * drv);extern void device_reprobe (struct device *dev); +/* +* Easy functions for dynamically creating devices on the fly +*/ +extern struct device *device_create (struct class *cls,struct device *parent, +dev_t devt,char *fmt, ...) + __attribute__((format (printf,4 ,5 ))); +extern void device_destroy (struct class *cls,dev_t devt);/* * Platform "fixup" functions - allow the platform to have their say
Signature · 1 line
1.4.0
PATCH 19/22 Driver core: add generic "subsystem" link to all devices
From: Kay Sievers <[email protected]>
Like the SUBSYTEM= key we find in the environment of the uevent, this creates a generic "subsystem" link in sysfs for every device. Userspace usually doesn't care at all if its a "class" or a "bus" device. This provides an unified way to determine the subsytem of a device, regardless of the way the driver core has created it.
--- block/genhd.c | 7 ++----- drivers/base/bus.c | 2 ++ drivers/base/class.c | 2 ++ drivers/base/core.c | 9 +++++++-- fs/partitions/check.c | 4 ++++ 5 files changed, 17 insertions(+), 7 deletions(-)
block/genhd.c +2 -5
@@ -17,8 +17,7 @@ #include <linux/kobj_map.h>#include <linux/buffer_head.h> #include <linux/mutex.h> -static struct subsystem block_subsys; - +struct subsystem block_subsys;static DEFINE_MUTEX (block_subsys_lock);/*
@@ -511,9 +510,7 @@ static struct kset_uevent_ops block_ueve .uevent = block_uevent, }; -/* declare block_subsys. */ -static decl_subsys(block, &ktype_block, &block_uevent_ops); - +decl_subsys (block, &ktype_block, &block_uevent_ops);/* * aggregate disk stat collector. Uses the same stats that the sysfs
drivers/base/bus.c +2 -0
@@ -374,6 +374,7 @@ int bus_add_device(struct device * dev) error =device_add_attrs (bus, dev);if (!error) {sysfs_create_link (&bus->devices.kobj, &dev->kobj, dev->bus_id); +sysfs_create_link (&dev->kobj, &dev->bus->subsys.kset.kobj,"subsystem" );sysfs_create_link (&dev->kobj, &dev->bus->subsys.kset.kobj,"bus" ); } }
@@ -408,6 +409,7 @@ void bus_attach_device(struct device * dvoid bus_remove_device (struct device * dev) {if (dev->bus) { +sysfs_remove_link (&dev->kobj,"subsystem" );sysfs_remove_link (&dev->kobj,"bus" );sysfs_remove_link (&dev->bus->devices.kobj, dev->bus_id);device_remove_attrs (dev->bus, dev);
drivers/base/class.c +2 -0
@@ -561,6 +561,7 @@ int class_device_add(struct class_device goto out2;/* add the needed attributes to this device */ +sysfs_create_link (&class_dev->kobj, &parent_class->subsys.kset.kobj,"subsystem" ); class_dev->uevent_attr.attr.name ="uevent" ; class_dev->uevent_attr.attr.mode =S_IWUSR ; class_dev->uevent_attr.attr.owner = parent_class->owner;
@@ -737,6 +738,7 @@ void class_device_del(struct class_devicsysfs_remove_link (&class_dev->kobj,"device" );sysfs_remove_link (&class_dev->dev->kobj, class_name); } +sysfs_remove_link (&class_dev->kobj,"subsystem" );class_device_remove_file (class_dev, &class_dev->uevent_attr);if (class_dev->devt_attr)class_device_remove_file (class_dev, class_dev->devt_attr);
drivers/base/core.c +7 -2
@@ -319,9 +319,12 @@ int device_add(struct device *dev) dev->devt_attr = attr; } -if (dev->class) +if (dev->class) { +sysfs_create_link (&dev->kobj, &dev->class->subsys.kset.kobj, +"subsystem" );sysfs_create_link (&dev->class->subsys.kset.kobj, &dev->kobj, dev->bus_id); + }if ((error =device_pm_add (dev))) goto PMError;
@@ -422,8 +425,10 @@ void device_del(struct device * dev)klist_del (&dev->knode_parent);if (dev->devt_attr)device_remove_file (dev, dev->devt_attr); -if (dev->class) +if (dev->class) { +sysfs_remove_link (&dev->kobj,"subsystem" );sysfs_remove_link (&dev->class->subsys.kset.kobj, dev->bus_id); + }device_remove_file (dev, &dev->uevent_attr);/* Notify the platform of the removal, in case they
fs/partitions/check.c +4 -0
@@ -329,6 +329,7 @@ void delete_partition(struct gendisk *di p->ios[0 ] = p->ios[1 ] =0 ; p->sectors[0 ] = p->sectors[1 ] =0 ;devfs_remove ("%s/part%d" , disk->devfs_name, part); +sysfs_remove_link (&p->kobj,"subsystem" );if (p->holder_dir)kobject_unregister (p->holder_dir);kobject_uevent (&p->kobj,KOBJ_REMOVE );
@@ -363,6 +364,7 @@ void add_partition(struct gendisk *disk,kobject_add (&p->kobj);if (!disk->part_uevent_suppress)kobject_uevent (&p->kobj,KOBJ_ADD ); +sysfs_create_link (&p->kobj, &block_subsys.kset.kobj,"subsystem" );partition_sysfs_add_subdir (p); disk->part[part-1 ] = p; }
@@ -398,6 +400,7 @@ static void disk_sysfs_symlinks(struct gkfree (disk_name); } } +sysfs_create_link (&disk->kobj, &block_subsys.kset.kobj,"subsystem" ); }/* Not exported, helper to add_disk(). */
@@ -548,5 +551,6 @@ void del_gendisk(struct gendisk *disk)put_device (disk->driverfs_dev); disk->driverfs_dev =NULL ; } +sysfs_remove_link (&disk->kobj,"subsystem" );kobject_del (&disk->kobj); }
Signature · 1 line
1.4.0
PATCH 20/22 Driver core: add proper symlinks for devices
From: Greg Kroah-Hartman <[email protected]>
We need to create the "compatible" symlinks that class_devices used to create when they were in the class directories so that userspace does not know anything changed at all.
Yeah, we have a lot of symlinks now, but we should be able to get rid of them in a year or two... (wishful thinking...)
--- drivers/base/core.c | 11 +++++++++++ 1 files changed, 11 insertions(+), 0 deletions(-)
drivers/base/core.c +11 -0
@@ -273,6 +273,7 @@ void device_initialize(struct device *deint device_add (struct device *dev) {struct device *parent =NULL ; +char *class_name =NULL ;int error = -EINVAL ; dev =get_device (dev);
@@ -324,6 +325,10 @@ int device_add(struct device *dev) "subsystem");sysfs_create_link (&dev->class->subsys.kset.kobj, &dev->kobj, dev->bus_id); + +sysfs_create_link (&dev->kobj, &dev->parent->kobj,"device" ); + class_name =make_class_name (dev->class->name, &dev->kobj); +sysfs_create_link (&dev->parent->kobj, &dev->kobj, class_name); }if ((error =device_pm_add (dev)))
@@ -339,6 +344,7 @@ int device_add(struct device *dev)if (platform_notify)platform_notify (dev); Done: +kfree (class_name);put_device (dev);return error; BusError:
@@ -420,6 +426,7 @@ void put_device(struct device * dev)void device_del (struct device * dev) {struct device * parent = dev->parent; +char *class_name =NULL ;if (parent)klist_del (&dev->knode_parent);
@@ -428,6 +435,10 @@ void device_del(struct device * dev)if (dev->class) {sysfs_remove_link (&dev->kobj,"subsystem" );sysfs_remove_link (&dev->class->subsys.kset.kobj, dev->bus_id); + class_name =make_class_name (dev->class->name, &dev->kobj); +sysfs_remove_link (&dev->kobj,"device" ); +sysfs_remove_link (&dev->parent->kobj, class_name); +kfree (class_name); }device_remove_file (dev, &dev->uevent_attr);
Signature · 1 line
1.4.0
PATCH 21/22 Driver Core: Make dev_info and friends print the bus name if there is no driver
From: Alan Stern <[email protected]>
This patch (as721) makes dev_info and related macros print the device's bus name if the device doesn't have a driver, instead of printing just a blank. If the device isn't on a bus either... well, then it does leave a blank space. But it will be easier for someone else to change if they want.
--- drivers/base/core.c | 16 ++++++++++++++++ include/linux/device.h | 3 ++- 2 files changed, 18 insertions(+), 1 deletions(-)
drivers/base/core.c +16 -0
@@ -29,6 +29,22 @@ int (*platform_notify_remove)(struct dev* sysfs bindings for devices. */ +/** +* dev_driver_string - Return a device's driver name, if at all possible +* @dev: struct device to get the name of +* +* Will return the device's driver's name if it is bound to a device. If +* the device is not bound to a device, it will return the name of the bus +* it is attached to. If it is not attached to a bus either, an empty +* string will be returned. +*/ +const char *dev_driver_string (struct device *dev) +{ +return dev->driver ? dev->driver->name : + (dev->bus ? dev->bus->name :"" ); +} +EXPORT_SYMBOL_GPL (dev_driver_string); +#define to_dev (obj) container_of(obj, struct device, kobj)#define to_dev_attr (_attr) container_of(_attr, struct device_attribute, attr)
include/linux/device.h +2 -1
@@ -416,8 +416,9 @@ extern int firmware_register(struct subsextern void firmware_unregister (struct subsystem *);/* debugging and troubleshooting/diagnostic helpers. */ +extern const char *dev_driver_string (struct device *dev); #define dev_printk(level, dev, format, arg...) \ - printk(level "%s %s: " format , (dev)->driver ? (dev)->driver->name : "" , (dev)->bus_id , ## arg) + printk(level "%s %s: " format , dev_driver_string(dev) , (dev)->bus_id , ## arg)#ifdef DEBUG #define dev_dbg(dev, format, arg...) \
Signature · 1 line
1.4.0
PATCH 22/22 Driver model: add ISA bus
From: Rene Herman <[email protected]>
During the recent "isa drivers using platform devices" discussion it was pointed out that (ALSA) ISA drivers ran into the problem of not having the option to fail driver load (device registration rather) upon not finding their hardware due to a probe() error not being passed up through the driver model. In the course of that, I suggested a seperate ISA bus might be best; Russell King agreed and suggested this bus could use the .match() method for the actual device discovery.
The attached does this. For this old non (generically) discoverable ISA hardware only the driver itself can do discovery so as a difference with the platform_bus, this isa_bus also distributes match() up to the driver.
As another difference: these devices only exist in the driver model due to the driver creating them because it might want to drive them, meaning that all device creation has been made internal as well.
The usage model this provides is nice, and has been acked from the ALSA side by Takashi Iwai and Jaroslav Kysela. The ALSA driver module_init's now (for oldisa-only drivers) become:
static int __init alsa_card_foo_init(void)
{
return isa_register_driver(&snd_foo_isa_driver, SNDRV_CARDS);
}static void __exit alsa_card_foo_exit(void)
{
isa_unregister_driver(&snd_foo_isa_driver);
}Quite like the other bus models therefore. This removes a lot of duplicated init code from the ALSA ISA drivers.
The passed in isa_driver struct is the regular driver struct embedding a struct device_driver, the normal probe/remove/shutdown/suspend/resume callbacks, and as indicated that .match callback.
The "SNDRV_CARDS" you see being passed in is a "unsigned int ndev" parameter, indicating how many devices to create and call our methods with.
The platform_driver callbacks are called with a platform_device param; the isa_driver callbacks are being called with a "struct device *dev, unsigned int id" pair directly -- with the device creation completely internal to the bus it's much cleaner to not leak isa_dev's by passing them in at all. The id is the only thing we ever want other then the struct device * anyways, and it makes for nicer code in the callbacks as well.
With this additional .match() callback ISA drivers have all options. If ALSA would want to keep the old non-load behaviour, it could stick all of the old .probe in .match, which would only keep them registered after everything was found to be present and accounted for. If it wanted the behaviour of always loading as it inadvertently did for a bit after the changeover to platform devices, it could just not provide a .match() and do everything in .probe() as before.
If it, as Takashi Iwai already suggested earlier as a way of following the model from saner buses more closely, wants to load when a later bind could conceivably succeed, it could use .match() for the prerequisites (such as checking the user wants the card enabled and that port/irq/dma values have been passed in) and .probe() for everything else. This is the nicest model.
To the code...
This exports only two functions; isa_{,un}register_driver().
isa_register_driver() register's the struct device_driver, and then loops over the passed in ndev creating devices and registering them. This causes the bus match method to be called for them, which is:
int isa_bus_match(struct device *dev, struct device_driver *driver)
{
struct isa_driver *isa_driver = to_isa_driver(driver);
if (dev->platform_data == isa_driver) {
if (!isa_driver->match ||
isa_driver->match(dev, to_isa_dev(dev)->id))
return 1;
dev->platform_data = NULL;
}
return 0;
}The first thing this does is check if this device is in fact one of this driver's devices by seeing if the device's platform_data pointer is set to this driver. Platform devices compare strings, but we don't need to do that with everything being internal, so isa_register_driver() abuses dev->platform_data as a isa_driver pointer which we can then check here. I believe platform_data is available for this, but if rather not, moving the isa_driver pointer to the private struct isa_dev is ofcourse fine as well.
Then, if the the driver did not provide a .match, it matches. If it did, the driver match() method is called to determine a match.
If it did _not_ match, dev->platform_data is reset to indicate this to isa_register_driver which can then unregister the device again.
If during all this, there's any error, or no devices matched at all everything is backed out again and the error, or -ENODEV, is returned.
isa_unregister_driver() just unregisters the matched devices and the driver itself.
More global points/questions...
- I'm introducing include/linux/isa.h. It was available but is ofcourse a somewhat generic name. Moving more isa stuff over to it in time is ofcourse fine, so can I have it please? :)
- I'm using device_initcall() and added the isa.o (dependent on CONFIG_ISA) after the base driver model things in the Makefile. Will this do, or I really need to stick it in drivers/base/init.c, inside #ifdef CONFIG_ISA? It's working fine.
Lastly -- I also looked, a bit, into integrating with PnP. "Old ISA" could be another pnp_protocol, but this does not seem to be a good match, largely due to the same reason platform_devices weren't -- the devices do not have a life of their own outside the driver, meaning the pnp_protocol {get,set}_resources callbacks would need to callback into driver -- which again means you first need to _have_ that driver. Even if there's clean way around that, you only end up inventing fake but valid-form PnP IDs and generally catering to the PnP layer without any practical advantages over this very simple isa_bus. The thing I also suggested earlier about the user echoing values into /sys to set up the hardware from userspace first is... well, cute, but a horrible idea from a user standpoint.
Comments ofcourse appreciated. Hope it's okay. As said, the usage model is nice at least.
--- drivers/base/Makefile | 1 drivers/base/isa.c | 180 +++++++++++++++++++++++++++++++++++++++++++++++++ include/linux/isa.h | 28 ++++++++ 3 files changed, 209 insertions(+), 0 deletions(-)
drivers/base/Makefile +1 -0
@@ -5,6 +5,7 @@ obj-y := core.o sys.o bus.o dd.o \ cpu.o firmware.o init.o map.o dmapool.o \ attribute_container.o transport_class.o obj-y += power/ +obj-$(CONFIG_ISA) += isa.o obj-$(CONFIG_FW_LOADER) += firmware_class.o obj-$(CONFIG_NUMA) += node.o obj-$(CONFIG_MEMORY_HOTPLUG) += memory.o
drivers/base/isa.c new file +180 -0
180 lines not on this page · raw message
include/linux/isa.h new file +28 -0
@@ -0,0 +1,28 @@ +/* +* ISA bus. +*/ + +#ifndef __LINUX_ISA_H +#define __LINUX_ISA_H + +#include <linux/device.h> +#include <linux/kernel.h> + +struct isa_driver { +int (*match)(struct device *,unsigned int ); +int (*probe)(struct device *,unsigned int ); +int (*remove)(struct device *,unsigned int ); +void (*shutdown)(struct device *,unsigned int ); +int (*suspend)(struct device *,unsigned int ,pm_message_t ); +int (*resume)(struct device *,unsigned int ); + +struct device_driver driver; +struct device *devices; +}; + +#define to_isa_driver (x) container_of((x), struct isa_driver, driver) + +int isa_register_driver (struct isa_driver *,unsigned int ); +void isa_unregister_driver (struct isa_driver *); + +#endif /* __LINUX_ISA_H */
Signature · 1 line
1.4.0