e820.c 35 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094109510961097109810991100110111021103110411051106110711081109111011111112111311141115111611171118111911201121112211231124112511261127112811291130113111321133113411351136113711381139114011411142114311441145114611471148114911501151115211531154115511561157115811591160116111621163116411651166116711681169117011711172117311741175117611771178117911801181118211831184118511861187118811891190119111921193119411951196119711981199120012011202120312041205120612071208120912101211121212131214121512161217121812191220122112221223122412251226122712281229123012311232123312341235123612371238123912401241124212431244124512461247124812491250125112521253125412551256125712581259126012611262126312641265126612671268126912701271127212731274127512761277127812791280128112821283128412851286128712881289129012911292129312941295129612971298129913001301130213031304130513061307130813091310131113121313131413151316131713181319132013211322132313241325132613271328132913301331133213331334133513361337133813391340134113421343134413451346134713481349135013511352135313541355135613571358135913601361136213631364136513661367136813691370137113721373137413751376137713781379138013811382138313841385138613871388138913901391
  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. /*
  601. * Early reserved memory areas.
  602. */
  603. #define MAX_EARLY_RES 20
  604. struct early_res {
  605. u64 start, end;
  606. char name[16];
  607. char overlap_ok;
  608. };
  609. static struct early_res early_res[MAX_EARLY_RES] __initdata = {
  610. { 0, PAGE_SIZE, "BIOS data page" }, /* BIOS data page */
  611. #if defined(CONFIG_X86_64) && defined(CONFIG_X86_TRAMPOLINE)
  612. { TRAMPOLINE_BASE, TRAMPOLINE_BASE + 2 * PAGE_SIZE, "TRAMPOLINE" },
  613. #endif
  614. #if defined(CONFIG_X86_32) && defined(CONFIG_SMP)
  615. /*
  616. * But first pinch a few for the stack/trampoline stuff
  617. * FIXME: Don't need the extra page at 4K, but need to fix
  618. * trampoline before removing it. (see the GDT stuff)
  619. */
  620. { PAGE_SIZE, PAGE_SIZE + PAGE_SIZE, "EX TRAMPOLINE" },
  621. /*
  622. * Has to be in very low memory so we can execute
  623. * real-mode AP code.
  624. */
  625. { TRAMPOLINE_BASE, TRAMPOLINE_BASE + PAGE_SIZE, "TRAMPOLINE" },
  626. #endif
  627. {}
  628. };
  629. static int __init find_overlapped_early(u64 start, u64 end)
  630. {
  631. int i;
  632. struct early_res *r;
  633. for (i = 0; i < MAX_EARLY_RES && early_res[i].end; i++) {
  634. r = &early_res[i];
  635. if (end > r->start && start < r->end)
  636. break;
  637. }
  638. return i;
  639. }
  640. /*
  641. * Drop the i-th range from the early reservation map,
  642. * by copying any higher ranges down one over it, and
  643. * clearing what had been the last slot.
  644. */
  645. static void __init drop_range(int i)
  646. {
  647. int j;
  648. for (j = i + 1; j < MAX_EARLY_RES && early_res[j].end; j++)
  649. ;
  650. memmove(&early_res[i], &early_res[i + 1],
  651. (j - 1 - i) * sizeof(struct early_res));
  652. early_res[j - 1].end = 0;
  653. }
  654. /*
  655. * Split any existing ranges that:
  656. * 1) are marked 'overlap_ok', and
  657. * 2) overlap with the stated range [start, end)
  658. * into whatever portion (if any) of the existing range is entirely
  659. * below or entirely above the stated range. Drop the portion
  660. * of the existing range that overlaps with the stated range,
  661. * which will allow the caller of this routine to then add that
  662. * stated range without conflicting with any existing range.
  663. */
  664. static void __init drop_overlaps_that_are_ok(u64 start, u64 end)
  665. {
  666. int i;
  667. struct early_res *r;
  668. u64 lower_start, lower_end;
  669. u64 upper_start, upper_end;
  670. char name[16];
  671. for (i = 0; i < MAX_EARLY_RES && early_res[i].end; i++) {
  672. r = &early_res[i];
  673. /* Continue past non-overlapping ranges */
  674. if (end <= r->start || start >= r->end)
  675. continue;
  676. /*
  677. * Leave non-ok overlaps as is; let caller
  678. * panic "Overlapping early reservations"
  679. * when it hits this overlap.
  680. */
  681. if (!r->overlap_ok)
  682. return;
  683. /*
  684. * We have an ok overlap. We will drop it from the early
  685. * reservation map, and add back in any non-overlapping
  686. * portions (lower or upper) as separate, overlap_ok,
  687. * non-overlapping ranges.
  688. */
  689. /* 1. Note any non-overlapping (lower or upper) ranges. */
  690. strncpy(name, r->name, sizeof(name) - 1);
  691. lower_start = lower_end = 0;
  692. upper_start = upper_end = 0;
  693. if (r->start < start) {
  694. lower_start = r->start;
  695. lower_end = start;
  696. }
  697. if (r->end > end) {
  698. upper_start = end;
  699. upper_end = r->end;
  700. }
  701. /* 2. Drop the original ok overlapping range */
  702. drop_range(i);
  703. i--; /* resume for-loop on copied down entry */
  704. /* 3. Add back in any non-overlapping ranges. */
  705. if (lower_end)
  706. reserve_early_overlap_ok(lower_start, lower_end, name);
  707. if (upper_end)
  708. reserve_early_overlap_ok(upper_start, upper_end, name);
  709. }
  710. }
  711. static void __init __reserve_early(u64 start, u64 end, char *name,
  712. int overlap_ok)
  713. {
  714. int i;
  715. struct early_res *r;
  716. i = find_overlapped_early(start, end);
  717. if (i >= MAX_EARLY_RES)
  718. panic("Too many early reservations");
  719. r = &early_res[i];
  720. if (r->end)
  721. panic("Overlapping early reservations "
  722. "%llx-%llx %s to %llx-%llx %s\n",
  723. start, end - 1, name?name:"", r->start,
  724. r->end - 1, r->name);
  725. r->start = start;
  726. r->end = end;
  727. r->overlap_ok = overlap_ok;
  728. if (name)
  729. strncpy(r->name, name, sizeof(r->name) - 1);
  730. }
  731. /*
  732. * A few early reservtations come here.
  733. *
  734. * The 'overlap_ok' in the name of this routine does -not- mean it
  735. * is ok for these reservations to overlap an earlier reservation.
  736. * Rather it means that it is ok for subsequent reservations to
  737. * overlap this one.
  738. *
  739. * Use this entry point to reserve early ranges when you are doing
  740. * so out of "Paranoia", reserving perhaps more memory than you need,
  741. * just in case, and don't mind a subsequent overlapping reservation
  742. * that is known to be needed.
  743. *
  744. * The drop_overlaps_that_are_ok() call here isn't really needed.
  745. * It would be needed if we had two colliding 'overlap_ok'
  746. * reservations, so that the second such would not panic on the
  747. * overlap with the first. We don't have any such as of this
  748. * writing, but might as well tolerate such if it happens in
  749. * the future.
  750. */
  751. void __init reserve_early_overlap_ok(u64 start, u64 end, char *name)
  752. {
  753. drop_overlaps_that_are_ok(start, end);
  754. __reserve_early(start, end, name, 1);
  755. }
  756. /*
  757. * Most early reservations come here.
  758. *
  759. * We first have drop_overlaps_that_are_ok() drop any pre-existing
  760. * 'overlap_ok' ranges, so that we can then reserve this memory
  761. * range without risk of panic'ing on an overlapping overlap_ok
  762. * early reservation.
  763. */
  764. void __init reserve_early(u64 start, u64 end, char *name)
  765. {
  766. drop_overlaps_that_are_ok(start, end);
  767. __reserve_early(start, end, name, 0);
  768. }
  769. void __init free_early(u64 start, u64 end)
  770. {
  771. struct early_res *r;
  772. int i;
  773. i = find_overlapped_early(start, end);
  774. r = &early_res[i];
  775. if (i >= MAX_EARLY_RES || r->end != end || r->start != start)
  776. panic("free_early on not reserved area: %llx-%llx!",
  777. start, end - 1);
  778. drop_range(i);
  779. }
  780. void __init early_res_to_bootmem(u64 start, u64 end)
  781. {
  782. int i, count;
  783. u64 final_start, final_end;
  784. count = 0;
  785. for (i = 0; i < MAX_EARLY_RES && early_res[i].end; i++)
  786. count++;
  787. printk(KERN_INFO "(%d early reservations) ==> bootmem [%010llx - %010llx]\n",
  788. count, start, end);
  789. for (i = 0; i < count; i++) {
  790. struct early_res *r = &early_res[i];
  791. printk(KERN_INFO " #%d [%010llx - %010llx] %16s", i,
  792. r->start, r->end, r->name);
  793. final_start = max(start, r->start);
  794. final_end = min(end, r->end);
  795. if (final_start >= final_end) {
  796. printk(KERN_CONT "\n");
  797. continue;
  798. }
  799. printk(KERN_CONT " ==> [%010llx - %010llx]\n",
  800. final_start, final_end);
  801. reserve_bootmem_generic(final_start, final_end - final_start,
  802. BOOTMEM_DEFAULT);
  803. }
  804. }
  805. /* Check for already reserved areas */
  806. static inline int __init bad_addr(u64 *addrp, u64 size, u64 align)
  807. {
  808. int i;
  809. u64 addr = *addrp;
  810. int changed = 0;
  811. struct early_res *r;
  812. again:
  813. i = find_overlapped_early(addr, addr + size);
  814. r = &early_res[i];
  815. if (i < MAX_EARLY_RES && r->end) {
  816. *addrp = addr = round_up(r->end, align);
  817. changed = 1;
  818. goto again;
  819. }
  820. return changed;
  821. }
  822. /* Check for already reserved areas */
  823. static inline int __init bad_addr_size(u64 *addrp, u64 *sizep, u64 align)
  824. {
  825. int i;
  826. u64 addr = *addrp, last;
  827. u64 size = *sizep;
  828. int changed = 0;
  829. again:
  830. last = addr + size;
  831. for (i = 0; i < MAX_EARLY_RES && early_res[i].end; i++) {
  832. struct early_res *r = &early_res[i];
  833. if (last > r->start && addr < r->start) {
  834. size = r->start - addr;
  835. changed = 1;
  836. goto again;
  837. }
  838. if (last > r->end && addr < r->end) {
  839. addr = round_up(r->end, align);
  840. size = last - addr;
  841. changed = 1;
  842. goto again;
  843. }
  844. if (last <= r->end && addr >= r->start) {
  845. (*sizep)++;
  846. return 0;
  847. }
  848. }
  849. if (changed) {
  850. *addrp = addr;
  851. *sizep = size;
  852. }
  853. return changed;
  854. }
  855. /*
  856. * Find a free area with specified alignment in a specific range.
  857. */
  858. u64 __init find_e820_area(u64 start, u64 end, u64 size, u64 align)
  859. {
  860. int i;
  861. for (i = 0; i < e820.nr_map; i++) {
  862. struct e820entry *ei = &e820.map[i];
  863. u64 addr, last;
  864. u64 ei_last;
  865. if (ei->type != E820_RAM)
  866. continue;
  867. addr = round_up(ei->addr, align);
  868. ei_last = ei->addr + ei->size;
  869. if (addr < start)
  870. addr = round_up(start, align);
  871. if (addr >= ei_last)
  872. continue;
  873. while (bad_addr(&addr, size, align) && addr+size <= ei_last)
  874. ;
  875. last = addr + size;
  876. if (last > ei_last)
  877. continue;
  878. if (last > end)
  879. continue;
  880. return addr;
  881. }
  882. return -1ULL;
  883. }
  884. /*
  885. * Find next free range after *start
  886. */
  887. u64 __init find_e820_area_size(u64 start, u64 *sizep, u64 align)
  888. {
  889. int i;
  890. for (i = 0; i < e820.nr_map; i++) {
  891. struct e820entry *ei = &e820.map[i];
  892. u64 addr, last;
  893. u64 ei_last;
  894. if (ei->type != E820_RAM)
  895. continue;
  896. addr = round_up(ei->addr, align);
  897. ei_last = ei->addr + ei->size;
  898. if (addr < start)
  899. addr = round_up(start, align);
  900. if (addr >= ei_last)
  901. continue;
  902. *sizep = ei_last - addr;
  903. while (bad_addr_size(&addr, sizep, align) &&
  904. addr + *sizep <= ei_last)
  905. ;
  906. last = addr + *sizep;
  907. if (last > ei_last)
  908. continue;
  909. return addr;
  910. }
  911. return -1UL;
  912. }
  913. /*
  914. * pre allocated 4k and reserved it in e820
  915. */
  916. u64 __init early_reserve_e820(u64 startt, u64 sizet, u64 align)
  917. {
  918. u64 size = 0;
  919. u64 addr;
  920. u64 start;
  921. start = startt;
  922. while (size < sizet)
  923. start = find_e820_area_size(start, &size, align);
  924. if (size < sizet)
  925. return 0;
  926. addr = round_down(start + size - sizet, align);
  927. e820_update_range(addr, sizet, E820_RAM, E820_RESERVED);
  928. e820_update_range_saved(addr, sizet, E820_RAM, E820_RESERVED);
  929. printk(KERN_INFO "update e820 for early_reserve_e820\n");
  930. update_e820();
  931. update_e820_saved();
  932. return addr;
  933. }
  934. #ifdef CONFIG_X86_32
  935. # ifdef CONFIG_X86_PAE
  936. # define MAX_ARCH_PFN (1ULL<<(36-PAGE_SHIFT))
  937. # else
  938. # define MAX_ARCH_PFN (1ULL<<(32-PAGE_SHIFT))
  939. # endif
  940. #else /* CONFIG_X86_32 */
  941. # define MAX_ARCH_PFN MAXMEM>>PAGE_SHIFT
  942. #endif
  943. /*
  944. * Find the highest page frame number we have available
  945. */
  946. static unsigned long __init e820_end_pfn(unsigned long limit_pfn, unsigned type)
  947. {
  948. int i;
  949. unsigned long last_pfn = 0;
  950. unsigned long max_arch_pfn = MAX_ARCH_PFN;
  951. for (i = 0; i < e820.nr_map; i++) {
  952. struct e820entry *ei = &e820.map[i];
  953. unsigned long start_pfn;
  954. unsigned long end_pfn;
  955. if (ei->type != type)
  956. continue;
  957. start_pfn = ei->addr >> PAGE_SHIFT;
  958. end_pfn = (ei->addr + ei->size) >> PAGE_SHIFT;
  959. if (start_pfn >= limit_pfn)
  960. continue;
  961. if (end_pfn > limit_pfn) {
  962. last_pfn = limit_pfn;
  963. break;
  964. }
  965. if (end_pfn > last_pfn)
  966. last_pfn = end_pfn;
  967. }
  968. if (last_pfn > max_arch_pfn)
  969. last_pfn = max_arch_pfn;
  970. printk(KERN_INFO "last_pfn = %#lx max_arch_pfn = %#lx\n",
  971. last_pfn, max_arch_pfn);
  972. return last_pfn;
  973. }
  974. unsigned long __init e820_end_of_ram_pfn(void)
  975. {
  976. return e820_end_pfn(MAX_ARCH_PFN, E820_RAM);
  977. }
  978. unsigned long __init e820_end_of_low_ram_pfn(void)
  979. {
  980. return e820_end_pfn(1UL<<(32 - PAGE_SHIFT), E820_RAM);
  981. }
  982. /*
  983. * Finds an active region in the address range from start_pfn to last_pfn and
  984. * returns its range in ei_startpfn and ei_endpfn for the e820 entry.
  985. */
  986. int __init e820_find_active_region(const struct e820entry *ei,
  987. unsigned long start_pfn,
  988. unsigned long last_pfn,
  989. unsigned long *ei_startpfn,
  990. unsigned long *ei_endpfn)
  991. {
  992. u64 align = PAGE_SIZE;
  993. *ei_startpfn = round_up(ei->addr, align) >> PAGE_SHIFT;
  994. *ei_endpfn = round_down(ei->addr + ei->size, align) >> PAGE_SHIFT;
  995. /* Skip map entries smaller than a page */
  996. if (*ei_startpfn >= *ei_endpfn)
  997. return 0;
  998. /* Skip if map is outside the node */
  999. if (ei->type != E820_RAM || *ei_endpfn <= start_pfn ||
  1000. *ei_startpfn >= last_pfn)
  1001. return 0;
  1002. /* Check for overlaps */
  1003. if (*ei_startpfn < start_pfn)
  1004. *ei_startpfn = start_pfn;
  1005. if (*ei_endpfn > last_pfn)
  1006. *ei_endpfn = last_pfn;
  1007. return 1;
  1008. }
  1009. /* Walk the e820 map and register active regions within a node */
  1010. void __init e820_register_active_regions(int nid, unsigned long start_pfn,
  1011. unsigned long last_pfn)
  1012. {
  1013. unsigned long ei_startpfn;
  1014. unsigned long ei_endpfn;
  1015. int i;
  1016. for (i = 0; i < e820.nr_map; i++)
  1017. if (e820_find_active_region(&e820.map[i],
  1018. start_pfn, last_pfn,
  1019. &ei_startpfn, &ei_endpfn))
  1020. add_active_range(nid, ei_startpfn, ei_endpfn);
  1021. }
  1022. /*
  1023. * Find the hole size (in bytes) in the memory range.
  1024. * @start: starting address of the memory range to scan
  1025. * @end: ending address of the memory range to scan
  1026. */
  1027. u64 __init e820_hole_size(u64 start, u64 end)
  1028. {
  1029. unsigned long start_pfn = start >> PAGE_SHIFT;
  1030. unsigned long last_pfn = end >> PAGE_SHIFT;
  1031. unsigned long ei_startpfn, ei_endpfn, ram = 0;
  1032. int i;
  1033. for (i = 0; i < e820.nr_map; i++) {
  1034. if (e820_find_active_region(&e820.map[i],
  1035. start_pfn, last_pfn,
  1036. &ei_startpfn, &ei_endpfn))
  1037. ram += ei_endpfn - ei_startpfn;
  1038. }
  1039. return end - start - ((u64)ram << PAGE_SHIFT);
  1040. }
  1041. static void early_panic(char *msg)
  1042. {
  1043. early_printk(msg);
  1044. panic(msg);
  1045. }
  1046. static int userdef __initdata;
  1047. /* "mem=nopentium" disables the 4MB page tables. */
  1048. static int __init parse_memopt(char *p)
  1049. {
  1050. u64 mem_size;
  1051. if (!p)
  1052. return -EINVAL;
  1053. #ifdef CONFIG_X86_32
  1054. if (!strcmp(p, "nopentium")) {
  1055. setup_clear_cpu_cap(X86_FEATURE_PSE);
  1056. return 0;
  1057. }
  1058. #endif
  1059. userdef = 1;
  1060. mem_size = memparse(p, &p);
  1061. e820_remove_range(mem_size, ULLONG_MAX - mem_size, E820_RAM, 1);
  1062. return 0;
  1063. }
  1064. early_param("mem", parse_memopt);
  1065. static int __init parse_memmap_opt(char *p)
  1066. {
  1067. char *oldp;
  1068. u64 start_at, mem_size;
  1069. if (!p)
  1070. return -EINVAL;
  1071. if (!strncmp(p, "exactmap", 8)) {
  1072. #ifdef CONFIG_CRASH_DUMP
  1073. /*
  1074. * If we are doing a crash dump, we still need to know
  1075. * the real mem size before original memory map is
  1076. * reset.
  1077. */
  1078. saved_max_pfn = e820_end_of_ram_pfn();
  1079. #endif
  1080. e820.nr_map = 0;
  1081. userdef = 1;
  1082. return 0;
  1083. }
  1084. oldp = p;
  1085. mem_size = memparse(p, &p);
  1086. if (p == oldp)
  1087. return -EINVAL;
  1088. userdef = 1;
  1089. if (*p == '@') {
  1090. start_at = memparse(p+1, &p);
  1091. e820_add_region(start_at, mem_size, E820_RAM);
  1092. } else if (*p == '#') {
  1093. start_at = memparse(p+1, &p);
  1094. e820_add_region(start_at, mem_size, E820_ACPI);
  1095. } else if (*p == '$') {
  1096. start_at = memparse(p+1, &p);
  1097. e820_add_region(start_at, mem_size, E820_RESERVED);
  1098. } else
  1099. e820_remove_range(mem_size, ULLONG_MAX - mem_size, E820_RAM, 1);
  1100. return *p == '\0' ? 0 : -EINVAL;
  1101. }
  1102. early_param("memmap", parse_memmap_opt);
  1103. void __init finish_e820_parsing(void)
  1104. {
  1105. if (userdef) {
  1106. int nr = e820.nr_map;
  1107. if (sanitize_e820_map(e820.map, ARRAY_SIZE(e820.map), &nr) < 0)
  1108. early_panic("Invalid user supplied memory map");
  1109. e820.nr_map = nr;
  1110. printk(KERN_INFO "user-defined physical RAM map:\n");
  1111. e820_print_map("user");
  1112. }
  1113. }
  1114. static inline const char *e820_type_to_string(int e820_type)
  1115. {
  1116. switch (e820_type) {
  1117. case E820_RESERVED_KERN:
  1118. case E820_RAM: return "System RAM";
  1119. case E820_ACPI: return "ACPI Tables";
  1120. case E820_NVS: return "ACPI Non-volatile Storage";
  1121. case E820_UNUSABLE: return "Unusable memory";
  1122. default: return "reserved";
  1123. }
  1124. }
  1125. /*
  1126. * Mark e820 reserved areas as busy for the resource manager.
  1127. */
  1128. static struct resource __initdata *e820_res;
  1129. void __init e820_reserve_resources(void)
  1130. {
  1131. int i;
  1132. struct resource *res;
  1133. u64 end;
  1134. res = alloc_bootmem_low(sizeof(struct resource) * e820.nr_map);
  1135. e820_res = res;
  1136. for (i = 0; i < e820.nr_map; i++) {
  1137. end = e820.map[i].addr + e820.map[i].size - 1;
  1138. if (end != (resource_size_t)end) {
  1139. res++;
  1140. continue;
  1141. }
  1142. res->name = e820_type_to_string(e820.map[i].type);
  1143. res->start = e820.map[i].addr;
  1144. res->end = end;
  1145. res->flags = IORESOURCE_MEM;
  1146. /*
  1147. * don't register the region that could be conflicted with
  1148. * pci device BAR resource and insert them later in
  1149. * pcibios_resource_survey()
  1150. */
  1151. if (e820.map[i].type != E820_RESERVED || res->start < (1ULL<<20)) {
  1152. res->flags |= IORESOURCE_BUSY;
  1153. insert_resource(&iomem_resource, res);
  1154. }
  1155. res++;
  1156. }
  1157. for (i = 0; i < e820_saved.nr_map; i++) {
  1158. struct e820entry *entry = &e820_saved.map[i];
  1159. firmware_map_add_early(entry->addr,
  1160. entry->addr + entry->size - 1,
  1161. e820_type_to_string(entry->type));
  1162. }
  1163. }
  1164. void __init e820_reserve_resources_late(void)
  1165. {
  1166. int i;
  1167. struct resource *res;
  1168. res = e820_res;
  1169. for (i = 0; i < e820.nr_map; i++) {
  1170. if (!res->parent && res->end)
  1171. insert_resource_expand_to_fit(&iomem_resource, res);
  1172. res++;
  1173. }
  1174. }
  1175. char *__init default_machine_specific_memory_setup(void)
  1176. {
  1177. char *who = "BIOS-e820";
  1178. int new_nr;
  1179. /*
  1180. * Try to copy the BIOS-supplied E820-map.
  1181. *
  1182. * Otherwise fake a memory map; one section from 0k->640k,
  1183. * the next section from 1mb->appropriate_mem_k
  1184. */
  1185. new_nr = boot_params.e820_entries;
  1186. sanitize_e820_map(boot_params.e820_map,
  1187. ARRAY_SIZE(boot_params.e820_map),
  1188. &new_nr);
  1189. boot_params.e820_entries = new_nr;
  1190. if (append_e820_map(boot_params.e820_map, boot_params.e820_entries)
  1191. < 0) {
  1192. u64 mem_size;
  1193. /* compare results from other methods and take the greater */
  1194. if (boot_params.alt_mem_k
  1195. < boot_params.screen_info.ext_mem_k) {
  1196. mem_size = boot_params.screen_info.ext_mem_k;
  1197. who = "BIOS-88";
  1198. } else {
  1199. mem_size = boot_params.alt_mem_k;
  1200. who = "BIOS-e801";
  1201. }
  1202. e820.nr_map = 0;
  1203. e820_add_region(0, LOWMEMSIZE(), E820_RAM);
  1204. e820_add_region(HIGH_MEMORY, mem_size << 10, E820_RAM);
  1205. }
  1206. /* In case someone cares... */
  1207. return who;
  1208. }
  1209. char *__init __attribute__((weak)) machine_specific_memory_setup(void)
  1210. {
  1211. if (x86_quirks->arch_memory_setup) {
  1212. char *who = x86_quirks->arch_memory_setup();
  1213. if (who)
  1214. return who;
  1215. }
  1216. return default_machine_specific_memory_setup();
  1217. }
  1218. /* Overridden in paravirt.c if CONFIG_PARAVIRT */
  1219. char * __init __attribute__((weak)) memory_setup(void)
  1220. {
  1221. return machine_specific_memory_setup();
  1222. }
  1223. void __init setup_memory_map(void)
  1224. {
  1225. char *who;
  1226. who = memory_setup();
  1227. memcpy(&e820_saved, &e820, sizeof(struct e820map));
  1228. printk(KERN_INFO "BIOS-provided physical RAM map:\n");
  1229. e820_print_map(who);
  1230. }