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/seq_file.h> 1570d64ceaSPaul Mackerras #include <linux/root_dev.h> 1670d64ceaSPaul Mackerras #include <linux/cpu.h> 1770d64ceaSPaul Mackerras #include <linux/console.h> 1895f72d1eSYinghai Lu #include <linux/memblock.h> 1970d64ceaSPaul Mackerras 2070d64ceaSPaul Mackerras #include <asm/io.h> 2170d64ceaSPaul Mackerras #include <asm/prom.h> 2270d64ceaSPaul Mackerras #include <asm/processor.h> 2370d64ceaSPaul Mackerras #include <asm/pgtable.h> 2470d64ceaSPaul Mackerras #include <asm/setup.h> 2570d64ceaSPaul Mackerras #include <asm/smp.h> 2670d64ceaSPaul Mackerras #include <asm/elf.h> 2770d64ceaSPaul Mackerras #include <asm/cputable.h> 2870d64ceaSPaul Mackerras #include <asm/bootx.h> 2970d64ceaSPaul Mackerras #include <asm/btext.h> 3070d64ceaSPaul Mackerras #include <asm/machdep.h> 3170d64ceaSPaul Mackerras #include <asm/uaccess.h> 3270d64ceaSPaul Mackerras #include <asm/pmac_feature.h> 3370d64ceaSPaul Mackerras #include <asm/sections.h> 3470d64ceaSPaul Mackerras #include <asm/nvram.h> 3570d64ceaSPaul Mackerras #include <asm/xmon.h> 366d7f58b0SKumar Gala #include <asm/time.h> 37463ce0e1SBenjamin Herrenschmidt #include <asm/serial.h> 3851d3082fSBenjamin Herrenschmidt #include <asm/udbg.h> 391cd03890SLEROY Christophe #include <asm/code-patching.h> 4070d64ceaSPaul Mackerras 4103501dabSPaul Mackerras #define DBG(fmt...) 4203501dabSPaul Mackerras 4370d64ceaSPaul Mackerras extern void bootx_init(unsigned long r4, unsigned long phys); 4470d64ceaSPaul Mackerras 4580579e1fSPaul Mackerras int boot_cpuid_phys; 469974eec2SAndrew Gabbasov EXPORT_SYMBOL_GPL(boot_cpuid_phys); 4780579e1fSPaul Mackerras 4813a9801eSNathan Lynch int smp_hw_index[NR_CPUS]; 4913a9801eSNathan Lynch 5070d64ceaSPaul Mackerras unsigned long ISA_DMA_THRESHOLD; 5170d64ceaSPaul Mackerras unsigned int DMA_MODE_READ; 5270d64ceaSPaul Mackerras unsigned int DMA_MODE_WRITE; 5370d64ceaSPaul Mackerras 5470d64ceaSPaul Mackerras /* 5570d64ceaSPaul Mackerras * These are used in binfmt_elf.c to put aux entries on the stack 5670d64ceaSPaul Mackerras * for each elf executable being started. 5770d64ceaSPaul Mackerras */ 5870d64ceaSPaul Mackerras int dcache_bsize; 5970d64ceaSPaul Mackerras int icache_bsize; 6070d64ceaSPaul Mackerras int ucache_bsize; 6170d64ceaSPaul Mackerras 6270d64ceaSPaul Mackerras /* 63bd7c93ccSBenjamin Herrenschmidt * We're called here very early in the boot. 6470d64ceaSPaul Mackerras * 6570d64ceaSPaul Mackerras * Note that the kernel may be running at an address which is different 6670d64ceaSPaul Mackerras * from the address that it was linked at, so we must use RELOC/PTRRELOC 6770d64ceaSPaul Mackerras * to access static data (including strings). -- paulus 6870d64ceaSPaul Mackerras */ 694e491d14SSteven Rostedt notrace unsigned long __init early_init(unsigned long dt_ptr) 7070d64ceaSPaul Mackerras { 7170d64ceaSPaul Mackerras unsigned long offset = reloc_offset(); 7270d64ceaSPaul Mackerras 73dd184343SPaul Mackerras /* First zero the BSS -- use memset_io, some platforms don't have 74dd184343SPaul Mackerras * caches on yet */ 75556b09c8SMark A. Greer memset_io((void __iomem *)PTRRELOC(&__bss_start), 0, 76556b09c8SMark A. Greer __bss_stop - __bss_start); 77dd184343SPaul Mackerras 7870d64ceaSPaul Mackerras /* 7970d64ceaSPaul Mackerras * Identify the CPU type and fix up code sections 8070d64ceaSPaul Mackerras * that depend on which cpu we have. 8170d64ceaSPaul Mackerras */ 829402c684SBenjamin Herrenschmidt identify_cpu(offset, mfspr(SPRN_PVR)); 8342c4aaadSBenjamin Herrenschmidt 849402c684SBenjamin Herrenschmidt apply_feature_fixups(); 85d715e433SAnton Blanchard 8670d64ceaSPaul Mackerras return KERNELBASE + offset; 8770d64ceaSPaul Mackerras } 8870d64ceaSPaul Mackerras 8970d64ceaSPaul Mackerras 9070d64ceaSPaul Mackerras /* 91bd7c93ccSBenjamin Herrenschmidt * This is run before start_kernel(), the kernel has been relocated 92bd7c93ccSBenjamin Herrenschmidt * and we are running with enough of the MMU enabled to have our 93bd7c93ccSBenjamin Herrenschmidt * proper kernel virtual addresses 94bd7c93ccSBenjamin Herrenschmidt * 9570d64ceaSPaul Mackerras * Find out what kind of machine we're on and save any data we need 9670d64ceaSPaul Mackerras * from the early boot process (devtree is copied on pmac by prom_init()). 9770d64ceaSPaul Mackerras * This is called very early on the boot process, after a minimal 9870d64ceaSPaul Mackerras * MMU environment has been set up but before MMU_init is called. 9970d64ceaSPaul Mackerras */ 100400c47d8SLEROY Christophe extern unsigned int memset_nocache_branch; /* Insn to be replaced by NOP */ 101400c47d8SLEROY Christophe 1026dece0ebSScott Wood notrace void __init machine_init(u64 dt_ptr) 10370d64ceaSPaul Mackerras { 104719c91ccSDavid Gibson /* Enable early debugging if any specified (see udbg.h) */ 105719c91ccSDavid Gibson udbg_early_init(); 10651d3082fSBenjamin Herrenschmidt 1071cd03890SLEROY Christophe patch_instruction((unsigned int *)&memcpy, PPC_INST_NOP); 108400c47d8SLEROY Christophe patch_instruction(&memset_nocache_branch, PPC_INST_NOP); 1091cd03890SLEROY Christophe 11051d3082fSBenjamin Herrenschmidt /* Do some early initialization based on the flat device tree */ 11170d64ceaSPaul Mackerras early_init_devtree(__va(dt_ptr)); 11270d64ceaSPaul Mackerras 11391b191c7SDave Kleikamp early_init_mmu(); 11491b191c7SDave Kleikamp 115f8f50b1bSDale Farnsworth setup_kdump_trampoline(); 11670d64ceaSPaul Mackerras } 11770d64ceaSPaul Mackerras 11870d64ceaSPaul Mackerras /* Checks "l2cr=xxxx" command-line option */ 11970d64ceaSPaul Mackerras int __init ppc_setup_l2cr(char *str) 12070d64ceaSPaul Mackerras { 12170d64ceaSPaul Mackerras if (cpu_has_feature(CPU_FTR_L2CR)) { 12270d64ceaSPaul Mackerras unsigned long val = simple_strtoul(str, NULL, 0); 12370d64ceaSPaul Mackerras printk(KERN_INFO "l2cr set to %lx\n", val); 12470d64ceaSPaul Mackerras _set_L2CR(0); /* force invalidate by disable cache */ 12570d64ceaSPaul Mackerras _set_L2CR(val); /* and enable it */ 12670d64ceaSPaul Mackerras } 12770d64ceaSPaul Mackerras return 1; 12870d64ceaSPaul Mackerras } 12970d64ceaSPaul Mackerras __setup("l2cr=", ppc_setup_l2cr); 13070d64ceaSPaul Mackerras 131a78bfbfcSRobert Brose /* Checks "l3cr=xxxx" command-line option */ 132a78bfbfcSRobert Brose int __init ppc_setup_l3cr(char *str) 133a78bfbfcSRobert Brose { 134a78bfbfcSRobert Brose if (cpu_has_feature(CPU_FTR_L3CR)) { 135a78bfbfcSRobert Brose unsigned long val = simple_strtoul(str, NULL, 0); 136a78bfbfcSRobert Brose printk(KERN_INFO "l3cr set to %lx\n", val); 137a78bfbfcSRobert Brose _set_L3CR(val); /* and enable it */ 138a78bfbfcSRobert Brose } 139a78bfbfcSRobert Brose return 1; 140a78bfbfcSRobert Brose } 141a78bfbfcSRobert Brose __setup("l3cr=", ppc_setup_l3cr); 142a78bfbfcSRobert Brose 14370d64ceaSPaul Mackerras #ifdef CONFIG_GENERIC_NVRAM 14470d64ceaSPaul Mackerras 14570d64ceaSPaul Mackerras /* Generic nvram hooks used by drivers/char/gen_nvram.c */ 14670d64ceaSPaul Mackerras unsigned char nvram_read_byte(int addr) 14770d64ceaSPaul Mackerras { 14870d64ceaSPaul Mackerras if (ppc_md.nvram_read_val) 14970d64ceaSPaul Mackerras return ppc_md.nvram_read_val(addr); 15070d64ceaSPaul Mackerras return 0xff; 15170d64ceaSPaul Mackerras } 15270d64ceaSPaul Mackerras EXPORT_SYMBOL(nvram_read_byte); 15370d64ceaSPaul Mackerras 15470d64ceaSPaul Mackerras void nvram_write_byte(unsigned char val, int addr) 15570d64ceaSPaul Mackerras { 15670d64ceaSPaul Mackerras if (ppc_md.nvram_write_val) 15770d64ceaSPaul Mackerras ppc_md.nvram_write_val(addr, val); 15870d64ceaSPaul Mackerras } 15970d64ceaSPaul Mackerras EXPORT_SYMBOL(nvram_write_byte); 16070d64ceaSPaul Mackerras 161d331d830SMartyn Welch ssize_t nvram_get_size(void) 162d331d830SMartyn Welch { 163d331d830SMartyn Welch if (ppc_md.nvram_size) 164d331d830SMartyn Welch return ppc_md.nvram_size(); 165d331d830SMartyn Welch return -1; 166d331d830SMartyn Welch } 167d331d830SMartyn Welch EXPORT_SYMBOL(nvram_get_size); 168d331d830SMartyn Welch 16970d64ceaSPaul Mackerras void nvram_sync(void) 17070d64ceaSPaul Mackerras { 17170d64ceaSPaul Mackerras if (ppc_md.nvram_sync) 17270d64ceaSPaul Mackerras ppc_md.nvram_sync(); 17370d64ceaSPaul Mackerras } 17470d64ceaSPaul Mackerras EXPORT_SYMBOL(nvram_sync); 17570d64ceaSPaul Mackerras 17670d64ceaSPaul Mackerras #endif /* CONFIG_NVRAM */ 17770d64ceaSPaul Mackerras 17870d64ceaSPaul Mackerras int __init ppc_init(void) 17970d64ceaSPaul Mackerras { 18070d64ceaSPaul Mackerras /* clear the progress line */ 1815e41763aSGiuliano Pochini if (ppc_md.progress) 1825e41763aSGiuliano Pochini ppc_md.progress(" ", 0xffff); 18370d64ceaSPaul Mackerras 18470d64ceaSPaul Mackerras /* call platform init */ 18570d64ceaSPaul Mackerras if (ppc_md.init != NULL) { 18670d64ceaSPaul Mackerras ppc_md.init(); 18770d64ceaSPaul Mackerras } 18870d64ceaSPaul Mackerras return 0; 18970d64ceaSPaul Mackerras } 19070d64ceaSPaul Mackerras 19170d64ceaSPaul Mackerras arch_initcall(ppc_init); 19270d64ceaSPaul Mackerras 193*b1923caaSBenjamin Herrenschmidt void __init irqstack_early_init(void) 19485218827SKumar Gala { 19585218827SKumar Gala unsigned int i; 19685218827SKumar Gala 19785218827SKumar Gala /* interrupt stacks must be in lowmem, we get that for free on ppc32 198e63075a3SBenjamin Herrenschmidt * as the memblock is limited to lowmem by default */ 19985218827SKumar Gala for_each_possible_cpu(i) { 20085218827SKumar Gala softirq_ctx[i] = (struct thread_info *) 20195f72d1eSYinghai Lu __va(memblock_alloc(THREAD_SIZE, THREAD_SIZE)); 20285218827SKumar Gala hardirq_ctx[i] = (struct thread_info *) 20395f72d1eSYinghai Lu __va(memblock_alloc(THREAD_SIZE, THREAD_SIZE)); 20485218827SKumar Gala } 20585218827SKumar Gala } 20685218827SKumar Gala 207bcf0b088SKumar Gala #if defined(CONFIG_BOOKE) || defined(CONFIG_40x) 208*b1923caaSBenjamin Herrenschmidt void __init exc_lvl_early_init(void) 209bcf0b088SKumar Gala { 2103e7f45adSDave Kleikamp unsigned int i, hw_cpu; 211bcf0b088SKumar Gala 212bcf0b088SKumar Gala /* interrupt stacks must be in lowmem, we get that for free on ppc32 21395f72d1eSYinghai Lu * as the memblock is limited to lowmem by MEMBLOCK_REAL_LIMIT */ 214bcf0b088SKumar Gala for_each_possible_cpu(i) { 21504a34113SKevin Hao #ifdef CONFIG_SMP 2163e7f45adSDave Kleikamp hw_cpu = get_hard_smp_processor_id(i); 21704a34113SKevin Hao #else 21804a34113SKevin Hao hw_cpu = 0; 21904a34113SKevin Hao #endif 22004a34113SKevin Hao 2213e7f45adSDave Kleikamp critirq_ctx[hw_cpu] = (struct thread_info *) 22295f72d1eSYinghai Lu __va(memblock_alloc(THREAD_SIZE, THREAD_SIZE)); 223bcf0b088SKumar Gala #ifdef CONFIG_BOOKE 2243e7f45adSDave Kleikamp dbgirq_ctx[hw_cpu] = (struct thread_info *) 22595f72d1eSYinghai Lu __va(memblock_alloc(THREAD_SIZE, THREAD_SIZE)); 2263e7f45adSDave Kleikamp mcheckirq_ctx[hw_cpu] = (struct thread_info *) 22795f72d1eSYinghai Lu __va(memblock_alloc(THREAD_SIZE, THREAD_SIZE)); 228bcf0b088SKumar Gala #endif 229bcf0b088SKumar Gala } 230bcf0b088SKumar Gala } 231bcf0b088SKumar Gala #endif 232bcf0b088SKumar Gala 233*b1923caaSBenjamin Herrenschmidt void __init setup_power_save(void) 23456571384SBenjamin Herrenschmidt { 23556571384SBenjamin Herrenschmidt #ifdef CONFIG_6xx 23656571384SBenjamin Herrenschmidt if (cpu_has_feature(CPU_FTR_CAN_DOZE) || 23756571384SBenjamin Herrenschmidt cpu_has_feature(CPU_FTR_CAN_NAP)) 23856571384SBenjamin Herrenschmidt ppc_md.power_save = ppc6xx_idle; 23956571384SBenjamin Herrenschmidt #endif 24056571384SBenjamin Herrenschmidt 24156571384SBenjamin Herrenschmidt #ifdef CONFIG_E500 24256571384SBenjamin Herrenschmidt if (cpu_has_feature(CPU_FTR_CAN_DOZE) || 24356571384SBenjamin Herrenschmidt cpu_has_feature(CPU_FTR_CAN_NAP)) 24456571384SBenjamin Herrenschmidt ppc_md.power_save = e500_idle; 24556571384SBenjamin Herrenschmidt #endif 24656571384SBenjamin Herrenschmidt } 24756571384SBenjamin Herrenschmidt 248*b1923caaSBenjamin Herrenschmidt __init void initialize_cache_info(void) 2498f212cb2SBenjamin Herrenschmidt { 2508f212cb2SBenjamin Herrenschmidt /* 2518f212cb2SBenjamin Herrenschmidt * Set cache line size based on type of cpu as a default. 2528f212cb2SBenjamin Herrenschmidt * Systems with OF can look in the properties on the cpu node(s) 2538f212cb2SBenjamin Herrenschmidt * for a possibly more accurate value. 2548f212cb2SBenjamin Herrenschmidt */ 2558f212cb2SBenjamin Herrenschmidt dcache_bsize = cur_cpu_spec->dcache_bsize; 2568f212cb2SBenjamin Herrenschmidt icache_bsize = cur_cpu_spec->icache_bsize; 2578f212cb2SBenjamin Herrenschmidt ucache_bsize = 0; 2588f212cb2SBenjamin Herrenschmidt if (cpu_has_feature(CPU_FTR_UNIFIED_ID_CACHE)) 2598f212cb2SBenjamin Herrenschmidt ucache_bsize = icache_bsize = dcache_bsize; 2608f212cb2SBenjamin Herrenschmidt } 261