All of lore.kernel.org
 help / color / mirror / Atom feed
From: Vasilis Liaskovitis <vasilis.liaskovitis@profitbricks.com>
To: Blue Swirl <blauwirbel@gmail.com>
Cc: kvm@vger.kernel.org, gleb@redhat.com, seabios@seabios.org,
	qemu-devel@nongnu.org, kevin@koconnor.net, avi@redhat.com,
	anthony@codemonkey.ws, imammedo@redhat.com
Subject: Re: [RFC PATCH v2 06/21] dimm: Implement memory device abstraction
Date: Fri, 13 Jul 2012 19:39:20 +0200	[thread overview]
Message-ID: <20120713173920.GC13216@dhcp-192-168-178-175.profitbricks.localdomain> (raw)
In-Reply-To: <CAAu8pHudXN=u6cg7yEeNLQc+Oii3ixrBDwX8D+QpZhLPVWSD8Q@mail.gmail.com>

Hi,

On Thu, Jul 12, 2012 at 07:55:42PM +0000, Blue Swirl wrote:
> On Wed, Jul 11, 2012 at 10:31 AM, Vasilis Liaskovitis
> <vasilis.liaskovitis@profitbricks.com> wrote:
> > Each hotplug-able memory slot is a SysBusDevice. A hot-add operation for a
> > particular dimm creates a new MemoryRegion of the given physical address
> > offset, size and node proximity, and attaches it to main system memory as a
> > sub_region. A hot-remove operation detaches and frees the MemoryRegion from
> > system memory.
> >
> > This prototype still lacks proper qdev integration: a separate
> > hotplug side-channel is used and main system bus hotplug capability is
> > ignored.
> >
> > Signed-off-by: Vasilis Liaskovitis <vasilis.liaskovitis@profitbricks.com>
> > ---
> >  hw/Makefile.objs |    2 +-
> >  hw/dimm.c        |  234 ++++++++++++++++++++++++++++++++++++++++++++++++++++++
> >  hw/dimm.h        |   58 +++++++++++++
> >  3 files changed, 293 insertions(+), 1 deletions(-)
> >  create mode 100644 hw/dimm.c
> >  create mode 100644 hw/dimm.h
> >
> > diff --git a/hw/Makefile.objs b/hw/Makefile.objs
> > index 3d77259..e2184bf 100644
> > --- a/hw/Makefile.objs
> > +++ b/hw/Makefile.objs
> > @@ -26,7 +26,7 @@ hw-obj-$(CONFIG_I8254) += i8254_common.o i8254.o
> >  hw-obj-$(CONFIG_PCSPK) += pcspk.o
> >  hw-obj-$(CONFIG_PCKBD) += pckbd.o
> >  hw-obj-$(CONFIG_FDC) += fdc.o
> > -hw-obj-$(CONFIG_ACPI) += acpi.o acpi_piix4.o
> > +hw-obj-$(CONFIG_ACPI) += acpi.o acpi_piix4.o dimm.o
> >  hw-obj-$(CONFIG_APM) += pm_smbus.o apm.o
> >  hw-obj-$(CONFIG_DMA) += dma.o
> >  hw-obj-$(CONFIG_I82374) += i82374.o
> > diff --git a/hw/dimm.c b/hw/dimm.c
> > new file mode 100644
> > index 0000000..00c4623
> > --- /dev/null
> > +++ b/hw/dimm.c
> > @@ -0,0 +1,234 @@
> > +/*
> > + * Dimm device for Memory Hotplug
> > + *
> > + * Copyright ProfitBricks GmbH 2012
> > + * 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 "trace.h"
> > +#include "qdev.h"
> > +#include "dimm.h"
> > +#include <time.h>
> > +#include "../exec-memory.h"
> > +#include "qmp-commands.h"
> > +
> > +static DeviceState *dimm_hotplug_qdev;
> > +static dimm_hotplug_fn dimm_hotplug;
> > +static QTAILQ_HEAD(Dimmlist, DimmState)  dimmlist;
> 
> Using global state does not look right. It should always be possible
> to pass around structures to avoid it.

ok, I 'll try to remove the global state.

> 
> > +
> > +static Property dimm_properties[] = {
> > +    DEFINE_PROP_END_OF_LIST()
> > +};
> > +
> > +void dimm_populate(DimmState *s)
> 
> All functions are global and exported but there does not seem to be
> users. Please make all static which you can.

will do

> 
> > +{
> > +    DeviceState *dev= (DeviceState*)s;
> > +    MemoryRegion *new = NULL;
> > +
> > +    new = g_malloc(sizeof(MemoryRegion));
> > +    memory_region_init_ram(new, dev->id, s->size);
> > +    vmstate_register_ram_global(new);
> > +    memory_region_add_subregion(get_system_memory(), s->start, new);
> > +    s->mr = new;
> > +    s->populated = true;
> > +}
> > +
> > +
> > +void dimm_depopulate(DimmState *s)
> > +{
> > +    assert(s);
> > +    if (s->populated) {
> > +        vmstate_unregister_ram(s->mr, NULL);
> > +        memory_region_del_subregion(get_system_memory(), s->mr);
> > +        memory_region_destroy(s->mr);
> > +        s->populated = false;
> > +        s->mr = NULL;
> > +    }
> > +}
> > +
> > +DimmState *dimm_create(char *id, uint64_t size, uint64_t node, uint32_t
> > +        dimm_idx, bool populated)
> > +{
> > +    DeviceState *dev;
> > +    DimmState *mdev;
> > +
> > +    dev = sysbus_create_simple("dimm", -1, NULL);
> > +    dev->id = id;
> > +
> > +    mdev = DIMM(dev);
> > +    mdev->idx = dimm_idx;
> > +    mdev->start = 0;
> > +    mdev->size = size;
> > +    mdev->node = node;
> > +    mdev->populated = populated;
> > +    QTAILQ_INSERT_TAIL(&dimmlist, mdev, nextdimm);
> > +    return mdev;
> > +}
> > +
> > +void dimm_register_hotplug(dimm_hotplug_fn hotplug, DeviceState *qdev)
> > +{
> > +    dimm_hotplug_qdev = qdev;
> > +    dimm_hotplug = hotplug;
> > +    dimm_scan_populated();
> > +}
> > +
> > +void dimm_activate(DimmState *slot)
> > +{
> > +    dimm_populate(slot);
> > +    if (dimm_hotplug)
> > +        dimm_hotplug(dimm_hotplug_qdev, (SysBusDevice*)slot, 1);
> 
> Why the cast?

dimm_hotplug accepts SysBusDevice, not DimmState, though that can be changed.
> 
> Also braces, please check your patches with checkpatch.pl.
>

ok, I 'll do checks with checkpatch.pl. 

> > +}
> > +
> > +void dimm_deactivate(DimmState *slot)
> > +{
> > +    if (dimm_hotplug)
> > +        dimm_hotplug(dimm_hotplug_qdev, (SysBusDevice*)slot, 0);
> > +}
> > +
> > +DimmState *dimm_find_from_name(char *id)
> 
> const char *id?
ok
> 
> > +{
> > +    Error *err = NULL;
> > +    DeviceState *qdev;
> > +    const char *type;
> > +    qdev = qdev_find_recursive(sysbus_get_default(), id);
> > +    if (qdev) {
> > +        type = object_property_get_str(OBJECT(qdev), "type", &err);
> > +        if (!type) {
> > +            return NULL;
> > +        }
> > +        if (!strcmp(type, "dimm")) {
> > +            return DIMM(qdev);
> > +        }
> > +    }
> > +    return NULL;
> > +}
> > +
> > +int dimm_do(Monitor *mon, const QDict *qdict, bool add)
> > +{
> > +    DimmState *slot = NULL;
> > +
> > +    char *id = (char*) qdict_get_try_str(qdict, "id");
> 
> Why this cast?

unneeded, because id should be declared as const char*. will fix.

> 
> > +    if (!id) {
> > +        fprintf(stderr, "ERROR %s invalid id\n",__FUNCTION__);
> > +        return 1;
> > +    }
> > +
> > +    slot = dimm_find_from_name(id);
> > +
> > +    if (!slot) {
> > +        fprintf(stderr, "%s no slot %s found\n", __FUNCTION__, id);
> > +        return 1;
> > +    }
> > +
> > +    if (add) {
> > +        if (slot->populated) {
> > +            fprintf(stderr, "ERROR %s slot %s already populated\n",
> > +                    __FUNCTION__, id);
> > +            return 1;
> > +        }
> > +        dimm_activate(slot);
> > +    }
> > +    else {
> > +        if (!slot->populated) {
> > +            fprintf(stderr, "ERROR %s slot %s is not populated\n",
> > +                    __FUNCTION__, id);
> > +            return 1;
> > +        }
> > +        dimm_deactivate(slot);
> > +    }
> > +
> > +    return 0;
> > +}
> > +
> > +DimmState *dimm_find_from_idx(uint32_t idx)
> > +{
> > +    DimmState *slot;
> > +
> > +    QTAILQ_FOREACH(slot, &dimmlist, nextdimm) {
> > +        if (slot->idx == idx) {
> > +            return slot;
> > +        }
> > +    }
> > +    return NULL;
> > +}
> > +
> > +/* used to calculate physical address offsets for all dimms */
> > +void dimm_calc_offsets(dimm_calcoffset_fn calcfn)
> > +{
> > +    DimmState *slot;
> > +    QTAILQ_FOREACH(slot, &dimmlist, nextdimm) {
> > +        if (!slot->start)
> > +            slot->start = calcfn(slot->size);
> > +    }
> > +}
> > +
> > +/* used to populate and activate dimms at boot time */
> > +void dimm_scan_populated(void)
> > +{
> > +    DimmState *slot;
> > +    QTAILQ_FOREACH(slot, &dimmlist, nextdimm) {
> > +        if (slot->populated && !slot->mr) {
> > +            dimm_activate(slot);
> > +        }
> > +    }
> > +}
> > +
> > +void dimm_notify(uint32_t idx, uint32_t event)
> > +{
> > +    DimmState *s;
> > +    s = dimm_find_from_idx(idx);
> > +    assert(s != NULL);
> > +
> > +    switch(event) {
> > +        case DIMM_REMOVE_SUCCESS:
> > +            dimm_depopulate(s);
> > +            break;
> > +        default:
> > +            break;
> > +    }
> > +}
> > +
> > +static int dimm_init(SysBusDevice *s)
> > +{
> > +    DimmState *slot;
> > +    slot = DIMM(s);
> > +    slot->mr = NULL;
> > +    slot->populated = false;
> > +    return 0;
> > +}
> > +
> > +static void dimm_class_init(ObjectClass *klass, void *data)
> > +{
> > +    SysBusDeviceClass *sc = SYS_BUS_DEVICE_CLASS(klass);
> > +    DeviceClass *dc = DEVICE_CLASS(klass);
> > +
> > +    dc->props = dimm_properties;
> > +    sc->init = dimm_init;
> > +    dimm_hotplug = NULL;
> > +    QTAILQ_INIT(&dimmlist);
> > +}
> > +
> > +static TypeInfo dimm_info = {
> > +    .name          = "dimm",
> > +    .parent        = TYPE_SYS_BUS_DEVICE,
> > +    .instance_size = sizeof(DimmState),
> > +    .class_init    = dimm_class_init,
> > +};
> > +
> > +static void dimm_register_types(void)
> > +{
> > +    type_register_static(&dimm_info);
> > +}
> > +
> > +type_init(dimm_register_types)
> > diff --git a/hw/dimm.h b/hw/dimm.h
> > new file mode 100644
> > index 0000000..643f319
> > --- /dev/null
> > +++ b/hw/dimm.h
> > @@ -0,0 +1,58 @@
> > +#ifndef QEMU_DIMM_H
> > +#define QEMU_DIMM_H
> 
> Should be HW_DIMM_H.
ok.

> 
> > +
> > +#include "qemu-common.h"
> > +#include "memory.h"
> > +#include "sysbus.h"
> > +#include "qapi-types.h"
> > +#include "qemu-queue.h"
> > +#include "cpus.h"
> > +#define MAX_DIMMS 255
> > +#define DIMM_BITMAP_BYTES (MAX_DIMMS + 7) / 8
> > +#define DEFAULT_DIMMSIZE 1024*1024*1024
> > +
> > +typedef enum {
> > +    DIMM_REMOVE_SUCCESS = 0,
> > +    DIMM_REMOVE_FAIL = 1,
> > +    DIMM_ADD_SUCCESS = 2,
> > +    DIMM_ADD_FAIL = 3
> > +} dimm_hp_result_code;
> > +
> > +#define TYPE_DIMM "dimm"
> > +#define DIMM(obj) \
> > +    OBJECT_CHECK(DimmState, (obj), TYPE_DIMM)
> > +#define DIMM_CLASS(klass) \
> > +    OBJECT_CLASS_CHECK(DimmClass, (obj), TYPE_DIMM)
> > +#define DIMM_GET_CLASS(obj) \
> > +    OBJECT_GET_CLASS(DimmClass, (obj), TYPE_DIMM)
> > +
> > +typedef struct DimmState {
> > +    SysBusDevice busdev;
> > +    uint32_t idx; /* index in memory hotplug register/bitmap */
> > +    ram_addr_t start; /* starting physical address */
> > +    ram_addr_t size;
> > +    uint32_t node; /* numa node proximity */
> > +    MemoryRegion *mr; /* MemoryRegion for this slot. !NULL only if populated */
> > +    bool populated; /* 1 means device has been hotplugged. Default is 0. */
> > +    QTAILQ_ENTRY (DimmState) nextdimm;
> > +} DimmState;
> > +
> > +typedef int (*dimm_hotplug_fn)(DeviceState *qdev, SysBusDevice *dev, int add);
> > +typedef target_phys_addr_t (*dimm_calcoffset_fn)(uint64_t size);
> > +
> > +DimmState *dimm_create(char *id, uint64_t size, uint64_t node, uint32_t
> > +        dimm_idx, bool populated);
> > +void dimm_populate(DimmState *s);
> > +void dimm_depopulate(DimmState *s);
> > +int dimm_do(Monitor *mon, const QDict *qdict, bool add);
> > +DimmState *dimm_find_from_idx(uint32_t idx);
> > +DimmState *dimm_find_from_name(char *id);
> > +void dimm_register_hotplug(dimm_hotplug_fn hotplug, DeviceState *qdev);
> > +void dimm_calc_offsets(dimm_calcoffset_fn calcfn);
> > +void dimm_activate(DimmState *slot);
> > +void dimm_deactivate(DimmState *slot);
> > +void dimm_scan_populated(void);
> > +void dimm_notify(uint32_t idx, uint32_t event);
> > +
> > +
> > +#endif
> > --
> > 1.7.9
> >
> >

WARNING: multiple messages have this Message-ID (diff)
From: Vasilis Liaskovitis <vasilis.liaskovitis@profitbricks.com>
To: Blue Swirl <blauwirbel@gmail.com>
Cc: kvm@vger.kernel.org, gleb@redhat.com, seabios@seabios.org,
	qemu-devel@nongnu.org, kevin@koconnor.net, avi@redhat.com,
	anthony@codemonkey.ws, imammedo@redhat.com
Subject: Re: [Qemu-devel] [RFC PATCH v2 06/21] dimm: Implement memory device abstraction
Date: Fri, 13 Jul 2012 19:39:20 +0200	[thread overview]
Message-ID: <20120713173920.GC13216@dhcp-192-168-178-175.profitbricks.localdomain> (raw)
In-Reply-To: <CAAu8pHudXN=u6cg7yEeNLQc+Oii3ixrBDwX8D+QpZhLPVWSD8Q@mail.gmail.com>

Hi,

On Thu, Jul 12, 2012 at 07:55:42PM +0000, Blue Swirl wrote:
> On Wed, Jul 11, 2012 at 10:31 AM, Vasilis Liaskovitis
> <vasilis.liaskovitis@profitbricks.com> wrote:
> > Each hotplug-able memory slot is a SysBusDevice. A hot-add operation for a
> > particular dimm creates a new MemoryRegion of the given physical address
> > offset, size and node proximity, and attaches it to main system memory as a
> > sub_region. A hot-remove operation detaches and frees the MemoryRegion from
> > system memory.
> >
> > This prototype still lacks proper qdev integration: a separate
> > hotplug side-channel is used and main system bus hotplug capability is
> > ignored.
> >
> > Signed-off-by: Vasilis Liaskovitis <vasilis.liaskovitis@profitbricks.com>
> > ---
> >  hw/Makefile.objs |    2 +-
> >  hw/dimm.c        |  234 ++++++++++++++++++++++++++++++++++++++++++++++++++++++
> >  hw/dimm.h        |   58 +++++++++++++
> >  3 files changed, 293 insertions(+), 1 deletions(-)
> >  create mode 100644 hw/dimm.c
> >  create mode 100644 hw/dimm.h
> >
> > diff --git a/hw/Makefile.objs b/hw/Makefile.objs
> > index 3d77259..e2184bf 100644
> > --- a/hw/Makefile.objs
> > +++ b/hw/Makefile.objs
> > @@ -26,7 +26,7 @@ hw-obj-$(CONFIG_I8254) += i8254_common.o i8254.o
> >  hw-obj-$(CONFIG_PCSPK) += pcspk.o
> >  hw-obj-$(CONFIG_PCKBD) += pckbd.o
> >  hw-obj-$(CONFIG_FDC) += fdc.o
> > -hw-obj-$(CONFIG_ACPI) += acpi.o acpi_piix4.o
> > +hw-obj-$(CONFIG_ACPI) += acpi.o acpi_piix4.o dimm.o
> >  hw-obj-$(CONFIG_APM) += pm_smbus.o apm.o
> >  hw-obj-$(CONFIG_DMA) += dma.o
> >  hw-obj-$(CONFIG_I82374) += i82374.o
> > diff --git a/hw/dimm.c b/hw/dimm.c
> > new file mode 100644
> > index 0000000..00c4623
> > --- /dev/null
> > +++ b/hw/dimm.c
> > @@ -0,0 +1,234 @@
> > +/*
> > + * Dimm device for Memory Hotplug
> > + *
> > + * Copyright ProfitBricks GmbH 2012
> > + * 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 "trace.h"
> > +#include "qdev.h"
> > +#include "dimm.h"
> > +#include <time.h>
> > +#include "../exec-memory.h"
> > +#include "qmp-commands.h"
> > +
> > +static DeviceState *dimm_hotplug_qdev;
> > +static dimm_hotplug_fn dimm_hotplug;
> > +static QTAILQ_HEAD(Dimmlist, DimmState)  dimmlist;
> 
> Using global state does not look right. It should always be possible
> to pass around structures to avoid it.

ok, I 'll try to remove the global state.

> 
> > +
> > +static Property dimm_properties[] = {
> > +    DEFINE_PROP_END_OF_LIST()
> > +};
> > +
> > +void dimm_populate(DimmState *s)
> 
> All functions are global and exported but there does not seem to be
> users. Please make all static which you can.

will do

> 
> > +{
> > +    DeviceState *dev= (DeviceState*)s;
> > +    MemoryRegion *new = NULL;
> > +
> > +    new = g_malloc(sizeof(MemoryRegion));
> > +    memory_region_init_ram(new, dev->id, s->size);
> > +    vmstate_register_ram_global(new);
> > +    memory_region_add_subregion(get_system_memory(), s->start, new);
> > +    s->mr = new;
> > +    s->populated = true;
> > +}
> > +
> > +
> > +void dimm_depopulate(DimmState *s)
> > +{
> > +    assert(s);
> > +    if (s->populated) {
> > +        vmstate_unregister_ram(s->mr, NULL);
> > +        memory_region_del_subregion(get_system_memory(), s->mr);
> > +        memory_region_destroy(s->mr);
> > +        s->populated = false;
> > +        s->mr = NULL;
> > +    }
> > +}
> > +
> > +DimmState *dimm_create(char *id, uint64_t size, uint64_t node, uint32_t
> > +        dimm_idx, bool populated)
> > +{
> > +    DeviceState *dev;
> > +    DimmState *mdev;
> > +
> > +    dev = sysbus_create_simple("dimm", -1, NULL);
> > +    dev->id = id;
> > +
> > +    mdev = DIMM(dev);
> > +    mdev->idx = dimm_idx;
> > +    mdev->start = 0;
> > +    mdev->size = size;
> > +    mdev->node = node;
> > +    mdev->populated = populated;
> > +    QTAILQ_INSERT_TAIL(&dimmlist, mdev, nextdimm);
> > +    return mdev;
> > +}
> > +
> > +void dimm_register_hotplug(dimm_hotplug_fn hotplug, DeviceState *qdev)
> > +{
> > +    dimm_hotplug_qdev = qdev;
> > +    dimm_hotplug = hotplug;
> > +    dimm_scan_populated();
> > +}
> > +
> > +void dimm_activate(DimmState *slot)
> > +{
> > +    dimm_populate(slot);
> > +    if (dimm_hotplug)
> > +        dimm_hotplug(dimm_hotplug_qdev, (SysBusDevice*)slot, 1);
> 
> Why the cast?

dimm_hotplug accepts SysBusDevice, not DimmState, though that can be changed.
> 
> Also braces, please check your patches with checkpatch.pl.
>

ok, I 'll do checks with checkpatch.pl. 

> > +}
> > +
> > +void dimm_deactivate(DimmState *slot)
> > +{
> > +    if (dimm_hotplug)
> > +        dimm_hotplug(dimm_hotplug_qdev, (SysBusDevice*)slot, 0);
> > +}
> > +
> > +DimmState *dimm_find_from_name(char *id)
> 
> const char *id?
ok
> 
> > +{
> > +    Error *err = NULL;
> > +    DeviceState *qdev;
> > +    const char *type;
> > +    qdev = qdev_find_recursive(sysbus_get_default(), id);
> > +    if (qdev) {
> > +        type = object_property_get_str(OBJECT(qdev), "type", &err);
> > +        if (!type) {
> > +            return NULL;
> > +        }
> > +        if (!strcmp(type, "dimm")) {
> > +            return DIMM(qdev);
> > +        }
> > +    }
> > +    return NULL;
> > +}
> > +
> > +int dimm_do(Monitor *mon, const QDict *qdict, bool add)
> > +{
> > +    DimmState *slot = NULL;
> > +
> > +    char *id = (char*) qdict_get_try_str(qdict, "id");
> 
> Why this cast?

unneeded, because id should be declared as const char*. will fix.

> 
> > +    if (!id) {
> > +        fprintf(stderr, "ERROR %s invalid id\n",__FUNCTION__);
> > +        return 1;
> > +    }
> > +
> > +    slot = dimm_find_from_name(id);
> > +
> > +    if (!slot) {
> > +        fprintf(stderr, "%s no slot %s found\n", __FUNCTION__, id);
> > +        return 1;
> > +    }
> > +
> > +    if (add) {
> > +        if (slot->populated) {
> > +            fprintf(stderr, "ERROR %s slot %s already populated\n",
> > +                    __FUNCTION__, id);
> > +            return 1;
> > +        }
> > +        dimm_activate(slot);
> > +    }
> > +    else {
> > +        if (!slot->populated) {
> > +            fprintf(stderr, "ERROR %s slot %s is not populated\n",
> > +                    __FUNCTION__, id);
> > +            return 1;
> > +        }
> > +        dimm_deactivate(slot);
> > +    }
> > +
> > +    return 0;
> > +}
> > +
> > +DimmState *dimm_find_from_idx(uint32_t idx)
> > +{
> > +    DimmState *slot;
> > +
> > +    QTAILQ_FOREACH(slot, &dimmlist, nextdimm) {
> > +        if (slot->idx == idx) {
> > +            return slot;
> > +        }
> > +    }
> > +    return NULL;
> > +}
> > +
> > +/* used to calculate physical address offsets for all dimms */
> > +void dimm_calc_offsets(dimm_calcoffset_fn calcfn)
> > +{
> > +    DimmState *slot;
> > +    QTAILQ_FOREACH(slot, &dimmlist, nextdimm) {
> > +        if (!slot->start)
> > +            slot->start = calcfn(slot->size);
> > +    }
> > +}
> > +
> > +/* used to populate and activate dimms at boot time */
> > +void dimm_scan_populated(void)
> > +{
> > +    DimmState *slot;
> > +    QTAILQ_FOREACH(slot, &dimmlist, nextdimm) {
> > +        if (slot->populated && !slot->mr) {
> > +            dimm_activate(slot);
> > +        }
> > +    }
> > +}
> > +
> > +void dimm_notify(uint32_t idx, uint32_t event)
> > +{
> > +    DimmState *s;
> > +    s = dimm_find_from_idx(idx);
> > +    assert(s != NULL);
> > +
> > +    switch(event) {
> > +        case DIMM_REMOVE_SUCCESS:
> > +            dimm_depopulate(s);
> > +            break;
> > +        default:
> > +            break;
> > +    }
> > +}
> > +
> > +static int dimm_init(SysBusDevice *s)
> > +{
> > +    DimmState *slot;
> > +    slot = DIMM(s);
> > +    slot->mr = NULL;
> > +    slot->populated = false;
> > +    return 0;
> > +}
> > +
> > +static void dimm_class_init(ObjectClass *klass, void *data)
> > +{
> > +    SysBusDeviceClass *sc = SYS_BUS_DEVICE_CLASS(klass);
> > +    DeviceClass *dc = DEVICE_CLASS(klass);
> > +
> > +    dc->props = dimm_properties;
> > +    sc->init = dimm_init;
> > +    dimm_hotplug = NULL;
> > +    QTAILQ_INIT(&dimmlist);
> > +}
> > +
> > +static TypeInfo dimm_info = {
> > +    .name          = "dimm",
> > +    .parent        = TYPE_SYS_BUS_DEVICE,
> > +    .instance_size = sizeof(DimmState),
> > +    .class_init    = dimm_class_init,
> > +};
> > +
> > +static void dimm_register_types(void)
> > +{
> > +    type_register_static(&dimm_info);
> > +}
> > +
> > +type_init(dimm_register_types)
> > diff --git a/hw/dimm.h b/hw/dimm.h
> > new file mode 100644
> > index 0000000..643f319
> > --- /dev/null
> > +++ b/hw/dimm.h
> > @@ -0,0 +1,58 @@
> > +#ifndef QEMU_DIMM_H
> > +#define QEMU_DIMM_H
> 
> Should be HW_DIMM_H.
ok.

> 
> > +
> > +#include "qemu-common.h"
> > +#include "memory.h"
> > +#include "sysbus.h"
> > +#include "qapi-types.h"
> > +#include "qemu-queue.h"
> > +#include "cpus.h"
> > +#define MAX_DIMMS 255
> > +#define DIMM_BITMAP_BYTES (MAX_DIMMS + 7) / 8
> > +#define DEFAULT_DIMMSIZE 1024*1024*1024
> > +
> > +typedef enum {
> > +    DIMM_REMOVE_SUCCESS = 0,
> > +    DIMM_REMOVE_FAIL = 1,
> > +    DIMM_ADD_SUCCESS = 2,
> > +    DIMM_ADD_FAIL = 3
> > +} dimm_hp_result_code;
> > +
> > +#define TYPE_DIMM "dimm"
> > +#define DIMM(obj) \
> > +    OBJECT_CHECK(DimmState, (obj), TYPE_DIMM)
> > +#define DIMM_CLASS(klass) \
> > +    OBJECT_CLASS_CHECK(DimmClass, (obj), TYPE_DIMM)
> > +#define DIMM_GET_CLASS(obj) \
> > +    OBJECT_GET_CLASS(DimmClass, (obj), TYPE_DIMM)
> > +
> > +typedef struct DimmState {
> > +    SysBusDevice busdev;
> > +    uint32_t idx; /* index in memory hotplug register/bitmap */
> > +    ram_addr_t start; /* starting physical address */
> > +    ram_addr_t size;
> > +    uint32_t node; /* numa node proximity */
> > +    MemoryRegion *mr; /* MemoryRegion for this slot. !NULL only if populated */
> > +    bool populated; /* 1 means device has been hotplugged. Default is 0. */
> > +    QTAILQ_ENTRY (DimmState) nextdimm;
> > +} DimmState;
> > +
> > +typedef int (*dimm_hotplug_fn)(DeviceState *qdev, SysBusDevice *dev, int add);
> > +typedef target_phys_addr_t (*dimm_calcoffset_fn)(uint64_t size);
> > +
> > +DimmState *dimm_create(char *id, uint64_t size, uint64_t node, uint32_t
> > +        dimm_idx, bool populated);
> > +void dimm_populate(DimmState *s);
> > +void dimm_depopulate(DimmState *s);
> > +int dimm_do(Monitor *mon, const QDict *qdict, bool add);
> > +DimmState *dimm_find_from_idx(uint32_t idx);
> > +DimmState *dimm_find_from_name(char *id);
> > +void dimm_register_hotplug(dimm_hotplug_fn hotplug, DeviceState *qdev);
> > +void dimm_calc_offsets(dimm_calcoffset_fn calcfn);
> > +void dimm_activate(DimmState *slot);
> > +void dimm_deactivate(DimmState *slot);
> > +void dimm_scan_populated(void);
> > +void dimm_notify(uint32_t idx, uint32_t event);
> > +
> > +
> > +#endif
> > --
> > 1.7.9
> >
> >

  reply	other threads:[~2012-07-13 17:39 UTC|newest]

Thread overview: 86+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2012-07-11 10:31 [RFC PATCH v2 00/21] ACPI memory hotplug Vasilis Liaskovitis
2012-07-11 10:31 ` [Qemu-devel] " Vasilis Liaskovitis
2012-07-11 10:31 ` [RFC PATCH v2 01/21][SeaBIOS] Add ACPI_EXTRACT_DEVICE* macros Vasilis Liaskovitis
2012-07-11 10:31   ` [Qemu-devel] " Vasilis Liaskovitis
2012-07-11 10:31 ` [RFC PATCH v2 02/21][SeaBIOS] Add SSDT memory device support Vasilis Liaskovitis
2012-07-11 10:31   ` [Qemu-devel] " Vasilis Liaskovitis
2012-07-11 10:31 ` [RFC PATCH v2 03/21][SeaBIOS] acpi-dsdt: Implement functions for memory hotplug Vasilis Liaskovitis
2012-07-11 10:31   ` [Qemu-devel] " Vasilis Liaskovitis
2012-07-17  7:23   ` Wen Congyang
2012-07-17  7:23     ` [Qemu-devel] " Wen Congyang
2012-07-20  8:48     ` Vasilis Liaskovitis
2012-07-20  8:48       ` [Qemu-devel] " Vasilis Liaskovitis
2012-07-11 10:31 ` [RFC PATCH v2 04/21][SeaBIOS] acpi: generate hotplug memory devices Vasilis Liaskovitis
2012-07-11 10:31   ` [Qemu-devel] " Vasilis Liaskovitis
2012-07-11 10:48   ` Wen Congyang
2012-07-11 10:48     ` [Qemu-devel] " Wen Congyang
2012-07-11 16:39     ` Vasilis Liaskovitis
2012-07-11 16:39       ` [Qemu-devel] " Vasilis Liaskovitis
2012-07-11 10:31 ` [RFC PATCH v2 05/21][SeaBIOS] pciinit: Fix pcimem_start value Vasilis Liaskovitis
2012-07-11 10:31   ` [Qemu-devel] " Vasilis Liaskovitis
2012-07-11 11:56   ` Gerd Hoffmann
2012-07-11 11:56     ` [Qemu-devel] " Gerd Hoffmann
2012-07-11 16:45     ` Vasilis Liaskovitis
2012-07-11 16:45       ` [Qemu-devel] " Vasilis Liaskovitis
2012-07-12  7:22       ` Gerd Hoffmann
2012-07-12  7:22         ` [Qemu-devel] " Gerd Hoffmann
2012-07-12  9:09         ` Vasilis Liaskovitis
2012-07-12  9:09           ` [Qemu-devel] " Vasilis Liaskovitis
2012-07-11 10:31 ` [RFC PATCH v2 06/21] dimm: Implement memory device abstraction Vasilis Liaskovitis
2012-07-11 10:31   ` [Qemu-devel] " Vasilis Liaskovitis
2012-07-12 19:55   ` Blue Swirl
2012-07-12 19:55     ` [Qemu-devel] " Blue Swirl
2012-07-13 17:39     ` Vasilis Liaskovitis [this message]
2012-07-13 17:39       ` Vasilis Liaskovitis
2012-07-11 10:31 ` [RFC PATCH v2 07/21] acpi_piix4: Implement memory device hotplug registers Vasilis Liaskovitis
2012-07-11 10:31   ` [Qemu-devel] " Vasilis Liaskovitis
2012-07-11 10:31 ` [RFC PATCH v2 08/21] pc: calculate dimm physical addresses and adjust memory map Vasilis Liaskovitis
2012-07-11 10:31   ` [Qemu-devel] " Vasilis Liaskovitis
2012-07-11 10:31 ` [RFC PATCH v2 09/21] pc: Add dimm paravirt SRAT info Vasilis Liaskovitis
2012-07-11 10:31   ` [Qemu-devel] " Vasilis Liaskovitis
2012-07-12 19:48   ` Blue Swirl
2012-07-12 19:48     ` [Qemu-devel] " Blue Swirl
2012-07-13 17:40     ` Vasilis Liaskovitis
2012-07-13 17:40       ` Vasilis Liaskovitis
2012-07-11 10:31 ` [RFC PATCH v2 10/21] Implement "-dimm" command line option Vasilis Liaskovitis
2012-07-11 10:31   ` [Qemu-devel] " Vasilis Liaskovitis
2012-07-11 10:31 ` [RFC PATCH v2 11/21] Implement dimm_add and dimm_del hmp/qmp commands Vasilis Liaskovitis
2012-07-11 10:31   ` [Qemu-devel] " Vasilis Liaskovitis
2012-07-11 10:31 ` [RFC PATCH v2 12/21] fix live-migration when "populated=on" is missing Vasilis Liaskovitis
2012-07-11 10:31   ` [Qemu-devel] " Vasilis Liaskovitis
2012-07-11 10:31 ` [RFC PATCH v2 13/21] Implement memory hotplug notification lists Vasilis Liaskovitis
2012-07-11 10:31   ` [Qemu-devel] " Vasilis Liaskovitis
2012-07-11 14:59   ` Eric Blake
2012-07-11 14:59     ` Eric Blake
2012-07-11 16:47     ` Vasilis Liaskovitis
2012-07-11 16:47       ` Vasilis Liaskovitis
2012-07-11 10:31 ` [RFC PATCH v2 14/21][SeaBIOS] acpi_dsdt: Support _OST dimm method Vasilis Liaskovitis
2012-07-11 10:31   ` [Qemu-devel] " Vasilis Liaskovitis
2012-07-11 10:32 ` [RFC PATCH v2 15/21] acpi_piix4: _OST dimm support Vasilis Liaskovitis
2012-07-11 10:32   ` [Qemu-devel] " Vasilis Liaskovitis
2012-07-11 10:32 ` [RFC PATCH v2 16/21] acpi_piix4: Update dimm state on VM reboot Vasilis Liaskovitis
2012-07-11 10:32   ` [Qemu-devel] " Vasilis Liaskovitis
2012-07-11 10:32 ` [RFC PATCH v2 17/21][SeaBIOS] acpi_dsdt: Revert internal dimm state on _OST failure Vasilis Liaskovitis
2012-07-11 10:32   ` [Qemu-devel] " Vasilis Liaskovitis
2012-07-11 10:32 ` [RFC PATCH v2 18/21] acpi_piix4: Update dimm bitmap state on hot-remove fail Vasilis Liaskovitis
2012-07-11 10:32   ` [Qemu-devel] " Vasilis Liaskovitis
2012-07-11 10:32 ` [RFC PATCH v2 19/21] Implement "info memtotal" and "query-memtotal" Vasilis Liaskovitis
2012-07-11 10:32   ` [Qemu-devel] " Vasilis Liaskovitis
2012-07-11 15:14   ` Eric Blake
2012-07-11 15:14     ` [Qemu-devel] " Eric Blake
2012-07-11 16:55     ` Vasilis Liaskovitis
2012-07-11 16:55       ` Vasilis Liaskovitis
2012-07-11 10:32 ` [RFC PATCH v2 20/21] Implement -dimms, -dimmspop command line options Vasilis Liaskovitis
2012-07-11 10:32   ` [Qemu-devel] " Vasilis Liaskovitis
2012-07-11 14:55   ` Avi Kivity
2012-07-11 14:55     ` [Qemu-devel] " Avi Kivity
2012-07-11 16:57     ` Vasilis Liaskovitis
2012-07-11 16:57       ` [Qemu-devel] " Vasilis Liaskovitis
2012-07-11 10:32 ` [RFC PATCH v2 21/21] Implement mem_increase, mem_decrease hmp/qmp commands Vasilis Liaskovitis
2012-07-11 10:32   ` [Qemu-devel] " Vasilis Liaskovitis
2012-07-12 20:04 ` [Qemu-devel] [RFC PATCH v2 00/21] ACPI memory hotplug Blue Swirl
2012-07-12 20:04   ` Blue Swirl
2012-07-13 17:49   ` Vasilis Liaskovitis
2012-07-13 17:49     ` Vasilis Liaskovitis
2012-07-14  9:08     ` Blue Swirl
2012-07-14  9:08       ` [Qemu-devel] " Blue Swirl

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=20120713173920.GC13216@dhcp-192-168-178-175.profitbricks.localdomain \
    --to=vasilis.liaskovitis@profitbricks.com \
    --cc=anthony@codemonkey.ws \
    --cc=avi@redhat.com \
    --cc=blauwirbel@gmail.com \
    --cc=gleb@redhat.com \
    --cc=imammedo@redhat.com \
    --cc=kevin@koconnor.net \
    --cc=kvm@vger.kernel.org \
    --cc=qemu-devel@nongnu.org \
    --cc=seabios@seabios.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.