setup.c 20 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827
  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. /*
  395. * Reserve initrd memory if needed.
  396. */
  397. finalize_initrd();
  398. }
  399. #endif /* CONFIG_SGI_IP27 */
  400. /*
  401. * arch_mem_init - initialize memory management subsystem
  402. *
  403. * o plat_mem_setup() detects the memory configuration and will record detected
  404. * memory areas using add_memory_region.
  405. *
  406. * At this stage the memory configuration of the system is known to the
  407. * kernel but generic memory management system is still entirely uninitialized.
  408. *
  409. * o bootmem_init()
  410. * o sparse_init()
  411. * o paging_init()
  412. * o dma_contiguous_reserve()
  413. *
  414. * At this stage the bootmem allocator is ready to use.
  415. *
  416. * NOTE: historically plat_mem_setup did the entire platform initialization.
  417. * This was rather impractical because it meant plat_mem_setup had to
  418. * get away without any kind of memory allocator. To keep old code from
  419. * breaking plat_setup was just renamed to plat_mem_setup and a second platform
  420. * initialization hook for anything else was introduced.
  421. */
  422. static int usermem __initdata;
  423. static int __init early_parse_mem(char *p)
  424. {
  425. phys_addr_t start, size;
  426. /*
  427. * If a user specifies memory size, we
  428. * blow away any automatically generated
  429. * size.
  430. */
  431. if (usermem == 0) {
  432. boot_mem_map.nr_map = 0;
  433. usermem = 1;
  434. }
  435. start = 0;
  436. size = memparse(p, &p);
  437. if (*p == '@')
  438. start = memparse(p + 1, &p);
  439. add_memory_region(start, size, BOOT_MEM_RAM);
  440. return 0;
  441. }
  442. early_param("mem", early_parse_mem);
  443. #ifdef CONFIG_PROC_VMCORE
  444. unsigned long setup_elfcorehdr, setup_elfcorehdr_size;
  445. static int __init early_parse_elfcorehdr(char *p)
  446. {
  447. int i;
  448. setup_elfcorehdr = memparse(p, &p);
  449. for (i = 0; i < boot_mem_map.nr_map; i++) {
  450. unsigned long start = boot_mem_map.map[i].addr;
  451. unsigned long end = (boot_mem_map.map[i].addr +
  452. boot_mem_map.map[i].size);
  453. if (setup_elfcorehdr >= start && setup_elfcorehdr < end) {
  454. /*
  455. * Reserve from the elf core header to the end of
  456. * the memory segment, that should all be kdump
  457. * reserved memory.
  458. */
  459. setup_elfcorehdr_size = end - setup_elfcorehdr;
  460. break;
  461. }
  462. }
  463. /*
  464. * If we don't find it in the memory map, then we shouldn't
  465. * have to worry about it, as the new kernel won't use it.
  466. */
  467. return 0;
  468. }
  469. early_param("elfcorehdr", early_parse_elfcorehdr);
  470. #endif
  471. static void __init arch_mem_addpart(phys_addr_t mem, phys_addr_t end, int type)
  472. {
  473. phys_addr_t size;
  474. int i;
  475. size = end - mem;
  476. if (!size)
  477. return;
  478. /* Make sure it is in the boot_mem_map */
  479. for (i = 0; i < boot_mem_map.nr_map; i++) {
  480. if (mem >= boot_mem_map.map[i].addr &&
  481. mem < (boot_mem_map.map[i].addr +
  482. boot_mem_map.map[i].size))
  483. return;
  484. }
  485. add_memory_region(mem, size, type);
  486. }
  487. #ifdef CONFIG_KEXEC
  488. static inline unsigned long long get_total_mem(void)
  489. {
  490. unsigned long long total;
  491. total = max_pfn - min_low_pfn;
  492. return total << PAGE_SHIFT;
  493. }
  494. static void __init mips_parse_crashkernel(void)
  495. {
  496. unsigned long long total_mem;
  497. unsigned long long crash_size, crash_base;
  498. int ret;
  499. total_mem = get_total_mem();
  500. ret = parse_crashkernel(boot_command_line, total_mem,
  501. &crash_size, &crash_base);
  502. if (ret != 0 || crash_size <= 0)
  503. return;
  504. crashk_res.start = crash_base;
  505. crashk_res.end = crash_base + crash_size - 1;
  506. }
  507. static void __init request_crashkernel(struct resource *res)
  508. {
  509. int ret;
  510. ret = request_resource(res, &crashk_res);
  511. if (!ret)
  512. pr_info("Reserving %ldMB of memory at %ldMB for crashkernel\n",
  513. (unsigned long)((crashk_res.end -
  514. crashk_res.start + 1) >> 20),
  515. (unsigned long)(crashk_res.start >> 20));
  516. }
  517. #else /* !defined(CONFIG_KEXEC) */
  518. static void __init mips_parse_crashkernel(void)
  519. {
  520. }
  521. static void __init request_crashkernel(struct resource *res)
  522. {
  523. }
  524. #endif /* !defined(CONFIG_KEXEC) */
  525. #define USE_PROM_CMDLINE IS_ENABLED(CONFIG_MIPS_CMDLINE_FROM_BOOTLOADER)
  526. #define USE_DTB_CMDLINE IS_ENABLED(CONFIG_MIPS_CMDLINE_FROM_DTB)
  527. #define EXTEND_WITH_PROM IS_ENABLED(CONFIG_MIPS_CMDLINE_EXTEND)
  528. static void __init arch_mem_init(char **cmdline_p)
  529. {
  530. struct memblock_region *reg;
  531. extern void plat_mem_setup(void);
  532. /* call board setup routine */
  533. plat_mem_setup();
  534. /*
  535. * Make sure all kernel memory is in the maps. The "UP" and
  536. * "DOWN" are opposite for initdata since if it crosses over
  537. * into another memory section you don't want that to be
  538. * freed when the initdata is freed.
  539. */
  540. arch_mem_addpart(PFN_DOWN(__pa_symbol(&_text)) << PAGE_SHIFT,
  541. PFN_UP(__pa_symbol(&_edata)) << PAGE_SHIFT,
  542. BOOT_MEM_RAM);
  543. arch_mem_addpart(PFN_UP(__pa_symbol(&__init_begin)) << PAGE_SHIFT,
  544. PFN_DOWN(__pa_symbol(&__init_end)) << PAGE_SHIFT,
  545. BOOT_MEM_INIT_RAM);
  546. pr_info("Determined physical RAM map:\n");
  547. print_memory_map();
  548. #if defined(CONFIG_CMDLINE_BOOL) && defined(CONFIG_CMDLINE_OVERRIDE)
  549. strlcpy(boot_command_line, builtin_cmdline, COMMAND_LINE_SIZE);
  550. #else
  551. if ((USE_PROM_CMDLINE && arcs_cmdline[0]) ||
  552. (USE_DTB_CMDLINE && !boot_command_line[0]))
  553. strlcpy(boot_command_line, arcs_cmdline, COMMAND_LINE_SIZE);
  554. if (EXTEND_WITH_PROM && arcs_cmdline[0]) {
  555. strlcat(boot_command_line, " ", COMMAND_LINE_SIZE);
  556. strlcat(boot_command_line, arcs_cmdline, COMMAND_LINE_SIZE);
  557. }
  558. #if defined(CONFIG_CMDLINE_BOOL)
  559. if (builtin_cmdline[0]) {
  560. strlcat(boot_command_line, " ", COMMAND_LINE_SIZE);
  561. strlcat(boot_command_line, builtin_cmdline, COMMAND_LINE_SIZE);
  562. }
  563. #endif
  564. #endif
  565. strlcpy(command_line, boot_command_line, COMMAND_LINE_SIZE);
  566. *cmdline_p = command_line;
  567. parse_early_param();
  568. if (usermem) {
  569. pr_info("User-defined physical RAM map:\n");
  570. print_memory_map();
  571. }
  572. bootmem_init();
  573. #ifdef CONFIG_PROC_VMCORE
  574. if (setup_elfcorehdr && setup_elfcorehdr_size) {
  575. printk(KERN_INFO "kdump reserved memory at %lx-%lx\n",
  576. setup_elfcorehdr, setup_elfcorehdr_size);
  577. reserve_bootmem(setup_elfcorehdr, setup_elfcorehdr_size,
  578. BOOTMEM_DEFAULT);
  579. }
  580. #endif
  581. mips_parse_crashkernel();
  582. #ifdef CONFIG_KEXEC
  583. if (crashk_res.start != crashk_res.end)
  584. reserve_bootmem(crashk_res.start,
  585. crashk_res.end - crashk_res.start + 1,
  586. BOOTMEM_DEFAULT);
  587. #endif
  588. device_tree_init();
  589. sparse_init();
  590. plat_swiotlb_setup();
  591. paging_init();
  592. dma_contiguous_reserve(PFN_PHYS(max_low_pfn));
  593. /* Tell bootmem about cma reserved memblock section */
  594. for_each_memblock(reserved, reg)
  595. if (reg->size != 0)
  596. reserve_bootmem(reg->base, reg->size, BOOTMEM_DEFAULT);
  597. }
  598. static void __init resource_init(void)
  599. {
  600. int i;
  601. if (UNCAC_BASE != IO_BASE)
  602. return;
  603. code_resource.start = __pa_symbol(&_text);
  604. code_resource.end = __pa_symbol(&_etext) - 1;
  605. data_resource.start = __pa_symbol(&_etext);
  606. data_resource.end = __pa_symbol(&_edata) - 1;
  607. for (i = 0; i < boot_mem_map.nr_map; i++) {
  608. struct resource *res;
  609. unsigned long start, end;
  610. start = boot_mem_map.map[i].addr;
  611. end = boot_mem_map.map[i].addr + boot_mem_map.map[i].size - 1;
  612. if (start >= HIGHMEM_START)
  613. continue;
  614. if (end >= HIGHMEM_START)
  615. end = HIGHMEM_START - 1;
  616. res = alloc_bootmem(sizeof(struct resource));
  617. switch (boot_mem_map.map[i].type) {
  618. case BOOT_MEM_RAM:
  619. case BOOT_MEM_INIT_RAM:
  620. case BOOT_MEM_ROM_DATA:
  621. res->name = "System RAM";
  622. break;
  623. case BOOT_MEM_RESERVED:
  624. default:
  625. res->name = "reserved";
  626. }
  627. res->start = start;
  628. res->end = end;
  629. res->flags = IORESOURCE_MEM | IORESOURCE_BUSY;
  630. request_resource(&iomem_resource, res);
  631. /*
  632. * We don't know which RAM region contains kernel data,
  633. * so we try it repeatedly and let the resource manager
  634. * test it.
  635. */
  636. request_resource(res, &code_resource);
  637. request_resource(res, &data_resource);
  638. request_crashkernel(res);
  639. }
  640. }
  641. #ifdef CONFIG_SMP
  642. static void __init prefill_possible_map(void)
  643. {
  644. int i, possible = num_possible_cpus();
  645. if (possible > nr_cpu_ids)
  646. possible = nr_cpu_ids;
  647. for (i = 0; i < possible; i++)
  648. set_cpu_possible(i, true);
  649. for (; i < NR_CPUS; i++)
  650. set_cpu_possible(i, false);
  651. nr_cpu_ids = possible;
  652. }
  653. #else
  654. static inline void prefill_possible_map(void) {}
  655. #endif
  656. void __init setup_arch(char **cmdline_p)
  657. {
  658. cpu_probe();
  659. prom_init();
  660. setup_early_fdc_console();
  661. #ifdef CONFIG_EARLY_PRINTK
  662. setup_early_printk();
  663. #endif
  664. cpu_report();
  665. check_bugs_early();
  666. #if defined(CONFIG_VT)
  667. #if defined(CONFIG_VGA_CONSOLE)
  668. conswitchp = &vga_con;
  669. #elif defined(CONFIG_DUMMY_CONSOLE)
  670. conswitchp = &dummy_con;
  671. #endif
  672. #endif
  673. arch_mem_init(cmdline_p);
  674. resource_init();
  675. plat_smp_setup();
  676. prefill_possible_map();
  677. cpu_cache_init();
  678. }
  679. unsigned long kernelsp[NR_CPUS];
  680. unsigned long fw_arg0, fw_arg1, fw_arg2, fw_arg3;
  681. #ifdef CONFIG_DEBUG_FS
  682. struct dentry *mips_debugfs_dir;
  683. static int __init debugfs_mips(void)
  684. {
  685. struct dentry *d;
  686. d = debugfs_create_dir("mips", NULL);
  687. if (!d)
  688. return -ENOMEM;
  689. mips_debugfs_dir = d;
  690. return 0;
  691. }
  692. arch_initcall(debugfs_mips);
  693. #endif