From nobody Wed Apr 16 17:39:12 2025 Delivered-To: importer@patchew.org Received-SPF: pass (zoho.com: domain of gnu.org designates 208.118.235.17 as permitted sender) client-ip=208.118.235.17; envelope-from=qemu-devel-bounces+importer=patchew.org@nongnu.org; helo=lists.gnu.org; Authentication-Results: mx.zohomail.com; spf=pass (zoho.com: domain of gnu.org designates 208.118.235.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; dmarc=fail(p=none dis=none) header.from=linaro.org Return-Path: Received: from lists.gnu.org (lists.gnu.org [208.118.235.17]) by mx.zohomail.com with SMTPS id 1519313446069917.9060202054085; Thu, 22 Feb 2018 07:30:46 -0800 (PST) Received: from localhost ([::1]:39004 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1eospU-0002bX-OM for importer@patchew.org; Thu, 22 Feb 2018 10:30:40 -0500 Received: from eggs.gnu.org ([2001:4830:134:3::10]:38427) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1eosie-0004qz-Mh for qemu-devel@nongnu.org; Thu, 22 Feb 2018 10:23:37 -0500 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1eosic-0001hF-EX for qemu-devel@nongnu.org; Thu, 22 Feb 2018 10:23:36 -0500 Received: from orth.archaic.org.uk ([2001:8b0:1d0::2]:46602) by eggs.gnu.org with esmtps (TLS1.0:RSA_AES_256_CBC_SHA1:32) (Exim 4.71) (envelope-from ) id 1eosic-0001gY-6u for qemu-devel@nongnu.org; Thu, 22 Feb 2018 10:23:34 -0500 Received: from pm215 by orth.archaic.org.uk with local (Exim 4.89) (envelope-from ) id 1eosib-00023U-98 for qemu-devel@nongnu.org; Thu, 22 Feb 2018 15:23:33 +0000 From: Peter Maydell To: qemu-devel@nongnu.org Date: Thu, 22 Feb 2018 15:22:49 +0000 Message-Id: <20180222152307.7499-15-peter.maydell@linaro.org> X-Mailer: git-send-email 2.16.1 In-Reply-To: <20180222152307.7499-1-peter.maydell@linaro.org> References: <20180222152307.7499-1-peter.maydell@linaro.org> MIME-Version: 1.0 Content-Type: text/plain; charset="utf-8" Content-Transfer-Encoding: quoted-printable X-detected-operating-system: by eggs.gnu.org: Genre and OS details not recognized. X-Received-From: 2001:8b0:1d0::2 Subject: [Qemu-devel] [PULL 14/32] sdcard: define SDMMC_CMD_MAX instead of using the magic '64' X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.21 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: "Qemu-devel" X-ZohoMail: RSF_0 Z_629925259 SPT_0 From: Philippe Mathieu-Daud=C3=A9 Signed-off-by: Philippe Mathieu-Daud=C3=A9 Reviewed-by: Alistair Francis Message-id: 20180215220540.6556-8-f4bug@amsat.org Signed-off-by: Peter Maydell --- 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=C3=A9 + * + * This work is licensed under the terms of the GNU GPL, version 2 or late= r. + * 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" =20 //#define DEBUG_SD 1 @@ -215,18 +216,21 @@ static void sd_set_mode(SDState *sd) } } =20 -static const sd_cmd_type_t sd_cmd_type[64] =3D { +static const sd_cmd_type_t sd_cmd_type[SDMMC_CMD_MAX] =3D { 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, }; =20 -static const int sd_cmd_class[64] =3D { +static const int sd_cmd_class[SDMMC_CMD_MAX] =3D { 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 &=3D ~APP_CMD; =20 - if (sd_cmd_type[req.cmd & 0x3F] =3D=3D sd_ac - || sd_cmd_type[req.cmd & 0x3F] =3D=3D sd_adtc) { + if (sd_cmd_type[req.cmd] =3D=3D sd_ac + || sd_cmd_type[req.cmd] =3D=3D sd_adtc) { rca =3D req.arg >> 16; } =20 @@ -1542,8 +1546,8 @@ static int cmd_valid_while_locked(SDState *sd, SDRequ= est *req) if (req->cmd =3D=3D 16 || req->cmd =3D=3D 55) { return 1; } - return sd_cmd_class[req->cmd & 0x3F] =3D=3D 0 - || sd_cmd_class[req->cmd & 0x3F] =3D=3D 7; + return sd_cmd_class[req->cmd] =3D=3D 0 + || sd_cmd_class[req->cmd] =3D=3D 7; } =20 int sd_do_command(SDState *sd, SDRequest *req, @@ -1562,6 +1566,12 @@ int sd_do_command(SDState *sd, SDRequest *req, goto send_response; } =20 + if (req->cmd >=3D SDMMC_CMD_MAX) { + qemu_log_mask(LOG_GUEST_ERROR, "SD: incorrect command 0x%02x\n", + req->cmd); + req->cmd &=3D 0x3f; + } + if (sd->card_status & CARD_IS_LOCKED) { if (!cmd_valid_while_locked(sd, req)) { sd->card_status |=3D ILLEGAL_COMMAND; --=20 2.16.1