From patchwork Wed Jul 18 13:19:02 2012 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Wanpeng Li X-Patchwork-Id: 171671 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@bilbo.ozlabs.org Received: from lists.gnu.org (lists.gnu.org [208.118.235.17]) (using TLSv1 with cipher AES256-SHA (256/256 bits)) (Client did not present a certificate) by ozlabs.org (Postfix) with ESMTPS id 94D8B2C0381 for ; Wed, 18 Jul 2012 23:20:38 +1000 (EST) Received: from localhost ([::1]:41246 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1SrUBA-0005yb-KM for incoming@patchwork.ozlabs.org; Wed, 18 Jul 2012 09:20:36 -0400 Received: from eggs.gnu.org ([208.118.235.92]:59351) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1SrUAQ-0005IG-It for qemu-devel@nongnu.org; Wed, 18 Jul 2012 09:20:24 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1SrU9z-000724-GU for qemu-devel@nongnu.org; Wed, 18 Jul 2012 09:19:50 -0400 Received: from e28smtp01.in.ibm.com ([122.248.162.1]:35527) by eggs.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1SrU9y-000703-Sp for qemu-devel@nongnu.org; Wed, 18 Jul 2012 09:19:23 -0400 Received: from /spool/local by e28smtp01.in.ibm.com with IBM ESMTP SMTP Gateway: Authorized Use Only! Violators will be prosecuted for from ; Wed, 18 Jul 2012 18:49:18 +0530 Received: from d28relay01.in.ibm.com (9.184.220.58) by e28smtp01.in.ibm.com (192.168.1.131) with IBM ESMTP SMTP Gateway: Authorized Use Only! Violators will be prosecuted; Wed, 18 Jul 2012 18:49:16 +0530 Received: from d28av04.in.ibm.com (d28av04.in.ibm.com [9.184.220.66]) by d28relay01.in.ibm.com (8.13.8/8.13.8/NCO v10.0) with ESMTP id q6IDJFf33670332 for ; Wed, 18 Jul 2012 18:49:15 +0530 Received: from d28av04.in.ibm.com (loopback [127.0.0.1]) by d28av04.in.ibm.com (8.14.4/8.13.1/NCO v10.0 AVout) with ESMTP id q6IIn3tQ005852 for ; Thu, 19 Jul 2012 04:49:03 +1000 Received: from localhost ([9.123.247.28]) by d28av04.in.ibm.com (8.14.4/8.13.1/NCO v10.0 AVin) with ESMTP id q6IIn2kB005783; Thu, 19 Jul 2012 04:49:02 +1000 From: Wanpeng Li To: Anthony Liguori Date: Wed, 18 Jul 2012 21:19:02 +0800 Message-Id: <1342617545-9261-3-git-send-email-liwanp@linux.vnet.ibm.com> X-Mailer: git-send-email 1.7.5.4 In-Reply-To: <1342617545-9261-1-git-send-email-liwanp@linux.vnet.ibm.com> References: <1342617545-9261-1-git-send-email-liwanp@linux.vnet.ibm.com> x-cbid: 12071813-4790-0000-0000-000003BE651A X-detected-operating-system: by eggs.gnu.org: Genre and OS details not recognized. X-Received-From: 122.248.162.1 Cc: Ram Pai , Gavin Shan , "Michael S. Tsirkin" , Jan Kiszka , qemu-devel@nongnu.org, Liu Ping Fan , Blue Swirl , Stefan Weil , Avi Kivity , Paolo Bonzini , Wanpeng Li Subject: [Qemu-devel] [PATCH v4 2/5] convert MemoryRegion to QOM X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.14 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: qemu-devel-bounces+incoming=patchwork.ozlabs.org@nongnu.org Sender: qemu-devel-bounces+incoming=patchwork.ozlabs.org@nongnu.org [CCing ML] From: Anthony Liguori Signed-off-by: Anthony Liguori Signed-off-by: Wanpeng Li --- memory.c | 94 ++++++++++++++++++++++++++++++++++++++++++++++---------------- memory.h | 8 +++++ 2 files changed, 78 insertions(+), 24 deletions(-) diff --git a/memory.c b/memory.c index aab4a31..3674535 100644 --- a/memory.c +++ b/memory.c @@ -797,35 +797,26 @@ static bool memory_region_wrong_endianness(MemoryRegion *mr) #endif } -void memory_region_init(MemoryRegion *mr, - const char *name, - uint64_t size) +void memory_region_set_name(MemoryRegion *mr, const char *name) +{ + mr->name = g_strdup(name); +} + +void memory_region_set_size(MemoryRegion *mr, uint64_t size) { - mr->ops = NULL; - mr->parent = NULL; mr->size = int128_make64(size); if (size == UINT64_MAX) { mr->size = int128_2_64(); } - mr->addr = 0; - mr->subpage = false; - mr->enabled = true; - mr->terminates = false; - mr->ram = false; - mr->readable = true; - mr->readonly = false; - mr->rom_device = false; - mr->destructor = memory_region_destructor_none; - mr->priority = 0; - mr->may_overlap = false; - mr->alias = NULL; - QTAILQ_INIT(&mr->subregions); - memset(&mr->subregions_link, 0, sizeof mr->subregions_link); - QTAILQ_INIT(&mr->coalesced); - mr->name = g_strdup(name); - mr->dirty_log_mask = 0; - mr->ioeventfd_nb = 0; - mr->ioeventfds = NULL; +} + +void memory_region_init(MemoryRegion *mr, + const char *name, + uint64_t size) +{ + object_initialize(mr, TYPE_MEMORY_REGION); + memory_region_set_name(mr, name); + memory_region_set_size(mr, size); } static bool memory_region_access_valid(MemoryRegion *mr, @@ -1645,3 +1636,58 @@ void mtree_info(fprintf_function mon_printf, void *f) g_free(ml); } } + +static void memory_region_initfn(Object *obj) +{ + MemoryRegion *mr = MEMORY_REGION(obj); + mr->ops = NULL; + mr->parent = NULL; + mr->size = int128_2_64(); + mr->addr = 0; + mr->subpage = false; + mr->enabled = true; + mr->terminates = false; + mr->ram = false; + mr->readable = true; + mr->readonly = false; + mr->rom_device = false; + mr->destructor = memory_region_destructor_none; + mr->priority = 0; + mr->may_overlap = false; + mr->alias = NULL; + mr->name = NULL; + QTAILQ_INIT(&mr->subregions); + memset(&mr->subregions_link, 0, sizeof mr->subregions_link); + QTAILQ_INIT(&mr->coalesced); + mr->dirty_log_mask = 0; + mr->ioeventfd_nb = 0; + mr->ioeventfds = NULL; +} + +static void memory_region_finalize(Object *obj) +{ + MemoryRegion *mr = MEMORY_REGION(obj); + + assert(QTAILQ_EMPTY(&mr->subregions)); + mr->destructor(mr); + memory_region_clear_coalescing(mr); + if (mr->name) { + g_free((char *)mr->name); + } + g_free(mr->ioeventfds); +} + +static TypeInfo memory_region_type = { + .name = TYPE_MEMORY_REGION, + .parent = TYPE_OBJECT, + .instance_size = sizeof(MemoryRegion), + .instance_init = memory_region_initfn, + .instance_finalize = memory_region_finalize, +}; + +static void register_devices(void) +{ + type_register_static(&memory_region_type); +} + +type_init(register_devices) diff --git a/memory.h b/memory.h index 740c48e..90a53f7 100644 --- a/memory.h +++ b/memory.h @@ -25,6 +25,7 @@ #include "iorange.h" #include "ioport.h" #include "int128.h" +#include "qemu/object.h" typedef struct MemoryRegionOps MemoryRegionOps; typedef struct MemoryRegion MemoryRegion; @@ -116,6 +117,9 @@ struct MemoryRegionOps { typedef struct CoalescedMemoryRange CoalescedMemoryRange; typedef struct MemoryRegionIoeventfd MemoryRegionIoeventfd; +#define TYPE_MEMORY_REGION "memory-region" +#define MEMORY_REGION(obj) OBJECT_CHECK(MemoryRegion, (obj), TYPE_MEMORY_REGION) + struct MemoryRegion { /* All fields are private - violators will be prosecuted */ const MemoryRegionOps *ops; @@ -748,6 +752,10 @@ void memory_global_dirty_log_stop(void); void mtree_info(fprintf_function mon_printf, void *f); +void memory_region_set_name(MemoryRegion *mr, const char *name); + +void memory_region_set_size(MemoryRegion *mr, uint64_t size); + #endif #endif