From cdd4003ce946a2310fa1afc8106a763848411555 Mon Sep 17 00:00:00 2001 From: Lioncash Date: Tue, 20 Feb 2018 08:35:41 -0500 Subject: [PATCH] Move RAMBlock to ram_addr.h Moves it back into qemu's includes. --- include/qemu.h | 24 +----------------------- qemu/include/exec/ram_addr.h | 28 ++++++++++++++++++++++++++++ 2 files changed, 29 insertions(+), 23 deletions(-) diff --git a/include/qemu.h b/include/qemu.h index 79366dc9..f7fc3fe5 100644 --- a/include/qemu.h +++ b/include/qemu.h @@ -17,30 +17,8 @@ struct uc_struct; #include "vl.h" -// This two struct is originally from qemu/include/exec/cpu-all.h +// These two structs are originally from qemu/include/exec/cpu-all.h // Temporarily moved here since there is circular inclusion. -struct RAMBlock { - struct MemoryRegion *mr; - uint8_t *host; - ram_addr_t offset; - ram_addr_t used_length; - ram_addr_t max_length; - void (*resized)(const char*, uint64_t length, void *host); - uint32_t flags; - char idstr[256]; - /* Reads can take either the iothread or the ramlist lock. - * Writes must take both locks. - */ - QLIST_ENTRY(RAMBlock) next; - int fd; -}; - -static inline void *ramblock_ptr(RAMBlock *block, ram_addr_t offset) -{ - assert(offset < block->used_length); - assert(block->host); - return (char *)block->host + offset; -} typedef struct { MemoryRegion *mr; diff --git a/qemu/include/exec/ram_addr.h b/qemu/include/exec/ram_addr.h index 4847e39d..8e5161cb 100644 --- a/qemu/include/exec/ram_addr.h +++ b/qemu/include/exec/ram_addr.h @@ -24,6 +24,34 @@ #ifndef CONFIG_USER_ONLY #include "hw/xen/xen.h" +struct RAMBlock { + struct MemoryRegion *mr; + uint8_t *host; + ram_addr_t offset; + ram_addr_t used_length; + ram_addr_t max_length; + void (*resized)(const char*, uint64_t length, void *host); + uint32_t flags; + char idstr[256]; + /* Reads can take either the iothread or the ramlist lock. + * Writes must take both locks. + */ + QLIST_ENTRY(RAMBlock) next; + int fd; +}; + +static inline bool offset_in_ramblock(RAMBlock *b, ram_addr_t offset) +{ + return (b && b->host && offset < b->used_length) ? true : false; +} + +static inline void *ramblock_ptr(RAMBlock *block, ram_addr_t offset) +{ + assert(offset < block->used_length); + assert(block->host); + return (char *)block->host + offset; +} + ram_addr_t qemu_ram_alloc_from_ptr(ram_addr_t size, void *host, MemoryRegion *mr, Error **errp); ram_addr_t qemu_ram_alloc(ram_addr_t size, MemoryRegion *mr, Error **errp);