@@ -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)
@@ -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);
new file mode 100644
@@ -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;
+}
new file mode 100644
@@ -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