From patchwork Sun Jul 11 18:09:23 2010 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Alex Williamson X-Patchwork-Id: 111332 Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by demeter.kernel.org (8.14.4/8.14.3) with ESMTP id o6BI9TjI023872 for ; Sun, 11 Jul 2010 18:09:29 GMT Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1754232Ab0GKSJ1 (ORCPT ); Sun, 11 Jul 2010 14:09:27 -0400 Received: from mx1.redhat.com ([209.132.183.28]:10584 "EHLO mx1.redhat.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1753983Ab0GKSJ0 (ORCPT ); Sun, 11 Jul 2010 14:09:26 -0400 Received: from int-mx01.intmail.prod.int.phx2.redhat.com (int-mx01.intmail.prod.int.phx2.redhat.com [10.5.11.11]) by mx1.redhat.com (8.13.8/8.13.8) with ESMTP id o6BI9O8C018038 (version=TLSv1/SSLv3 cipher=DHE-RSA-AES256-SHA bits=256 verify=OK); Sun, 11 Jul 2010 14:09:25 -0400 Received: from localhost6.localdomain6 (ovpn01.gateway.prod.ext.phx2.redhat.com [10.5.9.1]) by int-mx01.intmail.prod.int.phx2.redhat.com (8.13.8/8.13.8) with ESMTP id o6BI9NSX019463; Sun, 11 Jul 2010 14:09:24 -0400 From: Alex Williamson Subject: [RFC PATCH 2/5] Minimal RAM API support To: kvm@vger.kernel.org, qemu-devel@nongnu.org Cc: pugs@cisco.com, chrisw@redhat.com, mst@redhat.com, alex.williamson@redhat.com Date: Sun, 11 Jul 2010 12:09:23 -0600 Message-ID: <20100711180923.20121.58599.stgit@localhost6.localdomain6> In-Reply-To: <20100711180910.20121.93313.stgit@localhost6.localdomain6> References: <20100711180910.20121.93313.stgit@localhost6.localdomain6> User-Agent: StGIT/0.14.3 MIME-Version: 1.0 X-Scanned-By: MIMEDefang 2.67 on 10.5.11.11 Sender: kvm-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: kvm@vger.kernel.org X-Greylist: IP, sender and recipient auto-whitelisted, not delayed by milter-greylist-4.2.3 (demeter.kernel.org [140.211.167.41]); Sun, 11 Jul 2010 18:09:29 +0000 (UTC) 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 . + */ +#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