From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from [140.186.70.92] (port=33948 helo=eggs.gnu.org) by lists.gnu.org with esmtp (Exim 4.43) id 1PCkCE-0007EG-LL for qemu-devel@nongnu.org; Sun, 31 Oct 2010 22:32:35 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1PCkC9-0003Ub-9V for qemu-devel@nongnu.org; Sun, 31 Oct 2010 22:32:30 -0400 Received: from mail-bw0-f45.google.com ([209.85.214.45]:42027) by eggs.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1PCkC8-0003UR-VW for qemu-devel@nongnu.org; Sun, 31 Oct 2010 22:32:25 -0400 Received: by bwz2 with SMTP id 2so4306508bwz.4 for ; Sun, 31 Oct 2010 19:32:23 -0700 (PDT) MIME-Version: 1.0 Sender: alex.l.williamson@gmail.com In-Reply-To: <20101101021725.GB1020@valinux.co.jp> References: <20101029162918.26094.69379.stgit@s20.home> <20101029163842.26094.32206.stgit@s20.home> <20101101021725.GB1020@valinux.co.jp> Date: Sun, 31 Oct 2010 20:32:23 -0600 Message-ID: Subject: Re: [Qemu-devel] [PATCH 1/2] Minimal RAM API support From: Alex Williamson Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: quoted-printable List-Id: qemu-devel.nongnu.org List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , To: Isaku Yamahata Cc: chrisw@redhat.com, ddutile@redhat.com, qemu-devel@nongnu.org, kvm@vger.kernel.org, mst@redhat.com On Sun, Oct 31, 2010 at 8:17 PM, Isaku Yamahata wr= ote: > On Fri, Oct 29, 2010 at 10:39:03AM -0600, Alex Williamson wrote: >> 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 >> --- >> >> =C2=A0Makefile.target | =C2=A0 =C2=A01 + >> =C2=A0cpu-common.h =C2=A0 =C2=A0| =C2=A0 =C2=A02 + >> =C2=A0memory.c =C2=A0 =C2=A0 =C2=A0 =C2=A0| =C2=A0 82 ++++++++++++++++++= +++++++++++++++++++++++++++++++++++++ >> =C2=A0memory.h =C2=A0 =C2=A0 =C2=A0 =C2=A0| =C2=A0 23 +++++++++++++++ >> =C2=A04 files changed, 108 insertions(+), 0 deletions(-) >> =C2=A0create mode 100644 memory.c >> =C2=A0create mode 100644 memory.h >> >> diff --git a/Makefile.target b/Makefile.target >> index c48cbcc..e4e2eb4 100644 >> --- a/Makefile.target >> +++ b/Makefile.target >> @@ -175,6 +175,7 @@ obj-$(CONFIG_VIRTFS) +=3D virtio-9p.o >> =C2=A0obj-y +=3D rwhandler.o >> =C2=A0obj-$(CONFIG_KVM) +=3D kvm.o kvm-all.o >> =C2=A0obj-$(CONFIG_NO_KVM) +=3D kvm-stub.o >> +obj-y +=3D memory.o >> =C2=A0LIBS+=3D-lz >> >> =C2=A0QEMU_CFLAGS +=3D $(VNC_TLS_CFLAGS) >> diff --git a/cpu-common.h b/cpu-common.h >> index a543b5d..6aa2738 100644 >> --- a/cpu-common.h >> +++ b/cpu-common.h >> @@ -23,6 +23,8 @@ >> =C2=A0/* address in the RAM (different from a physical address) */ >> =C2=A0typedef unsigned long ram_addr_t; >> >> +#include "memory.h" >> + >> =C2=A0/* memory API */ >> >> =C2=A0typedef void CPUWriteMemoryFunc(void *opaque, target_phys_addr_t a= ddr, uint32_t value); >> diff --git a/memory.c b/memory.c >> new file mode 100644 >> index 0000000..86947fb >> --- /dev/null >> +++ b/memory.c >> @@ -0,0 +1,82 @@ >> +/* >> + * RAM API >> + * >> + * =C2=A0Copyright Red Hat, Inc. 2010 >> + * >> + * Authors: >> + * =C2=A0Alex Williamson >> + * >> + * 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. =C2=A0See the G= NU >> + * 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" >> +#include "range.h" >> + >> +QemuRamSlots ram_slots =3D { .slots =3D QLIST_HEAD_INITIALIZER(ram_slot= s) }; >> + >> +static QemuRamSlot *qemu_ram_find_slot(target_phys_addr_t start_addr, >> + =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 = =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 ram_addr_t s= ize) >> +{ >> + =C2=A0 =C2=A0QemuRamSlot *slot; >> + >> + =C2=A0 =C2=A0QLIST_FOREACH(slot, &ram_slots.slots, next) { >> + =C2=A0 =C2=A0 =C2=A0 =C2=A0if (slot->start_addr =3D=3D start_addr && s= lot->size =3D=3D size) { >> + =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0return slot; >> + =C2=A0 =C2=A0 =C2=A0 =C2=A0} >> + >> + =C2=A0 =C2=A0 =C2=A0 =C2=A0if (ranges_overlap(start_addr, size, slot->= start_addr, slot->size)) { >> + =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0abort(); >> + =C2=A0 =C2=A0 =C2=A0 =C2=A0} >> + =C2=A0 =C2=A0} >> + >> + =C2=A0 =C2=A0return NULL; >> +} >> + >> +void qemu_ram_register(target_phys_addr_t start_addr, ram_addr_t size, >> + =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 = =C2=A0 ram_addr_t phys_offset) >> +{ >> + =C2=A0 =C2=A0QemuRamSlot *slot; >> + >> + =C2=A0 =C2=A0if (!size) { >> + =C2=A0 =C2=A0 =C2=A0 =C2=A0return; >> + =C2=A0 =C2=A0} >> + >> + =C2=A0 =C2=A0assert(!qemu_ram_find_slot(start_addr, size)); >> + >> + =C2=A0 =C2=A0slot =3D qemu_mallocz(sizeof(QemuRamSlot)); >> + >> + =C2=A0 =C2=A0slot->start_addr =3D start_addr; >> + =C2=A0 =C2=A0slot->size =3D size; >> + =C2=A0 =C2=A0slot->offset =3D phys_offset; >> + >> + =C2=A0 =C2=A0QLIST_INSERT_HEAD(&ram_slots.slots, slot, next); >> + >> + =C2=A0 =C2=A0cpu_register_physical_memory(slot->start_addr, slot->size= , slot->offset); >> +} >> + >> +void qemu_ram_unregister(target_phys_addr_t start_addr, ram_addr_t size= ) >> +{ >> + =C2=A0 =C2=A0QemuRamSlot *slot; >> + >> + =C2=A0 =C2=A0if (!size) { >> + =C2=A0 =C2=A0 =C2=A0 =C2=A0return; >> + =C2=A0 =C2=A0} >> + >> + =C2=A0 =C2=A0slot =3D qemu_ram_find_slot(start_addr, size); >> + =C2=A0 =C2=A0assert(slot !=3D NULL); >> + >> + =C2=A0 =C2=A0QLIST_REMOVE(slot, next); >> + =C2=A0 =C2=A0cpu_register_physical_memory(start_addr, size, IO_MEM_UNA= SSIGNED); >> + >> + =C2=A0 =C2=A0return; >> +} > > qemu_free(slot) is necessary. Thank you! Alex