xref: /qemu/tests/qtest/libqos/malloc-pc.c (revision 5be5df720e600502ff530cee51a7ac0622f62f6f)
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 
13681c28a3SPeter Maydell #include "qemu/osdep.h"
148a0743cfSAnthony Liguori #include "libqos/malloc-pc.h"
1526491a38SMarkus Armbruster #include "libqos/fw_cfg.h"
168a0743cfSAnthony Liguori 
17*5be5df72SMarc-André Lureau #include "standard-headers/linux/qemu_fw_cfg.h"
188a0743cfSAnthony Liguori 
198a0743cfSAnthony Liguori #include "qemu-common.h"
208a0743cfSAnthony Liguori 
218a0743cfSAnthony Liguori #define PAGE_SIZE (4096)
228a0743cfSAnthony Liguori 
23ec2f1605SJohn Snow /*
24ec2f1605SJohn Snow  * Mostly for valgrind happiness, but it does offer
25ec2f1605SJohn Snow  * a chokepoint for debugging guest memory leaks, too.
26ec2f1605SJohn Snow  */
27ec2f1605SJohn Snow void pc_alloc_uninit(QGuestAllocator *allocator)
28ec2f1605SJohn Snow {
29292be092SMarc Marí     alloc_uninit(allocator);
30ec2f1605SJohn Snow }
31ec2f1605SJohn Snow 
3205e520f1SEric Blake QGuestAllocator *pc_alloc_init_flags(QTestState *qts, QAllocOpts flags)
338a0743cfSAnthony Liguori {
34af77f2cdSJohn Snow     QGuestAllocator *s;
358a0743cfSAnthony Liguori     uint64_t ram_size;
3605e520f1SEric Blake     QFWCFG *fw_cfg = pc_fw_cfg_init(qts);
37af77f2cdSJohn Snow 
38af77f2cdSJohn Snow     ram_size = qfw_cfg_get_u64(fw_cfg, FW_CFG_RAM_SIZE);
39fa02e608SJohn Snow     s = alloc_init_flags(flags, 1 << 20, MIN(ram_size, 0xE0000000));
40f6f363c1SJohn Snow     alloc_set_page_size(s, PAGE_SIZE);
418a0743cfSAnthony Liguori 
42f3cdcbaeSJohn Snow     /* clean-up */
43f3cdcbaeSJohn Snow     g_free(fw_cfg);
44f3cdcbaeSJohn Snow 
45292be092SMarc Marí     return s;
468a0743cfSAnthony Liguori }
47ec2f1605SJohn Snow 
4805e520f1SEric Blake inline QGuestAllocator *pc_alloc_init(QTestState *qts)
49ec2f1605SJohn Snow {
5005e520f1SEric Blake     return pc_alloc_init_flags(qts, ALLOC_NO_FLAGS);
51ec2f1605SJohn Snow }
52