^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1) // SPDX-License-Identifier: GPL-2.0
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2) /*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3) * linux/arch/sparc/kernel/setup.c
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4) *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5) * Copyright (C) 1995 David S. Miller (davem@caip.rutgers.edu)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6) * Copyright (C) 2000 Anton Blanchard (anton@samba.org)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 7) */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 8)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 9) #include <linux/errno.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 10) #include <linux/sched.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 11) #include <linux/kernel.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 12) #include <linux/mm.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 13) #include <linux/stddef.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 14) #include <linux/unistd.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 15) #include <linux/ptrace.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 16) #include <linux/slab.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 17) #include <linux/initrd.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 18) #include <asm/smp.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 19) #include <linux/user.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 20) #include <linux/screen_info.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 21) #include <linux/delay.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 22) #include <linux/fs.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 23) #include <linux/seq_file.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 24) #include <linux/syscalls.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 25) #include <linux/kdev_t.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 26) #include <linux/major.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 27) #include <linux/string.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 28) #include <linux/init.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 29) #include <linux/interrupt.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 30) #include <linux/console.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 31) #include <linux/spinlock.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 32) #include <linux/root_dev.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 33) #include <linux/cpu.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 34) #include <linux/kdebug.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 35) #include <linux/export.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 36) #include <linux/start_kernel.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 37) #include <uapi/linux/mount.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 38)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 39) #include <asm/io.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 40) #include <asm/processor.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 41) #include <asm/oplib.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 42) #include <asm/page.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 43) #include <asm/traps.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 44) #include <asm/vaddrs.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 45) #include <asm/mbus.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 46) #include <asm/idprom.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 47) #include <asm/cpudata.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 48) #include <asm/setup.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 49) #include <asm/cacheflush.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 50) #include <asm/sections.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 51)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 52) #include "kernel.h"
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 53)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 54) struct screen_info screen_info = {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 55) 0, 0, /* orig-x, orig-y */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 56) 0, /* unused */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 57) 0, /* orig-video-page */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 58) 0, /* orig-video-mode */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 59) 128, /* orig-video-cols */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 60) 0,0,0, /* ega_ax, ega_bx, ega_cx */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 61) 54, /* orig-video-lines */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 62) 0, /* orig-video-isVGA */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 63) 16 /* orig-video-points */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 64) };
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 65)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 66) /* Typing sync at the prom prompt calls the function pointed to by
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 67) * romvec->pv_synchook which I set to the following function.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 68) * This should sync all filesystems and return, for now it just
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 69) * prints out pretty messages and returns.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 70) */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 71)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 72) /* Pretty sick eh? */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 73) static void prom_sync_me(void)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 74) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 75) unsigned long prom_tbr, flags;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 76)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 77) /* XXX Badly broken. FIX! - Anton */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 78) local_irq_save(flags);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 79) __asm__ __volatile__("rd %%tbr, %0\n\t" : "=r" (prom_tbr));
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 80) __asm__ __volatile__("wr %0, 0x0, %%tbr\n\t"
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 81) "nop\n\t"
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 82) "nop\n\t"
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 83) "nop\n\t" : : "r" (&trapbase));
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 84)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 85) prom_printf("PROM SYNC COMMAND...\n");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 86) show_free_areas(0, NULL);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 87) if (!is_idle_task(current)) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 88) local_irq_enable();
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 89) ksys_sync();
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 90) local_irq_disable();
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 91) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 92) prom_printf("Returning to prom\n");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 93)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 94) __asm__ __volatile__("wr %0, 0x0, %%tbr\n\t"
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 95) "nop\n\t"
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 96) "nop\n\t"
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 97) "nop\n\t" : : "r" (prom_tbr));
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 98) local_irq_restore(flags);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 99) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 100)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 101) static unsigned int boot_flags __initdata = 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 102) #define BOOTME_DEBUG 0x1
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 103)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 104) /* Exported for mm/init.c:paging_init. */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 105) unsigned long cmdline_memory_size __initdata = 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 106)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 107) /* which CPU booted us (0xff = not set) */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 108) unsigned char boot_cpu_id = 0xff; /* 0xff will make it into DATA section... */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 109)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 110) static void
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 111) prom_console_write(struct console *con, const char *s, unsigned int n)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 112) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 113) prom_write(s, n);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 114) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 115)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 116) static struct console prom_early_console = {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 117) .name = "earlyprom",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 118) .write = prom_console_write,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 119) .flags = CON_PRINTBUFFER | CON_BOOT,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 120) .index = -1,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 121) };
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 122)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 123) /*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 124) * Process kernel command line switches that are specific to the
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 125) * SPARC or that require special low-level processing.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 126) */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 127) static void __init process_switch(char c)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 128) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 129) switch (c) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 130) case 'd':
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 131) boot_flags |= BOOTME_DEBUG;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 132) break;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 133) case 's':
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 134) break;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 135) case 'h':
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 136) prom_printf("boot_flags_init: Halt!\n");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 137) prom_halt();
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 138) break;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 139) case 'p':
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 140) prom_early_console.flags &= ~CON_BOOT;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 141) break;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 142) default:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 143) printk("Unknown boot switch (-%c)\n", c);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 144) break;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 145) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 146) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 147)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 148) static void __init boot_flags_init(char *commands)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 149) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 150) while (*commands) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 151) /* Move to the start of the next "argument". */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 152) while (*commands == ' ')
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 153) commands++;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 154)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 155) /* Process any command switches, otherwise skip it. */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 156) if (*commands == '\0')
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 157) break;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 158) if (*commands == '-') {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 159) commands++;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 160) while (*commands && *commands != ' ')
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 161) process_switch(*commands++);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 162) continue;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 163) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 164) if (!strncmp(commands, "mem=", 4)) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 165) /*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 166) * "mem=XXX[kKmM] overrides the PROM-reported
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 167) * memory size.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 168) */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 169) cmdline_memory_size = simple_strtoul(commands + 4,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 170) &commands, 0);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 171) if (*commands == 'K' || *commands == 'k') {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 172) cmdline_memory_size <<= 10;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 173) commands++;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 174) } else if (*commands=='M' || *commands=='m') {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 175) cmdline_memory_size <<= 20;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 176) commands++;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 177) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 178) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 179) while (*commands && *commands != ' ')
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 180) commands++;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 181) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 182) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 183)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 184) extern unsigned short root_flags;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 185) extern unsigned short root_dev;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 186) extern unsigned short ram_flags;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 187) #define RAMDISK_IMAGE_START_MASK 0x07FF
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 188) #define RAMDISK_PROMPT_FLAG 0x8000
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 189) #define RAMDISK_LOAD_FLAG 0x4000
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 190)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 191) extern int root_mountflags;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 192)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 193) char reboot_command[COMMAND_LINE_SIZE];
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 194)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 195) struct cpuid_patch_entry {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 196) unsigned int addr;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 197) unsigned int sun4d[3];
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 198) unsigned int leon[3];
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 199) };
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 200) extern struct cpuid_patch_entry __cpuid_patch, __cpuid_patch_end;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 201)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 202) static void __init per_cpu_patch(void)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 203) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 204) struct cpuid_patch_entry *p;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 205)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 206) if (sparc_cpu_model == sun4m) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 207) /* Nothing to do, this is what the unpatched code
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 208) * targets.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 209) */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 210) return;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 211) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 212)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 213) p = &__cpuid_patch;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 214) while (p < &__cpuid_patch_end) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 215) unsigned long addr = p->addr;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 216) unsigned int *insns;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 217)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 218) switch (sparc_cpu_model) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 219) case sun4d:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 220) insns = &p->sun4d[0];
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 221) break;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 222)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 223) case sparc_leon:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 224) insns = &p->leon[0];
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 225) break;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 226) default:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 227) prom_printf("Unknown cpu type, halting.\n");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 228) prom_halt();
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 229) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 230) *(unsigned int *) (addr + 0) = insns[0];
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 231) flushi(addr + 0);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 232) *(unsigned int *) (addr + 4) = insns[1];
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 233) flushi(addr + 4);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 234) *(unsigned int *) (addr + 8) = insns[2];
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 235) flushi(addr + 8);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 236)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 237) p++;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 238) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 239) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 240)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 241) struct leon_1insn_patch_entry {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 242) unsigned int addr;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 243) unsigned int insn;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 244) };
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 245)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 246) enum sparc_cpu sparc_cpu_model;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 247) EXPORT_SYMBOL(sparc_cpu_model);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 248)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 249) static __init void leon_patch(void)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 250) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 251) struct leon_1insn_patch_entry *start = (void *)__leon_1insn_patch;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 252) struct leon_1insn_patch_entry *end = (void *)__leon_1insn_patch_end;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 253)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 254) /* Default instruction is leon - no patching */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 255) if (sparc_cpu_model == sparc_leon)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 256) return;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 257)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 258) while (start < end) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 259) unsigned long addr = start->addr;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 260)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 261) *(unsigned int *)(addr) = start->insn;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 262) flushi(addr);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 263)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 264) start++;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 265) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 266) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 267)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 268) struct tt_entry *sparc_ttable;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 269) static struct pt_regs fake_swapper_regs;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 270)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 271) /* Called from head_32.S - before we have setup anything
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 272) * in the kernel. Be very careful with what you do here.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 273) */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 274) void __init sparc32_start_kernel(struct linux_romvec *rp)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 275) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 276) prom_init(rp);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 277)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 278) /* Set sparc_cpu_model */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 279) sparc_cpu_model = sun_unknown;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 280) if (!strcmp(&cputypval[0], "sun4m"))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 281) sparc_cpu_model = sun4m;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 282) if (!strcmp(&cputypval[0], "sun4s"))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 283) sparc_cpu_model = sun4m; /* CP-1200 with PROM 2.30 -E */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 284) if (!strcmp(&cputypval[0], "sun4d"))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 285) sparc_cpu_model = sun4d;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 286) if (!strcmp(&cputypval[0], "sun4e"))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 287) sparc_cpu_model = sun4e;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 288) if (!strcmp(&cputypval[0], "sun4u"))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 289) sparc_cpu_model = sun4u;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 290) if (!strncmp(&cputypval[0], "leon" , 4))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 291) sparc_cpu_model = sparc_leon;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 292)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 293) leon_patch();
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 294) start_kernel();
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 295) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 296)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 297) void __init setup_arch(char **cmdline_p)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 298) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 299) int i;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 300) unsigned long highest_paddr;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 301)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 302) sparc_ttable = &trapbase;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 303)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 304) /* Initialize PROM console and command line. */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 305) *cmdline_p = prom_getbootargs();
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 306) strlcpy(boot_command_line, *cmdline_p, COMMAND_LINE_SIZE);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 307) parse_early_param();
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 308)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 309) boot_flags_init(*cmdline_p);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 310)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 311) register_console(&prom_early_console);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 312)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 313) switch(sparc_cpu_model) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 314) case sun4m:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 315) pr_info("ARCH: SUN4M\n");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 316) break;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 317) case sun4d:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 318) pr_info("ARCH: SUN4D\n");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 319) break;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 320) case sun4e:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 321) pr_info("ARCH: SUN4E\n");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 322) break;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 323) case sun4u:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 324) pr_info("ARCH: SUN4U\n");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 325) break;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 326) case sparc_leon:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 327) pr_info("ARCH: LEON\n");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 328) break;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 329) default:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 330) pr_info("ARCH: UNKNOWN!\n");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 331) break;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 332) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 333)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 334) idprom_init();
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 335) load_mmu();
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 336)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 337) phys_base = 0xffffffffUL;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 338) highest_paddr = 0UL;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 339) for (i = 0; sp_banks[i].num_bytes != 0; i++) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 340) unsigned long top;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 341)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 342) if (sp_banks[i].base_addr < phys_base)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 343) phys_base = sp_banks[i].base_addr;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 344) top = sp_banks[i].base_addr +
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 345) sp_banks[i].num_bytes;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 346) if (highest_paddr < top)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 347) highest_paddr = top;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 348) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 349) pfn_base = phys_base >> PAGE_SHIFT;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 350)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 351) if (!root_flags)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 352) root_mountflags &= ~MS_RDONLY;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 353) ROOT_DEV = old_decode_dev(root_dev);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 354) #ifdef CONFIG_BLK_DEV_RAM
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 355) rd_image_start = ram_flags & RAMDISK_IMAGE_START_MASK;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 356) #endif
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 357)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 358) prom_setsync(prom_sync_me);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 359)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 360) if((boot_flags & BOOTME_DEBUG) && (linux_dbvec != NULL) &&
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 361) ((*(short *)linux_dbvec) != -1)) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 362) printk("Booted under KADB. Syncing trap table.\n");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 363) (*(linux_dbvec->teach_debugger))();
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 364) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 365)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 366) init_task.thread.kregs = &fake_swapper_regs;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 367)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 368) /* Run-time patch instructions to match the cpu model */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 369) per_cpu_patch();
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 370)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 371) paging_init();
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 372)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 373) smp_setup_cpu_possible_map();
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 374) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 375)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 376) extern int stop_a_enabled;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 377)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 378) void sun_do_break(void)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 379) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 380) if (!stop_a_enabled)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 381) return;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 382)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 383) printk("\n");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 384) flush_user_windows();
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 385)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 386) prom_cmdline();
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 387) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 388) EXPORT_SYMBOL(sun_do_break);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 389)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 390) int stop_a_enabled = 1;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 391)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 392) static int __init topology_init(void)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 393) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 394) int i, ncpus, err;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 395)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 396) /* Count the number of physically present processors in
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 397) * the machine, even on uniprocessor, so that /proc/cpuinfo
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 398) * output is consistent with 2.4.x
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 399) */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 400) ncpus = 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 401) while (!cpu_find_by_instance(ncpus, NULL, NULL))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 402) ncpus++;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 403) ncpus_probed = ncpus;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 404)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 405) err = 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 406) for_each_online_cpu(i) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 407) struct cpu *p = kzalloc(sizeof(*p), GFP_KERNEL);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 408) if (!p)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 409) err = -ENOMEM;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 410) else
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 411) register_cpu(p, i);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 412) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 413)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 414) return err;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 415) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 416)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 417) subsys_initcall(topology_init);