1d670bd4fSSam Ravnborg /* 2d670bd4fSSam Ravnborg * linux/arch/sparc/kernel/setup.c 3d670bd4fSSam Ravnborg * 4d670bd4fSSam Ravnborg * Copyright (C) 1995 David S. Miller (davem@caip.rutgers.edu) 5d670bd4fSSam Ravnborg * Copyright (C) 2000 Anton Blanchard (anton@samba.org) 6d670bd4fSSam Ravnborg */ 7d670bd4fSSam Ravnborg 8d670bd4fSSam Ravnborg #include <linux/errno.h> 9d670bd4fSSam Ravnborg #include <linux/sched.h> 10d670bd4fSSam Ravnborg #include <linux/kernel.h> 11d670bd4fSSam Ravnborg #include <linux/mm.h> 12d670bd4fSSam Ravnborg #include <linux/stddef.h> 13d670bd4fSSam Ravnborg #include <linux/unistd.h> 14d670bd4fSSam Ravnborg #include <linux/ptrace.h> 15d670bd4fSSam Ravnborg #include <linux/slab.h> 16d670bd4fSSam Ravnborg #include <linux/initrd.h> 17d670bd4fSSam Ravnborg #include <asm/smp.h> 18d670bd4fSSam Ravnborg #include <linux/user.h> 19d670bd4fSSam Ravnborg #include <linux/screen_info.h> 20d670bd4fSSam Ravnborg #include <linux/delay.h> 21d670bd4fSSam Ravnborg #include <linux/fs.h> 22d670bd4fSSam Ravnborg #include <linux/seq_file.h> 23d670bd4fSSam Ravnborg #include <linux/syscalls.h> 24d670bd4fSSam Ravnborg #include <linux/kdev_t.h> 25d670bd4fSSam Ravnborg #include <linux/major.h> 26d670bd4fSSam Ravnborg #include <linux/string.h> 27d670bd4fSSam Ravnborg #include <linux/init.h> 28d670bd4fSSam Ravnborg #include <linux/interrupt.h> 29d670bd4fSSam Ravnborg #include <linux/console.h> 30d670bd4fSSam Ravnborg #include <linux/spinlock.h> 31d670bd4fSSam Ravnborg #include <linux/root_dev.h> 32d670bd4fSSam Ravnborg #include <linux/cpu.h> 33d670bd4fSSam Ravnborg #include <linux/kdebug.h> 347b64db60SPaul Gortmaker #include <linux/export.h> 35d670bd4fSSam Ravnborg 36d670bd4fSSam Ravnborg #include <asm/system.h> 37d670bd4fSSam Ravnborg #include <asm/io.h> 38d670bd4fSSam Ravnborg #include <asm/processor.h> 39d670bd4fSSam Ravnborg #include <asm/oplib.h> 40d670bd4fSSam Ravnborg #include <asm/page.h> 41d670bd4fSSam Ravnborg #include <asm/pgtable.h> 42d670bd4fSSam Ravnborg #include <asm/traps.h> 43d670bd4fSSam Ravnborg #include <asm/vaddrs.h> 44d670bd4fSSam Ravnborg #include <asm/mbus.h> 45d670bd4fSSam Ravnborg #include <asm/idprom.h> 46d670bd4fSSam Ravnborg #include <asm/machines.h> 47d670bd4fSSam Ravnborg #include <asm/cpudata.h> 48d670bd4fSSam Ravnborg #include <asm/setup.h> 49d670bd4fSSam Ravnborg 5053ae3419SSam Ravnborg #include "kernel.h" 5153ae3419SSam Ravnborg 52d670bd4fSSam Ravnborg struct screen_info screen_info = { 53d670bd4fSSam Ravnborg 0, 0, /* orig-x, orig-y */ 54d670bd4fSSam Ravnborg 0, /* unused */ 55d670bd4fSSam Ravnborg 0, /* orig-video-page */ 56d670bd4fSSam Ravnborg 0, /* orig-video-mode */ 57d670bd4fSSam Ravnborg 128, /* orig-video-cols */ 58d670bd4fSSam Ravnborg 0,0,0, /* ega_ax, ega_bx, ega_cx */ 59d670bd4fSSam Ravnborg 54, /* orig-video-lines */ 60d670bd4fSSam Ravnborg 0, /* orig-video-isVGA */ 61d670bd4fSSam Ravnborg 16 /* orig-video-points */ 62d670bd4fSSam Ravnborg }; 63d670bd4fSSam Ravnborg 64d670bd4fSSam Ravnborg /* Typing sync at the prom prompt calls the function pointed to by 65d670bd4fSSam Ravnborg * romvec->pv_synchook which I set to the following function. 66d670bd4fSSam Ravnborg * This should sync all filesystems and return, for now it just 67d670bd4fSSam Ravnborg * prints out pretty messages and returns. 68d670bd4fSSam Ravnborg */ 69d670bd4fSSam Ravnborg 70d670bd4fSSam Ravnborg extern unsigned long trapbase; 71d670bd4fSSam Ravnborg 72d670bd4fSSam Ravnborg /* Pretty sick eh? */ 73d670bd4fSSam Ravnborg static void prom_sync_me(void) 74d670bd4fSSam Ravnborg { 75d670bd4fSSam Ravnborg unsigned long prom_tbr, flags; 76d670bd4fSSam Ravnborg 77d670bd4fSSam Ravnborg /* XXX Badly broken. FIX! - Anton */ 78d670bd4fSSam Ravnborg local_irq_save(flags); 79d670bd4fSSam Ravnborg __asm__ __volatile__("rd %%tbr, %0\n\t" : "=r" (prom_tbr)); 80d670bd4fSSam Ravnborg __asm__ __volatile__("wr %0, 0x0, %%tbr\n\t" 81d670bd4fSSam Ravnborg "nop\n\t" 82d670bd4fSSam Ravnborg "nop\n\t" 83d670bd4fSSam Ravnborg "nop\n\t" : : "r" (&trapbase)); 84d670bd4fSSam Ravnborg 85d670bd4fSSam Ravnborg prom_printf("PROM SYNC COMMAND...\n"); 867bf02ea2SDavid Rientjes show_free_areas(0); 87d670bd4fSSam Ravnborg if(current->pid != 0) { 88d670bd4fSSam Ravnborg local_irq_enable(); 89d670bd4fSSam Ravnborg sys_sync(); 90d670bd4fSSam Ravnborg local_irq_disable(); 91d670bd4fSSam Ravnborg } 92d670bd4fSSam Ravnborg prom_printf("Returning to prom\n"); 93d670bd4fSSam Ravnborg 94d670bd4fSSam Ravnborg __asm__ __volatile__("wr %0, 0x0, %%tbr\n\t" 95d670bd4fSSam Ravnborg "nop\n\t" 96d670bd4fSSam Ravnborg "nop\n\t" 97d670bd4fSSam Ravnborg "nop\n\t" : : "r" (prom_tbr)); 98d670bd4fSSam Ravnborg local_irq_restore(flags); 99d670bd4fSSam Ravnborg } 100d670bd4fSSam Ravnborg 101d670bd4fSSam Ravnborg static unsigned int boot_flags __initdata = 0; 102d670bd4fSSam Ravnborg #define BOOTME_DEBUG 0x1 103d670bd4fSSam Ravnborg 104d670bd4fSSam Ravnborg /* Exported for mm/init.c:paging_init. */ 105d670bd4fSSam Ravnborg unsigned long cmdline_memory_size __initdata = 0; 106d670bd4fSSam Ravnborg 1075fcafb7aSDaniel Hellstrom /* which CPU booted us (0xff = not set) */ 1085fcafb7aSDaniel Hellstrom unsigned char boot_cpu_id = 0xff; /* 0xff will make it into DATA section... */ 1095fcafb7aSDaniel Hellstrom unsigned char boot_cpu_id4; /* boot_cpu_id << 2 */ 1105fcafb7aSDaniel Hellstrom 111d670bd4fSSam Ravnborg static void 112d670bd4fSSam Ravnborg prom_console_write(struct console *con, const char *s, unsigned n) 113d670bd4fSSam Ravnborg { 114d670bd4fSSam Ravnborg prom_write(s, n); 115d670bd4fSSam Ravnborg } 116d670bd4fSSam Ravnborg 1177671fa22SSam Ravnborg static struct console prom_early_console = { 1187671fa22SSam Ravnborg .name = "earlyprom", 119d670bd4fSSam Ravnborg .write = prom_console_write, 1207671fa22SSam Ravnborg .flags = CON_PRINTBUFFER | CON_BOOT, 121d670bd4fSSam Ravnborg .index = -1, 122d670bd4fSSam Ravnborg }; 123d670bd4fSSam Ravnborg 124d670bd4fSSam Ravnborg /* 125d670bd4fSSam Ravnborg * Process kernel command line switches that are specific to the 126d670bd4fSSam Ravnborg * SPARC or that require special low-level processing. 127d670bd4fSSam Ravnborg */ 128d670bd4fSSam Ravnborg static void __init process_switch(char c) 129d670bd4fSSam Ravnborg { 130d670bd4fSSam Ravnborg switch (c) { 131d670bd4fSSam Ravnborg case 'd': 132d670bd4fSSam Ravnborg boot_flags |= BOOTME_DEBUG; 133d670bd4fSSam Ravnborg break; 134d670bd4fSSam Ravnborg case 's': 135d670bd4fSSam Ravnborg break; 136d670bd4fSSam Ravnborg case 'h': 137d670bd4fSSam Ravnborg prom_printf("boot_flags_init: Halt!\n"); 138d670bd4fSSam Ravnborg prom_halt(); 139d670bd4fSSam Ravnborg break; 140d670bd4fSSam Ravnborg case 'p': 14111032c17SDavid S. Miller prom_early_console.flags &= ~CON_BOOT; 142d670bd4fSSam Ravnborg break; 143d670bd4fSSam Ravnborg default: 144d670bd4fSSam Ravnborg printk("Unknown boot switch (-%c)\n", c); 145d670bd4fSSam Ravnborg break; 146d670bd4fSSam Ravnborg } 147d670bd4fSSam Ravnborg } 148d670bd4fSSam Ravnborg 149d670bd4fSSam Ravnborg static void __init boot_flags_init(char *commands) 150d670bd4fSSam Ravnborg { 151d670bd4fSSam Ravnborg while (*commands) { 152d670bd4fSSam Ravnborg /* Move to the start of the next "argument". */ 153d670bd4fSSam Ravnborg while (*commands && *commands == ' ') 154d670bd4fSSam Ravnborg commands++; 155d670bd4fSSam Ravnborg 156d670bd4fSSam Ravnborg /* Process any command switches, otherwise skip it. */ 157d670bd4fSSam Ravnborg if (*commands == '\0') 158d670bd4fSSam Ravnborg break; 159d670bd4fSSam Ravnborg if (*commands == '-') { 160d670bd4fSSam Ravnborg commands++; 161d670bd4fSSam Ravnborg while (*commands && *commands != ' ') 162d670bd4fSSam Ravnborg process_switch(*commands++); 163d670bd4fSSam Ravnborg continue; 164d670bd4fSSam Ravnborg } 165d670bd4fSSam Ravnborg if (!strncmp(commands, "mem=", 4)) { 166d670bd4fSSam Ravnborg /* 167d670bd4fSSam Ravnborg * "mem=XXX[kKmM] overrides the PROM-reported 168d670bd4fSSam Ravnborg * memory size. 169d670bd4fSSam Ravnborg */ 170d670bd4fSSam Ravnborg cmdline_memory_size = simple_strtoul(commands + 4, 171d670bd4fSSam Ravnborg &commands, 0); 172d670bd4fSSam Ravnborg if (*commands == 'K' || *commands == 'k') { 173d670bd4fSSam Ravnborg cmdline_memory_size <<= 10; 174d670bd4fSSam Ravnborg commands++; 175d670bd4fSSam Ravnborg } else if (*commands=='M' || *commands=='m') { 176d670bd4fSSam Ravnborg cmdline_memory_size <<= 20; 177d670bd4fSSam Ravnborg commands++; 178d670bd4fSSam Ravnborg } 179d670bd4fSSam Ravnborg } 180d670bd4fSSam Ravnborg while (*commands && *commands != ' ') 181d670bd4fSSam Ravnborg commands++; 182d670bd4fSSam Ravnborg } 183d670bd4fSSam Ravnborg } 184d670bd4fSSam Ravnborg 185d670bd4fSSam Ravnborg /* This routine will in the future do all the nasty prom stuff 186d670bd4fSSam Ravnborg * to probe for the mmu type and its parameters, etc. This will 187d670bd4fSSam Ravnborg * also be where SMP things happen. 188d670bd4fSSam Ravnborg */ 189d670bd4fSSam Ravnborg 190d670bd4fSSam Ravnborg extern void sun4c_probe_vac(void); 191d670bd4fSSam Ravnborg 192d670bd4fSSam Ravnborg extern unsigned short root_flags; 193d670bd4fSSam Ravnborg extern unsigned short root_dev; 194d670bd4fSSam Ravnborg extern unsigned short ram_flags; 195d670bd4fSSam Ravnborg #define RAMDISK_IMAGE_START_MASK 0x07FF 196d670bd4fSSam Ravnborg #define RAMDISK_PROMPT_FLAG 0x8000 197d670bd4fSSam Ravnborg #define RAMDISK_LOAD_FLAG 0x4000 198d670bd4fSSam Ravnborg 199d670bd4fSSam Ravnborg extern int root_mountflags; 200d670bd4fSSam Ravnborg 201d670bd4fSSam Ravnborg char reboot_command[COMMAND_LINE_SIZE]; 2026943f3daSSam Ravnborg 203d670bd4fSSam Ravnborg enum sparc_cpu sparc_cpu_model; 2046943f3daSSam Ravnborg EXPORT_SYMBOL(sparc_cpu_model); 205d670bd4fSSam Ravnborg 206d670bd4fSSam Ravnborg struct tt_entry *sparc_ttable; 207d670bd4fSSam Ravnborg 208d670bd4fSSam Ravnborg struct pt_regs fake_swapper_regs; 209d670bd4fSSam Ravnborg 210d670bd4fSSam Ravnborg void __init setup_arch(char **cmdline_p) 211d670bd4fSSam Ravnborg { 212d670bd4fSSam Ravnborg int i; 213d670bd4fSSam Ravnborg unsigned long highest_paddr; 214d670bd4fSSam Ravnborg 215e405ae76SSam Ravnborg sparc_ttable = (struct tt_entry *) &trapbase; 216d670bd4fSSam Ravnborg 217d670bd4fSSam Ravnborg /* Initialize PROM console and command line. */ 218d670bd4fSSam Ravnborg *cmdline_p = prom_getbootargs(); 219d670bd4fSSam Ravnborg strcpy(boot_command_line, *cmdline_p); 220d670bd4fSSam Ravnborg parse_early_param(); 221d670bd4fSSam Ravnborg 2227671fa22SSam Ravnborg boot_flags_init(*cmdline_p); 2237671fa22SSam Ravnborg 2247671fa22SSam Ravnborg register_console(&prom_early_console); 2257671fa22SSam Ravnborg 226d670bd4fSSam Ravnborg /* Set sparc_cpu_model */ 227d670bd4fSSam Ravnborg sparc_cpu_model = sun_unknown; 228b7afdb7eSSam Ravnborg if (!strcmp(&cputypval[0], "sun4 ")) 229d670bd4fSSam Ravnborg sparc_cpu_model = sun4; 230b7afdb7eSSam Ravnborg if (!strcmp(&cputypval[0], "sun4c")) 231d670bd4fSSam Ravnborg sparc_cpu_model = sun4c; 232b7afdb7eSSam Ravnborg if (!strcmp(&cputypval[0], "sun4m")) 233d670bd4fSSam Ravnborg sparc_cpu_model = sun4m; 234b7afdb7eSSam Ravnborg if (!strcmp(&cputypval[0], "sun4s")) 235d670bd4fSSam Ravnborg sparc_cpu_model = sun4m; /* CP-1200 with PROM 2.30 -E */ 236b7afdb7eSSam Ravnborg if (!strcmp(&cputypval[0], "sun4d")) 237d670bd4fSSam Ravnborg sparc_cpu_model = sun4d; 238b7afdb7eSSam Ravnborg if (!strcmp(&cputypval[0], "sun4e")) 239d670bd4fSSam Ravnborg sparc_cpu_model = sun4e; 240b7afdb7eSSam Ravnborg if (!strcmp(&cputypval[0], "sun4u")) 241d670bd4fSSam Ravnborg sparc_cpu_model = sun4u; 242b7afdb7eSSam Ravnborg if (!strncmp(&cputypval[0], "leon" , 4)) 2430fd7ef1fSKonrad Eisele sparc_cpu_model = sparc_leon; 244d670bd4fSSam Ravnborg 245d670bd4fSSam Ravnborg printk("ARCH: "); 246d670bd4fSSam Ravnborg switch(sparc_cpu_model) { 247d670bd4fSSam Ravnborg case sun4: 248d670bd4fSSam Ravnborg printk("SUN4\n"); 249d670bd4fSSam Ravnborg break; 250d670bd4fSSam Ravnborg case sun4c: 251d670bd4fSSam Ravnborg printk("SUN4C\n"); 252d670bd4fSSam Ravnborg break; 253d670bd4fSSam Ravnborg case sun4m: 254d670bd4fSSam Ravnborg printk("SUN4M\n"); 255d670bd4fSSam Ravnborg break; 256d670bd4fSSam Ravnborg case sun4d: 257d670bd4fSSam Ravnborg printk("SUN4D\n"); 258d670bd4fSSam Ravnborg break; 259d670bd4fSSam Ravnborg case sun4e: 260d670bd4fSSam Ravnborg printk("SUN4E\n"); 261d670bd4fSSam Ravnborg break; 262d670bd4fSSam Ravnborg case sun4u: 263d670bd4fSSam Ravnborg printk("SUN4U\n"); 264d670bd4fSSam Ravnborg break; 2650fd7ef1fSKonrad Eisele case sparc_leon: 2660fd7ef1fSKonrad Eisele printk("LEON\n"); 2670fd7ef1fSKonrad Eisele break; 268d670bd4fSSam Ravnborg default: 269d670bd4fSSam Ravnborg printk("UNKNOWN!\n"); 270d670bd4fSSam Ravnborg break; 2716cb79b3fSJoe Perches } 272d670bd4fSSam Ravnborg 273d670bd4fSSam Ravnborg #ifdef CONFIG_DUMMY_CONSOLE 274d670bd4fSSam Ravnborg conswitchp = &dummy_con; 275d670bd4fSSam Ravnborg #endif 276d670bd4fSSam Ravnborg 277d670bd4fSSam Ravnborg idprom_init(); 278d670bd4fSSam Ravnborg if (ARCH_SUN4C) 279d670bd4fSSam Ravnborg sun4c_probe_vac(); 280d670bd4fSSam Ravnborg load_mmu(); 281d670bd4fSSam Ravnborg 282d670bd4fSSam Ravnborg phys_base = 0xffffffffUL; 283d670bd4fSSam Ravnborg highest_paddr = 0UL; 284d670bd4fSSam Ravnborg for (i = 0; sp_banks[i].num_bytes != 0; i++) { 285d670bd4fSSam Ravnborg unsigned long top; 286d670bd4fSSam Ravnborg 287d670bd4fSSam Ravnborg if (sp_banks[i].base_addr < phys_base) 288d670bd4fSSam Ravnborg phys_base = sp_banks[i].base_addr; 289d670bd4fSSam Ravnborg top = sp_banks[i].base_addr + 290d670bd4fSSam Ravnborg sp_banks[i].num_bytes; 291d670bd4fSSam Ravnborg if (highest_paddr < top) 292d670bd4fSSam Ravnborg highest_paddr = top; 293d670bd4fSSam Ravnborg } 294d670bd4fSSam Ravnborg pfn_base = phys_base >> PAGE_SHIFT; 295d670bd4fSSam Ravnborg 296d670bd4fSSam Ravnborg if (!root_flags) 297d670bd4fSSam Ravnborg root_mountflags &= ~MS_RDONLY; 298d670bd4fSSam Ravnborg ROOT_DEV = old_decode_dev(root_dev); 299d670bd4fSSam Ravnborg #ifdef CONFIG_BLK_DEV_RAM 300d670bd4fSSam Ravnborg rd_image_start = ram_flags & RAMDISK_IMAGE_START_MASK; 301d670bd4fSSam Ravnborg rd_prompt = ((ram_flags & RAMDISK_PROMPT_FLAG) != 0); 302d670bd4fSSam Ravnborg rd_doload = ((ram_flags & RAMDISK_LOAD_FLAG) != 0); 303d670bd4fSSam Ravnborg #endif 304d670bd4fSSam Ravnborg 305d670bd4fSSam Ravnborg prom_setsync(prom_sync_me); 306d670bd4fSSam Ravnborg 307d670bd4fSSam Ravnborg if((boot_flags&BOOTME_DEBUG) && (linux_dbvec!=0) && 308d670bd4fSSam Ravnborg ((*(short *)linux_dbvec) != -1)) { 309d670bd4fSSam Ravnborg printk("Booted under KADB. Syncing trap table.\n"); 310d670bd4fSSam Ravnborg (*(linux_dbvec->teach_debugger))(); 311d670bd4fSSam Ravnborg } 312d670bd4fSSam Ravnborg 313d670bd4fSSam Ravnborg init_mm.context = (unsigned long) NO_CONTEXT; 314d670bd4fSSam Ravnborg init_task.thread.kregs = &fake_swapper_regs; 315d670bd4fSSam Ravnborg 316d670bd4fSSam Ravnborg paging_init(); 317d670bd4fSSam Ravnborg 318d670bd4fSSam Ravnborg smp_setup_cpu_possible_map(); 319d670bd4fSSam Ravnborg } 320d670bd4fSSam Ravnborg 321d670bd4fSSam Ravnborg extern int stop_a_enabled; 322d670bd4fSSam Ravnborg 323d670bd4fSSam Ravnborg void sun_do_break(void) 324d670bd4fSSam Ravnborg { 325d670bd4fSSam Ravnborg if (!stop_a_enabled) 326d670bd4fSSam Ravnborg return; 327d670bd4fSSam Ravnborg 328d670bd4fSSam Ravnborg printk("\n"); 329d670bd4fSSam Ravnborg flush_user_windows(); 330d670bd4fSSam Ravnborg 331d670bd4fSSam Ravnborg prom_cmdline(); 332d670bd4fSSam Ravnborg } 3336943f3daSSam Ravnborg EXPORT_SYMBOL(sun_do_break); 334d670bd4fSSam Ravnborg 335d670bd4fSSam Ravnborg int stop_a_enabled = 1; 336d670bd4fSSam Ravnborg 337d670bd4fSSam Ravnborg static int __init topology_init(void) 338d670bd4fSSam Ravnborg { 339d670bd4fSSam Ravnborg int i, ncpus, err; 340d670bd4fSSam Ravnborg 341d670bd4fSSam Ravnborg /* Count the number of physically present processors in 342d670bd4fSSam Ravnborg * the machine, even on uniprocessor, so that /proc/cpuinfo 343d670bd4fSSam Ravnborg * output is consistent with 2.4.x 344d670bd4fSSam Ravnborg */ 345d670bd4fSSam Ravnborg ncpus = 0; 346d670bd4fSSam Ravnborg while (!cpu_find_by_instance(ncpus, NULL, NULL)) 347d670bd4fSSam Ravnborg ncpus++; 348d670bd4fSSam Ravnborg ncpus_probed = ncpus; 349d670bd4fSSam Ravnborg 350d670bd4fSSam Ravnborg err = 0; 351d670bd4fSSam Ravnborg for_each_online_cpu(i) { 352d670bd4fSSam Ravnborg struct cpu *p = kzalloc(sizeof(*p), GFP_KERNEL); 353d670bd4fSSam Ravnborg if (!p) 354d670bd4fSSam Ravnborg err = -ENOMEM; 355d670bd4fSSam Ravnborg else 356d670bd4fSSam Ravnborg register_cpu(p, i); 357d670bd4fSSam Ravnborg } 358d670bd4fSSam Ravnborg 359d670bd4fSSam Ravnborg return err; 360d670bd4fSSam Ravnborg } 361d670bd4fSSam Ravnborg 362d670bd4fSSam Ravnborg subsys_initcall(topology_init); 363