setup.c 21 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902
  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. bool __init memory_region_available(phys_addr_t start, phys_addr_t size)
  126. {
  127. int i;
  128. bool in_ram = false, free = true;
  129. for (i = 0; i < boot_mem_map.nr_map; i++) {
  130. phys_addr_t start_, end_;
  131. start_ = boot_mem_map.map[i].addr;
  132. end_ = boot_mem_map.map[i].addr + boot_mem_map.map[i].size;
  133. switch (boot_mem_map.map[i].type) {
  134. case BOOT_MEM_RAM:
  135. if (start >= start_ && start + size <= end_)
  136. in_ram = true;
  137. break;
  138. case BOOT_MEM_RESERVED:
  139. if ((start >= start_ && start < end_) ||
  140. (start < start_ && start + size >= start_))
  141. free = false;
  142. break;
  143. default:
  144. continue;
  145. }
  146. }
  147. return in_ram && free;
  148. }
  149. static void __init print_memory_map(void)
  150. {
  151. int i;
  152. const int field = 2 * sizeof(unsigned long);
  153. for (i = 0; i < boot_mem_map.nr_map; i++) {
  154. printk(KERN_INFO " memory: %0*Lx @ %0*Lx ",
  155. field, (unsigned long long) boot_mem_map.map[i].size,
  156. field, (unsigned long long) boot_mem_map.map[i].addr);
  157. switch (boot_mem_map.map[i].type) {
  158. case BOOT_MEM_RAM:
  159. printk(KERN_CONT "(usable)\n");
  160. break;
  161. case BOOT_MEM_INIT_RAM:
  162. printk(KERN_CONT "(usable after init)\n");
  163. break;
  164. case BOOT_MEM_ROM_DATA:
  165. printk(KERN_CONT "(ROM data)\n");
  166. break;
  167. case BOOT_MEM_RESERVED:
  168. printk(KERN_CONT "(reserved)\n");
  169. break;
  170. default:
  171. printk(KERN_CONT "type %lu\n", boot_mem_map.map[i].type);
  172. break;
  173. }
  174. }
  175. }
  176. /*
  177. * Manage initrd
  178. */
  179. #ifdef CONFIG_BLK_DEV_INITRD
  180. static int __init rd_start_early(char *p)
  181. {
  182. unsigned long start = memparse(p, &p);
  183. #ifdef CONFIG_64BIT
  184. /* Guess if the sign extension was forgotten by bootloader */
  185. if (start < XKPHYS)
  186. start = (int)start;
  187. #endif
  188. initrd_start = start;
  189. initrd_end += start;
  190. return 0;
  191. }
  192. early_param("rd_start", rd_start_early);
  193. static int __init rd_size_early(char *p)
  194. {
  195. initrd_end += memparse(p, &p);
  196. return 0;
  197. }
  198. early_param("rd_size", rd_size_early);
  199. /* it returns the next free pfn after initrd */
  200. static unsigned long __init init_initrd(void)
  201. {
  202. unsigned long end;
  203. /*
  204. * Board specific code or command line parser should have
  205. * already set up initrd_start and initrd_end. In these cases
  206. * perfom sanity checks and use them if all looks good.
  207. */
  208. if (!initrd_start || initrd_end <= initrd_start)
  209. goto disable;
  210. if (initrd_start & ~PAGE_MASK) {
  211. pr_err("initrd start must be page aligned\n");
  212. goto disable;
  213. }
  214. if (initrd_start < PAGE_OFFSET) {
  215. pr_err("initrd start < PAGE_OFFSET\n");
  216. goto disable;
  217. }
  218. /*
  219. * Sanitize initrd addresses. For example firmware
  220. * can't guess if they need to pass them through
  221. * 64-bits values if the kernel has been built in pure
  222. * 32-bit. We need also to switch from KSEG0 to XKPHYS
  223. * addresses now, so the code can now safely use __pa().
  224. */
  225. end = __pa(initrd_end);
  226. initrd_end = (unsigned long)__va(end);
  227. initrd_start = (unsigned long)__va(__pa(initrd_start));
  228. ROOT_DEV = Root_RAM0;
  229. return PFN_UP(end);
  230. disable:
  231. initrd_start = 0;
  232. initrd_end = 0;
  233. return 0;
  234. }
  235. static void __init finalize_initrd(void)
  236. {
  237. unsigned long size = initrd_end - initrd_start;
  238. if (size == 0) {
  239. printk(KERN_INFO "Initrd not found or empty");
  240. goto disable;
  241. }
  242. if (__pa(initrd_end) > PFN_PHYS(max_low_pfn)) {
  243. printk(KERN_ERR "Initrd extends beyond end of memory");
  244. goto disable;
  245. }
  246. reserve_bootmem(__pa(initrd_start), size, BOOTMEM_DEFAULT);
  247. initrd_below_start_ok = 1;
  248. pr_info("Initial ramdisk at: 0x%lx (%lu bytes)\n",
  249. initrd_start, size);
  250. return;
  251. disable:
  252. printk(KERN_CONT " - disabling initrd\n");
  253. initrd_start = 0;
  254. initrd_end = 0;
  255. }
  256. #else /* !CONFIG_BLK_DEV_INITRD */
  257. static unsigned long __init init_initrd(void)
  258. {
  259. return 0;
  260. }
  261. #define finalize_initrd() do {} while (0)
  262. #endif
  263. /*
  264. * Initialize the bootmem allocator. It also setup initrd related data
  265. * if needed.
  266. */
  267. #if defined(CONFIG_SGI_IP27) || (defined(CONFIG_CPU_LOONGSON3) && defined(CONFIG_NUMA))
  268. static void __init bootmem_init(void)
  269. {
  270. init_initrd();
  271. finalize_initrd();
  272. }
  273. #else /* !CONFIG_SGI_IP27 */
  274. static unsigned long __init bootmap_bytes(unsigned long pages)
  275. {
  276. unsigned long bytes = DIV_ROUND_UP(pages, 8);
  277. return ALIGN(bytes, sizeof(long));
  278. }
  279. static void __init bootmem_init(void)
  280. {
  281. unsigned long reserved_end;
  282. unsigned long mapstart = ~0UL;
  283. unsigned long bootmap_size;
  284. bool bootmap_valid = false;
  285. int i;
  286. /*
  287. * Sanity check any INITRD first. We don't take it into account
  288. * for bootmem setup initially, rely on the end-of-kernel-code
  289. * as our memory range starting point. Once bootmem is inited we
  290. * will reserve the area used for the initrd.
  291. */
  292. init_initrd();
  293. reserved_end = (unsigned long) PFN_UP(__pa_symbol(&_end));
  294. /*
  295. * max_low_pfn is not a number of pages. The number of pages
  296. * of the system is given by 'max_low_pfn - min_low_pfn'.
  297. */
  298. min_low_pfn = ~0UL;
  299. max_low_pfn = 0;
  300. /*
  301. * Find the highest page frame number we have available.
  302. */
  303. for (i = 0; i < boot_mem_map.nr_map; i++) {
  304. unsigned long start, end;
  305. if (boot_mem_map.map[i].type != BOOT_MEM_RAM)
  306. continue;
  307. start = PFN_UP(boot_mem_map.map[i].addr);
  308. end = PFN_DOWN(boot_mem_map.map[i].addr
  309. + boot_mem_map.map[i].size);
  310. if (end > max_low_pfn)
  311. max_low_pfn = end;
  312. if (start < min_low_pfn)
  313. min_low_pfn = start;
  314. if (end <= reserved_end)
  315. continue;
  316. #ifdef CONFIG_BLK_DEV_INITRD
  317. /* Skip zones before initrd and initrd itself */
  318. if (initrd_end && end <= (unsigned long)PFN_UP(__pa(initrd_end)))
  319. continue;
  320. #endif
  321. if (start >= mapstart)
  322. continue;
  323. mapstart = max(reserved_end, start);
  324. }
  325. if (min_low_pfn >= max_low_pfn)
  326. panic("Incorrect memory mapping !!!");
  327. if (min_low_pfn > ARCH_PFN_OFFSET) {
  328. pr_info("Wasting %lu bytes for tracking %lu unused pages\n",
  329. (min_low_pfn - ARCH_PFN_OFFSET) * sizeof(struct page),
  330. min_low_pfn - ARCH_PFN_OFFSET);
  331. } else if (min_low_pfn < ARCH_PFN_OFFSET) {
  332. pr_info("%lu free pages won't be used\n",
  333. ARCH_PFN_OFFSET - min_low_pfn);
  334. }
  335. min_low_pfn = ARCH_PFN_OFFSET;
  336. /*
  337. * Determine low and high memory ranges
  338. */
  339. max_pfn = max_low_pfn;
  340. if (max_low_pfn > PFN_DOWN(HIGHMEM_START)) {
  341. #ifdef CONFIG_HIGHMEM
  342. highstart_pfn = PFN_DOWN(HIGHMEM_START);
  343. highend_pfn = max_low_pfn;
  344. #endif
  345. max_low_pfn = PFN_DOWN(HIGHMEM_START);
  346. }
  347. #ifdef CONFIG_BLK_DEV_INITRD
  348. /*
  349. * mapstart should be after initrd_end
  350. */
  351. if (initrd_end)
  352. mapstart = max(mapstart, (unsigned long)PFN_UP(__pa(initrd_end)));
  353. #endif
  354. /*
  355. * check that mapstart doesn't overlap with any of
  356. * memory regions that have been reserved through eg. DTB
  357. */
  358. bootmap_size = bootmap_bytes(max_low_pfn - min_low_pfn);
  359. bootmap_valid = memory_region_available(PFN_PHYS(mapstart),
  360. bootmap_size);
  361. for (i = 0; i < boot_mem_map.nr_map && !bootmap_valid; i++) {
  362. unsigned long mapstart_addr;
  363. switch (boot_mem_map.map[i].type) {
  364. case BOOT_MEM_RESERVED:
  365. mapstart_addr = PFN_ALIGN(boot_mem_map.map[i].addr +
  366. boot_mem_map.map[i].size);
  367. if (PHYS_PFN(mapstart_addr) < mapstart)
  368. break;
  369. bootmap_valid = memory_region_available(mapstart_addr,
  370. bootmap_size);
  371. if (bootmap_valid)
  372. mapstart = PHYS_PFN(mapstart_addr);
  373. break;
  374. default:
  375. break;
  376. }
  377. }
  378. if (!bootmap_valid)
  379. panic("No memory area to place a bootmap bitmap");
  380. /*
  381. * Initialize the boot-time allocator with low memory only.
  382. */
  383. if (bootmap_size != init_bootmem_node(NODE_DATA(0), mapstart,
  384. min_low_pfn, max_low_pfn))
  385. panic("Unexpected memory size required for bootmap");
  386. for (i = 0; i < boot_mem_map.nr_map; i++) {
  387. unsigned long start, end;
  388. start = PFN_UP(boot_mem_map.map[i].addr);
  389. end = PFN_DOWN(boot_mem_map.map[i].addr
  390. + boot_mem_map.map[i].size);
  391. if (start <= min_low_pfn)
  392. start = min_low_pfn;
  393. if (start >= end)
  394. continue;
  395. #ifndef CONFIG_HIGHMEM
  396. if (end > max_low_pfn)
  397. end = max_low_pfn;
  398. /*
  399. * ... finally, is the area going away?
  400. */
  401. if (end <= start)
  402. continue;
  403. #endif
  404. memblock_add_node(PFN_PHYS(start), PFN_PHYS(end - start), 0);
  405. }
  406. /*
  407. * Register fully available low RAM pages with the bootmem allocator.
  408. */
  409. for (i = 0; i < boot_mem_map.nr_map; i++) {
  410. unsigned long start, end, size;
  411. start = PFN_UP(boot_mem_map.map[i].addr);
  412. end = PFN_DOWN(boot_mem_map.map[i].addr
  413. + boot_mem_map.map[i].size);
  414. /*
  415. * Reserve usable memory.
  416. */
  417. switch (boot_mem_map.map[i].type) {
  418. case BOOT_MEM_RAM:
  419. break;
  420. case BOOT_MEM_INIT_RAM:
  421. memory_present(0, start, end);
  422. continue;
  423. default:
  424. /* Not usable memory */
  425. if (start > min_low_pfn && end < max_low_pfn)
  426. reserve_bootmem(boot_mem_map.map[i].addr,
  427. boot_mem_map.map[i].size,
  428. BOOTMEM_DEFAULT);
  429. continue;
  430. }
  431. /*
  432. * We are rounding up the start address of usable memory
  433. * and at the end of the usable range downwards.
  434. */
  435. if (start >= max_low_pfn)
  436. continue;
  437. if (start < reserved_end)
  438. start = reserved_end;
  439. if (end > max_low_pfn)
  440. end = max_low_pfn;
  441. /*
  442. * ... finally, is the area going away?
  443. */
  444. if (end <= start)
  445. continue;
  446. size = end - start;
  447. /* Register lowmem ranges */
  448. free_bootmem(PFN_PHYS(start), size << PAGE_SHIFT);
  449. memory_present(0, start, end);
  450. }
  451. /*
  452. * Reserve the bootmap memory.
  453. */
  454. reserve_bootmem(PFN_PHYS(mapstart), bootmap_size, BOOTMEM_DEFAULT);
  455. /*
  456. * Reserve initrd memory if needed.
  457. */
  458. finalize_initrd();
  459. }
  460. #endif /* CONFIG_SGI_IP27 */
  461. /*
  462. * arch_mem_init - initialize memory management subsystem
  463. *
  464. * o plat_mem_setup() detects the memory configuration and will record detected
  465. * memory areas using add_memory_region.
  466. *
  467. * At this stage the memory configuration of the system is known to the
  468. * kernel but generic memory management system is still entirely uninitialized.
  469. *
  470. * o bootmem_init()
  471. * o sparse_init()
  472. * o paging_init()
  473. * o dma_contiguous_reserve()
  474. *
  475. * At this stage the bootmem allocator is ready to use.
  476. *
  477. * NOTE: historically plat_mem_setup did the entire platform initialization.
  478. * This was rather impractical because it meant plat_mem_setup had to
  479. * get away without any kind of memory allocator. To keep old code from
  480. * breaking plat_setup was just renamed to plat_mem_setup and a second platform
  481. * initialization hook for anything else was introduced.
  482. */
  483. static int usermem __initdata;
  484. static int __init early_parse_mem(char *p)
  485. {
  486. phys_addr_t start, size;
  487. /*
  488. * If a user specifies memory size, we
  489. * blow away any automatically generated
  490. * size.
  491. */
  492. if (usermem == 0) {
  493. boot_mem_map.nr_map = 0;
  494. usermem = 1;
  495. }
  496. start = 0;
  497. size = memparse(p, &p);
  498. if (*p == '@')
  499. start = memparse(p + 1, &p);
  500. add_memory_region(start, size, BOOT_MEM_RAM);
  501. return 0;
  502. }
  503. early_param("mem", early_parse_mem);
  504. #ifdef CONFIG_PROC_VMCORE
  505. unsigned long setup_elfcorehdr, setup_elfcorehdr_size;
  506. static int __init early_parse_elfcorehdr(char *p)
  507. {
  508. int i;
  509. setup_elfcorehdr = memparse(p, &p);
  510. for (i = 0; i < boot_mem_map.nr_map; i++) {
  511. unsigned long start = boot_mem_map.map[i].addr;
  512. unsigned long end = (boot_mem_map.map[i].addr +
  513. boot_mem_map.map[i].size);
  514. if (setup_elfcorehdr >= start && setup_elfcorehdr < end) {
  515. /*
  516. * Reserve from the elf core header to the end of
  517. * the memory segment, that should all be kdump
  518. * reserved memory.
  519. */
  520. setup_elfcorehdr_size = end - setup_elfcorehdr;
  521. break;
  522. }
  523. }
  524. /*
  525. * If we don't find it in the memory map, then we shouldn't
  526. * have to worry about it, as the new kernel won't use it.
  527. */
  528. return 0;
  529. }
  530. early_param("elfcorehdr", early_parse_elfcorehdr);
  531. #endif
  532. static void __init arch_mem_addpart(phys_addr_t mem, phys_addr_t end, int type)
  533. {
  534. phys_addr_t size;
  535. int i;
  536. size = end - mem;
  537. if (!size)
  538. return;
  539. /* Make sure it is in the boot_mem_map */
  540. for (i = 0; i < boot_mem_map.nr_map; i++) {
  541. if (mem >= boot_mem_map.map[i].addr &&
  542. mem < (boot_mem_map.map[i].addr +
  543. boot_mem_map.map[i].size))
  544. return;
  545. }
  546. add_memory_region(mem, size, type);
  547. }
  548. #ifdef CONFIG_KEXEC
  549. static inline unsigned long long get_total_mem(void)
  550. {
  551. unsigned long long total;
  552. total = max_pfn - min_low_pfn;
  553. return total << PAGE_SHIFT;
  554. }
  555. static void __init mips_parse_crashkernel(void)
  556. {
  557. unsigned long long total_mem;
  558. unsigned long long crash_size, crash_base;
  559. int ret;
  560. total_mem = get_total_mem();
  561. ret = parse_crashkernel(boot_command_line, total_mem,
  562. &crash_size, &crash_base);
  563. if (ret != 0 || crash_size <= 0)
  564. return;
  565. crashk_res.start = crash_base;
  566. crashk_res.end = crash_base + crash_size - 1;
  567. }
  568. static void __init request_crashkernel(struct resource *res)
  569. {
  570. int ret;
  571. ret = request_resource(res, &crashk_res);
  572. if (!ret)
  573. pr_info("Reserving %ldMB of memory at %ldMB for crashkernel\n",
  574. (unsigned long)((crashk_res.end -
  575. crashk_res.start + 1) >> 20),
  576. (unsigned long)(crashk_res.start >> 20));
  577. }
  578. #else /* !defined(CONFIG_KEXEC) */
  579. static void __init mips_parse_crashkernel(void)
  580. {
  581. }
  582. static void __init request_crashkernel(struct resource *res)
  583. {
  584. }
  585. #endif /* !defined(CONFIG_KEXEC) */
  586. #define USE_PROM_CMDLINE IS_ENABLED(CONFIG_MIPS_CMDLINE_FROM_BOOTLOADER)
  587. #define USE_DTB_CMDLINE IS_ENABLED(CONFIG_MIPS_CMDLINE_FROM_DTB)
  588. #define EXTEND_WITH_PROM IS_ENABLED(CONFIG_MIPS_CMDLINE_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. strlcat(boot_command_line, " ", COMMAND_LINE_SIZE);
  617. strlcat(boot_command_line, arcs_cmdline, COMMAND_LINE_SIZE);
  618. }
  619. #if defined(CONFIG_CMDLINE_BOOL)
  620. if (builtin_cmdline[0]) {
  621. strlcat(boot_command_line, " ", COMMAND_LINE_SIZE);
  622. strlcat(boot_command_line, builtin_cmdline, COMMAND_LINE_SIZE);
  623. }
  624. #endif
  625. #endif
  626. strlcpy(command_line, boot_command_line, COMMAND_LINE_SIZE);
  627. *cmdline_p = command_line;
  628. parse_early_param();
  629. if (usermem) {
  630. pr_info("User-defined physical RAM map:\n");
  631. print_memory_map();
  632. }
  633. bootmem_init();
  634. #ifdef CONFIG_PROC_VMCORE
  635. if (setup_elfcorehdr && setup_elfcorehdr_size) {
  636. printk(KERN_INFO "kdump reserved memory at %lx-%lx\n",
  637. setup_elfcorehdr, setup_elfcorehdr_size);
  638. reserve_bootmem(setup_elfcorehdr, setup_elfcorehdr_size,
  639. BOOTMEM_DEFAULT);
  640. }
  641. #endif
  642. mips_parse_crashkernel();
  643. #ifdef CONFIG_KEXEC
  644. if (crashk_res.start != crashk_res.end)
  645. reserve_bootmem(crashk_res.start,
  646. crashk_res.end - crashk_res.start + 1,
  647. BOOTMEM_DEFAULT);
  648. #endif
  649. device_tree_init();
  650. sparse_init();
  651. plat_swiotlb_setup();
  652. paging_init();
  653. dma_contiguous_reserve(PFN_PHYS(max_low_pfn));
  654. /* Tell bootmem about cma reserved memblock section */
  655. for_each_memblock(reserved, reg)
  656. if (reg->size != 0)
  657. reserve_bootmem(reg->base, reg->size, BOOTMEM_DEFAULT);
  658. reserve_bootmem_region(__pa_symbol(&__nosave_begin),
  659. __pa_symbol(&__nosave_end)); /* Reserve for hibernation */
  660. }
  661. static void __init resource_init(void)
  662. {
  663. int i;
  664. if (UNCAC_BASE != IO_BASE)
  665. return;
  666. code_resource.start = __pa_symbol(&_text);
  667. code_resource.end = __pa_symbol(&_etext) - 1;
  668. data_resource.start = __pa_symbol(&_etext);
  669. data_resource.end = __pa_symbol(&_edata) - 1;
  670. for (i = 0; i < boot_mem_map.nr_map; i++) {
  671. struct resource *res;
  672. unsigned long start, end;
  673. start = boot_mem_map.map[i].addr;
  674. end = boot_mem_map.map[i].addr + boot_mem_map.map[i].size - 1;
  675. if (start >= HIGHMEM_START)
  676. continue;
  677. if (end >= HIGHMEM_START)
  678. end = HIGHMEM_START - 1;
  679. res = alloc_bootmem(sizeof(struct resource));
  680. switch (boot_mem_map.map[i].type) {
  681. case BOOT_MEM_RAM:
  682. case BOOT_MEM_INIT_RAM:
  683. case BOOT_MEM_ROM_DATA:
  684. res->name = "System RAM";
  685. break;
  686. case BOOT_MEM_RESERVED:
  687. default:
  688. res->name = "reserved";
  689. }
  690. res->start = start;
  691. res->end = end;
  692. res->flags = IORESOURCE_MEM | IORESOURCE_BUSY;
  693. request_resource(&iomem_resource, res);
  694. /*
  695. * We don't know which RAM region contains kernel data,
  696. * so we try it repeatedly and let the resource manager
  697. * test it.
  698. */
  699. request_resource(res, &code_resource);
  700. request_resource(res, &data_resource);
  701. request_crashkernel(res);
  702. }
  703. }
  704. #ifdef CONFIG_SMP
  705. static void __init prefill_possible_map(void)
  706. {
  707. int i, possible = num_possible_cpus();
  708. if (possible > nr_cpu_ids)
  709. possible = nr_cpu_ids;
  710. for (i = 0; i < possible; i++)
  711. set_cpu_possible(i, true);
  712. for (; i < NR_CPUS; i++)
  713. set_cpu_possible(i, false);
  714. nr_cpu_ids = possible;
  715. }
  716. #else
  717. static inline void prefill_possible_map(void) {}
  718. #endif
  719. void __init setup_arch(char **cmdline_p)
  720. {
  721. cpu_probe();
  722. prom_init();
  723. setup_early_fdc_console();
  724. #ifdef CONFIG_EARLY_PRINTK
  725. setup_early_printk();
  726. #endif
  727. cpu_report();
  728. check_bugs_early();
  729. #if defined(CONFIG_VT)
  730. #if defined(CONFIG_VGA_CONSOLE)
  731. conswitchp = &vga_con;
  732. #elif defined(CONFIG_DUMMY_CONSOLE)
  733. conswitchp = &dummy_con;
  734. #endif
  735. #endif
  736. arch_mem_init(cmdline_p);
  737. resource_init();
  738. plat_smp_setup();
  739. prefill_possible_map();
  740. cpu_cache_init();
  741. }
  742. unsigned long kernelsp[NR_CPUS];
  743. unsigned long fw_arg0, fw_arg1, fw_arg2, fw_arg3;
  744. #ifdef CONFIG_DEBUG_FS
  745. struct dentry *mips_debugfs_dir;
  746. static int __init debugfs_mips(void)
  747. {
  748. struct dentry *d;
  749. d = debugfs_create_dir("mips", NULL);
  750. if (!d)
  751. return -ENOMEM;
  752. mips_debugfs_dir = d;
  753. return 0;
  754. }
  755. arch_initcall(debugfs_mips);
  756. #endif