Patchwork [04/10] ide: add DMA hooks to bus ops

login
register
mail settings
Submitter Alexander Graf
Date Dec. 1, 2010, 7:17 p.m.
Message ID <1291231032-21150-5-git-send-email-agraf@suse.de>
Download mbox | patch
Permalink /patch/73900/
State New
Headers show

Comments

Alexander Graf - Dec. 1, 2010, 7:17 p.m.
For DMA operations, we need to hook into even more IDE functionality.

This patch adds the respective hooking points, allowing us to handle
SG lists ourselves in the AHCI code.

Signed-off-by: Roland Elek <elek.roland@gmail.com>
Signed-off-by: Alexander Graf <agraf@suse.de>

---

v1 -> v2:

  - make dma hooks explicit by putting them into ops struct (stefanha)

v6 -> v7:

  - rename IDEBusOps (stefanha)
---
 hw/ide/core.c     |    9 ++++++---
 hw/ide/internal.h |    4 ++++
 2 files changed, 10 insertions(+), 3 deletions(-)
Stefan Hajnoczi - Dec. 2, 2010, 10:17 a.m.
On Wed, Dec 1, 2010 at 7:17 PM, Alexander Graf <agraf@suse.de> wrote:
> For DMA operations, we need to hook into even more IDE functionality.
>
> This patch adds the respective hooking points, allowing us to handle
> SG lists ourselves in the AHCI code.
>
> Signed-off-by: Roland Elek <elek.roland@gmail.com>
> Signed-off-by: Alexander Graf <agraf@suse.de>
>
> ---
>
> v1 -> v2:
>
>  - make dma hooks explicit by putting them into ops struct (stefanha)
>
> v6 -> v7:
>
>  - rename IDEBusOps (stefanha)
> ---
>  hw/ide/core.c     |    9 ++++++---
>  hw/ide/internal.h |    4 ++++
>  2 files changed, 10 insertions(+), 3 deletions(-)

Reviewed-by: Stefan Hajnoczi <stefanha@linux.vnet.ibm.com>

Patch

diff --git a/hw/ide/core.c b/hw/ide/core.c
index 3912c21..1680a38 100644
--- a/hw/ide/core.c
+++ b/hw/ide/core.c
@@ -614,7 +614,7 @@  static void ide_read_dma_cb(void *opaque, int ret)
     n = s->nsector;
     s->io_buffer_index = 0;
     s->io_buffer_size = n * 512;
-    if (dma_buf_prepare(bm, 1) == 0)
+    if (s->bus->ops->dma_prepare(bm, 1) == 0)
         goto eot;
 #ifdef DEBUG_AIO
     printf("aio_read: sector_num=%" PRId64 " n=%d\n", sector_num, n);
@@ -756,7 +756,7 @@  static void ide_write_dma_cb(void *opaque, int ret)
     n = s->nsector;
     s->io_buffer_size = n * 512;
     /* launch next transfer */
-    if (dma_buf_prepare(bm, 0) == 0)
+    if (s->bus->ops->dma_prepare(bm, 0) == 0)
         goto eot;
 #ifdef DEBUG_AIO
     printf("aio_write: sector_num=%" PRId64 " n=%d\n", sector_num, n);
@@ -1064,7 +1064,7 @@  static void ide_atapi_cmd_read_dma_cb(void *opaque, int ret)
 	    s->lba += n;
 	}
         s->packet_transfer_size -= s->io_buffer_size;
-        if (dma_buf_rw(bm, 1) == 0)
+        if (s->bus->ops->dma_rw(bm, 1) == 0)
             goto eot;
     }
 
@@ -2716,6 +2716,7 @@  int ide_init_drive(IDEState *s, BlockDriverState *bs,
     } else {
         pstrcpy(s->version, sizeof(s->version), QEMU_VERSION);
     }
+
     ide_reset(s);
     bdrv_set_removable(bs, s->drive_kind == IDE_CD);
     return 0;
@@ -2741,6 +2742,8 @@  static IDEBusOps pata_bus_ops = {
     .transfer_start = pata_transfer_start,
     .set_irq = pata_set_irq,
     .dma_start = pata_dma_start,
+    .dma_prepare = dma_buf_prepare,
+    .dma_rw = dma_buf_rw,
 };
 
 void ide_init2(IDEBus *bus, qemu_irq irq)
diff --git a/hw/ide/internal.h b/hw/ide/internal.h
index f5d6ba7..1b5e738 100644
--- a/hw/ide/internal.h
+++ b/hw/ide/internal.h
@@ -375,6 +375,8 @@  typedef void TransferStartFunc(IDEState *,
                              EndTransferFunc *);
 typedef void IRQSetFunc(IDEBus *);
 typedef void DMAStartFunc(IDEState *, BlockDriverCompletionFunc *);
+typedef int DMAPrepareFunc(BMDMAState *, int);
+typedef int DMARWFunc(BMDMAState *, int);
 
 /* NOTE: IDEState represents in fact one drive */
 struct IDEState {
@@ -458,6 +460,8 @@  struct IDEBusOps {
     TransferStartFunc *transfer_start;
     IRQSetFunc *set_irq;
     DMAStartFunc *dma_start;
+    DMAPrepareFunc *dma_prepare;
+    DMARWFunc *dma_rw;
 };
 
 struct IDEBus {