Skip to contentSkip to conversation

ARM: tegra: Unify tegra{20,30,114}_init_early()

PATCH Superseded Hiroshi Doyu 3 participants 14 messages Feb 11, 2013 – Feb 13, 2013

Subsystems (3)

v2 of 3 Superseded Latest is v3 →

lore
Share & tools
lore
#0 lore raw

PATCH v2 1/3 ARM: tegra: Unify tegra{20,30,114}_init_early()

Refactored tegra{20,30,114}_init_early() so that we have the unified tegra_init_early().

---
Update:
Used IS_ENABLED() instead of ifdefs as Arnd/Felipe suggested.

---
 arch/arm/mach-tegra/board-dt-tegra114.c |    2 +-
 arch/arm/mach-tegra/board-dt-tegra20.c  |    2 +-
 arch/arm/mach-tegra/board-dt-tegra30.c  |    4 ++--
 arch/arm/mach-tegra/board.h             |    4 +---
 arch/arm/mach-tegra/common.c            |   26 ++------------------------
 arch/arm/mach-tegra/hotplug.c           |   23 +++++++++--------------
 arch/arm/mach-tegra/sleep.h             |   10 +++++-----
 7 files changed, 21 insertions(+), 50 deletions(-)
arch/arm/mach-tegra/board-dt-tegra114.c +1 -1
index 085d636..08e8294 100644
@@ -36,7 +36,7 @@ static const char * const tegra114_dt_board_compat[] = {
 DT_MACHINE_START(TEGRA114_DT, "NVIDIA Tegra114 (Flattened Device Tree)")
 	.smp		= smp_ops(tegra_smp_ops),
 	.map_io		= tegra_map_common_io,
-	.init_early	= tegra114_init_early,
+	.init_early	= tegra_init_early,
 	.init_irq	= tegra_dt_init_irq,
 	.init_time	= clocksource_of_init,
 	.init_machine	= tegra114_dt_init,
arch/arm/mach-tegra/board-dt-tegra20.c +1 -1
index a0edf25..fca18e9 100644
@@ -145,7 +145,7 @@ static const char *tegra20_dt_board_compat[] = {
 DT_MACHINE_START(TEGRA_DT, "nVidia Tegra20 (Flattened Device Tree)")
 	.map_io		= tegra_map_common_io,
 	.smp		= smp_ops(tegra_smp_ops),
-	.init_early	= tegra20_init_early,
+	.init_early	= tegra_init_early,
 	.init_irq	= tegra_dt_init_irq,
 	.init_time	= clocksource_of_init,
 	.init_machine	= tegra_dt_init,
arch/arm/mach-tegra/board-dt-tegra30.c +2 -2
index bf68567..63f8139 100644
@@ -3,7 +3,7 @@
  *
  * NVIDIA Tegra30 device tree board support
  *
- * Copyright (C) 2011 NVIDIA Corporation
+ * Copyright (C) 2011, 2013, NVIDIA Corporation
  *
  * Derived from:
  *
@@ -50,7 +50,7 @@ static const char *tegra30_dt_board_compat[] = {
 DT_MACHINE_START(TEGRA30_DT, "NVIDIA Tegra30 (Flattened Device Tree)")
 	.smp		= smp_ops(tegra_smp_ops),
 	.map_io		= tegra_map_common_io,
-	.init_early	= tegra30_init_early,
+	.init_early	= tegra_init_early,
 	.init_irq	= tegra_dt_init_irq,
 	.init_time	= clocksource_of_init,
 	.init_machine	= tegra30_dt_init,
arch/arm/mach-tegra/board.h +1 -3
index 86851c8..60431de 100644
@@ -26,9 +26,7 @@
 
 void tegra_assert_system_reset(char mode, const char *cmd);
 
-void __init tegra20_init_early(void);
-void __init tegra30_init_early(void);
-void __init tegra114_init_early(void);
+void __init tegra_init_early(void);
 void __init tegra_map_common_io(void);
 void __init tegra_init_irq(void);
 void __init tegra_dt_init_irq(void);
arch/arm/mach-tegra/common.c +2 -24
index 5449a3f..f0315c9 100644
@@ -94,7 +94,7 @@ static void __init tegra_init_cache(void)
 
 }
 
-static void __init tegra_init_early(void)
+void __init tegra_init_early(void)
 {
 	tegra_cpu_reset_handler_init();
 	tegra_apb_io_init();
@@ -102,31 +102,9 @@ static void __init tegra_init_early(void)
 	tegra_init_cache();
 	tegra_pmc_init();
 	tegra_powergate_init();
+	tegra_hotplug_init();
 }
 
-#ifdef CONFIG_ARCH_TEGRA_2x_SOC
-void __init tegra20_init_early(void)
-{
-	tegra_init_early();
-	tegra20_hotplug_init();
-}
-#endif
-
-#ifdef CONFIG_ARCH_TEGRA_3x_SOC
-void __init tegra30_init_early(void)
-{
-	tegra_init_early();
-	tegra30_hotplug_init();
-}
-#endif
-
-#ifdef CONFIG_ARCH_TEGRA_114_SOC
-void __init tegra114_init_early(void)
-{
-	tegra_init_early();
-}
-#endif
-
 void __init tegra_init_late(void)
 {
 	tegra_powergate_debugfs_init();
arch/arm/mach-tegra/hotplug.c +9 -14
index a599f6e..8da9f78 100644
@@ -1,8 +1,7 @@
 /*
- *
  *  Copyright (C) 2002 ARM Ltd.
  *  All Rights Reserved
- *  Copyright (c) 2010, 2012 NVIDIA Corporation. All rights reserved.
+ *  Copyright (c) 2010, 2012-2013, NVIDIA Corporation. All rights reserved.
  *
  * This program is free software; you can redistribute it and/or modify
  * it under the terms of the GNU General Public License version 2 as
@@ -15,6 +14,7 @@
 #include <asm/cacheflush.h>
 #include <asm/smp_plat.h>
 
+#include "fuse.h"
 #include "sleep.h"
 
 static void (*tegra_hotplug_shutdown)(void);
@@ -56,18 +56,13 @@ int tegra_cpu_disable(unsigned int cpu)
 	return cpu == 0 ? -EPERM : 0;
 }
 
-#ifdef CONFIG_ARCH_TEGRA_2x_SOC
-extern void tegra20_hotplug_shutdown(void);
-void __init tegra20_hotplug_init(void)
+void __init tegra_hotplug_init(void)
 {
-	tegra_hotplug_shutdown = tegra20_hotplug_shutdown;
-}
-#endif
+	if (!IS_ENABLED(CONFIG_HOTPLUG_CPU))
+		return;
 
-#ifdef CONFIG_ARCH_TEGRA_3x_SOC
-extern void tegra30_hotplug_shutdown(void);
-void __init tegra30_hotplug_init(void)
-{
-	tegra_hotplug_shutdown = tegra30_hotplug_shutdown;
+	if (IS_ENABLED(CONFIG_ARCH_TEGRA_2x_SOC) && tegra_chip_id == TEGRA20)
+		tegra_hotplug_shutdown = tegra20_hotplug_shutdown;
+	if (IS_ENABLED(CONFIG_ARCH_TEGRA_3x_SOC) && tegra_chip_id == TEGRA30)
+		tegra_hotplug_shutdown = tegra30_hotplug_shutdown;
 }
-#endif
arch/arm/mach-tegra/sleep.h +5 -5
index 4ffae54..970ebd5 100644
@@ -1,5 +1,5 @@
 /*
- * Copyright (c) 2010-2012, NVIDIA Corporation. All rights reserved.
+ * Copyright (c) 2010-2013, NVIDIA Corporation. All rights reserved.
  *
  * This program is free software; you can redistribute it and/or modify it
  * under the terms and conditions of the GNU General Public License,
@@ -124,11 +124,11 @@ int tegra_sleep_cpu_finish(unsigned long);
 void tegra_disable_clean_inv_dcache(void);
 
 #ifdef CONFIG_HOTPLUG_CPU
-void tegra20_hotplug_init(void);
-void tegra30_hotplug_init(void);
+void tegra20_hotplug_shutdown(void);
+void tegra30_hotplug_shutdown(void);
+void tegra_hotplug_init(void);
 #else
-static inline void tegra20_hotplug_init(void) {}
-static inline void tegra30_hotplug_init(void) {}
+static inline void tegra_hotplug_init(void) {}
 #endif
 
 void tegra20_cpu_shutdown(int cpu);
Signature · 1 line
1.7.9.5
#1 lore raw

PATCH v2 2/3 ARM: tegra: Rename board-dt-tegra20.c to tegra.c

This is the preparation to unify "board-dt-tegra{20,30,114}.c" to a single file "tegra.c".

---
 arch/arm/mach-tegra/Makefile                       |    2 +-
 .../arm/mach-tegra/{board-dt-tegra20.c => tegra.c} |    0
 2 files changed, 1 insertion(+), 1 deletion(-)
 rename arch/arm/mach-tegra/{board-dt-tegra20.c => tegra.c} (100%)
arch/arm/mach-tegra/Makefile +1 -1
index f6b46ae..c6d6be2 100644
@@ -27,7 +27,7 @@ obj-$(CONFIG_HOTPLUG_CPU)               += hotplug.o
 obj-$(CONFIG_CPU_FREQ)                  += cpu-tegra.o
 obj-$(CONFIG_TEGRA_PCI)			+= pcie.o
 
-obj-$(CONFIG_ARCH_TEGRA_2x_SOC)		+= board-dt-tegra20.o
+obj-$(CONFIG_ARCH_TEGRA_2x_SOC)		+= tegra.o
 obj-$(CONFIG_ARCH_TEGRA_3x_SOC)		+= board-dt-tegra30.o
 obj-$(CONFIG_ARCH_TEGRA_114_SOC)	+= board-dt-tegra114.o
 ifeq ($(CONFIG_CPU_IDLE),y)
arch/arm/mach-tegra/tegra.c renamed from arch/arm/mach-tegra/board-dt-tegra20.c +0 -0
similarity index 100%
rename from arch/arm/mach-tegra/board-dt-tegra20.c
rename to arch/arm/mach-tegra/tegra.c
Signature · 1 line
1.7.9.5
#2 lore raw

PATCH v2 3/3 ARM: tegra: Unify Device tree board files

In reply to Hiroshi Doyu

Unify board-dt-tegra{30,114} to the Tegra20 DT board file, "tegra.c".

---
 arch/arm/mach-tegra/Makefile            |    5 ++-
 arch/arm/mach-tegra/board-dt-tegra114.c |   46 ------------------------
 arch/arm/mach-tegra/board-dt-tegra30.c  |   60 -------------------------------
 arch/arm/mach-tegra/tegra.c             |   24 +++++++------
 4 files changed, 16 insertions(+), 119 deletions(-)
 delete mode 100644 arch/arm/mach-tegra/board-dt-tegra114.c
 delete mode 100644 arch/arm/mach-tegra/board-dt-tegra30.c
arch/arm/mach-tegra/Makefile +2 -3
index c6d6be2..ee866337 100644
@@ -27,9 +27,8 @@ obj-$(CONFIG_HOTPLUG_CPU)               += hotplug.o
 obj-$(CONFIG_CPU_FREQ)                  += cpu-tegra.o
 obj-$(CONFIG_TEGRA_PCI)			+= pcie.o
 
-obj-$(CONFIG_ARCH_TEGRA_2x_SOC)		+= tegra.o
-obj-$(CONFIG_ARCH_TEGRA_3x_SOC)		+= board-dt-tegra30.o
-obj-$(CONFIG_ARCH_TEGRA_114_SOC)	+= board-dt-tegra114.o
+obj-y					+= tegra.o
+
 ifeq ($(CONFIG_CPU_IDLE),y)
 obj-$(CONFIG_ARCH_TEGRA_114_SOC)	+= cpuidle-tegra114.o
 endif
arch/arm/mach-tegra/board-dt-tegra114.c deleted +0 -46

46 lines not on this page · raw message

arch/arm/mach-tegra/board-dt-tegra30.c deleted +0 -60

60 lines not on this page · raw message

arch/arm/mach-tegra/tegra.c +14 -10
index fca18e9..00debef 100644
@@ -1,6 +1,7 @@
 /*
- * nVidia Tegra device tree board support
+ * NVIDIA Tegra SoC device tree board support
  *
+ * Copyright (C) 2011, 2013, NVIDIA Corporation
  * Copyright (C) 2010 Secret Lab Technologies, Ltd.
  * Copyright (C) 2010 Google, Inc.
  *
@@ -67,13 +68,15 @@ static struct tegra_ehci_platform_data tegra_ehci3_pdata = {
 	.vbus_gpio = -1,
 };
 
-static struct of_dev_auxdata tegra20_auxdata_lookup[] __initdata = {
+static struct of_dev_auxdata tegra_auxdata_lookup[] __initdata = {
+#ifdef CONFIG_ARCH_TEGRA_2x_SOC
 	OF_DEV_AUXDATA("nvidia,tegra20-ehci", 0xC5000000, "tegra-ehci.0",
 		       &tegra_ehci1_pdata),
 	OF_DEV_AUXDATA("nvidia,tegra20-ehci", 0xC5004000, "tegra-ehci.1",
 		       &tegra_ehci2_pdata),
 	OF_DEV_AUXDATA("nvidia,tegra20-ehci", 0xC5008000, "tegra-ehci.2",
 		       &tegra_ehci3_pdata),
+#endif
 	{}
 };
 
@@ -84,29 +87,25 @@ static void __init tegra_dt_init(void)
 	 * devices
 	 */
 	of_platform_populate(NULL, of_default_bus_match_table,
-				tegra20_auxdata_lookup, NULL);
+				tegra_auxdata_lookup, NULL);
 }
 
 static void __init trimslice_init(void)
 {
-#ifdef CONFIG_TEGRA_PCI
 	int ret;
 
 	ret = tegra_pcie_init(true, true);
 	if (ret)
 		pr_err("tegra_pci_init() failed: %d\n", ret);
-#endif
 }
 
 static void __init harmony_init(void)
 {
-#ifdef CONFIG_TEGRA_PCI
 	int ret;
 
 	ret = harmony_pcie_init();
 	if (ret)
 		pr_err("harmony_pcie_init() failed: %d\n", ret);
-#endif
 }
 
 static void __init paz00_init(void)
@@ -129,6 +128,9 @@ static void __init tegra_dt_init_late(void)
 
 	tegra_init_late();
 
+	if (IS_ENABLED(CONFIG_PCI) && IS_ENABLED(CONFIG_ARCH_TEGRA_2x_SOC))
+		return;
+
 	for (i = 0; i < ARRAY_SIZE(board_init_funcs); i++) {
 		if (of_machine_is_compatible(board_init_funcs[i].machine)) {
 			board_init_funcs[i].init();
@@ -137,12 +139,14 @@ static void __init tegra_dt_init_late(void)
 	}
 }
 
-static const char *tegra20_dt_board_compat[] = {
+static const char * const tegra_dt_board_compat[] = {
 	"nvidia,tegra20",
+	"nvidia,tegra30",
+	"nvidia,tegra114",
 	NULL
 };
 
-DT_MACHINE_START(TEGRA_DT, "nVidia Tegra20 (Flattened Device Tree)")
+DT_MACHINE_START(TEGRA_DT, "NVIDIA Tegra SoC (Flattened Device Tree)")
 	.map_io		= tegra_map_common_io,
 	.smp		= smp_ops(tegra_smp_ops),
 	.init_early	= tegra_init_early,
@@ -151,5 +155,5 @@ DT_MACHINE_START(TEGRA_DT, "nVidia Tegra20 (Flattened Device Tree)")
 	.init_machine	= tegra_dt_init,
 	.init_late	= tegra_dt_init_late,
 	.restart	= tegra_assert_system_reset,
-	.dt_compat	= tegra20_dt_board_compat,
+	.dt_compat	= tegra_dt_board_compat,
 MACHINE_END
Signature · 1 line
1.7.9.5
#3 lore raw

Re: [v2 3/3] ARM: tegra: Unify Device tree board files

arch/arm/mach-tegra/Makefile obj-$(CONFIG_HOTPLUG_CPU) += hotplug.o · line 31

Quoted 12 lines · Hiroshi Doyu

Unify board-dt-tegra{30,114} to the Tegra20 DT board file, "tegra.c".

arch/arm/mach-tegra/Makefile +2 -3
 
 obj-$(CONFIG_CPU_FREQ)                  += cpu-tegra.o
 obj-$(CONFIG_TEGRA_PCI)			+= pcie.o
 
-obj-$(CONFIG_ARCH_TEGRA_2x_SOC)		+= tegra.o
-obj-$(CONFIG_ARCH_TEGRA_3x_SOC)		+= board-dt-tegra30.o
-obj-$(CONFIG_ARCH_TEGRA_114_SOC)	+= board-dt-tegra114.o
+obj-y					+= tegra.o
+

I think I'd be tempted to move that line together with all the others that don't depend on some config option.

Quoted 4 lines
arch/arm/mach-tegra/tegra.c +1 -1
 
-static struct of_dev_auxdata tegra20_auxdata_lookup[] __initdata = {
+static struct of_dev_auxdata tegra_auxdata_lookup[] __initdata = {

arch/arm/mach-tegra/tegra.c static struct tegra_ehci_platform_data tegra_ehci3_pdata = { · line 81

Quoted 10 lines
arch/arm/mach-tegra/tegra.c +2 -0
+#ifdef CONFIG_ARCH_TEGRA_2x_SOC
 	OF_DEV_AUXDATA("nvidia,tegra20-ehci", 0xC5000000, "tegra-ehci.0",
 		       &tegra_ehci1_pdata),
 	OF_DEV_AUXDATA("nvidia,tegra20-ehci", 0xC5004000, "tegra-ehci.1",
 		       &tegra_ehci2_pdata),
 	OF_DEV_AUXDATA("nvidia,tegra20-ehci", 0xC5008000, "tegra-ehci.2",
 		       &tegra_ehci3_pdata),
+#endif
 	{}
 };

Why ifdef? This is certainly small enough that it shouldn't matter for any Tegra30- or Tegra114-kernel, and it's hopefully going away very soon, so I'd prefer to drop the addition of the ifdefs to avoid any conflicts with any other changes to that table.

Quoted 11 lines

static void __init trimslice_init(void)
{

arch/arm/mach-tegra/tegra.c +0 -2
-#ifdef CONFIG_TEGRA_PCI
 	int ret;
 
 	ret = tegra_pcie_init(true, true);
 	if (ret)
 		pr_err("tegra_pci_init() failed: %d\n", ret);
-#endif
 }
 

arch/arm/mach-tegra/tegra.c static void __init tegra_dt_init(void) · line 109

Quoted 10 lines
arch/arm/mach-tegra/tegra.c +0 -2
 static void __init harmony_init(void)
 {
-#ifdef CONFIG_TEGRA_PCI
 	int ret;
 
 	ret = harmony_pcie_init();
 	if (ret)
 		pr_err("harmony_pcie_init() failed: %d\n", ret);
-#endif
 }

Why drop those ifdefs? Does the code still compile (link) if built for Tegra30-only or Tegra114-only, where the Tegra PCI driver won't be enabled, and hence those functions don't exist?

arch/arm/mach-tegra/tegra.c static void __init tegra_dt_init_late(void) · line 132

Quoted 7 lines

static void __init paz00_init(void)

arch/arm/mach-tegra/tegra.c +2 -0
@@ -129,6 +128,9 @@ static void __init tegra_dt_init_late(void)
 
 	tegra_init_late();
 
+	if (IS_ENABLED(CONFIG_PCI) && IS_ENABLED(CONFIG_ARCH_TEGRA_2x_SOC))
+		return;

I don't think that's going to help any link issues, so I'd drop it and keep this function simple. After all, what if someone wants to add some non-PCI-related entry into board_init_funcs[]?

arch/arm/mach-tegra/tegra.c static void __init tegra_dt_init_late(void) · line 147

Quoted 7 lines
arch/arm/mach-tegra/tegra.c +3 -1
-static const char *tegra20_dt_board_compat[] = {
+static const char * const tegra_dt_board_compat[] = {
 	"nvidia,tegra20",
+	"nvidia,tegra30",
+	"nvidia,tegra114",
 	NULL
 };

It'd be best to add the newer values first. It shouldn't matter, but currently does at least for device compatible matching, so we may as well be consistent here.

#4 lore raw

Re: [v2 3/3] ARM: tegra: Unify Device tree board files

Stephen Warren <[email protected]> wrote @ Tue, 12 Feb 2013 00:54:03 +0100:

Quoted 8 lines

arch/arm/mach-tegra/Makefile obj-$(CONFIG_HOTPLUG_CPU) += hotplug.o · line 31

Quoted 5 lines
arch/arm/mach-tegra/Makefile +2 -3
-obj-$(CONFIG_ARCH_TEGRA_2x_SOC)		+= tegra.o
-obj-$(CONFIG_ARCH_TEGRA_3x_SOC)		+= board-dt-tegra30.o
-obj-$(CONFIG_ARCH_TEGRA_114_SOC)	+= board-dt-tegra114.o
+obj-y					+= tegra.o
+

I think I'd be tempted to move that line together with all the others that don't depend on some config option.

In arch/arm/mach-tegra/Makefile, we have:

obj-y                                   += common.o
obj-y                                   += io.o
obj-y                                   += irq.o

obj-y += fuse.o
obj-y += pmc.o
.....

Should we have a single entry for them as well?

obj-y:= common.o io.o irq.o fuse.o pmc.o flowctrl.o powergate.o apbio.o pm.o \
reset.o reset-handler.o sleep.o tegra.o

I think that this moval could be done another patch.

Quoted 5 lines
Quoted 5 lines

static void __init harmony_init(void)
{

(quoted diff) +0 -1
-#ifdef CONFIG_TEGRA_PCI
 	int ret;
Quoted 9 lines

arch/arm/mach-tegra/tegra.c static void __init tegra_dt_init(void) · line 109

Quoted 5 lines
arch/arm/mach-tegra/tegra.c +0 -1
 	ret = harmony_pcie_init();
 	if (ret)
 		pr_err("harmony_pcie_init() failed: %d\n", ret);
-#endif
 }

Why drop those ifdefs? Does the code still compile (link) if built for Tegra30-only or Tegra114-only, where the Tegra PCI driver won't be enabled, and hence those functions don't exist?

This function itself will be dropped by the following IS_ENABLED().

Quoted 10 lines

arch/arm/mach-tegra/tegra.c static void __init tegra_dt_init_late(void) · line 132

Quoted 7 lines

static void __init paz00_init(void)

arch/arm/mach-tegra/tegra.c +2 -0
@@ -129,6 +128,9 @@ static void __init tegra_dt_init_late(void)
 
 	tegra_init_late();
 
+	if (IS_ENABLED(CONFIG_PCI) && IS_ENABLED(CONFIG_ARCH_TEGRA_2x_SOC))
+		return;

I don't think that's going to help any link issues, so I'd drop it and keep this function simple.

As explained in the above, a complier will drop unnecessary functions automatically with this IS_ENABLED(), which could save many ifdefs.

Quoted 2 lines

After all, what if someone wants to add some
non-PCI-related entry into board_init_funcs[]?

I originally thought that one should try to solve those board specific problems with DT basically and this tegra specific board_init_funcs[] was left only for the legacy support during DT transition.

#5 lore raw

Re: [v2 3/3] ARM: tegra: Unify Device tree board files

Quoted 20 lines · Hiroshi Doyu

Stephen Warren <[email protected]> wrote @ Tue, 12 Feb 2013 00:54:03 +0100:

Quoted 8 lines

arch/arm/mach-tegra/Makefile obj-$(CONFIG_HOTPLUG_CPU) += hotplug.o · line 31

Quoted 5 lines
arch/arm/mach-tegra/Makefile +2 -3
-obj-$(CONFIG_ARCH_TEGRA_2x_SOC)		+= tegra.o
-obj-$(CONFIG_ARCH_TEGRA_3x_SOC)		+= board-dt-tegra30.o
-obj-$(CONFIG_ARCH_TEGRA_114_SOC)	+= board-dt-tegra114.o
+obj-y					+= tegra.o
+

I think I'd be tempted to move that line together with all the others that don't depend on some config option.

In arch/arm/mach-tegra/Makefile, we have:

obj-y                                   += common.o
obj-y                                   += io.o
obj-y                                   += irq.o

obj-y += fuse.o
obj-y += pmc.o
.....

Quoted 6 lines

Should we have a single entry for them as well?

obj-y:= common.o io.o irq.o fuse.o pmc.o flowctrl.o powergate.o apbio.o pm.o \
reset.o reset-handler.o sleep.o tegra.o

I think that this moval could be done another patch.

I just meant put the lines next to each-other. We definitely shouldn't merge the lines together or it'll make it more painful to change the list of files later.

Quoted 22 lines
Quoted 5 lines
Quoted 5 lines

static void __init harmony_init(void)
{

(quoted diff) +0 -1
-#ifdef CONFIG_TEGRA_PCI
 	int ret;
Quoted 9 lines

arch/arm/mach-tegra/tegra.c static void __init tegra_dt_init(void) · line 109

Quoted 5 lines
arch/arm/mach-tegra/tegra.c +0 -1
 	ret = harmony_pcie_init();
 	if (ret)
 		pr_err("harmony_pcie_init() failed: %d\n", ret);
-#endif
 }

Why drop those ifdefs? Does the code still compile (link) if built for Tegra30-only or Tegra114-only, where the Tegra PCI driver won't be enabled, and hence those functions don't exist?

This function itself will be dropped by the following IS_ENABLED().

Quoted 5 lines
Quoted 5 lines

static void __init paz00_init(void)

arch/arm/mach-tegra/tegra.c +0 -0
@@ -129,6 +128,9 @@ static void __init tegra_dt_init_late(void)
 
 	tegra_init_late();
 
Quoted 8 lines
Quoted 5 lines

arch/arm/mach-tegra/tegra.c static void __init tegra_dt_init_late(void) · line 132

Quoted 2 lines
arch/arm/mach-tegra/tegra.c +2 -0
+	if (IS_ENABLED(CONFIG_PCI) && IS_ENABLED(CONFIG_ARCH_TEGRA_2x_SOC))
+		return;

I don't think that's going to help any link issues, so I'd drop it and keep this function simple.

As explained in the above, a complier will drop unnecessary functions automatically with this IS_ENABLED(), which could save many ifdefs.

That sounds extremely brittle. Have you validated this on a wide variety of compiler versions?

Quoted 6 lines
Quoted 2 lines

After all, what if someone wants to add some
non-PCI-related entry into board_init_funcs[]?

I originally thought that one should try to solve those board specific problems with DT basically and this tegra specific board_init_funcs[] was left only for the legacy support during DT transition.

That's the intent right now, but who knows what else might end up getting added there. It seems simplest just to maintain the ifdefs since they're already there.

#6 lore raw

Re: [v2 3/3] ARM: tegra: Unify Device tree board files

Stephen Warren <[email protected]> wrote @ Tue, 12 Feb 2013 05:47:20 +0100:

Quoted 28 lines
Quoted 28 lines
Quoted 5 lines
Quoted 5 lines

static void __init harmony_init(void)
{

(quoted diff) +0 -1
-#ifdef CONFIG_TEGRA_PCI
 	int ret;
Quoted 9 lines

arch/arm/mach-tegra/tegra.c static void __init tegra_dt_init(void) · line 109

Quoted 5 lines
arch/arm/mach-tegra/tegra.c +0 -1
 	ret = harmony_pcie_init();
 	if (ret)
 		pr_err("harmony_pcie_init() failed: %d\n", ret);
-#endif
 }

Why drop those ifdefs? Does the code still compile (link) if built for Tegra30-only or Tegra114-only, where the Tegra PCI driver won't be enabled, and hence those functions don't exist?

This function itself will be dropped by the following IS_ENABLED().

Quoted 10 lines

arch/arm/mach-tegra/tegra.c static void __init tegra_dt_init_late(void) · line 132

Quoted 7 lines

static void __init paz00_init(void)

arch/arm/mach-tegra/tegra.c +2 -0
@@ -129,6 +128,9 @@ static void __init tegra_dt_init_late(void)
 
 	tegra_init_late();
 
+	if (IS_ENABLED(CONFIG_PCI) && IS_ENABLED(CONFIG_ARCH_TEGRA_2x_SOC))
+		return;

I don't think that's going to help any link issues, so I'd drop it and keep this function simple.

Quoted 5 lines
Quoted 2 lines

As explained in the above, a complier will drop unnecessary functions automatically with this IS_ENABLED(), which could save many ifdefs.

That sounds extremely brittle. Have you validated this on a wide variety of compiler versions?

I verified with gcc-4.6.
IIRC, that's the point of IS_ENABLED() being introduced. Arnd?

#7 lore raw

Re: [v2 3/3] ARM: tegra: Unify Device tree board files

Quoted 11 lines · Hiroshi Doyu
Quoted 11 lines
Quoted 11 lines
Quoted 10 lines

arch/arm/mach-tegra/tegra.c static void __init tegra_dt_init_late(void) · line 132

Quoted 7 lines

static void __init paz00_init(void)

arch/arm/mach-tegra/tegra.c +2 -0
@@ -129,6 +128,9 @@ static void __init tegra_dt_init_late(void)
 
  tegra_init_late();
 
+ if (IS_ENABLED(CONFIG_PCI) && IS_ENABLED(CONFIG_ARCH_TEGRA_2x_SOC))
+         return;

I don't think that's going to help any link issues, so I'd drop it and keep this function simple.

Quoted 8 lines
Quoted 5 lines
Quoted 2 lines

As explained in the above, a complier will drop unnecessary functions automatically with this IS_ENABLED(), which could save many ifdefs.

That sounds extremely brittle. Have you validated this on a wide variety of compiler versions?

I verified with gcc-4.6.
IIRC, that's the point of IS_ENABLED() being introduced. Arnd?

It's certainly expected to work with all compilers, yes. If a compiler cannot remove conditional function calls that depend on a constant expression, we have a lot of other problems alredy.

However, from what I see above, you have the logic reversed (it should return if neither TEGRA_2x nor PCI are enabled, rather than return if one of them is enabled). and it becomes a little confusing to read.

If you want to get rid of the #ifdef here, I would suggest you put those into the functions directly, like

static void __init harmony_init(void)

{
        int ret = 0;

        if (IS_ENABLED(CONFIG_PCI) && IS_ENABLED(CONFIG_ARCH_TEGRA_2x_SOC))
		ret = harmony_pcie_init();
        if (ret)
                pr_err("harmony_pcie_init() failed: %d\n", ret);
}

which will turn into an empty function if one of the two is disabled.

Since we are not going to add any other board specfic init functions, you can also unroll the loop and put everything into tegra_dt_init_late:

/* Board specific fixups, try not add any new ones here */ static void __init tegra_dt_init_late(void)

{
	tegra_powergate_debugfs_init();

	/* so far, these all apply only to tegra2x */
	if (!IS_ENABLED(CONFIG_ARCH_TEGRA_2x_SOC))
		return;

	if (of_machine_is_compatible("compal,paz00"))
		tegra_paz00_wifikill_init();
	if (IS_ENABLED(CONFIG_PCI) && of_machine_is_compatible("nvidia,harmony")
		harmony_pcie_init();
	if (IS_ENABLED(CONFIG_PCI) && of_machine_is_compatible("compulab,trimslice")
		tegra_pcie_init(true, true);
}

Arnd

#8 lore raw

Re: [v2 3/3] ARM: tegra: Unify Device tree board files

Quoted 18 lines · Arnd Bergmann
Quoted 17 lines · Hiroshi Doyu
Quoted 16 lines
Quoted 5 lines
Quoted 5 lines
Quoted 5 lines

static void __init paz00_init(void)

arch/arm/mach-tegra/tegra.c +0 -0
@@ -129,6 +128,9 @@ static void __init tegra_dt_init_late(void)
 
  tegra_init_late();
 
Quoted 8 lines
Quoted 5 lines

arch/arm/mach-tegra/tegra.c static void __init tegra_dt_init_late(void) · line 132

Quoted 2 lines
arch/arm/mach-tegra/tegra.c +2 -0
+ if (IS_ENABLED(CONFIG_PCI) && IS_ENABLED(CONFIG_ARCH_TEGRA_2x_SOC))
+         return;

I don't think that's going to help any link issues, so I'd drop it and keep this function simple.

As explained in the above, a complier will drop unnecessary functions automatically with this IS_ENABLED(), which could save many ifdefs.

That sounds extremely brittle. Have you validated this on a wide variety of compiler versions?

Quoted 6 lines
Quoted 2 lines

I verified with gcc-4.6.
IIRC, that's the point of IS_ENABLED() being introduced. Arnd?

It's certainly expected to work with all compilers, yes. If a compiler cannot remove conditional function calls that depend on a constant expression, we have a lot of other problems alredy.

Removing the function calls isn't guaranteed to remove the body of the functions though. Those functions aren't implemented in some separate file that's optionally included, but rather are implemented in the same object file, now unconditionally, and they in turn reference (with no IS_ENABLED logic) other functions that are implemented in conditionally linked files.

Quoted 18 lines

However, from what I see above, you have the logic reversed (it should return if neither TEGRA_2x nor PCI are enabled, rather than return if one of them is enabled). and it becomes a little confusing to read.

If you want to get rid of the #ifdef here, I would suggest you put those into the functions directly, like

static void __init harmony_init(void)

{
        int ret = 0;

        if (IS_ENABLED(CONFIG_PCI) && IS_ENABLED(CONFIG_ARCH_TEGRA_2x_SOC))
		ret = harmony_pcie_init();
        if (ret)
                pr_err("harmony_pcie_init() failed: %d\n", ret);
}
Quoted 1 line

which will turn into an empty function if one of the two is disabled.

That would work.

However I'd like to avoid changing the body of those two functions at all if possible, since I hope the PCIe driver rework will be merged in 3.10, and that will allow the Harmony and TrimSlice init functions to be removed entirely. I'd rather not have conflicts with the removal patch.

Quoted 2 lines

Since we are not going to add any other board specfic init functions, you can also unroll the loop and put everything into tegra_dt_init_late:

That's not necessarily true. While we certainly don't plan to, I don't think we can rule it out; after all, we don't have rfkill bindings and yet other boards will need them.

#9 lore raw

Re: [v2 3/3] ARM: tegra: Unify Device tree board files

Quoted 16 lines · Stephen Warren
Quoted 9 lines
Quoted 9 lines
Quoted 8 lines
Quoted 5 lines
Quoted 2 lines

I don't think that's going to help any link issues, so I'd drop it and keep this function simple.

As explained in the above, a complier will drop unnecessary functions automatically with this IS_ENABLED(), which could save many ifdefs.

That sounds extremely brittle. Have you validated this on a wide variety of compiler versions?

Quoted 6 lines
Quoted 2 lines

I verified with gcc-4.6.
IIRC, that's the point of IS_ENABLED() being introduced. Arnd?

It's certainly expected to work with all compilers, yes. If a compiler cannot remove conditional function calls that depend on a constant expression, we have a lot of other problems alredy.

Quoted 6 lines

Removing the function calls isn't guaranteed to remove the body of the functions though. Those functions aren't implemented in some separate file that's optionally included, but rather are implemented in the same object file, now unconditionally, and they in turn reference (with no IS_ENABLED logic) other functions that are implemented in conditionally linked files.

I think gcc should remove all of that in this case, since board_init_funcs becomes unused when the only code that references it cannot be reached, and when that array is gone, the now unused functions would be removed as well.

We have had bugs with prerelease gcc versions that did not handle cases like this in the way we want it, but I think all releases get it right. I don't think it's mandated anywhere in the C99 standard that this is what happens, but we do rely on it anyway AFAIK.

Quoted 10 lines
Quoted 10 lines

static void __init harmony_init(void)

{
        int ret = 0;

        if (IS_ENABLED(CONFIG_PCI) && IS_ENABLED(CONFIG_ARCH_TEGRA_2x_SOC))
              ret = harmony_pcie_init();
        if (ret)
                pr_err("harmony_pcie_init() failed: %d\n", ret);
}
Quoted 8 lines
Quoted 1 line

which will turn into an empty function if one of the two is disabled.

That would work.

However I'd like to avoid changing the body of those two functions at all if possible, since I hope the PCIe driver rework will be merged in 3.10, and that will allow the Harmony and TrimSlice init functions to be removed entirely. I'd rather not have conflicts with the removal patch.

Yes, makes sense.

Quoted 6 lines
Quoted 2 lines

Since we are not going to add any other board specfic init functions, you can also unroll the loop and put everything into tegra_dt_init_late:

That's not necessarily true. While we certainly don't plan to, I don't think we can rule it out; after all, we don't have rfkill bindings and yet other boards will need them.

Ok.

Arnd

#10 lore raw

Re: [v2 3/3] ARM: tegra: Unify Device tree board files

Quoted 29 lines · Arnd Bergmann
Quoted 16 lines · Stephen Warren
Quoted 9 lines
Quoted 9 lines
Quoted 8 lines
Quoted 5 lines
Quoted 2 lines

I don't think that's going to help any link issues, so I'd drop it and keep this function simple.

As explained in the above, a complier will drop unnecessary functions automatically with this IS_ENABLED(), which could save many ifdefs.

That sounds extremely brittle. Have you validated this on a wide variety of compiler versions?

Quoted 6 lines
Quoted 2 lines

I verified with gcc-4.6.
IIRC, that's the point of IS_ENABLED() being introduced. Arnd?

It's certainly expected to work with all compilers, yes. If a compiler cannot remove conditional function calls that depend on a constant expression, we have a lot of other problems alredy.

Quoted 6 lines

Removing the function calls isn't guaranteed to remove the body of the functions though. Those functions aren't implemented in some separate file that's optionally included, but rather are implemented in the same object file, now unconditionally, and they in turn reference (with no IS_ENABLED logic) other functions that are implemented in conditionally linked files.

I think gcc should remove all of that in this case, since board_init_funcs becomes unused when the only code that references it cannot be reached, and when that array is gone, the now unused functions would be removed as well.

Quoted 4 lines

We have had bugs with prerelease gcc versions that did not handle cases like this in the way we want it, but I think all releases get it right. I don't think it's mandated anywhere in the C99 standard that this is what happens, but we do rely on it anyway AFAIK.

Hmmm. Very surprisingly (to me), this does indeed work fine, even with an older gcc-4.4.1 I had lying around (after fixing the test inversion in tegra_dt_init_late).

I believe U-Boot enabled -ffunction-sections -fdata-sections or similar (recently?) to get this kind of behaviour. I wonder why the kernel didn't need that. Perhaps -O2 is more aggressive (within a file at least) than I thought.

I did note a few warnings due to the ifdefs in tegra_auxdata_lookup[]:

arch/arm/mach-tegra/tegra.c:47: warning: 'tegra_ehci1_pdata' defined but not used
arch/arm/mach-tegra/tegra.c:58: warning: 'tegra_ehci2_pdata' defined but not used
arch/arm/mach-tegra/tegra.c:65: warning: 'tegra_ehci3_pdata' defined but not used

(I built a tegra_defconfig kernel and modified it to enable Tegra30+Tegra114, disable Tegra20, disable DRM)

#11 lore raw

Re: [v2 3/3] ARM: tegra: Unify Device tree board files

Quoted 4 lines · Stephen Warren

I believe U-Boot enabled -ffunction-sections -fdata-sections or similar (recently?) to get this kind of behaviour. I wonder why the kernel didn't need that. Perhaps -O2 is more aggressive (within a file at least) than I thought.

-ffunction-sections works across files, while the trick I described only works on file static symbols. David Woodhouse at some point had a working kernel build with -ffunction-sections but for some reason that never got merged.

Arnd

#12 lore raw

Re: [v2 3/3] ARM: tegra: Unify Device tree board files

In reply to Stephen Warren

Stephen Warren <[email protected]> wrote @ Tue, 12 Feb 2013 17:35:56 +0100:

Quoted 11 lines

However I'd like to avoid changing the body of those two functions at all if possible, since I hope the PCIe driver rework will be merged in 3.10, and that will allow the Harmony and TrimSlice init functions to be removed entirely. I'd rather not have conflicts with the removal patch.

Quoted 2 lines

Since we are not going to add any other board specfic init functions, you can also unroll the loop and put everything into tegra_dt_init_late:

That's not necessarily true. While we certainly don't plan to, I don't think we can rule it out; after all, we don't have rfkill bindings and yet other boards will need them.

Considering the above points,

- The Harmony and TrimSlice init functions will be removed entirely so soon that we want to avoid those merge conflicts as much as possible.
- We may still need board specific init, especially for rfkill.
- We want to build any combination of Tegra{20,30,114}, 2^3 - 1 == 7.

The patch for "tegra.c" would be as below.

Should I still keep the name, "tegra20_auxdata_lookup" to avoid any conflicts or "tegra_auxdata_lookup" would be ok for merge?

arch/arm/mach-tegra/tegra.c +11 -7
index fca18e9..fd4412d 100644
@@ -1,6 +1,7 @@
 /*
- * nVidia Tegra device tree board support
+ * NVIDIA Tegra SoC device tree board support
  *
+ * Copyright (C) 2011, 2013, NVIDIA Corporation
  * Copyright (C) 2010 Secret Lab Technologies, Ltd.
  * Copyright (C) 2010 Google, Inc.
  *
@@ -67,7 +68,7 @@ static struct tegra_ehci_platform_data tegra_ehci3_pdata = {
 	.vbus_gpio = -1,
 };
 
-static struct of_dev_auxdata tegra20_auxdata_lookup[] __initdata = {
+static struct of_dev_auxdata tegra_auxdata_lookup[] __initdata = {
 	OF_DEV_AUXDATA("nvidia,tegra20-ehci", 0xC5000000, "tegra-ehci.0",
 		       &tegra_ehci1_pdata),
 	OF_DEV_AUXDATA("nvidia,tegra20-ehci", 0xC5004000, "tegra-ehci.1",
@@ -84,7 +85,7 @@ static void __init tegra_dt_init(void)
 	 * devices
 	 */
 	of_platform_populate(NULL, of_default_bus_match_table,
-				tegra20_auxdata_lookup, NULL);
+				tegra_auxdata_lookup, NULL);
 }
 
 static void __init trimslice_init(void)
@@ -111,7 +112,8 @@ static void __init harmony_init(void)
 
 static void __init paz00_init(void)
 {
-	tegra_paz00_wifikill_init();
+	if (IS_ENABLED(CONFIG_ARCH_TEGRA_2x_SOC))
+		tegra_paz00_wifikill_init();
 }
 
 static struct {
@@ -137,12 +139,14 @@ static void __init tegra_dt_init_late(void)
 	}
 }
 
-static const char *tegra20_dt_board_compat[] = {
+static const char * const tegra_dt_board_compat[] = {
+	"nvidia,tegra114",
+	"nvidia,tegra30",
 	"nvidia,tegra20",
 	NULL
 };
 
-DT_MACHINE_START(TEGRA_DT, "nVidia Tegra20 (Flattened Device Tree)")
+DT_MACHINE_START(TEGRA_DT, "NVIDIA Tegra SoC (Flattened Device Tree)")
 	.map_io		= tegra_map_common_io,
 	.smp		= smp_ops(tegra_smp_ops),
 	.init_early	= tegra_init_early,
@@ -151,5 +155,5 @@ DT_MACHINE_START(TEGRA_DT, "nVidia Tegra20 (Flattened Device Tree)")
 	.init_machine	= tegra_dt_init,
 	.init_late	= tegra_dt_init_late,
 	.restart	= tegra_assert_system_reset,
-	.dt_compat	= tegra20_dt_board_compat,
+	.dt_compat	= tegra_dt_board_compat,
 MACHINE_END
Signature · 1 line
1.7.9.5
#13 lore raw

Re: [v2 3/3] ARM: tegra: Unify Device tree board files

Quoted 22 lines · Hiroshi Doyu

Stephen Warren <[email protected]> wrote @ Tue, 12 Feb 2013 17:35:56 +0100:

Quoted 11 lines

However I'd like to avoid changing the body of those two functions at all if possible, since I hope the PCIe driver rework will be merged in 3.10, and that will allow the Harmony and TrimSlice init functions to be removed entirely. I'd rather not have conflicts with the removal patch.

Quoted 2 lines

Since we are not going to add any other board specfic init functions, you can also unroll the loop and put everything into tegra_dt_init_late:

That's not necessarily true. While we certainly don't plan to, I don't think we can rule it out; after all, we don't have rfkill bindings and yet other boards will need them.

Considering the above points,

- The Harmony and TrimSlice init functions will be removed entirely so soon that we want to avoid those merge conflicts as much as possible.
- We may still need board specific init, especially for rfkill.
- We want to build any combination of Tegra{20,30,114}, 2^3 - 1 == 7.

Quoted 4 lines

The patch for "tegra.c" would be as below.

Should I still keep the name, "tegra20_auxdata_lookup" to avoid any conflicts or "tegra_auxdata_lookup" would be ok for merge?

Yes, avoiding the rename of the auxdata table might be a good idea.

Aside from that, I think the patch you gave looks fine.