setup_32.c 7.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329
  1. /*
  2. * Common prep/pmac/chrp boot and setup code.
  3. */
  4. #include <linux/module.h>
  5. #include <linux/string.h>
  6. #include <linux/sched.h>
  7. #include <linux/init.h>
  8. #include <linux/kernel.h>
  9. #include <linux/reboot.h>
  10. #include <linux/delay.h>
  11. #include <linux/initrd.h>
  12. #include <linux/tty.h>
  13. #include <linux/seq_file.h>
  14. #include <linux/root_dev.h>
  15. #include <linux/cpu.h>
  16. #include <linux/console.h>
  17. #include <linux/memblock.h>
  18. #include <asm/io.h>
  19. #include <asm/prom.h>
  20. #include <asm/processor.h>
  21. #include <asm/pgtable.h>
  22. #include <asm/setup.h>
  23. #include <asm/smp.h>
  24. #include <asm/elf.h>
  25. #include <asm/cputable.h>
  26. #include <asm/bootx.h>
  27. #include <asm/btext.h>
  28. #include <asm/machdep.h>
  29. #include <asm/uaccess.h>
  30. #include <asm/pmac_feature.h>
  31. #include <asm/sections.h>
  32. #include <asm/nvram.h>
  33. #include <asm/xmon.h>
  34. #include <asm/time.h>
  35. #include <asm/serial.h>
  36. #include <asm/udbg.h>
  37. #include <asm/mmu_context.h>
  38. #include <asm/epapr_hcalls.h>
  39. #include <asm/code-patching.h>
  40. #define DBG(fmt...)
  41. extern void bootx_init(unsigned long r4, unsigned long phys);
  42. int boot_cpuid_phys;
  43. EXPORT_SYMBOL_GPL(boot_cpuid_phys);
  44. int smp_hw_index[NR_CPUS];
  45. unsigned long ISA_DMA_THRESHOLD;
  46. unsigned int DMA_MODE_READ;
  47. unsigned int DMA_MODE_WRITE;
  48. /*
  49. * These are used in binfmt_elf.c to put aux entries on the stack
  50. * for each elf executable being started.
  51. */
  52. int dcache_bsize;
  53. int icache_bsize;
  54. int ucache_bsize;
  55. /*
  56. * We're called here very early in the boot. We determine the machine
  57. * type and call the appropriate low-level setup functions.
  58. * -- Cort <cort@fsmlabs.com>
  59. *
  60. * Note that the kernel may be running at an address which is different
  61. * from the address that it was linked at, so we must use RELOC/PTRRELOC
  62. * to access static data (including strings). -- paulus
  63. */
  64. notrace unsigned long __init early_init(unsigned long dt_ptr)
  65. {
  66. unsigned long offset = reloc_offset();
  67. struct cpu_spec *spec;
  68. /* First zero the BSS -- use memset_io, some platforms don't have
  69. * caches on yet */
  70. memset_io((void __iomem *)PTRRELOC(&__bss_start), 0,
  71. __bss_stop - __bss_start);
  72. /*
  73. * Identify the CPU type and fix up code sections
  74. * that depend on which cpu we have.
  75. */
  76. spec = identify_cpu(offset, mfspr(SPRN_PVR));
  77. do_feature_fixups(spec->cpu_features,
  78. PTRRELOC(&__start___ftr_fixup),
  79. PTRRELOC(&__stop___ftr_fixup));
  80. do_feature_fixups(spec->mmu_features,
  81. PTRRELOC(&__start___mmu_ftr_fixup),
  82. PTRRELOC(&__stop___mmu_ftr_fixup));
  83. do_lwsync_fixups(spec->cpu_features,
  84. PTRRELOC(&__start___lwsync_fixup),
  85. PTRRELOC(&__stop___lwsync_fixup));
  86. do_final_fixups();
  87. return KERNELBASE + offset;
  88. }
  89. /*
  90. * Find out what kind of machine we're on and save any data we need
  91. * from the early boot process (devtree is copied on pmac by prom_init()).
  92. * This is called very early on the boot process, after a minimal
  93. * MMU environment has been set up but before MMU_init is called.
  94. */
  95. extern unsigned int memset_nocache_branch; /* Insn to be replaced by NOP */
  96. notrace void __init machine_init(u64 dt_ptr)
  97. {
  98. lockdep_init();
  99. /* Enable early debugging if any specified (see udbg.h) */
  100. udbg_early_init();
  101. patch_instruction((unsigned int *)&memcpy, PPC_INST_NOP);
  102. patch_instruction(&memset_nocache_branch, PPC_INST_NOP);
  103. /* Do some early initialization based on the flat device tree */
  104. early_init_devtree(__va(dt_ptr));
  105. epapr_paravirt_early_init();
  106. early_init_mmu();
  107. probe_machine();
  108. setup_kdump_trampoline();
  109. #ifdef CONFIG_6xx
  110. if (cpu_has_feature(CPU_FTR_CAN_DOZE) ||
  111. cpu_has_feature(CPU_FTR_CAN_NAP))
  112. ppc_md.power_save = ppc6xx_idle;
  113. #endif
  114. #ifdef CONFIG_E500
  115. if (cpu_has_feature(CPU_FTR_CAN_DOZE) ||
  116. cpu_has_feature(CPU_FTR_CAN_NAP))
  117. ppc_md.power_save = e500_idle;
  118. #endif
  119. if (ppc_md.progress)
  120. ppc_md.progress("id mach(): done", 0x200);
  121. }
  122. /* Checks "l2cr=xxxx" command-line option */
  123. int __init ppc_setup_l2cr(char *str)
  124. {
  125. if (cpu_has_feature(CPU_FTR_L2CR)) {
  126. unsigned long val = simple_strtoul(str, NULL, 0);
  127. printk(KERN_INFO "l2cr set to %lx\n", val);
  128. _set_L2CR(0); /* force invalidate by disable cache */
  129. _set_L2CR(val); /* and enable it */
  130. }
  131. return 1;
  132. }
  133. __setup("l2cr=", ppc_setup_l2cr);
  134. /* Checks "l3cr=xxxx" command-line option */
  135. int __init ppc_setup_l3cr(char *str)
  136. {
  137. if (cpu_has_feature(CPU_FTR_L3CR)) {
  138. unsigned long val = simple_strtoul(str, NULL, 0);
  139. printk(KERN_INFO "l3cr set to %lx\n", val);
  140. _set_L3CR(val); /* and enable it */
  141. }
  142. return 1;
  143. }
  144. __setup("l3cr=", ppc_setup_l3cr);
  145. #ifdef CONFIG_GENERIC_NVRAM
  146. /* Generic nvram hooks used by drivers/char/gen_nvram.c */
  147. unsigned char nvram_read_byte(int addr)
  148. {
  149. if (ppc_md.nvram_read_val)
  150. return ppc_md.nvram_read_val(addr);
  151. return 0xff;
  152. }
  153. EXPORT_SYMBOL(nvram_read_byte);
  154. void nvram_write_byte(unsigned char val, int addr)
  155. {
  156. if (ppc_md.nvram_write_val)
  157. ppc_md.nvram_write_val(addr, val);
  158. }
  159. EXPORT_SYMBOL(nvram_write_byte);
  160. ssize_t nvram_get_size(void)
  161. {
  162. if (ppc_md.nvram_size)
  163. return ppc_md.nvram_size();
  164. return -1;
  165. }
  166. EXPORT_SYMBOL(nvram_get_size);
  167. void nvram_sync(void)
  168. {
  169. if (ppc_md.nvram_sync)
  170. ppc_md.nvram_sync();
  171. }
  172. EXPORT_SYMBOL(nvram_sync);
  173. #endif /* CONFIG_NVRAM */
  174. int __init ppc_init(void)
  175. {
  176. /* clear the progress line */
  177. if (ppc_md.progress)
  178. ppc_md.progress(" ", 0xffff);
  179. /* call platform init */
  180. if (ppc_md.init != NULL) {
  181. ppc_md.init();
  182. }
  183. return 0;
  184. }
  185. arch_initcall(ppc_init);
  186. static void __init irqstack_early_init(void)
  187. {
  188. unsigned int i;
  189. /* interrupt stacks must be in lowmem, we get that for free on ppc32
  190. * as the memblock is limited to lowmem by default */
  191. for_each_possible_cpu(i) {
  192. softirq_ctx[i] = (struct thread_info *)
  193. __va(memblock_alloc(THREAD_SIZE, THREAD_SIZE));
  194. hardirq_ctx[i] = (struct thread_info *)
  195. __va(memblock_alloc(THREAD_SIZE, THREAD_SIZE));
  196. }
  197. }
  198. #if defined(CONFIG_BOOKE) || defined(CONFIG_40x)
  199. static void __init exc_lvl_early_init(void)
  200. {
  201. unsigned int i, hw_cpu;
  202. /* interrupt stacks must be in lowmem, we get that for free on ppc32
  203. * as the memblock is limited to lowmem by MEMBLOCK_REAL_LIMIT */
  204. for_each_possible_cpu(i) {
  205. #ifdef CONFIG_SMP
  206. hw_cpu = get_hard_smp_processor_id(i);
  207. #else
  208. hw_cpu = 0;
  209. #endif
  210. critirq_ctx[hw_cpu] = (struct thread_info *)
  211. __va(memblock_alloc(THREAD_SIZE, THREAD_SIZE));
  212. #ifdef CONFIG_BOOKE
  213. dbgirq_ctx[hw_cpu] = (struct thread_info *)
  214. __va(memblock_alloc(THREAD_SIZE, THREAD_SIZE));
  215. mcheckirq_ctx[hw_cpu] = (struct thread_info *)
  216. __va(memblock_alloc(THREAD_SIZE, THREAD_SIZE));
  217. #endif
  218. }
  219. }
  220. #else
  221. #define exc_lvl_early_init()
  222. #endif
  223. /* Warning, IO base is not yet inited */
  224. void __init setup_arch(char **cmdline_p)
  225. {
  226. *cmdline_p = boot_command_line;
  227. /* so udelay does something sensible, assume <= 1000 bogomips */
  228. loops_per_jiffy = 500000000 / HZ;
  229. unflatten_device_tree();
  230. check_for_initrd();
  231. if (ppc_md.init_early)
  232. ppc_md.init_early();
  233. find_legacy_serial_ports();
  234. smp_setup_cpu_maps();
  235. /* Register early console */
  236. register_early_udbg_console();
  237. xmon_setup();
  238. /*
  239. * Set cache line size based on type of cpu as a default.
  240. * Systems with OF can look in the properties on the cpu node(s)
  241. * for a possibly more accurate value.
  242. */
  243. dcache_bsize = cur_cpu_spec->dcache_bsize;
  244. icache_bsize = cur_cpu_spec->icache_bsize;
  245. ucache_bsize = 0;
  246. if (cpu_has_feature(CPU_FTR_UNIFIED_ID_CACHE))
  247. ucache_bsize = icache_bsize = dcache_bsize;
  248. if (ppc_md.panic)
  249. setup_panic();
  250. init_mm.start_code = (unsigned long)_stext;
  251. init_mm.end_code = (unsigned long) _etext;
  252. init_mm.end_data = (unsigned long) _edata;
  253. init_mm.brk = klimit;
  254. exc_lvl_early_init();
  255. irqstack_early_init();
  256. initmem_init();
  257. if ( ppc_md.progress ) ppc_md.progress("setup_arch: initmem", 0x3eab);
  258. #ifdef CONFIG_DUMMY_CONSOLE
  259. conswitchp = &dummy_con;
  260. #endif
  261. if (ppc_md.setup_arch)
  262. ppc_md.setup_arch();
  263. if ( ppc_md.progress ) ppc_md.progress("arch: exit", 0x3eab);
  264. paging_init();
  265. /* Initialize the MMU context management stuff */
  266. mmu_context_init();
  267. }