From: Wanpeng Li <liwp@linux.vnet.ibm.com>
To: qemu-devel@nongnu.org
Cc: Wanpeng Li <liwp@linux.vnet.ibm.com>,
Anthony Liguori <aliguori@us.ibm.com>,
Avi Kivity <avi@redhat.com>,
Gavin Shan <shangw@linux.vnet.ibm.com>
Subject: [Qemu-devel] [PATCH 2/6] convert MemoryRegion to QOM
Date: Mon, 26 Mar 2012 10:06:44 +0800 [thread overview]
Message-ID: <1332727608-26523-3-git-send-email-liwp@linux.vnet.ibm.com> (raw)
In-Reply-To: <1332727608-26523-1-git-send-email-liwp@linux.vnet.ibm.com>
From: Anthony Liguori <aliguori@us.ibm.com>
Signed-off-by: Anthony Liguori <aliguori@us.ibm.com>
Signed-off-by: Wanpeng Li <liwp@linux.vnet.ibm.com>
---
memory.c | 94 ++++++++++++++++++++++++++++++++++++++++++++++----------------
memory.h | 8 +++++
2 files changed, 78 insertions(+), 24 deletions(-)
diff --git a/memory.c b/memory.c
index 22b0352..ec1a4ae 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,
@@ -1640,3 +1631,58 @@ void mtree_info(fprintf_function mon_printf, void *f)
mtree_print_mr(mon_printf, f, address_space_io.root, 0, 0, &ml_head);
}
}
+
+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 53ff62b..d4d5600 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;
@@ -719,6 +723,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
--
1.7.5.4
next prev parent reply other threads:[~2012-03-26 2:07 UTC|newest]
Thread overview: 42+ messages / expand[flat|nested] mbox.gz Atom feed top
2012-03-26 2:06 [Qemu-devel] [PATCH 0/6] refactor PC machine, i440fx and piix3 to take advantage of QOM Wanpeng Li
2012-03-26 2:06 ` [Qemu-devel] [PATCH 1/6] eliminate piix_pci.c and module i440fx and piix3 Wanpeng Li
2012-03-26 2:06 ` Wanpeng Li [this message]
2012-03-26 2:06 ` [Qemu-devel] [PATCH 3/6] convert pci-host to QOM Wanpeng Li
2012-03-26 7:32 ` Stefan Hajnoczi
2012-03-26 9:22 ` Wanpeng Li
2012-03-26 14:25 ` Andreas Färber
2012-03-26 2:06 ` [Qemu-devel] [PATCH 4/6] prepare to create HPET, RTC and i8254 through composition Wanpeng Li
2012-03-26 2:06 ` [Qemu-devel] [PATCH 5/6] merge pc_piix.c to pc.c Wanpeng Li
2012-03-26 12:42 ` Avi Kivity
2012-03-26 12:47 ` Jan Kiszka
2012-03-26 17:37 ` Anthony Liguori
2012-03-26 2:06 ` [Qemu-devel] [PATCH 6/6] make some functions static Wanpeng Li
2012-03-26 12:20 ` [Qemu-devel] [PATCH 0/6] refactor PC machine, i440fx and piix3 to take advantage of QOM Jan Kiszka
2012-03-26 15:54 ` Isaku Yamahata
2012-03-26 17:29 ` Anthony Liguori
2012-03-27 10:31 ` Avi Kivity
2012-03-27 13:52 ` Anthony Liguori
2012-03-27 14:18 ` Avi Kivity
2012-03-26 17:17 ` Blue Swirl
2012-03-26 17:33 ` Anthony Liguori
2012-03-26 19:30 ` Jan Kiszka
2012-03-26 19:35 ` Anthony Liguori
2012-03-26 19:37 ` Jan Kiszka
2012-03-26 19:39 ` Anthony Liguori
2012-03-26 19:44 ` Jan Kiszka
2012-03-26 19:49 ` Anthony Liguori
2012-03-26 20:10 ` Jan Kiszka
2012-03-26 20:13 ` Anthony Liguori
2012-03-26 20:30 ` Jan Kiszka
2012-03-26 21:00 ` Anthony Liguori
2012-03-26 19:52 ` Anthony Liguori
2012-03-26 12:47 ` Andreas Färber
2012-03-26 12:57 ` Wanpeng Li
2012-03-26 17:09 ` Blue Swirl
2012-03-26 17:35 ` Anthony Liguori
2012-03-26 17:43 ` Blue Swirl
2012-03-26 17:45 ` Anthony Liguori
2012-03-26 18:01 ` Blue Swirl
2012-03-26 18:07 ` Anthony Liguori
2012-03-26 18:25 ` Blue Swirl
2012-03-26 17:25 ` Anthony Liguori
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=1332727608-26523-3-git-send-email-liwp@linux.vnet.ibm.com \
--to=liwp@linux.vnet.ibm.com \
--cc=aliguori@us.ibm.com \
--cc=avi@redhat.com \
--cc=qemu-devel@nongnu.org \
--cc=shangw@linux.vnet.ibm.com \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).