aout: remove unnecessary inclusions of {asm, linux}/a.out.h
[safe/jmp/linux-2.6] / arch / sparc64 / kernel / setup.c
1 /*  $Id: setup.c,v 1.72 2002/02/09 19:49:30 davem Exp $
2  *  linux/arch/sparc64/kernel/setup.c
3  *
4  *  Copyright (C) 1995,1996  David S. Miller (davem@caip.rutgers.edu)
5  *  Copyright (C) 1997       Jakub Jelinek (jj@sunsite.mff.cuni.cz)
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 <asm/smp.h>
17 #include <linux/user.h>
18 #include <linux/screen_info.h>
19 #include <linux/delay.h>
20 #include <linux/fs.h>
21 #include <linux/seq_file.h>
22 #include <linux/syscalls.h>
23 #include <linux/kdev_t.h>
24 #include <linux/major.h>
25 #include <linux/string.h>
26 #include <linux/init.h>
27 #include <linux/inet.h>
28 #include <linux/console.h>
29 #include <linux/root_dev.h>
30 #include <linux/interrupt.h>
31 #include <linux/cpu.h>
32 #include <linux/initrd.h>
33
34 #include <asm/system.h>
35 #include <asm/io.h>
36 #include <asm/processor.h>
37 #include <asm/oplib.h>
38 #include <asm/page.h>
39 #include <asm/pgtable.h>
40 #include <asm/idprom.h>
41 #include <asm/head.h>
42 #include <asm/starfire.h>
43 #include <asm/mmu_context.h>
44 #include <asm/timer.h>
45 #include <asm/sections.h>
46 #include <asm/setup.h>
47 #include <asm/mmu.h>
48 #include <asm/ns87303.h>
49
50 #ifdef CONFIG_IP_PNP
51 #include <net/ipconfig.h>
52 #endif
53
54 /* Used to synchronize accesses to NatSemi SUPER I/O chip configure
55  * operations in asm/ns87303.h
56  */
57 DEFINE_SPINLOCK(ns87303_lock);
58
59 struct screen_info screen_info = {
60         0, 0,                   /* orig-x, orig-y */
61         0,                      /* unused */
62         0,                      /* orig-video-page */
63         0,                      /* orig-video-mode */
64         128,                    /* orig-video-cols */
65         0, 0, 0,                /* unused, ega_bx, unused */
66         54,                     /* orig-video-lines */
67         0,                      /* orig-video-isVGA */
68         16                      /* orig-video-points */
69 };
70
71 void (*prom_palette)(int);
72 void (*prom_keyboard)(void);
73
74 static void
75 prom_console_write(struct console *con, const char *s, unsigned n)
76 {
77         prom_write(s, n);
78 }
79
80 unsigned int boot_flags = 0;
81 #define BOOTME_DEBUG  0x1
82
83 /* Exported for mm/init.c:paging_init. */
84 unsigned long cmdline_memory_size = 0;
85
86 static struct console prom_debug_console = {
87         .name =         "debug",
88         .write =        prom_console_write,
89         .flags =        CON_PRINTBUFFER,
90         .index =        -1,
91 };
92
93 /* XXX Implement this at some point... */
94 void kernel_enter_debugger(void)
95 {
96 }
97
98 /* 
99  * Process kernel command line switches that are specific to the
100  * SPARC or that require special low-level processing.
101  */
102 static void __init process_switch(char c)
103 {
104         switch (c) {
105         case 'd':
106                 boot_flags |= BOOTME_DEBUG;
107                 break;
108         case 's':
109                 break;
110         case 'h':
111                 prom_printf("boot_flags_init: Halt!\n");
112                 prom_halt();
113                 break;
114         case 'p':
115                 /* Use PROM debug console. */
116                 register_console(&prom_debug_console);
117                 break;
118         case 'P':
119                 /* Force UltraSPARC-III P-Cache on. */
120                 if (tlb_type != cheetah) {
121                         printk("BOOT: Ignoring P-Cache force option.\n");
122                         break;
123                 }
124                 cheetah_pcache_forced_on = 1;
125                 add_taint(TAINT_MACHINE_CHECK);
126                 cheetah_enable_pcache();
127                 break;
128
129         default:
130                 printk("Unknown boot switch (-%c)\n", c);
131                 break;
132         }
133 }
134
135 static void __init boot_flags_init(char *commands)
136 {
137         while (*commands) {
138                 /* Move to the start of the next "argument". */
139                 while (*commands && *commands == ' ')
140                         commands++;
141
142                 /* Process any command switches, otherwise skip it. */
143                 if (*commands == '\0')
144                         break;
145                 if (*commands == '-') {
146                         commands++;
147                         while (*commands && *commands != ' ')
148                                 process_switch(*commands++);
149                         continue;
150                 }
151                 if (!strncmp(commands, "mem=", 4)) {
152                         /*
153                          * "mem=XXX[kKmM]" overrides the PROM-reported
154                          * memory size.
155                          */
156                         cmdline_memory_size = simple_strtoul(commands + 4,
157                                                              &commands, 0);
158                         if (*commands == 'K' || *commands == 'k') {
159                                 cmdline_memory_size <<= 10;
160                                 commands++;
161                         } else if (*commands=='M' || *commands=='m') {
162                                 cmdline_memory_size <<= 20;
163                                 commands++;
164                         }
165                 }
166                 while (*commands && *commands != ' ')
167                         commands++;
168         }
169 }
170
171 extern void panic_setup(char *, int *);
172
173 extern unsigned short root_flags;
174 extern unsigned short root_dev;
175 extern unsigned short ram_flags;
176 #define RAMDISK_IMAGE_START_MASK        0x07FF
177 #define RAMDISK_PROMPT_FLAG             0x8000
178 #define RAMDISK_LOAD_FLAG               0x4000
179
180 extern int root_mountflags;
181
182 char reboot_command[COMMAND_LINE_SIZE];
183
184 static struct pt_regs fake_swapper_regs = { { 0, }, 0, 0, 0, 0 };
185
186 void __init per_cpu_patch(void)
187 {
188         struct cpuid_patch_entry *p;
189         unsigned long ver;
190         int is_jbus;
191
192         if (tlb_type == spitfire && !this_is_starfire)
193                 return;
194
195         is_jbus = 0;
196         if (tlb_type != hypervisor) {
197                 __asm__ ("rdpr %%ver, %0" : "=r" (ver));
198                 is_jbus = ((ver >> 32UL) == __JALAPENO_ID ||
199                            (ver >> 32UL) == __SERRANO_ID);
200         }
201
202         p = &__cpuid_patch;
203         while (p < &__cpuid_patch_end) {
204                 unsigned long addr = p->addr;
205                 unsigned int *insns;
206
207                 switch (tlb_type) {
208                 case spitfire:
209                         insns = &p->starfire[0];
210                         break;
211                 case cheetah:
212                 case cheetah_plus:
213                         if (is_jbus)
214                                 insns = &p->cheetah_jbus[0];
215                         else
216                                 insns = &p->cheetah_safari[0];
217                         break;
218                 case hypervisor:
219                         insns = &p->sun4v[0];
220                         break;
221                 default:
222                         prom_printf("Unknown cpu type, halting.\n");
223                         prom_halt();
224                 };
225
226                 *(unsigned int *) (addr +  0) = insns[0];
227                 wmb();
228                 __asm__ __volatile__("flush     %0" : : "r" (addr +  0));
229
230                 *(unsigned int *) (addr +  4) = insns[1];
231                 wmb();
232                 __asm__ __volatile__("flush     %0" : : "r" (addr +  4));
233
234                 *(unsigned int *) (addr +  8) = insns[2];
235                 wmb();
236                 __asm__ __volatile__("flush     %0" : : "r" (addr +  8));
237
238                 *(unsigned int *) (addr + 12) = insns[3];
239                 wmb();
240                 __asm__ __volatile__("flush     %0" : : "r" (addr + 12));
241
242                 p++;
243         }
244 }
245
246 void __init sun4v_patch(void)
247 {
248         extern void sun4v_hvapi_init(void);
249         struct sun4v_1insn_patch_entry *p1;
250         struct sun4v_2insn_patch_entry *p2;
251
252         if (tlb_type != hypervisor)
253                 return;
254
255         p1 = &__sun4v_1insn_patch;
256         while (p1 < &__sun4v_1insn_patch_end) {
257                 unsigned long addr = p1->addr;
258
259                 *(unsigned int *) (addr +  0) = p1->insn;
260                 wmb();
261                 __asm__ __volatile__("flush     %0" : : "r" (addr +  0));
262
263                 p1++;
264         }
265
266         p2 = &__sun4v_2insn_patch;
267         while (p2 < &__sun4v_2insn_patch_end) {
268                 unsigned long addr = p2->addr;
269
270                 *(unsigned int *) (addr +  0) = p2->insns[0];
271                 wmb();
272                 __asm__ __volatile__("flush     %0" : : "r" (addr +  0));
273
274                 *(unsigned int *) (addr +  4) = p2->insns[1];
275                 wmb();
276                 __asm__ __volatile__("flush     %0" : : "r" (addr +  4));
277
278                 p2++;
279         }
280
281         sun4v_hvapi_init();
282 }
283
284 #ifdef CONFIG_SMP
285 void __init boot_cpu_id_too_large(int cpu)
286 {
287         prom_printf("Serious problem, boot cpu id (%d) >= NR_CPUS (%d)\n",
288                     cpu, NR_CPUS);
289         prom_halt();
290 }
291 #endif
292
293 void __init setup_arch(char **cmdline_p)
294 {
295         /* Initialize PROM console and command line. */
296         *cmdline_p = prom_getbootargs();
297         strcpy(boot_command_line, *cmdline_p);
298
299         if (tlb_type == hypervisor)
300                 printk("ARCH: SUN4V\n");
301         else
302                 printk("ARCH: SUN4U\n");
303
304 #ifdef CONFIG_DUMMY_CONSOLE
305         conswitchp = &dummy_con;
306 #elif defined(CONFIG_PROM_CONSOLE)
307         conswitchp = &prom_con;
308 #endif
309
310         boot_flags_init(*cmdline_p);
311
312         idprom_init();
313
314         if (!root_flags)
315                 root_mountflags &= ~MS_RDONLY;
316         ROOT_DEV = old_decode_dev(root_dev);
317 #ifdef CONFIG_BLK_DEV_RAM
318         rd_image_start = ram_flags & RAMDISK_IMAGE_START_MASK;
319         rd_prompt = ((ram_flags & RAMDISK_PROMPT_FLAG) != 0);
320         rd_doload = ((ram_flags & RAMDISK_LOAD_FLAG) != 0);     
321 #endif
322
323         task_thread_info(&init_task)->kregs = &fake_swapper_regs;
324
325 #ifdef CONFIG_IP_PNP
326         if (!ic_set_manually) {
327                 int chosen = prom_finddevice ("/chosen");
328                 u32 cl, sv, gw;
329                 
330                 cl = prom_getintdefault (chosen, "client-ip", 0);
331                 sv = prom_getintdefault (chosen, "server-ip", 0);
332                 gw = prom_getintdefault (chosen, "gateway-ip", 0);
333                 if (cl && sv) {
334                         ic_myaddr = cl;
335                         ic_servaddr = sv;
336                         if (gw)
337                                 ic_gateway = gw;
338 #if defined(CONFIG_IP_PNP_BOOTP) || defined(CONFIG_IP_PNP_RARP)
339                         ic_proto_enabled = 0;
340 #endif
341                 }
342         }
343 #endif
344
345         /* Get boot processor trap_block[] setup.  */
346         init_cur_cpu_trap(current_thread_info());
347
348         paging_init();
349 }
350
351 /* BUFFER is PAGE_SIZE bytes long. */
352
353 extern char *sparc_cpu_type;
354 extern char *sparc_fpu_type;
355
356 extern void smp_info(struct seq_file *);
357 extern void smp_bogo(struct seq_file *);
358 extern void mmu_info(struct seq_file *);
359
360 unsigned int dcache_parity_tl1_occurred;
361 unsigned int icache_parity_tl1_occurred;
362
363 int ncpus_probed;
364
365 static int show_cpuinfo(struct seq_file *m, void *__unused)
366 {
367         seq_printf(m, 
368                    "cpu\t\t: %s\n"
369                    "fpu\t\t: %s\n"
370                    "prom\t\t: %s\n"
371                    "type\t\t: %s\n"
372                    "ncpus probed\t: %d\n"
373                    "ncpus active\t: %d\n"
374                    "D$ parity tl1\t: %u\n"
375                    "I$ parity tl1\t: %u\n"
376 #ifndef CONFIG_SMP
377                    "Cpu0ClkTck\t: %016lx\n"
378 #endif
379                    ,
380                    sparc_cpu_type,
381                    sparc_fpu_type,
382                    prom_version,
383                    ((tlb_type == hypervisor) ?
384                     "sun4v" :
385                     "sun4u"),
386                    ncpus_probed,
387                    num_online_cpus(),
388                    dcache_parity_tl1_occurred,
389                    icache_parity_tl1_occurred
390 #ifndef CONFIG_SMP
391                    , cpu_data(0).clock_tick
392 #endif
393                 );
394 #ifdef CONFIG_SMP
395         smp_bogo(m);
396 #endif
397         mmu_info(m);
398 #ifdef CONFIG_SMP
399         smp_info(m);
400 #endif
401         return 0;
402 }
403
404 static void *c_start(struct seq_file *m, loff_t *pos)
405 {
406         /* The pointer we are returning is arbitrary,
407          * it just has to be non-NULL and not IS_ERR
408          * in the success case.
409          */
410         return *pos == 0 ? &c_start : NULL;
411 }
412
413 static void *c_next(struct seq_file *m, void *v, loff_t *pos)
414 {
415         ++*pos;
416         return c_start(m, pos);
417 }
418
419 static void c_stop(struct seq_file *m, void *v)
420 {
421 }
422
423 const struct seq_operations cpuinfo_op = {
424         .start =c_start,
425         .next = c_next,
426         .stop = c_stop,
427         .show = show_cpuinfo,
428 };
429
430 extern int stop_a_enabled;
431
432 void sun_do_break(void)
433 {
434         if (!stop_a_enabled)
435                 return;
436
437         prom_printf("\n");
438         flush_user_windows();
439
440         prom_cmdline();
441 }
442
443 int stop_a_enabled = 1;