xref: /qemu/tests/qtest/libqos/malloc-pc.c (revision f6f363c1f4f962aee9f69c67ab2f3ff58c30f8c1)
18a0743cfSAnthony Liguori /*
28a0743cfSAnthony Liguori  * libqos malloc support for PC
38a0743cfSAnthony Liguori  *
48a0743cfSAnthony Liguori  * Copyright IBM, Corp. 2012-2013
58a0743cfSAnthony Liguori  *
68a0743cfSAnthony Liguori  * Authors:
78a0743cfSAnthony Liguori  *  Anthony Liguori   <aliguori@us.ibm.com>
88a0743cfSAnthony Liguori  *
98a0743cfSAnthony Liguori  * This work is licensed under the terms of the GNU GPL, version 2 or later.
108a0743cfSAnthony Liguori  * See the COPYING file in the top-level directory.
118a0743cfSAnthony Liguori  */
128a0743cfSAnthony Liguori 
138a0743cfSAnthony Liguori #include "libqos/malloc-pc.h"
1426491a38SMarkus Armbruster #include "libqos/fw_cfg.h"
158a0743cfSAnthony Liguori 
168a0743cfSAnthony Liguori #define NO_QEMU_PROTOS
178a0743cfSAnthony Liguori #include "hw/nvram/fw_cfg.h"
188a0743cfSAnthony Liguori 
198a0743cfSAnthony Liguori #include "qemu-common.h"
208a0743cfSAnthony Liguori #include <glib.h>
218a0743cfSAnthony Liguori 
228a0743cfSAnthony Liguori #define PAGE_SIZE (4096)
238a0743cfSAnthony Liguori 
24ec2f1605SJohn Snow /*
25ec2f1605SJohn Snow  * Mostly for valgrind happiness, but it does offer
26ec2f1605SJohn Snow  * a chokepoint for debugging guest memory leaks, too.
27ec2f1605SJohn Snow  */
28ec2f1605SJohn Snow void pc_alloc_uninit(QGuestAllocator *allocator)
29ec2f1605SJohn Snow {
30292be092SMarc Marí     alloc_uninit(allocator);
31ec2f1605SJohn Snow }
32ec2f1605SJohn Snow 
33292be092SMarc Marí QGuestAllocator *pc_alloc_init_flags(QAllocOpts flags)
348a0743cfSAnthony Liguori {
35af77f2cdSJohn Snow     QGuestAllocator *s;
368a0743cfSAnthony Liguori     uint64_t ram_size;
378a0743cfSAnthony Liguori     QFWCFG *fw_cfg = pc_fw_cfg_init();
38af77f2cdSJohn Snow 
39af77f2cdSJohn Snow     ram_size = qfw_cfg_get_u64(fw_cfg, FW_CFG_RAM_SIZE);
40fa02e608SJohn Snow     s = alloc_init_flags(flags, 1 << 20, MIN(ram_size, 0xE0000000));
41*f6f363c1SJohn Snow     alloc_set_page_size(s, PAGE_SIZE);
428a0743cfSAnthony Liguori 
43f3cdcbaeSJohn Snow     /* clean-up */
44f3cdcbaeSJohn Snow     g_free(fw_cfg);
45f3cdcbaeSJohn Snow 
46292be092SMarc Marí     return s;
478a0743cfSAnthony Liguori }
48ec2f1605SJohn Snow 
49ec2f1605SJohn Snow inline QGuestAllocator *pc_alloc_init(void)
50ec2f1605SJohn Snow {
51292be092SMarc Marí     return pc_alloc_init_flags(ALLOC_NO_FLAGS);
52ec2f1605SJohn Snow }
53