[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index] [Xen-devel] [PATCH 1/4] x86/e820: introduce a function to remove ranges from e820
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@xxxxxxxxxx> --- --- xen/arch/x86/e820.c | 56 ++++++++++++++++++++++++++++++++++++++ xen/include/asm-x86/e820.h | 2 ++ 2 files changed, 58 insertions(+) diff --git a/xen/arch/x86/e820.c b/xen/arch/x86/e820.c index 590ea985ef..2b03c56b93 100644 --- a/xen/arch/x86/e820.c +++ b/xen/arch/x86/e820.c @@ -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) diff --git a/xen/include/asm-x86/e820.h b/xen/include/asm-x86/e820.h index ee317b17aa..f77b821ae9 100644 --- a/xen/include/asm-x86/e820.h +++ b/xen/include/asm-x86/e820.h @@ -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; -- 2.17.2 (Apple Git-113) _______________________________________________ Xen-devel mailing list Xen-devel@xxxxxxxxxxxxxxxxxxxx https://lists.xenproject.org/mailman/listinfo/xen-devel
|
Lists.xenproject.org is hosted with RackSpace, monitoring our |