1 // SPDX-License-Identifier: GPL-2.0
2 /*
3 * arch/sh/kernel/topology.c
4 *
5 * Copyright (C) 2007 Paul Mundt
6 */
7 #include <linux/cpu.h>
8 #include <linux/cpumask.h>
9 #include <linux/init.h>
10 #include <linux/percpu.h>
11 #include <linux/topology.h>
12 #include <linux/node.h>
13 #include <linux/nodemask.h>
14 #include <linux/export.h>
15
16 static DEFINE_PER_CPU(struct cpu, cpu_devices);
17
18 cpumask_t cpu_core_map[NR_CPUS];
19 EXPORT_SYMBOL(cpu_core_map);
20
cpu_coregroup_map(int cpu)21 static cpumask_t cpu_coregroup_map(int cpu)
22 {
23 /*
24 * Presently all SH-X3 SMP cores are multi-cores, so just keep it
25 * simple until we have a method for determining topology..
26 */
27 return *cpu_possible_mask;
28 }
29
cpu_coregroup_mask(int cpu)30 const struct cpumask *cpu_coregroup_mask(int cpu)
31 {
32 return &cpu_core_map[cpu];
33 }
34
arch_update_cpu_topology(void)35 int arch_update_cpu_topology(void)
36 {
37 unsigned int cpu;
38
39 for_each_possible_cpu(cpu)
40 cpu_core_map[cpu] = cpu_coregroup_map(cpu);
41
42 return 0;
43 }
44
topology_init(void)45 static int __init topology_init(void)
46 {
47 int i, ret;
48
49 #ifdef CONFIG_NUMA
50 for_each_online_node(i)
51 register_one_node(i);
52 #endif
53
54 for_each_present_cpu(i) {
55 struct cpu *c = &per_cpu(cpu_devices, i);
56
57 c->hotpluggable = 1;
58
59 ret = register_cpu(c, i);
60 if (unlikely(ret))
61 printk(KERN_WARNING "%s: register_cpu %d failed (%d)\n",
62 __func__, i, ret);
63 }
64
65 #if defined(CONFIG_NUMA) && !defined(CONFIG_SMP)
66 /*
67 * In the UP case, make sure the CPU association is still
68 * registered under each node. Without this, sysfs fails
69 * to make the connection between nodes other than node0
70 * and cpu0.
71 */
72 for_each_online_node(i)
73 if (i != numa_node_id())
74 register_cpu_under_node(raw_smp_processor_id(), i);
75 #endif
76
77 return 0;
78 }
79 subsys_initcall(topology_init);
80