e820_64.c 19 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725
  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/suspend.h>
  21. #include <linux/pfn.h>
  22. #include <asm/pgtable.h>
  23. #include <asm/page.h>
  24. #include <asm/e820.h>
  25. #include <asm/proto.h>
  26. #include <asm/bootsetup.h>
  27. #include <asm/sections.h>
  28. struct e820map e820;
  29. /*
  30. * PFN of last memory page.
  31. */
  32. unsigned long end_pfn;
  33. EXPORT_SYMBOL(end_pfn);
  34. /*
  35. * end_pfn only includes RAM, while end_pfn_map includes all e820 entries.
  36. * The direct mapping extends to end_pfn_map, so that we can directly access
  37. * apertures, ACPI and other tables without having to play with fixmaps.
  38. */
  39. unsigned long end_pfn_map;
  40. /*
  41. * Last pfn which the user wants to use.
  42. */
  43. static unsigned long __initdata end_user_pfn = MAXMEM>>PAGE_SHIFT;
  44. extern struct resource code_resource, data_resource;
  45. /* Check for some hardcoded bad areas that early boot is not allowed to touch */
  46. static inline int bad_addr(unsigned long *addrp, unsigned long size)
  47. {
  48. unsigned long addr = *addrp, last = addr + size;
  49. /* various gunk below that needed for SMP startup */
  50. if (addr < 0x8000) {
  51. *addrp = PAGE_ALIGN(0x8000);
  52. return 1;
  53. }
  54. /* direct mapping tables of the kernel */
  55. if (last >= table_start<<PAGE_SHIFT && addr < table_end<<PAGE_SHIFT) {
  56. *addrp = PAGE_ALIGN(table_end << PAGE_SHIFT);
  57. return 1;
  58. }
  59. /* initrd */
  60. #ifdef CONFIG_BLK_DEV_INITRD
  61. if (LOADER_TYPE && INITRD_START && last >= INITRD_START &&
  62. addr < INITRD_START+INITRD_SIZE) {
  63. *addrp = PAGE_ALIGN(INITRD_START + INITRD_SIZE);
  64. return 1;
  65. }
  66. #endif
  67. /* kernel code */
  68. if (last >= __pa_symbol(&_text) && addr < __pa_symbol(&_end)) {
  69. *addrp = PAGE_ALIGN(__pa_symbol(&_end));
  70. return 1;
  71. }
  72. if (last >= ebda_addr && addr < ebda_addr + ebda_size) {
  73. *addrp = PAGE_ALIGN(ebda_addr + ebda_size);
  74. return 1;
  75. }
  76. #ifdef CONFIG_NUMA
  77. /* NUMA memory to node map */
  78. if (last >= nodemap_addr && addr < nodemap_addr + nodemap_size) {
  79. *addrp = nodemap_addr + nodemap_size;
  80. return 1;
  81. }
  82. #endif
  83. /* XXX ramdisk image here? */
  84. return 0;
  85. }
  86. /*
  87. * This function checks if any part of the range <start,end> is mapped
  88. * with type.
  89. */
  90. int
  91. e820_any_mapped(unsigned long start, unsigned long end, unsigned type)
  92. {
  93. int i;
  94. for (i = 0; i < e820.nr_map; i++) {
  95. struct e820entry *ei = &e820.map[i];
  96. if (type && ei->type != type)
  97. continue;
  98. if (ei->addr >= end || ei->addr + ei->size <= start)
  99. continue;
  100. return 1;
  101. }
  102. return 0;
  103. }
  104. EXPORT_SYMBOL_GPL(e820_any_mapped);
  105. /*
  106. * This function checks if the entire range <start,end> is mapped with type.
  107. *
  108. * Note: this function only works correct if the e820 table is sorted and
  109. * not-overlapping, which is the case
  110. */
  111. int __init e820_all_mapped(unsigned long start, unsigned long end, unsigned type)
  112. {
  113. int i;
  114. for (i = 0; i < e820.nr_map; i++) {
  115. struct e820entry *ei = &e820.map[i];
  116. if (type && ei->type != type)
  117. continue;
  118. /* is the region (part) in overlap with the current region ?*/
  119. if (ei->addr >= end || ei->addr + ei->size <= start)
  120. continue;
  121. /* if the region is at the beginning of <start,end> we move
  122. * start to the end of the region since it's ok until there
  123. */
  124. if (ei->addr <= start)
  125. start = ei->addr + ei->size;
  126. /* if start is now at or beyond end, we're done, full coverage */
  127. if (start >= end)
  128. return 1; /* we're done */
  129. }
  130. return 0;
  131. }
  132. /*
  133. * Find a free area in a specific range.
  134. */
  135. unsigned long __init find_e820_area(unsigned long start, unsigned long end, unsigned size)
  136. {
  137. int i;
  138. for (i = 0; i < e820.nr_map; i++) {
  139. struct e820entry *ei = &e820.map[i];
  140. unsigned long addr = ei->addr, last;
  141. if (ei->type != E820_RAM)
  142. continue;
  143. if (addr < start)
  144. addr = start;
  145. if (addr > ei->addr + ei->size)
  146. continue;
  147. while (bad_addr(&addr, size) && addr+size <= ei->addr+ei->size)
  148. ;
  149. last = PAGE_ALIGN(addr) + size;
  150. if (last > ei->addr + ei->size)
  151. continue;
  152. if (last > end)
  153. continue;
  154. return addr;
  155. }
  156. return -1UL;
  157. }
  158. /*
  159. * Find the highest page frame number we have available
  160. */
  161. unsigned long __init e820_end_of_ram(void)
  162. {
  163. unsigned long end_pfn = 0;
  164. end_pfn = find_max_pfn_with_active_regions();
  165. if (end_pfn > end_pfn_map)
  166. end_pfn_map = end_pfn;
  167. if (end_pfn_map > MAXMEM>>PAGE_SHIFT)
  168. end_pfn_map = MAXMEM>>PAGE_SHIFT;
  169. if (end_pfn > end_user_pfn)
  170. end_pfn = end_user_pfn;
  171. if (end_pfn > end_pfn_map)
  172. end_pfn = end_pfn_map;
  173. printk("end_pfn_map = %lu\n", end_pfn_map);
  174. return end_pfn;
  175. }
  176. /*
  177. * Mark e820 reserved areas as busy for the resource manager.
  178. */
  179. void __init e820_reserve_resources(void)
  180. {
  181. int i;
  182. for (i = 0; i < e820.nr_map; i++) {
  183. struct resource *res;
  184. res = alloc_bootmem_low(sizeof(struct resource));
  185. switch (e820.map[i].type) {
  186. case E820_RAM: res->name = "System RAM"; break;
  187. case E820_ACPI: res->name = "ACPI Tables"; break;
  188. case E820_NVS: res->name = "ACPI Non-volatile Storage"; break;
  189. default: res->name = "reserved";
  190. }
  191. res->start = e820.map[i].addr;
  192. res->end = res->start + e820.map[i].size - 1;
  193. res->flags = IORESOURCE_MEM | IORESOURCE_BUSY;
  194. request_resource(&iomem_resource, res);
  195. if (e820.map[i].type == E820_RAM) {
  196. /*
  197. * We don't know which RAM region contains kernel data,
  198. * so we try it repeatedly and let the resource manager
  199. * test it.
  200. */
  201. request_resource(res, &code_resource);
  202. request_resource(res, &data_resource);
  203. #ifdef CONFIG_KEXEC
  204. request_resource(res, &crashk_res);
  205. #endif
  206. }
  207. }
  208. }
  209. /*
  210. * Find the ranges of physical addresses that do not correspond to
  211. * e820 RAM areas and mark the corresponding pages as nosave for software
  212. * suspend and suspend to RAM.
  213. *
  214. * This function requires the e820 map to be sorted and without any
  215. * overlapping entries and assumes the first e820 area to be RAM.
  216. */
  217. void __init e820_mark_nosave_regions(void)
  218. {
  219. int i;
  220. unsigned long paddr;
  221. paddr = round_down(e820.map[0].addr + e820.map[0].size, PAGE_SIZE);
  222. for (i = 1; i < e820.nr_map; i++) {
  223. struct e820entry *ei = &e820.map[i];
  224. if (paddr < ei->addr)
  225. register_nosave_region(PFN_DOWN(paddr),
  226. PFN_UP(ei->addr));
  227. paddr = round_down(ei->addr + ei->size, PAGE_SIZE);
  228. if (ei->type != E820_RAM)
  229. register_nosave_region(PFN_UP(ei->addr),
  230. PFN_DOWN(paddr));
  231. if (paddr >= (end_pfn << PAGE_SHIFT))
  232. break;
  233. }
  234. }
  235. /*
  236. * Finds an active region in the address range from start_pfn to end_pfn and
  237. * returns its range in ei_startpfn and ei_endpfn for the e820 entry.
  238. */
  239. static int __init e820_find_active_region(const struct e820entry *ei,
  240. unsigned long start_pfn,
  241. unsigned long end_pfn,
  242. unsigned long *ei_startpfn,
  243. unsigned long *ei_endpfn)
  244. {
  245. *ei_startpfn = round_up(ei->addr, PAGE_SIZE) >> PAGE_SHIFT;
  246. *ei_endpfn = round_down(ei->addr + ei->size, PAGE_SIZE) >> PAGE_SHIFT;
  247. /* Skip map entries smaller than a page */
  248. if (*ei_startpfn >= *ei_endpfn)
  249. return 0;
  250. /* Check if end_pfn_map should be updated */
  251. if (ei->type != E820_RAM && *ei_endpfn > end_pfn_map)
  252. end_pfn_map = *ei_endpfn;
  253. /* Skip if map is outside the node */
  254. if (ei->type != E820_RAM || *ei_endpfn <= start_pfn ||
  255. *ei_startpfn >= end_pfn)
  256. return 0;
  257. /* Check for overlaps */
  258. if (*ei_startpfn < start_pfn)
  259. *ei_startpfn = start_pfn;
  260. if (*ei_endpfn > end_pfn)
  261. *ei_endpfn = end_pfn;
  262. /* Obey end_user_pfn to save on memmap */
  263. if (*ei_startpfn >= end_user_pfn)
  264. return 0;
  265. if (*ei_endpfn > end_user_pfn)
  266. *ei_endpfn = end_user_pfn;
  267. return 1;
  268. }
  269. /* Walk the e820 map and register active regions within a node */
  270. void __init
  271. e820_register_active_regions(int nid, unsigned long start_pfn,
  272. unsigned long end_pfn)
  273. {
  274. unsigned long ei_startpfn;
  275. unsigned long ei_endpfn;
  276. int i;
  277. for (i = 0; i < e820.nr_map; i++)
  278. if (e820_find_active_region(&e820.map[i],
  279. start_pfn, end_pfn,
  280. &ei_startpfn, &ei_endpfn))
  281. add_active_range(nid, ei_startpfn, ei_endpfn);
  282. }
  283. /*
  284. * Add a memory region to the kernel e820 map.
  285. */
  286. void __init add_memory_region(unsigned long start, unsigned long size, int type)
  287. {
  288. int x = e820.nr_map;
  289. if (x == E820MAX) {
  290. printk(KERN_ERR "Ooops! Too many entries in the memory map!\n");
  291. return;
  292. }
  293. e820.map[x].addr = start;
  294. e820.map[x].size = size;
  295. e820.map[x].type = type;
  296. e820.nr_map++;
  297. }
  298. /*
  299. * Find the hole size (in bytes) in the memory range.
  300. * @start: starting address of the memory range to scan
  301. * @end: ending address of the memory range to scan
  302. */
  303. unsigned long __init e820_hole_size(unsigned long start, unsigned long end)
  304. {
  305. unsigned long start_pfn = start >> PAGE_SHIFT;
  306. unsigned long end_pfn = end >> PAGE_SHIFT;
  307. unsigned long ei_startpfn;
  308. unsigned long ei_endpfn;
  309. unsigned long ram = 0;
  310. int i;
  311. for (i = 0; i < e820.nr_map; i++) {
  312. if (e820_find_active_region(&e820.map[i],
  313. start_pfn, end_pfn,
  314. &ei_startpfn, &ei_endpfn))
  315. ram += ei_endpfn - ei_startpfn;
  316. }
  317. return end - start - (ram << PAGE_SHIFT);
  318. }
  319. void __init e820_print_map(char *who)
  320. {
  321. int i;
  322. for (i = 0; i < e820.nr_map; i++) {
  323. printk(KERN_INFO " %s: %016Lx - %016Lx ", who,
  324. (unsigned long long) e820.map[i].addr,
  325. (unsigned long long) (e820.map[i].addr + e820.map[i].size));
  326. switch (e820.map[i].type) {
  327. case E820_RAM: printk("(usable)\n");
  328. break;
  329. case E820_RESERVED:
  330. printk("(reserved)\n");
  331. break;
  332. case E820_ACPI:
  333. printk("(ACPI data)\n");
  334. break;
  335. case E820_NVS:
  336. printk("(ACPI NVS)\n");
  337. break;
  338. default: printk("type %u\n", e820.map[i].type);
  339. break;
  340. }
  341. }
  342. }
  343. /*
  344. * Sanitize the BIOS e820 map.
  345. *
  346. * Some e820 responses include overlapping entries. The following
  347. * replaces the original e820 map with a new one, removing overlaps.
  348. *
  349. */
  350. static int __init sanitize_e820_map(struct e820entry * biosmap, char * pnr_map)
  351. {
  352. struct change_member {
  353. struct e820entry *pbios; /* pointer to original bios entry */
  354. unsigned long long addr; /* address for this change point */
  355. };
  356. static struct change_member change_point_list[2*E820MAX] __initdata;
  357. static struct change_member *change_point[2*E820MAX] __initdata;
  358. static struct e820entry *overlap_list[E820MAX] __initdata;
  359. static struct e820entry new_bios[E820MAX] __initdata;
  360. struct change_member *change_tmp;
  361. unsigned long current_type, last_type;
  362. unsigned long long last_addr;
  363. int chgidx, still_changing;
  364. int overlap_entries;
  365. int new_bios_entry;
  366. int old_nr, new_nr, chg_nr;
  367. int i;
  368. /*
  369. Visually we're performing the following (1,2,3,4 = memory types)...
  370. Sample memory map (w/overlaps):
  371. ____22__________________
  372. ______________________4_
  373. ____1111________________
  374. _44_____________________
  375. 11111111________________
  376. ____________________33__
  377. ___________44___________
  378. __________33333_________
  379. ______________22________
  380. ___________________2222_
  381. _________111111111______
  382. _____________________11_
  383. _________________4______
  384. Sanitized equivalent (no overlap):
  385. 1_______________________
  386. _44_____________________
  387. ___1____________________
  388. ____22__________________
  389. ______11________________
  390. _________1______________
  391. __________3_____________
  392. ___________44___________
  393. _____________33_________
  394. _______________2________
  395. ________________1_______
  396. _________________4______
  397. ___________________2____
  398. ____________________33__
  399. ______________________4_
  400. */
  401. /* if there's only one memory region, don't bother */
  402. if (*pnr_map < 2)
  403. return -1;
  404. old_nr = *pnr_map;
  405. /* bail out if we find any unreasonable addresses in bios map */
  406. for (i=0; i<old_nr; i++)
  407. if (biosmap[i].addr + biosmap[i].size < biosmap[i].addr)
  408. return -1;
  409. /* create pointers for initial change-point information (for sorting) */
  410. for (i=0; i < 2*old_nr; i++)
  411. change_point[i] = &change_point_list[i];
  412. /* record all known change-points (starting and ending addresses),
  413. omitting those that are for empty memory regions */
  414. chgidx = 0;
  415. for (i=0; i < old_nr; i++) {
  416. if (biosmap[i].size != 0) {
  417. change_point[chgidx]->addr = biosmap[i].addr;
  418. change_point[chgidx++]->pbios = &biosmap[i];
  419. change_point[chgidx]->addr = biosmap[i].addr + biosmap[i].size;
  420. change_point[chgidx++]->pbios = &biosmap[i];
  421. }
  422. }
  423. chg_nr = chgidx;
  424. /* sort change-point list by memory addresses (low -> high) */
  425. still_changing = 1;
  426. while (still_changing) {
  427. still_changing = 0;
  428. for (i=1; i < chg_nr; i++) {
  429. /* if <current_addr> > <last_addr>, swap */
  430. /* or, if current=<start_addr> & last=<end_addr>, swap */
  431. if ((change_point[i]->addr < change_point[i-1]->addr) ||
  432. ((change_point[i]->addr == change_point[i-1]->addr) &&
  433. (change_point[i]->addr == change_point[i]->pbios->addr) &&
  434. (change_point[i-1]->addr != change_point[i-1]->pbios->addr))
  435. )
  436. {
  437. change_tmp = change_point[i];
  438. change_point[i] = change_point[i-1];
  439. change_point[i-1] = change_tmp;
  440. still_changing=1;
  441. }
  442. }
  443. }
  444. /* create a new bios memory map, removing overlaps */
  445. overlap_entries=0; /* number of entries in the overlap table */
  446. new_bios_entry=0; /* index for creating new bios map entries */
  447. last_type = 0; /* start with undefined memory type */
  448. last_addr = 0; /* start with 0 as last starting address */
  449. /* loop through change-points, determining affect on the new bios map */
  450. for (chgidx=0; chgidx < chg_nr; chgidx++)
  451. {
  452. /* keep track of all overlapping bios entries */
  453. if (change_point[chgidx]->addr == change_point[chgidx]->pbios->addr)
  454. {
  455. /* add map entry to overlap list (> 1 entry implies an overlap) */
  456. overlap_list[overlap_entries++]=change_point[chgidx]->pbios;
  457. }
  458. else
  459. {
  460. /* remove entry from list (order independent, so swap with last) */
  461. for (i=0; i<overlap_entries; i++)
  462. {
  463. if (overlap_list[i] == change_point[chgidx]->pbios)
  464. overlap_list[i] = overlap_list[overlap_entries-1];
  465. }
  466. overlap_entries--;
  467. }
  468. /* if there are overlapping entries, decide which "type" to use */
  469. /* (larger value takes precedence -- 1=usable, 2,3,4,4+=unusable) */
  470. current_type = 0;
  471. for (i=0; i<overlap_entries; i++)
  472. if (overlap_list[i]->type > current_type)
  473. current_type = overlap_list[i]->type;
  474. /* continue building up new bios map based on this information */
  475. if (current_type != last_type) {
  476. if (last_type != 0) {
  477. new_bios[new_bios_entry].size =
  478. change_point[chgidx]->addr - last_addr;
  479. /* move forward only if the new size was non-zero */
  480. if (new_bios[new_bios_entry].size != 0)
  481. if (++new_bios_entry >= E820MAX)
  482. break; /* no more space left for new bios entries */
  483. }
  484. if (current_type != 0) {
  485. new_bios[new_bios_entry].addr = change_point[chgidx]->addr;
  486. new_bios[new_bios_entry].type = current_type;
  487. last_addr=change_point[chgidx]->addr;
  488. }
  489. last_type = current_type;
  490. }
  491. }
  492. new_nr = new_bios_entry; /* retain count for new bios entries */
  493. /* copy new bios mapping into original location */
  494. memcpy(biosmap, new_bios, new_nr*sizeof(struct e820entry));
  495. *pnr_map = new_nr;
  496. return 0;
  497. }
  498. /*
  499. * Copy the BIOS e820 map into a safe place.
  500. *
  501. * Sanity-check it while we're at it..
  502. *
  503. * If we're lucky and live on a modern system, the setup code
  504. * will have given us a memory map that we can use to properly
  505. * set up memory. If we aren't, we'll fake a memory map.
  506. */
  507. static int __init copy_e820_map(struct e820entry * biosmap, int nr_map)
  508. {
  509. /* Only one memory region (or negative)? Ignore it */
  510. if (nr_map < 2)
  511. return -1;
  512. do {
  513. unsigned long start = biosmap->addr;
  514. unsigned long size = biosmap->size;
  515. unsigned long end = start + size;
  516. unsigned long type = biosmap->type;
  517. /* Overflow in 64 bits? Ignore the memory map. */
  518. if (start > end)
  519. return -1;
  520. add_memory_region(start, size, type);
  521. } while (biosmap++,--nr_map);
  522. return 0;
  523. }
  524. void early_panic(char *msg)
  525. {
  526. early_printk(msg);
  527. panic(msg);
  528. }
  529. void __init setup_memory_region(void)
  530. {
  531. /*
  532. * Try to copy the BIOS-supplied E820-map.
  533. *
  534. * Otherwise fake a memory map; one section from 0k->640k,
  535. * the next section from 1mb->appropriate_mem_k
  536. */
  537. sanitize_e820_map(E820_MAP, &E820_MAP_NR);
  538. if (copy_e820_map(E820_MAP, E820_MAP_NR) < 0)
  539. early_panic("Cannot find a valid memory map");
  540. printk(KERN_INFO "BIOS-provided physical RAM map:\n");
  541. e820_print_map("BIOS-e820");
  542. }
  543. static int __init parse_memopt(char *p)
  544. {
  545. if (!p)
  546. return -EINVAL;
  547. end_user_pfn = memparse(p, &p);
  548. end_user_pfn >>= PAGE_SHIFT;
  549. return 0;
  550. }
  551. early_param("mem", parse_memopt);
  552. static int userdef __initdata;
  553. static int __init parse_memmap_opt(char *p)
  554. {
  555. char *oldp;
  556. unsigned long long start_at, mem_size;
  557. if (!strcmp(p, "exactmap")) {
  558. #ifdef CONFIG_CRASH_DUMP
  559. /* If we are doing a crash dump, we
  560. * still need to know the real mem
  561. * size before original memory map is
  562. * reset.
  563. */
  564. e820_register_active_regions(0, 0, -1UL);
  565. saved_max_pfn = e820_end_of_ram();
  566. remove_all_active_ranges();
  567. #endif
  568. end_pfn_map = 0;
  569. e820.nr_map = 0;
  570. userdef = 1;
  571. return 0;
  572. }
  573. oldp = p;
  574. mem_size = memparse(p, &p);
  575. if (p == oldp)
  576. return -EINVAL;
  577. if (*p == '@') {
  578. start_at = memparse(p+1, &p);
  579. add_memory_region(start_at, mem_size, E820_RAM);
  580. } else if (*p == '#') {
  581. start_at = memparse(p+1, &p);
  582. add_memory_region(start_at, mem_size, E820_ACPI);
  583. } else if (*p == '$') {
  584. start_at = memparse(p+1, &p);
  585. add_memory_region(start_at, mem_size, E820_RESERVED);
  586. } else {
  587. end_user_pfn = (mem_size >> PAGE_SHIFT);
  588. }
  589. return *p == '\0' ? 0 : -EINVAL;
  590. }
  591. early_param("memmap", parse_memmap_opt);
  592. void __init finish_e820_parsing(void)
  593. {
  594. if (userdef) {
  595. printk(KERN_INFO "user-defined physical RAM map:\n");
  596. e820_print_map("user");
  597. }
  598. }
  599. unsigned long pci_mem_start = 0xaeedbabe;
  600. EXPORT_SYMBOL(pci_mem_start);
  601. /*
  602. * Search for the biggest gap in the low 32 bits of the e820
  603. * memory space. We pass this space to PCI to assign MMIO resources
  604. * for hotplug or unconfigured devices in.
  605. * Hopefully the BIOS let enough space left.
  606. */
  607. __init void e820_setup_gap(void)
  608. {
  609. unsigned long gapstart, gapsize, round;
  610. unsigned long last;
  611. int i;
  612. int found = 0;
  613. last = 0x100000000ull;
  614. gapstart = 0x10000000;
  615. gapsize = 0x400000;
  616. i = e820.nr_map;
  617. while (--i >= 0) {
  618. unsigned long long start = e820.map[i].addr;
  619. unsigned long long end = start + e820.map[i].size;
  620. /*
  621. * Since "last" is at most 4GB, we know we'll
  622. * fit in 32 bits if this condition is true
  623. */
  624. if (last > end) {
  625. unsigned long gap = last - end;
  626. if (gap > gapsize) {
  627. gapsize = gap;
  628. gapstart = end;
  629. found = 1;
  630. }
  631. }
  632. if (start < last)
  633. last = start;
  634. }
  635. if (!found) {
  636. gapstart = (end_pfn << PAGE_SHIFT) + 1024*1024;
  637. printk(KERN_ERR "PCI: Warning: Cannot find a gap in the 32bit address range\n"
  638. KERN_ERR "PCI: Unassigned devices with 32bit resource registers may break!\n");
  639. }
  640. /*
  641. * See how much we want to round up: start off with
  642. * rounding to the next 1MB area.
  643. */
  644. round = 0x100000;
  645. while ((gapsize >> 4) > round)
  646. round += round;
  647. /* Fun with two's complement */
  648. pci_mem_start = (gapstart + round) & -round;
  649. printk(KERN_INFO "Allocating PCI resources starting at %lx (gap: %lx:%lx)\n",
  650. pci_mem_start, gapstart, gapsize);
  651. }