qemu-devel.nongnu.org archive mirror
 help / color / mirror / Atom feed
From: Alex Williamson <alex.williamson@redhat.com>
To: kvm@vger.kernel.org, qemu-devel@nongnu.org
Cc: chrisw@redhat.com, alex.williamson@redhat.com, pugs@cisco.com,
	mst@redhat.com
Subject: [Qemu-devel] [RFC PATCH 1/5] qemu_ram_map/unmap: Allow pre-allocated space to be mapped
Date: Sun, 11 Jul 2010 12:09:17 -0600	[thread overview]
Message-ID: <20100711180917.20121.51464.stgit@localhost6.localdomain6> (raw)
In-Reply-To: <20100711180910.20121.93313.stgit@localhost6.localdomain6>

For assigned devices, we want to map the PCI BARs into the VM
address space.  This is just like mapping an option ROM except
the host backing is an mmap area instead of a chunk of vmalloc
memory.  This allow registration and removal of such areas.

Signed-off-by: Alex Williamson <alex.williamson@redhat.com>
---

 cpu-common.h |    3 +++
 exec.c       |   56 ++++++++++++++++++++++++++++++++++++++++++++++++++++++++
 2 files changed, 59 insertions(+), 0 deletions(-)

diff --git a/cpu-common.h b/cpu-common.h
index 71e7933..8d03f4e 100644
--- a/cpu-common.h
+++ b/cpu-common.h
@@ -40,7 +40,10 @@ static inline void cpu_register_physical_memory(target_phys_addr_t start_addr,
 }
 
 ram_addr_t cpu_get_physical_page_desc(target_phys_addr_t addr);
+ram_addr_t qemu_ram_map(DeviceState *dev, const char *name,
+                        ram_addr_t size, void *host);
 ram_addr_t qemu_ram_alloc(DeviceState *dev, const char *name, ram_addr_t size);
+void qemu_ram_unmap(ram_addr_t addr);
 void qemu_ram_free(ram_addr_t addr);
 /* This should only be used for ram local to a device.  */
 void *qemu_get_ram_ptr(ram_addr_t addr);
diff --git a/exec.c b/exec.c
index 5420f56..a98b4e9 100644
--- a/exec.c
+++ b/exec.c
@@ -2808,6 +2808,49 @@ static ram_addr_t last_ram_offset(void)
     return last;
 }
 
+ram_addr_t qemu_ram_map(DeviceState *dev, const char *name,
+                        ram_addr_t size, void *host)
+{
+    RAMBlock *new_block, *block;
+
+    size = TARGET_PAGE_ALIGN(size);
+    new_block = qemu_mallocz(sizeof(*new_block));
+
+    if (dev && dev->parent_bus && dev->parent_bus->info->get_dev_path) {
+        char *id = dev->parent_bus->info->get_dev_path(dev);
+        if (id) {
+            snprintf(new_block->idstr, sizeof(new_block->idstr), "%s/", id);
+            qemu_free(id);
+        }
+    }
+    pstrcat(new_block->idstr, sizeof(new_block->idstr), name);
+
+    QLIST_FOREACH(block, &ram_list.blocks, next) {
+        if (!strcmp(block->idstr, new_block->idstr)) {
+            fprintf(stderr, "RAMBlock \"%s\" already registered, abort!\n",
+                    new_block->idstr);
+            abort();
+        }
+    }
+
+    new_block->host = host;
+
+    new_block->offset = find_ram_offset(size);
+    new_block->length = size;
+
+    QLIST_INSERT_HEAD(&ram_list.blocks, new_block, next);
+
+    ram_list.phys_dirty = qemu_realloc(ram_list.phys_dirty,
+                                       last_ram_offset() >> TARGET_PAGE_BITS);
+    memset(ram_list.phys_dirty + (new_block->offset >> TARGET_PAGE_BITS),
+           0xff, size >> TARGET_PAGE_BITS);
+
+    if (kvm_enabled())
+        kvm_setup_guest_memory(new_block->host, size);
+
+    return new_block->offset;
+}
+
 ram_addr_t qemu_ram_alloc(DeviceState *dev, const char *name, ram_addr_t size)
 {
     RAMBlock *new_block, *block;
@@ -2874,6 +2917,19 @@ ram_addr_t qemu_ram_alloc(DeviceState *dev, const char *name, ram_addr_t size)
     return new_block->offset;
 }
 
+void qemu_ram_unmap(ram_addr_t addr)
+{
+    RAMBlock *block;
+
+    QLIST_FOREACH(block, &ram_list.blocks, next) {
+        if (addr == block->offset) {
+            QLIST_REMOVE(block, next);
+            qemu_free(block);
+            return;
+        }
+    }
+}
+
 void qemu_ram_free(ram_addr_t addr)
 {
     RAMBlock *block;

  reply	other threads:[~2010-07-11 18:09 UTC|newest]

Thread overview: 32+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2010-07-11 18:09 [Qemu-devel] [RFC PATCH 0/5] QEMU VFIO device assignment Alex Williamson
2010-07-11 18:09 ` Alex Williamson [this message]
2010-07-11 18:09 ` [Qemu-devel] [RFC PATCH 2/5] Minimal RAM API support Alex Williamson
2010-07-11 18:18   ` [Qemu-devel] " Alex Williamson
2010-07-11 18:20   ` Avi Kivity
2010-07-11 18:24     ` Alex Williamson
2010-07-11 18:29       ` Avi Kivity
2010-07-11 18:09 ` [Qemu-devel] [RFC PATCH 3/5] RAM API: Make use of it for x86 PC Alex Williamson
2010-07-11 18:09 ` [Qemu-devel] [RFC PATCH 4/5] APIC/IOAPIC EOI callback Alex Williamson
2010-07-11 18:14   ` [Qemu-devel] " Avi Kivity
2010-07-11 18:26     ` Alex Williamson
2010-07-11 18:30       ` Avi Kivity
2010-07-11 18:54         ` Michael S. Tsirkin
2010-07-11 19:21           ` Alex Williamson
2010-07-11 19:23             ` Michael S. Tsirkin
2010-07-11 20:03               ` Alex Williamson
2010-07-11 20:05                 ` Michael S. Tsirkin
2010-07-11 20:12                 ` Michael S. Tsirkin
2010-07-11 21:59                   ` Alex Williamson
2010-07-12  6:33         ` Avi Kivity
2010-07-12  9:05           ` Gleb Natapov
2010-07-12  9:13             ` Avi Kivity
2010-07-11 18:09 ` [Qemu-devel] [RFC PATCH 5/5] VFIO based device assignment Alex Williamson
2010-07-11 18:27   ` [Qemu-devel] " Avi Kivity
2010-07-11 19:38     ` Alex Williamson
2010-07-12  6:37       ` Avi Kivity
2010-07-11 18:17 ` [Qemu-devel] Re: [RFC PATCH 0/5] QEMU VFIO " Avi Kivity
2010-07-11 18:37   ` Alex Williamson
2010-07-11 18:43     ` Avi Kivity
2010-07-11 20:24       ` Alex Williamson
2010-07-12  6:29         ` Avi Kivity
2010-07-12 11:03           ` Michael S. Tsirkin

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=20100711180917.20121.51464.stgit@localhost6.localdomain6 \
    --to=alex.williamson@redhat.com \
    --cc=chrisw@redhat.com \
    --cc=kvm@vger.kernel.org \
    --cc=mst@redhat.com \
    --cc=pugs@cisco.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 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).