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

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

 



On Mon, Dec 13, 2010 at 8:47 PM, Alex Williamson
<alex.williamson@xxxxxxxxxx> 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.objs | Â Â1 +
> Âcpu-common.h Â| Â Â2 +
> Âmemory.c   Â|  97 +++++++++++++++++++++++++++++++++++++++++++++++++++++++++
> Âmemory.h   Â|  44 ++++++++++++++++++++++++++
> Â4 files changed, 144 insertions(+), 0 deletions(-)
> Âcreate mode 100644 memory.c
> Âcreate mode 100644 memory.h
>
> diff --git a/Makefile.objs b/Makefile.objs
> index cebb945..47f3c3a 100644
> --- a/Makefile.objs
> +++ b/Makefile.objs
> @@ -172,6 +172,7 @@ hw-obj-y += pci.o pci_bridge.o msix.o msi.o
> Âhw-obj-$(CONFIG_PCI) += pci_host.o pcie_host.o
> Âhw-obj-$(CONFIG_PCI) += ioh3420.o xio3130_upstream.o xio3130_downstream.o
> Âhw-obj-y += watchdog.o
> +hw-obj-y += memory.o
> Âhw-obj-$(CONFIG_ISA_MMIO) += isa_mmio.o
> Âhw-obj-$(CONFIG_ECC) += ecc.o
> Âhw-obj-$(CONFIG_NAND) += nand.o
> diff --git a/cpu-common.h b/cpu-common.h
> index 6d4a898..f08f93b 100644
> --- a/cpu-common.h
> +++ b/cpu-common.h
> @@ -29,6 +29,8 @@ enum device_endian {
> Â/* 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..742776f
> --- /dev/null
> +++ b/memory.c
> @@ -0,0 +1,97 @@
> +/*
> + * RAM API
> + *
> + * ÂCopyright Red Hat, Inc. 2010
> + *
> + * Authors:
> + * ÂAlex Williamson <alex.williamson@xxxxxxxxxx>
> + *
> + * This work is licensed under the terms of the GNU GPL, version 2. ÂSee
> + * the COPYING file in the top-level directory.
> + *
> + */
> +#include "memory.h"
> +#include "range.h"
> +
> +typedef struct ram_slot {
> + Â Âtarget_phys_addr_t start_addr;
> + Â Âram_addr_t size;
> + Â Âram_addr_t offset;
> + Â ÂQLIST_ENTRY(ram_slot) next;
> +} ram_slot;

Please see CODING_STYLE for structure naming.

> +
> +static QLIST_HEAD(ram_slots, ram_slot) ram_slots =
> + Â ÂQLIST_HEAD_INITIALIZER(ram_slots);
> +
> +static ram_slot *qemu_ram_find_slot(target_phys_addr_t start_addr,
> + Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â ram_addr_t size)
> +{
> + Â Âram_slot *slot;
> +
> + Â ÂQLIST_FOREACH(slot, &ram_slots, next) {
> + Â Â Â Âif (slot->start_addr == start_addr && slot->size == size) {
> + Â Â Â Â Â Âreturn slot;
> + Â Â Â Â}
> +
> + Â Â Â Âif (ranges_overlap(start_addr, size, slot->start_addr, slot->size)) {
> + Â Â Â Â Â Âhw_error("Ram range overlaps existing slot\n");
> + Â Â Â Â}
> + Â Â}
> +
> + Â Âreturn NULL;
> +}
> +
> +int qemu_ram_register(target_phys_addr_t start_addr, ram_addr_t size,
> + Â Â Â Â Â Â Â Â Â Â Âram_addr_t phys_offset)
> +{
> + Â Âram_slot *slot;
> +
> + Â Âif (!size) {
> + Â Â Â Âreturn -EINVAL;
> + Â Â}
> +
> + Â Âassert(!qemu_ram_find_slot(start_addr, size));
> +
> + Â Âslot = qemu_mallocz(sizeof(ram_slot));

Since you initialize every field by hand later, this could be qemu_malloc().

> +
> + Â Âslot->start_addr = start_addr;
> + Â Âslot->size = size;
> + Â Âslot->offset = phys_offset;
> +
> + Â ÂQLIST_INSERT_HEAD(&ram_slots, slot, next);
> +
> + Â Âcpu_register_physical_memory(slot->start_addr, slot->size, slot->offset);
> +
> + Â Âreturn 0;
> +}
> +
> +void qemu_ram_unregister(target_phys_addr_t start_addr, ram_addr_t size)
> +{
> + Â Âram_slot *slot;
> +
> + Â Âif (!size) {
> + Â Â Â Âreturn;
> + Â Â}
> +
> + Â Âslot = qemu_ram_find_slot(start_addr, size);
> + Â Âassert(slot != NULL);
> +
> + Â ÂQLIST_REMOVE(slot, next);
> + Â Âqemu_free(slot);
> + Â Âcpu_register_physical_memory(start_addr, size, IO_MEM_UNASSIGNED);
> +
> + Â Âreturn;

Useless.
--
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