Anthony Liguori | 8a0743c | 2013-04-16 09:45:18 -0500 | [diff] [blame] | 1 | /* |
| 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 Maydell | 681c28a | 2016-02-08 18:08:51 +0000 | [diff] [blame] | 13 | #include "qemu/osdep.h" |
Anthony Liguori | 8a0743c | 2013-04-16 09:45:18 -0500 | [diff] [blame] | 14 | #include "libqos/malloc-pc.h" |
Markus Armbruster | 26491a3 | 2013-06-26 15:52:22 +0200 | [diff] [blame] | 15 | #include "libqos/fw_cfg.h" |
Anthony Liguori | 8a0743c | 2013-04-16 09:45:18 -0500 | [diff] [blame] | 16 | |
Markus Armbruster | 6f061ea | 2016-03-10 14:09:58 +0100 | [diff] [blame] | 17 | #include "hw/nvram/fw_cfg_keys.h" |
Anthony Liguori | 8a0743c | 2013-04-16 09:45:18 -0500 | [diff] [blame] | 18 | |
| 19 | #include "qemu-common.h" |
| 20 | #include <glib.h> |
| 21 | |
| 22 | #define PAGE_SIZE (4096) |
| 23 | |
John Snow | ec2f160 | 2014-08-01 11:38:58 -0400 | [diff] [blame] | 24 | /* |
| 25 | * Mostly for valgrind happiness, but it does offer |
| 26 | * a chokepoint for debugging guest memory leaks, too. |
| 27 | */ |
| 28 | void pc_alloc_uninit(QGuestAllocator *allocator) |
| 29 | { |
Marc Marí | 292be09 | 2014-10-23 10:12:42 +0200 | [diff] [blame] | 30 | alloc_uninit(allocator); |
John Snow | ec2f160 | 2014-08-01 11:38:58 -0400 | [diff] [blame] | 31 | } |
| 32 | |
Marc Marí | 292be09 | 2014-10-23 10:12:42 +0200 | [diff] [blame] | 33 | QGuestAllocator *pc_alloc_init_flags(QAllocOpts flags) |
Anthony Liguori | 8a0743c | 2013-04-16 09:45:18 -0500 | [diff] [blame] | 34 | { |
John Snow | af77f2c | 2015-01-19 15:15:49 -0500 | [diff] [blame] | 35 | QGuestAllocator *s; |
Anthony Liguori | 8a0743c | 2013-04-16 09:45:18 -0500 | [diff] [blame] | 36 | uint64_t ram_size; |
| 37 | QFWCFG *fw_cfg = pc_fw_cfg_init(); |
John Snow | af77f2c | 2015-01-19 15:15:49 -0500 | [diff] [blame] | 38 | |
| 39 | ram_size = qfw_cfg_get_u64(fw_cfg, FW_CFG_RAM_SIZE); |
John Snow | fa02e60 | 2015-01-19 15:15:53 -0500 | [diff] [blame] | 40 | s = alloc_init_flags(flags, 1 << 20, MIN(ram_size, 0xE0000000)); |
John Snow | f6f363c | 2015-01-19 15:15:54 -0500 | [diff] [blame] | 41 | alloc_set_page_size(s, PAGE_SIZE); |
Anthony Liguori | 8a0743c | 2013-04-16 09:45:18 -0500 | [diff] [blame] | 42 | |
John Snow | f3cdcba | 2014-08-04 17:11:21 -0400 | [diff] [blame] | 43 | /* clean-up */ |
| 44 | g_free(fw_cfg); |
| 45 | |
Marc Marí | 292be09 | 2014-10-23 10:12:42 +0200 | [diff] [blame] | 46 | return s; |
Anthony Liguori | 8a0743c | 2013-04-16 09:45:18 -0500 | [diff] [blame] | 47 | } |
John Snow | ec2f160 | 2014-08-01 11:38:58 -0400 | [diff] [blame] | 48 | |
| 49 | inline QGuestAllocator *pc_alloc_init(void) |
| 50 | { |
Marc Marí | 292be09 | 2014-10-23 10:12:42 +0200 | [diff] [blame] | 51 | return pc_alloc_init_flags(ALLOC_NO_FLAGS); |
John Snow | ec2f160 | 2014-08-01 11:38:58 -0400 | [diff] [blame] | 52 | } |