* [patch 2.6.19-rc6] platform_driver_probe(), can save codespace
@ 2006-11-17 7:28 David Brownell
2006-11-17 14:32 ` Dmitry Torokhov
0 siblings, 1 reply; 6+ messages in thread
From: David Brownell @ 2006-11-17 7:28 UTC (permalink / raw)
To: Greg KH, Linux Kernel list
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 recovering hundreds to thousands of bytes per driver. That's memory
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
the linkage requirement that pointers to init section code (like, ideally,
probe support) must not live in other sections (like driver method tables)
after 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-11-16 18:19:43.000000000 -0800
+++ g26/include/linux/platform_device.h 2006-11-16 18:51:02.000000000 -0800
@@ -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-11-16 18:19:43.000000000 -0800
+++ g26/drivers/base/platform.c 2006-11-16 23:23:53.000000000 -0800
@@ -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,49 @@ 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, code;
+
+ /* temporary section violation during probe() */
+ drv->probe = probe;
+ retval = code = platform_driver_register(drv);
+
+ /* 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->probe = NULL;
+ if (code == 0 && list_empty(&drv->driver.klist_devices.k_list))
+ retval = -ENODEV;
+ drv->driver.probe = platform_drv_probe_fail;
+ spin_unlock(&platform_bus_type.klist_drivers.k_lock);
+
+ if (code != 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
^ permalink raw reply [flat|nested] 6+ messages in thread* Re: [patch 2.6.19-rc6] platform_driver_probe(), can save codespace
2006-11-17 7:28 [patch 2.6.19-rc6] platform_driver_probe(), can save codespace David Brownell
@ 2006-11-17 14:32 ` Dmitry Torokhov
2006-11-17 18:48 ` David Brownell
0 siblings, 1 reply; 6+ messages in thread
From: Dmitry Torokhov @ 2006-11-17 14:32 UTC (permalink / raw)
To: David Brownell; +Cc: Greg KH, Linux Kernel list
On 11/17/06, David Brownell <david-b@pacbell.net> wrote:
> +
> + /* 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->probe = NULL;
> + if (code == 0 && list_empty(&drv->driver.klist_devices.k_list))
> + retval = -ENODEV;
> + drv->driver.probe = platform_drv_probe_fail;
> + spin_unlock(&platform_bus_type.klist_drivers.k_lock);
I think this code should not be executed if driver is compiled as a
module because __init sections will stay anyway. Also, why don't you
also remove "bind" attribute if driver is built-in. That should save a
bit of dynamic memory.
--
Dmitry
^ permalink raw reply [flat|nested] 6+ messages in thread
* Re: [patch 2.6.19-rc6] platform_driver_probe(), can save codespace
2006-11-17 14:32 ` Dmitry Torokhov
@ 2006-11-17 18:48 ` David Brownell
2006-11-17 19:11 ` Dmitry Torokhov
0 siblings, 1 reply; 6+ messages in thread
From: David Brownell @ 2006-11-17 18:48 UTC (permalink / raw)
To: Dmitry Torokhov; +Cc: Greg KH, Linux Kernel list
On Friday 17 November 2006 6:32 am, Dmitry Torokhov wrote:
> On 11/17/06, David Brownell <david-b@pacbell.net> wrote:
> > +
> > + /* 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->probe = NULL;
> > + if (code == 0 && list_empty(&drv->driver.klist_devices.k_list))
> > + retval = -ENODEV;
> > + drv->driver.probe = platform_drv_probe_fail;
> > + spin_unlock(&platform_bus_type.klist_drivers.k_lock);
>
> I think this code should not be executed if driver is compiled as a
> module because __init sections will stay anyway.
Huh?? No they won't. Are you thinking "__devinit" with CONFIG_HOTPLUG?
(Remember, this routine is not for use with hotpluggable devices.)
> Also, why don't you
> also remove "bind" attribute if driver is built-in. That should save a
> bit of dynamic memory.
That would be an additional nuance. Feel free to submit another patch
on top of this one ... :)
- Dave
> --
> Dmitry
>
^ permalink raw reply [flat|nested] 6+ messages in thread
* Re: [patch 2.6.19-rc6] platform_driver_probe(), can save codespace
2006-11-17 18:48 ` David Brownell
@ 2006-11-17 19:11 ` Dmitry Torokhov
2006-11-17 20:26 ` David Brownell
0 siblings, 1 reply; 6+ messages in thread
From: Dmitry Torokhov @ 2006-11-17 19:11 UTC (permalink / raw)
To: David Brownell; +Cc: Greg KH, Linux Kernel list
On 11/17/06, David Brownell <david-b@pacbell.net> wrote:
> On Friday 17 November 2006 6:32 am, Dmitry Torokhov wrote:
> > On 11/17/06, David Brownell <david-b@pacbell.net> wrote:
> > > +
> > > + /* 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->probe = NULL;
> > > + if (code == 0 && list_empty(&drv->driver.klist_devices.k_list))
> > > + retval = -ENODEV;
> > > + drv->driver.probe = platform_drv_probe_fail;
> > > + spin_unlock(&platform_bus_type.klist_drivers.k_lock);
> >
> > I think this code should not be executed if driver is compiled as a
> > module because __init sections will stay anyway.
>
> Huh?? No they won't. Are you thinking "__devinit" with CONFIG_HOTPLUG?
> (Remember, this routine is not for use with hotpluggable devices.)
>
Do we discard __init sections in modules nowadays? I thought we did
that only for the kernel image itself.
--
Dmitry
^ permalink raw reply [flat|nested] 6+ messages in thread
end of thread, other threads:[~2006-11-17 21:50 UTC | newest]
Thread overview: 6+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2006-11-17 7:28 [patch 2.6.19-rc6] platform_driver_probe(), can save codespace David Brownell
2006-11-17 14:32 ` Dmitry Torokhov
2006-11-17 18:48 ` David Brownell
2006-11-17 19:11 ` Dmitry Torokhov
2006-11-17 20:26 ` David Brownell
2006-11-17 21:50 ` Dmitry Torokhov
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox