setup.c 19 KB

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