e820.c 35 KB

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