setup.c 20 KB

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