From patchwork Thu Feb 15 22:05:36 2018 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: =?utf-8?q?Philippe_Mathieu-Daud=C3=A9?= X-Patchwork-Id: 874176 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@bilbo.ozlabs.org Authentication-Results: ozlabs.org; spf=pass (mailfrom) smtp.mailfrom=nongnu.org (client-ip=2001:4830:134:3::11; helo=lists.gnu.org; envelope-from=qemu-devel-bounces+incoming=patchwork.ozlabs.org@nongnu.org; receiver=) Authentication-Results: ozlabs.org; dkim=fail reason="signature verification failed" (2048-bit key; unprotected) header.d=gmail.com header.i=@gmail.com header.b="IP3NQr+B"; dkim-atps=neutral Received: from lists.gnu.org (lists.gnu.org [IPv6:2001:4830:134:3::11]) (using TLSv1 with cipher AES256-SHA (256/256 bits)) (No client certificate requested) by ozlabs.org (Postfix) with ESMTPS id 3zj9cj3f5nz9t2f for ; Fri, 16 Feb 2018 09:17:25 +1100 (AEDT) Received: from localhost ([::1]:36869 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1emRqF-0000Gp-ER for incoming@patchwork.ozlabs.org; Thu, 15 Feb 2018 17:17:23 -0500 Received: from eggs.gnu.org ([2001:4830:134:3::10]:55815) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1emRfX-0006Lz-Lp for qemu-devel@nongnu.org; Thu, 15 Feb 2018 17:06:20 -0500 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1emRfU-0001BK-GU for qemu-devel@nongnu.org; Thu, 15 Feb 2018 17:06:19 -0500 Received: from mail-qt0-x243.google.com ([2607:f8b0:400d:c0d::243]:45665) by eggs.gnu.org with esmtps (TLS1.0:RSA_AES_128_CBC_SHA1:16) (Exim 4.71) (envelope-from ) id 1emRfU-0001B6-C1 for qemu-devel@nongnu.org; Thu, 15 Feb 2018 17:06:16 -0500 Received: by mail-qt0-x243.google.com with SMTP id x27so1574435qtm.12 for ; Thu, 15 Feb 2018 14:06:16 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=sender:from:to:cc:subject:date:message-id:in-reply-to:references :mime-version:content-transfer-encoding; bh=Pv33HSo/9ouTH9UJyrbpKyM6FMsrj7CtbYsvjAlIgEY=; b=IP3NQr+ByyfkF31CTdnJxdtITtFDUJT2aFddjyVGJIeA6L9ZOiOrlJGlHtkcTYjRZe +IphbG7u25gqVokCZqMf4fMOoPddGUZ0SLHG7i6+oIm+gvEDG0XbM74PxMAlFVLFAgsT QGF2veBg2JdoDgUl7rz4BMgItNfwn0/oTLcLGsbT9XhNUl9261pWtM9rZ+zH4h8MzZ93 k1+UAfNWmlo1TPTuRpcgJMJ0Ptv+9J7XTGmqPtccEjwVN1c7EaO/jLHphU9XXhnDxRPW AZCKzbg9Hi8P8/ZMAtJqGxUtAFzpqgpKiOLHfxSoZGaEiPa/nG0CXo05Ljmt/4zrkbp5 9zSw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:sender:from:to:cc:subject:date:message-id :in-reply-to:references:mime-version:content-transfer-encoding; bh=Pv33HSo/9ouTH9UJyrbpKyM6FMsrj7CtbYsvjAlIgEY=; b=l0f3RaGSwoEY9BuAxgtPB5q8b9g2OWmbO6nLyxAjdGeMi1kyhwtqqzjAT2L37QOTec E3QPTH9//ov+3Q5d8FaKWTKGkZmyezPyTc9tHW/9vzb6k0iHe29BtUVSMBuhibdRzKaK jAJ9esul0jWRkCQvgXQQ9OWDWJjr65oCOzaSCMrWkj1m6EJ2QtHEt6YkhmrX30cg8IOc 1cxda58zjElewb1/fBvDifkp3cMt0uFablvLfmVuYpAcNX7NCdqoyQONHSZhJGYiCyRy jE30CYVkZK5VrDwkV1gtlQ+Zwb9LYgfb3DH+9EsfNEcCMz3u0l/Qyg/whlp4ZGzjkTzE jWyw== X-Gm-Message-State: APf1xPCfWh/eKaXmjGnrtVKl4J1y+wGFM9P7pgGSXBW7LeFf3Lf5jIQT 4G6qoDYDstHgey+HJAMPSg8AyF8CNE8= X-Google-Smtp-Source: AH8x226nNPnROHM2B5R/gQEGWuUvAGbxqEX9RzO4NwiMiDD7jdFYdcTuTLaVs1PS18mmiTr0JEj29A== X-Received: by 10.200.51.13 with SMTP id t13mr6584959qta.263.1518732375894; Thu, 15 Feb 2018 14:06:15 -0800 (PST) Received: from x1.lan ([138.117.48.219]) by smtp.gmail.com with ESMTPSA id h200sm6330991qke.66.2018.02.15.14.06.11 (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Thu, 15 Feb 2018 14:06:14 -0800 (PST) From: =?utf-8?q?Philippe_Mathieu-Daud=C3=A9?= To: Alistair Francis , Peter Maydell , Igor Mitsyanko Date: Thu, 15 Feb 2018 19:05:36 -0300 Message-Id: <20180215220540.6556-8-f4bug@amsat.org> X-Mailer: git-send-email 2.16.1 In-Reply-To: <20180215220540.6556-1-f4bug@amsat.org> References: <20180215220540.6556-1-f4bug@amsat.org> MIME-Version: 1.0 X-detected-operating-system: by eggs.gnu.org: Genre and OS details not recognized. X-Received-From: 2607:f8b0:400d:c0d::243 Subject: [Qemu-devel] [PATCH v4 07/11] 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: , Cc: "Edgar E . Iglesias" , Prasad J Pandit , =?utf-8?q?Philippe_Mathieu-Daud=C3=A9?= , qemu-devel@nongnu.org Errors-To: qemu-devel-bounces+incoming=patchwork.ozlabs.org@nongnu.org Sender: "Qemu-devel" Signed-off-by: Philippe Mathieu-Daudé Reviewed-by: Alistair Francis --- Since v3: add "sdmmc-internal.h" 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é + * + * 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 af4df2b104..6acd6b3c5c 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, @@ -831,8 +835,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; } @@ -1544,8 +1548,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, @@ -1564,6 +1568,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;