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
6 * Copyright (C) 1999,2001-2003 Silicon Graphics, Inc. All rights reserved.
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>
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>
34 #include <asm/machvec.h>
35 #include <asm/system.h>
36 #include <asm/processor.h>
37 #include <asm/sn/sgi.h>
38 #include <asm/sn/io.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/sn_private.h>
45 #include <asm/sn/simulator.h>
46 #include <asm/sn/leds.h>
47 #include <asm/sn/bte.h>
48 #include <asm/sn/clksupport.h>
49 #include <asm/sn/sn_sal.h>
50 #include <asm/sn/sn2/shub.h>
52 DEFINE_PER_CPU(struct pda_s, pda_percpu);
54 #define MAX_PHYS_MEMORY (1UL << 49) /* 1 TB */
56 extern void bte_init_node (nodepda_t *, cnodeid_t);
57 extern void sn_timer_init(void);
58 extern unsigned long last_time_offset;
59 extern void init_platform_hubinfo(nodepda_t **nodepdaindr);
60 extern void (*ia64_mark_idle)(int);
61 extern void snidle(int);
62 extern unsigned char acpi_kbd_controller_present;
65 unsigned long sn_rtc_cycles_per_second;
67 partid_t sn_partid = -1;
68 char sn_system_serial_number_string[128];
69 u64 sn_partition_serial_number;
71 short physical_node_map[MAX_PHYSNODE_ID];
73 EXPORT_SYMBOL(physical_node_map);
77 * This is the address of the RRegs in the HSpace of the global
78 * master. It is used by a hack in serial.c (serial_[in|out],
79 * printk.c (early_printk), and kdb_io.c to put console output on that
80 * node's Bedrock UART. It is initialized here to 0, so that
81 * early_printk won't try to access the UART before
82 * master_node_bedrock_address is properly calculated.
84 u64 master_node_bedrock_address;
86 static void sn_init_pdas(char **);
87 static void scan_for_ionodes(void);
90 static nodepda_t *nodepdaindr[MAX_COMPACT_NODES];
96 * The format of "screen_info" is strange, and due to early i386-setup
97 * code. This is just enough to make the console code think we're on a
100 struct screen_info sn_screen_info = {
103 .orig_video_mode = 3,
104 .orig_video_cols = 80,
105 .orig_video_ega_bx = 3,
106 .orig_video_lines = 25,
107 .orig_video_isVGA = 1,
108 .orig_video_points = 16
112 * This is here so we can use the CMOS detection in ide-probe.c to
113 * determine what drives are present. In theory, we don't need this
114 * as the auto-detection could be done via ide-probe.c:do_probe() but
115 * in practice that would be much slower, which is painful when
116 * running in the simulator. Note that passing zeroes in DRIVE_INFO
117 * is sufficient (the IDE driver will autodetect the drive geometry).
119 #ifdef CONFIG_IA64_GENERIC
120 extern char drive_info[4*16];
122 char drive_info[4*16];
126 * This routine can only be used during init, since
127 * smp_boot_data is an init data structure.
128 * We have to use smp_boot_data.cpu_phys_id to find
129 * the physical id of the processor because the normal
130 * cpu_physical_id() relies on data structures that
131 * may not be initialized yet.
135 pxm_to_nasid(int pxm)
140 nid = pxm_to_nid_map[pxm];
141 for (i = 0; i < num_node_memblks; i++) {
142 if (node_memblk[i].nid == nid) {
143 return NASID_GET(node_memblk[i].start_paddr);
149 * early_sn_setup - early setup routine for SN platforms
151 * Sets up an initial console to aid debugging. Intended primarily
152 * for bringup. See start_kernel() in init/main.c.
158 void ia64_sal_handler_init (void *entry_point, void *gpval);
159 efi_system_table_t *efi_systab;
160 efi_config_table_t *config_tables;
161 struct ia64_sal_systab *sal_systab;
162 struct ia64_sal_desc_entry_point *ep;
167 * Parse enough of the SAL tables to locate the SAL entry point. Since, console
168 * IO on SN2 is done via SAL calls, early_printk won't work without this.
170 * This code duplicates some of the ACPI table parsing that is in efi.c & sal.c.
171 * Any changes to those file may have to be made hereas well.
173 efi_systab = (efi_system_table_t*)__va(ia64_boot_param->efi_systab);
174 config_tables = __va(efi_systab->tables);
175 for (i = 0; i < efi_systab->nr_tables; i++) {
176 if (efi_guidcmp(config_tables[i].guid, SAL_SYSTEM_TABLE_GUID) == 0) {
177 sal_systab = __va(config_tables[i].table);
178 p = (char*)(sal_systab+1);
179 for (i = 0; i < sal_systab->entry_count; i++) {
180 if (*p == SAL_DESC_ENTRY_POINT) {
181 ep = (struct ia64_sal_desc_entry_point *) p;
182 ia64_sal_handler_init(__va(ep->sal_proc), __va(ep->gp));
185 p += SAL_DESC_SIZE(*p);
190 if ( IS_RUNNING_ON_SIMULATOR() ) {
191 master_node_bedrock_address = (u64)REMOTE_HUB(get_nasid(), SH_JUNK_BUS_UART0);
192 printk(KERN_DEBUG "early_sn_setup: setting master_node_bedrock_address to 0x%lx\n", master_node_bedrock_address);
196 extern int platform_intr_list[];
197 extern nasid_t master_nasid;
198 static int shub_1_1_found __initdata;
204 * Set flag for enabling shub specific wars
207 static inline int __init
208 is_shub_1_1(int nasid)
213 id = REMOTE_HUB_L(nasid, SH_SHUB_ID);
214 rev = (id & SH_SHUB_ID_REVISION_MASK) >> SH_SHUB_ID_REVISION_SHFT;
219 sn_check_for_wars(void)
223 for (cnode=0; cnode< numnodes; cnode++)
224 if (is_shub_1_1(cnodeid_to_nasid(cnode)))
229 * sn_set_error_handling_features - Tell the SN prom how to handle certain
233 sn_set_error_handling_features(void)
236 u64 sn_ehf_bits[7]; /* see ia64_sn_set_error_handling_features */
237 memset(sn_ehf_bits, 0, sizeof(sn_ehf_bits));
238 #define EHF(x) __set_bit(SN_SAL_EHF_ ## x, sn_ehf_bits)
239 EHF(MCA_SLV_TO_OS_INIT_SLV);
241 // Uncomment once Jesse's code goes in - EHF(NO_RZ_IO_READ);
243 ret = ia64_sn_set_error_handling_features(sn_ehf_bits);
245 printk(KERN_ERR "%s: failed, return code %ld\n", __FUNCTION__, ret);
249 * sn_setup - SN platform setup routine
250 * @cmdline_p: kernel command line
252 * Handles platform setup for SN machines. This includes determining
253 * the RTC frequency (via a SAL call), initializing secondary CPUs, and
254 * setting up per-node data areas. The console is also initialized here.
257 sn_setup(char **cmdline_p)
259 long status, ticks_per_sec, drift;
261 int major = sn_sal_rev_major(), minor = sn_sal_rev_minor();
262 extern nasid_t snia_get_master_baseio_nasid(void);
263 extern void sn_cpu_init(void);
264 extern nasid_t snia_get_console_nasid(void);
267 * If the generic code has enabled vga console support - lets
268 * get rid of it again. This is a kludge for the fact that ACPI
269 * currtently has no way of informing us if legacy VGA is available
272 #if defined(CONFIG_VT) && defined(CONFIG_VGA_CONSOLE)
273 if (conswitchp == &vga_con) {
274 printk(KERN_DEBUG "SGI: Disabling VGA console\n");
275 #ifdef CONFIG_DUMMY_CONSOLE
276 conswitchp = &dummy_con;
279 #endif /* CONFIG_DUMMY_CONSOLE */
281 #endif /* def(CONFIG_VT) && def(CONFIG_VGA_CONSOLE) */
283 MAX_DMA_ADDRESS = PAGE_OFFSET + MAX_PHYS_MEMORY;
285 memset(physical_node_map, -1, sizeof(physical_node_map));
286 for (pxm=0; pxm<MAX_PXM_DOMAINS; pxm++)
287 if (pxm_to_nid_map[pxm] != -1)
288 physical_node_map[pxm_to_nasid(pxm)] = pxm_to_nid_map[pxm];
292 * Old PROMs do not provide an ACPI FADT. Disable legacy keyboard
293 * support here so we don't have to listen to failed keyboard probe
296 if ((major < 2 || (major == 2 && minor <= 9)) &&
297 acpi_kbd_controller_present) {
298 printk(KERN_INFO "Disabling legacy keyboard support as prom "
299 "is too old and doesn't provide FADT\n");
300 acpi_kbd_controller_present = 0;
303 printk("SGI SAL version %x.%02x\n", major, minor);
306 * Confirm the SAL we're running on is recent enough...
308 if ((major < SN_SAL_MIN_MAJOR) || (major == SN_SAL_MIN_MAJOR &&
309 minor < SN_SAL_MIN_MINOR)) {
310 printk(KERN_ERR "This kernel needs SGI SAL version >= "
311 "%x.%02x\n", SN_SAL_MIN_MAJOR, SN_SAL_MIN_MINOR);
312 panic("PROM version too old\n");
315 master_nasid = get_nasid();
316 (void)snia_get_console_nasid();
317 (void)snia_get_master_baseio_nasid();
319 status = ia64_sal_freq_base(SAL_FREQ_BASE_REALTIME_CLOCK, &ticks_per_sec, &drift);
320 if (status != 0 || ticks_per_sec < 100000) {
321 printk(KERN_WARNING "unable to determine platform RTC clock frequency, guessing.\n");
322 /* PROM gives wrong value for clock freq. so guess */
323 sn_rtc_cycles_per_second = 1000000000000UL/30000UL;
326 sn_rtc_cycles_per_second = ticks_per_sec;
328 platform_intr_list[ACPI_INTERRUPT_CPEI] = IA64_CPE_VECTOR;
331 if ( IS_RUNNING_ON_SIMULATOR() )
333 master_node_bedrock_address = (u64)REMOTE_HUB(get_nasid(), SH_JUNK_BUS_UART0);
334 printk(KERN_DEBUG "sn_setup: setting master_node_bedrock_address to 0x%lx\n",
335 master_node_bedrock_address);
338 /* Tell the prom how to handle certain error types */
339 sn_set_error_handling_features();
342 * we set the default root device to /dev/hda
343 * to make simulation easy
345 ROOT_DEV = Root_HDA1;
348 * Create the PDAs and NODEPDAs for all the cpus.
350 sn_init_pdas(cmdline_p);
352 ia64_mark_idle = &snidle;
355 * For the bootcpu, we do this here. All other cpus will make the
356 * call as part of cpu_init in slave cpu initialization.
361 * Setup hubinfo stuff. Has to happen AFTER sn_cpu_init(),
362 * because it uses the cnode to nasid tables.
364 init_platform_hubinfo(nodepdaindr);
369 screen_info = sn_screen_info;
375 * sn_init_pdas - setup node data areas
377 * One time setup for Node Data Area. Called by sn_setup().
380 sn_init_pdas(char **cmdline_p)
384 memset(pda->cnodeid_to_nasid_table, -1, sizeof(pda->cnodeid_to_nasid_table));
385 for (cnode=0; cnode<numnodes; cnode++)
386 pda->cnodeid_to_nasid_table[cnode] = pxm_to_nasid(nid_to_pxm_map[cnode]);
388 numionodes = numnodes;
392 * Allocate & initalize the nodepda for each node.
394 for (cnode=0; cnode < numnodes; cnode++) {
395 nodepdaindr[cnode] = alloc_bootmem_node(NODE_DATA(cnode), sizeof(nodepda_t));
396 memset(nodepdaindr[cnode], 0, sizeof(nodepda_t));
400 * Now copy the array of nodepda pointers to each nodepda.
402 for (cnode=0; cnode < numionodes; cnode++)
403 memcpy(nodepdaindr[cnode]->pernode_pdaindr, nodepdaindr, sizeof(nodepdaindr));
407 * Set up IO related platform-dependent nodepda fields.
408 * The following routine actually sets up the hubinfo struct
411 for (cnode = 0; cnode < numnodes; cnode++) {
412 init_platform_nodepda(nodepdaindr[cnode], cnode);
413 bte_init_node (nodepdaindr[cnode], cnode);
418 * sn_cpu_init - initialize per-cpu data areas
419 * @cpuid: cpuid of the caller
421 * Called during cpu initialization on each cpu as it starts.
422 * Currently, initializes the per-cpu data area for SNIA.
423 * Also sets up a few fields in the nodepda. Also known as
424 * platform_cpu_init() by the ia64 machvec code.
434 static int wars_have_been_checked;
437 * The boot cpu makes this call again after platform initialization is
440 if (nodepdaindr[0] == NULL)
443 cpuid = smp_processor_id();
444 cpuphyid = ((ia64_getreg(_IA64_REG_CR_LID) >> 16) & 0xffff);
445 nasid = cpu_physical_id_to_nasid(cpuphyid);
446 cnode = nasid_to_cnodeid(nasid);
447 slice = cpu_physical_id_to_slice(cpuphyid);
449 memset(pda, 0, sizeof(pda));
450 pda->p_nodepda = nodepdaindr[cnode];
451 pda->led_address = (typeof(pda->led_address)) (LED0 + (slice<<LED_CPU_SHIFT));
452 pda->led_state = LED_ALWAYS_SET;
453 pda->hb_count = HZ/2;
458 memcpy(pda->cnodeid_to_nasid_table, pdacpu(0)->cnodeid_to_nasid_table,
459 sizeof(pda->cnodeid_to_nasid_table));
464 * Only needs to be done once, on BSP.
465 * Has to be done after loop above, because it uses pda.cnodeid_to_nasid_table[i].
466 * Has to be done before assignment below.
468 if (!wars_have_been_checked) {
470 wars_have_been_checked = 1;
472 pda->shub_1_1_found = shub_1_1_found;
476 * We must use different memory allocators for first cpu (bootmem
477 * allocator) than for the other cpus (regular allocator).
480 irqpdaindr = alloc_bootmem_node(NODE_DATA(cpuid_to_cnodeid(cpuid)),sizeof(irqpda_t));
482 memset(irqpdaindr, 0, sizeof(irqpda_t));
483 irqpdaindr->irq_flags[SGI_PCIBR_ERROR] = SN2_IRQ_SHARED;
484 irqpdaindr->irq_flags[SGI_PCIBR_ERROR] |= SN2_IRQ_RESERVED;
485 irqpdaindr->irq_flags[SGI_II_ERROR] = SN2_IRQ_SHARED;
486 irqpdaindr->irq_flags[SGI_II_ERROR] |= SN2_IRQ_RESERVED;
488 pda->pio_write_status_addr = (volatile unsigned long *)
489 LOCAL_MMR_ADDR((slice < 2 ? SH_PIO_WRITE_STATUS_0 : SH_PIO_WRITE_STATUS_1 ) );
490 pda->mem_write_status_addr = (volatile u64 *)
491 LOCAL_MMR_ADDR((slice < 2 ? SH_MEMORY_WRITE_STATUS_0 : SH_MEMORY_WRITE_STATUS_1 ) );
493 if (local_node_data->active_cpu_count++ == 0) {
495 buddy_nasid = cnodeid_to_nasid(numa_node_id() == numnodes-1 ? 0 : numa_node_id()+ 1);
496 pda->pio_shub_war_cam_addr = (volatile unsigned long*)GLOBAL_MMR_ADDR(nasid, SH_PI_CAM_CONTROL);
501 * Scan klconfig for ionodes. Add the nasids to the
502 * physical_node_map and the pda and increment numionodes.
506 scan_for_ionodes(void)
511 /* Setup ionodes with memory */
512 for (nasid = 0; nasid < MAX_PHYSNODE_ID; nasid +=2) {
516 if (physical_node_map[nasid] == -1)
519 klgraph_header = cnodeid = -1;
520 klgraph_header = ia64_sn_get_klconfig_addr(nasid);
521 if (klgraph_header <= 0) {
522 if ( IS_RUNNING_ON_SIMULATOR() )
524 BUG(); /* All nodes must have klconfig tables! */
526 cnodeid = nasid_to_cnodeid(nasid);
527 root_lboard[cnodeid] = (lboard_t *)
528 NODE_OFFSET_TO_LBOARD( (nasid),
529 ((kl_config_hdr_t *)(klgraph_header))->
533 /* Scan headless/memless IO Nodes. */
534 for (nasid = 0; nasid < MAX_PHYSNODE_ID; nasid +=2) {
535 /* if there's no nasid, don't try to read the klconfig on the node */
536 if (physical_node_map[nasid] == -1) continue;
537 brd = find_lboard_any((lboard_t *)root_lboard[nasid_to_cnodeid(nasid)], KLTYPE_SNIA);
539 brd = KLCF_NEXT_ANY(brd); /* Skip this node's lboard */
544 brd = find_lboard_any(brd, KLTYPE_SNIA);
546 pda->cnodeid_to_nasid_table[numionodes] = brd->brd_nasid;
547 physical_node_map[brd->brd_nasid] = numionodes;
548 root_lboard[numionodes] = brd;
550 brd = KLCF_NEXT_ANY(brd);
554 brd = find_lboard_any(brd, KLTYPE_SNIA);