* [PATCH 01/12] hw/sd/sdcard: Add sd_acmd_SET_BUS_WIDTH handler (ACMD6)
2024-06-27 16:48 [PATCH 00/12] hw/sd/sdcard: Convert ACMD to sd_cmd_handler format Philippe Mathieu-Daudé
@ 2024-06-27 16:48 ` Philippe Mathieu-Daudé
2024-06-28 4:53 ` [PATCH 02/12] hw/sd/sdcard: Add sd_acmd_SD_STATUS handler (ACMD13) Philippe Mathieu-Daudé
` (10 subsequent siblings)
11 siblings, 0 replies; 13+ messages in thread
From: Philippe Mathieu-Daudé @ 2024-06-27 16:48 UTC (permalink / raw)
To: qemu-devel
Cc: Luc Michel, Bin Meng, Philippe Mathieu-Daudé, qemu-block,
Francisco Iglesias, Cédric Le Goater, Sai Pavan Boddu,
Joel Stanley
Signed-off-by: Philippe Mathieu-Daudé <philmd@linaro.org>
---
hw/sd/sd.c | 28 +++++++++++++++-------------
1 file changed, 15 insertions(+), 13 deletions(-)
diff --git a/hw/sd/sd.c b/hw/sd/sd.c
index 2f853a89d1..0310a5a3a1 100644
--- a/hw/sd/sd.c
+++ b/hw/sd/sd.c
@@ -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)
--
2.41.0
^ permalink raw reply related [flat|nested] 13+ messages in thread
* [PATCH 02/12] hw/sd/sdcard: Add sd_acmd_SD_STATUS handler (ACMD13)
2024-06-27 16:48 [PATCH 00/12] hw/sd/sdcard: Convert ACMD to sd_cmd_handler format Philippe Mathieu-Daudé
2024-06-27 16:48 ` [PATCH 01/12] hw/sd/sdcard: Add sd_acmd_SET_BUS_WIDTH handler (ACMD6) Philippe Mathieu-Daudé
@ 2024-06-28 4:53 ` Philippe Mathieu-Daudé
2024-06-28 4:53 ` [PATCH 03/12] hw/sd/sdcard: Add sd_acmd_SEND_NUM_WR_BLOCKS handler (ACMD22) Philippe Mathieu-Daudé
` (9 subsequent siblings)
11 siblings, 0 replies; 13+ messages in thread
From: Philippe Mathieu-Daudé @ 2024-06-28 4:53 UTC (permalink / raw)
To: qemu-devel
Cc: Luc Michel, Francisco Iglesias, Cédric Le Goater,
Sai Pavan Boddu, Joel Stanley, Bin Meng, qemu-block,
Philippe Mathieu-Daudé
Signed-off-by: Philippe Mathieu-Daudé <philmd@linaro.org>
---
hw/sd/sd.c | 22 +++++++++-------------
1 file changed, 9 insertions(+), 13 deletions(-)
diff --git a/hw/sd/sd.c b/hw/sd/sd.c
index 0310a5a3a1..5323a42df2 100644
--- a/hw/sd/sd.c
+++ b/hw/sd/sd.c
@@ -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},
},
};
--
2.41.0
^ permalink raw reply related [flat|nested] 13+ messages in thread
* [PATCH 03/12] hw/sd/sdcard: Add sd_acmd_SEND_NUM_WR_BLOCKS handler (ACMD22)
2024-06-27 16:48 [PATCH 00/12] hw/sd/sdcard: Convert ACMD to sd_cmd_handler format Philippe Mathieu-Daudé
2024-06-27 16:48 ` [PATCH 01/12] hw/sd/sdcard: Add sd_acmd_SET_BUS_WIDTH handler (ACMD6) Philippe Mathieu-Daudé
2024-06-28 4:53 ` [PATCH 02/12] hw/sd/sdcard: Add sd_acmd_SD_STATUS handler (ACMD13) Philippe Mathieu-Daudé
@ 2024-06-28 4:53 ` Philippe Mathieu-Daudé
2024-06-28 4:53 ` [PATCH 04/12] hw/sd/sdcard: Add sd_acmd_SET_WR_BLK_ERASE_COUNT handler (ACMD23) Philippe Mathieu-Daudé
` (8 subsequent siblings)
11 siblings, 0 replies; 13+ messages in thread
From: Philippe Mathieu-Daudé @ 2024-06-28 4:53 UTC (permalink / raw)
To: qemu-devel
Cc: Luc Michel, Francisco Iglesias, Cédric Le Goater,
Sai Pavan Boddu, Joel Stanley, Bin Meng, qemu-block,
Philippe Mathieu-Daudé
Signed-off-by: Philippe Mathieu-Daudé <philmd@linaro.org>
---
hw/sd/sd.c | 23 ++++++++++-------------
1 file changed, 10 insertions(+), 13 deletions(-)
diff --git a/hw/sd/sd.c b/hw/sd/sd.c
index 5323a42df2..9d66c3715a 100644
--- a/hw/sd/sd.c
+++ b/hw/sd/sd.c
@@ -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},
},
};
--
2.41.0
^ permalink raw reply related [flat|nested] 13+ messages in thread
* [PATCH 04/12] hw/sd/sdcard: Add sd_acmd_SET_WR_BLK_ERASE_COUNT handler (ACMD23)
2024-06-27 16:48 [PATCH 00/12] hw/sd/sdcard: Convert ACMD to sd_cmd_handler format Philippe Mathieu-Daudé
` (2 preceding siblings ...)
2024-06-28 4:53 ` [PATCH 03/12] hw/sd/sdcard: Add sd_acmd_SEND_NUM_WR_BLOCKS handler (ACMD22) Philippe Mathieu-Daudé
@ 2024-06-28 4:53 ` Philippe Mathieu-Daudé
2024-06-28 4:53 ` [PATCH 05/12] hw/sd/sdcard: Add sd_acmd_SD_APP_OP_COND handler (ACMD41) Philippe Mathieu-Daudé
` (7 subsequent siblings)
11 siblings, 0 replies; 13+ messages in thread
From: Philippe Mathieu-Daudé @ 2024-06-28 4:53 UTC (permalink / raw)
To: qemu-devel
Cc: Luc Michel, Francisco Iglesias, Cédric Le Goater,
Sai Pavan Boddu, Joel Stanley, Bin Meng, qemu-block,
Philippe Mathieu-Daudé
Signed-off-by: Philippe Mathieu-Daudé <philmd@linaro.org>
---
hw/sd/sd.c | 22 +++++++++++-----------
1 file changed, 11 insertions(+), 11 deletions(-)
diff --git a/hw/sd/sd.c b/hw/sd/sd.c
index 9d66c3715a..cd207a3090 100644
--- a/hw/sd/sd.c
+++ b/hw/sd/sd.c
@@ -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},
},
};
--
2.41.0
^ permalink raw reply related [flat|nested] 13+ messages in thread
* [PATCH 05/12] hw/sd/sdcard: Add sd_acmd_SD_APP_OP_COND handler (ACMD41)
2024-06-27 16:48 [PATCH 00/12] hw/sd/sdcard: Convert ACMD to sd_cmd_handler format Philippe Mathieu-Daudé
` (3 preceding siblings ...)
2024-06-28 4:53 ` [PATCH 04/12] hw/sd/sdcard: Add sd_acmd_SET_WR_BLK_ERASE_COUNT handler (ACMD23) Philippe Mathieu-Daudé
@ 2024-06-28 4:53 ` Philippe Mathieu-Daudé
2024-06-28 4:53 ` [PATCH 06/12] hw/sd/sdcard: Add sd_acmd_SET_CLR_CARD_DETECT handler (ACMD42) Philippe Mathieu-Daudé
` (6 subsequent siblings)
11 siblings, 0 replies; 13+ messages in thread
From: Philippe Mathieu-Daudé @ 2024-06-28 4:53 UTC (permalink / raw)
To: qemu-devel
Cc: Luc Michel, Francisco Iglesias, Cédric Le Goater,
Sai Pavan Boddu, Joel Stanley, Bin Meng, qemu-block,
Philippe Mathieu-Daudé
Signed-off-by: Philippe Mathieu-Daudé <philmd@linaro.org>
---
hw/sd/sd.c | 82 ++++++++++++++++++++++++++++++------------------------
1 file changed, 45 insertions(+), 37 deletions(-)
diff --git a/hw/sd/sd.c b/hw/sd/sd.c
index cd207a3090..167e1c517a 100644
--- a/hw/sd/sd.c
+++ b/hw/sd/sd.c
@@ -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},
},
};
--
2.41.0
^ permalink raw reply related [flat|nested] 13+ messages in thread
* [PATCH 06/12] hw/sd/sdcard: Add sd_acmd_SET_CLR_CARD_DETECT handler (ACMD42)
2024-06-27 16:48 [PATCH 00/12] hw/sd/sdcard: Convert ACMD to sd_cmd_handler format Philippe Mathieu-Daudé
` (4 preceding siblings ...)
2024-06-28 4:53 ` [PATCH 05/12] hw/sd/sdcard: Add sd_acmd_SD_APP_OP_COND handler (ACMD41) Philippe Mathieu-Daudé
@ 2024-06-28 4:53 ` Philippe Mathieu-Daudé
2024-06-28 4:53 ` [PATCH 07/12] hw/sd/sdcard: Add sd_acmd_SEND_SCR handler (ACMD51) Philippe Mathieu-Daudé
` (5 subsequent siblings)
11 siblings, 0 replies; 13+ messages in thread
From: Philippe Mathieu-Daudé @ 2024-06-28 4:53 UTC (permalink / raw)
To: qemu-devel
Cc: Luc Michel, Francisco Iglesias, Cédric Le Goater,
Sai Pavan Boddu, Joel Stanley, Bin Meng, qemu-block,
Philippe Mathieu-Daudé
Signed-off-by: Philippe Mathieu-Daudé <philmd@linaro.org>
---
hw/sd/sd.c | 25 +++++++++++++------------
1 file changed, 13 insertions(+), 12 deletions(-)
diff --git a/hw/sd/sd.c b/hw/sd/sd.c
index 167e1c517a..a27a7e0f24 100644
--- a/hw/sd/sd.c
+++ b/hw/sd/sd.c
@@ -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},
},
};
--
2.41.0
^ permalink raw reply related [flat|nested] 13+ messages in thread
* [PATCH 07/12] hw/sd/sdcard: Add sd_acmd_SEND_SCR handler (ACMD51)
2024-06-27 16:48 [PATCH 00/12] hw/sd/sdcard: Convert ACMD to sd_cmd_handler format Philippe Mathieu-Daudé
` (5 preceding siblings ...)
2024-06-28 4:53 ` [PATCH 06/12] hw/sd/sdcard: Add sd_acmd_SET_CLR_CARD_DETECT handler (ACMD42) Philippe Mathieu-Daudé
@ 2024-06-28 4:53 ` Philippe Mathieu-Daudé
2024-06-28 4:53 ` [PATCH 08/12] hw/sd/sdcard: Remove sd_none enum from sd_cmd_type_t Philippe Mathieu-Daudé
` (4 subsequent siblings)
11 siblings, 0 replies; 13+ messages in thread
From: Philippe Mathieu-Daudé @ 2024-06-28 4:53 UTC (permalink / raw)
To: qemu-devel
Cc: Luc Michel, Francisco Iglesias, Cédric Le Goater,
Sai Pavan Boddu, Joel Stanley, Bin Meng, qemu-block,
Philippe Mathieu-Daudé
Signed-off-by: Philippe Mathieu-Daudé <philmd@linaro.org>
---
hw/sd/sd.c | 19 ++++++++-----------
1 file changed, 8 insertions(+), 11 deletions(-)
diff --git a/hw/sd/sd.c b/hw/sd/sd.c
index a27a7e0f24..6a9d611429 100644
--- a/hw/sd/sd.c
+++ b/hw/sd/sd.c
@@ -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},
},
};
--
2.41.0
^ permalink raw reply related [flat|nested] 13+ messages in thread
* [PATCH 08/12] hw/sd/sdcard: Remove sd_none enum from sd_cmd_type_t
2024-06-27 16:48 [PATCH 00/12] hw/sd/sdcard: Convert ACMD to sd_cmd_handler format Philippe Mathieu-Daudé
` (6 preceding siblings ...)
2024-06-28 4:53 ` [PATCH 07/12] hw/sd/sdcard: Add sd_acmd_SEND_SCR handler (ACMD51) Philippe Mathieu-Daudé
@ 2024-06-28 4:53 ` Philippe Mathieu-Daudé
2024-06-28 4:53 ` [PATCH 09/12] hw/sd/sdcard: Remove noise from sd_acmd_name() Philippe Mathieu-Daudé
` (3 subsequent siblings)
11 siblings, 0 replies; 13+ messages in thread
From: Philippe Mathieu-Daudé @ 2024-06-28 4:53 UTC (permalink / raw)
To: qemu-devel
Cc: Luc Michel, Francisco Iglesias, Cédric Le Goater,
Sai Pavan Boddu, Joel Stanley, Bin Meng, qemu-block,
Philippe Mathieu-Daudé
All handlers using the 'sd_none' enum got converted,
remove it.
Signed-off-by: Philippe Mathieu-Daudé <philmd@linaro.org>
---
include/hw/sd/sd.h | 1 -
hw/sd/sd.c | 7 +------
2 files changed, 1 insertion(+), 7 deletions(-)
diff --git a/include/hw/sd/sd.h b/include/hw/sd/sd.h
index 29c76935a0..c1a35ab420 100644
--- a/include/hw/sd/sd.h
+++ b/include/hw/sd/sd.h
@@ -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 */
diff --git a/hw/sd/sd.c b/hw/sd/sd.c
index 6a9d611429..7f93d363c7 100644
--- a/hw/sd/sd.c
+++ b/hw/sd/sd.c
@@ -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();
}
}
--
2.41.0
^ permalink raw reply related [flat|nested] 13+ messages in thread
* [PATCH 09/12] hw/sd/sdcard: Remove noise from sd_acmd_name()
2024-06-27 16:48 [PATCH 00/12] hw/sd/sdcard: Convert ACMD to sd_cmd_handler format Philippe Mathieu-Daudé
` (7 preceding siblings ...)
2024-06-28 4:53 ` [PATCH 08/12] hw/sd/sdcard: Remove sd_none enum from sd_cmd_type_t Philippe Mathieu-Daudé
@ 2024-06-28 4:53 ` Philippe Mathieu-Daudé
2024-06-28 4:53 ` [PATCH 10/12] hw/sd/sdcard: Remove noise from sd_cmd_name() Philippe Mathieu-Daudé
` (2 subsequent siblings)
11 siblings, 0 replies; 13+ messages in thread
From: Philippe Mathieu-Daudé @ 2024-06-28 4:53 UTC (permalink / raw)
To: qemu-devel
Cc: Luc Michel, Francisco Iglesias, Cédric Le Goater,
Sai Pavan Boddu, Joel Stanley, Bin Meng, qemu-block,
Philippe Mathieu-Daudé
These ACMD names weren't really useful, "UNKNOWN_ACMD" is simpler.
Signed-off-by: Philippe Mathieu-Daudé <philmd@linaro.org>
---
hw/sd/sd.c | 12 +-----------
1 file changed, 1 insertion(+), 11 deletions(-)
diff --git a/hw/sd/sd.c b/hw/sd/sd.c
index 7f93d363c7..19322c558f 100644
--- a/hw/sd/sd.c
+++ b/hw/sd/sd.c
@@ -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)
--
2.41.0
^ permalink raw reply related [flat|nested] 13+ messages in thread
* [PATCH 10/12] hw/sd/sdcard: Remove noise from sd_cmd_name()
2024-06-27 16:48 [PATCH 00/12] hw/sd/sdcard: Convert ACMD to sd_cmd_handler format Philippe Mathieu-Daudé
` (8 preceding siblings ...)
2024-06-28 4:53 ` [PATCH 09/12] hw/sd/sdcard: Remove noise from sd_acmd_name() Philippe Mathieu-Daudé
@ 2024-06-28 4:53 ` Philippe Mathieu-Daudé
2024-06-28 4:53 ` [PATCH 11/12] hw/sd/sdcard: Remove default case in read/write on DAT lines Philippe Mathieu-Daudé
2024-06-28 4:53 ` [PATCH 12/12] hw/sd/sdcard: Trace length of data read " Philippe Mathieu-Daudé
11 siblings, 0 replies; 13+ messages in thread
From: Philippe Mathieu-Daudé @ 2024-06-28 4:53 UTC (permalink / raw)
To: qemu-devel
Cc: Luc Michel, Francisco Iglesias, Cédric Le Goater,
Sai Pavan Boddu, Joel Stanley, Bin Meng, qemu-block,
Philippe Mathieu-Daudé
These CMD names weren't really useful, "UNKNOWN_CMD" is simpler.
Signed-off-by: Philippe Mathieu-Daudé <philmd@linaro.org>
---
hw/sd/sd.c | 5 -----
1 file changed, 5 deletions(-)
diff --git a/hw/sd/sd.c b/hw/sd/sd.c
index 19322c558f..0a7b422b2c 100644
--- a/hw/sd/sd.c
+++ b/hw/sd/sd.c
@@ -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;
--
2.41.0
^ permalink raw reply related [flat|nested] 13+ messages in thread
* [PATCH 11/12] hw/sd/sdcard: Remove default case in read/write on DAT lines
2024-06-27 16:48 [PATCH 00/12] hw/sd/sdcard: Convert ACMD to sd_cmd_handler format Philippe Mathieu-Daudé
` (9 preceding siblings ...)
2024-06-28 4:53 ` [PATCH 10/12] hw/sd/sdcard: Remove noise from sd_cmd_name() Philippe Mathieu-Daudé
@ 2024-06-28 4:53 ` Philippe Mathieu-Daudé
2024-06-28 4:53 ` [PATCH 12/12] hw/sd/sdcard: Trace length of data read " Philippe Mathieu-Daudé
11 siblings, 0 replies; 13+ messages in thread
From: Philippe Mathieu-Daudé @ 2024-06-28 4:53 UTC (permalink / raw)
To: qemu-devel
Cc: Luc Michel, Francisco Iglesias, Cédric Le Goater,
Sai Pavan Boddu, Joel Stanley, Bin Meng, qemu-block,
Philippe Mathieu-Daudé
All read/write on DAT lines are explicitly handled.
Reaching this point would be a programming error:
replace by an assertion.
Signed-off-by: Philippe Mathieu-Daudé <philmd@linaro.org>
---
hw/sd/sd.c | 9 ++++-----
1 file changed, 4 insertions(+), 5 deletions(-)
diff --git a/hw/sd/sd.c b/hw/sd/sd.c
index 0a7b422b2c..64621d4340 100644
--- a/hw/sd/sd.c
+++ b/hw/sd/sd.c
@@ -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;
--
2.41.0
^ permalink raw reply related [flat|nested] 13+ messages in thread
* [PATCH 12/12] hw/sd/sdcard: Trace length of data read on DAT lines
2024-06-27 16:48 [PATCH 00/12] hw/sd/sdcard: Convert ACMD to sd_cmd_handler format Philippe Mathieu-Daudé
` (10 preceding siblings ...)
2024-06-28 4:53 ` [PATCH 11/12] hw/sd/sdcard: Remove default case in read/write on DAT lines Philippe Mathieu-Daudé
@ 2024-06-28 4:53 ` Philippe Mathieu-Daudé
11 siblings, 0 replies; 13+ messages in thread
From: Philippe Mathieu-Daudé @ 2024-06-28 4:53 UTC (permalink / raw)
To: qemu-devel
Cc: Luc Michel, Francisco Iglesias, Cédric Le Goater,
Sai Pavan Boddu, Joel Stanley, Bin Meng, qemu-block,
Philippe Mathieu-Daudé
Some commands expect less than BLOCK_LENGTH.
Signed-off-by: Philippe Mathieu-Daudé <philmd@linaro.org>
---
hw/sd/sd.c | 4 ++--
hw/sd/trace-events | 2 +-
2 files changed, 3 insertions(+), 3 deletions(-)
diff --git a/hw/sd/sd.c b/hw/sd/sd.c
index 64621d4340..a0da06e017 100644
--- a/hw/sd/sd.c
+++ b/hw/sd/sd.c
@@ -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 */
diff --git a/hw/sd/trace-events b/hw/sd/trace-events
index 6a51b0e906..5dfe6be7b7 100644
--- a/hw/sd/trace-events
+++ b/hw/sd/trace-events
@@ -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
--
2.41.0
^ permalink raw reply related [flat|nested] 13+ messages in thread