All of lore.kernel.org
 help / color / mirror / Atom feed
From: Eduard - Gabriel Munteanu <eduard.munteanu@linux360.ro>
To: joro@8bytes.org
Cc: avi@redhat.com, paul@codesourcery.com, kvm@vger.kernel.org,
	qemu-devel@nongnu.org,
	Eduard - Gabriel Munteanu <eduard.munteanu@linux360.ro>
Subject: [RFC PATCH 4/7] ide: IOMMU support
Date: Wed, 14 Jul 2010 08:45:04 +0300	[thread overview]
Message-ID: <1279086307-9596-5-git-send-email-eduard.munteanu@linux360.ro> (raw)
In-Reply-To: <1279086307-9596-1-git-send-email-eduard.munteanu@linux360.ro>

Memory accesses must go through the IOMMU layer.

Signed-off-by: Eduard - Gabriel Munteanu <eduard.munteanu@linux360.ro>
---
 hw/ide/core.c |   46 +++++++++++++++++++++++++++++++---------------
 1 files changed, 31 insertions(+), 15 deletions(-)

diff --git a/hw/ide/core.c b/hw/ide/core.c
index 0b3b7c2..7f8f7df 100644
--- a/hw/ide/core.c
+++ b/hw/ide/core.c
@@ -26,6 +26,7 @@
 #include <hw/pc.h>
 #include <hw/pci.h>
 #include <hw/scsi.h>
+#include <hw/iommu.h>
 #include "qemu-timer.h"
 #include "sysemu.h"
 #include "dma.h"
@@ -433,7 +434,12 @@ static int dma_buf_prepare(BMDMAState *bm, int is_write)
         uint32_t addr;
         uint32_t size;
     } prd;
-    int l, len;
+    int l, len, err, io_len;
+    struct iommu *iommu;
+    DeviceState *dev;
+    target_phys_addr_t io_addr;
+
+    iommu = iommu_get(s->bus->qbus.parent, &dev);
 
     qemu_sglist_init(&s->sg, s->nsector / (IDE_PAGE_SIZE / 512) + 1);
     s->io_buffer_size = 0;
@@ -443,7 +449,7 @@ static int dma_buf_prepare(BMDMAState *bm, int is_write)
             if (bm->cur_prd_last ||
                 (bm->cur_addr - bm->addr) >= IDE_PAGE_SIZE)
                 return s->io_buffer_size != 0;
-            cpu_physical_memory_read(bm->cur_addr, (uint8_t *)&prd, 8);
+            err = iommu_read(iommu, dev, bm->cur_addr, (uint8_t *)&prd, 8);
             bm->cur_addr += 8;
             prd.addr = le32_to_cpu(prd.addr);
             prd.size = le32_to_cpu(prd.size);
@@ -455,11 +461,22 @@ static int dma_buf_prepare(BMDMAState *bm, int is_write)
             bm->cur_prd_last = (prd.size & 0x80000000);
         }
         l = bm->cur_prd_len;
-        if (l > 0) {
-            qemu_sglist_add(&s->sg, bm->cur_prd_addr, l);
-            bm->cur_prd_addr += l;
-            bm->cur_prd_len -= l;
-            s->io_buffer_size += l;
+        while (l > 0) {
+            /*
+             * In case translation / access checking fails no
+             * transfer happens but we pretend it went through.
+             */
+            err = iommu_translate(iommu, dev, bm->cur_prd_addr,
+                                  &io_addr, &io_len, !is_write);
+            if (!err) {
+                if (io_len > l)
+                    io_len = l;
+                qemu_sglist_add(&s->sg, io_addr, io_len);
+            }
+            bm->cur_prd_addr += io_len;
+            bm->cur_prd_len -= io_len;
+            s->io_buffer_size += io_len;
+            l -= io_len;
         }
     }
     return 1;
@@ -516,6 +533,10 @@ static int dma_buf_rw(BMDMAState *bm, int is_write)
         uint32_t size;
     } prd;
     int l, len;
+    struct iommu *iommu;
+    DeviceState *dev;
+
+    iommu = iommu_get(s->bus->qbus.parent, &dev);
 
     for(;;) {
         l = s->io_buffer_size - s->io_buffer_index;
@@ -526,7 +547,7 @@ static int dma_buf_rw(BMDMAState *bm, int is_write)
             if (bm->cur_prd_last ||
                 (bm->cur_addr - bm->addr) >= IDE_PAGE_SIZE)
                 return 0;
-            cpu_physical_memory_read(bm->cur_addr, (uint8_t *)&prd, 8);
+            iommu_read(iommu, dev, bm->cur_addr, (uint8_t *)&prd, 8);
             bm->cur_addr += 8;
             prd.addr = le32_to_cpu(prd.addr);
             prd.size = le32_to_cpu(prd.size);
@@ -540,13 +561,8 @@ static int dma_buf_rw(BMDMAState *bm, int is_write)
         if (l > bm->cur_prd_len)
             l = bm->cur_prd_len;
         if (l > 0) {
-            if (is_write) {
-                cpu_physical_memory_write(bm->cur_prd_addr,
-                                          s->io_buffer + s->io_buffer_index, l);
-            } else {
-                cpu_physical_memory_read(bm->cur_prd_addr,
-                                          s->io_buffer + s->io_buffer_index, l);
-            }
+            iommu_rw(iommu, dev, bm->cur_prd_addr,
+                     s->io_buffer + s->io_buffer_index, l, is_write);
             bm->cur_prd_addr += l;
             bm->cur_prd_len -= l;
             s->io_buffer_index += l;
-- 
1.7.1


WARNING: multiple messages have this Message-ID (diff)
From: Eduard - Gabriel Munteanu <eduard.munteanu@linux360.ro>
To: joro@8bytes.org
Cc: qemu-devel@nongnu.org,
	Eduard - Gabriel Munteanu <eduard.munteanu@linux360.ro>,
	avi@redhat.com, kvm@vger.kernel.org, paul@codesourcery.com
Subject: [Qemu-devel] [RFC PATCH 4/7] ide: IOMMU support
Date: Wed, 14 Jul 2010 08:45:04 +0300	[thread overview]
Message-ID: <1279086307-9596-5-git-send-email-eduard.munteanu@linux360.ro> (raw)
In-Reply-To: <1279086307-9596-1-git-send-email-eduard.munteanu@linux360.ro>

Memory accesses must go through the IOMMU layer.

Signed-off-by: Eduard - Gabriel Munteanu <eduard.munteanu@linux360.ro>
---
 hw/ide/core.c |   46 +++++++++++++++++++++++++++++++---------------
 1 files changed, 31 insertions(+), 15 deletions(-)

diff --git a/hw/ide/core.c b/hw/ide/core.c
index 0b3b7c2..7f8f7df 100644
--- a/hw/ide/core.c
+++ b/hw/ide/core.c
@@ -26,6 +26,7 @@
 #include <hw/pc.h>
 #include <hw/pci.h>
 #include <hw/scsi.h>
+#include <hw/iommu.h>
 #include "qemu-timer.h"
 #include "sysemu.h"
 #include "dma.h"
@@ -433,7 +434,12 @@ static int dma_buf_prepare(BMDMAState *bm, int is_write)
         uint32_t addr;
         uint32_t size;
     } prd;
-    int l, len;
+    int l, len, err, io_len;
+    struct iommu *iommu;
+    DeviceState *dev;
+    target_phys_addr_t io_addr;
+
+    iommu = iommu_get(s->bus->qbus.parent, &dev);
 
     qemu_sglist_init(&s->sg, s->nsector / (IDE_PAGE_SIZE / 512) + 1);
     s->io_buffer_size = 0;
@@ -443,7 +449,7 @@ static int dma_buf_prepare(BMDMAState *bm, int is_write)
             if (bm->cur_prd_last ||
                 (bm->cur_addr - bm->addr) >= IDE_PAGE_SIZE)
                 return s->io_buffer_size != 0;
-            cpu_physical_memory_read(bm->cur_addr, (uint8_t *)&prd, 8);
+            err = iommu_read(iommu, dev, bm->cur_addr, (uint8_t *)&prd, 8);
             bm->cur_addr += 8;
             prd.addr = le32_to_cpu(prd.addr);
             prd.size = le32_to_cpu(prd.size);
@@ -455,11 +461,22 @@ static int dma_buf_prepare(BMDMAState *bm, int is_write)
             bm->cur_prd_last = (prd.size & 0x80000000);
         }
         l = bm->cur_prd_len;
-        if (l > 0) {
-            qemu_sglist_add(&s->sg, bm->cur_prd_addr, l);
-            bm->cur_prd_addr += l;
-            bm->cur_prd_len -= l;
-            s->io_buffer_size += l;
+        while (l > 0) {
+            /*
+             * In case translation / access checking fails no
+             * transfer happens but we pretend it went through.
+             */
+            err = iommu_translate(iommu, dev, bm->cur_prd_addr,
+                                  &io_addr, &io_len, !is_write);
+            if (!err) {
+                if (io_len > l)
+                    io_len = l;
+                qemu_sglist_add(&s->sg, io_addr, io_len);
+            }
+            bm->cur_prd_addr += io_len;
+            bm->cur_prd_len -= io_len;
+            s->io_buffer_size += io_len;
+            l -= io_len;
         }
     }
     return 1;
@@ -516,6 +533,10 @@ static int dma_buf_rw(BMDMAState *bm, int is_write)
         uint32_t size;
     } prd;
     int l, len;
+    struct iommu *iommu;
+    DeviceState *dev;
+
+    iommu = iommu_get(s->bus->qbus.parent, &dev);
 
     for(;;) {
         l = s->io_buffer_size - s->io_buffer_index;
@@ -526,7 +547,7 @@ static int dma_buf_rw(BMDMAState *bm, int is_write)
             if (bm->cur_prd_last ||
                 (bm->cur_addr - bm->addr) >= IDE_PAGE_SIZE)
                 return 0;
-            cpu_physical_memory_read(bm->cur_addr, (uint8_t *)&prd, 8);
+            iommu_read(iommu, dev, bm->cur_addr, (uint8_t *)&prd, 8);
             bm->cur_addr += 8;
             prd.addr = le32_to_cpu(prd.addr);
             prd.size = le32_to_cpu(prd.size);
@@ -540,13 +561,8 @@ static int dma_buf_rw(BMDMAState *bm, int is_write)
         if (l > bm->cur_prd_len)
             l = bm->cur_prd_len;
         if (l > 0) {
-            if (is_write) {
-                cpu_physical_memory_write(bm->cur_prd_addr,
-                                          s->io_buffer + s->io_buffer_index, l);
-            } else {
-                cpu_physical_memory_read(bm->cur_prd_addr,
-                                          s->io_buffer + s->io_buffer_index, l);
-            }
+            iommu_rw(iommu, dev, bm->cur_prd_addr,
+                     s->io_buffer + s->io_buffer_index, l, is_write);
             bm->cur_prd_addr += l;
             bm->cur_prd_len -= l;
             s->io_buffer_index += l;
-- 
1.7.1

  parent reply	other threads:[~2010-07-14  5:46 UTC|newest]

Thread overview: 83+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2010-07-14  5:45 [RFC PATCH 0/7] AMD IOMMU emulation patchset Eduard - Gabriel Munteanu
2010-07-14  5:45 ` [Qemu-devel] " Eduard - Gabriel Munteanu
2010-07-14  5:45 ` [RFC PATCH 1/7] Generic IOMMU layer Eduard - Gabriel Munteanu
2010-07-14  5:45   ` [Qemu-devel] " Eduard - Gabriel Munteanu
2010-07-14  6:07   ` malc
2010-07-14  6:07     ` [Qemu-devel] " malc
2010-07-14 22:47     ` Eduard - Gabriel Munteanu
2010-07-14 22:47       ` Eduard - Gabriel Munteanu
2010-07-14  5:45 ` [RFC PATCH 2/7] AMD IOMMU emulation Eduard - Gabriel Munteanu
2010-07-14  5:45   ` [Qemu-devel] " Eduard - Gabriel Munteanu
2010-07-14 20:16   ` Paul Brook
2010-07-14 20:16     ` Paul Brook
2010-07-14  5:45 ` [RFC PATCH 3/7] pci: call IOMMU hooks Eduard - Gabriel Munteanu
2010-07-14  5:45   ` [Qemu-devel] " Eduard - Gabriel Munteanu
2010-07-14  7:37   ` Isaku Yamahata
2010-07-14  7:37     ` Isaku Yamahata
2010-07-14 22:50     ` Eduard - Gabriel Munteanu
2010-07-14 22:50       ` Eduard - Gabriel Munteanu
2010-07-14  5:45 ` Eduard - Gabriel Munteanu [this message]
2010-07-14  5:45   ` [Qemu-devel] [RFC PATCH 4/7] ide: IOMMU support Eduard - Gabriel Munteanu
2010-07-14 13:53   ` Paul Brook
2010-07-14 13:53     ` [Qemu-devel] " Paul Brook
2010-07-14 18:33     ` Joerg Roedel
2010-07-14 18:33       ` [Qemu-devel] " Joerg Roedel
2010-07-14 20:13       ` Paul Brook
2010-07-14 21:29         ` Anthony Liguori
2010-07-14 21:29           ` Anthony Liguori
2010-07-14 22:24           ` Chris Wright
2010-07-14 22:24             ` Chris Wright
2010-07-15 10:28             ` Paul Brook
2010-07-15 10:28               ` Paul Brook
2010-07-15 16:52               ` Chris Wright
2010-07-15 16:52                 ` Chris Wright
2010-07-15 17:02                 ` Avi Kivity
2010-07-15 17:02                   ` Avi Kivity
2010-07-15 17:17                   ` Chris Wright
2010-07-15 17:17                     ` Chris Wright
2010-07-15 17:22                     ` Avi Kivity
2010-07-15 17:22                       ` Avi Kivity
2010-07-15 17:25                       ` Chris Wright
2010-07-15 17:25                         ` Chris Wright
2010-07-15 17:27                     ` Eduard - Gabriel Munteanu
2010-07-15 17:27                       ` Eduard - Gabriel Munteanu
2010-07-15 17:22                   ` Joerg Roedel
2010-07-15 17:22                     ` Joerg Roedel
2010-07-15 17:14                 ` Chris Wright
2010-07-15 17:14                   ` Chris Wright
2010-07-15  9:10           ` Joerg Roedel
2010-07-15  9:10             ` Joerg Roedel
2010-07-15 12:45             ` Anthony Liguori
2010-07-15 12:45               ` Anthony Liguori
2010-07-15 14:45               ` Joerg Roedel
2010-07-15 14:45                 ` Joerg Roedel
2010-07-15 16:45               ` Eduard - Gabriel Munteanu
2010-07-15 16:45                 ` Eduard - Gabriel Munteanu
2010-07-15 17:42                 ` Anthony Liguori
2010-07-15 17:42                   ` Anthony Liguori
2010-07-15 10:33           ` Paul Brook
2010-07-15 10:33             ` Paul Brook
2010-07-15 12:42             ` Anthony Liguori
2010-07-15 12:42               ` Anthony Liguori
2010-07-15 14:02               ` Paul Brook
2010-07-15 14:02                 ` Paul Brook
2010-07-14 23:39         ` Eduard - Gabriel Munteanu
2010-07-14 23:39           ` Eduard - Gabriel Munteanu
2010-07-15  9:22         ` Joerg Roedel
2010-07-15  9:22           ` Joerg Roedel
2010-07-15 10:49           ` Paul Brook
2010-07-15 10:49             ` Paul Brook
2010-07-15 14:59             ` Joerg Roedel
2010-07-15 14:59               ` Joerg Roedel
2010-07-14 23:11     ` Eduard - Gabriel Munteanu
2010-07-14 23:11       ` [Qemu-devel] " Eduard - Gabriel Munteanu
2010-07-15 10:58       ` Paul Brook
2010-07-15 10:58         ` [Qemu-devel] " Paul Brook
2010-07-14  5:45 ` [RFC PATCH 5/7] rtl8139: " Eduard - Gabriel Munteanu
2010-07-14  5:45   ` [Qemu-devel] " Eduard - Gabriel Munteanu
2010-07-14  5:45 ` [RFC PATCH 6/7] eepro100: " Eduard - Gabriel Munteanu
2010-07-14  5:45   ` [Qemu-devel] " Eduard - Gabriel Munteanu
2010-07-14  5:45 ` [RFC PATCH 7/7] ac97: " Eduard - Gabriel Munteanu
2010-07-14  5:45   ` [Qemu-devel] " Eduard - Gabriel Munteanu
2010-07-14  6:09   ` malc
2010-07-14  6:09     ` [Qemu-devel] " malc

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=1279086307-9596-5-git-send-email-eduard.munteanu@linux360.ro \
    --to=eduard.munteanu@linux360.ro \
    --cc=avi@redhat.com \
    --cc=joro@8bytes.org \
    --cc=kvm@vger.kernel.org \
    --cc=paul@codesourcery.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 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.