[PATCH] ia64: Remove SN PDA page overflow check
[linux-2.6/history.git] / arch / ia64 / sn / kernel / setup.c
blobe42c83cfa9db8e38847955173ae182ffce576c58
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 * Copyright (C) 1999,2001-2003 Silicon Graphics, Inc. All rights reserved.
7 */
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>
32 #include <asm/io.h>
33 #include <asm/sal.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 bte_init_cpu (void);
58 extern void sn_timer_init(void);
59 extern unsigned long last_time_offset;
60 extern void init_platform_hubinfo(nodepda_t **nodepdaindr);
61 extern void (*ia64_mark_idle)(int);
62 extern void snidle(int);
63 extern unsigned char acpi_kbd_controller_present;
66 unsigned long sn_rtc_cycles_per_second;
68 partid_t sn_partid = -1;
69 char sn_system_serial_number_string[128];
70 u64 sn_partition_serial_number;
72 short physical_node_map[MAX_PHYSNODE_ID];
74 EXPORT_SYMBOL(physical_node_map);
76 int numionodes;
78 * This is the address of the RRegs in the HSpace of the global
79 * master. It is used by a hack in serial.c (serial_[in|out],
80 * printk.c (early_printk), and kdb_io.c to put console output on that
81 * node's Bedrock UART. It is initialized here to 0, so that
82 * early_printk won't try to access the UART before
83 * master_node_bedrock_address is properly calculated.
85 u64 master_node_bedrock_address;
87 static void sn_init_pdas(char **);
88 static void scan_for_ionodes(void);
91 static nodepda_t *nodepdaindr[MAX_COMPACT_NODES];
93 irqpda_t *irqpdaindr;
97 * The format of "screen_info" is strange, and due to early i386-setup
98 * code. This is just enough to make the console code think we're on a
99 * VGA color display.
101 struct screen_info sn_screen_info = {
102 .orig_x = 0,
103 .orig_y = 0,
104 .orig_video_mode = 3,
105 .orig_video_cols = 80,
106 .orig_video_ega_bx = 3,
107 .orig_video_lines = 25,
108 .orig_video_isVGA = 1,
109 .orig_video_points = 16
113 * This is here so we can use the CMOS detection in ide-probe.c to
114 * determine what drives are present. In theory, we don't need this
115 * as the auto-detection could be done via ide-probe.c:do_probe() but
116 * in practice that would be much slower, which is painful when
117 * running in the simulator. Note that passing zeroes in DRIVE_INFO
118 * is sufficient (the IDE driver will autodetect the drive geometry).
120 #ifdef CONFIG_IA64_GENERIC
121 extern char drive_info[4*16];
122 #else
123 char drive_info[4*16];
124 #endif
127 * This routine can only be used during init, since
128 * smp_boot_data is an init data structure.
129 * We have to use smp_boot_data.cpu_phys_id to find
130 * the physical id of the processor because the normal
131 * cpu_physical_id() relies on data structures that
132 * may not be initialized yet.
135 static int __init
136 pxm_to_nasid(int pxm)
138 int i;
139 int nid;
141 nid = pxm_to_nid_map[pxm];
142 for (i = 0; i < num_node_memblks; i++) {
143 if (node_memblk[i].nid == nid) {
144 return NASID_GET(node_memblk[i].start_paddr);
147 return -1;
150 * early_sn_setup - early setup routine for SN platforms
152 * Sets up an initial console to aid debugging. Intended primarily
153 * for bringup. See start_kernel() in init/main.c.
156 void __init
157 early_sn_setup(void)
159 void ia64_sal_handler_init (void *entry_point, void *gpval);
160 efi_system_table_t *efi_systab;
161 efi_config_table_t *config_tables;
162 struct ia64_sal_systab *sal_systab;
163 struct ia64_sal_desc_entry_point *ep;
164 char *p;
165 int i;
168 * Parse enough of the SAL tables to locate the SAL entry point. Since, console
169 * IO on SN2 is done via SAL calls, early_printk won't work without this.
171 * This code duplicates some of the ACPI table parsing that is in efi.c & sal.c.
172 * Any changes to those file may have to be made hereas well.
174 efi_systab = (efi_system_table_t*)__va(ia64_boot_param->efi_systab);
175 config_tables = __va(efi_systab->tables);
176 for (i = 0; i < efi_systab->nr_tables; i++) {
177 if (efi_guidcmp(config_tables[i].guid, SAL_SYSTEM_TABLE_GUID) == 0) {
178 sal_systab = __va(config_tables[i].table);
179 p = (char*)(sal_systab+1);
180 for (i = 0; i < sal_systab->entry_count; i++) {
181 if (*p == SAL_DESC_ENTRY_POINT) {
182 ep = (struct ia64_sal_desc_entry_point *) p;
183 ia64_sal_handler_init(__va(ep->sal_proc), __va(ep->gp));
184 break;
186 p += SAL_DESC_SIZE(*p);
191 if ( IS_RUNNING_ON_SIMULATOR() ) {
192 master_node_bedrock_address = (u64)REMOTE_HUB(get_nasid(), SH_JUNK_BUS_UART0);
193 printk(KERN_DEBUG "early_sn_setup: setting master_node_bedrock_address to 0x%lx\n", master_node_bedrock_address);
197 extern int platform_intr_list[];
198 extern nasid_t master_nasid;
199 static int shub_1_1_found __initdata;
203 * sn_check_for_wars
205 * Set flag for enabling shub specific wars
208 static inline int __init
209 is_shub_1_1(int nasid)
211 unsigned long id;
212 int rev;
214 id = REMOTE_HUB_L(nasid, SH_SHUB_ID);
215 rev = (id & SH_SHUB_ID_REVISION_MASK) >> SH_SHUB_ID_REVISION_SHFT;
216 return rev <= 2;
219 static void __init
220 sn_check_for_wars(void)
222 int cnode;
224 for (cnode=0; cnode< numnodes; cnode++)
225 if (is_shub_1_1(cnodeid_to_nasid(cnode)))
226 shub_1_1_found = 1;
232 * sn_setup - SN platform setup routine
233 * @cmdline_p: kernel command line
235 * Handles platform setup for SN machines. This includes determining
236 * the RTC frequency (via a SAL call), initializing secondary CPUs, and
237 * setting up per-node data areas. The console is also initialized here.
239 void __init
240 sn_setup(char **cmdline_p)
242 long status, ticks_per_sec, drift;
243 int pxm;
244 int major = sn_sal_rev_major(), minor = sn_sal_rev_minor();
245 extern nasid_t snia_get_master_baseio_nasid(void);
246 extern void sn_cpu_init(void);
247 extern nasid_t snia_get_console_nasid(void);
250 * If the generic code has enabled vga console support - lets
251 * get rid of it again. This is a kludge for the fact that ACPI
252 * currtently has no way of informing us if legacy VGA is available
253 * or not.
255 #if defined(CONFIG_VT) && defined(CONFIG_VGA_CONSOLE)
256 if (conswitchp == &vga_con) {
257 printk(KERN_DEBUG "SGI: Disabling VGA console\n");
258 #ifdef CONFIG_DUMMY_CONSOLE
259 conswitchp = &dummy_con;
260 #else
261 conswitchp = NULL;
262 #endif /* CONFIG_DUMMY_CONSOLE */
264 #endif /* def(CONFIG_VT) && def(CONFIG_VGA_CONSOLE) */
266 MAX_DMA_ADDRESS = PAGE_OFFSET + MAX_PHYS_MEMORY;
268 memset(physical_node_map, -1, sizeof(physical_node_map));
269 for (pxm=0; pxm<MAX_PXM_DOMAINS; pxm++)
270 if (pxm_to_nid_map[pxm] != -1)
271 physical_node_map[pxm_to_nasid(pxm)] = pxm_to_nid_map[pxm];
275 * Old PROMs do not provide an ACPI FADT. Disable legacy keyboard
276 * support here so we don't have to listen to failed keyboard probe
277 * messages.
279 if ((major < 2 || (major == 2 && minor <= 9)) &&
280 acpi_kbd_controller_present) {
281 printk(KERN_INFO "Disabling legacy keyboard support as prom "
282 "is too old and doesn't provide FADT\n");
283 acpi_kbd_controller_present = 0;
286 printk("SGI SAL version %x.%02x\n", major, minor);
289 * Confirm the SAL we're running on is recent enough...
291 if ((major < SN_SAL_MIN_MAJOR) || (major == SN_SAL_MIN_MAJOR &&
292 minor < SN_SAL_MIN_MINOR)) {
293 printk(KERN_ERR "This kernel needs SGI SAL version >= "
294 "%x.%02x\n", SN_SAL_MIN_MAJOR, SN_SAL_MIN_MINOR);
295 panic("PROM version too old\n");
298 master_nasid = get_nasid();
299 (void)snia_get_console_nasid();
300 (void)snia_get_master_baseio_nasid();
302 status = ia64_sal_freq_base(SAL_FREQ_BASE_REALTIME_CLOCK, &ticks_per_sec, &drift);
303 if (status != 0 || ticks_per_sec < 100000) {
304 printk(KERN_WARNING "unable to determine platform RTC clock frequency, guessing.\n");
305 /* PROM gives wrong value for clock freq. so guess */
306 sn_rtc_cycles_per_second = 1000000000000UL/30000UL;
308 else
309 sn_rtc_cycles_per_second = ticks_per_sec;
311 platform_intr_list[ACPI_INTERRUPT_CPEI] = IA64_CPE_VECTOR;
314 if ( IS_RUNNING_ON_SIMULATOR() )
316 master_node_bedrock_address = (u64)REMOTE_HUB(get_nasid(), SH_JUNK_BUS_UART0);
317 printk(KERN_DEBUG "sn_setup: setting master_node_bedrock_address to 0x%lx\n",
318 master_node_bedrock_address);
322 * we set the default root device to /dev/hda
323 * to make simulation easy
325 ROOT_DEV = Root_HDA1;
328 * Create the PDAs and NODEPDAs for all the cpus.
330 sn_init_pdas(cmdline_p);
332 ia64_mark_idle = &snidle;
335 * For the bootcpu, we do this here. All other cpus will make the
336 * call as part of cpu_init in slave cpu initialization.
338 sn_cpu_init();
341 * Setup hubinfo stuff. Has to happen AFTER sn_cpu_init(),
342 * because it uses the cnode to nasid tables.
344 init_platform_hubinfo(nodepdaindr);
346 #ifdef CONFIG_SMP
347 init_smp_config();
348 #endif
349 screen_info = sn_screen_info;
351 sn_timer_init();
355 * sn_init_pdas - setup node data areas
357 * One time setup for Node Data Area. Called by sn_setup().
359 void __init
360 sn_init_pdas(char **cmdline_p)
362 cnodeid_t cnode;
364 memset(pda->cnodeid_to_nasid_table, -1, sizeof(pda->cnodeid_to_nasid_table));
365 for (cnode=0; cnode<numnodes; cnode++)
366 pda->cnodeid_to_nasid_table[cnode] = pxm_to_nasid(nid_to_pxm_map[cnode]);
368 numionodes = numnodes;
369 scan_for_ionodes();
372 * Allocate & initalize the nodepda for each node.
374 for (cnode=0; cnode < numnodes; cnode++) {
375 nodepdaindr[cnode] = alloc_bootmem_node(NODE_DATA(cnode), sizeof(nodepda_t));
376 memset(nodepdaindr[cnode], 0, sizeof(nodepda_t));
380 * Now copy the array of nodepda pointers to each nodepda.
382 for (cnode=0; cnode < numionodes; cnode++)
383 memcpy(nodepdaindr[cnode]->pernode_pdaindr, nodepdaindr, sizeof(nodepdaindr));
387 * Set up IO related platform-dependent nodepda fields.
388 * The following routine actually sets up the hubinfo struct
389 * in nodepda.
391 for (cnode = 0; cnode < numnodes; cnode++) {
392 init_platform_nodepda(nodepdaindr[cnode], cnode);
393 bte_init_node (nodepdaindr[cnode], cnode);
398 * sn_cpu_init - initialize per-cpu data areas
399 * @cpuid: cpuid of the caller
401 * Called during cpu initialization on each cpu as it starts.
402 * Currently, initializes the per-cpu data area for SNIA.
403 * Also sets up a few fields in the nodepda. Also known as
404 * platform_cpu_init() by the ia64 machvec code.
406 void __init
407 sn_cpu_init(void)
409 int cpuid;
410 int cpuphyid;
411 int nasid;
412 int slice;
413 int cnode;
414 static int wars_have_been_checked;
417 * The boot cpu makes this call again after platform initialization is
418 * complete.
420 if (nodepdaindr[0] == NULL)
421 return;
423 cpuid = smp_processor_id();
424 cpuphyid = ((ia64_getreg(_IA64_REG_CR_LID) >> 16) & 0xffff);
425 nasid = cpu_physical_id_to_nasid(cpuphyid);
426 cnode = nasid_to_cnodeid(nasid);
427 slice = cpu_physical_id_to_slice(cpuphyid);
429 memset(pda, 0, sizeof(pda));
430 pda->p_nodepda = nodepdaindr[cnode];
431 pda->led_address = (typeof(pda->led_address)) (LED0 + (slice<<LED_CPU_SHIFT));
432 pda->led_state = LED_ALWAYS_SET;
433 pda->hb_count = HZ/2;
434 pda->hb_state = 0;
435 pda->idle_flag = 0;
437 if (cpuid != 0){
438 memcpy(pda->cnodeid_to_nasid_table, pdacpu(0)->cnodeid_to_nasid_table,
439 sizeof(pda->cnodeid_to_nasid_table));
443 * Check for WARs.
444 * Only needs to be done once, on BSP.
445 * Has to be done after loop above, because it uses pda.cnodeid_to_nasid_table[i].
446 * Has to be done before assignment below.
448 if (!wars_have_been_checked) {
449 sn_check_for_wars();
450 wars_have_been_checked = 1;
452 pda->shub_1_1_found = shub_1_1_found;
454 if (local_node_data->active_cpu_count == 1)
455 nodepda->node_first_cpu = cpuid;
460 * We must use different memory allocators for first cpu (bootmem
461 * allocator) than for the other cpus (regular allocator).
463 if (cpuid == 0)
464 irqpdaindr = alloc_bootmem_node(NODE_DATA(cpuid_to_cnodeid(cpuid)),sizeof(irqpda_t));
466 memset(irqpdaindr, 0, sizeof(irqpda_t));
467 irqpdaindr->irq_flags[SGI_PCIBR_ERROR] = SN2_IRQ_SHARED;
468 irqpdaindr->irq_flags[SGI_PCIBR_ERROR] |= SN2_IRQ_RESERVED;
469 irqpdaindr->irq_flags[SGI_II_ERROR] = SN2_IRQ_SHARED;
470 irqpdaindr->irq_flags[SGI_II_ERROR] |= SN2_IRQ_RESERVED;
472 pda->pio_write_status_addr = (volatile unsigned long *)
473 LOCAL_MMR_ADDR((slice < 2 ? SH_PIO_WRITE_STATUS_0 : SH_PIO_WRITE_STATUS_1 ) );
474 pda->mem_write_status_addr = (volatile u64 *)
475 LOCAL_MMR_ADDR((slice < 2 ? SH_MEMORY_WRITE_STATUS_0 : SH_MEMORY_WRITE_STATUS_1 ) );
477 if (nodepda->node_first_cpu == cpuid) {
478 int buddy_nasid;
479 buddy_nasid = cnodeid_to_nasid(numa_node_id() == numnodes-1 ? 0 : numa_node_id()+ 1);
480 pda->pio_shub_war_cam_addr = (volatile unsigned long*)GLOBAL_MMR_ADDR(nasid, SH_PI_CAM_CONTROL);
483 bte_init_cpu();
487 * Scan klconfig for ionodes. Add the nasids to the
488 * physical_node_map and the pda and increment numionodes.
491 static void __init
492 scan_for_ionodes(void)
494 int nasid = 0;
495 lboard_t *brd;
497 /* Setup ionodes with memory */
498 for (nasid = 0; nasid < MAX_PHYSNODE_ID; nasid +=2) {
499 u64 klgraph_header;
500 cnodeid_t cnodeid;
502 if (physical_node_map[nasid] == -1)
503 continue;
505 klgraph_header = cnodeid = -1;
506 klgraph_header = ia64_sn_get_klconfig_addr(nasid);
507 if (klgraph_header <= 0) {
508 if ( IS_RUNNING_ON_SIMULATOR() )
509 continue;
510 BUG(); /* All nodes must have klconfig tables! */
512 cnodeid = nasid_to_cnodeid(nasid);
513 root_lboard[cnodeid] = (lboard_t *)
514 NODE_OFFSET_TO_LBOARD( (nasid),
515 ((kl_config_hdr_t *)(klgraph_header))->
516 ch_board_info);
519 /* Scan headless/memless IO Nodes. */
520 for (nasid = 0; nasid < MAX_PHYSNODE_ID; nasid +=2) {
521 /* if there's no nasid, don't try to read the klconfig on the node */
522 if (physical_node_map[nasid] == -1) continue;
523 brd = find_lboard_any((lboard_t *)root_lboard[nasid_to_cnodeid(nasid)], KLTYPE_SNIA);
524 if (brd) {
525 brd = KLCF_NEXT_ANY(brd); /* Skip this node's lboard */
526 if (!brd)
527 continue;
530 brd = find_lboard_any(brd, KLTYPE_SNIA);
531 while (brd) {
532 pda->cnodeid_to_nasid_table[numionodes] = brd->brd_nasid;
533 physical_node_map[brd->brd_nasid] = numionodes;
534 root_lboard[numionodes] = brd;
535 numionodes++;
536 brd = KLCF_NEXT_ANY(brd);
537 if (!brd)
538 break;
540 brd = find_lboard_any(brd, KLTYPE_SNIA);