2 * libqos malloc support for PC
4 * Copyright IBM, Corp. 2012-2013
7 * Anthony Liguori <aliguori@us.ibm.com>
9 * This work is licensed under the terms of the GNU GPL, version 2 or later.
10 * See the COPYING file in the top-level directory.
13 #include "libqos/malloc-pc.h"
14 #include "libqos/fw_cfg.h"
16 #define NO_QEMU_PROTOS
17 #include "hw/nvram/fw_cfg.h"
19 #include "qemu-common.h"
22 #define PAGE_SIZE (4096)
24 typedef struct PCAlloc
26 QGuestAllocator alloc
;
32 static uint64_t pc_alloc(QGuestAllocator
*allocator
, size_t size
)
34 PCAlloc
*s
= container_of(allocator
, PCAlloc
, alloc
);
38 size
+= (PAGE_SIZE
- 1);
41 g_assert_cmpint((s
->start
+ size
), <=, s
->end
);
49 static void pc_free(QGuestAllocator
*allocator
, uint64_t addr
)
53 QGuestAllocator
*pc_alloc_init(void)
55 PCAlloc
*s
= g_malloc0(sizeof(*s
));
57 QFWCFG
*fw_cfg
= pc_fw_cfg_init();
59 s
->alloc
.alloc
= pc_alloc
;
60 s
->alloc
.free
= pc_free
;
62 ram_size
= qfw_cfg_get_u64(fw_cfg
, FW_CFG_RAM_SIZE
);
67 /* Respect PCI hole */
68 s
->end
= MIN(ram_size
, 0xE0000000);