Introduce builtin_driver and use it for non-modular code
Subsystems (12)
cover Introduce builtin_driver and use it for non-modular code
We see an increasing number of non-modular drivers using the modular_driver() type register functions. There are several downsides to this (as listed in the 1st commit log), so here we introduce similar non-modular macros for builtin drivers.
Then we convert builtin drivers (controlled by a bool Kconfig) by making the following type of changes:
module_platform_driver() ---> builtin_platform_driver()
module_platform_driver_probe() ---> builtin_platform_driver_probe().
The set of drivers that are converted here are just the ones that showed up as relying on an implicit include of <module.h> during a pending header cleanup. So we convert them here vs. adding an include of <module.h> to non-modular code to avoid compile fails. Additonal conversions can be done asynchronously at any time.
These changes, and the pending header cleanup are a refactoring of a larger series[1] into smaller, more easily reviewed chunks that share a common theme.
Note to maintainers: None of the conversion patches here can be taken into subtrees individually, since they all rely on the 1st patch to add the builtin macros. But I'll add Acks as requested.
Thanks,
Paul.
[1] https://marc.info/?l=linux-kernel&m=139033951228828
---
PATCH 3/7 drivers/cpuidle: Convert non-modular drivers to use builtin_driver_register
All these drivers are configured with Kconfig options that are declared as bool. Hence it is not possible for the code to be built as modular. However the code is currently using the module_platform_driver() macro for driver registration.
While this currently works, we really don't want to be including the module.h header in non-modular code, which we'll be forced to do, pending some upcoming code relocation from init.h into module.h. So we fix it now by using the non-modular equivalent.
--- drivers/cpuidle/cpuidle-at91.c | 3 +-- drivers/cpuidle/cpuidle-calxeda.c | 3 +-- drivers/cpuidle/cpuidle-zynq.c | 3 +-- 3 files changed, 3 insertions(+), 6 deletions(-)
drivers/cpuidle/cpuidle-at91.c +1 -2
@@ -62,5 +62,4 @@ static struct platform_driver at91_cpuidle_driver = { }, .probe = at91_cpuidle_probe, }; - -module_platform_driver (at91_cpuidle_driver); +builtin_platform_driver (at91_cpuidle_driver);
drivers/cpuidle/cpuidle-calxeda.c +1 -2
@@ -75,5 +75,4 @@ static struct platform_driver calxeda_cpuidle_plat_driver = { }, .probe = calxeda_cpuidle_probe, }; - -module_platform_driver (calxeda_cpuidle_plat_driver); +builtin_platform_driver (calxeda_cpuidle_plat_driver);
drivers/cpuidle/cpuidle-zynq.c +1 -2
@@ -73,5 +73,4 @@ static struct platform_driver zynq_cpuidle_driver = { }, .probe = zynq_cpuidle_probe, }; - -module_platform_driver (zynq_cpuidle_driver); +builtin_platform_driver (zynq_cpuidle_driver);
Signature · 1 line
2.2.1
PATCH 4/7 drivers/cpufreq: Convert non-modular drivers to use builtin_driver_register
In reply to Paul GortmakerThese files depend on Kconfig options all of which are a bool, so we use the appropriate registration function, which avoids us relying on an implicit inclusion of <module.h> which we are doing currently.
While this currently works, we really don't want to be including the module.h header in non-modular code, which we'd be forced to do, pending some upcoming code relocation from init.h into module.h. So we fix it now by using the non-modular equivalent.
--- drivers/cpufreq/exynos-cpufreq.c | 2 +- drivers/cpufreq/s5pv210-cpufreq.c | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-)
drivers/cpufreq/exynos-cpufreq.c +1 -1
@@ -236,4 +236,4 @@ static struct platform_driver exynos_cpufreq_platdrv = { }, .probe = exynos_cpufreq_probe, }; -module_platform_driver (exynos_cpufreq_platdrv); +builtin_platform_driver (exynos_cpufreq_platdrv);
drivers/cpufreq/s5pv210-cpufreq.c +1 -1
@@ -659,4 +659,4 @@ static struct platform_driver s5pv210_cpufreq_platdrv = { }, .probe = s5pv210_cpufreq_probe, }; -module_platform_driver (s5pv210_cpufreq_platdrv); +builtin_platform_driver (s5pv210_cpufreq_platdrv);
Signature · 1 line
2.2.1
PATCH 5/7 drivers/soc: Convert non-modular tegra/pmc to use builtin_driver_register
In reply to Paul GortmakerThis file depends on Kconfig ARCH_TEGRA which is a bool, so we use the appropriate registration function, which avoids us relying on an implicit inclusion of <module.h> which we are doing currently.
While this currently works, we really don't want to be including the module.h header in non-modular code, which we'd be forced to do, pending some upcoming code relocation from init.h into module.h. So we fix it now by using the non-modular equivalent.
--- drivers/soc/tegra/pmc.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-)
drivers/soc/tegra/pmc.c +1 -1
@@ -1010,7 +1010,7 @@ static struct platform_driver tegra_pmc_driver = { }, .probe = tegra_pmc_probe, }; -module_platform_driver (tegra_pmc_driver); +builtin_platform_driver (tegra_pmc_driver);/* * Early initialization to allow access to registers in the very early boot
Signature · 1 line
2.2.1
PATCH 1/7 platform_device: better support builtin boilerplate avoidance
In reply to Paul GortmakerWe have macros that help reduce the boilerplate for modules that register with no extra init/exit complexity other than the most standard use case. However we see an increasing number of non-modular drivers using these modular_driver() type register functions.
There are several downsides to this:
1) The code can appear modular to a reader of the code, and they won't know if the code really is modular without checking the Makefile and Kconfig to see if compilation is governed by a bool or tristate.
2) Coders of drivers may be tempted to code up an __exit function that is never used, just in order to satisfy the required three args of the modular registration function.
3) Non-modular code ends up including the <module.h> which increases CPP overhead that they don't need.
4) It hinders us from performing better separation of the module init code and the generic init code.
Here we introduce similar macros, with the mapping from module_driver to builtin_driver and similar, so that simple changes of:
module_platform_driver() ---> builtin_platform_driver()
module_platform_driver_probe() ---> builtin_platform_driver_probe().
can help us avoid #3 above, without having to code up the same __init functions and device_initcall() boilerplate.
For non modular code, module_init becomes __initcall. But direct use of __initcall is discouraged, vs. one of the priority categorized subgroups. As __initcall gets mapped onto device_initcall, our use of device_initcall directly in this change means that the runtime impact is zero -- drivers will remain at level 6 in the initcall ordering.
---
[checkpatch complains about this patch, but I choose to ignore that
and keep the added code 100% consistent with the existing code.]
include/linux/device.h | 22 ++++++++++++++++++++++ include/linux/platform_device.h | 23 +++++++++++++++++++++++ 2 files changed, 45 insertions(+)
include/linux/device.h +22 -0
@@ -1269,4 +1269,26 @@ static void __exit __driver##_exit(void) \ } \ module_exit(__driver##_exit); +/** +* builtin_driver() - Helper macro for drivers that don't do anything +* special in init and have no exit. This eliminates some boilerplate. +* Each driver may only use this macro once, and calling it replaces +* device_initcall (or in some cases, the legacy __initcall). This is +* meant to be a direct parallel of module_driver() above but without +* the __exit stuff that is not used for builtin cases. +* +* @__driver: driver name +* @__register: register function for this driver type +* @...: Additional arguments to be passed to __register +* +* Use this macro to construct bus specific macros for registering +* drivers, and do not use it on its own. +*/ +#define builtin_driver (__driver, __register, ...) \ +static int __init __driver##_init(void) \ +{ \ + return __register(&(__driver) , ##__VA_ARGS__); \ +} \ +device_initcall(__driver##_init); +#endif /* _DEVICE_H_ */
include/linux/platform_device.h +23 -0
@@ -222,6 +222,15 @@ static inline void platform_set_drvdata(struct platform_device *pdev,module_driver (__platform_driver, platform_driver_register, \ platform_driver_unregister) +/* builtin_platform_driver() - Helper macro for builtin drivers that +* don't do anything special in driver init. This eliminates some +* boilerplate. Each driver may only use this macro once, and +* calling it replaces device_initcall(). Note this is meant to be +* a parallel of module_platform_driver() above, but w/o _exit stuff. + */ +#define builtin_platform_driver (__platform_driver) \ + builtin_driver(__platform_driver, platform_driver_register) +/* module_platform_driver_probe() - Helper macro for drivers that don't do * anything special in module init/exit. This eliminates a lot of * boilerplate. Each module may only use this macro once, and
@@ -240,6 +249,20 @@ static void __exit __platform_driver##_exit(void) \ } \ module_exit(__platform_driver##_exit); +/* builtin_platform_driver_probe() - Helper macro for drivers that don't do +* anything special in device init. This eliminates some boilerplate. Each +* driver may only use this macro once, and using it replaces device_initcall. +* This is meant to be a parallel of module_platform_driver_probe above, but +* without the __exit parts. +*/ +#define builtin_platform_driver_probe (__platform_driver, __platform_probe) \ +static int __init __platform_driver##_init(void) \ +{ \ + return platform_driver_probe(&(__platform_driver), \ + __platform_probe); \ +} \ +device_initcall(__platform_driver##_init); \ +#define platform_create_bundle (driver, probe, res, n_res, data, size) \ __platform_create_bundle(driver, probe, res, n_res, data, size, THIS_MODULE) extern struct platform_device *__platform_create_bundle(
Signature · 1 line
2.2.1
PATCH 2/7 drivers/platform: Convert non-modular pdev_bus to use builtin_driver_register
In reply to Paul GortmakerThis driver is configured with a Kconfig option that is declared as a bool. Hence it is not possible for the code to be built as modular. However the code is currently using the module_platform_driver() macro for driver registration.
While this currently works, we really don't want to be including the module.h header in non-modular code, which we'll be forced to do, pending some upcoming code relocation from init.h into module.h. So we fix it now by using the non-modular equivalent. And since we've already established that the code is non-modular, we can completely drop any code relating to module_exit.
--- drivers/platform/goldfish/pdev_bus.c | 12 +----------- 1 file changed, 1 insertion(+), 11 deletions(-)
drivers/platform/goldfish/pdev_bus.c +1 -11
@@ -220,20 +220,10 @@ free_resources:return ret; } -static int goldfish_pdev_bus_remove (struct platform_device *pdev) -{ -iounmap (pdev_bus_base); -free_irq (pdev_bus_irq, pdev); -release_mem_region (pdev_bus_addr, pdev_bus_len); -return 0 ; -} -static struct platform_driver goldfish_pdev_bus_driver = { .probe = goldfish_pdev_bus_probe, - .remove = goldfish_pdev_bus_remove, .driver = { .name ="goldfish_pdev_bus" } }; - -module_platform_driver (goldfish_pdev_bus_driver); +builtin_platform_driver (goldfish_pdev_bus_driver);
Signature · 1 line
2.2.1
PATCH 6/7 drivers/soc: Convert non-modular soc-realview to use builtin_driver_register
In reply to Paul GortmakerThis file depends on Kconfig SOC_REALVIEW which is a bool, so we use the appropriate registration function, which avoids us relying on an implicit inclusion of <module.h> which we are doing currently.
While this currently works, we really don't want to be including the module.h header in non-modular code, which we'd be forced to do, pending some upcoming code relocation from init.h into module.h. So we fix it now by using the non-modular equivalent.
--- drivers/soc/versatile/soc-realview.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-)
drivers/soc/versatile/soc-realview.c +1 -1
@@ -142,4 +142,4 @@ static struct platform_driver realview_soc_driver = { .of_match_table = realview_soc_of_match, }, }; -module_platform_driver (realview_soc_driver); +builtin_platform_driver (realview_soc_driver);
Signature · 1 line
2.2.1
PATCH 7/7 drivers/power: Convert non-modular syscon-reboot to use builtin_driver_register
In reply to Paul GortmakerThis file depends on Kconfig options all of which are a bool, so we use the appropriate registration function, which avoids us relying on an implicit inclusion of <module.h> which we are doing currently.
While this currently works, we really don't want to be including the module.h header in non-modular code, which we'd be forced to do, pending some upcoming code relocation from init.h into module.h. So we fix it now by using the non-modular equivalent.
--- drivers/power/reset/syscon-reboot.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-)
drivers/power/reset/syscon-reboot.c +1 -1
@@ -88,4 +88,4 @@ static struct platform_driver syscon_reboot_driver = { .of_match_table = syscon_reboot_of_match, }, }; -module_platform_driver (syscon_reboot_driver); +builtin_platform_driver (syscon_reboot_driver);
Signature · 1 line
2.2.1
Re: [PATCH 3/7] drivers/cpuidle: Convert non-modular drivers to use builtin_driver_register
In reply to Paul GortmakerQuoted 10 lines · Paul Gortmaker
All these drivers are configured with
Kconfigoptions that are declared as bool. Hence it is not possible for the code to be built as modular. However the code is currently using themodule_platform_driver()macro for driver registration.While this currently works, we really don't want to be including the
module.hheader in non-modular code, which we'll be forced to do, pending some upcoming code relocation frominit.hintomodule.h. So we fix it now by using the non-modular equivalent.
Quoted 6 lines
Cc "Rafael J. Wysocki" <[email protected]>Cc Daniel Lezcano <[email protected]>Cc Michal Simek <[email protected]>Cc linux-pm at vger.kernel.orgCc linux-arm-kernel at lists.infradead.orgSigned-off-by Paul Gortmaker <[email protected]>
Sounds reasonable.
-- Daniel
Quoted 40 lines
--- drivers/cpuidle/cpuidle-at91.c | 3 +-- drivers/cpuidle/cpuidle-calxeda.c | 3 +-- drivers/cpuidle/cpuidle-zynq.c | 3 +-- 3 files changed, 3 insertions(+), 6 deletions(-)drivers/cpuidle/cpuidle-at91.c +1
-2@@ -62,5 +62,4 @@ static struct platform_driver at91_cpuidle_driver = { }, .probe = at91_cpuidle_probe, }; - -module_platform_driver (at91_cpuidle_driver); +builtin_platform_driver (at91_cpuidle_driver);drivers/cpuidle/cpuidle-calxeda.c +1
-2@@ -75,5 +75,4 @@ static struct platform_driver calxeda_cpuidle_plat_driver = { }, .probe = calxeda_cpuidle_probe, }; - -module_platform_driver (calxeda_cpuidle_plat_driver); +builtin_platform_driver (calxeda_cpuidle_plat_driver);drivers/cpuidle/cpuidle-zynq.c +1
-2@@ -73,5 +73,4 @@ static struct platform_driver zynq_cpuidle_driver = { }, .probe = zynq_cpuidle_probe, }; - -module_platform_driver (zynq_cpuidle_driver); +builtin_platform_driver (zynq_cpuidle_driver);
Signature · 5 lines
<http://www.linaro.org/> Linaro.org ? Open source software for ARM SoCs Follow Linaro: <http://www.facebook.com/pages/Linaro> Facebook | <http://twitter.com/#!/linaroorg> Twitter | <http://www.linaro.org/linaro-blog/> Blog
Viresh Kumar
maintainerRe: [PATCH 4/7] drivers/cpufreq: Convert non-modular drivers to use builtin_driver_register
In reply to Paul GortmakerQuoted 10 lines · Paul Gortmaker
These files depend on
Kconfigoptions all of which are a bool, so we use the appropriate registration function, which avoids us relying on an implicit inclusion of <module.h> which we are doing currently.While this currently works, we really don't want to be including the
module.hheader in non-modular code, which we'd be forced to do, pending some upcoming code relocation frominit.hintomodule.h. So we fix it now by using the non-modular equivalent.
Quoted 8 lines
Cc "Rafael J. Wysocki" <[email protected]>Cc Viresh Kumar <[email protected]>Cc Kukjin Kim <[email protected]>Cc linux-pm at vger.kernel.orgCc linux-arm-kernel at lists.infradead.orgSigned-off-by Paul Gortmaker <[email protected]>--- drivers/cpufreq/exynos-cpufreq.c | 2 +-
Exynos can be compiled as a module:
drivers/cpufreq/Kconfig.arm:
config ARM_EXYNOS_CPUFREQ
tristate "SAMSUNG EXYNOS CPUfreq Driver" depends on CPU_EXYNOS4210 || SOC_EXYNOS4212 || SOC_EXYNOS4412 || SOC_EXYNOS5250
--
viresh
Re: [PATCH 6/7] drivers/soc: Convert non-modular soc-realview to use builtin_driver_register
In reply to Paul GortmakerQuoted 10 lines · Paul Gortmaker
This file depends on
KconfigSOC_REALVIEWwhich is a bool, so we use the appropriate registration function, which avoids us relying on an implicit inclusion of <module.h> which we are doing currently.While this currently works, we really don't want to be including the
module.hheader in non-modular code, which we'd be forced to do, pending some upcoming code relocation frominit.hintomodule.h. So we fix it now by using the non-modular equivalent.
Quoted 4 lines
Cc Arnd Bergmann <[email protected]>Cc Linus Walleij <[email protected]>Cc Axel Lin <[email protected]>Signed-off-by Paul Gortmaker <[email protected]>
Yours,
Linus Walleij
Re: [PATCH 1/7] platform_device: better support builtin boilerplate avoidance
In reply to Paul GortmakerQuoted 35 lines · Paul Gortmaker
We have macros that help reduce the boilerplate for modules that register with no extra init/exit complexity other than the most standard use case. However we see an increasing number of non-modular drivers using these
modular_driver()type register functions.There are several downsides to this:
1) The code can appear modular to a reader of the code, and they won't know if the code really is modular without checking theMakefileandKconfigto see if compilation is governed by a bool or tristate.
2) Coders of drivers may be tempted to code up an__exitfunction that is never used, just in order to satisfy the required three args of the modular registration function.
3) Non-modular code ends up including the <module.h> which increases CPP overhead that they don't need.
4) It hinders us from performing better separation of the module init code and the generic init code.Here we introduce similar macros, with the mapping from
module_drivertobuiltin_driverand similar, so that simple changes of:
module_platform_driver()--->builtin_platform_driver()
module_platform_driver_probe()--->builtin_platform_driver_probe().can help us avoid #3 above, without having to code up the same
__initfunctions anddevice_initcall()boilerplate.For non modular code,
module_initbecomes__initcall. But direct use of__initcallis discouraged, vs. one of the priority categorized subgroups. As__initcallgets mapped ontodevice_initcall, our use ofdevice_initcalldirectly in this change means that the runtime impact is zero -- drivers will remain at level 6 in the initcall ordering.
Quoted 2 lines
Cc Greg Kroah-Hartman <[email protected]>Signed-off-by Paul Gortmaker <[email protected]>
This does not inhibit probe() and remove() to be triggered from sysfs does it?
What is needed on builtin drivers is to set .suppress_bind_attrs = true on the struct device_driver so that we inhibit the creation of sysfs files to probe and remove the driver by operator intervention.
I don't know if there is a simple way do address this though since you don't seem to operate on the struct device_driver, just pass it on.
Maybe it's possible to inhibit compilation of builtin_platform_driver's if .suppress_bind_attrs == 0?
Yours,
Linus Walleij
Re: [PATCH 4/7] drivers/cpufreq: Convert non-modular drivers to use builtin_driver_register
In reply to Viresh KumarQuoted 20 lines · Viresh Kumar
Quoted 10 lines · Paul Gortmaker
These files depend on
Kconfigoptions all of which are a bool, so we use the appropriate registration function, which avoids us relying on an implicit inclusion of <module.h> which we are doing currently.While this currently works, we really don't want to be including the
module.hheader in non-modular code, which we'd be forced to do, pending some upcoming code relocation frominit.hintomodule.h. So we fix it now by using the non-modular equivalent.Quoted 8 lines
Cc "Rafael J. Wysocki" <[email protected]>Cc Viresh Kumar <[email protected]>Cc Kukjin Kim <[email protected]>Cc linux-pm at vger.kernel.orgCc linux-arm-kernel at lists.infradead.orgSigned-off-by Paul Gortmaker <[email protected]>--- drivers/cpufreq/exynos-cpufreq.c | 2 +-
Quoted 7 lines
Exynos can be compiled as a module:
drivers/cpufreq/Kconfig.arm:config
ARM_EXYNOS_CPUFREQ
tristate "SAMSUNG EXYNOS CPUfreq Driver"
depends onCPU_EXYNOS4210||SOC_EXYNOS4212||SOC_EXYNOS4412||SOC_EXYNOS5250
Sounds like things have changed since I did the original compile testing ; thanks for the heads-up and I will follow up with the details, once I can re-test.
Thanks,
Paul.
--
Quoted 8 lines
--
viresh
--
To unsubscribe from this list: send the line "unsubscribe linux-kernel" in the body of a message to majordomo at vger.kernel.org
More majordomo info at http://vger.kernel.org/majordomo-info.html
Please read the FAQ at http://www.tux.org/lkml/
Re: [PATCH 7/7] drivers/power: Convert non-modular syscon-reboot to use builtin_driver_register
In reply to Paul GortmakerHi,
Quoted 24 lines · Paul Gortmaker
This file depends on
Kconfigoptions all of which are a bool, so we use the appropriate registration function, which avoids us relying on an implicit inclusion of <module.h> which we are doing currently.While this currently works, we really don't want to be including the
module.hheader in non-modular code, which we'd be forced to do, pending some upcoming code relocation frominit.hintomodule.h. So we fix it now by using the non-modular equivalent.Cc Sebastian Reichel <[email protected]>Cc Dmitry Eremin-Solenikov <[email protected]>Cc David Woodhouse <[email protected]>Signed-off-by Paul Gortmaker <[email protected]>--- drivers/power/reset/syscon-reboot.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-)drivers/power/reset/syscon-reboot.c +0
-0
drivers/power/reset/syscon-reboot.c static struct platform_driver syscon_reboot_driver = { · line 91
Quoted 5 lines
drivers/power/reset/syscon-reboot.c +1
-1@@ -88,4 +88,4 @@ static struct platform_driver syscon_reboot_driver = { .of_match_table = syscon_reboot_of_match, }, }; -module_platform_driver (syscon_reboot_driver); +builtin_platform_driver (syscon_reboot_driver);
-- Sebastian
Re: [PATCH 1/7] platform_device: better support builtin boilerplate avoidance
In reply to Linus WalleijQuoted 41 lines · [Re: [PATCH 1/7] platform_device: better support builtin boilerplate…
Quoted 35 lines · Paul Gortmaker
We have macros that help reduce the boilerplate for modules that register with no extra init/exit complexity other than the most standard use case. However we see an increasing number of non-modular drivers using these
modular_driver()type register functions.There are several downsides to this:
1) The code can appear modular to a reader of the code, and they won't know if the code really is modular without checking theMakefileandKconfigto see if compilation is governed by a bool or tristate.
2) Coders of drivers may be tempted to code up an__exitfunction that is never used, just in order to satisfy the required three args of the modular registration function.
3) Non-modular code ends up including the <module.h> which increases CPP overhead that they don't need.
4) It hinders us from performing better separation of the module init code and the generic init code.Here we introduce similar macros, with the mapping from
module_drivertobuiltin_driverand similar, so that simple changes of:
module_platform_driver()--->builtin_platform_driver()
module_platform_driver_probe()--->builtin_platform_driver_probe().can help us avoid #3 above, without having to code up the same
__initfunctions anddevice_initcall()boilerplate.For non modular code,
module_initbecomes__initcall. But direct use of__initcallis discouraged, vs. one of the priority categorized subgroups. As__initcallgets mapped ontodevice_initcall, our use ofdevice_initcalldirectly in this change means that the runtime impact is zero -- drivers will remain at level 6 in the initcall ordering.Quoted 2 lines
Cc Greg Kroah-Hartman <[email protected]>Signed-off-by Paul Gortmaker <[email protected]>
Quoted 7 lines
This does not inhibit
probe()andremove()to be triggered from sysfs does it?What is needed on builtin drivers is to set .suppress_bind_attrs = true on the struct
device_driverso that we inhibit the creation of sysfs files to probe and remove the driver by operator intervention.
Is this needed? I think we will break existing use cases if we do this.
For example, I have IGB as built-in, but I can still unbind one of the four devices and make it available for PCI pass through to KVM with:
echo "0000:0a:00.1" > /sys/bus/pci/drivers/igb/unbind echo "0000:0a:00.1" > /sys/bus/pci/drivers/pci-stub/bind
Quoted 7 lines
I don't know if there is a simple way do address this though since you don't seem to operate on the struct
device_driver, just pass it on.Maybe it's possible to inhibit compilation of builtin_platform_driver's if .suppress_bind_attrs == 0?
If we wanted to do this, I think we could simply do something like:
int __platform_driver_register(struct platform_driver *drv,
struct module *owner)
{
drv->driver.owner = owner;
drv->driver.bus = &platform_bus_type;
+ if (!owner) /* built in */
+ drv->driver.suppress_bind_attrs = true;
if (drv->probe)
drv->driver.probe = platform_drv_probe;
if (drv->remove)...but again, I'm thinking that will break things for people, unless I'm missing something here.
Paul.
--
Quoted 3 lines
Yours,
Linus Walleij
Re: [PATCH 1/7] platform_device: better support builtin boilerplate avoidance
Quoted 10 lines · Paul Gortmaker
Quoted 7 lines · [Re: [PATCH 1/7] platform_device: better support builtin boilerplate…
This does not inhibit
probe()andremove()to be
triggered from sysfs does it?What is needed on builtin drivers is to set .suppress_bind_attrs = true on the struct
device_driverso that we inhibit the creation of sysfs files to probe and remove the driver by operator intervention.
Quoted 7 lines
Is this needed? I think we will break existing use cases if we do this.
For example, I have IGB as built-in, but I can still unbind one of the four devices and make it available for PCI pass through to KVM with:
echo "0000:0a:00.1" >
/sys/bus/pci/drivers/igb/unbindecho "0000:0a:00.1" >/sys/bus/pci/drivers/pci-stub/bind
Aha PCI device which noone else is dependent on, I guess it's true.
I think we have a problem as to what "builtin" really means. For example if this is a builtin regulator, clock, GPIO, DMA etc driver, we want to suppress the binding/unbinding from userspace too, since these drivers provide resources to others and if you unbind them, nasty things happen. Unbinding/rebinding is fine as long as noone else depend on you. However for a large number of builtins, that is the case :P
Yours,
Linus Walleij
Re: [PATCH 1/7] platform_device: better support builtin boilerplate avoidance
Quoted 17 lines · Linus Walleij
Quoted 15 lines · Paul Gortmaker
Quoted 7 lines · [Re: [PATCH 1/7] platform_device: better support builtin boilerplate…
This does not inhibit
probe()andremove()to be
triggered from sysfs does it?What is needed on builtin drivers is to set .suppress_bind_attrs = true on the struct
device_driverso that we inhibit the creation of sysfs files to probe and remove the driver by operator intervention.Is this needed? I think we will break existing use cases if we do this.
For example, I have IGB as built-in, but I can still unbind one of the four devices and make it available for PCI pass through to KVM with:
Quoted 7 lines
Quoted 2 lines
echo "0000:0a:00.1" >
/sys/bus/pci/drivers/igb/unbindecho "0000:0a:00.1" >/sys/bus/pci/drivers/pci-stub/bindAha PCI device which noone else is dependent on, I guess it's true.
I think we have a problem as to what "builtin" really means.
Well, people have had trouble with what "is" means before, so I guess it is possible. However, I think here it is pretty clear that builtin means a Kconfig which is "y" and where "m" is not a possible selection.
Quoted 6 lines
For example if this is a builtin regulator, clock, GPIO, DMA etc driver, we want to suppress the binding/unbinding from userspace too, since these drivers provide resources to others and if you unbind them, nasty things happen. Unbinding/rebinding is fine as long as noone else depend on you. However for a large number of builtins, that is the case :P
So, to summarize:
1) Currently drivers can unbind that really should not do so.
2) This is not a new issue, nor is it introduced by this series.
3) We can't set policy based on built in vs modular; the only sane thing appears to be to let the driver decide itself.
Paul.
--
Quoted 4 lines
Yours,
Linus Walleij
PATCH 1/1 drivers/clk: convert sunxi/clk-mod0.c to use builtin_platform_driver
In reply to Paul GortmakerThis driver builds based on obj-y and hence will not ever be modular. Change it to use the non-modular registration so that it won't suffer a compile fail once a header move places the modular registration within the module.h file.
---
[appending this to the builtin_platform_driver series of commits; see
https://lkml.kernel.org/r/1431287385-1526-1-git-send-email-paul.gortmaker at windriver.com for original series posting. The final header move can be found at:
https://lkml.kernel.org/r/1433276168-21550-1-git-send-email-paul.gortmaker at windriver.com ]
drivers/clk/sunxi/clk-mod0.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-)
drivers/clk/sunxi/clk-mod0.c +1 -1
@@ -128,7 +128,7 @@ static struct platform_driver sun4i_a10_mod0_clk_driver = { }, .probe = sun4i_a10_mod0_clk_probe, }; -module_platform_driver (sun4i_a10_mod0_clk_driver); +builtin_platform_driver (sun4i_a10_mod0_clk_driver);static const struct factors_data sun9i_a80_mod0_data__initconst = { .enable =31 ,
Signature · 1 line
2.2.1
Re: [PATCH 4/7] drivers/cpufreq: Convert non-modular drivers to use builtin_driver_register
In reply to Viresh KumarQuoted 20 lines · [Re: [PATCH 4/7] drivers/cpufreq: Convert non-modular drivers to use…
Quoted 10 lines · Paul Gortmaker
These files depend on
Kconfigoptions all of which are a bool, so we use the appropriate registration function, which avoids us relying on an implicit inclusion of <module.h> which we are doing currently.While this currently works, we really don't want to be including the
module.hheader in non-modular code, which we'd be forced to do, pending some upcoming code relocation frominit.hintomodule.h. So we fix it now by using the non-modular equivalent.Quoted 8 lines
Cc "Rafael J. Wysocki" <[email protected]>Cc Viresh Kumar <[email protected]>Cc Kukjin Kim <[email protected]>Cc linux-pm at vger.kernel.orgCc linux-arm-kernel at lists.infradead.orgSigned-off-by Paul Gortmaker <[email protected]>--- drivers/cpufreq/exynos-cpufreq.c | 2 +-
Quoted 7 lines
Exynos can be compiled as a module:
drivers/cpufreq/Kconfig.arm:config
ARM_EXYNOS_CPUFREQtristate "SAMSUNG EXYNOS CPUfreq Driver" depends on CPU_EXYNOS4210 || SOC_EXYNOS4212 || SOC_EXYNOS4412 || SOC_EXYNOS5250
Thanks -- I think I managed to confuse myself into thinking it was builtin always, courtesy of the "-y" in this Makefile line...
arm-exynos-cpufreq-y := exynos-cpufreq.o
I'll drop the exynos chunk from this patch and fix the implicit module.h exynos usage in a new follow on patch, both to be sent shortly.
Paul.
--
Quoted 3 lines
--
viresh
PATCH v2 1/1 drivers/cpufreq: Convert non-modular s5pv210-cpufreq.c to use builtin_platform_driver
In reply to Viresh KumarThis file depends on a Kconfig option which is a bool, so we use the appropriate registration function, which avoids us relying on an implicit inclusion of <module.h> which we are doing currently.
While this currently works, we really don't want to be including the module.h header in non-modular code, which we'd be forced to do, pending some upcoming code relocation from init.h into module.h. So we fix it now by using the non-modular equivalent.
---
[v2: drop exnyos part from patch, since it really was modular and
instead needs its implicit include fixed.]
drivers/cpufreq/s5pv210-cpufreq.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-)
drivers/cpufreq/s5pv210-cpufreq.c +1 -1
@@ -659,4 +659,4 @@ static struct platform_driver s5pv210_cpufreq_platdrv = { }, .probe = s5pv210_cpufreq_probe, }; -module_platform_driver (s5pv210_cpufreq_platdrv); +builtin_platform_driver (s5pv210_cpufreq_platdrv);
Signature · 1 line
2.2.1
Re: [PATCH v2] drivers/cpufreq: Convert non-modular s5pv210-cpufreq.c to use builtin_platform_driver
Quoted 29 lines · Paul Gortmaker
This file depends on a
Kconfigoption which is a bool, so we use the appropriate registration function, which avoids us relying on an implicit inclusion of <module.h> which we are doing currently.While this currently works, we really don't want to be including the
module.hheader in non-modular code, which we'd be forced to do, pending some upcoming code relocation frominit.hintomodule.h. So we fix it now by using the non-modular equivalent.Cc "Rafael J. Wysocki" <[email protected]>Cc Viresh Kumar <[email protected]>Cc Kukjin Kim <[email protected]>Cc linux-pm at vger.kernel.orgCc linux-arm-kernel at lists.infradead.orgSigned-off-by Paul Gortmaker <[email protected]>---
[v2: drop exnyos part from patch, since it really was modular and
instead needs its implicit include fixed.]drivers/cpufreq/s5pv210-cpufreq.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-)drivers/cpufreq/s5pv210-cpufreq.c +0
-0
drivers/cpufreq/s5pv210-cpufreq.c static struct platform_driver s5pv210_cpufreq_platdrv = { · line 662
Quoted 5 lines
drivers/cpufreq/s5pv210-cpufreq.c +1
-1@@ -659,4 +659,4 @@ static struct platform_driver s5pv210_cpufreq_platdrv = { }, .probe = s5pv210_cpufreq_probe, }; -module_platform_driver (s5pv210_cpufreq_platdrv); +builtin_platform_driver (s5pv210_cpufreq_platdrv);
Signature · 1 line
viresh
Re: [PATCH] drivers/clk: convert sunxi/clk-mod0.c to use builtin_platform_driver
In reply to Paul GortmakerQuoted 5 lines · Paul Gortmaker
This driver builds based on obj-y and hence will not ever be modular. Change it to use the non-modular registration so that it won't suffer a compile fail once a header move places the modular registration within the
module.hfile.
Quoted 7 lines
Cc "Emilio L?pez" <[email protected]>Cc Mike Turquette <[email protected]>Cc Stephen Boyd <[email protected]>Cc Maxime Ripard <[email protected]>Cc linux-clk at vger.kernel.orgCc linux-arm-kernel at lists.infradead.orgSigned-off-by Paul Gortmaker <[email protected]>
Thanks!
Maxime
Signature · 10 lines
Maxime Ripard, Free Electrons Embedded Linux, Kernel and Android engineering http://free-electrons.com -------------- next part -------------- A non-text attachment was scrubbed... Name: signature.asc Type: application/pgp-signature Size: 819 bytes Desc: Digital signature URL: <http://lists.infradead.org/pipermail/linux-arm-kernel/attachments/20150604/0ba0c04a/attachment.sig>
Re: [PATCH] drivers/clk: convert sunxi/clk-mod0.c to use builtin_platform_driver
In reply to Paul GortmakerQuoted 5 lines · Paul Gortmaker
This driver builds based on obj-y and hence will not ever be modular. Change it to use the non-modular registration so that it won't suffer a compile fail once a header move places the modular registration within the
module.hfile.
Quoted 8 lines
Cc "Emilio L?pez" <[email protected]>Cc Mike Turquette <[email protected]>Cc Stephen Boyd <[email protected]>Cc Maxime Ripard <[email protected]>Cc linux-clk at vger.kernel.orgCc linux-arm-kernel at lists.infradead.orgSigned-off-by Paul Gortmaker <[email protected]>---
Signature · 2 lines
Qualcomm Innovation Center, Inc. is a member of Code Aurora Forum, a Linux Foundation Collaborative Project
Re: [PATCH 1/7] platform_device: better support builtin boilerplate avoidance
In reply to Paul GortmakerQuoted 9 lines · Paul Gortmaker
Quoted 6 lines · Linus Walleij
For example if this is a builtin regulator, clock, GPIO, DMA etc driver, we want to suppress the binding/unbinding from userspace too, since these drivers provide resources to others and if you unbind them, nasty things happen. Unbinding/rebinding is fine as long as noone else depend on you. However for a large number of builtins, that is the case :P
Quoted 8 lines
So, to summarize:
1) Currently drivers can unbind that really should not do so.
2) This is not a new issue, nor is it introduced by this series.
3) We can't set policy based on built in vs modular; the only sane thing appears to be to let the driver decide itself.
Yeah I think you're right. If I wanted to fix this problem I should come up with some patches to help driver authors do it themselves in a simpler way.
Yours,
Linus Walleij
Re: [PATCH v2] drivers/cpufreq: Convert non-modular s5pv210-cpufreq.c to use builtin_platform_driver
In reply to Paul GortmakerQuoted 10 lines · Paul Gortmaker
This file depends on a
Kconfigoption which is a bool, so we use the appropriate registration function, which avoids us relying on an implicit inclusion of <module.h> which we are doing currently.While this currently works, we really don't want to be including the
module.hheader in non-modular code, which we'd be forced to do, pending some upcoming code relocation frominit.hintomodule.h. So we fix it now by using the non-modular equivalent.
Quoted 6 lines
Cc "Rafael J. Wysocki" <[email protected]>Cc Viresh Kumar <[email protected]>Cc Kukjin Kim <[email protected]>Signed-off-by Paul Gortmaker <[email protected]>
I'm assuming that this will go in via the Samsung tree.
Signature · 2 lines
I speak only for myself. Rafael J. Wysocki, Intel Open Source Technology Center.
Re: [PATCH v2] drivers/cpufreq: Convert non-modular s5pv210-cpufreq.c to use builtin_platform_driver
Quoted 11 lines · Rafael J. Wysocki
Quoted 10 lines · Paul Gortmaker
This file depends on a
Kconfigoption which is a bool, so we use the appropriate registration function, which avoids us relying on an implicit inclusion of <module.h> which we are doing currently.While this currently works, we really don't want to be including the
module.hheader in non-modular code, which we'd be forced to do, pending some upcoming code relocation frominit.hintomodule.h. So we fix it now by using the non-modular equivalent.
Quoted 8 lines
Quoted 6 lines
Cc "Rafael J. Wysocki" <[email protected]>Cc Viresh Kumar <[email protected]>Cc Kukjin Kim <[email protected]>Cc linux-pm at vger.kernel.orgCc linux-arm-kernel at lists.infradead.orgSigned-off-by Paul Gortmaker <[email protected]>I'm assuming that this will go in via the Samsung tree.
Per other patch, I'll have to keep a copy in my branch to avoid introducing bisect compile fails into the git history.
Thanks,
Paul.