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 2/5] Minimal RAM API support
Date: Sun, 11 Jul 2010 12:09:23 -0600 [thread overview]
Message-ID: <20100711180923.20121.58599.stgit@localhost6.localdomain6> (raw)
In-Reply-To: <20100711180910.20121.93313.stgit@localhost6.localdomain6>
This adds a minimum chunk of Anthony's RAM API support so that we
can identify actual VM RAM versus all the other things that make
use of qemu_ram_alloc.
Signed-off-by: Alex Williamson <alex.williamson@gmail.com>
---
Makefile.target | 1 +
cpu-common.h | 2 +
memory.c | 77 +++++++++++++++++++++++++++++++++++++++++++++++++++++++
memory.h | 23 ++++++++++++++++
4 files changed, 103 insertions(+), 0 deletions(-)
create mode 100644 memory.c
create mode 100644 memory.h
diff --git a/Makefile.target b/Makefile.target
index 7489910..0c1b916 100644
--- a/Makefile.target
+++ b/Makefile.target
@@ -173,6 +173,7 @@ obj-$(CONFIG_VIRTFS) += virtio-9p.o
obj-y += rwhandler.o
obj-$(CONFIG_KVM) += kvm.o kvm-all.o
obj-$(CONFIG_NO_KVM) += kvm-stub.o
+obj-y += memory.o
LIBS+=-lz
QEMU_CFLAGS += $(VNC_TLS_CFLAGS)
diff --git a/cpu-common.h b/cpu-common.h
index 8d03f4e..7e76f9d 100644
--- a/cpu-common.h
+++ b/cpu-common.h
@@ -23,6 +23,8 @@
/* address in the RAM (different from a physical address) */
typedef unsigned long ram_addr_t;
+#include "memory.h"
+
/* memory API */
typedef void CPUWriteMemoryFunc(void *opaque, target_phys_addr_t addr, uint32_t value);
diff --git a/memory.c b/memory.c
new file mode 100644
index 0000000..f5f9273
--- /dev/null
+++ b/memory.c
@@ -0,0 +1,77 @@
+/*
+ * virtual page mapping and translated block handling
+ *
+ * Copyright (c) 2003 Fabrice Bellard
+ *
+ * This library is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU Lesser General Public
+ * License as published by the Free Software Foundation; either
+ * version 2 of the License, or (at your option) any later version.
+ *
+ * This library is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ * Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public
+ * License along with this library; if not, see <http://www.gnu.org/licenses/>.
+ */
+#include "memory.h"
+
+QemuRamSlots ram_slots = { .slots = QLIST_HEAD_INITIALIZER(ram_slots) };
+
+static QemuRamSlot *qemu_ram_find_slot(target_phys_addr_t start_addr,
+ ram_addr_t size)
+{
+ QemuRamSlot *slot;
+
+ QLIST_FOREACH(slot, &ram_slots.slots, next) {
+ if (slot->start_addr == start_addr && slot->size == size) {
+ return slot;
+ }
+
+ if ((start_addr - slot->start_addr < slot->size) ||
+ (start_addr + size - slot->start_addr < slot->size))
+ abort();
+ }
+
+ return NULL;
+}
+
+void qemu_ram_register(target_phys_addr_t start_addr, ram_addr_t size,
+ ram_addr_t phys_offset)
+{
+ QemuRamSlot *slot;
+
+ if (!size)
+ return;
+
+ slot = qemu_ram_find_slot(start_addr, size);
+ assert(slot == NULL);
+
+ slot = qemu_mallocz(sizeof(QemuRamSlot));
+
+ slot->start_addr = start_addr;
+ slot->size = size;
+ slot->offset = phys_offset;
+
+ QLIST_INSERT_HEAD(&ram_slots.slots, slot, next);
+
+ cpu_register_physical_memory(slot->start_addr, slot->size, slot->offset);
+}
+
+void qemu_ram_unregister(target_phys_addr_t start_addr, ram_addr_t size)
+{
+ QemuRamSlot *slot;
+
+ if (!size)
+ return;
+
+ slot = qemu_ram_find_slot(start_addr, size);
+ assert(slot != NULL);
+
+ QLIST_REMOVE(slot, next);
+ cpu_register_physical_memory(start_addr, size, IO_MEM_UNASSIGNED);
+
+ return;
+}
diff --git a/memory.h b/memory.h
new file mode 100644
index 0000000..91e552e
--- /dev/null
+++ b/memory.h
@@ -0,0 +1,23 @@
+#ifndef QEMU_MEMORY_H
+#define QEMU_MEMORY_H
+
+#include "qemu-common.h"
+#include "cpu-common.h"
+
+typedef struct QemuRamSlot {
+ target_phys_addr_t start_addr;
+ ram_addr_t size;
+ ram_addr_t offset;
+ void *host;
+ QLIST_ENTRY(QemuRamSlot) next;
+} QemuRamSlot;
+
+typedef struct QemuRamSlots {
+ QLIST_HEAD(slots, QemuRamSlot) slots;
+} QemuRamSlots;
+extern QemuRamSlots ram_slots;
+
+void qemu_ram_register(target_phys_addr_t start_addr, ram_addr_t size,
+ ram_addr_t phys_offset);
+void qemu_ram_unregister(target_phys_addr_t start_addr, ram_addr_t size);
+#endif
next prev parent 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 ` [Qemu-devel] [RFC PATCH 1/5] qemu_ram_map/unmap: Allow pre-allocated space to be mapped Alex Williamson
2010-07-11 18:09 ` Alex Williamson [this message]
2010-07-11 18:18 ` [Qemu-devel] Re: [RFC PATCH 2/5] Minimal RAM API support 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=20100711180923.20121.58599.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).