Re: [Qemu-devel] [PATCH 1/2] Minimal RAM API support

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



On Sun, Oct 31, 2010 at 8:17 PM, Isaku Yamahata <yamahata@xxxxxxxxxxxxx> wrote:
> 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 <alex.williamson@xxxxxxxxxx>
>> ---
>>
>> ÂMakefile.target | Â Â1 +
>> Âcpu-common.h  Â|  Â2 +
>> Âmemory.c    Â|  82 +++++++++++++++++++++++++++++++++++++++++++++++++++++++
>> Âmemory.h    Â|  23 +++++++++++++++
>> Â4 files changed, 108 insertions(+), 0 deletions(-)
>> Âcreate mode 100644 memory.c
>> Âcreate 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) += 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 a543b5d..6aa2738 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..86947fb
>> --- /dev/null
>> +++ b/memory.c
>> @@ -0,0 +1,82 @@
>> +/*
>> + * RAM API
>> + *
>> + * ÂCopyright Red Hat, Inc. 2010
>> + *
>> + * Authors:
>> + * ÂAlex Williamson <alex.williamson@xxxxxxxxxx>
>> + *
>> + * 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"
>> +#include "range.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 (ranges_overlap(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;
>> + Â Â}
>> +
>> + Â Âassert(!qemu_ram_find_slot(start_addr, size));
>> +
>> + Â Â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;
>> +}
>
> qemu_free(slot) is necessary.

Thank you!

Alex
--
To unsubscribe from this list: send the line "unsubscribe kvm" in
the body of a message to majordomo@xxxxxxxxxxxxxxx
More majordomo info at  http://vger.kernel.org/majordomo-info.html


[Index of Archives]     [KVM ARM]     [KVM ia64]     [KVM ppc]     [Virtualization Tools]     [Spice Development]     [Libvirt]     [Libvirt Users]     [Linux USB Devel]     [Linux Audio Users]     [Yosemite Questions]     [Linux Kernel]     [Linux SCSI]     [XFree86]
  Powered by Linux