]>
Commit | Line | Data |
---|---|---|
ac23d4ee JS |
1 | /* |
2 | * This file is subject to the terms and conditions of the GNU General Public | |
3 | * License. See the file "COPYING" in the main directory of this archive | |
4 | * for more details. | |
5 | * | |
6 | * SGI UV APIC functions (note: not an Intel compatible APIC) | |
7 | * | |
9f5314fb | 8 | * Copyright (C) 2007-2008 Silicon Graphics, Inc. All rights reserved. |
ac23d4ee | 9 | */ |
ac23d4ee | 10 | #include <linux/cpumask.h> |
0b1da1c8 IM |
11 | #include <linux/hardirq.h> |
12 | #include <linux/proc_fs.h> | |
13 | #include <linux/threads.h> | |
14 | #include <linux/kernel.h> | |
15 | #include <linux/module.h> | |
ac23d4ee | 16 | #include <linux/string.h> |
ac23d4ee | 17 | #include <linux/ctype.h> |
ac23d4ee | 18 | #include <linux/sched.h> |
7f1baa06 | 19 | #include <linux/timer.h> |
0b1da1c8 IM |
20 | #include <linux/cpu.h> |
21 | #include <linux/init.h> | |
27229ca6 | 22 | #include <linux/io.h> |
0b1da1c8 | 23 | |
ac23d4ee JS |
24 | #include <asm/uv/uv_mmrs.h> |
25 | #include <asm/uv/uv_hub.h> | |
0b1da1c8 IM |
26 | #include <asm/current.h> |
27 | #include <asm/pgtable.h> | |
7019cc2d | 28 | #include <asm/uv/bios.h> |
0b1da1c8 IM |
29 | #include <asm/uv/uv.h> |
30 | #include <asm/apic.h> | |
31 | #include <asm/ipi.h> | |
32 | #include <asm/smp.h> | |
fd12a0d6 | 33 | #include <asm/x86_init.h> |
ac23d4ee | 34 | |
510b3725 YL |
35 | DEFINE_PER_CPU(int, x2apic_extra_bits); |
36 | ||
1b9b89e7 | 37 | static enum uv_system_type uv_system_type; |
fd12a0d6 JS |
38 | static u64 gru_start_paddr, gru_end_paddr; |
39 | ||
eb41c8be | 40 | static inline bool is_GRU_range(u64 start, u64 end) |
fd12a0d6 JS |
41 | { |
42 | return start >= gru_start_paddr && end < gru_end_paddr; | |
43 | } | |
44 | ||
eb41c8be | 45 | static bool uv_is_untracked_pat_range(u64 start, u64 end) |
fd12a0d6 JS |
46 | { |
47 | return is_ISA_range(start, end) || is_GRU_range(start, end); | |
48 | } | |
1b9b89e7 | 49 | |
27229ca6 JS |
50 | static int early_get_nodeid(void) |
51 | { | |
52 | union uvh_node_id_u node_id; | |
53 | unsigned long *mmr; | |
54 | ||
55 | mmr = early_ioremap(UV_LOCAL_MMR_BASE | UVH_NODE_ID, sizeof(*mmr)); | |
56 | node_id.v = *mmr; | |
57 | early_iounmap(mmr, sizeof(*mmr)); | |
58 | return node_id.s.node_id; | |
59 | } | |
60 | ||
52459ab9 | 61 | static int __init uv_acpi_madt_oem_check(char *oem_id, char *oem_table_id) |
1b9b89e7 YL |
62 | { |
63 | if (!strcmp(oem_id, "SGI")) { | |
fd12a0d6 | 64 | x86_platform.is_untracked_pat_range = uv_is_untracked_pat_range; |
1b9b89e7 YL |
65 | if (!strcmp(oem_table_id, "UVL")) |
66 | uv_system_type = UV_LEGACY_APIC; | |
67 | else if (!strcmp(oem_table_id, "UVX")) | |
68 | uv_system_type = UV_X2APIC; | |
69 | else if (!strcmp(oem_table_id, "UVH")) { | |
27229ca6 JS |
70 | __get_cpu_var(x2apic_extra_bits) = |
71 | early_get_nodeid() << (UV_APIC_PNODE_SHIFT - 1); | |
1b9b89e7 YL |
72 | uv_system_type = UV_NON_UNIQUE_APIC; |
73 | return 1; | |
74 | } | |
75 | } | |
76 | return 0; | |
77 | } | |
78 | ||
79 | enum uv_system_type get_uv_system_type(void) | |
80 | { | |
81 | return uv_system_type; | |
82 | } | |
83 | ||
84 | int is_uv_system(void) | |
85 | { | |
86 | return uv_system_type != UV_NONE; | |
87 | } | |
8067794b | 88 | EXPORT_SYMBOL_GPL(is_uv_system); |
1b9b89e7 | 89 | |
ac23d4ee JS |
90 | DEFINE_PER_CPU(struct uv_hub_info_s, __uv_hub_info); |
91 | EXPORT_PER_CPU_SYMBOL_GPL(__uv_hub_info); | |
92 | ||
93 | struct uv_blade_info *uv_blade_info; | |
94 | EXPORT_SYMBOL_GPL(uv_blade_info); | |
95 | ||
96 | short *uv_node_to_blade; | |
97 | EXPORT_SYMBOL_GPL(uv_node_to_blade); | |
98 | ||
99 | short *uv_cpu_to_blade; | |
100 | EXPORT_SYMBOL_GPL(uv_cpu_to_blade); | |
101 | ||
102 | short uv_possible_blades; | |
103 | EXPORT_SYMBOL_GPL(uv_possible_blades); | |
104 | ||
7019cc2d RA |
105 | unsigned long sn_rtc_cycles_per_second; |
106 | EXPORT_SYMBOL(sn_rtc_cycles_per_second); | |
107 | ||
ac23d4ee JS |
108 | /* Start with all IRQs pointing to boot CPU. IRQ balancing will shift them. */ |
109 | ||
bcda016e | 110 | static const struct cpumask *uv_target_cpus(void) |
ac23d4ee | 111 | { |
bcda016e | 112 | return cpumask_of(0); |
ac23d4ee JS |
113 | } |
114 | ||
bcda016e | 115 | static void uv_vector_allocation_domain(int cpu, struct cpumask *retmask) |
ac23d4ee | 116 | { |
bcda016e MT |
117 | cpumask_clear(retmask); |
118 | cpumask_set_cpu(cpu, retmask); | |
ac23d4ee JS |
119 | } |
120 | ||
667c5296 | 121 | static int __cpuinit uv_wakeup_secondary(int phys_apicid, unsigned long start_rip) |
ac23d4ee | 122 | { |
0b1da1c8 | 123 | #ifdef CONFIG_SMP |
ac23d4ee | 124 | unsigned long val; |
9f5314fb | 125 | int pnode; |
ac23d4ee | 126 | |
9f5314fb | 127 | pnode = uv_apicid_to_pnode(phys_apicid); |
ac23d4ee JS |
128 | val = (1UL << UVH_IPI_INT_SEND_SHFT) | |
129 | (phys_apicid << UVH_IPI_INT_APIC_ID_SHFT) | | |
2b6163bf | 130 | ((start_rip << UVH_IPI_INT_VECTOR_SHFT) >> 12) | |
34d05591 | 131 | APIC_DM_INIT; |
9f5314fb | 132 | uv_write_global_mmr64(pnode, UVH_IPI_INT, val); |
34d05591 JS |
133 | mdelay(10); |
134 | ||
135 | val = (1UL << UVH_IPI_INT_SEND_SHFT) | | |
136 | (phys_apicid << UVH_IPI_INT_APIC_ID_SHFT) | | |
2b6163bf | 137 | ((start_rip << UVH_IPI_INT_VECTOR_SHFT) >> 12) | |
34d05591 | 138 | APIC_DM_STARTUP; |
9f5314fb | 139 | uv_write_global_mmr64(pnode, UVH_IPI_INT, val); |
2b6163bf YL |
140 | |
141 | atomic_set(&init_deasserted, 1); | |
0b1da1c8 | 142 | #endif |
ac23d4ee JS |
143 | return 0; |
144 | } | |
145 | ||
146 | static void uv_send_IPI_one(int cpu, int vector) | |
147 | { | |
66666e50 | 148 | unsigned long apicid; |
9f5314fb | 149 | int pnode; |
ac23d4ee | 150 | |
1e0b5d00 | 151 | apicid = per_cpu(x86_cpu_to_apicid, cpu); |
9f5314fb | 152 | pnode = uv_apicid_to_pnode(apicid); |
66666e50 | 153 | uv_hub_send_ipi(pnode, apicid, vector); |
ac23d4ee JS |
154 | } |
155 | ||
bcda016e | 156 | static void uv_send_IPI_mask(const struct cpumask *mask, int vector) |
ac23d4ee JS |
157 | { |
158 | unsigned int cpu; | |
159 | ||
bcda016e | 160 | for_each_cpu(cpu, mask) |
e7986739 MT |
161 | uv_send_IPI_one(cpu, vector); |
162 | } | |
163 | ||
bcda016e | 164 | static void uv_send_IPI_mask_allbutself(const struct cpumask *mask, int vector) |
e7986739 | 165 | { |
e7986739 | 166 | unsigned int this_cpu = smp_processor_id(); |
dac5f412 | 167 | unsigned int cpu; |
e7986739 | 168 | |
dac5f412 | 169 | for_each_cpu(cpu, mask) { |
e7986739 | 170 | if (cpu != this_cpu) |
ac23d4ee | 171 | uv_send_IPI_one(cpu, vector); |
dac5f412 | 172 | } |
ac23d4ee JS |
173 | } |
174 | ||
175 | static void uv_send_IPI_allbutself(int vector) | |
176 | { | |
e7986739 | 177 | unsigned int this_cpu = smp_processor_id(); |
dac5f412 | 178 | unsigned int cpu; |
ac23d4ee | 179 | |
dac5f412 | 180 | for_each_online_cpu(cpu) { |
e7986739 MT |
181 | if (cpu != this_cpu) |
182 | uv_send_IPI_one(cpu, vector); | |
dac5f412 | 183 | } |
ac23d4ee JS |
184 | } |
185 | ||
186 | static void uv_send_IPI_all(int vector) | |
187 | { | |
bcda016e | 188 | uv_send_IPI_mask(cpu_online_mask, vector); |
ac23d4ee JS |
189 | } |
190 | ||
191 | static int uv_apic_id_registered(void) | |
192 | { | |
193 | return 1; | |
194 | } | |
195 | ||
277d1f58 | 196 | static void uv_init_apic_ldr(void) |
5c520a67 SS |
197 | { |
198 | } | |
199 | ||
bcda016e | 200 | static unsigned int uv_cpu_mask_to_apicid(const struct cpumask *cpumask) |
ac23d4ee | 201 | { |
ac23d4ee JS |
202 | /* |
203 | * We're using fixed IRQ delivery, can only return one phys APIC ID. | |
204 | * May as well be the first. | |
205 | */ | |
debccb3e IM |
206 | int cpu = cpumask_first(cpumask); |
207 | ||
247bc6ca | 208 | if ((unsigned)cpu < nr_cpu_ids) |
ac23d4ee JS |
209 | return per_cpu(x86_cpu_to_apicid, cpu); |
210 | else | |
211 | return BAD_APICID; | |
212 | } | |
213 | ||
debccb3e IM |
214 | static unsigned int |
215 | uv_cpu_mask_to_apicid_and(const struct cpumask *cpumask, | |
216 | const struct cpumask *andmask) | |
95d313cf MT |
217 | { |
218 | int cpu; | |
219 | ||
220 | /* | |
221 | * We're using fixed IRQ delivery, can only return one phys APIC ID. | |
222 | * May as well be the first. | |
223 | */ | |
debccb3e | 224 | for_each_cpu_and(cpu, cpumask, andmask) { |
a775a38b MT |
225 | if (cpumask_test_cpu(cpu, cpu_online_mask)) |
226 | break; | |
debccb3e | 227 | } |
6eeb7c5a MT |
228 | if (cpu < nr_cpu_ids) |
229 | return per_cpu(x86_cpu_to_apicid, cpu); | |
debccb3e | 230 | |
95d313cf MT |
231 | return BAD_APICID; |
232 | } | |
233 | ||
ca6c8ed4 | 234 | static unsigned int x2apic_get_apic_id(unsigned long x) |
0c81c746 SS |
235 | { |
236 | unsigned int id; | |
237 | ||
238 | WARN_ON(preemptible() && num_online_cpus() > 1); | |
f910a9dc | 239 | id = x | __get_cpu_var(x2apic_extra_bits); |
0c81c746 SS |
240 | |
241 | return id; | |
242 | } | |
243 | ||
1b9b89e7 | 244 | static unsigned long set_apic_id(unsigned int id) |
f910a9dc YL |
245 | { |
246 | unsigned long x; | |
247 | ||
248 | /* maskout x2apic_extra_bits ? */ | |
249 | x = id; | |
250 | return x; | |
251 | } | |
252 | ||
253 | static unsigned int uv_read_apic_id(void) | |
254 | { | |
255 | ||
ca6c8ed4 | 256 | return x2apic_get_apic_id(apic_read(APIC_ID)); |
f910a9dc YL |
257 | } |
258 | ||
d4c9a9f3 | 259 | static int uv_phys_pkg_id(int initial_apicid, int index_msb) |
ac23d4ee | 260 | { |
0c81c746 | 261 | return uv_read_apic_id() >> index_msb; |
ac23d4ee JS |
262 | } |
263 | ||
ac23d4ee JS |
264 | static void uv_send_IPI_self(int vector) |
265 | { | |
266 | apic_write(APIC_SELF_IPI, vector); | |
267 | } | |
ac23d4ee | 268 | |
52459ab9 | 269 | struct apic __refdata apic_x2apic_uv_x = { |
c7967329 IM |
270 | |
271 | .name = "UV large system", | |
272 | .probe = NULL, | |
273 | .acpi_madt_oem_check = uv_acpi_madt_oem_check, | |
274 | .apic_id_registered = uv_apic_id_registered, | |
275 | ||
f8987a10 | 276 | .irq_delivery_mode = dest_Fixed, |
c5997fa8 | 277 | .irq_dest_mode = 0, /* physical */ |
c7967329 IM |
278 | |
279 | .target_cpus = uv_target_cpus, | |
08125d3e | 280 | .disable_esr = 0, |
bdb1a9b6 | 281 | .dest_logical = APIC_DEST_LOGICAL, |
c7967329 IM |
282 | .check_apicid_used = NULL, |
283 | .check_apicid_present = NULL, | |
284 | ||
c7967329 IM |
285 | .vector_allocation_domain = uv_vector_allocation_domain, |
286 | .init_apic_ldr = uv_init_apic_ldr, | |
287 | ||
288 | .ioapic_phys_id_map = NULL, | |
289 | .setup_apic_routing = NULL, | |
290 | .multi_timer_check = NULL, | |
291 | .apicid_to_node = NULL, | |
292 | .cpu_to_logical_apicid = NULL, | |
a21769a4 | 293 | .cpu_present_to_apicid = default_cpu_present_to_apicid, |
c7967329 IM |
294 | .apicid_to_cpu_present = NULL, |
295 | .setup_portio_remap = NULL, | |
a27a6210 | 296 | .check_phys_apicid_present = default_check_phys_apicid_present, |
c7967329 | 297 | .enable_apic_mode = NULL, |
d4c9a9f3 | 298 | .phys_pkg_id = uv_phys_pkg_id, |
c7967329 IM |
299 | .mps_oem_check = NULL, |
300 | ||
ca6c8ed4 | 301 | .get_apic_id = x2apic_get_apic_id, |
c7967329 IM |
302 | .set_apic_id = set_apic_id, |
303 | .apic_id_mask = 0xFFFFFFFFu, | |
304 | ||
305 | .cpu_mask_to_apicid = uv_cpu_mask_to_apicid, | |
306 | .cpu_mask_to_apicid_and = uv_cpu_mask_to_apicid_and, | |
307 | ||
308 | .send_IPI_mask = uv_send_IPI_mask, | |
309 | .send_IPI_mask_allbutself = uv_send_IPI_mask_allbutself, | |
310 | .send_IPI_allbutself = uv_send_IPI_allbutself, | |
311 | .send_IPI_all = uv_send_IPI_all, | |
312 | .send_IPI_self = uv_send_IPI_self, | |
313 | ||
1f5bcabf | 314 | .wakeup_secondary_cpu = uv_wakeup_secondary, |
abfa584c IM |
315 | .trampoline_phys_low = DEFAULT_TRAMPOLINE_PHYS_LOW, |
316 | .trampoline_phys_high = DEFAULT_TRAMPOLINE_PHYS_HIGH, | |
c7967329 IM |
317 | .wait_for_init_deassert = NULL, |
318 | .smp_callin_clear_local_apic = NULL, | |
c7967329 | 319 | .inquire_remote_apic = NULL, |
c1eeb2de YL |
320 | |
321 | .read = native_apic_msr_read, | |
322 | .write = native_apic_msr_write, | |
323 | .icr_read = native_x2apic_icr_read, | |
324 | .icr_write = native_x2apic_icr_write, | |
325 | .wait_icr_idle = native_x2apic_wait_icr_idle, | |
326 | .safe_wait_icr_idle = native_safe_x2apic_wait_icr_idle, | |
ac23d4ee JS |
327 | }; |
328 | ||
9f5314fb | 329 | static __cpuinit void set_x2apic_extra_bits(int pnode) |
ac23d4ee | 330 | { |
9f5314fb | 331 | __get_cpu_var(x2apic_extra_bits) = (pnode << 6); |
ac23d4ee JS |
332 | } |
333 | ||
334 | /* | |
335 | * Called on boot cpu. | |
336 | */ | |
9f5314fb JS |
337 | static __init int boot_pnode_to_blade(int pnode) |
338 | { | |
339 | int blade; | |
340 | ||
341 | for (blade = 0; blade < uv_num_possible_blades(); blade++) | |
342 | if (pnode == uv_blade_info[blade].pnode) | |
343 | return blade; | |
344 | BUG(); | |
345 | } | |
346 | ||
347 | struct redir_addr { | |
348 | unsigned long redirect; | |
349 | unsigned long alias; | |
350 | }; | |
351 | ||
352 | #define DEST_SHIFT UVH_RH_GAM_ALIAS210_REDIRECT_CONFIG_0_MMR_DEST_BASE_SHFT | |
353 | ||
354 | static __initdata struct redir_addr redir_addrs[] = { | |
355 | {UVH_RH_GAM_ALIAS210_REDIRECT_CONFIG_0_MMR, UVH_SI_ALIAS0_OVERLAY_CONFIG}, | |
356 | {UVH_RH_GAM_ALIAS210_REDIRECT_CONFIG_1_MMR, UVH_SI_ALIAS1_OVERLAY_CONFIG}, | |
357 | {UVH_RH_GAM_ALIAS210_REDIRECT_CONFIG_2_MMR, UVH_SI_ALIAS2_OVERLAY_CONFIG}, | |
358 | }; | |
359 | ||
360 | static __init void get_lowmem_redirect(unsigned long *base, unsigned long *size) | |
361 | { | |
362 | union uvh_si_alias0_overlay_config_u alias; | |
363 | union uvh_rh_gam_alias210_redirect_config_2_mmr_u redirect; | |
364 | int i; | |
365 | ||
366 | for (i = 0; i < ARRAY_SIZE(redir_addrs); i++) { | |
367 | alias.v = uv_read_local_mmr(redir_addrs[i].alias); | |
368 | if (alias.s.base == 0) { | |
369 | *size = (1UL << alias.s.m_alias); | |
370 | redirect.v = uv_read_local_mmr(redir_addrs[i].redirect); | |
371 | *base = (unsigned long)redirect.s.dest_base << DEST_SHIFT; | |
372 | return; | |
373 | } | |
374 | } | |
375 | BUG(); | |
376 | } | |
377 | ||
83f5d894 JS |
378 | enum map_type {map_wb, map_uc}; |
379 | ||
d2f904bb JS |
380 | static __init void map_high(char *id, unsigned long base, int shift, |
381 | int max_pnode, enum map_type map_type) | |
83f5d894 JS |
382 | { |
383 | unsigned long bytes, paddr; | |
384 | ||
385 | paddr = base << shift; | |
d2f904bb | 386 | bytes = (1UL << shift) * (max_pnode + 1); |
83f5d894 | 387 | printk(KERN_INFO "UV: Map %s_HI 0x%lx - 0x%lx\n", id, paddr, |
0b1da1c8 | 388 | paddr + bytes); |
83f5d894 JS |
389 | if (map_type == map_uc) |
390 | init_extra_mapping_uc(paddr, bytes); | |
391 | else | |
392 | init_extra_mapping_wb(paddr, bytes); | |
393 | ||
394 | } | |
395 | static __init void map_gru_high(int max_pnode) | |
396 | { | |
397 | union uvh_rh_gam_gru_overlay_config_mmr_u gru; | |
398 | int shift = UVH_RH_GAM_GRU_OVERLAY_CONFIG_MMR_BASE_SHFT; | |
399 | ||
400 | gru.v = uv_read_local_mmr(UVH_RH_GAM_GRU_OVERLAY_CONFIG_MMR); | |
fd12a0d6 | 401 | if (gru.s.enable) { |
d2f904bb | 402 | map_high("GRU", gru.s.base, shift, max_pnode, map_wb); |
fd12a0d6 JS |
403 | gru_start_paddr = ((u64)gru.s.base << shift); |
404 | gru_end_paddr = gru_start_paddr + (1UL << shift) * (max_pnode + 1); | |
405 | ||
406 | } | |
83f5d894 JS |
407 | } |
408 | ||
daf7b9c9 JS |
409 | static __init void map_mmr_high(int max_pnode) |
410 | { | |
411 | union uvh_rh_gam_mmr_overlay_config_mmr_u mmr; | |
412 | int shift = UVH_RH_GAM_MMR_OVERLAY_CONFIG_MMR_BASE_SHFT; | |
413 | ||
414 | mmr.v = uv_read_local_mmr(UVH_RH_GAM_MMR_OVERLAY_CONFIG_MMR); | |
415 | if (mmr.s.enable) | |
416 | map_high("MMR", mmr.s.base, shift, max_pnode, map_uc); | |
417 | } | |
418 | ||
83f5d894 JS |
419 | static __init void map_mmioh_high(int max_pnode) |
420 | { | |
421 | union uvh_rh_gam_mmioh_overlay_config_mmr_u mmioh; | |
422 | int shift = UVH_RH_GAM_MMIOH_OVERLAY_CONFIG_MMR_BASE_SHFT; | |
423 | ||
424 | mmioh.v = uv_read_local_mmr(UVH_RH_GAM_MMIOH_OVERLAY_CONFIG_MMR); | |
425 | if (mmioh.s.enable) | |
d2f904bb | 426 | map_high("MMIOH", mmioh.s.base, shift, max_pnode, map_uc); |
83f5d894 JS |
427 | } |
428 | ||
7019cc2d RA |
429 | static __init void uv_rtc_init(void) |
430 | { | |
922402f1 RA |
431 | long status; |
432 | u64 ticks_per_sec; | |
7019cc2d | 433 | |
922402f1 RA |
434 | status = uv_bios_freq_base(BIOS_FREQ_BASE_REALTIME_CLOCK, |
435 | &ticks_per_sec); | |
436 | if (status != BIOS_STATUS_SUCCESS || ticks_per_sec < 100000) { | |
7019cc2d RA |
437 | printk(KERN_WARNING |
438 | "unable to determine platform RTC clock frequency, " | |
439 | "guessing.\n"); | |
440 | /* BIOS gives wrong value for clock freq. so guess */ | |
441 | sn_rtc_cycles_per_second = 1000000000000UL / 30000UL; | |
442 | } else | |
443 | sn_rtc_cycles_per_second = ticks_per_sec; | |
444 | } | |
445 | ||
7f1baa06 MT |
446 | /* |
447 | * percpu heartbeat timer | |
448 | */ | |
449 | static void uv_heartbeat(unsigned long ignored) | |
450 | { | |
451 | struct timer_list *timer = &uv_hub_info->scir.timer; | |
452 | unsigned char bits = uv_hub_info->scir.state; | |
453 | ||
454 | /* flip heartbeat bit */ | |
455 | bits ^= SCIR_CPU_HEARTBEAT; | |
456 | ||
69a72a0e MT |
457 | /* is this cpu idle? */ |
458 | if (idle_cpu(raw_smp_processor_id())) | |
7f1baa06 MT |
459 | bits &= ~SCIR_CPU_ACTIVITY; |
460 | else | |
461 | bits |= SCIR_CPU_ACTIVITY; | |
462 | ||
463 | /* update system controller interface reg */ | |
464 | uv_set_scir_bits(bits); | |
465 | ||
466 | /* enable next timer period */ | |
5c333864 | 467 | mod_timer_pinned(timer, jiffies + SCIR_CPU_HB_INTERVAL); |
7f1baa06 MT |
468 | } |
469 | ||
470 | static void __cpuinit uv_heartbeat_enable(int cpu) | |
471 | { | |
472 | if (!uv_cpu_hub_info(cpu)->scir.enabled) { | |
473 | struct timer_list *timer = &uv_cpu_hub_info(cpu)->scir.timer; | |
474 | ||
475 | uv_set_cpu_scir_bits(cpu, SCIR_CPU_HEARTBEAT|SCIR_CPU_ACTIVITY); | |
476 | setup_timer(timer, uv_heartbeat, cpu); | |
477 | timer->expires = jiffies + SCIR_CPU_HB_INTERVAL; | |
478 | add_timer_on(timer, cpu); | |
479 | uv_cpu_hub_info(cpu)->scir.enabled = 1; | |
480 | } | |
481 | ||
482 | /* check boot cpu */ | |
483 | if (!uv_cpu_hub_info(0)->scir.enabled) | |
484 | uv_heartbeat_enable(0); | |
485 | } | |
486 | ||
77be80e4 | 487 | #ifdef CONFIG_HOTPLUG_CPU |
7f1baa06 MT |
488 | static void __cpuinit uv_heartbeat_disable(int cpu) |
489 | { | |
490 | if (uv_cpu_hub_info(cpu)->scir.enabled) { | |
491 | uv_cpu_hub_info(cpu)->scir.enabled = 0; | |
492 | del_timer(&uv_cpu_hub_info(cpu)->scir.timer); | |
493 | } | |
494 | uv_set_cpu_scir_bits(cpu, 0xff); | |
495 | } | |
496 | ||
7f1baa06 MT |
497 | /* |
498 | * cpu hotplug notifier | |
499 | */ | |
500 | static __cpuinit int uv_scir_cpu_notify(struct notifier_block *self, | |
501 | unsigned long action, void *hcpu) | |
502 | { | |
503 | long cpu = (long)hcpu; | |
504 | ||
505 | switch (action) { | |
506 | case CPU_ONLINE: | |
507 | uv_heartbeat_enable(cpu); | |
508 | break; | |
509 | case CPU_DOWN_PREPARE: | |
510 | uv_heartbeat_disable(cpu); | |
511 | break; | |
512 | default: | |
513 | break; | |
514 | } | |
515 | return NOTIFY_OK; | |
516 | } | |
517 | ||
518 | static __init void uv_scir_register_cpu_notifier(void) | |
519 | { | |
520 | hotcpu_notifier(uv_scir_cpu_notify, 0); | |
521 | } | |
522 | ||
523 | #else /* !CONFIG_HOTPLUG_CPU */ | |
524 | ||
525 | static __init void uv_scir_register_cpu_notifier(void) | |
526 | { | |
527 | } | |
528 | ||
529 | static __init int uv_init_heartbeat(void) | |
530 | { | |
531 | int cpu; | |
532 | ||
533 | if (is_uv_system()) | |
534 | for_each_online_cpu(cpu) | |
535 | uv_heartbeat_enable(cpu); | |
536 | return 0; | |
537 | } | |
538 | ||
539 | late_initcall(uv_init_heartbeat); | |
540 | ||
541 | #endif /* !CONFIG_HOTPLUG_CPU */ | |
542 | ||
8da077d6 JS |
543 | /* |
544 | * Called on each cpu to initialize the per_cpu UV data area. | |
0b1da1c8 | 545 | * FIXME: hotplug not supported yet |
8da077d6 JS |
546 | */ |
547 | void __cpuinit uv_cpu_init(void) | |
548 | { | |
549 | /* CPU 0 initilization will be done via uv_system_init. */ | |
550 | if (!uv_blade_info) | |
551 | return; | |
552 | ||
553 | uv_blade_info[uv_numa_blade_id()].nr_online_cpus++; | |
554 | ||
555 | if (get_uv_system_type() == UV_NON_UNIQUE_APIC) | |
556 | set_x2apic_extra_bits(uv_hub_info->pnode); | |
557 | } | |
558 | ||
c4bd1fda MS |
559 | |
560 | void __init uv_system_init(void) | |
ac23d4ee JS |
561 | { |
562 | union uvh_si_addr_map_config_u m_n_config; | |
9f5314fb JS |
563 | union uvh_node_id_u node_id; |
564 | unsigned long gnode_upper, lowmem_redir_base, lowmem_redir_size; | |
565 | int bytes, nid, cpu, lcpu, pnode, blade, i, j, m_val, n_val; | |
c4ed3f04 | 566 | int gnode_extra, max_pnode = 0; |
6a891a24 JS |
567 | unsigned long mmr_base, present, paddr; |
568 | unsigned short pnode_mask; | |
ac23d4ee JS |
569 | |
570 | m_n_config.v = uv_read_local_mmr(UVH_SI_ADDR_MAP_CONFIG); | |
9f5314fb JS |
571 | m_val = m_n_config.s.m_skt; |
572 | n_val = m_n_config.s.n_skt; | |
ac23d4ee JS |
573 | mmr_base = |
574 | uv_read_local_mmr(UVH_RH_GAM_MMR_OVERLAY_CONFIG_MMR) & | |
575 | ~UV_MMR_ENABLE; | |
c4ed3f04 JS |
576 | pnode_mask = (1 << n_val) - 1; |
577 | node_id.v = uv_read_local_mmr(UVH_NODE_ID); | |
578 | gnode_extra = (node_id.s.node_id & ~((1 << n_val) - 1)) >> 1; | |
579 | gnode_upper = ((unsigned long)gnode_extra << m_val); | |
580 | printk(KERN_DEBUG "UV: N %d, M %d, gnode_upper 0x%lx, gnode_extra 0x%x\n", | |
581 | n_val, m_val, gnode_upper, gnode_extra); | |
582 | ||
ac23d4ee JS |
583 | printk(KERN_DEBUG "UV: global MMR base 0x%lx\n", mmr_base); |
584 | ||
9f5314fb JS |
585 | for(i = 0; i < UVH_NODE_PRESENT_TABLE_DEPTH; i++) |
586 | uv_possible_blades += | |
587 | hweight64(uv_read_local_mmr( UVH_NODE_PRESENT_TABLE + i * 8)); | |
ac23d4ee JS |
588 | printk(KERN_DEBUG "UV: Found %d blades\n", uv_num_possible_blades()); |
589 | ||
590 | bytes = sizeof(struct uv_blade_info) * uv_num_possible_blades(); | |
ef020ab0 | 591 | uv_blade_info = kmalloc(bytes, GFP_KERNEL); |
9a8709d4 | 592 | BUG_ON(!uv_blade_info); |
6c7184b7 JS |
593 | for (blade = 0; blade < uv_num_possible_blades(); blade++) |
594 | uv_blade_info[blade].memory_nid = -1; | |
ac23d4ee | 595 | |
9f5314fb JS |
596 | get_lowmem_redirect(&lowmem_redir_base, &lowmem_redir_size); |
597 | ||
ac23d4ee | 598 | bytes = sizeof(uv_node_to_blade[0]) * num_possible_nodes(); |
ef020ab0 | 599 | uv_node_to_blade = kmalloc(bytes, GFP_KERNEL); |
9a8709d4 | 600 | BUG_ON(!uv_node_to_blade); |
ac23d4ee JS |
601 | memset(uv_node_to_blade, 255, bytes); |
602 | ||
603 | bytes = sizeof(uv_cpu_to_blade[0]) * num_possible_cpus(); | |
ef020ab0 | 604 | uv_cpu_to_blade = kmalloc(bytes, GFP_KERNEL); |
9a8709d4 | 605 | BUG_ON(!uv_cpu_to_blade); |
ac23d4ee JS |
606 | memset(uv_cpu_to_blade, 255, bytes); |
607 | ||
9f5314fb JS |
608 | blade = 0; |
609 | for (i = 0; i < UVH_NODE_PRESENT_TABLE_DEPTH; i++) { | |
610 | present = uv_read_local_mmr(UVH_NODE_PRESENT_TABLE + i * 8); | |
611 | for (j = 0; j < 64; j++) { | |
612 | if (!test_bit(j, &present)) | |
613 | continue; | |
614 | uv_blade_info[blade].pnode = (i * 64 + j); | |
615 | uv_blade_info[blade].nr_possible_cpus = 0; | |
ac23d4ee | 616 | uv_blade_info[blade].nr_online_cpus = 0; |
9f5314fb | 617 | blade++; |
ac23d4ee | 618 | } |
9f5314fb | 619 | } |
ac23d4ee | 620 | |
7f594232 | 621 | uv_bios_init(); |
922402f1 | 622 | uv_bios_get_sn_info(0, &uv_type, &sn_partition_id, |
b0f20989 | 623 | &sn_coherency_id, &sn_region_size); |
7019cc2d RA |
624 | uv_rtc_init(); |
625 | ||
9f5314fb JS |
626 | for_each_present_cpu(cpu) { |
627 | nid = cpu_to_node(cpu); | |
628 | pnode = uv_apicid_to_pnode(per_cpu(x86_cpu_to_apicid, cpu)); | |
629 | blade = boot_pnode_to_blade(pnode); | |
630 | lcpu = uv_blade_info[blade].nr_possible_cpus; | |
631 | uv_blade_info[blade].nr_possible_cpus++; | |
632 | ||
6c7184b7 JS |
633 | /* Any node on the blade, else will contain -1. */ |
634 | uv_blade_info[blade].memory_nid = nid; | |
635 | ||
9f5314fb | 636 | uv_cpu_hub_info(cpu)->lowmem_remap_base = lowmem_redir_base; |
189f67c4 | 637 | uv_cpu_hub_info(cpu)->lowmem_remap_top = lowmem_redir_size; |
9f5314fb JS |
638 | uv_cpu_hub_info(cpu)->m_val = m_val; |
639 | uv_cpu_hub_info(cpu)->n_val = m_val; | |
ac23d4ee JS |
640 | uv_cpu_hub_info(cpu)->numa_blade_id = blade; |
641 | uv_cpu_hub_info(cpu)->blade_processor_id = lcpu; | |
9f5314fb | 642 | uv_cpu_hub_info(cpu)->pnode = pnode; |
6a891a24 | 643 | uv_cpu_hub_info(cpu)->pnode_mask = pnode_mask; |
9f5314fb JS |
644 | uv_cpu_hub_info(cpu)->gpa_mask = (1 << (m_val + n_val)) - 1; |
645 | uv_cpu_hub_info(cpu)->gnode_upper = gnode_upper; | |
c4ed3f04 | 646 | uv_cpu_hub_info(cpu)->gnode_extra = gnode_extra; |
ac23d4ee | 647 | uv_cpu_hub_info(cpu)->global_mmr_base = mmr_base; |
b0f20989 | 648 | uv_cpu_hub_info(cpu)->coherency_domain_number = sn_coherency_id; |
7f1baa06 | 649 | uv_cpu_hub_info(cpu)->scir.offset = SCIR_LOCAL_MMR_BASE + lcpu; |
ac23d4ee JS |
650 | uv_node_to_blade[nid] = blade; |
651 | uv_cpu_to_blade[cpu] = blade; | |
83f5d894 | 652 | max_pnode = max(pnode, max_pnode); |
ac23d4ee | 653 | |
83f5d894 | 654 | printk(KERN_DEBUG "UV: cpu %d, apicid 0x%x, pnode %d, nid %d, " |
9f5314fb JS |
655 | "lcpu %d, blade %d\n", |
656 | cpu, per_cpu(x86_cpu_to_apicid, cpu), pnode, nid, | |
657 | lcpu, blade); | |
ac23d4ee | 658 | } |
83f5d894 | 659 | |
6a891a24 JS |
660 | /* Add blade/pnode info for nodes without cpus */ |
661 | for_each_online_node(nid) { | |
662 | if (uv_node_to_blade[nid] >= 0) | |
663 | continue; | |
664 | paddr = node_start_pfn(nid) << PAGE_SHIFT; | |
fc61e663 | 665 | paddr = uv_soc_phys_ram_to_gpa(paddr); |
6a891a24 JS |
666 | pnode = (paddr >> m_val) & pnode_mask; |
667 | blade = boot_pnode_to_blade(pnode); | |
668 | uv_node_to_blade[nid] = blade; | |
cc5e4fa1 | 669 | max_pnode = max(pnode, max_pnode); |
6a891a24 JS |
670 | } |
671 | ||
83f5d894 | 672 | map_gru_high(max_pnode); |
daf7b9c9 | 673 | map_mmr_high(max_pnode); |
83f5d894 | 674 | map_mmioh_high(max_pnode); |
ac23d4ee | 675 | |
8da077d6 | 676 | uv_cpu_init(); |
7f1baa06 | 677 | uv_scir_register_cpu_notifier(); |
a3d732f9 | 678 | proc_mkdir("sgi_uv", NULL); |
ac23d4ee | 679 | } |