summary refs log tree commit diff stats
path: root/hw/sd/sd.c
diff options
context:
space:
mode:
authorPhilippe Mathieu-Daudé <f4bug@amsat.org>2020-10-26 01:32:52 +0100
committerPhilippe Mathieu-Daudé <philmd@linaro.org>2024-07-02 10:08:32 +0200
commitcb49e2ca22b830f0ca2752118b0bd01981e02bf3 (patch)
tree72c1d8cc091bdefa39d3af764a30742428156844 /hw/sd/sd.c
parent12160bebd4ed928fb4decdde4c4adc6af044839f (diff)
downloadfocaccia-qemu-cb49e2ca22b830f0ca2752118b0bd01981e02bf3.tar.gz
focaccia-qemu-cb49e2ca22b830f0ca2752118b0bd01981e02bf3.zip
hw/sd/sdcard: Extract sd_blk_len() helper
Extract sd_blk_len() helper, use definitions instead
of magic values.

Signed-off-by: Philippe Mathieu-Daudé <f4bug@amsat.org>
Signed-off-by: Philippe Mathieu-Daudé <philmd@linaro.org>
Tested-by: Cédric Le Goater <clg@redhat.com>
Reviewed-by: Cédric Le Goater <clg@redhat.com>
Message-Id: <20240628070216.92609-15-philmd@linaro.org>
Diffstat (limited to 'hw/sd/sd.c')
-rw-r--r--hw/sd/sd.c10
1 files changed, 9 insertions, 1 deletions
diff --git a/hw/sd/sd.c b/hw/sd/sd.c
index d06e670024..18bb2f9fd8 100644
--- a/hw/sd/sd.c
+++ b/hw/sd/sd.c
@@ -601,6 +601,14 @@ static void sd_response_r7_make(SDState *sd, uint8_t *response)
     stl_be_p(response, sd->vhs);
 }
 
+static uint32_t sd_blk_len(SDState *sd)
+{
+    if (FIELD_EX32(sd->ocr, OCR, CARD_CAPACITY)) {
+        return 1 << HWBLOCK_SHIFT;
+    }
+    return sd->blk_len;
+}
+
 static uint64_t sd_req_get_address(SDState *sd, SDRequest req)
 {
     uint64_t addr;
@@ -2074,7 +2082,7 @@ uint8_t sd_read_byte(SDState *sd)
     if (sd->card_status & (ADDRESS_ERROR | WP_VIOLATION))
         return 0x00;
 
-    io_len = (sd->ocr & (1 << 30)) ? 512 : sd->blk_len;
+    io_len = sd_blk_len(sd);
 
     trace_sdcard_read_data(sd->proto->name,
                            sd->last_cmd_name,