Heiko Carstens | dbd70fb | 2008-04-17 07:46:12 +0200 | [diff] [blame] | 1 | /* |
Heiko Carstens | dbd70fb | 2008-04-17 07:46:12 +0200 | [diff] [blame] | 2 | * Copyright IBM Corp. 2007 |
| 3 | * Author(s): Heiko Carstens <heiko.carstens@de.ibm.com> |
| 4 | */ |
| 5 | |
Martin Schwidefsky | 395d31d | 2008-12-25 13:39:50 +0100 | [diff] [blame] | 6 | #define KMSG_COMPONENT "cpu" |
| 7 | #define pr_fmt(fmt) KMSG_COMPONENT ": " fmt |
| 8 | |
Heiko Carstens | dbd70fb | 2008-04-17 07:46:12 +0200 | [diff] [blame] | 9 | #include <linux/kernel.h> |
| 10 | #include <linux/mm.h> |
| 11 | #include <linux/init.h> |
| 12 | #include <linux/device.h> |
| 13 | #include <linux/bootmem.h> |
| 14 | #include <linux/sched.h> |
| 15 | #include <linux/workqueue.h> |
| 16 | #include <linux/cpu.h> |
| 17 | #include <linux/smp.h> |
Heiko Carstens | f414f5f | 2008-12-25 13:37:59 +0100 | [diff] [blame] | 18 | #include <linux/cpuset.h> |
Heiko Carstens | dbd70fb | 2008-04-17 07:46:12 +0200 | [diff] [blame] | 19 | #include <asm/delay.h> |
| 20 | #include <asm/s390_ext.h> |
| 21 | #include <asm/sysinfo.h> |
| 22 | |
| 23 | #define CPU_BITS 64 |
Heiko Carstens | c10fde0 | 2008-04-17 07:46:13 +0200 | [diff] [blame] | 24 | #define NR_MAG 6 |
| 25 | |
| 26 | #define PTF_HORIZONTAL (0UL) |
| 27 | #define PTF_VERTICAL (1UL) |
| 28 | #define PTF_CHECK (2UL) |
Heiko Carstens | dbd70fb | 2008-04-17 07:46:12 +0200 | [diff] [blame] | 29 | |
| 30 | struct tl_cpu { |
Heiko Carstens | c10fde0 | 2008-04-17 07:46:13 +0200 | [diff] [blame] | 31 | unsigned char reserved0[4]; |
| 32 | unsigned char :6; |
| 33 | unsigned char pp:2; |
| 34 | unsigned char reserved1; |
Heiko Carstens | dbd70fb | 2008-04-17 07:46:12 +0200 | [diff] [blame] | 35 | unsigned short origin; |
| 36 | unsigned long mask[CPU_BITS / BITS_PER_LONG]; |
| 37 | }; |
| 38 | |
| 39 | struct tl_container { |
Heiko Carstens | 10d3858 | 2010-05-17 10:00:12 +0200 | [diff] [blame] | 40 | unsigned char reserved[7]; |
| 41 | unsigned char id; |
Heiko Carstens | dbd70fb | 2008-04-17 07:46:12 +0200 | [diff] [blame] | 42 | }; |
| 43 | |
| 44 | union tl_entry { |
| 45 | unsigned char nl; |
| 46 | struct tl_cpu cpu; |
| 47 | struct tl_container container; |
| 48 | }; |
| 49 | |
Heiko Carstens | dbd70fb | 2008-04-17 07:46:12 +0200 | [diff] [blame] | 50 | struct tl_info { |
| 51 | unsigned char reserved0[2]; |
| 52 | unsigned short length; |
| 53 | unsigned char mag[NR_MAG]; |
| 54 | unsigned char reserved1; |
| 55 | unsigned char mnest; |
| 56 | unsigned char reserved2[4]; |
| 57 | union tl_entry tle[0]; |
| 58 | }; |
| 59 | |
Heiko Carstens | 4cb14bc | 2010-08-31 10:28:18 +0200 | [diff] [blame] | 60 | struct mask_info { |
| 61 | struct mask_info *next; |
Heiko Carstens | 10d3858 | 2010-05-17 10:00:12 +0200 | [diff] [blame] | 62 | unsigned char id; |
Heiko Carstens | dbd70fb | 2008-04-17 07:46:12 +0200 | [diff] [blame] | 63 | cpumask_t mask; |
| 64 | }; |
| 65 | |
Heiko Carstens | c9af3fa | 2010-10-25 16:10:43 +0200 | [diff] [blame^] | 66 | static int topology_enabled = 1; |
Heiko Carstens | dbd70fb | 2008-04-17 07:46:12 +0200 | [diff] [blame] | 67 | static void topology_work_fn(struct work_struct *work); |
| 68 | static struct tl_info *tl_info; |
Heiko Carstens | dbd70fb | 2008-04-17 07:46:12 +0200 | [diff] [blame] | 69 | static int machine_has_topology; |
Heiko Carstens | dbd70fb | 2008-04-17 07:46:12 +0200 | [diff] [blame] | 70 | static struct timer_list topology_timer; |
| 71 | static void set_topology_timer(void); |
| 72 | static DECLARE_WORK(topology_work, topology_work_fn); |
Heiko Carstens | 74af283 | 2008-11-14 18:18:07 +0100 | [diff] [blame] | 73 | /* topology_lock protects the core linked list */ |
| 74 | static DEFINE_SPINLOCK(topology_lock); |
Heiko Carstens | dbd70fb | 2008-04-17 07:46:12 +0200 | [diff] [blame] | 75 | |
Heiko Carstens | 4cb14bc | 2010-08-31 10:28:18 +0200 | [diff] [blame] | 76 | static struct mask_info core_info; |
Heiko Carstens | d00aa4e | 2008-04-30 13:38:40 +0200 | [diff] [blame] | 77 | cpumask_t cpu_core_map[NR_CPUS]; |
Heiko Carstens | 10d3858 | 2010-05-17 10:00:12 +0200 | [diff] [blame] | 78 | unsigned char cpu_core_id[NR_CPUS]; |
Heiko Carstens | d00aa4e | 2008-04-30 13:38:40 +0200 | [diff] [blame] | 79 | |
Heiko Carstens | 4cb14bc | 2010-08-31 10:28:18 +0200 | [diff] [blame] | 80 | #ifdef CONFIG_SCHED_BOOK |
| 81 | static struct mask_info book_info; |
| 82 | cpumask_t cpu_book_map[NR_CPUS]; |
| 83 | unsigned char cpu_book_id[NR_CPUS]; |
| 84 | #endif |
| 85 | |
| 86 | static cpumask_t cpu_group_map(struct mask_info *info, unsigned int cpu) |
Heiko Carstens | dbd70fb | 2008-04-17 07:46:12 +0200 | [diff] [blame] | 87 | { |
Heiko Carstens | dbd70fb | 2008-04-17 07:46:12 +0200 | [diff] [blame] | 88 | cpumask_t mask; |
| 89 | |
| 90 | cpus_clear(mask); |
Heiko Carstens | 2b1a61f | 2008-12-25 13:39:23 +0100 | [diff] [blame] | 91 | if (!topology_enabled || !machine_has_topology) |
Heiko Carstens | 5439050 | 2008-12-25 13:37:57 +0100 | [diff] [blame] | 92 | return cpu_possible_map; |
Heiko Carstens | 4cb14bc | 2010-08-31 10:28:18 +0200 | [diff] [blame] | 93 | while (info) { |
| 94 | if (cpu_isset(cpu, info->mask)) { |
| 95 | mask = info->mask; |
Heiko Carstens | dbd70fb | 2008-04-17 07:46:12 +0200 | [diff] [blame] | 96 | break; |
| 97 | } |
Heiko Carstens | 4cb14bc | 2010-08-31 10:28:18 +0200 | [diff] [blame] | 98 | info = info->next; |
Heiko Carstens | dbd70fb | 2008-04-17 07:46:12 +0200 | [diff] [blame] | 99 | } |
Heiko Carstens | dbd70fb | 2008-04-17 07:46:12 +0200 | [diff] [blame] | 100 | if (cpus_empty(mask)) |
| 101 | mask = cpumask_of_cpu(cpu); |
| 102 | return mask; |
| 103 | } |
| 104 | |
Heiko Carstens | 4cb14bc | 2010-08-31 10:28:18 +0200 | [diff] [blame] | 105 | static void add_cpus_to_mask(struct tl_cpu *tl_cpu, struct mask_info *book, |
| 106 | struct mask_info *core) |
Heiko Carstens | dbd70fb | 2008-04-17 07:46:12 +0200 | [diff] [blame] | 107 | { |
| 108 | unsigned int cpu; |
| 109 | |
| 110 | for (cpu = find_first_bit(&tl_cpu->mask[0], CPU_BITS); |
| 111 | cpu < CPU_BITS; |
| 112 | cpu = find_next_bit(&tl_cpu->mask[0], CPU_BITS, cpu + 1)) |
| 113 | { |
| 114 | unsigned int rcpu, lcpu; |
| 115 | |
| 116 | rcpu = CPU_BITS - 1 - cpu + tl_cpu->origin; |
| 117 | for_each_present_cpu(lcpu) { |
Heiko Carstens | 4cb14bc | 2010-08-31 10:28:18 +0200 | [diff] [blame] | 118 | if (cpu_logical_map(lcpu) != rcpu) |
| 119 | continue; |
| 120 | #ifdef CONFIG_SCHED_BOOK |
| 121 | cpu_set(lcpu, book->mask); |
| 122 | cpu_book_id[lcpu] = book->id; |
| 123 | #endif |
| 124 | cpu_set(lcpu, core->mask); |
| 125 | cpu_core_id[lcpu] = core->id; |
| 126 | smp_cpu_polarization[lcpu] = tl_cpu->pp; |
Heiko Carstens | dbd70fb | 2008-04-17 07:46:12 +0200 | [diff] [blame] | 127 | } |
| 128 | } |
| 129 | } |
| 130 | |
Heiko Carstens | 4cb14bc | 2010-08-31 10:28:18 +0200 | [diff] [blame] | 131 | static void clear_masks(void) |
Heiko Carstens | dbd70fb | 2008-04-17 07:46:12 +0200 | [diff] [blame] | 132 | { |
Heiko Carstens | 4cb14bc | 2010-08-31 10:28:18 +0200 | [diff] [blame] | 133 | struct mask_info *info; |
Heiko Carstens | dbd70fb | 2008-04-17 07:46:12 +0200 | [diff] [blame] | 134 | |
Heiko Carstens | 4cb14bc | 2010-08-31 10:28:18 +0200 | [diff] [blame] | 135 | info = &core_info; |
| 136 | while (info) { |
| 137 | cpus_clear(info->mask); |
| 138 | info = info->next; |
Heiko Carstens | dbd70fb | 2008-04-17 07:46:12 +0200 | [diff] [blame] | 139 | } |
Heiko Carstens | 4cb14bc | 2010-08-31 10:28:18 +0200 | [diff] [blame] | 140 | #ifdef CONFIG_SCHED_BOOK |
| 141 | info = &book_info; |
| 142 | while (info) { |
| 143 | cpus_clear(info->mask); |
| 144 | info = info->next; |
| 145 | } |
| 146 | #endif |
Heiko Carstens | dbd70fb | 2008-04-17 07:46:12 +0200 | [diff] [blame] | 147 | } |
| 148 | |
| 149 | static union tl_entry *next_tle(union tl_entry *tle) |
| 150 | { |
| 151 | if (tle->nl) |
| 152 | return (union tl_entry *)((struct tl_container *)tle + 1); |
| 153 | else |
| 154 | return (union tl_entry *)((struct tl_cpu *)tle + 1); |
| 155 | } |
| 156 | |
| 157 | static void tl_to_cores(struct tl_info *info) |
| 158 | { |
Heiko Carstens | 4cb14bc | 2010-08-31 10:28:18 +0200 | [diff] [blame] | 159 | #ifdef CONFIG_SCHED_BOOK |
| 160 | struct mask_info *book = &book_info; |
| 161 | #else |
| 162 | struct mask_info *book = NULL; |
| 163 | #endif |
| 164 | struct mask_info *core = &core_info; |
Heiko Carstens | dbd70fb | 2008-04-17 07:46:12 +0200 | [diff] [blame] | 165 | union tl_entry *tle, *end; |
Heiko Carstens | 4cb14bc | 2010-08-31 10:28:18 +0200 | [diff] [blame] | 166 | |
Heiko Carstens | dbd70fb | 2008-04-17 07:46:12 +0200 | [diff] [blame] | 167 | |
Heiko Carstens | 74af283 | 2008-11-14 18:18:07 +0100 | [diff] [blame] | 168 | spin_lock_irq(&topology_lock); |
Heiko Carstens | 4cb14bc | 2010-08-31 10:28:18 +0200 | [diff] [blame] | 169 | clear_masks(); |
Heiko Carstens | c10fde0 | 2008-04-17 07:46:13 +0200 | [diff] [blame] | 170 | tle = info->tle; |
Heiko Carstens | dbd70fb | 2008-04-17 07:46:12 +0200 | [diff] [blame] | 171 | end = (union tl_entry *)((unsigned long)info + info->length); |
| 172 | while (tle < end) { |
| 173 | switch (tle->nl) { |
Heiko Carstens | 4cb14bc | 2010-08-31 10:28:18 +0200 | [diff] [blame] | 174 | #ifdef CONFIG_SCHED_BOOK |
Heiko Carstens | dbd70fb | 2008-04-17 07:46:12 +0200 | [diff] [blame] | 175 | case 2: |
Heiko Carstens | 4cb14bc | 2010-08-31 10:28:18 +0200 | [diff] [blame] | 176 | book = book->next; |
| 177 | book->id = tle->container.id; |
Heiko Carstens | dbd70fb | 2008-04-17 07:46:12 +0200 | [diff] [blame] | 178 | break; |
Heiko Carstens | 4cb14bc | 2010-08-31 10:28:18 +0200 | [diff] [blame] | 179 | #endif |
Heiko Carstens | dbd70fb | 2008-04-17 07:46:12 +0200 | [diff] [blame] | 180 | case 1: |
| 181 | core = core->next; |
Heiko Carstens | 10d3858 | 2010-05-17 10:00:12 +0200 | [diff] [blame] | 182 | core->id = tle->container.id; |
Heiko Carstens | dbd70fb | 2008-04-17 07:46:12 +0200 | [diff] [blame] | 183 | break; |
| 184 | case 0: |
Heiko Carstens | 4cb14bc | 2010-08-31 10:28:18 +0200 | [diff] [blame] | 185 | add_cpus_to_mask(&tle->cpu, book, core); |
Heiko Carstens | dbd70fb | 2008-04-17 07:46:12 +0200 | [diff] [blame] | 186 | break; |
| 187 | default: |
Heiko Carstens | 4cb14bc | 2010-08-31 10:28:18 +0200 | [diff] [blame] | 188 | clear_masks(); |
Heiko Carstens | dbd70fb | 2008-04-17 07:46:12 +0200 | [diff] [blame] | 189 | machine_has_topology = 0; |
Julia Lawall | d7015c1 | 2010-04-09 13:42:58 +0200 | [diff] [blame] | 190 | goto out; |
Heiko Carstens | dbd70fb | 2008-04-17 07:46:12 +0200 | [diff] [blame] | 191 | } |
| 192 | tle = next_tle(tle); |
| 193 | } |
Julia Lawall | d7015c1 | 2010-04-09 13:42:58 +0200 | [diff] [blame] | 194 | out: |
Heiko Carstens | 74af283 | 2008-11-14 18:18:07 +0100 | [diff] [blame] | 195 | spin_unlock_irq(&topology_lock); |
Heiko Carstens | dbd70fb | 2008-04-17 07:46:12 +0200 | [diff] [blame] | 196 | } |
| 197 | |
Heiko Carstens | c10fde0 | 2008-04-17 07:46:13 +0200 | [diff] [blame] | 198 | static void topology_update_polarization_simple(void) |
| 199 | { |
| 200 | int cpu; |
| 201 | |
| 202 | mutex_lock(&smp_cpu_state_mutex); |
Heiko Carstens | 5439050 | 2008-12-25 13:37:57 +0100 | [diff] [blame] | 203 | for_each_possible_cpu(cpu) |
Heiko Carstens | c10fde0 | 2008-04-17 07:46:13 +0200 | [diff] [blame] | 204 | smp_cpu_polarization[cpu] = POLARIZATION_HRZ; |
| 205 | mutex_unlock(&smp_cpu_state_mutex); |
| 206 | } |
| 207 | |
| 208 | static int ptf(unsigned long fc) |
Heiko Carstens | dbd70fb | 2008-04-17 07:46:12 +0200 | [diff] [blame] | 209 | { |
| 210 | int rc; |
| 211 | |
| 212 | asm volatile( |
| 213 | " .insn rre,0xb9a20000,%1,%1\n" |
| 214 | " ipm %0\n" |
| 215 | " srl %0,28\n" |
| 216 | : "=d" (rc) |
Heiko Carstens | c10fde0 | 2008-04-17 07:46:13 +0200 | [diff] [blame] | 217 | : "d" (fc) : "cc"); |
| 218 | return rc; |
| 219 | } |
| 220 | |
| 221 | int topology_set_cpu_management(int fc) |
| 222 | { |
| 223 | int cpu; |
| 224 | int rc; |
| 225 | |
| 226 | if (!machine_has_topology) |
| 227 | return -EOPNOTSUPP; |
| 228 | if (fc) |
| 229 | rc = ptf(PTF_VERTICAL); |
| 230 | else |
| 231 | rc = ptf(PTF_HORIZONTAL); |
| 232 | if (rc) |
| 233 | return -EBUSY; |
Heiko Carstens | 5439050 | 2008-12-25 13:37:57 +0100 | [diff] [blame] | 234 | for_each_possible_cpu(cpu) |
Heiko Carstens | c10fde0 | 2008-04-17 07:46:13 +0200 | [diff] [blame] | 235 | smp_cpu_polarization[cpu] = POLARIZATION_UNKNWN; |
Heiko Carstens | dbd70fb | 2008-04-17 07:46:12 +0200 | [diff] [blame] | 236 | return rc; |
| 237 | } |
| 238 | |
Heiko Carstens | d00aa4e | 2008-04-30 13:38:40 +0200 | [diff] [blame] | 239 | static void update_cpu_core_map(void) |
| 240 | { |
Heiko Carstens | 4cb14bc | 2010-08-31 10:28:18 +0200 | [diff] [blame] | 241 | unsigned long flags; |
Heiko Carstens | d00aa4e | 2008-04-30 13:38:40 +0200 | [diff] [blame] | 242 | int cpu; |
| 243 | |
Heiko Carstens | 4cb14bc | 2010-08-31 10:28:18 +0200 | [diff] [blame] | 244 | spin_lock_irqsave(&topology_lock, flags); |
| 245 | for_each_possible_cpu(cpu) { |
| 246 | cpu_core_map[cpu] = cpu_group_map(&core_info, cpu); |
| 247 | #ifdef CONFIG_SCHED_BOOK |
| 248 | cpu_book_map[cpu] = cpu_group_map(&book_info, cpu); |
| 249 | #endif |
| 250 | } |
| 251 | spin_unlock_irqrestore(&topology_lock, flags); |
| 252 | } |
| 253 | |
| 254 | static void store_topology(struct tl_info *info) |
| 255 | { |
| 256 | #ifdef CONFIG_SCHED_BOOK |
| 257 | int rc; |
| 258 | |
| 259 | rc = stsi(info, 15, 1, 3); |
| 260 | if (rc != -ENOSYS) |
| 261 | return; |
| 262 | #endif |
| 263 | stsi(info, 15, 1, 2); |
Heiko Carstens | d00aa4e | 2008-04-30 13:38:40 +0200 | [diff] [blame] | 264 | } |
| 265 | |
Heiko Carstens | ee79d1b | 2008-12-09 18:49:50 +0100 | [diff] [blame] | 266 | int arch_update_cpu_topology(void) |
Heiko Carstens | dbd70fb | 2008-04-17 07:46:12 +0200 | [diff] [blame] | 267 | { |
| 268 | struct tl_info *info = tl_info; |
| 269 | struct sys_device *sysdev; |
| 270 | int cpu; |
| 271 | |
Heiko Carstens | c10fde0 | 2008-04-17 07:46:13 +0200 | [diff] [blame] | 272 | if (!machine_has_topology) { |
Heiko Carstens | d00aa4e | 2008-04-30 13:38:40 +0200 | [diff] [blame] | 273 | update_cpu_core_map(); |
Heiko Carstens | c10fde0 | 2008-04-17 07:46:13 +0200 | [diff] [blame] | 274 | topology_update_polarization_simple(); |
Heiko Carstens | ee79d1b | 2008-12-09 18:49:50 +0100 | [diff] [blame] | 275 | return 0; |
Heiko Carstens | c10fde0 | 2008-04-17 07:46:13 +0200 | [diff] [blame] | 276 | } |
Heiko Carstens | 4cb14bc | 2010-08-31 10:28:18 +0200 | [diff] [blame] | 277 | store_topology(info); |
Heiko Carstens | dbd70fb | 2008-04-17 07:46:12 +0200 | [diff] [blame] | 278 | tl_to_cores(info); |
Heiko Carstens | d00aa4e | 2008-04-30 13:38:40 +0200 | [diff] [blame] | 279 | update_cpu_core_map(); |
Heiko Carstens | dbd70fb | 2008-04-17 07:46:12 +0200 | [diff] [blame] | 280 | for_each_online_cpu(cpu) { |
| 281 | sysdev = get_cpu_sysdev(cpu); |
| 282 | kobject_uevent(&sysdev->kobj, KOBJ_CHANGE); |
| 283 | } |
Heiko Carstens | ee79d1b | 2008-12-09 18:49:50 +0100 | [diff] [blame] | 284 | return 1; |
Heiko Carstens | dbd70fb | 2008-04-17 07:46:12 +0200 | [diff] [blame] | 285 | } |
| 286 | |
Heiko Carstens | fd781fa | 2008-04-30 13:38:41 +0200 | [diff] [blame] | 287 | static void topology_work_fn(struct work_struct *work) |
| 288 | { |
Heiko Carstens | f414f5f | 2008-12-25 13:37:59 +0100 | [diff] [blame] | 289 | rebuild_sched_domains(); |
Heiko Carstens | dbd70fb | 2008-04-17 07:46:12 +0200 | [diff] [blame] | 290 | } |
| 291 | |
Heiko Carstens | c10fde0 | 2008-04-17 07:46:13 +0200 | [diff] [blame] | 292 | void topology_schedule_update(void) |
| 293 | { |
| 294 | schedule_work(&topology_work); |
| 295 | } |
| 296 | |
Heiko Carstens | dbd70fb | 2008-04-17 07:46:12 +0200 | [diff] [blame] | 297 | static void topology_timer_fn(unsigned long ignored) |
| 298 | { |
Heiko Carstens | c10fde0 | 2008-04-17 07:46:13 +0200 | [diff] [blame] | 299 | if (ptf(PTF_CHECK)) |
| 300 | topology_schedule_update(); |
Heiko Carstens | dbd70fb | 2008-04-17 07:46:12 +0200 | [diff] [blame] | 301 | set_topology_timer(); |
| 302 | } |
| 303 | |
| 304 | static void set_topology_timer(void) |
| 305 | { |
| 306 | topology_timer.function = topology_timer_fn; |
| 307 | topology_timer.data = 0; |
| 308 | topology_timer.expires = jiffies + 60 * HZ; |
| 309 | add_timer(&topology_timer); |
| 310 | } |
| 311 | |
Heiko Carstens | 2b1a61f | 2008-12-25 13:39:23 +0100 | [diff] [blame] | 312 | static int __init early_parse_topology(char *p) |
Heiko Carstens | dbd70fb | 2008-04-17 07:46:12 +0200 | [diff] [blame] | 313 | { |
Heiko Carstens | c9af3fa | 2010-10-25 16:10:43 +0200 | [diff] [blame^] | 314 | if (strncmp(p, "off", 3)) |
Heiko Carstens | 2b1a61f | 2008-12-25 13:39:23 +0100 | [diff] [blame] | 315 | return 0; |
Heiko Carstens | c9af3fa | 2010-10-25 16:10:43 +0200 | [diff] [blame^] | 316 | topology_enabled = 0; |
Heiko Carstens | 2b1a61f | 2008-12-25 13:39:23 +0100 | [diff] [blame] | 317 | return 0; |
Heiko Carstens | dbd70fb | 2008-04-17 07:46:12 +0200 | [diff] [blame] | 318 | } |
Heiko Carstens | 2b1a61f | 2008-12-25 13:39:23 +0100 | [diff] [blame] | 319 | early_param("topology", early_parse_topology); |
Heiko Carstens | dbd70fb | 2008-04-17 07:46:12 +0200 | [diff] [blame] | 320 | |
| 321 | static int __init init_topology_update(void) |
| 322 | { |
| 323 | int rc; |
| 324 | |
Heiko Carstens | d00aa4e | 2008-04-30 13:38:40 +0200 | [diff] [blame] | 325 | rc = 0; |
Heiko Carstens | c10fde0 | 2008-04-17 07:46:13 +0200 | [diff] [blame] | 326 | if (!machine_has_topology) { |
| 327 | topology_update_polarization_simple(); |
Heiko Carstens | d00aa4e | 2008-04-30 13:38:40 +0200 | [diff] [blame] | 328 | goto out; |
Heiko Carstens | c10fde0 | 2008-04-17 07:46:13 +0200 | [diff] [blame] | 329 | } |
| 330 | init_timer_deferrable(&topology_timer); |
Heiko Carstens | 349f1b6 | 2008-12-25 13:39:24 +0100 | [diff] [blame] | 331 | set_topology_timer(); |
Heiko Carstens | d00aa4e | 2008-04-30 13:38:40 +0200 | [diff] [blame] | 332 | out: |
| 333 | update_cpu_core_map(); |
| 334 | return rc; |
Heiko Carstens | dbd70fb | 2008-04-17 07:46:12 +0200 | [diff] [blame] | 335 | } |
| 336 | __initcall(init_topology_update); |
| 337 | |
Heiko Carstens | 4cb14bc | 2010-08-31 10:28:18 +0200 | [diff] [blame] | 338 | static void alloc_masks(struct tl_info *info, struct mask_info *mask, int offset) |
| 339 | { |
| 340 | int i, nr_masks; |
| 341 | |
| 342 | nr_masks = info->mag[NR_MAG - offset]; |
| 343 | for (i = 0; i < info->mnest - offset; i++) |
| 344 | nr_masks *= info->mag[NR_MAG - offset - 1 - i]; |
| 345 | nr_masks = max(nr_masks, 1); |
| 346 | for (i = 0; i < nr_masks; i++) { |
| 347 | mask->next = alloc_bootmem(sizeof(struct mask_info)); |
| 348 | mask = mask->next; |
| 349 | } |
| 350 | } |
| 351 | |
Heiko Carstens | dbd70fb | 2008-04-17 07:46:12 +0200 | [diff] [blame] | 352 | void __init s390_init_cpu_topology(void) |
| 353 | { |
| 354 | unsigned long long facility_bits; |
| 355 | struct tl_info *info; |
Heiko Carstens | dbd70fb | 2008-04-17 07:46:12 +0200 | [diff] [blame] | 356 | int i; |
| 357 | |
| 358 | if (stfle(&facility_bits, 1) <= 0) |
| 359 | return; |
| 360 | if (!(facility_bits & (1ULL << 52)) || !(facility_bits & (1ULL << 61))) |
| 361 | return; |
| 362 | machine_has_topology = 1; |
| 363 | |
Heiko Carstens | dbd70fb | 2008-04-17 07:46:12 +0200 | [diff] [blame] | 364 | tl_info = alloc_bootmem_pages(PAGE_SIZE); |
Heiko Carstens | dbd70fb | 2008-04-17 07:46:12 +0200 | [diff] [blame] | 365 | info = tl_info; |
Heiko Carstens | 4cb14bc | 2010-08-31 10:28:18 +0200 | [diff] [blame] | 366 | store_topology(info); |
Martin Schwidefsky | 395d31d | 2008-12-25 13:39:50 +0100 | [diff] [blame] | 367 | pr_info("The CPU configuration topology of the machine is:"); |
Heiko Carstens | dbd70fb | 2008-04-17 07:46:12 +0200 | [diff] [blame] | 368 | for (i = 0; i < NR_MAG; i++) |
| 369 | printk(" %d", info->mag[i]); |
| 370 | printk(" / %d\n", info->mnest); |
Heiko Carstens | 4cb14bc | 2010-08-31 10:28:18 +0200 | [diff] [blame] | 371 | alloc_masks(info, &core_info, 2); |
| 372 | #ifdef CONFIG_SCHED_BOOK |
| 373 | alloc_masks(info, &book_info, 3); |
| 374 | #endif |
Heiko Carstens | dbd70fb | 2008-04-17 07:46:12 +0200 | [diff] [blame] | 375 | } |