Skip to contentSkip to conversation

platform_device_probe(), to conserve memory

patch/RFC 2.6.18-rc David Brownell 3 participants 5 messages Sep 4, 2006

Subsystems (2)
lore
Share & tools
lore
#0 lore raw

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.

include/linux/platform_device.h +6 -0
Index: g26/include/linux/platform_device.h
===================================================================
@@ -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))
 
drivers/base/platform.c +45 -0

51 lines not on this page · raw message

Signature · 1 line
VGER BF report: U 0.499965
#1 lore raw
Quoted 4 lines · David Brownell

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.

Signature · 4 lines
Dmitry

-- 
VGER BF report: H 0.000843217
#2 lore raw
Quoted 11 lines

From: Dmitry Torokhov <[email protected]>
Date: Sun, 3 Sep 2006 21:34:29 -0400

Quoted 4 lines · David Brownell

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

Signature · 1 line
VGER BF report: H 1.38493e-10
#3 lore raw
In reply to David Brownell

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.

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

include/linux/platform_device.h +6 -0
Index: g26/include/linux/platform_device.h
===================================================================
@@ -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))
 
drivers/base/platform.c +51 -0

63 lines not on this page · raw message

Signature · 1 line
VGER BF report: H 1.23077e-10
#4 lore raw

Hallo,

David Brownell wrote:
[...]

Quoted 4 lines

+ * 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/.

Signature · 3 lines
-o--=O`C  /. .\   (+)
 #oo'L O      o    |
<___=E M    ^--    |  (you're barking up the wrong tree)
Documentation/driver-model/driver.txt renamed from Documentation/driver-model/driver.txt~ +7 -0
@@ -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