1 // SPDX-License-Identifier: GPL-2.0-or-later
2 #include "tests/common.h"
3 #include <string.h>
4 
5 #define INIT_MEMBLOCK_REGIONS			128
6 #define INIT_MEMBLOCK_RESERVED_REGIONS		INIT_MEMBLOCK_REGIONS
7 
8 static struct test_memory memory_block;
9 
reset_memblock_regions(void)10 void reset_memblock_regions(void)
11 {
12 	memset(memblock.memory.regions, 0,
13 	       memblock.memory.cnt * sizeof(struct memblock_region));
14 	memblock.memory.cnt	= 1;
15 	memblock.memory.max	= INIT_MEMBLOCK_REGIONS;
16 	memblock.memory.total_size = 0;
17 
18 	memset(memblock.reserved.regions, 0,
19 	       memblock.reserved.cnt * sizeof(struct memblock_region));
20 	memblock.reserved.cnt	= 1;
21 	memblock.reserved.max	= INIT_MEMBLOCK_RESERVED_REGIONS;
22 	memblock.reserved.total_size = 0;
23 }
24 
reset_memblock_attributes(void)25 void reset_memblock_attributes(void)
26 {
27 	memblock.memory.name	= "memory";
28 	memblock.reserved.name	= "reserved";
29 	memblock.bottom_up	= false;
30 	memblock.current_limit	= MEMBLOCK_ALLOC_ANYWHERE;
31 }
32 
setup_memblock(void)33 void setup_memblock(void)
34 {
35 	reset_memblock_regions();
36 	memblock_add((phys_addr_t)memory_block.base, MEM_SIZE);
37 }
38 
dummy_physical_memory_init(void)39 void dummy_physical_memory_init(void)
40 {
41 	memory_block.base = malloc(MEM_SIZE);
42 	assert(memory_block.base);
43 }
44 
dummy_physical_memory_cleanup(void)45 void dummy_physical_memory_cleanup(void)
46 {
47 	free(memory_block.base);
48 }
49