All of lore.kernel.org
 help / color / mirror / Atom feed
From: "Philippe Mathieu-Daudé" <philmd@redhat.com>
To: qemu-devel@nongnu.org
Cc: "Peter Maydell" <peter.maydell@linaro.org>,
	"David Hildenbrand" <david@redhat.com>,
	"Mark Cave-Ayland" <mark.cave-ayland@ilande.co.uk>,
	"Alistair Francis" <alistair@alistair23.me>,
	"Jianxian Wen" <jianxian.wen@verisilicon.com>,
	"Peter Xu" <peterx@redhat.com>,
	qemu-arm@nongnu.org, "Gerd Hoffmann" <kraxel@redhat.com>,
	"Paolo Bonzini" <pbonzini@redhat.com>,
	"Edgar E. Iglesias" <edgar.iglesias@gmail.com>,
	"Philippe Mathieu-Daudé" <philmd@redhat.com>
Subject: [PATCH 4/6] hw/dma: Replace alloc() + address_space_init() by address_space_create()
Date: Thu, 19 Aug 2021 16:20:37 +0200	[thread overview]
Message-ID: <20210819142039.2825366-5-philmd@redhat.com> (raw)
In-Reply-To: <20210819142039.2825366-1-philmd@redhat.com>

Replace g_malloc0() + address_space_init() by address_space_create().
Release the resource in DeviceUnrealize().

Signed-off-by: Philippe Mathieu-Daudé <philmd@redhat.com>
---
 hw/dma/xlnx-zdma.c    | 15 +++++++++------
 hw/dma/xlnx_csu_dma.c |  9 ++-------
 2 files changed, 11 insertions(+), 13 deletions(-)

diff --git a/hw/dma/xlnx-zdma.c b/hw/dma/xlnx-zdma.c
index fa38a556341..9f6b3fa47c6 100644
--- a/hw/dma/xlnx-zdma.c
+++ b/hw/dma/xlnx-zdma.c
@@ -777,15 +777,17 @@ static void zdma_realize(DeviceState *dev, Error **errp)
         };
     }
 
-    if (s->dma_mr) {
-        s->dma_as = g_malloc0(sizeof(AddressSpace));
-        address_space_init(s->dma_as, s->dma_mr, NULL);
-    } else {
-        s->dma_as = &address_space_memory;
-    }
+    s->dma_as = address_space_create(s->dma_mr ?: get_system_memory(), NULL);
     s->attr = MEMTXATTRS_UNSPECIFIED;
 }
 
+static void zdma_unrealize(DeviceState *dev)
+{
+    XlnxZDMA *s = XLNX_ZDMA(dev);
+
+    address_space_destroy(s->dma_as);
+}
+
 static void zdma_init(Object *obj)
 {
     XlnxZDMA *s = XLNX_ZDMA(obj);
@@ -827,6 +829,7 @@ static void zdma_class_init(ObjectClass *klass, void *data)
 
     dc->reset = zdma_reset;
     dc->realize = zdma_realize;
+    dc->unrealize = zdma_unrealize;
     device_class_set_props(dc, zdma_props);
     dc->vmsd = &vmstate_zdma;
 }
diff --git a/hw/dma/xlnx_csu_dma.c b/hw/dma/xlnx_csu_dma.c
index 0c1c19cab5a..730c0f999ce 100644
--- a/hw/dma/xlnx_csu_dma.c
+++ b/hw/dma/xlnx_csu_dma.c
@@ -648,13 +648,7 @@ static void xlnx_csu_dma_realize(DeviceState *dev, Error **errp)
     s->src_timer = ptimer_init(xlnx_csu_dma_src_timeout_hit,
                                s, PTIMER_POLICY_DEFAULT);
 
-    if (s->dma_mr) {
-        s->dma_as = g_malloc0(sizeof(AddressSpace));
-        address_space_init(s->dma_as, s->dma_mr, NULL);
-    } else {
-        s->dma_as = &address_space_memory;
-    }
-
+    s->dma_as = address_space_create(s->dma_mr ?: get_system_memory(), NULL);
     s->attr = MEMTXATTRS_UNSPECIFIED;
 
     s->r_size_last_word = 0;
@@ -665,6 +659,7 @@ static void xlnx_csu_dma_unrealize(DeviceState *dev)
     XlnxCSUDMA *s = XLNX_CSU_DMA(dev);
 
     ptimer_free(s->src_timer);
+    address_space_destroy(s->dma_as);
 }
 
 static const VMStateDescription vmstate_xlnx_csu_dma = {
-- 
2.31.1



  parent reply	other threads:[~2021-08-19 14:23 UTC|newest]

Thread overview: 18+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2021-08-19 14:20 [PATCH 0/6] memory: Introduce address_space_create(), re-use &address_space_memory Philippe Mathieu-Daudé
2021-08-19 14:20 ` [PATCH 1/6] memory: Do not increase refcount on global system_memory region Philippe Mathieu-Daudé
2021-08-19 14:23   ` Peter Maydell
2021-08-19 14:20 ` [PATCH 2/6] memory: Introduce address_space_create() Philippe Mathieu-Daudé
2021-08-19 14:24   ` Peter Maydell
2021-08-19 14:36     ` Philippe Mathieu-Daudé
2021-08-19 14:20 ` [PATCH 3/6] memory: Have cpu_address_space_init() use address_space_create() Philippe Mathieu-Daudé
2021-08-19 14:20 ` Philippe Mathieu-Daudé [this message]
2021-08-19 14:22   ` [PATCH 4/6] hw/dma: Replace alloc() + address_space_init() by address_space_create() Peter Maydell
2021-08-19 14:32     ` Philippe Mathieu-Daudé
2021-08-19 14:38       ` Peter Maydell
2021-08-19 14:41         ` Philippe Mathieu-Daudé
2021-08-19 14:20 ` [PATCH 5/6] hw/usb: " Philippe Mathieu-Daudé
2021-08-19 14:20 ` [RFC PATCH 6/6] memory: Have address_space_create() re-use global &address_space_memory Philippe Mathieu-Daudé
2021-08-19 14:34   ` Peter Maydell
2021-08-19 14:41     ` Philippe Mathieu-Daudé
2021-08-20  6:07     ` Gerd Hoffmann
2021-08-20  7:17       ` Philippe Mathieu-Daudé

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=20210819142039.2825366-5-philmd@redhat.com \
    --to=philmd@redhat.com \
    --cc=alistair@alistair23.me \
    --cc=david@redhat.com \
    --cc=edgar.iglesias@gmail.com \
    --cc=jianxian.wen@verisilicon.com \
    --cc=kraxel@redhat.com \
    --cc=mark.cave-ayland@ilande.co.uk \
    --cc=pbonzini@redhat.com \
    --cc=peter.maydell@linaro.org \
    --cc=peterx@redhat.com \
    --cc=qemu-arm@nongnu.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 an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.