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: 132119 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@bilbo.ozlabs.org Received: from lists.gnu.org (lists.gnu.org [140.186.70.17]) (using TLSv1 with cipher AES256-SHA (256/256 bits)) (Client did not present a certificate) by ozlabs.org (Postfix) with ESMTPS id 5BC06B6FD3 for ; Mon, 19 Dec 2011 08:12:04 +1100 (EST) Received: from localhost ([::1]:53720 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1RcNVc-0007oI-8L for incoming@patchwork.ozlabs.org; Sun, 18 Dec 2011 15:39:00 -0500 Received: from eggs.gnu.org ([140.186.70.92]:43050) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1RcNUv-0005VM-5m for qemu-devel@nongnu.org; Sun, 18 Dec 2011 15:38:19 -0500 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1RcNUs-0006zv-Hs for qemu-devel@nongnu.org; Sun, 18 Dec 2011 15:38:17 -0500 Received: from mnementh.archaic.org.uk ([81.2.115.146]:38904) by eggs.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1RcNUs-0006yK-9o for qemu-devel@nongnu.org; Sun, 18 Dec 2011 15:38:14 -0500 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 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> X-detected-operating-system: by eggs.gnu.org: GNU/Linux 2.6 (newer, 2) X-Received-From: 81.2.115.146 Cc: patches@linaro.org Subject: [Qemu-devel] [PATCH 05/10] hw/sd.c: Handle illegal commands in sd_do_command X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.14 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: qemu-devel-bounces+incoming=patchwork.ozlabs.org@nongnu.org Sender: qemu-devel-bounces+incoming=patchwork.ozlabs.org@nongnu.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;