qemu-arm
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: [PATCH 4/6] hw/dma: Replace alloc() + address_space_init() by addres


From: Peter Maydell
Subject: Re: [PATCH 4/6] hw/dma: Replace alloc() + address_space_init() by address_space_create()
Date: Thu, 19 Aug 2021 15:38:15 +0100

On Thu, 19 Aug 2021 at 15:32, Philippe Mathieu-Daudé <philmd@redhat.com> wrote:
>
> On 8/19/21 4:22 PM, Peter Maydell wrote:
> > On Thu, 19 Aug 2021 at 15:21, Philippe Mathieu-Daudé <philmd@redhat.com> 
> > wrote:
> >>
> >> 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;
> >>  }
> >
> > Why are these devices doing a heap allocation rather than
> > having an AddressSpace whatever field in their device struct ?
>
> To easily use &address_space_memory if 'memory' link is NULL?

They could do that with
    AddressSpace our_as;
    AddressSpace *dma_as;

and set dma_as to &s->our_as or &address_space_memory.

Or we could fix the two boards which create these devices to always
pass in an MR to use for DMA and drop the conditionality.

-- PMM



reply via email to

[Prev in Thread] Current Thread [Next in Thread]