setup.c 8.5 KB

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