All of lore.kernel.org
 help / color / mirror / Atom feed
From: "Philippe Mathieu-Daudé" <f4bug@amsat.org>
To: qemu-devel@nongnu.org
Cc: "Peter Maydell" <peter.maydell@linaro.org>,
	qemu-block@nongnu.org,
	"Philippe Mathieu-Daudé" <philmd@redhat.com>,
	"Richard Henderson" <richard.henderson@linaro.org>,
	"Philippe Mathieu-Daudé" <f4bug@amsat.org>,
	"Andrew Baumann" <Andrew.Baumann@microsoft.com>,
	"Beniamino Galvani" <b.galvani@gmail.com>,
	"Michael Walle" <michael@walle.cc>,
	qemu-arm@nongnu.org
Subject: [PULL 21/23] hw/sd: Use sdbus_read_data() instead of sdbus_read_byte() when possible
Date: Fri, 21 Aug 2020 19:29:14 +0200	[thread overview]
Message-ID: <20200821172916.1260954-22-f4bug@amsat.org> (raw)
In-Reply-To: <20200821172916.1260954-1-f4bug@amsat.org>

Use the recently added sdbus_read_data() to read multiple
bytes at once, instead of looping calling sdbus_read_byte().

Signed-off-by: Philippe Mathieu-Daudé <f4bug@amsat.org>
Reviewed-by: Richard Henderson <richard.henderson@linaro.org>
Message-Id: <20200814092346.21825-8-f4bug@amsat.org>
---
 hw/sd/allwinner-sdhost.c  | 10 +++-------
 hw/sd/milkymist-memcard.c |  7 ++-----
 hw/sd/sdhci.c             | 28 ++++++++--------------------
 3 files changed, 13 insertions(+), 32 deletions(-)

diff --git a/hw/sd/allwinner-sdhost.c b/hw/sd/allwinner-sdhost.c
index eea5659c5f1..f9eb92c09ed 100644
--- a/hw/sd/allwinner-sdhost.c
+++ b/hw/sd/allwinner-sdhost.c
@@ -337,9 +337,7 @@ static uint32_t allwinner_sdhost_process_desc(AwSdHostState *s,
 
         /* Read from SD bus */
         } else {
-            for (uint32_t i = 0; i < buf_bytes; i++) {
-                buf[i] = sdbus_read_byte(&s->sdbus);
-            }
+            sdbus_read_data(&s->sdbus, buf, buf_bytes);
             cpu_physical_memory_write((desc->addr & DESC_SIZE_MASK) + num_done,
                                        buf, buf_bytes);
         }
@@ -518,10 +516,8 @@ static uint64_t allwinner_sdhost_read(void *opaque, hwaddr offset,
         break;
     case REG_SD_FIFO:      /* Read/Write FIFO */
         if (sdbus_data_ready(&s->sdbus)) {
-            res = sdbus_read_byte(&s->sdbus);
-            res |= sdbus_read_byte(&s->sdbus) << 8;
-            res |= sdbus_read_byte(&s->sdbus) << 16;
-            res |= sdbus_read_byte(&s->sdbus) << 24;
+            sdbus_read_data(&s->sdbus, &res, sizeof(uint32_t));
+            le32_to_cpus(&res);
             allwinner_sdhost_update_transfer_cnt(s, sizeof(uint32_t));
             allwinner_sdhost_auto_stop(s);
             allwinner_sdhost_update_irq(s);
diff --git a/hw/sd/milkymist-memcard.c b/hw/sd/milkymist-memcard.c
index 12e091a46e7..be89a938763 100644
--- a/hw/sd/milkymist-memcard.c
+++ b/hw/sd/milkymist-memcard.c
@@ -151,11 +151,8 @@ static uint64_t memcard_read(void *opaque, hwaddr addr,
         if (!s->enabled) {
             r = 0xffffffff;
         } else {
-            r = 0;
-            r |= sdbus_read_byte(&s->sdbus) << 24;
-            r |= sdbus_read_byte(&s->sdbus) << 16;
-            r |= sdbus_read_byte(&s->sdbus) << 8;
-            r |= sdbus_read_byte(&s->sdbus);
+            sdbus_read_data(&s->sdbus, &r, sizeof(r));
+            be32_to_cpus(&r);
         }
         break;
     case R_CLK2XDIV:
diff --git a/hw/sd/sdhci.c b/hw/sd/sdhci.c
index ddf36915619..1785d7e1f79 100644
--- a/hw/sd/sdhci.c
+++ b/hw/sd/sdhci.c
@@ -399,8 +399,6 @@ static void sdhci_end_transfer(SDHCIState *s)
 /* Fill host controller's read buffer with BLKSIZE bytes of data from card */
 static void sdhci_read_block_from_card(SDHCIState *s)
 {
-    int index = 0;
-    uint8_t data;
     const uint16_t blk_size = s->blksize & BLOCK_SIZE_MASK;
 
     if ((s->trnmod & SDHC_TRNS_MULTI) &&
@@ -408,12 +406,9 @@ static void sdhci_read_block_from_card(SDHCIState *s)
         return;
     }
 
-    for (index = 0; index < blk_size; index++) {
-        data = sdbus_read_byte(&s->sdbus);
-        if (!FIELD_EX32(s->hostctl2, SDHC_HOSTCTL2, EXECUTE_TUNING)) {
-            /* Device is not in tuning */
-            s->fifo_buffer[index] = data;
-        }
+    if (!FIELD_EX32(s->hostctl2, SDHC_HOSTCTL2, EXECUTE_TUNING)) {
+        /* Device is not in tuning */
+        sdbus_read_data(&s->sdbus, s->fifo_buffer, blk_size);
     }
 
     if (FIELD_EX32(s->hostctl2, SDHC_HOSTCTL2, EXECUTE_TUNING)) {
@@ -574,7 +569,7 @@ static void sdhci_write_dataport(SDHCIState *s, uint32_t value, unsigned size)
 static void sdhci_sdma_transfer_multi_blocks(SDHCIState *s)
 {
     bool page_aligned = false;
-    unsigned int n, begin;
+    unsigned int begin;
     const uint16_t block_size = s->blksize & BLOCK_SIZE_MASK;
     uint32_t boundary_chk = 1 << (((s->blksize & ~BLOCK_SIZE_MASK) >> 12) + 12);
     uint32_t boundary_count = boundary_chk - (s->sdmasysad % boundary_chk);
@@ -596,9 +591,7 @@ static void sdhci_sdma_transfer_multi_blocks(SDHCIState *s)
                 SDHC_DAT_LINE_ACTIVE;
         while (s->blkcnt) {
             if (s->data_count == 0) {
-                for (n = 0; n < block_size; n++) {
-                    s->fifo_buffer[n] = sdbus_read_byte(&s->sdbus);
-                }
+                sdbus_read_data(&s->sdbus, s->fifo_buffer, block_size);
             }
             begin = s->data_count;
             if (((boundary_count + begin) < block_size) && page_aligned) {
@@ -662,13 +655,10 @@ static void sdhci_sdma_transfer_multi_blocks(SDHCIState *s)
 /* single block SDMA transfer */
 static void sdhci_sdma_transfer_single_block(SDHCIState *s)
 {
-    int n;
     uint32_t datacnt = s->blksize & BLOCK_SIZE_MASK;
 
     if (s->trnmod & SDHC_TRNS_READ) {
-        for (n = 0; n < datacnt; n++) {
-            s->fifo_buffer[n] = sdbus_read_byte(&s->sdbus);
-        }
+        sdbus_read_data(&s->sdbus, s->fifo_buffer, datacnt);
         dma_memory_write(s->dma_as, s->sdmasysad, s->fifo_buffer, datacnt);
     } else {
         dma_memory_read(s->dma_as, s->sdmasysad, s->fifo_buffer, datacnt);
@@ -731,7 +721,7 @@ static void get_adma_description(SDHCIState *s, ADMADescr *dscr)
 
 static void sdhci_do_adma(SDHCIState *s)
 {
-    unsigned int n, begin, length;
+    unsigned int begin, length;
     const uint16_t block_size = s->blksize & BLOCK_SIZE_MASK;
     ADMADescr dscr = {};
     int i;
@@ -765,9 +755,7 @@ static void sdhci_do_adma(SDHCIState *s)
             if (s->trnmod & SDHC_TRNS_READ) {
                 while (length) {
                     if (s->data_count == 0) {
-                        for (n = 0; n < block_size; n++) {
-                            s->fifo_buffer[n] = sdbus_read_byte(&s->sdbus);
-                        }
+                        sdbus_read_data(&s->sdbus, s->fifo_buffer, block_size);
                     }
                     begin = s->data_count;
                     if ((length + begin) < block_size) {
-- 
2.26.2



  parent reply	other threads:[~2020-08-21 17:43 UTC|newest]

Thread overview: 35+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2020-08-21 17:28 [PULL 00/23] SD/MMC patches for 2020-08-21 Philippe Mathieu-Daudé
2020-08-21 17:28 ` [PULL 01/23] hw/sd/pxa2xx_mmci: Do not create SD card within the SD host controller Philippe Mathieu-Daudé
2020-08-21 17:28 ` [PULL 02/23] hw/sd/pxa2xx_mmci: Trivial simplification Philippe Mathieu-Daudé
2020-08-21 17:28 ` [PULL 03/23] hw/lm32/milkymist: Un-inline milkymist_memcard_create() Philippe Mathieu-Daudé
2020-08-21 17:28 ` [PULL 04/23] hw/sd/milkymist: Create the SDBus at init() Philippe Mathieu-Daudé
2020-08-21 17:28 ` [PULL 05/23] hw/sd/milkymist: Do not create SD card within the SD host controller Philippe Mathieu-Daudé
2020-08-21 17:28 ` [PULL 06/23] hw/sd/pl181: Replace fprintf(stderr, "*\n") with error_report() Philippe Mathieu-Daudé
2020-08-21 17:29 ` [PULL 07/23] hw/sd/pl181: Rename pl181_send_command() as pl181_do_command() Philippe Mathieu-Daudé
2020-08-21 17:29 ` [PULL 08/23] hw/sd/pl181: Add TODO to use Fifo32 API Philippe Mathieu-Daudé
2020-08-21 17:29 ` [PULL 09/23] hw/sd/pl181: Use named GPIOs Philippe Mathieu-Daudé
2020-08-21 17:29 ` [PULL 10/23] hw/sd/pl181: Expose a SDBus and connect the SDCard to it Philippe Mathieu-Daudé
2020-08-21 17:29 ` [PULL 11/23] hw/sd/pl181: Do not create SD card within the SD host controller Philippe Mathieu-Daudé
2020-08-21 17:29 ` [PULL 12/23] hw/sd/pl181: Replace disabled fprintf()s by trace events Philippe Mathieu-Daudé
2020-08-21 17:29 ` [PULL 13/23] hw/sd/sdcard: Make sd_data_ready() static Philippe Mathieu-Daudé
2020-08-21 17:29 ` [PULL 14/23] hw/sd: Move sdcard legacy API to 'hw/sd/sdcard_legacy.h' Philippe Mathieu-Daudé
2020-08-21 17:29 ` [PULL 15/23] hw/sd: Rename read/write_data() as read/write_byte() Philippe Mathieu-Daudé
2020-08-21 17:29 ` [PULL 16/23] hw/sd: Rename sdbus_write_data() as sdbus_write_byte() Philippe Mathieu-Daudé
2020-08-21 17:29 ` [PULL 17/23] hw/sd: Rename sdbus_read_data() as sdbus_read_byte() Philippe Mathieu-Daudé
2020-08-21 17:29 ` [PULL 18/23] hw/sd: Add sdbus_write_data() to write multiples bytes on the data line Philippe Mathieu-Daudé
2020-08-21 17:29 ` [PULL 19/23] hw/sd: Use sdbus_write_data() instead of sdbus_write_byte when possible Philippe Mathieu-Daudé
2020-08-21 17:29 ` [PULL 20/23] hw/sd: Add sdbus_read_data() to read multiples bytes on the data line Philippe Mathieu-Daudé
2020-08-21 17:29 ` Philippe Mathieu-Daudé [this message]
2020-08-21 17:29 ` [PULL 22/23] hw/sd: Fix incorrect populated function switch status data structure Philippe Mathieu-Daudé
2020-10-20 15:16   ` Philippe Mathieu-Daudé
2020-10-21  9:57     ` Bin Meng
2020-10-21 10:07       ` Philippe Mathieu-Daudé
2020-10-22 14:47         ` Bin Meng
2020-10-22 15:20           ` Niek Linnenbank
2020-10-23  2:02             ` Bin Meng
2020-10-23  9:23               ` Philippe Mathieu-Daudé
2020-10-23  9:34                 ` Should we keep using Avocado for functional testing? (was: Re: [PULL 22/23] hw/sd: Fix incorrect populated function switch status data structure) Philippe Mathieu-Daudé
2020-10-24 21:41                   ` Niek Linnenbank
2020-10-26 16:14                   ` Cleber Rosa
2020-08-21 17:29 ` [PULL 23/23] hw/sd: Correct the maximum size of a Standard Capacity SD Memory Card Philippe Mathieu-Daudé
2020-08-23 10:37 ` [PULL 00/23] SD/MMC patches for 2020-08-21 Peter Maydell

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=20200821172916.1260954-22-f4bug@amsat.org \
    --to=f4bug@amsat.org \
    --cc=Andrew.Baumann@microsoft.com \
    --cc=b.galvani@gmail.com \
    --cc=michael@walle.cc \
    --cc=peter.maydell@linaro.org \
    --cc=philmd@redhat.com \
    --cc=qemu-arm@nongnu.org \
    --cc=qemu-block@nongnu.org \
    --cc=qemu-devel@nongnu.org \
    --cc=richard.henderson@linaro.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.