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 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 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) 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 48 static inline void update_numa_cpu_lookup_table(unsigned int cpu, int node) 49 { 50 numa_cpu_lookup_table[cpu] = node; 51 } 52 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 void update_numa_distance(struct device_node *node); 68 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 */ 73 74 int cpu_to_coregroup_id(int cpu); 75 #else 76 77 static inline int early_cpu_to_node(int cpu) { return 0; } 78 79 static inline void dump_numa_cpu_topology(void) {} 80 81 static inline int sysfs_add_device_to_node(struct device *dev, int nid) 82 { 83 return 0; 84 } 85 86 static inline void sysfs_remove_device_from_node(struct device *dev, 87 int nid) 88 { 89 } 90 91 static inline void update_numa_cpu_lookup_table(unsigned int cpu, int node) {} 92 93 static inline int cpu_relative_distance(__be32 *cpu1_assoc, __be32 *cpu2_assoc) 94 { 95 return 0; 96 } 97 98 static inline int of_drconf_to_nid_single(struct drmem_lmb *lmb) 99 { 100 return first_online_node; 101 } 102 103 static inline void update_numa_distance(struct device_node *node) {} 104 105 #ifdef CONFIG_SMP 106 static inline void map_cpu_to_node(int cpu, int node) {} 107 #ifdef CONFIG_HOTPLUG_CPU 108 static inline void unmap_cpu_from_node(unsigned long cpu) {} 109 #endif /* CONFIG_HOTPLUG_CPU */ 110 #endif /* CONFIG_SMP */ 111 static inline int cpu_to_coregroup_id(int cpu) 112 { 113 #ifdef CONFIG_SMP 114 return cpu_to_core_id(cpu); 115 #else 116 return 0; 117 #endif 118 } 119 120 #endif /* CONFIG_NUMA */ 121 122 #if defined(CONFIG_NUMA) && defined(CONFIG_PPC_SPLPAR) 123 void find_and_update_cpu_nid(int cpu); 124 #else 125 static inline void find_and_update_cpu_nid(int cpu) {} 126 #endif /* CONFIG_NUMA && CONFIG_PPC_SPLPAR */ 127 128 #include <asm-generic/topology.h> 129 130 #ifdef CONFIG_SMP 131 #include <asm/cputable.h> 132 133 struct cpumask *cpu_coregroup_mask(int cpu); 134 const struct cpumask *cpu_die_mask(int cpu); 135 int cpu_die_id(int cpu); 136 137 /* 138 * Points to where the LLC is. On power9 this will point at CACHE 139 * domain, On others it will point to SMT domain. In all cases 140 * cpu_l2_cache_mask points to where LLC is 141 */ 142 #define arch_llc_mask(cpu) cpu_l2_cache_mask(cpu) 143 144 #ifdef CONFIG_PPC64 145 #include <asm/smp.h> 146 147 #define topology_physical_package_id(cpu) (cpu_to_chip_id(cpu)) 148 #define topology_sibling_cpumask(cpu) (per_cpu(cpu_sibling_map, cpu)) 149 #define topology_core_cpumask(cpu) (per_cpu(cpu_core_map, cpu)) 150 #define topology_core_id(cpu) (cpu_to_core_id(cpu)) 151 #define topology_die_id(cpu) (cpu_die_id(cpu)) 152 #define topology_die_cpumask(cpu) (cpu_die_mask(cpu)) 153 154 #endif 155 #endif 156 157 #ifdef CONFIG_HOTPLUG_SMT 158 #include <linux/cpu_smt.h> 159 #include <linux/cpumask.h> 160 #include <asm/cputhreads.h> 161 162 static inline bool topology_is_primary_thread(unsigned int cpu) 163 { 164 return cpu == cpu_first_thread_sibling(cpu); 165 } 166 #define topology_is_primary_thread topology_is_primary_thread 167 168 static inline bool topology_smt_thread_allowed(unsigned int cpu) 169 { 170 return cpu_thread_in_core(cpu) < cpu_smt_num_threads; 171 } 172 173 #define topology_is_core_online topology_is_core_online 174 static inline bool topology_is_core_online(unsigned int cpu) 175 { 176 int i, first_cpu = cpu_first_thread_sibling(cpu); 177 178 for (i = first_cpu; i < first_cpu + threads_per_core; ++i) { 179 if (cpu_online(i)) 180 return true; 181 } 182 return false; 183 } 184 #endif 185 186 #endif /* __KERNEL__ */ 187 #endif /* _ASM_POWERPC_TOPOLOGY_H */ 188