blob: fea71ee891eb13c925274adf06d76fd8071ce15f [file] [log] [blame]
Linus Torvalds1da177e2005-04-16 15:20:36 -07001/*
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 *
Dean Nelson2e34f072005-03-21 19:41:00 -07006 * Copyright (C) 1999,2001-2005 Silicon Graphics, Inc. All rights reserved.
Linus Torvalds1da177e2005-04-16 15:20:36 -07007 */
8
9#include <linux/config.h>
10#include <linux/module.h>
11#include <linux/init.h>
12#include <linux/delay.h>
13#include <linux/kernel.h>
14#include <linux/kdev_t.h>
15#include <linux/string.h>
16#include <linux/tty.h>
17#include <linux/console.h>
18#include <linux/timex.h>
19#include <linux/sched.h>
20#include <linux/ioport.h>
21#include <linux/mm.h>
22#include <linux/serial.h>
23#include <linux/irq.h>
24#include <linux/bootmem.h>
25#include <linux/mmzone.h>
26#include <linux/interrupt.h>
27#include <linux/acpi.h>
28#include <linux/compiler.h>
29#include <linux/sched.h>
30#include <linux/root_dev.h>
31#include <linux/nodemask.h>
Aaron J Youngc1298c52005-04-25 13:11:14 -070032#include <linux/pm.h>
Linus Torvalds1da177e2005-04-16 15:20:36 -070033
34#include <asm/io.h>
35#include <asm/sal.h>
36#include <asm/machvec.h>
37#include <asm/system.h>
38#include <asm/processor.h>
39#include <asm/sn/arch.h>
40#include <asm/sn/addrs.h>
41#include <asm/sn/pda.h>
42#include <asm/sn/nodepda.h>
43#include <asm/sn/sn_cpuid.h>
44#include <asm/sn/simulator.h>
45#include <asm/sn/leds.h>
46#include <asm/sn/bte.h>
47#include <asm/sn/shub_mmr.h>
48#include <asm/sn/clksupport.h>
49#include <asm/sn/sn_sal.h>
50#include <asm/sn/geo.h>
51#include "xtalk/xwidgetdev.h"
52#include "xtalk/hubdev.h"
53#include <asm/sn/klconfig.h>
54
55
56DEFINE_PER_CPU(struct pda_s, pda_percpu);
57
58#define MAX_PHYS_MEMORY (1UL << 49) /* 1 TB */
59
60lboard_t *root_lboard[MAX_COMPACT_NODES];
61
62extern void bte_init_node(nodepda_t *, cnodeid_t);
63
64extern void sn_timer_init(void);
65extern unsigned long last_time_offset;
66extern void (*ia64_mark_idle) (int);
67extern void snidle(int);
68extern unsigned char acpi_kbd_controller_present;
69
70unsigned long sn_rtc_cycles_per_second;
71EXPORT_SYMBOL(sn_rtc_cycles_per_second);
72
73DEFINE_PER_CPU(struct sn_hub_info_s, __sn_hub_info);
74EXPORT_PER_CPU_SYMBOL(__sn_hub_info);
75
Dean Nelson2e34f072005-03-21 19:41:00 -070076DEFINE_PER_CPU(short, __sn_cnodeid_to_nasid[MAX_NUMNODES]);
77EXPORT_PER_CPU_SYMBOL(__sn_cnodeid_to_nasid);
78
Linus Torvalds1da177e2005-04-16 15:20:36 -070079partid_t sn_partid = -1;
80EXPORT_SYMBOL(sn_partid);
81char sn_system_serial_number_string[128];
82EXPORT_SYMBOL(sn_system_serial_number_string);
83u64 sn_partition_serial_number;
84EXPORT_SYMBOL(sn_partition_serial_number);
85u8 sn_partition_id;
86EXPORT_SYMBOL(sn_partition_id);
87u8 sn_system_size;
88EXPORT_SYMBOL(sn_system_size);
89u8 sn_sharing_domain_size;
90EXPORT_SYMBOL(sn_sharing_domain_size);
91u8 sn_coherency_id;
92EXPORT_SYMBOL(sn_coherency_id);
93u8 sn_region_size;
94EXPORT_SYMBOL(sn_region_size);
95
96short physical_node_map[MAX_PHYSNODE_ID];
97
98EXPORT_SYMBOL(physical_node_map);
99
100int numionodes;
101
102static void sn_init_pdas(char **);
103static void scan_for_ionodes(void);
104
105static nodepda_t *nodepdaindr[MAX_COMPACT_NODES];
106
107/*
108 * The format of "screen_info" is strange, and due to early i386-setup
109 * code. This is just enough to make the console code think we're on a
110 * VGA color display.
111 */
112struct screen_info sn_screen_info = {
113 .orig_x = 0,
114 .orig_y = 0,
115 .orig_video_mode = 3,
116 .orig_video_cols = 80,
117 .orig_video_ega_bx = 3,
118 .orig_video_lines = 25,
119 .orig_video_isVGA = 1,
120 .orig_video_points = 16
121};
122
123/*
124 * This is here so we can use the CMOS detection in ide-probe.c to
125 * determine what drives are present. In theory, we don't need this
126 * as the auto-detection could be done via ide-probe.c:do_probe() but
127 * in practice that would be much slower, which is painful when
128 * running in the simulator. Note that passing zeroes in DRIVE_INFO
129 * is sufficient (the IDE driver will autodetect the drive geometry).
130 */
131#ifdef CONFIG_IA64_GENERIC
132extern char drive_info[4 * 16];
133#else
134char drive_info[4 * 16];
135#endif
136
137/*
138 * Get nasid of current cpu early in boot before nodepda is initialized
139 */
140static int
141boot_get_nasid(void)
142{
143 int nasid;
144
145 if (ia64_sn_get_sapic_info(get_sapicid(), &nasid, NULL, NULL))
146 BUG();
147 return nasid;
148}
149
150/*
151 * This routine can only be used during init, since
152 * smp_boot_data is an init data structure.
153 * We have to use smp_boot_data.cpu_phys_id to find
154 * the physical id of the processor because the normal
155 * cpu_physical_id() relies on data structures that
156 * may not be initialized yet.
157 */
158
159static int __init pxm_to_nasid(int pxm)
160{
161 int i;
162 int nid;
163
164 nid = pxm_to_nid_map[pxm];
165 for (i = 0; i < num_node_memblks; i++) {
166 if (node_memblk[i].nid == nid) {
167 return NASID_GET(node_memblk[i].start_paddr);
168 }
169 }
170 return -1;
171}
172
173/**
174 * early_sn_setup - early setup routine for SN platforms
175 *
176 * Sets up an initial console to aid debugging. Intended primarily
177 * for bringup. See start_kernel() in init/main.c.
178 */
179
180void __init early_sn_setup(void)
181{
182 efi_system_table_t *efi_systab;
183 efi_config_table_t *config_tables;
184 struct ia64_sal_systab *sal_systab;
185 struct ia64_sal_desc_entry_point *ep;
186 char *p;
187 int i, j;
188
189 /*
190 * Parse enough of the SAL tables to locate the SAL entry point. Since, console
191 * IO on SN2 is done via SAL calls, early_printk won't work without this.
192 *
193 * This code duplicates some of the ACPI table parsing that is in efi.c & sal.c.
194 * Any changes to those file may have to be made hereas well.
195 */
196 efi_systab = (efi_system_table_t *) __va(ia64_boot_param->efi_systab);
197 config_tables = __va(efi_systab->tables);
198 for (i = 0; i < efi_systab->nr_tables; i++) {
199 if (efi_guidcmp(config_tables[i].guid, SAL_SYSTEM_TABLE_GUID) ==
200 0) {
201 sal_systab = __va(config_tables[i].table);
202 p = (char *)(sal_systab + 1);
203 for (j = 0; j < sal_systab->entry_count; j++) {
204 if (*p == SAL_DESC_ENTRY_POINT) {
205 ep = (struct ia64_sal_desc_entry_point
206 *)p;
207 ia64_sal_handler_init(__va
208 (ep->sal_proc),
209 __va(ep->gp));
210 return;
211 }
212 p += SAL_DESC_SIZE(*p);
213 }
214 }
215 }
216 /* Uh-oh, SAL not available?? */
217 printk(KERN_ERR "failed to find SAL entry point\n");
218}
219
220extern int platform_intr_list[];
221extern nasid_t master_nasid;
222static int shub_1_1_found __initdata;
223
224/*
225 * sn_check_for_wars
226 *
227 * Set flag for enabling shub specific wars
228 */
229
230static inline int __init is_shub_1_1(int nasid)
231{
232 unsigned long id;
233 int rev;
234
235 if (is_shub2())
236 return 0;
237 id = REMOTE_HUB_L(nasid, SH1_SHUB_ID);
238 rev = (id & SH1_SHUB_ID_REVISION_MASK) >> SH1_SHUB_ID_REVISION_SHFT;
239 return rev <= 2;
240}
241
242static void __init sn_check_for_wars(void)
243{
244 int cnode;
245
246 if (is_shub2()) {
247 /* none yet */
248 } else {
249 for_each_online_node(cnode) {
250 if (is_shub_1_1(cnodeid_to_nasid(cnode)))
251 sn_hub_info->shub_1_1_found = 1;
252 }
253 }
254}
255
256/**
257 * sn_setup - SN platform setup routine
258 * @cmdline_p: kernel command line
259 *
260 * Handles platform setup for SN machines. This includes determining
261 * the RTC frequency (via a SAL call), initializing secondary CPUs, and
262 * setting up per-node data areas. The console is also initialized here.
263 */
264void __init sn_setup(char **cmdline_p)
265{
266 long status, ticks_per_sec, drift;
267 int pxm;
268 int major = sn_sal_rev_major(), minor = sn_sal_rev_minor();
269 extern void sn_cpu_init(void);
270
271 /*
272 * If the generic code has enabled vga console support - lets
273 * get rid of it again. This is a kludge for the fact that ACPI
274 * currtently has no way of informing us if legacy VGA is available
275 * or not.
276 */
277#if defined(CONFIG_VT) && defined(CONFIG_VGA_CONSOLE)
278 if (conswitchp == &vga_con) {
279 printk(KERN_DEBUG "SGI: Disabling VGA console\n");
280#ifdef CONFIG_DUMMY_CONSOLE
281 conswitchp = &dummy_con;
282#else
283 conswitchp = NULL;
284#endif /* CONFIG_DUMMY_CONSOLE */
285 }
286#endif /* def(CONFIG_VT) && def(CONFIG_VGA_CONSOLE) */
287
288 MAX_DMA_ADDRESS = PAGE_OFFSET + MAX_PHYS_MEMORY;
289
290 memset(physical_node_map, -1, sizeof(physical_node_map));
291 for (pxm = 0; pxm < MAX_PXM_DOMAINS; pxm++)
292 if (pxm_to_nid_map[pxm] != -1)
293 physical_node_map[pxm_to_nasid(pxm)] =
294 pxm_to_nid_map[pxm];
295
296 /*
297 * Old PROMs do not provide an ACPI FADT. Disable legacy keyboard
298 * support here so we don't have to listen to failed keyboard probe
299 * messages.
300 */
301 if ((major < 2 || (major == 2 && minor <= 9)) &&
302 acpi_kbd_controller_present) {
303 printk(KERN_INFO "Disabling legacy keyboard support as prom "
304 "is too old and doesn't provide FADT\n");
305 acpi_kbd_controller_present = 0;
306 }
307
308 printk("SGI SAL version %x.%02x\n", major, minor);
309
310 /*
311 * Confirm the SAL we're running on is recent enough...
312 */
313 if ((major < SN_SAL_MIN_MAJOR) || (major == SN_SAL_MIN_MAJOR &&
314 minor < SN_SAL_MIN_MINOR)) {
315 printk(KERN_ERR "This kernel needs SGI SAL version >= "
316 "%x.%02x\n", SN_SAL_MIN_MAJOR, SN_SAL_MIN_MINOR);
317 panic("PROM version too old\n");
318 }
319
320 master_nasid = boot_get_nasid();
321
322 status =
323 ia64_sal_freq_base(SAL_FREQ_BASE_REALTIME_CLOCK, &ticks_per_sec,
324 &drift);
325 if (status != 0 || ticks_per_sec < 100000) {
326 printk(KERN_WARNING
327 "unable to determine platform RTC clock frequency, guessing.\n");
328 /* PROM gives wrong value for clock freq. so guess */
329 sn_rtc_cycles_per_second = 1000000000000UL / 30000UL;
330 } else
331 sn_rtc_cycles_per_second = ticks_per_sec;
332
333 platform_intr_list[ACPI_INTERRUPT_CPEI] = IA64_CPE_VECTOR;
334
335 /*
336 * we set the default root device to /dev/hda
337 * to make simulation easy
338 */
339 ROOT_DEV = Root_HDA1;
340
341 /*
342 * Create the PDAs and NODEPDAs for all the cpus.
343 */
344 sn_init_pdas(cmdline_p);
345
346 ia64_mark_idle = &snidle;
347
348 /*
349 * For the bootcpu, we do this here. All other cpus will make the
350 * call as part of cpu_init in slave cpu initialization.
351 */
352 sn_cpu_init();
353
354#ifdef CONFIG_SMP
355 init_smp_config();
356#endif
357 screen_info = sn_screen_info;
358
359 sn_timer_init();
Aaron J Youngc1298c52005-04-25 13:11:14 -0700360
361 /*
362 * set pm_power_off to a SAL call to allow
363 * sn machines to power off. The SAL call can be replaced
364 * by an ACPI interface call when ACPI is fully implemented
365 * for sn.
366 */
367 pm_power_off = ia64_sn_power_down;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700368}
369
370/**
371 * sn_init_pdas - setup node data areas
372 *
373 * One time setup for Node Data Area. Called by sn_setup().
374 */
375static void __init sn_init_pdas(char **cmdline_p)
376{
377 cnodeid_t cnode;
378
Dean Nelson2e34f072005-03-21 19:41:00 -0700379 memset(sn_cnodeid_to_nasid, -1,
380 sizeof(__ia64_per_cpu_var(__sn_cnodeid_to_nasid)));
Linus Torvalds1da177e2005-04-16 15:20:36 -0700381 for_each_online_node(cnode)
Dean Nelson2e34f072005-03-21 19:41:00 -0700382 sn_cnodeid_to_nasid[cnode] =
383 pxm_to_nasid(nid_to_pxm_map[cnode]);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700384
385 numionodes = num_online_nodes();
386 scan_for_ionodes();
387
388 /*
389 * Allocate & initalize the nodepda for each node.
390 */
391 for_each_online_node(cnode) {
392 nodepdaindr[cnode] =
393 alloc_bootmem_node(NODE_DATA(cnode), sizeof(nodepda_t));
394 memset(nodepdaindr[cnode], 0, sizeof(nodepda_t));
395 memset(nodepdaindr[cnode]->phys_cpuid, -1,
396 sizeof(nodepdaindr[cnode]->phys_cpuid));
397 }
398
399 /*
400 * Allocate & initialize nodepda for TIOs. For now, put them on node 0.
401 */
402 for (cnode = num_online_nodes(); cnode < numionodes; cnode++) {
403 nodepdaindr[cnode] =
404 alloc_bootmem_node(NODE_DATA(0), sizeof(nodepda_t));
405 memset(nodepdaindr[cnode], 0, sizeof(nodepda_t));
406 }
407
408 /*
409 * Now copy the array of nodepda pointers to each nodepda.
410 */
411 for (cnode = 0; cnode < numionodes; cnode++)
412 memcpy(nodepdaindr[cnode]->pernode_pdaindr, nodepdaindr,
413 sizeof(nodepdaindr));
414
415 /*
416 * Set up IO related platform-dependent nodepda fields.
417 * The following routine actually sets up the hubinfo struct
418 * in nodepda.
419 */
420 for_each_online_node(cnode) {
421 bte_init_node(nodepdaindr[cnode], cnode);
422 }
423
424 /*
425 * Initialize the per node hubdev. This includes IO Nodes and
426 * headless/memless nodes.
427 */
428 for (cnode = 0; cnode < numionodes; cnode++) {
429 hubdev_init_node(nodepdaindr[cnode], cnode);
430 }
431}
432
433/**
434 * sn_cpu_init - initialize per-cpu data areas
435 * @cpuid: cpuid of the caller
436 *
437 * Called during cpu initialization on each cpu as it starts.
438 * Currently, initializes the per-cpu data area for SNIA.
439 * Also sets up a few fields in the nodepda. Also known as
440 * platform_cpu_init() by the ia64 machvec code.
441 */
442void __init sn_cpu_init(void)
443{
444 int cpuid;
445 int cpuphyid;
446 int nasid;
447 int subnode;
448 int slice;
449 int cnode;
450 int i;
451 static int wars_have_been_checked;
452
453 memset(pda, 0, sizeof(pda));
454 if (ia64_sn_get_sn_info(0, &sn_hub_info->shub2, &sn_hub_info->nasid_bitmask, &sn_hub_info->nasid_shift,
455 &sn_system_size, &sn_sharing_domain_size, &sn_partition_id,
456 &sn_coherency_id, &sn_region_size))
457 BUG();
458 sn_hub_info->as_shift = sn_hub_info->nasid_shift - 2;
459
460 /*
461 * The boot cpu makes this call again after platform initialization is
462 * complete.
463 */
464 if (nodepdaindr[0] == NULL)
465 return;
466
467 cpuid = smp_processor_id();
468 cpuphyid = get_sapicid();
469
470 if (ia64_sn_get_sapic_info(cpuphyid, &nasid, &subnode, &slice))
471 BUG();
472
473 for (i=0; i < MAX_NUMNODES; i++) {
474 if (nodepdaindr[i]) {
475 nodepdaindr[i]->phys_cpuid[cpuid].nasid = nasid;
476 nodepdaindr[i]->phys_cpuid[cpuid].slice = slice;
477 nodepdaindr[i]->phys_cpuid[cpuid].subnode = subnode;
478 }
479 }
480
481 cnode = nasid_to_cnodeid(nasid);
482
483 pda->p_nodepda = nodepdaindr[cnode];
484 pda->led_address =
485 (typeof(pda->led_address)) (LED0 + (slice << LED_CPU_SHIFT));
486 pda->led_state = LED_ALWAYS_SET;
487 pda->hb_count = HZ / 2;
488 pda->hb_state = 0;
489 pda->idle_flag = 0;
490
491 if (cpuid != 0) {
Dean Nelson2e34f072005-03-21 19:41:00 -0700492 /* copy cpu 0's sn_cnodeid_to_nasid table to this cpu's */
493 memcpy(sn_cnodeid_to_nasid,
494 (&per_cpu(__sn_cnodeid_to_nasid, 0)),
495 sizeof(__ia64_per_cpu_var(__sn_cnodeid_to_nasid)));
Linus Torvalds1da177e2005-04-16 15:20:36 -0700496 }
497
498 /*
499 * Check for WARs.
500 * Only needs to be done once, on BSP.
Dean Nelson2e34f072005-03-21 19:41:00 -0700501 * Has to be done after loop above, because it uses this cpu's
502 * sn_cnodeid_to_nasid table which was just initialized if this
503 * isn't cpu 0.
Linus Torvalds1da177e2005-04-16 15:20:36 -0700504 * Has to be done before assignment below.
505 */
506 if (!wars_have_been_checked) {
507 sn_check_for_wars();
508 wars_have_been_checked = 1;
509 }
510 sn_hub_info->shub_1_1_found = shub_1_1_found;
511
512 /*
513 * Set up addresses of PIO/MEM write status registers.
514 */
515 {
516 u64 pio1[] = {SH1_PIO_WRITE_STATUS_0, 0, SH1_PIO_WRITE_STATUS_1, 0};
517 u64 pio2[] = {SH2_PIO_WRITE_STATUS_0, SH2_PIO_WRITE_STATUS_1,
518 SH2_PIO_WRITE_STATUS_2, SH2_PIO_WRITE_STATUS_3};
519 u64 *pio;
520 pio = is_shub1() ? pio1 : pio2;
521 pda->pio_write_status_addr = (volatile unsigned long *) LOCAL_MMR_ADDR(pio[slice]);
522 pda->pio_write_status_val = is_shub1() ? SH_PIO_WRITE_STATUS_PENDING_WRITE_COUNT_MASK : 0;
523 }
524
525 /*
526 * WAR addresses for SHUB 1.x.
527 */
528 if (local_node_data->active_cpu_count++ == 0 && is_shub1()) {
529 int buddy_nasid;
530 buddy_nasid =
531 cnodeid_to_nasid(numa_node_id() ==
532 num_online_nodes() - 1 ? 0 : numa_node_id() + 1);
533 pda->pio_shub_war_cam_addr =
534 (volatile unsigned long *)GLOBAL_MMR_ADDR(nasid,
535 SH1_PI_CAM_CONTROL);
536 }
537}
538
539/*
540 * Scan klconfig for ionodes. Add the nasids to the
541 * physical_node_map and the pda and increment numionodes.
542 */
543
544static void __init scan_for_ionodes(void)
545{
546 int nasid = 0;
547 lboard_t *brd;
548
549 /* Setup ionodes with memory */
550 for (nasid = 0; nasid < MAX_PHYSNODE_ID; nasid += 2) {
551 char *klgraph_header;
552 cnodeid_t cnodeid;
553
554 if (physical_node_map[nasid] == -1)
555 continue;
556
557 cnodeid = -1;
558 klgraph_header = __va(ia64_sn_get_klconfig_addr(nasid));
559 if (!klgraph_header) {
560 if (IS_RUNNING_ON_SIMULATOR())
561 continue;
562 BUG(); /* All nodes must have klconfig tables! */
563 }
564 cnodeid = nasid_to_cnodeid(nasid);
565 root_lboard[cnodeid] = (lboard_t *)
566 NODE_OFFSET_TO_LBOARD((nasid),
567 ((kl_config_hdr_t
568 *) (klgraph_header))->
569 ch_board_info);
570 }
571
572 /* Scan headless/memless IO Nodes. */
573 for (nasid = 0; nasid < MAX_PHYSNODE_ID; nasid += 2) {
574 /* if there's no nasid, don't try to read the klconfig on the node */
575 if (physical_node_map[nasid] == -1)
576 continue;
577 brd = find_lboard_any((lboard_t *)
578 root_lboard[nasid_to_cnodeid(nasid)],
579 KLTYPE_SNIA);
580 if (brd) {
581 brd = KLCF_NEXT_ANY(brd); /* Skip this node's lboard */
582 if (!brd)
583 continue;
584 }
585
586 brd = find_lboard_any(brd, KLTYPE_SNIA);
587
588 while (brd) {
Dean Nelson2e34f072005-03-21 19:41:00 -0700589 sn_cnodeid_to_nasid[numionodes] = brd->brd_nasid;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700590 physical_node_map[brd->brd_nasid] = numionodes;
591 root_lboard[numionodes] = brd;
592 numionodes++;
593 brd = KLCF_NEXT_ANY(brd);
594 if (!brd)
595 break;
596
597 brd = find_lboard_any(brd, KLTYPE_SNIA);
598 }
599 }
600
601 /* Scan for TIO nodes. */
602 for (nasid = 0; nasid < MAX_PHYSNODE_ID; nasid += 2) {
603 /* if there's no nasid, don't try to read the klconfig on the node */
604 if (physical_node_map[nasid] == -1)
605 continue;
606 brd = find_lboard_any((lboard_t *)
607 root_lboard[nasid_to_cnodeid(nasid)],
608 KLTYPE_TIO);
609 while (brd) {
Dean Nelson2e34f072005-03-21 19:41:00 -0700610 sn_cnodeid_to_nasid[numionodes] = brd->brd_nasid;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700611 physical_node_map[brd->brd_nasid] = numionodes;
612 root_lboard[numionodes] = brd;
613 numionodes++;
614 brd = KLCF_NEXT_ANY(brd);
615 if (!brd)
616 break;
617
618 brd = find_lboard_any(brd, KLTYPE_TIO);
619 }
620 }
Linus Torvalds1da177e2005-04-16 15:20:36 -0700621}
622
623int
624nasid_slice_to_cpuid(int nasid, int slice)
625{
626 long cpu;
627
628 for (cpu=0; cpu < NR_CPUS; cpu++)
629 if (nodepda->phys_cpuid[cpu].nasid == nasid && nodepda->phys_cpuid[cpu].slice == slice)
630 return cpu;
631
632 return -1;
633}