From patchwork Sun Dec 18 20:37:55 2011 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Peter Maydell X-Patchwork-Id: 5845 Return-Path: X-Original-To: patchwork@peony.canonical.com Delivered-To: patchwork@peony.canonical.com Received: from fiordland.canonical.com (fiordland.canonical.com [91.189.94.145]) by peony.canonical.com (Postfix) with ESMTP id D47F523E2D for ; Sun, 18 Dec 2011 20:38:16 +0000 (UTC) Received: from mail-ey0-f180.google.com (mail-ey0-f180.google.com [209.85.215.180]) by fiordland.canonical.com (Postfix) with ESMTP id C50D5A18271 for ; Sun, 18 Dec 2011 20:38:16 +0000 (UTC) Received: by mail-ey0-f180.google.com with SMTP id c11so1269913eaa.11 for ; Sun, 18 Dec 2011 12:38:16 -0800 (PST) Received: by 10.204.129.24 with SMTP id m24mr757141bks.89.1324240696631; Sun, 18 Dec 2011 12:38:16 -0800 (PST) X-Forwarded-To: linaro-patchwork@canonical.com X-Forwarded-For: patch@linaro.org linaro-patchwork@canonical.com Delivered-To: patches@linaro.org Received: by 10.204.40.4 with SMTP id i4cs108685bke; Sun, 18 Dec 2011 12:38:16 -0800 (PST) Received: by 10.227.207.205 with SMTP id fz13mr10447948wbb.0.1324240695254; Sun, 18 Dec 2011 12:38:15 -0800 (PST) Received: from mnementh.archaic.org.uk (mnementh.archaic.org.uk. [81.2.115.146]) by mx.google.com with ESMTPS id ei1si9181055wid.77.2011.12.18.12.38.14 (version=TLSv1/SSLv3 cipher=OTHER); Sun, 18 Dec 2011 12:38:15 -0800 (PST) Received-SPF: pass (google.com: best guess record for domain of pm215@archaic.org.uk designates 81.2.115.146 as permitted sender) client-ip=81.2.115.146; Authentication-Results: mx.google.com; spf=pass (google.com: best guess record for domain of pm215@archaic.org.uk designates 81.2.115.146 as permitted sender) smtp.mail=pm215@archaic.org.uk Received: from pm215 by mnementh.archaic.org.uk with local (Exim 4.72) (envelope-from ) id 1RcNUe-00070Y-P4; Sun, 18 Dec 2011 20:38:00 +0000 From: Peter Maydell To: qemu-devel@nongnu.org Cc: patches@linaro.org Subject: [PATCH 05/10] hw/sd.c: Handle illegal commands in sd_do_command Date: Sun, 18 Dec 2011 20:37:55 +0000 Message-Id: <1324240680-26905-6-git-send-email-peter.maydell@linaro.org> X-Mailer: git-send-email 1.7.2.5 In-Reply-To: <1324240680-26905-1-git-send-email-peter.maydell@linaro.org> References: <1324240680-26905-1-git-send-email-peter.maydell@linaro.org> Add an extra sd_illegal value to the sd_rsp_type_t enum so that sd_app_command() and sd_normal_command() can tell sd_do_command() that the command was illegal. This is needed so we can do things like reset certain status bits only on receipt of a valid command. For the moment, just use it to pull out the setting of the ILLEGAL_COMMAND status bit into sd_do_command(). Signed-off-by: Peter Maydell --- hw/sd.c | 25 +++++++++++-------------- 1 files changed, 11 insertions(+), 14 deletions(-) diff --git a/hw/sd.c b/hw/sd.c index dd28061..57925af 100644 --- a/hw/sd.c +++ b/hw/sd.c @@ -51,6 +51,7 @@ typedef enum { sd_r6 = 6, /* Published RCA response */ sd_r7, /* Operating voltage */ sd_r1b = -1, + sd_illegal = -2, } sd_rsp_type_t; struct SDState { @@ -679,8 +680,7 @@ static sd_rsp_type_t sd_normal_command(SDState *sd, break; case 5: /* CMD5: reserved for SDIO cards */ - sd->card_status |= ILLEGAL_COMMAND; - return sd_r0; + return sd_illegal; case 6: /* CMD6: SWITCH_FUNCTION */ if (sd->spi) @@ -1115,8 +1115,7 @@ static sd_rsp_type_t sd_normal_command(SDState *sd, * on stderr, as some OSes may use these in their * probing for presence of an SDIO card. */ - sd->card_status |= ILLEGAL_COMMAND; - return sd_r0; + return sd_illegal; /* Application specific commands (Class 8) */ case 55: /* CMD55: APP_CMD */ @@ -1145,21 +1144,17 @@ static sd_rsp_type_t sd_normal_command(SDState *sd, default: bad_cmd: - sd->card_status |= ILLEGAL_COMMAND; - fprintf(stderr, "SD: Unknown CMD%i\n", req.cmd); - return sd_r0; + return sd_illegal; unimplemented_cmd: /* Commands that are recognised but not yet implemented in SPI mode. */ - sd->card_status |= ILLEGAL_COMMAND; fprintf(stderr, "SD: CMD%i not implemented in SPI mode\n", req.cmd); - return sd_r0; + return sd_illegal; } - sd->card_status |= ILLEGAL_COMMAND; fprintf(stderr, "SD: CMD%i in a wrong state\n", req.cmd); - return sd_r0; + return sd_illegal; } static sd_rsp_type_t sd_app_command(SDState *sd, @@ -1321,6 +1316,10 @@ int sd_do_command(SDState *sd, SDRequest *req, } else rtype = sd_normal_command(sd, *req); + if (rtype == sd_illegal) { + sd->card_status |= ILLEGAL_COMMAND; + } + sd->current_cmd = req->cmd; switch (rtype) { @@ -1356,14 +1355,12 @@ int sd_do_command(SDState *sd, SDRequest *req, break; case sd_r0: + case sd_illegal: default: rsplen = 0; break; } - if (sd->card_status & ILLEGAL_COMMAND) - rsplen = 0; - #ifdef DEBUG_SD if (rsplen) { int i;