]> err.no Git - linux-2.6/blobdiff - arch/x86/kernel/e820.c
mm, generic, x86 boot: more tweaks to hex prints of some pfn addresses
[linux-2.6] / arch / x86 / kernel / e820.c
index 8a8afbdeb34ee593698066ffe82fa23388af58f8..1dcb66533dfcbb50fa801c5b35e2c05fabe4a472 100644 (file)
@@ -405,6 +405,9 @@ u64 __init e820_update_range(u64 start, u64 size, unsigned old_type,
 
        BUG_ON(old_type == new_type);
 
+       if (size > (ULLONG_MAX - start))
+               size = ULLONG_MAX - start;
+
        for (i = 0; i < e820.nr_map; i++) {
                struct e820entry *ei = &e820.map[i];
                u64 final_start, final_end;
@@ -425,6 +428,11 @@ u64 __init e820_update_range(u64 start, u64 size, unsigned old_type,
                e820_add_region(final_start, final_end - final_start,
                                         new_type);
                real_updated_size += final_end - final_start;
+
+               ei->size -= final_end - final_start;
+               if (ei->addr < final_start)
+                       continue;
+               ei->addr = final_end;
        }
        return real_updated_size;
 }
@@ -436,6 +444,9 @@ u64 __init e820_remove_range(u64 start, u64 size, unsigned old_type,
        int i;
        u64 real_removed_size = 0;
 
+       if (size > (ULLONG_MAX - start))
+               size = ULLONG_MAX - start;
+
        for (i = 0; i < e820.nr_map; i++) {
                struct e820entry *ei = &e820.map[i];
                u64 final_start, final_end;
@@ -477,26 +488,22 @@ void __init update_e820(void)
 }
 
 /*
- * Search for the biggest gap in the low 32 bits of the e820
- * memory space.  We pass this space to PCI to assign MMIO resources
- * for hotplug or unconfigured devices in.
- * Hopefully the BIOS let enough space left.
+ * Search for a gap in the e820 memory space from start_addr to 2^32.
  */
-__init void e820_setup_gap(void)
+__init int e820_search_gap(unsigned long *gapstart, unsigned long *gapsize,
+               unsigned long start_addr)
 {
-       unsigned long gapstart, gapsize, round;
-       unsigned long long last;
-       int i;
+       unsigned long long last = 0x100000000ull;
+       int i = e820.nr_map;
        int found = 0;
 
-       last = 0x100000000ull;
-       gapstart = 0x10000000;
-       gapsize = 0x400000;
-       i = e820.nr_map;
        while (--i >= 0) {
                unsigned long long start = e820.map[i].addr;
                unsigned long long end = start + e820.map[i].size;
 
+               if (end < start_addr)
+                       continue;
+
                /*
                 * Since "last" is at most 4GB, we know we'll
                 * fit in 32 bits if this condition is true
@@ -504,19 +511,36 @@ __init void e820_setup_gap(void)
                if (last > end) {
                        unsigned long gap = last - end;
 
-                       if (gap > gapsize) {
-                               gapsize = gap;
-                               gapstart = end;
+                       if (gap >= *gapsize) {
+                               *gapsize = gap;
+                               *gapstart = end;
                                found = 1;
                        }
                }
                if (start < last)
                        last = start;
        }
+       return found;
+}
+
+/*
+ * Search for the biggest gap in the low 32 bits of the e820
+ * memory space.  We pass this space to PCI to assign MMIO resources
+ * for hotplug or unconfigured devices in.
+ * Hopefully the BIOS let enough space left.
+ */
+__init void e820_setup_gap(void)
+{
+       unsigned long gapstart, gapsize, round;
+       int found;
+
+       gapstart = 0x10000000;
+       gapsize = 0x400000;
+       found  = e820_search_gap(&gapstart, &gapsize, 0);
 
 #ifdef CONFIG_X86_64
        if (!found) {
-               gapstart = (end_pfn << PAGE_SHIFT) + 1024*1024;
+               gapstart = (max_pfn << PAGE_SHIFT) + 1024*1024;
                printk(KERN_ERR "PCI: Warning: Cannot find a gap in the 32bit "
                       "address range\n"
                       KERN_ERR "PCI: Unassigned devices with 32bit resource "
@@ -604,6 +628,7 @@ void __init e820_mark_nosave_regions(unsigned long limit_pfn)
 struct early_res {
        u64 start, end;
        char name[16];
+       char overlap_ok;
 };
 static struct early_res early_res[MAX_EARLY_RES] __initdata = {
        { 0, PAGE_SIZE, "BIOS data page" },     /* BIOS data page */
@@ -640,7 +665,93 @@ static int __init find_overlapped_early(u64 start, u64 end)
        return i;
 }
 
-void __init reserve_early(u64 start, u64 end, char *name)
+/*
+ * Drop the i-th range from the early reservation map,
+ * by copying any higher ranges down one over it, and
+ * clearing what had been the last slot.
+ */
+static void __init drop_range(int i)
+{
+       int j;
+
+       for (j = i + 1; j < MAX_EARLY_RES && early_res[j].end; j++)
+               ;
+
+       memmove(&early_res[i], &early_res[i + 1],
+              (j - 1 - i) * sizeof(struct early_res));
+
+       early_res[j - 1].end = 0;
+}
+
+/*
+ * Split any existing ranges that:
+ *  1) are marked 'overlap_ok', and
+ *  2) overlap with the stated range [start, end)
+ * into whatever portion (if any) of the existing range is entirely
+ * below or entirely above the stated range.  Drop the portion
+ * of the existing range that overlaps with the stated range,
+ * which will allow the caller of this routine to then add that
+ * stated range without conflicting with any existing range.
+ */
+static void __init drop_overlaps_that_are_ok(u64 start, u64 end)
+{
+       int i;
+       struct early_res *r;
+       u64 lower_start, lower_end;
+       u64 upper_start, upper_end;
+       char name[16];
+
+       for (i = 0; i < MAX_EARLY_RES && early_res[i].end; i++) {
+               r = &early_res[i];
+
+               /* Continue past non-overlapping ranges */
+               if (end <= r->start || start >= r->end)
+                       continue;
+
+               /*
+                * Leave non-ok overlaps as is; let caller
+                * panic "Overlapping early reservations"
+                * when it hits this overlap.
+                */
+               if (!r->overlap_ok)
+                       return;
+
+               /*
+                * We have an ok overlap.  We will drop it from the early
+                * reservation map, and add back in any non-overlapping
+                * portions (lower or upper) as separate, overlap_ok,
+                * non-overlapping ranges.
+                */
+
+               /* 1. Note any non-overlapping (lower or upper) ranges. */
+               strncpy(name, r->name, sizeof(name) - 1);
+
+               lower_start = lower_end = 0;
+               upper_start = upper_end = 0;
+               if (r->start < start) {
+                       lower_start = r->start;
+                       lower_end = start;
+               }
+               if (r->end > end) {
+                       upper_start = end;
+                       upper_end = r->end;
+               }
+
+               /* 2. Drop the original ok overlapping range */
+               drop_range(i);
+
+               i--;            /* resume for-loop on copied down entry */
+
+               /* 3. Add back in any non-overlapping ranges. */
+               if (lower_end)
+                       reserve_early_overlap_ok(lower_start, lower_end, name);
+               if (upper_end)
+                       reserve_early_overlap_ok(upper_start, upper_end, name);
+       }
+}
+
+static void __init __reserve_early(u64 start, u64 end, char *name,
+                                               int overlap_ok)
 {
        int i;
        struct early_res *r;
@@ -656,14 +767,55 @@ void __init reserve_early(u64 start, u64 end, char *name)
                      r->end - 1, r->name);
        r->start = start;
        r->end = end;
+       r->overlap_ok = overlap_ok;
        if (name)
                strncpy(r->name, name, sizeof(r->name) - 1);
 }
 
+/*
+ * A few early reservtations come here.
+ *
+ * The 'overlap_ok' in the name of this routine does -not- mean it
+ * is ok for these reservations to overlap an earlier reservation.
+ * Rather it means that it is ok for subsequent reservations to
+ * overlap this one.
+ *
+ * Use this entry point to reserve early ranges when you are doing
+ * so out of "Paranoia", reserving perhaps more memory than you need,
+ * just in case, and don't mind a subsequent overlapping reservation
+ * that is known to be needed.
+ *
+ * The drop_overlaps_that_are_ok() call here isn't really needed.
+ * It would be needed if we had two colliding 'overlap_ok'
+ * reservations, so that the second such would not panic on the
+ * overlap with the first.  We don't have any such as of this
+ * writing, but might as well tolerate such if it happens in
+ * the future.
+ */
+void __init reserve_early_overlap_ok(u64 start, u64 end, char *name)
+{
+       drop_overlaps_that_are_ok(start, end);
+       __reserve_early(start, end, name, 1);
+}
+
+/*
+ * Most early reservations come here.
+ *
+ * We first have drop_overlaps_that_are_ok() drop any pre-existing
+ * 'overlap_ok' ranges, so that we can then reserve this memory
+ * range without risk of panic'ing on an overlapping overlap_ok
+ * early reservation.
+ */
+void __init reserve_early(u64 start, u64 end, char *name)
+{
+       drop_overlaps_that_are_ok(start, end);
+       __reserve_early(start, end, name, 0);
+}
+
 void __init free_early(u64 start, u64 end)
 {
        struct early_res *r;
-       int i, j;
+       int i;
 
        i = find_overlapped_early(start, end);
        r = &early_res[i];
@@ -671,13 +823,7 @@ void __init free_early(u64 start, u64 end)
                panic("free_early on not reserved area: %llx-%llx!",
                         start, end - 1);
 
-       for (j = i + 1; j < MAX_EARLY_RES && early_res[j].end; j++)
-               ;
-
-       memmove(&early_res[i], &early_res[i + 1],
-              (j - 1 - i) * sizeof(struct early_res));
-
-       early_res[j - 1].end = 0;
+       drop_range(i);
 }
 
 void __init early_res_to_bootmem(u64 start, u64 end)
@@ -868,7 +1014,7 @@ unsigned long __init e820_end_of_ram(void)
        if (last_pfn > end_user_pfn)
                last_pfn = end_user_pfn;
 
-       printk(KERN_INFO "last_pfn = %lu max_arch_pfn = %lu\n",
+       printk(KERN_INFO "last_pfn = %#lx max_arch_pfn = %#lx\n",
                         last_pfn, max_arch_pfn);
        return last_pfn;
 }