mbox series

[00/19] DT header disentangling, part 1

Message ID 20230329-dt-cpu-header-cleanups-v1-0-581e2605fe47@kernel.org
Headers show
Series DT header disentangling, part 1 | expand

Message

Rob Herring (Arm) March 29, 2023, 3:51 p.m. UTC
This is the first of a series of clean-ups to disentangle the DT 
includes. There's a decade plus old comment in of_device.h:

 #include <linux/of_platform.h> /* temporary until merge */

Who's this Grant person that wrote this? ;)

It gets better. of_device.h also pulls in of.h, and of_platform.h 
includes of_device.h. So naturally, drivers include all combinations of 
those 3 headers and sometimes they actually need them. 

I started on fixing this years ago, but just dropping the circular 
includes and fixing all the fallout was massive and didn't sit well. 
Pulling in of_device.h in all the drivers that happen to call only
of_device_get_match_data/of_match_device didn't seem great when the rest 
of of_device.h would never be needed. of_device.h being everything that 
works on a struct device is not a great split because several types of 
users deal with struct device. The better split seems to be by user 
(subsys driver vs. consumer) which several subsystems now do. For 
of_device.h, the users can primarily be split between bus 
implementations and device drivers. Device drivers also typically need 
of.h to read properties. So let's move of_device.h towards just bus 
related functions and move device driver related functions to of.h.

This series is just the first step. It makes a couple of clean-ups to 
replace some includes with forward declarations. It moves 
of_device_get_match_data() and of_cpu_device_node_get() to of.h. The 
former move is transparent for now and preparation for the next series.
The last part of the series updates drivers using 
of_cpu_device_node_get() and/or relying on the implicit cpu.h include 
which is removed in the last patch.

Signed-off-by: Rob Herring <robh@kernel.org>
---
Rob Herring (19):
      of: Make devtree_lock declaration private
      of: Move of_device_(add|register|unregister) to of_platform.h
      of: Move of_device_get_match_data() declaration
      of: Move CPU node related functions to their own file
      of: Drop unnecessary includes in headers
      ARM: sunxi: Drop of_device.h include
      ARM: cpuidle: Drop of_device.h include
      riscv: Add explicit include for cpu.h
      riscv: cacheinfo: Adjust includes to remove of_device.h
      cacheinfo: Adjust includes to remove of_device.h
      clocksource: ingenic: Add explicit include for cpuhotplug.h
      thermal: cpuidle_cooling: Adjust includes to remove of_device.h
      soc: mediatek: mtk-svs: Add explicit include for cpu.h
      cpufreq: Adjust includes to remove of_device.h
      cpufreq: sun50i: Add explicit include for cpu.h
      cpuidle: Adjust includes to remove of_device.h
      irqchip: loongson-eiointc: Add explicit include for cpuhotplug.h
      OPP: Adjust includes to remove of_device.h
      of: Drop cpu.h include from of_device.h

 arch/arm/kernel/cpuidle.c              |   1 -
 arch/arm/mach-sunxi/mc_smp.c           |   1 -
 arch/riscv/kernel/cacheinfo.c          |   1 -
 arch/riscv/kernel/setup.c              |   2 +-
 arch/sparc/include/asm/prom.h          |   3 +
 drivers/base/cacheinfo.c               |   2 +-
 drivers/clocksource/ingenic-timer.c    |   3 +-
 drivers/cpufreq/cpufreq-dt-platdev.c   |   1 -
 drivers/cpufreq/kirkwood-cpufreq.c     |   2 +-
 drivers/cpufreq/maple-cpufreq.c        |   2 +-
 drivers/cpufreq/pmac32-cpufreq.c       |   2 +-
 drivers/cpufreq/pmac64-cpufreq.c       |   2 +-
 drivers/cpufreq/qcom-cpufreq-hw.c      |   4 +-
 drivers/cpufreq/spear-cpufreq.c        |   2 +-
 drivers/cpufreq/sun50i-cpufreq-nvmem.c |   3 +-
 drivers/cpufreq/tegra124-cpufreq.c     |   1 -
 drivers/cpufreq/tegra20-cpufreq.c      |   2 +-
 drivers/cpuidle/cpuidle-psci.c         |   1 -
 drivers/cpuidle/cpuidle-qcom-spm.c     |   3 +-
 drivers/cpuidle/cpuidle-riscv-sbi.c    |   2 +-
 drivers/cpuidle/dt_idle_states.c       |   1 -
 drivers/irqchip/irq-loongson-eiointc.c |   5 +-
 drivers/of/Makefile                    |   2 +-
 drivers/of/base.c                      | 187 -----------------------------
 drivers/of/cpu.c                       | 210 +++++++++++++++++++++++++++++++++
 drivers/of/of_private.h                |   1 +
 drivers/opp/of.c                       |   2 +-
 drivers/soc/mediatek/mtk-svs.c         |   1 +
 drivers/thermal/cpuidle_cooling.c      |   3 +-
 include/linux/cpufreq.h                |   1 -
 include/linux/of.h                     |  28 +++--
 include/linux/of_device.h              |  24 +---
 include/linux/of_platform.h            |  10 +-
 33 files changed, 261 insertions(+), 254 deletions(-)
---
base-commit: fe15c26ee26efa11741a7b632e9f23b01aca4cc6
change-id: 20230329-dt-cpu-header-cleanups-c7bed8c0b352

Best regards,

Comments

Viresh Kumar March 30, 2023, 3:54 a.m. UTC | #1
On 29-03-23, 10:52, Rob Herring wrote:
> Removing the include of cpu.h from of_device.h causes an error:
> 
> drivers/cpufreq/sun50i-cpufreq-nvmem.c:42:19: error: implicit declaration of function ‘get_cpu_device’; did you mean ‘get_device’? [-Werror=implicit-function-declaration]
> 
> As of_device.h is not otherwise needed, it can be replaced with of.h
> (also implicitly included).
> 
> Signed-off-by: Rob Herring <robh@kernel.org>
> ---
> Please ack and I will take the series via the DT tree.
> ---
>  drivers/cpufreq/sun50i-cpufreq-nvmem.c | 3 ++-
>  1 file changed, 2 insertions(+), 1 deletion(-)
> 
> diff --git a/drivers/cpufreq/sun50i-cpufreq-nvmem.c b/drivers/cpufreq/sun50i-cpufreq-nvmem.c
> index 1583a370da39..4321d7bbe769 100644
> --- a/drivers/cpufreq/sun50i-cpufreq-nvmem.c
> +++ b/drivers/cpufreq/sun50i-cpufreq-nvmem.c
> @@ -10,9 +10,10 @@
>  
>  #define pr_fmt(fmt) KBUILD_MODNAME ": " fmt
>  
> +#include <linux/cpu.h>
>  #include <linux/module.h>
>  #include <linux/nvmem-consumer.h>
> -#include <linux/of_device.h>
> +#include <linux/of.h>
>  #include <linux/platform_device.h>
>  #include <linux/pm_opp.h>
>  #include <linux/slab.h>

Acked-by: Viresh Kumar <viresh.kumar@linaro.org>
Anup Patel March 30, 2023, 4:02 a.m. UTC | #2
On Wed, Mar 29, 2023 at 9:22 PM Rob Herring <robh@kernel.org> wrote:
>
> Now that of_cpu_device_node_get() is defined in of.h, of_device.h is just
> implicitly including other includes, and is no longer needed. Adjust the
> include files with what was implicitly included by of_device.h (cpu.h,
> cpuhotplug.h, of.h, and of_platform.h) and drop including of_device.h.
>
> Signed-off-by: Rob Herring <robh@kernel.org>

For cpuidle-riscv-sbi.c
Acked-by: Anup Patel <anup@brainfault.org>

Regards,
Anup

> ---
> Please ack and I will take the series via the DT tree.
> ---
>  drivers/cpuidle/cpuidle-psci.c      | 1 -
>  drivers/cpuidle/cpuidle-qcom-spm.c  | 3 +--
>  drivers/cpuidle/cpuidle-riscv-sbi.c | 2 +-
>  drivers/cpuidle/dt_idle_states.c    | 1 -
>  4 files changed, 2 insertions(+), 5 deletions(-)
>
> diff --git a/drivers/cpuidle/cpuidle-psci.c b/drivers/cpuidle/cpuidle-psci.c
> index 6de027f9f6f5..bf68920d038a 100644
> --- a/drivers/cpuidle/cpuidle-psci.c
> +++ b/drivers/cpuidle/cpuidle-psci.c
> @@ -16,7 +16,6 @@
>  #include <linux/kernel.h>
>  #include <linux/module.h>
>  #include <linux/of.h>
> -#include <linux/of_device.h>
>  #include <linux/platform_device.h>
>  #include <linux/psci.h>
>  #include <linux/pm_domain.h>
> diff --git a/drivers/cpuidle/cpuidle-qcom-spm.c b/drivers/cpuidle/cpuidle-qcom-spm.c
> index c6e2e91bb4c3..1fc9968eae19 100644
> --- a/drivers/cpuidle/cpuidle-qcom-spm.c
> +++ b/drivers/cpuidle/cpuidle-qcom-spm.c
> @@ -11,8 +11,7 @@
>  #include <linux/io.h>
>  #include <linux/slab.h>
>  #include <linux/of.h>
> -#include <linux/of_address.h>
> -#include <linux/of_device.h>
> +#include <linux/of_platform.h>
>  #include <linux/err.h>
>  #include <linux/platform_device.h>
>  #include <linux/cpuidle.h>
> diff --git a/drivers/cpuidle/cpuidle-riscv-sbi.c b/drivers/cpuidle/cpuidle-riscv-sbi.c
> index be383f4b6855..ae0b838a0634 100644
> --- a/drivers/cpuidle/cpuidle-riscv-sbi.c
> +++ b/drivers/cpuidle/cpuidle-riscv-sbi.c
> @@ -8,6 +8,7 @@
>
>  #define pr_fmt(fmt) "cpuidle-riscv-sbi: " fmt
>
> +#include <linux/cpuhotplug.h>
>  #include <linux/cpuidle.h>
>  #include <linux/cpumask.h>
>  #include <linux/cpu_pm.h>
> @@ -15,7 +16,6 @@
>  #include <linux/kernel.h>
>  #include <linux/module.h>
>  #include <linux/of.h>
> -#include <linux/of_device.h>
>  #include <linux/slab.h>
>  #include <linux/platform_device.h>
>  #include <linux/pm_domain.h>
> diff --git a/drivers/cpuidle/dt_idle_states.c b/drivers/cpuidle/dt_idle_states.c
> index 02aa0b39af9d..12fec92a85fd 100644
> --- a/drivers/cpuidle/dt_idle_states.c
> +++ b/drivers/cpuidle/dt_idle_states.c
> @@ -14,7 +14,6 @@
>  #include <linux/kernel.h>
>  #include <linux/module.h>
>  #include <linux/of.h>
> -#include <linux/of_device.h>
>
>  #include "dt_idle_states.h"
>
>
> --
> 2.39.2
>
Daniel Lezcano April 1, 2023, 7:22 p.m. UTC | #3
On 29/03/2023 17:52, Rob Herring wrote:
> Removing include of cpu.h from of_device.h (included by of_platform.h)
> causes an error in ingenic-timer:
> 
> drivers/clocksource/ingenic-timer.c: In function ‘ingenic_tcu_init’:
> drivers/clocksource/ingenic-timer.c:338:15: error: implicit declaration of function ‘cpuhp_setup_state’
> 
> The of_platform.h header is not necessary either, so it and of_address.h
> can be dropped.
> 
> Signed-off-by: Rob Herring <robh@kernel.org>
> ---
> Please ack and I will take the series via the DT tree.
> ---

Acked-by: Daniel Lezcano <daniel.lezcano@linaro.org>