VServer 1.9.2 (patch-2.6.8.1-vs1.9.2.diff)
[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 partid_t sn_partid = -1;
68 char sn_system_serial_number_string[128];
69 u64 sn_partition_serial_number;
70
71 short physical_node_map[MAX_PHYSNODE_ID];
72
73 EXPORT_SYMBOL(physical_node_map);
74
75 int     numionodes;
76 /*
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.
83  */
84 u64 master_node_bedrock_address;
85
86 static void sn_init_pdas(char **);
87 static void scan_for_ionodes(void);
88
89
90 static nodepda_t        *nodepdaindr[MAX_COMPACT_NODES];
91
92 irqpda_t                *irqpdaindr;
93
94
95 /*
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
98  * VGA color display.
99  */
100 struct screen_info sn_screen_info = {
101         .orig_x                 = 0,
102         .orig_y                 = 0,
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
109 };
110
111 /*
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).
118  */
119 #ifdef CONFIG_IA64_GENERIC
120 extern char drive_info[4*16];
121 #else
122 char drive_info[4*16];
123 #endif
124
125 /*
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.
132  */
133
134 static int __init
135 pxm_to_nasid(int pxm)
136 {
137         int i;
138         int nid;
139
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);
144                 }
145         }
146         return -1;
147 }
148 /**
149  * early_sn_setup - early setup routine for SN platforms
150  *
151  * Sets up an initial console to aid debugging.  Intended primarily
152  * for bringup.  See start_kernel() in init/main.c.
153  */
154
155 void __init
156 early_sn_setup(void)
157 {
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;
163         char                                    *p;
164         int                                     i;
165
166         /*
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.
169          *
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.
172          */
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));
183                                         break;
184                                 }
185                                 p += SAL_DESC_SIZE(*p);
186                         }
187                 }
188         }
189
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);
193         }
194 }
195
196 extern int platform_intr_list[];
197 extern nasid_t master_nasid;
198 static int shub_1_1_found __initdata;
199
200
201 /*
202  * sn_check_for_wars
203  *
204  * Set flag for enabling shub specific wars
205  */
206
207 static inline int __init
208 is_shub_1_1(int nasid)
209 {
210         unsigned long id;
211         int     rev;
212
213         id = REMOTE_HUB_L(nasid, SH_SHUB_ID);
214         rev =  (id & SH_SHUB_ID_REVISION_MASK) >> SH_SHUB_ID_REVISION_SHFT;
215         return rev <= 2;
216 }
217
218 static void __init
219 sn_check_for_wars(void)
220 {
221         int     cnode;
222
223         for (cnode=0; cnode< numnodes; cnode++)
224                 if (is_shub_1_1(cnodeid_to_nasid(cnode)))
225                         shub_1_1_found = 1;
226 }
227
228 /**
229  * sn_set_error_handling_features - Tell the SN prom how to handle certain
230  * error types.
231  */
232 static void __init
233 sn_set_error_handling_features(void)
234 {
235         u64 ret;
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);
240         EHF(NO_RZ_TLBC);
241         // Uncomment once Jesse's code goes in - EHF(NO_RZ_IO_READ); 
242 #undef  EHF
243         ret = ia64_sn_set_error_handling_features(sn_ehf_bits);
244         if (ret)
245                 printk(KERN_ERR "%s: failed, return code %ld\n", __FUNCTION__, ret);
246 }
247
248 /**
249  * sn_setup - SN platform setup routine
250  * @cmdline_p: kernel command line
251  *
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.
255  */
256 void __init
257 sn_setup(char **cmdline_p)
258 {
259         long status, ticks_per_sec, drift;
260         int pxm;
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);
265
266         /*
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
270          * or not.
271          */
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;
277 #else
278                 conswitchp = NULL;
279 #endif /* CONFIG_DUMMY_CONSOLE */
280         }
281 #endif /* def(CONFIG_VT) && def(CONFIG_VGA_CONSOLE) */
282
283         MAX_DMA_ADDRESS = PAGE_OFFSET + MAX_PHYS_MEMORY;
284
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];
289
290
291         /*
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
294          * messages.
295          */
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;
301         }
302
303         printk("SGI SAL version %x.%02x\n", major, minor);
304
305         /*
306          * Confirm the SAL we're running on is recent enough...
307          */
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");
313         }
314
315         master_nasid = get_nasid();
316         (void)snia_get_console_nasid();
317         (void)snia_get_master_baseio_nasid();
318
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;
324         }
325         else
326                 sn_rtc_cycles_per_second = ticks_per_sec;
327
328         platform_intr_list[ACPI_INTERRUPT_CPEI] = IA64_CPE_VECTOR;
329
330
331         if ( IS_RUNNING_ON_SIMULATOR() )
332         {
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);
336         }
337
338         /* Tell the prom how to handle certain error types */
339         sn_set_error_handling_features();
340
341         /*
342          * we set the default root device to /dev/hda
343          * to make simulation easy
344          */
345         ROOT_DEV = Root_HDA1;
346
347         /*
348          * Create the PDAs and NODEPDAs for all the cpus.
349          */
350         sn_init_pdas(cmdline_p);
351
352         ia64_mark_idle = &snidle;
353
354         /* 
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.
357          */
358         sn_cpu_init();
359
360         /*
361          * Setup hubinfo stuff. Has to happen AFTER sn_cpu_init(),
362          * because it uses the cnode to nasid tables.
363          */
364         init_platform_hubinfo(nodepdaindr);
365
366 #ifdef CONFIG_SMP
367         init_smp_config();
368 #endif
369         screen_info = sn_screen_info;
370
371         sn_timer_init();
372 }
373
374 /**
375  * sn_init_pdas - setup node data areas
376  *
377  * One time setup for Node Data Area.  Called by sn_setup().
378  */
379 void __init
380 sn_init_pdas(char **cmdline_p)
381 {
382         cnodeid_t       cnode;
383
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]);
387
388         numionodes = numnodes;
389         scan_for_ionodes();
390
391         /*
392          * Allocate & initalize the nodepda for each node.
393          */
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));
397         }
398
399         /*
400          * Now copy the array of nodepda pointers to each nodepda.
401          */
402         for (cnode=0; cnode < numionodes; cnode++)
403                 memcpy(nodepdaindr[cnode]->pernode_pdaindr, nodepdaindr, sizeof(nodepdaindr));
404
405
406         /*
407          * Set up IO related platform-dependent nodepda fields.
408          * The following routine actually sets up the hubinfo struct
409          * in nodepda.
410          */
411         for (cnode = 0; cnode < numnodes; cnode++) {
412                 init_platform_nodepda(nodepdaindr[cnode], cnode);
413                 bte_init_node (nodepdaindr[cnode], cnode);
414         }
415 }
416
417 /**
418  * sn_cpu_init - initialize per-cpu data areas
419  * @cpuid: cpuid of the caller
420  *
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.
425  */
426 void __init
427 sn_cpu_init(void)
428 {
429         int     cpuid;
430         int     cpuphyid;
431         int     nasid;
432         int     slice;
433         int     cnode;
434         static int      wars_have_been_checked;
435
436         /*
437          * The boot cpu makes this call again after platform initialization is
438          * complete.
439          */
440         if (nodepdaindr[0] == NULL)
441                 return;
442
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);
448
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;
454         pda->hb_state = 0;
455         pda->idle_flag = 0;
456
457         if (cpuid != 0){
458                 memcpy(pda->cnodeid_to_nasid_table, pdacpu(0)->cnodeid_to_nasid_table,
459                                 sizeof(pda->cnodeid_to_nasid_table));
460         }
461
462         /*
463          * Check for WARs.
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.
467          */
468         if (!wars_have_been_checked) {
469                 sn_check_for_wars();
470                 wars_have_been_checked = 1;
471         }
472         pda->shub_1_1_found = shub_1_1_found;
473         
474
475         /*
476          * We must use different memory allocators for first cpu (bootmem 
477          * allocator) than for the other cpus (regular allocator).
478          */
479         if (cpuid == 0)
480                 irqpdaindr = alloc_bootmem_node(NODE_DATA(cpuid_to_cnodeid(cpuid)),sizeof(irqpda_t));
481
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;
487
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 ) );
492
493         if (local_node_data->active_cpu_count++ == 0) {
494                 int     buddy_nasid;
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);
497         }
498 }
499
500 /*
501  * Scan klconfig for ionodes.  Add the nasids to the
502  * physical_node_map and the pda and increment numionodes.
503  */
504
505 static void __init
506 scan_for_ionodes(void)
507 {
508         int nasid = 0;
509         lboard_t *brd;
510
511         /* Setup ionodes with memory */
512         for (nasid = 0; nasid < MAX_PHYSNODE_ID; nasid +=2) {
513                 u64 klgraph_header;
514                 cnodeid_t cnodeid;
515
516                 if (physical_node_map[nasid] == -1) 
517                         continue;
518
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() )
523                                 continue;
524                         BUG(); /* All nodes must have klconfig tables! */
525                 }
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))->
530                                         ch_board_info);
531         }
532
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);
538                 if (brd) {
539                         brd = KLCF_NEXT_ANY(brd); /* Skip this node's lboard */
540                         if (!brd)
541                                 continue;
542                 }
543
544                 brd = find_lboard_any(brd, KLTYPE_SNIA);
545                 while (brd) {
546                         pda->cnodeid_to_nasid_table[numionodes] = brd->brd_nasid;
547                         physical_node_map[brd->brd_nasid] = numionodes;
548                         root_lboard[numionodes] = brd;
549                         numionodes++;
550                         brd = KLCF_NEXT_ANY(brd);
551                         if (!brd)
552                                 break;
553
554                         brd = find_lboard_any(brd, KLTYPE_SNIA);
555                 }
556         }
557 }