qemu-block
[Top][All Lists]
Advanced

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

[Qemu-block] [PATCH 09/13] hw/block/pflash_cfi02: Use the ldst API in pf


From: Philippe Mathieu-Daudé
Subject: [Qemu-block] [PATCH 09/13] hw/block/pflash_cfi02: Use the ldst API in pflash_read()
Date: Mon, 6 May 2019 00:15:40 +0200

The load/store API eases code review.

Signed-off-by: Stephen Checkoway <address@hidden>
Message-Id: <address@hidden>
Reviewed-by: Philippe Mathieu-Daudé <address@hidden>
Tested-by: Philippe Mathieu-Daudé <address@hidden>
[PMD: Extracted from bigger patch]
Signed-off-by: Philippe Mathieu-Daudé <address@hidden>
---
 hw/block/pflash_cfi02.c | 26 ++++++--------------------
 1 file changed, 6 insertions(+), 20 deletions(-)

diff --git a/hw/block/pflash_cfi02.c b/hw/block/pflash_cfi02.c
index 69e0086324e..2777167af11 100644
--- a/hw/block/pflash_cfi02.c
+++ b/hw/block/pflash_cfi02.c
@@ -196,34 +196,20 @@ static uint32_t pflash_read(PFlashCFI02 *pfl, hwaddr 
offset,
     case 0x00:
     flash_read:
         /* Flash area read */
-        p = pfl->storage;
+        p = (uint8_t *)pfl->storage + offset;
+        if (pfl->be) {
+            ret = ldn_be_p(p, width);
+        } else {
+            ret = ldn_le_p(p, width);
+        }
         switch (width) {
         case 1:
-            ret = p[offset];
             trace_pflash_data_read8(offset, ret);
             break;
         case 2:
-            if (be) {
-                ret = p[offset] << 8;
-                ret |= p[offset + 1];
-            } else {
-                ret = p[offset];
-                ret |= p[offset + 1] << 8;
-            }
             trace_pflash_data_read16(offset, ret);
             break;
         case 4:
-            if (be) {
-                ret = p[offset] << 24;
-                ret |= p[offset + 1] << 16;
-                ret |= p[offset + 2] << 8;
-                ret |= p[offset + 3];
-            } else {
-                ret = p[offset];
-                ret |= p[offset + 1] << 8;
-                ret |= p[offset + 2] << 16;
-                ret |= p[offset + 3] << 24;
-            }
             trace_pflash_data_read32(offset, ret);
             break;
         }
-- 
2.20.1




reply via email to

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