setup.c 7.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324
  1. /*
  2. * arch/sh/kernel/setup.c
  3. *
  4. * This file handles the architecture-dependent parts of initialization
  5. *
  6. * Copyright (C) 1999 Niibe Yutaka
  7. * Copyright (C) 2002 - 2010 Paul Mundt
  8. */
  9. #include <linux/screen_info.h>
  10. #include <linux/ioport.h>
  11. #include <linux/init.h>
  12. #include <linux/initrd.h>
  13. #include <linux/bootmem.h>
  14. #include <linux/console.h>
  15. #include <linux/root_dev.h>
  16. #include <linux/utsname.h>
  17. #include <linux/nodemask.h>
  18. #include <linux/cpu.h>
  19. #include <linux/pfn.h>
  20. #include <linux/fs.h>
  21. #include <linux/mm.h>
  22. #include <linux/kexec.h>
  23. #include <linux/module.h>
  24. #include <linux/smp.h>
  25. #include <linux/err.h>
  26. #include <linux/crash_dump.h>
  27. #include <linux/mmzone.h>
  28. #include <linux/clk.h>
  29. #include <linux/delay.h>
  30. #include <linux/platform_device.h>
  31. #include <linux/memblock.h>
  32. #include <asm/uaccess.h>
  33. #include <asm/io.h>
  34. #include <asm/page.h>
  35. #include <asm/elf.h>
  36. #include <asm/sections.h>
  37. #include <asm/irq.h>
  38. #include <asm/setup.h>
  39. #include <asm/clock.h>
  40. #include <asm/smp.h>
  41. #include <asm/mmu_context.h>
  42. #include <asm/mmzone.h>
  43. #include <asm/sparsemem.h>
  44. /*
  45. * Initialize loops_per_jiffy as 10000000 (1000MIPS).
  46. * This value will be used at the very early stage of serial setup.
  47. * The bigger value means no problem.
  48. */
  49. struct sh_cpuinfo cpu_data[NR_CPUS] __read_mostly = {
  50. [0] = {
  51. .type = CPU_SH_NONE,
  52. .family = CPU_FAMILY_UNKNOWN,
  53. .loops_per_jiffy = 10000000,
  54. .phys_bits = MAX_PHYSMEM_BITS,
  55. },
  56. };
  57. EXPORT_SYMBOL(cpu_data);
  58. /*
  59. * The machine vector. First entry in .machvec.init, or clobbered by
  60. * sh_mv= on the command line, prior to .machvec.init teardown.
  61. */
  62. struct sh_machine_vector sh_mv = { .mv_name = "generic", };
  63. EXPORT_SYMBOL(sh_mv);
  64. #ifdef CONFIG_VT
  65. struct screen_info screen_info;
  66. #endif
  67. extern int root_mountflags;
  68. #define RAMDISK_IMAGE_START_MASK 0x07FF
  69. #define RAMDISK_PROMPT_FLAG 0x8000
  70. #define RAMDISK_LOAD_FLAG 0x4000
  71. static char __initdata command_line[COMMAND_LINE_SIZE] = { 0, };
  72. static struct resource code_resource = {
  73. .name = "Kernel code",
  74. .flags = IORESOURCE_BUSY | IORESOURCE_MEM,
  75. };
  76. static struct resource data_resource = {
  77. .name = "Kernel data",
  78. .flags = IORESOURCE_BUSY | IORESOURCE_MEM,
  79. };
  80. static struct resource bss_resource = {
  81. .name = "Kernel bss",
  82. .flags = IORESOURCE_BUSY | IORESOURCE_MEM,
  83. };
  84. unsigned long memory_start;
  85. EXPORT_SYMBOL(memory_start);
  86. unsigned long memory_end = 0;
  87. EXPORT_SYMBOL(memory_end);
  88. unsigned long memory_limit = 0;
  89. static struct resource mem_resources[MAX_NUMNODES];
  90. int l1i_cache_shape, l1d_cache_shape, l2_cache_shape;
  91. static int __init early_parse_mem(char *p)
  92. {
  93. if (!p)
  94. return 1;
  95. memory_limit = PAGE_ALIGN(memparse(p, &p));
  96. pr_notice("Memory limited to %ldMB\n", memory_limit >> 20);
  97. return 0;
  98. }
  99. early_param("mem", early_parse_mem);
  100. void __init check_for_initrd(void)
  101. {
  102. #ifdef CONFIG_BLK_DEV_INITRD
  103. unsigned long start, end;
  104. /*
  105. * Check for the rare cases where boot loaders adhere to the boot
  106. * ABI.
  107. */
  108. if (!LOADER_TYPE || !INITRD_START || !INITRD_SIZE)
  109. goto disable;
  110. start = INITRD_START + __MEMORY_START;
  111. end = start + INITRD_SIZE;
  112. if (unlikely(end <= start))
  113. goto disable;
  114. if (unlikely(start & ~PAGE_MASK)) {
  115. pr_err("initrd must be page aligned\n");
  116. goto disable;
  117. }
  118. if (unlikely(start < __MEMORY_START)) {
  119. pr_err("initrd start (%08lx) < __MEMORY_START(%x)\n",
  120. start, __MEMORY_START);
  121. goto disable;
  122. }
  123. if (unlikely(end > memblock_end_of_DRAM())) {
  124. pr_err("initrd extends beyond end of memory "
  125. "(0x%08lx > 0x%08lx)\ndisabling initrd\n",
  126. end, (unsigned long)memblock_end_of_DRAM());
  127. goto disable;
  128. }
  129. /*
  130. * If we got this far in spite of the boot loader's best efforts
  131. * to the contrary, assume we actually have a valid initrd and
  132. * fix up the root dev.
  133. */
  134. ROOT_DEV = Root_RAM0;
  135. /*
  136. * Address sanitization
  137. */
  138. initrd_start = (unsigned long)__va(start);
  139. initrd_end = initrd_start + INITRD_SIZE;
  140. memblock_reserve(__pa(initrd_start), INITRD_SIZE);
  141. return;
  142. disable:
  143. pr_info("initrd disabled\n");
  144. initrd_start = initrd_end = 0;
  145. #endif
  146. }
  147. void calibrate_delay(void)
  148. {
  149. struct clk *clk = clk_get(NULL, "cpu_clk");
  150. if (IS_ERR(clk))
  151. panic("Need a sane CPU clock definition!");
  152. loops_per_jiffy = (clk_get_rate(clk) >> 1) / HZ;
  153. printk(KERN_INFO "Calibrating delay loop (skipped)... "
  154. "%lu.%02lu BogoMIPS PRESET (lpj=%lu)\n",
  155. loops_per_jiffy/(500000/HZ),
  156. (loops_per_jiffy/(5000/HZ)) % 100,
  157. loops_per_jiffy);
  158. }
  159. void __init __add_active_range(unsigned int nid, unsigned long start_pfn,
  160. unsigned long end_pfn)
  161. {
  162. struct resource *res = &mem_resources[nid];
  163. unsigned long start, end;
  164. WARN_ON(res->name); /* max one active range per node for now */
  165. start = start_pfn << PAGE_SHIFT;
  166. end = end_pfn << PAGE_SHIFT;
  167. res->name = "System RAM";
  168. res->start = start;
  169. res->end = end - 1;
  170. res->flags = IORESOURCE_MEM | IORESOURCE_BUSY;
  171. if (request_resource(&iomem_resource, res)) {
  172. pr_err("unable to request memory_resource 0x%lx 0x%lx\n",
  173. start_pfn, end_pfn);
  174. return;
  175. }
  176. /*
  177. * We don't know which RAM region contains kernel data or
  178. * the reserved crashkernel region, so try it repeatedly
  179. * and let the resource manager test it.
  180. */
  181. request_resource(res, &code_resource);
  182. request_resource(res, &data_resource);
  183. request_resource(res, &bss_resource);
  184. #ifdef CONFIG_KEXEC
  185. request_resource(res, &crashk_res);
  186. #endif
  187. /*
  188. * Also make sure that there is a PMB mapping that covers this
  189. * range before we attempt to activate it, to avoid reset by MMU.
  190. * We can hit this path with NUMA or memory hot-add.
  191. */
  192. pmb_bolt_mapping((unsigned long)__va(start), start, end - start,
  193. PAGE_KERNEL);
  194. memblock_set_node(PFN_PHYS(start_pfn), PFN_PHYS(end_pfn - start_pfn),
  195. &memblock.memory, nid);
  196. }
  197. void __init __weak plat_early_device_setup(void)
  198. {
  199. }
  200. void __init setup_arch(char **cmdline_p)
  201. {
  202. enable_mmu();
  203. ROOT_DEV = old_decode_dev(ORIG_ROOT_DEV);
  204. printk(KERN_NOTICE "Boot params:\n"
  205. "... MOUNT_ROOT_RDONLY - %08lx\n"
  206. "... RAMDISK_FLAGS - %08lx\n"
  207. "... ORIG_ROOT_DEV - %08lx\n"
  208. "... LOADER_TYPE - %08lx\n"
  209. "... INITRD_START - %08lx\n"
  210. "... INITRD_SIZE - %08lx\n",
  211. MOUNT_ROOT_RDONLY, RAMDISK_FLAGS,
  212. ORIG_ROOT_DEV, LOADER_TYPE,
  213. INITRD_START, INITRD_SIZE);
  214. #ifdef CONFIG_BLK_DEV_RAM
  215. rd_image_start = RAMDISK_FLAGS & RAMDISK_IMAGE_START_MASK;
  216. rd_prompt = ((RAMDISK_FLAGS & RAMDISK_PROMPT_FLAG) != 0);
  217. rd_doload = ((RAMDISK_FLAGS & RAMDISK_LOAD_FLAG) != 0);
  218. #endif
  219. if (!MOUNT_ROOT_RDONLY)
  220. root_mountflags &= ~MS_RDONLY;
  221. init_mm.start_code = (unsigned long) _text;
  222. init_mm.end_code = (unsigned long) _etext;
  223. init_mm.end_data = (unsigned long) _edata;
  224. init_mm.brk = (unsigned long) _end;
  225. code_resource.start = virt_to_phys(_text);
  226. code_resource.end = virt_to_phys(_etext)-1;
  227. data_resource.start = virt_to_phys(_etext);
  228. data_resource.end = virt_to_phys(_edata)-1;
  229. bss_resource.start = virt_to_phys(__bss_start);
  230. bss_resource.end = virt_to_phys(__bss_stop)-1;
  231. #ifdef CONFIG_CMDLINE_OVERWRITE
  232. strlcpy(command_line, CONFIG_CMDLINE, sizeof(command_line));
  233. #else
  234. strlcpy(command_line, COMMAND_LINE, sizeof(command_line));
  235. #ifdef CONFIG_CMDLINE_EXTEND
  236. strlcat(command_line, " ", sizeof(command_line));
  237. strlcat(command_line, CONFIG_CMDLINE, sizeof(command_line));
  238. #endif
  239. #endif
  240. /* Save unparsed command line copy for /proc/cmdline */
  241. memcpy(boot_command_line, command_line, COMMAND_LINE_SIZE);
  242. *cmdline_p = command_line;
  243. parse_early_param();
  244. plat_early_device_setup();
  245. sh_mv_setup();
  246. /* Let earlyprintk output early console messages */
  247. early_platform_driver_probe("earlyprintk", 1, 1);
  248. paging_init();
  249. #ifdef CONFIG_DUMMY_CONSOLE
  250. conswitchp = &dummy_con;
  251. #endif
  252. /* Perform the machine specific initialisation */
  253. if (likely(sh_mv.mv_setup))
  254. sh_mv.mv_setup(cmdline_p);
  255. plat_smp_setup();
  256. }
  257. /* processor boot mode configuration */
  258. int generic_mode_pins(void)
  259. {
  260. pr_warning("generic_mode_pins(): missing mode pin configuration\n");
  261. return 0;
  262. }
  263. int test_mode_pin(int pin)
  264. {
  265. return sh_mv.mv_mode_pins() & pin;
  266. }