From patchwork Wed Apr 27 13:43:07 2011 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Kevin Wolf X-Patchwork-Id: 93057 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 140861007D7 for ; Wed, 27 Apr 2011 23:43:34 +1000 (EST) Received: from localhost ([::1]:33326 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1QF51f-0001Hr-95 for incoming@patchwork.ozlabs.org; Wed, 27 Apr 2011 09:43:31 -0400 Received: from eggs.gnu.org ([140.186.70.92]:51783) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1QF4z7-0005cn-3D for qemu-devel@nongnu.org; Wed, 27 Apr 2011 09:40:57 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1QF4z5-0007o2-JJ for qemu-devel@nongnu.org; Wed, 27 Apr 2011 09:40:52 -0400 Received: from mx1.redhat.com ([209.132.183.28]:32070) by eggs.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1QF4z5-0007nr-Av for qemu-devel@nongnu.org; Wed, 27 Apr 2011 09:40:51 -0400 Received: from int-mx02.intmail.prod.int.phx2.redhat.com (int-mx02.intmail.prod.int.phx2.redhat.com [10.5.11.12]) by mx1.redhat.com (8.14.4/8.14.4) with ESMTP id p3RDem72011500 (version=TLSv1/SSLv3 cipher=DHE-RSA-AES256-SHA bits=256 verify=OK); Wed, 27 Apr 2011 09:40:48 -0400 Received: from dhcp-5-188.str.redhat.com (dhcp-5-175.str.redhat.com [10.32.5.175]) by int-mx02.intmail.prod.int.phx2.redhat.com (8.13.8/8.13.8) with ESMTP id p3RDeaVY016837; Wed, 27 Apr 2011 09:40:47 -0400 From: Kevin Wolf To: anthony@codemonkey.ws Date: Wed, 27 Apr 2011 15:43:07 +0200 Message-Id: <1303911790-27422-9-git-send-email-kwolf@redhat.com> In-Reply-To: <1303911790-27422-1-git-send-email-kwolf@redhat.com> References: <1303911790-27422-1-git-send-email-kwolf@redhat.com> X-Scanned-By: MIMEDefang 2.67 on 10.5.11.12 X-detected-operating-system: by eggs.gnu.org: Genre and OS details not recognized. X-Received-From: 209.132.183.28 Cc: kwolf@redhat.com, qemu-devel@nongnu.org Subject: [Qemu-devel] [PATCH 08/11] ide/atapi: Introduce CHECK_READY flag for commands 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 Some commands are supposed to report a Not Ready Condition (i.e. they require a medium to be present in order to execute successfully). Instead of duplicating the check in each command implementation, let's add a flag and check it before calling the command. This patch only converts existing checks, it does not introduce new checks for any of the other commands that can/should report a Not Ready Condition. Signed-off-by: Kevin Wolf --- hw/ide/atapi.c | 48 +++++++++++++++++++++++------------------------- 1 files changed, 23 insertions(+), 25 deletions(-) diff --git a/hw/ide/atapi.c b/hw/ide/atapi.c index 0d14439..c0a3199 100644 --- a/hw/ide/atapi.c +++ b/hw/ide/atapi.c @@ -813,11 +813,9 @@ error_cmd: static void cmd_test_unit_ready(IDEState *s, uint8_t *buf) { - if (bdrv_is_inserted(s->bs)) { - ide_atapi_cmd_ok(s); - } else { - ide_atapi_cmd_error(s, SENSE_NOT_READY, ASC_MEDIUM_NOT_PRESENT); - } + /* Not Ready Conditions are already handled in ide_atapi_cmd(), so if we + * come here, we know that it's ready. */ + ide_atapi_cmd_ok(s); } static void cmd_prevent_allow_medium_removal(IDEState *s, uint8_t* buf) @@ -883,11 +881,6 @@ static void cmd_seek(IDEState *s, uint8_t* buf) unsigned int lba; uint64_t total_sectors = s->nb_sectors >> 2; - if (total_sectors == 0) { - ide_atapi_cmd_error(s, SENSE_NOT_READY, ASC_MEDIUM_NOT_PRESENT); - return; - } - lba = ube32_to_cpu(buf + 2); if (lba >= total_sectors) { ide_atapi_cmd_error(s, SENSE_ILLEGAL_REQUEST, ASC_LOGICAL_BLOCK_OOR); @@ -941,13 +934,8 @@ static void cmd_mechanism_status(IDEState *s, uint8_t* buf) static void cmd_read_toc_pma_atip(IDEState *s, uint8_t* buf) { int format, msf, start_track, len; - uint64_t total_sectors = s->nb_sectors >> 2; int max_len; - - if (total_sectors == 0) { - ide_atapi_cmd_error(s, SENSE_NOT_READY, ASC_MEDIUM_NOT_PRESENT); - return; - } + uint64_t total_sectors = s->nb_sectors >> 2; max_len = ube16_to_cpu(buf + 7); format = buf[9] >> 6; @@ -986,11 +974,6 @@ static void cmd_read_cdvd_capacity(IDEState *s, uint8_t* buf) { uint64_t total_sectors = s->nb_sectors >> 2; - if (total_sectors == 0) { - ide_atapi_cmd_error(s, SENSE_NOT_READY, ASC_MEDIUM_NOT_PRESENT); - return; - } - /* NOTE: it is really the number of sectors minus 1 */ cpu_to_ube32(buf, total_sectors - 1); cpu_to_ube32(buf + 4, 2048); @@ -1062,22 +1045,29 @@ enum { * unit attention condition. (See MMC-5, section 4.1.6.1) */ ALLOW_UA = 0x01, + + /* + * Commands flagged with CHECK_READY can only execute if a medium is present. + * Otherwise they report the Not Ready Condition. (See MMC-5, section + * 4.1.8) + */ + CHECK_READY = 0x02, }; static const struct { void (*handler)(IDEState *s, uint8_t *buf); int flags; } atapi_cmd_table[0x100] = { - [ 0x00 ] = { cmd_test_unit_ready, 0 }, + [ 0x00 ] = { cmd_test_unit_ready, CHECK_READY }, [ 0x03 ] = { cmd_request_sense, ALLOW_UA }, [ 0x12 ] = { cmd_inquiry, ALLOW_UA }, [ 0x1a ] = { cmd_mode_sense, /* (6) */ 0 }, [ 0x1b ] = { cmd_start_stop_unit, 0 }, [ 0x1e ] = { cmd_prevent_allow_medium_removal, 0 }, - [ 0x25 ] = { cmd_read_cdvd_capacity, 0 }, + [ 0x25 ] = { cmd_read_cdvd_capacity, CHECK_READY }, [ 0x28 ] = { cmd_read, /* (10) */ 0 }, - [ 0x2b ] = { cmd_seek, 0 }, - [ 0x43 ] = { cmd_read_toc_pma_atip, 0 }, + [ 0x2b ] = { cmd_seek, CHECK_READY }, + [ 0x43 ] = { cmd_read_toc_pma_atip, CHECK_READY }, [ 0x46 ] = { cmd_get_configuration, ALLOW_UA }, [ 0x4a ] = { cmd_get_event_status_notification, ALLOW_UA }, [ 0x5a ] = { cmd_mode_sense, /* (10) */ 0 }, @@ -1126,6 +1116,14 @@ void ide_atapi_cmd(IDEState *s) return; } + /* Report a Not Ready condition if appropriate for the command */ + if ((atapi_cmd_table[s->io_buffer[0]].flags & CHECK_READY) && + (!media_present(s) || !bdrv_is_inserted(s->bs))) + { + ide_atapi_cmd_error(s, SENSE_NOT_READY, ASC_MEDIUM_NOT_PRESENT); + return; + } + /* Execute the command */ if (atapi_cmd_table[s->io_buffer[0]].handler) { atapi_cmd_table[s->io_buffer[0]].handler(s, buf);