Browse Source

[pcbios] Merge adjacent memory regions of same type

Some BIOSes can report multiple memory regions which may be adjacent
and the same type.  Since only the first region is used in the
mboot.c32 layer it's possible to run out of memory when loading all of
the boot modules.  One may get around this problem by having iPXE
merge these memory regions internally.

Signed-off-by: Michael Brown <mcb30@ipxe.org>
tags/v1.20.1
Eduardo Habkost 13 years ago
parent
commit
3293eb8e73
1 changed files with 10 additions and 2 deletions
  1. 10
    2
      src/arch/i386/firmware/pcbios/memmap.c

+ 10
- 2
src/arch/i386/firmware/pcbios/memmap.c View File

156
  */
156
  */
157
 static int meme820 ( struct memory_map *memmap ) {
157
 static int meme820 ( struct memory_map *memmap ) {
158
 	struct memory_region *region = memmap->regions;
158
 	struct memory_region *region = memmap->regions;
159
+	struct memory_region *prev_region = NULL;
159
 	uint32_t next = 0;
160
 	uint32_t next = 0;
160
 	uint32_t smap;
161
 	uint32_t smap;
161
 	size_t size;
162
 	size_t size;
238
 
239
 
239
 		region->start = e820buf.start;
240
 		region->start = e820buf.start;
240
 		region->end = e820buf.start + e820buf.len;
241
 		region->end = e820buf.start + e820buf.len;
241
-		region++;
242
-		memmap->count++;
242
+
243
+		/* Check for adjacent regions and merge them */
244
+		if ( prev_region && ( region->start == prev_region->end ) ) {
245
+			prev_region->end = region->end;
246
+		} else {
247
+			prev_region = region;
248
+			region++;
249
+			memmap->count++;
250
+		}
243
 
251
 
244
 		if ( memmap->count >= ( sizeof ( memmap->regions ) /
252
 		if ( memmap->count >= ( sizeof ( memmap->regions ) /
245
 					sizeof ( memmap->regions[0] ) ) ) {
253
 					sizeof ( memmap->regions[0] ) ) ) {

Loading…
Cancel
Save