diff mbox series

[v42,14/98] hw/sd/sdcard: Extract sd_blk_len() helper

Message ID 20240628070216.92609-15-philmd@linaro.org
State Superseded
Headers show
Series hw/sd/sdcard: Add eMMC support | expand

Commit Message

Philippe Mathieu-Daudé June 28, 2024, 7 a.m. UTC
From: Philippe Mathieu-Daudé <f4bug@amsat.org>

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>
---
 hw/sd/sd.c | 10 +++++++++-
 1 file changed, 9 insertions(+), 1 deletion(-)

Comments

Cédric Le Goater June 28, 2024, 7:28 a.m. UTC | #1
On 6/28/24 9:00 AM, Philippe Mathieu-Daudé wrote:
> From: Philippe Mathieu-Daudé <f4bug@amsat.org>
> 
> 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>


Reviewed-by: Cédric Le Goater <clg@redhat.com>

Thanks,

C.


> ---
>   hw/sd/sd.c | 10 +++++++++-
>   1 file changed, 9 insertions(+), 1 deletion(-)
> 
> diff --git a/hw/sd/sd.c b/hw/sd/sd.c
> index aaa50ab2c5..5997e13107 100644
> --- a/hw/sd/sd.c
> +++ b/hw/sd/sd.c
> @@ -603,6 +603,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;
> @@ -2076,7 +2084,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,
diff mbox series

Patch

diff --git a/hw/sd/sd.c b/hw/sd/sd.c
index aaa50ab2c5..5997e13107 100644
--- a/hw/sd/sd.c
+++ b/hw/sd/sd.c
@@ -603,6 +603,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;
@@ -2076,7 +2084,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,