blob: eee706bd6344f2e766801f82a8068b2c269bb5c7 [file] [log] [blame]
Anthony Liguori8a0743c2013-04-16 09:45:18 -05001/*
2 * libqos malloc support for PC
3 *
4 * Copyright IBM, Corp. 2012-2013
5 *
6 * Authors:
7 * Anthony Liguori <aliguori@us.ibm.com>
8 *
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.
11 */
12
Peter Maydell681c28a2016-02-08 18:08:51 +000013#include "qemu/osdep.h"
Anthony Liguori8a0743c2013-04-16 09:45:18 -050014#include "libqos/malloc-pc.h"
Markus Armbruster26491a32013-06-26 15:52:22 +020015#include "libqos/fw_cfg.h"
Anthony Liguori8a0743c2013-04-16 09:45:18 -050016
Markus Armbruster6f061ea2016-03-10 14:09:58 +010017#include "hw/nvram/fw_cfg_keys.h"
Anthony Liguori8a0743c2013-04-16 09:45:18 -050018
19#include "qemu-common.h"
20#include <glib.h>
21
22#define PAGE_SIZE (4096)
23
John Snowec2f1602014-08-01 11:38:58 -040024/*
25 * Mostly for valgrind happiness, but it does offer
26 * a chokepoint for debugging guest memory leaks, too.
27 */
28void pc_alloc_uninit(QGuestAllocator *allocator)
29{
Marc Marí292be092014-10-23 10:12:42 +020030 alloc_uninit(allocator);
John Snowec2f1602014-08-01 11:38:58 -040031}
32
Marc Marí292be092014-10-23 10:12:42 +020033QGuestAllocator *pc_alloc_init_flags(QAllocOpts flags)
Anthony Liguori8a0743c2013-04-16 09:45:18 -050034{
John Snowaf77f2c2015-01-19 15:15:49 -050035 QGuestAllocator *s;
Anthony Liguori8a0743c2013-04-16 09:45:18 -050036 uint64_t ram_size;
37 QFWCFG *fw_cfg = pc_fw_cfg_init();
John Snowaf77f2c2015-01-19 15:15:49 -050038
39 ram_size = qfw_cfg_get_u64(fw_cfg, FW_CFG_RAM_SIZE);
John Snowfa02e602015-01-19 15:15:53 -050040 s = alloc_init_flags(flags, 1 << 20, MIN(ram_size, 0xE0000000));
John Snowf6f363c2015-01-19 15:15:54 -050041 alloc_set_page_size(s, PAGE_SIZE);
Anthony Liguori8a0743c2013-04-16 09:45:18 -050042
John Snowf3cdcba2014-08-04 17:11:21 -040043 /* clean-up */
44 g_free(fw_cfg);
45
Marc Marí292be092014-10-23 10:12:42 +020046 return s;
Anthony Liguori8a0743c2013-04-16 09:45:18 -050047}
John Snowec2f1602014-08-01 11:38:58 -040048
49inline QGuestAllocator *pc_alloc_init(void)
50{
Marc Marí292be092014-10-23 10:12:42 +020051 return pc_alloc_init_flags(ALLOC_NO_FLAGS);
John Snowec2f1602014-08-01 11:38:58 -040052}