From: Laurent Vivier <laurent@vivier.eu>
To: "Philippe Mathieu-Daudé" <philmd@redhat.com>,
"Stefano Garzarella" <sgarzare@redhat.com>,
qemu-devel@nongnu.org
Cc: Peter Maydell <peter.maydell@linaro.org>,
Paolo Bonzini <pbonzini@redhat.com>
Subject: Re: [PATCH v2 1/2] exec/memory: Extract address_space_set() from dma_memory_set()
Date: Thu, 15 Apr 2021 12:46:34 +0200 [thread overview]
Message-ID: <9a72b757-1d9a-f4c7-e22c-8a073a48a9a9@vivier.eu> (raw)
In-Reply-To: <20210415100409.3977971-2-philmd@redhat.com>
Le 15/04/2021 à 12:04, Philippe Mathieu-Daudé a écrit :
> dma_memory_set() does a DMA barrier, set the address space with
> a constant value. The constant value filling code is not specific
> to DMA and can be used for AddressSpace. Extract it as a new
> helper: address_space_set().
>
> Signed-off-by: Philippe Mathieu-Daudé <philmd@redhat.com>
> ---
> include/exec/memory.h | 16 ++++++++++++++++
> softmmu/dma-helpers.c | 16 +---------------
> softmmu/physmem.c | 19 +++++++++++++++++++
> 3 files changed, 36 insertions(+), 15 deletions(-)
>
> diff --git a/include/exec/memory.h b/include/exec/memory.h
> index 5728a681b27..192139af58e 100644
> --- a/include/exec/memory.h
> +++ b/include/exec/memory.h
> @@ -2568,6 +2568,22 @@ address_space_write_cached(MemoryRegionCache *cache, hwaddr addr,
> }
> }
>
> +/**
> + * address_space_set: Fill address space with a constant byte.
> + *
> + * Return a MemTxResult indicating whether the operation succeeded
> + * or failed (eg unassigned memory, device rejected the transaction,
> + * IOMMU fault).
> + *
> + * @as: #AddressSpace to be accessed
> + * @addr: address within that address space
> + * @c: constant byte to fill the memory
> + * @len: the number of bytes to fill with the constant byte
> + * @attrs: memory transaction attributes
> + */
> +MemTxResult address_space_set(AddressSpace *as, hwaddr addr,
> + uint8_t c, hwaddr len, MemTxAttrs attrs);
> +
> #ifdef NEED_CPU_H
> /* enum device_endian to MemOp. */
> static inline MemOp devend_memop(enum device_endian end)
> diff --git a/softmmu/dma-helpers.c b/softmmu/dma-helpers.c
> index 7d766a5e89a..8e1e7ad5320 100644
> --- a/softmmu/dma-helpers.c
> +++ b/softmmu/dma-helpers.c
> @@ -23,21 +23,7 @@ MemTxResult dma_memory_set(AddressSpace *as, dma_addr_t addr,
> {
> dma_barrier(as, DMA_DIRECTION_FROM_DEVICE);
>
> -#define FILLBUF_SIZE 512
> - uint8_t fillbuf[FILLBUF_SIZE];
> - int l;
> - MemTxResult error = MEMTX_OK;
> -
> - memset(fillbuf, c, FILLBUF_SIZE);
> - while (len > 0) {
> - l = len < FILLBUF_SIZE ? len : FILLBUF_SIZE;
> - error |= address_space_write(as, addr, MEMTXATTRS_UNSPECIFIED,
> - fillbuf, l);
> - len -= l;
> - addr += l;
> - }
> -
> - return error;
> + return address_space_set(as, addr, c, len, MEMTXATTRS_UNSPECIFIED);
> }
>
> void qemu_sglist_init(QEMUSGList *qsg, DeviceState *dev, int alloc_hint,
> diff --git a/softmmu/physmem.c b/softmmu/physmem.c
> index 85034d9c11e..c9117527ae7 100644
> --- a/softmmu/physmem.c
> +++ b/softmmu/physmem.c
> @@ -2891,6 +2891,25 @@ MemTxResult address_space_rw(AddressSpace *as, hwaddr addr, MemTxAttrs attrs,
> }
> }
>
> +MemTxResult address_space_set(AddressSpace *as, hwaddr addr,
> + uint8_t c, hwaddr len, MemTxAttrs attrs)
> +{
> +#define FILLBUF_SIZE 512
> + uint8_t fillbuf[FILLBUF_SIZE];
> + int l;
> + MemTxResult error = MEMTX_OK;
> +
> + memset(fillbuf, c, FILLBUF_SIZE);
> + while (len > 0) {
> + l = len < FILLBUF_SIZE ? len : FILLBUF_SIZE;
> + error |= address_space_write(as, addr, attrs, fillbuf, l);
> + len -= l;
> + addr += l;
> + }
> +
> + return error;
> +}
> +
> void cpu_physical_memory_rw(hwaddr addr, void *buf,
> hwaddr len, bool is_write)
> {
>
Reviewed-by: Laurent Vivier <laurent@vivier.eu>
next prev parent reply other threads:[~2021-04-15 10:49 UTC|newest]
Thread overview: 12+ messages / expand[flat|nested] mbox.gz Atom feed top
2021-04-15 10:04 [PATCH v2 0/2] hw/elf_ops: clear uninitialized segment space Philippe Mathieu-Daudé
2021-04-15 10:04 ` [PATCH v2 1/2] exec/memory: Extract address_space_set() from dma_memory_set() Philippe Mathieu-Daudé
2021-04-15 10:46 ` Laurent Vivier [this message]
2021-04-15 11:00 ` Stefano Garzarella
2021-04-15 11:05 ` Peter Maydell
2021-04-15 11:18 ` Stefano Garzarella
2021-04-15 22:32 ` Richard Henderson
2021-04-15 10:04 ` [PATCH v2 2/2] hw/elf_ops: clear uninitialized segment space Philippe Mathieu-Daudé
2021-04-15 11:02 ` Stefano Garzarella
2021-04-15 13:26 ` Laurent Vivier
2021-04-15 22:33 ` Richard Henderson
2021-04-17 15:36 ` Laurent Vivier
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=9a72b757-1d9a-f4c7-e22c-8a073a48a9a9@vivier.eu \
--to=laurent@vivier.eu \
--cc=pbonzini@redhat.com \
--cc=peter.maydell@linaro.org \
--cc=philmd@redhat.com \
--cc=qemu-devel@nongnu.org \
--cc=sgarzare@redhat.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).