]> xenbits.xensource.com Git - people/royger/xen.git/commitdiff
x86/e820: introduce a function to remove ranges from e820
authorRoger Pau Monne <roger.pau@citrix.com>
Thu, 27 Dec 2018 14:48:40 +0000 (15:48 +0100)
committerRoger Pau Monne <roger.pau@citrix.com>
Thu, 27 Dec 2018 14:48:40 +0000 (15:48 +0100)
This function is based on the Linux e820__range_remove function,
modified to fit Xen coding style.

Signed-off-by: Roger Pau Monné <roger.pau@citrix.com>
---

xen/arch/x86/e820.c
xen/include/asm-x86/e820.h

index 590ea985ef082e1101120b37817e12be473a14d1..2b03c56b93acbff1a8b7dd6ff756ac47ea706b80 100644 (file)
@@ -599,6 +599,62 @@ int __init e820_add_range(
     return 1;
 }
 
+uint64_t __init e820_remove_range(struct e820map *e820, uint64_t start,
+                                  uint64_t end, uint32_t type, bool check_type)
+{
+    unsigned int i;
+    uint64_t real_removed_size = 0;
+
+    ASSERT(end > start);
+
+    for ( i = 0; i < e820->nr_map; i++ )
+    {
+        struct e820entry *entry = &e820->map[i];
+        uint64_t final_start, final_end, entry_end;
+
+        if ( check_type && entry->type != type )
+            continue;
+
+        entry_end = entry->addr + entry->size;
+
+        /* Completely covered? */
+        if ( entry->addr >= start && entry_end <= end )
+        {
+            real_removed_size += entry->size;
+            memset(entry, 0, sizeof(*entry));
+            continue;
+        }
+
+        /* Is the new range completely covered? */
+        if (entry->addr < start && entry_end > end) {
+            e820_add_range(e820, end, entry_end, entry->type);
+            entry->size = start - entry->addr;
+            real_removed_size += end - start;
+            continue;
+        }
+
+        /* Partially covered: */
+        final_start = max(start, entry->addr);
+        final_end = min(end, entry_end);
+        if ( final_start >= final_end )
+            continue;
+
+        real_removed_size += final_end - final_start;
+
+        /*
+         * Left range could be head or tail, so need to update
+         * the size first:
+         */
+        entry->size -= final_end - final_start;
+        if ( entry->addr < final_start )
+            continue;
+
+        entry->addr = final_end;
+    }
+
+    return real_removed_size;
+}
+
 int __init e820_change_range_type(
     struct e820map *e820, uint64_t s, uint64_t e,
     uint32_t orig_type, uint32_t new_type)
index ee317b17aa0f387eb5e64b6c81ce2de74bd6a522..f77b821ae9eb6ba04839cad4cb92f5df69afdee6 100644 (file)
@@ -31,6 +31,8 @@ extern int e820_change_range_type(
     uint32_t orig_type, uint32_t new_type);
 extern int e820_add_range(
     struct e820map *, uint64_t s, uint64_t e, uint32_t type);
+extern uint64_t e820_remove_range(struct e820map *e820, uint64_t start,
+                                  uint64_t end, uint32_t type, bool check_type);
 extern unsigned long init_e820(const char *, struct e820map *);
 extern struct e820map e820;
 extern struct e820map e820_raw;