On 6/21/24 10:05 AM, Philippe Mathieu-Daudé wrote:
> 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>
Thanks,
C.
> ---
> 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)) {