170d64ceaSPaul Mackerras /* 270d64ceaSPaul Mackerras * Common prep/pmac/chrp boot and setup code. 370d64ceaSPaul Mackerras */ 470d64ceaSPaul Mackerras 570d64ceaSPaul Mackerras #include <linux/module.h> 670d64ceaSPaul Mackerras #include <linux/string.h> 770d64ceaSPaul Mackerras #include <linux/sched.h> 870d64ceaSPaul Mackerras #include <linux/init.h> 970d64ceaSPaul Mackerras #include <linux/kernel.h> 1070d64ceaSPaul Mackerras #include <linux/reboot.h> 1170d64ceaSPaul Mackerras #include <linux/delay.h> 1270d64ceaSPaul Mackerras #include <linux/initrd.h> 1370d64ceaSPaul Mackerras #include <linux/tty.h> 1470d64ceaSPaul Mackerras #include <linux/bootmem.h> 1570d64ceaSPaul Mackerras #include <linux/seq_file.h> 1670d64ceaSPaul Mackerras #include <linux/root_dev.h> 1770d64ceaSPaul Mackerras #include <linux/cpu.h> 1870d64ceaSPaul Mackerras #include <linux/console.h> 1995f72d1eSYinghai Lu #include <linux/memblock.h> 2070d64ceaSPaul Mackerras 2170d64ceaSPaul Mackerras #include <asm/io.h> 2270d64ceaSPaul Mackerras #include <asm/prom.h> 2370d64ceaSPaul Mackerras #include <asm/processor.h> 2470d64ceaSPaul Mackerras #include <asm/pgtable.h> 2570d64ceaSPaul Mackerras #include <asm/setup.h> 2670d64ceaSPaul Mackerras #include <asm/smp.h> 2770d64ceaSPaul Mackerras #include <asm/elf.h> 2870d64ceaSPaul Mackerras #include <asm/cputable.h> 2970d64ceaSPaul Mackerras #include <asm/bootx.h> 3070d64ceaSPaul Mackerras #include <asm/btext.h> 3170d64ceaSPaul Mackerras #include <asm/machdep.h> 3270d64ceaSPaul Mackerras #include <asm/uaccess.h> 3370d64ceaSPaul Mackerras #include <asm/system.h> 3470d64ceaSPaul Mackerras #include <asm/pmac_feature.h> 3570d64ceaSPaul Mackerras #include <asm/sections.h> 3670d64ceaSPaul Mackerras #include <asm/nvram.h> 3770d64ceaSPaul Mackerras #include <asm/xmon.h> 386d7f58b0SKumar Gala #include <asm/time.h> 39463ce0e1SBenjamin Herrenschmidt #include <asm/serial.h> 4051d3082fSBenjamin Herrenschmidt #include <asm/udbg.h> 4177520351SBenjamin Herrenschmidt #include <asm/mmu_context.h> 4270d64ceaSPaul Mackerras 4366ba135cSStephen Rothwell #include "setup.h" 4466ba135cSStephen Rothwell 4503501dabSPaul Mackerras #define DBG(fmt...) 4603501dabSPaul Mackerras 4770d64ceaSPaul Mackerras extern void bootx_init(unsigned long r4, unsigned long phys); 4870d64ceaSPaul Mackerras 4980579e1fSPaul Mackerras int boot_cpuid; 5080579e1fSPaul Mackerras EXPORT_SYMBOL_GPL(boot_cpuid); 5180579e1fSPaul Mackerras int boot_cpuid_phys; 5280579e1fSPaul Mackerras 5313a9801eSNathan Lynch int smp_hw_index[NR_CPUS]; 5413a9801eSNathan Lynch 5570d64ceaSPaul Mackerras unsigned long ISA_DMA_THRESHOLD; 5670d64ceaSPaul Mackerras unsigned int DMA_MODE_READ; 5770d64ceaSPaul Mackerras unsigned int DMA_MODE_WRITE; 5870d64ceaSPaul Mackerras 5970d64ceaSPaul Mackerras #ifdef CONFIG_VGA_CONSOLE 6070d64ceaSPaul Mackerras unsigned long vgacon_remap_base; 61d003e7a1SMathieu Desnoyers EXPORT_SYMBOL(vgacon_remap_base); 6270d64ceaSPaul Mackerras #endif 6370d64ceaSPaul Mackerras 6470d64ceaSPaul Mackerras /* 6570d64ceaSPaul Mackerras * These are used in binfmt_elf.c to put aux entries on the stack 6670d64ceaSPaul Mackerras * for each elf executable being started. 6770d64ceaSPaul Mackerras */ 6870d64ceaSPaul Mackerras int dcache_bsize; 6970d64ceaSPaul Mackerras int icache_bsize; 7070d64ceaSPaul Mackerras int ucache_bsize; 7170d64ceaSPaul Mackerras 7270d64ceaSPaul Mackerras /* 7370d64ceaSPaul Mackerras * We're called here very early in the boot. We determine the machine 7470d64ceaSPaul Mackerras * type and call the appropriate low-level setup functions. 7570d64ceaSPaul Mackerras * -- Cort <cort@fsmlabs.com> 7670d64ceaSPaul Mackerras * 7770d64ceaSPaul Mackerras * Note that the kernel may be running at an address which is different 7870d64ceaSPaul Mackerras * from the address that it was linked at, so we must use RELOC/PTRRELOC 7970d64ceaSPaul Mackerras * to access static data (including strings). -- paulus 8070d64ceaSPaul Mackerras */ 814e491d14SSteven Rostedt notrace unsigned long __init early_init(unsigned long dt_ptr) 8270d64ceaSPaul Mackerras { 8370d64ceaSPaul Mackerras unsigned long offset = reloc_offset(); 8442c4aaadSBenjamin Herrenschmidt struct cpu_spec *spec; 8570d64ceaSPaul Mackerras 86dd184343SPaul Mackerras /* First zero the BSS -- use memset_io, some platforms don't have 87dd184343SPaul Mackerras * caches on yet */ 88556b09c8SMark A. Greer memset_io((void __iomem *)PTRRELOC(&__bss_start), 0, 89556b09c8SMark A. Greer __bss_stop - __bss_start); 90dd184343SPaul Mackerras 9170d64ceaSPaul Mackerras /* 9270d64ceaSPaul Mackerras * Identify the CPU type and fix up code sections 9370d64ceaSPaul Mackerras * that depend on which cpu we have. 9470d64ceaSPaul Mackerras */ 95974a76f5SPaul Mackerras spec = identify_cpu(offset, mfspr(SPRN_PVR)); 9642c4aaadSBenjamin Herrenschmidt 970909c8c2SBenjamin Herrenschmidt do_feature_fixups(spec->cpu_features, 9842c4aaadSBenjamin Herrenschmidt PTRRELOC(&__start___ftr_fixup), 9942c4aaadSBenjamin Herrenschmidt PTRRELOC(&__stop___ftr_fixup)); 10070d64ceaSPaul Mackerras 1017c03d653SBenjamin Herrenschmidt do_feature_fixups(spec->mmu_features, 1027c03d653SBenjamin Herrenschmidt PTRRELOC(&__start___mmu_ftr_fixup), 1037c03d653SBenjamin Herrenschmidt PTRRELOC(&__stop___mmu_ftr_fixup)); 1047c03d653SBenjamin Herrenschmidt 1052d1b2027SKumar Gala do_lwsync_fixups(spec->cpu_features, 1062d1b2027SKumar Gala PTRRELOC(&__start___lwsync_fixup), 1072d1b2027SKumar Gala PTRRELOC(&__stop___lwsync_fixup)); 1082d1b2027SKumar Gala 10970d64ceaSPaul Mackerras return KERNELBASE + offset; 11070d64ceaSPaul Mackerras } 11170d64ceaSPaul Mackerras 11270d64ceaSPaul Mackerras 11370d64ceaSPaul Mackerras /* 11470d64ceaSPaul Mackerras * Find out what kind of machine we're on and save any data we need 11570d64ceaSPaul Mackerras * from the early boot process (devtree is copied on pmac by prom_init()). 11670d64ceaSPaul Mackerras * This is called very early on the boot process, after a minimal 11770d64ceaSPaul Mackerras * MMU environment has been set up but before MMU_init is called. 11870d64ceaSPaul Mackerras */ 119cd301c7bSSebastian Andrzej Siewior notrace void __init machine_init(unsigned long dt_ptr) 12070d64ceaSPaul Mackerras { 1215d38902cSBenjamin Herrenschmidt lockdep_init(); 1225d38902cSBenjamin Herrenschmidt 123719c91ccSDavid Gibson /* Enable early debugging if any specified (see udbg.h) */ 124719c91ccSDavid Gibson udbg_early_init(); 12551d3082fSBenjamin Herrenschmidt 12651d3082fSBenjamin Herrenschmidt /* Do some early initialization based on the flat device tree */ 12770d64ceaSPaul Mackerras early_init_devtree(__va(dt_ptr)); 12870d64ceaSPaul Mackerras 129e8222502SBenjamin Herrenschmidt probe_machine(); 13035499c01SPaul Mackerras 131f8f50b1bSDale Farnsworth setup_kdump_trampoline(); 132f8f50b1bSDale Farnsworth 13370d64ceaSPaul Mackerras #ifdef CONFIG_6xx 134a0652fc9SPaul Mackerras if (cpu_has_feature(CPU_FTR_CAN_DOZE) || 135a0652fc9SPaul Mackerras cpu_has_feature(CPU_FTR_CAN_NAP)) 13670d64ceaSPaul Mackerras ppc_md.power_save = ppc6xx_idle; 13770d64ceaSPaul Mackerras #endif 13870d64ceaSPaul Mackerras 139fc4033b2SKumar Gala #ifdef CONFIG_E500 140fc4033b2SKumar Gala if (cpu_has_feature(CPU_FTR_CAN_DOZE) || 141fc4033b2SKumar Gala cpu_has_feature(CPU_FTR_CAN_NAP)) 142fc4033b2SKumar Gala ppc_md.power_save = e500_idle; 143fc4033b2SKumar Gala #endif 14470d64ceaSPaul Mackerras if (ppc_md.progress) 14570d64ceaSPaul Mackerras ppc_md.progress("id mach(): done", 0x200); 14670d64ceaSPaul Mackerras } 14770d64ceaSPaul Mackerras 14870d64ceaSPaul Mackerras #ifdef CONFIG_BOOKE_WDT 14970d64ceaSPaul Mackerras /* Checks wdt=x and wdt_period=xx command-line option */ 1504e491d14SSteven Rostedt notrace int __init early_parse_wdt(char *p) 15170d64ceaSPaul Mackerras { 15270d64ceaSPaul Mackerras if (p && strncmp(p, "0", 1) != 0) 15370d64ceaSPaul Mackerras booke_wdt_enabled = 1; 15470d64ceaSPaul Mackerras 15570d64ceaSPaul Mackerras return 0; 15670d64ceaSPaul Mackerras } 15770d64ceaSPaul Mackerras early_param("wdt", early_parse_wdt); 15870d64ceaSPaul Mackerras 15970d64ceaSPaul Mackerras int __init early_parse_wdt_period (char *p) 16070d64ceaSPaul Mackerras { 16170d64ceaSPaul Mackerras if (p) 16270d64ceaSPaul Mackerras booke_wdt_period = simple_strtoul(p, NULL, 0); 16370d64ceaSPaul Mackerras 16470d64ceaSPaul Mackerras return 0; 16570d64ceaSPaul Mackerras } 16670d64ceaSPaul Mackerras early_param("wdt_period", early_parse_wdt_period); 16770d64ceaSPaul Mackerras #endif /* CONFIG_BOOKE_WDT */ 16870d64ceaSPaul Mackerras 16970d64ceaSPaul Mackerras /* Checks "l2cr=xxxx" command-line option */ 17070d64ceaSPaul Mackerras int __init ppc_setup_l2cr(char *str) 17170d64ceaSPaul Mackerras { 17270d64ceaSPaul Mackerras if (cpu_has_feature(CPU_FTR_L2CR)) { 17370d64ceaSPaul Mackerras unsigned long val = simple_strtoul(str, NULL, 0); 17470d64ceaSPaul Mackerras printk(KERN_INFO "l2cr set to %lx\n", val); 17570d64ceaSPaul Mackerras _set_L2CR(0); /* force invalidate by disable cache */ 17670d64ceaSPaul Mackerras _set_L2CR(val); /* and enable it */ 17770d64ceaSPaul Mackerras } 17870d64ceaSPaul Mackerras return 1; 17970d64ceaSPaul Mackerras } 18070d64ceaSPaul Mackerras __setup("l2cr=", ppc_setup_l2cr); 18170d64ceaSPaul Mackerras 182a78bfbfcSRobert Brose /* Checks "l3cr=xxxx" command-line option */ 183a78bfbfcSRobert Brose int __init ppc_setup_l3cr(char *str) 184a78bfbfcSRobert Brose { 185a78bfbfcSRobert Brose if (cpu_has_feature(CPU_FTR_L3CR)) { 186a78bfbfcSRobert Brose unsigned long val = simple_strtoul(str, NULL, 0); 187a78bfbfcSRobert Brose printk(KERN_INFO "l3cr set to %lx\n", val); 188a78bfbfcSRobert Brose _set_L3CR(val); /* and enable it */ 189a78bfbfcSRobert Brose } 190a78bfbfcSRobert Brose return 1; 191a78bfbfcSRobert Brose } 192a78bfbfcSRobert Brose __setup("l3cr=", ppc_setup_l3cr); 193a78bfbfcSRobert Brose 19470d64ceaSPaul Mackerras #ifdef CONFIG_GENERIC_NVRAM 19570d64ceaSPaul Mackerras 19670d64ceaSPaul Mackerras /* Generic nvram hooks used by drivers/char/gen_nvram.c */ 19770d64ceaSPaul Mackerras unsigned char nvram_read_byte(int addr) 19870d64ceaSPaul Mackerras { 19970d64ceaSPaul Mackerras if (ppc_md.nvram_read_val) 20070d64ceaSPaul Mackerras return ppc_md.nvram_read_val(addr); 20170d64ceaSPaul Mackerras return 0xff; 20270d64ceaSPaul Mackerras } 20370d64ceaSPaul Mackerras EXPORT_SYMBOL(nvram_read_byte); 20470d64ceaSPaul Mackerras 20570d64ceaSPaul Mackerras void nvram_write_byte(unsigned char val, int addr) 20670d64ceaSPaul Mackerras { 20770d64ceaSPaul Mackerras if (ppc_md.nvram_write_val) 20870d64ceaSPaul Mackerras ppc_md.nvram_write_val(addr, val); 20970d64ceaSPaul Mackerras } 21070d64ceaSPaul Mackerras EXPORT_SYMBOL(nvram_write_byte); 21170d64ceaSPaul Mackerras 212d331d830SMartyn Welch ssize_t nvram_get_size(void) 213d331d830SMartyn Welch { 214d331d830SMartyn Welch if (ppc_md.nvram_size) 215d331d830SMartyn Welch return ppc_md.nvram_size(); 216d331d830SMartyn Welch return -1; 217d331d830SMartyn Welch } 218d331d830SMartyn Welch EXPORT_SYMBOL(nvram_get_size); 219d331d830SMartyn Welch 22070d64ceaSPaul Mackerras void nvram_sync(void) 22170d64ceaSPaul Mackerras { 22270d64ceaSPaul Mackerras if (ppc_md.nvram_sync) 22370d64ceaSPaul Mackerras ppc_md.nvram_sync(); 22470d64ceaSPaul Mackerras } 22570d64ceaSPaul Mackerras EXPORT_SYMBOL(nvram_sync); 22670d64ceaSPaul Mackerras 22770d64ceaSPaul Mackerras #endif /* CONFIG_NVRAM */ 22870d64ceaSPaul Mackerras 22970d64ceaSPaul Mackerras int __init ppc_init(void) 23070d64ceaSPaul Mackerras { 23170d64ceaSPaul Mackerras /* clear the progress line */ 2325e41763aSGiuliano Pochini if (ppc_md.progress) 2335e41763aSGiuliano Pochini ppc_md.progress(" ", 0xffff); 23470d64ceaSPaul Mackerras 23570d64ceaSPaul Mackerras /* call platform init */ 23670d64ceaSPaul Mackerras if (ppc_md.init != NULL) { 23770d64ceaSPaul Mackerras ppc_md.init(); 23870d64ceaSPaul Mackerras } 23970d64ceaSPaul Mackerras return 0; 24070d64ceaSPaul Mackerras } 24170d64ceaSPaul Mackerras 24270d64ceaSPaul Mackerras arch_initcall(ppc_init); 24370d64ceaSPaul Mackerras 24485218827SKumar Gala static void __init irqstack_early_init(void) 24585218827SKumar Gala { 24685218827SKumar Gala unsigned int i; 24785218827SKumar Gala 24885218827SKumar Gala /* interrupt stacks must be in lowmem, we get that for free on ppc32 24995f72d1eSYinghai Lu * as the memblock is limited to lowmem by MEMBLOCK_REAL_LIMIT */ 25085218827SKumar Gala for_each_possible_cpu(i) { 25185218827SKumar Gala softirq_ctx[i] = (struct thread_info *) 25295f72d1eSYinghai Lu __va(memblock_alloc(THREAD_SIZE, THREAD_SIZE)); 25385218827SKumar Gala hardirq_ctx[i] = (struct thread_info *) 25495f72d1eSYinghai Lu __va(memblock_alloc(THREAD_SIZE, THREAD_SIZE)); 25585218827SKumar Gala } 25685218827SKumar Gala } 25785218827SKumar Gala 258bcf0b088SKumar Gala #if defined(CONFIG_BOOKE) || defined(CONFIG_40x) 259bcf0b088SKumar Gala static void __init exc_lvl_early_init(void) 260bcf0b088SKumar Gala { 261*3e7f45adSDave Kleikamp unsigned int i, hw_cpu; 262bcf0b088SKumar Gala 263bcf0b088SKumar Gala /* interrupt stacks must be in lowmem, we get that for free on ppc32 26495f72d1eSYinghai Lu * as the memblock is limited to lowmem by MEMBLOCK_REAL_LIMIT */ 265bcf0b088SKumar Gala for_each_possible_cpu(i) { 266*3e7f45adSDave Kleikamp hw_cpu = get_hard_smp_processor_id(i); 267*3e7f45adSDave Kleikamp critirq_ctx[hw_cpu] = (struct thread_info *) 26895f72d1eSYinghai Lu __va(memblock_alloc(THREAD_SIZE, THREAD_SIZE)); 269bcf0b088SKumar Gala #ifdef CONFIG_BOOKE 270*3e7f45adSDave Kleikamp dbgirq_ctx[hw_cpu] = (struct thread_info *) 27195f72d1eSYinghai Lu __va(memblock_alloc(THREAD_SIZE, THREAD_SIZE)); 272*3e7f45adSDave Kleikamp mcheckirq_ctx[hw_cpu] = (struct thread_info *) 27395f72d1eSYinghai Lu __va(memblock_alloc(THREAD_SIZE, THREAD_SIZE)); 274bcf0b088SKumar Gala #endif 275bcf0b088SKumar Gala } 276bcf0b088SKumar Gala } 277bcf0b088SKumar Gala #else 278bcf0b088SKumar Gala #define exc_lvl_early_init() 279bcf0b088SKumar Gala #endif 280bcf0b088SKumar Gala 28170d64ceaSPaul Mackerras /* Warning, IO base is not yet inited */ 28270d64ceaSPaul Mackerras void __init setup_arch(char **cmdline_p) 28370d64ceaSPaul Mackerras { 284846f77b0SMichael Ellerman *cmdline_p = cmd_line; 285846f77b0SMichael Ellerman 28670d64ceaSPaul Mackerras /* so udelay does something sensible, assume <= 1000 bogomips */ 28770d64ceaSPaul Mackerras loops_per_jiffy = 500000000 / HZ; 28870d64ceaSPaul Mackerras 28970d64ceaSPaul Mackerras unflatten_device_tree(); 290a82765b6SDavid Woodhouse check_for_initrd(); 291463ce0e1SBenjamin Herrenschmidt 292463ce0e1SBenjamin Herrenschmidt if (ppc_md.init_early) 293463ce0e1SBenjamin Herrenschmidt ppc_md.init_early(); 294463ce0e1SBenjamin Herrenschmidt 295463ce0e1SBenjamin Herrenschmidt find_legacy_serial_ports(); 29670d64ceaSPaul Mackerras 2975ad57078SPaul Mackerras smp_setup_cpu_maps(); 2985ad57078SPaul Mackerras 29951d3082fSBenjamin Herrenschmidt /* Register early console */ 30051d3082fSBenjamin Herrenschmidt register_early_udbg_console(); 30170d64ceaSPaul Mackerras 30247679283SMichael Ellerman xmon_setup(); 30347679283SMichael Ellerman 30470d64ceaSPaul Mackerras /* 30570d64ceaSPaul Mackerras * Set cache line size based on type of cpu as a default. 30670d64ceaSPaul Mackerras * Systems with OF can look in the properties on the cpu node(s) 30770d64ceaSPaul Mackerras * for a possibly more accurate value. 30870d64ceaSPaul Mackerras */ 30970d64ceaSPaul Mackerras dcache_bsize = cur_cpu_spec->dcache_bsize; 31070d64ceaSPaul Mackerras icache_bsize = cur_cpu_spec->icache_bsize; 31170d64ceaSPaul Mackerras ucache_bsize = 0; 3124508dc21SDavid Gibson if (cpu_has_feature(CPU_FTR_UNIFIED_ID_CACHE)) 3134508dc21SDavid Gibson ucache_bsize = icache_bsize = dcache_bsize; 31470d64ceaSPaul Mackerras 31570d64ceaSPaul Mackerras /* reboot on panic */ 31670d64ceaSPaul Mackerras panic_timeout = 180; 31770d64ceaSPaul Mackerras 3187e990266SKumar Gala if (ppc_md.panic) 3197e990266SKumar Gala setup_panic(); 3207e990266SKumar Gala 3214846c5deSKumar Gala init_mm.start_code = (unsigned long)_stext; 32270d64ceaSPaul Mackerras init_mm.end_code = (unsigned long) _etext; 32370d64ceaSPaul Mackerras init_mm.end_data = (unsigned long) _edata; 32449b09853SPaul Mackerras init_mm.brk = klimit; 32570d64ceaSPaul Mackerras 326bcf0b088SKumar Gala exc_lvl_early_init(); 327bcf0b088SKumar Gala 32885218827SKumar Gala irqstack_early_init(); 32985218827SKumar Gala 33070d64ceaSPaul Mackerras /* set up the bootmem stuff with available memory */ 33170d64ceaSPaul Mackerras do_init_bootmem(); 33270d64ceaSPaul Mackerras if ( ppc_md.progress ) ppc_md.progress("setup_arch: bootmem", 0x3eab); 33370d64ceaSPaul Mackerras 33470d64ceaSPaul Mackerras #ifdef CONFIG_DUMMY_CONSOLE 33570d64ceaSPaul Mackerras conswitchp = &dummy_con; 33670d64ceaSPaul Mackerras #endif 33770d64ceaSPaul Mackerras 33838db7e74SGrant Likely if (ppc_md.setup_arch) 33970d64ceaSPaul Mackerras ppc_md.setup_arch(); 34070d64ceaSPaul Mackerras if ( ppc_md.progress ) ppc_md.progress("arch: exit", 0x3eab); 34170d64ceaSPaul Mackerras 34270d64ceaSPaul Mackerras paging_init(); 34377520351SBenjamin Herrenschmidt 34477520351SBenjamin Herrenschmidt /* Initialize the MMU context management stuff */ 34577520351SBenjamin Herrenschmidt mmu_context_init(); 34677520351SBenjamin Herrenschmidt 34770d64ceaSPaul Mackerras } 348