From: Andrea Arcangeli <aarcange@redhat.com>
To: Anthony Liguori <anthony@codemonkey.ws>
Cc: chrisw@redhat.com, avi@redhat.com,
Gerd Hoffmann <kraxel@redhat.com>,
kvm@vger.kernel.org, qemu-devel@nongnu.org
Subject: [Qemu-devel] [PATCH 2 of 5] add can_dma/post_dma for direct IO
Date: Fri, 12 Dec 2008 19:16:44 +0100 [thread overview]
Message-ID: <cc5d812eb9369a7ad2ef.1229105804@duo.random> (raw)
In-Reply-To: <patchbomb.1229105802@duo.random>
From: Andrea Arcangeli <aarcange@redhat.com>
Add can_dma and post_dma methods needed before/after direct IO to guest
physical memory.
Signed-off-by: Andrea Arcangeli <aarcange@redhat.com>
---
diff --git a/cpu-all.h b/cpu-all.h
--- a/cpu-all.h
+++ b/cpu-all.h
@@ -912,6 +912,11 @@ CPUReadMemoryFunc **cpu_get_io_memory_re
void cpu_physical_memory_rw(target_phys_addr_t addr, uint8_t *buf,
size_t len, int is_write);
+void cpu_physical_memory_write_post_dma(target_phys_addr_t addr,
+ size_t len);
+uint8_t *cpu_physical_memory_can_dma(target_phys_addr_t addr,
+ size_t len, int is_write,
+ int alignment);
static inline void cpu_physical_memory_read(target_phys_addr_t addr,
uint8_t *buf, size_t len)
{
diff --git a/exec.c b/exec.c
--- a/exec.c
+++ b/exec.c
@@ -2974,6 +2974,111 @@ void cpu_physical_memory_rw(target_phys_
}
}
+uint8_t *cpu_physical_memory_can_dma(target_phys_addr_t addr,
+ size_t len, int is_write,
+ int alignment)
+{
+ int l, first = 1;
+ uint8_t *ptr = NULL;
+ target_phys_addr_t page;
+ unsigned long pd, pd_first = 0;
+ PhysPageDesc *p;
+
+ if (len & (alignment-1))
+ goto out;
+
+ while (len > 0) {
+ page = addr & TARGET_PAGE_MASK;
+ p = phys_page_find(page >> TARGET_PAGE_BITS);
+
+ l = (page + TARGET_PAGE_SIZE) - addr;
+ if (l > len)
+ l = len;
+
+ if (!p)
+ pd = IO_MEM_UNASSIGNED;
+ else
+ pd = p->phys_offset;
+
+ if (is_write) {
+ if ((pd & ~TARGET_PAGE_MASK) != IO_MEM_RAM)
+ return NULL;
+ } else {
+ if ((pd & ~TARGET_PAGE_MASK) > IO_MEM_ROM &&
+ !(pd & IO_MEM_ROMD))
+ return NULL;
+ }
+
+ if (first) {
+ first = 0;
+ ptr = phys_ram_base + (pd & TARGET_PAGE_MASK) +
+ (addr & ~TARGET_PAGE_MASK);
+ if ((unsigned long)ptr & (alignment-1))
+ return NULL;
+ pd_first = pd;
+ }
+
+ /* nonlinear range */
+ if (pd_first != pd)
+ return NULL;
+ pd_first += TARGET_PAGE_SIZE;
+
+ len -= l;
+ addr += l;
+ }
+
+out:
+ return ptr;
+}
+
+void cpu_physical_memory_write_post_dma(target_phys_addr_t addr,
+ size_t len)
+{
+ int l;
+ uint8_t *ptr;
+ target_phys_addr_t page;
+ unsigned long pd;
+ PhysPageDesc *p;
+
+ while (len > 0) {
+ page = addr & TARGET_PAGE_MASK;
+
+ l = (page + TARGET_PAGE_SIZE) - addr;
+ if (l > len)
+ l = len;
+
+ p = phys_page_find(page >> TARGET_PAGE_BITS);
+ if (!p)
+ pd = IO_MEM_UNASSIGNED;
+ else
+ pd = p->phys_offset;
+
+ if ((pd & ~TARGET_PAGE_MASK) != IO_MEM_RAM) {
+ printf("ERROR cpu_physical_memory_post_dma: memory layout changed\n");
+ continue;
+ } else {
+ unsigned long addr1;
+ addr1 = (pd & TARGET_PAGE_MASK) + (addr & ~TARGET_PAGE_MASK);
+ /* RAM case */
+ ptr = phys_ram_base + addr1;
+ if (!cpu_physical_memory_is_dirty(addr1)) {
+ /* invalidate code */
+ tb_invalidate_phys_page_range(addr1, addr1 + l, 0);
+ /* set dirty bit */
+ phys_ram_dirty[addr1 >> TARGET_PAGE_BITS] |=
+ (0xff & ~CODE_DIRTY_FLAG);
+ }
+ /* qemu doesn't execute guest code directly, but kvm does
+ therefore fluch instruction caches */
+ if (kvm_enabled())
+ flush_icache_range((unsigned long)ptr,
+ ((unsigned long)ptr)+l);
+ }
+ len -= l;
+ addr += l;
+ }
+}
+
/* used for ROM loading : can write in RAM and ROM */
void cpu_physical_memory_write_rom(target_phys_addr_t addr,
const uint8_t *buf, int len)
next prev parent reply other threads:[~2008-12-12 18:18 UTC|newest]
Thread overview: 58+ messages / expand[flat|nested] mbox.gz Atom feed top
2008-12-12 18:16 [Qemu-devel] [PATCH 0 of 5] dma api v3 Andrea Arcangeli
2008-12-12 18:16 ` [Qemu-devel] [PATCH 1 of 5] fix cpu_physical_memory len Andrea Arcangeli
2008-12-12 19:06 ` [Qemu-devel] " Anthony Liguori
2008-12-12 19:26 ` Andrea Arcangeli
2008-12-12 18:16 ` Andrea Arcangeli [this message]
2008-12-12 19:00 ` [Qemu-devel] [PATCH 2 of 5] add can_dma/post_dma for direct IO Blue Swirl
2008-12-12 19:18 ` Anthony Liguori
2008-12-12 20:05 ` Blue Swirl
2008-12-12 20:10 ` Anthony Liguori
2008-12-12 19:15 ` [Qemu-devel] " Anthony Liguori
2008-12-12 19:37 ` Andrea Arcangeli
2008-12-12 20:09 ` Anthony Liguori
2008-12-12 20:25 ` Gerd Hoffmann
2008-12-12 19:39 ` Anthony Liguori
2008-12-13 9:22 ` Avi Kivity
2008-12-13 16:45 ` Anthony Liguori
2008-12-13 19:48 ` Avi Kivity
2008-12-13 21:07 ` Anthony Liguori
2008-12-14 6:03 ` Avi Kivity
2008-12-14 19:10 ` Anthony Liguori
2008-12-14 19:49 ` Avi Kivity
2008-12-14 23:08 ` Anthony Liguori
2008-12-15 0:57 ` Paul Brook
2008-12-15 2:09 ` Anthony Liguori
2008-12-15 6:23 ` Avi Kivity
2008-12-15 18:35 ` Blue Swirl
2008-12-15 22:06 ` Anthony Liguori
2008-12-16 9:41 ` Avi Kivity
2008-12-16 16:55 ` Blue Swirl
2008-12-16 17:09 ` Avi Kivity
2008-12-16 17:48 ` Anthony Liguori
2008-12-16 18:11 ` Blue Swirl
2008-12-16 15:57 ` Blue Swirl
2008-12-16 16:29 ` Paul Brook
2008-12-16 16:35 ` Blue Swirl
2008-12-14 17:30 ` Jamie Lokier
2008-12-13 14:39 ` Andrea Arcangeli
2008-12-13 16:46 ` Anthony Liguori
2008-12-13 16:53 ` Andrea Arcangeli
2008-12-13 17:54 ` Andreas Färber
2008-12-13 21:11 ` Anthony Liguori
2008-12-14 16:47 ` Andrea Arcangeli
2008-12-14 17:01 ` Avi Kivity
2008-12-14 17:15 ` Andrea Arcangeli
2008-12-14 19:59 ` Avi Kivity
2008-12-22 16:44 ` Ian Jackson
2008-12-22 19:44 ` Avi Kivity
2008-12-23 0:03 ` Thiemo Seufer
2008-12-23 1:02 ` Andrea Arcangeli
2008-12-23 17:31 ` Avi Kivity
2008-12-22 19:46 ` Avi Kivity
2009-01-05 10:27 ` Gerd Hoffmann
2008-12-13 22:47 ` Anthony Liguori
2008-12-14 6:07 ` Avi Kivity
2008-12-12 18:16 ` [Qemu-devel] [PATCH 3 of 5] rename dma.c to isa_dma.c Andrea Arcangeli
2008-12-12 18:16 ` [Qemu-devel] [PATCH 4 of 5] dma api Andrea Arcangeli
2008-12-12 18:55 ` Blue Swirl
2008-12-12 18:16 ` [Qemu-devel] [PATCH 5 of 5] bdrv_aio_readv/writev Andrea Arcangeli
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=cc5d812eb9369a7ad2ef.1229105804@duo.random \
--to=aarcange@redhat.com \
--cc=anthony@codemonkey.ws \
--cc=avi@redhat.com \
--cc=chrisw@redhat.com \
--cc=kraxel@redhat.com \
--cc=kvm@vger.kernel.org \
--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).