vserver 1.9.3
[linux-2.6.git] / arch / ia64 / sn / kernel / setup.c
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  * Copyright (C) 1999,2001-2003 Silicon Graphics, Inc. All rights reserved.
7  */
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
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>
51
52 DEFINE_PER_CPU(struct pda_s, pda_percpu);
53
54 #define MAX_PHYS_MEMORY         (1UL << 49)     /* 1 TB */
55
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;
63
64
65 unsigned long sn_rtc_cycles_per_second;   
66
67 EXPORT_SYMBOL(sn_rtc_cycles_per_second);
68
69 partid_t sn_partid = -1;
70 char sn_system_serial_number_string[128];
71 u64 sn_partition_serial_number;
72
73 short physical_node_map[MAX_PHYSNODE_ID];
74
75 EXPORT_SYMBOL(physical_node_map);
76
77 int     numionodes;
78 /*
79  * This is the address of the RRegs in the HSpace of the global
80  * master.  It is used by a hack in serial.c (serial_[in|out],
81  * printk.c (early_printk), and kdb_io.c to put console output on that
82  * node's Bedrock UART.  It is initialized here to 0, so that
83  * early_printk won't try to access the UART before
84  * master_node_bedrock_address is properly calculated.
85  */
86 u64 master_node_bedrock_address;
87
88 static void sn_init_pdas(char **);
89 static void scan_for_ionodes(void);
90
91
92 static nodepda_t        *nodepdaindr[MAX_COMPACT_NODES];
93
94 irqpda_t                *irqpdaindr;
95
96
97 /*
98  * The format of "screen_info" is strange, and due to early i386-setup
99  * code. This is just enough to make the console code think we're on a
100  * VGA color display.
101  */
102 struct screen_info sn_screen_info = {
103         .orig_x                 = 0,
104         .orig_y                 = 0,
105         .orig_video_mode        = 3,
106         .orig_video_cols        = 80,
107         .orig_video_ega_bx      = 3,
108         .orig_video_lines       = 25,
109         .orig_video_isVGA       = 1,
110         .orig_video_points      = 16
111 };
112
113 /*
114  * This is here so we can use the CMOS detection in ide-probe.c to
115  * determine what drives are present.  In theory, we don't need this
116  * as the auto-detection could be done via ide-probe.c:do_probe() but
117  * in practice that would be much slower, which is painful when
118  * running in the simulator.  Note that passing zeroes in DRIVE_INFO
119  * is sufficient (the IDE driver will autodetect the drive geometry).
120  */
121 #ifdef CONFIG_IA64_GENERIC
122 extern char drive_info[4*16];
123 #else
124 char drive_info[4*16];
125 #endif
126
127 /*
128  * This routine can only be used during init, since
129  * smp_boot_data is an init data structure.
130  * We have to use smp_boot_data.cpu_phys_id to find
131  * the physical id of the processor because the normal
132  * cpu_physical_id() relies on data structures that
133  * may not be initialized yet.
134  */
135
136 static int __init
137 pxm_to_nasid(int pxm)
138 {
139         int i;
140         int nid;
141
142         nid = pxm_to_nid_map[pxm];
143         for (i = 0; i < num_node_memblks; i++) {
144                 if (node_memblk[i].nid == nid) {
145                         return NASID_GET(node_memblk[i].start_paddr);
146                 }
147         }
148         return -1;
149 }
150 /**
151  * early_sn_setup - early setup routine for SN platforms
152  *
153  * Sets up an initial console to aid debugging.  Intended primarily
154  * for bringup.  See start_kernel() in init/main.c.
155  */
156
157 void __init
158 early_sn_setup(void)
159 {
160         void ia64_sal_handler_init (void *entry_point, void *gpval);
161         efi_system_table_t                      *efi_systab;
162         efi_config_table_t                      *config_tables;
163         struct ia64_sal_systab                  *sal_systab;
164         struct ia64_sal_desc_entry_point        *ep;
165         char                                    *p;
166         int                                     i;
167
168         /*
169          * Parse enough of the SAL tables to locate the SAL entry point. Since, console
170          * IO on SN2 is done via SAL calls, early_printk won't work without this.
171          *
172          * This code duplicates some of the ACPI table parsing that is in efi.c & sal.c.
173          * Any changes to those file may have to be made hereas well.
174          */
175         efi_systab = (efi_system_table_t*)__va(ia64_boot_param->efi_systab);
176         config_tables = __va(efi_systab->tables);
177         for (i = 0; i < efi_systab->nr_tables; i++) {
178                 if (efi_guidcmp(config_tables[i].guid, SAL_SYSTEM_TABLE_GUID) == 0) {
179                         sal_systab = __va(config_tables[i].table);
180                         p = (char*)(sal_systab+1);
181                         for (i = 0; i < sal_systab->entry_count; i++) {
182                                 if (*p == SAL_DESC_ENTRY_POINT) {
183                                         ep = (struct ia64_sal_desc_entry_point *) p;
184                                         ia64_sal_handler_init(__va(ep->sal_proc), __va(ep->gp));
185                                         break;
186                                 }
187                                 p += SAL_DESC_SIZE(*p);
188                         }
189                 }
190         }
191
192         if ( IS_RUNNING_ON_SIMULATOR() ) {
193                 master_node_bedrock_address = (u64)REMOTE_HUB(get_nasid(), SH_JUNK_BUS_UART0);
194                 printk(KERN_DEBUG "early_sn_setup: setting master_node_bedrock_address to 0x%lx\n", master_node_bedrock_address);
195         }
196 }
197
198 extern int platform_intr_list[];
199 extern nasid_t master_nasid;
200 static int shub_1_1_found __initdata;
201
202
203 /*
204  * sn_check_for_wars
205  *
206  * Set flag for enabling shub specific wars
207  */
208
209 static inline int __init
210 is_shub_1_1(int nasid)
211 {
212         unsigned long id;
213         int     rev;
214
215         id = REMOTE_HUB_L(nasid, SH_SHUB_ID);
216         rev =  (id & SH_SHUB_ID_REVISION_MASK) >> SH_SHUB_ID_REVISION_SHFT;
217         return rev <= 2;
218 }
219
220 static void __init
221 sn_check_for_wars(void)
222 {
223         int     cnode;
224
225         for (cnode=0; cnode< numnodes; cnode++)
226                 if (is_shub_1_1(cnodeid_to_nasid(cnode)))
227                         shub_1_1_found = 1;
228 }
229
230 /**
231  * sn_set_error_handling_features - Tell the SN prom how to handle certain
232  * error types.
233  */
234 static void __init
235 sn_set_error_handling_features(void)
236 {
237         u64 ret;
238         u64 sn_ehf_bits[7];     /* see ia64_sn_set_error_handling_features */
239         memset(sn_ehf_bits, 0, sizeof(sn_ehf_bits));
240 #define EHF(x) __set_bit(SN_SAL_EHF_ ## x, sn_ehf_bits)
241         EHF(MCA_SLV_TO_OS_INIT_SLV);
242         EHF(NO_RZ_TLBC);
243         // Uncomment once Jesse's code goes in - EHF(NO_RZ_IO_READ); 
244 #undef  EHF
245         ret = ia64_sn_set_error_handling_features(sn_ehf_bits);
246         if (ret)
247                 printk(KERN_ERR "%s: failed, return code %ld\n", __FUNCTION__, ret);
248 }
249
250 /**
251  * sn_setup - SN platform setup routine
252  * @cmdline_p: kernel command line
253  *
254  * Handles platform setup for SN machines.  This includes determining
255  * the RTC frequency (via a SAL call), initializing secondary CPUs, and
256  * setting up per-node data areas.  The console is also initialized here.
257  */
258 void __init
259 sn_setup(char **cmdline_p)
260 {
261         long status, ticks_per_sec, drift;
262         int pxm;
263         int major = sn_sal_rev_major(), minor = sn_sal_rev_minor();
264         extern nasid_t snia_get_master_baseio_nasid(void);
265         extern void sn_cpu_init(void);
266         extern nasid_t snia_get_console_nasid(void);
267
268         /*
269          * If the generic code has enabled vga console support - lets
270          * get rid of it again. This is a kludge for the fact that ACPI
271          * currtently has no way of informing us if legacy VGA is available
272          * or not.
273          */
274 #if defined(CONFIG_VT) && defined(CONFIG_VGA_CONSOLE)
275         if (conswitchp == &vga_con) {
276                 printk(KERN_DEBUG "SGI: Disabling VGA console\n");
277 #ifdef CONFIG_DUMMY_CONSOLE
278                 conswitchp = &dummy_con;
279 #else
280                 conswitchp = NULL;
281 #endif /* CONFIG_DUMMY_CONSOLE */
282         }
283 #endif /* def(CONFIG_VT) && def(CONFIG_VGA_CONSOLE) */
284
285         MAX_DMA_ADDRESS = PAGE_OFFSET + MAX_PHYS_MEMORY;
286
287         memset(physical_node_map, -1, sizeof(physical_node_map));
288         for (pxm=0; pxm<MAX_PXM_DOMAINS; pxm++)
289                 if (pxm_to_nid_map[pxm] != -1)
290                         physical_node_map[pxm_to_nasid(pxm)] = pxm_to_nid_map[pxm];
291
292
293         /*
294          * Old PROMs do not provide an ACPI FADT. Disable legacy keyboard
295          * support here so we don't have to listen to failed keyboard probe
296          * messages.
297          */
298         if ((major < 2 || (major == 2 && minor <= 9)) &&
299             acpi_kbd_controller_present) {
300                 printk(KERN_INFO "Disabling legacy keyboard support as prom "
301                        "is too old and doesn't provide FADT\n");
302                 acpi_kbd_controller_present = 0;
303         }
304
305         printk("SGI SAL version %x.%02x\n", major, minor);
306
307         /*
308          * Confirm the SAL we're running on is recent enough...
309          */
310         if ((major < SN_SAL_MIN_MAJOR) || (major == SN_SAL_MIN_MAJOR &&
311                                            minor < SN_SAL_MIN_MINOR)) {
312                 printk(KERN_ERR "This kernel needs SGI SAL version >= "
313                        "%x.%02x\n", SN_SAL_MIN_MAJOR, SN_SAL_MIN_MINOR);
314                 panic("PROM version too old\n");
315         }
316
317         master_nasid = get_nasid();
318         (void)snia_get_console_nasid();
319         (void)snia_get_master_baseio_nasid();
320
321         status = ia64_sal_freq_base(SAL_FREQ_BASE_REALTIME_CLOCK, &ticks_per_sec, &drift);
322         if (status != 0 || ticks_per_sec < 100000) {
323                 printk(KERN_WARNING "unable to determine platform RTC clock frequency, guessing.\n");
324                 /* PROM gives wrong value for clock freq. so guess */
325                 sn_rtc_cycles_per_second = 1000000000000UL/30000UL;
326         }
327         else
328                 sn_rtc_cycles_per_second = ticks_per_sec;
329
330         platform_intr_list[ACPI_INTERRUPT_CPEI] = IA64_CPE_VECTOR;
331
332
333         if ( IS_RUNNING_ON_SIMULATOR() )
334         {
335                 master_node_bedrock_address = (u64)REMOTE_HUB(get_nasid(), SH_JUNK_BUS_UART0);
336                 printk(KERN_DEBUG "sn_setup: setting master_node_bedrock_address to 0x%lx\n",
337                        master_node_bedrock_address);
338         }
339
340         /* Tell the prom how to handle certain error types */
341         sn_set_error_handling_features();
342
343         /*
344          * we set the default root device to /dev/hda
345          * to make simulation easy
346          */
347         ROOT_DEV = Root_HDA1;
348
349         /*
350          * Create the PDAs and NODEPDAs for all the cpus.
351          */
352         sn_init_pdas(cmdline_p);
353
354         ia64_mark_idle = &snidle;
355
356         /* 
357          * For the bootcpu, we do this here. All other cpus will make the
358          * call as part of cpu_init in slave cpu initialization.
359          */
360         sn_cpu_init();
361
362         /*
363          * Setup hubinfo stuff. Has to happen AFTER sn_cpu_init(),
364          * because it uses the cnode to nasid tables.
365          */
366         init_platform_hubinfo(nodepdaindr);
367
368 #ifdef CONFIG_SMP
369         init_smp_config();
370 #endif
371         screen_info = sn_screen_info;
372
373         sn_timer_init();
374 }
375
376 /**
377  * sn_init_pdas - setup node data areas
378  *
379  * One time setup for Node Data Area.  Called by sn_setup().
380  */
381 void __init
382 sn_init_pdas(char **cmdline_p)
383 {
384         cnodeid_t       cnode;
385
386         memset(pda->cnodeid_to_nasid_table, -1, sizeof(pda->cnodeid_to_nasid_table));
387         for (cnode=0; cnode<numnodes; cnode++)
388                 pda->cnodeid_to_nasid_table[cnode] = pxm_to_nasid(nid_to_pxm_map[cnode]);
389
390         numionodes = numnodes;
391         scan_for_ionodes();
392
393         /*
394          * Allocate & initalize the nodepda for each node.
395          */
396         for (cnode=0; cnode < numnodes; cnode++) {
397                 nodepdaindr[cnode] = alloc_bootmem_node(NODE_DATA(cnode), sizeof(nodepda_t));
398                 memset(nodepdaindr[cnode], 0, sizeof(nodepda_t));
399         }
400
401         /*
402          * Now copy the array of nodepda pointers to each nodepda.
403          */
404         for (cnode=0; cnode < numionodes; cnode++)
405                 memcpy(nodepdaindr[cnode]->pernode_pdaindr, nodepdaindr, sizeof(nodepdaindr));
406
407
408         /*
409          * Set up IO related platform-dependent nodepda fields.
410          * The following routine actually sets up the hubinfo struct
411          * in nodepda.
412          */
413         for (cnode = 0; cnode < numnodes; cnode++) {
414                 init_platform_nodepda(nodepdaindr[cnode], cnode);
415                 bte_init_node (nodepdaindr[cnode], cnode);
416         }
417 }
418
419 /**
420  * sn_cpu_init - initialize per-cpu data areas
421  * @cpuid: cpuid of the caller
422  *
423  * Called during cpu initialization on each cpu as it starts.
424  * Currently, initializes the per-cpu data area for SNIA.
425  * Also sets up a few fields in the nodepda.  Also known as
426  * platform_cpu_init() by the ia64 machvec code.
427  */
428 void __init
429 sn_cpu_init(void)
430 {
431         int     cpuid;
432         int     cpuphyid;
433         int     nasid;
434         int     slice;
435         int     cnode;
436         static int      wars_have_been_checked;
437
438         /*
439          * The boot cpu makes this call again after platform initialization is
440          * complete.
441          */
442         if (nodepdaindr[0] == NULL)
443                 return;
444
445         cpuid = smp_processor_id();
446         cpuphyid = ((ia64_getreg(_IA64_REG_CR_LID) >> 16) & 0xffff);
447         nasid = cpu_physical_id_to_nasid(cpuphyid);
448         cnode = nasid_to_cnodeid(nasid);
449         slice = cpu_physical_id_to_slice(cpuphyid);
450
451         memset(pda, 0, sizeof(pda));
452         pda->p_nodepda = nodepdaindr[cnode];
453         pda->led_address = (typeof(pda->led_address)) (LED0 + (slice<<LED_CPU_SHIFT));
454         pda->led_state = LED_ALWAYS_SET;
455         pda->hb_count = HZ/2;
456         pda->hb_state = 0;
457         pda->idle_flag = 0;
458
459         if (cpuid != 0){
460                 memcpy(pda->cnodeid_to_nasid_table, pdacpu(0)->cnodeid_to_nasid_table,
461                                 sizeof(pda->cnodeid_to_nasid_table));
462         }
463
464         /*
465          * Check for WARs.
466          * Only needs to be done once, on BSP.
467          * Has to be done after loop above, because it uses pda.cnodeid_to_nasid_table[i].
468          * Has to be done before assignment below.
469          */
470         if (!wars_have_been_checked) {
471                 sn_check_for_wars();
472                 wars_have_been_checked = 1;
473         }
474         pda->shub_1_1_found = shub_1_1_found;
475         
476
477         /*
478          * We must use different memory allocators for first cpu (bootmem 
479          * allocator) than for the other cpus (regular allocator).
480          */
481         if (cpuid == 0)
482                 irqpdaindr = alloc_bootmem_node(NODE_DATA(cpuid_to_cnodeid(cpuid)),sizeof(irqpda_t));
483
484         memset(irqpdaindr, 0, sizeof(irqpda_t));
485         irqpdaindr->irq_flags[SGI_PCIBR_ERROR] = SN2_IRQ_SHARED;
486         irqpdaindr->irq_flags[SGI_PCIBR_ERROR] |= SN2_IRQ_RESERVED;
487         irqpdaindr->irq_flags[SGI_II_ERROR] = SN2_IRQ_SHARED;
488         irqpdaindr->irq_flags[SGI_II_ERROR] |= SN2_IRQ_RESERVED;
489
490         pda->pio_write_status_addr = (volatile unsigned long *)
491                         LOCAL_MMR_ADDR((slice < 2 ? SH_PIO_WRITE_STATUS_0 : SH_PIO_WRITE_STATUS_1 ) );
492         pda->mem_write_status_addr = (volatile u64 *)
493                         LOCAL_MMR_ADDR((slice < 2 ? SH_MEMORY_WRITE_STATUS_0 : SH_MEMORY_WRITE_STATUS_1 ) );
494
495         if (local_node_data->active_cpu_count++ == 0) {
496                 int     buddy_nasid;
497                 buddy_nasid = cnodeid_to_nasid(numa_node_id() == numnodes-1 ? 0 : numa_node_id()+ 1);
498                 pda->pio_shub_war_cam_addr = (volatile unsigned long*)GLOBAL_MMR_ADDR(nasid, SH_PI_CAM_CONTROL);
499         }
500 }
501
502 /*
503  * Scan klconfig for ionodes.  Add the nasids to the
504  * physical_node_map and the pda and increment numionodes.
505  */
506
507 static void __init
508 scan_for_ionodes(void)
509 {
510         int nasid = 0;
511         lboard_t *brd;
512
513         /* Setup ionodes with memory */
514         for (nasid = 0; nasid < MAX_PHYSNODE_ID; nasid +=2) {
515                 u64 klgraph_header;
516                 cnodeid_t cnodeid;
517
518                 if (physical_node_map[nasid] == -1) 
519                         continue;
520
521                 klgraph_header = cnodeid = -1;
522                 klgraph_header = ia64_sn_get_klconfig_addr(nasid);
523                 if (klgraph_header <= 0) {
524                         if ( IS_RUNNING_ON_SIMULATOR() )
525                                 continue;
526                         BUG(); /* All nodes must have klconfig tables! */
527                 }
528                 cnodeid = nasid_to_cnodeid(nasid);
529                 root_lboard[cnodeid] = (lboard_t *)
530                                         NODE_OFFSET_TO_LBOARD( (nasid),
531                                         ((kl_config_hdr_t *)(klgraph_header))->
532                                         ch_board_info);
533         }
534
535         /* Scan headless/memless IO Nodes. */
536         for (nasid = 0; nasid < MAX_PHYSNODE_ID; nasid +=2) {
537                 /* if there's no nasid, don't try to read the klconfig on the node */
538                 if (physical_node_map[nasid] == -1) continue;
539                 brd = find_lboard_any((lboard_t *)root_lboard[nasid_to_cnodeid(nasid)], KLTYPE_SNIA);
540                 if (brd) {
541                         brd = KLCF_NEXT_ANY(brd); /* Skip this node's lboard */
542                         if (!brd)
543                                 continue;
544                 }
545
546                 brd = find_lboard_any(brd, KLTYPE_SNIA);
547                 while (brd) {
548                         pda->cnodeid_to_nasid_table[numionodes] = brd->brd_nasid;
549                         physical_node_map[brd->brd_nasid] = numionodes;
550                         root_lboard[numionodes] = brd;
551                         numionodes++;
552                         brd = KLCF_NEXT_ANY(brd);
553                         if (!brd)
554                                 break;
555
556                         brd = find_lboard_any(brd, KLTYPE_SNIA);
557                 }
558         }
559 }