public inbox for linux-kernel@vger.kernel.org
 help / color / mirror / Atom feed
* [patch/RFC 2.6.18-rc] platform_device_probe(), to conserve memory
@ 2006-09-04  1:23 David Brownell
  2006-09-04  1:34 ` Dmitry Torokhov
  2006-09-04  5:24 ` David Brownell
  0 siblings, 2 replies; 5+ messages in thread
From: David Brownell @ 2006-09-04  1:23 UTC (permalink / raw)
  To: linux-kernel; +Cc: Russell King, Greg KH

This defines a new platform_driver_probe() method allowing the driver's
probe() method, and its support code+data, to safely live in __init
sections for common system configurations.

Many system-on-chip processors could benefit from this API to the tune
of saving hundreds to thousands of bytes per driver, which is currently
wasted holding code which can never be called after system startup yet may
not be removed.   It may not be removed because of the linkage requirement
that pointers to init section code (like, ideally, probe support) must
not live in sections that persist after that section is removed (like
driver methods) when those pointers would be invalid.

Signed-off-by: David Brownell <dbrownell@users.sourceforge.net>

Index: g26/include/linux/platform_device.h
===================================================================
--- g26.orig/include/linux/platform_device.h	2006-09-03 13:02:23.000000000 -0700
+++ g26/include/linux/platform_device.h	2006-09-03 13:02:49.000000000 -0700
@@ -58,6 +58,12 @@ struct platform_driver {
 extern int platform_driver_register(struct platform_driver *);
 extern void platform_driver_unregister(struct platform_driver *);
 
+/* non-hotpluggable platform devices may use this so that probe() and
+ * its support may live in __init sections, conserving runtime memory.
+ */
+extern int platform_driver_probe(struct platform_driver *driver,
+		int (*probe)(struct platform_device *));
+
 #define platform_get_drvdata(_dev)	dev_get_drvdata(&(_dev)->dev)
 #define platform_set_drvdata(_dev,data)	dev_set_drvdata(&(_dev)->dev, (data))
 
Index: g26/drivers/base/platform.c
===================================================================
--- g26.orig/drivers/base/platform.c	2006-09-03 13:02:23.000000000 -0700
+++ g26/drivers/base/platform.c	2006-09-03 13:02:49.000000000 -0700
@@ -451,6 +451,51 @@ void platform_driver_unregister(struct p
 }
 EXPORT_SYMBOL_GPL(platform_driver_unregister);
 
+/**
+ * platform_driver_probe - register driver for non-hotpluggable device
+ * @drv: platform driver structure
+ * @probe: the driver probe routine, probably from an __init section
+ *
+ * Use this instead of platform_driver_register() when you know the device
+ * is not hotpluggable and has already been registered, and you want to
+ * remove its run-once probe() infrastructure from memory after the driver
+ * has bound to the device.
+ *
+ * One typical use for this would be with drivers for controllers integrated
+ * into system-on-chip processors, where the controller devices have been
+ * configured as part of board setup.
+ *
+ * Returns zero if the driver registered and bound to a device, else returns
+ * a negative error code and with the driver not registered.
+ */
+int platform_driver_probe(struct platform_driver *drv,
+		int (*probe)(struct platform_device *))
+{
+	int retval;
+
+	/* temporary section violation */
+	drv->probe = probe;
+
+	retval = platform_driver_register(drv);
+	if (retval)
+		return retval;
+
+	/* Fixup that section violation, being paranoid about code scanning
+	 * the list of drivers in order to probe new devices.  Check to see
+	 * if the probe was successful.
+	 */
+	spin_lock(&platform_bus_type.klist_drivers.k_lock);
+	drv->driver.probe = NULL;
+	drv->probe = NULL;
+	if (list_empty(&drv->driver.klist_devices.k_list))
+		retval = -ENODEV;
+	spin_unlock(&platform_bus_type.klist_drivers.k_lock);
+
+	if (retval)
+		platform_driver_unregister(drv);
+	return retval;
+}
+EXPORT_SYMBOL_GPL(platform_driver_probe);
 
 /* modalias support enables more hands-off userspace setup:
  * (a) environment variable lets new-style hotplug events work once system is

-- 
VGER BF report: U 0.499965

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

* Re: [patch/RFC 2.6.18-rc] platform_device_probe(), to conserve memory
  2006-09-04  1:23 [patch/RFC 2.6.18-rc] platform_device_probe(), to conserve memory David Brownell
@ 2006-09-04  1:34 ` Dmitry Torokhov
  2006-09-04  2:34   ` David Brownell
  2006-09-04  5:24 ` David Brownell
  1 sibling, 1 reply; 5+ messages in thread
From: Dmitry Torokhov @ 2006-09-04  1:34 UTC (permalink / raw)
  To: David Brownell; +Cc: linux-kernel, Russell King, Greg KH

On Sunday 03 September 2006 21:23, David Brownell wrote:
> This defines a new platform_driver_probe() method allowing the driver's
> probe() method, and its support code+data, to safely live in __init
> sections for common system configurations.
> 

If you do this you also need to kill drivers bind/unbind attributes
to show that dynamic [un]binding is not supported.

-- 
Dmitry

-- 
VGER BF report: H 0.000843217

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

* Re: [patch/RFC 2.6.18-rc] platform_device_probe(), to conserve memory
  2006-09-04  1:34 ` Dmitry Torokhov
@ 2006-09-04  2:34   ` David Brownell
  0 siblings, 0 replies; 5+ messages in thread
From: David Brownell @ 2006-09-04  2:34 UTC (permalink / raw)
  To: dtor; +Cc: rmk, linux-kernel, greg

> From: Dmitry Torokhov <dtor@insightbb.com>
> Date: Sun, 3 Sep 2006 21:34:29 -0400
>
> On Sunday 03 September 2006 21:23, David Brownell wrote:
> > This defines a new platform_driver_probe() method allowing the driver's
> > probe() method, and its support code+data, to safely live in __init
> > sections for common system configurations.
> > 
>
> If you do this you also need to kill drivers bind/unbind attributes
> to show that dynamic [un]binding is not supported.

Unbinding hasn't changed; so if that attribute breaks because of this,
it was already broken.

It might be important that drv->probe() be replaced with something
that always fails though, since it seems there's an odd assumption
that not having a probe() means the driver works for any device...

- Dave


-- 
VGER BF report: H 1.38493e-10

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

* Re: [patch/RFC 2.6.18-rc] platform_device_probe(), to conserve memory
  2006-09-04  1:23 [patch/RFC 2.6.18-rc] platform_device_probe(), to conserve memory David Brownell
  2006-09-04  1:34 ` Dmitry Torokhov
@ 2006-09-04  5:24 ` David Brownell
  2006-09-04 14:25   ` Oleg Verych
  1 sibling, 1 reply; 5+ messages in thread
From: David Brownell @ 2006-09-04  5:24 UTC (permalink / raw)
  To: linux-kernel, Dmitry Torokhov; +Cc: Russell King, Greg KH

This defines a new platform_driver_probe() method allowing the driver's
probe() method, and its support code+data, to safely live in __init
sections for typical system configurations.

Many system-on-chip processors could benefit from this API to the tune
of saving hundreds to thousands of bytes per driver, which is currently
wasted holding code which can never be called after system startup yet
can not be removed.   It can't be removed because of linkage requirement
that pointers to init section code (like, ideally, probe support) must
not live in sections that persist after that section is removed (like
driver methods) when those pointers would be invalid.

Signed-off-by: David Brownell <dbrownell@users.sourceforge.net>
---
Updated -- now forces probe failure after the probe() is gone, so that
the /sys/bus/platform/drivers/*/bind attribute can't break anything.
(Maybe that should be used whenever a driver has no probe routine...)

Index: g26/include/linux/platform_device.h
===================================================================
--- g26.orig/include/linux/platform_device.h	2006-09-03 13:02:23.000000000 -0700
+++ g26/include/linux/platform_device.h	2006-09-03 19:39:23.000000000 -0700
@@ -58,6 +58,12 @@ struct platform_driver {
 extern int platform_driver_register(struct platform_driver *);
 extern void platform_driver_unregister(struct platform_driver *);
 
+/* non-hotpluggable platform devices may use this so that probe() and
+ * its support may live in __init sections, conserving runtime memory.
+ */
+extern int platform_driver_probe(struct platform_driver *driver,
+		int (*probe)(struct platform_device *));
+
 #define platform_get_drvdata(_dev)	dev_get_drvdata(&(_dev)->dev)
 #define platform_set_drvdata(_dev,data)	dev_set_drvdata(&(_dev)->dev, (data))
 
Index: g26/drivers/base/platform.c
===================================================================
--- g26.orig/drivers/base/platform.c	2006-09-03 13:02:23.000000000 -0700
+++ g26/drivers/base/platform.c	2006-09-03 19:56:20.000000000 -0700
@@ -388,6 +388,11 @@ static int platform_drv_probe(struct dev
 	return drv->probe(dev);
 }
 
+static int platform_drv_probe_fail(struct device *_dev)
+{
+	return -ENXIO;
+}
+
 static int platform_drv_remove(struct device *_dev)
 {
 	struct platform_driver *drv = to_platform_driver(_dev->driver);
@@ -451,6 +456,52 @@ void platform_driver_unregister(struct p
 }
 EXPORT_SYMBOL_GPL(platform_driver_unregister);
 
+/**
+ * platform_driver_probe - register driver for non-hotpluggable device
+ * @drv: platform driver structure
+ * @probe: the driver probe routine, probably from an __init section
+ *
+ * Use this instead of platform_driver_register() when you know the device
+ * is not hotpluggable and has already been registered, and you want to
+ * remove its run-once probe() infrastructure from memory after the driver
+ * has bound to the device.
+ *
+ * One typical use for this would be with drivers for controllers integrated
+ * into system-on-chip processors, where the controller devices have been
+ * configured as part of board setup.
+ *
+ * Returns zero if the driver registered and bound to a device, else returns
+ * a negative error code and with the driver not registered.
+ */
+int platform_driver_probe(struct platform_driver *drv,
+		int (*probe)(struct platform_device *))
+{
+	int retval;
+
+	/* temporary section violation */
+	drv->probe = probe;
+
+	retval = platform_driver_register(drv);
+	if (retval)
+		return retval;
+
+	/* Fixup that section violation, being paranoid about code scanning
+	 * the list of drivers in order to probe new devices.  Check to see
+	 * if the probe was successful, and make sure any forced probes of
+	 * new devices fail.
+	 */
+	spin_lock(&platform_bus_type.klist_drivers.k_lock);
+	drv->driver.probe = platform_drv_probe_fail;
+	drv->probe = NULL;
+	if (list_empty(&drv->driver.klist_devices.k_list))
+		retval = -ENODEV;
+	spin_unlock(&platform_bus_type.klist_drivers.k_lock);
+
+	if (retval)
+		platform_driver_unregister(drv);
+	return retval;
+}
+EXPORT_SYMBOL_GPL(platform_driver_probe);
 
 /* modalias support enables more hands-off userspace setup:
  * (a) environment variable lets new-style hotplug events work once system is

-- 
VGER BF report: H 1.23077e-10

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

* Re: [patch/RFC 2.6.18-rc] platform_device_probe(), to conserve memory
  2006-09-04  5:24 ` David Brownell
@ 2006-09-04 14:25   ` Oleg Verych
  0 siblings, 0 replies; 5+ messages in thread
From: Oleg Verych @ 2006-09-04 14:25 UTC (permalink / raw)
  To: linux-kernel; +Cc: David Brownell, Russell King, Greg KH

[-- Attachment #1: Type: text/plain, Size: 548 bytes --]

Hallo,

David Brownell wrote:
[...]

 > + * One typical use for this would be with drivers for controllers integrated
 > + * into system-on-chip processors, where the controller devices have been
 > + * configured as part of board setup.
 > + *


Or every not-on-external-bus (usb/firewire/cardbus) device in laptop.

IMHO it's very good addition to everything-plug device driver model.
It must have its place in Documentation/driver-model/.

-- 
-o--=O`C  /. .\   (+)
  #oo'L O      o    |
<___=E M    ^--    |  (you're barking up the wrong tree)

[-- Attachment #2: doc-platform_driver_probe.patch --]
[-- Type: text/x-patch, Size: 1160 bytes --]

--- linux-2.6.18-rc6/Documentation/driver-model/driver.txt~	2006-09-04 04:19:48.000000000 +0200
+++ linux-2.6.18-rc6/Documentation/driver-model/driver.txt	2006-09-04 16:14:18.551630750 +0200
@@ -105,14 +105,21 @@
 
 It is important that drivers register their driver structure as early as
 possible. Registration with the core initializes several fields in the
 struct device_driver object, including the reference count and the
 lock. These fields are assumed to be valid at all times and may be
 used by the device model core or the bus driver.
 
+int platform_driver_probe(struct platform_driver *drv,
+			  int (*probe)(struct platform_device *))
+
+Use this instead of platform_driver_register() when you know the device
+is not hotpluggable and has already been registered, and you want to
+remove its run-once probe() infrastructure from memory after the driver
+has bound to the device.
 
 Transition Bus Drivers
 ~~~~~~~~~~~~~~~~~~~~~~
 
 By defining wrapper functions, the transition to the new model can be
 made easier. Drivers can ignore the generic structure altogether and
 let the bus wrapper fill in the fields. For the callbacks, the bus can

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

end of thread, other threads:[~2006-09-04 13:26 UTC | newest]

Thread overview: 5+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2006-09-04  1:23 [patch/RFC 2.6.18-rc] platform_device_probe(), to conserve memory David Brownell
2006-09-04  1:34 ` Dmitry Torokhov
2006-09-04  2:34   ` David Brownell
2006-09-04  5:24 ` David Brownell
2006-09-04 14:25   ` Oleg Verych

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox