xref: /linux/arch/sh/kernel/topology.c (revision 4f2c0a4acffbec01079c28f839422e64ddeff004)
1*5933f6d2SKuninori Morimoto // SPDX-License-Identifier: GPL-2.0
205a11784SPaul Mundt /*
305a11784SPaul Mundt  * arch/sh/kernel/topology.c
405a11784SPaul Mundt  *
505a11784SPaul Mundt  *  Copyright (C) 2007  Paul Mundt
605a11784SPaul Mundt  */
77a302a96SPaul Mundt #include <linux/cpu.h>
87a302a96SPaul Mundt #include <linux/cpumask.h>
97a302a96SPaul Mundt #include <linux/init.h>
107a302a96SPaul Mundt #include <linux/percpu.h>
116988d647SNobuhiro Iwamatsu #include <linux/topology.h>
12d22d9b3aSPaul Mundt #include <linux/node.h>
13d22d9b3aSPaul Mundt #include <linux/nodemask.h>
14f7be3455SPaul Gortmaker #include <linux/export.h>
157a302a96SPaul Mundt 
167a302a96SPaul Mundt static DEFINE_PER_CPU(struct cpu, cpu_devices);
177a302a96SPaul Mundt 
18896f0c0eSPaul Mundt cpumask_t cpu_core_map[NR_CPUS];
1924ee7d79SAurelien Jarno EXPORT_SYMBOL(cpu_core_map);
20896f0c0eSPaul Mundt 
cpu_coregroup_map(int cpu)21ccc7d5a1SRich Felker static cpumask_t cpu_coregroup_map(int cpu)
22896f0c0eSPaul Mundt {
23896f0c0eSPaul Mundt 	/*
24896f0c0eSPaul Mundt 	 * Presently all SH-X3 SMP cores are multi-cores, so just keep it
25896f0c0eSPaul Mundt 	 * simple until we have a method for determining topology..
26896f0c0eSPaul Mundt 	 */
27004f4ce9SRusty Russell 	return *cpu_possible_mask;
28896f0c0eSPaul Mundt }
29896f0c0eSPaul Mundt 
cpu_coregroup_mask(int cpu)30ccc7d5a1SRich Felker const struct cpumask *cpu_coregroup_mask(int cpu)
31896f0c0eSPaul Mundt {
32896f0c0eSPaul Mundt 	return &cpu_core_map[cpu];
33896f0c0eSPaul Mundt }
34896f0c0eSPaul Mundt 
arch_update_cpu_topology(void)35896f0c0eSPaul Mundt int arch_update_cpu_topology(void)
36896f0c0eSPaul Mundt {
37896f0c0eSPaul Mundt 	unsigned int cpu;
38896f0c0eSPaul Mundt 
39896f0c0eSPaul Mundt 	for_each_possible_cpu(cpu)
40896f0c0eSPaul Mundt 		cpu_core_map[cpu] = cpu_coregroup_map(cpu);
41896f0c0eSPaul Mundt 
42896f0c0eSPaul Mundt 	return 0;
43896f0c0eSPaul Mundt }
44896f0c0eSPaul Mundt 
topology_init(void)457a302a96SPaul Mundt static int __init topology_init(void)
467a302a96SPaul Mundt {
477a302a96SPaul Mundt 	int i, ret;
487a302a96SPaul Mundt 
497a302a96SPaul Mundt 	for_each_present_cpu(i) {
509e8c5be8SPaul Mundt 		struct cpu *c = &per_cpu(cpu_devices, i);
519e8c5be8SPaul Mundt 
529e8c5be8SPaul Mundt 		c->hotpluggable = 1;
539e8c5be8SPaul Mundt 
549e8c5be8SPaul Mundt 		ret = register_cpu(c, i);
557a302a96SPaul Mundt 		if (unlikely(ret))
567a302a96SPaul Mundt 			printk(KERN_WARNING "%s: register_cpu %d failed (%d)\n",
57866e6b9eSHarvey Harrison 			       __func__, i, ret);
587a302a96SPaul Mundt 	}
597a302a96SPaul Mundt 
6005a11784SPaul Mundt #if defined(CONFIG_NUMA) && !defined(CONFIG_SMP)
6105a11784SPaul Mundt 	/*
6205a11784SPaul Mundt 	 * In the UP case, make sure the CPU association is still
6305a11784SPaul Mundt 	 * registered under each node. Without this, sysfs fails
6405a11784SPaul Mundt 	 * to make the connection between nodes other than node0
6505a11784SPaul Mundt 	 * and cpu0.
6605a11784SPaul Mundt 	 */
6705a11784SPaul Mundt 	for_each_online_node(i)
6805a11784SPaul Mundt 		if (i != numa_node_id())
6905a11784SPaul Mundt 			register_cpu_under_node(raw_smp_processor_id(), i);
7005a11784SPaul Mundt #endif
7105a11784SPaul Mundt 
727a302a96SPaul Mundt 	return 0;
737a302a96SPaul Mundt }
747a302a96SPaul Mundt subsys_initcall(topology_init);
75