disas/libvixl: Update to upstream VIXL 1.7
[qemu.git] / tests / libqos / malloc-pc.c
blobc9c48fddc9893bf7da408114e31e2e2f7e46a65e
1 /*
2 * libqos malloc support for PC
4 * Copyright IBM, Corp. 2012-2013
6 * Authors:
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"
20 #include <glib.h>
22 #define PAGE_SIZE (4096)
25 * Mostly for valgrind happiness, but it does offer
26 * a chokepoint for debugging guest memory leaks, too.
28 void pc_alloc_uninit(QGuestAllocator *allocator)
30 alloc_uninit(allocator);
33 QGuestAllocator *pc_alloc_init_flags(QAllocOpts flags)
35 QGuestAllocator *s = g_malloc0(sizeof(*s));
36 uint64_t ram_size;
37 QFWCFG *fw_cfg = pc_fw_cfg_init();
38 MemBlock *node;
40 s->opts = flags;
41 s->page_size = PAGE_SIZE;
43 ram_size = qfw_cfg_get_u64(fw_cfg, FW_CFG_RAM_SIZE);
45 /* Start at 1MB */
46 s->start = 1 << 20;
48 /* Respect PCI hole */
49 s->end = MIN(ram_size, 0xE0000000);
51 /* clean-up */
52 g_free(fw_cfg);
54 QTAILQ_INIT(&s->used);
55 QTAILQ_INIT(&s->free);
57 node = mlist_new(s->start, s->end - s->start);
58 QTAILQ_INSERT_HEAD(&s->free, node, MLIST_ENTNAME);
60 return s;
63 inline QGuestAllocator *pc_alloc_init(void)
65 return pc_alloc_init_flags(ALLOC_NO_FLAGS);