qemu-devel.nongnu.org archive mirror
 help / color / mirror / Atom feed
From: "Philippe Mathieu-Daudé" <philmd@redhat.com>
To: qemu-devel@nongnu.org
Cc: "Fam Zheng" <fam@euphon.net>,
	"Peter Maydell" <peter.maydell@linaro.org>,
	"Jason Wang" <jasowang@redhat.com>,
	"Mark Cave-Ayland" <mark.cave-ayland@ilande.co.uk>,
	"Laurent Vivier" <laurent@vivier.eu>,
	"Paolo Bonzini" <pbonzini@redhat.com>,
	"Philippe Mathieu-Daudé" <philmd@redhat.com>
Subject: [PATCH 3/3] hw/net/pcnet: Let phys_mem_read/write take void pointer and boolean
Date: Fri, 21 Feb 2020 14:25:50 +0100	[thread overview]
Message-ID: <20200221132550.22156-4-philmd@redhat.com> (raw)
In-Reply-To: <20200221132550.22156-1-philmd@redhat.com>

Both PCNetState::phys_mem_read/write handlers end calling
dma_memory_read/write, which both take void pointers (since
introduced in commit d86a77f8). The PCNetState phys_mem_read/write
handlers can take a void pointer too.
As the length is always a sizeof(), use a size_t type.
The 'do_bswap' is used as a boolean argument. Use an explicit
boolean type.

The changes in hw/net/pcnet.c are produced using the following
Coccinelle script:

    @@
    expression E1, E2, E3, E4;
    @@
    (
    - s->phys_mem_read(E1, E2, (void *)(E3), E4, 0);
    + s->phys_mem_read(E1, E2, E3, E4, false);
    |
    - s->phys_mem_write(E1, E2, (void *)(E3), E4, 0);
    + s->phys_mem_write(E1, E2, E3, E4, false);
    |
    - s->phys_mem_read(E1, E2, (void *)(E3), E4, 1);
    + s->phys_mem_read(E1, E2, E3, E4, true);
    |
    - s->phys_mem_write(E1, E2, (void *)(E3), E4, 1);
    + s->phys_mem_write(E1, E2, E3, E4, true);
    )

Signed-off-by: Philippe Mathieu-Daudé <philmd@redhat.com>
---
 hw/net/pcnet.h                 |  4 ++--
 include/hw/sparc/sparc32_dma.h |  4 ++--
 hw/dma/sparc32_dma.c           |  4 ++--
 hw/net/pcnet-pci.c             |  5 +++--
 hw/net/pcnet.c                 | 16 ++++++++--------
 5 files changed, 17 insertions(+), 16 deletions(-)

diff --git a/hw/net/pcnet.h b/hw/net/pcnet.h
index f49b213c57..3f15e6f065 100644
--- a/hw/net/pcnet.h
+++ b/hw/net/pcnet.h
@@ -47,9 +47,9 @@ struct PCNetState_st {
     uint8_t buffer[4096];
     qemu_irq irq;
     void (*phys_mem_read)(void *dma_opaque, hwaddr addr,
-                         uint8_t *buf, int len, int do_bswap);
+                          void *buf, size_t len, bool do_bswap);
     void (*phys_mem_write)(void *dma_opaque, hwaddr addr,
-                          uint8_t *buf, int len, int do_bswap);
+                           const void *buf, size_t len, bool do_bswap);
     DeviceState *dma_opaque;
     int tx_busy;
     int looptest;
diff --git a/include/hw/sparc/sparc32_dma.h b/include/hw/sparc/sparc32_dma.h
index b3811b617d..db42f7440d 100644
--- a/include/hw/sparc/sparc32_dma.h
+++ b/include/hw/sparc/sparc32_dma.h
@@ -58,8 +58,8 @@ typedef struct SPARC32DMAState {
 
 /* sparc32_dma.c */
 void ledma_memory_read(void *opaque, hwaddr addr,
-                       uint8_t *buf, int len, int do_bswap);
+                       void *buf, size_t len, bool do_bswap);
 void ledma_memory_write(void *opaque, hwaddr addr,
-                        uint8_t *buf, int len, int do_bswap);
+                        const void *buf, size_t len, bool do_bswap);
 
 #endif
diff --git a/hw/dma/sparc32_dma.c b/hw/dma/sparc32_dma.c
index fbe58b8fea..629f9830f7 100644
--- a/hw/dma/sparc32_dma.c
+++ b/hw/dma/sparc32_dma.c
@@ -72,7 +72,7 @@ enum {
 
 /* Note: on sparc, the lance 16 bit bus is swapped */
 void ledma_memory_read(void *opaque, hwaddr addr,
-                       uint8_t *buf, int len, int do_bswap)
+                       void *buf, size_t len, bool do_bswap)
 {
     DMADeviceState *s = opaque;
     IOMMUState *is = (IOMMUState *)s->iommu;
@@ -93,7 +93,7 @@ void ledma_memory_read(void *opaque, hwaddr addr,
 }
 
 void ledma_memory_write(void *opaque, hwaddr addr,
-                        uint8_t *buf, int len, int do_bswap)
+                        const void *buf, size_t len, bool do_bswap)
 {
     DMADeviceState *s = opaque;
     IOMMUState *is = (IOMMUState *)s->iommu;
diff --git a/hw/net/pcnet-pci.c b/hw/net/pcnet-pci.c
index d1f31e0272..4e4d60b046 100644
--- a/hw/net/pcnet-pci.c
+++ b/hw/net/pcnet-pci.c
@@ -167,13 +167,14 @@ static const MemoryRegionOps pcnet_mmio_ops = {
 };
 
 static void pci_physical_memory_write(void *dma_opaque, hwaddr addr,
-                                      uint8_t *buf, int len, int do_bswap)
+                                      const void *buf, size_t len,
+                                      bool do_bswap)
 {
     pci_dma_write(dma_opaque, addr, buf, len);
 }
 
 static void pci_physical_memory_read(void *dma_opaque, hwaddr addr,
-                                     uint8_t *buf, int len, int do_bswap)
+                                     void *buf, size_t len, bool do_bswap)
 {
     pci_dma_read(dma_opaque, addr, buf, len);
 }
diff --git a/hw/net/pcnet.c b/hw/net/pcnet.c
index f3f18d8598..d669ca2aa3 100644
--- a/hw/net/pcnet.c
+++ b/hw/net/pcnet.c
@@ -305,14 +305,14 @@ static inline void pcnet_tmd_load(PCNetState *s, struct pcnet_TMD *tmd,
             int16_t length;
             int16_t status;
         } xda;
-        s->phys_mem_read(s->dma_opaque, addr, (void *)&xda, sizeof(xda), 0);
+        s->phys_mem_read(s->dma_opaque, addr, &xda, sizeof(xda), false);
         tmd->tbadr = le32_to_cpu(xda.tbadr) & 0xffffff;
         tmd->length = le16_to_cpu(xda.length);
         tmd->status = (le32_to_cpu(xda.tbadr) >> 16) & 0xff00;
         tmd->misc = le16_to_cpu(xda.status) << 16;
         tmd->res = 0;
     } else {
-        s->phys_mem_read(s->dma_opaque, addr, (void *)tmd, sizeof(*tmd), 0);
+        s->phys_mem_read(s->dma_opaque, addr, tmd, sizeof(*tmd), false);
         le32_to_cpus(&tmd->tbadr);
         le16_to_cpus((uint16_t *)&tmd->length);
         le16_to_cpus((uint16_t *)&tmd->status);
@@ -339,7 +339,7 @@ static inline void pcnet_tmd_store(PCNetState *s, const struct pcnet_TMD *tmd,
                                 ((tmd->status & 0xff00) << 16));
         xda.length = cpu_to_le16(tmd->length);
         xda.status = cpu_to_le16(tmd->misc >> 16);
-        s->phys_mem_write(s->dma_opaque, addr, (void *)&xda, sizeof(xda), 0);
+        s->phys_mem_write(s->dma_opaque, addr, &xda, sizeof(xda), false);
     } else {
         struct {
             uint32_t tbadr;
@@ -358,7 +358,7 @@ static inline void pcnet_tmd_store(PCNetState *s, const struct pcnet_TMD *tmd,
             xda.tbadr = xda.misc;
             xda.misc = tmp;
         }
-        s->phys_mem_write(s->dma_opaque, addr, (void *)&xda, sizeof(xda), 0);
+        s->phys_mem_write(s->dma_opaque, addr, &xda, sizeof(xda), false);
     }
 }
 
@@ -371,14 +371,14 @@ static inline void pcnet_rmd_load(PCNetState *s, struct pcnet_RMD *rmd,
             int16_t buf_length;
             int16_t msg_length;
 	} rda;
-        s->phys_mem_read(s->dma_opaque, addr, (void *)&rda, sizeof(rda), 0);
+        s->phys_mem_read(s->dma_opaque, addr, &rda, sizeof(rda), false);
         rmd->rbadr = le32_to_cpu(rda.rbadr) & 0xffffff;
         rmd->buf_length = le16_to_cpu(rda.buf_length);
         rmd->status = (le32_to_cpu(rda.rbadr) >> 16) & 0xff00;
         rmd->msg_length = le16_to_cpu(rda.msg_length);
         rmd->res = 0;
     } else {
-        s->phys_mem_read(s->dma_opaque, addr, (void *)rmd, sizeof(*rmd), 0);
+        s->phys_mem_read(s->dma_opaque, addr, rmd, sizeof(*rmd), false);
         le32_to_cpus(&rmd->rbadr);
         le16_to_cpus((uint16_t *)&rmd->buf_length);
         le16_to_cpus((uint16_t *)&rmd->status);
@@ -405,7 +405,7 @@ static inline void pcnet_rmd_store(PCNetState *s, struct pcnet_RMD *rmd,
                                 ((rmd->status & 0xff00) << 16));
         rda.buf_length = cpu_to_le16(rmd->buf_length);
         rda.msg_length = cpu_to_le16(rmd->msg_length);
-        s->phys_mem_write(s->dma_opaque, addr, (void *)&rda, sizeof(rda), 0);
+        s->phys_mem_write(s->dma_opaque, addr, &rda, sizeof(rda), false);
     } else {
         struct {
             uint32_t rbadr;
@@ -424,7 +424,7 @@ static inline void pcnet_rmd_store(PCNetState *s, struct pcnet_RMD *rmd,
             rda.rbadr = rda.msg_length;
             rda.msg_length = tmp;
         }
-        s->phys_mem_write(s->dma_opaque, addr, (void *)&rda, sizeof(rda), 0);
+        s->phys_mem_write(s->dma_opaque, addr, &rda, sizeof(rda), false);
     }
 }
 
-- 
2.21.1



  parent reply	other threads:[~2020-02-21 13:38 UTC|newest]

Thread overview: 7+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2020-02-21 13:25 [PATCH 0/3] hw: More dma_memory_read/write() API cleanup Philippe Mathieu-Daudé
2020-02-21 13:25 ` [PATCH 1/3] hw/dma/sparc32_dma: Make espdma_memory_[read/write] static Philippe Mathieu-Daudé
2020-02-21 13:27   ` Peter Maydell
2020-02-21 13:25 ` [PATCH 2/3] hw/scsi/esp: Let ESPDMAMemoryReadWriteFunc take void pointer and size_t Philippe Mathieu-Daudé
2020-02-21 13:25 ` Philippe Mathieu-Daudé [this message]
2020-02-21 16:34 ` [PATCH 0/3] hw: More dma_memory_read/write() API cleanup Paolo Bonzini
2020-02-22 19:39 ` Mark Cave-Ayland

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=20200221132550.22156-4-philmd@redhat.com \
    --to=philmd@redhat.com \
    --cc=fam@euphon.net \
    --cc=jasowang@redhat.com \
    --cc=laurent@vivier.eu \
    --cc=mark.cave-ayland@ilande.co.uk \
    --cc=pbonzini@redhat.com \
    --cc=peter.maydell@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).