[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[PATCH 14/23] hw/sd/sdcard: Factor sd_req_get_rca() method out
From: |
Philippe Mathieu-Daudé |
Subject: |
[PATCH 14/23] hw/sd/sdcard: Factor sd_req_get_rca() method out |
Date: |
Fri, 21 Jun 2024 10:05:45 +0200 |
Extract sd_req_get_rca() so we can re-use it in various
SDProto handlers. Return a 16-bit value since RCA is 16-bit.
Signed-off-by: Philippe Mathieu-Daudé <philmd@linaro.org>
---
hw/sd/sd.c | 15 +++++++++------
1 file changed, 9 insertions(+), 6 deletions(-)
diff --git a/hw/sd/sd.c b/hw/sd/sd.c
index 510784fc82..bc47ae36bc 100644
--- a/hw/sd/sd.c
+++ b/hw/sd/sd.c
@@ -471,6 +471,14 @@ static void sd_set_csd(SDState *sd, uint64_t size)
sd->csd[15] = (sd_crc7(sd->csd, 15) << 1) | 1;
}
+static uint16_t sd_req_get_rca(SDState *s, SDRequest req)
+{
+ if (sd_cmd_type[req.cmd] == sd_ac || sd_cmd_type[req.cmd] == sd_adtc) {
+ return req.arg >> 16;
+ }
+ return 0;
+}
+
FIELD(CSR, AKE_SEQ_ERROR, 3, 1)
FIELD(CSR, APP_CMD, 5, 1)
FIELD(CSR, FX_EVENT, 6, 1)
@@ -1094,7 +1102,7 @@ static sd_rsp_type_t sd_cmd_SET_BLOCK_COUNT(SDState *sd,
SDRequest req)
static sd_rsp_type_t sd_normal_command(SDState *sd, SDRequest req)
{
- uint32_t rca = 0x0000;
+ uint16_t rca = sd_req_get_rca(sd, req);
uint64_t addr = (sd->ocr & (1 << 30)) ? (uint64_t) req.arg << 9 : req.arg;
sd->last_cmd_name = sd_cmd_name(req.cmd);
@@ -1110,11 +1118,6 @@ static sd_rsp_type_t sd_normal_command(SDState *sd,
SDRequest req)
/* Not interpreting this as an app command */
sd->card_status &= ~APP_CMD;
- if (sd_cmd_type[req.cmd] == sd_ac
- || sd_cmd_type[req.cmd] == sd_adtc) {
- rca = req.arg >> 16;
- }
-
/* CMD23 (set block count) must be immediately followed by CMD18 or CMD25
* if not, its effects are cancelled */
if (sd->multi_blk_cnt != 0 && !(req.cmd == 18 || req.cmd == 25)) {
--
2.41.0
- Re: [PATCH 08/23] hw/sd/sdcard: Remove explicit entries for illegal commands, (continued)
- [PATCH 09/23] hw/sd/sdcard: Generate random RCA value, Philippe Mathieu-Daudé, 2024/06/21
- [PATCH 10/23] hw/sd/sdcard: Track last command used to help logging, Philippe Mathieu-Daudé, 2024/06/21
- [PATCH 11/23] hw/sd/sdcard: Trace update of block count (CMD23), Philippe Mathieu-Daudé, 2024/06/21
- [PATCH 12/23] hw/sd/sdcard: Trace block offset in READ/WRITE data accesses, Philippe Mathieu-Daudé, 2024/06/21
- [PATCH 13/23] hw/sd/sdcard: Have cmd_valid_while_locked() return a boolean value, Philippe Mathieu-Daudé, 2024/06/21
- [PATCH 14/23] hw/sd/sdcard: Factor sd_req_get_rca() method out,
Philippe Mathieu-Daudé <=
- [PATCH 15/23] hw/sd/sdcard: Only call sd_req_get_rca() where RCA is used, Philippe Mathieu-Daudé, 2024/06/21
- [PATCH 16/23] hw/sd/sdcard: Factor sd_req_get_address() method out, Philippe Mathieu-Daudé, 2024/06/21
- [PATCH 17/23] hw/sd/sdcard: Only call sd_req_get_address() where address is used, Philippe Mathieu-Daudé, 2024/06/21
- [PATCH 18/23] hw/sd/sdcard: Add sd_invalid_mode_for_cmd to report invalid mode switch, Philippe Mathieu-Daudé, 2024/06/21
- [PATCH 19/23] hw/sd/sdcard: Inline BLK_READ_BLOCK / BLK_WRITE_BLOCK macros, Philippe Mathieu-Daudé, 2024/06/21