diff mbox

[RFC,3/5] arm64: introduce CPU_OF_TABLES for cpu ops selection

Message ID 1428601031-5366-4-git-send-email-galak@codeaurora.org (mailing list archive)
State New, archived
Headers show

Commit Message

Kumar Gala April 9, 2015, 5:37 p.m. UTC
From: Abhimanyu Kapur <abhimany@codeaurora.org>

Add support to arm64 to provide a dt-based method to allow soc-vendors to
supply cpu_ops. Also move psci and smp_spin_table ops to use CPU_OF_TABLES.

Signed-off-by: Abhimanyu Kapur <abhimany@codeaurora.org>
Signed-off-by: Kumar Gala <galak@codeaurora.org>
---
 arch/arm64/include/asm/cpu_ops.h   |  5 +++++
 arch/arm64/kernel/cpu_ops.c        | 27 +++++++++------------------
 arch/arm64/kernel/psci.c           |  1 +
 arch/arm64/kernel/smp_spin_table.c |  3 ++-
 4 files changed, 17 insertions(+), 19 deletions(-)

Comments

Arnd Bergmann April 9, 2015, 9:17 p.m. UTC | #1
On Thursday 09 April 2015 12:37:09 Kumar Gala wrote:
> @@ -67,4 +67,9 @@ extern const struct cpu_operations *cpu_ops[NR_CPUS];
>  int __init cpu_read_ops(struct device_node *dn, int cpu);
>  void __init cpu_read_bootcpu_ops(void);
>  
> +#define CPU_METHOD_OF_DECLARE(name, __ops)                             \
> +       static const struct cpu_operations *__cpu_method_table_##name   \
> +       __used __section(__cpu_method_of_table)                         \
> +       = __ops;
> +
>  #endif /* ifndef __ASM_CPU_OPS_H */
> 

I'd rather not add this, to avoid giving the appearance that platforms
can just add another one here.

	Arnd
Lorenzo Pieralisi April 10, 2015, 10:28 a.m. UTC | #2
On Thu, Apr 09, 2015 at 06:37:09PM +0100, Kumar Gala wrote:
> From: Abhimanyu Kapur <abhimany@codeaurora.org>
> 
> Add support to arm64 to provide a dt-based method to allow soc-vendors to
> supply cpu_ops. Also move psci and smp_spin_table ops to use CPU_OF_TABLES.

On arm64 there are two enable methods: PSCI and spin-table.

Update your firmware accordingly and drop this patch, thanks.

Lorenzo

> Signed-off-by: Abhimanyu Kapur <abhimany@codeaurora.org>
> Signed-off-by: Kumar Gala <galak@codeaurora.org>
> ---
>  arch/arm64/include/asm/cpu_ops.h   |  5 +++++
>  arch/arm64/kernel/cpu_ops.c        | 27 +++++++++------------------
>  arch/arm64/kernel/psci.c           |  1 +
>  arch/arm64/kernel/smp_spin_table.c |  3 ++-
>  4 files changed, 17 insertions(+), 19 deletions(-)
> 
> diff --git a/arch/arm64/include/asm/cpu_ops.h b/arch/arm64/include/asm/cpu_ops.h
> index da301ee..a7efab8 100644
> --- a/arch/arm64/include/asm/cpu_ops.h
> +++ b/arch/arm64/include/asm/cpu_ops.h
> @@ -67,4 +67,9 @@ extern const struct cpu_operations *cpu_ops[NR_CPUS];
>  int __init cpu_read_ops(struct device_node *dn, int cpu);
>  void __init cpu_read_bootcpu_ops(void);
>  
> +#define CPU_METHOD_OF_DECLARE(name, __ops)				\
> +	static const struct cpu_operations *__cpu_method_table_##name	\
> +	__used __section(__cpu_method_of_table)				\
> +	= __ops;
> +
>  #endif /* ifndef __ASM_CPU_OPS_H */
> diff --git a/arch/arm64/kernel/cpu_ops.c b/arch/arm64/kernel/cpu_ops.c
> index cce9524..ad33f98 100644
> --- a/arch/arm64/kernel/cpu_ops.c
> +++ b/arch/arm64/kernel/cpu_ops.c
> @@ -22,29 +22,20 @@
>  #include <linux/of.h>
>  #include <linux/string.h>
>  
> -extern const struct cpu_operations smp_spin_table_ops;
> -extern const struct cpu_operations cpu_psci_ops;
> -
>  const struct cpu_operations *cpu_ops[NR_CPUS];
>  
> -static const struct cpu_operations *supported_cpu_ops[] __initconst = {
> -#ifdef CONFIG_SMP
> -	&smp_spin_table_ops,
> -#endif
> -	&cpu_psci_ops,
> -	NULL,
> -};
> +extern struct cpu_operations __cpu_method_of_table[];
> +static const struct cpu_operations *__cpu_method_of_table_sentinel
> +	__used __section(__cpu_method_of_table_end);
>  
> -static const struct cpu_operations * __init cpu_get_ops(const char *name)
> +const struct cpu_operations * __init cpu_get_ops(const char *name)
>  {
> -	const struct cpu_operations **ops = supported_cpu_ops;
> -
> -	while (*ops) {
> -		if (!strcmp(name, (*ops)->name))
> -			return *ops;
> +	const struct cpu_operations **start = (void *)__cpu_method_of_table;
>  
> -		ops++;
> -	}
> +	for (; *start; start++) {
> +		if (!strcmp((*start)->name, name))
> +			return *start;
> +	};
>  
>  	return NULL;
>  }
> diff --git a/arch/arm64/kernel/psci.c b/arch/arm64/kernel/psci.c
> index 9b8a70a..2f255c7 100644
> --- a/arch/arm64/kernel/psci.c
> +++ b/arch/arm64/kernel/psci.c
> @@ -523,3 +523,4 @@ const struct cpu_operations cpu_psci_ops = {
>  #endif
>  };
>  
> +CPU_METHOD_OF_DECLARE(psci, &cpu_psci_ops);
> diff --git a/arch/arm64/kernel/smp_spin_table.c b/arch/arm64/kernel/smp_spin_table.c
> index 14944e5..b41a8b4 100644
> --- a/arch/arm64/kernel/smp_spin_table.c
> +++ b/arch/arm64/kernel/smp_spin_table.c
> @@ -119,9 +119,10 @@ static int smp_spin_table_cpu_boot(unsigned int cpu)
>  	return 0;
>  }
>  
> -const struct cpu_operations smp_spin_table_ops = {
> +static const struct cpu_operations smp_spin_table_ops = {
>  	.name		= "spin-table",
>  	.cpu_init	= smp_spin_table_cpu_init,
>  	.cpu_prepare	= smp_spin_table_cpu_prepare,
>  	.cpu_boot	= smp_spin_table_cpu_boot,
>  };
> +CPU_METHOD_OF_DECLARE(spin_table, &smp_spin_table_ops);
> -- 
> Qualcomm Innovation Center, Inc.
> The Qualcomm Innovation Center, Inc. is a member of the Code Aurora Forum,
> a Linux Foundation Collaborative Project
> 
> --
> To unsubscribe from this list: send the line "unsubscribe linux-kernel" in
> the body of a message to majordomo@vger.kernel.org
> More majordomo info at  http://vger.kernel.org/majordomo-info.html
> Please read the FAQ at  http://www.tux.org/lkml/
>
Mark Rutland April 14, 2015, 3:52 p.m. UTC | #3
On Thu, Apr 09, 2015 at 10:17:06PM +0100, Arnd Bergmann wrote:
> On Thursday 09 April 2015 12:37:09 Kumar Gala wrote:
> > @@ -67,4 +67,9 @@ extern const struct cpu_operations *cpu_ops[NR_CPUS];
> >  int __init cpu_read_ops(struct device_node *dn, int cpu);
> >  void __init cpu_read_bootcpu_ops(void);
> >  
> > +#define CPU_METHOD_OF_DECLARE(name, __ops)                             \
> > +       static const struct cpu_operations *__cpu_method_table_##name   \
> > +       __used __section(__cpu_method_of_table)                         \
> > +       = __ops;
> > +
> >  #endif /* ifndef __ASM_CPU_OPS_H */
> > 
> 
> I'd rather not add this, to avoid giving the appearance that platforms
> can just add another one here.

Likewise.

SMP bringup is always hairy, and giving the appearance that such code
should be hidden away somewhere (and missing critical review) is a bad
idea.

While this seemed like a good idea in the past for 32-bit, we've only
seen marginal decoupling, and very little in the way of actual semantics
defined for the enable-methods. Which effectively spreads implementation
details further rather than separating them from the interface.

Mark.
diff mbox

Patch

diff --git a/arch/arm64/include/asm/cpu_ops.h b/arch/arm64/include/asm/cpu_ops.h
index da301ee..a7efab8 100644
--- a/arch/arm64/include/asm/cpu_ops.h
+++ b/arch/arm64/include/asm/cpu_ops.h
@@ -67,4 +67,9 @@  extern const struct cpu_operations *cpu_ops[NR_CPUS];
 int __init cpu_read_ops(struct device_node *dn, int cpu);
 void __init cpu_read_bootcpu_ops(void);
 
+#define CPU_METHOD_OF_DECLARE(name, __ops)				\
+	static const struct cpu_operations *__cpu_method_table_##name	\
+	__used __section(__cpu_method_of_table)				\
+	= __ops;
+
 #endif /* ifndef __ASM_CPU_OPS_H */
diff --git a/arch/arm64/kernel/cpu_ops.c b/arch/arm64/kernel/cpu_ops.c
index cce9524..ad33f98 100644
--- a/arch/arm64/kernel/cpu_ops.c
+++ b/arch/arm64/kernel/cpu_ops.c
@@ -22,29 +22,20 @@ 
 #include <linux/of.h>
 #include <linux/string.h>
 
-extern const struct cpu_operations smp_spin_table_ops;
-extern const struct cpu_operations cpu_psci_ops;
-
 const struct cpu_operations *cpu_ops[NR_CPUS];
 
-static const struct cpu_operations *supported_cpu_ops[] __initconst = {
-#ifdef CONFIG_SMP
-	&smp_spin_table_ops,
-#endif
-	&cpu_psci_ops,
-	NULL,
-};
+extern struct cpu_operations __cpu_method_of_table[];
+static const struct cpu_operations *__cpu_method_of_table_sentinel
+	__used __section(__cpu_method_of_table_end);
 
-static const struct cpu_operations * __init cpu_get_ops(const char *name)
+const struct cpu_operations * __init cpu_get_ops(const char *name)
 {
-	const struct cpu_operations **ops = supported_cpu_ops;
-
-	while (*ops) {
-		if (!strcmp(name, (*ops)->name))
-			return *ops;
+	const struct cpu_operations **start = (void *)__cpu_method_of_table;
 
-		ops++;
-	}
+	for (; *start; start++) {
+		if (!strcmp((*start)->name, name))
+			return *start;
+	};
 
 	return NULL;
 }
diff --git a/arch/arm64/kernel/psci.c b/arch/arm64/kernel/psci.c
index 9b8a70a..2f255c7 100644
--- a/arch/arm64/kernel/psci.c
+++ b/arch/arm64/kernel/psci.c
@@ -523,3 +523,4 @@  const struct cpu_operations cpu_psci_ops = {
 #endif
 };
 
+CPU_METHOD_OF_DECLARE(psci, &cpu_psci_ops);
diff --git a/arch/arm64/kernel/smp_spin_table.c b/arch/arm64/kernel/smp_spin_table.c
index 14944e5..b41a8b4 100644
--- a/arch/arm64/kernel/smp_spin_table.c
+++ b/arch/arm64/kernel/smp_spin_table.c
@@ -119,9 +119,10 @@  static int smp_spin_table_cpu_boot(unsigned int cpu)
 	return 0;
 }
 
-const struct cpu_operations smp_spin_table_ops = {
+static const struct cpu_operations smp_spin_table_ops = {
 	.name		= "spin-table",
 	.cpu_init	= smp_spin_table_cpu_init,
 	.cpu_prepare	= smp_spin_table_cpu_prepare,
 	.cpu_boot	= smp_spin_table_cpu_boot,
 };
+CPU_METHOD_OF_DECLARE(spin_table, &smp_spin_table_ops);