hw/sd/sdcard: Factor sd_req_get_rca() method out
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>
Reviewed-by: Cédric Le Goater <clg@redhat.com>
Tested-by: Cédric Le Goater <clg@redhat.com>
Message-Id: <20240621080554.18986-15-philmd@linaro.org>
diff --git a/hw/sd/sd.c b/hw/sd/sd.c
index 04b1417..b909a85 100644
--- a/hw/sd/sd.c
+++ b/hw/sd/sd.c
@@ -474,6 +474,14 @@
sd->rca += 0x4567;
}
+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)
@@ -1097,7 +1105,7 @@
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;
/* CMD55 precedes an ACMD, so we are not interested in tracing it.
@@ -1112,11 +1120,6 @@
/* 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)) {