xref: /kvm-unit-tests/lib/vmalloc.c (revision efd8e5aa7474352dd66b0e647948fd9cec3cadc6)
1 /*
2  * Copyright (C) 2012, 2017, Red Hat Inc.
3  *
4  * This allocator provides contiguous physical addresses with page
5  * granularity.
6  */
7 
8 #include "libcflat.h"
9 #include "asm/spinlock.h"
10 #include "asm/page.h"
11 
12 static struct spinlock lock;
13 static void *vfree_top = 0;
14 
15 void *alloc_vpages(ulong nr)
16 {
17 	spin_lock(&lock);
18 	vfree_top -= PAGE_SIZE * nr;
19 	spin_unlock(&lock);
20 	return vfree_top;
21 }
22 
23 void *alloc_vpage(void)
24 {
25 	return alloc_vpages(1);
26 }
27 
28 void init_alloc_vpage(void *top)
29 {
30 	vfree_top = top;
31 }
32