1 /* SPDX-License-Identifier: GPL-2.0 */
2 #ifndef _ASM_POWERPC_TOPOLOGY_H
3 #define _ASM_POWERPC_TOPOLOGY_H
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().
17 #define RECLAIM_DISTANCE 10
19 #include <asm/mmzone.h>
21 #define cpumask_of_node(node) ((node) == -1 ? \
23 node_to_cpumask_map[node])
27 extern int pcibus_to_node(struct pci_bus *bus);
29 static inline int pcibus_to_node(struct pci_bus *bus)
35 #define cpumask_of_pcibus(bus) (pcibus_to_node(bus) == -1 ? \
37 cpumask_of_node(pcibus_to_node(bus)))
39 int cpu_relative_distance(__be32 *cpu1_assoc, __be32 *cpu2_assoc);
40 extern int __node_distance(int, int);
41 #define node_distance(a, b) __node_distance(a, b)
43 extern void __init dump_numa_cpu_topology(void);
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);
48 static inline void update_numa_cpu_lookup_table(unsigned int cpu, int node)
50 numa_cpu_lookup_table[cpu] = node;
53 static inline int early_cpu_to_node(int cpu)
57 nid = numa_cpu_lookup_table[cpu];
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)).
63 return (nid < 0) ? 0 : nid;
66 int of_drconf_to_nid_single(struct drmem_lmb *lmb);
67 void update_numa_distance(struct device_node *node);
69 extern void map_cpu_to_node(int cpu, int node);
70 #ifdef CONFIG_HOTPLUG_CPU
71 extern void unmap_cpu_from_node(unsigned long cpu);
72 #endif /* CONFIG_HOTPLUG_CPU */
76 static inline int early_cpu_to_node(int cpu) { return 0; }
78 static inline void dump_numa_cpu_topology(void) {}
80 static inline int sysfs_add_device_to_node(struct device *dev, int nid)
85 static inline void sysfs_remove_device_from_node(struct device *dev,
90 static inline void update_numa_cpu_lookup_table(unsigned int cpu, int node) {}
92 static inline int cpu_relative_distance(__be32 *cpu1_assoc, __be32 *cpu2_assoc)
97 static inline int of_drconf_to_nid_single(struct drmem_lmb *lmb)
99 return first_online_node;
102 static inline void update_numa_distance(struct device_node *node) {}
105 static inline void map_cpu_to_node(int cpu, int node) {}
106 #ifdef CONFIG_HOTPLUG_CPU
107 static inline void unmap_cpu_from_node(unsigned long cpu) {}
108 #endif /* CONFIG_HOTPLUG_CPU */
109 #endif /* CONFIG_SMP */
111 #endif /* CONFIG_NUMA */
113 #if defined(CONFIG_NUMA) && defined(CONFIG_PPC_SPLPAR)
114 void find_and_update_cpu_nid(int cpu);
115 extern int cpu_to_coregroup_id(int cpu);
117 static inline void find_and_update_cpu_nid(int cpu) {}
118 static inline int cpu_to_coregroup_id(int cpu)
121 return cpu_to_core_id(cpu);
127 #endif /* CONFIG_NUMA && CONFIG_PPC_SPLPAR */
129 #include <asm-generic/topology.h>
132 #include <asm/cputable.h>
137 #define topology_physical_package_id(cpu) (cpu_to_chip_id(cpu))
139 #define topology_sibling_cpumask(cpu) (per_cpu(cpu_sibling_map, cpu))
140 #define topology_core_cpumask(cpu) (per_cpu(cpu_core_map, cpu))
141 #define topology_core_id(cpu) (cpu_to_core_id(cpu))
146 #ifdef CONFIG_HOTPLUG_SMT
147 #include <linux/cpu_smt.h>
148 #include <linux/cpumask.h>
149 #include <asm/cputhreads.h>
151 static inline bool topology_is_primary_thread(unsigned int cpu)
153 return cpu == cpu_first_thread_sibling(cpu);
156 static inline bool topology_smt_thread_allowed(unsigned int cpu)
158 return cpu_thread_in_core(cpu) < cpu_smt_num_threads;
161 #define topology_is_core_online topology_is_core_online
162 static inline bool topology_is_core_online(unsigned int cpu)
164 int i, first_cpu = cpu_first_thread_sibling(cpu);
166 for (i = first_cpu; i < first_cpu + threads_per_core; ++i) {
174 #endif /* __KERNEL__ */
175 #endif /* _ASM_POWERPC_TOPOLOGY_H */