From patchwork Tue Sep 6 16:58:35 2011 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Markus Armbruster X-Patchwork-Id: 113649 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 B1C1CB6F76 for ; Wed, 7 Sep 2011 03:48:03 +1000 (EST) Received: from localhost ([::1]:36595 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1R0yzy-0007Gx-43 for incoming@patchwork.ozlabs.org; Tue, 06 Sep 2011 12:59:46 -0400 Received: from eggs.gnu.org ([140.186.70.92]:38085) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1R0yzO-0005c5-6h for qemu-devel@nongnu.org; Tue, 06 Sep 2011 12:59:19 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1R0yzJ-0004YH-F3 for qemu-devel@nongnu.org; Tue, 06 Sep 2011 12:59:10 -0400 Received: from oxygen.pond.sub.org ([78.46.104.156]:55947) by eggs.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1R0yzJ-0004XN-2V for qemu-devel@nongnu.org; Tue, 06 Sep 2011 12:59:05 -0400 Received: from blackfin.pond.sub.org (p5B32C9A8.dip.t-dialin.net [91.50.201.168]) by oxygen.pond.sub.org (Postfix) with ESMTPA id BFBA8A246F; Tue, 6 Sep 2011 18:59:01 +0200 (CEST) Received: by blackfin.pond.sub.org (Postfix, from userid 500) id 724A76006D; Tue, 6 Sep 2011 18:59:00 +0200 (CEST) From: Markus Armbruster To: qemu-devel@nongnu.org Date: Tue, 6 Sep 2011 18:58:35 +0200 Message-Id: <1315328340-6192-3-git-send-email-armbru@redhat.com> X-Mailer: git-send-email 1.7.6 In-Reply-To: <1315328340-6192-1-git-send-email-armbru@redhat.com> References: <1315328340-6192-1-git-send-email-armbru@redhat.com> X-detected-operating-system: by eggs.gnu.org: Genre and OS details not recognized. X-Received-From: 78.46.104.156 Cc: kwolf@redhat.com, stefano.stabellini@eu.citrix.com, lcapitulino@redhat.com, hare@suse.de, amit.shah@redhat.com, pbonzini@redhat.com, hch@lst.de Subject: [Qemu-devel] [PATCH v3 02/27] ide: Use a table to declare which drive kinds accept each 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 No functional change. It would be nice to have handler functions in the table, like commit e1a064f9 did for ATAPI. Left for another day. Signed-off-by: Markus Armbruster --- hw/ide/core.c | 105 +++++++++++++++++++++++++++++++++++++++++++------------- 1 files changed, 80 insertions(+), 25 deletions(-) diff --git a/hw/ide/core.c b/hw/ide/core.c index def0126..65ce289 100644 --- a/hw/ide/core.c +++ b/hw/ide/core.c @@ -901,6 +901,78 @@ void ide_ioport_write(void *opaque, uint32_t addr, uint32_t val) } } +#define HD_OK (1u << IDE_HD) +#define CD_OK (1u << IDE_CD) +#define CFA_OK (1u << IDE_CFATA) +#define HD_CFA_OK (HD_OK | CFA_OK) +#define ALL_OK (HD_OK | CD_OK | CFA_OK) + +/* See ACS-2 T13/2015-D Table B.2 Command codes */ +static const uint8_t ide_cmd_table[0x100] = { + /* NOP not implemented, mandatory for CD */ + [CFA_REQ_EXT_ERROR_CODE] = CFA_OK, + [WIN_DSM] = ALL_OK, + [WIN_DEVICE_RESET] = CD_OK, + [WIN_RECAL] = ALL_OK, + [WIN_READ] = ALL_OK, + [WIN_READ_ONCE] = ALL_OK, + [WIN_READ_EXT] = ALL_OK, + [WIN_READDMA_EXT] = ALL_OK, + [WIN_READ_NATIVE_MAX_EXT] = ALL_OK, + [WIN_MULTREAD_EXT] = ALL_OK, + [WIN_WRITE] = ALL_OK, + [WIN_WRITE_ONCE] = ALL_OK, + [WIN_WRITE_EXT] = ALL_OK, + [WIN_WRITEDMA_EXT] = ALL_OK, + [CFA_WRITE_SECT_WO_ERASE] = ALL_OK, + [WIN_MULTWRITE_EXT] = ALL_OK, + [WIN_WRITE_VERIFY] = ALL_OK, + [WIN_VERIFY] = ALL_OK, + [WIN_VERIFY_ONCE] = ALL_OK, + [WIN_VERIFY_EXT] = ALL_OK, + [WIN_SEEK] = HD_CFA_OK, + [CFA_TRANSLATE_SECTOR] = CFA_OK, + [WIN_DIAGNOSE] = ALL_OK, + [WIN_SPECIFY] = ALL_OK, + [WIN_STANDBYNOW2] = ALL_OK, + [WIN_IDLEIMMEDIATE2] = ALL_OK, + [WIN_STANDBY2] = ALL_OK, + [WIN_SETIDLE2] = ALL_OK, + [WIN_CHECKPOWERMODE2] = ALL_OK, + [WIN_SLEEPNOW2] = ALL_OK, + [WIN_PACKETCMD] = CD_OK, + [WIN_PIDENTIFY] = CD_OK, + [WIN_SMART] = HD_CFA_OK, + [CFA_ACCESS_METADATA_STORAGE] = CFA_OK, + [CFA_ERASE_SECTORS] = CFA_OK, + [WIN_MULTREAD] = ALL_OK, + [WIN_MULTWRITE] = ALL_OK, + [WIN_SETMULT] = ALL_OK, + [WIN_READDMA] = ALL_OK, + [WIN_READDMA_ONCE] = ALL_OK, + [WIN_WRITEDMA] = ALL_OK, + [WIN_WRITEDMA_ONCE] = ALL_OK, + [CFA_WRITE_MULTI_WO_ERASE] = ALL_OK, + [WIN_STANDBYNOW1] = ALL_OK, + [WIN_IDLEIMMEDIATE] = ALL_OK, + [WIN_STANDBY] = ALL_OK, + [WIN_SETIDLE1] = ALL_OK, + [WIN_CHECKPOWERMODE1] = ALL_OK, + [WIN_SLEEPNOW1] = ALL_OK, + [WIN_FLUSH_CACHE] = ALL_OK, + [WIN_FLUSH_CACHE_EXT] = ALL_OK, + [WIN_IDENTIFY] = ALL_OK, + [WIN_SETFEATURES] = ALL_OK, + [IBM_SENSE_CONDITION] = CFA_OK, + [CFA_WEAR_LEVEL] = CFA_OK, + [WIN_READ_NATIVE_MAX] = ALL_OK, +}; + +static bool ide_cmd_permitted(IDEState *s, uint32_t cmd) +{ + return cmd <= ARRAY_SIZE(ide_cmd_table) + && (ide_cmd_table[cmd] & (1u << s->drive_kind)); +} void ide_exec_cmd(IDEBus *bus, uint32_t val) { @@ -920,6 +992,10 @@ void ide_exec_cmd(IDEBus *bus, uint32_t val) if ((s->status & (BUSY_STAT|DRQ_STAT)) && val != WIN_DEVICE_RESET) return; + if (!ide_cmd_permitted(s, val)) { + goto abort_cmd; + } + switch(val) { case WIN_DSM: switch (s->feature) { @@ -1140,21 +1216,15 @@ void ide_exec_cmd(IDEBus *bus, uint32_t val) ide_set_irq(s->bus); break; case WIN_SEEK: - if(s->drive_kind == IDE_CD) - goto abort_cmd; /* XXX: Check that seek is within bounds */ s->status = READY_STAT | SEEK_STAT; ide_set_irq(s->bus); break; /* ATAPI commands */ case WIN_PIDENTIFY: - if (s->drive_kind == IDE_CD) { - ide_atapi_identify(s); - s->status = READY_STAT | SEEK_STAT; - ide_transfer_start(s, s->io_buffer, 512, ide_transfer_stop); - } else { - ide_abort_command(s); - } + ide_atapi_identify(s); + s->status = READY_STAT | SEEK_STAT; + ide_transfer_start(s, s->io_buffer, 512, ide_transfer_stop); ide_set_irq(s->bus); break; case WIN_DIAGNOSE: @@ -1171,15 +1241,11 @@ void ide_exec_cmd(IDEBus *bus, uint32_t val) ide_set_irq(s->bus); break; case WIN_DEVICE_RESET: - if (s->drive_kind != IDE_CD) - goto abort_cmd; ide_set_signature(s); s->status = 0x00; /* NOTE: READY is _not_ set */ s->error = 0x01; break; case WIN_PACKETCMD: - if (s->drive_kind != IDE_CD) - goto abort_cmd; /* overlapping commands not supported */ if (s->feature & 0x02) goto abort_cmd; @@ -1191,16 +1257,12 @@ void ide_exec_cmd(IDEBus *bus, uint32_t val) break; /* CF-ATA commands */ case CFA_REQ_EXT_ERROR_CODE: - if (s->drive_kind != IDE_CFATA) - goto abort_cmd; s->error = 0x09; /* miscellaneous error */ s->status = READY_STAT | SEEK_STAT; ide_set_irq(s->bus); break; case CFA_ERASE_SECTORS: case CFA_WEAR_LEVEL: - if (s->drive_kind != IDE_CFATA) - goto abort_cmd; if (val == CFA_WEAR_LEVEL) s->nsector = 0; if (val == CFA_ERASE_SECTORS) @@ -1210,8 +1272,6 @@ void ide_exec_cmd(IDEBus *bus, uint32_t val) ide_set_irq(s->bus); break; case CFA_TRANSLATE_SECTOR: - if (s->drive_kind != IDE_CFATA) - goto abort_cmd; s->error = 0x00; s->status = READY_STAT | SEEK_STAT; memset(s->io_buffer, 0, 0x200); @@ -1230,8 +1290,6 @@ void ide_exec_cmd(IDEBus *bus, uint32_t val) ide_set_irq(s->bus); break; case CFA_ACCESS_METADATA_STORAGE: - if (s->drive_kind != IDE_CFATA) - goto abort_cmd; switch (s->feature) { case 0x02: /* Inquiry Metadata Storage */ ide_cfata_metadata_inquiry(s); @@ -1250,8 +1308,6 @@ void ide_exec_cmd(IDEBus *bus, uint32_t val) ide_set_irq(s->bus); break; case IBM_SENSE_CONDITION: - if (s->drive_kind != IDE_CFATA) - goto abort_cmd; switch (s->feature) { case 0x01: /* sense temperature in device */ s->nsector = 0x50; /* +20 C */ @@ -1264,8 +1320,6 @@ void ide_exec_cmd(IDEBus *bus, uint32_t val) break; case WIN_SMART: - if (s->drive_kind == IDE_CD) - goto abort_cmd; if (s->hcyl != 0xc2 || s->lcyl != 0x4f) goto abort_cmd; if (!s->smart_enabled && s->feature != SMART_ENABLE) @@ -1420,6 +1474,7 @@ void ide_exec_cmd(IDEBus *bus, uint32_t val) } break; default: + /* should not be reachable */ abort_cmd: ide_abort_command(s); ide_set_irq(s->bus);