Skip to content

Commit cd1aebf

Browse files
mrutland-armctmarinas
authored andcommitted
arm64: reorganise smp_enable_ops
For hotplug support, we're going to want a place to store operations that do more than bring CPUs online, and it makes sense to group these with our current smp_enable_ops. For cpuidle support, we'll want to group additional functions, and we may want them even for UP kernels. This patch renames smp_enable_ops to the more general cpu_operations, and pulls the definitions out of smp code such that they can be used in UP kernels. While we're at it, fix up instances of the cpu parameter to be an unsigned int, drop the init markings and rename the *_cpu functions to cpu_* to reduce future churn when cpu_operations is extended. Signed-off-by: Mark Rutland <mark.rutland@arm.com> Signed-off-by: Catalin Marinas <catalin.marinas@arm.com>
1 parent 00ef54b commit cd1aebf

7 files changed

Lines changed: 102 additions & 52 deletions

File tree

‎arch/arm64/include/asm/cpu_ops.h‎

Lines changed: 33 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,33 @@
1+
/*
2+
* Copyright (C) 2013 ARM Ltd.
3+
*
4+
* This program is free software; you can redistribute it and/or modify
5+
* it under the terms of the GNU General Public License version 2 as
6+
* published by the Free Software Foundation.
7+
*
8+
* This program is distributed in the hope that it will be useful,
9+
* but WITHOUT ANY WARRANTY; without even the implied warranty of
10+
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
11+
* GNU General Public License for more details.
12+
*
13+
* You should have received a copy of the GNU General Public License
14+
* along with this program. If not, see <http://www.gnu.org/licenses/>.
15+
*/
16+
#ifndef __ASM_CPU_OPS_H
17+
#define __ASM_CPU_OPS_H
18+
19+
#include <linux/init.h>
20+
#include <linux/threads.h>
21+
22+
struct device_node;
23+
24+
struct cpu_operations {
25+
const char *name;
26+
int (*cpu_init)(struct device_node *, unsigned int);
27+
int (*cpu_prepare)(unsigned int);
28+
};
29+
30+
extern const struct cpu_operations *cpu_ops[NR_CPUS];
31+
extern const struct cpu_operations * __init cpu_get_ops(const char *name);
32+
33+
#endif /* ifndef __ASM_CPU_OPS_H */

‎arch/arm64/include/asm/smp.h‎

Lines changed: 0 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -66,15 +66,4 @@ extern volatile unsigned long secondary_holding_pen_release;
6666
extern void arch_send_call_function_single_ipi(int cpu);
6767
extern void arch_send_call_function_ipi_mask(const struct cpumask *mask);
6868

69-
struct device_node;
70-
71-
struct smp_enable_ops {
72-
const char *name;
73-
int (*init_cpu)(struct device_node *, int);
74-
int (*prepare_cpu)(int);
75-
};
76-
77-
extern const struct smp_enable_ops smp_spin_table_ops;
78-
extern const struct smp_enable_ops smp_psci_ops;
79-
8069
#endif /* ifndef __ASM_SMP_H */

‎arch/arm64/kernel/Makefile‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@ AFLAGS_head.o := -DTEXT_OFFSET=$(TEXT_OFFSET)
99
arm64-obj-y := cputable.o debug-monitors.o entry.o irq.o fpsimd.o \
1010
entry-fpsimd.o process.o ptrace.o setup.o signal.o \
1111
sys.o stacktrace.o time.o traps.o io.o vdso.o \
12-
hyp-stub.o psci.o
12+
hyp-stub.o psci.o cpu_ops.o
1313

1414
arm64-obj-$(CONFIG_COMPAT) += sys32.o kuser32.o signal32.o \
1515
sys_compat.o

‎arch/arm64/kernel/cpu_ops.c‎

Lines changed: 47 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,47 @@
1+
/*
2+
* CPU kernel entry/exit control
3+
*
4+
* Copyright (C) 2013 ARM Ltd.
5+
*
6+
* This program is free software; you can redistribute it and/or modify
7+
* it under the terms of the GNU General Public License version 2 as
8+
* published by the Free Software Foundation.
9+
*
10+
* This program is distributed in the hope that it will be useful,
11+
* but WITHOUT ANY WARRANTY; without even the implied warranty of
12+
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13+
* GNU General Public License for more details.
14+
*
15+
* You should have received a copy of the GNU General Public License
16+
* along with this program. If not, see <http://www.gnu.org/licenses/>.
17+
*/
18+
19+
#include <asm/cpu_ops.h>
20+
#include <linux/string.h>
21+
22+
extern const struct cpu_operations smp_spin_table_ops;
23+
extern const struct cpu_operations cpu_psci_ops;
24+
25+
const struct cpu_operations *cpu_ops[NR_CPUS];
26+
27+
static const struct cpu_operations *supported_cpu_ops[] __initconst = {
28+
#ifdef CONFIG_SMP
29+
&smp_spin_table_ops,
30+
&cpu_psci_ops,
31+
#endif
32+
NULL,
33+
};
34+
35+
const struct cpu_operations * __init cpu_get_ops(const char *name)
36+
{
37+
const struct cpu_operations **ops = supported_cpu_ops;
38+
39+
while (*ops) {
40+
if (!strcmp(name, (*ops)->name))
41+
return *ops;
42+
43+
ops++;
44+
}
45+
46+
return NULL;
47+
}

‎arch/arm64/kernel/psci.c‎

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,7 @@
2020
#include <linux/smp.h>
2121

2222
#include <asm/compiler.h>
23+
#include <asm/cpu_ops.h>
2324
#include <asm/errno.h>
2425
#include <asm/psci.h>
2526
#include <asm/smp_plat.h>
@@ -231,12 +232,12 @@ int __init psci_init(void)
231232

232233
#ifdef CONFIG_SMP
233234

234-
static int __init smp_psci_init_cpu(struct device_node *dn, int cpu)
235+
static int __init cpu_psci_cpu_init(struct device_node *dn, unsigned int cpu)
235236
{
236237
return 0;
237238
}
238239

239-
static int __init smp_psci_prepare_cpu(int cpu)
240+
static int __init cpu_psci_cpu_prepare(unsigned int cpu)
240241
{
241242
int err;
242243

@@ -254,10 +255,10 @@ static int __init smp_psci_prepare_cpu(int cpu)
254255
return 0;
255256
}
256257

257-
const struct smp_enable_ops smp_psci_ops __initconst = {
258+
const struct cpu_operations cpu_psci_ops = {
258259
.name = "psci",
259-
.init_cpu = smp_psci_init_cpu,
260-
.prepare_cpu = smp_psci_prepare_cpu,
260+
.cpu_init = cpu_psci_cpu_init,
261+
.cpu_prepare = cpu_psci_cpu_prepare,
261262
};
262263

263264
#endif

‎arch/arm64/kernel/smp.c‎

Lines changed: 9 additions & 30 deletions
Original file line numberDiff line numberDiff line change
@@ -39,6 +39,7 @@
3939
#include <asm/atomic.h>
4040
#include <asm/cacheflush.h>
4141
#include <asm/cputype.h>
42+
#include <asm/cpu_ops.h>
4243
#include <asm/mmu_context.h>
4344
#include <asm/pgtable.h>
4445
#include <asm/pgalloc.h>
@@ -232,28 +233,6 @@ void __init smp_prepare_boot_cpu(void)
232233

233234
static void (*smp_cross_call)(const struct cpumask *, unsigned int);
234235

235-
static const struct smp_enable_ops *enable_ops[] __initconst = {
236-
&smp_spin_table_ops,
237-
&smp_psci_ops,
238-
NULL,
239-
};
240-
241-
static const struct smp_enable_ops *smp_enable_ops[NR_CPUS];
242-
243-
static const struct smp_enable_ops * __init smp_get_enable_ops(const char *name)
244-
{
245-
const struct smp_enable_ops **ops = enable_ops;
246-
247-
while (*ops) {
248-
if (!strcmp(name, (*ops)->name))
249-
return *ops;
250-
251-
ops++;
252-
}
253-
254-
return NULL;
255-
}
256-
257236
/*
258237
* Enumerate the possible CPU set from the device tree and build the
259238
* cpu logical map array containing MPIDR values related to logical
@@ -263,7 +242,7 @@ void __init smp_init_cpus(void)
263242
{
264243
const char *enable_method;
265244
struct device_node *dn = NULL;
266-
int i, cpu = 1;
245+
unsigned int i, cpu = 1;
267246
bool bootcpu_valid = false;
268247

269248
while ((dn = of_find_node_by_type(dn, "cpu"))) {
@@ -342,15 +321,15 @@ void __init smp_init_cpus(void)
342321
goto next;
343322
}
344323

345-
smp_enable_ops[cpu] = smp_get_enable_ops(enable_method);
324+
cpu_ops[cpu] = cpu_get_ops(enable_method);
346325

347-
if (!smp_enable_ops[cpu]) {
326+
if (!cpu_ops[cpu]) {
348327
pr_err("%s: invalid enable-method property: %s\n",
349328
dn->full_name, enable_method);
350329
goto next;
351330
}
352331

353-
if (smp_enable_ops[cpu]->init_cpu(dn, cpu))
332+
if (cpu_ops[cpu]->cpu_init(dn, cpu))
354333
goto next;
355334

356335
pr_debug("cpu logical map 0x%llx\n", hwid);
@@ -380,8 +359,8 @@ void __init smp_init_cpus(void)
380359

381360
void __init smp_prepare_cpus(unsigned int max_cpus)
382361
{
383-
int cpu, err;
384-
unsigned int ncores = num_possible_cpus();
362+
int err;
363+
unsigned int cpu, ncores = num_possible_cpus();
385364

386365
/*
387366
* are we trying to boot more cores than exist?
@@ -408,10 +387,10 @@ void __init smp_prepare_cpus(unsigned int max_cpus)
408387
if (cpu == smp_processor_id())
409388
continue;
410389

411-
if (!smp_enable_ops[cpu])
390+
if (!cpu_ops[cpu])
412391
continue;
413392

414-
err = smp_enable_ops[cpu]->prepare_cpu(cpu);
393+
err = cpu_ops[cpu]->cpu_prepare(cpu);
415394
if (err)
416395
continue;
417396

‎arch/arm64/kernel/smp_spin_table.c‎

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -21,10 +21,11 @@
2121
#include <linux/smp.h>
2222

2323
#include <asm/cacheflush.h>
24+
#include <asm/cpu_ops.h>
2425

2526
static phys_addr_t cpu_release_addr[NR_CPUS];
2627

27-
static int __init smp_spin_table_init_cpu(struct device_node *dn, int cpu)
28+
static int smp_spin_table_cpu_init(struct device_node *dn, unsigned int cpu)
2829
{
2930
/*
3031
* Determine the address from which the CPU is polling.
@@ -40,7 +41,7 @@ static int __init smp_spin_table_init_cpu(struct device_node *dn, int cpu)
4041
return 0;
4142
}
4243

43-
static int __init smp_spin_table_prepare_cpu(int cpu)
44+
static int smp_spin_table_cpu_prepare(unsigned int cpu)
4445
{
4546
void **release_addr;
4647

@@ -59,8 +60,8 @@ static int __init smp_spin_table_prepare_cpu(int cpu)
5960
return 0;
6061
}
6162

62-
const struct smp_enable_ops smp_spin_table_ops __initconst = {
63+
const struct cpu_operations smp_spin_table_ops = {
6364
.name = "spin-table",
64-
.init_cpu = smp_spin_table_init_cpu,
65-
.prepare_cpu = smp_spin_table_prepare_cpu,
65+
.cpu_init = smp_spin_table_cpu_init,
66+
.cpu_prepare = smp_spin_table_cpu_prepare,
6667
};

0 commit comments

Comments
 (0)