setup.c 25 KB

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