[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[Qemu-devel] [PATCH v4 06/17] ide: move restart callback to common code
From: |
John Snow |
Subject: |
[Qemu-devel] [PATCH v4 06/17] ide: move restart callback to common code |
Date: |
Mon, 23 Feb 2015 11:17:55 -0500 |
From: Paolo Bonzini <address@hidden>
With BMDMA specific excised from the restart functions,
create a HBA-agnostic restart callback to be shared
between the different HBAs.
Change the callback registered with the vmstate_change
handler to always point to ide_restart_cb instead of
relying on the IDEDMAOps.restart_cb() member.
Signed-off-by: Paolo Bonzini <address@hidden>
Signed-off-by: John Snow <address@hidden>
---
hw/ide/core.c | 80 ++++++++++++++++++++++++++++++++++++++++++++++++++++++-
hw/ide/internal.h | 2 ++
hw/ide/pci.c | 79 ------------------------------------------------------
hw/ide/pci.h | 1 -
4 files changed, 81 insertions(+), 81 deletions(-)
diff --git a/hw/ide/core.c b/hw/ide/core.c
index 9d510b1..a4250f6 100644
--- a/hw/ide/core.c
+++ b/hw/ide/core.c
@@ -2314,6 +2314,10 @@ static int ide_nop_int(IDEDMA *dma, int x)
return 0;
}
+static void ide_nop(IDEDMA *dma)
+{
+}
+
static int32_t ide_nop_int32(IDEDMA *dma, int x)
{
return 0;
@@ -2325,14 +2329,88 @@ static void ide_nop_restart(void *opaque, int x,
RunState y)
static const IDEDMAOps ide_dma_nop_ops = {
.prepare_buf = ide_nop_int32,
+ .restart_dma = ide_nop,
.rw_buf = ide_nop_int,
.set_unit = ide_nop_int,
.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);
+ } else {
+ /*
+ * We've not got any bits to tell us about ATAPI - but
+ * we do have the end_transfer_func that tells us what
+ * we're trying to do.
+ */
+ if (s->end_transfer_func == ide_atapi_cmd) {
+ ide_atapi_dma_restart(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 57ef5ca..9a11c3c 100644
--- a/hw/ide/internal.h
+++ b/hw/ide/internal.h
@@ -456,6 +456,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 45254d4..cd1bbb0 100644
--- a/hw/ide/pci.c
+++ b/hw/ide/pci.c
@@ -194,84 +194,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);
- } else {
- IDEState *s = bmdma_active_if(bm);
-
- /*
- * We've not got any bits to tell us about ATAPI - but
- * we do have the end_transfer_func that tells us what
- * we're trying to do.
- */
- if (s->end_transfer_func == ide_atapi_cmd) {
- ide_atapi_dma_restart(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, bus);
- qemu_bh_schedule(bm->bh);
- }
-}
-
static void bmdma_cancel(BMDMAState *bm)
{
if (bm->status & BM_STATUS_DMAING) {
@@ -535,7 +457,6 @@ static const struct IDEDMAOps bmdma_ops = {
.set_unit = bmdma_set_unit,
.restart_dma = bmdma_restart_dma,
.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 2e9314a..ea4e051 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.9.3
- [Qemu-devel] [PATCH v4 00/17] ide: rerror/werror migration fixes for IDE/ISA and AHCI, John Snow, 2015/02/23
- [Qemu-devel] [PATCH v4 04/17] ide: do not use BMDMA in restart callback, John Snow, 2015/02/23
- [Qemu-devel] [PATCH v4 01/17] ide: start extracting ide_restart_dma out of bmdma_restart_dma, John Snow, 2015/02/23
- [Qemu-devel] [PATCH v4 03/17] ide: introduce ide_register_restart_cb, John Snow, 2015/02/23
- [Qemu-devel] [PATCH v4 08/17] ide: replace set_unit callback with more IDEBus state, John Snow, 2015/02/23
- [Qemu-devel] [PATCH v4 02/17] ide: prepare to move restart to common code, John Snow, 2015/02/23
- [Qemu-devel] [PATCH v4 09/17] ide: place initial state of the current request to IDEBus, John Snow, 2015/02/23
- [Qemu-devel] [PATCH v4 06/17] ide: move restart callback to common code,
John Snow <=
- [Qemu-devel] [PATCH v4 10/17] ide: migrate initial request state via IDEBus, John Snow, 2015/02/23
- [Qemu-devel] [PATCH v4 05/17] ide: pass IDEBus to the restart_cb, John Snow, 2015/02/23
- [Qemu-devel] [PATCH v4 07/17] ide: remove restart_cb callback, John Snow, 2015/02/23
- [Qemu-devel] [PATCH v4 15/17] ahci: add support for restarting non-queued commands, John Snow, 2015/02/23
- [Qemu-devel] [PATCH v4 13/17] ide: support PIO restart for the ISA controller, John Snow, 2015/02/23
- [Qemu-devel] [PATCH v4 14/17] ahci: Migrate IDEStatus, John Snow, 2015/02/23
- [Qemu-devel] [PATCH v4 17/17] qtest/ide: Test flush / retry for ISA and PCI, John Snow, 2015/02/23
- [Qemu-devel] [PATCH v4 12/17] ide: make more functions static, John Snow, 2015/02/23
- [Qemu-devel] [PATCH v4 16/17] ahci: Recompute cur_cmd on migrate post load, John Snow, 2015/02/23
- [Qemu-devel] [PATCH v4 11/17] ide: commonize io_buffer_index initialization, John Snow, 2015/02/23