patch-2_6_7-vs1_9_1_12
[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 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;
64
65
66 unsigned long sn_rtc_cycles_per_second;   
67
68 partid_t sn_partid = -1;
69 char sn_system_serial_number_string[128];
70 u64 sn_partition_serial_number;
71
72 short physical_node_map[MAX_PHYSNODE_ID];
73
74 EXPORT_SYMBOL(physical_node_map);
75
76 int     numionodes;
77 /*
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.
84  */
85 u64 master_node_bedrock_address;
86
87 static void sn_init_pdas(char **);
88 static void scan_for_ionodes(void);
89
90
91 static nodepda_t        *nodepdaindr[MAX_COMPACT_NODES];
92
93 irqpda_t                *irqpdaindr;
94
95
96 /*
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.
100  */
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
110 };
111
112 /*
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).
119  */
120 #ifdef CONFIG_IA64_GENERIC
121 extern char drive_info[4*16];
122 #else
123 char drive_info[4*16];
124 #endif
125
126 /*
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.
133  */
134
135 static int __init
136 pxm_to_nasid(int pxm)
137 {
138         int i;
139         int nid;
140
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);
145                 }
146         }
147         return -1;
148 }
149 /**
150  * early_sn_setup - early setup routine for SN platforms
151  *
152  * Sets up an initial console to aid debugging.  Intended primarily
153  * for bringup.  See start_kernel() in init/main.c.
154  */
155
156 void __init
157 early_sn_setup(void)
158 {
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;
166
167         /*
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.
170          *
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.
173          */
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;
185                                 }
186                                 p += SAL_DESC_SIZE(*p);
187                         }
188                 }
189         }
190
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);
194         }
195 }
196
197 extern int platform_intr_list[];
198 extern nasid_t master_nasid;
199 static int shub_1_1_found __initdata;
200
201
202 /*
203  * sn_check_for_wars
204  *
205  * Set flag for enabling shub specific wars
206  */
207
208 static inline int __init
209 is_shub_1_1(int nasid)
210 {
211         unsigned long id;
212         int     rev;
213
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;
217 }
218
219 static void __init
220 sn_check_for_wars(void)
221 {
222         int     cnode;
223
224         for (cnode=0; cnode< numnodes; cnode++)
225                 if (is_shub_1_1(cnodeid_to_nasid(cnode)))
226                         shub_1_1_found = 1;
227 }
228
229
230
231 /**
232  * sn_setup - SN platform setup routine
233  * @cmdline_p: kernel command line
234  *
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.
238  */
239 void __init
240 sn_setup(char **cmdline_p)
241 {
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);
248
249         /*
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.
254          */
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 */
263         }
264 #endif /* def(CONFIG_VT) && def(CONFIG_VGA_CONSOLE) */
265
266         MAX_DMA_ADDRESS = PAGE_OFFSET + MAX_PHYS_MEMORY;
267
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];
272
273
274         /*
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.
278          */
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;
284         }
285
286         printk("SGI SAL version %x.%02x\n", major, minor);
287
288         /*
289          * Confirm the SAL we're running on is recent enough...
290          */
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");
296         }
297
298         master_nasid = get_nasid();
299         (void)snia_get_console_nasid();
300         (void)snia_get_master_baseio_nasid();
301
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;
307         }
308         else
309                 sn_rtc_cycles_per_second = ticks_per_sec;
310
311         platform_intr_list[ACPI_INTERRUPT_CPEI] = IA64_CPE_VECTOR;
312
313
314         if ( IS_RUNNING_ON_SIMULATOR() )
315         {
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);
319         }
320
321         /*
322          * we set the default root device to /dev/hda
323          * to make simulation easy
324          */
325         ROOT_DEV = Root_HDA1;
326
327         /*
328          * Create the PDAs and NODEPDAs for all the cpus.
329          */
330         sn_init_pdas(cmdline_p);
331
332         ia64_mark_idle = &snidle;
333
334         /* 
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.
337          */
338         sn_cpu_init();
339
340         /*
341          * Setup hubinfo stuff. Has to happen AFTER sn_cpu_init(),
342          * because it uses the cnode to nasid tables.
343          */
344         init_platform_hubinfo(nodepdaindr);
345
346 #ifdef CONFIG_SMP
347         init_smp_config();
348 #endif
349         screen_info = sn_screen_info;
350
351         sn_timer_init();
352 }
353
354 /**
355  * sn_init_pdas - setup node data areas
356  *
357  * One time setup for Node Data Area.  Called by sn_setup().
358  */
359 void __init
360 sn_init_pdas(char **cmdline_p)
361 {
362         cnodeid_t       cnode;
363
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]);
367
368         numionodes = numnodes;
369         scan_for_ionodes();
370
371         /*
372          * Allocate & initalize the nodepda for each node.
373          */
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));
377         }
378
379         /*
380          * Now copy the array of nodepda pointers to each nodepda.
381          */
382         for (cnode=0; cnode < numionodes; cnode++)
383                 memcpy(nodepdaindr[cnode]->pernode_pdaindr, nodepdaindr, sizeof(nodepdaindr));
384
385
386         /*
387          * Set up IO related platform-dependent nodepda fields.
388          * The following routine actually sets up the hubinfo struct
389          * in nodepda.
390          */
391         for (cnode = 0; cnode < numnodes; cnode++) {
392                 init_platform_nodepda(nodepdaindr[cnode], cnode);
393                 bte_init_node (nodepdaindr[cnode], cnode);
394         }
395 }
396
397 /**
398  * sn_cpu_init - initialize per-cpu data areas
399  * @cpuid: cpuid of the caller
400  *
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.
405  */
406 void __init
407 sn_cpu_init(void)
408 {
409         int     cpuid;
410         int     cpuphyid;
411         int     nasid;
412         int     slice;
413         int     cnode;
414         static int      wars_have_been_checked;
415
416         /*
417          * The boot cpu makes this call again after platform initialization is
418          * complete.
419          */
420         if (nodepdaindr[0] == NULL)
421                 return;
422
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);
428
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;
436
437         if (cpuid != 0){
438                 memcpy(pda->cnodeid_to_nasid_table, pdacpu(0)->cnodeid_to_nasid_table,
439                                 sizeof(pda->cnodeid_to_nasid_table));
440         }
441
442         /*
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.
447          */
448         if (!wars_have_been_checked) {
449                 sn_check_for_wars();
450                 wars_have_been_checked = 1;
451         }
452         pda->shub_1_1_found = shub_1_1_found;
453         
454
455         /*
456          * We must use different memory allocators for first cpu (bootmem 
457          * allocator) than for the other cpus (regular allocator).
458          */
459         if (cpuid == 0)
460                 irqpdaindr = alloc_bootmem_node(NODE_DATA(cpuid_to_cnodeid(cpuid)),sizeof(irqpda_t));
461
462         memset(irqpdaindr, 0, sizeof(irqpda_t));
463         irqpdaindr->irq_flags[SGI_PCIBR_ERROR] = SN2_IRQ_SHARED;
464         irqpdaindr->irq_flags[SGI_PCIBR_ERROR] |= SN2_IRQ_RESERVED;
465         irqpdaindr->irq_flags[SGI_II_ERROR] = SN2_IRQ_SHARED;
466         irqpdaindr->irq_flags[SGI_II_ERROR] |= SN2_IRQ_RESERVED;
467
468         pda->pio_write_status_addr = (volatile unsigned long *)
469                         LOCAL_MMR_ADDR((slice < 2 ? SH_PIO_WRITE_STATUS_0 : SH_PIO_WRITE_STATUS_1 ) );
470         pda->mem_write_status_addr = (volatile u64 *)
471                         LOCAL_MMR_ADDR((slice < 2 ? SH_MEMORY_WRITE_STATUS_0 : SH_MEMORY_WRITE_STATUS_1 ) );
472
473         if (local_node_data->active_cpu_count++ == 0) {
474                 int     buddy_nasid;
475                 buddy_nasid = cnodeid_to_nasid(numa_node_id() == numnodes-1 ? 0 : numa_node_id()+ 1);
476                 pda->pio_shub_war_cam_addr = (volatile unsigned long*)GLOBAL_MMR_ADDR(nasid, SH_PI_CAM_CONTROL);
477         }
478
479         bte_init_cpu();
480 }
481
482 /*
483  * Scan klconfig for ionodes.  Add the nasids to the
484  * physical_node_map and the pda and increment numionodes.
485  */
486
487 static void __init
488 scan_for_ionodes(void)
489 {
490         int nasid = 0;
491         lboard_t *brd;
492
493         /* Setup ionodes with memory */
494         for (nasid = 0; nasid < MAX_PHYSNODE_ID; nasid +=2) {
495                 u64 klgraph_header;
496                 cnodeid_t cnodeid;
497
498                 if (physical_node_map[nasid] == -1) 
499                         continue;
500
501                 klgraph_header = cnodeid = -1;
502                 klgraph_header = ia64_sn_get_klconfig_addr(nasid);
503                 if (klgraph_header <= 0) {
504                         if ( IS_RUNNING_ON_SIMULATOR() )
505                                 continue;
506                         BUG(); /* All nodes must have klconfig tables! */
507                 }
508                 cnodeid = nasid_to_cnodeid(nasid);
509                 root_lboard[cnodeid] = (lboard_t *)
510                                         NODE_OFFSET_TO_LBOARD( (nasid),
511                                         ((kl_config_hdr_t *)(klgraph_header))->
512                                         ch_board_info);
513         }
514
515         /* Scan headless/memless IO Nodes. */
516         for (nasid = 0; nasid < MAX_PHYSNODE_ID; nasid +=2) {
517                 /* if there's no nasid, don't try to read the klconfig on the node */
518                 if (physical_node_map[nasid] == -1) continue;
519                 brd = find_lboard_any((lboard_t *)root_lboard[nasid_to_cnodeid(nasid)], KLTYPE_SNIA);
520                 if (brd) {
521                         brd = KLCF_NEXT_ANY(brd); /* Skip this node's lboard */
522                         if (!brd)
523                                 continue;
524                 }
525
526                 brd = find_lboard_any(brd, KLTYPE_SNIA);
527                 while (brd) {
528                         pda->cnodeid_to_nasid_table[numionodes] = brd->brd_nasid;
529                         physical_node_map[brd->brd_nasid] = numionodes;
530                         root_lboard[numionodes] = brd;
531                         numionodes++;
532                         brd = KLCF_NEXT_ANY(brd);
533                         if (!brd)
534                                 break;
535
536                         brd = find_lboard_any(brd, KLTYPE_SNIA);
537                 }
538         }
539 }