hw/sd/sdcard: Convert ACMD to sd_cmd_handler format
cover hw/sd/sdcard: Convert ACMD to sd_cmd_handler format
For each switch case in the big sd_app_command() function, extract the corresponding sd_cmd_handler.
Few housekeeping patches at the end.
Based-on: <[email protected]>
Full series for testing:
https://gitlab.com/philmd/qemu/-/tags/emmc-v4
Philippe Mathieu-Daudé (12):
hw/sd/sdcard: Add sd_acmd_SET_BUS_WIDTH handler (ACMD6) hw/sd/sdcard: Add sd_acmd_SD_STATUS handler (ACMD13) hw/sd/sdcard: Add sd_acmd_SEND_NUM_WR_BLOCKS handler (ACMD22) hw/sd/sdcard: Add sd_acmd_SET_WR_BLK_ERASE_COUNT handler (ACMD23) hw/sd/sdcard: Add sd_acmd_SD_APP_OP_COND handler (ACMD41) hw/sd/sdcard: Add sd_acmd_SET_CLR_CARD_DETECT handler (ACMD42) hw/sd/sdcard: Add sd_acmd_SEND_SCR handler (ACMD51) hw/sd/sdcard: Remove sd_none enum from sd_cmd_type_t hw/sd/sdcard: Remove noise from sd_acmd_name() hw/sd/sdcard: Remove noise from sd_cmd_name() hw/sd/sdcard: Remove default case in read/write on DAT lines hw/sd/sdcard: Trace length of data read on DAT lines
include/hw/sd/sd.h | 1 - hw/sd/sd.c | 256 +++++++++++++++++++++------------------------ hw/sd/trace-events | 2 +- 3 files changed, 119 insertions(+), 140 deletions(-)
Signature · 1 line
2.41.0
PATCH 1/12 hw/sd/sdcard: Add sd_acmd_SET_BUS_WIDTH handler (ACMD6)
--- hw/sd/sd.c | 28 +++++++++++++++------------- 1 file changed, 15 insertions(+), 13 deletions(-)
hw/sd/sd.c +15 -13
@@ -260,7 +260,6 @@ static const char *sd_cmd_name(SDState *sd, uint8_t cmd)static const char *sd_acmd_name (SDState *sd,uint8_t cmd) {static const char *acmd_abbrev[SDMMC_CMD_MAX ] = { - [6 ] ="SET_BUS_WIDTH" , [13 ] ="SD_STATUS" , [14 ] ="DPS_spec" , [15 ] ="DPS_spec" , [16 ] ="DPS_spec" ,
@@ -1672,6 +1671,18 @@ static sd_rsp_type_t spi_cmd_CRC_ON_OFF(SDState *sd, SDRequest req)return sd_r1; } +/* ACMD6 */ +static sd_rsp_type_t sd_acmd_SET_BUS_WIDTH (SDState *sd,SDRequest req) +{ +if (sd->state != sd_transfer_state) { +return sd_invalid_state_for_cmd (sd, req); + } + + sd->sd_status[0 ] &=0x3f ; + sd->sd_status[0 ] |= (req.arg &0x03 ) <<6 ; +return sd_r1; +} +static sd_rsp_type_t sd_normal_command (SDState *sd,SDRequest req) {uint64_t addr;
@@ -1780,18 +1791,6 @@ static sd_rsp_type_t sd_app_command(SDState *sd, }switch (req.cmd) { -case 6 :/* ACMD6: SET_BUS_WIDTH */ -switch (sd->state) { -case sd_transfer_state: - sd->sd_status[0 ] &=0x3f ; - sd->sd_status[0 ] |= (req.arg &0x03 ) <<6 ; -return sd_r1; - -default : -break ; - } -break ; -case 13 :/* ACMD13: SD_STATUS */ switch (sd->state) {case sd_transfer_state:
@@ -2385,6 +2384,9 @@ static const SDProto sd_proto_sd = { [58] = {11, sd_adtc, "READ_EXTR_MULTI", sd_cmd_optional}, [59 ] = {11 , sd_adtc,"WRITE_EXTR_MULTI" , sd_cmd_optional}, }, + .acmd = { + [6 ] = {8 , sd_ac,"SET_BUS_WIDTH" , sd_acmd_SET_BUS_WIDTH}, + }, };static void sd_instance_init (Object *obj)
Signature · 1 line
2.41.0
PATCH 2/12 hw/sd/sdcard: Add sd_acmd_SD_STATUS handler (ACMD13)
In reply to Philippe Mathieu-Daudé--- hw/sd/sd.c | 22 +++++++++------------- 1 file changed, 9 insertions(+), 13 deletions(-)
hw/sd/sd.c +9 -13
@@ -260,7 +260,6 @@ static const char *sd_cmd_name(SDState *sd, uint8_t cmd)static const char *sd_acmd_name (SDState *sd,uint8_t cmd) {static const char *acmd_abbrev[SDMMC_CMD_MAX ] = { - [13 ] ="SD_STATUS" , [14 ] ="DPS_spec" , [15 ] ="DPS_spec" , [16 ] ="DPS_spec" , [18 ] ="SECU_spec" ,
@@ -1683,6 +1682,13 @@ static sd_rsp_type_t sd_acmd_SET_BUS_WIDTH(SDState *sd, SDRequest req)return sd_r1; } +/* ACMD13 */ +static sd_rsp_type_t sd_acmd_SD_STATUS (SDState *sd,SDRequest req) +{ +return sd_cmd_to_sendingdata (sd, req,0 , + sd->sd_status,sizeof (sd->sd_status)); +} +static sd_rsp_type_t sd_normal_command (SDState *sd,SDRequest req) {uint64_t addr;
@@ -1791,18 +1797,6 @@ static sd_rsp_type_t sd_app_command(SDState *sd, }switch (req.cmd) { -case 13 :/* ACMD13: SD_STATUS */ -switch (sd->state) { -case sd_transfer_state: -return sd_cmd_to_sendingdata (sd, req,0 , - sd->sd_status, -sizeof (sd->sd_status)); - -default : -break ; - } -break ; -case 22 :/* ACMD22: SEND_NUM_WR_BLOCKS */ switch (sd->state) {case sd_transfer_state:
@@ -2329,6 +2323,7 @@ static const SDProto sd_proto_spi = { [59 ] = {0 , sd_spi,"CRC_ON_OFF" , spi_cmd_CRC_ON_OFF}, }, .acmd = { + [13 ] = {8 , sd_spi,"SD_STATUS" , sd_acmd_SD_STATUS}, [41 ] = {8 , sd_spi,"SEND_OP_COND" , spi_cmd_SEND_OP_COND}, }, };
@@ -2386,6 +2381,7 @@ static const SDProto sd_proto_sd = { }, .acmd = { [6] = {8, sd_ac, "SET_BUS_WIDTH", sd_acmd_SET_BUS_WIDTH}, + [13] = {8, sd_adtc, "SD_STATUS", sd_acmd_SD_STATUS}, }, };
Signature · 1 line
2.41.0
PATCH 3/12 hw/sd/sdcard: Add sd_acmd_SEND_NUM_WR_BLOCKS handler (ACMD22)
In reply to Philippe Mathieu-Daudé--- hw/sd/sd.c | 23 ++++++++++------------- 1 file changed, 10 insertions(+), 13 deletions(-)
hw/sd/sd.c +10 -13
@@ -263,7 +263,7 @@ static const char *sd_acmd_name(SDState *sd, uint8_t cmd) [14] = "DPS_spec", [15] = "DPS_spec", [16] = "DPS_spec", [18] = "SECU_spec", - [22] = "SEND_NUM_WR_BLOCKS", [23] = "SET_WR_BLK_ERASE_COUNT", + [23] = "SET_WR_BLK_ERASE_COUNT", [42] = "SET_CLR_CARD_DETECT", [51] = "SEND_SCR", [52] = "SECU_spec", [53] = "SECU_spec",
@@ -1689,6 +1689,13 @@ static sd_rsp_type_t sd_acmd_SD_STATUS(SDState *sd, SDRequest req) sd->sd_status, sizeof(sd->sd_status)); } +/* ACMD22 */ +static sd_rsp_type_t sd_acmd_SEND_NUM_WR_BLOCKS (SDState *sd,SDRequest req) +{ +return sd_cmd_to_sendingdata (sd, req,0 , + &sd->blk_written,sizeof (sd->blk_written)); +} +static sd_rsp_type_t sd_normal_command (SDState *sd,SDRequest req) {uint64_t addr;
@@ -1797,18 +1804,6 @@ static sd_rsp_type_t sd_app_command(SDState *sd, }switch (req.cmd) { -case 22 :/* ACMD22: SEND_NUM_WR_BLOCKS */ -switch (sd->state) { -case sd_transfer_state: -return sd_cmd_to_sendingdata (sd, req,0 , - &sd->blk_written, -sizeof (sd->blk_written)); - -default : -break ; - } -break ; -case 23 :/* ACMD23: SET_WR_BLK_ERASE_COUNT */ switch (sd->state) {case sd_transfer_state:
@@ -2324,6 +2319,7 @@ static const SDProto sd_proto_spi = { }, .acmd = { [13] = {8, sd_spi, "SD_STATUS", sd_acmd_SD_STATUS}, + [22] = {8, sd_spi, "SEND_NUM_WR_BLOCKS", sd_acmd_SEND_NUM_WR_BLOCKS}, [41] = {8, sd_spi, "SEND_OP_COND", spi_cmd_SEND_OP_COND}, }, };
@@ -2382,6 +2378,7 @@ static const SDProto sd_proto_sd = { .acmd = { [6] = {8, sd_ac, "SET_BUS_WIDTH", sd_acmd_SET_BUS_WIDTH}, [13] = {8, sd_adtc, "SD_STATUS", sd_acmd_SD_STATUS}, + [22] = {8, sd_adtc, "SEND_NUM_WR_BLOCKS", sd_acmd_SEND_NUM_WR_BLOCKS}, }, };
Signature · 1 line
2.41.0
PATCH 4/12 hw/sd/sdcard: Add sd_acmd_SET_WR_BLK_ERASE_COUNT handler (ACMD23)
In reply to Philippe Mathieu-Daudé--- hw/sd/sd.c | 22 +++++++++++----------- 1 file changed, 11 insertions(+), 11 deletions(-)
hw/sd/sd.c +11 -11
@@ -263,7 +263,6 @@ static const char *sd_acmd_name(SDState *sd, uint8_t cmd) [14] = "DPS_spec", [15] = "DPS_spec", [16] = "DPS_spec", [18] = "SECU_spec", - [23] = "SET_WR_BLK_ERASE_COUNT", [42] = "SET_CLR_CARD_DETECT", [51] = "SEND_SCR", [52] = "SECU_spec", [53] = "SECU_spec",
@@ -1696,6 +1695,15 @@ static sd_rsp_type_t sd_acmd_SEND_NUM_WR_BLOCKS(SDState *sd, SDRequest req) &sd->blk_written, sizeof(sd->blk_written)); } +/* ACMD23 */ +static sd_rsp_type_t sd_acmd_SET_WR_BLK_ERASE_COUNT (SDState *sd,SDRequest req) +{ +if (sd->state != sd_transfer_state) { +return sd_invalid_state_for_cmd (sd, req); + } +return sd_r1; +} +static sd_rsp_type_t sd_normal_command (SDState *sd,SDRequest req) {uint64_t addr;
@@ -1804,16 +1812,6 @@ static sd_rsp_type_t sd_app_command(SDState *sd, }switch (req.cmd) { -case 23 :/* ACMD23: SET_WR_BLK_ERASE_COUNT */ -switch (sd->state) { -case sd_transfer_state: -return sd_r1; - -default : -break ; - } -break ; -case 41 :/* ACMD41: SD_APP_OP_COND */ if (sd->state != sd_idle_state) {break ;
@@ -2320,6 +2318,7 @@ static const SDProto sd_proto_spi = { .acmd = { [13] = {8, sd_spi, "SD_STATUS", sd_acmd_SD_STATUS}, [22] = {8, sd_spi, "SEND_NUM_WR_BLOCKS", sd_acmd_SEND_NUM_WR_BLOCKS}, + [23] = {8, sd_spi, "SET_WR_BLK_ERASE_COUNT", sd_acmd_SET_WR_BLK_ERASE_COUNT}, [41] = {8, sd_spi, "SEND_OP_COND", spi_cmd_SEND_OP_COND}, }, };
@@ -2379,6 +2378,7 @@ static const SDProto sd_proto_sd = { [6] = {8, sd_ac, "SET_BUS_WIDTH", sd_acmd_SET_BUS_WIDTH}, [13] = {8, sd_adtc, "SD_STATUS", sd_acmd_SD_STATUS}, [22] = {8, sd_adtc, "SEND_NUM_WR_BLOCKS", sd_acmd_SEND_NUM_WR_BLOCKS}, + [23] = {8, sd_ac, "SET_WR_BLK_ERASE_COUNT", sd_acmd_SET_WR_BLK_ERASE_COUNT}, }, };
Signature · 1 line
2.41.0
PATCH 5/12 hw/sd/sdcard: Add sd_acmd_SD_APP_OP_COND handler (ACMD41)
In reply to Philippe Mathieu-Daudé--- hw/sd/sd.c | 82 ++++++++++++++++++++++++++++++------------------------ 1 file changed, 45 insertions(+), 37 deletions(-)
hw/sd/sd.c +45 -37
@@ -1704,6 +1704,50 @@ static sd_rsp_type_t sd_acmd_SET_WR_BLK_ERASE_COUNT(SDState *sd, SDRequest req)return sd_r1; } +/* ACMD41 */ +static sd_rsp_type_t sd_acmd_SD_APP_OP_COND (SDState *sd,SDRequest req) +{ +if (sd->state != sd_idle_state) { +return sd_invalid_state_for_cmd (sd, req); + } + +/* +* If it's the first ACMD41 since reset, we need to decide +* whether to power up. If this is not an enquiry ACMD41, +* we immediately report power on and proceed below to the +* ready state, but if it is, we set a timer to model a +* delay for power up. This works around a bug in EDK2 +* UEFI, which sends an initial enquiry ACMD41, but +* assumes that the card is in ready state as soon as it +* sees the power up bit set. +*/ +if (!FIELD_EX32 (sd->ocr,OCR ,CARD_POWER_UP )) { +if ((req.arg &ACMD41_ENQUIRY_MASK ) !=0 ) { +timer_del (sd->ocr_power_timer); +sd_ocr_powerup (sd); + }else { +trace_sdcard_inquiry_cmd41 (); +if (!timer_pending (sd->ocr_power_timer)) { +timer_mod_ns (sd->ocr_power_timer, + (qemu_clock_get_ns (QEMU_CLOCK_VIRTUAL ) + +OCR_POWER_DELAY_NS )); + } + } + } + +if (FIELD_EX32 (sd->ocr & req.arg,OCR ,VDD_VOLTAGE_WINDOW )) { +/* +* We accept any voltage. 10000 V is nothing. +* +* Once we're powered up, we advance straight to ready state +* unless it's an enquiry ACMD41 (bits 23:0 == 0). +*/ + sd->state = sd_ready_state; + } + +return sd_r3; +} +static sd_rsp_type_t sd_normal_command (SDState *sd,SDRequest req) {uint64_t addr;
@@ -1812,43 +1856,6 @@ static sd_rsp_type_t sd_app_command(SDState *sd, }switch (req.cmd) { -case 41 :/* ACMD41: SD_APP_OP_COND */ -if (sd->state != sd_idle_state) { -break ; - } -/* If it's the first ACMD41 since reset, we need to decide -* whether to power up. If this is not an enquiry ACMD41, -* we immediately report power on and proceed below to the -* ready state, but if it is, we set a timer to model a -* delay for power up. This works around a bug in EDK2 -* UEFI, which sends an initial enquiry ACMD41, but -* assumes that the card is in ready state as soon as it -* sees the power up bit set. */ -if (!FIELD_EX32 (sd->ocr,OCR ,CARD_POWER_UP )) { -if ((req.arg &ACMD41_ENQUIRY_MASK ) !=0 ) { -timer_del (sd->ocr_power_timer); -sd_ocr_powerup (sd); - }else { -trace_sdcard_inquiry_cmd41 (); -if (!timer_pending (sd->ocr_power_timer)) { -timer_mod_ns (sd->ocr_power_timer, - (qemu_clock_get_ns (QEMU_CLOCK_VIRTUAL ) - +OCR_POWER_DELAY_NS )); - } - } - } - -if (FIELD_EX32 (sd->ocr & req.arg,OCR ,VDD_VOLTAGE_WINDOW )) { -/* We accept any voltage. 10000 V is nothing. -* -* Once we're powered up, we advance straight to ready state -* unless it's an enquiry ACMD41 (bits 23:0 == 0). -*/ - sd->state = sd_ready_state; - } - -return sd_r3; -case 42 :/* ACMD42: SET_CLR_CARD_DETECT */ switch (sd->state) {case sd_transfer_state:
@@ -2379,6 +2386,7 @@ static const SDProto sd_proto_sd = { [13] = {8, sd_adtc, "SD_STATUS", sd_acmd_SD_STATUS}, [22] = {8, sd_adtc, "SEND_NUM_WR_BLOCKS", sd_acmd_SEND_NUM_WR_BLOCKS}, [23] = {8, sd_ac, "SET_WR_BLK_ERASE_COUNT", sd_acmd_SET_WR_BLK_ERASE_COUNT}, + [41] = {8, sd_bcr, "SD_APP_OP_COND", sd_acmd_SD_APP_OP_COND}, }, };
Signature · 1 line
2.41.0
PATCH 6/12 hw/sd/sdcard: Add sd_acmd_SET_CLR_CARD_DETECT handler (ACMD42)
In reply to Philippe Mathieu-Daudé--- hw/sd/sd.c | 25 +++++++++++++------------ 1 file changed, 13 insertions(+), 12 deletions(-)
hw/sd/sd.c +13 -12
@@ -263,7 +263,6 @@ static const char *sd_acmd_name(SDState *sd, uint8_t cmd) [14] = "DPS_spec", [15] = "DPS_spec", [16] = "DPS_spec", [18] = "SECU_spec", - [42] = "SET_CLR_CARD_DETECT", [51] = "SEND_SCR", [52] = "SECU_spec", [53] = "SECU_spec", [54] = "SECU_spec",
@@ -1748,6 +1747,17 @@ static sd_rsp_type_t sd_acmd_SD_APP_OP_COND(SDState *sd, SDRequest req)return sd_r3; } +/* ACMD42 */ +static sd_rsp_type_t sd_acmd_SET_CLR_CARD_DETECT (SDState *sd,SDRequest req) +{ +if (sd->state != sd_transfer_state) { +return sd_invalid_state_for_cmd (sd, req); + } + +/* Bringing in the 50KOhm pull-up resistor... Done. */ +return sd_r1; +} +static sd_rsp_type_t sd_normal_command (SDState *sd,SDRequest req) {uint64_t addr;
@@ -1856,17 +1866,6 @@ static sd_rsp_type_t sd_app_command(SDState *sd, }switch (req.cmd) { -case 42 :/* ACMD42: SET_CLR_CARD_DETECT */ -switch (sd->state) { -case sd_transfer_state: -/* Bringing in the 50KOhm pull-up resistor... Done. */ -return sd_r1; - -default : -break ; - } -break ; -case 51 :/* ACMD51: SEND_SCR */ switch (sd->state) {case sd_transfer_state:
@@ -2327,6 +2326,7 @@ static const SDProto sd_proto_spi = { [22] = {8, sd_spi, "SEND_NUM_WR_BLOCKS", sd_acmd_SEND_NUM_WR_BLOCKS}, [23] = {8, sd_spi, "SET_WR_BLK_ERASE_COUNT", sd_acmd_SET_WR_BLK_ERASE_COUNT}, [41] = {8, sd_spi, "SEND_OP_COND", spi_cmd_SEND_OP_COND}, + [42] = {8, sd_spi, "SET_CLR_CARD_DETECT", sd_acmd_SET_CLR_CARD_DETECT}, }, };
@@ -2387,6 +2387,7 @@ static const SDProto sd_proto_sd = { [22] = {8, sd_adtc, "SEND_NUM_WR_BLOCKS", sd_acmd_SEND_NUM_WR_BLOCKS}, [23] = {8, sd_ac, "SET_WR_BLK_ERASE_COUNT", sd_acmd_SET_WR_BLK_ERASE_COUNT}, [41] = {8, sd_bcr, "SD_APP_OP_COND", sd_acmd_SD_APP_OP_COND}, + [42] = {8, sd_ac, "SET_CLR_CARD_DETECT", sd_acmd_SET_CLR_CARD_DETECT}, }, };
Signature · 1 line
2.41.0
PATCH 7/12 hw/sd/sdcard: Add sd_acmd_SEND_SCR handler (ACMD51)
In reply to Philippe Mathieu-Daudé--- hw/sd/sd.c | 19 ++++++++----------- 1 file changed, 8 insertions(+), 11 deletions(-)
hw/sd/sd.c +8 -11
@@ -263,7 +263,6 @@ static const char *sd_acmd_name(SDState *sd, uint8_t cmd) [14] = "DPS_spec", [15] = "DPS_spec", [16] = "DPS_spec", [18] = "SECU_spec", - [51] = "SEND_SCR", [52] = "SECU_spec", [53] = "SECU_spec", [54] = "SECU_spec", [56] = "SECU_spec", [57] = "SECU_spec",
@@ -1758,6 +1757,12 @@ static sd_rsp_type_t sd_acmd_SET_CLR_CARD_DETECT(SDState *sd, SDRequest req)return sd_r1; } +/* ACMD51 */ +static sd_rsp_type_t sd_acmd_SEND_SCR (SDState *sd,SDRequest req) +{ +return sd_cmd_to_sendingdata (sd, req,0 , sd->scr,sizeof (sd->scr)); +} +static sd_rsp_type_t sd_normal_command (SDState *sd,SDRequest req) {uint64_t addr;
@@ -1866,16 +1871,6 @@ static sd_rsp_type_t sd_app_command(SDState *sd, }switch (req.cmd) { -case 51 :/* ACMD51: SEND_SCR */ -switch (sd->state) { -case sd_transfer_state: -return sd_cmd_to_sendingdata (sd, req,0 , sd->scr,sizeof (sd->scr)); - -default : -break ; - } -break ; -case 18 :/* Reserved for SD security applications */ case 25 :case 26 :
@@ -2327,6 +2322,7 @@ static const SDProto sd_proto_spi = { [23] = {8, sd_spi, "SET_WR_BLK_ERASE_COUNT", sd_acmd_SET_WR_BLK_ERASE_COUNT}, [41] = {8, sd_spi, "SEND_OP_COND", spi_cmd_SEND_OP_COND}, [42] = {8, sd_spi, "SET_CLR_CARD_DETECT", sd_acmd_SET_CLR_CARD_DETECT}, + [51] = {8, sd_spi, "SEND_SCR", sd_acmd_SEND_SCR}, }, };
@@ -2388,6 +2384,7 @@ static const SDProto sd_proto_sd = { [23] = {8, sd_ac, "SET_WR_BLK_ERASE_COUNT", sd_acmd_SET_WR_BLK_ERASE_COUNT}, [41] = {8, sd_bcr, "SD_APP_OP_COND", sd_acmd_SD_APP_OP_COND}, [42] = {8, sd_ac, "SET_CLR_CARD_DETECT", sd_acmd_SET_CLR_CARD_DETECT}, + [51] = {8, sd_adtc, "SEND_SCR", sd_acmd_SEND_SCR}, }, };
Signature · 1 line
2.41.0
PATCH 8/12 hw/sd/sdcard: Remove sd_none enum from sd_cmd_type_t
In reply to Philippe Mathieu-DaudéAll handlers using the 'sd_none' enum got converted, remove it.
--- include/hw/sd/sd.h | 1 - hw/sd/sd.c | 7 +------ 2 files changed, 1 insertion(+), 7 deletions(-)
include/hw/sd/sd.h +0 -1
@@ -76,7 +76,6 @@ typedef enum { } sd_uhs_mode_t; typedef enum { - sd_none = 0, sd_spi, sd_bc, /* broadcast -- no response */ sd_bcr, /* broadcast with response */
hw/sd/sd.c +1 -6
@@ -526,17 +526,12 @@ static void sd_set_rca(SDState *sd, uint16_t value)static uint16_t sd_req_get_rca (SDState *s,SDRequest req) {switch (s->proto->cmd[req.cmd].type) { -case sd_none: -/* Called from legacy code not ported to SDProto array */ -assert (!s->proto->cmd[req.cmd].handler); -/* fall-through */ case sd_ac:case sd_adtc:return req.arg >>16 ;case sd_spi: -g_assert_not_reached ();default : -return 0 ; +g_assert_not_reached (); } }
Signature · 1 line
2.41.0
PATCH 9/12 hw/sd/sdcard: Remove noise from sd_acmd_name()
In reply to Philippe Mathieu-DaudéThese ACMD names weren't really useful, "UNKNOWN_ACMD" is simpler.
--- hw/sd/sd.c | 12 +----------- 1 file changed, 1 insertion(+), 11 deletions(-)
hw/sd/sd.c +1 -11
@@ -259,23 +259,13 @@ static const char *sd_cmd_name(SDState *sd, uint8_t cmd)static const char *sd_acmd_name (SDState *sd,uint8_t cmd) { -static const char *acmd_abbrev[SDMMC_CMD_MAX ] = { - [14 ] ="DPS_spec" , [15 ] ="DPS_spec" , - [16 ] ="DPS_spec" , - [18 ] ="SECU_spec" , - [52 ] ="SECU_spec" , [53 ] ="SECU_spec" , - [54 ] ="SECU_spec" , - [56 ] ="SECU_spec" , [57 ] ="SECU_spec" , - [58 ] ="SECU_spec" , [59 ] ="SECU_spec" , - };const SDProto *sdp = sd->proto;if (sdp->acmd[cmd].handler) { -assert (!acmd_abbrev[cmd]);return sdp->acmd[cmd].name; } -return acmd_abbrev[cmd] ? acmd_abbrev[cmd] :"UNKNOWN_ACMD" ; +return "UNKNOWN_ACMD" ; }static uint8_t sd_get_dat_lines (SDState *sd)
Signature · 1 line
2.41.0
PATCH 10/12 hw/sd/sdcard: Remove noise from sd_cmd_name()
In reply to Philippe Mathieu-DaudéThese CMD names weren't really useful, "UNKNOWN_CMD" is simpler.
--- hw/sd/sd.c | 5 ----- 1 file changed, 5 deletions(-)
hw/sd/sd.c +0 -5
@@ -241,12 +241,7 @@ static const char *sd_cmd_name(SDState *sd, uint8_t cmd) {static const char *cmd_abbrev[SDMMC_CMD_MAX ] = { [18 ] ="READ_MULTIPLE_BLOCK" , - [21 ] ="DPS_spec" , [25 ] ="WRITE_MULTIPLE_BLOCK" , - [26 ] ="MANUF_RSVD" , - [40 ] ="DPS_spec" , - [60 ] ="MANUF_RSVD" , [61 ] ="MANUF_RSVD" , - [62 ] ="MANUF_RSVD" , [63 ] ="MANUF_RSVD" , };const SDProto *sdp = sd->proto;
Signature · 1 line
2.41.0
PATCH 11/12 hw/sd/sdcard: Remove default case in read/write on DAT lines
In reply to Philippe Mathieu-DaudéAll read/write on DAT lines are explicitly handled. Reaching this point would be a programming error:
replace by an assertion.
--- hw/sd/sd.c | 9 ++++----- 1 file changed, 4 insertions(+), 5 deletions(-)
hw/sd/sd.c +4 -5
@@ -1951,7 +1951,6 @@ int sd_do_command(SDState *sd, SDRequest *req,/* Valid command, we can update the 'state before command' bits. * (Do this now so they appear in r1 responses.) */ - sd->current_cmd = req->cmd; sd->card_status =FIELD_DP32 (sd->card_status,CSR ,CURRENT_STATE , last_state); }
@@ -2016,6 +2015,8 @@ send_response:qemu_hexdump (stderr,"Response" , response, rsplen);#endif + sd->current_cmd = rtype == sd_illegal ?0 : req->cmd; +return rsplen; }
@@ -2171,8 +2172,7 @@ void sd_write_byte(SDState *sd, uint8_t value)break ;default : -qemu_log_mask (LOG_GUEST_ERROR ,"%s: unknown command\n" , __func__); -break ; +g_assert_not_reached (); } }
@@ -2238,8 +2238,7 @@ uint8_t sd_read_byte(SDState *sd)break ;default : -qemu_log_mask (LOG_GUEST_ERROR ,"%s: unknown command\n" , __func__); -return 0x00 ; +g_assert_not_reached (); }return ret;
Signature · 1 line
2.41.0
PATCH 12/12 hw/sd/sdcard: Trace length of data read on DAT lines
In reply to Philippe Mathieu-DaudéSome commands expect less than BLOCK_LENGTH.
--- hw/sd/sd.c | 4 ++-- hw/sd/trace-events | 2 +- 2 files changed, 3 insertions(+), 3 deletions(-)
hw/sd/sd.c +2 -2
@@ -2197,8 +2197,8 @@ uint8_t sd_read_byte(SDState *sd) io_len =sd_blk_len (sd);trace_sdcard_read_data (sd->proto->name, - sd->last_cmd_name, - sd->current_cmd, sd->data_offset, io_len); + sd->last_cmd_name, sd->current_cmd, + sd->data_offset, sd->data_size, io_len);switch (sd->current_cmd) {case 6 :/* CMD6: SWITCH_FUNCTION */ case 9 :/* CMD9: SEND_CSD */
hw/sd/trace-events +1 -1
@@ -55,7 +55,7 @@ sdcard_req_addr(uint32_t req_arg, uint64_t addr) "req 0x%" PRIx32 " addr 0x%" PR sdcard_read_block(uint64_t addr, uint32_t len) "addr 0x%" PRIx64 " size 0x%x" sdcard_write_block(uint64_t addr, uint32_t len) "addr 0x%" PRIx64 " size 0x%x" sdcard_write_data(const char *proto, const char *cmd_desc, uint8_t cmd, uint32_t offset, uint8_t value) "%s %20s/ CMD%02d ofs %"PRIu32" value 0x%02x" -sdcard_read_data(const char *proto, const char *cmd_desc, uint8_t cmd, uint32_t offset, uint32_t length) "%s %20s/ CMD%02d ofs %"PRIu32" len %" PRIu32 +sdcard_read_data(const char *proto, const char *cmd_desc, uint8_t cmd, uint32_t offset, uint64_t size, uint32_t blklen) "%s %20s/ CMD%02d ofs %"PRIu32" size %"PRIu64" blklen %" PRIu32 sdcard_set_voltage(uint16_t millivolts) "%u mV" # pxa2xx_mmci.c
Signature · 1 line
2.41.0