target-ppc: Fix invalid SPR read/write warnings
[qemu/agraf.git] / tests / libqos / malloc-pc.c
blobadc36c47312b162fd7c7d0f9aafd9810bcf6f669
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-pc.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)
24 typedef struct PCAlloc
26 QGuestAllocator alloc;
28 uint64_t start;
29 uint64_t end;
30 } PCAlloc;
32 static uint64_t pc_alloc(QGuestAllocator *allocator, size_t size)
34 PCAlloc *s = container_of(allocator, PCAlloc, alloc);
35 uint64_t addr;
38 size += (PAGE_SIZE - 1);
39 size &= PAGE_SIZE;
41 g_assert_cmpint((s->start + size), <=, s->end);
43 addr = s->start;
44 s->start += size;
46 return addr;
49 static void pc_free(QGuestAllocator *allocator, uint64_t addr)
53 QGuestAllocator *pc_alloc_init(void)
55 PCAlloc *s = g_malloc0(sizeof(*s));
56 uint64_t ram_size;
57 QFWCFG *fw_cfg = pc_fw_cfg_init();
59 s->alloc.alloc = pc_alloc;
60 s->alloc.free = pc_free;
62 ram_size = qfw_cfg_get_u64(fw_cfg, FW_CFG_RAM_SIZE);
64 /* Start at 1MB */
65 s->start = 1 << 20;
67 /* Respect PCI hole */
68 s->end = MIN(ram_size, 0xE0000000);
70 return &s->alloc;