[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[Qemu-devel] [PULL 14/32] sdcard: define SDMMC_CMD_MAX instead of using
From: |
Peter Maydell |
Subject: |
[Qemu-devel] [PULL 14/32] sdcard: define SDMMC_CMD_MAX instead of using the magic '64' |
Date: |
Thu, 22 Feb 2018 15:22:49 +0000 |
From: Philippe Mathieu-Daudé <address@hidden>
Signed-off-by: Philippe Mathieu-Daudé <address@hidden>
Reviewed-by: Alistair Francis <address@hidden>
Message-id: address@hidden
Signed-off-by: Peter Maydell <address@hidden>
---
hw/sd/sdmmc-internal.h | 15 +++++++++++++++
hw/sd/sd.c | 22 ++++++++++++++++------
2 files changed, 31 insertions(+), 6 deletions(-)
create mode 100644 hw/sd/sdmmc-internal.h
diff --git a/hw/sd/sdmmc-internal.h b/hw/sd/sdmmc-internal.h
new file mode 100644
index 0000000000..0e96cb0081
--- /dev/null
+++ b/hw/sd/sdmmc-internal.h
@@ -0,0 +1,15 @@
+/*
+ * SD/MMC cards common
+ *
+ * Copyright (c) 2018 Philippe Mathieu-Daudé <address@hidden>
+ *
+ * This work is licensed under the terms of the GNU GPL, version 2 or later.
+ * See the COPYING file in the top-level directory.
+ * SPDX-License-Identifier: GPL-2.0-or-later
+ */
+#ifndef SD_INTERNAL_H
+#define SD_INTERNAL_H
+
+#define SDMMC_CMD_MAX 64
+
+#endif
diff --git a/hw/sd/sd.c b/hw/sd/sd.c
index 564f7a9bfd..90d1e27ee7 100644
--- a/hw/sd/sd.c
+++ b/hw/sd/sd.c
@@ -40,6 +40,7 @@
#include "qemu/error-report.h"
#include "qemu/timer.h"
#include "qemu/log.h"
+#include "sdmmc-internal.h"
#include "trace.h"
//#define DEBUG_SD 1
@@ -215,18 +216,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 +833,8 @@ static sd_rsp_type_t sd_normal_command(SDState *sd,
/* 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 +1546,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 +1566,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.16.1
- [Qemu-devel] [PULL 05/32] hw/sd/milkymist-memcard: use qemu_log_mask(), (continued)
- [Qemu-devel] [PULL 05/32] hw/sd/milkymist-memcard: use qemu_log_mask(), Peter Maydell, 2018/02/22
- [Qemu-devel] [PULL 06/32] hw/sd/milkymist-memcard: split realize() out of SysBusDevice init(), Peter Maydell, 2018/02/22
- [Qemu-devel] [PULL 02/32] raspi: Add "raspi3" machine type, Peter Maydell, 2018/02/22
- [Qemu-devel] [PULL 08/32] hw/sd/ssi-sd: use the SDBus API, connect the SDCard to the bus, Peter Maydell, 2018/02/22
- [Qemu-devel] [PULL 10/32] sdcard: replace DPRINTF() by trace events, Peter Maydell, 2018/02/22
- [Qemu-devel] [PULL 07/32] hw/sd/milkymist-memcard: expose a SDBus and connect the SDCard to it, Peter Maydell, 2018/02/22
- [Qemu-devel] [PULL 09/32] sdcard: reorder SDState struct members, Peter Maydell, 2018/02/22
- [Qemu-devel] [PULL 11/32] sdcard: add a trace event for command responses, Peter Maydell, 2018/02/22
- [Qemu-devel] [PULL 13/32] sdcard: add more trace events, Peter Maydell, 2018/02/22
- [Qemu-devel] [PULL 12/32] sdcard: replace fprintf() by qemu_hexdump(), Peter Maydell, 2018/02/22
- [Qemu-devel] [PULL 14/32] sdcard: define SDMMC_CMD_MAX instead of using the magic '64',
Peter Maydell <=
- [Qemu-devel] [PULL 17/32] sdcard: Don't always set the high capacity bit, Peter Maydell, 2018/02/22
- [Qemu-devel] [PULL 19/32] sdcard: fix the 'maximum data transfer rate' to 25MHz, Peter Maydell, 2018/02/22
- [Qemu-devel] [PULL 20/32] sdcard: clean the SCR register and add few comments, Peter Maydell, 2018/02/22
- [Qemu-devel] [PULL 16/32] sdcard: use the registerfields API to access the OCR register, Peter Maydell, 2018/02/22
- [Qemu-devel] [PULL 15/32] sdcard: use G_BYTE from cutils, Peter Maydell, 2018/02/22
- [Qemu-devel] [PULL 21/32] sdcard: remove commands from unsupported old MMC specification, Peter Maydell, 2018/02/22
- [Qemu-devel] [PULL 18/32] sdcard: update the CSD CRC register regardless the CSD structure version, Peter Maydell, 2018/02/22
- [Qemu-devel] [PULL 23/32] sdcard: use the correct masked OCR in the R3 reply, Peter Maydell, 2018/02/22
- [Qemu-devel] [PULL 22/32] sdcard: simplify using the ldst API, Peter Maydell, 2018/02/22
- [Qemu-devel] [PULL 25/32] sdcard: handle CMD54 (SDIO), Peter Maydell, 2018/02/22