From: Paolo Bonzini <pbonzini@redhat.com>
To: qemu-devel@nongnu.org
Cc: mst@redhat.com
Subject: [Qemu-devel] [PATCH 19/24] ide: move restart callback to common code
Date: Mon, 28 Oct 2013 17:43:35 +0100 [thread overview]
Message-ID: <1382978620-16641-20-git-send-email-pbonzini@redhat.com> (raw)
In-Reply-To: <1382978620-16641-1-git-send-email-pbonzini@redhat.com>
Signed-off-by: Paolo Bonzini <pbonzini@redhat.com>
---
hw/ide/core.c | 66 ++++++++++++++++++++++++++++++++++++++++++++++++++++-
hw/ide/internal.h | 2 ++
hw/ide/pci.c | 68 -------------------------------------------------------
hw/ide/pci.h | 1 -
4 files changed, 67 insertions(+), 70 deletions(-)
diff --git a/hw/ide/core.c b/hw/ide/core.c
index 5820fad..256f62a 100644
--- a/hw/ide/core.c
+++ b/hw/ide/core.c
@@ -2193,9 +2193,73 @@ static const IDEDMAOps ide_dma_nop_ops = {
.restart_cb = ide_nop_restart,
};
+static void ide_restart_dma(IDEState *s, enum ide_dma_cmd dma_cmd)
+{
+ s->bus->dma->ops->restart_dma(s->bus->dma);
+ s->io_buffer_index = 0;
+ s->io_buffer_size = 0;
+ s->dma_cmd = dma_cmd;
+ ide_start_dma(s, ide_dma_cb);
+}
+
+static void ide_restart_bh(void *opaque)
+{
+ IDEBus *bus = opaque;
+ IDEState *s;
+ bool is_read;
+ int error_status;
+
+ qemu_bh_delete(bus->bh);
+ bus->bh = NULL;
+
+ error_status = bus->error_status;
+ if (bus->error_status == 0) {
+ return;
+ }
+
+ s = idebus_active_if(bus);
+ is_read = (bus->error_status & IDE_RETRY_READ) != 0;
+
+ /* The error status must be cleared before resubmitting the request: The
+ * request may fail again, and this case can only be distinguished if the
+ * called function can set a new error status. */
+ bus->error_status = 0;
+
+ if (error_status & IDE_RETRY_DMA) {
+ if (error_status & IDE_RETRY_TRIM) {
+ ide_restart_dma(s, IDE_DMA_TRIM);
+ } else {
+ ide_restart_dma(s, is_read ? IDE_DMA_READ : IDE_DMA_WRITE);
+ }
+ } else if (error_status & IDE_RETRY_PIO) {
+ if (is_read) {
+ ide_sector_read(s);
+ } else {
+ ide_sector_write(s);
+ }
+ } else if (error_status & IDE_RETRY_FLUSH) {
+ ide_flush_cache(s);
+ }
+}
+
+static void ide_restart_cb(void *opaque, int running, RunState state)
+{
+ IDEBus *bus = opaque;
+
+ if (!running)
+ return;
+
+ if (!bus->bh) {
+ bus->bh = qemu_bh_new(ide_restart_bh, bus);
+ qemu_bh_schedule(bus->bh);
+ }
+}
+
void ide_register_restart_cb(IDEBus *bus)
{
- qemu_add_vm_change_state_handler(bus->dma->ops->restart_cb, bus);
+ if (bus->dma->ops->restart_dma) {
+ qemu_add_vm_change_state_handler(ide_restart_cb, bus);
+ }
}
static IDEDMA ide_dma_nop = {
diff --git a/hw/ide/internal.h b/hw/ide/internal.h
index 678b33c..e24f6cb 100644
--- a/hw/ide/internal.h
+++ b/hw/ide/internal.h
@@ -452,6 +452,8 @@ struct IDEBus {
IDEDevice *master;
IDEDevice *slave;
IDEState ifs[2];
+ QEMUBH *bh;
+
int bus_id;
int max_units;
IDEDMA *dma;
diff --git a/hw/ide/pci.c b/hw/ide/pci.c
index 9d26a26..7568f1e 100644
--- a/hw/ide/pci.c
+++ b/hw/ide/pci.c
@@ -185,73 +185,6 @@ static void bmdma_restart_dma(IDEDMA *dma)
bm->cur_addr = bm->addr;
}
-static void ide_restart_dma(IDEState *s, enum ide_dma_cmd dma_cmd)
-{
- if (s->bus->dma->ops->restart_dma) {
- s->bus->dma->ops->restart_dma(s->bus->dma);
- }
- s->io_buffer_index = 0;
- s->io_buffer_size = 0;
- s->dma_cmd = dma_cmd;
- ide_start_dma(s, ide_dma_cb);
-}
-
-/* TODO This should be common IDE code */
-static void bmdma_restart_bh(void *opaque)
-{
- IDEBus *bus = opaque;
- BMDMAState *bm = DO_UPCAST(BMDMAState, dma, bus->dma);
- IDEState *s;
- bool is_read;
- int error_status;
-
- qemu_bh_delete(bm->bh);
- bm->bh = NULL;
-
- error_status = bus->error_status;
- if (bus->error_status == 0) {
- return;
- }
-
- s = idebus_active_if(bus);
- is_read = (bus->error_status & IDE_RETRY_READ) != 0;
-
- /* The error status must be cleared before resubmitting the request: The
- * request may fail again, and this case can only be distinguished if the
- * called function can set a new error status. */
- bus->error_status = 0;
-
- if (error_status & IDE_RETRY_DMA) {
- if (error_status & IDE_RETRY_TRIM) {
- ide_restart_dma(s, IDE_DMA_TRIM);
- } else {
- ide_restart_dma(s, is_read ? IDE_DMA_READ : IDE_DMA_WRITE);
- }
- } else if (error_status & IDE_RETRY_PIO) {
- if (is_read) {
- ide_sector_read(s);
- } else {
- ide_sector_write(s);
- }
- } else if (error_status & IDE_RETRY_FLUSH) {
- ide_flush_cache(s);
- }
-}
-
-static void bmdma_restart_cb(void *opaque, int running, RunState state)
-{
- IDEBus *bus = opaque;
- BMDMAState *bm = DO_UPCAST(BMDMAState, dma, bus->dma);
-
- if (!running)
- return;
-
- if (!bm->bh) {
- bm->bh = qemu_bh_new(bmdma_restart_bh, &bm->dma);
- qemu_bh_schedule(bm->bh);
- }
-}
-
static void bmdma_cancel(BMDMAState *bm)
{
if (bm->status & BM_STATUS_DMAING) {
@@ -520,7 +453,6 @@ static const struct IDEDMAOps bmdma_ops = {
.restart_dma = bmdma_restart_dma,
.trigger_irq = bmdma_trigger_irq,
.set_inactive = bmdma_set_inactive,
- .restart_cb = bmdma_restart_cb,
.reset = bmdma_reset,
};
diff --git a/hw/ide/pci.h b/hw/ide/pci.h
index 517711f..78e5550 100644
--- a/hw/ide/pci.h
+++ b/hw/ide/pci.h
@@ -28,7 +28,6 @@ typedef struct BMDMAState {
uint32_t nsector;
MemoryRegion addr_ioport;
MemoryRegion extra_io;
- QEMUBH *bh;
qemu_irq irq;
/* Bit 0-2 and 7: BM status register
--
1.8.3.1
next prev parent reply other threads:[~2013-10-28 16:44 UTC|newest]
Thread overview: 49+ messages / expand[flat|nested] mbox.gz Atom feed top
2013-10-28 16:43 [Qemu-devel] [WIP PATCH 00/24] IDE cleanups, initial work on AHCI rerror/werror=stop Paolo Bonzini
2013-10-28 16:43 ` [Qemu-devel] [PATCH 01/24] blkdebug: report errors on flush too Paolo Bonzini
2013-10-30 12:01 ` Kevin Wolf
2013-10-28 16:43 ` [Qemu-devel] [PATCH 02/24] libqtest: return progress from qmp/qmpv Paolo Bonzini
2013-10-30 12:06 ` Kevin Wolf
2013-10-30 12:10 ` Paolo Bonzini
2013-10-28 16:43 ` [Qemu-devel] [PATCH 03/24] libqtest: add QTEST_LOG for debugging qtest testcases Paolo Bonzini
2013-10-30 12:08 ` Kevin Wolf
2013-10-28 16:43 ` [Qemu-devel] [PATCH 04/24] ide-test: add test for werror=stop Paolo Bonzini
2013-10-28 16:43 ` [Qemu-devel] [PATCH 05/24] ide: simplify reset callbacks Paolo Bonzini
2013-10-28 16:43 ` [Qemu-devel] [PATCH 06/24] ide: simplify set_inactive callbacks Paolo Bonzini
2013-10-30 12:20 ` Kevin Wolf
2013-10-28 16:43 ` [Qemu-devel] [PATCH 07/24] ide: simplify async_cmd_done callbacks Paolo Bonzini
2013-10-28 16:43 ` [Qemu-devel] [PATCH 08/24] ide: simplify start_transfer callbacks Paolo Bonzini
2013-10-28 16:43 ` [Qemu-devel] [PATCH 09/24] ide: wrap start_dma callback Paolo Bonzini
2013-10-30 12:29 ` Kevin Wolf
2013-10-30 12:44 ` Paolo Bonzini
2013-10-28 16:43 ` [Qemu-devel] [PATCH 10/24] ide: add trigger_irq callback Paolo Bonzini
2013-10-30 12:47 ` Kevin Wolf
2013-10-30 13:16 ` Paolo Bonzini
2013-10-30 13:34 ` Kevin Wolf
2013-10-30 14:33 ` Paolo Bonzini
2013-10-28 16:43 ` [Qemu-devel] [PATCH 11/24] ide: fold add_status callback into set_inactive Paolo Bonzini
2013-10-28 16:43 ` [Qemu-devel] [PATCH 12/24] ide: move BM_STATUS bits to pci.[ch] Paolo Bonzini
2013-10-28 16:43 ` [Qemu-devel] [PATCH 13/24] ide: move retry constants out of BM_STATUS_* namespace Paolo Bonzini
2013-10-30 12:55 ` Kevin Wolf
2013-10-28 16:43 ` [Qemu-devel] [PATCH 14/24] ide: start extracting ide_restart_dma out of bmdma_restart_dma Paolo Bonzini
2013-10-28 16:43 ` [Qemu-devel] [PATCH 15/24] ide: prepare to move restart to common code Paolo Bonzini
2013-10-30 12:14 ` Paolo Bonzini
2013-10-28 16:43 ` [Qemu-devel] [PATCH 16/24] ide: introduce ide_register_restart_cb Paolo Bonzini
2013-10-30 13:13 ` Kevin Wolf
2013-10-30 13:19 ` Paolo Bonzini
2013-10-28 16:43 ` [Qemu-devel] [PATCH 17/24] ide: do not use BMDMA in restart callback Paolo Bonzini
2013-10-28 16:43 ` [Qemu-devel] [PATCH 18/24] ide: pass IDEBus to the restart_cb Paolo Bonzini
2013-10-30 12:19 ` Paolo Bonzini
2013-10-28 16:43 ` Paolo Bonzini [this message]
2013-10-28 16:43 ` [Qemu-devel] [PATCH 20/24] ide: remove restart_cb callback Paolo Bonzini
2013-10-28 16:43 ` [Qemu-devel] [PATCH 21/24] ide: replace set_unit callback with more IDEBus state Paolo Bonzini
2013-10-28 16:43 ` [Qemu-devel] [PATCH 22/24] ide: place initial state of the current request to IDEBus Paolo Bonzini
2013-10-28 16:43 ` [Qemu-devel] [PATCH 23/24] ide: migrate initial request state via IDEBus Paolo Bonzini
2013-10-28 16:43 ` [Qemu-devel] [PATCH 24/24] ide: commonize io_buffer_index initialization Paolo Bonzini
2013-10-28 17:16 ` [Qemu-devel] [WIP PATCH 00/24] IDE cleanups, initial work on AHCI rerror/werror=stop Michael S. Tsirkin
2013-10-28 17:26 ` Paolo Bonzini
2013-10-28 18:00 ` Michael S. Tsirkin
2013-10-28 18:36 ` Paolo Bonzini
2013-10-28 18:42 ` Michael S. Tsirkin
2013-10-29 9:10 ` Paolo Bonzini
2013-10-29 18:30 ` Kevin Wolf
2013-10-30 16:56 ` Paolo Bonzini
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=1382978620-16641-20-git-send-email-pbonzini@redhat.com \
--to=pbonzini@redhat.com \
--cc=mst@redhat.com \
--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).