setup.c 22 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915
  1. /*
  2. * This file is subject to the terms and conditions of the GNU General Public
  3. * License. See the file "COPYING" in the main directory of this archive
  4. * for more details.
  5. *
  6. * Copyright (C) 1995 Linus Torvalds
  7. * Copyright (C) 1995 Waldorf Electronics
  8. * Copyright (C) 1994, 95, 96, 97, 98, 99, 2000, 01, 02, 03 Ralf Baechle
  9. * Copyright (C) 1996 Stoned Elipot
  10. * Copyright (C) 1999 Silicon Graphics, Inc.
  11. * Copyright (C) 2000, 2001, 2002, 2007 Maciej W. Rozycki
  12. */
  13. #include <linux/init.h>
  14. #include <linux/ioport.h>
  15. #include <linux/export.h>
  16. #include <linux/screen_info.h>
  17. #include <linux/memblock.h>
  18. #include <linux/bootmem.h>
  19. #include <linux/initrd.h>
  20. #include <linux/root_dev.h>
  21. #include <linux/highmem.h>
  22. #include <linux/console.h>
  23. #include <linux/pfn.h>
  24. #include <linux/debugfs.h>
  25. #include <linux/kexec.h>
  26. #include <linux/sizes.h>
  27. #include <linux/device.h>
  28. #include <linux/dma-contiguous.h>
  29. #include <linux/decompress/generic.h>
  30. #include <asm/addrspace.h>
  31. #include <asm/bootinfo.h>
  32. #include <asm/bugs.h>
  33. #include <asm/cache.h>
  34. #include <asm/cdmm.h>
  35. #include <asm/cpu.h>
  36. #include <asm/debug.h>
  37. #include <asm/sections.h>
  38. #include <asm/setup.h>
  39. #include <asm/smp-ops.h>
  40. #include <asm/prom.h>
  41. #ifdef CONFIG_MIPS_ELF_APPENDED_DTB
  42. const char __section(.appended_dtb) __appended_dtb[0x100000];
  43. #endif /* CONFIG_MIPS_ELF_APPENDED_DTB */
  44. struct cpuinfo_mips cpu_data[NR_CPUS] __read_mostly;
  45. EXPORT_SYMBOL(cpu_data);
  46. #ifdef CONFIG_VT
  47. struct screen_info screen_info;
  48. #endif
  49. /*
  50. * Setup information
  51. *
  52. * These are initialized so they are in the .data section
  53. */
  54. unsigned long mips_machtype __read_mostly = MACH_UNKNOWN;
  55. EXPORT_SYMBOL(mips_machtype);
  56. struct boot_mem_map boot_mem_map;
  57. static char __initdata command_line[COMMAND_LINE_SIZE];
  58. char __initdata arcs_cmdline[COMMAND_LINE_SIZE];
  59. #ifdef CONFIG_CMDLINE_BOOL
  60. static char __initdata builtin_cmdline[COMMAND_LINE_SIZE] = CONFIG_CMDLINE;
  61. #endif
  62. /*
  63. * mips_io_port_base is the begin of the address space to which x86 style
  64. * I/O ports are mapped.
  65. */
  66. const unsigned long mips_io_port_base = -1;
  67. EXPORT_SYMBOL(mips_io_port_base);
  68. static struct resource code_resource = { .name = "Kernel code", };
  69. static struct resource data_resource = { .name = "Kernel data", };
  70. static void *detect_magic __initdata = detect_memory_region;
  71. void __init add_memory_region(phys_addr_t start, phys_addr_t size, long type)
  72. {
  73. int x = boot_mem_map.nr_map;
  74. int i;
  75. /*
  76. * If the region reaches the top of the physical address space, adjust
  77. * the size slightly so that (start + size) doesn't overflow
  78. */
  79. if (start + size - 1 == (phys_addr_t)ULLONG_MAX)
  80. --size;
  81. /* Sanity check */
  82. if (start + size < start) {
  83. pr_warn("Trying to add an invalid memory region, skipped\n");
  84. return;
  85. }
  86. /*
  87. * Try to merge with existing entry, if any.
  88. */
  89. for (i = 0; i < boot_mem_map.nr_map; i++) {
  90. struct boot_mem_map_entry *entry = boot_mem_map.map + i;
  91. unsigned long top;
  92. if (entry->type != type)
  93. continue;
  94. if (start + size < entry->addr)
  95. continue; /* no overlap */
  96. if (entry->addr + entry->size < start)
  97. continue; /* no overlap */
  98. top = max(entry->addr + entry->size, start + size);
  99. entry->addr = min(entry->addr, start);
  100. entry->size = top - entry->addr;
  101. return;
  102. }
  103. if (boot_mem_map.nr_map == BOOT_MEM_MAP_MAX) {
  104. pr_err("Ooops! Too many entries in the memory map!\n");
  105. return;
  106. }
  107. boot_mem_map.map[x].addr = start;
  108. boot_mem_map.map[x].size = size;
  109. boot_mem_map.map[x].type = type;
  110. boot_mem_map.nr_map++;
  111. }
  112. void __init detect_memory_region(phys_addr_t start, phys_addr_t sz_min, phys_addr_t sz_max)
  113. {
  114. void *dm = &detect_magic;
  115. phys_addr_t size;
  116. for (size = sz_min; size < sz_max; size <<= 1) {
  117. if (!memcmp(dm, dm + size, sizeof(detect_magic)))
  118. break;
  119. }
  120. pr_debug("Memory: %lluMB of RAM detected at 0x%llx (min: %lluMB, max: %lluMB)\n",
  121. ((unsigned long long) size) / SZ_1M,
  122. (unsigned long long) start,
  123. ((unsigned long long) sz_min) / SZ_1M,
  124. ((unsigned long long) sz_max) / SZ_1M);
  125. add_memory_region(start, size, BOOT_MEM_RAM);
  126. }
  127. static void __init print_memory_map(void)
  128. {
  129. int i;
  130. const int field = 2 * sizeof(unsigned long);
  131. for (i = 0; i < boot_mem_map.nr_map; i++) {
  132. printk(KERN_INFO " memory: %0*Lx @ %0*Lx ",
  133. field, (unsigned long long) boot_mem_map.map[i].size,
  134. field, (unsigned long long) boot_mem_map.map[i].addr);
  135. switch (boot_mem_map.map[i].type) {
  136. case BOOT_MEM_RAM:
  137. printk(KERN_CONT "(usable)\n");
  138. break;
  139. case BOOT_MEM_INIT_RAM:
  140. printk(KERN_CONT "(usable after init)\n");
  141. break;
  142. case BOOT_MEM_ROM_DATA:
  143. printk(KERN_CONT "(ROM data)\n");
  144. break;
  145. case BOOT_MEM_RESERVED:
  146. printk(KERN_CONT "(reserved)\n");
  147. break;
  148. default:
  149. printk(KERN_CONT "type %lu\n", boot_mem_map.map[i].type);
  150. break;
  151. }
  152. }
  153. }
  154. /*
  155. * Manage initrd
  156. */
  157. #ifdef CONFIG_BLK_DEV_INITRD
  158. static int __init rd_start_early(char *p)
  159. {
  160. unsigned long start = memparse(p, &p);
  161. #ifdef CONFIG_64BIT
  162. /* Guess if the sign extension was forgotten by bootloader */
  163. if (start < XKPHYS)
  164. start = (int)start;
  165. #endif
  166. initrd_start = start;
  167. initrd_end += start;
  168. return 0;
  169. }
  170. early_param("rd_start", rd_start_early);
  171. static int __init rd_size_early(char *p)
  172. {
  173. initrd_end += memparse(p, &p);
  174. return 0;
  175. }
  176. early_param("rd_size", rd_size_early);
  177. /* it returns the next free pfn after initrd */
  178. static unsigned long __init init_initrd(void)
  179. {
  180. unsigned long end;
  181. /*
  182. * Board specific code or command line parser should have
  183. * already set up initrd_start and initrd_end. In these cases
  184. * perfom sanity checks and use them if all looks good.
  185. */
  186. if (!initrd_start || initrd_end <= initrd_start)
  187. goto disable;
  188. if (initrd_start & ~PAGE_MASK) {
  189. pr_err("initrd start must be page aligned\n");
  190. goto disable;
  191. }
  192. if (initrd_start < PAGE_OFFSET) {
  193. pr_err("initrd start < PAGE_OFFSET\n");
  194. goto disable;
  195. }
  196. /*
  197. * Sanitize initrd addresses. For example firmware
  198. * can't guess if they need to pass them through
  199. * 64-bits values if the kernel has been built in pure
  200. * 32-bit. We need also to switch from KSEG0 to XKPHYS
  201. * addresses now, so the code can now safely use __pa().
  202. */
  203. end = __pa(initrd_end);
  204. initrd_end = (unsigned long)__va(end);
  205. initrd_start = (unsigned long)__va(__pa(initrd_start));
  206. ROOT_DEV = Root_RAM0;
  207. return PFN_UP(end);
  208. disable:
  209. initrd_start = 0;
  210. initrd_end = 0;
  211. return 0;
  212. }
  213. /* In some conditions (e.g. big endian bootloader with a little endian
  214. kernel), the initrd might appear byte swapped. Try to detect this and
  215. byte swap it if needed. */
  216. static void __init maybe_bswap_initrd(void)
  217. {
  218. #if defined(CONFIG_CPU_CAVIUM_OCTEON)
  219. u64 buf;
  220. /* Check for CPIO signature */
  221. if (!memcmp((void *)initrd_start, "070701", 6))
  222. return;
  223. /* Check for compressed initrd */
  224. if (decompress_method((unsigned char *)initrd_start, 8, NULL))
  225. return;
  226. /* Try again with a byte swapped header */
  227. buf = swab64p((u64 *)initrd_start);
  228. if (!memcmp(&buf, "070701", 6) ||
  229. decompress_method((unsigned char *)(&buf), 8, NULL)) {
  230. unsigned long i;
  231. pr_info("Byteswapped initrd detected\n");
  232. for (i = initrd_start; i < ALIGN(initrd_end, 8); i += 8)
  233. swab64s((u64 *)i);
  234. }
  235. #endif
  236. }
  237. static void __init finalize_initrd(void)
  238. {
  239. unsigned long size = initrd_end - initrd_start;
  240. if (size == 0) {
  241. printk(KERN_INFO "Initrd not found or empty");
  242. goto disable;
  243. }
  244. if (__pa(initrd_end) > PFN_PHYS(max_low_pfn)) {
  245. printk(KERN_ERR "Initrd extends beyond end of memory");
  246. goto disable;
  247. }
  248. maybe_bswap_initrd();
  249. reserve_bootmem(__pa(initrd_start), size, BOOTMEM_DEFAULT);
  250. initrd_below_start_ok = 1;
  251. pr_info("Initial ramdisk at: 0x%lx (%lu bytes)\n",
  252. initrd_start, size);
  253. return;
  254. disable:
  255. printk(KERN_CONT " - disabling initrd\n");
  256. initrd_start = 0;
  257. initrd_end = 0;
  258. }
  259. #else /* !CONFIG_BLK_DEV_INITRD */
  260. static unsigned long __init init_initrd(void)
  261. {
  262. return 0;
  263. }
  264. #define finalize_initrd() do {} while (0)
  265. #endif
  266. /*
  267. * Initialize the bootmem allocator. It also setup initrd related data
  268. * if needed.
  269. */
  270. #if defined(CONFIG_SGI_IP27) || (defined(CONFIG_CPU_LOONGSON3) && defined(CONFIG_NUMA))
  271. static void __init bootmem_init(void)
  272. {
  273. init_initrd();
  274. finalize_initrd();
  275. }
  276. #else /* !CONFIG_SGI_IP27 */
  277. static void __init bootmem_init(void)
  278. {
  279. unsigned long reserved_end;
  280. unsigned long mapstart = ~0UL;
  281. unsigned long bootmap_size;
  282. int i;
  283. /*
  284. * Sanity check any INITRD first. We don't take it into account
  285. * for bootmem setup initially, rely on the end-of-kernel-code
  286. * as our memory range starting point. Once bootmem is inited we
  287. * will reserve the area used for the initrd.
  288. */
  289. init_initrd();
  290. reserved_end = (unsigned long) PFN_UP(__pa_symbol(&_end));
  291. /*
  292. * max_low_pfn is not a number of pages. The number of pages
  293. * of the system is given by 'max_low_pfn - min_low_pfn'.
  294. */
  295. min_low_pfn = ~0UL;
  296. max_low_pfn = 0;
  297. /*
  298. * Find the highest page frame number we have available.
  299. */
  300. for (i = 0; i < boot_mem_map.nr_map; i++) {
  301. unsigned long start, end;
  302. if (boot_mem_map.map[i].type != BOOT_MEM_RAM)
  303. continue;
  304. start = PFN_UP(boot_mem_map.map[i].addr);
  305. end = PFN_DOWN(boot_mem_map.map[i].addr
  306. + boot_mem_map.map[i].size);
  307. #ifndef CONFIG_HIGHMEM
  308. /*
  309. * Skip highmem here so we get an accurate max_low_pfn if low
  310. * memory stops short of high memory.
  311. * If the region overlaps HIGHMEM_START, end is clipped so
  312. * max_pfn excludes the highmem portion.
  313. */
  314. if (start >= PFN_DOWN(HIGHMEM_START))
  315. continue;
  316. if (end > PFN_DOWN(HIGHMEM_START))
  317. end = PFN_DOWN(HIGHMEM_START);
  318. #endif
  319. if (end > max_low_pfn)
  320. max_low_pfn = end;
  321. if (start < min_low_pfn)
  322. min_low_pfn = start;
  323. if (end <= reserved_end)
  324. continue;
  325. #ifdef CONFIG_BLK_DEV_INITRD
  326. /* Skip zones before initrd and initrd itself */
  327. if (initrd_end && end <= (unsigned long)PFN_UP(__pa(initrd_end)))
  328. continue;
  329. #endif
  330. if (start >= mapstart)
  331. continue;
  332. mapstart = max(reserved_end, start);
  333. }
  334. if (min_low_pfn >= max_low_pfn)
  335. panic("Incorrect memory mapping !!!");
  336. if (min_low_pfn > ARCH_PFN_OFFSET) {
  337. pr_info("Wasting %lu bytes for tracking %lu unused pages\n",
  338. (min_low_pfn - ARCH_PFN_OFFSET) * sizeof(struct page),
  339. min_low_pfn - ARCH_PFN_OFFSET);
  340. } else if (min_low_pfn < ARCH_PFN_OFFSET) {
  341. pr_info("%lu free pages won't be used\n",
  342. ARCH_PFN_OFFSET - min_low_pfn);
  343. }
  344. min_low_pfn = ARCH_PFN_OFFSET;
  345. /*
  346. * Determine low and high memory ranges
  347. */
  348. max_pfn = max_low_pfn;
  349. if (max_low_pfn > PFN_DOWN(HIGHMEM_START)) {
  350. #ifdef CONFIG_HIGHMEM
  351. highstart_pfn = PFN_DOWN(HIGHMEM_START);
  352. highend_pfn = max_low_pfn;
  353. #endif
  354. max_low_pfn = PFN_DOWN(HIGHMEM_START);
  355. }
  356. #ifdef CONFIG_BLK_DEV_INITRD
  357. /*
  358. * mapstart should be after initrd_end
  359. */
  360. if (initrd_end)
  361. mapstart = max(mapstart, (unsigned long)PFN_UP(__pa(initrd_end)));
  362. #endif
  363. /*
  364. * Initialize the boot-time allocator with low memory only.
  365. */
  366. bootmap_size = init_bootmem_node(NODE_DATA(0), mapstart,
  367. min_low_pfn, max_low_pfn);
  368. for (i = 0; i < boot_mem_map.nr_map; i++) {
  369. unsigned long start, end;
  370. start = PFN_UP(boot_mem_map.map[i].addr);
  371. end = PFN_DOWN(boot_mem_map.map[i].addr
  372. + boot_mem_map.map[i].size);
  373. if (start <= min_low_pfn)
  374. start = min_low_pfn;
  375. if (start >= end)
  376. continue;
  377. #ifndef CONFIG_HIGHMEM
  378. if (end > max_low_pfn)
  379. end = max_low_pfn;
  380. /*
  381. * ... finally, is the area going away?
  382. */
  383. if (end <= start)
  384. continue;
  385. #endif
  386. memblock_add_node(PFN_PHYS(start), PFN_PHYS(end - start), 0);
  387. }
  388. /*
  389. * Register fully available low RAM pages with the bootmem allocator.
  390. */
  391. for (i = 0; i < boot_mem_map.nr_map; i++) {
  392. unsigned long start, end, size;
  393. start = PFN_UP(boot_mem_map.map[i].addr);
  394. end = PFN_DOWN(boot_mem_map.map[i].addr
  395. + boot_mem_map.map[i].size);
  396. /*
  397. * Reserve usable memory.
  398. */
  399. switch (boot_mem_map.map[i].type) {
  400. case BOOT_MEM_RAM:
  401. break;
  402. case BOOT_MEM_INIT_RAM:
  403. memory_present(0, start, end);
  404. continue;
  405. default:
  406. /* Not usable memory */
  407. continue;
  408. }
  409. /*
  410. * We are rounding up the start address of usable memory
  411. * and at the end of the usable range downwards.
  412. */
  413. if (start >= max_low_pfn)
  414. continue;
  415. if (start < reserved_end)
  416. start = reserved_end;
  417. if (end > max_low_pfn)
  418. end = max_low_pfn;
  419. /*
  420. * ... finally, is the area going away?
  421. */
  422. if (end <= start)
  423. continue;
  424. size = end - start;
  425. /* Register lowmem ranges */
  426. free_bootmem(PFN_PHYS(start), size << PAGE_SHIFT);
  427. memory_present(0, start, end);
  428. }
  429. /*
  430. * Reserve the bootmap memory.
  431. */
  432. reserve_bootmem(PFN_PHYS(mapstart), bootmap_size, BOOTMEM_DEFAULT);
  433. #ifdef CONFIG_RELOCATABLE
  434. /*
  435. * The kernel reserves all memory below its _end symbol as bootmem,
  436. * but the kernel may now be at a much higher address. The memory
  437. * between the original and new locations may be returned to the system.
  438. */
  439. if (__pa_symbol(_text) > __pa_symbol(VMLINUX_LOAD_ADDRESS)) {
  440. unsigned long offset;
  441. extern void show_kernel_relocation(const char *level);
  442. offset = __pa_symbol(_text) - __pa_symbol(VMLINUX_LOAD_ADDRESS);
  443. free_bootmem(__pa_symbol(VMLINUX_LOAD_ADDRESS), offset);
  444. #if defined(CONFIG_DEBUG_KERNEL) && defined(CONFIG_DEBUG_INFO)
  445. /*
  446. * This information is necessary when debugging the kernel
  447. * But is a security vulnerability otherwise!
  448. */
  449. show_kernel_relocation(KERN_INFO);
  450. #endif
  451. }
  452. #endif
  453. /*
  454. * Reserve initrd memory if needed.
  455. */
  456. finalize_initrd();
  457. }
  458. #endif /* CONFIG_SGI_IP27 */
  459. /*
  460. * arch_mem_init - initialize memory management subsystem
  461. *
  462. * o plat_mem_setup() detects the memory configuration and will record detected
  463. * memory areas using add_memory_region.
  464. *
  465. * At this stage the memory configuration of the system is known to the
  466. * kernel but generic memory management system is still entirely uninitialized.
  467. *
  468. * o bootmem_init()
  469. * o sparse_init()
  470. * o paging_init()
  471. * o dma_contiguous_reserve()
  472. *
  473. * At this stage the bootmem allocator is ready to use.
  474. *
  475. * NOTE: historically plat_mem_setup did the entire platform initialization.
  476. * This was rather impractical because it meant plat_mem_setup had to
  477. * get away without any kind of memory allocator. To keep old code from
  478. * breaking plat_setup was just renamed to plat_mem_setup and a second platform
  479. * initialization hook for anything else was introduced.
  480. */
  481. static int usermem __initdata;
  482. static int __init early_parse_mem(char *p)
  483. {
  484. phys_addr_t start, size;
  485. /*
  486. * If a user specifies memory size, we
  487. * blow away any automatically generated
  488. * size.
  489. */
  490. if (usermem == 0) {
  491. boot_mem_map.nr_map = 0;
  492. usermem = 1;
  493. }
  494. start = 0;
  495. size = memparse(p, &p);
  496. if (*p == '@')
  497. start = memparse(p + 1, &p);
  498. add_memory_region(start, size, BOOT_MEM_RAM);
  499. return 0;
  500. }
  501. early_param("mem", early_parse_mem);
  502. #ifdef CONFIG_PROC_VMCORE
  503. unsigned long setup_elfcorehdr, setup_elfcorehdr_size;
  504. static int __init early_parse_elfcorehdr(char *p)
  505. {
  506. int i;
  507. setup_elfcorehdr = memparse(p, &p);
  508. for (i = 0; i < boot_mem_map.nr_map; i++) {
  509. unsigned long start = boot_mem_map.map[i].addr;
  510. unsigned long end = (boot_mem_map.map[i].addr +
  511. boot_mem_map.map[i].size);
  512. if (setup_elfcorehdr >= start && setup_elfcorehdr < end) {
  513. /*
  514. * Reserve from the elf core header to the end of
  515. * the memory segment, that should all be kdump
  516. * reserved memory.
  517. */
  518. setup_elfcorehdr_size = end - setup_elfcorehdr;
  519. break;
  520. }
  521. }
  522. /*
  523. * If we don't find it in the memory map, then we shouldn't
  524. * have to worry about it, as the new kernel won't use it.
  525. */
  526. return 0;
  527. }
  528. early_param("elfcorehdr", early_parse_elfcorehdr);
  529. #endif
  530. static void __init arch_mem_addpart(phys_addr_t mem, phys_addr_t end, int type)
  531. {
  532. phys_addr_t size;
  533. int i;
  534. size = end - mem;
  535. if (!size)
  536. return;
  537. /* Make sure it is in the boot_mem_map */
  538. for (i = 0; i < boot_mem_map.nr_map; i++) {
  539. if (mem >= boot_mem_map.map[i].addr &&
  540. mem < (boot_mem_map.map[i].addr +
  541. boot_mem_map.map[i].size))
  542. return;
  543. }
  544. add_memory_region(mem, size, type);
  545. }
  546. #ifdef CONFIG_KEXEC
  547. static inline unsigned long long get_total_mem(void)
  548. {
  549. unsigned long long total;
  550. total = max_pfn - min_low_pfn;
  551. return total << PAGE_SHIFT;
  552. }
  553. static void __init mips_parse_crashkernel(void)
  554. {
  555. unsigned long long total_mem;
  556. unsigned long long crash_size, crash_base;
  557. int ret;
  558. total_mem = get_total_mem();
  559. ret = parse_crashkernel(boot_command_line, total_mem,
  560. &crash_size, &crash_base);
  561. if (ret != 0 || crash_size <= 0)
  562. return;
  563. crashk_res.start = crash_base;
  564. crashk_res.end = crash_base + crash_size - 1;
  565. }
  566. static void __init request_crashkernel(struct resource *res)
  567. {
  568. int ret;
  569. ret = request_resource(res, &crashk_res);
  570. if (!ret)
  571. pr_info("Reserving %ldMB of memory at %ldMB for crashkernel\n",
  572. (unsigned long)((crashk_res.end -
  573. crashk_res.start + 1) >> 20),
  574. (unsigned long)(crashk_res.start >> 20));
  575. }
  576. #else /* !defined(CONFIG_KEXEC) */
  577. static void __init mips_parse_crashkernel(void)
  578. {
  579. }
  580. static void __init request_crashkernel(struct resource *res)
  581. {
  582. }
  583. #endif /* !defined(CONFIG_KEXEC) */
  584. #define USE_PROM_CMDLINE IS_ENABLED(CONFIG_MIPS_CMDLINE_FROM_BOOTLOADER)
  585. #define USE_DTB_CMDLINE IS_ENABLED(CONFIG_MIPS_CMDLINE_FROM_DTB)
  586. #define EXTEND_WITH_PROM IS_ENABLED(CONFIG_MIPS_CMDLINE_DTB_EXTEND)
  587. #define BUILTIN_EXTEND_WITH_PROM \
  588. IS_ENABLED(CONFIG_MIPS_CMDLINE_BUILTIN_EXTEND)
  589. static void __init arch_mem_init(char **cmdline_p)
  590. {
  591. struct memblock_region *reg;
  592. extern void plat_mem_setup(void);
  593. /* call board setup routine */
  594. plat_mem_setup();
  595. /*
  596. * Make sure all kernel memory is in the maps. The "UP" and
  597. * "DOWN" are opposite for initdata since if it crosses over
  598. * into another memory section you don't want that to be
  599. * freed when the initdata is freed.
  600. */
  601. arch_mem_addpart(PFN_DOWN(__pa_symbol(&_text)) << PAGE_SHIFT,
  602. PFN_UP(__pa_symbol(&_edata)) << PAGE_SHIFT,
  603. BOOT_MEM_RAM);
  604. arch_mem_addpart(PFN_UP(__pa_symbol(&__init_begin)) << PAGE_SHIFT,
  605. PFN_DOWN(__pa_symbol(&__init_end)) << PAGE_SHIFT,
  606. BOOT_MEM_INIT_RAM);
  607. pr_info("Determined physical RAM map:\n");
  608. print_memory_map();
  609. #if defined(CONFIG_CMDLINE_BOOL) && defined(CONFIG_CMDLINE_OVERRIDE)
  610. strlcpy(boot_command_line, builtin_cmdline, COMMAND_LINE_SIZE);
  611. #else
  612. if ((USE_PROM_CMDLINE && arcs_cmdline[0]) ||
  613. (USE_DTB_CMDLINE && !boot_command_line[0]))
  614. strlcpy(boot_command_line, arcs_cmdline, COMMAND_LINE_SIZE);
  615. if (EXTEND_WITH_PROM && arcs_cmdline[0]) {
  616. if (boot_command_line[0])
  617. strlcat(boot_command_line, " ", COMMAND_LINE_SIZE);
  618. strlcat(boot_command_line, arcs_cmdline, COMMAND_LINE_SIZE);
  619. }
  620. #if defined(CONFIG_CMDLINE_BOOL)
  621. if (builtin_cmdline[0]) {
  622. if (boot_command_line[0])
  623. strlcat(boot_command_line, " ", COMMAND_LINE_SIZE);
  624. strlcat(boot_command_line, builtin_cmdline, COMMAND_LINE_SIZE);
  625. }
  626. if (BUILTIN_EXTEND_WITH_PROM && arcs_cmdline[0]) {
  627. if (boot_command_line[0])
  628. strlcat(boot_command_line, " ", COMMAND_LINE_SIZE);
  629. strlcat(boot_command_line, arcs_cmdline, COMMAND_LINE_SIZE);
  630. }
  631. #endif
  632. #endif
  633. strlcpy(command_line, boot_command_line, COMMAND_LINE_SIZE);
  634. *cmdline_p = command_line;
  635. parse_early_param();
  636. if (usermem) {
  637. pr_info("User-defined physical RAM map:\n");
  638. print_memory_map();
  639. }
  640. bootmem_init();
  641. #ifdef CONFIG_PROC_VMCORE
  642. if (setup_elfcorehdr && setup_elfcorehdr_size) {
  643. printk(KERN_INFO "kdump reserved memory at %lx-%lx\n",
  644. setup_elfcorehdr, setup_elfcorehdr_size);
  645. reserve_bootmem(setup_elfcorehdr, setup_elfcorehdr_size,
  646. BOOTMEM_DEFAULT);
  647. }
  648. #endif
  649. mips_parse_crashkernel();
  650. #ifdef CONFIG_KEXEC
  651. if (crashk_res.start != crashk_res.end)
  652. reserve_bootmem(crashk_res.start,
  653. crashk_res.end - crashk_res.start + 1,
  654. BOOTMEM_DEFAULT);
  655. #endif
  656. device_tree_init();
  657. sparse_init();
  658. plat_swiotlb_setup();
  659. dma_contiguous_reserve(PFN_PHYS(max_low_pfn));
  660. /* Tell bootmem about cma reserved memblock section */
  661. for_each_memblock(reserved, reg)
  662. if (reg->size != 0)
  663. reserve_bootmem(reg->base, reg->size, BOOTMEM_DEFAULT);
  664. reserve_bootmem_region(__pa_symbol(&__nosave_begin),
  665. __pa_symbol(&__nosave_end)); /* Reserve for hibernation */
  666. }
  667. static void __init resource_init(void)
  668. {
  669. int i;
  670. if (UNCAC_BASE != IO_BASE)
  671. return;
  672. code_resource.start = __pa_symbol(&_text);
  673. code_resource.end = __pa_symbol(&_etext) - 1;
  674. data_resource.start = __pa_symbol(&_etext);
  675. data_resource.end = __pa_symbol(&_edata) - 1;
  676. for (i = 0; i < boot_mem_map.nr_map; i++) {
  677. struct resource *res;
  678. unsigned long start, end;
  679. start = boot_mem_map.map[i].addr;
  680. end = boot_mem_map.map[i].addr + boot_mem_map.map[i].size - 1;
  681. if (start >= HIGHMEM_START)
  682. continue;
  683. if (end >= HIGHMEM_START)
  684. end = HIGHMEM_START - 1;
  685. res = alloc_bootmem(sizeof(struct resource));
  686. res->start = start;
  687. res->end = end;
  688. res->flags = IORESOURCE_MEM | IORESOURCE_BUSY;
  689. switch (boot_mem_map.map[i].type) {
  690. case BOOT_MEM_RAM:
  691. case BOOT_MEM_INIT_RAM:
  692. case BOOT_MEM_ROM_DATA:
  693. res->name = "System RAM";
  694. res->flags |= IORESOURCE_SYSRAM;
  695. break;
  696. case BOOT_MEM_RESERVED:
  697. default:
  698. res->name = "reserved";
  699. }
  700. request_resource(&iomem_resource, res);
  701. /*
  702. * We don't know which RAM region contains kernel data,
  703. * so we try it repeatedly and let the resource manager
  704. * test it.
  705. */
  706. request_resource(res, &code_resource);
  707. request_resource(res, &data_resource);
  708. request_crashkernel(res);
  709. }
  710. }
  711. #ifdef CONFIG_SMP
  712. static void __init prefill_possible_map(void)
  713. {
  714. int i, possible = num_possible_cpus();
  715. if (possible > nr_cpu_ids)
  716. possible = nr_cpu_ids;
  717. for (i = 0; i < possible; i++)
  718. set_cpu_possible(i, true);
  719. for (; i < NR_CPUS; i++)
  720. set_cpu_possible(i, false);
  721. nr_cpu_ids = possible;
  722. }
  723. #else
  724. static inline void prefill_possible_map(void) {}
  725. #endif
  726. void __init setup_arch(char **cmdline_p)
  727. {
  728. cpu_probe();
  729. mips_cm_probe();
  730. prom_init();
  731. setup_early_fdc_console();
  732. #ifdef CONFIG_EARLY_PRINTK
  733. setup_early_printk();
  734. #endif
  735. cpu_report();
  736. check_bugs_early();
  737. #if defined(CONFIG_VT)
  738. #if defined(CONFIG_VGA_CONSOLE)
  739. conswitchp = &vga_con;
  740. #elif defined(CONFIG_DUMMY_CONSOLE)
  741. conswitchp = &dummy_con;
  742. #endif
  743. #endif
  744. arch_mem_init(cmdline_p);
  745. resource_init();
  746. plat_smp_setup();
  747. prefill_possible_map();
  748. cpu_cache_init();
  749. paging_init();
  750. }
  751. unsigned long kernelsp[NR_CPUS];
  752. unsigned long fw_arg0, fw_arg1, fw_arg2, fw_arg3;
  753. #ifdef CONFIG_USE_OF
  754. unsigned long fw_passed_dtb;
  755. #endif
  756. #ifdef CONFIG_DEBUG_FS
  757. struct dentry *mips_debugfs_dir;
  758. static int __init debugfs_mips(void)
  759. {
  760. struct dentry *d;
  761. d = debugfs_create_dir("mips", NULL);
  762. if (!d)
  763. return -ENOMEM;
  764. mips_debugfs_dir = d;
  765. return 0;
  766. }
  767. arch_initcall(debugfs_mips);
  768. #endif