diff options
Diffstat (limited to 'emulators/xen-kernel/files/0001-introduce-a-helper-to-allocate-non-contiguous-memory.patch')
-rw-r--r-- | emulators/xen-kernel/files/0001-introduce-a-helper-to-allocate-non-contiguous-memory.patch | 141 |
1 files changed, 141 insertions, 0 deletions
diff --git a/emulators/xen-kernel/files/0001-introduce-a-helper-to-allocate-non-contiguous-memory.patch b/emulators/xen-kernel/files/0001-introduce-a-helper-to-allocate-non-contiguous-memory.patch new file mode 100644 index 000000000000..af799b45e4c3 --- /dev/null +++ b/emulators/xen-kernel/files/0001-introduce-a-helper-to-allocate-non-contiguous-memory.patch @@ -0,0 +1,141 @@ +From 411801087603a1a070de7abbfa4373afe91ca3f5 Mon Sep 17 00:00:00 2001 +From: =?UTF-8?q?Roger=20Pau=20Monn=C3=A9?= <roger.pau@citrix.com> +Date: Fri, 9 Oct 2015 12:57:31 +0200 +Subject: [PATCH 1/8] introduce a helper to allocate non-contiguous memory +MIME-Version: 1.0 +Content-Type: text/plain; charset=UTF-8 +Content-Transfer-Encoding: 8bit + +The allocator uses independent calls to alloc_domheap_pages in order to get +the desired amount of memory and then maps all the independent physical +addresses into a contiguous virtual address space. + +Signed-off-by: Roger Pau Monné <roger.pau@citrix.com> +Tested-by: Julien Grall <julien.grall@citrix.com> (ARM) +Reviewed-by: Tim Deegan <tim@xen.org> +--- + xen/common/vmap.c | 67 ++++++++++++++++++++++++++++++++++++++++++++++ + xen/include/asm-arm/mm.h | 2 ++ + xen/include/asm-x86/page.h | 2 ++ + xen/include/xen/vmap.h | 3 +++ + 4 files changed, 74 insertions(+) + +diff --git a/xen/common/vmap.c b/xen/common/vmap.c +index 783cea3..b6827b5 100644 +--- a/xen/common/vmap.c ++++ b/xen/common/vmap.c +@@ -215,4 +215,71 @@ void vunmap(const void *va) + #endif + vm_free(va); + } ++ ++void *vmalloc(size_t size) ++{ ++ unsigned long *mfn; ++ size_t pages, i; ++ struct page_info *pg; ++ void *va; ++ ++ ASSERT(size); ++ ++ pages = PFN_UP(size); ++ mfn = xmalloc_array(unsigned long, pages); ++ if ( mfn == NULL ) ++ return NULL; ++ ++ for ( i = 0; i < pages; i++ ) ++ { ++ pg = alloc_domheap_page(NULL, 0); ++ if ( pg == NULL ) ++ goto error; ++ mfn[i] = page_to_mfn(pg); ++ } ++ ++ va = vmap(mfn, pages); ++ if ( va == NULL ) ++ goto error; ++ ++ xfree(mfn); ++ return va; ++ ++ error: ++ while ( i-- ) ++ free_domheap_page(mfn_to_page(mfn[i])); ++ xfree(mfn); ++ return NULL; ++} ++ ++void *vzalloc(size_t size) ++{ ++ void *p = vmalloc(size); ++ int i; ++ ++ if ( p == NULL ) ++ return NULL; ++ ++ for ( i = 0; i < size; i += PAGE_SIZE ) ++ clear_page(p + i); ++ ++ return p; ++} ++ ++void vfree(void *va) ++{ ++ unsigned int i, pages = vm_size(va); ++ struct page_info *pg; ++ PAGE_LIST_HEAD(pg_list); ++ ++ ASSERT(pages); ++ ++ for ( i = 0; i < pages; i++ ) ++ page_list_add(vmap_to_page(va + i * PAGE_SIZE), &pg_list); ++ ++ vunmap(va); ++ ++ while ( (pg = page_list_remove_head(&pg_list)) != NULL ) ++ free_domheap_page(pg); ++} + #endif +diff --git a/xen/include/asm-arm/mm.h b/xen/include/asm-arm/mm.h +index d25e485..c0afcec 100644 +--- a/xen/include/asm-arm/mm.h ++++ b/xen/include/asm-arm/mm.h +@@ -208,6 +208,8 @@ static inline void __iomem *ioremap_wc(paddr_t start, size_t len) + #define pfn_to_paddr(pfn) ((paddr_t)(pfn) << PAGE_SHIFT) + #define paddr_to_pfn(pa) ((unsigned long)((pa) >> PAGE_SHIFT)) + #define paddr_to_pdx(pa) pfn_to_pdx(paddr_to_pfn(pa)) ++#define vmap_to_mfn(va) paddr_to_pfn(virt_to_maddr((vaddr_t)va)) ++#define vmap_to_page(va) mfn_to_page(vmap_to_mfn(va)) + + /* Page-align address and convert to frame number format */ + #define paddr_to_pfn_aligned(paddr) paddr_to_pfn(PAGE_ALIGN(paddr)) +diff --git a/xen/include/asm-x86/page.h b/xen/include/asm-x86/page.h +index ccf0752..27c2ae7 100644 +--- a/xen/include/asm-x86/page.h ++++ b/xen/include/asm-x86/page.h +@@ -262,6 +262,8 @@ void copy_page_sse2(void *, const void *); + #define pfn_to_paddr(pfn) __pfn_to_paddr(pfn) + #define paddr_to_pfn(pa) __paddr_to_pfn(pa) + #define paddr_to_pdx(pa) pfn_to_pdx(paddr_to_pfn(pa)) ++#define vmap_to_mfn(va) l1e_get_pfn(*virt_to_xen_l1e((unsigned long)(va))) ++#define vmap_to_page(va) mfn_to_page(vmap_to_mfn(va)) + + #endif /* !defined(__ASSEMBLY__) */ + +diff --git a/xen/include/xen/vmap.h b/xen/include/xen/vmap.h +index b1923dd..a13591d 100644 +--- a/xen/include/xen/vmap.h ++++ b/xen/include/xen/vmap.h +@@ -11,6 +11,9 @@ void *__vmap(const unsigned long *mfn, unsigned int granularity, + unsigned int nr, unsigned int align, unsigned int flags); + void *vmap(const unsigned long *mfn, unsigned int nr); + void vunmap(const void *); ++void *vmalloc(size_t size); ++void *vzalloc(size_t size); ++void vfree(void *va); + + void __iomem *ioremap(paddr_t, size_t); + +-- +1.9.5 (Apple Git-50.3) + |