setup.c 25 KB

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