* [Qemu-devel] [PATCH] macio: call dma_memory_unmap() at the end of each DMA transfer
@ 2016-06-10 18:26 Mark Cave-Ayland
2016-06-14 0:43 ` David Gibson
0 siblings, 1 reply; 2+ messages in thread
From: Mark Cave-Ayland @ 2016-06-10 18:26 UTC (permalink / raw)
To: qemu-ppc, qemu-devel, david, aurelien
This ensures that the underlying memory is marked dirty once the transfer
is complete and resolves cache coherency problems under MacOS 9.
Signed-off-by: Mark Cave-Ayland <mark.cave-ayland@ilande.co.uk>
---
hw/ide/macio.c | 46 +++++++++++++++++++++++++-------------------
include/hw/ppc/mac_dbdma.h | 5 +++++
2 files changed, 31 insertions(+), 20 deletions(-)
diff --git a/hw/ide/macio.c b/hw/ide/macio.c
index 78c10a0..fa57352 100644
--- a/hw/ide/macio.c
+++ b/hw/ide/macio.c
@@ -66,8 +66,7 @@ static void pmac_dma_read(BlockBackend *blk,
DBDMA_io *io = opaque;
MACIOIDEState *m = io->opaque;
IDEState *s = idebus_active_if(&m->bus);
- dma_addr_t dma_addr, dma_len;
- void *mem;
+ dma_addr_t dma_addr;
int64_t sector_num;
int nsector;
uint64_t align = BDRV_SECTOR_SIZE;
@@ -84,9 +83,10 @@ static void pmac_dma_read(BlockBackend *blk,
sector_num, nsector);
dma_addr = io->addr;
- dma_len = io->len;
- mem = dma_memory_map(&address_space_memory, dma_addr, &dma_len,
- DMA_DIRECTION_FROM_DEVICE);
+ io->dir = DMA_DIRECTION_FROM_DEVICE;
+ io->dma_len = io->len;
+ io->dma_mem = dma_memory_map(&address_space_memory, dma_addr, &io->dma_len,
+ io->dir);
if (offset & (align - 1)) {
head_bytes = offset & (align - 1);
@@ -100,7 +100,7 @@ static void pmac_dma_read(BlockBackend *blk,
offset = offset & ~(align - 1);
}
- qemu_iovec_add(&io->iov, mem, io->len);
+ qemu_iovec_add(&io->iov, io->dma_mem, io->len);
if ((offset + bytes) & (align - 1)) {
tail_bytes = (offset + bytes) & (align - 1);
@@ -130,8 +130,7 @@ static void pmac_dma_write(BlockBackend *blk,
DBDMA_io *io = opaque;
MACIOIDEState *m = io->opaque;
IDEState *s = idebus_active_if(&m->bus);
- dma_addr_t dma_addr, dma_len;
- void *mem;
+ dma_addr_t dma_addr;
int64_t sector_num;
int nsector;
uint64_t align = BDRV_SECTOR_SIZE;
@@ -149,9 +148,10 @@ static void pmac_dma_write(BlockBackend *blk,
sector_num, nsector);
dma_addr = io->addr;
- dma_len = io->len;
- mem = dma_memory_map(&address_space_memory, dma_addr, &dma_len,
- DMA_DIRECTION_TO_DEVICE);
+ io->dir = DMA_DIRECTION_TO_DEVICE;
+ io->dma_len = io->len;
+ io->dma_mem = dma_memory_map(&address_space_memory, dma_addr, &io->dma_len,
+ io->dir);
if (offset & (align - 1)) {
head_bytes = offset & (align - 1);
@@ -163,7 +163,7 @@ static void pmac_dma_write(BlockBackend *blk,
blk_pread(s->blk, (sector_num << 9), &io->head_remainder, align);
qemu_iovec_add(&io->iov, &io->head_remainder, head_bytes);
- qemu_iovec_add(&io->iov, mem, io->len);
+ qemu_iovec_add(&io->iov, io->dma_mem, io->len);
bytes += offset & (align - 1);
offset = offset & ~(align - 1);
@@ -181,7 +181,7 @@ static void pmac_dma_write(BlockBackend *blk,
blk_pread(s->blk, (sector_num << 9), &io->tail_remainder, align);
if (!unaligned_head) {
- qemu_iovec_add(&io->iov, mem, io->len);
+ qemu_iovec_add(&io->iov, io->dma_mem, io->len);
}
qemu_iovec_add(&io->iov, &io->tail_remainder + tail_bytes,
@@ -193,7 +193,7 @@ static void pmac_dma_write(BlockBackend *blk,
}
if (!unaligned_head && !unaligned_tail) {
- qemu_iovec_add(&io->iov, mem, io->len);
+ qemu_iovec_add(&io->iov, io->dma_mem, io->len);
}
s->io_buffer_size -= io->len;
@@ -214,18 +214,18 @@ static void pmac_dma_trim(BlockBackend *blk,
DBDMA_io *io = opaque;
MACIOIDEState *m = io->opaque;
IDEState *s = idebus_active_if(&m->bus);
- dma_addr_t dma_addr, dma_len;
- void *mem;
+ dma_addr_t dma_addr;
qemu_iovec_destroy(&io->iov);
qemu_iovec_init(&io->iov, io->len / MACIO_PAGE_SIZE + 1);
dma_addr = io->addr;
- dma_len = io->len;
- mem = dma_memory_map(&address_space_memory, dma_addr, &dma_len,
- DMA_DIRECTION_TO_DEVICE);
+ io->dir = DMA_DIRECTION_TO_DEVICE;
+ io->dma_len = io->len;
+ io->dma_mem = dma_memory_map(&address_space_memory, dma_addr, &io->dma_len,
+ io->dir);
- qemu_iovec_add(&io->iov, mem, io->len);
+ qemu_iovec_add(&io->iov, io->dma_mem, io->len);
s->io_buffer_size -= io->len;
s->io_buffer_index += io->len;
io->len = 0;
@@ -285,6 +285,9 @@ static void pmac_ide_atapi_transfer_cb(void *opaque, int ret)
return;
done:
+ dma_memory_unmap(&address_space_memory, io->dma_mem, io->dma_len,
+ io->dir, io->dma_len);
+
if (ret < 0) {
block_acct_failed(blk_get_stats(s->blk), &s->acct);
} else {
@@ -351,6 +354,9 @@ static void pmac_ide_transfer_cb(void *opaque, int ret)
return;
done:
+ dma_memory_unmap(&address_space_memory, io->dma_mem, io->dma_len,
+ io->dir, io->dma_len);
+
if (s->dma_cmd == IDE_DMA_READ || s->dma_cmd == IDE_DMA_WRITE) {
if (ret < 0) {
block_acct_failed(blk_get_stats(s->blk), &s->acct);
diff --git a/include/hw/ppc/mac_dbdma.h b/include/hw/ppc/mac_dbdma.h
index 0cce4e8..d15a6cc 100644
--- a/include/hw/ppc/mac_dbdma.h
+++ b/include/hw/ppc/mac_dbdma.h
@@ -24,6 +24,7 @@
#include "exec/memory.h"
#include "qemu/iov.h"
+#include "sysemu/dma.h"
typedef struct DBDMA_io DBDMA_io;
@@ -44,6 +45,10 @@ struct DBDMA_io {
uint8_t head_remainder[0x200];
uint8_t tail_remainder[0x200];
QEMUIOVector iov;
+ /* DMA request */
+ void *dma_mem;
+ dma_addr_t dma_len;
+ DMADirection dir;
};
/*
--
1.7.10.4
^ permalink raw reply related [flat|nested] 2+ messages in thread
* Re: [Qemu-devel] [PATCH] macio: call dma_memory_unmap() at the end of each DMA transfer
2016-06-10 18:26 [Qemu-devel] [PATCH] macio: call dma_memory_unmap() at the end of each DMA transfer Mark Cave-Ayland
@ 2016-06-14 0:43 ` David Gibson
0 siblings, 0 replies; 2+ messages in thread
From: David Gibson @ 2016-06-14 0:43 UTC (permalink / raw)
To: Mark Cave-Ayland; +Cc: qemu-ppc, qemu-devel, aurelien
[-- Attachment #1: Type: text/plain, Size: 6556 bytes --]
On Fri, Jun 10, 2016 at 07:26:37PM +0100, Mark Cave-Ayland wrote:
> This ensures that the underlying memory is marked dirty once the transfer
> is complete and resolves cache coherency problems under MacOS 9.
>
> Signed-off-by: Mark Cave-Ayland <mark.cave-ayland@ilande.co.uk>
Applied to ppc-for-2.7, thanks.
> ---
> hw/ide/macio.c | 46 +++++++++++++++++++++++++-------------------
> include/hw/ppc/mac_dbdma.h | 5 +++++
> 2 files changed, 31 insertions(+), 20 deletions(-)
>
> diff --git a/hw/ide/macio.c b/hw/ide/macio.c
> index 78c10a0..fa57352 100644
> --- a/hw/ide/macio.c
> +++ b/hw/ide/macio.c
> @@ -66,8 +66,7 @@ static void pmac_dma_read(BlockBackend *blk,
> DBDMA_io *io = opaque;
> MACIOIDEState *m = io->opaque;
> IDEState *s = idebus_active_if(&m->bus);
> - dma_addr_t dma_addr, dma_len;
> - void *mem;
> + dma_addr_t dma_addr;
> int64_t sector_num;
> int nsector;
> uint64_t align = BDRV_SECTOR_SIZE;
> @@ -84,9 +83,10 @@ static void pmac_dma_read(BlockBackend *blk,
> sector_num, nsector);
>
> dma_addr = io->addr;
> - dma_len = io->len;
> - mem = dma_memory_map(&address_space_memory, dma_addr, &dma_len,
> - DMA_DIRECTION_FROM_DEVICE);
> + io->dir = DMA_DIRECTION_FROM_DEVICE;
> + io->dma_len = io->len;
> + io->dma_mem = dma_memory_map(&address_space_memory, dma_addr, &io->dma_len,
> + io->dir);
>
> if (offset & (align - 1)) {
> head_bytes = offset & (align - 1);
> @@ -100,7 +100,7 @@ static void pmac_dma_read(BlockBackend *blk,
> offset = offset & ~(align - 1);
> }
>
> - qemu_iovec_add(&io->iov, mem, io->len);
> + qemu_iovec_add(&io->iov, io->dma_mem, io->len);
>
> if ((offset + bytes) & (align - 1)) {
> tail_bytes = (offset + bytes) & (align - 1);
> @@ -130,8 +130,7 @@ static void pmac_dma_write(BlockBackend *blk,
> DBDMA_io *io = opaque;
> MACIOIDEState *m = io->opaque;
> IDEState *s = idebus_active_if(&m->bus);
> - dma_addr_t dma_addr, dma_len;
> - void *mem;
> + dma_addr_t dma_addr;
> int64_t sector_num;
> int nsector;
> uint64_t align = BDRV_SECTOR_SIZE;
> @@ -149,9 +148,10 @@ static void pmac_dma_write(BlockBackend *blk,
> sector_num, nsector);
>
> dma_addr = io->addr;
> - dma_len = io->len;
> - mem = dma_memory_map(&address_space_memory, dma_addr, &dma_len,
> - DMA_DIRECTION_TO_DEVICE);
> + io->dir = DMA_DIRECTION_TO_DEVICE;
> + io->dma_len = io->len;
> + io->dma_mem = dma_memory_map(&address_space_memory, dma_addr, &io->dma_len,
> + io->dir);
>
> if (offset & (align - 1)) {
> head_bytes = offset & (align - 1);
> @@ -163,7 +163,7 @@ static void pmac_dma_write(BlockBackend *blk,
> blk_pread(s->blk, (sector_num << 9), &io->head_remainder, align);
>
> qemu_iovec_add(&io->iov, &io->head_remainder, head_bytes);
> - qemu_iovec_add(&io->iov, mem, io->len);
> + qemu_iovec_add(&io->iov, io->dma_mem, io->len);
>
> bytes += offset & (align - 1);
> offset = offset & ~(align - 1);
> @@ -181,7 +181,7 @@ static void pmac_dma_write(BlockBackend *blk,
> blk_pread(s->blk, (sector_num << 9), &io->tail_remainder, align);
>
> if (!unaligned_head) {
> - qemu_iovec_add(&io->iov, mem, io->len);
> + qemu_iovec_add(&io->iov, io->dma_mem, io->len);
> }
>
> qemu_iovec_add(&io->iov, &io->tail_remainder + tail_bytes,
> @@ -193,7 +193,7 @@ static void pmac_dma_write(BlockBackend *blk,
> }
>
> if (!unaligned_head && !unaligned_tail) {
> - qemu_iovec_add(&io->iov, mem, io->len);
> + qemu_iovec_add(&io->iov, io->dma_mem, io->len);
> }
>
> s->io_buffer_size -= io->len;
> @@ -214,18 +214,18 @@ static void pmac_dma_trim(BlockBackend *blk,
> DBDMA_io *io = opaque;
> MACIOIDEState *m = io->opaque;
> IDEState *s = idebus_active_if(&m->bus);
> - dma_addr_t dma_addr, dma_len;
> - void *mem;
> + dma_addr_t dma_addr;
>
> qemu_iovec_destroy(&io->iov);
> qemu_iovec_init(&io->iov, io->len / MACIO_PAGE_SIZE + 1);
>
> dma_addr = io->addr;
> - dma_len = io->len;
> - mem = dma_memory_map(&address_space_memory, dma_addr, &dma_len,
> - DMA_DIRECTION_TO_DEVICE);
> + io->dir = DMA_DIRECTION_TO_DEVICE;
> + io->dma_len = io->len;
> + io->dma_mem = dma_memory_map(&address_space_memory, dma_addr, &io->dma_len,
> + io->dir);
>
> - qemu_iovec_add(&io->iov, mem, io->len);
> + qemu_iovec_add(&io->iov, io->dma_mem, io->len);
> s->io_buffer_size -= io->len;
> s->io_buffer_index += io->len;
> io->len = 0;
> @@ -285,6 +285,9 @@ static void pmac_ide_atapi_transfer_cb(void *opaque, int ret)
> return;
>
> done:
> + dma_memory_unmap(&address_space_memory, io->dma_mem, io->dma_len,
> + io->dir, io->dma_len);
> +
> if (ret < 0) {
> block_acct_failed(blk_get_stats(s->blk), &s->acct);
> } else {
> @@ -351,6 +354,9 @@ static void pmac_ide_transfer_cb(void *opaque, int ret)
> return;
>
> done:
> + dma_memory_unmap(&address_space_memory, io->dma_mem, io->dma_len,
> + io->dir, io->dma_len);
> +
> if (s->dma_cmd == IDE_DMA_READ || s->dma_cmd == IDE_DMA_WRITE) {
> if (ret < 0) {
> block_acct_failed(blk_get_stats(s->blk), &s->acct);
> diff --git a/include/hw/ppc/mac_dbdma.h b/include/hw/ppc/mac_dbdma.h
> index 0cce4e8..d15a6cc 100644
> --- a/include/hw/ppc/mac_dbdma.h
> +++ b/include/hw/ppc/mac_dbdma.h
> @@ -24,6 +24,7 @@
>
> #include "exec/memory.h"
> #include "qemu/iov.h"
> +#include "sysemu/dma.h"
>
> typedef struct DBDMA_io DBDMA_io;
>
> @@ -44,6 +45,10 @@ struct DBDMA_io {
> uint8_t head_remainder[0x200];
> uint8_t tail_remainder[0x200];
> QEMUIOVector iov;
> + /* DMA request */
> + void *dma_mem;
> + dma_addr_t dma_len;
> + DMADirection dir;
> };
>
> /*
--
David Gibson | I'll have my music baroque, and my code
david AT gibson.dropbear.id.au | minimalist, thank you. NOT _the_ _other_
| _way_ _around_!
http://www.ozlabs.org/~dgibson
[-- Attachment #2: signature.asc --]
[-- Type: application/pgp-signature, Size: 819 bytes --]
^ permalink raw reply [flat|nested] 2+ messages in thread
end of thread, other threads:[~2016-06-14 0:55 UTC | newest]
Thread overview: 2+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2016-06-10 18:26 [Qemu-devel] [PATCH] macio: call dma_memory_unmap() at the end of each DMA transfer Mark Cave-Ayland
2016-06-14 0:43 ` David Gibson
This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.