x86, UV: Fix initialization of max_pnode
[linux-2.6/linux-acpi-2.6/ibm-acpi-2.6.git] / arch / x86 / kernel / apic / x2apic_uv_x.c
blobf744f54cb248e7ac0cd6defaa84a8e673468b30a
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.
6 * SGI UV APIC functions (note: not an Intel compatible APIC)
8 * Copyright (C) 2007-2009 Silicon Graphics, Inc. All rights reserved.
9 */
10 #include <linux/cpumask.h>
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>
16 #include <linux/string.h>
17 #include <linux/ctype.h>
18 #include <linux/sched.h>
19 #include <linux/timer.h>
20 #include <linux/slab.h>
21 #include <linux/cpu.h>
22 #include <linux/init.h>
23 #include <linux/io.h>
24 #include <linux/pci.h>
25 #include <linux/kdebug.h>
27 #include <asm/uv/uv_mmrs.h>
28 #include <asm/uv/uv_hub.h>
29 #include <asm/current.h>
30 #include <asm/pgtable.h>
31 #include <asm/uv/bios.h>
32 #include <asm/uv/uv.h>
33 #include <asm/apic.h>
34 #include <asm/ipi.h>
35 #include <asm/smp.h>
36 #include <asm/x86_init.h>
38 DEFINE_PER_CPU(int, x2apic_extra_bits);
40 #define PR_DEVEL(fmt, args...) pr_devel("%s: " fmt, __func__, args)
42 static enum uv_system_type uv_system_type;
43 static u64 gru_start_paddr, gru_end_paddr;
44 int uv_min_hub_revision_id;
45 EXPORT_SYMBOL_GPL(uv_min_hub_revision_id);
46 static DEFINE_SPINLOCK(uv_nmi_lock);
48 static inline bool is_GRU_range(u64 start, u64 end)
50 return start >= gru_start_paddr && end <= gru_end_paddr;
53 static bool uv_is_untracked_pat_range(u64 start, u64 end)
55 return is_ISA_range(start, end) || is_GRU_range(start, end);
58 static int early_get_nodeid(void)
60 union uvh_node_id_u node_id;
61 unsigned long *mmr;
63 mmr = early_ioremap(UV_LOCAL_MMR_BASE | UVH_NODE_ID, sizeof(*mmr));
64 node_id.v = *mmr;
65 early_iounmap(mmr, sizeof(*mmr));
67 /* Currently, all blades have same revision number */
68 uv_min_hub_revision_id = node_id.s.revision;
70 return node_id.s.node_id;
73 static int __init uv_acpi_madt_oem_check(char *oem_id, char *oem_table_id)
75 int nodeid;
77 if (!strcmp(oem_id, "SGI")) {
78 nodeid = early_get_nodeid();
79 x86_platform.is_untracked_pat_range = uv_is_untracked_pat_range;
80 x86_platform.nmi_init = uv_nmi_init;
81 if (!strcmp(oem_table_id, "UVL"))
82 uv_system_type = UV_LEGACY_APIC;
83 else if (!strcmp(oem_table_id, "UVX"))
84 uv_system_type = UV_X2APIC;
85 else if (!strcmp(oem_table_id, "UVH")) {
86 __get_cpu_var(x2apic_extra_bits) =
87 nodeid << (UV_APIC_PNODE_SHIFT - 1);
88 uv_system_type = UV_NON_UNIQUE_APIC;
89 return 1;
92 return 0;
95 enum uv_system_type get_uv_system_type(void)
97 return uv_system_type;
100 int is_uv_system(void)
102 return uv_system_type != UV_NONE;
104 EXPORT_SYMBOL_GPL(is_uv_system);
106 DEFINE_PER_CPU(struct uv_hub_info_s, __uv_hub_info);
107 EXPORT_PER_CPU_SYMBOL_GPL(__uv_hub_info);
109 struct uv_blade_info *uv_blade_info;
110 EXPORT_SYMBOL_GPL(uv_blade_info);
112 short *uv_node_to_blade;
113 EXPORT_SYMBOL_GPL(uv_node_to_blade);
115 short *uv_cpu_to_blade;
116 EXPORT_SYMBOL_GPL(uv_cpu_to_blade);
118 short uv_possible_blades;
119 EXPORT_SYMBOL_GPL(uv_possible_blades);
121 unsigned long sn_rtc_cycles_per_second;
122 EXPORT_SYMBOL(sn_rtc_cycles_per_second);
124 static const struct cpumask *uv_target_cpus(void)
126 return cpu_online_mask;
129 static void uv_vector_allocation_domain(int cpu, struct cpumask *retmask)
131 cpumask_clear(retmask);
132 cpumask_set_cpu(cpu, retmask);
135 static int __cpuinit uv_wakeup_secondary(int phys_apicid, unsigned long start_rip)
137 #ifdef CONFIG_SMP
138 unsigned long val;
139 int pnode;
141 pnode = uv_apicid_to_pnode(phys_apicid);
142 val = (1UL << UVH_IPI_INT_SEND_SHFT) |
143 (phys_apicid << UVH_IPI_INT_APIC_ID_SHFT) |
144 ((start_rip << UVH_IPI_INT_VECTOR_SHFT) >> 12) |
145 APIC_DM_INIT;
146 uv_write_global_mmr64(pnode, UVH_IPI_INT, val);
147 mdelay(10);
149 val = (1UL << UVH_IPI_INT_SEND_SHFT) |
150 (phys_apicid << UVH_IPI_INT_APIC_ID_SHFT) |
151 ((start_rip << UVH_IPI_INT_VECTOR_SHFT) >> 12) |
152 APIC_DM_STARTUP;
153 uv_write_global_mmr64(pnode, UVH_IPI_INT, val);
155 atomic_set(&init_deasserted, 1);
156 #endif
157 return 0;
160 static void uv_send_IPI_one(int cpu, int vector)
162 unsigned long apicid;
163 int pnode;
165 apicid = per_cpu(x86_cpu_to_apicid, cpu);
166 pnode = uv_apicid_to_pnode(apicid);
167 uv_hub_send_ipi(pnode, apicid, vector);
170 static void uv_send_IPI_mask(const struct cpumask *mask, int vector)
172 unsigned int cpu;
174 for_each_cpu(cpu, mask)
175 uv_send_IPI_one(cpu, vector);
178 static void uv_send_IPI_mask_allbutself(const struct cpumask *mask, int vector)
180 unsigned int this_cpu = smp_processor_id();
181 unsigned int cpu;
183 for_each_cpu(cpu, mask) {
184 if (cpu != this_cpu)
185 uv_send_IPI_one(cpu, vector);
189 static void uv_send_IPI_allbutself(int vector)
191 unsigned int this_cpu = smp_processor_id();
192 unsigned int cpu;
194 for_each_online_cpu(cpu) {
195 if (cpu != this_cpu)
196 uv_send_IPI_one(cpu, vector);
200 static void uv_send_IPI_all(int vector)
202 uv_send_IPI_mask(cpu_online_mask, vector);
205 static int uv_apic_id_registered(void)
207 return 1;
210 static void uv_init_apic_ldr(void)
214 static unsigned int uv_cpu_mask_to_apicid(const struct cpumask *cpumask)
217 * We're using fixed IRQ delivery, can only return one phys APIC ID.
218 * May as well be the first.
220 int cpu = cpumask_first(cpumask);
222 if ((unsigned)cpu < nr_cpu_ids)
223 return per_cpu(x86_cpu_to_apicid, cpu);
224 else
225 return BAD_APICID;
228 static unsigned int
229 uv_cpu_mask_to_apicid_and(const struct cpumask *cpumask,
230 const struct cpumask *andmask)
232 int cpu;
235 * We're using fixed IRQ delivery, can only return one phys APIC ID.
236 * May as well be the first.
238 for_each_cpu_and(cpu, cpumask, andmask) {
239 if (cpumask_test_cpu(cpu, cpu_online_mask))
240 break;
242 return per_cpu(x86_cpu_to_apicid, cpu);
245 static unsigned int x2apic_get_apic_id(unsigned long x)
247 unsigned int id;
249 WARN_ON(preemptible() && num_online_cpus() > 1);
250 id = x | __get_cpu_var(x2apic_extra_bits);
252 return id;
255 static unsigned long set_apic_id(unsigned int id)
257 unsigned long x;
259 /* maskout x2apic_extra_bits ? */
260 x = id;
261 return x;
264 static unsigned int uv_read_apic_id(void)
267 return x2apic_get_apic_id(apic_read(APIC_ID));
270 static int uv_phys_pkg_id(int initial_apicid, int index_msb)
272 return uv_read_apic_id() >> index_msb;
275 static void uv_send_IPI_self(int vector)
277 apic_write(APIC_SELF_IPI, vector);
280 struct apic __refdata apic_x2apic_uv_x = {
282 .name = "UV large system",
283 .probe = NULL,
284 .acpi_madt_oem_check = uv_acpi_madt_oem_check,
285 .apic_id_registered = uv_apic_id_registered,
287 .irq_delivery_mode = dest_Fixed,
288 .irq_dest_mode = 0, /* physical */
290 .target_cpus = uv_target_cpus,
291 .disable_esr = 0,
292 .dest_logical = APIC_DEST_LOGICAL,
293 .check_apicid_used = NULL,
294 .check_apicid_present = NULL,
296 .vector_allocation_domain = uv_vector_allocation_domain,
297 .init_apic_ldr = uv_init_apic_ldr,
299 .ioapic_phys_id_map = NULL,
300 .setup_apic_routing = NULL,
301 .multi_timer_check = NULL,
302 .apicid_to_node = NULL,
303 .cpu_to_logical_apicid = NULL,
304 .cpu_present_to_apicid = default_cpu_present_to_apicid,
305 .apicid_to_cpu_present = NULL,
306 .setup_portio_remap = NULL,
307 .check_phys_apicid_present = default_check_phys_apicid_present,
308 .enable_apic_mode = NULL,
309 .phys_pkg_id = uv_phys_pkg_id,
310 .mps_oem_check = NULL,
312 .get_apic_id = x2apic_get_apic_id,
313 .set_apic_id = set_apic_id,
314 .apic_id_mask = 0xFFFFFFFFu,
316 .cpu_mask_to_apicid = uv_cpu_mask_to_apicid,
317 .cpu_mask_to_apicid_and = uv_cpu_mask_to_apicid_and,
319 .send_IPI_mask = uv_send_IPI_mask,
320 .send_IPI_mask_allbutself = uv_send_IPI_mask_allbutself,
321 .send_IPI_allbutself = uv_send_IPI_allbutself,
322 .send_IPI_all = uv_send_IPI_all,
323 .send_IPI_self = uv_send_IPI_self,
325 .wakeup_secondary_cpu = uv_wakeup_secondary,
326 .trampoline_phys_low = DEFAULT_TRAMPOLINE_PHYS_LOW,
327 .trampoline_phys_high = DEFAULT_TRAMPOLINE_PHYS_HIGH,
328 .wait_for_init_deassert = NULL,
329 .smp_callin_clear_local_apic = NULL,
330 .inquire_remote_apic = NULL,
332 .read = native_apic_msr_read,
333 .write = native_apic_msr_write,
334 .icr_read = native_x2apic_icr_read,
335 .icr_write = native_x2apic_icr_write,
336 .wait_icr_idle = native_x2apic_wait_icr_idle,
337 .safe_wait_icr_idle = native_safe_x2apic_wait_icr_idle,
340 static __cpuinit void set_x2apic_extra_bits(int pnode)
342 __get_cpu_var(x2apic_extra_bits) = (pnode << 6);
346 * Called on boot cpu.
348 static __init int boot_pnode_to_blade(int pnode)
350 int blade;
352 for (blade = 0; blade < uv_num_possible_blades(); blade++)
353 if (pnode == uv_blade_info[blade].pnode)
354 return blade;
355 BUG();
358 struct redir_addr {
359 unsigned long redirect;
360 unsigned long alias;
363 #define DEST_SHIFT UVH_RH_GAM_ALIAS210_REDIRECT_CONFIG_0_MMR_DEST_BASE_SHFT
365 static __initdata struct redir_addr redir_addrs[] = {
366 {UVH_RH_GAM_ALIAS210_REDIRECT_CONFIG_0_MMR, UVH_SI_ALIAS0_OVERLAY_CONFIG},
367 {UVH_RH_GAM_ALIAS210_REDIRECT_CONFIG_1_MMR, UVH_SI_ALIAS1_OVERLAY_CONFIG},
368 {UVH_RH_GAM_ALIAS210_REDIRECT_CONFIG_2_MMR, UVH_SI_ALIAS2_OVERLAY_CONFIG},
371 static __init void get_lowmem_redirect(unsigned long *base, unsigned long *size)
373 union uvh_si_alias0_overlay_config_u alias;
374 union uvh_rh_gam_alias210_redirect_config_2_mmr_u redirect;
375 int i;
377 for (i = 0; i < ARRAY_SIZE(redir_addrs); i++) {
378 alias.v = uv_read_local_mmr(redir_addrs[i].alias);
379 if (alias.s.enable && alias.s.base == 0) {
380 *size = (1UL << alias.s.m_alias);
381 redirect.v = uv_read_local_mmr(redir_addrs[i].redirect);
382 *base = (unsigned long)redirect.s.dest_base << DEST_SHIFT;
383 return;
386 *base = *size = 0;
389 enum map_type {map_wb, map_uc};
391 static __init void map_high(char *id, unsigned long base, int pshift,
392 int bshift, int max_pnode, enum map_type map_type)
394 unsigned long bytes, paddr;
396 paddr = base << pshift;
397 bytes = (1UL << bshift) * (max_pnode + 1);
398 printk(KERN_INFO "UV: Map %s_HI 0x%lx - 0x%lx\n", id, paddr,
399 paddr + bytes);
400 if (map_type == map_uc)
401 init_extra_mapping_uc(paddr, bytes);
402 else
403 init_extra_mapping_wb(paddr, bytes);
406 static __init void map_gru_high(int max_pnode)
408 union uvh_rh_gam_gru_overlay_config_mmr_u gru;
409 int shift = UVH_RH_GAM_GRU_OVERLAY_CONFIG_MMR_BASE_SHFT;
411 gru.v = uv_read_local_mmr(UVH_RH_GAM_GRU_OVERLAY_CONFIG_MMR);
412 if (gru.s.enable) {
413 map_high("GRU", gru.s.base, shift, shift, max_pnode, map_wb);
414 gru_start_paddr = ((u64)gru.s.base << shift);
415 gru_end_paddr = gru_start_paddr + (1UL << shift) * (max_pnode + 1);
420 static __init void map_mmr_high(int max_pnode)
422 union uvh_rh_gam_mmr_overlay_config_mmr_u mmr;
423 int shift = UVH_RH_GAM_MMR_OVERLAY_CONFIG_MMR_BASE_SHFT;
425 mmr.v = uv_read_local_mmr(UVH_RH_GAM_MMR_OVERLAY_CONFIG_MMR);
426 if (mmr.s.enable)
427 map_high("MMR", mmr.s.base, shift, shift, max_pnode, map_uc);
430 static __init void map_mmioh_high(int max_pnode)
432 union uvh_rh_gam_mmioh_overlay_config_mmr_u mmioh;
433 int shift = UVH_RH_GAM_MMIOH_OVERLAY_CONFIG_MMR_BASE_SHFT;
435 mmioh.v = uv_read_local_mmr(UVH_RH_GAM_MMIOH_OVERLAY_CONFIG_MMR);
436 if (mmioh.s.enable)
437 map_high("MMIOH", mmioh.s.base, shift, mmioh.s.m_io,
438 max_pnode, map_uc);
441 static __init void map_low_mmrs(void)
443 init_extra_mapping_uc(UV_GLOBAL_MMR32_BASE, UV_GLOBAL_MMR32_SIZE);
444 init_extra_mapping_uc(UV_LOCAL_MMR_BASE, UV_LOCAL_MMR_SIZE);
447 static __init void uv_rtc_init(void)
449 long status;
450 u64 ticks_per_sec;
452 status = uv_bios_freq_base(BIOS_FREQ_BASE_REALTIME_CLOCK,
453 &ticks_per_sec);
454 if (status != BIOS_STATUS_SUCCESS || ticks_per_sec < 100000) {
455 printk(KERN_WARNING
456 "unable to determine platform RTC clock frequency, "
457 "guessing.\n");
458 /* BIOS gives wrong value for clock freq. so guess */
459 sn_rtc_cycles_per_second = 1000000000000UL / 30000UL;
460 } else
461 sn_rtc_cycles_per_second = ticks_per_sec;
465 * percpu heartbeat timer
467 static void uv_heartbeat(unsigned long ignored)
469 struct timer_list *timer = &uv_hub_info->scir.timer;
470 unsigned char bits = uv_hub_info->scir.state;
472 /* flip heartbeat bit */
473 bits ^= SCIR_CPU_HEARTBEAT;
475 /* is this cpu idle? */
476 if (idle_cpu(raw_smp_processor_id()))
477 bits &= ~SCIR_CPU_ACTIVITY;
478 else
479 bits |= SCIR_CPU_ACTIVITY;
481 /* update system controller interface reg */
482 uv_set_scir_bits(bits);
484 /* enable next timer period */
485 mod_timer_pinned(timer, jiffies + SCIR_CPU_HB_INTERVAL);
488 static void __cpuinit uv_heartbeat_enable(int cpu)
490 while (!uv_cpu_hub_info(cpu)->scir.enabled) {
491 struct timer_list *timer = &uv_cpu_hub_info(cpu)->scir.timer;
493 uv_set_cpu_scir_bits(cpu, SCIR_CPU_HEARTBEAT|SCIR_CPU_ACTIVITY);
494 setup_timer(timer, uv_heartbeat, cpu);
495 timer->expires = jiffies + SCIR_CPU_HB_INTERVAL;
496 add_timer_on(timer, cpu);
497 uv_cpu_hub_info(cpu)->scir.enabled = 1;
499 /* also ensure that boot cpu is enabled */
500 cpu = 0;
504 #ifdef CONFIG_HOTPLUG_CPU
505 static void __cpuinit uv_heartbeat_disable(int cpu)
507 if (uv_cpu_hub_info(cpu)->scir.enabled) {
508 uv_cpu_hub_info(cpu)->scir.enabled = 0;
509 del_timer(&uv_cpu_hub_info(cpu)->scir.timer);
511 uv_set_cpu_scir_bits(cpu, 0xff);
515 * cpu hotplug notifier
517 static __cpuinit int uv_scir_cpu_notify(struct notifier_block *self,
518 unsigned long action, void *hcpu)
520 long cpu = (long)hcpu;
522 switch (action) {
523 case CPU_ONLINE:
524 uv_heartbeat_enable(cpu);
525 break;
526 case CPU_DOWN_PREPARE:
527 uv_heartbeat_disable(cpu);
528 break;
529 default:
530 break;
532 return NOTIFY_OK;
535 static __init void uv_scir_register_cpu_notifier(void)
537 hotcpu_notifier(uv_scir_cpu_notify, 0);
540 #else /* !CONFIG_HOTPLUG_CPU */
542 static __init void uv_scir_register_cpu_notifier(void)
546 static __init int uv_init_heartbeat(void)
548 int cpu;
550 if (is_uv_system())
551 for_each_online_cpu(cpu)
552 uv_heartbeat_enable(cpu);
553 return 0;
556 late_initcall(uv_init_heartbeat);
558 #endif /* !CONFIG_HOTPLUG_CPU */
560 /* Direct Legacy VGA I/O traffic to designated IOH */
561 int uv_set_vga_state(struct pci_dev *pdev, bool decode,
562 unsigned int command_bits, bool change_bridge)
564 int domain, bus, rc;
566 PR_DEVEL("devfn %x decode %d cmd %x chg_brdg %d\n",
567 pdev->devfn, decode, command_bits, change_bridge);
569 if (!change_bridge)
570 return 0;
572 if ((command_bits & PCI_COMMAND_IO) == 0)
573 return 0;
575 domain = pci_domain_nr(pdev->bus);
576 bus = pdev->bus->number;
578 rc = uv_bios_set_legacy_vga_target(decode, domain, bus);
579 PR_DEVEL("vga decode %d %x:%x, rc: %d\n", decode, domain, bus, rc);
581 return rc;
585 * Called on each cpu to initialize the per_cpu UV data area.
586 * FIXME: hotplug not supported yet
588 void __cpuinit uv_cpu_init(void)
590 /* CPU 0 initilization will be done via uv_system_init. */
591 if (!uv_blade_info)
592 return;
594 uv_blade_info[uv_numa_blade_id()].nr_online_cpus++;
596 if (get_uv_system_type() == UV_NON_UNIQUE_APIC)
597 set_x2apic_extra_bits(uv_hub_info->pnode);
601 * When NMI is received, print a stack trace.
603 int uv_handle_nmi(struct notifier_block *self, unsigned long reason, void *data)
605 if (reason != DIE_NMI_IPI)
606 return NOTIFY_OK;
608 if (in_crash_kexec)
609 /* do nothing if entering the crash kernel */
610 return NOTIFY_OK;
612 * Use a lock so only one cpu prints at a time
613 * to prevent intermixed output.
615 spin_lock(&uv_nmi_lock);
616 pr_info("NMI stack dump cpu %u:\n", smp_processor_id());
617 dump_stack();
618 spin_unlock(&uv_nmi_lock);
620 return NOTIFY_STOP;
623 static struct notifier_block uv_dump_stack_nmi_nb = {
624 .notifier_call = uv_handle_nmi
627 void uv_register_nmi_notifier(void)
629 if (register_die_notifier(&uv_dump_stack_nmi_nb))
630 printk(KERN_WARNING "UV NMI handler failed to register\n");
633 void uv_nmi_init(void)
635 unsigned int value;
638 * Unmask NMI on all cpus
640 value = apic_read(APIC_LVT1) | APIC_DM_NMI;
641 value &= ~APIC_LVT_MASKED;
642 apic_write(APIC_LVT1, value);
645 void __init uv_system_init(void)
647 union uvh_si_addr_map_config_u m_n_config;
648 union uvh_node_id_u node_id;
649 unsigned long gnode_upper, lowmem_redir_base, lowmem_redir_size;
650 int bytes, nid, cpu, lcpu, pnode, blade, i, j, m_val, n_val;
651 int gnode_extra, max_pnode = 0;
652 unsigned long mmr_base, present, paddr;
653 unsigned short pnode_mask;
655 map_low_mmrs();
657 m_n_config.v = uv_read_local_mmr(UVH_SI_ADDR_MAP_CONFIG);
658 m_val = m_n_config.s.m_skt;
659 n_val = m_n_config.s.n_skt;
660 mmr_base =
661 uv_read_local_mmr(UVH_RH_GAM_MMR_OVERLAY_CONFIG_MMR) &
662 ~UV_MMR_ENABLE;
663 pnode_mask = (1 << n_val) - 1;
664 node_id.v = uv_read_local_mmr(UVH_NODE_ID);
665 gnode_extra = (node_id.s.node_id & ~((1 << n_val) - 1)) >> 1;
666 gnode_upper = ((unsigned long)gnode_extra << m_val);
667 printk(KERN_DEBUG "UV: N %d, M %d, gnode_upper 0x%lx, gnode_extra 0x%x\n",
668 n_val, m_val, gnode_upper, gnode_extra);
670 printk(KERN_DEBUG "UV: global MMR base 0x%lx\n", mmr_base);
672 for(i = 0; i < UVH_NODE_PRESENT_TABLE_DEPTH; i++)
673 uv_possible_blades +=
674 hweight64(uv_read_local_mmr( UVH_NODE_PRESENT_TABLE + i * 8));
675 printk(KERN_DEBUG "UV: Found %d blades\n", uv_num_possible_blades());
677 bytes = sizeof(struct uv_blade_info) * uv_num_possible_blades();
678 uv_blade_info = kmalloc(bytes, GFP_KERNEL);
679 BUG_ON(!uv_blade_info);
680 for (blade = 0; blade < uv_num_possible_blades(); blade++)
681 uv_blade_info[blade].memory_nid = -1;
683 get_lowmem_redirect(&lowmem_redir_base, &lowmem_redir_size);
685 bytes = sizeof(uv_node_to_blade[0]) * num_possible_nodes();
686 uv_node_to_blade = kmalloc(bytes, GFP_KERNEL);
687 BUG_ON(!uv_node_to_blade);
688 memset(uv_node_to_blade, 255, bytes);
690 bytes = sizeof(uv_cpu_to_blade[0]) * num_possible_cpus();
691 uv_cpu_to_blade = kmalloc(bytes, GFP_KERNEL);
692 BUG_ON(!uv_cpu_to_blade);
693 memset(uv_cpu_to_blade, 255, bytes);
695 blade = 0;
696 for (i = 0; i < UVH_NODE_PRESENT_TABLE_DEPTH; i++) {
697 present = uv_read_local_mmr(UVH_NODE_PRESENT_TABLE + i * 8);
698 for (j = 0; j < 64; j++) {
699 if (!test_bit(j, &present))
700 continue;
701 pnode = (i * 64 + j);
702 uv_blade_info[blade].pnode = pnode;
703 uv_blade_info[blade].nr_possible_cpus = 0;
704 uv_blade_info[blade].nr_online_cpus = 0;
705 max_pnode = max(pnode, max_pnode);
706 blade++;
710 uv_bios_init();
711 uv_bios_get_sn_info(0, &uv_type, &sn_partition_id, &sn_coherency_id,
712 &sn_region_size, &system_serial_number);
713 uv_rtc_init();
715 for_each_present_cpu(cpu) {
716 int apicid = per_cpu(x86_cpu_to_apicid, cpu);
718 nid = cpu_to_node(cpu);
719 pnode = uv_apicid_to_pnode(apicid);
720 blade = boot_pnode_to_blade(pnode);
721 lcpu = uv_blade_info[blade].nr_possible_cpus;
722 uv_blade_info[blade].nr_possible_cpus++;
724 /* Any node on the blade, else will contain -1. */
725 uv_blade_info[blade].memory_nid = nid;
727 uv_cpu_hub_info(cpu)->lowmem_remap_base = lowmem_redir_base;
728 uv_cpu_hub_info(cpu)->lowmem_remap_top = lowmem_redir_size;
729 uv_cpu_hub_info(cpu)->m_val = m_val;
730 uv_cpu_hub_info(cpu)->n_val = n_val;
731 uv_cpu_hub_info(cpu)->numa_blade_id = blade;
732 uv_cpu_hub_info(cpu)->blade_processor_id = lcpu;
733 uv_cpu_hub_info(cpu)->pnode = pnode;
734 uv_cpu_hub_info(cpu)->pnode_mask = pnode_mask;
735 uv_cpu_hub_info(cpu)->gpa_mask = (1UL << (m_val + n_val)) - 1;
736 uv_cpu_hub_info(cpu)->gnode_upper = gnode_upper;
737 uv_cpu_hub_info(cpu)->gnode_extra = gnode_extra;
738 uv_cpu_hub_info(cpu)->global_mmr_base = mmr_base;
739 uv_cpu_hub_info(cpu)->coherency_domain_number = sn_coherency_id;
740 uv_cpu_hub_info(cpu)->scir.offset = uv_scir_offset(apicid);
741 uv_node_to_blade[nid] = blade;
742 uv_cpu_to_blade[cpu] = blade;
745 /* Add blade/pnode info for nodes without cpus */
746 for_each_online_node(nid) {
747 if (uv_node_to_blade[nid] >= 0)
748 continue;
749 paddr = node_start_pfn(nid) << PAGE_SHIFT;
750 paddr = uv_soc_phys_ram_to_gpa(paddr);
751 pnode = (paddr >> m_val) & pnode_mask;
752 blade = boot_pnode_to_blade(pnode);
753 uv_node_to_blade[nid] = blade;
756 map_gru_high(max_pnode);
757 map_mmr_high(max_pnode);
758 map_mmioh_high(max_pnode);
760 uv_cpu_init();
761 uv_scir_register_cpu_notifier();
762 uv_register_nmi_notifier();
763 proc_mkdir("sgi_uv", NULL);
765 /* register Legacy VGA I/O redirection handler */
766 pci_register_set_vga_state(uv_set_vga_state);