[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index] [mini-os master] mini-os: add memory map service functions
commit a7d27a7332baa5c6a6056084ecc3f3b14f312769 Author: Juergen Gross <jgross@xxxxxxxx> AuthorDate: Tue Dec 21 09:46:32 2021 +0100 Commit: Andrew Cooper <andrew.cooper3@xxxxxxxxxx> CommitDate: Tue Dec 21 10:53:49 2021 +0000 mini-os: add memory map service functions Add two functions for adding reserved areas to the memory map and for removing them again. Those will be needed for proper grant table/mapping support in PVH mode. Signed-off-by: Juergen Gross <jgross@xxxxxxxx> Reviewed-by: Samuel Thibault <samuel.thibault@xxxxxxxxxxxx> --- e820.c | 50 ++++++++++++++++++++++++++++++++++++++++++++++++++ include/e820.h | 4 ++++ 2 files changed, 54 insertions(+) diff --git a/e820.c b/e820.c index d60eb83..991ed38 100644 --- a/e820.c +++ b/e820.c @@ -283,6 +283,56 @@ void arch_print_memmap(void) printk("%012lx-%012lx: %s\n", from, to, type); } } + +unsigned long e820_get_reserved_pfns(int pages) +{ + int i; + unsigned long last = 0, needed = (long)pages << PAGE_SHIFT; + + for ( i = 0; i < e820_entries && e820_map[i].addr < last + needed; i++ ) + last = e820_map[i].addr + e820_map[i].size; + + if ( i == 0 || e820_map[i - 1].type != E820_RESERVED ) + e820_insert_entry_at(i, last, needed, E820_RESERVED); + else + e820_map[i - 1].size += needed; + + return last >> PAGE_SHIFT; +} + +void e820_put_reserved_pfns(unsigned long start_pfn, int pages) +{ + int i; + unsigned long addr = start_pfn << PAGE_SHIFT; + unsigned long size = (long)pages << PAGE_SHIFT; + + for ( i = 0; + i < e820_entries && addr >= e820_map[i].addr + e820_map[i].size; + i++ ); + + BUG_ON(i == e820_entries || e820_map[i].type != E820_RESERVED || + addr + size > e820_map[i].addr + e820_map[i].size); + + if ( addr == e820_map[i].addr ) + { + e820_map[i].addr += size; + e820_map[i].size -= size; + if ( e820_map[i].size == 0 ) + e820_remove_entry(i); + return; + } + + if ( addr + size == e820_map[i].addr + e820_map[i].size ) + { + e820_map[i].size -= size; + return; + } + + e820_insert_entry_at(i + 1, addr + size, + e820_map[i].addr + e820_map[i].size - addr - size, + E820_RESERVED); + e820_map[i].size = addr - e820_map[i].addr; +} #endif unsigned long e820_get_maxpfn(unsigned long pages) diff --git a/include/e820.h b/include/e820.h index 8d4d371..aaf2f2c 100644 --- a/include/e820.h +++ b/include/e820.h @@ -51,5 +51,9 @@ extern unsigned e820_entries; unsigned long e820_get_maxpfn(unsigned long pages); unsigned long e820_get_max_contig_pages(unsigned long pfn, unsigned long pages); +#ifndef CONFIG_E820_TRIVIAL +unsigned long e820_get_reserved_pfns(int pages); +void e820_put_reserved_pfns(unsigned long start_pfn, int pages); +#endif #endif /*__E820_HEADER*/ -- generated by git-patchbot for /home/xen/git/mini-os.git#master
|
Lists.xenproject.org is hosted with RackSpace, monitoring our |