All of lore.kernel.org
 help / color / mirror / Atom feed
From: Anthony Liguori <anthony@codemonkey.ws>
To: Alex Williamson <alex.williamson@redhat.com>
Cc: qemu-devel@nongnu.org, blauwirbel@gmail.com, chrisw@redhat.com,
	ddutile@redhat.com, kvm@vger.kernel.org, mst@redhat.com
Subject: Re: [Qemu-devel] [PATCH v2 1/2] Minimal RAM API support
Date: Tue, 16 Nov 2010 08:55:00 -0600	[thread overview]
Message-ID: <4CE29B44.1070202@codemonkey.ws> (raw)
In-Reply-To: <20101101151330.3927.32277.stgit@s20.home>

On 11/01/2010 10:14 AM, 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@redhat.com>
> ---
>
>   Makefile.objs |    1 +
>   cpu-common.h  |    2 +
>   memory.c      |  109 +++++++++++++++++++++++++++++++++++++++++++++++++++++++++
>   memory.h      |   18 +++++++++
>   4 files changed, 130 insertions(+), 0 deletions(-)
>   create mode 100644 memory.c
>   create mode 100644 memory.h
>
> diff --git a/Makefile.objs b/Makefile.objs
> index f07fb01..33fae0b 100644
> --- a/Makefile.objs
> +++ b/Makefile.objs
> @@ -154,6 +154,7 @@ hw-obj-y += vl.o loader.o
>   hw-obj-y += virtio.o virtio-console.o
>   hw-obj-y += fw_cfg.o pci.o pci_host.o pcie_host.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 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..2895082
> --- /dev/null
> +++ b/memory.c
> @@ -0,0 +1,109 @@
> +/*
> + * RAM API
> + *
> + *  Copyright Red Hat, Inc. 2010
> + *
> + * Authors:
> + *  Alex Williamson<alex.williamson@redhat.com>
> + *
> + * 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"
> +
> +typedef struct QemuRamSlot {
> +    target_phys_addr_t start_addr;
> +    ram_addr_t size;
> +    ram_addr_t offset;
> +    QLIST_ENTRY(QemuRamSlot) next;
> +} QemuRamSlot;
> +
> +typedef struct QemuRamSlots {
> +    QLIST_HEAD(slots, QemuRamSlot) slots;
> +} QemuRamSlots;
>    

No need for all of the 'Qemu' prefixes.

> +
> +static QemuRamSlots ram_slots = { .slots = QLIST_HEAD_INITIALIZER(ram_slots) };
>    

Might be nicer to just typedef the extra struct away.

> +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();
>    

Should display a message before aborting.

> +        }
> +    }
> +
> +    return NULL;
> +}
> +
> +int qemu_ram_register(target_phys_addr_t start_addr, ram_addr_t size,
> +                       ram_addr_t phys_offset)
> +{
> +    QemuRamSlot *slot;
> +
> +    if (!size) {
> +        return -EINVAL;
> +    }
> +
> +    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);
> +
> +    return 0;
> +}
> +
> +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);
> +    qemu_free(slot);
> +    cpu_register_physical_memory(start_addr, size, IO_MEM_UNASSIGNED);
> +
> +    return;
> +}
> +
> +int qemu_ram_for_each_slot(void *opaque, qemu_ram_for_each_slot_fn fn)
> +{
> +    QemuRamSlot *slot;
> +
> +    QLIST_FOREACH(slot,&ram_slots.slots, next) {
> +        int ret = fn(opaque, slot->start_addr, slot->size, slot->offset);
> +        if (ret) {
> +            return ret;
> +        }
> +    }
> +    return 0;
> +}
> diff --git a/memory.h b/memory.h
> new file mode 100644
> index 0000000..0c17ff9
> --- /dev/null
> +++ b/memory.h
> @@ -0,0 +1,18 @@
> +#ifndef QEMU_MEMORY_H
> +#define QEMU_MEMORY_H
> +
> +#include "qemu-common.h"
> +#include "cpu-common.h"
>    

Header needs copyright and would be nice to have some comments 
explaining these functions.

Regards,

Anthony Liguori

> +int 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);
> +
> +typedef int (*qemu_ram_for_each_slot_fn)(void *opaque,
> +                                         target_phys_addr_t start_addr,
> +                                         ram_addr_t size,
> +                                         ram_addr_t phys_offset);
> +
> +int qemu_ram_for_each_slot(void *opaque, qemu_ram_for_each_slot_fn fn);
> +#endif
>
>
>
>    


WARNING: multiple messages have this Message-ID (diff)
From: Anthony Liguori <anthony@codemonkey.ws>
To: Alex Williamson <alex.williamson@redhat.com>
Cc: chrisw@redhat.com, kvm@vger.kernel.org, mst@redhat.com,
	qemu-devel@nongnu.org, blauwirbel@gmail.com, ddutile@redhat.com
Subject: Re: [Qemu-devel] [PATCH v2 1/2] Minimal RAM API support
Date: Tue, 16 Nov 2010 08:55:00 -0600	[thread overview]
Message-ID: <4CE29B44.1070202@codemonkey.ws> (raw)
In-Reply-To: <20101101151330.3927.32277.stgit@s20.home>

On 11/01/2010 10:14 AM, 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@redhat.com>
> ---
>
>   Makefile.objs |    1 +
>   cpu-common.h  |    2 +
>   memory.c      |  109 +++++++++++++++++++++++++++++++++++++++++++++++++++++++++
>   memory.h      |   18 +++++++++
>   4 files changed, 130 insertions(+), 0 deletions(-)
>   create mode 100644 memory.c
>   create mode 100644 memory.h
>
> diff --git a/Makefile.objs b/Makefile.objs
> index f07fb01..33fae0b 100644
> --- a/Makefile.objs
> +++ b/Makefile.objs
> @@ -154,6 +154,7 @@ hw-obj-y += vl.o loader.o
>   hw-obj-y += virtio.o virtio-console.o
>   hw-obj-y += fw_cfg.o pci.o pci_host.o pcie_host.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 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..2895082
> --- /dev/null
> +++ b/memory.c
> @@ -0,0 +1,109 @@
> +/*
> + * RAM API
> + *
> + *  Copyright Red Hat, Inc. 2010
> + *
> + * Authors:
> + *  Alex Williamson<alex.williamson@redhat.com>
> + *
> + * 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"
> +
> +typedef struct QemuRamSlot {
> +    target_phys_addr_t start_addr;
> +    ram_addr_t size;
> +    ram_addr_t offset;
> +    QLIST_ENTRY(QemuRamSlot) next;
> +} QemuRamSlot;
> +
> +typedef struct QemuRamSlots {
> +    QLIST_HEAD(slots, QemuRamSlot) slots;
> +} QemuRamSlots;
>    

No need for all of the 'Qemu' prefixes.

> +
> +static QemuRamSlots ram_slots = { .slots = QLIST_HEAD_INITIALIZER(ram_slots) };
>    

Might be nicer to just typedef the extra struct away.

> +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();
>    

Should display a message before aborting.

> +        }
> +    }
> +
> +    return NULL;
> +}
> +
> +int qemu_ram_register(target_phys_addr_t start_addr, ram_addr_t size,
> +                       ram_addr_t phys_offset)
> +{
> +    QemuRamSlot *slot;
> +
> +    if (!size) {
> +        return -EINVAL;
> +    }
> +
> +    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);
> +
> +    return 0;
> +}
> +
> +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);
> +    qemu_free(slot);
> +    cpu_register_physical_memory(start_addr, size, IO_MEM_UNASSIGNED);
> +
> +    return;
> +}
> +
> +int qemu_ram_for_each_slot(void *opaque, qemu_ram_for_each_slot_fn fn)
> +{
> +    QemuRamSlot *slot;
> +
> +    QLIST_FOREACH(slot,&ram_slots.slots, next) {
> +        int ret = fn(opaque, slot->start_addr, slot->size, slot->offset);
> +        if (ret) {
> +            return ret;
> +        }
> +    }
> +    return 0;
> +}
> diff --git a/memory.h b/memory.h
> new file mode 100644
> index 0000000..0c17ff9
> --- /dev/null
> +++ b/memory.h
> @@ -0,0 +1,18 @@
> +#ifndef QEMU_MEMORY_H
> +#define QEMU_MEMORY_H
> +
> +#include "qemu-common.h"
> +#include "cpu-common.h"
>    

Header needs copyright and would be nice to have some comments 
explaining these functions.

Regards,

Anthony Liguori

> +int 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);
> +
> +typedef int (*qemu_ram_for_each_slot_fn)(void *opaque,
> +                                         target_phys_addr_t start_addr,
> +                                         ram_addr_t size,
> +                                         ram_addr_t phys_offset);
> +
> +int qemu_ram_for_each_slot(void *opaque, qemu_ram_for_each_slot_fn fn);
> +#endif
>
>
>
>    

  reply	other threads:[~2010-11-16 14:55 UTC|newest]

Thread overview: 53+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2010-10-29 16:38 [PATCH 0/2] Minimal RAM API support Alex Williamson
2010-10-29 16:38 ` [Qemu-devel] " Alex Williamson
2010-10-29 16:39 ` [PATCH 1/2] " Alex Williamson
2010-10-29 16:39   ` [Qemu-devel] " Alex Williamson
2010-10-29 19:57   ` Blue Swirl
2010-10-29 19:57     ` Blue Swirl
2010-10-29 20:15     ` Alex Williamson
2010-10-29 20:15       ` Alex Williamson
2010-11-01  2:17   ` Isaku Yamahata
2010-11-01  2:17     ` Isaku Yamahata
2010-11-01  2:32     ` Alex Williamson
2010-11-01  2:32       ` Alex Williamson
2010-10-29 16:39 ` [PATCH 2/2] RAM API: Make use of it for x86 PC Alex Williamson
2010-10-29 16:39   ` [Qemu-devel] " Alex Williamson
2010-11-01 15:13 ` [PATCH v2 0/2] Minimal RAM API support Alex Williamson
2010-11-01 15:13   ` [Qemu-devel] " Alex Williamson
2010-11-01 15:14   ` [PATCH v2 1/2] " Alex Williamson
2010-11-01 15:14     ` [Qemu-devel] " Alex Williamson
2010-11-16 14:55     ` Anthony Liguori [this message]
2010-11-16 14:55       ` Anthony Liguori
2010-11-16 15:02       ` Alexander Graf
2010-11-16 15:02         ` Alexander Graf
2010-11-16 15:08         ` Anthony Liguori
2010-11-16 15:08           ` Anthony Liguori
2010-11-01 15:14   ` [PATCH v2 2/2] RAM API: Make use of it for x86 PC Alex Williamson
2010-11-01 15:14     ` [Qemu-devel] " Alex Williamson
2010-11-16 14:58     ` Anthony Liguori
2010-11-16 14:58       ` Anthony Liguori
2010-11-16 21:24       ` Alex Williamson
2010-11-16 21:24         ` Alex Williamson
2010-11-17  9:31         ` Gleb Natapov
2010-11-17  9:31           ` Gleb Natapov
2010-11-17 23:42         ` Anthony Liguori
2010-11-18 15:22           ` Avi Kivity
2010-11-18 15:22             ` Avi Kivity
2010-11-18 15:46             ` Anthony Liguori
2010-11-18 15:46               ` Anthony Liguori
2010-11-18 15:57               ` Avi Kivity
2010-11-18 15:57                 ` Avi Kivity
2010-11-18 16:09                 ` Anthony Liguori
2010-11-18 16:09                   ` Anthony Liguori
2010-11-18 16:18                   ` Avi Kivity
2010-11-18 16:18                     ` Avi Kivity
2010-11-18 16:35                     ` Michael S. Tsirkin
2010-11-18 16:35                       ` Michael S. Tsirkin
2010-11-18 15:51           ` Gleb Natapov
2010-11-18 15:51             ` Gleb Natapov
2010-11-18 21:41   ` [PATCH v3 0/2] Minimal RAM API support Alex Williamson
2010-11-18 21:41     ` [Qemu-devel] " Alex Williamson
2010-11-18 21:41     ` [PATCH v3 1/2] " Alex Williamson
2010-11-18 21:41       ` [Qemu-devel] " Alex Williamson
2010-11-18 21:41     ` [PATCH v3 2/2] RAM API: Make use of it for x86 PC Alex Williamson
2010-11-18 21:41       ` [Qemu-devel] " Alex Williamson

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=4CE29B44.1070202@codemonkey.ws \
    --to=anthony@codemonkey.ws \
    --cc=alex.williamson@redhat.com \
    --cc=blauwirbel@gmail.com \
    --cc=chrisw@redhat.com \
    --cc=ddutile@redhat.com \
    --cc=kvm@vger.kernel.org \
    --cc=mst@redhat.com \
    --cc=qemu-devel@nongnu.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.