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