1 /* 2 * Copyright (C) 2007-2009 Michal Simek <monstr@monstr.eu> 3 * Copyright (C) 2007-2009 PetaLogix 4 * Copyright (C) 2006 Atmark Techno, Inc. 5 * 6 * This file is subject to the terms and conditions of the GNU General Public 7 * License. See the file "COPYING" in the main directory of this archive 8 * for more details. 9 */ 10 11 #include <linux/init.h> 12 #include <linux/clocksource.h> 13 #include <linux/string.h> 14 #include <linux/seq_file.h> 15 #include <linux/cpu.h> 16 #include <linux/initrd.h> 17 #include <linux/console.h> 18 #include <linux/debugfs.h> 19 #include <linux/of_fdt.h> 20 21 #include <asm/setup.h> 22 #include <asm/sections.h> 23 #include <asm/page.h> 24 #include <linux/io.h> 25 #include <linux/bug.h> 26 #include <linux/param.h> 27 #include <linux/pci.h> 28 #include <linux/cache.h> 29 #include <linux/of_platform.h> 30 #include <linux/dma-mapping.h> 31 #include <asm/cacheflush.h> 32 #include <asm/entry.h> 33 #include <asm/cpuinfo.h> 34 35 #include <asm/prom.h> 36 #include <asm/pgtable.h> 37 38 DEFINE_PER_CPU(unsigned int, KSP); /* Saved kernel stack pointer */ 39 DEFINE_PER_CPU(unsigned int, KM); /* Kernel/user mode */ 40 DEFINE_PER_CPU(unsigned int, ENTRY_SP); /* Saved SP on kernel entry */ 41 DEFINE_PER_CPU(unsigned int, R11_SAVE); /* Temp variable for entry */ 42 DEFINE_PER_CPU(unsigned int, CURRENT_SAVE); /* Saved current pointer */ 43 44 unsigned int boot_cpuid; 45 /* 46 * Placed cmd_line to .data section because can be initialized from 47 * ASM code. Default position is BSS section which is cleared 48 * in machine_early_init(). 49 */ 50 char cmd_line[COMMAND_LINE_SIZE] __attribute__ ((section(".data"))); 51 52 void __init setup_arch(char **cmdline_p) 53 { 54 *cmdline_p = boot_command_line; 55 56 console_verbose(); 57 58 unflatten_device_tree(); 59 60 setup_cpuinfo(); 61 62 microblaze_cache_init(); 63 64 setup_memory(); 65 66 #ifdef CONFIG_EARLY_PRINTK 67 /* remap early console to virtual address */ 68 remap_early_printk(); 69 #endif 70 71 xilinx_pci_init(); 72 73 #ifdef CONFIG_VT 74 #if defined(CONFIG_XILINX_CONSOLE) 75 conswitchp = &xil_con; 76 #elif defined(CONFIG_DUMMY_CONSOLE) 77 conswitchp = &dummy_con; 78 #endif 79 #endif 80 } 81 82 #ifdef CONFIG_MTD_UCLINUX 83 /* Handle both romfs and cramfs types, without generating unnecessary 84 code (ie no point checking for CRAMFS if it's not even enabled) */ 85 inline unsigned get_romfs_len(unsigned *addr) 86 { 87 #ifdef CONFIG_ROMFS_FS 88 if (memcmp(&addr[0], "-rom1fs-", 8) == 0) /* romfs */ 89 return be32_to_cpu(addr[2]); 90 #endif 91 92 #ifdef CONFIG_CRAMFS 93 if (addr[0] == le32_to_cpu(0x28cd3d45)) /* cramfs */ 94 return le32_to_cpu(addr[1]); 95 #endif 96 return 0; 97 } 98 #endif /* CONFIG_MTD_UCLINUX_EBSS */ 99 100 unsigned long kernel_tlb; 101 102 void __init machine_early_init(const char *cmdline, unsigned int ram, 103 unsigned int fdt, unsigned int msr, unsigned int tlb0, 104 unsigned int tlb1) 105 { 106 unsigned long *src, *dst; 107 unsigned int offset = 0; 108 109 /* If CONFIG_MTD_UCLINUX is defined, assume ROMFS is at the 110 * end of kernel. There are two position which we want to check. 111 * The first is __init_end and the second __bss_start. 112 */ 113 #ifdef CONFIG_MTD_UCLINUX 114 int romfs_size; 115 unsigned int romfs_base; 116 char *old_klimit = klimit; 117 118 romfs_base = (ram ? ram : (unsigned int)&__init_end); 119 romfs_size = PAGE_ALIGN(get_romfs_len((unsigned *)romfs_base)); 120 if (!romfs_size) { 121 romfs_base = (unsigned int)&__bss_start; 122 romfs_size = PAGE_ALIGN(get_romfs_len((unsigned *)romfs_base)); 123 } 124 125 /* Move ROMFS out of BSS before clearing it */ 126 if (romfs_size > 0) { 127 memmove(&__bss_stop, (int *)romfs_base, romfs_size); 128 klimit += romfs_size; 129 } 130 #endif 131 132 /* clearing bss section */ 133 memset(__bss_start, 0, __bss_stop-__bss_start); 134 memset(_ssbss, 0, _esbss-_ssbss); 135 136 lockdep_init(); 137 138 /* initialize device tree for usage in early_printk */ 139 early_init_devtree((void *)_fdt_start); 140 141 #ifdef CONFIG_EARLY_PRINTK 142 setup_early_printk(NULL); 143 #endif 144 145 /* setup kernel_tlb after BSS cleaning 146 * Maybe worth to move to asm code */ 147 kernel_tlb = tlb0 + tlb1; 148 /* printk("TLB1 0x%08x, TLB0 0x%08x, tlb 0x%x\n", tlb0, 149 tlb1, kernel_tlb); */ 150 151 pr_info("Ramdisk addr 0x%08x, ", ram); 152 if (fdt) 153 pr_info("FDT at 0x%08x\n", fdt); 154 else 155 pr_info("Compiled-in FDT at 0x%08x\n", 156 (unsigned int)_fdt_start); 157 158 #ifdef CONFIG_MTD_UCLINUX 159 pr_info("Found romfs @ 0x%08x (0x%08x)\n", 160 romfs_base, romfs_size); 161 pr_info("#### klimit %p ####\n", old_klimit); 162 BUG_ON(romfs_size < 0); /* What else can we do? */ 163 164 pr_info("Moved 0x%08x bytes from 0x%08x to 0x%08x\n", 165 romfs_size, romfs_base, (unsigned)&__bss_stop); 166 167 pr_info("New klimit: 0x%08x\n", (unsigned)klimit); 168 #endif 169 170 #if CONFIG_XILINX_MICROBLAZE0_USE_MSR_INSTR 171 if (msr) { 172 pr_info("!!!Your kernel has setup MSR instruction but "); 173 pr_cont("CPU don't have it %x\n", msr); 174 } 175 #else 176 if (!msr) { 177 pr_info("!!!Your kernel not setup MSR instruction but "); 178 pr_cont"CPU have it %x\n", msr); 179 } 180 #endif 181 182 /* Do not copy reset vectors. offset = 0x2 means skip the first 183 * two instructions. dst is pointer to MB vectors which are placed 184 * in block ram. If you want to copy reset vector setup offset to 0x0 */ 185 #if !CONFIG_MANUAL_RESET_VECTOR 186 offset = 0x2; 187 #endif 188 dst = (unsigned long *) (offset * sizeof(u32)); 189 for (src = __ivt_start + offset; src < __ivt_end; src++, dst++) 190 *dst = *src; 191 192 /* Initialize global data */ 193 per_cpu(KM, 0) = 0x1; /* We start in kernel mode */ 194 per_cpu(CURRENT_SAVE, 0) = (unsigned long)current; 195 } 196 197 void __init time_init(void) 198 { 199 clocksource_of_init(); 200 } 201 202 #ifdef CONFIG_DEBUG_FS 203 struct dentry *of_debugfs_root; 204 205 static int microblaze_debugfs_init(void) 206 { 207 of_debugfs_root = debugfs_create_dir("microblaze", NULL); 208 209 return of_debugfs_root == NULL; 210 } 211 arch_initcall(microblaze_debugfs_init); 212 213 # ifdef CONFIG_MMU 214 static int __init debugfs_tlb(void) 215 { 216 struct dentry *d; 217 218 if (!of_debugfs_root) 219 return -ENODEV; 220 221 d = debugfs_create_u32("tlb_skip", S_IRUGO, of_debugfs_root, &tlb_skip); 222 if (!d) 223 return -ENOMEM; 224 225 return 0; 226 } 227 device_initcall(debugfs_tlb); 228 # endif 229 #endif 230 231 static int dflt_bus_notify(struct notifier_block *nb, 232 unsigned long action, void *data) 233 { 234 struct device *dev = data; 235 236 /* We are only intereted in device addition */ 237 if (action != BUS_NOTIFY_ADD_DEVICE) 238 return 0; 239 240 set_dma_ops(dev, &dma_direct_ops); 241 242 return NOTIFY_DONE; 243 } 244 245 static struct notifier_block dflt_plat_bus_notifier = { 246 .notifier_call = dflt_bus_notify, 247 .priority = INT_MAX, 248 }; 249 250 static int __init setup_bus_notifier(void) 251 { 252 bus_register_notifier(&platform_bus_type, &dflt_plat_bus_notifier); 253 254 return 0; 255 } 256 257 arch_initcall(setup_bus_notifier); 258