qemu-devel.nongnu.org archive mirror
 help / color / mirror / Atom feed
From: Paolo Bonzini <pbonzini@redhat.com>
To: qemu-devel@nongnu.org
Cc: "Mark Cave-Ayland" <mark.cave-ayland@ilande.co.uk>,
	"Philippe Mathieu-Daudé" <philmd@linaro.org>
Subject: [PULL 10/20] softmmu/ioport.c: QOMify MemoryRegionPortioList
Date: Thu, 25 May 2023 16:15:22 +0200	[thread overview]
Message-ID: <20230525141532.295817-11-pbonzini@redhat.com> (raw)
In-Reply-To: <20230525141532.295817-1-pbonzini@redhat.com>

From: Mark Cave-Ayland <mark.cave-ayland@ilande.co.uk>

The aim of QOMification is so that the lifetime of the MemoryRegionPortioList
structure can be managed using QOM's in-built refcounting instead of having to
handle this manually.

Due to the use of an opaque pointer it isn't possible to model the new
TYPE_MEMORY_REGION_PORTIO_LIST directly using QOM properties, however since
use of the new object is restricted to the portio API we can simply set the
opaque pointer (and the heap-allocated port list) internally.

Signed-off-by: Mark Cave-Ayland <mark.cave-ayland@ilande.co.uk>
Reviewed-by: Philippe Mathieu-Daudé <philmd@linaro.org>
Message-Id: <20230419151652.362717-3-mark.cave-ayland@ilande.co.uk>
Signed-off-by: Paolo Bonzini <pbonzini@redhat.com>
---
 softmmu/ioport.c | 36 +++++++++++++++++++++++++++++++-----
 1 file changed, 31 insertions(+), 5 deletions(-)

diff --git a/softmmu/ioport.c b/softmmu/ioport.c
index d0d5b0bcaa2d..33720fe5664a 100644
--- a/softmmu/ioport.c
+++ b/softmmu/ioport.c
@@ -32,11 +32,16 @@
 #include "exec/address-spaces.h"
 #include "trace.h"
 
-typedef struct MemoryRegionPortioList {
+struct MemoryRegionPortioList {
+    Object obj;
+
     MemoryRegion mr;
     void *portio_opaque;
     MemoryRegionPortio *ports;
-} MemoryRegionPortioList;
+};
+
+#define TYPE_MEMORY_REGION_PORTIO_LIST "memory-region-portio-list"
+OBJECT_DECLARE_SIMPLE_TYPE(MemoryRegionPortioList, MEMORY_REGION_PORTIO_LIST)
 
 static uint64_t unassigned_io_read(void *opaque, hwaddr addr, unsigned size)
 {
@@ -147,8 +152,7 @@ void portio_list_destroy(PortioList *piolist)
     for (i = 0; i < piolist->nr; ++i) {
         mrpio = container_of(piolist->regions[i], MemoryRegionPortioList, mr);
         object_unparent(OBJECT(&mrpio->mr));
-        g_free(mrpio->ports);
-        g_free(mrpio);
+        object_unref(mrpio);
     }
     g_free(piolist->regions);
 }
@@ -228,7 +232,8 @@ static void portio_list_add_1(PortioList *piolist,
     unsigned i;
 
     /* Copy the sub-list and null-terminate it.  */
-    mrpio = g_malloc0(sizeof(MemoryRegionPortioList));
+    mrpio = MEMORY_REGION_PORTIO_LIST(
+                object_new(TYPE_MEMORY_REGION_PORTIO_LIST));
     mrpio->portio_opaque = piolist->opaque;
     mrpio->ports = g_malloc0(sizeof(MemoryRegionPortio) * (count + 1));
     memcpy(mrpio->ports, pio_init, sizeof(MemoryRegionPortio) * count);
@@ -298,3 +303,24 @@ void portio_list_del(PortioList *piolist)
         memory_region_del_subregion(piolist->address_space, &mrpio->mr);
     }
 }
+
+static void memory_region_portio_list_finalize(Object *obj)
+{
+    MemoryRegionPortioList *mrpio = MEMORY_REGION_PORTIO_LIST(obj);
+
+    g_free(mrpio->ports);
+}
+
+static const TypeInfo memory_region_portio_list_info = {
+    .parent             = TYPE_OBJECT,
+    .name               = TYPE_MEMORY_REGION_PORTIO_LIST,
+    .instance_size      = sizeof(MemoryRegionPortioList),
+    .instance_finalize  = memory_region_portio_list_finalize,
+};
+
+static void ioport_register_types(void)
+{
+    type_register_static(&memory_region_portio_list_info);
+}
+
+type_init(ioport_register_types)
-- 
2.40.1



  parent reply	other threads:[~2023-05-25 14:16 UTC|newest]

Thread overview: 22+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2023-05-25 14:15 [PULL 00/20] Misc patches for 2023-05-25 Paolo Bonzini
2023-05-25 14:15 ` [PULL 01/20] target/i386: EPYC-Rome model without XSAVES Paolo Bonzini
2023-05-25 14:15 ` [PULL 02/20] meson.build: Fix glib -Wno-unused-function workaround Paolo Bonzini
2023-05-25 14:15 ` [PULL 03/20] meson: fix rule for qemu-ga installer Paolo Bonzini
2023-05-25 14:15 ` [PULL 04/20] meson: move -no-pie from linker to compiler Paolo Bonzini
2023-05-25 14:15 ` [PULL 05/20] tests/docker: simplify HOST_ARCH definition Paolo Bonzini
2023-05-25 14:15 ` [PULL 06/20] tests/vm: fix and " Paolo Bonzini
2023-05-25 14:15 ` [PULL 07/20] Makefile: remove $(TESTS_PYTHON) Paolo Bonzini
2023-05-25 14:15 ` [PULL 08/20] usb/ohci: Set pad to 0 after frame update Paolo Bonzini
2023-05-25 14:15 ` [PULL 09/20] softmmu/ioport.c: allocate MemoryRegionPortioList ports on the heap Paolo Bonzini
2023-05-25 14:15 ` Paolo Bonzini [this message]
2023-05-25 14:15 ` [PULL 11/20] softmmu/ioport.c: make MemoryRegionPortioList owner of portio_list MemoryRegions Paolo Bonzini
2023-05-25 14:15 ` [PULL 12/20] monitor: use QEMU_LOCK_GUARD a bit more Paolo Bonzini
2023-05-25 14:15 ` [PULL 13/20] monitor: allow calling monitor_resume under mon_lock Paolo Bonzini
2023-05-25 14:15 ` [PULL 14/20] monitor: add more *_locked() functions Paolo Bonzini
2023-05-25 14:15 ` [PULL 15/20] monitor: do not use mb_read/mb_set for suspend_cnt Paolo Bonzini
2023-05-25 14:15 ` [PULL 16/20] monitor: cleanup detection of qmp_dispatcher_co shutting down Paolo Bonzini
2023-05-25 14:15 ` [PULL 17/20] monitor: cleanup fetching of QMP requests Paolo Bonzini
2023-05-25 14:15 ` [PULL 18/20] monitor: introduce qmp_dispatcher_co_wake Paolo Bonzini
2023-05-25 14:15 ` [PULL 19/20] monitor: extract request dequeuing to a new function Paolo Bonzini
2023-05-25 14:15 ` [PULL 20/20] monitor: do not use mb_read/mb_set Paolo Bonzini
2023-05-25 17:15 ` [PULL 00/20] Misc patches for 2023-05-25 Richard Henderson

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=20230525141532.295817-11-pbonzini@redhat.com \
    --to=pbonzini@redhat.com \
    --cc=mark.cave-ayland@ilande.co.uk \
    --cc=philmd@linaro.org \
    --cc=qemu-devel@nongnu.org \
    /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).