1 /* SPDX-License-Identifier: GPL-2.0 */
2 #ifndef _ASM_POWERPC_TOPOLOGY_H
3 #define _ASM_POWERPC_TOPOLOGY_H
4 #ifdef __KERNEL__
5
6
7 struct device;
8 struct device_node;
9 struct drmem_lmb;
10
11 #ifdef CONFIG_NUMA
12
13 /*
14 * If zone_reclaim_mode is enabled, a RECLAIM_DISTANCE of 10 will mean that
15 * all zones on all nodes will be eligible for zone_reclaim().
16 */
17 #define RECLAIM_DISTANCE 10
18
19 #include <asm/mmzone.h>
20
21 #define cpumask_of_node(node) ((node) == -1 ? \
22 cpu_all_mask : \
23 node_to_cpumask_map[node])
24
25 struct pci_bus;
26 #ifdef CONFIG_PCI
27 extern int pcibus_to_node(struct pci_bus *bus);
28 #else
pcibus_to_node(struct pci_bus * bus)29 static inline int pcibus_to_node(struct pci_bus *bus)
30 {
31 return -1;
32 }
33 #endif
34
35 #define cpumask_of_pcibus(bus) (pcibus_to_node(bus) == -1 ? \
36 cpu_all_mask : \
37 cpumask_of_node(pcibus_to_node(bus)))
38
39 extern int cpu_distance(__be32 *cpu1_assoc, __be32 *cpu2_assoc);
40 extern int __node_distance(int, int);
41 #define node_distance(a, b) __node_distance(a, b)
42
43 extern void __init dump_numa_cpu_topology(void);
44
45 extern int sysfs_add_device_to_node(struct device *dev, int nid);
46 extern void sysfs_remove_device_from_node(struct device *dev, int nid);
47
update_numa_cpu_lookup_table(unsigned int cpu,int node)48 static inline void update_numa_cpu_lookup_table(unsigned int cpu, int node)
49 {
50 numa_cpu_lookup_table[cpu] = node;
51 }
52
early_cpu_to_node(int cpu)53 static inline int early_cpu_to_node(int cpu)
54 {
55 int nid;
56
57 nid = numa_cpu_lookup_table[cpu];
58
59 /*
60 * Fall back to node 0 if nid is unset (it should be, except bugs).
61 * This allows callers to safely do NODE_DATA(early_cpu_to_node(cpu)).
62 */
63 return (nid < 0) ? 0 : nid;
64 }
65
66 int of_drconf_to_nid_single(struct drmem_lmb *lmb);
67
68 extern void map_cpu_to_node(int cpu, int node);
69 #ifdef CONFIG_HOTPLUG_CPU
70 extern void unmap_cpu_from_node(unsigned long cpu);
71 #endif /* CONFIG_HOTPLUG_CPU */
72
73 #else
74
early_cpu_to_node(int cpu)75 static inline int early_cpu_to_node(int cpu) { return 0; }
76
dump_numa_cpu_topology(void)77 static inline void dump_numa_cpu_topology(void) {}
78
sysfs_add_device_to_node(struct device * dev,int nid)79 static inline int sysfs_add_device_to_node(struct device *dev, int nid)
80 {
81 return 0;
82 }
83
sysfs_remove_device_from_node(struct device * dev,int nid)84 static inline void sysfs_remove_device_from_node(struct device *dev,
85 int nid)
86 {
87 }
88
update_numa_cpu_lookup_table(unsigned int cpu,int node)89 static inline void update_numa_cpu_lookup_table(unsigned int cpu, int node) {}
90
cpu_distance(__be32 * cpu1_assoc,__be32 * cpu2_assoc)91 static inline int cpu_distance(__be32 *cpu1_assoc, __be32 *cpu2_assoc)
92 {
93 return 0;
94 }
95
of_drconf_to_nid_single(struct drmem_lmb * lmb)96 static inline int of_drconf_to_nid_single(struct drmem_lmb *lmb)
97 {
98 return first_online_node;
99 }
100
101
102 #ifdef CONFIG_SMP
map_cpu_to_node(int cpu,int node)103 static inline void map_cpu_to_node(int cpu, int node) {}
104 #ifdef CONFIG_HOTPLUG_CPU
unmap_cpu_from_node(unsigned long cpu)105 static inline void unmap_cpu_from_node(unsigned long cpu) {}
106 #endif /* CONFIG_HOTPLUG_CPU */
107 #endif /* CONFIG_SMP */
108
109 #endif /* CONFIG_NUMA */
110
111 #if defined(CONFIG_NUMA) && defined(CONFIG_PPC_SPLPAR)
112 extern int find_and_online_cpu_nid(int cpu);
113 extern int cpu_to_coregroup_id(int cpu);
114 #else
find_and_online_cpu_nid(int cpu)115 static inline int find_and_online_cpu_nid(int cpu)
116 {
117 return 0;
118 }
119
cpu_to_coregroup_id(int cpu)120 static inline int cpu_to_coregroup_id(int cpu)
121 {
122 #ifdef CONFIG_SMP
123 return cpu_to_core_id(cpu);
124 #else
125 return 0;
126 #endif
127 }
128
129 #endif /* CONFIG_NUMA && CONFIG_PPC_SPLPAR */
130
131 #include <asm-generic/topology.h>
132
133 #ifdef CONFIG_SMP
134 #include <asm/cputable.h>
135
136 #ifdef CONFIG_PPC64
137 #include <asm/smp.h>
138
139 #define topology_physical_package_id(cpu) (cpu_to_chip_id(cpu))
140
141 #define topology_sibling_cpumask(cpu) (per_cpu(cpu_sibling_map, cpu))
142 #define topology_core_cpumask(cpu) (cpu_cpu_mask(cpu))
143 #define topology_core_id(cpu) (cpu_to_core_id(cpu))
144
145 #endif
146 #endif
147
148 #endif /* __KERNEL__ */
149 #endif /* _ASM_POWERPC_TOPOLOGY_H */
150