1 /* $Id: setup.c,v 1.120 2000/10/14 10:09:00 davem Exp $
2 * linux/arch/sparc/kernel/setup.c
4 * Copyright (C) 1995 David S. Miller (davem@caip.rutgers.edu)
7 #include <linux/errno.h>
8 #include <linux/sched.h>
9 #include <linux/kernel.h>
11 #include <linux/stddef.h>
12 #include <linux/unistd.h>
13 #include <linux/ptrace.h>
14 #include <linux/malloc.h>
16 #include <linux/user.h>
17 #include <linux/a.out.h>
18 #include <linux/tty.h>
19 #include <linux/delay.h>
20 #include <linux/config.h>
22 #include <linux/kdev_t.h>
23 #include <linux/major.h>
24 #include <linux/string.h>
25 #include <linux/blk.h>
26 #include <linux/init.h>
27 #include <linux/interrupt.h>
28 #include <linux/console.h>
29 #include <linux/spinlock.h>
31 #include <asm/segment.h>
32 #include <asm/system.h>
35 #include <asm/processor.h>
36 #include <asm/oplib.h>
38 #include <asm/pgtable.h>
39 #include <asm/traps.h>
40 #include <asm/vaddrs.h>
41 #include <asm/kdebug.h>
43 #include <asm/idprom.h>
44 #include <asm/softirq.h>
45 #include <asm/hardirq.h>
46 #include <asm/machines.h>
48 #undef PROM_DEBUG_CONSOLE
50 struct screen_info screen_info
= {
51 0, 0, /* orig-x, orig-y */
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 */
62 unsigned int phys_bytes_of_ram
, end_of_phys_memory
;
64 /* Typing sync at the prom prompt calls the function pointed to by
65 * romvec->pv_synchook which I set to the following function.
66 * This should sync all filesystems and return, for now it just
67 * prints out pretty messages and returns.
70 extern unsigned long trapbase
;
71 extern int serial_console
;
72 extern void breakpoint(void);
73 #if CONFIG_SUN_CONSOLE
74 void (*prom_palette
)(int);
76 asmlinkage
void sys_sync(void); /* it's really int */
79 void prom_sync_me(void)
81 unsigned long prom_tbr
, flags
;
84 __asm__
__volatile__("rd %%tbr, %0\n\t" : "=r" (prom_tbr
));
85 __asm__
__volatile__("wr %0, 0x0, %%tbr\n\t"
88 "nop\n\t" : : "r" (&trapbase
));
90 #ifdef CONFIG_SUN_CONSOLE
94 prom_printf("PROM SYNC COMMAND...\n");
96 if(current
->pid
!= 0) {
101 prom_printf("Returning to prom\n");
103 __asm__
__volatile__("wr %0, 0x0, %%tbr\n\t"
106 "nop\n\t" : : "r" (prom_tbr
));
107 restore_flags(flags
);
112 extern void rs_kgdb_hook(int tty_num
); /* sparc/serial.c */
114 unsigned int boot_flags
;
115 #define BOOTME_DEBUG 0x1
116 #define BOOTME_SINGLE 0x2
117 #define BOOTME_KGDBA 0x4
118 #define BOOTME_KGDBB 0x8
119 #define BOOTME_KGDB 0xc
121 #ifdef CONFIG_SUN_CONSOLE
122 static int console_fb
= 0;
125 /* Exported for mm/init.c:paging_init. */
126 unsigned long cmdline_memory_size __initdata
= 0;
128 void kernel_enter_debugger(void)
130 if (boot_flags
& BOOTME_KGDB
) {
131 printk("KGDB: Entered\n");
136 int obp_system_intr(void)
138 if (boot_flags
& BOOTME_KGDB
) {
139 printk("KGDB: system interrupted\n");
143 if (boot_flags
& BOOTME_DEBUG
) {
144 printk("OBP: system interrupted\n");
152 * Process kernel command line switches that are specific to the
153 * SPARC or that require special low-level processing.
155 static void __init
process_switch(char c
)
159 boot_flags
|= BOOTME_DEBUG
;
162 boot_flags
|= BOOTME_SINGLE
;
165 prom_printf("boot_flags_init: Halt!\n");
169 printk("Unknown boot switch (-%c)\n", c
);
174 static void __init
boot_flags_init(char *commands
)
177 /* Move to the start of the next "argument". */
178 while (*commands
&& *commands
== ' ')
181 /* Process any command switches, otherwise skip it. */
182 if (*commands
== '\0')
184 else if (*commands
== '-') {
186 while (*commands
&& *commands
!= ' ')
187 process_switch(*commands
++);
188 } else if (strlen(commands
) >= 9
189 && !strncmp(commands
, "kgdb=tty", 8)) {
190 switch (commands
[8]) {
191 #ifdef CONFIG_SUN_SERIAL
193 boot_flags
|= BOOTME_KGDBA
;
194 prom_printf("KGDB: Using serial line /dev/ttya.\n");
197 boot_flags
|= BOOTME_KGDBB
;
198 prom_printf("KGDB: Using serial line /dev/ttyb.\n");
202 printk("KGDB: Unknown tty line.\n");
207 #if CONFIG_SUN_CONSOLE
208 if (!strncmp(commands
, "console=", 8)) {
210 if (!strncmp (commands
, "ttya", 4)) {
212 prom_printf ("Using /dev/ttya as console.\n");
213 } else if (!strncmp (commands
, "ttyb", 4)) {
215 prom_printf ("Using /dev/ttyb as console.\n");
216 #if defined(CONFIG_PROM_CONSOLE)
217 } else if (!strncmp (commands
, "prom", 4)) {
220 for (p
= commands
- 8; *p
&& *p
!= ' '; p
++)
222 conswitchp
= &prom_con
;
230 if (!strncmp(commands
, "mem=", 4)) {
232 * "mem=XXX[kKmM] overrides the PROM-reported
235 cmdline_memory_size
= simple_strtoul(commands
+ 4,
237 if (*commands
== 'K' || *commands
== 'k') {
238 cmdline_memory_size
<<= 10;
240 } else if (*commands
=='M' || *commands
=='m') {
241 cmdline_memory_size
<<= 20;
245 while (*commands
&& *commands
!= ' ')
251 /* This routine will in the future do all the nasty prom stuff
252 * to probe for the mmu type and its parameters, etc. This will
253 * also be where SMP things happen plus the Sparc specific memory
254 * physical memory probe as on the alpha.
257 extern int prom_probe_memory(void);
258 extern void sun4c_probe_vac(void);
259 extern char cputypval
;
260 extern unsigned long start
, end
;
261 extern void panic_setup(char *, int *);
262 extern void srmmu_end_memory(unsigned long, unsigned long *);
263 extern void sun_serial_setup(void);
265 extern unsigned short root_flags
;
266 extern unsigned short root_dev
;
267 extern unsigned short ram_flags
;
268 #define RAMDISK_IMAGE_START_MASK 0x07FF
269 #define RAMDISK_PROMPT_FLAG 0x8000
270 #define RAMDISK_LOAD_FLAG 0x4000
272 extern int root_mountflags
;
274 char saved_command_line
[256];
275 char reboot_command
[256];
276 enum sparc_cpu sparc_cpu_model
;
278 struct tt_entry
*sparc_ttable
;
280 struct pt_regs fake_swapper_regs
= { 0, 0, 0, 0, { 0, } };
282 #ifdef PROM_DEBUG_CONSOLE
283 static void prom_cons_write(struct console
*con
, const char *str
, unsigned count
)
286 prom_printf("%c", *str
++);
289 static struct console prom_console
= {
291 write
: prom_cons_write
,
292 flags
: CON_PRINTBUFFER
,
296 extern void paging_init(void);
298 void __init
setup_arch(char **cmdline_p
)
301 unsigned long highest_paddr
;
303 sparc_ttable
= (struct tt_entry
*) &start
;
305 /* Initialize PROM console and command line. */
306 *cmdline_p
= prom_getbootargs();
307 strcpy(saved_command_line
, *cmdline_p
);
309 /* Set sparc_cpu_model */
310 sparc_cpu_model
= sun_unknown
;
311 if(!strcmp(&cputypval
,"sun4 ")) { sparc_cpu_model
=sun4
; }
312 if(!strcmp(&cputypval
,"sun4c")) { sparc_cpu_model
=sun4c
; }
313 if(!strcmp(&cputypval
,"sun4m")) { sparc_cpu_model
=sun4m
; }
314 if(!strcmp(&cputypval
,"sun4s")) { sparc_cpu_model
=sun4m
; } /* CP-1200 with PROM 2.30 -E */
315 if(!strcmp(&cputypval
,"sun4d")) { sparc_cpu_model
=sun4d
; }
316 if(!strcmp(&cputypval
,"sun4e")) { sparc_cpu_model
=sun4e
; }
317 if(!strcmp(&cputypval
,"sun4u")) { sparc_cpu_model
=sun4u
; }
320 if (sparc_cpu_model
!= sun4
) {
321 prom_printf("This kernel is for Sun4 architecture only.\n");
326 switch(sparc_cpu_model
) {
346 printk("UNKNOWN!\n");
349 #ifdef PROM_DEBUG_CONSOLE
350 register_console(&prom_console
);
353 #ifdef CONFIG_DUMMY_CONSOLE
354 conswitchp
= &dummy_con
;
355 #elif defined(CONFIG_PROM_CONSOLE)
356 conswitchp
= &prom_con
;
358 boot_flags_init(*cmdline_p
);
364 (void) prom_probe_memory();
366 phys_base
= 0xffffffffUL
;
368 for (i
= 0; sp_banks
[i
].num_bytes
!= 0; i
++) {
371 if (sp_banks
[i
].base_addr
< phys_base
)
372 phys_base
= sp_banks
[i
].base_addr
;
373 top
= sp_banks
[i
].base_addr
+
374 sp_banks
[i
].num_bytes
;
375 if (highest_paddr
< top
)
380 root_mountflags
&= ~MS_RDONLY
;
381 ROOT_DEV
= to_kdev_t(root_dev
);
382 #ifdef CONFIG_BLK_DEV_RAM
383 rd_image_start
= ram_flags
& RAMDISK_IMAGE_START_MASK
;
384 rd_prompt
= ((ram_flags
& RAMDISK_PROMPT_FLAG
) != 0);
385 rd_doload
= ((ram_flags
& RAMDISK_LOAD_FLAG
) != 0);
388 prom_setsync(prom_sync_me
);
391 #if !CONFIG_SUN_SERIAL
394 switch (console_fb
) {
395 case 0: /* Let get our io devices from prom */
397 int idev
= prom_query_input_device();
398 int odev
= prom_query_output_device();
399 if (idev
== PROMDEV_IKBD
&& odev
== PROMDEV_OSCREEN
) {
401 } else if (idev
== PROMDEV_ITTYA
&& odev
== PROMDEV_OTTYA
) {
403 } else if (idev
== PROMDEV_ITTYB
&& odev
== PROMDEV_OTTYB
) {
405 } else if (idev
== PROMDEV_I_UNK
&& odev
== PROMDEV_OTTYA
) {
406 prom_printf("MrCoffee ttya\n");
408 } else if (idev
== PROMDEV_I_UNK
&& odev
== PROMDEV_OSCREEN
) {
410 prom_printf("MrCoffee keyboard\n");
412 prom_printf("Inconsistent or unknown console\n");
413 prom_printf("You cannot mix serial and non serial input/output devices\n");
418 case 1: serial_console
= 0; break; /* Force one of the framebuffers as console */
419 case 2: serial_console
= 1; break; /* Force ttya as console */
420 case 3: serial_console
= 2; break; /* Force ttyb as console */
425 if ((boot_flags
& BOOTME_KGDBA
)) {
428 if ((boot_flags
& BOOTME_KGDBB
)) {
432 if((boot_flags
&BOOTME_DEBUG
) && (linux_dbvec
!=0) &&
433 ((*(short *)linux_dbvec
) != -1)) {
434 printk("Booted under KADB. Syncing trap table.\n");
435 (*(linux_dbvec
->teach_debugger
))();
437 if((boot_flags
& BOOTME_KGDB
)) {
439 prom_printf ("Breakpoint!\n");
443 /* Due to stack alignment restrictions and assumptions... */
444 init_mm
.mmap
->vm_page_prot
= PAGE_SHARED
;
445 init_mm
.mmap
->vm_start
= PAGE_OFFSET
;
446 init_mm
.mmap
->vm_end
= PAGE_OFFSET
+ highest_paddr
;
447 init_mm
.context
= (unsigned long) NO_CONTEXT
;
448 init_task
.thread
.kregs
= &fake_swapper_regs
;
456 asmlinkage
int sys_ioperm(unsigned long from
, unsigned long num
, int on
)
461 /* BUFFER is PAGE_SIZE bytes long. */
463 extern char *sparc_cpu_type
[];
464 extern char *sparc_fpu_type
[];
466 int get_cpuinfo(char *buffer
)
468 int cpuid
=hard_smp_processor_id();
471 len
= sprintf(buffer
, "cpu\t\t: %s\n"
473 "promlib\t\t: Version %d Revision %d\n"
476 "ncpus probed\t: %d\n"
477 "ncpus active\t: %d\n"
479 "BogoMips\t: %lu.%02lu\n"
482 sparc_cpu_type
[cpuid
] ? : "undetermined",
483 sparc_fpu_type
[cpuid
] ? : "undetermined",
484 romvec
->pv_romvers
, prom_rev
, romvec
->pv_printrev
>> 16, (short)romvec
->pv_printrev
,
486 linux_num_cpus
, smp_num_cpus
488 , loops_per_sec
/500000, (loops_per_sec
/5000) % 100
492 len
+= smp_bogo_info(buffer
+ len
);
494 len
+= mmu_info(buffer
+ len
);
496 len
+= smp_info(buffer
+ len
);