vserver 1.9.3
[linux-2.6.git] / arch / ppc64 / kernel / setup.c
1 /*
2  * 
3  * Common boot and setup code.
4  *
5  * Copyright (C) 2001 PPC64 Team, IBM Corp
6  *
7  *      This program is free software; you can redistribute it and/or
8  *      modify it under the terms of the GNU General Public License
9  *      as published by the Free Software Foundation; either version
10  *      2 of the License, or (at your option) any later version.
11  */
12
13 #undef DEBUG
14
15 #include <linux/config.h>
16 #include <linux/module.h>
17 #include <linux/string.h>
18 #include <linux/sched.h>
19 #include <linux/init.h>
20 #include <linux/reboot.h>
21 #include <linux/delay.h>
22 #include <linux/initrd.h>
23 #include <linux/ide.h>
24 #include <linux/seq_file.h>
25 #include <linux/ioport.h>
26 #include <linux/console.h>
27 #include <linux/version.h>
28 #include <linux/tty.h>
29 #include <linux/root_dev.h>
30 #include <linux/notifier.h>
31 #include <linux/cpu.h>
32 #include <linux/unistd.h>
33 #include <asm/io.h>
34 #include <asm/prom.h>
35 #include <asm/processor.h>
36 #include <asm/pgtable.h>
37 #include <asm/bootinfo.h>
38 #include <asm/smp.h>
39 #include <asm/elf.h>
40 #include <asm/machdep.h>
41 #include <asm/iSeries/LparData.h>
42 #include <asm/naca.h>
43 #include <asm/paca.h>
44 #include <asm/ppcdebug.h>
45 #include <asm/time.h>
46 #include <asm/cputable.h>
47 #include <asm/sections.h>
48 #include <asm/btext.h>
49 #include <asm/nvram.h>
50 #include <asm/setup.h>
51 #include <asm/system.h>
52 #include <asm/rtas.h>
53 #include <asm/iommu.h>
54
55 #ifdef DEBUG
56 #define DBG(fmt...) udbg_printf(fmt)
57 #else
58 #define DBG(fmt...)
59 #endif
60
61 /*
62  * Here are some early debugging facilities. You can enable one
63  * but your kernel will not boot on anything else if you do so
64  */
65
66 /* This one is for use on LPAR machines that support an HVC console
67  * on vterm 0
68  */
69 extern void udbg_init_debug_lpar(void);
70 /* This one is for use on Apple G5 machines
71  */
72 extern void udbg_init_pmac_realmode(void);
73 /* That's RTAS panel debug */
74 extern void call_rtas_display_status_delay(unsigned char c);
75
76 #define EARLY_DEBUG_INIT() do {} while(0)
77
78 #if 0
79 #define EARLY_DEBUG_INIT() udbg_init_debug_lpar()
80 #define EARLY_DEBUG_INIT() udbg_init_pmac_realmode()
81 #define EARLY_DEBUG_INIT()                                              \
82         do { ppc_md.udbg_putc = call_rtas_display_status_delay; } while(0)
83 #endif
84
85 /* extern void *stab; */
86 extern HTAB htab_data;
87 extern unsigned long klimit;
88
89 extern void mm_init_ppc64(void);
90 extern int  idle_setup(void);
91 extern void stab_initialize(unsigned long stab);
92 extern void htab_initialize(void);
93 extern void early_init_devtree(void *flat_dt);
94 extern void unflatten_device_tree(void);
95
96 unsigned long decr_overclock = 1;
97 unsigned long decr_overclock_proc0 = 1;
98 unsigned long decr_overclock_set = 0;
99 unsigned long decr_overclock_proc0_set = 0;
100
101 int have_of = 1;
102 int boot_cpuid = 0;
103 dev_t boot_dev;
104
105 /*
106  * These are used in binfmt_elf.c to put aux entries on the stack
107  * for each elf executable being started.
108  */
109 int dcache_bsize;
110 int icache_bsize;
111 int ucache_bsize;
112
113 /* The main machine-dep calls structure
114  */
115 struct machdep_calls ppc_md;
116
117 #ifdef CONFIG_MAGIC_SYSRQ
118 unsigned long SYSRQ_KEY;
119 #endif /* CONFIG_MAGIC_SYSRQ */
120
121
122 static int ppc64_panic_event(struct notifier_block *, unsigned long, void *);
123 static struct notifier_block ppc64_panic_block = {
124         .notifier_call = ppc64_panic_event,
125         .priority = INT_MIN /* may not return; must be done last */
126 };
127
128 /*
129  * Perhaps we can put the pmac screen_info[] here
130  * on pmac as well so we don't need the ifdef's.
131  * Until we get multiple-console support in here
132  * that is.  -- Cort
133  * Maybe tie it to serial consoles, since this is really what
134  * these processors use on existing boards.  -- Dan
135  */ 
136 struct screen_info screen_info = {
137         .orig_x = 0,
138         .orig_y = 25,
139         .orig_video_cols = 80,
140         .orig_video_lines = 25,
141         .orig_video_isVGA = 1,
142         .orig_video_points = 16
143 };
144
145 /*
146  * Initialize the PPCDBG state.  Called before relocation has been enabled.
147  */
148 void __init ppcdbg_initialize(void)
149 {
150         naca->debug_switch = PPC_DEBUG_DEFAULT; /* | PPCDBG_BUSWALK | */
151         /* PPCDBG_PHBINIT | PPCDBG_MM | PPCDBG_MMINIT | PPCDBG_TCEINIT | PPCDBG_TCE */;
152 }
153
154 /*
155  * Early boot console based on udbg
156  */
157 static struct console udbg_console = {
158         .name   = "udbg",
159         .write  = udbg_console_write,
160         .flags  = CON_PRINTBUFFER,
161         .index  = -1,
162 };
163 static int early_console_initialized;
164
165 void __init disable_early_printk(void)
166 {
167         if (!early_console_initialized)
168                 return;
169         unregister_console(&udbg_console);
170         early_console_initialized = 0;
171 }
172
173 #if defined(CONFIG_PPC_MULTIPLATFORM) && defined(CONFIG_SMP)
174
175 static int smt_enabled_cmdline;
176
177 /* Look for ibm,smt-enabled OF option */
178 static void check_smt_enabled(void)
179 {
180         struct device_node *dn;
181         char *smt_option;
182
183         /* Allow the command line to overrule the OF option */
184         if (smt_enabled_cmdline)
185                 return;
186
187         dn = of_find_node_by_path("/options");
188
189         if (dn) {
190                 smt_option = (char *)get_property(dn, "ibm,smt-enabled", NULL);
191
192                 if (smt_option) {
193                         if (!strcmp(smt_option, "on"))
194                                 smt_enabled_at_boot = 1;
195                         else if (!strcmp(smt_option, "off"))
196                                 smt_enabled_at_boot = 0;
197                 }
198         }
199 }
200
201 /* Look for smt-enabled= cmdline option */
202 static int __init early_smt_enabled(char *p)
203 {
204         smt_enabled_cmdline = 1;
205
206         if (!p)
207                 return 0;
208
209         if (!strcmp(p, "on") || !strcmp(p, "1"))
210                 smt_enabled_at_boot = 1;
211         else if (!strcmp(p, "off") || !strcmp(p, "0"))
212                 smt_enabled_at_boot = 0;
213
214         return 0;
215 }
216 early_param("smt-enabled", early_smt_enabled);
217
218 /**
219  * setup_cpu_maps - initialize the following cpu maps:
220  *                  cpu_possible_map
221  *                  cpu_present_map
222  *                  cpu_sibling_map
223  *
224  * Having the possible map set up early allows us to restrict allocations
225  * of things like irqstacks to num_possible_cpus() rather than NR_CPUS.
226  *
227  * We do not initialize the online map here; cpus set their own bits in
228  * cpu_online_map as they come up.
229  *
230  * This function is valid only for Open Firmware systems.  finish_device_tree
231  * must be called before using this.
232  *
233  * While we're here, we may as well set the "physical" cpu ids in the paca.
234  */
235 static void __init setup_cpu_maps(void)
236 {
237         struct device_node *dn = NULL;
238         int cpu = 0;
239
240         check_smt_enabled();
241
242         while ((dn = of_find_node_by_type(dn, "cpu")) && cpu < NR_CPUS) {
243                 u32 *intserv;
244                 int j, len = sizeof(u32), nthreads;
245
246                 intserv = (u32 *)get_property(dn, "ibm,ppc-interrupt-server#s",
247                                               &len);
248                 if (!intserv)
249                         intserv = (u32 *)get_property(dn, "reg", NULL);
250
251                 nthreads = len / sizeof(u32);
252
253                 for (j = 0; j < nthreads && cpu < NR_CPUS; j++) {
254                         /*
255                          * Only spin up secondary threads if SMT is enabled.
256                          * We must leave space in the logical map for the
257                          * threads.
258                          */
259                         if (j == 0 || smt_enabled_at_boot) {
260                                 cpu_set(cpu, cpu_present_map);
261                                 set_hard_smp_processor_id(cpu, intserv[j]);
262                         }
263                         cpu_set(cpu, cpu_possible_map);
264                         cpu++;
265                 }
266         }
267
268         /*
269          * On pSeries LPAR, we need to know how many cpus
270          * could possibly be added to this partition.
271          */
272         if (systemcfg->platform == PLATFORM_PSERIES_LPAR &&
273                                 (dn = of_find_node_by_path("/rtas"))) {
274                 int num_addr_cell, num_size_cell, maxcpus;
275                 unsigned int *ireg;
276
277                 num_addr_cell = prom_n_addr_cells(dn);
278                 num_size_cell = prom_n_size_cells(dn);
279
280                 ireg = (unsigned int *)
281                         get_property(dn, "ibm,lrdr-capacity", NULL);
282
283                 if (!ireg)
284                         goto out;
285
286                 maxcpus = ireg[num_addr_cell + num_size_cell];
287
288                 /* Double maxcpus for processors which have SMT capability */
289                 if (cur_cpu_spec->cpu_features & CPU_FTR_SMT)
290                         maxcpus *= 2;
291
292                 if (maxcpus > NR_CPUS) {
293                         printk(KERN_WARNING
294                                "Partition configured for %d cpus, "
295                                "operating system maximum is %d.\n",
296                                maxcpus, NR_CPUS);
297                         maxcpus = NR_CPUS;
298                 } else
299                         printk(KERN_INFO "Partition configured for %d cpus.\n",
300                                maxcpus);
301
302                 for (cpu = 0; cpu < maxcpus; cpu++)
303                         cpu_set(cpu, cpu_possible_map);
304         out:
305                 of_node_put(dn);
306         }
307
308         /*
309          * Do the sibling map; assume only two threads per processor.
310          */
311         for_each_cpu(cpu) {
312                 cpu_set(cpu, cpu_sibling_map[cpu]);
313                 if (cur_cpu_spec->cpu_features & CPU_FTR_SMT)
314                         cpu_set(cpu ^ 0x1, cpu_sibling_map[cpu]);
315         }
316
317         systemcfg->processorCount = num_present_cpus();
318 }
319 #endif /* defined(CONFIG_PPC_MULTIPLATFORM) && defined(CONFIG_SMP) */
320
321
322 #ifdef CONFIG_PPC_MULTIPLATFORM
323
324 extern struct machdep_calls pSeries_md;
325 extern struct machdep_calls pmac_md;
326
327 /* Ultimately, stuff them in an elf section like initcalls... */
328 static struct machdep_calls __initdata *machines[] = {
329 #ifdef CONFIG_PPC_PSERIES
330         &pSeries_md,
331 #endif /* CONFIG_PPC_PSERIES */
332 #ifdef CONFIG_PPC_PMAC
333         &pmac_md,
334 #endif /* CONFIG_PPC_PMAC */
335         NULL
336 };
337
338 /*
339  * Early initialization entry point. This is called by head.S
340  * with MMU translation disabled. We rely on the "feature" of
341  * the CPU that ignores the top 2 bits of the address in real
342  * mode so we can access kernel globals normally provided we
343  * only toy with things in the RMO region. From here, we do
344  * some early parsing of the device-tree to setup out LMB
345  * data structures, and allocate & initialize the hash table
346  * and segment tables so we can start running with translation
347  * enabled.
348  *
349  * It is this function which will call the probe() callback of
350  * the various platform types and copy the matching one to the
351  * global ppc_md structure. Your platform can eventually do
352  * some very early initializations from the probe() routine, but
353  * this is not recommended, be very careful as, for example, the
354  * device-tree is not accessible via normal means at this point.
355  */
356
357 void __init early_setup(unsigned long dt_ptr)
358 {
359         struct paca_struct *lpaca = get_paca();
360         static struct machdep_calls **mach;
361
362         /*
363          * Enable early debugging if any specified (see top of
364          * this file)
365          */
366         EARLY_DEBUG_INIT();
367
368         DBG(" -> early_setup()\n");
369
370         /*
371          * Fill the default DBG level in naca (do we want to keep
372          * that old mecanism around forever ?)
373          */
374         ppcdbg_initialize();
375
376         /*
377          * Do early initializations using the flattened device
378          * tree, like retreiving the physical memory map or
379          * calculating/retreiving the hash table size
380          */
381         early_init_devtree(__va(dt_ptr));
382
383         /*
384          * Iterate all ppc_md structures until we find the proper
385          * one for the current machine type
386          */
387         DBG("Probing machine type for platform %x...\n",
388             systemcfg->platform);
389
390         for (mach = machines; *mach; mach++) {
391                 if ((*mach)->probe(systemcfg->platform))
392                         break;
393         }
394         /* What can we do if we didn't find ? */
395         if (*mach == NULL) {
396                 DBG("No suitable machine found !\n");
397                 for (;;);
398         }
399         ppc_md = **mach;
400
401         /* our udbg callbacks got overriden by the above, let's put them
402          * back in. Ultimately, I want those things to be split from the
403          * main ppc_md
404          */
405         EARLY_DEBUG_INIT();
406
407         DBG("Found, Initializing memory management...\n");
408
409         /*
410          * Initialize stab / SLB management
411          */
412         stab_initialize(lpaca->stab_real);
413
414         /*
415          * Initialize the MMU Hash table and create the linear mapping
416          * of memory
417          */
418         htab_initialize();
419
420         DBG(" <- early_setup()\n");
421 }
422
423
424 /*
425  * Initialize some remaining members of the naca and systemcfg structures
426  * (at least until we get rid of them completely). This is mostly some
427  * cache informations about the CPU that will be used by cache flush
428  * routines and/or provided to userland
429  */
430 static void __init initialize_naca(void)
431 {
432         struct device_node *np;
433         unsigned long num_cpus = 0;
434
435         DBG(" -> initialize_naca()\n");
436
437         for (np = NULL; (np = of_find_node_by_type(np, "cpu"));) {
438                 num_cpus += 1;
439
440                 /* We're assuming *all* of the CPUs have the same
441                  * d-cache and i-cache sizes... -Peter
442                  */
443
444                 if ( num_cpus == 1 ) {
445                         u32 *sizep, *lsizep;
446                         u32 size, lsize;
447                         const char *dc, *ic;
448
449                         /* Then read cache informations */
450                         if (systemcfg->platform == PLATFORM_POWERMAC) {
451                                 dc = "d-cache-block-size";
452                                 ic = "i-cache-block-size";
453                         } else {
454                                 dc = "d-cache-line-size";
455                                 ic = "i-cache-line-size";
456                         }
457
458                         size = 0;
459                         lsize = cur_cpu_spec->dcache_bsize;
460                         sizep = (u32 *)get_property(np, "d-cache-size", NULL);
461                         if (sizep != NULL)
462                                 size = *sizep;
463                         lsizep = (u32 *) get_property(np, dc, NULL);
464                         if (lsizep != NULL)
465                                 lsize = *lsizep;
466
467                         if (sizep == 0 || lsizep == 0)
468                                 DBG("Argh, can't find dcache properties ! "
469                                     "sizep: %p, lsizep: %p\n", sizep, lsizep);
470
471                         systemcfg->dCacheL1Size = size;
472                         systemcfg->dCacheL1LineSize = lsize;
473                         naca->dCacheL1LogLineSize = __ilog2(lsize);
474                         naca->dCacheL1LinesPerPage = PAGE_SIZE/(lsize);
475
476                         size = 0;
477                         lsize = cur_cpu_spec->icache_bsize;
478                         sizep = (u32 *)get_property(np, "i-cache-size", NULL);
479                         if (sizep != NULL)
480                                 size = *sizep;
481                         lsizep = (u32 *)get_property(np, ic, NULL);
482                         if (lsizep != NULL)
483                                 lsize = *lsizep;
484                         if (sizep == 0 || lsizep == 0)
485                                 DBG("Argh, can't find icache properties ! "
486                                     "sizep: %p, lsizep: %p\n", sizep, lsizep);
487
488                         systemcfg->iCacheL1Size = size;
489                         systemcfg->iCacheL1LineSize = lsize;
490                         naca->iCacheL1LogLineSize = __ilog2(lsize);
491                         naca->iCacheL1LinesPerPage = PAGE_SIZE/(lsize);
492
493                 }
494         }
495
496         /* Add an eye catcher and the systemcfg layout version number */
497         strcpy(systemcfg->eye_catcher, "SYSTEMCFG:PPC64");
498         systemcfg->version.major = SYSTEMCFG_MAJOR;
499         systemcfg->version.minor = SYSTEMCFG_MINOR;
500         systemcfg->processor = mfspr(SPRN_PVR);
501
502         DBG(" <- initialize_naca()\n");
503 }
504
505 static void __init check_for_initrd(void)
506 {
507 #ifdef CONFIG_BLK_DEV_INITRD
508         u64 *prop;
509
510         DBG(" -> check_for_initrd()\n");
511
512         prop = (u64 *)get_property(of_chosen, "linux,initrd-start", NULL);
513         if (prop != NULL) {
514                 initrd_start = (unsigned long)__va(*prop);
515                 prop = (u64 *)get_property(of_chosen, "linux,initrd-end", NULL);
516                 if (prop != NULL) {
517                         initrd_end = (unsigned long)__va(*prop);
518                         initrd_below_start_ok = 1;
519                 } else
520                         initrd_start = 0;
521         }
522
523         /* If we were passed an initrd, set the ROOT_DEV properly if the values
524          * look sensible. If not, clear initrd reference.
525          */
526         if (initrd_start >= KERNELBASE && initrd_end >= KERNELBASE &&
527             initrd_end > initrd_start)
528                 ROOT_DEV = Root_RAM0;
529         else
530                 initrd_start = initrd_end = 0;
531
532         if (initrd_start)
533                 printk("Found initrd at 0x%lx:0x%lx\n", initrd_start, initrd_end);
534
535         DBG(" <- check_for_initrd()\n");
536 #endif /* CONFIG_BLK_DEV_INITRD */
537 }
538
539 #endif /* CONFIG_PPC_MULTIPLATFORM */
540
541 /*
542  * Do some initial setup of the system.  The parameters are those which 
543  * were passed in from the bootloader.
544  */
545 void __init setup_system(void)
546 {
547         DBG(" -> setup_system()\n");
548
549 #ifdef CONFIG_PPC_ISERIES
550         /* pSeries systems are identified in prom.c via OF. */
551         if (itLpNaca.xLparInstalled == 1)
552                 systemcfg->platform = PLATFORM_ISERIES_LPAR;
553
554         ppc_md.init_early();
555 #else /* CONFIG_PPC_ISERIES */
556
557         /*
558          * Unflatten the device-tree passed by prom_init or kexec
559          */
560         unflatten_device_tree();
561
562         /*
563          * Fill the naca & systemcfg structures with informations
564          * retreived from the device-tree. Need to be called before
565          * finish_device_tree() since the later requires some of the
566          * informations filled up here to properly parse the interrupt
567          * tree.
568          * It also sets up the cache line sizes which allows to call
569          * routines like flush_icache_range (used by the hash init
570          * later on).
571          */
572         initialize_naca();
573
574 #ifdef CONFIG_PPC_PSERIES
575         /*
576          * Initialize RTAS if available
577          */
578         rtas_initialize();
579 #endif /* CONFIG_PPC_PSERIES */
580
581         /*
582          * Check if we have an initrd provided via the device-tree
583          */
584         check_for_initrd();
585
586         /*
587          * Do some platform specific early initializations, that includes
588          * setting up the hash table pointers. It also sets up some interrupt-mapping
589          * related options that will be used by finish_device_tree()
590          */
591         ppc_md.init_early();
592
593         /*
594          * "Finish" the device-tree, that is do the actual parsing of
595          * some of the properties like the interrupt map
596          */
597         finish_device_tree();
598
599         /*
600          * Initialize xmon
601          */
602 #ifdef CONFIG_XMON_DEFAULT
603         xmon_init();
604 #endif
605         /*
606          * Register early console
607          */
608         early_console_initialized = 1;
609         register_console(&udbg_console);
610
611 #endif /* !CONFIG_PPC_ISERIES */
612
613         /* Save unparsed command line copy for /proc/cmdline */
614         strlcpy(saved_command_line, cmd_line, COMMAND_LINE_SIZE);
615
616         parse_early_param();
617
618 #if defined(CONFIG_SMP) && !defined(CONFIG_PPC_ISERIES)
619         /*
620          * iSeries has already initialized the cpu maps at this point.
621          */
622         setup_cpu_maps();
623 #endif /* defined(CONFIG_SMP) && !defined(CONFIG_PPC_ISERIES) */
624
625         printk("Starting Linux PPC64 %s\n", UTS_RELEASE);
626
627         printk("-----------------------------------------------------\n");
628         printk("naca                          = 0x%p\n", naca);
629         printk("naca->pftSize                 = 0x%lx\n", naca->pftSize);
630         printk("naca->debug_switch            = 0x%lx\n", naca->debug_switch);
631         printk("naca->interrupt_controller    = 0x%ld\n", naca->interrupt_controller);
632         printk("systemcfg                     = 0x%p\n", systemcfg);
633         printk("systemcfg->processorCount     = 0x%lx\n", systemcfg->processorCount);
634         printk("systemcfg->physicalMemorySize = 0x%lx\n", systemcfg->physicalMemorySize);
635         printk("systemcfg->dCacheL1LineSize   = 0x%x\n", systemcfg->dCacheL1LineSize);
636         printk("systemcfg->iCacheL1LineSize   = 0x%x\n", systemcfg->iCacheL1LineSize);
637         printk("htab_data.htab                = 0x%p\n", htab_data.htab);
638         printk("htab_data.num_ptegs           = 0x%lx\n", htab_data.htab_num_ptegs);
639         printk("-----------------------------------------------------\n");
640
641         mm_init_ppc64();
642
643         DBG(" <- setup_system()\n");
644 }
645
646
647 void machine_restart(char *cmd)
648 {
649         if (ppc_md.nvram_sync)
650                 ppc_md.nvram_sync();
651         ppc_md.restart(cmd);
652 }
653
654 EXPORT_SYMBOL(machine_restart);
655   
656 void machine_power_off(void)
657 {
658         if (ppc_md.nvram_sync)
659                 ppc_md.nvram_sync();
660         ppc_md.power_off();
661 }
662
663 EXPORT_SYMBOL(machine_power_off);
664   
665 void machine_halt(void)
666 {
667         if (ppc_md.nvram_sync)
668                 ppc_md.nvram_sync();
669         ppc_md.halt();
670 }
671
672 EXPORT_SYMBOL(machine_halt);
673
674 unsigned long ppc_proc_freq;
675 unsigned long ppc_tb_freq;
676
677 static int ppc64_panic_event(struct notifier_block *this,
678                              unsigned long event, void *ptr)
679 {
680         ppc_md.panic((char *)ptr);  /* May not return */
681         return NOTIFY_DONE;
682 }
683
684
685 #ifdef CONFIG_SMP
686 DEFINE_PER_CPU(unsigned int, pvr);
687 #endif
688
689 static int show_cpuinfo(struct seq_file *m, void *v)
690 {
691         unsigned long cpu_id = (unsigned long)v - 1;
692         unsigned int pvr;
693         unsigned short maj;
694         unsigned short min;
695
696         if (cpu_id == NR_CPUS) {
697                 seq_printf(m, "timebase\t: %lu\n", ppc_tb_freq);
698
699                 if (ppc_md.get_cpuinfo != NULL)
700                         ppc_md.get_cpuinfo(m);
701
702                 return 0;
703         }
704
705         /* We only show online cpus: disable preempt (overzealous, I
706          * knew) to prevent cpu going down. */
707         preempt_disable();
708         if (!cpu_online(cpu_id)) {
709                 preempt_enable();
710                 return 0;
711         }
712
713 #ifdef CONFIG_SMP
714         pvr = per_cpu(pvr, cpu_id);
715 #else
716         pvr = mfspr(SPRN_PVR);
717 #endif
718         maj = (pvr >> 8) & 0xFF;
719         min = pvr & 0xFF;
720
721         seq_printf(m, "processor\t: %lu\n", cpu_id);
722         seq_printf(m, "cpu\t\t: ");
723
724         if (cur_cpu_spec->pvr_mask)
725                 seq_printf(m, "%s", cur_cpu_spec->cpu_name);
726         else
727                 seq_printf(m, "unknown (%08x)", pvr);
728
729 #ifdef CONFIG_ALTIVEC
730         if (cur_cpu_spec->cpu_features & CPU_FTR_ALTIVEC)
731                 seq_printf(m, ", altivec supported");
732 #endif /* CONFIG_ALTIVEC */
733
734         seq_printf(m, "\n");
735
736         /*
737          * Assume here that all clock rates are the same in a
738          * smp system.  -- Cort
739          */
740         seq_printf(m, "clock\t\t: %lu.%06luMHz\n", ppc_proc_freq / 1000000,
741                    ppc_proc_freq % 1000000);
742
743         seq_printf(m, "revision\t: %hd.%hd\n\n", maj, min);
744
745         preempt_enable();
746         return 0;
747 }
748
749 static void *c_start(struct seq_file *m, loff_t *pos)
750 {
751         return *pos <= NR_CPUS ? (void *)((*pos)+1) : NULL;
752 }
753 static void *c_next(struct seq_file *m, void *v, loff_t *pos)
754 {
755         ++*pos;
756         return c_start(m, pos);
757 }
758 static void c_stop(struct seq_file *m, void *v)
759 {
760 }
761 struct seq_operations cpuinfo_op = {
762         .start =c_start,
763         .next = c_next,
764         .stop = c_stop,
765         .show = show_cpuinfo,
766 };
767
768 #if 0 /* XXX not currently used */
769 unsigned long memory_limit;
770
771 static int __init early_parsemem(char *p)
772 {
773         if (!p)
774                 return 0;
775
776         memory_limit = memparse(p, &p);
777
778         return 0;
779 }
780 early_param("mem", early_parsemem);
781 #endif
782
783 #ifdef CONFIG_PPC_MULTIPLATFORM
784 static int __init set_preferred_console(void)
785 {
786         struct device_node *prom_stdout;
787         char *name;
788         int offset = 0;
789 #if  0
790         phandle *stdout_ph;
791 #endif
792         DBG(" -> set_preferred_console()\n");
793
794         /* The user has requested a console so this is already set up. */
795         if (strstr(saved_command_line, "console=")) {
796                 DBG(" console was specified !\n");
797                 return -EBUSY;
798         }
799
800         if (!of_chosen) {
801                 DBG(" of_chosen is NULL !\n");
802                 return -ENODEV;
803         }
804         /* We are getting a weird phandle from OF ... */
805 #if 0
806         stdout_ph = (phandle *)get_property(of_chosen, "linux,stdout-package", NULL);
807         if (stdout_ph == NULL) {
808                 DBG(" no linux,stdout-package !\n");
809                 return -ENODEV;
810         }
811         prom_stdout = of_find_node_by_phandle(*stdout_ph);
812         if (!prom_stdout) {
813                 DBG(" can't find stdout package for phandle 0x%x !\n", *stdout_ph);
814                 return -ENODEV;
815         }
816 #endif
817         /* ... So use the full path instead */
818 #if 1
819         name = (char *)get_property(of_chosen, "linux,stdout-path", NULL);
820         if (name == NULL) {
821                 DBG(" no linux,stdout-path !\n");
822                 return -ENODEV;
823         }
824         prom_stdout = of_find_node_by_path(name);
825         if (!prom_stdout) {
826                 DBG(" can't find stdout package %s !\n", name);
827                 return -ENODEV;
828         }       
829 #endif
830         DBG("stdout is %s\n", prom_stdout->full_name);
831
832         name = (char *)get_property(prom_stdout, "name", NULL);
833         if (!name) {
834                 DBG(" stdout package has no name !\n");
835                 goto not_found;
836         }
837
838         if (strcmp(name, "serial") == 0) {
839                 int i;
840                 u32 *reg = (u32 *)get_property(prom_stdout, "reg", &i);
841                 if (i > 8) {
842                         switch (reg[1]) {
843                                 case 0x3f8:
844                                         offset = 0;
845                                         break;
846                                 case 0x2f8:
847                                         offset = 1;
848                                         break;
849                                 case 0x898:
850                                         offset = 2;
851                                         break;
852                                 case 0x890:
853                                         offset = 3;
854                                         break;
855                                 default:
856                                         /* We dont recognise the serial port */
857                                         goto not_found;
858                         }
859                 }
860         }
861 #ifdef CONFIG_PPC_PSERIES
862         else if (strcmp(name, "vty") == 0) {
863                 u32 *reg = (u32 *)get_property(prom_stdout, "reg", NULL);
864                 char *compat = (char *)get_property(prom_stdout, "compatible", NULL);
865
866                 if (reg && compat && (strcmp(compat, "hvterm-protocol") == 0)) {
867                         /* Host Virtual Serial Interface */
868                         int offset;
869                         switch (reg[0]) {
870                                 case 0x30000000:
871                                         offset = 0;
872                                         break;
873                                 case 0x30000001:
874                                         offset = 1;
875                                         break;
876                                 default:
877                                         goto not_found;
878                         }
879                         of_node_put(prom_stdout);
880                         DBG("Found hvsi console at offset %d\n", offset);
881                         return add_preferred_console("hvsi", offset, NULL);
882                 } else {
883                         /* pSeries LPAR virtual console */
884                         of_node_put(prom_stdout);
885                         DBG("Found hvc console\n");
886                         return add_preferred_console("hvc", 0, NULL);
887                 }
888         }
889 #endif /* CONFIG_PPC_PSERIES */
890         else if (strcmp(name, "ch-a") == 0)
891                 offset = 0;
892         else if (strcmp(name, "ch-b") == 0)
893                 offset = 1;
894         else
895                 goto not_found;
896         of_node_put(prom_stdout);
897
898         DBG("Found serial console at ttyS%d\n", offset);
899
900         return add_preferred_console("ttyS", offset, NULL);
901
902  not_found:
903         DBG("No preferred console found !\n");
904         of_node_put(prom_stdout);
905         return -ENODEV;
906 }
907 console_initcall(set_preferred_console);
908 #endif /* CONFIG_PPC_MULTIPLATFORM */
909
910 #ifdef CONFIG_IRQSTACKS
911 static void __init irqstack_early_init(void)
912 {
913         unsigned int i;
914
915         /*
916          * interrupt stacks must be under 256MB, we cannot afford to take
917          * SLB misses on them.
918          */
919         for_each_cpu(i) {
920                 softirq_ctx[i] = (struct thread_info *)__va(lmb_alloc_base(THREAD_SIZE,
921                                         THREAD_SIZE, 0x10000000));
922                 hardirq_ctx[i] = (struct thread_info *)__va(lmb_alloc_base(THREAD_SIZE,
923                                         THREAD_SIZE, 0x10000000));
924         }
925 }
926 #else
927 #define irqstack_early_init()
928 #endif
929
930 /*
931  * Stack space used when we detect a bad kernel stack pointer, and
932  * early in SMP boots before relocation is enabled.
933  */
934 static void __init emergency_stack_init(void)
935 {
936         unsigned long limit;
937         unsigned int i;
938
939         /*
940          * Emergency stacks must be under 256MB, we cannot afford to take
941          * SLB misses on them. The ABI also requires them to be 128-byte
942          * aligned.
943          *
944          * Since we use these as temporary stacks during secondary CPU
945          * bringup, we need to get at them in real mode. This means they
946          * must also be within the RMO region.
947          */
948         limit = min(0x10000000UL, lmb.rmo_size);
949
950         for_each_cpu(i)
951                 paca[i].emergency_sp = __va(lmb_alloc_base(PAGE_SIZE, 128,
952                                                 limit)) + PAGE_SIZE;
953 }
954
955 /*
956  * Called into from start_kernel, after lock_kernel has been called.
957  * Initializes bootmem, which is unsed to manage page allocation until
958  * mem_init is called.
959  */
960 void __init setup_arch(char **cmdline_p)
961 {
962         extern int panic_timeout;
963         extern void do_init_bootmem(void);
964
965         ppc64_boot_msg(0x12, "Setup Arch");
966
967         *cmdline_p = cmd_line;
968
969         /*
970          * Set cache line size based on type of cpu as a default.
971          * Systems with OF can look in the properties on the cpu node(s)
972          * for a possibly more accurate value.
973          */
974         dcache_bsize = systemcfg->dCacheL1LineSize; 
975         icache_bsize = systemcfg->iCacheL1LineSize; 
976
977         /* reboot on panic */
978         panic_timeout = 180;
979
980         if (ppc_md.panic)
981                 notifier_chain_register(&panic_notifier_list, &ppc64_panic_block);
982
983         init_mm.start_code = PAGE_OFFSET;
984         init_mm.end_code = (unsigned long) _etext;
985         init_mm.end_data = (unsigned long) _edata;
986         init_mm.brk = klimit;
987         
988         irqstack_early_init();
989         emergency_stack_init();
990
991         /* set up the bootmem stuff with available memory */
992         do_init_bootmem();
993
994         /* Select the correct idle loop for the platform. */
995         idle_setup();
996
997         ppc_md.setup_arch();
998
999         paging_init();
1000         ppc64_boot_msg(0x15, "Setup Done");
1001 }
1002
1003
1004 /* ToDo: do something useful if ppc_md is not yet setup. */
1005 #define PPC64_LINUX_FUNCTION 0x0f000000
1006 #define PPC64_IPL_MESSAGE 0xc0000000
1007 #define PPC64_TERM_MESSAGE 0xb0000000
1008 #define PPC64_ATTN_MESSAGE 0xa0000000
1009 #define PPC64_DUMP_MESSAGE 0xd0000000
1010
1011 static void ppc64_do_msg(unsigned int src, const char *msg)
1012 {
1013         if (ppc_md.progress) {
1014                 char buf[32];
1015
1016                 sprintf(buf, "%08x        \n", src);
1017                 ppc_md.progress(buf, 0);
1018                 sprintf(buf, "%-16s", msg);
1019                 ppc_md.progress(buf, 0);
1020         }
1021 }
1022
1023 /* Print a boot progress message. */
1024 void ppc64_boot_msg(unsigned int src, const char *msg)
1025 {
1026         ppc64_do_msg(PPC64_LINUX_FUNCTION|PPC64_IPL_MESSAGE|src, msg);
1027         printk("[boot]%04x %s\n", src, msg);
1028 }
1029
1030 /* Print a termination message (print only -- does not stop the kernel) */
1031 void ppc64_terminate_msg(unsigned int src, const char *msg)
1032 {
1033         ppc64_do_msg(PPC64_LINUX_FUNCTION|PPC64_TERM_MESSAGE|src, msg);
1034         printk("[terminate]%04x %s\n", src, msg);
1035 }
1036
1037 /* Print something that needs attention (device error, etc) */
1038 void ppc64_attention_msg(unsigned int src, const char *msg)
1039 {
1040         ppc64_do_msg(PPC64_LINUX_FUNCTION|PPC64_ATTN_MESSAGE|src, msg);
1041         printk("[attention]%04x %s\n", src, msg);
1042 }
1043
1044 /* Print a dump progress message. */
1045 void ppc64_dump_msg(unsigned int src, const char *msg)
1046 {
1047         ppc64_do_msg(PPC64_LINUX_FUNCTION|PPC64_DUMP_MESSAGE|src, msg);
1048         printk("[dump]%04x %s\n", src, msg);
1049 }
1050
1051 int set_spread_lpevents( char * str )
1052 {
1053         /* The parameter is the number of processors to share in processing lp events */
1054         unsigned long i;
1055         unsigned long val = simple_strtoul( str, NULL, 0 );
1056         if ( ( val > 0 ) && ( val <= NR_CPUS ) ) {
1057                 for ( i=1; i<val; ++i )
1058                         paca[i].lpqueue_ptr = paca[0].lpqueue_ptr;
1059                 printk("lpevent processing spread over %ld processors\n", val);
1060         }
1061         else
1062                 printk("invalid spreaqd_lpevents %ld\n", val);
1063         return 1;
1064 }       
1065
1066 /* This should only be called on processor 0 during calibrate decr */
1067 void setup_default_decr(void)
1068 {
1069         struct paca_struct *lpaca = get_paca();
1070
1071         if ( decr_overclock_set && !decr_overclock_proc0_set )
1072                 decr_overclock_proc0 = decr_overclock;
1073
1074         lpaca->default_decr = tb_ticks_per_jiffy / decr_overclock_proc0;        
1075         lpaca->next_jiffy_update_tb = get_tb() + tb_ticks_per_jiffy;
1076 }
1077
1078 int set_decr_overclock_proc0( char * str )
1079 {
1080         unsigned long val = simple_strtoul( str, NULL, 0 );
1081         if ( ( val >= 1 ) && ( val <= 48 ) ) {
1082                 decr_overclock_proc0_set = 1;
1083                 decr_overclock_proc0 = val;
1084                 printk("proc 0 decrementer overclock factor of %ld\n", val);
1085         }
1086         else
1087                 printk("invalid proc 0 decrementer overclock factor of %ld\n", val);
1088         return 1;
1089 }
1090
1091 int set_decr_overclock( char * str )
1092 {
1093         unsigned long val = simple_strtoul( str, NULL, 0 );
1094         if ( ( val >= 1 ) && ( val <= 48 ) ) {
1095                 decr_overclock_set = 1;
1096                 decr_overclock = val;
1097                 printk("decrementer overclock factor of %ld\n", val);
1098         }
1099         else
1100                 printk("invalid decrementer overclock factor of %ld\n", val);
1101         return 1;
1102
1103 }
1104
1105 __setup("spread_lpevents=", set_spread_lpevents );
1106 __setup("decr_overclock_proc0=", set_decr_overclock_proc0 );
1107 __setup("decr_overclock=", set_decr_overclock );
1108
1109 #ifdef CONFIG_XMON
1110 static int __init early_xmon(char *p)
1111 {
1112         /* ensure xmon is enabled */
1113         xmon_init();
1114         debugger(0);
1115
1116         return 0;
1117 }
1118 early_param("xmon", early_xmon);
1119 #endif
1120