* [Qemu-devel] [PATCH 00/17] ide: Use ide_cmd_table function pointers for command execution
@ 2013-06-18 8:25 Kevin Wolf
2013-06-18 8:25 ` [Qemu-devel] [PATCH 01/17] ide: Add handler to ide_cmd_table Kevin Wolf
` (17 more replies)
0 siblings, 18 replies; 20+ messages in thread
From: Kevin Wolf @ 2013-06-18 8:25 UTC (permalink / raw)
To: qemu-devel; +Cc: kwolf, stefanha
The ATAPI code has been using a table of callback functions for each
command for quite a while now, this series does the same for ATA
commands (which already got the table, but no function pointers, just
flags)
The main advantage is that we get a more consistent behaviour of the
commands because we get a clear separation between things that are common
between all (or most) commands, like setting status register bits or triggering
IRQs, and can be handled in one central place, and command specific code
that is refactored into its own function. In the past we've had bugs
from forgetting to do one of the common things, like setting the BSY
flag, which will be avoided with the new infrastructure.
It's also a good opportunity to clean up some of the coding style
problems of the IDE code.
Kevin Wolf (17):
ide: Add handler to ide_cmd_table
ide: Convert WIN_DSM to ide_cmd_table handler
ide: Convert WIN_IDENTIFY to ide_cmd_table handler
ide: Convert cmd_nop commands to ide_cmd_table handler
ide: Convert verify commands to ide_cmd_table handler
ide: Convert read/write multiple commands to ide_cmd_table handler
ide: Convert PIO read/write commands to ide_cmd_table handler
ide: Convert DMA read/write commands to ide_cmd_table handler
ide: Convert READ NATIVE MAX ADDRESS to ide_cmd_table handler
ide: Convert CHECK POWER MDOE to ide_cmd_table handler
ide: Convert SET FEATURES to ide_cmd_table handler
ide: Convert FLUSH CACHE to ide_cmd_table handler
ide: Convert SEEK to ide_cmd_table handler
ide: Convert ATAPI commands to ide_cmd_table handler
ide: Convert CF-ATA commands to ide_cmd_table handler
ide: Convert SMART commands to ide_cmd_table handler
ide: Clean up ide_exec_cmd()
hw/ide/core.c | 1242 +++++++++++++++++++++++++++++++--------------------------
1 file changed, 669 insertions(+), 573 deletions(-)
--
1.8.1.4
^ permalink raw reply [flat|nested] 20+ messages in thread
* [Qemu-devel] [PATCH 01/17] ide: Add handler to ide_cmd_table
2013-06-18 8:25 [Qemu-devel] [PATCH 00/17] ide: Use ide_cmd_table function pointers for command execution Kevin Wolf
@ 2013-06-18 8:25 ` Kevin Wolf
2013-06-19 11:45 ` Stefan Hajnoczi
2013-06-18 8:25 ` [Qemu-devel] [PATCH 02/17] ide: Convert WIN_DSM to ide_cmd_table handler Kevin Wolf
` (16 subsequent siblings)
17 siblings, 1 reply; 20+ messages in thread
From: Kevin Wolf @ 2013-06-18 8:25 UTC (permalink / raw)
To: qemu-devel; +Cc: kwolf, stefanha
As a preparation for moving all IDE commands into their own function
like in the ATAPI code, introduce a 'handler' callback to ide_cmd_table.
Commands using this new infrastructure get some things handled
automatically:
* The BSY flag is set before calling the handler (in order to avoid bugs
like the one fixed in f68ec837) and reset on completion.
* The (obsolete) DSC flag in the status register is set on completion if
the command is flagged with SET_DSC in the command table
* An IRQ is triggered on completion.
* The error register and the ERR flag in the status register are cleared
before calling the handler and on completion it is asserted that
either none or both of them are set.
No commands are converted at this point.
Signed-off-by: Kevin Wolf <kwolf@redhat.com>
---
hw/ide/core.c | 144 +++++++++++++++++++++++++++++++++++-----------------------
1 file changed, 86 insertions(+), 58 deletions(-)
diff --git a/hw/ide/core.c b/hw/ide/core.c
index 9926d92..cd9de14 100644
--- a/hw/ide/core.c
+++ b/hw/ide/core.c
@@ -1010,71 +1010,78 @@ void ide_ioport_write(void *opaque, uint32_t addr, uint32_t val)
#define HD_CFA_OK (HD_OK | CFA_OK)
#define ALL_OK (HD_OK | CD_OK | CFA_OK)
+/* Set the Disk Seek Completed status bit during completion */
+#define SET_DSC (1u << 8)
+
/* See ACS-2 T13/2015-D Table B.2 Command codes */
-static const uint8_t ide_cmd_table[0x100] = {
+static const struct {
+ /* Returns true if the completion code should be run */
+ bool (*handler)(IDEState *s, uint8_t cmd);
+ int flags;
+} 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] = HD_CFA_OK,
- [WIN_READ] = ALL_OK,
- [WIN_READ_ONCE] = ALL_OK,
- [WIN_READ_EXT] = HD_CFA_OK,
- [WIN_READDMA_EXT] = HD_CFA_OK,
- [WIN_READ_NATIVE_MAX_EXT] = HD_CFA_OK,
- [WIN_MULTREAD_EXT] = HD_CFA_OK,
- [WIN_WRITE] = HD_CFA_OK,
- [WIN_WRITE_ONCE] = HD_CFA_OK,
- [WIN_WRITE_EXT] = HD_CFA_OK,
- [WIN_WRITEDMA_EXT] = HD_CFA_OK,
- [CFA_WRITE_SECT_WO_ERASE] = CFA_OK,
- [WIN_MULTWRITE_EXT] = HD_CFA_OK,
- [WIN_WRITE_VERIFY] = HD_CFA_OK,
- [WIN_VERIFY] = HD_CFA_OK,
- [WIN_VERIFY_ONCE] = HD_CFA_OK,
- [WIN_VERIFY_EXT] = HD_CFA_OK,
- [WIN_SEEK] = HD_CFA_OK,
- [CFA_TRANSLATE_SECTOR] = CFA_OK,
- [WIN_DIAGNOSE] = ALL_OK,
- [WIN_SPECIFY] = HD_CFA_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] = HD_CFA_OK,
- [WIN_MULTWRITE] = HD_CFA_OK,
- [WIN_SETMULT] = HD_CFA_OK,
- [WIN_READDMA] = HD_CFA_OK,
- [WIN_READDMA_ONCE] = HD_CFA_OK,
- [WIN_WRITEDMA] = HD_CFA_OK,
- [WIN_WRITEDMA_ONCE] = HD_CFA_OK,
- [CFA_WRITE_MULTI_WO_ERASE] = CFA_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] = HD_CFA_OK,
- [WIN_IDENTIFY] = ALL_OK,
- [WIN_SETFEATURES] = ALL_OK,
- [IBM_SENSE_CONDITION] = CFA_OK,
- [CFA_WEAR_LEVEL] = HD_CFA_OK,
- [WIN_READ_NATIVE_MAX] = ALL_OK,
+ [CFA_REQ_EXT_ERROR_CODE] = { NULL, CFA_OK },
+ [WIN_DSM] = { NULL, ALL_OK },
+ [WIN_DEVICE_RESET] = { NULL, CD_OK },
+ [WIN_RECAL] = { NULL, HD_CFA_OK },
+ [WIN_READ] = { NULL, ALL_OK },
+ [WIN_READ_ONCE] = { NULL, ALL_OK },
+ [WIN_READ_EXT] = { NULL, HD_CFA_OK },
+ [WIN_READDMA_EXT] = { NULL, HD_CFA_OK },
+ [WIN_READ_NATIVE_MAX_EXT] = { NULL, HD_CFA_OK },
+ [WIN_MULTREAD_EXT] = { NULL, HD_CFA_OK },
+ [WIN_WRITE] = { NULL, HD_CFA_OK },
+ [WIN_WRITE_ONCE] = { NULL, HD_CFA_OK },
+ [WIN_WRITE_EXT] = { NULL, HD_CFA_OK },
+ [WIN_WRITEDMA_EXT] = { NULL, HD_CFA_OK },
+ [CFA_WRITE_SECT_WO_ERASE] = { NULL, CFA_OK },
+ [WIN_MULTWRITE_EXT] = { NULL, HD_CFA_OK },
+ [WIN_WRITE_VERIFY] = { NULL, HD_CFA_OK },
+ [WIN_VERIFY] = { NULL, HD_CFA_OK },
+ [WIN_VERIFY_ONCE] = { NULL, HD_CFA_OK },
+ [WIN_VERIFY_EXT] = { NULL, HD_CFA_OK },
+ [WIN_SEEK] = { NULL, HD_CFA_OK },
+ [CFA_TRANSLATE_SECTOR] = { NULL, CFA_OK },
+ [WIN_DIAGNOSE] = { NULL, ALL_OK },
+ [WIN_SPECIFY] = { NULL, HD_CFA_OK },
+ [WIN_STANDBYNOW2] = { NULL, ALL_OK },
+ [WIN_IDLEIMMEDIATE2] = { NULL, ALL_OK },
+ [WIN_STANDBY2] = { NULL, ALL_OK },
+ [WIN_SETIDLE2] = { NULL, ALL_OK },
+ [WIN_CHECKPOWERMODE2] = { NULL, ALL_OK },
+ [WIN_SLEEPNOW2] = { NULL, ALL_OK },
+ [WIN_PACKETCMD] = { NULL, CD_OK },
+ [WIN_PIDENTIFY] = { NULL, CD_OK },
+ [WIN_SMART] = { NULL, HD_CFA_OK },
+ [CFA_ACCESS_METADATA_STORAGE] = { NULL, CFA_OK },
+ [CFA_ERASE_SECTORS] = { NULL, CFA_OK },
+ [WIN_MULTREAD] = { NULL, HD_CFA_OK },
+ [WIN_MULTWRITE] = { NULL, HD_CFA_OK },
+ [WIN_SETMULT] = { NULL, HD_CFA_OK },
+ [WIN_READDMA] = { NULL, HD_CFA_OK },
+ [WIN_READDMA_ONCE] = { NULL, HD_CFA_OK },
+ [WIN_WRITEDMA] = { NULL, HD_CFA_OK },
+ [WIN_WRITEDMA_ONCE] = { NULL, HD_CFA_OK },
+ [CFA_WRITE_MULTI_WO_ERASE] = { NULL, CFA_OK },
+ [WIN_STANDBYNOW1] = { NULL, ALL_OK },
+ [WIN_IDLEIMMEDIATE] = { NULL, ALL_OK },
+ [WIN_STANDBY] = { NULL, ALL_OK },
+ [WIN_SETIDLE1] = { NULL, ALL_OK },
+ [WIN_CHECKPOWERMODE1] = { NULL, ALL_OK },
+ [WIN_SLEEPNOW1] = { NULL, ALL_OK },
+ [WIN_FLUSH_CACHE] = { NULL, ALL_OK },
+ [WIN_FLUSH_CACHE_EXT] = { NULL, HD_CFA_OK },
+ [WIN_IDENTIFY] = { NULL, ALL_OK },
+ [WIN_SETFEATURES] = { NULL, ALL_OK },
+ [IBM_SENSE_CONDITION] = { NULL, CFA_OK },
+ [CFA_WEAR_LEVEL] = { NULL, HD_CFA_OK },
+ [WIN_READ_NATIVE_MAX] = { NULL, 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));
+ && (ide_cmd_table[cmd].flags & (1u << s->drive_kind));
}
void ide_exec_cmd(IDEBus *bus, uint32_t val)
@@ -1100,6 +1107,27 @@ void ide_exec_cmd(IDEBus *bus, uint32_t val)
goto abort_cmd;
}
+ if (ide_cmd_table[val].handler != NULL) {
+ bool complete;
+
+ s->status = READY_STAT | BUSY_STAT;
+ s->error = 0;
+
+ complete = ide_cmd_table[val].handler(s, val);
+ if (complete) {
+ s->status &= ~BUSY_STAT;
+ assert(!!s->error == !!(s->status & ERR_STAT));
+
+ if ((ide_cmd_table[val].flags & SET_DSC) && !s->error) {
+ s->status |= SEEK_STAT;
+ }
+
+ ide_set_irq(s->bus);
+ }
+
+ return;
+ }
+
switch(val) {
case WIN_DSM:
switch (s->feature) {
--
1.8.1.4
^ permalink raw reply related [flat|nested] 20+ messages in thread
* [Qemu-devel] [PATCH 02/17] ide: Convert WIN_DSM to ide_cmd_table handler
2013-06-18 8:25 [Qemu-devel] [PATCH 00/17] ide: Use ide_cmd_table function pointers for command execution Kevin Wolf
2013-06-18 8:25 ` [Qemu-devel] [PATCH 01/17] ide: Add handler to ide_cmd_table Kevin Wolf
@ 2013-06-18 8:25 ` Kevin Wolf
2013-06-18 8:25 ` [Qemu-devel] [PATCH 03/17] ide: Convert WIN_IDENTIFY " Kevin Wolf
` (15 subsequent siblings)
17 siblings, 0 replies; 20+ messages in thread
From: Kevin Wolf @ 2013-06-18 8:25 UTC (permalink / raw)
To: qemu-devel; +Cc: kwolf, stefanha
Signed-off-by: Kevin Wolf <kwolf@redhat.com>
---
hw/ide/core.c | 29 ++++++++++++++++-------------
1 file changed, 16 insertions(+), 13 deletions(-)
diff --git a/hw/ide/core.c b/hw/ide/core.c
index cd9de14..567515e 100644
--- a/hw/ide/core.c
+++ b/hw/ide/core.c
@@ -1004,6 +1004,21 @@ void ide_ioport_write(void *opaque, uint32_t addr, uint32_t val)
}
}
+static bool cmd_data_set_management(IDEState *s, uint8_t cmd)
+{
+ switch (s->feature) {
+ case DSM_TRIM:
+ if (s->bs) {
+ ide_sector_start_dma(s, IDE_DMA_TRIM);
+ return false;
+ }
+ break;
+ }
+
+ ide_abort_command(s);
+ return true;
+}
+
#define HD_OK (1u << IDE_HD)
#define CD_OK (1u << IDE_CD)
#define CFA_OK (1u << IDE_CFATA)
@@ -1021,7 +1036,7 @@ static const struct {
} ide_cmd_table[0x100] = {
/* NOP not implemented, mandatory for CD */
[CFA_REQ_EXT_ERROR_CODE] = { NULL, CFA_OK },
- [WIN_DSM] = { NULL, ALL_OK },
+ [WIN_DSM] = { cmd_data_set_management, ALL_OK },
[WIN_DEVICE_RESET] = { NULL, CD_OK },
[WIN_RECAL] = { NULL, HD_CFA_OK },
[WIN_READ] = { NULL, ALL_OK },
@@ -1129,18 +1144,6 @@ void ide_exec_cmd(IDEBus *bus, uint32_t val)
}
switch(val) {
- case WIN_DSM:
- switch (s->feature) {
- case DSM_TRIM:
- if (!s->bs) {
- goto abort_cmd;
- }
- ide_sector_start_dma(s, IDE_DMA_TRIM);
- break;
- default:
- goto abort_cmd;
- }
- break;
case WIN_IDENTIFY:
if (s->bs && s->drive_kind != IDE_CD) {
if (s->drive_kind != IDE_CFATA)
--
1.8.1.4
^ permalink raw reply related [flat|nested] 20+ messages in thread
* [Qemu-devel] [PATCH 03/17] ide: Convert WIN_IDENTIFY to ide_cmd_table handler
2013-06-18 8:25 [Qemu-devel] [PATCH 00/17] ide: Use ide_cmd_table function pointers for command execution Kevin Wolf
2013-06-18 8:25 ` [Qemu-devel] [PATCH 01/17] ide: Add handler to ide_cmd_table Kevin Wolf
2013-06-18 8:25 ` [Qemu-devel] [PATCH 02/17] ide: Convert WIN_DSM to ide_cmd_table handler Kevin Wolf
@ 2013-06-18 8:25 ` Kevin Wolf
2013-06-18 8:25 ` [Qemu-devel] [PATCH 04/17] ide: Convert cmd_nop commands " Kevin Wolf
` (14 subsequent siblings)
17 siblings, 0 replies; 20+ messages in thread
From: Kevin Wolf @ 2013-06-18 8:25 UTC (permalink / raw)
To: qemu-devel; +Cc: kwolf, stefanha
Signed-off-by: Kevin Wolf <kwolf@redhat.com>
---
hw/ide/core.c | 40 +++++++++++++++++++++++-----------------
1 file changed, 23 insertions(+), 17 deletions(-)
diff --git a/hw/ide/core.c b/hw/ide/core.c
index 567515e..2df078b 100644
--- a/hw/ide/core.c
+++ b/hw/ide/core.c
@@ -1019,6 +1019,28 @@ static bool cmd_data_set_management(IDEState *s, uint8_t cmd)
return true;
}
+static bool cmd_identify(IDEState *s, uint8_t cmd)
+{
+ if (s->bs && s->drive_kind != IDE_CD) {
+ if (s->drive_kind != IDE_CFATA) {
+ ide_identify(s);
+ } else {
+ ide_cfata_identify(s);
+ }
+ s->status = READY_STAT | SEEK_STAT;
+ ide_transfer_start(s, s->io_buffer, 512, ide_transfer_stop);
+ ide_set_irq(s->bus);
+ return false;
+ } else {
+ if (s->drive_kind == IDE_CD) {
+ ide_set_signature(s);
+ }
+ ide_abort_command(s);
+ }
+
+ return true;
+}
+
#define HD_OK (1u << IDE_HD)
#define CD_OK (1u << IDE_CD)
#define CFA_OK (1u << IDE_CFATA)
@@ -1086,7 +1108,7 @@ static const struct {
[WIN_SLEEPNOW1] = { NULL, ALL_OK },
[WIN_FLUSH_CACHE] = { NULL, ALL_OK },
[WIN_FLUSH_CACHE_EXT] = { NULL, HD_CFA_OK },
- [WIN_IDENTIFY] = { NULL, ALL_OK },
+ [WIN_IDENTIFY] = { cmd_identify, ALL_OK },
[WIN_SETFEATURES] = { NULL, ALL_OK },
[IBM_SENSE_CONDITION] = { NULL, CFA_OK },
[CFA_WEAR_LEVEL] = { NULL, HD_CFA_OK },
@@ -1144,22 +1166,6 @@ void ide_exec_cmd(IDEBus *bus, uint32_t val)
}
switch(val) {
- case WIN_IDENTIFY:
- if (s->bs && s->drive_kind != IDE_CD) {
- if (s->drive_kind != IDE_CFATA)
- ide_identify(s);
- else
- ide_cfata_identify(s);
- s->status = READY_STAT | SEEK_STAT;
- ide_transfer_start(s, s->io_buffer, 512, ide_transfer_stop);
- } else {
- if (s->drive_kind == IDE_CD) {
- ide_set_signature(s);
- }
- ide_abort_command(s);
- }
- ide_set_irq(s->bus);
- break;
case WIN_SPECIFY:
case WIN_RECAL:
s->error = 0;
--
1.8.1.4
^ permalink raw reply related [flat|nested] 20+ messages in thread
* [Qemu-devel] [PATCH 04/17] ide: Convert cmd_nop commands to ide_cmd_table handler
2013-06-18 8:25 [Qemu-devel] [PATCH 00/17] ide: Use ide_cmd_table function pointers for command execution Kevin Wolf
` (2 preceding siblings ...)
2013-06-18 8:25 ` [Qemu-devel] [PATCH 03/17] ide: Convert WIN_IDENTIFY " Kevin Wolf
@ 2013-06-18 8:25 ` Kevin Wolf
2013-06-18 8:25 ` [Qemu-devel] [PATCH 05/17] ide: Convert verify " Kevin Wolf
` (13 subsequent siblings)
17 siblings, 0 replies; 20+ messages in thread
From: Kevin Wolf @ 2013-06-18 8:25 UTC (permalink / raw)
To: qemu-devel; +Cc: kwolf, stefanha
cmd_nop handles all commands that don't really do anything in our
implementation except setting status register flags.
Signed-off-by: Kevin Wolf <kwolf@redhat.com>
---
hw/ide/core.c | 48 +++++++++++++++++-------------------------------
1 file changed, 17 insertions(+), 31 deletions(-)
diff --git a/hw/ide/core.c b/hw/ide/core.c
index 2df078b..057662d 100644
--- a/hw/ide/core.c
+++ b/hw/ide/core.c
@@ -1004,6 +1004,11 @@ void ide_ioport_write(void *opaque, uint32_t addr, uint32_t val)
}
}
+static bool cmd_nop(IDEState *s, uint8_t cmd)
+{
+ return true;
+}
+
static bool cmd_data_set_management(IDEState *s, uint8_t cmd)
{
switch (s->feature) {
@@ -1060,7 +1065,7 @@ static const struct {
[CFA_REQ_EXT_ERROR_CODE] = { NULL, CFA_OK },
[WIN_DSM] = { cmd_data_set_management, ALL_OK },
[WIN_DEVICE_RESET] = { NULL, CD_OK },
- [WIN_RECAL] = { NULL, HD_CFA_OK },
+ [WIN_RECAL] = { cmd_nop, HD_CFA_OK | SET_DSC},
[WIN_READ] = { NULL, ALL_OK },
[WIN_READ_ONCE] = { NULL, ALL_OK },
[WIN_READ_EXT] = { NULL, HD_CFA_OK },
@@ -1080,13 +1085,13 @@ static const struct {
[WIN_SEEK] = { NULL, HD_CFA_OK },
[CFA_TRANSLATE_SECTOR] = { NULL, CFA_OK },
[WIN_DIAGNOSE] = { NULL, ALL_OK },
- [WIN_SPECIFY] = { NULL, HD_CFA_OK },
- [WIN_STANDBYNOW2] = { NULL, ALL_OK },
- [WIN_IDLEIMMEDIATE2] = { NULL, ALL_OK },
- [WIN_STANDBY2] = { NULL, ALL_OK },
- [WIN_SETIDLE2] = { NULL, ALL_OK },
+ [WIN_SPECIFY] = { cmd_nop, HD_CFA_OK | SET_DSC },
+ [WIN_STANDBYNOW2] = { cmd_nop, ALL_OK },
+ [WIN_IDLEIMMEDIATE2] = { cmd_nop, ALL_OK },
+ [WIN_STANDBY2] = { cmd_nop, ALL_OK },
+ [WIN_SETIDLE2] = { cmd_nop, ALL_OK },
[WIN_CHECKPOWERMODE2] = { NULL, ALL_OK },
- [WIN_SLEEPNOW2] = { NULL, ALL_OK },
+ [WIN_SLEEPNOW2] = { cmd_nop, ALL_OK },
[WIN_PACKETCMD] = { NULL, CD_OK },
[WIN_PIDENTIFY] = { NULL, CD_OK },
[WIN_SMART] = { NULL, HD_CFA_OK },
@@ -1100,12 +1105,12 @@ static const struct {
[WIN_WRITEDMA] = { NULL, HD_CFA_OK },
[WIN_WRITEDMA_ONCE] = { NULL, HD_CFA_OK },
[CFA_WRITE_MULTI_WO_ERASE] = { NULL, CFA_OK },
- [WIN_STANDBYNOW1] = { NULL, ALL_OK },
- [WIN_IDLEIMMEDIATE] = { NULL, ALL_OK },
- [WIN_STANDBY] = { NULL, ALL_OK },
- [WIN_SETIDLE1] = { NULL, ALL_OK },
+ [WIN_STANDBYNOW1] = { cmd_nop, ALL_OK },
+ [WIN_IDLEIMMEDIATE] = { cmd_nop, ALL_OK },
+ [WIN_STANDBY] = { cmd_nop, ALL_OK },
+ [WIN_SETIDLE1] = { cmd_nop, ALL_OK },
[WIN_CHECKPOWERMODE1] = { NULL, ALL_OK },
- [WIN_SLEEPNOW1] = { NULL, ALL_OK },
+ [WIN_SLEEPNOW1] = { cmd_nop, ALL_OK },
[WIN_FLUSH_CACHE] = { NULL, ALL_OK },
[WIN_FLUSH_CACHE_EXT] = { NULL, HD_CFA_OK },
[WIN_IDENTIFY] = { cmd_identify, ALL_OK },
@@ -1166,12 +1171,6 @@ void ide_exec_cmd(IDEBus *bus, uint32_t val)
}
switch(val) {
- case WIN_SPECIFY:
- case WIN_RECAL:
- s->error = 0;
- s->status = READY_STAT | SEEK_STAT;
- ide_set_irq(s->bus);
- break;
case WIN_SETMULT:
if (s->drive_kind == IDE_CFATA && s->nsector == 0) {
/* Disable Read and Write Multiple */
@@ -1391,19 +1390,6 @@ void ide_exec_cmd(IDEBus *bus, uint32_t val)
case WIN_FLUSH_CACHE_EXT:
ide_flush_cache(s);
break;
- case WIN_STANDBY:
- case WIN_STANDBY2:
- case WIN_STANDBYNOW1:
- case WIN_STANDBYNOW2:
- case WIN_IDLEIMMEDIATE:
- case WIN_IDLEIMMEDIATE2:
- case WIN_SETIDLE1:
- case WIN_SETIDLE2:
- case WIN_SLEEPNOW1:
- case WIN_SLEEPNOW2:
- s->status = READY_STAT;
- ide_set_irq(s->bus);
- break;
case WIN_SEEK:
/* XXX: Check that seek is within bounds */
s->status = READY_STAT | SEEK_STAT;
--
1.8.1.4
^ permalink raw reply related [flat|nested] 20+ messages in thread
* [Qemu-devel] [PATCH 05/17] ide: Convert verify commands to ide_cmd_table handler
2013-06-18 8:25 [Qemu-devel] [PATCH 00/17] ide: Use ide_cmd_table function pointers for command execution Kevin Wolf
` (3 preceding siblings ...)
2013-06-18 8:25 ` [Qemu-devel] [PATCH 04/17] ide: Convert cmd_nop commands " Kevin Wolf
@ 2013-06-18 8:25 ` Kevin Wolf
2013-06-18 8:26 ` [Qemu-devel] [PATCH 06/17] ide: Convert read/write multiple " Kevin Wolf
` (12 subsequent siblings)
17 siblings, 0 replies; 20+ messages in thread
From: Kevin Wolf @ 2013-06-18 8:25 UTC (permalink / raw)
To: qemu-devel; +Cc: kwolf, stefanha
Signed-off-by: Kevin Wolf <kwolf@redhat.com>
---
hw/ide/core.c | 27 +++++++++++++--------------
1 file changed, 13 insertions(+), 14 deletions(-)
diff --git a/hw/ide/core.c b/hw/ide/core.c
index 057662d..bf2007a 100644
--- a/hw/ide/core.c
+++ b/hw/ide/core.c
@@ -1046,6 +1046,16 @@ static bool cmd_identify(IDEState *s, uint8_t cmd)
return true;
}
+static bool cmd_verify(IDEState *s, uint8_t cmd)
+{
+ bool lba48 = (cmd == WIN_VERIFY_EXT);
+
+ /* do sector number check ? */
+ ide_cmd_lba48_transform(s, lba48);
+
+ return true;
+}
+
#define HD_OK (1u << IDE_HD)
#define CD_OK (1u << IDE_CD)
#define CFA_OK (1u << IDE_CFATA)
@@ -1079,9 +1089,9 @@ static const struct {
[CFA_WRITE_SECT_WO_ERASE] = { NULL, CFA_OK },
[WIN_MULTWRITE_EXT] = { NULL, HD_CFA_OK },
[WIN_WRITE_VERIFY] = { NULL, HD_CFA_OK },
- [WIN_VERIFY] = { NULL, HD_CFA_OK },
- [WIN_VERIFY_ONCE] = { NULL, HD_CFA_OK },
- [WIN_VERIFY_EXT] = { NULL, HD_CFA_OK },
+ [WIN_VERIFY] = { cmd_verify, HD_CFA_OK | SET_DSC },
+ [WIN_VERIFY_ONCE] = { cmd_verify, HD_CFA_OK | SET_DSC },
+ [WIN_VERIFY_EXT] = { cmd_verify, HD_CFA_OK | SET_DSC },
[WIN_SEEK] = { NULL, HD_CFA_OK },
[CFA_TRANSLATE_SECTOR] = { NULL, CFA_OK },
[WIN_DIAGNOSE] = { NULL, ALL_OK },
@@ -1187,17 +1197,6 @@ void ide_exec_cmd(IDEBus *bus, uint32_t val)
ide_set_irq(s->bus);
break;
- case WIN_VERIFY_EXT:
- lba48 = 1;
- /* fall through */
- case WIN_VERIFY:
- case WIN_VERIFY_ONCE:
- /* do sector number check ? */
- ide_cmd_lba48_transform(s, lba48);
- s->status = READY_STAT | SEEK_STAT;
- ide_set_irq(s->bus);
- break;
-
case WIN_READ_EXT:
lba48 = 1;
/* fall through */
--
1.8.1.4
^ permalink raw reply related [flat|nested] 20+ messages in thread
* [Qemu-devel] [PATCH 06/17] ide: Convert read/write multiple commands to ide_cmd_table handler
2013-06-18 8:25 [Qemu-devel] [PATCH 00/17] ide: Use ide_cmd_table function pointers for command execution Kevin Wolf
` (4 preceding siblings ...)
2013-06-18 8:25 ` [Qemu-devel] [PATCH 05/17] ide: Convert verify " Kevin Wolf
@ 2013-06-18 8:26 ` Kevin Wolf
2013-06-18 8:26 ` [Qemu-devel] [PATCH 07/17] ide: Convert PIO read/write " Kevin Wolf
` (11 subsequent siblings)
17 siblings, 0 replies; 20+ messages in thread
From: Kevin Wolf @ 2013-06-18 8:26 UTC (permalink / raw)
To: qemu-devel; +Cc: kwolf, stefanha
Signed-off-by: Kevin Wolf <kwolf@redhat.com>
---
hw/ide/core.c | 119 +++++++++++++++++++++++++++++-----------------------------
1 file changed, 60 insertions(+), 59 deletions(-)
diff --git a/hw/ide/core.c b/hw/ide/core.c
index bf2007a..e6cd7b8 100644
--- a/hw/ide/core.c
+++ b/hw/ide/core.c
@@ -1056,6 +1056,60 @@ static bool cmd_verify(IDEState *s, uint8_t cmd)
return true;
}
+static bool cmd_set_multiple_mode(IDEState *s, uint8_t cmd)
+{
+ if (s->drive_kind == IDE_CFATA && s->nsector == 0) {
+ /* Disable Read and Write Multiple */
+ s->mult_sectors = 0;
+ } else if ((s->nsector & 0xff) != 0 &&
+ ((s->nsector & 0xff) > MAX_MULT_SECTORS ||
+ (s->nsector & (s->nsector - 1)) != 0)) {
+ ide_abort_command(s);
+ } else {
+ s->mult_sectors = s->nsector & 0xff;
+ }
+
+ return true;
+}
+
+static bool cmd_read_multiple(IDEState *s, uint8_t cmd)
+{
+ bool lba48 = (cmd == WIN_MULTREAD_EXT);
+
+ if (!s->bs || !s->mult_sectors) {
+ ide_abort_command(s);
+ return true;
+ }
+
+ ide_cmd_lba48_transform(s, lba48);
+ s->req_nb_sectors = s->mult_sectors;
+ ide_sector_read(s);
+ return false;
+}
+
+static bool cmd_write_multiple(IDEState *s, uint8_t cmd)
+{
+ bool lba48 = (cmd == WIN_MULTWRITE_EXT);
+ int n;
+
+ if (!s->bs || !s->mult_sectors) {
+ ide_abort_command(s);
+ return true;
+ }
+
+ ide_cmd_lba48_transform(s, lba48);
+
+ s->req_nb_sectors = s->mult_sectors;
+ n = MIN(s->nsector, s->req_nb_sectors);
+
+ s->status = SEEK_STAT | READY_STAT;
+ ide_transfer_start(s, s->io_buffer, 512 * n, ide_sector_write);
+
+ s->media_changed = 1;
+
+ return false;
+}
+
#define HD_OK (1u << IDE_HD)
#define CD_OK (1u << IDE_CD)
#define CFA_OK (1u << IDE_CFATA)
@@ -1081,13 +1135,13 @@ static const struct {
[WIN_READ_EXT] = { NULL, HD_CFA_OK },
[WIN_READDMA_EXT] = { NULL, HD_CFA_OK },
[WIN_READ_NATIVE_MAX_EXT] = { NULL, HD_CFA_OK },
- [WIN_MULTREAD_EXT] = { NULL, HD_CFA_OK },
+ [WIN_MULTREAD_EXT] = { cmd_read_multiple, HD_CFA_OK },
[WIN_WRITE] = { NULL, HD_CFA_OK },
[WIN_WRITE_ONCE] = { NULL, HD_CFA_OK },
[WIN_WRITE_EXT] = { NULL, HD_CFA_OK },
[WIN_WRITEDMA_EXT] = { NULL, HD_CFA_OK },
[CFA_WRITE_SECT_WO_ERASE] = { NULL, CFA_OK },
- [WIN_MULTWRITE_EXT] = { NULL, HD_CFA_OK },
+ [WIN_MULTWRITE_EXT] = { cmd_write_multiple, HD_CFA_OK },
[WIN_WRITE_VERIFY] = { NULL, HD_CFA_OK },
[WIN_VERIFY] = { cmd_verify, HD_CFA_OK | SET_DSC },
[WIN_VERIFY_ONCE] = { cmd_verify, HD_CFA_OK | SET_DSC },
@@ -1107,14 +1161,14 @@ static const struct {
[WIN_SMART] = { NULL, HD_CFA_OK },
[CFA_ACCESS_METADATA_STORAGE] = { NULL, CFA_OK },
[CFA_ERASE_SECTORS] = { NULL, CFA_OK },
- [WIN_MULTREAD] = { NULL, HD_CFA_OK },
- [WIN_MULTWRITE] = { NULL, HD_CFA_OK },
- [WIN_SETMULT] = { NULL, HD_CFA_OK },
+ [WIN_MULTREAD] = { cmd_read_multiple, HD_CFA_OK },
+ [WIN_MULTWRITE] = { cmd_write_multiple, HD_CFA_OK },
+ [WIN_SETMULT] = { cmd_set_multiple_mode, HD_CFA_OK | SET_DSC },
[WIN_READDMA] = { NULL, HD_CFA_OK },
[WIN_READDMA_ONCE] = { NULL, HD_CFA_OK },
[WIN_WRITEDMA] = { NULL, HD_CFA_OK },
[WIN_WRITEDMA_ONCE] = { NULL, HD_CFA_OK },
- [CFA_WRITE_MULTI_WO_ERASE] = { NULL, CFA_OK },
+ [CFA_WRITE_MULTI_WO_ERASE] = { cmd_write_multiple, CFA_OK },
[WIN_STANDBYNOW1] = { cmd_nop, ALL_OK },
[WIN_IDLEIMMEDIATE] = { cmd_nop, ALL_OK },
[WIN_STANDBY] = { cmd_nop, ALL_OK },
@@ -1181,22 +1235,6 @@ void ide_exec_cmd(IDEBus *bus, uint32_t val)
}
switch(val) {
- case WIN_SETMULT:
- if (s->drive_kind == IDE_CFATA && s->nsector == 0) {
- /* Disable Read and Write Multiple */
- s->mult_sectors = 0;
- s->status = READY_STAT | SEEK_STAT;
- } else if ((s->nsector & 0xff) != 0 &&
- ((s->nsector & 0xff) > MAX_MULT_SECTORS ||
- (s->nsector & (s->nsector - 1)) != 0)) {
- ide_abort_command(s);
- } else {
- s->mult_sectors = s->nsector & 0xff;
- s->status = READY_STAT | SEEK_STAT;
- }
- ide_set_irq(s->bus);
- break;
-
case WIN_READ_EXT:
lba48 = 1;
/* fall through */
@@ -1232,43 +1270,6 @@ void ide_exec_cmd(IDEBus *bus, uint32_t val)
s->media_changed = 1;
break;
- case WIN_MULTREAD_EXT:
- lba48 = 1;
- /* fall through */
- case WIN_MULTREAD:
- if (!s->bs) {
- goto abort_cmd;
- }
- if (!s->mult_sectors) {
- goto abort_cmd;
- }
- ide_cmd_lba48_transform(s, lba48);
- s->req_nb_sectors = s->mult_sectors;
- ide_sector_read(s);
- break;
-
- case WIN_MULTWRITE_EXT:
- lba48 = 1;
- /* fall through */
- case WIN_MULTWRITE:
- case CFA_WRITE_MULTI_WO_ERASE:
- if (!s->bs) {
- goto abort_cmd;
- }
- if (!s->mult_sectors) {
- goto abort_cmd;
- }
- ide_cmd_lba48_transform(s, lba48);
- s->error = 0;
- s->status = SEEK_STAT | READY_STAT;
- s->req_nb_sectors = s->mult_sectors;
- n = s->nsector;
- if (n > s->req_nb_sectors)
- n = s->req_nb_sectors;
- ide_transfer_start(s, s->io_buffer, 512 * n, ide_sector_write);
- s->media_changed = 1;
- break;
-
case WIN_READDMA_EXT:
lba48 = 1;
/* fall through */
--
1.8.1.4
^ permalink raw reply related [flat|nested] 20+ messages in thread
* [Qemu-devel] [PATCH 07/17] ide: Convert PIO read/write commands to ide_cmd_table handler
2013-06-18 8:25 [Qemu-devel] [PATCH 00/17] ide: Use ide_cmd_table function pointers for command execution Kevin Wolf
` (5 preceding siblings ...)
2013-06-18 8:26 ` [Qemu-devel] [PATCH 06/17] ide: Convert read/write multiple " Kevin Wolf
@ 2013-06-18 8:26 ` Kevin Wolf
2013-06-18 8:26 ` [Qemu-devel] [PATCH 08/17] ide: Convert DMA " Kevin Wolf
` (10 subsequent siblings)
17 siblings, 0 replies; 20+ messages in thread
From: Kevin Wolf @ 2013-06-18 8:26 UTC (permalink / raw)
To: qemu-devel; +Cc: kwolf, stefanha
Signed-off-by: Kevin Wolf <kwolf@redhat.com>
---
hw/ide/core.c | 93 ++++++++++++++++++++++++++++++++---------------------------
1 file changed, 50 insertions(+), 43 deletions(-)
diff --git a/hw/ide/core.c b/hw/ide/core.c
index e6cd7b8..86af4b0 100644
--- a/hw/ide/core.c
+++ b/hw/ide/core.c
@@ -1110,6 +1110,48 @@ static bool cmd_write_multiple(IDEState *s, uint8_t cmd)
return false;
}
+static bool cmd_read_pio(IDEState *s, uint8_t cmd)
+{
+ bool lba48 = (cmd == WIN_READ_EXT);
+
+ if (s->drive_kind == IDE_CD) {
+ ide_set_signature(s); /* odd, but ATA4 8.27.5.2 requires it */
+ ide_abort_command(s);
+ return true;
+ }
+
+ if (!s->bs) {
+ ide_abort_command(s);
+ return true;
+ }
+
+ ide_cmd_lba48_transform(s, lba48);
+ s->req_nb_sectors = 1;
+ ide_sector_read(s);
+
+ return false;
+}
+
+static bool cmd_write_pio(IDEState *s, uint8_t cmd)
+{
+ bool lba48 = (cmd == WIN_WRITE_EXT);
+
+ if (!s->bs) {
+ ide_abort_command(s);
+ return true;
+ }
+
+ ide_cmd_lba48_transform(s, lba48);
+
+ s->req_nb_sectors = 1;
+ s->status = SEEK_STAT | READY_STAT;
+ ide_transfer_start(s, s->io_buffer, 512, ide_sector_write);
+
+ s->media_changed = 1;
+
+ return false;
+}
+
#define HD_OK (1u << IDE_HD)
#define CD_OK (1u << IDE_CD)
#define CFA_OK (1u << IDE_CFATA)
@@ -1130,19 +1172,19 @@ static const struct {
[WIN_DSM] = { cmd_data_set_management, ALL_OK },
[WIN_DEVICE_RESET] = { NULL, CD_OK },
[WIN_RECAL] = { cmd_nop, HD_CFA_OK | SET_DSC},
- [WIN_READ] = { NULL, ALL_OK },
- [WIN_READ_ONCE] = { NULL, ALL_OK },
- [WIN_READ_EXT] = { NULL, HD_CFA_OK },
+ [WIN_READ] = { cmd_read_pio, ALL_OK },
+ [WIN_READ_ONCE] = { cmd_read_pio, ALL_OK },
+ [WIN_READ_EXT] = { cmd_read_pio, HD_CFA_OK },
[WIN_READDMA_EXT] = { NULL, HD_CFA_OK },
[WIN_READ_NATIVE_MAX_EXT] = { NULL, HD_CFA_OK },
[WIN_MULTREAD_EXT] = { cmd_read_multiple, HD_CFA_OK },
- [WIN_WRITE] = { NULL, HD_CFA_OK },
- [WIN_WRITE_ONCE] = { NULL, HD_CFA_OK },
- [WIN_WRITE_EXT] = { NULL, HD_CFA_OK },
+ [WIN_WRITE] = { cmd_write_pio, HD_CFA_OK },
+ [WIN_WRITE_ONCE] = { cmd_write_pio, HD_CFA_OK },
+ [WIN_WRITE_EXT] = { cmd_write_pio, HD_CFA_OK },
[WIN_WRITEDMA_EXT] = { NULL, HD_CFA_OK },
- [CFA_WRITE_SECT_WO_ERASE] = { NULL, CFA_OK },
+ [CFA_WRITE_SECT_WO_ERASE] = { cmd_write_pio, CFA_OK },
[WIN_MULTWRITE_EXT] = { cmd_write_multiple, HD_CFA_OK },
- [WIN_WRITE_VERIFY] = { NULL, HD_CFA_OK },
+ [WIN_WRITE_VERIFY] = { cmd_write_pio, HD_CFA_OK },
[WIN_VERIFY] = { cmd_verify, HD_CFA_OK | SET_DSC },
[WIN_VERIFY_ONCE] = { cmd_verify, HD_CFA_OK | SET_DSC },
[WIN_VERIFY_EXT] = { cmd_verify, HD_CFA_OK | SET_DSC },
@@ -1235,41 +1277,6 @@ void ide_exec_cmd(IDEBus *bus, uint32_t val)
}
switch(val) {
- case WIN_READ_EXT:
- lba48 = 1;
- /* fall through */
- case WIN_READ:
- case WIN_READ_ONCE:
- if (s->drive_kind == IDE_CD) {
- ide_set_signature(s); /* odd, but ATA4 8.27.5.2 requires it */
- goto abort_cmd;
- }
- if (!s->bs) {
- goto abort_cmd;
- }
- ide_cmd_lba48_transform(s, lba48);
- s->req_nb_sectors = 1;
- ide_sector_read(s);
- break;
-
- case WIN_WRITE_EXT:
- lba48 = 1;
- /* fall through */
- case WIN_WRITE:
- case WIN_WRITE_ONCE:
- case CFA_WRITE_SECT_WO_ERASE:
- case WIN_WRITE_VERIFY:
- if (!s->bs) {
- goto abort_cmd;
- }
- ide_cmd_lba48_transform(s, lba48);
- s->error = 0;
- s->status = SEEK_STAT | READY_STAT;
- s->req_nb_sectors = 1;
- ide_transfer_start(s, s->io_buffer, 512, ide_sector_write);
- s->media_changed = 1;
- break;
-
case WIN_READDMA_EXT:
lba48 = 1;
/* fall through */
--
1.8.1.4
^ permalink raw reply related [flat|nested] 20+ messages in thread
* [Qemu-devel] [PATCH 08/17] ide: Convert DMA read/write commands to ide_cmd_table handler
2013-06-18 8:25 [Qemu-devel] [PATCH 00/17] ide: Use ide_cmd_table function pointers for command execution Kevin Wolf
` (6 preceding siblings ...)
2013-06-18 8:26 ` [Qemu-devel] [PATCH 07/17] ide: Convert PIO read/write " Kevin Wolf
@ 2013-06-18 8:26 ` Kevin Wolf
2013-06-18 8:26 ` [Qemu-devel] [PATCH 09/17] ide: Convert READ NATIVE MAX ADDRESS " Kevin Wolf
` (9 subsequent siblings)
17 siblings, 0 replies; 20+ messages in thread
From: Kevin Wolf @ 2013-06-18 8:26 UTC (permalink / raw)
To: qemu-devel; +Cc: kwolf, stefanha
Signed-off-by: Kevin Wolf <kwolf@redhat.com>
---
hw/ide/core.c | 69 ++++++++++++++++++++++++++++++++---------------------------
1 file changed, 38 insertions(+), 31 deletions(-)
diff --git a/hw/ide/core.c b/hw/ide/core.c
index 86af4b0..2c8a0ff 100644
--- a/hw/ide/core.c
+++ b/hw/ide/core.c
@@ -1152,6 +1152,38 @@ static bool cmd_write_pio(IDEState *s, uint8_t cmd)
return false;
}
+static bool cmd_read_dma(IDEState *s, uint8_t cmd)
+{
+ bool lba48 = (cmd == WIN_READDMA_EXT);
+
+ if (!s->bs) {
+ ide_abort_command(s);
+ return true;
+ }
+
+ ide_cmd_lba48_transform(s, lba48);
+ ide_sector_start_dma(s, IDE_DMA_READ);
+
+ return false;
+}
+
+static bool cmd_write_dma(IDEState *s, uint8_t cmd)
+{
+ bool lba48 = (cmd == WIN_WRITEDMA_EXT);
+
+ if (!s->bs) {
+ ide_abort_command(s);
+ return true;
+ }
+
+ ide_cmd_lba48_transform(s, lba48);
+ ide_sector_start_dma(s, IDE_DMA_WRITE);
+
+ s->media_changed = 1;
+
+ return false;
+}
+
#define HD_OK (1u << IDE_HD)
#define CD_OK (1u << IDE_CD)
#define CFA_OK (1u << IDE_CFATA)
@@ -1175,13 +1207,13 @@ static const struct {
[WIN_READ] = { cmd_read_pio, ALL_OK },
[WIN_READ_ONCE] = { cmd_read_pio, ALL_OK },
[WIN_READ_EXT] = { cmd_read_pio, HD_CFA_OK },
- [WIN_READDMA_EXT] = { NULL, HD_CFA_OK },
+ [WIN_READDMA_EXT] = { cmd_read_dma, HD_CFA_OK },
[WIN_READ_NATIVE_MAX_EXT] = { NULL, HD_CFA_OK },
[WIN_MULTREAD_EXT] = { cmd_read_multiple, HD_CFA_OK },
[WIN_WRITE] = { cmd_write_pio, HD_CFA_OK },
[WIN_WRITE_ONCE] = { cmd_write_pio, HD_CFA_OK },
[WIN_WRITE_EXT] = { cmd_write_pio, HD_CFA_OK },
- [WIN_WRITEDMA_EXT] = { NULL, HD_CFA_OK },
+ [WIN_WRITEDMA_EXT] = { cmd_write_dma, HD_CFA_OK },
[CFA_WRITE_SECT_WO_ERASE] = { cmd_write_pio, CFA_OK },
[WIN_MULTWRITE_EXT] = { cmd_write_multiple, HD_CFA_OK },
[WIN_WRITE_VERIFY] = { cmd_write_pio, HD_CFA_OK },
@@ -1206,10 +1238,10 @@ static const struct {
[WIN_MULTREAD] = { cmd_read_multiple, HD_CFA_OK },
[WIN_MULTWRITE] = { cmd_write_multiple, HD_CFA_OK },
[WIN_SETMULT] = { cmd_set_multiple_mode, HD_CFA_OK | SET_DSC },
- [WIN_READDMA] = { NULL, HD_CFA_OK },
- [WIN_READDMA_ONCE] = { NULL, HD_CFA_OK },
- [WIN_WRITEDMA] = { NULL, HD_CFA_OK },
- [WIN_WRITEDMA_ONCE] = { NULL, HD_CFA_OK },
+ [WIN_READDMA] = { cmd_read_dma, HD_CFA_OK },
+ [WIN_READDMA_ONCE] = { cmd_read_dma, HD_CFA_OK },
+ [WIN_WRITEDMA] = { cmd_write_dma, HD_CFA_OK },
+ [WIN_WRITEDMA_ONCE] = { cmd_write_dma, HD_CFA_OK },
[CFA_WRITE_MULTI_WO_ERASE] = { cmd_write_multiple, CFA_OK },
[WIN_STANDBYNOW1] = { cmd_nop, ALL_OK },
[WIN_IDLEIMMEDIATE] = { cmd_nop, ALL_OK },
@@ -1277,31 +1309,6 @@ void ide_exec_cmd(IDEBus *bus, uint32_t val)
}
switch(val) {
- case WIN_READDMA_EXT:
- lba48 = 1;
- /* fall through */
- case WIN_READDMA:
- case WIN_READDMA_ONCE:
- if (!s->bs) {
- goto abort_cmd;
- }
- ide_cmd_lba48_transform(s, lba48);
- ide_sector_start_dma(s, IDE_DMA_READ);
- break;
-
- case WIN_WRITEDMA_EXT:
- lba48 = 1;
- /* fall through */
- case WIN_WRITEDMA:
- case WIN_WRITEDMA_ONCE:
- if (!s->bs) {
- goto abort_cmd;
- }
- ide_cmd_lba48_transform(s, lba48);
- ide_sector_start_dma(s, IDE_DMA_WRITE);
- s->media_changed = 1;
- break;
-
case WIN_READ_NATIVE_MAX_EXT:
lba48 = 1;
/* fall through */
--
1.8.1.4
^ permalink raw reply related [flat|nested] 20+ messages in thread
* [Qemu-devel] [PATCH 09/17] ide: Convert READ NATIVE MAX ADDRESS to ide_cmd_table handler
2013-06-18 8:25 [Qemu-devel] [PATCH 00/17] ide: Use ide_cmd_table function pointers for command execution Kevin Wolf
` (7 preceding siblings ...)
2013-06-18 8:26 ` [Qemu-devel] [PATCH 08/17] ide: Convert DMA " Kevin Wolf
@ 2013-06-18 8:26 ` Kevin Wolf
2013-06-18 8:26 ` [Qemu-devel] [PATCH 10/17] ide: Convert CHECK POWER MDOE " Kevin Wolf
` (8 subsequent siblings)
17 siblings, 0 replies; 20+ messages in thread
From: Kevin Wolf @ 2013-06-18 8:26 UTC (permalink / raw)
To: qemu-devel; +Cc: kwolf, stefanha
Signed-off-by: Kevin Wolf <kwolf@redhat.com>
---
hw/ide/core.c | 35 ++++++++++++++++++-----------------
1 file changed, 18 insertions(+), 17 deletions(-)
diff --git a/hw/ide/core.c b/hw/ide/core.c
index 2c8a0ff..3064e2e 100644
--- a/hw/ide/core.c
+++ b/hw/ide/core.c
@@ -1184,6 +1184,22 @@ static bool cmd_write_dma(IDEState *s, uint8_t cmd)
return false;
}
+static bool cmd_read_native_max(IDEState *s, uint8_t cmd)
+{
+ bool lba48 = (cmd == WIN_READ_NATIVE_MAX_EXT);
+
+ /* Refuse if no sectors are addressable (e.g. medium not inserted) */
+ if (s->nb_sectors == 0) {
+ ide_abort_command(s);
+ return true;
+ }
+
+ ide_cmd_lba48_transform(s, lba48);
+ ide_set_sector(s, s->nb_sectors - 1);
+
+ return true;
+}
+
#define HD_OK (1u << IDE_HD)
#define CD_OK (1u << IDE_CD)
#define CFA_OK (1u << IDE_CFATA)
@@ -1208,7 +1224,7 @@ static const struct {
[WIN_READ_ONCE] = { cmd_read_pio, ALL_OK },
[WIN_READ_EXT] = { cmd_read_pio, HD_CFA_OK },
[WIN_READDMA_EXT] = { cmd_read_dma, HD_CFA_OK },
- [WIN_READ_NATIVE_MAX_EXT] = { NULL, HD_CFA_OK },
+ [WIN_READ_NATIVE_MAX_EXT] = { cmd_read_native_max, HD_CFA_OK | SET_DSC },
[WIN_MULTREAD_EXT] = { cmd_read_multiple, HD_CFA_OK },
[WIN_WRITE] = { cmd_write_pio, HD_CFA_OK },
[WIN_WRITE_ONCE] = { cmd_write_pio, HD_CFA_OK },
@@ -1255,7 +1271,7 @@ static const struct {
[WIN_SETFEATURES] = { NULL, ALL_OK },
[IBM_SENSE_CONDITION] = { NULL, CFA_OK },
[CFA_WEAR_LEVEL] = { NULL, HD_CFA_OK },
- [WIN_READ_NATIVE_MAX] = { NULL, ALL_OK },
+ [WIN_READ_NATIVE_MAX] = { cmd_read_native_max, ALL_OK | SET_DSC },
};
static bool ide_cmd_permitted(IDEState *s, uint32_t cmd)
@@ -1269,7 +1285,6 @@ void ide_exec_cmd(IDEBus *bus, uint32_t val)
uint16_t *identify_data;
IDEState *s;
int n;
- int lba48 = 0;
#if defined(DEBUG_IDE)
printf("ide: CMD=%02x\n", val);
@@ -1309,20 +1324,6 @@ void ide_exec_cmd(IDEBus *bus, uint32_t val)
}
switch(val) {
- case WIN_READ_NATIVE_MAX_EXT:
- lba48 = 1;
- /* fall through */
- case WIN_READ_NATIVE_MAX:
- /* Refuse if no sectors are addressable (e.g. medium not inserted) */
- if (s->nb_sectors == 0) {
- goto abort_cmd;
- }
- ide_cmd_lba48_transform(s, lba48);
- ide_set_sector(s, s->nb_sectors - 1);
- s->status = READY_STAT | SEEK_STAT;
- ide_set_irq(s->bus);
- break;
-
case WIN_CHECKPOWERMODE1:
case WIN_CHECKPOWERMODE2:
s->error = 0;
--
1.8.1.4
^ permalink raw reply related [flat|nested] 20+ messages in thread
* [Qemu-devel] [PATCH 10/17] ide: Convert CHECK POWER MDOE to ide_cmd_table handler
2013-06-18 8:25 [Qemu-devel] [PATCH 00/17] ide: Use ide_cmd_table function pointers for command execution Kevin Wolf
` (8 preceding siblings ...)
2013-06-18 8:26 ` [Qemu-devel] [PATCH 09/17] ide: Convert READ NATIVE MAX ADDRESS " Kevin Wolf
@ 2013-06-18 8:26 ` Kevin Wolf
2013-06-18 8:26 ` [Qemu-devel] [PATCH 11/17] ide: Convert SET FEATURES " Kevin Wolf
` (7 subsequent siblings)
17 siblings, 0 replies; 20+ messages in thread
From: Kevin Wolf @ 2013-06-18 8:26 UTC (permalink / raw)
To: qemu-devel; +Cc: kwolf, stefanha
Signed-off-by: Kevin Wolf <kwolf@redhat.com>
---
hw/ide/core.c | 17 ++++++++---------
1 file changed, 8 insertions(+), 9 deletions(-)
diff --git a/hw/ide/core.c b/hw/ide/core.c
index 3064e2e..a7f8445 100644
--- a/hw/ide/core.c
+++ b/hw/ide/core.c
@@ -1200,6 +1200,12 @@ static bool cmd_read_native_max(IDEState *s, uint8_t cmd)
return true;
}
+static bool cmd_check_power_mode(IDEState *s, uint8_t cmd)
+{
+ s->nsector = 0xff; /* device active or idle */
+ return true;
+}
+
#define HD_OK (1u << IDE_HD)
#define CD_OK (1u << IDE_CD)
#define CFA_OK (1u << IDE_CFATA)
@@ -1244,7 +1250,7 @@ static const struct {
[WIN_IDLEIMMEDIATE2] = { cmd_nop, ALL_OK },
[WIN_STANDBY2] = { cmd_nop, ALL_OK },
[WIN_SETIDLE2] = { cmd_nop, ALL_OK },
- [WIN_CHECKPOWERMODE2] = { NULL, ALL_OK },
+ [WIN_CHECKPOWERMODE2] = { cmd_check_power_mode, ALL_OK | SET_DSC },
[WIN_SLEEPNOW2] = { cmd_nop, ALL_OK },
[WIN_PACKETCMD] = { NULL, CD_OK },
[WIN_PIDENTIFY] = { NULL, CD_OK },
@@ -1263,7 +1269,7 @@ static const struct {
[WIN_IDLEIMMEDIATE] = { cmd_nop, ALL_OK },
[WIN_STANDBY] = { cmd_nop, ALL_OK },
[WIN_SETIDLE1] = { cmd_nop, ALL_OK },
- [WIN_CHECKPOWERMODE1] = { NULL, ALL_OK },
+ [WIN_CHECKPOWERMODE1] = { cmd_check_power_mode, ALL_OK | SET_DSC },
[WIN_SLEEPNOW1] = { cmd_nop, ALL_OK },
[WIN_FLUSH_CACHE] = { NULL, ALL_OK },
[WIN_FLUSH_CACHE_EXT] = { NULL, HD_CFA_OK },
@@ -1324,13 +1330,6 @@ void ide_exec_cmd(IDEBus *bus, uint32_t val)
}
switch(val) {
- case WIN_CHECKPOWERMODE1:
- case WIN_CHECKPOWERMODE2:
- s->error = 0;
- s->nsector = 0xff; /* device active or idle */
- s->status = READY_STAT | SEEK_STAT;
- ide_set_irq(s->bus);
- break;
case WIN_SETFEATURES:
if (!s->bs)
goto abort_cmd;
--
1.8.1.4
^ permalink raw reply related [flat|nested] 20+ messages in thread
* [Qemu-devel] [PATCH 11/17] ide: Convert SET FEATURES to ide_cmd_table handler
2013-06-18 8:25 [Qemu-devel] [PATCH 00/17] ide: Use ide_cmd_table function pointers for command execution Kevin Wolf
` (9 preceding siblings ...)
2013-06-18 8:26 ` [Qemu-devel] [PATCH 10/17] ide: Convert CHECK POWER MDOE " Kevin Wolf
@ 2013-06-18 8:26 ` Kevin Wolf
2013-06-18 8:26 ` [Qemu-devel] [PATCH 12/17] ide: Convert FLUSH CACHE " Kevin Wolf
` (6 subsequent siblings)
17 siblings, 0 replies; 20+ messages in thread
From: Kevin Wolf @ 2013-06-18 8:26 UTC (permalink / raw)
To: qemu-devel; +Cc: kwolf, stefanha
Signed-off-by: Kevin Wolf <kwolf@redhat.com>
---
hw/ide/core.c | 147 ++++++++++++++++++++++++++++++----------------------------
1 file changed, 75 insertions(+), 72 deletions(-)
diff --git a/hw/ide/core.c b/hw/ide/core.c
index a7f8445..8789758 100644
--- a/hw/ide/core.c
+++ b/hw/ide/core.c
@@ -1206,6 +1206,80 @@ static bool cmd_check_power_mode(IDEState *s, uint8_t cmd)
return true;
}
+static bool cmd_set_features(IDEState *s, uint8_t cmd)
+{
+ uint16_t *identify_data;
+
+ if (!s->bs) {
+ ide_abort_command(s);
+ return true;
+ }
+
+ /* XXX: valid for CDROM ? */
+ switch (s->feature) {
+ case 0x02: /* write cache enable */
+ bdrv_set_enable_write_cache(s->bs, true);
+ identify_data = (uint16_t *)s->identify_data;
+ put_le16(identify_data + 85, (1 << 14) | (1 << 5) | 1);
+ return true;
+ case 0x82: /* write cache disable */
+ bdrv_set_enable_write_cache(s->bs, false);
+ identify_data = (uint16_t *)s->identify_data;
+ put_le16(identify_data + 85, (1 << 14) | 1);
+ ide_flush_cache(s);
+ return false;
+ case 0xcc: /* reverting to power-on defaults enable */
+ case 0x66: /* reverting to power-on defaults disable */
+ case 0xaa: /* read look-ahead enable */
+ case 0x55: /* read look-ahead disable */
+ case 0x05: /* set advanced power management mode */
+ case 0x85: /* disable advanced power management mode */
+ case 0x69: /* NOP */
+ case 0x67: /* NOP */
+ case 0x96: /* NOP */
+ case 0x9a: /* NOP */
+ case 0x42: /* enable Automatic Acoustic Mode */
+ case 0xc2: /* disable Automatic Acoustic Mode */
+ return true;
+ case 0x03: /* set transfer mode */
+ {
+ uint8_t val = s->nsector & 0x07;
+ identify_data = (uint16_t *)s->identify_data;
+
+ switch (s->nsector >> 3) {
+ case 0x00: /* pio default */
+ case 0x01: /* pio mode */
+ put_le16(identify_data + 62, 0x07);
+ put_le16(identify_data + 63, 0x07);
+ put_le16(identify_data + 88, 0x3f);
+ break;
+ case 0x02: /* sigle word dma mode*/
+ put_le16(identify_data + 62, 0x07 | (1 << (val + 8)));
+ put_le16(identify_data + 63, 0x07);
+ put_le16(identify_data + 88, 0x3f);
+ break;
+ case 0x04: /* mdma mode */
+ put_le16(identify_data + 62, 0x07);
+ put_le16(identify_data + 63, 0x07 | (1 << (val + 8)));
+ put_le16(identify_data + 88, 0x3f);
+ break;
+ case 0x08: /* udma mode */
+ put_le16(identify_data + 62, 0x07);
+ put_le16(identify_data + 63, 0x07);
+ put_le16(identify_data + 88, 0x3f | (1 << (val + 8)));
+ break;
+ default:
+ goto abort_cmd;
+ }
+ return true;
+ }
+ }
+
+abort_cmd:
+ ide_abort_command(s);
+ return true;
+}
+
#define HD_OK (1u << IDE_HD)
#define CD_OK (1u << IDE_CD)
#define CFA_OK (1u << IDE_CFATA)
@@ -1274,7 +1348,7 @@ static const struct {
[WIN_FLUSH_CACHE] = { NULL, ALL_OK },
[WIN_FLUSH_CACHE_EXT] = { NULL, HD_CFA_OK },
[WIN_IDENTIFY] = { cmd_identify, ALL_OK },
- [WIN_SETFEATURES] = { NULL, ALL_OK },
+ [WIN_SETFEATURES] = { cmd_set_features, ALL_OK | SET_DSC },
[IBM_SENSE_CONDITION] = { NULL, CFA_OK },
[CFA_WEAR_LEVEL] = { NULL, HD_CFA_OK },
[WIN_READ_NATIVE_MAX] = { cmd_read_native_max, ALL_OK | SET_DSC },
@@ -1288,7 +1362,6 @@ static bool ide_cmd_permitted(IDEState *s, uint32_t cmd)
void ide_exec_cmd(IDEBus *bus, uint32_t val)
{
- uint16_t *identify_data;
IDEState *s;
int n;
@@ -1330,76 +1403,6 @@ void ide_exec_cmd(IDEBus *bus, uint32_t val)
}
switch(val) {
- case WIN_SETFEATURES:
- if (!s->bs)
- goto abort_cmd;
- /* XXX: valid for CDROM ? */
- switch(s->feature) {
- case 0x02: /* write cache enable */
- bdrv_set_enable_write_cache(s->bs, true);
- identify_data = (uint16_t *)s->identify_data;
- put_le16(identify_data + 85, (1 << 14) | (1 << 5) | 1);
- s->status = READY_STAT | SEEK_STAT;
- ide_set_irq(s->bus);
- break;
- case 0x82: /* write cache disable */
- bdrv_set_enable_write_cache(s->bs, false);
- identify_data = (uint16_t *)s->identify_data;
- put_le16(identify_data + 85, (1 << 14) | 1);
- ide_flush_cache(s);
- break;
- case 0xcc: /* reverting to power-on defaults enable */
- case 0x66: /* reverting to power-on defaults disable */
- case 0xaa: /* read look-ahead enable */
- case 0x55: /* read look-ahead disable */
- case 0x05: /* set advanced power management mode */
- case 0x85: /* disable advanced power management mode */
- case 0x69: /* NOP */
- case 0x67: /* NOP */
- case 0x96: /* NOP */
- case 0x9a: /* NOP */
- case 0x42: /* enable Automatic Acoustic Mode */
- case 0xc2: /* disable Automatic Acoustic Mode */
- s->status = READY_STAT | SEEK_STAT;
- ide_set_irq(s->bus);
- break;
- case 0x03: { /* set transfer mode */
- uint8_t val = s->nsector & 0x07;
- identify_data = (uint16_t *)s->identify_data;
-
- switch (s->nsector >> 3) {
- case 0x00: /* pio default */
- case 0x01: /* pio mode */
- put_le16(identify_data + 62,0x07);
- put_le16(identify_data + 63,0x07);
- put_le16(identify_data + 88,0x3f);
- break;
- case 0x02: /* sigle word dma mode*/
- put_le16(identify_data + 62,0x07 | (1 << (val + 8)));
- put_le16(identify_data + 63,0x07);
- put_le16(identify_data + 88,0x3f);
- break;
- case 0x04: /* mdma mode */
- put_le16(identify_data + 62,0x07);
- put_le16(identify_data + 63,0x07 | (1 << (val + 8)));
- put_le16(identify_data + 88,0x3f);
- break;
- case 0x08: /* udma mode */
- put_le16(identify_data + 62,0x07);
- put_le16(identify_data + 63,0x07);
- put_le16(identify_data + 88,0x3f | (1 << (val + 8)));
- break;
- default:
- goto abort_cmd;
- }
- s->status = READY_STAT | SEEK_STAT;
- ide_set_irq(s->bus);
- break;
- }
- default:
- goto abort_cmd;
- }
- break;
case WIN_FLUSH_CACHE:
case WIN_FLUSH_CACHE_EXT:
ide_flush_cache(s);
--
1.8.1.4
^ permalink raw reply related [flat|nested] 20+ messages in thread
* [Qemu-devel] [PATCH 12/17] ide: Convert FLUSH CACHE to ide_cmd_table handler
2013-06-18 8:25 [Qemu-devel] [PATCH 00/17] ide: Use ide_cmd_table function pointers for command execution Kevin Wolf
` (10 preceding siblings ...)
2013-06-18 8:26 ` [Qemu-devel] [PATCH 11/17] ide: Convert SET FEATURES " Kevin Wolf
@ 2013-06-18 8:26 ` Kevin Wolf
2013-06-18 8:26 ` [Qemu-devel] [PATCH 13/17] ide: Convert SEEK " Kevin Wolf
` (5 subsequent siblings)
17 siblings, 0 replies; 20+ messages in thread
From: Kevin Wolf @ 2013-06-18 8:26 UTC (permalink / raw)
To: qemu-devel; +Cc: kwolf, stefanha
Signed-off-by: Kevin Wolf <kwolf@redhat.com>
---
hw/ide/core.c | 14 ++++++++------
1 file changed, 8 insertions(+), 6 deletions(-)
diff --git a/hw/ide/core.c b/hw/ide/core.c
index 8789758..83e86aa 100644
--- a/hw/ide/core.c
+++ b/hw/ide/core.c
@@ -1184,6 +1184,12 @@ static bool cmd_write_dma(IDEState *s, uint8_t cmd)
return false;
}
+static bool cmd_flush_cache(IDEState *s, uint8_t cmd)
+{
+ ide_flush_cache(s);
+ return false;
+}
+
static bool cmd_read_native_max(IDEState *s, uint8_t cmd)
{
bool lba48 = (cmd == WIN_READ_NATIVE_MAX_EXT);
@@ -1345,8 +1351,8 @@ static const struct {
[WIN_SETIDLE1] = { cmd_nop, ALL_OK },
[WIN_CHECKPOWERMODE1] = { cmd_check_power_mode, ALL_OK | SET_DSC },
[WIN_SLEEPNOW1] = { cmd_nop, ALL_OK },
- [WIN_FLUSH_CACHE] = { NULL, ALL_OK },
- [WIN_FLUSH_CACHE_EXT] = { NULL, HD_CFA_OK },
+ [WIN_FLUSH_CACHE] = { cmd_flush_cache, ALL_OK },
+ [WIN_FLUSH_CACHE_EXT] = { cmd_flush_cache, HD_CFA_OK },
[WIN_IDENTIFY] = { cmd_identify, ALL_OK },
[WIN_SETFEATURES] = { cmd_set_features, ALL_OK | SET_DSC },
[IBM_SENSE_CONDITION] = { NULL, CFA_OK },
@@ -1403,10 +1409,6 @@ void ide_exec_cmd(IDEBus *bus, uint32_t val)
}
switch(val) {
- case WIN_FLUSH_CACHE:
- case WIN_FLUSH_CACHE_EXT:
- ide_flush_cache(s);
- break;
case WIN_SEEK:
/* XXX: Check that seek is within bounds */
s->status = READY_STAT | SEEK_STAT;
--
1.8.1.4
^ permalink raw reply related [flat|nested] 20+ messages in thread
* [Qemu-devel] [PATCH 13/17] ide: Convert SEEK to ide_cmd_table handler
2013-06-18 8:25 [Qemu-devel] [PATCH 00/17] ide: Use ide_cmd_table function pointers for command execution Kevin Wolf
` (11 preceding siblings ...)
2013-06-18 8:26 ` [Qemu-devel] [PATCH 12/17] ide: Convert FLUSH CACHE " Kevin Wolf
@ 2013-06-18 8:26 ` Kevin Wolf
2013-06-18 8:26 ` [Qemu-devel] [PATCH 14/17] ide: Convert ATAPI commands " Kevin Wolf
` (4 subsequent siblings)
17 siblings, 0 replies; 20+ messages in thread
From: Kevin Wolf @ 2013-06-18 8:26 UTC (permalink / raw)
To: qemu-devel; +Cc: kwolf, stefanha
Signed-off-by: Kevin Wolf <kwolf@redhat.com>
---
hw/ide/core.c | 13 +++++++------
1 file changed, 7 insertions(+), 6 deletions(-)
diff --git a/hw/ide/core.c b/hw/ide/core.c
index 83e86aa..76a3fdf 100644
--- a/hw/ide/core.c
+++ b/hw/ide/core.c
@@ -1190,6 +1190,12 @@ static bool cmd_flush_cache(IDEState *s, uint8_t cmd)
return false;
}
+static bool cmd_seek(IDEState *s, uint8_t cmd)
+{
+ /* XXX: Check that seek is within bounds */
+ return true;
+}
+
static bool cmd_read_native_max(IDEState *s, uint8_t cmd)
{
bool lba48 = (cmd == WIN_READ_NATIVE_MAX_EXT);
@@ -1322,7 +1328,7 @@ static const struct {
[WIN_VERIFY] = { cmd_verify, HD_CFA_OK | SET_DSC },
[WIN_VERIFY_ONCE] = { cmd_verify, HD_CFA_OK | SET_DSC },
[WIN_VERIFY_EXT] = { cmd_verify, HD_CFA_OK | SET_DSC },
- [WIN_SEEK] = { NULL, HD_CFA_OK },
+ [WIN_SEEK] = { cmd_seek, HD_CFA_OK | SET_DSC },
[CFA_TRANSLATE_SECTOR] = { NULL, CFA_OK },
[WIN_DIAGNOSE] = { NULL, ALL_OK },
[WIN_SPECIFY] = { cmd_nop, HD_CFA_OK | SET_DSC },
@@ -1409,11 +1415,6 @@ void ide_exec_cmd(IDEBus *bus, uint32_t val)
}
switch(val) {
- case WIN_SEEK:
- /* XXX: Check that seek is within bounds */
- s->status = READY_STAT | SEEK_STAT;
- ide_set_irq(s->bus);
- break;
/* ATAPI commands */
case WIN_PIDENTIFY:
ide_atapi_identify(s);
--
1.8.1.4
^ permalink raw reply related [flat|nested] 20+ messages in thread
* [Qemu-devel] [PATCH 14/17] ide: Convert ATAPI commands to ide_cmd_table handler
2013-06-18 8:25 [Qemu-devel] [PATCH 00/17] ide: Use ide_cmd_table function pointers for command execution Kevin Wolf
` (12 preceding siblings ...)
2013-06-18 8:26 ` [Qemu-devel] [PATCH 13/17] ide: Convert SEEK " Kevin Wolf
@ 2013-06-18 8:26 ` Kevin Wolf
2013-06-18 8:26 ` [Qemu-devel] [PATCH 15/17] ide: Convert CF-ATA " Kevin Wolf
` (3 subsequent siblings)
17 siblings, 0 replies; 20+ messages in thread
From: Kevin Wolf @ 2013-06-18 8:26 UTC (permalink / raw)
To: qemu-devel; +Cc: kwolf, stefanha
Signed-off-by: Kevin Wolf <kwolf@redhat.com>
---
hw/ide/core.c | 100 +++++++++++++++++++++++++++++++++++-----------------------
1 file changed, 61 insertions(+), 39 deletions(-)
diff --git a/hw/ide/core.c b/hw/ide/core.c
index 76a3fdf..eebd5d9 100644
--- a/hw/ide/core.c
+++ b/hw/ide/core.c
@@ -1292,6 +1292,63 @@ abort_cmd:
return true;
}
+
+/*** ATAPI commands ***/
+
+static bool cmd_identify_packet(IDEState *s, uint8_t cmd)
+{
+ 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);
+ return false;
+}
+
+static bool cmd_exec_dev_diagnostic(IDEState *s, uint8_t cmd)
+{
+ ide_set_signature(s);
+
+ if (s->drive_kind == IDE_CD) {
+ s->status = 0; /* ATAPI spec (v6) section 9.10 defines packet
+ * devices to return a clear status register
+ * with READY_STAT *not* set. */
+ } else {
+ s->status = READY_STAT | SEEK_STAT;
+ /* The bits of the error register are not as usual for this command!
+ * They are part of the regular output (this is why ERR_STAT isn't set)
+ * Device 0 passed, Device 1 passed or not present. */
+ s->error = 0x01;
+ ide_set_irq(s->bus);
+ }
+
+ return false;
+}
+
+static bool cmd_device_reset(IDEState *s, uint8_t cmd)
+{
+ ide_set_signature(s);
+ s->status = 0x00; /* NOTE: READY is _not_ set */
+ s->error = 0x01;
+
+ return false;
+}
+
+static bool cmd_packet(IDEState *s, uint8_t cmd)
+{
+ /* overlapping commands not supported */
+ if (s->feature & 0x02) {
+ ide_abort_command(s);
+ return true;
+ }
+
+ s->status = READY_STAT | SEEK_STAT;
+ s->atapi_dma = s->feature & 1;
+ s->nsector = 1;
+ ide_transfer_start(s, s->io_buffer, ATAPI_PACKET_SIZE,
+ ide_atapi_cmd);
+ return false;
+}
+
#define HD_OK (1u << IDE_HD)
#define CD_OK (1u << IDE_CD)
#define CFA_OK (1u << IDE_CFATA)
@@ -1310,7 +1367,7 @@ static const struct {
/* NOP not implemented, mandatory for CD */
[CFA_REQ_EXT_ERROR_CODE] = { NULL, CFA_OK },
[WIN_DSM] = { cmd_data_set_management, ALL_OK },
- [WIN_DEVICE_RESET] = { NULL, CD_OK },
+ [WIN_DEVICE_RESET] = { cmd_device_reset, CD_OK },
[WIN_RECAL] = { cmd_nop, HD_CFA_OK | SET_DSC},
[WIN_READ] = { cmd_read_pio, ALL_OK },
[WIN_READ_ONCE] = { cmd_read_pio, ALL_OK },
@@ -1330,7 +1387,7 @@ static const struct {
[WIN_VERIFY_EXT] = { cmd_verify, HD_CFA_OK | SET_DSC },
[WIN_SEEK] = { cmd_seek, HD_CFA_OK | SET_DSC },
[CFA_TRANSLATE_SECTOR] = { NULL, CFA_OK },
- [WIN_DIAGNOSE] = { NULL, ALL_OK },
+ [WIN_DIAGNOSE] = { cmd_exec_dev_diagnostic, ALL_OK },
[WIN_SPECIFY] = { cmd_nop, HD_CFA_OK | SET_DSC },
[WIN_STANDBYNOW2] = { cmd_nop, ALL_OK },
[WIN_IDLEIMMEDIATE2] = { cmd_nop, ALL_OK },
@@ -1338,8 +1395,8 @@ static const struct {
[WIN_SETIDLE2] = { cmd_nop, ALL_OK },
[WIN_CHECKPOWERMODE2] = { cmd_check_power_mode, ALL_OK | SET_DSC },
[WIN_SLEEPNOW2] = { cmd_nop, ALL_OK },
- [WIN_PACKETCMD] = { NULL, CD_OK },
- [WIN_PIDENTIFY] = { NULL, CD_OK },
+ [WIN_PACKETCMD] = { cmd_packet, CD_OK },
+ [WIN_PIDENTIFY] = { cmd_identify_packet, CD_OK },
[WIN_SMART] = { NULL, HD_CFA_OK },
[CFA_ACCESS_METADATA_STORAGE] = { NULL, CFA_OK },
[CFA_ERASE_SECTORS] = { NULL, CFA_OK },
@@ -1415,41 +1472,6 @@ void ide_exec_cmd(IDEBus *bus, uint32_t val)
}
switch(val) {
- /* ATAPI commands */
- case WIN_PIDENTIFY:
- 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:
- ide_set_signature(s);
- if (s->drive_kind == IDE_CD)
- s->status = 0; /* ATAPI spec (v6) section 9.10 defines packet
- * devices to return a clear status register
- * with READY_STAT *not* set. */
- else
- s->status = READY_STAT | SEEK_STAT;
- s->error = 0x01; /* Device 0 passed, Device 1 passed or not
- * present.
- */
- ide_set_irq(s->bus);
- break;
- case WIN_DEVICE_RESET:
- ide_set_signature(s);
- s->status = 0x00; /* NOTE: READY is _not_ set */
- s->error = 0x01;
- break;
- case WIN_PACKETCMD:
- /* overlapping commands not supported */
- if (s->feature & 0x02)
- goto abort_cmd;
- s->status = READY_STAT | SEEK_STAT;
- s->atapi_dma = s->feature & 1;
- s->nsector = 1;
- ide_transfer_start(s, s->io_buffer, ATAPI_PACKET_SIZE,
- ide_atapi_cmd);
- break;
/* CF-ATA commands */
case CFA_REQ_EXT_ERROR_CODE:
s->error = 0x09; /* miscellaneous error */
--
1.8.1.4
^ permalink raw reply related [flat|nested] 20+ messages in thread
* [Qemu-devel] [PATCH 15/17] ide: Convert CF-ATA commands to ide_cmd_table handler
2013-06-18 8:25 [Qemu-devel] [PATCH 00/17] ide: Use ide_cmd_table function pointers for command execution Kevin Wolf
` (13 preceding siblings ...)
2013-06-18 8:26 ` [Qemu-devel] [PATCH 14/17] ide: Convert ATAPI commands " Kevin Wolf
@ 2013-06-18 8:26 ` Kevin Wolf
2013-06-18 8:26 ` [Qemu-devel] [PATCH 16/17] ide: Convert SMART " Kevin Wolf
` (2 subsequent siblings)
17 siblings, 0 replies; 20+ messages in thread
From: Kevin Wolf @ 2013-06-18 8:26 UTC (permalink / raw)
To: qemu-devel; +Cc: kwolf, stefanha
Signed-off-by: Kevin Wolf <kwolf@redhat.com>
---
hw/ide/core.c | 170 ++++++++++++++++++++++++++++++++--------------------------
1 file changed, 95 insertions(+), 75 deletions(-)
diff --git a/hw/ide/core.c b/hw/ide/core.c
index eebd5d9..a563f6e 100644
--- a/hw/ide/core.c
+++ b/hw/ide/core.c
@@ -1349,6 +1349,95 @@ static bool cmd_packet(IDEState *s, uint8_t cmd)
return false;
}
+
+/*** CF-ATA commands ***/
+
+static bool cmd_cfa_req_ext_error_code(IDEState *s, uint8_t cmd)
+{
+ s->error = 0x09; /* miscellaneous error */
+ s->status = READY_STAT | SEEK_STAT;
+ ide_set_irq(s->bus);
+
+ return false;
+}
+
+static bool cmd_cfa_erase_sectors(IDEState *s, uint8_t cmd)
+{
+ /* WIN_SECURITY_FREEZE_LOCK has the same ID as CFA_WEAR_LEVEL and is
+ * required for Windows 8 to work with AHCI */
+
+ if (cmd == CFA_WEAR_LEVEL) {
+ s->nsector = 0;
+ }
+
+ if (cmd == CFA_ERASE_SECTORS) {
+ s->media_changed = 1;
+ }
+
+ return true;
+}
+
+static bool cmd_cfa_translate_sector(IDEState *s, uint8_t cmd)
+{
+ s->status = READY_STAT | SEEK_STAT;
+
+ memset(s->io_buffer, 0, 0x200);
+ s->io_buffer[0x00] = s->hcyl; /* Cyl MSB */
+ s->io_buffer[0x01] = s->lcyl; /* Cyl LSB */
+ s->io_buffer[0x02] = s->select; /* Head */
+ s->io_buffer[0x03] = s->sector; /* Sector */
+ s->io_buffer[0x04] = ide_get_sector(s) >> 16; /* LBA MSB */
+ s->io_buffer[0x05] = ide_get_sector(s) >> 8; /* LBA */
+ s->io_buffer[0x06] = ide_get_sector(s) >> 0; /* LBA LSB */
+ s->io_buffer[0x13] = 0x00; /* Erase flag */
+ s->io_buffer[0x18] = 0x00; /* Hot count */
+ s->io_buffer[0x19] = 0x00; /* Hot count */
+ s->io_buffer[0x1a] = 0x01; /* Hot count */
+
+ ide_transfer_start(s, s->io_buffer, 0x200, ide_transfer_stop);
+ ide_set_irq(s->bus);
+
+ return false;
+}
+
+static bool cmd_cfa_access_metadata_storage(IDEState *s, uint8_t cmd)
+{
+ switch (s->feature) {
+ case 0x02: /* Inquiry Metadata Storage */
+ ide_cfata_metadata_inquiry(s);
+ break;
+ case 0x03: /* Read Metadata Storage */
+ ide_cfata_metadata_read(s);
+ break;
+ case 0x04: /* Write Metadata Storage */
+ ide_cfata_metadata_write(s);
+ break;
+ default:
+ ide_abort_command(s);
+ return true;
+ }
+
+ ide_transfer_start(s, s->io_buffer, 0x200, ide_transfer_stop);
+ s->status = 0x00; /* NOTE: READY is _not_ set */
+ ide_set_irq(s->bus);
+
+ return false;
+}
+
+static bool cmd_ibm_sense_condition(IDEState *s, uint8_t cmd)
+{
+ switch (s->feature) {
+ case 0x01: /* sense temperature in device */
+ s->nsector = 0x50; /* +20 C */
+ break;
+ default:
+ ide_abort_command(s);
+ return true;
+ }
+
+ return true;
+}
+
#define HD_OK (1u << IDE_HD)
#define CD_OK (1u << IDE_CD)
#define CFA_OK (1u << IDE_CFATA)
@@ -1365,7 +1454,7 @@ static const struct {
int flags;
} ide_cmd_table[0x100] = {
/* NOP not implemented, mandatory for CD */
- [CFA_REQ_EXT_ERROR_CODE] = { NULL, CFA_OK },
+ [CFA_REQ_EXT_ERROR_CODE] = { cmd_cfa_req_ext_error_code, CFA_OK },
[WIN_DSM] = { cmd_data_set_management, ALL_OK },
[WIN_DEVICE_RESET] = { cmd_device_reset, CD_OK },
[WIN_RECAL] = { cmd_nop, HD_CFA_OK | SET_DSC},
@@ -1386,7 +1475,7 @@ static const struct {
[WIN_VERIFY_ONCE] = { cmd_verify, HD_CFA_OK | SET_DSC },
[WIN_VERIFY_EXT] = { cmd_verify, HD_CFA_OK | SET_DSC },
[WIN_SEEK] = { cmd_seek, HD_CFA_OK | SET_DSC },
- [CFA_TRANSLATE_SECTOR] = { NULL, CFA_OK },
+ [CFA_TRANSLATE_SECTOR] = { cmd_cfa_translate_sector, CFA_OK },
[WIN_DIAGNOSE] = { cmd_exec_dev_diagnostic, ALL_OK },
[WIN_SPECIFY] = { cmd_nop, HD_CFA_OK | SET_DSC },
[WIN_STANDBYNOW2] = { cmd_nop, ALL_OK },
@@ -1398,8 +1487,8 @@ static const struct {
[WIN_PACKETCMD] = { cmd_packet, CD_OK },
[WIN_PIDENTIFY] = { cmd_identify_packet, CD_OK },
[WIN_SMART] = { NULL, HD_CFA_OK },
- [CFA_ACCESS_METADATA_STORAGE] = { NULL, CFA_OK },
- [CFA_ERASE_SECTORS] = { NULL, CFA_OK },
+ [CFA_ACCESS_METADATA_STORAGE] = { cmd_cfa_access_metadata_storage, CFA_OK },
+ [CFA_ERASE_SECTORS] = { cmd_cfa_erase_sectors, CFA_OK | SET_DSC },
[WIN_MULTREAD] = { cmd_read_multiple, HD_CFA_OK },
[WIN_MULTWRITE] = { cmd_write_multiple, HD_CFA_OK },
[WIN_SETMULT] = { cmd_set_multiple_mode, HD_CFA_OK | SET_DSC },
@@ -1418,8 +1507,8 @@ static const struct {
[WIN_FLUSH_CACHE_EXT] = { cmd_flush_cache, HD_CFA_OK },
[WIN_IDENTIFY] = { cmd_identify, ALL_OK },
[WIN_SETFEATURES] = { cmd_set_features, ALL_OK | SET_DSC },
- [IBM_SENSE_CONDITION] = { NULL, CFA_OK },
- [CFA_WEAR_LEVEL] = { NULL, HD_CFA_OK },
+ [IBM_SENSE_CONDITION] = { cmd_ibm_sense_condition, CFA_OK | SET_DSC },
+ [CFA_WEAR_LEVEL] = { cmd_cfa_erase_sectors, HD_CFA_OK | SET_DSC },
[WIN_READ_NATIVE_MAX] = { cmd_read_native_max, ALL_OK | SET_DSC },
};
@@ -1472,75 +1561,6 @@ void ide_exec_cmd(IDEBus *bus, uint32_t val)
}
switch(val) {
- /* CF-ATA commands */
- case CFA_REQ_EXT_ERROR_CODE:
- 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 0
- /* This one has the same ID as CFA_WEAR_LEVEL and is required for
- Windows 8 to work with AHCI */
- case WIN_SECURITY_FREEZE_LOCK:
-#endif
- if (val == CFA_WEAR_LEVEL)
- s->nsector = 0;
- if (val == CFA_ERASE_SECTORS)
- s->media_changed = 1;
- s->error = 0x00;
- s->status = READY_STAT | SEEK_STAT;
- ide_set_irq(s->bus);
- break;
- case CFA_TRANSLATE_SECTOR:
- s->error = 0x00;
- s->status = READY_STAT | SEEK_STAT;
- memset(s->io_buffer, 0, 0x200);
- s->io_buffer[0x00] = s->hcyl; /* Cyl MSB */
- s->io_buffer[0x01] = s->lcyl; /* Cyl LSB */
- s->io_buffer[0x02] = s->select; /* Head */
- s->io_buffer[0x03] = s->sector; /* Sector */
- s->io_buffer[0x04] = ide_get_sector(s) >> 16; /* LBA MSB */
- s->io_buffer[0x05] = ide_get_sector(s) >> 8; /* LBA */
- s->io_buffer[0x06] = ide_get_sector(s) >> 0; /* LBA LSB */
- s->io_buffer[0x13] = 0x00; /* Erase flag */
- s->io_buffer[0x18] = 0x00; /* Hot count */
- s->io_buffer[0x19] = 0x00; /* Hot count */
- s->io_buffer[0x1a] = 0x01; /* Hot count */
- ide_transfer_start(s, s->io_buffer, 0x200, ide_transfer_stop);
- ide_set_irq(s->bus);
- break;
- case CFA_ACCESS_METADATA_STORAGE:
- switch (s->feature) {
- case 0x02: /* Inquiry Metadata Storage */
- ide_cfata_metadata_inquiry(s);
- break;
- case 0x03: /* Read Metadata Storage */
- ide_cfata_metadata_read(s);
- break;
- case 0x04: /* Write Metadata Storage */
- ide_cfata_metadata_write(s);
- break;
- default:
- goto abort_cmd;
- }
- ide_transfer_start(s, s->io_buffer, 0x200, ide_transfer_stop);
- s->status = 0x00; /* NOTE: READY is _not_ set */
- ide_set_irq(s->bus);
- break;
- case IBM_SENSE_CONDITION:
- switch (s->feature) {
- case 0x01: /* sense temperature in device */
- s->nsector = 0x50; /* +20 C */
- break;
- default:
- goto abort_cmd;
- }
- s->status = READY_STAT | SEEK_STAT;
- ide_set_irq(s->bus);
- break;
-
case WIN_SMART:
if (s->hcyl != 0xc2 || s->lcyl != 0x4f)
goto abort_cmd;
--
1.8.1.4
^ permalink raw reply related [flat|nested] 20+ messages in thread
* [Qemu-devel] [PATCH 16/17] ide: Convert SMART commands to ide_cmd_table handler
2013-06-18 8:25 [Qemu-devel] [PATCH 00/17] ide: Use ide_cmd_table function pointers for command execution Kevin Wolf
` (14 preceding siblings ...)
2013-06-18 8:26 ` [Qemu-devel] [PATCH 15/17] ide: Convert CF-ATA " Kevin Wolf
@ 2013-06-18 8:26 ` Kevin Wolf
2013-06-18 8:26 ` [Qemu-devel] [PATCH 17/17] ide: Clean up ide_exec_cmd() Kevin Wolf
2013-06-19 12:28 ` [Qemu-devel] [PATCH 00/17] ide: Use ide_cmd_table function pointers for command execution Stefan Hajnoczi
17 siblings, 0 replies; 20+ messages in thread
From: Kevin Wolf @ 2013-06-18 8:26 UTC (permalink / raw)
To: qemu-devel; +Cc: kwolf, stefanha
Signed-off-by: Kevin Wolf <kwolf@redhat.com>
---
hw/ide/core.c | 325 +++++++++++++++++++++++++++++++---------------------------
1 file changed, 174 insertions(+), 151 deletions(-)
diff --git a/hw/ide/core.c b/hw/ide/core.c
index a563f6e..1c8f414 100644
--- a/hw/ide/core.c
+++ b/hw/ide/core.c
@@ -1438,6 +1438,179 @@ static bool cmd_ibm_sense_condition(IDEState *s, uint8_t cmd)
return true;
}
+
+/*** SMART commands ***/
+
+static bool cmd_smart(IDEState *s, uint8_t cmd)
+{
+ int n;
+
+ if (s->hcyl != 0xc2 || s->lcyl != 0x4f) {
+ goto abort_cmd;
+ }
+
+ if (!s->smart_enabled && s->feature != SMART_ENABLE) {
+ goto abort_cmd;
+ }
+
+ switch (s->feature) {
+ case SMART_DISABLE:
+ s->smart_enabled = 0;
+ return true;
+
+ case SMART_ENABLE:
+ s->smart_enabled = 1;
+ return true;
+
+ case SMART_ATTR_AUTOSAVE:
+ switch (s->sector) {
+ case 0x00:
+ s->smart_autosave = 0;
+ break;
+ case 0xf1:
+ s->smart_autosave = 1;
+ break;
+ default:
+ goto abort_cmd;
+ }
+ return true;
+
+ case SMART_STATUS:
+ if (!s->smart_errors) {
+ s->hcyl = 0xc2;
+ s->lcyl = 0x4f;
+ } else {
+ s->hcyl = 0x2c;
+ s->lcyl = 0xf4;
+ }
+ return true;
+
+ case SMART_READ_THRESH:
+ memset(s->io_buffer, 0, 0x200);
+ s->io_buffer[0] = 0x01; /* smart struct version */
+
+ for (n = 0; n < ARRAY_SIZE(smart_attributes); n++) {
+ s->io_buffer[2 + 0 + (n * 12)] = smart_attributes[n][0];
+ s->io_buffer[2 + 1 + (n * 12)] = smart_attributes[n][11];
+ }
+
+ /* checksum */
+ for (n = 0; n < 511; n++) {
+ s->io_buffer[511] += s->io_buffer[n];
+ }
+ s->io_buffer[511] = 0x100 - s->io_buffer[511];
+
+ s->status = READY_STAT | SEEK_STAT;
+ ide_transfer_start(s, s->io_buffer, 0x200, ide_transfer_stop);
+ ide_set_irq(s->bus);
+ return false;
+
+ case SMART_READ_DATA:
+ memset(s->io_buffer, 0, 0x200);
+ s->io_buffer[0] = 0x01; /* smart struct version */
+
+ for (n = 0; n < ARRAY_SIZE(smart_attributes); n++) {
+ int i;
+ for (i = 0; i < 11; i++) {
+ s->io_buffer[2 + i + (n * 12)] = smart_attributes[n][i];
+ }
+ }
+
+ s->io_buffer[362] = 0x02 | (s->smart_autosave ? 0x80 : 0x00);
+ if (s->smart_selftest_count == 0) {
+ s->io_buffer[363] = 0;
+ } else {
+ s->io_buffer[363] =
+ s->smart_selftest_data[3 +
+ (s->smart_selftest_count - 1) *
+ 24];
+ }
+ s->io_buffer[364] = 0x20;
+ s->io_buffer[365] = 0x01;
+ /* offline data collection capacity: execute + self-test*/
+ s->io_buffer[367] = (1 << 4 | 1 << 3 | 1);
+ s->io_buffer[368] = 0x03; /* smart capability (1) */
+ s->io_buffer[369] = 0x00; /* smart capability (2) */
+ s->io_buffer[370] = 0x01; /* error logging supported */
+ s->io_buffer[372] = 0x02; /* minutes for poll short test */
+ s->io_buffer[373] = 0x36; /* minutes for poll ext test */
+ s->io_buffer[374] = 0x01; /* minutes for poll conveyance */
+
+ for (n = 0; n < 511; n++) {
+ s->io_buffer[511] += s->io_buffer[n];
+ }
+ s->io_buffer[511] = 0x100 - s->io_buffer[511];
+
+ s->status = READY_STAT | SEEK_STAT;
+ ide_transfer_start(s, s->io_buffer, 0x200, ide_transfer_stop);
+ ide_set_irq(s->bus);
+ return false;
+
+ case SMART_READ_LOG:
+ switch (s->sector) {
+ case 0x01: /* summary smart error log */
+ memset(s->io_buffer, 0, 0x200);
+ s->io_buffer[0] = 0x01;
+ s->io_buffer[1] = 0x00; /* no error entries */
+ s->io_buffer[452] = s->smart_errors & 0xff;
+ s->io_buffer[453] = (s->smart_errors & 0xff00) >> 8;
+
+ for (n = 0; n < 511; n++) {
+ s->io_buffer[511] += s->io_buffer[n];
+ }
+ s->io_buffer[511] = 0x100 - s->io_buffer[511];
+ break;
+ case 0x06: /* smart self test log */
+ memset(s->io_buffer, 0, 0x200);
+ s->io_buffer[0] = 0x01;
+ if (s->smart_selftest_count == 0) {
+ s->io_buffer[508] = 0;
+ } else {
+ s->io_buffer[508] = s->smart_selftest_count;
+ for (n = 2; n < 506; n++) {
+ s->io_buffer[n] = s->smart_selftest_data[n];
+ }
+ }
+
+ for (n = 0; n < 511; n++) {
+ s->io_buffer[511] += s->io_buffer[n];
+ }
+ s->io_buffer[511] = 0x100 - s->io_buffer[511];
+ break;
+ default:
+ goto abort_cmd;
+ }
+ s->status = READY_STAT | SEEK_STAT;
+ ide_transfer_start(s, s->io_buffer, 0x200, ide_transfer_stop);
+ ide_set_irq(s->bus);
+ return false;
+
+ case SMART_EXECUTE_OFFLINE:
+ switch (s->sector) {
+ case 0: /* off-line routine */
+ case 1: /* short self test */
+ case 2: /* extended self test */
+ s->smart_selftest_count++;
+ if (s->smart_selftest_count > 21) {
+ s->smart_selftest_count = 0;
+ }
+ n = 2 + (s->smart_selftest_count - 1) * 24;
+ s->smart_selftest_data[n] = s->sector;
+ s->smart_selftest_data[n + 1] = 0x00; /* OK and finished */
+ s->smart_selftest_data[n + 2] = 0x34; /* hour count lsb */
+ s->smart_selftest_data[n + 3] = 0x12; /* hour count msb */
+ break;
+ default:
+ goto abort_cmd;
+ }
+ return true;
+ }
+
+abort_cmd:
+ ide_abort_command(s);
+ return true;
+}
+
#define HD_OK (1u << IDE_HD)
#define CD_OK (1u << IDE_CD)
#define CFA_OK (1u << IDE_CFATA)
@@ -1486,7 +1659,7 @@ static const struct {
[WIN_SLEEPNOW2] = { cmd_nop, ALL_OK },
[WIN_PACKETCMD] = { cmd_packet, CD_OK },
[WIN_PIDENTIFY] = { cmd_identify_packet, CD_OK },
- [WIN_SMART] = { NULL, HD_CFA_OK },
+ [WIN_SMART] = { cmd_smart, HD_CFA_OK | SET_DSC },
[CFA_ACCESS_METADATA_STORAGE] = { cmd_cfa_access_metadata_storage, CFA_OK },
[CFA_ERASE_SECTORS] = { cmd_cfa_erase_sectors, CFA_OK | SET_DSC },
[WIN_MULTREAD] = { cmd_read_multiple, HD_CFA_OK },
@@ -1521,7 +1694,6 @@ static bool ide_cmd_permitted(IDEState *s, uint32_t cmd)
void ide_exec_cmd(IDEBus *bus, uint32_t val)
{
IDEState *s;
- int n;
#if defined(DEBUG_IDE)
printf("ide: CMD=%02x\n", val);
@@ -1561,155 +1733,6 @@ void ide_exec_cmd(IDEBus *bus, uint32_t val)
}
switch(val) {
- case WIN_SMART:
- if (s->hcyl != 0xc2 || s->lcyl != 0x4f)
- goto abort_cmd;
- if (!s->smart_enabled && s->feature != SMART_ENABLE)
- goto abort_cmd;
- switch (s->feature) {
- case SMART_DISABLE:
- s->smart_enabled = 0;
- s->status = READY_STAT | SEEK_STAT;
- ide_set_irq(s->bus);
- break;
- case SMART_ENABLE:
- s->smart_enabled = 1;
- s->status = READY_STAT | SEEK_STAT;
- ide_set_irq(s->bus);
- break;
- case SMART_ATTR_AUTOSAVE:
- switch (s->sector) {
- case 0x00:
- s->smart_autosave = 0;
- break;
- case 0xf1:
- s->smart_autosave = 1;
- break;
- default:
- goto abort_cmd;
- }
- s->status = READY_STAT | SEEK_STAT;
- ide_set_irq(s->bus);
- break;
- case SMART_STATUS:
- if (!s->smart_errors) {
- s->hcyl = 0xc2;
- s->lcyl = 0x4f;
- } else {
- s->hcyl = 0x2c;
- s->lcyl = 0xf4;
- }
- s->status = READY_STAT | SEEK_STAT;
- ide_set_irq(s->bus);
- break;
- case SMART_READ_THRESH:
- memset(s->io_buffer, 0, 0x200);
- s->io_buffer[0] = 0x01; /* smart struct version */
- for (n = 0; n < ARRAY_SIZE(smart_attributes); n++) {
- s->io_buffer[2+0+(n*12)] = smart_attributes[n][0];
- s->io_buffer[2+1+(n*12)] = smart_attributes[n][11];
- }
- for (n=0; n<511; n++) /* checksum */
- s->io_buffer[511] += s->io_buffer[n];
- s->io_buffer[511] = 0x100 - s->io_buffer[511];
- s->status = READY_STAT | SEEK_STAT;
- ide_transfer_start(s, s->io_buffer, 0x200, ide_transfer_stop);
- ide_set_irq(s->bus);
- break;
- case SMART_READ_DATA:
- memset(s->io_buffer, 0, 0x200);
- s->io_buffer[0] = 0x01; /* smart struct version */
- for (n = 0; n < ARRAY_SIZE(smart_attributes); n++) {
- int i;
- for(i = 0; i < 11; i++) {
- s->io_buffer[2+i+(n*12)] = smart_attributes[n][i];
- }
- }
- s->io_buffer[362] = 0x02 | (s->smart_autosave?0x80:0x00);
- if (s->smart_selftest_count == 0) {
- s->io_buffer[363] = 0;
- } else {
- s->io_buffer[363] =
- s->smart_selftest_data[3 +
- (s->smart_selftest_count - 1) *
- 24];
- }
- s->io_buffer[364] = 0x20;
- s->io_buffer[365] = 0x01;
- /* offline data collection capacity: execute + self-test*/
- s->io_buffer[367] = (1<<4 | 1<<3 | 1);
- s->io_buffer[368] = 0x03; /* smart capability (1) */
- s->io_buffer[369] = 0x00; /* smart capability (2) */
- s->io_buffer[370] = 0x01; /* error logging supported */
- s->io_buffer[372] = 0x02; /* minutes for poll short test */
- s->io_buffer[373] = 0x36; /* minutes for poll ext test */
- s->io_buffer[374] = 0x01; /* minutes for poll conveyance */
-
- for (n=0; n<511; n++)
- s->io_buffer[511] += s->io_buffer[n];
- s->io_buffer[511] = 0x100 - s->io_buffer[511];
- s->status = READY_STAT | SEEK_STAT;
- ide_transfer_start(s, s->io_buffer, 0x200, ide_transfer_stop);
- ide_set_irq(s->bus);
- break;
- case SMART_READ_LOG:
- switch (s->sector) {
- case 0x01: /* summary smart error log */
- memset(s->io_buffer, 0, 0x200);
- s->io_buffer[0] = 0x01;
- s->io_buffer[1] = 0x00; /* no error entries */
- s->io_buffer[452] = s->smart_errors & 0xff;
- s->io_buffer[453] = (s->smart_errors & 0xff00) >> 8;
-
- for (n=0; n<511; n++)
- s->io_buffer[511] += s->io_buffer[n];
- s->io_buffer[511] = 0x100 - s->io_buffer[511];
- break;
- case 0x06: /* smart self test log */
- memset(s->io_buffer, 0, 0x200);
- s->io_buffer[0] = 0x01;
- if (s->smart_selftest_count == 0) {
- s->io_buffer[508] = 0;
- } else {
- s->io_buffer[508] = s->smart_selftest_count;
- for (n=2; n<506; n++)
- s->io_buffer[n] = s->smart_selftest_data[n];
- }
- for (n=0; n<511; n++)
- s->io_buffer[511] += s->io_buffer[n];
- s->io_buffer[511] = 0x100 - s->io_buffer[511];
- break;
- default:
- goto abort_cmd;
- }
- s->status = READY_STAT | SEEK_STAT;
- ide_transfer_start(s, s->io_buffer, 0x200, ide_transfer_stop);
- ide_set_irq(s->bus);
- break;
- case SMART_EXECUTE_OFFLINE:
- switch (s->sector) {
- case 0: /* off-line routine */
- case 1: /* short self test */
- case 2: /* extended self test */
- s->smart_selftest_count++;
- if(s->smart_selftest_count > 21)
- s->smart_selftest_count = 0;
- n = 2 + (s->smart_selftest_count - 1) * 24;
- s->smart_selftest_data[n] = s->sector;
- s->smart_selftest_data[n+1] = 0x00; /* OK and finished */
- s->smart_selftest_data[n+2] = 0x34; /* hour count lsb */
- s->smart_selftest_data[n+3] = 0x12; /* hour count msb */
- s->status = READY_STAT | SEEK_STAT;
- ide_set_irq(s->bus);
- break;
- default:
- goto abort_cmd;
- }
- break;
- default:
- goto abort_cmd;
- }
- break;
default:
/* should not be reachable */
abort_cmd:
--
1.8.1.4
^ permalink raw reply related [flat|nested] 20+ messages in thread
* [Qemu-devel] [PATCH 17/17] ide: Clean up ide_exec_cmd()
2013-06-18 8:25 [Qemu-devel] [PATCH 00/17] ide: Use ide_cmd_table function pointers for command execution Kevin Wolf
` (15 preceding siblings ...)
2013-06-18 8:26 ` [Qemu-devel] [PATCH 16/17] ide: Convert SMART " Kevin Wolf
@ 2013-06-18 8:26 ` Kevin Wolf
2013-06-19 12:28 ` [Qemu-devel] [PATCH 00/17] ide: Use ide_cmd_table function pointers for command execution Stefan Hajnoczi
17 siblings, 0 replies; 20+ messages in thread
From: Kevin Wolf @ 2013-06-18 8:26 UTC (permalink / raw)
To: qemu-devel; +Cc: kwolf, stefanha
All commands are now converted to ide_cmd_table handlers, so it can be
unconditional now and the old switch block can go.
Signed-off-by: Kevin Wolf <kwolf@redhat.com>
---
hw/ide/core.c | 36 ++++++++++++------------------------
1 file changed, 12 insertions(+), 24 deletions(-)
diff --git a/hw/ide/core.c b/hw/ide/core.c
index 1c8f414..03d1cfa 100644
--- a/hw/ide/core.c
+++ b/hw/ide/core.c
@@ -1694,6 +1694,7 @@ static bool ide_cmd_permitted(IDEState *s, uint32_t cmd)
void ide_exec_cmd(IDEBus *bus, uint32_t val)
{
IDEState *s;
+ bool complete;
#if defined(DEBUG_IDE)
printf("ide: CMD=%02x\n", val);
@@ -1708,37 +1709,24 @@ void ide_exec_cmd(IDEBus *bus, uint32_t val)
return;
if (!ide_cmd_permitted(s, val)) {
- goto abort_cmd;
+ ide_abort_command(s);
+ ide_set_irq(s->bus);
+ return;
}
- if (ide_cmd_table[val].handler != NULL) {
- bool complete;
-
- s->status = READY_STAT | BUSY_STAT;
- s->error = 0;
-
- complete = ide_cmd_table[val].handler(s, val);
- if (complete) {
- s->status &= ~BUSY_STAT;
- assert(!!s->error == !!(s->status & ERR_STAT));
+ s->status = READY_STAT | BUSY_STAT;
+ s->error = 0;
- if ((ide_cmd_table[val].flags & SET_DSC) && !s->error) {
- s->status |= SEEK_STAT;
- }
+ complete = ide_cmd_table[val].handler(s, val);
+ if (complete) {
+ s->status &= ~BUSY_STAT;
+ assert(!!s->error == !!(s->status & ERR_STAT));
- ide_set_irq(s->bus);
+ if ((ide_cmd_table[val].flags & SET_DSC) && !s->error) {
+ s->status |= SEEK_STAT;
}
- return;
- }
-
- switch(val) {
- default:
- /* should not be reachable */
- abort_cmd:
- ide_abort_command(s);
ide_set_irq(s->bus);
- break;
}
}
--
1.8.1.4
^ permalink raw reply related [flat|nested] 20+ messages in thread
* Re: [Qemu-devel] [PATCH 01/17] ide: Add handler to ide_cmd_table
2013-06-18 8:25 ` [Qemu-devel] [PATCH 01/17] ide: Add handler to ide_cmd_table Kevin Wolf
@ 2013-06-19 11:45 ` Stefan Hajnoczi
0 siblings, 0 replies; 20+ messages in thread
From: Stefan Hajnoczi @ 2013-06-19 11:45 UTC (permalink / raw)
To: Kevin Wolf; +Cc: qemu-devel, stefanha
On Tue, Jun 18, 2013 at 10:25:55AM +0200, Kevin Wolf wrote:
> As a preparation for moving all IDE commands into their own function
> like in the ATAPI code, introduce a 'handler' callback to ide_cmd_table.
>
> Commands using this new infrastructure get some things handled
> automatically:
>
> * The BSY flag is set before calling the handler (in order to avoid bugs
> like the one fixed in f68ec837) and reset on completion.
>
> * The (obsolete) DSC flag in the status register is set on completion if
> the command is flagged with SET_DSC in the command table
>
> * An IRQ is triggered on completion.
>
> * The error register and the ERR flag in the status register are cleared
> before calling the handler and on completion it is asserted that
> either none or both of them are set.
>
> No commands are converted at this point.
>
> Signed-off-by: Kevin Wolf <kwolf@redhat.com>
> ---
> hw/ide/core.c | 144 +++++++++++++++++++++++++++++++++++-----------------------
> 1 file changed, 86 insertions(+), 58 deletions(-)
>
> diff --git a/hw/ide/core.c b/hw/ide/core.c
> index 9926d92..cd9de14 100644
> --- a/hw/ide/core.c
> +++ b/hw/ide/core.c
> @@ -1010,71 +1010,78 @@ void ide_ioport_write(void *opaque, uint32_t addr, uint32_t val)
> #define HD_CFA_OK (HD_OK | CFA_OK)
> #define ALL_OK (HD_OK | CD_OK | CFA_OK)
>
> +/* Set the Disk Seek Completed status bit during completion */
> +#define SET_DSC (1u << 8)
If DriveKind changes there could be unnoticed collisions and in the
meantime we have empty flags bits...
Creating a single IDEHandlerFlags enum would still depend on
IDEDriveKind constants so I don't see a nicer solution than what you've
done. We can live with this.
^ permalink raw reply [flat|nested] 20+ messages in thread
* Re: [Qemu-devel] [PATCH 00/17] ide: Use ide_cmd_table function pointers for command execution
2013-06-18 8:25 [Qemu-devel] [PATCH 00/17] ide: Use ide_cmd_table function pointers for command execution Kevin Wolf
` (16 preceding siblings ...)
2013-06-18 8:26 ` [Qemu-devel] [PATCH 17/17] ide: Clean up ide_exec_cmd() Kevin Wolf
@ 2013-06-19 12:28 ` Stefan Hajnoczi
17 siblings, 0 replies; 20+ messages in thread
From: Stefan Hajnoczi @ 2013-06-19 12:28 UTC (permalink / raw)
To: Kevin Wolf; +Cc: qemu-devel, stefanha
On Tue, Jun 18, 2013 at 10:25:54AM +0200, Kevin Wolf wrote:
> The ATAPI code has been using a table of callback functions for each
> command for quite a while now, this series does the same for ATA
> commands (which already got the table, but no function pointers, just
> flags)
>
> The main advantage is that we get a more consistent behaviour of the
> commands because we get a clear separation between things that are common
> between all (or most) commands, like setting status register bits or triggering
> IRQs, and can be handled in one central place, and command specific code
> that is refactored into its own function. In the past we've had bugs
> from forgetting to do one of the common things, like setting the BSY
> flag, which will be avoided with the new infrastructure.
>
> It's also a good opportunity to clean up some of the coding style
> problems of the IDE code.
>
> Kevin Wolf (17):
> ide: Add handler to ide_cmd_table
> ide: Convert WIN_DSM to ide_cmd_table handler
> ide: Convert WIN_IDENTIFY to ide_cmd_table handler
> ide: Convert cmd_nop commands to ide_cmd_table handler
> ide: Convert verify commands to ide_cmd_table handler
> ide: Convert read/write multiple commands to ide_cmd_table handler
> ide: Convert PIO read/write commands to ide_cmd_table handler
> ide: Convert DMA read/write commands to ide_cmd_table handler
> ide: Convert READ NATIVE MAX ADDRESS to ide_cmd_table handler
> ide: Convert CHECK POWER MDOE to ide_cmd_table handler
> ide: Convert SET FEATURES to ide_cmd_table handler
> ide: Convert FLUSH CACHE to ide_cmd_table handler
> ide: Convert SEEK to ide_cmd_table handler
> ide: Convert ATAPI commands to ide_cmd_table handler
> ide: Convert CF-ATA commands to ide_cmd_table handler
> ide: Convert SMART commands to ide_cmd_table handler
> ide: Clean up ide_exec_cmd()
>
> hw/ide/core.c | 1242 +++++++++++++++++++++++++++++++--------------------------
> 1 file changed, 669 insertions(+), 573 deletions(-)
>
> --
> 1.8.1.4
Nice series! Thanks, applied to my block tree:
https://github.com/stefanha/qemu/commits/block
Stefan
^ permalink raw reply [flat|nested] 20+ messages in thread
end of thread, other threads:[~2013-06-19 12:28 UTC | newest]
Thread overview: 20+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2013-06-18 8:25 [Qemu-devel] [PATCH 00/17] ide: Use ide_cmd_table function pointers for command execution Kevin Wolf
2013-06-18 8:25 ` [Qemu-devel] [PATCH 01/17] ide: Add handler to ide_cmd_table Kevin Wolf
2013-06-19 11:45 ` Stefan Hajnoczi
2013-06-18 8:25 ` [Qemu-devel] [PATCH 02/17] ide: Convert WIN_DSM to ide_cmd_table handler Kevin Wolf
2013-06-18 8:25 ` [Qemu-devel] [PATCH 03/17] ide: Convert WIN_IDENTIFY " Kevin Wolf
2013-06-18 8:25 ` [Qemu-devel] [PATCH 04/17] ide: Convert cmd_nop commands " Kevin Wolf
2013-06-18 8:25 ` [Qemu-devel] [PATCH 05/17] ide: Convert verify " Kevin Wolf
2013-06-18 8:26 ` [Qemu-devel] [PATCH 06/17] ide: Convert read/write multiple " Kevin Wolf
2013-06-18 8:26 ` [Qemu-devel] [PATCH 07/17] ide: Convert PIO read/write " Kevin Wolf
2013-06-18 8:26 ` [Qemu-devel] [PATCH 08/17] ide: Convert DMA " Kevin Wolf
2013-06-18 8:26 ` [Qemu-devel] [PATCH 09/17] ide: Convert READ NATIVE MAX ADDRESS " Kevin Wolf
2013-06-18 8:26 ` [Qemu-devel] [PATCH 10/17] ide: Convert CHECK POWER MDOE " Kevin Wolf
2013-06-18 8:26 ` [Qemu-devel] [PATCH 11/17] ide: Convert SET FEATURES " Kevin Wolf
2013-06-18 8:26 ` [Qemu-devel] [PATCH 12/17] ide: Convert FLUSH CACHE " Kevin Wolf
2013-06-18 8:26 ` [Qemu-devel] [PATCH 13/17] ide: Convert SEEK " Kevin Wolf
2013-06-18 8:26 ` [Qemu-devel] [PATCH 14/17] ide: Convert ATAPI commands " Kevin Wolf
2013-06-18 8:26 ` [Qemu-devel] [PATCH 15/17] ide: Convert CF-ATA " Kevin Wolf
2013-06-18 8:26 ` [Qemu-devel] [PATCH 16/17] ide: Convert SMART " Kevin Wolf
2013-06-18 8:26 ` [Qemu-devel] [PATCH 17/17] ide: Clean up ide_exec_cmd() Kevin Wolf
2013-06-19 12:28 ` [Qemu-devel] [PATCH 00/17] ide: Use ide_cmd_table function pointers for command execution Stefan Hajnoczi
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).