setup_32.c 8.1 KB

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