xref: /kvm-unit-tests/lib/alloc_phys.h (revision 4363f1d9a646a5c7ea673bee8fc33ca6f2cddbd8)
1 #ifndef _ALLOC_PHYS_H_
2 #define _ALLOC_PHYS_H_
3 /*
4  * phys_alloc is a very simple allocator which allows physical memory
5  * to be partitioned into regions until all memory is allocated.
6  *
7  * Note: This is such a simple allocator that there is no way to free
8  * a region. For more complicated memory management a single region
9  * can be allocated, but then have its memory managed by a more
10  * sophisticated allocator, e.g. a page allocator.
11  *
12  * Copyright (C) 2014, Red Hat Inc, Andrew Jones <drjones@redhat.com>
13  *
14  * This work is licensed under the terms of the GNU LGPL, version 2.
15  */
16 #include "libcflat.h"
17 
18 #define DEFAULT_MINIMUM_ALIGNMENT 32
19 
20 /*
21  * phys_alloc_init creates the initial free memory region of size @size
22  * at @base. The minimum alignment is set to DEFAULT_MINIMUM_ALIGNMENT.
23  */
24 extern void phys_alloc_init(phys_addr_t base, phys_addr_t size);
25 
26 /*
27  * phys_alloc_set_minimum_alignment sets the minimum alignment to
28  * @align.
29  */
30 extern void phys_alloc_set_minimum_alignment(phys_addr_t align);
31 
32 /*
33  * phys_alloc_show outputs all currently allocated regions with the
34  * following format
35  *   <start_addr>-<end_addr> [<USED|FREE>]
36  */
37 extern void phys_alloc_show(void);
38 
39 /*
40  * phys_alloc_get_unused returns the addresses for the still-unused part
41  * of the initial free memory region passed to phys_alloc_init.
42  */
43 extern void phys_alloc_get_unused(phys_addr_t *p_base, phys_addr_t *p_top);
44 
45 #endif /* _ALLOC_PHYS_H_ */
46