[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[Qemu-devel] [PATCH v3 07/12] sdcard: define SDMMC_CMD_MAX instead of us
From: |
Philippe Mathieu-Daudé |
Subject: |
[Qemu-devel] [PATCH v3 07/12] sdcard: define SDMMC_CMD_MAX instead of using the magic '64' |
Date: |
Tue, 23 Jan 2018 00:21:30 -0300 |
Signed-off-by: Philippe Mathieu-Daudé <address@hidden>
Reviewed-by: Alistair Francis <address@hidden>
---
hw/sd/sd.c | 23 +++++++++++++++++------
1 file changed, 17 insertions(+), 6 deletions(-)
diff --git a/hw/sd/sd.c b/hw/sd/sd.c
index 27c08aa894..7b1cbc0a2e 100644
--- a/hw/sd/sd.c
+++ b/hw/sd/sd.c
@@ -126,6 +126,8 @@ struct SDState {
bool cmd_line;
};
+#define SDMMC_CMD_MAX 64
+
static const char *sd_state_name(enum SDCardStates state)
{
static const char *state_name[] = {
@@ -213,18 +215,21 @@ static void sd_set_mode(SDState *sd)
}
}
-static const sd_cmd_type_t sd_cmd_type[64] = {
+static const sd_cmd_type_t sd_cmd_type[SDMMC_CMD_MAX] = {
sd_bc, sd_none, sd_bcr, sd_bcr, sd_none, sd_none, sd_none, sd_ac,
sd_bcr, sd_ac, sd_ac, sd_adtc, sd_ac, sd_ac, sd_none, sd_ac,
+ /* 16 */
sd_ac, sd_adtc, sd_adtc, sd_none, sd_none, sd_none, sd_none, sd_none,
sd_adtc, sd_adtc, sd_adtc, sd_adtc, sd_ac, sd_ac, sd_adtc, sd_none,
+ /* 32 */
sd_ac, sd_ac, sd_none, sd_none, sd_none, sd_none, sd_ac, sd_none,
sd_none, sd_none, sd_bc, sd_none, sd_none, sd_none, sd_none, sd_none,
+ /* 48 */
sd_none, sd_none, sd_none, sd_none, sd_none, sd_none, sd_none, sd_ac,
sd_adtc, sd_none, sd_none, sd_none, sd_none, sd_none, sd_none, sd_none,
};
-static const int sd_cmd_class[64] = {
+static const int sd_cmd_class[SDMMC_CMD_MAX] = {
0, 0, 0, 0, 0, 9, 10, 0, 0, 0, 0, 1, 0, 0, 0, 0,
2, 2, 2, 2, 3, 3, 3, 3, 4, 4, 4, 4, 6, 6, 6, 6,
5, 5, 10, 10, 10, 10, 5, 9, 9, 9, 7, 7, 7, 7, 7, 7,
@@ -829,8 +834,8 @@ 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 & 0x3F] == sd_ac
- || sd_cmd_type[req.cmd & 0x3F] == sd_adtc) {
+ if (sd_cmd_type[req.cmd] == sd_ac
+ || sd_cmd_type[req.cmd] == sd_adtc) {
rca = req.arg >> 16;
}
@@ -1542,8 +1547,8 @@ static int cmd_valid_while_locked(SDState *sd, SDRequest
*req)
if (req->cmd == 16 || req->cmd == 55) {
return 1;
}
- return sd_cmd_class[req->cmd & 0x3F] == 0
- || sd_cmd_class[req->cmd & 0x3F] == 7;
+ return sd_cmd_class[req->cmd] == 0
+ || sd_cmd_class[req->cmd] == 7;
}
int sd_do_command(SDState *sd, SDRequest *req,
@@ -1562,6 +1567,12 @@ int sd_do_command(SDState *sd, SDRequest *req,
goto send_response;
}
+ if (req->cmd >= SDMMC_CMD_MAX) {
+ qemu_log_mask(LOG_GUEST_ERROR, "SD: incorrect command 0x%02x\n",
+ req->cmd);
+ req->cmd &= 0x3f;
+ }
+
if (sd->card_status & CARD_IS_LOCKED) {
if (!cmd_valid_while_locked(sd, req)) {
sd->card_status |= ILLEGAL_COMMAND;
--
2.15.1
- [Qemu-devel] [PATCH v3 02/12] sdcard: replace DPRINTF() by trace events, (continued)
- [Qemu-devel] [PATCH v3 02/12] sdcard: replace DPRINTF() by trace events, Philippe Mathieu-Daudé, 2018/01/22
- [Qemu-devel] [PATCH v3 03/12] sdcard: add a trace event for command responses, Philippe Mathieu-Daudé, 2018/01/22
- [Qemu-devel] [PATCH v3 04/12] sdcard: replace fprintf() by qemu_hexdump(), Philippe Mathieu-Daudé, 2018/01/22
- [Qemu-devel] [PATCH v3 05/12] sdcard: add more trace events, Philippe Mathieu-Daudé, 2018/01/22
- [Qemu-devel] [PATCH v3 06/12] sdcard: do not trace CMD55 when expecting ACMD, Philippe Mathieu-Daudé, 2018/01/22
- [Qemu-devel] [PATCH v3 07/12] sdcard: define SDMMC_CMD_MAX instead of using the magic '64',
Philippe Mathieu-Daudé <=
- [Qemu-devel] [PATCH v3 08/12] sdcard: display command name when tracing CMD/ACMD, Philippe Mathieu-Daudé, 2018/01/22
- [Qemu-devel] [PATCH v3 09/12] sdcard: display protocol used when tracing, Philippe Mathieu-Daudé, 2018/01/22
- [Qemu-devel] [PATCH v3 10/12] sdcard: rename sd_set_$REG() functions called once as sd_reset_$REG(), Philippe Mathieu-Daudé, 2018/01/22
- [Qemu-devel] [PATCH v3 11/12] sdcard: use G_BYTE from cutils, Philippe Mathieu-Daudé, 2018/01/22
- [Qemu-devel] [PATCH v3 12/12] sdcard: use the registerfields API to access the OCR register, Philippe Mathieu-Daudé, 2018/01/22