qemu-devel.nongnu.org archive mirror
 help / color / mirror / Atom feed
From: Kevin Wolf <kwolf@redhat.com>
To: anthony@codemonkey.ws
Cc: kwolf@redhat.com, qemu-devel@nongnu.org
Subject: [Qemu-devel] [PATCH 03/35] ide: Use a table to declare which drive kinds accept each command
Date: Mon, 12 Sep 2011 16:19:02 +0200	[thread overview]
Message-ID: <1315837174-15327-4-git-send-email-kwolf@redhat.com> (raw)
In-Reply-To: <1315837174-15327-1-git-send-email-kwolf@redhat.com>

From: Markus Armbruster <armbru@redhat.com>

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 <armbru@redhat.com>
Signed-off-by: Kevin Wolf <kwolf@redhat.com>
---
 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..4a45b3e 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);
-- 
1.7.6

  parent reply	other threads:[~2011-09-12 14:16 UTC|newest]

Thread overview: 37+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2011-09-12 14:18 [Qemu-devel] [PULL 00/35] Block patches Kevin Wolf
2011-09-12 14:19 ` [Qemu-devel] [PATCH 01/35] qcow2: removed unused depends_on field Kevin Wolf
2011-09-12 14:19 ` [Qemu-devel] [PATCH 02/35] ide: Fix ATA command READ to set ATAPI signature for CD-ROM Kevin Wolf
2011-09-12 14:19 ` Kevin Wolf [this message]
2011-09-12 14:19 ` [Qemu-devel] [PATCH 04/35] ide: Reject ATA commands specific to drive kinds Kevin Wolf
2011-09-12 14:19 ` [Qemu-devel] [PATCH 05/35] ide/atapi: Clean up misleading name in cmd_start_stop_unit() Kevin Wolf
2011-09-12 14:19 ` [Qemu-devel] [PATCH 06/35] ide/atapi: Track tray open/close state Kevin Wolf
2011-09-12 14:19 ` [Qemu-devel] [PATCH 07/35] scsi-disk: Factor out scsi_disk_emulate_start_stop() Kevin Wolf
2011-09-12 14:19 ` [Qemu-devel] [PATCH 08/35] scsi-disk: Track tray open/close state Kevin Wolf
2011-09-12 14:19 ` [Qemu-devel] [PATCH 09/35] block: Revert entanglement of bdrv_is_inserted() with tray status Kevin Wolf
2011-09-12 14:19 ` [Qemu-devel] [PATCH 10/35] block: Drop tray status tracking, no longer used Kevin Wolf
2011-09-12 14:19 ` [Qemu-devel] [PATCH 11/35] ide/atapi: Track tray locked state Kevin Wolf
2011-09-12 14:19 ` [Qemu-devel] [PATCH 12/35] scsi-disk: " Kevin Wolf
2011-09-12 14:19 ` [Qemu-devel] [PATCH 13/35] block: Leave enforcing tray lock to device models Kevin Wolf
2011-09-12 14:19 ` [Qemu-devel] [PATCH 14/35] block: Drop medium lock tracking, ask device models instead Kevin Wolf
2011-09-12 14:19 ` [Qemu-devel] [PATCH 15/35] block: Rename bdrv_set_locked() to bdrv_lock_medium() Kevin Wolf
2011-09-12 14:19 ` [Qemu-devel] [PATCH 16/35] rbd: allow client id to be specified in config string Kevin Wolf
2011-09-12 14:19 ` [Qemu-devel] [PATCH 17/35] rbd: clean up, fix style Kevin Wolf
2011-09-12 14:19 ` [Qemu-devel] [PATCH 18/35] rbd: fix leak in qemu_rbd_open failure paths Kevin Wolf
2011-09-12 14:19 ` [Qemu-devel] [PATCH 19/35] ide/atapi: Don't fail eject when tray is already open Kevin Wolf
2011-09-12 14:19 ` [Qemu-devel] [PATCH 20/35] scsi-disk: Fix START_STOP to fail when it can't eject Kevin Wolf
2011-09-12 14:19 ` [Qemu-devel] [PATCH 21/35] ide/atapi: Preserve tray state on migration Kevin Wolf
2011-09-12 14:19 ` [Qemu-devel] [PATCH 22/35] block: Clean up remaining users of "removable" Kevin Wolf
2011-09-12 14:19 ` [Qemu-devel] [PATCH 23/35] block: Drop BlockDriverState member removable Kevin Wolf
2011-09-12 14:19 ` [Qemu-devel] [PATCH 24/35] block: Show whether the virtual tray is open in info block Kevin Wolf
2011-09-12 14:19 ` [Qemu-devel] [PATCH 25/35] block: Move BlockConf & friends from block_int.h to block.h Kevin Wolf
2011-09-12 14:19 ` [Qemu-devel] [PATCH 26/35] hw: Trim superfluous #include "block_int.h" Kevin Wolf
2011-09-12 14:19 ` [Qemu-devel] [PATCH 27/35] block: New bdrv_set_buffer_alignment() Kevin Wolf
2011-09-12 14:19 ` [Qemu-devel] [PATCH 28/35] block: Reset buffer alignment on detach Kevin Wolf
2011-09-12 14:19 ` [Qemu-devel] [PATCH 29/35] nbd: Clean up use of block_int.h Kevin Wolf
2011-09-12 14:19 ` [Qemu-devel] [PATCH 30/35] block: New change_media_cb() parameter load Kevin Wolf
2011-09-12 14:19 ` [Qemu-devel] [PATCH 31/35] ide/atapi scsi-disk: Make monitor eject -f, then change work Kevin Wolf
2011-09-12 14:19 ` [Qemu-devel] [PATCH 32/35] qcow2: initialize metadata before inserting in cluster_allocs Kevin Wolf
2011-09-12 14:19 ` [Qemu-devel] [PATCH 33/35] ahci: Remove unused struct member Kevin Wolf
2011-09-12 14:19 ` [Qemu-devel] [PATCH 34/35] qcow2: align cluster_data to block to improve performance using O_DIRECT Kevin Wolf
2011-09-12 14:19 ` [Qemu-devel] [PATCH 35/35] qcow2: fix range check Kevin Wolf
2011-09-15 19:09 ` [Qemu-devel] [PULL 00/35] Block patches Anthony Liguori

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=1315837174-15327-4-git-send-email-kwolf@redhat.com \
    --to=kwolf@redhat.com \
    --cc=anthony@codemonkey.ws \
    --cc=qemu-devel@nongnu.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).