2010-08-23 17:18:51

by Kevin Hilman

[permalink] [raw]
Subject: [PATCH v2] driver core: platform_bus: allow runtime override of dev_pm_ops

Currently, the platform_bus allows customization of several of the
busses dev_pm_ops methods by using weak symbols so that platform code
can override them. The weak-symbol approach is not scalable when
wanting to support multiple platforms in a single kernel binary.

Instead, provide __init methods for platform code to customize the
dev_pm_ops methods at runtime.

NOTE: after these dynamic methods are merged, the weak symbols should
be removed from drivers/base/platform.c. AFAIK, this will only
affect SH and sh-mobile which should be converted to use this
runtime approach instead of the weak symbols. After SH &
sh-mobile are converted, the weak symobols could be removed.

Tested on OMAP3.

Cc: Grant Likely <[email protected]>
Cc: Magnus Damm <[email protected]>
Signed-off-by: Kevin Hilman <[email protected]>
---
drivers/base/platform.c | 35 +++++++++++++++++++++++++++++++++++
include/linux/platform_device.h | 3 +++
2 files changed, 38 insertions(+), 0 deletions(-)

diff --git a/drivers/base/platform.c b/drivers/base/platform.c
index c6c933f..e40a773 100644
--- a/drivers/base/platform.c
+++ b/drivers/base/platform.c
@@ -976,6 +976,41 @@ struct bus_type platform_bus_type = {
};
EXPORT_SYMBOL_GPL(platform_bus_type);

+/**
+ * platform_bus_get_pm_ops: return pointer to busses dev_pm_ops
+ *
+ * This function can be used by platform code to get the current
+ * set of dev_pm_ops functions used by the platform_bus_type.
+ */
+const struct dev_pm_ops * __init platform_bus_get_pm_ops(void)
+{
+ return platform_bus_type.pm;
+}
+
+/**
+ * platform_bus_set_pm_ops: update dev_pm_ops for the platform_bus_type
+ *
+ * @pm: pointer to new dev_pm_ops struct to be used for platform_bus_type
+ *
+ * Platform code can override the dev_pm_ops methods of
+ * platform_bus_type by using this function. It is expected that
+ * platform code will first do a platform_bus_get_pm_ops(), then
+ * kmemdup it, then customize selected methods and pass a pointer to
+ * the new struct dev_pm_ops to this function.
+ *
+ * Since platform-specific code is customizing methods for *all*
+ * devices (not just platform-specific devices) it is expected that
+ * any custom overrides of these functions will keep existing behavior
+ * and simply extend it. For example, any customization of the
+ * runtime PM methods should continue to call the pm_generic_*
+ * functions as the default ones do in addition to the
+ * platform-specific behavior.
+ */
+void __init platform_bus_set_pm_ops(struct dev_pm_ops *pm)
+{
+ platform_bus_type.pm = pm;
+}
+
int __init platform_bus_init(void)
{
int error;
diff --git a/include/linux/platform_device.h b/include/linux/platform_device.h
index d7ecad0..cd55d39 100644
--- a/include/linux/platform_device.h
+++ b/include/linux/platform_device.h
@@ -138,6 +138,9 @@ extern struct platform_device *platform_create_bundle(struct platform_driver *dr
struct resource *res, unsigned int n_res,
const void *data, size_t size);

+extern const struct dev_pm_ops * __init platform_bus_get_pm_ops(void);
+extern void __init platform_bus_set_pm_ops(struct dev_pm_ops *pm);
+
/* early platform driver interface */
struct early_platform_driver {
const char *class_str;
--
1.7.2.1


2010-08-25 07:30:32

by Grant Likely

[permalink] [raw]
Subject: Re: [PATCH v2] driver core: platform_bus: allow runtime override of dev_pm_ops

On Mon, Aug 23, 2010 at 11:18 AM, Kevin Hilman
<[email protected]> wrote:
> Currently, the platform_bus allows customization of several of the
> busses dev_pm_ops methods by using weak symbols so that platform code
> can override them. ?The weak-symbol approach is not scalable when
> wanting to support multiple platforms in a single kernel binary.
>
> Instead, provide __init methods for platform code to customize the
> dev_pm_ops methods at runtime.
>
> NOTE: after these dynamic methods are merged, the weak symbols should
> ? ? ?be removed from drivers/base/platform.c. ?AFAIK, this will only
> ? ? ?affect SH and sh-mobile which should be converted to use this
> ? ? ?runtime approach instead of the weak symbols. ?After SH &
> ? ? ?sh-mobile are converted, the weak symobols could be removed.
>
> Tested on OMAP3.
>
> Cc: Grant Likely <[email protected]>
> Cc: Magnus Damm <[email protected]>
> Signed-off-by: Kevin Hilman <[email protected]>

Looks good to me. A handful of nitpicks below, I don't know if Greg
will want you to respin for these or not. Feel free to add my
acked-by line though:

Acked-by: Grant Likely <[email protected]>

> ---
> ?drivers/base/platform.c ? ? ? ? | ? 35 +++++++++++++++++++++++++++++++++++
> ?include/linux/platform_device.h | ? ?3 +++
> ?2 files changed, 38 insertions(+), 0 deletions(-)
>
> diff --git a/drivers/base/platform.c b/drivers/base/platform.c
> index c6c933f..e40a773 100644
> --- a/drivers/base/platform.c
> +++ b/drivers/base/platform.c
> @@ -976,6 +976,41 @@ struct bus_type platform_bus_type = {
> ?};
> ?EXPORT_SYMBOL_GPL(platform_bus_type);
>
> +/**
> + * platform_bus_get_pm_ops: return pointer to busses dev_pm_ops

Nit: first line of kerneldoc format should look like this:

/**
* platform_bus_get_pm_ops() - return pointer to busses dev_pm_ops

> + *
> + * This function can be used by platform code to get the current
> + * set of dev_pm_ops functions used by the platform_bus_type.
> + */
> +const struct dev_pm_ops * __init platform_bus_get_pm_ops(void)
> +{
> + ? ? ? return platform_bus_type.pm;
> +}
> +
> +/**
> + * platform_bus_set_pm_ops: update dev_pm_ops for the platform_bus_type
> + *
> + * @pm: pointer to new dev_pm_ops struct to be used for platform_bus_type
> + *
> + * Platform code can override the dev_pm_ops methods of
> + * platform_bus_type by using this function. ?It is expected that
> + * platform code will first do a platform_bus_get_pm_ops(), then
> + * kmemdup it, then customize selected methods and pass a pointer to
> + * the new struct dev_pm_ops to this function.
> + *
> + * Since platform-specific code is customizing methods for *all*
> + * devices (not just platform-specific devices) it is expected that
> + * any custom overrides of these functions will keep existing behavior
> + * and simply extend it. ?For example, any customization of the
> + * runtime PM methods should continue to call the pm_generic_*
> + * functions as the default ones do in addition to the
> + * platform-specific behavior.
> + */
> +void __init platform_bus_set_pm_ops(struct dev_pm_ops *pm)

nit: const struct dev_pm_ops would be appropriate

> +{
> + ? ? ? platform_bus_type.pm = pm;
> +}
> +
> ?int __init platform_bus_init(void)
> ?{
> ? ? ? ?int error;
> diff --git a/include/linux/platform_device.h b/include/linux/platform_device.h
> index d7ecad0..cd55d39 100644
> --- a/include/linux/platform_device.h
> +++ b/include/linux/platform_device.h
> @@ -138,6 +138,9 @@ extern struct platform_device *platform_create_bundle(struct platform_driver *dr
> ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ?struct resource *res, unsigned int n_res,
> ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ?const void *data, size_t size);
>
> +extern const struct dev_pm_ops * __init platform_bus_get_pm_ops(void);
> +extern void __init platform_bus_set_pm_ops(struct dev_pm_ops *pm);

The __init annotations should only appear in the .c file, not the header.

Cheers,
g.

2010-08-25 19:50:06

by Kevin Hilman

[permalink] [raw]
Subject: Re: [PATCH v2] driver core: platform_bus: allow runtime override of dev_pm_ops

Grant Likely <[email protected]> writes:

> On Mon, Aug 23, 2010 at 11:18 AM, Kevin Hilman
> <[email protected]> wrote:
>> Currently, the platform_bus allows customization of several of the
>> busses dev_pm_ops methods by using weak symbols so that platform code
>> can override them. ?The weak-symbol approach is not scalable when
>> wanting to support multiple platforms in a single kernel binary.
>>
>> Instead, provide __init methods for platform code to customize the
>> dev_pm_ops methods at runtime.
>>
>> NOTE: after these dynamic methods are merged, the weak symbols should
>> ? ? ?be removed from drivers/base/platform.c. ?AFAIK, this will only
>> ? ? ?affect SH and sh-mobile which should be converted to use this
>> ? ? ?runtime approach instead of the weak symbols. ?After SH &
>> ? ? ?sh-mobile are converted, the weak symobols could be removed.
>>
>> Tested on OMAP3.
>>
>> Cc: Grant Likely <[email protected]>
>> Cc: Magnus Damm <[email protected]>
>> Signed-off-by: Kevin Hilman <[email protected]>
>
> Looks good to me. A handful of nitpicks below, I don't know if Greg
> will want you to respin for these or not. Feel free to add my
> acked-by line though:
>
> Acked-by: Grant Likely <[email protected]>

Thanks, here's a re-spin with your signoff and fixing the issues you
raised.

Applies to v2.6.36-rc1.

Kevin

>From 728f0ae551e805a10c9a45bcfb29f81ad45842da Mon Sep 17 00:00:00 2001
From: Kevin Hilman <[email protected]>
Date: Fri, 20 Aug 2010 10:46:53 -0700
Subject: [PATCH] driver core: platform_bus: allow runtime override of dev_pm_ops

Currently, the platform_bus allows customization of several of the
busses dev_pm_ops methods by using weak symbols so that platform code
can override them. The weak-symbol approach is not scalable when
wanting to support multiple platforms in a single kernel binary.

Instead, provide __init methods for platform code to customize the
dev_pm_ops methods at runtime.

NOTE: after these dynamic methods are merged, the weak symbols should
be removed from drivers/base/platform.c. AFAIK, this will only
affect SH and sh-mobile which should be converted to use this
runtime approach instead of the weak symbols. After SH &
sh-mobile are converted, the weak symobols could be removed.

Tested on OMAP3.

Cc: Magnus Damm <[email protected]>
Acked-by: Grant Likely <[email protected]>
Signed-off-by: Kevin Hilman <[email protected]>
---
drivers/base/platform.c | 35 +++++++++++++++++++++++++++++++++++
include/linux/platform_device.h | 3 +++
2 files changed, 38 insertions(+), 0 deletions(-)

diff --git a/drivers/base/platform.c b/drivers/base/platform.c
index c6c933f..468bbfd 100644
--- a/drivers/base/platform.c
+++ b/drivers/base/platform.c
@@ -976,6 +976,41 @@ struct bus_type platform_bus_type = {
};
EXPORT_SYMBOL_GPL(platform_bus_type);

+/**
+ * platform_bus_get_pm_ops() - return pointer to busses dev_pm_ops
+ *
+ * This function can be used by platform code to get the current
+ * set of dev_pm_ops functions used by the platform_bus_type.
+ */
+const struct dev_pm_ops * __init platform_bus_get_pm_ops(void)
+{
+ return platform_bus_type.pm;
+}
+
+/**
+ * platform_bus_set_pm_ops() - update dev_pm_ops for the platform_bus_type
+ *
+ * @pm: pointer to new dev_pm_ops struct to be used for platform_bus_type
+ *
+ * Platform code can override the dev_pm_ops methods of
+ * platform_bus_type by using this function. It is expected that
+ * platform code will first do a platform_bus_get_pm_ops(), then
+ * kmemdup it, then customize selected methods and pass a pointer to
+ * the new struct dev_pm_ops to this function.
+ *
+ * Since platform-specific code is customizing methods for *all*
+ * devices (not just platform-specific devices) it is expected that
+ * any custom overrides of these functions will keep existing behavior
+ * and simply extend it. For example, any customization of the
+ * runtime PM methods should continue to call the pm_generic_*
+ * functions as the default ones do in addition to the
+ * platform-specific behavior.
+ */
+void __init platform_bus_set_pm_ops(const struct dev_pm_ops *pm)
+{
+ platform_bus_type.pm = pm;
+}
+
int __init platform_bus_init(void)
{
int error;
diff --git a/include/linux/platform_device.h b/include/linux/platform_device.h
index d7ecad0..2e700ec 100644
--- a/include/linux/platform_device.h
+++ b/include/linux/platform_device.h
@@ -138,6 +138,9 @@ extern struct platform_device *platform_create_bundle(struct platform_driver *dr
struct resource *res, unsigned int n_res,
const void *data, size_t size);

+extern const struct dev_pm_ops * platform_bus_get_pm_ops(void);
+extern void platform_bus_set_pm_ops(const struct dev_pm_ops *pm);
+
/* early platform driver interface */
struct early_platform_driver {
const char *class_str;
--
1.7.2.1