e820.c 35 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150115111521153115411551156115711581159116011611162116311641165116611671168116911701171117211731174117511761177117811791180118111821183118411851186118711881189119011911192119311941195119611971198119912001201120212031204120512061207120812091210121112121213121412151216121712181219122012211222122312241225122612271228122912301231123212331234123512361237123812391240124112421243124412451246124712481249125012511252125312541255125612571258125912601261126212631264126512661267126812691270127112721273127412751276127712781279128012811282128312841285128612871288128912901291129212931294129512961297129812991300130113021303130413051306130713081309131013111312131313141315131613171318131913201321132213231324132513261327132813291330133113321333133413351336133713381339134013411342134313441345134613471348134913501351135213531354135513561357135813591360136113621363136413651366136713681369137013711372137313741375137613771378137913801381138213831384138513861387138813891390139113921393139413951396139713981399140014011402140314041405140614071408140914101411141214131414141514161417141814191420
  1. /*
  2. * Handle the memory map.
  3. * The functions here do the job until bootmem takes over.
  4. *
  5. * Getting sanitize_e820_map() in sync with i386 version by applying change:
  6. * - Provisions for empty E820 memory regions (reported by certain BIOSes).
  7. * Alex Achenbach <xela@slit.de>, December 2002.
  8. * Venkatesh Pallipadi <venkatesh.pallipadi@intel.com>
  9. *
  10. */
  11. #include <linux/kernel.h>
  12. #include <linux/types.h>
  13. #include <linux/init.h>
  14. #include <linux/bootmem.h>
  15. #include <linux/ioport.h>
  16. #include <linux/string.h>
  17. #include <linux/kexec.h>
  18. #include <linux/module.h>
  19. #include <linux/mm.h>
  20. #include <linux/pfn.h>
  21. #include <linux/suspend.h>
  22. #include <linux/firmware-map.h>
  23. #include <asm/pgtable.h>
  24. #include <asm/page.h>
  25. #include <asm/e820.h>
  26. #include <asm/proto.h>
  27. #include <asm/setup.h>
  28. #include <asm/trampoline.h>
  29. /*
  30. * The e820 map is the map that gets modified e.g. with command line parameters
  31. * and that is also registered with modifications in the kernel resource tree
  32. * with the iomem_resource as parent.
  33. *
  34. * The e820_saved is directly saved after the BIOS-provided memory map is
  35. * copied. It doesn't get modified afterwards. It's registered for the
  36. * /sys/firmware/memmap interface.
  37. *
  38. * That memory map is not modified and is used as base for kexec. The kexec'd
  39. * kernel should get the same memory map as the firmware provides. Then the
  40. * user can e.g. boot the original kernel with mem=1G while still booting the
  41. * next kernel with full memory.
  42. */
  43. struct e820map e820;
  44. struct e820map e820_saved;
  45. /* For PCI or other memory-mapped resources */
  46. unsigned long pci_mem_start = 0xaeedbabe;
  47. #ifdef CONFIG_PCI
  48. EXPORT_SYMBOL(pci_mem_start);
  49. #endif
  50. /*
  51. * This function checks if any part of the range <start,end> is mapped
  52. * with type.
  53. */
  54. int
  55. e820_any_mapped(u64 start, u64 end, unsigned type)
  56. {
  57. int i;
  58. for (i = 0; i < e820.nr_map; i++) {
  59. struct e820entry *ei = &e820.map[i];
  60. if (type && ei->type != type)
  61. continue;
  62. if (ei->addr >= end || ei->addr + ei->size <= start)
  63. continue;
  64. return 1;
  65. }
  66. return 0;
  67. }
  68. EXPORT_SYMBOL_GPL(e820_any_mapped);
  69. /*
  70. * This function checks if the entire range <start,end> is mapped with type.
  71. *
  72. * Note: this function only works correct if the e820 table is sorted and
  73. * not-overlapping, which is the case
  74. */
  75. int __init e820_all_mapped(u64 start, u64 end, unsigned type)
  76. {
  77. int i;
  78. for (i = 0; i < e820.nr_map; i++) {
  79. struct e820entry *ei = &e820.map[i];
  80. if (type && ei->type != type)
  81. continue;
  82. /* is the region (part) in overlap with the current region ?*/
  83. if (ei->addr >= end || ei->addr + ei->size <= start)
  84. continue;
  85. /* if the region is at the beginning of <start,end> we move
  86. * start to the end of the region since it's ok until there
  87. */
  88. if (ei->addr <= start)
  89. start = ei->addr + ei->size;
  90. /*
  91. * if start is now at or beyond end, we're done, full
  92. * coverage
  93. */
  94. if (start >= end)
  95. return 1;
  96. }
  97. return 0;
  98. }
  99. /*
  100. * Add a memory region to the kernel e820 map.
  101. */
  102. static void __init __e820_add_region(struct e820map *e820x, u64 start, u64 size,
  103. int type)
  104. {
  105. int x = e820x->nr_map;
  106. if (x == ARRAY_SIZE(e820x->map)) {
  107. printk(KERN_ERR "Ooops! Too many entries in the memory map!\n");
  108. return;
  109. }
  110. e820x->map[x].addr = start;
  111. e820x->map[x].size = size;
  112. e820x->map[x].type = type;
  113. e820x->nr_map++;
  114. }
  115. void __init e820_add_region(u64 start, u64 size, int type)
  116. {
  117. __e820_add_region(&e820, start, size, type);
  118. }
  119. void __init e820_print_map(char *who)
  120. {
  121. int i;
  122. for (i = 0; i < e820.nr_map; i++) {
  123. printk(KERN_INFO " %s: %016Lx - %016Lx ", who,
  124. (unsigned long long) e820.map[i].addr,
  125. (unsigned long long)
  126. (e820.map[i].addr + e820.map[i].size));
  127. switch (e820.map[i].type) {
  128. case E820_RAM:
  129. case E820_RESERVED_KERN:
  130. printk(KERN_CONT "(usable)\n");
  131. break;
  132. case E820_RESERVED:
  133. printk(KERN_CONT "(reserved)\n");
  134. break;
  135. case E820_ACPI:
  136. printk(KERN_CONT "(ACPI data)\n");
  137. break;
  138. case E820_NVS:
  139. printk(KERN_CONT "(ACPI NVS)\n");
  140. break;
  141. case E820_UNUSABLE:
  142. printk("(unusable)\n");
  143. break;
  144. default:
  145. printk(KERN_CONT "type %u\n", e820.map[i].type);
  146. break;
  147. }
  148. }
  149. }
  150. /*
  151. * Sanitize the BIOS e820 map.
  152. *
  153. * Some e820 responses include overlapping entries. The following
  154. * replaces the original e820 map with a new one, removing overlaps,
  155. * and resolving conflicting memory types in favor of highest
  156. * numbered type.
  157. *
  158. * The input parameter biosmap points to an array of 'struct
  159. * e820entry' which on entry has elements in the range [0, *pnr_map)
  160. * valid, and which has space for up to max_nr_map entries.
  161. * On return, the resulting sanitized e820 map entries will be in
  162. * overwritten in the same location, starting at biosmap.
  163. *
  164. * The integer pointed to by pnr_map must be valid on entry (the
  165. * current number of valid entries located at biosmap) and will
  166. * be updated on return, with the new number of valid entries
  167. * (something no more than max_nr_map.)
  168. *
  169. * The return value from sanitize_e820_map() is zero if it
  170. * successfully 'sanitized' the map entries passed in, and is -1
  171. * if it did nothing, which can happen if either of (1) it was
  172. * only passed one map entry, or (2) any of the input map entries
  173. * were invalid (start + size < start, meaning that the size was
  174. * so big the described memory range wrapped around through zero.)
  175. *
  176. * Visually we're performing the following
  177. * (1,2,3,4 = memory types)...
  178. *
  179. * Sample memory map (w/overlaps):
  180. * ____22__________________
  181. * ______________________4_
  182. * ____1111________________
  183. * _44_____________________
  184. * 11111111________________
  185. * ____________________33__
  186. * ___________44___________
  187. * __________33333_________
  188. * ______________22________
  189. * ___________________2222_
  190. * _________111111111______
  191. * _____________________11_
  192. * _________________4______
  193. *
  194. * Sanitized equivalent (no overlap):
  195. * 1_______________________
  196. * _44_____________________
  197. * ___1____________________
  198. * ____22__________________
  199. * ______11________________
  200. * _________1______________
  201. * __________3_____________
  202. * ___________44___________
  203. * _____________33_________
  204. * _______________2________
  205. * ________________1_______
  206. * _________________4______
  207. * ___________________2____
  208. * ____________________33__
  209. * ______________________4_
  210. */
  211. int __init sanitize_e820_map(struct e820entry *biosmap, int max_nr_map,
  212. int *pnr_map)
  213. {
  214. struct change_member {
  215. struct e820entry *pbios; /* pointer to original bios entry */
  216. unsigned long long addr; /* address for this change point */
  217. };
  218. static struct change_member change_point_list[2*E820_X_MAX] __initdata;
  219. static struct change_member *change_point[2*E820_X_MAX] __initdata;
  220. static struct e820entry *overlap_list[E820_X_MAX] __initdata;
  221. static struct e820entry new_bios[E820_X_MAX] __initdata;
  222. struct change_member *change_tmp;
  223. unsigned long current_type, last_type;
  224. unsigned long long last_addr;
  225. int chgidx, still_changing;
  226. int overlap_entries;
  227. int new_bios_entry;
  228. int old_nr, new_nr, chg_nr;
  229. int i;
  230. /* if there's only one memory region, don't bother */
  231. if (*pnr_map < 2)
  232. return -1;
  233. old_nr = *pnr_map;
  234. BUG_ON(old_nr > max_nr_map);
  235. /* bail out if we find any unreasonable addresses in bios map */
  236. for (i = 0; i < old_nr; i++)
  237. if (biosmap[i].addr + biosmap[i].size < biosmap[i].addr)
  238. return -1;
  239. /* create pointers for initial change-point information (for sorting) */
  240. for (i = 0; i < 2 * old_nr; i++)
  241. change_point[i] = &change_point_list[i];
  242. /* record all known change-points (starting and ending addresses),
  243. omitting those that are for empty memory regions */
  244. chgidx = 0;
  245. for (i = 0; i < old_nr; i++) {
  246. if (biosmap[i].size != 0) {
  247. change_point[chgidx]->addr = biosmap[i].addr;
  248. change_point[chgidx++]->pbios = &biosmap[i];
  249. change_point[chgidx]->addr = biosmap[i].addr +
  250. biosmap[i].size;
  251. change_point[chgidx++]->pbios = &biosmap[i];
  252. }
  253. }
  254. chg_nr = chgidx;
  255. /* sort change-point list by memory addresses (low -> high) */
  256. still_changing = 1;
  257. while (still_changing) {
  258. still_changing = 0;
  259. for (i = 1; i < chg_nr; i++) {
  260. unsigned long long curaddr, lastaddr;
  261. unsigned long long curpbaddr, lastpbaddr;
  262. curaddr = change_point[i]->addr;
  263. lastaddr = change_point[i - 1]->addr;
  264. curpbaddr = change_point[i]->pbios->addr;
  265. lastpbaddr = change_point[i - 1]->pbios->addr;
  266. /*
  267. * swap entries, when:
  268. *
  269. * curaddr > lastaddr or
  270. * curaddr == lastaddr and curaddr == curpbaddr and
  271. * lastaddr != lastpbaddr
  272. */
  273. if (curaddr < lastaddr ||
  274. (curaddr == lastaddr && curaddr == curpbaddr &&
  275. lastaddr != lastpbaddr)) {
  276. change_tmp = change_point[i];
  277. change_point[i] = change_point[i-1];
  278. change_point[i-1] = change_tmp;
  279. still_changing = 1;
  280. }
  281. }
  282. }
  283. /* create a new bios memory map, removing overlaps */
  284. overlap_entries = 0; /* number of entries in the overlap table */
  285. new_bios_entry = 0; /* index for creating new bios map entries */
  286. last_type = 0; /* start with undefined memory type */
  287. last_addr = 0; /* start with 0 as last starting address */
  288. /* loop through change-points, determining affect on the new bios map */
  289. for (chgidx = 0; chgidx < chg_nr; chgidx++) {
  290. /* keep track of all overlapping bios entries */
  291. if (change_point[chgidx]->addr ==
  292. change_point[chgidx]->pbios->addr) {
  293. /*
  294. * add map entry to overlap list (> 1 entry
  295. * implies an overlap)
  296. */
  297. overlap_list[overlap_entries++] =
  298. change_point[chgidx]->pbios;
  299. } else {
  300. /*
  301. * remove entry from list (order independent,
  302. * so swap with last)
  303. */
  304. for (i = 0; i < overlap_entries; i++) {
  305. if (overlap_list[i] ==
  306. change_point[chgidx]->pbios)
  307. overlap_list[i] =
  308. overlap_list[overlap_entries-1];
  309. }
  310. overlap_entries--;
  311. }
  312. /*
  313. * if there are overlapping entries, decide which
  314. * "type" to use (larger value takes precedence --
  315. * 1=usable, 2,3,4,4+=unusable)
  316. */
  317. current_type = 0;
  318. for (i = 0; i < overlap_entries; i++)
  319. if (overlap_list[i]->type > current_type)
  320. current_type = overlap_list[i]->type;
  321. /*
  322. * continue building up new bios map based on this
  323. * information
  324. */
  325. if (current_type != last_type) {
  326. if (last_type != 0) {
  327. new_bios[new_bios_entry].size =
  328. change_point[chgidx]->addr - last_addr;
  329. /*
  330. * move forward only if the new size
  331. * was non-zero
  332. */
  333. if (new_bios[new_bios_entry].size != 0)
  334. /*
  335. * no more space left for new
  336. * bios entries ?
  337. */
  338. if (++new_bios_entry >= max_nr_map)
  339. break;
  340. }
  341. if (current_type != 0) {
  342. new_bios[new_bios_entry].addr =
  343. change_point[chgidx]->addr;
  344. new_bios[new_bios_entry].type = current_type;
  345. last_addr = change_point[chgidx]->addr;
  346. }
  347. last_type = current_type;
  348. }
  349. }
  350. /* retain count for new bios entries */
  351. new_nr = new_bios_entry;
  352. /* copy new bios mapping into original location */
  353. memcpy(biosmap, new_bios, new_nr * sizeof(struct e820entry));
  354. *pnr_map = new_nr;
  355. return 0;
  356. }
  357. static int __init __append_e820_map(struct e820entry *biosmap, int nr_map)
  358. {
  359. while (nr_map) {
  360. u64 start = biosmap->addr;
  361. u64 size = biosmap->size;
  362. u64 end = start + size;
  363. u32 type = biosmap->type;
  364. /* Overflow in 64 bits? Ignore the memory map. */
  365. if (start > end)
  366. return -1;
  367. e820_add_region(start, size, type);
  368. biosmap++;
  369. nr_map--;
  370. }
  371. return 0;
  372. }
  373. /*
  374. * Copy the BIOS e820 map into a safe place.
  375. *
  376. * Sanity-check it while we're at it..
  377. *
  378. * If we're lucky and live on a modern system, the setup code
  379. * will have given us a memory map that we can use to properly
  380. * set up memory. If we aren't, we'll fake a memory map.
  381. */
  382. static int __init append_e820_map(struct e820entry *biosmap, int nr_map)
  383. {
  384. /* Only one memory region (or negative)? Ignore it */
  385. if (nr_map < 2)
  386. return -1;
  387. return __append_e820_map(biosmap, nr_map);
  388. }
  389. static u64 __init __e820_update_range(struct e820map *e820x, u64 start,
  390. u64 size, unsigned old_type,
  391. unsigned new_type)
  392. {
  393. unsigned int i;
  394. u64 real_updated_size = 0;
  395. BUG_ON(old_type == new_type);
  396. if (size > (ULLONG_MAX - start))
  397. size = ULLONG_MAX - start;
  398. for (i = 0; i < e820x->nr_map; i++) {
  399. struct e820entry *ei = &e820x->map[i];
  400. u64 final_start, final_end;
  401. if (ei->type != old_type)
  402. continue;
  403. /* totally covered? */
  404. if (ei->addr >= start &&
  405. (ei->addr + ei->size) <= (start + size)) {
  406. ei->type = new_type;
  407. real_updated_size += ei->size;
  408. continue;
  409. }
  410. /* partially covered */
  411. final_start = max(start, ei->addr);
  412. final_end = min(start + size, ei->addr + ei->size);
  413. if (final_start >= final_end)
  414. continue;
  415. __e820_add_region(e820x, final_start, final_end - final_start,
  416. new_type);
  417. real_updated_size += final_end - final_start;
  418. /*
  419. * left range could be head or tail, so need to update
  420. * size at first.
  421. */
  422. ei->size -= final_end - final_start;
  423. if (ei->addr < final_start)
  424. continue;
  425. ei->addr = final_end;
  426. }
  427. return real_updated_size;
  428. }
  429. u64 __init e820_update_range(u64 start, u64 size, unsigned old_type,
  430. unsigned new_type)
  431. {
  432. return __e820_update_range(&e820, start, size, old_type, new_type);
  433. }
  434. static u64 __init e820_update_range_saved(u64 start, u64 size,
  435. unsigned old_type, unsigned new_type)
  436. {
  437. return __e820_update_range(&e820_saved, start, size, old_type,
  438. new_type);
  439. }
  440. /* make e820 not cover the range */
  441. u64 __init e820_remove_range(u64 start, u64 size, unsigned old_type,
  442. int checktype)
  443. {
  444. int i;
  445. u64 real_removed_size = 0;
  446. if (size > (ULLONG_MAX - start))
  447. size = ULLONG_MAX - start;
  448. for (i = 0; i < e820.nr_map; i++) {
  449. struct e820entry *ei = &e820.map[i];
  450. u64 final_start, final_end;
  451. if (checktype && ei->type != old_type)
  452. continue;
  453. /* totally covered? */
  454. if (ei->addr >= start &&
  455. (ei->addr + ei->size) <= (start + size)) {
  456. real_removed_size += ei->size;
  457. memset(ei, 0, sizeof(struct e820entry));
  458. continue;
  459. }
  460. /* partially covered */
  461. final_start = max(start, ei->addr);
  462. final_end = min(start + size, ei->addr + ei->size);
  463. if (final_start >= final_end)
  464. continue;
  465. real_removed_size += final_end - final_start;
  466. ei->size -= final_end - final_start;
  467. if (ei->addr < final_start)
  468. continue;
  469. ei->addr = final_end;
  470. }
  471. return real_removed_size;
  472. }
  473. void __init update_e820(void)
  474. {
  475. int nr_map;
  476. nr_map = e820.nr_map;
  477. if (sanitize_e820_map(e820.map, ARRAY_SIZE(e820.map), &nr_map))
  478. return;
  479. e820.nr_map = nr_map;
  480. printk(KERN_INFO "modified physical RAM map:\n");
  481. e820_print_map("modified");
  482. }
  483. static void __init update_e820_saved(void)
  484. {
  485. int nr_map;
  486. nr_map = e820_saved.nr_map;
  487. if (sanitize_e820_map(e820_saved.map, ARRAY_SIZE(e820_saved.map), &nr_map))
  488. return;
  489. e820_saved.nr_map = nr_map;
  490. }
  491. #define MAX_GAP_END 0x100000000ull
  492. /*
  493. * Search for a gap in the e820 memory space from start_addr to end_addr.
  494. */
  495. __init int e820_search_gap(unsigned long *gapstart, unsigned long *gapsize,
  496. unsigned long start_addr, unsigned long long end_addr)
  497. {
  498. unsigned long long last;
  499. int i = e820.nr_map;
  500. int found = 0;
  501. last = (end_addr && end_addr < MAX_GAP_END) ? end_addr : MAX_GAP_END;
  502. while (--i >= 0) {
  503. unsigned long long start = e820.map[i].addr;
  504. unsigned long long end = start + e820.map[i].size;
  505. if (end < start_addr)
  506. continue;
  507. /*
  508. * Since "last" is at most 4GB, we know we'll
  509. * fit in 32 bits if this condition is true
  510. */
  511. if (last > end) {
  512. unsigned long gap = last - end;
  513. if (gap >= *gapsize) {
  514. *gapsize = gap;
  515. *gapstart = end;
  516. found = 1;
  517. }
  518. }
  519. if (start < last)
  520. last = start;
  521. }
  522. return found;
  523. }
  524. /*
  525. * Search for the biggest gap in the low 32 bits of the e820
  526. * memory space. We pass this space to PCI to assign MMIO resources
  527. * for hotplug or unconfigured devices in.
  528. * Hopefully the BIOS let enough space left.
  529. */
  530. __init void e820_setup_gap(void)
  531. {
  532. unsigned long gapstart, gapsize, round;
  533. int found;
  534. gapstart = 0x10000000;
  535. gapsize = 0x400000;
  536. found = e820_search_gap(&gapstart, &gapsize, 0, MAX_GAP_END);
  537. #ifdef CONFIG_X86_64
  538. if (!found) {
  539. gapstart = (max_pfn << PAGE_SHIFT) + 1024*1024;
  540. printk(KERN_ERR "PCI: Warning: Cannot find a gap in the 32bit "
  541. "address range\n"
  542. KERN_ERR "PCI: Unassigned devices with 32bit resource "
  543. "registers may break!\n");
  544. }
  545. #endif
  546. /*
  547. * See how much we want to round up: start off with
  548. * rounding to the next 1MB area.
  549. */
  550. round = 0x100000;
  551. while ((gapsize >> 4) > round)
  552. round += round;
  553. /* Fun with two's complement */
  554. pci_mem_start = (gapstart + round) & -round;
  555. printk(KERN_INFO
  556. "Allocating PCI resources starting at %lx (gap: %lx:%lx)\n",
  557. pci_mem_start, gapstart, gapsize);
  558. }
  559. /**
  560. * Because of the size limitation of struct boot_params, only first
  561. * 128 E820 memory entries are passed to kernel via
  562. * boot_params.e820_map, others are passed via SETUP_E820_EXT node of
  563. * linked list of struct setup_data, which is parsed here.
  564. */
  565. void __init parse_e820_ext(struct setup_data *sdata, unsigned long pa_data)
  566. {
  567. u32 map_len;
  568. int entries;
  569. struct e820entry *extmap;
  570. entries = sdata->len / sizeof(struct e820entry);
  571. map_len = sdata->len + sizeof(struct setup_data);
  572. if (map_len > PAGE_SIZE)
  573. sdata = early_ioremap(pa_data, map_len);
  574. extmap = (struct e820entry *)(sdata->data);
  575. __append_e820_map(extmap, entries);
  576. sanitize_e820_map(e820.map, ARRAY_SIZE(e820.map), &e820.nr_map);
  577. if (map_len > PAGE_SIZE)
  578. early_iounmap(sdata, map_len);
  579. printk(KERN_INFO "extended physical RAM map:\n");
  580. e820_print_map("extended");
  581. }
  582. #if defined(CONFIG_X86_64) || \
  583. (defined(CONFIG_X86_32) && defined(CONFIG_HIBERNATION))
  584. /**
  585. * Find the ranges of physical addresses that do not correspond to
  586. * e820 RAM areas and mark the corresponding pages as nosave for
  587. * hibernation (32 bit) or software suspend and suspend to RAM (64 bit).
  588. *
  589. * This function requires the e820 map to be sorted and without any
  590. * overlapping entries and assumes the first e820 area to be RAM.
  591. */
  592. void __init e820_mark_nosave_regions(unsigned long limit_pfn)
  593. {
  594. int i;
  595. unsigned long pfn;
  596. pfn = PFN_DOWN(e820.map[0].addr + e820.map[0].size);
  597. for (i = 1; i < e820.nr_map; i++) {
  598. struct e820entry *ei = &e820.map[i];
  599. if (pfn < PFN_UP(ei->addr))
  600. register_nosave_region(pfn, PFN_UP(ei->addr));
  601. pfn = PFN_DOWN(ei->addr + ei->size);
  602. if (ei->type != E820_RAM && ei->type != E820_RESERVED_KERN)
  603. register_nosave_region(PFN_UP(ei->addr), pfn);
  604. if (pfn >= limit_pfn)
  605. break;
  606. }
  607. }
  608. #endif
  609. #ifdef CONFIG_HIBERNATION
  610. /**
  611. * Mark ACPI NVS memory region, so that we can save/restore it during
  612. * hibernation and the subsequent resume.
  613. */
  614. static int __init e820_mark_nvs_memory(void)
  615. {
  616. int i;
  617. for (i = 0; i < e820.nr_map; i++) {
  618. struct e820entry *ei = &e820.map[i];
  619. if (ei->type == E820_NVS)
  620. hibernate_nvs_register(ei->addr, ei->size);
  621. }
  622. return 0;
  623. }
  624. core_initcall(e820_mark_nvs_memory);
  625. #endif
  626. /*
  627. * Early reserved memory areas.
  628. */
  629. #define MAX_EARLY_RES 20
  630. struct early_res {
  631. u64 start, end;
  632. char name[16];
  633. char overlap_ok;
  634. };
  635. static struct early_res early_res[MAX_EARLY_RES] __initdata = {
  636. { 0, PAGE_SIZE, "BIOS data page" }, /* BIOS data page */
  637. {}
  638. };
  639. static int __init find_overlapped_early(u64 start, u64 end)
  640. {
  641. int i;
  642. struct early_res *r;
  643. for (i = 0; i < MAX_EARLY_RES && early_res[i].end; i++) {
  644. r = &early_res[i];
  645. if (end > r->start && start < r->end)
  646. break;
  647. }
  648. return i;
  649. }
  650. /*
  651. * Drop the i-th range from the early reservation map,
  652. * by copying any higher ranges down one over it, and
  653. * clearing what had been the last slot.
  654. */
  655. static void __init drop_range(int i)
  656. {
  657. int j;
  658. for (j = i + 1; j < MAX_EARLY_RES && early_res[j].end; j++)
  659. ;
  660. memmove(&early_res[i], &early_res[i + 1],
  661. (j - 1 - i) * sizeof(struct early_res));
  662. early_res[j - 1].end = 0;
  663. }
  664. /*
  665. * Split any existing ranges that:
  666. * 1) are marked 'overlap_ok', and
  667. * 2) overlap with the stated range [start, end)
  668. * into whatever portion (if any) of the existing range is entirely
  669. * below or entirely above the stated range. Drop the portion
  670. * of the existing range that overlaps with the stated range,
  671. * which will allow the caller of this routine to then add that
  672. * stated range without conflicting with any existing range.
  673. */
  674. static void __init drop_overlaps_that_are_ok(u64 start, u64 end)
  675. {
  676. int i;
  677. struct early_res *r;
  678. u64 lower_start, lower_end;
  679. u64 upper_start, upper_end;
  680. char name[16];
  681. for (i = 0; i < MAX_EARLY_RES && early_res[i].end; i++) {
  682. r = &early_res[i];
  683. /* Continue past non-overlapping ranges */
  684. if (end <= r->start || start >= r->end)
  685. continue;
  686. /*
  687. * Leave non-ok overlaps as is; let caller
  688. * panic "Overlapping early reservations"
  689. * when it hits this overlap.
  690. */
  691. if (!r->overlap_ok)
  692. return;
  693. /*
  694. * We have an ok overlap. We will drop it from the early
  695. * reservation map, and add back in any non-overlapping
  696. * portions (lower or upper) as separate, overlap_ok,
  697. * non-overlapping ranges.
  698. */
  699. /* 1. Note any non-overlapping (lower or upper) ranges. */
  700. strncpy(name, r->name, sizeof(name) - 1);
  701. lower_start = lower_end = 0;
  702. upper_start = upper_end = 0;
  703. if (r->start < start) {
  704. lower_start = r->start;
  705. lower_end = start;
  706. }
  707. if (r->end > end) {
  708. upper_start = end;
  709. upper_end = r->end;
  710. }
  711. /* 2. Drop the original ok overlapping range */
  712. drop_range(i);
  713. i--; /* resume for-loop on copied down entry */
  714. /* 3. Add back in any non-overlapping ranges. */
  715. if (lower_end)
  716. reserve_early_overlap_ok(lower_start, lower_end, name);
  717. if (upper_end)
  718. reserve_early_overlap_ok(upper_start, upper_end, name);
  719. }
  720. }
  721. static void __init __reserve_early(u64 start, u64 end, char *name,
  722. int overlap_ok)
  723. {
  724. int i;
  725. struct early_res *r;
  726. i = find_overlapped_early(start, end);
  727. if (i >= MAX_EARLY_RES)
  728. panic("Too many early reservations");
  729. r = &early_res[i];
  730. if (r->end)
  731. panic("Overlapping early reservations "
  732. "%llx-%llx %s to %llx-%llx %s\n",
  733. start, end - 1, name?name:"", r->start,
  734. r->end - 1, r->name);
  735. r->start = start;
  736. r->end = end;
  737. r->overlap_ok = overlap_ok;
  738. if (name)
  739. strncpy(r->name, name, sizeof(r->name) - 1);
  740. }
  741. /*
  742. * A few early reservtations come here.
  743. *
  744. * The 'overlap_ok' in the name of this routine does -not- mean it
  745. * is ok for these reservations to overlap an earlier reservation.
  746. * Rather it means that it is ok for subsequent reservations to
  747. * overlap this one.
  748. *
  749. * Use this entry point to reserve early ranges when you are doing
  750. * so out of "Paranoia", reserving perhaps more memory than you need,
  751. * just in case, and don't mind a subsequent overlapping reservation
  752. * that is known to be needed.
  753. *
  754. * The drop_overlaps_that_are_ok() call here isn't really needed.
  755. * It would be needed if we had two colliding 'overlap_ok'
  756. * reservations, so that the second such would not panic on the
  757. * overlap with the first. We don't have any such as of this
  758. * writing, but might as well tolerate such if it happens in
  759. * the future.
  760. */
  761. void __init reserve_early_overlap_ok(u64 start, u64 end, char *name)
  762. {
  763. drop_overlaps_that_are_ok(start, end);
  764. __reserve_early(start, end, name, 1);
  765. }
  766. /*
  767. * Most early reservations come here.
  768. *
  769. * We first have drop_overlaps_that_are_ok() drop any pre-existing
  770. * 'overlap_ok' ranges, so that we can then reserve this memory
  771. * range without risk of panic'ing on an overlapping overlap_ok
  772. * early reservation.
  773. */
  774. void __init reserve_early(u64 start, u64 end, char *name)
  775. {
  776. if (start >= end)
  777. return;
  778. drop_overlaps_that_are_ok(start, end);
  779. __reserve_early(start, end, name, 0);
  780. }
  781. void __init free_early(u64 start, u64 end)
  782. {
  783. struct early_res *r;
  784. int i;
  785. i = find_overlapped_early(start, end);
  786. r = &early_res[i];
  787. if (i >= MAX_EARLY_RES || r->end != end || r->start != start)
  788. panic("free_early on not reserved area: %llx-%llx!",
  789. start, end - 1);
  790. drop_range(i);
  791. }
  792. void __init early_res_to_bootmem(u64 start, u64 end)
  793. {
  794. int i, count;
  795. u64 final_start, final_end;
  796. count = 0;
  797. for (i = 0; i < MAX_EARLY_RES && early_res[i].end; i++)
  798. count++;
  799. printk(KERN_INFO "(%d early reservations) ==> bootmem [%010llx - %010llx]\n",
  800. count, start, end);
  801. for (i = 0; i < count; i++) {
  802. struct early_res *r = &early_res[i];
  803. printk(KERN_INFO " #%d [%010llx - %010llx] %16s", i,
  804. r->start, r->end, r->name);
  805. final_start = max(start, r->start);
  806. final_end = min(end, r->end);
  807. if (final_start >= final_end) {
  808. printk(KERN_CONT "\n");
  809. continue;
  810. }
  811. printk(KERN_CONT " ==> [%010llx - %010llx]\n",
  812. final_start, final_end);
  813. reserve_bootmem_generic(final_start, final_end - final_start,
  814. BOOTMEM_DEFAULT);
  815. }
  816. }
  817. /* Check for already reserved areas */
  818. static inline int __init bad_addr(u64 *addrp, u64 size, u64 align)
  819. {
  820. int i;
  821. u64 addr = *addrp;
  822. int changed = 0;
  823. struct early_res *r;
  824. again:
  825. i = find_overlapped_early(addr, addr + size);
  826. r = &early_res[i];
  827. if (i < MAX_EARLY_RES && r->end) {
  828. *addrp = addr = round_up(r->end, align);
  829. changed = 1;
  830. goto again;
  831. }
  832. return changed;
  833. }
  834. /* Check for already reserved areas */
  835. static inline int __init bad_addr_size(u64 *addrp, u64 *sizep, u64 align)
  836. {
  837. int i;
  838. u64 addr = *addrp, last;
  839. u64 size = *sizep;
  840. int changed = 0;
  841. again:
  842. last = addr + size;
  843. for (i = 0; i < MAX_EARLY_RES && early_res[i].end; i++) {
  844. struct early_res *r = &early_res[i];
  845. if (last > r->start && addr < r->start) {
  846. size = r->start - addr;
  847. changed = 1;
  848. goto again;
  849. }
  850. if (last > r->end && addr < r->end) {
  851. addr = round_up(r->end, align);
  852. size = last - addr;
  853. changed = 1;
  854. goto again;
  855. }
  856. if (last <= r->end && addr >= r->start) {
  857. (*sizep)++;
  858. return 0;
  859. }
  860. }
  861. if (changed) {
  862. *addrp = addr;
  863. *sizep = size;
  864. }
  865. return changed;
  866. }
  867. /*
  868. * Find a free area with specified alignment in a specific range.
  869. */
  870. u64 __init find_e820_area(u64 start, u64 end, u64 size, u64 align)
  871. {
  872. int i;
  873. for (i = 0; i < e820.nr_map; i++) {
  874. struct e820entry *ei = &e820.map[i];
  875. u64 addr, last;
  876. u64 ei_last;
  877. if (ei->type != E820_RAM)
  878. continue;
  879. addr = round_up(ei->addr, align);
  880. ei_last = ei->addr + ei->size;
  881. if (addr < start)
  882. addr = round_up(start, align);
  883. if (addr >= ei_last)
  884. continue;
  885. while (bad_addr(&addr, size, align) && addr+size <= ei_last)
  886. ;
  887. last = addr + size;
  888. if (last > ei_last)
  889. continue;
  890. if (last > end)
  891. continue;
  892. return addr;
  893. }
  894. return -1ULL;
  895. }
  896. /*
  897. * Find next free range after *start
  898. */
  899. u64 __init find_e820_area_size(u64 start, u64 *sizep, u64 align)
  900. {
  901. int i;
  902. for (i = 0; i < e820.nr_map; i++) {
  903. struct e820entry *ei = &e820.map[i];
  904. u64 addr, last;
  905. u64 ei_last;
  906. if (ei->type != E820_RAM)
  907. continue;
  908. addr = round_up(ei->addr, align);
  909. ei_last = ei->addr + ei->size;
  910. if (addr < start)
  911. addr = round_up(start, align);
  912. if (addr >= ei_last)
  913. continue;
  914. *sizep = ei_last - addr;
  915. while (bad_addr_size(&addr, sizep, align) &&
  916. addr + *sizep <= ei_last)
  917. ;
  918. last = addr + *sizep;
  919. if (last > ei_last)
  920. continue;
  921. return addr;
  922. }
  923. return -1ULL;
  924. }
  925. /*
  926. * pre allocated 4k and reserved it in e820
  927. */
  928. u64 __init early_reserve_e820(u64 startt, u64 sizet, u64 align)
  929. {
  930. u64 size = 0;
  931. u64 addr;
  932. u64 start;
  933. start = startt;
  934. while (size < sizet && (start + 1))
  935. start = find_e820_area_size(start, &size, align);
  936. if (size < sizet)
  937. return 0;
  938. #ifdef CONFIG_X86_32
  939. if (start >= MAXMEM)
  940. return 0;
  941. if (start + size > MAXMEM)
  942. size = MAXMEM - start;
  943. #endif
  944. addr = round_down(start + size - sizet, align);
  945. if (addr < start)
  946. return 0;
  947. e820_update_range(addr, sizet, E820_RAM, E820_RESERVED);
  948. e820_update_range_saved(addr, sizet, E820_RAM, E820_RESERVED);
  949. printk(KERN_INFO "update e820 for early_reserve_e820\n");
  950. update_e820();
  951. update_e820_saved();
  952. return addr;
  953. }
  954. #ifdef CONFIG_X86_32
  955. # ifdef CONFIG_X86_PAE
  956. # define MAX_ARCH_PFN (1ULL<<(36-PAGE_SHIFT))
  957. # else
  958. # define MAX_ARCH_PFN (1ULL<<(32-PAGE_SHIFT))
  959. # endif
  960. #else /* CONFIG_X86_32 */
  961. # define MAX_ARCH_PFN MAXMEM>>PAGE_SHIFT
  962. #endif
  963. /*
  964. * Find the highest page frame number we have available
  965. */
  966. static unsigned long __init e820_end_pfn(unsigned long limit_pfn, unsigned type)
  967. {
  968. int i;
  969. unsigned long last_pfn = 0;
  970. unsigned long max_arch_pfn = MAX_ARCH_PFN;
  971. for (i = 0; i < e820.nr_map; i++) {
  972. struct e820entry *ei = &e820.map[i];
  973. unsigned long start_pfn;
  974. unsigned long end_pfn;
  975. if (ei->type != type)
  976. continue;
  977. start_pfn = ei->addr >> PAGE_SHIFT;
  978. end_pfn = (ei->addr + ei->size) >> PAGE_SHIFT;
  979. if (start_pfn >= limit_pfn)
  980. continue;
  981. if (end_pfn > limit_pfn) {
  982. last_pfn = limit_pfn;
  983. break;
  984. }
  985. if (end_pfn > last_pfn)
  986. last_pfn = end_pfn;
  987. }
  988. if (last_pfn > max_arch_pfn)
  989. last_pfn = max_arch_pfn;
  990. printk(KERN_INFO "last_pfn = %#lx max_arch_pfn = %#lx\n",
  991. last_pfn, max_arch_pfn);
  992. return last_pfn;
  993. }
  994. unsigned long __init e820_end_of_ram_pfn(void)
  995. {
  996. return e820_end_pfn(MAX_ARCH_PFN, E820_RAM);
  997. }
  998. unsigned long __init e820_end_of_low_ram_pfn(void)
  999. {
  1000. return e820_end_pfn(1UL<<(32 - PAGE_SHIFT), E820_RAM);
  1001. }
  1002. /*
  1003. * Finds an active region in the address range from start_pfn to last_pfn and
  1004. * returns its range in ei_startpfn and ei_endpfn for the e820 entry.
  1005. */
  1006. int __init e820_find_active_region(const struct e820entry *ei,
  1007. unsigned long start_pfn,
  1008. unsigned long last_pfn,
  1009. unsigned long *ei_startpfn,
  1010. unsigned long *ei_endpfn)
  1011. {
  1012. u64 align = PAGE_SIZE;
  1013. *ei_startpfn = round_up(ei->addr, align) >> PAGE_SHIFT;
  1014. *ei_endpfn = round_down(ei->addr + ei->size, align) >> PAGE_SHIFT;
  1015. /* Skip map entries smaller than a page */
  1016. if (*ei_startpfn >= *ei_endpfn)
  1017. return 0;
  1018. /* Skip if map is outside the node */
  1019. if (ei->type != E820_RAM || *ei_endpfn <= start_pfn ||
  1020. *ei_startpfn >= last_pfn)
  1021. return 0;
  1022. /* Check for overlaps */
  1023. if (*ei_startpfn < start_pfn)
  1024. *ei_startpfn = start_pfn;
  1025. if (*ei_endpfn > last_pfn)
  1026. *ei_endpfn = last_pfn;
  1027. return 1;
  1028. }
  1029. /* Walk the e820 map and register active regions within a node */
  1030. void __init e820_register_active_regions(int nid, unsigned long start_pfn,
  1031. unsigned long last_pfn)
  1032. {
  1033. unsigned long ei_startpfn;
  1034. unsigned long ei_endpfn;
  1035. int i;
  1036. for (i = 0; i < e820.nr_map; i++)
  1037. if (e820_find_active_region(&e820.map[i],
  1038. start_pfn, last_pfn,
  1039. &ei_startpfn, &ei_endpfn))
  1040. add_active_range(nid, ei_startpfn, ei_endpfn);
  1041. }
  1042. /*
  1043. * Find the hole size (in bytes) in the memory range.
  1044. * @start: starting address of the memory range to scan
  1045. * @end: ending address of the memory range to scan
  1046. */
  1047. u64 __init e820_hole_size(u64 start, u64 end)
  1048. {
  1049. unsigned long start_pfn = start >> PAGE_SHIFT;
  1050. unsigned long last_pfn = end >> PAGE_SHIFT;
  1051. unsigned long ei_startpfn, ei_endpfn, ram = 0;
  1052. int i;
  1053. for (i = 0; i < e820.nr_map; i++) {
  1054. if (e820_find_active_region(&e820.map[i],
  1055. start_pfn, last_pfn,
  1056. &ei_startpfn, &ei_endpfn))
  1057. ram += ei_endpfn - ei_startpfn;
  1058. }
  1059. return end - start - ((u64)ram << PAGE_SHIFT);
  1060. }
  1061. static void early_panic(char *msg)
  1062. {
  1063. early_printk(msg);
  1064. panic(msg);
  1065. }
  1066. static int userdef __initdata;
  1067. /* "mem=nopentium" disables the 4MB page tables. */
  1068. static int __init parse_memopt(char *p)
  1069. {
  1070. u64 mem_size;
  1071. if (!p)
  1072. return -EINVAL;
  1073. #ifdef CONFIG_X86_32
  1074. if (!strcmp(p, "nopentium")) {
  1075. setup_clear_cpu_cap(X86_FEATURE_PSE);
  1076. return 0;
  1077. }
  1078. #endif
  1079. userdef = 1;
  1080. mem_size = memparse(p, &p);
  1081. e820_remove_range(mem_size, ULLONG_MAX - mem_size, E820_RAM, 1);
  1082. return 0;
  1083. }
  1084. early_param("mem", parse_memopt);
  1085. static int __init parse_memmap_opt(char *p)
  1086. {
  1087. char *oldp;
  1088. u64 start_at, mem_size;
  1089. if (!p)
  1090. return -EINVAL;
  1091. if (!strncmp(p, "exactmap", 8)) {
  1092. #ifdef CONFIG_CRASH_DUMP
  1093. /*
  1094. * If we are doing a crash dump, we still need to know
  1095. * the real mem size before original memory map is
  1096. * reset.
  1097. */
  1098. saved_max_pfn = e820_end_of_ram_pfn();
  1099. #endif
  1100. e820.nr_map = 0;
  1101. userdef = 1;
  1102. return 0;
  1103. }
  1104. oldp = p;
  1105. mem_size = memparse(p, &p);
  1106. if (p == oldp)
  1107. return -EINVAL;
  1108. userdef = 1;
  1109. if (*p == '@') {
  1110. start_at = memparse(p+1, &p);
  1111. e820_add_region(start_at, mem_size, E820_RAM);
  1112. } else if (*p == '#') {
  1113. start_at = memparse(p+1, &p);
  1114. e820_add_region(start_at, mem_size, E820_ACPI);
  1115. } else if (*p == '$') {
  1116. start_at = memparse(p+1, &p);
  1117. e820_add_region(start_at, mem_size, E820_RESERVED);
  1118. } else
  1119. e820_remove_range(mem_size, ULLONG_MAX - mem_size, E820_RAM, 1);
  1120. return *p == '\0' ? 0 : -EINVAL;
  1121. }
  1122. early_param("memmap", parse_memmap_opt);
  1123. void __init finish_e820_parsing(void)
  1124. {
  1125. if (userdef) {
  1126. int nr = e820.nr_map;
  1127. if (sanitize_e820_map(e820.map, ARRAY_SIZE(e820.map), &nr) < 0)
  1128. early_panic("Invalid user supplied memory map");
  1129. e820.nr_map = nr;
  1130. printk(KERN_INFO "user-defined physical RAM map:\n");
  1131. e820_print_map("user");
  1132. }
  1133. }
  1134. static inline const char *e820_type_to_string(int e820_type)
  1135. {
  1136. switch (e820_type) {
  1137. case E820_RESERVED_KERN:
  1138. case E820_RAM: return "System RAM";
  1139. case E820_ACPI: return "ACPI Tables";
  1140. case E820_NVS: return "ACPI Non-volatile Storage";
  1141. case E820_UNUSABLE: return "Unusable memory";
  1142. default: return "reserved";
  1143. }
  1144. }
  1145. /*
  1146. * Mark e820 reserved areas as busy for the resource manager.
  1147. */
  1148. static struct resource __initdata *e820_res;
  1149. void __init e820_reserve_resources(void)
  1150. {
  1151. int i;
  1152. struct resource *res;
  1153. u64 end;
  1154. res = alloc_bootmem_low(sizeof(struct resource) * e820.nr_map);
  1155. e820_res = res;
  1156. for (i = 0; i < e820.nr_map; i++) {
  1157. end = e820.map[i].addr + e820.map[i].size - 1;
  1158. if (end != (resource_size_t)end) {
  1159. res++;
  1160. continue;
  1161. }
  1162. res->name = e820_type_to_string(e820.map[i].type);
  1163. res->start = e820.map[i].addr;
  1164. res->end = end;
  1165. res->flags = IORESOURCE_MEM;
  1166. /*
  1167. * don't register the region that could be conflicted with
  1168. * pci device BAR resource and insert them later in
  1169. * pcibios_resource_survey()
  1170. */
  1171. if (e820.map[i].type != E820_RESERVED || res->start < (1ULL<<20)) {
  1172. res->flags |= IORESOURCE_BUSY;
  1173. insert_resource(&iomem_resource, res);
  1174. }
  1175. res++;
  1176. }
  1177. for (i = 0; i < e820_saved.nr_map; i++) {
  1178. struct e820entry *entry = &e820_saved.map[i];
  1179. firmware_map_add_early(entry->addr,
  1180. entry->addr + entry->size - 1,
  1181. e820_type_to_string(entry->type));
  1182. }
  1183. }
  1184. void __init e820_reserve_resources_late(void)
  1185. {
  1186. int i;
  1187. struct resource *res;
  1188. res = e820_res;
  1189. for (i = 0; i < e820.nr_map; i++) {
  1190. if (!res->parent && res->end)
  1191. insert_resource_expand_to_fit(&iomem_resource, res);
  1192. res++;
  1193. }
  1194. }
  1195. char *__init default_machine_specific_memory_setup(void)
  1196. {
  1197. char *who = "BIOS-e820";
  1198. int new_nr;
  1199. /*
  1200. * Try to copy the BIOS-supplied E820-map.
  1201. *
  1202. * Otherwise fake a memory map; one section from 0k->640k,
  1203. * the next section from 1mb->appropriate_mem_k
  1204. */
  1205. new_nr = boot_params.e820_entries;
  1206. sanitize_e820_map(boot_params.e820_map,
  1207. ARRAY_SIZE(boot_params.e820_map),
  1208. &new_nr);
  1209. boot_params.e820_entries = new_nr;
  1210. if (append_e820_map(boot_params.e820_map, boot_params.e820_entries)
  1211. < 0) {
  1212. u64 mem_size;
  1213. /* compare results from other methods and take the greater */
  1214. if (boot_params.alt_mem_k
  1215. < boot_params.screen_info.ext_mem_k) {
  1216. mem_size = boot_params.screen_info.ext_mem_k;
  1217. who = "BIOS-88";
  1218. } else {
  1219. mem_size = boot_params.alt_mem_k;
  1220. who = "BIOS-e801";
  1221. }
  1222. e820.nr_map = 0;
  1223. e820_add_region(0, LOWMEMSIZE(), E820_RAM);
  1224. e820_add_region(HIGH_MEMORY, mem_size << 10, E820_RAM);
  1225. }
  1226. /* In case someone cares... */
  1227. return who;
  1228. }
  1229. char *__init __attribute__((weak)) machine_specific_memory_setup(void)
  1230. {
  1231. if (x86_quirks->arch_memory_setup) {
  1232. char *who = x86_quirks->arch_memory_setup();
  1233. if (who)
  1234. return who;
  1235. }
  1236. return default_machine_specific_memory_setup();
  1237. }
  1238. /* Overridden in paravirt.c if CONFIG_PARAVIRT */
  1239. char * __init __attribute__((weak)) memory_setup(void)
  1240. {
  1241. return machine_specific_memory_setup();
  1242. }
  1243. void __init setup_memory_map(void)
  1244. {
  1245. char *who;
  1246. who = memory_setup();
  1247. memcpy(&e820_saved, &e820, sizeof(struct e820map));
  1248. printk(KERN_INFO "BIOS-provided physical RAM map:\n");
  1249. e820_print_map(who);
  1250. }