- Kai Germaschewski: ISDN update (including Makefiles)
[davej-history.git] / arch / sparc64 / kernel / setup.c
blobfa46489c1e2a5ad9aabcb96b802b74fa8c775615
1 /* $Id: setup.c,v 1.57 2000/10/14 10:09:00 davem Exp $
2 * linux/arch/sparc64/kernel/setup.c
4 * Copyright (C) 1995,1996 David S. Miller (davem@caip.rutgers.edu)
5 * Copyright (C) 1997 Jakub Jelinek (jj@sunsite.mff.cuni.cz)
6 */
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/malloc.h>
16 #include <asm/smp.h>
17 #include <linux/user.h>
18 #include <linux/a.out.h>
19 #include <linux/tty.h>
20 #include <linux/delay.h>
21 #include <linux/config.h>
22 #include <linux/fs.h>
23 #include <linux/kdev_t.h>
24 #include <linux/major.h>
25 #include <linux/string.h>
26 #include <linux/blk.h>
27 #include <linux/init.h>
28 #include <linux/inet.h>
29 #include <linux/console.h>
31 #include <asm/segment.h>
32 #include <asm/system.h>
33 #include <asm/io.h>
34 #include <asm/processor.h>
35 #include <asm/oplib.h>
36 #include <asm/page.h>
37 #include <asm/pgtable.h>
38 #include <asm/idprom.h>
39 #include <asm/head.h>
40 #include <asm/starfire.h>
42 #ifdef CONFIG_IP_PNP
43 #include <net/ipconfig.h>
44 #endif
46 #undef PROM_DEBUG_CONSOLE
48 struct screen_info screen_info = {
49 0, 0, /* orig-x, orig-y */
50 0, /* unused */
51 0, /* orig-video-page */
52 0, /* orig-video-mode */
53 128, /* orig-video-cols */
54 0, 0, 0, /* unused, ega_bx, unused */
55 54, /* orig-video-lines */
56 0, /* orig-video-isVGA */
57 16 /* orig-video-points */
60 /* Typing sync at the prom prompt calls the function pointed to by
61 * the sync callback which I set to the following function.
62 * This should sync all filesystems and return, for now it just
63 * prints out pretty messages and returns.
66 #if CONFIG_SUN_CONSOLE
67 void (*prom_palette)(int);
68 #endif
69 asmlinkage void sys_sync(void); /* it's really int */
71 static void
72 prom_console_write(struct console *con, const char *s, unsigned n)
74 prom_printf("%s", s);
77 static struct console prom_console = {
78 name: "prom",
79 write: prom_console_write,
80 flags: CON_CONSDEV | CON_ENABLED,
81 index: -1,
84 #define PROM_TRUE -1
85 #define PROM_FALSE 0
87 /* Pretty sick eh? */
88 int prom_callback(long *args)
90 struct console *cons, *saved_console = NULL;
91 unsigned long flags;
92 char *cmd;
94 if (!args)
95 return -1;
96 if (!(cmd = (char *)args[0]))
97 return -1;
99 save_and_cli(flags);
100 cons = console_drivers;
101 while (cons) {
102 unregister_console(cons);
103 cons->flags &= ~(CON_PRINTBUFFER);
104 cons->next = saved_console;
105 saved_console = cons;
106 cons = console_drivers;
108 register_console(&prom_console);
109 if (!strcmp(cmd, "sync")) {
110 prom_printf("PROM `%s' command...\n", cmd);
111 show_free_areas();
112 if(current->pid != 0) {
113 sti();
114 sys_sync();
115 cli();
117 args[2] = 0;
118 args[args[1] + 3] = -1;
119 prom_printf("Returning to PROM\n");
120 } else if (!strcmp(cmd, "va>tte-data")) {
121 unsigned long ctx, va;
122 unsigned long tte = 0;
123 long res = PROM_FALSE;
125 ctx = args[3];
126 va = args[4];
127 if (ctx) {
129 * Find process owning ctx, lookup mapping.
131 struct task_struct *p;
132 struct mm_struct *mm = NULL;
133 pgd_t *pgdp;
134 pmd_t *pmdp;
135 pte_t *ptep;
137 for_each_task(p) {
138 mm = p->mm;
139 if (CTX_HWBITS(mm->context) == ctx)
140 break;
142 if (!mm ||
143 CTX_HWBITS(mm->context) != ctx)
144 goto done;
146 pgdp = pgd_offset(mm, va);
147 if (pgd_none(*pgdp))
148 goto done;
149 pmdp = pmd_offset(pgdp, va);
150 if (pmd_none(*pmdp))
151 goto done;
152 ptep = pte_offset(pmdp, va);
153 if (!pte_present(*ptep))
154 goto done;
155 tte = pte_val(*ptep);
156 res = PROM_TRUE;
157 goto done;
160 if ((va >= KERNBASE) && (va < (KERNBASE + (4 * 1024 * 1024)))) {
161 /* Spitfire Errata #32 workaround */
162 __asm__ __volatile__("stxa %0, [%1] %2\n\t"
163 "flush %%g6"
164 : /* No outputs */
165 : "r" (0),
166 "r" (PRIMARY_CONTEXT), "i" (ASI_DMMU));
169 * Locked down tlb entry 63.
172 tte = spitfire_get_dtlb_data(63);
173 res = PROM_TRUE;
174 goto done;
177 if (va < PGDIR_SIZE) {
179 * vmalloc or prom_inherited mapping.
181 pgd_t *pgdp;
182 pmd_t *pmdp;
183 pte_t *ptep;
185 pgdp = pgd_offset_k(va);
186 if (pgd_none(*pgdp))
187 goto done;
188 pmdp = pmd_offset(pgdp, va);
189 if (pmd_none(*pmdp))
190 goto done;
191 ptep = pte_offset(pmdp, va);
192 if (!pte_present(*ptep))
193 goto done;
194 tte = pte_val(*ptep);
195 res = PROM_TRUE;
196 goto done;
199 if (va < PAGE_OFFSET) {
201 * No mappings here.
203 goto done;
206 if (va & (1UL << 40)) {
208 * I/O page.
211 tte = (__pa(va) & _PAGE_PADDR) |
212 _PAGE_VALID | _PAGE_SZ4MB |
213 _PAGE_E | _PAGE_P | _PAGE_W;
214 res = PROM_TRUE;
215 goto done;
219 * Normal page.
221 tte = (__pa(va) & _PAGE_PADDR) |
222 _PAGE_VALID | _PAGE_SZ4MB |
223 _PAGE_CP | _PAGE_CV | _PAGE_P | _PAGE_W;
224 res = PROM_TRUE;
226 done:
227 if (res == PROM_TRUE) {
228 args[2] = 3;
229 args[args[1] + 3] = 0;
230 args[args[1] + 4] = res;
231 args[args[1] + 5] = tte;
232 } else {
233 args[2] = 2;
234 args[args[1] + 3] = 0;
235 args[args[1] + 4] = res;
237 } else if (!strcmp(cmd, ".soft1")) {
238 unsigned long tte;
240 tte = args[3];
241 prom_printf("%lx:\"%s%s%s%s%s\" ",
242 (tte & _PAGE_SOFT) >> 7,
243 tte & _PAGE_MODIFIED ? "M" : "-",
244 tte & _PAGE_ACCESSED ? "A" : "-",
245 tte & _PAGE_READ ? "W" : "-",
246 tte & _PAGE_WRITE ? "R" : "-",
247 tte & _PAGE_PRESENT ? "P" : "-");
249 args[2] = 2;
250 args[args[1] + 3] = 0;
251 args[args[1] + 4] = PROM_TRUE;
252 } else if (!strcmp(cmd, ".soft2")) {
253 unsigned long tte;
255 tte = args[3];
256 prom_printf("%lx ", (tte & _PAGE_SOFT2) >> 50);
258 args[2] = 2;
259 args[args[1] + 3] = 0;
260 args[args[1] + 4] = PROM_TRUE;
261 } else {
262 prom_printf("unknown PROM `%s' command...\n", cmd);
264 unregister_console(&prom_console);
265 while (saved_console) {
266 cons = saved_console;
267 saved_console = cons->next;
268 register_console(cons);
270 restore_flags(flags);
271 return 0;
274 extern void rs_kgdb_hook(int tty_num); /* sparc/serial.c */
276 unsigned int boot_flags = 0;
277 #define BOOTME_DEBUG 0x1
278 #define BOOTME_SINGLE 0x2
279 #define BOOTME_KGDB 0x4
281 #ifdef CONFIG_SUN_CONSOLE
282 static int console_fb __initdata = 0;
283 #endif
285 /* Exported for mm/init.c:paging_init. */
286 unsigned long cmdline_memory_size = 0;
288 #ifdef PROM_DEBUG_CONSOLE
289 static struct console prom_debug_console = {
290 name: "debug",
291 write: prom_console_write,
292 flags: CON_PRINTBUFFER,
293 index: -1,
295 #endif
297 /* XXX Implement this at some point... */
298 void kernel_enter_debugger(void)
302 int obp_system_intr(void)
304 if (boot_flags & BOOTME_DEBUG) {
305 printk("OBP: system interrupted\n");
306 prom_halt();
307 return 1;
309 return 0;
313 * Process kernel command line switches that are specific to the
314 * SPARC or that require special low-level processing.
316 static void __init process_switch(char c)
318 switch (c) {
319 case 'd':
320 boot_flags |= BOOTME_DEBUG;
321 break;
322 case 's':
323 boot_flags |= BOOTME_SINGLE;
324 break;
325 case 'h':
326 prom_printf("boot_flags_init: Halt!\n");
327 prom_halt();
328 break;
329 default:
330 printk("Unknown boot switch (-%c)\n", c);
331 break;
335 static void __init boot_flags_init(char *commands)
337 while (*commands) {
338 /* Move to the start of the next "argument". */
339 while (*commands && *commands == ' ')
340 commands++;
342 /* Process any command switches, otherwise skip it. */
343 if (*commands == '\0')
344 break;
345 else if (*commands == '-') {
346 commands++;
347 while (*commands && *commands != ' ')
348 process_switch(*commands++);
349 } else if (strlen(commands) >= 9
350 && !strncmp(commands, "kgdb=tty", 8)) {
351 boot_flags |= BOOTME_KGDB;
352 switch (commands[8]) {
353 #ifdef CONFIG_SUN_SERIAL
354 case 'a':
355 rs_kgdb_hook(0);
356 prom_printf("KGDB: Using serial line /dev/ttya.\n");
357 break;
358 case 'b':
359 rs_kgdb_hook(1);
360 prom_printf("KGDB: Using serial line /dev/ttyb.\n");
361 break;
362 #endif
363 default:
364 printk("KGDB: Unknown tty line.\n");
365 boot_flags &= ~BOOTME_KGDB;
366 break;
368 commands += 9;
369 } else {
370 #if CONFIG_SUN_CONSOLE
371 if (!strncmp(commands, "console=", 8)) {
372 commands += 8;
373 if (!strncmp (commands, "ttya", 4)) {
374 console_fb = 2;
375 prom_printf ("Using /dev/ttya as console.\n");
376 } else if (!strncmp (commands, "ttyb", 4)) {
377 console_fb = 3;
378 prom_printf ("Using /dev/ttyb as console.\n");
379 #if defined(CONFIG_PROM_CONSOLE)
380 } else if (!strncmp (commands, "prom", 4)) {
381 char *p;
383 for (p = commands - 8; *p && *p != ' '; p++)
384 *p = ' ';
385 conswitchp = &prom_con;
386 console_fb = 1;
387 #endif
388 } else {
389 console_fb = 1;
391 } else
392 #endif
393 if (!strncmp(commands, "mem=", 4)) {
395 * "mem=XXX[kKmM]" overrides the PROM-reported
396 * memory size.
398 cmdline_memory_size = simple_strtoul(commands + 4,
399 &commands, 0);
400 if (*commands == 'K' || *commands == 'k') {
401 cmdline_memory_size <<= 10;
402 commands++;
403 } else if (*commands=='M' || *commands=='m') {
404 cmdline_memory_size <<= 20;
405 commands++;
408 while (*commands && *commands != ' ')
409 commands++;
414 extern int prom_probe_memory(void);
415 extern unsigned long start, end;
416 extern void panic_setup(char *, int *);
418 extern unsigned short root_flags;
419 extern unsigned short root_dev;
420 extern unsigned short ram_flags;
421 #define RAMDISK_IMAGE_START_MASK 0x07FF
422 #define RAMDISK_PROMPT_FLAG 0x8000
423 #define RAMDISK_LOAD_FLAG 0x4000
425 extern int root_mountflags;
427 char saved_command_line[256];
428 char reboot_command[256];
430 extern unsigned long phys_base;
432 static struct pt_regs fake_swapper_regs = { { 0, }, 0, 0, 0, 0 };
434 void register_prom_callbacks(void)
436 prom_setcallback(prom_callback);
437 prom_feval(": linux-va>tte-data 2 \" va>tte-data\" $callback drop ; "
438 "' linux-va>tte-data to va>tte-data");
439 prom_feval(": linux-.soft1 1 \" .soft1\" $callback 2drop ; "
440 "' linux-.soft1 to .soft1");
441 prom_feval(": linux-.soft2 1 \" .soft2\" $callback 2drop ; "
442 "' linux-.soft2 to .soft2");
445 extern void paging_init(void);
447 void __init setup_arch(char **cmdline_p)
449 extern int serial_console; /* in console.c, of course */
450 unsigned long highest_paddr;
451 int i;
453 /* Initialize PROM console and command line. */
454 *cmdline_p = prom_getbootargs();
455 strcpy(saved_command_line, *cmdline_p);
457 #ifdef PROM_DEBUG_CONSOLE
458 register_console(&prom_debug_console);
459 #endif
461 printk("ARCH: SUN4U\n");
463 #ifdef CONFIG_DUMMY_CONSOLE
464 conswitchp = &dummy_con;
465 #elif defined(CONFIG_PROM_CONSOLE)
466 conswitchp = &prom_con;
467 #endif
469 /* Work out if we are starfire early on */
470 check_if_starfire();
472 boot_flags_init(*cmdline_p);
474 idprom_init();
475 (void) prom_probe_memory();
477 /* In paging_init() we tip off this value to see if we need
478 * to change init_mm.pgd to point to the real alias mapping.
480 phys_base = 0xffffffffffffffffUL;
481 highest_paddr = 0UL;
482 for (i = 0; sp_banks[i].num_bytes != 0; i++) {
483 unsigned long top;
485 if (sp_banks[i].base_addr < phys_base)
486 phys_base = sp_banks[i].base_addr;
487 top = sp_banks[i].base_addr +
488 sp_banks[i].num_bytes;
489 if (highest_paddr < top)
490 highest_paddr = top;
493 if (!root_flags)
494 root_mountflags &= ~MS_RDONLY;
495 ROOT_DEV = to_kdev_t(root_dev);
496 #ifdef CONFIG_BLK_DEV_RAM
497 rd_image_start = ram_flags & RAMDISK_IMAGE_START_MASK;
498 rd_prompt = ((ram_flags & RAMDISK_PROMPT_FLAG) != 0);
499 rd_doload = ((ram_flags & RAMDISK_LOAD_FLAG) != 0);
500 #endif
502 /* Due to stack alignment restrictions and assumptions... */
503 init_mm.mmap->vm_page_prot = PAGE_SHARED;
504 init_mm.mmap->vm_start = PAGE_OFFSET;
505 init_mm.mmap->vm_end = PAGE_OFFSET + highest_paddr;
506 init_task.thread.kregs = &fake_swapper_regs;
508 #ifdef CONFIG_IP_PNP
509 if (!ic_set_manually) {
510 int chosen = prom_finddevice ("/chosen");
511 u32 cl, sv, gw;
513 cl = prom_getintdefault (chosen, "client-ip", 0);
514 sv = prom_getintdefault (chosen, "server-ip", 0);
515 gw = prom_getintdefault (chosen, "gateway-ip", 0);
516 if (cl && sv) {
517 ic_myaddr = cl;
518 ic_servaddr = sv;
519 if (gw)
520 ic_gateway = gw;
521 #if defined(CONFIG_IP_PNP_BOOTP) || defined(CONFIG_IP_PNP_RARP)
522 ic_proto_enabled = 0;
523 #endif
526 #endif
528 #ifdef CONFIG_SUN_SERIAL
529 switch (console_fb) {
530 case 0: /* Let's get our io devices from prom */
532 int idev = prom_query_input_device();
533 int odev = prom_query_output_device();
534 if (idev == PROMDEV_IKBD && odev == PROMDEV_OSCREEN) {
535 serial_console = 0;
536 } else if (idev == PROMDEV_ITTYA && odev == PROMDEV_OTTYA) {
537 serial_console = 1;
538 } else if (idev == PROMDEV_ITTYB && odev == PROMDEV_OTTYB) {
539 serial_console = 2;
540 } else {
541 prom_printf("Inconsistent console: "
542 "input %d, output %d\n",
543 idev, odev);
544 prom_halt();
547 break;
548 case 1: /* Force one of the framebuffers as console */
549 serial_console = 0;
550 break;
551 case 2: /* Force ttya as console */
552 serial_console = 1;
553 break;
554 case 3: /* Force ttyb as console */
555 serial_console = 2;
556 break;
558 #else
559 serial_console = 0;
560 #endif
561 if (serial_console)
562 conswitchp = NULL;
564 paging_init();
567 asmlinkage int sys_ioperm(unsigned long from, unsigned long num, int on)
569 return -EIO;
572 /* BUFFER is PAGE_SIZE bytes long. */
574 extern char *sparc_cpu_type[];
575 extern char *sparc_fpu_type[];
577 extern int smp_info(char *);
578 extern int smp_bogo(char *);
579 extern int mmu_info(char *);
581 int get_cpuinfo(char *buffer)
583 int cpuid=smp_processor_id();
584 int len;
586 len = sprintf(buffer,
587 "cpu\t\t: %s\n"
588 "fpu\t\t: %s\n"
589 "promlib\t\t: Version 3 Revision %d\n"
590 "prom\t\t: %d.%d.%d\n"
591 "type\t\t: sun4u\n"
592 "ncpus probed\t: %d\n"
593 "ncpus active\t: %d\n"
594 #ifndef CONFIG_SMP
595 "BogoMips\t: %lu.%02lu\n"
596 #endif
598 sparc_cpu_type[cpuid],
599 sparc_fpu_type[cpuid],
600 prom_rev, prom_prev >> 16, (prom_prev >> 8) & 0xff, prom_prev & 0xff,
601 linux_num_cpus, smp_num_cpus
602 #ifndef CONFIG_SMP
603 , loops_per_sec/500000, (loops_per_sec/5000) % 100
604 #endif
606 #ifdef CONFIG_SMP
607 len += smp_bogo(buffer + len);
608 #endif
609 len += mmu_info(buffer + len);
610 #ifdef CONFIG_SMP
611 len += smp_info(buffer + len);
612 #endif
613 #undef ZS_LOG
614 #ifdef ZS_LOG
616 extern int zs_dumplog(char *);
617 len += zs_dumplog(buffer + len);
619 #endif
620 return len;