linux-kernel.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
* [GIT PATCH] Driver Core patches for 2.6.17
@ 2006-06-21 19:45 Greg KH
  2006-06-21 19:45 ` [PATCH 1/22] [PATCH] kobject: make people pay attention to kobject_add errors Greg KH
  0 siblings, 1 reply; 23+ messages in thread
From: Greg KH @ 2006-06-21 19:45 UTC (permalink / raw)
  To: Linus Torvalds, Andrew Morton; +Cc: linux-kernel

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


^ permalink raw reply	[flat|nested] 23+ messages in thread

* [PATCH 1/22] [PATCH] kobject: make people pay attention to kobject_add errors
  2006-06-21 19:45 [GIT PATCH] Driver Core patches for 2.6.17 Greg KH
@ 2006-06-21 19:45 ` Greg KH
  2006-06-21 19:45   ` [PATCH 2/22] [PATCH] Add kernel<->userspace ABI stability documentation Greg KH
  0 siblings, 1 reply; 23+ messages in thread
From: Greg KH @ 2006-06-21 19:45 UTC (permalink / raw)
  To: linux-kernel; +Cc: Greg Kroah-Hartman

From: Greg Kroah-Hartman <gregkh@suse.de>

These really need to be fixed, shout it out to the world.

Signed-off-by: Greg Kroah-Hartman <gregkh@suse.de>
---
 lib/kobject.c |    6 +++---
 1 files changed, 3 insertions(+), 3 deletions(-)

diff --git a/lib/kobject.c b/lib/kobject.c
index 687ab41..8e7c719 100644
--- a/lib/kobject.c
+++ b/lib/kobject.c
@@ -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;
-- 
1.4.0


^ permalink raw reply related	[flat|nested] 23+ messages in thread

* [PATCH 2/22] [PATCH] Add kernel<->userspace ABI stability documentation
  2006-06-21 19:45 ` [PATCH 1/22] [PATCH] kobject: make people pay attention to kobject_add errors Greg KH
@ 2006-06-21 19:45   ` Greg KH
  2006-06-21 19:45     ` [PATCH 3/22] [PATCH] CCISS: add device symlink to the block cciss block devices in sysfs Greg KH
  0 siblings, 1 reply; 23+ messages in thread
From: Greg KH @ 2006-06-21 19:45 UTC (permalink / raw)
  To: linux-kernel; +Cc: Greg Kroah-Hartman, Kay Sievers

From: Greg Kroah-Hartman <gregkh@suse.de>

Signed-off-by: Kay Sievers <kay.sievers@suse.de>
Signed-off-by: Greg Kroah-Hartman <gregkh@suse.de>
---
 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(-)

diff --git a/Documentation/ABI/README b/Documentation/ABI/README
new file mode 100644
index 0000000..9feaf16
--- /dev/null
+++ b/Documentation/ABI/README
@@ -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.
diff --git a/Documentation/ABI/obsolete/devfs b/Documentation/ABI/obsolete/devfs
new file mode 100644
index 0000000..b8b8739
--- /dev/null
+++ b/Documentation/ABI/obsolete/devfs
@@ -0,0 +1,13 @@
+What:		devfs
+Date:		July 2005
+Contact:	Greg Kroah-Hartman <gregkh@suse.de>
+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:
+
diff --git a/Documentation/ABI/stable/syscalls b/Documentation/ABI/stable/syscalls
new file mode 100644
index 0000000..c3ae3e7
--- /dev/null
+++ b/Documentation/ABI/stable/syscalls
@@ -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.
diff --git a/Documentation/ABI/stable/sysfs-module b/Documentation/ABI/stable/sysfs-module
new file mode 100644
index 0000000..75be431
--- /dev/null
+++ b/Documentation/ABI/stable/sysfs-module
@@ -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.
diff --git a/Documentation/ABI/testing/sysfs-class b/Documentation/ABI/testing/sysfs-class
new file mode 100644
index 0000000..4b0cb89
--- /dev/null
+++ b/Documentation/ABI/testing/sysfs-class
@@ -0,0 +1,16 @@
+What:		/sys/class/
+Date:		Febuary 2006
+Contact:	Greg Kroah-Hartman <gregkh@suse.de>
+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 <linux-hotplug-devel@lists.sourceforge.net>
diff --git a/Documentation/ABI/testing/sysfs-devices b/Documentation/ABI/testing/sysfs-devices
new file mode 100644
index 0000000..6a25671
--- /dev/null
+++ b/Documentation/ABI/testing/sysfs-devices
@@ -0,0 +1,25 @@
+What:		/sys/devices
+Date:		February 2006
+Contact:	Greg Kroah-Hartman <gregkh@suse.de>
+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 <linux-hotplug-devel@lists.sourceforge.net>
-- 
1.4.0


^ permalink raw reply related	[flat|nested] 23+ messages in thread

* [PATCH 3/22] [PATCH] CCISS: add device symlink to the block cciss block devices in sysfs
  2006-06-21 19:45   ` [PATCH 2/22] [PATCH] Add kernel<->userspace ABI stability documentation Greg KH
@ 2006-06-21 19:45     ` Greg KH
  2006-06-21 19:45       ` [PATCH 4/22] [PATCH] Driver core: bus device event delay Greg KH
  0 siblings, 1 reply; 23+ messages in thread
From: Greg KH @ 2006-06-21 19:45 UTC (permalink / raw)
  To: linux-kernel; +Cc: Greg Kroah-Hartman

From: Greg Kroah-Hartman <gregkh@suse.de>

Signed-off-by: Greg Kroah-Hartman <gregkh@suse.de>
---
 drivers/block/cciss.c |    1 +
 1 files changed, 1 insertions(+), 0 deletions(-)

diff --git a/drivers/block/cciss.c b/drivers/block/cciss.c
index 1319d8f..25c3c4a 100644
--- a/drivers/block/cciss.c
+++ b/drivers/block/cciss.c
@@ -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)
-- 
1.4.0


^ permalink raw reply related	[flat|nested] 23+ messages in thread

* [PATCH 4/22] [PATCH] Driver core: bus device event delay
  2006-06-21 19:45     ` [PATCH 3/22] [PATCH] CCISS: add device symlink to the block cciss block devices in sysfs Greg KH
@ 2006-06-21 19:45       ` Greg KH
  2006-06-21 19:45         ` [PATCH 5/22] [PATCH] TTY: return class device pointer from tty_register_device() Greg KH
  0 siblings, 1 reply; 23+ messages in thread
From: Greg KH @ 2006-06-21 19:45 UTC (permalink / raw)
  To: linux-kernel; +Cc: Kay Sievers, Greg Kroah-Hartman

From: Kay Sievers <kay.sievers@suse.de>

split bus_add_device() and send device uevents after sysfs population

Signed-off-by: Kay Sievers <kay.sievers@suse.de>
Signed-off-by: Greg Kroah-Hartman <gregkh@suse.de>
---
 drivers/base/base.h |    1 +
 drivers/base/bus.c  |   22 ++++++++++++++++++----
 drivers/base/core.c |    3 ++-
 3 files changed, 21 insertions(+), 5 deletions(-)

diff --git a/drivers/base/base.h b/drivers/base/base.h
index 5735b38..bbbc2ac 100644
--- a/drivers/base/base.h
+++ b/drivers/base/base.h
@@ -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 *);
diff --git a/drivers/base/bus.c b/drivers/base/bus.c
index 76656ac..b27a606 100644
--- a/drivers/base/bus.c
+++ b/drivers/base/bus.c
@@ -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);
diff --git a/drivers/base/core.c b/drivers/base/core.c
index 6b355bd..d5e15a0 100644
--- a/drivers/base/core.c
+++ b/drivers/base/core.c
@@ -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);
 
-- 
1.4.0


^ permalink raw reply related	[flat|nested] 23+ messages in thread

* [PATCH 5/22] [PATCH] TTY: return class device pointer from tty_register_device()
  2006-06-21 19:45       ` [PATCH 4/22] [PATCH] Driver core: bus device event delay Greg KH
@ 2006-06-21 19:45         ` Greg KH
  2006-06-21 19:45           ` [PATCH 6/22] [PATCH] i4l gigaset: move sysfs entry to tty class device Greg KH
  0 siblings, 1 reply; 23+ messages in thread
From: Greg KH @ 2006-06-21 19:45 UTC (permalink / raw)
  To: linux-kernel; +Cc: Hansjoerg Lipp, Tilman Schmidt, Greg Kroah-Hartman

From: Hansjoerg Lipp <hjlipp@web.de>

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.

Signed-off-by: Hansjoerg Lipp <hjlipp@web.de>
Signed-off-by: Tilman Schmidt <tilman@imap.cc>
Signed-off-by: Greg Kroah-Hartman <gregkh@suse.de>
---
 drivers/char/tty_io.c |   11 +++++++----
 include/linux/tty.h   |    4 +++-
 2 files changed, 10 insertions(+), 5 deletions(-)

diff --git a/drivers/char/tty_io.c b/drivers/char/tty_io.c
index a88b94a..8b2a599 100644
--- a/drivers/char/tty_io.c
+++ b/drivers/char/tty_io.c
@@ -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_driv
 	if (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_driv
 		pty_line_name(driver, index, name);
 	else
 		tty_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);
 }
 
 /**
diff --git a/include/linux/tty.h b/include/linux/tty.h
index e898eeb..cb35ca5 100644
--- a/include/linux/tty.h
+++ b/include/linux/tty.h
@@ -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);
-- 
1.4.0


^ permalink raw reply related	[flat|nested] 23+ messages in thread

* [PATCH 6/22] [PATCH] i4l gigaset: move sysfs entry to tty class device
  2006-06-21 19:45         ` [PATCH 5/22] [PATCH] TTY: return class device pointer from tty_register_device() Greg KH
@ 2006-06-21 19:45           ` Greg KH
  2006-06-21 19:45             ` [PATCH 7/22] [PATCH] Driver core: class_device_add needs error checks Greg KH
  0 siblings, 1 reply; 23+ messages in thread
From: Greg KH @ 2006-06-21 19:45 UTC (permalink / raw)
  To: linux-kernel; +Cc: Hansjoerg Lipp, Tilman Schmidt, Greg Kroah-Hartman

From: Hansjoerg Lipp <hjlipp@web.de>

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.

Signed-off-by: Hansjoerg Lipp <hjlipp@web.de>
Signed-off-by: Tilman Schmidt <tilman@imap.cc>
Signed-off-by: Greg Kroah-Hartman <gregkh@suse.de>
---
 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(-)

diff --git a/Documentation/isdn/README.gigaset b/Documentation/isdn/README.gigaset
index 85a64de..fa0d4cc 100644
--- a/Documentation/isdn/README.gigaset
+++ b/Documentation/isdn/README.gigaset
@@ -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
diff --git a/drivers/isdn/gigaset/common.c b/drivers/isdn/gigaset/common.c
index e55767b..acb7e26 100644
--- a/drivers/isdn/gigaset/common.c
+++ b/drivers/isdn/gigaset/common.c
@@ -460,6 +460,9 @@ void gigaset_freecs(struct cardstate *cs
 
 	switch (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(struct 
 
 	gigaset_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:
diff --git a/drivers/isdn/gigaset/gigaset.h b/drivers/isdn/gigaset/gigaset.h
index 22b9693..8d63d82 100644
--- a/drivers/isdn/gigaset/gigaset.h
+++ b/drivers/isdn/gigaset/gigaset.h
@@ -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;
 
diff --git a/drivers/isdn/gigaset/interface.c b/drivers/isdn/gigaset/interface.c
index 08e4c4e..74fd234 100644
--- a/drivers/isdn/gigaset/interface.c
+++ b/drivers/isdn/gigaset/interface.c
@@ -625,7 +625,14 @@ void gigaset_if_init(struct cardstate *c
 		return;
 
 	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 *c
 
 	tasklet_disable(&cs->if_wake_tasklet);
 	tasklet_kill(&cs->if_wake_tasklet);
+	cs->class = NULL;
 	tty_unregister_device(drv->tty, cs->minor_index);
 }
 
diff --git a/drivers/isdn/gigaset/proc.c b/drivers/isdn/gigaset/proc.c
index d267a63..9ae3a7f 100644
--- a/drivers/isdn/gigaset/proc.c
+++ b/drivers/isdn/gigaset/proc.c
@@ -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 devic
 	return 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 device
 	return 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);
 }
-- 
1.4.0


^ permalink raw reply related	[flat|nested] 23+ messages in thread

* [PATCH 7/22] [PATCH] Driver core: class_device_add needs error checks
  2006-06-21 19:45           ` [PATCH 6/22] [PATCH] i4l gigaset: move sysfs entry to tty class device Greg KH
@ 2006-06-21 19:45             ` Greg KH
  2006-06-21 19:45               ` [PATCH 8/22] [PATCH] Driver Core: CONFIG_DEBUG_PM covers drivers/base/power too Greg KH
  0 siblings, 1 reply; 23+ messages in thread
From: Greg KH @ 2006-06-21 19:45 UTC (permalink / raw)
  To: linux-kernel; +Cc: Stephen Hemminger, Greg Kroah-Hartman

From: Stephen Hemminger <shemminger@osdl.org>

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.

Signed-off-by: Stephen Hemminger <shemminger@osdl.org>
Signed-off-by: Greg Kroah-Hartman <gregkh@suse.de>
---
 drivers/base/class.c |   72 ++++++++++++++++++++++++++++++++++++++------------
 1 files changed, 54 insertions(+), 18 deletions(-)

diff --git a/drivers/base/class.c b/drivers/base/class.c
index b1ea4df..48ad5df 100644
--- a/drivers/base/class.c
+++ b/drivers/base/class.c
@@ -535,18 +535,22 @@ int class_device_add(struct class_device
 		return -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;
-- 
1.4.0


^ permalink raw reply related	[flat|nested] 23+ messages in thread

* [PATCH 8/22] [PATCH] Driver Core: CONFIG_DEBUG_PM covers drivers/base/power too
  2006-06-21 19:45             ` [PATCH 7/22] [PATCH] Driver core: class_device_add needs error checks Greg KH
@ 2006-06-21 19:45               ` Greg KH
  2006-06-21 19:45                 ` [PATCH 9/22] [PATCH] platform_bus learns about modalias Greg KH
  0 siblings, 1 reply; 23+ messages in thread
From: Greg KH @ 2006-06-21 19:45 UTC (permalink / raw)
  To: linux-kernel; +Cc: David Brownell, David Brownell, Greg Kroah-Hartman

From: David Brownell <david-b@pacbell.net>

The drivers/base/power PM debug messages should appear when
either PM or driver model debug are enabled.

Signed-off-by: David Brownell <dbrownell@users.sourceforge.net>
Signed-off-by: Greg Kroah-Hartman <gregkh@suse.de>
---
 drivers/base/power/Makefile |    3 +++
 1 files changed, 3 insertions(+), 0 deletions(-)

diff --git a/drivers/base/power/Makefile b/drivers/base/power/Makefile
index c0219ad..ceeeba2 100644
--- a/drivers/base/power/Makefile
+++ b/drivers/base/power/Makefile
@@ -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
-- 
1.4.0


^ permalink raw reply related	[flat|nested] 23+ messages in thread

* [PATCH 9/22] [PATCH] platform_bus learns about modalias
  2006-06-21 19:45               ` [PATCH 8/22] [PATCH] Driver Core: CONFIG_DEBUG_PM covers drivers/base/power too Greg KH
@ 2006-06-21 19:45                 ` Greg KH
  2006-06-21 19:45                   ` [PATCH 10/22] [PATCH] Driver Core: remove unused exports Greg KH
  0 siblings, 1 reply; 23+ messages in thread
From: Greg KH @ 2006-06-21 19:45 UTC (permalink / raw)
  To: linux-kernel; +Cc: David Brownell, David Brownell, Greg Kroah-Hartman

From: David Brownell <david-b@pacbell.net>

This patch adds modalias support to platform devices, for simpler
hotplug/coldplug driven driver setup.

Signed-off-by: David Brownell <dbrownell@users.sourceforge.net>
Signed-off-by: Greg Kroah-Hartman <gregkh@suse.de>
---
 drivers/base/platform.c |   33 +++++++++++++++++++++++++++++++++
 1 files changed, 33 insertions(+), 0 deletions(-)

diff --git a/drivers/base/platform.c b/drivers/base/platform.c
index 83f5c59..f807197 100644
--- a/drivers/base/platform.c
+++ b/drivers/base/platform.c
@@ -452,6 +452,37 @@ void platform_driver_unregister(struct p
 EXPORT_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 device
 
 struct bus_type platform_bus_type = {
 	.name		= "platform",
+	.dev_attrs	= platform_dev_attrs,
 	.match		= platform_match,
+	.uevent		= platform_uevent,
 	.suspend	= platform_suspend,
 	.resume		= platform_resume,
 };
-- 
1.4.0


^ permalink raw reply related	[flat|nested] 23+ messages in thread

* [PATCH 10/22] [PATCH] Driver Core: remove unused exports
  2006-06-21 19:45                 ` [PATCH 9/22] [PATCH] platform_bus learns about modalias Greg KH
@ 2006-06-21 19:45                   ` Greg KH
  2006-06-21 19:45                     ` [PATCH 11/22] [PATCH] Driver Core: Allow sysdev_class have attributes Greg KH
  0 siblings, 1 reply; 23+ messages in thread
From: Greg KH @ 2006-06-21 19:45 UTC (permalink / raw)
  To: linux-kernel; +Cc: Greg Kroah-Hartman

From: Greg Kroah-Hartman <gregkh@suse.de>

Cc: Arjan van de Ven <arjan@linux.intel.com>
Signed-off-by: Greg Kroah-Hartman <gregkh@suse.de>
---
 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(-)

diff --git a/drivers/base/attribute_container.c b/drivers/base/attribute_container.c
index 2a7d7ae..2222073 100644
--- a/drivers/base/attribute_container.c
+++ b/drivers/base/attribute_container.c
@@ -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 cla
 
 	return 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(str
 		return 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(struct 
 	for (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(str
 	attribute_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
diff --git a/drivers/base/base.h b/drivers/base/base.h
index bbbc2ac..122498a 100644
--- a/drivers/base/base.h
+++ b/drivers/base/base.h
@@ -13,6 +13,8 @@ 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 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 *);
diff --git a/drivers/base/bus.c b/drivers/base/bus.c
index b27a606..64ba901 100644
--- a/drivers/base/bus.c
+++ b/drivers/base/bus.c
@@ -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);
diff --git a/drivers/base/class.c b/drivers/base/class.c
index 48ad5df..4b598be 100644
--- a/drivers/base/class.c
+++ b/drivers/base/class.c
@@ -91,14 +91,14 @@ void class_remove_file(struct class * cl
 		sysfs_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);
 
diff --git a/include/linux/device.h b/include/linux/device.h
index b2e5da2..ade10dd 100644
--- a/include/linux/device.h
+++ b/include/linux/device.h
@@ -60,11 +60,6 @@ extern void bus_unregister(struct bus_ty
 
 extern 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;
-- 
1.4.0


^ permalink raw reply related	[flat|nested] 23+ messages in thread

* [PATCH 11/22] [PATCH] Driver Core: Allow sysdev_class have attributes
  2006-06-21 19:45                   ` [PATCH 10/22] [PATCH] Driver Core: remove unused exports Greg KH
@ 2006-06-21 19:45                     ` Greg KH
  2006-06-21 19:45                       ` [PATCH 12/22] [PATCH] Driver Core: Fix platform_device_add to use device_add Greg KH
  0 siblings, 1 reply; 23+ messages in thread
From: Greg KH @ 2006-06-21 19:45 UTC (permalink / raw)
  To: linux-kernel; +Cc: Shaohua Li, Greg Kroah-Hartman

From: Shaohua Li <shaohua.li@intel.com>

allow sysdev_class adding attribute. Next patch will use the new API to
add an attribute under /sys/device/system/cpu/.

Signed-off-by: Shaohua Li <shaohua.li@intel.com>
Signed-off-by: Greg Kroah-Hartman <gregkh@suse.de>
---
 drivers/base/sys.c     |   51 +++++++++++++++++++++++++++++++++++++++++++++++-
 include/linux/sysdev.h |   18 ++++++++++++++++-
 2 files changed, 67 insertions(+), 2 deletions(-)

diff --git a/drivers/base/sys.c b/drivers/base/sys.c
index 6fc23ab..6858178 100644
--- a/drivers/base/sys.c
+++ b/drivers/base/sys.c
@@ -80,10 +80,59 @@ void sysdev_remove_file(struct sys_devic
 EXPORT_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)
 {
diff --git a/include/linux/sysdev.h b/include/linux/sysdev.h
index 2a4b432..166a2e5 100644
--- a/include/linux/sysdev.h
+++ b/include/linux/sysdev.h
@@ -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.
  */
-- 
1.4.0


^ permalink raw reply related	[flat|nested] 23+ messages in thread

* [PATCH 12/22] [PATCH] Driver Core: Fix platform_device_add to use device_add
  2006-06-21 19:45                     ` [PATCH 11/22] [PATCH] Driver Core: Allow sysdev_class have attributes Greg KH
@ 2006-06-21 19:45                       ` Greg KH
  2006-06-21 19:45                         ` [PATCH 13/22] [PATCH] Driver Core: Add /sys/hypervisor when needed Greg KH
  0 siblings, 1 reply; 23+ messages in thread
From: Greg KH @ 2006-06-21 19:45 UTC (permalink / raw)
  To: linux-kernel; +Cc: Russell King, Russell King, Greg Kroah-Hartman

From: Russell King <rmk+lkml@arm.linux.org.uk>

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().

Signed-off-by: Russell King <rmk@arm.linux.org.uk>
Signed-off-by: Greg Kroah-Hartman <gregkh@suse.de>
---
 drivers/base/platform.c |    2 +-
 1 files changed, 1 insertions(+), 1 deletions(-)

diff --git a/drivers/base/platform.c b/drivers/base/platform.c
index f807197..2b8755d 100644
--- a/drivers/base/platform.c
+++ b/drivers/base/platform.c
@@ -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;
 
-- 
1.4.0


^ permalink raw reply related	[flat|nested] 23+ messages in thread

* [PATCH 13/22] [PATCH] Driver Core: Add /sys/hypervisor when needed
  2006-06-21 19:45                       ` [PATCH 12/22] [PATCH] Driver Core: Fix platform_device_add to use device_add Greg KH
@ 2006-06-21 19:45                         ` Greg KH
  2006-06-21 19:45                           ` [PATCH 14/22] [PATCH] remove duplication from Documentation/power/devices.txt Greg KH
  0 siblings, 1 reply; 23+ messages in thread
From: Greg KH @ 2006-06-21 19:45 UTC (permalink / raw)
  To: linux-kernel; +Cc: Michael Holzheu, Greg Kroah-Hartman

From: Michael Holzheu <holzheu@de.ibm.com>

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).

Acked-by: Martin Schwidefsky <schwidefsky@de.ibm.com>
Signed-off-by: Michael Holzheu <holzheu@de.ibm.com>
Signed-off-by: Greg Kroah-Hartman <gregkh@suse.de>
---
 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(-)

diff --git a/drivers/base/Kconfig b/drivers/base/Kconfig
index f0eff3d..80502dc 100644
--- a/drivers/base/Kconfig
+++ b/drivers/base/Kconfig
@@ -38,3 +38,7 @@ config DEBUG_DRIVER
 	  If you are unsure about this, say N here.
 
 endmenu
+
+config SYS_HYPERVISOR
+	bool
+	default n
diff --git a/drivers/base/Makefile b/drivers/base/Makefile
index e99471d..659cde6 100644
--- a/drivers/base/Makefile
+++ b/drivers/base/Makefile
@@ -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
diff --git a/drivers/base/base.h b/drivers/base/base.h
index 122498a..79115ef 100644
--- a/drivers/base/base.h
+++ b/drivers/base/base.h
@@ -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);
diff --git a/drivers/base/hypervisor.c b/drivers/base/hypervisor.c
new file mode 100644
index 0000000..0c85e9d
--- /dev/null
+++ b/drivers/base/hypervisor.c
@@ -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);
+}
diff --git a/drivers/base/init.c b/drivers/base/init.c
index c648914..3713815 100644
--- a/drivers/base/init.c
+++ b/drivers/base/init.c
@@ -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.
diff --git a/include/linux/kobject.h b/include/linux/kobject.h
index c187c53..2d22932 100644
--- a/include/linux/kobject.h
+++ b/include/linux/kobject.h
@@ -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.
-- 
1.4.0


^ permalink raw reply related	[flat|nested] 23+ messages in thread

* [PATCH 14/22] [PATCH] remove duplication from Documentation/power/devices.txt
  2006-06-21 19:45                         ` [PATCH 13/22] [PATCH] Driver Core: Add /sys/hypervisor when needed Greg KH
@ 2006-06-21 19:45                           ` Greg KH
  2006-06-21 19:45                             ` [PATCH 15/22] [PATCH] Driver core: PM_DEBUG device suspend() messages become informative Greg KH
  0 siblings, 1 reply; 23+ messages in thread
From: Greg KH @ 2006-06-21 19:45 UTC (permalink / raw)
  To: linux-kernel; +Cc: David Brownell, Greg Kroah-Hartman

From: David Brownell <david-b@pacbell.net>

Remove a chunk of duplicated documentation text.

Signed-off-by: Greg Kroah-Hartman <gregkh@suse.de>
---
 Documentation/power/devices.txt |   90 ---------------------------------------
 1 files changed, 0 insertions(+), 90 deletions(-)

diff --git a/Documentation/power/devices.txt b/Documentation/power/devices.txt
index f987afe..fba1e05 100644
--- a/Documentation/power/devices.txt
+++ b/Documentation/power/devices.txt
@@ -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
-- 
1.4.0


^ permalink raw reply related	[flat|nested] 23+ messages in thread

* [PATCH 15/22] [PATCH] Driver core: PM_DEBUG device suspend() messages become informative
  2006-06-21 19:45                           ` [PATCH 14/22] [PATCH] remove duplication from Documentation/power/devices.txt Greg KH
@ 2006-06-21 19:45                             ` Greg KH
  2006-06-21 19:45                               ` [PATCH 16/22] [PATCH] firmware_class: s/semaphores/mutexes Greg KH
  0 siblings, 1 reply; 23+ messages in thread
From: Greg KH @ 2006-06-21 19:45 UTC (permalink / raw)
  To: linux-kernel; +Cc: David Brownell, David Brownell, Greg Kroah-Hartman

From: David Brownell <david-b@pacbell.net>

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.

Signed-off-by: David Brownell <dbrownell@users.sourceforge.net>
Signed-off-by: Greg Kroah-Hartman <gregkh@suse.de>
---
 drivers/base/power/suspend.c |   17 ++++++++++++++++-
 1 files changed, 16 insertions(+), 1 deletions(-)

diff --git a/drivers/base/power/suspend.c b/drivers/base/power/suspend.c
index 2a769cc..1a1fe43 100644
--- a/drivers/base/power/suspend.c
+++ b/drivers/base/power/suspend.c
@@ -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);
 	}
-- 
1.4.0


^ permalink raw reply related	[flat|nested] 23+ messages in thread

* [PATCH 16/22] [PATCH] firmware_class: s/semaphores/mutexes
  2006-06-21 19:45                             ` [PATCH 15/22] [PATCH] Driver core: PM_DEBUG device suspend() messages become informative Greg KH
@ 2006-06-21 19:45                               ` Greg KH
  2006-06-21 19:46                                 ` [PATCH 17/22] [PATCH] Driver core: change make_class_name() to take kobjects Greg KH
  0 siblings, 1 reply; 23+ messages in thread
From: Greg KH @ 2006-06-21 19:45 UTC (permalink / raw)
  To: linux-kernel; +Cc: Laura Garcia, Greg Kroah-Hartman

From: Laura Garcia <nevola@gmail.com>

Hi, this patch converts semaphores to mutexes for Randy's firmware_class.

Signed-off-by: Laura Garcia Liebana <nevola@gmail.com>
Signed-off-by: Greg Kroah-Hartman <gregkh@suse.de>
---
 drivers/base/firmware_class.c |   22 +++++++++++-----------
 1 files changed, 11 insertions(+), 11 deletions(-)

diff --git a/drivers/base/firmware_class.c b/drivers/base/firmware_class.c
index 0c99ae6..5d6c011 100644
--- a/drivers/base/firmware_class.c
+++ b/drivers/base/firmware_class.c
@@ -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_devi
 
 	switch (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 *kobj
 	if (!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;
 
-- 
1.4.0


^ permalink raw reply related	[flat|nested] 23+ messages in thread

* [PATCH 17/22] [PATCH] Driver core: change make_class_name() to take kobjects
  2006-06-21 19:45                               ` [PATCH 16/22] [PATCH] firmware_class: s/semaphores/mutexes Greg KH
@ 2006-06-21 19:46                                 ` Greg KH
  2006-06-21 19:46                                   ` [PATCH 18/22] [PATCH] Driver core: allow struct device to have a dev_t Greg KH
  0 siblings, 1 reply; 23+ messages in thread
From: Greg KH @ 2006-06-21 19:46 UTC (permalink / raw)
  To: linux-kernel; +Cc: Greg Kroah-Hartman

From: Greg Kroah-Hartman <gregkh@suse.de>

This is needed for a future patch for the device code to create the
proper symlinks for devices that are "class devices".

Signed-off-by: Greg Kroah-Hartman <gregkh@suse.de>
---
 drivers/base/base.h  |    1 +
 drivers/base/class.c |   31 +++++++++++++++++--------------
 2 files changed, 18 insertions(+), 14 deletions(-)

diff --git a/drivers/base/base.h b/drivers/base/base.h
index 79115ef..c3b8dc9 100644
--- a/drivers/base/base.h
+++ b/drivers/base/base.h
@@ -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);
 
diff --git a/drivers/base/class.c b/drivers/base/class.c
index 4b598be..41a8e09 100644
--- a/drivers/base/class.c
+++ b/drivers/base/class.c
@@ -504,22 +504,21 @@ void class_device_initialize(struct clas
 	INIT_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);
-- 
1.4.0


^ permalink raw reply related	[flat|nested] 23+ messages in thread

* [PATCH 18/22] [PATCH] Driver core: allow struct device to have a dev_t
  2006-06-21 19:46                                 ` [PATCH 17/22] [PATCH] Driver core: change make_class_name() to take kobjects Greg KH
@ 2006-06-21 19:46                                   ` Greg KH
  2006-06-21 19:46                                     ` [PATCH 19/22] [PATCH] Driver core: add generic "subsystem" link to all devices Greg KH
  0 siblings, 1 reply; 23+ messages in thread
From: Greg KH @ 2006-06-21 19:46 UTC (permalink / raw)
  To: linux-kernel; +Cc: Greg Kroah-Hartman

From: Greg Kroah-Hartman <gregkh@suse.de>

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.

Cc: Kay Sievers <kay.sievers@vrfy.org>
Signed-off-by: Greg Kroah-Hartman <gregkh@suse.de>
---
 drivers/base/class.c   |    1 
 drivers/base/core.c    |  162 ++++++++++++++++++++++++++++++++++++++++++++++++
 include/linux/device.h |   14 ++++
 3 files changed, 176 insertions(+), 1 deletions(-)

diff --git a/drivers/base/class.c b/drivers/base/class.c
index 41a8e09..50e841a 100644
--- a/drivers/base/class.c
+++ b/drivers/base/class.c
@@ -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);
diff --git a/drivers/base/core.c b/drivers/base/core.c
index d5e15a0..252cf40 100644
--- a/drivers/base/core.c
+++ b/drivers/base/core.c
@@ -15,6 +15,7 @@ #include <linux/init.h>
 #include <linux/module.h>
 #include <linux/slab.h>
 #include <linux/string.h>
+#include <linux/kdev_t.h>
 
 #include <asm/semaphore.h>
 
@@ -98,6 +99,8 @@ static int dev_uevent_filter(struct kset
 		struct device *dev = to_dev(kobj);
 		if (dev->bus)
 			return 1;
+		if (dev->class)
+			return 1;
 	}
 	return 0;
 }
@@ -106,7 +109,11 @@ static const char *dev_uevent_name(struc
 {
 	struct device *dev = to_dev(kobj);
 
-	return dev->bus->name;
+	if (dev->bus)
+		return dev->bus->name;
+	if (dev->class)
+		return dev->class->name;
+	return NULL;
 }
 
 static int dev_uevent(struct kset *kset, struct kobject *kobj, char **envp,
@@ -117,6 +124,16 @@ static int dev_uevent(struct kset *kset,
 	int length = 0;
 	int retval = 0;
 
+	/* add the major/minor if present */
+	if (MAJOR(dev->devt)) {
+		add_uevent_var(envp, num_envp, &i,
+			       buffer, buffer_size, &length,
+			       "MAJOR=%u", MAJOR(dev->devt));
+		add_uevent_var(envp, num_envp, &i,
+			       buffer, buffer_size, &length,
+			       "MINOR=%u", MINOR(dev->devt));
+	}
+
 	/* add bus name of physical device */
 	if (dev->bus)
 		add_uevent_var(envp, num_envp, &i,
@@ -161,6 +178,12 @@ static ssize_t store_uevent(struct devic
 	return count;
 }
 
+static ssize_t show_dev(struct device *dev, struct device_attribute *attr,
+			char *buf)
+{
+	return print_dev_t(buf, dev->devt);
+}
+
 /*
  *	devices_subsys - structure to be registered with kobject core.
  */
@@ -231,6 +254,7 @@ void device_initialize(struct device *de
 	klist_init(&dev->klist_children, klist_children_get,
 		   klist_children_put);
 	INIT_LIST_HEAD(&dev->dma_pools);
+	INIT_LIST_HEAD(&dev->node);
 	init_MUTEX(&dev->sem);
 	device_init_wakeup(dev, 0);
 }
@@ -274,6 +298,31 @@ int device_add(struct device *dev)
 	dev->uevent_attr.store = store_uevent;
 	device_create_file(dev, &dev->uevent_attr);
 
+	if (MAJOR(dev->devt)) {
+		struct device_attribute *attr;
+		attr = kzalloc(sizeof(*attr), GFP_KERNEL);
+		if (!attr) {
+			error = -ENOMEM;
+			goto PMError;
+		}
+		attr->attr.name = "dev";
+		attr->attr.mode = S_IRUGO;
+		if (dev->driver)
+			attr->attr.owner = dev->driver->owner;
+		attr->show = show_dev;
+		error = device_create_file(dev, attr);
+		if (error) {
+			kfree(attr);
+			goto attrError;
+		}
+
+		dev->devt_attr = attr;
+	}
+
+	if (dev->class)
+		sysfs_create_link(&dev->class->subsys.kset.kobj, &dev->kobj,
+				  dev->bus_id);
+
 	if ((error = device_pm_add(dev)))
 		goto PMError;
 	if ((error = bus_add_device(dev)))
@@ -292,6 +341,11 @@ int device_add(struct device *dev)
  BusError:
 	device_pm_remove(dev);
  PMError:
+	if (dev->devt_attr) {
+		device_remove_file(dev, dev->devt_attr);
+		kfree(dev->devt_attr);
+	}
+ attrError:
 	kobject_uevent(&dev->kobj, KOBJ_REMOVE);
 	kobject_del(&dev->kobj);
  Error:
@@ -366,6 +420,10 @@ void device_del(struct device * dev)
 
 	if (parent)
 		klist_del(&dev->knode_parent);
+	if (dev->devt_attr)
+		device_remove_file(dev, dev->devt_attr);
+	if (dev->class)
+		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
@@ -450,3 +508,105 @@ EXPORT_SYMBOL_GPL(put_device);
 
 EXPORT_SYMBOL_GPL(device_create_file);
 EXPORT_SYMBOL_GPL(device_remove_file);
+
+
+static void device_create_release(struct device *dev)
+{
+	pr_debug("%s called for %s\n", __FUNCTION__, dev->bus_id);
+	kfree(dev);
+}
+
+/**
+ * device_create - creates a device and registers it with sysfs
+ * @cs: pointer to the struct class that this device should be registered to.
+ * @parent: pointer to the parent struct device of this new device, if any.
+ * @dev: the dev_t for the char device to be added.
+ * @fmt: string for the class device's name
+ *
+ * This function can be used by char device classes.  A struct
+ * device will be created in sysfs, registered to the specified
+ * class.
+ * A "dev" file will be created, showing the dev_t for the device, if
+ * the dev_t is not 0,0.
+ * If a pointer to a parent struct device is passed in, the newly
+ * created struct device will be a child of that device in sysfs.  The
+ * pointer to the struct device will be returned from the call.  Any
+ * further sysfs files that might be required can be created using this
+ * pointer.
+ *
+ * Note: the struct class passed to this function must have previously
+ * been created with a call to class_create().
+ */
+struct device *device_create(struct class *class, struct device *parent,
+			     dev_t devt, char *fmt, ...)
+{
+	va_list args;
+	struct device *dev = NULL;
+	int retval = -ENODEV;
+
+	if (class == NULL || IS_ERR(class))
+		goto error;
+	if (parent == NULL) {
+		printk(KERN_WARNING "%s does not work yet for NULL parents\n", __FUNCTION__);
+		goto error;
+	}
+
+	dev = kzalloc(sizeof(*dev), GFP_KERNEL);
+	if (!dev) {
+		retval = -ENOMEM;
+		goto error;
+	}
+
+	dev->devt = devt;
+	dev->class = class;
+	dev->parent = parent;
+	dev->release = device_create_release;
+
+	va_start(args, fmt);
+	vsnprintf(dev->bus_id, BUS_ID_SIZE, fmt, args);
+	va_end(args);
+	retval = device_register(dev);
+	if (retval)
+		goto error;
+
+	/* tie the class to the device */
+	down(&class->sem);
+	list_add_tail(&dev->node, &class->devices);
+	up(&class->sem);
+
+	return dev;
+
+error:
+	kfree(dev);
+	return ERR_PTR(retval);
+}
+EXPORT_SYMBOL_GPL(device_create);
+
+/**
+ * device_destroy - removes a device that was created with device_create()
+ * @class: the pointer to the struct class that this device was registered * with.
+ * @dev: the dev_t of the device that was previously registered.
+ *
+ * This call unregisters and cleans up a class device that was created with a
+ * call to class_device_create()
+ */
+void device_destroy(struct class *class, dev_t devt)
+{
+	struct device *dev = NULL;
+	struct device *dev_tmp;
+
+	down(&class->sem);
+	list_for_each_entry(dev_tmp, &class->devices, node) {
+		if (dev_tmp->devt == devt) {
+			dev = dev_tmp;
+			break;
+		}
+	}
+	up(&class->sem);
+
+	if (dev) {
+		list_del_init(&dev->node);
+		device_unregister(dev);
+	}
+}
+EXPORT_SYMBOL_GPL(device_destroy);
diff --git a/include/linux/device.h b/include/linux/device.h
index ade10dd..b473f42 100644
--- a/include/linux/device.h
+++ b/include/linux/device.h
@@ -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 device 
 extern 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
-- 
1.4.0


^ permalink raw reply related	[flat|nested] 23+ messages in thread

* [PATCH 19/22] [PATCH] Driver core: add generic "subsystem" link to all devices
  2006-06-21 19:46                                   ` [PATCH 18/22] [PATCH] Driver core: allow struct device to have a dev_t Greg KH
@ 2006-06-21 19:46                                     ` Greg KH
  2006-06-21 19:46                                       ` [PATCH 20/22] [PATCH] Driver core: add proper symlinks for devices Greg KH
  0 siblings, 1 reply; 23+ messages in thread
From: Greg KH @ 2006-06-21 19:46 UTC (permalink / raw)
  To: linux-kernel; +Cc: Kay Sievers, Greg Kroah-Hartman

From: Kay Sievers <kay.sievers@suse.de>

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.

Signed-off-by: Kay Sievers <kay.sievers@suse.de>
Signed-off-by: Greg Kroah-Hartman <gregkh@suse.de>
---
 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(-)

diff --git a/block/genhd.c b/block/genhd.c
index 5a8d3bf..8d73395 100644
--- a/block/genhd.c
+++ b/block/genhd.c
@@ -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
diff --git a/drivers/base/bus.c b/drivers/base/bus.c
index 64ba901..050d86d 100644
--- a/drivers/base/bus.c
+++ b/drivers/base/bus.c
@@ -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 * d
 void 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);
diff --git a/drivers/base/class.c b/drivers/base/class.c
index 50e841a..9aa1274 100644
--- a/drivers/base/class.c
+++ b/drivers/base/class.c
@@ -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_devic
 		sysfs_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);
diff --git a/drivers/base/core.c b/drivers/base/core.c
index 252cf40..cc8bb97 100644
--- a/drivers/base/core.c
+++ b/drivers/base/core.c
@@ -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
diff --git a/fs/partitions/check.c b/fs/partitions/check.c
index 7ef1f09..8851b81 100644
--- a/fs/partitions/check.c
+++ b/fs/partitions/check.c
@@ -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 g
 			kfree(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);
 }
-- 
1.4.0


^ permalink raw reply related	[flat|nested] 23+ messages in thread

* [PATCH 20/22] [PATCH] Driver core: add proper symlinks for devices
  2006-06-21 19:46                                     ` [PATCH 19/22] [PATCH] Driver core: add generic "subsystem" link to all devices Greg KH
@ 2006-06-21 19:46                                       ` Greg KH
  2006-06-21 19:46                                         ` [PATCH 21/22] [PATCH] Driver Core: Make dev_info and friends print the bus name if there is no driver Greg KH
  0 siblings, 1 reply; 23+ messages in thread
From: Greg KH @ 2006-06-21 19:46 UTC (permalink / raw)
  To: linux-kernel; +Cc: Greg Kroah-Hartman

From: Greg Kroah-Hartman <gregkh@suse.de>

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...)

Signed-off-by: Greg Kroah-Hartman <gregkh@suse.de>
---
 drivers/base/core.c |   11 +++++++++++
 1 files changed, 11 insertions(+), 0 deletions(-)

diff --git a/drivers/base/core.c b/drivers/base/core.c
index cc8bb97..a979bc3 100644
--- a/drivers/base/core.c
+++ b/drivers/base/core.c
@@ -273,6 +273,7 @@ void device_initialize(struct device *de
 int 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);
 
-- 
1.4.0


^ permalink raw reply related	[flat|nested] 23+ messages in thread

* [PATCH 21/22] [PATCH] Driver Core: Make dev_info and friends print the bus name if there is no driver
  2006-06-21 19:46                                       ` [PATCH 20/22] [PATCH] Driver core: add proper symlinks for devices Greg KH
@ 2006-06-21 19:46                                         ` Greg KH
  2006-06-21 19:46                                           ` [PATCH 22/22] [PATCH] Driver model: add ISA bus Greg KH
  0 siblings, 1 reply; 23+ messages in thread
From: Greg KH @ 2006-06-21 19:46 UTC (permalink / raw)
  To: linux-kernel; +Cc: Alan Stern, Greg Kroah-Hartman

From: Alan Stern <stern@rowland.harvard.edu>

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.

Cc: Matthew Wilcox <matthew@wil.cx>
Signed-off-by: Alan Stern <stern@rowland.harvard.edu>
Signed-off-by: Greg Kroah-Hartman <gregkh@suse.de>
---
 drivers/base/core.c    |   16 ++++++++++++++++
 include/linux/device.h |    3 ++-
 2 files changed, 18 insertions(+), 1 deletions(-)

diff --git a/drivers/base/core.c b/drivers/base/core.c
index a979bc3..d0f84ff 100644
--- a/drivers/base/core.c
+++ b/drivers/base/core.c
@@ -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)
 
diff --git a/include/linux/device.h b/include/linux/device.h
index b473f42..1e5f30d 100644
--- a/include/linux/device.h
+++ b/include/linux/device.h
@@ -416,8 +416,9 @@ extern int firmware_register(struct subs
 extern 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...)		\
-- 
1.4.0


^ permalink raw reply related	[flat|nested] 23+ messages in thread

* [PATCH 22/22] [PATCH] Driver model: add ISA bus
  2006-06-21 19:46                                         ` [PATCH 21/22] [PATCH] Driver Core: Make dev_info and friends print the bus name if there is no driver Greg KH
@ 2006-06-21 19:46                                           ` Greg KH
  0 siblings, 0 replies; 23+ messages in thread
From: Greg KH @ 2006-06-21 19:46 UTC (permalink / raw)
  To: linux-kernel; +Cc: Rene Herman

From: Rene Herman <rene.herman@keyaccess.nl>

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.

Signed-off-by: Rene Herman <rene.herman@keyaccess.nl>
---
 drivers/base/Makefile |    1 
 drivers/base/isa.c    |  180 +++++++++++++++++++++++++++++++++++++++++++++++++
 include/linux/isa.h   |   28 ++++++++
 3 files changed, 209 insertions(+), 0 deletions(-)

diff --git a/drivers/base/Makefile b/drivers/base/Makefile
index 659cde6..b539e5e 100644
--- a/drivers/base/Makefile
+++ b/drivers/base/Makefile
@@ -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
diff --git a/drivers/base/isa.c b/drivers/base/isa.c
new file mode 100644
index 0000000..d222239
--- /dev/null
+++ b/drivers/base/isa.c
@@ -0,0 +1,180 @@
+/*
+ * ISA bus.
+ */
+
+#include <linux/device.h>
+#include <linux/kernel.h>
+#include <linux/slab.h>
+#include <linux/module.h>
+#include <linux/init.h>
+#include <linux/isa.h>
+
+static struct device isa_bus = {
+	.bus_id		= "isa"
+};
+
+struct isa_dev {
+	struct device dev;
+	struct device *next;
+	unsigned int id;
+};
+
+#define to_isa_dev(x) container_of((x), struct isa_dev, dev)
+
+static 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;
+}
+
+static int isa_bus_probe(struct device *dev)
+{
+	struct isa_driver *isa_driver = dev->platform_data;
+
+	if (isa_driver->probe)
+		return isa_driver->probe(dev, to_isa_dev(dev)->id);
+
+	return 0;
+}
+
+static int isa_bus_remove(struct device *dev)
+{
+	struct isa_driver *isa_driver = dev->platform_data;
+
+	if (isa_driver->remove)
+		return isa_driver->remove(dev, to_isa_dev(dev)->id);
+
+	return 0;
+}
+
+static void isa_bus_shutdown(struct device *dev)
+{
+	struct isa_driver *isa_driver = dev->platform_data;
+
+	if (isa_driver->shutdown)
+		isa_driver->shutdown(dev, to_isa_dev(dev)->id);
+}
+
+static int isa_bus_suspend(struct device *dev, pm_message_t state)
+{
+	struct isa_driver *isa_driver = dev->platform_data;
+
+	if (isa_driver->suspend)
+		return isa_driver->suspend(dev, to_isa_dev(dev)->id, state);
+
+	return 0;
+}
+
+static int isa_bus_resume(struct device *dev)
+{
+	struct isa_driver *isa_driver = dev->platform_data;
+
+	if (isa_driver->resume)
+		return isa_driver->resume(dev, to_isa_dev(dev)->id);
+
+	return 0;
+}
+
+static struct bus_type isa_bus_type = {
+	.name		= "isa",
+	.match		= isa_bus_match,
+	.probe		= isa_bus_probe,
+	.remove		= isa_bus_remove,
+	.shutdown	= isa_bus_shutdown,
+	.suspend	= isa_bus_suspend,
+	.resume		= isa_bus_resume
+};
+
+static void isa_dev_release(struct device *dev)
+{
+	kfree(to_isa_dev(dev));
+}
+
+void isa_unregister_driver(struct isa_driver *isa_driver)
+{
+	struct device *dev = isa_driver->devices;
+
+	while (dev) {
+		struct device *tmp = to_isa_dev(dev)->next;
+		device_unregister(dev);
+		dev = tmp;
+	}
+	driver_unregister(&isa_driver->driver);
+}
+EXPORT_SYMBOL_GPL(isa_unregister_driver);
+
+int isa_register_driver(struct isa_driver *isa_driver, unsigned int ndev)
+{
+	int error;
+	unsigned int id;
+
+	isa_driver->driver.bus	= &isa_bus_type;
+	isa_driver->devices	= NULL;
+
+	error = driver_register(&isa_driver->driver);
+	if (error)
+		return error;
+
+	for (id = 0; id < ndev; id++) {
+		struct isa_dev *isa_dev;
+
+		isa_dev = kzalloc(sizeof *isa_dev, GFP_KERNEL);
+		if (!isa_dev) {
+			error = -ENOMEM;
+			break;
+		}
+
+		isa_dev->dev.parent	= &isa_bus;
+		isa_dev->dev.bus	= &isa_bus_type;
+
+		snprintf(isa_dev->dev.bus_id, BUS_ID_SIZE, "%s.%u",
+				isa_driver->driver.name, id);
+
+		isa_dev->dev.platform_data	= isa_driver;
+		isa_dev->dev.release		= isa_dev_release;
+		isa_dev->id			= id;
+
+		error = device_register(&isa_dev->dev);
+		if (error) {
+			put_device(&isa_dev->dev);
+			break;
+		}
+
+		if (isa_dev->dev.platform_data) {
+			isa_dev->next = isa_driver->devices;
+			isa_driver->devices = &isa_dev->dev;
+		} else
+			device_unregister(&isa_dev->dev);
+	}
+
+	if (!error && !isa_driver->devices)
+		error = -ENODEV;
+
+	if (error)
+		isa_unregister_driver(isa_driver);
+
+	return error;
+}
+EXPORT_SYMBOL_GPL(isa_register_driver);
+
+static int __init isa_bus_init(void)
+{
+	int error;
+
+	error = bus_register(&isa_bus_type);
+	if (!error) {
+		error = device_register(&isa_bus);
+		if (error)
+			bus_unregister(&isa_bus_type);
+	}
+	return error;
+}
+
+device_initcall(isa_bus_init);
diff --git a/include/linux/isa.h b/include/linux/isa.h
new file mode 100644
index 0000000..1b85533
--- /dev/null
+++ b/include/linux/isa.h
@@ -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 */
-- 
1.4.0


^ permalink raw reply related	[flat|nested] 23+ messages in thread

end of thread, other threads:[~2006-06-21 19:56 UTC | newest]

Thread overview: 23+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2006-06-21 19:45 [GIT PATCH] Driver Core patches for 2.6.17 Greg KH
2006-06-21 19:45 ` [PATCH 1/22] [PATCH] kobject: make people pay attention to kobject_add errors Greg KH
2006-06-21 19:45   ` [PATCH 2/22] [PATCH] Add kernel<->userspace ABI stability documentation Greg KH
2006-06-21 19:45     ` [PATCH 3/22] [PATCH] CCISS: add device symlink to the block cciss block devices in sysfs Greg KH
2006-06-21 19:45       ` [PATCH 4/22] [PATCH] Driver core: bus device event delay Greg KH
2006-06-21 19:45         ` [PATCH 5/22] [PATCH] TTY: return class device pointer from tty_register_device() Greg KH
2006-06-21 19:45           ` [PATCH 6/22] [PATCH] i4l gigaset: move sysfs entry to tty class device Greg KH
2006-06-21 19:45             ` [PATCH 7/22] [PATCH] Driver core: class_device_add needs error checks Greg KH
2006-06-21 19:45               ` [PATCH 8/22] [PATCH] Driver Core: CONFIG_DEBUG_PM covers drivers/base/power too Greg KH
2006-06-21 19:45                 ` [PATCH 9/22] [PATCH] platform_bus learns about modalias Greg KH
2006-06-21 19:45                   ` [PATCH 10/22] [PATCH] Driver Core: remove unused exports Greg KH
2006-06-21 19:45                     ` [PATCH 11/22] [PATCH] Driver Core: Allow sysdev_class have attributes Greg KH
2006-06-21 19:45                       ` [PATCH 12/22] [PATCH] Driver Core: Fix platform_device_add to use device_add Greg KH
2006-06-21 19:45                         ` [PATCH 13/22] [PATCH] Driver Core: Add /sys/hypervisor when needed Greg KH
2006-06-21 19:45                           ` [PATCH 14/22] [PATCH] remove duplication from Documentation/power/devices.txt Greg KH
2006-06-21 19:45                             ` [PATCH 15/22] [PATCH] Driver core: PM_DEBUG device suspend() messages become informative Greg KH
2006-06-21 19:45                               ` [PATCH 16/22] [PATCH] firmware_class: s/semaphores/mutexes Greg KH
2006-06-21 19:46                                 ` [PATCH 17/22] [PATCH] Driver core: change make_class_name() to take kobjects Greg KH
2006-06-21 19:46                                   ` [PATCH 18/22] [PATCH] Driver core: allow struct device to have a dev_t Greg KH
2006-06-21 19:46                                     ` [PATCH 19/22] [PATCH] Driver core: add generic "subsystem" link to all devices Greg KH
2006-06-21 19:46                                       ` [PATCH 20/22] [PATCH] Driver core: add proper symlinks for devices Greg KH
2006-06-21 19:46                                         ` [PATCH 21/22] [PATCH] Driver Core: Make dev_info and friends print the bus name if there is no driver Greg KH
2006-06-21 19:46                                           ` [PATCH 22/22] [PATCH] Driver model: add ISA bus Greg KH

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).