[Bluetooth] Make use of virtual devices tree
[pandora-kernel.git] / arch / sparc / kernel / setup.c
1 /*  $Id: setup.c,v 1.126 2001/11/13 00:49:27 davem Exp $
2  *  linux/arch/sparc/kernel/setup.c
3  *
4  *  Copyright (C) 1995  David S. Miller (davem@caip.rutgers.edu)
5  *  Copyright (C) 2000  Anton Blanchard (anton@samba.org)
6  */
7
8 #include <linux/errno.h>
9 #include <linux/sched.h>
10 #include <linux/kernel.h>
11 #include <linux/mm.h>
12 #include <linux/stddef.h>
13 #include <linux/unistd.h>
14 #include <linux/ptrace.h>
15 #include <linux/slab.h>
16 #include <linux/initrd.h>
17 #include <asm/smp.h>
18 #include <linux/user.h>
19 #include <linux/a.out.h>
20 #include <linux/screen_info.h>
21 #include <linux/delay.h>
22 #include <linux/fs.h>
23 #include <linux/seq_file.h>
24 #include <linux/syscalls.h>
25 #include <linux/kdev_t.h>
26 #include <linux/major.h>
27 #include <linux/string.h>
28 #include <linux/init.h>
29 #include <linux/interrupt.h>
30 #include <linux/console.h>
31 #include <linux/spinlock.h>
32 #include <linux/root_dev.h>
33 #include <linux/cpu.h>
34
35 #include <asm/system.h>
36 #include <asm/io.h>
37 #include <asm/processor.h>
38 #include <asm/oplib.h>
39 #include <asm/page.h>
40 #include <asm/pgtable.h>
41 #include <asm/traps.h>
42 #include <asm/vaddrs.h>
43 #include <asm/kdebug.h>
44 #include <asm/mbus.h>
45 #include <asm/idprom.h>
46 #include <asm/machines.h>
47 #include <asm/cpudata.h>
48 #include <asm/setup.h>
49
50 struct screen_info screen_info = {
51         0, 0,                   /* orig-x, orig-y */
52         0,                      /* unused */
53         0,                      /* orig-video-page */
54         0,                      /* orig-video-mode */
55         128,                    /* orig-video-cols */
56         0,0,0,                  /* ega_ax, ega_bx, ega_cx */
57         54,                     /* orig-video-lines */
58         0,                      /* orig-video-isVGA */
59         16                      /* orig-video-points */
60 };
61
62 /* Typing sync at the prom prompt calls the function pointed to by
63  * romvec->pv_synchook which I set to the following function.
64  * This should sync all filesystems and return, for now it just
65  * prints out pretty messages and returns.
66  */
67
68 extern unsigned long trapbase;
69 void (*prom_palette)(int);
70
71 /* Pretty sick eh? */
72 void prom_sync_me(void)
73 {
74         unsigned long prom_tbr, flags;
75
76         /* XXX Badly broken. FIX! - Anton */
77         local_irq_save(flags);
78         __asm__ __volatile__("rd %%tbr, %0\n\t" : "=r" (prom_tbr));
79         __asm__ __volatile__("wr %0, 0x0, %%tbr\n\t"
80                              "nop\n\t"
81                              "nop\n\t"
82                              "nop\n\t" : : "r" (&trapbase));
83
84         if (prom_palette)
85                 prom_palette(1);
86         prom_printf("PROM SYNC COMMAND...\n");
87         show_free_areas();
88         if(current->pid != 0) {
89                 local_irq_enable();
90                 sys_sync();
91                 local_irq_disable();
92         }
93         prom_printf("Returning to prom\n");
94
95         __asm__ __volatile__("wr %0, 0x0, %%tbr\n\t"
96                              "nop\n\t"
97                              "nop\n\t"
98                              "nop\n\t" : : "r" (prom_tbr));
99         local_irq_restore(flags);
100
101         return;
102 }
103
104 unsigned int boot_flags __initdata = 0;
105 #define BOOTME_DEBUG  0x1
106 #define BOOTME_SINGLE 0x2
107
108 /* Exported for mm/init.c:paging_init. */
109 unsigned long cmdline_memory_size __initdata = 0;
110
111 static void
112 prom_console_write(struct console *con, const char *s, unsigned n)
113 {
114         prom_write(s, n);
115 }
116
117 static struct console prom_debug_console = {
118         .name =         "debug",
119         .write =        prom_console_write,
120         .flags =        CON_PRINTBUFFER,
121         .index =        -1,
122 };
123
124 /* 
125  * Process kernel command line switches that are specific to the
126  * SPARC or that require special low-level processing.
127  */
128 static void __init process_switch(char c)
129 {
130         switch (c) {
131         case 'd':
132                 boot_flags |= BOOTME_DEBUG;
133                 break;
134         case 's':
135                 boot_flags |= BOOTME_SINGLE;
136                 break;
137         case 'h':
138                 prom_printf("boot_flags_init: Halt!\n");
139                 prom_halt();
140                 break;
141         case 'p':
142                 /* Use PROM debug console. */
143                 register_console(&prom_debug_console);
144                 break;
145         default:
146                 printk("Unknown boot switch (-%c)\n", c);
147                 break;
148         }
149 }
150
151 static void __init process_console(char *commands)
152 {
153         serial_console = 0;
154         commands += 8;
155         /* Linux-style serial */
156         if (!strncmp(commands, "ttyS", 4))
157                 serial_console = simple_strtoul(commands + 4, NULL, 10) + 1;
158         else if (!strncmp(commands, "tty", 3)) {
159                 char c = *(commands + 3);
160                 /* Solaris-style serial */
161                 if (c == 'a' || c == 'b')
162                         serial_console = c - 'a' + 1;
163                 /* else Linux-style fbcon, not serial */
164         }
165 #if defined(CONFIG_PROM_CONSOLE)
166         if (!strncmp(commands, "prom", 4)) {
167                 char *p;
168
169                 for (p = commands - 8; *p && *p != ' '; p++)
170                         *p = ' ';
171                 conswitchp = &prom_con;
172         }
173 #endif
174 }
175
176 static void __init boot_flags_init(char *commands)
177 {
178         while (*commands) {
179                 /* Move to the start of the next "argument". */
180                 while (*commands && *commands == ' ')
181                         commands++;
182
183                 /* Process any command switches, otherwise skip it. */
184                 if (*commands == '\0')
185                         break;
186                 if (*commands == '-') {
187                         commands++;
188                         while (*commands && *commands != ' ')
189                                 process_switch(*commands++);
190                         continue;
191                 }
192                 if (!strncmp(commands, "console=", 8)) {
193                         process_console(commands);
194                 } else if (!strncmp(commands, "mem=", 4)) {
195                         /*
196                          * "mem=XXX[kKmM] overrides the PROM-reported
197                          * memory size.
198                          */
199                         cmdline_memory_size = simple_strtoul(commands + 4,
200                                                      &commands, 0);
201                         if (*commands == 'K' || *commands == 'k') {
202                                 cmdline_memory_size <<= 10;
203                                 commands++;
204                         } else if (*commands=='M' || *commands=='m') {
205                                 cmdline_memory_size <<= 20;
206                                 commands++;
207                         }
208                 }
209                 while (*commands && *commands != ' ')
210                         commands++;
211         }
212 }
213
214 /* This routine will in the future do all the nasty prom stuff
215  * to probe for the mmu type and its parameters, etc. This will
216  * also be where SMP things happen plus the Sparc specific memory
217  * physical memory probe as on the alpha.
218  */
219
220 extern int prom_probe_memory(void);
221 extern void sun4c_probe_vac(void);
222 extern char cputypval;
223 extern unsigned long start, end;
224 extern void panic_setup(char *, int *);
225
226 extern unsigned short root_flags;
227 extern unsigned short root_dev;
228 extern unsigned short ram_flags;
229 #define RAMDISK_IMAGE_START_MASK        0x07FF
230 #define RAMDISK_PROMPT_FLAG             0x8000
231 #define RAMDISK_LOAD_FLAG               0x4000
232
233 extern int root_mountflags;
234
235 char reboot_command[COMMAND_LINE_SIZE];
236 enum sparc_cpu sparc_cpu_model;
237
238 struct tt_entry *sparc_ttable;
239
240 struct pt_regs fake_swapper_regs;
241
242 void __init setup_arch(char **cmdline_p)
243 {
244         int i;
245         unsigned long highest_paddr;
246
247         sparc_ttable = (struct tt_entry *) &start;
248
249         /* Initialize PROM console and command line. */
250         *cmdline_p = prom_getbootargs();
251         strcpy(saved_command_line, *cmdline_p);
252
253         /* Set sparc_cpu_model */
254         sparc_cpu_model = sun_unknown;
255         if(!strcmp(&cputypval,"sun4 ")) { sparc_cpu_model=sun4; }
256         if(!strcmp(&cputypval,"sun4c")) { sparc_cpu_model=sun4c; }
257         if(!strcmp(&cputypval,"sun4m")) { sparc_cpu_model=sun4m; }
258         if(!strcmp(&cputypval,"sun4s")) { sparc_cpu_model=sun4m; }  /* CP-1200 with PROM 2.30 -E */
259         if(!strcmp(&cputypval,"sun4d")) { sparc_cpu_model=sun4d; }
260         if(!strcmp(&cputypval,"sun4e")) { sparc_cpu_model=sun4e; }
261         if(!strcmp(&cputypval,"sun4u")) { sparc_cpu_model=sun4u; }
262
263 #ifdef CONFIG_SUN4
264         if (sparc_cpu_model != sun4) {
265                 prom_printf("This kernel is for Sun4 architecture only.\n");
266                 prom_halt();
267         }
268 #endif
269         printk("ARCH: ");
270         switch(sparc_cpu_model) {
271         case sun4:
272                 printk("SUN4\n");
273                 break;
274         case sun4c:
275                 printk("SUN4C\n");
276                 break;
277         case sun4m:
278                 printk("SUN4M\n");
279                 break;
280         case sun4d:
281                 printk("SUN4D\n");
282                 break;
283         case sun4e:
284                 printk("SUN4E\n");
285                 break;
286         case sun4u:
287                 printk("SUN4U\n");
288                 break;
289         default:
290                 printk("UNKNOWN!\n");
291                 break;
292         };
293
294 #ifdef CONFIG_DUMMY_CONSOLE
295         conswitchp = &dummy_con;
296 #elif defined(CONFIG_PROM_CONSOLE)
297         conswitchp = &prom_con;
298 #endif
299         boot_flags_init(*cmdline_p);
300
301         idprom_init();
302         if (ARCH_SUN4C_SUN4)
303                 sun4c_probe_vac();
304         load_mmu();
305         (void) prom_probe_memory();
306
307         phys_base = 0xffffffffUL;
308         highest_paddr = 0UL;
309         for (i = 0; sp_banks[i].num_bytes != 0; i++) {
310                 unsigned long top;
311
312                 if (sp_banks[i].base_addr < phys_base)
313                         phys_base = sp_banks[i].base_addr;
314                 top = sp_banks[i].base_addr +
315                         sp_banks[i].num_bytes;
316                 if (highest_paddr < top)
317                         highest_paddr = top;
318         }
319         pfn_base = phys_base >> PAGE_SHIFT;
320
321         if (!root_flags)
322                 root_mountflags &= ~MS_RDONLY;
323         ROOT_DEV = old_decode_dev(root_dev);
324 #ifdef CONFIG_BLK_DEV_RAM
325         rd_image_start = ram_flags & RAMDISK_IMAGE_START_MASK;
326         rd_prompt = ((ram_flags & RAMDISK_PROMPT_FLAG) != 0);
327         rd_doload = ((ram_flags & RAMDISK_LOAD_FLAG) != 0);     
328 #endif
329
330         prom_setsync(prom_sync_me);
331
332         if((boot_flags&BOOTME_DEBUG) && (linux_dbvec!=0) && 
333            ((*(short *)linux_dbvec) != -1)) {
334                 printk("Booted under KADB. Syncing trap table.\n");
335                 (*(linux_dbvec->teach_debugger))();
336         }
337
338         init_mm.context = (unsigned long) NO_CONTEXT;
339         init_task.thread.kregs = &fake_swapper_regs;
340
341         paging_init();
342
343         smp_setup_cpu_possible_map();
344 }
345
346 static int __init set_preferred_console(void)
347 {
348         int idev, odev;
349
350         /* The user has requested a console so this is already set up. */
351         if (serial_console >= 0)
352                 return -EBUSY;
353
354         idev = prom_query_input_device();
355         odev = prom_query_output_device();
356         if (idev == PROMDEV_IKBD && odev == PROMDEV_OSCREEN) {
357                 serial_console = 0;
358         } else if (idev == PROMDEV_ITTYA && odev == PROMDEV_OTTYA) {
359                 serial_console = 1;
360         } else if (idev == PROMDEV_ITTYB && odev == PROMDEV_OTTYB) {
361                 serial_console = 2;
362         } else if (idev == PROMDEV_I_UNK && odev == PROMDEV_OTTYA) {
363                 prom_printf("MrCoffee ttya\n");
364                 serial_console = 1;
365         } else if (idev == PROMDEV_I_UNK && odev == PROMDEV_OSCREEN) {
366                 serial_console = 0;
367                 prom_printf("MrCoffee keyboard\n");
368         } else {
369                 prom_printf("Confusing console (idev %d, odev %d)\n",
370                     idev, odev);
371                 serial_console = 1;
372         }
373
374         if (serial_console)
375                 return add_preferred_console("ttyS", serial_console - 1, NULL);
376
377         return -ENODEV;
378 }
379 console_initcall(set_preferred_console);
380
381 extern char *sparc_cpu_type;
382 extern char *sparc_fpu_type;
383
384 static int ncpus_probed;
385
386 static int show_cpuinfo(struct seq_file *m, void *__unused)
387 {
388         seq_printf(m,
389                    "cpu\t\t: %s\n"
390                    "fpu\t\t: %s\n"
391                    "promlib\t\t: Version %d Revision %d\n"
392                    "prom\t\t: %d.%d\n"
393                    "type\t\t: %s\n"
394                    "ncpus probed\t: %d\n"
395                    "ncpus active\t: %d\n"
396 #ifndef CONFIG_SMP
397                    "CPU0Bogo\t: %lu.%02lu\n"
398                    "CPU0ClkTck\t: %ld\n"
399 #endif
400                    ,
401                    sparc_cpu_type ? sparc_cpu_type : "undetermined",
402                    sparc_fpu_type ? sparc_fpu_type : "undetermined",
403                    romvec->pv_romvers,
404                    prom_rev,
405                    romvec->pv_printrev >> 16,
406                    romvec->pv_printrev & 0xffff,
407                    &cputypval,
408                    ncpus_probed,
409                    num_online_cpus()
410 #ifndef CONFIG_SMP
411                    , cpu_data(0).udelay_val/(500000/HZ),
412                    (cpu_data(0).udelay_val/(5000/HZ)) % 100,
413                    cpu_data(0).clock_tick
414 #endif
415                 );
416
417 #ifdef CONFIG_SMP
418         smp_bogo(m);
419 #endif
420         mmu_info(m);
421 #ifdef CONFIG_SMP
422         smp_info(m);
423 #endif
424         return 0;
425 }
426
427 static void *c_start(struct seq_file *m, loff_t *pos)
428 {
429         /* The pointer we are returning is arbitrary,
430          * it just has to be non-NULL and not IS_ERR
431          * in the success case.
432          */
433         return *pos == 0 ? &c_start : NULL;
434 }
435
436 static void *c_next(struct seq_file *m, void *v, loff_t *pos)
437 {
438         ++*pos;
439         return c_start(m, pos);
440 }
441
442 static void c_stop(struct seq_file *m, void *v)
443 {
444 }
445
446 struct seq_operations cpuinfo_op = {
447         .start =c_start,
448         .next = c_next,
449         .stop = c_stop,
450         .show = show_cpuinfo,
451 };
452
453 extern int stop_a_enabled;
454
455 void sun_do_break(void)
456 {
457         if (!stop_a_enabled)
458                 return;
459
460         printk("\n");
461         flush_user_windows();
462
463         prom_cmdline();
464 }
465
466 int serial_console = -1;
467 int stop_a_enabled = 1;
468
469 static int __init topology_init(void)
470 {
471         int i, ncpus, err;
472
473         /* Count the number of physically present processors in
474          * the machine, even on uniprocessor, so that /proc/cpuinfo
475          * output is consistent with 2.4.x
476          */
477         ncpus = 0;
478         while (!cpu_find_by_instance(ncpus, NULL, NULL))
479                 ncpus++;
480         ncpus_probed = ncpus;
481
482         err = 0;
483         for_each_online_cpu(i) {
484                 struct cpu *p = kzalloc(sizeof(*p), GFP_KERNEL);
485                 if (!p)
486                         err = -ENOMEM;
487                 else
488                         register_cpu(p, i);
489         }
490
491         return err;
492 }
493
494 subsys_initcall(topology_init);