2014-06-02 15:25:05 +02:00
|
|
|
/*
|
|
|
|
* Dimm device for Memory Hotplug
|
|
|
|
*
|
|
|
|
* Copyright ProfitBricks GmbH 2012
|
|
|
|
* Copyright (C) 2014 Red Hat Inc
|
|
|
|
*
|
|
|
|
* 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/>
|
|
|
|
*/
|
|
|
|
|
2016-01-26 19:17:30 +01:00
|
|
|
#include "qemu/osdep.h"
|
2014-06-02 15:25:05 +02:00
|
|
|
#include "hw/mem/pc-dimm.h"
|
include/qemu/osdep.h: Don't include qapi/error.h
Commit 57cb38b included qapi/error.h into qemu/osdep.h to get the
Error typedef. Since then, we've moved to include qemu/osdep.h
everywhere. Its file comment explains: "To avoid getting into
possible circular include dependencies, this file should not include
any other QEMU headers, with the exceptions of config-host.h,
compiler.h, os-posix.h and os-win32.h, all of which are doing a
similar job to this file and are under similar constraints."
qapi/error.h doesn't do a similar job, and it doesn't adhere to
similar constraints: it includes qapi-types.h. That's in excess of
100KiB of crap most .c files don't actually need.
Add the typedef to qemu/typedefs.h, and include that instead of
qapi/error.h. Include qapi/error.h in .c files that need it and don't
get it now. Include qapi-types.h in qom/object.h for uint16List.
Update scripts/clean-includes accordingly. Update it further to match
reality: replace config.h by config-target.h, add sysemu/os-posix.h,
sysemu/os-win32.h. Update the list of includes in the qemu/osdep.h
comment quoted above similarly.
This reduces the number of objects depending on qapi/error.h from "all
of them" to less than a third. Unfortunately, the number depending on
qapi-types.h shrinks only a little. More work is needed for that one.
Signed-off-by: Markus Armbruster <armbru@redhat.com>
[Fix compilation without the spice devel packages. - Paolo]
Signed-off-by: Paolo Bonzini <pbonzini@redhat.com>
2016-03-14 09:01:28 +01:00
|
|
|
#include "qapi/error.h"
|
2014-06-02 15:25:05 +02:00
|
|
|
#include "qemu/config-file.h"
|
|
|
|
#include "qapi/visitor.h"
|
2014-06-02 15:25:13 +02:00
|
|
|
#include "qemu/range.h"
|
2015-02-08 19:51:16 +01:00
|
|
|
#include "sysemu/numa.h"
|
2015-06-29 10:20:23 +02:00
|
|
|
#include "sysemu/kvm.h"
|
|
|
|
#include "trace.h"
|
2015-10-06 10:37:28 +02:00
|
|
|
#include "hw/virtio/vhost.h"
|
2015-01-27 05:05:01 +01:00
|
|
|
|
2015-01-27 05:05:02 +01:00
|
|
|
typedef struct pc_dimms_capacity {
|
|
|
|
uint64_t size;
|
|
|
|
Error **errp;
|
|
|
|
} pc_dimms_capacity;
|
|
|
|
|
2015-06-29 10:20:23 +02:00
|
|
|
void pc_dimm_memory_plug(DeviceState *dev, MemoryHotplugState *hpms,
|
2015-10-28 17:55:06 +01:00
|
|
|
MemoryRegion *mr, uint64_t align, Error **errp)
|
2015-06-29 10:20:23 +02:00
|
|
|
{
|
|
|
|
int slot;
|
|
|
|
MachineState *machine = MACHINE(qdev_get_machine());
|
|
|
|
PCDIMMDevice *dimm = PC_DIMM(dev);
|
2016-06-07 14:21:57 +02:00
|
|
|
PCDIMMDeviceClass *ddc = PC_DIMM_GET_CLASS(dimm);
|
|
|
|
MemoryRegion *vmstate_mr = ddc->get_vmstate_memory_region(dimm);
|
2015-06-29 10:20:23 +02:00
|
|
|
Error *local_err = NULL;
|
|
|
|
uint64_t existing_dimms_capacity = 0;
|
|
|
|
uint64_t addr;
|
|
|
|
|
|
|
|
addr = object_property_get_int(OBJECT(dimm), PC_DIMM_ADDR_PROP, &local_err);
|
|
|
|
if (local_err) {
|
|
|
|
goto out;
|
|
|
|
}
|
|
|
|
|
|
|
|
addr = pc_dimm_get_free_addr(hpms->base,
|
|
|
|
memory_region_size(&hpms->mr),
|
2015-10-28 17:55:06 +01:00
|
|
|
!addr ? NULL : &addr, align,
|
2015-06-29 10:20:23 +02:00
|
|
|
memory_region_size(mr), &local_err);
|
|
|
|
if (local_err) {
|
|
|
|
goto out;
|
|
|
|
}
|
|
|
|
|
|
|
|
existing_dimms_capacity = pc_existing_dimms_capacity(&local_err);
|
|
|
|
if (local_err) {
|
|
|
|
goto out;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (existing_dimms_capacity + memory_region_size(mr) >
|
|
|
|
machine->maxram_size - machine->ram_size) {
|
|
|
|
error_setg(&local_err, "not enough space, currently 0x%" PRIx64
|
|
|
|
" in use of total hot pluggable 0x" RAM_ADDR_FMT,
|
|
|
|
existing_dimms_capacity,
|
|
|
|
machine->maxram_size - machine->ram_size);
|
|
|
|
goto out;
|
|
|
|
}
|
|
|
|
|
|
|
|
object_property_set_int(OBJECT(dev), addr, PC_DIMM_ADDR_PROP, &local_err);
|
|
|
|
if (local_err) {
|
|
|
|
goto out;
|
|
|
|
}
|
|
|
|
trace_mhp_pc_dimm_assigned_address(addr);
|
|
|
|
|
|
|
|
slot = object_property_get_int(OBJECT(dev), PC_DIMM_SLOT_PROP, &local_err);
|
|
|
|
if (local_err) {
|
|
|
|
goto out;
|
|
|
|
}
|
|
|
|
|
|
|
|
slot = pc_dimm_get_free_slot(slot == PC_DIMM_UNASSIGNED_SLOT ? NULL : &slot,
|
|
|
|
machine->ram_slots, &local_err);
|
|
|
|
if (local_err) {
|
|
|
|
goto out;
|
|
|
|
}
|
|
|
|
object_property_set_int(OBJECT(dev), slot, PC_DIMM_SLOT_PROP, &local_err);
|
|
|
|
if (local_err) {
|
|
|
|
goto out;
|
|
|
|
}
|
|
|
|
trace_mhp_pc_dimm_assigned_slot(slot);
|
|
|
|
|
|
|
|
if (kvm_enabled() && !kvm_has_free_slot(machine)) {
|
|
|
|
error_setg(&local_err, "hypervisor has no free memory slots left");
|
|
|
|
goto out;
|
|
|
|
}
|
|
|
|
|
2015-10-06 10:37:28 +02:00
|
|
|
if (!vhost_has_free_slot()) {
|
|
|
|
error_setg(&local_err, "a used vhost backend has no free"
|
|
|
|
" memory slots left");
|
|
|
|
goto out;
|
|
|
|
}
|
|
|
|
|
2015-06-29 10:20:23 +02:00
|
|
|
memory_region_add_subregion(&hpms->mr, addr - hpms->base, mr);
|
2016-06-07 14:21:57 +02:00
|
|
|
vmstate_register_ram(vmstate_mr, dev);
|
2015-06-29 10:20:25 +02:00
|
|
|
numa_set_mem_node_id(addr, memory_region_size(mr), dimm->node);
|
2015-06-29 10:20:23 +02:00
|
|
|
|
|
|
|
out:
|
|
|
|
error_propagate(errp, local_err);
|
|
|
|
}
|
|
|
|
|
|
|
|
void pc_dimm_memory_unplug(DeviceState *dev, MemoryHotplugState *hpms,
|
|
|
|
MemoryRegion *mr)
|
|
|
|
{
|
2015-06-29 10:20:25 +02:00
|
|
|
PCDIMMDevice *dimm = PC_DIMM(dev);
|
2016-06-07 14:21:57 +02:00
|
|
|
PCDIMMDeviceClass *ddc = PC_DIMM_GET_CLASS(dimm);
|
|
|
|
MemoryRegion *vmstate_mr = ddc->get_vmstate_memory_region(dimm);
|
2015-06-29 10:20:25 +02:00
|
|
|
|
|
|
|
numa_unset_mem_node_id(dimm->addr, memory_region_size(mr), dimm->node);
|
2015-06-29 10:20:23 +02:00
|
|
|
memory_region_del_subregion(&hpms->mr, mr);
|
2016-06-07 14:21:57 +02:00
|
|
|
vmstate_unregister_ram(vmstate_mr, dev);
|
2015-06-29 10:20:23 +02:00
|
|
|
}
|
|
|
|
|
2015-01-27 05:05:02 +01:00
|
|
|
static int pc_existing_dimms_capacity_internal(Object *obj, void *opaque)
|
2015-01-27 05:05:01 +01:00
|
|
|
{
|
2015-01-27 05:05:02 +01:00
|
|
|
pc_dimms_capacity *cap = opaque;
|
|
|
|
uint64_t *size = &cap->size;
|
2015-01-27 05:05:01 +01:00
|
|
|
|
|
|
|
if (object_dynamic_cast(obj, TYPE_PC_DIMM)) {
|
|
|
|
DeviceState *dev = DEVICE(obj);
|
|
|
|
|
|
|
|
if (dev->realized) {
|
|
|
|
(*size) += object_property_get_int(obj, PC_DIMM_SIZE_PROP,
|
2015-01-27 05:05:02 +01:00
|
|
|
cap->errp);
|
2015-01-27 05:05:01 +01:00
|
|
|
}
|
|
|
|
|
2015-01-27 05:05:02 +01:00
|
|
|
if (cap->errp && *cap->errp) {
|
2015-01-27 05:05:01 +01:00
|
|
|
return 1;
|
|
|
|
}
|
|
|
|
}
|
2015-01-27 05:05:02 +01:00
|
|
|
object_child_foreach(obj, pc_existing_dimms_capacity_internal, opaque);
|
2015-01-27 05:05:01 +01:00
|
|
|
return 0;
|
|
|
|
}
|
2014-06-02 15:25:13 +02:00
|
|
|
|
2015-01-27 05:05:02 +01:00
|
|
|
uint64_t pc_existing_dimms_capacity(Error **errp)
|
|
|
|
{
|
|
|
|
pc_dimms_capacity cap;
|
|
|
|
|
|
|
|
cap.size = 0;
|
|
|
|
cap.errp = errp;
|
|
|
|
|
|
|
|
pc_existing_dimms_capacity_internal(qdev_get_machine(), &cap);
|
|
|
|
return cap.size;
|
|
|
|
}
|
|
|
|
|
2014-06-16 19:12:25 +02:00
|
|
|
int qmp_pc_dimm_device_list(Object *obj, void *opaque)
|
|
|
|
{
|
|
|
|
MemoryDeviceInfoList ***prev = opaque;
|
|
|
|
|
|
|
|
if (object_dynamic_cast(obj, TYPE_PC_DIMM)) {
|
|
|
|
DeviceState *dev = DEVICE(obj);
|
|
|
|
|
|
|
|
if (dev->realized) {
|
|
|
|
MemoryDeviceInfoList *elem = g_new0(MemoryDeviceInfoList, 1);
|
|
|
|
MemoryDeviceInfo *info = g_new0(MemoryDeviceInfo, 1);
|
|
|
|
PCDIMMDeviceInfo *di = g_new0(PCDIMMDeviceInfo, 1);
|
|
|
|
DeviceClass *dc = DEVICE_GET_CLASS(obj);
|
|
|
|
PCDIMMDevice *dimm = PC_DIMM(obj);
|
|
|
|
|
|
|
|
if (dev->id) {
|
|
|
|
di->has_id = true;
|
|
|
|
di->id = g_strdup(dev->id);
|
|
|
|
}
|
|
|
|
di->hotplugged = dev->hotplugged;
|
|
|
|
di->hotpluggable = dc->hotpluggable;
|
|
|
|
di->addr = dimm->addr;
|
|
|
|
di->slot = dimm->slot;
|
|
|
|
di->node = dimm->node;
|
|
|
|
di->size = object_property_get_int(OBJECT(dimm), PC_DIMM_SIZE_PROP,
|
|
|
|
NULL);
|
|
|
|
di->memdev = object_get_canonical_path(OBJECT(dimm->hostmem));
|
|
|
|
|
qapi: Don't special-case simple union wrappers
Simple unions were carrying a special case that hid their 'data'
QMP member from the resulting C struct, via the hack method
QAPISchemaObjectTypeVariant.simple_union_type(). But by using
the work we started by unboxing flat union and alternate
branches, coupled with the ability to visit the members of an
implicit type, we can now expose the simple union's implicit
type in qapi-types.h:
| struct q_obj_ImageInfoSpecificQCow2_wrapper {
| ImageInfoSpecificQCow2 *data;
| };
|
| struct q_obj_ImageInfoSpecificVmdk_wrapper {
| ImageInfoSpecificVmdk *data;
| };
...
| struct ImageInfoSpecific {
| ImageInfoSpecificKind type;
| union { /* union tag is @type */
| void *data;
|- ImageInfoSpecificQCow2 *qcow2;
|- ImageInfoSpecificVmdk *vmdk;
|+ q_obj_ImageInfoSpecificQCow2_wrapper qcow2;
|+ q_obj_ImageInfoSpecificVmdk_wrapper vmdk;
| } u;
| };
Doing this removes asymmetry between QAPI's QMP side and its
C side (both sides now expose 'data'), and means that the
treatment of a simple union as sugar for a flat union is now
equivalent in both languages (previously the two approaches used
a different layer of dereferencing, where the simple union could
be converted to a flat union with equivalent C layout but
different {} on the wire, or to an equivalent QMP wire form
but with different C representation). Using the implicit type
also lets us get rid of the simple_union_type() hack.
Of course, now all clients of simple unions have to adjust from
using su->u.member to using su->u.member.data; while this touches
a number of files in the tree, some earlier cleanup patches
helped minimize the change to the initialization of a temporary
variable rather than every single member access. The generated
qapi-visit.c code is also affected by the layout change:
|@@ -7393,10 +7393,10 @@ void visit_type_ImageInfoSpecific_member
| }
| switch (obj->type) {
| case IMAGE_INFO_SPECIFIC_KIND_QCOW2:
|- visit_type_ImageInfoSpecificQCow2(v, "data", &obj->u.qcow2, &err);
|+ visit_type_q_obj_ImageInfoSpecificQCow2_wrapper_members(v, &obj->u.qcow2, &err);
| break;
| case IMAGE_INFO_SPECIFIC_KIND_VMDK:
|- visit_type_ImageInfoSpecificVmdk(v, "data", &obj->u.vmdk, &err);
|+ visit_type_q_obj_ImageInfoSpecificVmdk_wrapper_members(v, &obj->u.vmdk, &err);
| break;
| default:
| abort();
Signed-off-by: Eric Blake <eblake@redhat.com>
Message-Id: <1458254921-17042-13-git-send-email-eblake@redhat.com>
Signed-off-by: Markus Armbruster <armbru@redhat.com>
2016-03-17 23:48:37 +01:00
|
|
|
info->u.dimm.data = di;
|
2014-06-16 19:12:25 +02:00
|
|
|
elem->value = info;
|
|
|
|
elem->next = NULL;
|
|
|
|
**prev = elem;
|
|
|
|
*prev = &elem->next;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
object_child_foreach(obj, qmp_pc_dimm_device_list, opaque);
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
2014-06-02 15:25:14 +02:00
|
|
|
static int pc_dimm_slot2bitmap(Object *obj, void *opaque)
|
|
|
|
{
|
|
|
|
unsigned long *bitmap = opaque;
|
|
|
|
|
|
|
|
if (object_dynamic_cast(obj, TYPE_PC_DIMM)) {
|
|
|
|
DeviceState *dev = DEVICE(obj);
|
|
|
|
if (dev->realized) { /* count only realized DIMMs */
|
|
|
|
PCDIMMDevice *d = PC_DIMM(obj);
|
|
|
|
set_bit(d->slot, bitmap);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
object_child_foreach(obj, pc_dimm_slot2bitmap, opaque);
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
int pc_dimm_get_free_slot(const int *hint, int max_slots, Error **errp)
|
|
|
|
{
|
|
|
|
unsigned long *bitmap = bitmap_new(max_slots);
|
|
|
|
int slot = 0;
|
|
|
|
|
|
|
|
object_child_foreach(qdev_get_machine(), pc_dimm_slot2bitmap, bitmap);
|
|
|
|
|
|
|
|
/* check if requested slot is not occupied */
|
|
|
|
if (hint) {
|
|
|
|
if (*hint >= max_slots) {
|
|
|
|
error_setg(errp, "invalid slot# %d, should be less than %d",
|
|
|
|
*hint, max_slots);
|
|
|
|
} else if (!test_bit(*hint, bitmap)) {
|
|
|
|
slot = *hint;
|
|
|
|
} else {
|
|
|
|
error_setg(errp, "slot %d is busy", *hint);
|
|
|
|
}
|
|
|
|
goto out;
|
|
|
|
}
|
|
|
|
|
|
|
|
/* search for free slot */
|
|
|
|
slot = find_first_zero_bit(bitmap, max_slots);
|
|
|
|
if (slot == max_slots) {
|
|
|
|
error_setg(errp, "no free slots available");
|
|
|
|
}
|
|
|
|
out:
|
|
|
|
g_free(bitmap);
|
|
|
|
return slot;
|
|
|
|
}
|
|
|
|
|
2014-06-02 15:25:13 +02:00
|
|
|
static gint pc_dimm_addr_sort(gconstpointer a, gconstpointer b)
|
|
|
|
{
|
|
|
|
PCDIMMDevice *x = PC_DIMM(a);
|
|
|
|
PCDIMMDevice *y = PC_DIMM(b);
|
|
|
|
Int128 diff = int128_sub(int128_make64(x->addr), int128_make64(y->addr));
|
|
|
|
|
|
|
|
if (int128_lt(diff, int128_zero())) {
|
|
|
|
return -1;
|
|
|
|
} else if (int128_gt(diff, int128_zero())) {
|
|
|
|
return 1;
|
|
|
|
}
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
static int pc_dimm_built_list(Object *obj, void *opaque)
|
|
|
|
{
|
|
|
|
GSList **list = opaque;
|
|
|
|
|
|
|
|
if (object_dynamic_cast(obj, TYPE_PC_DIMM)) {
|
|
|
|
DeviceState *dev = DEVICE(obj);
|
|
|
|
if (dev->realized) { /* only realized DIMMs matter */
|
|
|
|
*list = g_slist_insert_sorted(*list, dev, pc_dimm_addr_sort);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
object_child_foreach(obj, pc_dimm_built_list, opaque);
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
uint64_t pc_dimm_get_free_addr(uint64_t address_space_start,
|
|
|
|
uint64_t address_space_size,
|
2015-10-28 17:55:06 +01:00
|
|
|
uint64_t *hint, uint64_t align, uint64_t size,
|
|
|
|
Error **errp)
|
2014-06-02 15:25:13 +02:00
|
|
|
{
|
|
|
|
GSList *list = NULL, *item;
|
|
|
|
uint64_t new_addr, ret = 0;
|
|
|
|
uint64_t address_space_end = address_space_start + address_space_size;
|
|
|
|
|
2014-10-31 17:38:40 +01:00
|
|
|
g_assert(QEMU_ALIGN_UP(address_space_start, align) == address_space_start);
|
|
|
|
|
2014-06-30 12:43:29 +02:00
|
|
|
if (!address_space_size) {
|
|
|
|
error_setg(errp, "memory hotplug is not enabled, "
|
|
|
|
"please add maxmem option");
|
|
|
|
goto out;
|
|
|
|
}
|
|
|
|
|
2014-10-31 17:38:36 +01:00
|
|
|
if (hint && QEMU_ALIGN_UP(*hint, align) != *hint) {
|
|
|
|
error_setg(errp, "address must be aligned to 0x%" PRIx64 " bytes",
|
|
|
|
align);
|
|
|
|
goto out;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (QEMU_ALIGN_UP(size, align) != size) {
|
|
|
|
error_setg(errp, "backend memory size must be multiple of 0x%"
|
|
|
|
PRIx64, align);
|
|
|
|
goto out;
|
|
|
|
}
|
|
|
|
|
2014-06-30 12:43:29 +02:00
|
|
|
assert(address_space_end > address_space_start);
|
2014-06-02 15:25:13 +02:00
|
|
|
object_child_foreach(qdev_get_machine(), pc_dimm_built_list, &list);
|
|
|
|
|
|
|
|
if (hint) {
|
|
|
|
new_addr = *hint;
|
|
|
|
} else {
|
|
|
|
new_addr = address_space_start;
|
|
|
|
}
|
|
|
|
|
|
|
|
/* find address range that will fit new DIMM */
|
|
|
|
for (item = list; item; item = g_slist_next(item)) {
|
|
|
|
PCDIMMDevice *dimm = item->data;
|
|
|
|
uint64_t dimm_size = object_property_get_int(OBJECT(dimm),
|
|
|
|
PC_DIMM_SIZE_PROP,
|
|
|
|
errp);
|
|
|
|
if (errp && *errp) {
|
|
|
|
goto out;
|
|
|
|
}
|
|
|
|
|
2015-10-28 17:55:06 +01:00
|
|
|
if (ranges_overlap(dimm->addr, dimm_size, new_addr, size)) {
|
2014-06-02 15:25:13 +02:00
|
|
|
if (hint) {
|
|
|
|
DeviceState *d = DEVICE(dimm);
|
|
|
|
error_setg(errp, "address range conflicts with '%s'", d->id);
|
|
|
|
goto out;
|
|
|
|
}
|
2015-10-28 17:55:06 +01:00
|
|
|
new_addr = QEMU_ALIGN_UP(dimm->addr + dimm_size, align);
|
2014-06-02 15:25:13 +02:00
|
|
|
}
|
|
|
|
}
|
|
|
|
ret = new_addr;
|
|
|
|
|
|
|
|
if (new_addr < address_space_start) {
|
|
|
|
error_setg(errp, "can't add memory [0x%" PRIx64 ":0x%" PRIx64
|
|
|
|
"] at 0x%" PRIx64, new_addr, size, address_space_start);
|
|
|
|
} else if ((new_addr + size) > address_space_end) {
|
|
|
|
error_setg(errp, "can't add memory [0x%" PRIx64 ":0x%" PRIx64
|
|
|
|
"] beyond 0x%" PRIx64, new_addr, size, address_space_end);
|
|
|
|
}
|
|
|
|
|
|
|
|
out:
|
|
|
|
g_slist_free(list);
|
|
|
|
return ret;
|
|
|
|
}
|
2014-06-02 15:25:05 +02:00
|
|
|
|
|
|
|
static Property pc_dimm_properties[] = {
|
|
|
|
DEFINE_PROP_UINT64(PC_DIMM_ADDR_PROP, PCDIMMDevice, addr, 0),
|
|
|
|
DEFINE_PROP_UINT32(PC_DIMM_NODE_PROP, PCDIMMDevice, node, 0),
|
|
|
|
DEFINE_PROP_INT32(PC_DIMM_SLOT_PROP, PCDIMMDevice, slot,
|
|
|
|
PC_DIMM_UNASSIGNED_SLOT),
|
|
|
|
DEFINE_PROP_END_OF_LIST(),
|
|
|
|
};
|
|
|
|
|
qom: Swap 'name' next to visitor in ObjectPropertyAccessor
Similar to the previous patch, it's nice to have all functions
in the tree that involve a visitor and a name for conversion to
or from QAPI to consistently stick the 'name' parameter next
to the Visitor parameter.
Done by manually changing include/qom/object.h and qom/object.c,
then running this Coccinelle script and touching up the fallout
(Coccinelle insisted on adding some trailing whitespace).
@ rule1 @
identifier fn;
typedef Object, Visitor, Error;
identifier obj, v, opaque, name, errp;
@@
void fn
- (Object *obj, Visitor *v, void *opaque, const char *name,
+ (Object *obj, Visitor *v, const char *name, void *opaque,
Error **errp) { ... }
@@
identifier rule1.fn;
expression obj, v, opaque, name, errp;
@@
fn(obj, v,
- opaque, name,
+ name, opaque,
errp)
Signed-off-by: Eric Blake <eblake@redhat.com>
Reviewed-by: Marc-André Lureau <marcandre.lureau@redhat.com>
Message-Id: <1454075341-13658-20-git-send-email-eblake@redhat.com>
Signed-off-by: Markus Armbruster <armbru@redhat.com>
2016-01-29 14:48:55 +01:00
|
|
|
static void pc_dimm_get_size(Object *obj, Visitor *v, const char *name,
|
|
|
|
void *opaque, Error **errp)
|
2014-06-02 15:25:05 +02:00
|
|
|
{
|
|
|
|
int64_t value;
|
|
|
|
MemoryRegion *mr;
|
|
|
|
PCDIMMDevice *dimm = PC_DIMM(obj);
|
2016-05-20 10:19:58 +02:00
|
|
|
PCDIMMDeviceClass *ddc = PC_DIMM_GET_CLASS(obj);
|
2014-06-02 15:25:05 +02:00
|
|
|
|
2016-05-20 10:19:58 +02:00
|
|
|
mr = ddc->get_memory_region(dimm);
|
2014-06-02 15:25:05 +02:00
|
|
|
value = memory_region_size(mr);
|
|
|
|
|
qapi: Swap visit_* arguments for consistent 'name' placement
JSON uses "name":value, but many of our visitor interfaces were
called with visit_type_FOO(v, &value, name, errp). This can be
a bit confusing to have to mentally swap the parameter order to
match JSON order. It's particularly bad for visit_start_struct(),
where the 'name' parameter is smack in the middle of the
otherwise-related group of 'obj, kind, size' parameters! It's
time to do a global swap of the parameter ordering, so that the
'name' parameter is always immediately after the Visitor argument.
Additional reason in favor of the swap: the existing include/qjson.h
prefers listing 'name' first in json_prop_*(), and I have plans to
unify that file with the qapi visitors; listing 'name' first in
qapi will minimize churn to the (admittedly few) qjson.h clients.
Later patches will then fix docs, object.h, visitor-impl.h, and
those clients to match.
Done by first patching scripts/qapi*.py by hand to make generated
files do what I want, then by running the following Coccinelle
script to affect the rest of the code base:
$ spatch --sp-file script `git grep -l '\bvisit_' -- '**/*.[ch]'`
I then had to apply some touchups (Coccinelle insisted on TAB
indentation in visitor.h, and botched the signature of
visit_type_enum() by rewriting 'const char *const strings[]' to
the syntactically invalid 'const char*const[] strings'). The
movement of parameters is sufficient to provoke compiler errors
if any callers were missed.
// Part 1: Swap declaration order
@@
type TV, TErr, TObj, T1, T2;
identifier OBJ, ARG1, ARG2;
@@
void visit_start_struct
-(TV v, TObj OBJ, T1 ARG1, const char *name, T2 ARG2, TErr errp)
+(TV v, const char *name, TObj OBJ, T1 ARG1, T2 ARG2, TErr errp)
{ ... }
@@
type bool, TV, T1;
identifier ARG1;
@@
bool visit_optional
-(TV v, T1 ARG1, const char *name)
+(TV v, const char *name, T1 ARG1)
{ ... }
@@
type TV, TErr, TObj, T1;
identifier OBJ, ARG1;
@@
void visit_get_next_type
-(TV v, TObj OBJ, T1 ARG1, const char *name, TErr errp)
+(TV v, const char *name, TObj OBJ, T1 ARG1, TErr errp)
{ ... }
@@
type TV, TErr, TObj, T1, T2;
identifier OBJ, ARG1, ARG2;
@@
void visit_type_enum
-(TV v, TObj OBJ, T1 ARG1, T2 ARG2, const char *name, TErr errp)
+(TV v, const char *name, TObj OBJ, T1 ARG1, T2 ARG2, TErr errp)
{ ... }
@@
type TV, TErr, TObj;
identifier OBJ;
identifier VISIT_TYPE =~ "^visit_type_";
@@
void VISIT_TYPE
-(TV v, TObj OBJ, const char *name, TErr errp)
+(TV v, const char *name, TObj OBJ, TErr errp)
{ ... }
// Part 2: swap caller order
@@
expression V, NAME, OBJ, ARG1, ARG2, ERR;
identifier VISIT_TYPE =~ "^visit_type_";
@@
(
-visit_start_struct(V, OBJ, ARG1, NAME, ARG2, ERR)
+visit_start_struct(V, NAME, OBJ, ARG1, ARG2, ERR)
|
-visit_optional(V, ARG1, NAME)
+visit_optional(V, NAME, ARG1)
|
-visit_get_next_type(V, OBJ, ARG1, NAME, ERR)
+visit_get_next_type(V, NAME, OBJ, ARG1, ERR)
|
-visit_type_enum(V, OBJ, ARG1, ARG2, NAME, ERR)
+visit_type_enum(V, NAME, OBJ, ARG1, ARG2, ERR)
|
-VISIT_TYPE(V, OBJ, NAME, ERR)
+VISIT_TYPE(V, NAME, OBJ, ERR)
)
Signed-off-by: Eric Blake <eblake@redhat.com>
Reviewed-by: Marc-André Lureau <marcandre.lureau@redhat.com>
Message-Id: <1454075341-13658-19-git-send-email-eblake@redhat.com>
Signed-off-by: Markus Armbruster <armbru@redhat.com>
2016-01-29 14:48:54 +01:00
|
|
|
visit_type_int(v, name, &value, errp);
|
2014-06-02 15:25:05 +02:00
|
|
|
}
|
|
|
|
|
2014-06-02 15:25:07 +02:00
|
|
|
static void pc_dimm_check_memdev_is_busy(Object *obj, const char *name,
|
|
|
|
Object *val, Error **errp)
|
|
|
|
{
|
2016-03-01 10:40:48 +01:00
|
|
|
Error *local_err = NULL;
|
2014-06-02 15:25:07 +02:00
|
|
|
|
2016-07-13 06:18:06 +02:00
|
|
|
if (host_memory_backend_is_mapped(MEMORY_BACKEND(val))) {
|
2014-06-02 15:25:07 +02:00
|
|
|
char *path = object_get_canonical_path_component(val);
|
2016-03-01 10:40:48 +01:00
|
|
|
error_setg(&local_err, "can't use already busy memdev: %s", path);
|
2014-06-02 15:25:07 +02:00
|
|
|
g_free(path);
|
|
|
|
} else {
|
2016-03-01 10:40:48 +01:00
|
|
|
qdev_prop_allow_set_link_before_realize(obj, name, val, &local_err);
|
2014-06-02 15:25:07 +02:00
|
|
|
}
|
2016-03-01 10:40:48 +01:00
|
|
|
|
|
|
|
error_propagate(errp, local_err);
|
2014-06-02 15:25:07 +02:00
|
|
|
}
|
|
|
|
|
2014-06-02 15:25:05 +02:00
|
|
|
static void pc_dimm_init(Object *obj)
|
|
|
|
{
|
|
|
|
PCDIMMDevice *dimm = PC_DIMM(obj);
|
|
|
|
|
|
|
|
object_property_add(obj, PC_DIMM_SIZE_PROP, "int", pc_dimm_get_size,
|
|
|
|
NULL, NULL, NULL, &error_abort);
|
|
|
|
object_property_add_link(obj, PC_DIMM_MEMDEV_PROP, TYPE_MEMORY_BACKEND,
|
|
|
|
(Object **)&dimm->hostmem,
|
2014-06-02 15:25:07 +02:00
|
|
|
pc_dimm_check_memdev_is_busy,
|
2014-06-02 15:25:05 +02:00
|
|
|
OBJ_PROP_LINK_UNREF_ON_RELEASE,
|
|
|
|
&error_abort);
|
|
|
|
}
|
|
|
|
|
|
|
|
static void pc_dimm_realize(DeviceState *dev, Error **errp)
|
|
|
|
{
|
|
|
|
PCDIMMDevice *dimm = PC_DIMM(dev);
|
2016-05-20 10:19:59 +02:00
|
|
|
PCDIMMDeviceClass *ddc = PC_DIMM_GET_CLASS(dimm);
|
2014-06-02 15:25:05 +02:00
|
|
|
|
|
|
|
if (!dimm->hostmem) {
|
|
|
|
error_setg(errp, "'" PC_DIMM_MEMDEV_PROP "' property is not set");
|
|
|
|
return;
|
|
|
|
}
|
2015-07-17 14:49:40 +02:00
|
|
|
if (((nb_numa_nodes > 0) && (dimm->node >= nb_numa_nodes)) ||
|
|
|
|
(!nb_numa_nodes && dimm->node)) {
|
2014-08-04 14:21:59 +02:00
|
|
|
error_setg(errp, "'DIMM property " PC_DIMM_NODE_PROP " has value %"
|
|
|
|
PRIu32 "' which exceeds the number of numa nodes: %d",
|
2015-07-17 14:49:40 +02:00
|
|
|
dimm->node, nb_numa_nodes ? nb_numa_nodes : 1);
|
2014-08-04 10:16:08 +02:00
|
|
|
return;
|
|
|
|
}
|
2016-05-20 10:19:59 +02:00
|
|
|
|
|
|
|
if (ddc->realize) {
|
|
|
|
ddc->realize(dimm, errp);
|
|
|
|
}
|
2016-07-13 06:18:06 +02:00
|
|
|
|
|
|
|
host_memory_backend_set_mapped(dimm->hostmem, true);
|
|
|
|
}
|
|
|
|
|
|
|
|
static void pc_dimm_unrealize(DeviceState *dev, Error **errp)
|
|
|
|
{
|
|
|
|
PCDIMMDevice *dimm = PC_DIMM(dev);
|
|
|
|
|
|
|
|
host_memory_backend_set_mapped(dimm->hostmem, false);
|
2014-06-02 15:25:05 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
static MemoryRegion *pc_dimm_get_memory_region(PCDIMMDevice *dimm)
|
|
|
|
{
|
|
|
|
return host_memory_backend_get_memory(dimm->hostmem, &error_abort);
|
|
|
|
}
|
|
|
|
|
2016-06-07 14:21:57 +02:00
|
|
|
static MemoryRegion *pc_dimm_get_vmstate_memory_region(PCDIMMDevice *dimm)
|
|
|
|
{
|
|
|
|
return host_memory_backend_get_memory(dimm->hostmem, &error_abort);
|
|
|
|
}
|
|
|
|
|
2014-06-02 15:25:05 +02:00
|
|
|
static void pc_dimm_class_init(ObjectClass *oc, void *data)
|
|
|
|
{
|
|
|
|
DeviceClass *dc = DEVICE_CLASS(oc);
|
|
|
|
PCDIMMDeviceClass *ddc = PC_DIMM_CLASS(oc);
|
|
|
|
|
|
|
|
dc->realize = pc_dimm_realize;
|
2016-07-13 06:18:06 +02:00
|
|
|
dc->unrealize = pc_dimm_unrealize;
|
2014-06-02 15:25:05 +02:00
|
|
|
dc->props = pc_dimm_properties;
|
2015-03-10 12:25:51 +01:00
|
|
|
dc->desc = "DIMM memory module";
|
2014-06-02 15:25:05 +02:00
|
|
|
|
|
|
|
ddc->get_memory_region = pc_dimm_get_memory_region;
|
2016-06-07 14:21:57 +02:00
|
|
|
ddc->get_vmstate_memory_region = pc_dimm_get_vmstate_memory_region;
|
2014-06-02 15:25:05 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
static TypeInfo pc_dimm_info = {
|
|
|
|
.name = TYPE_PC_DIMM,
|
|
|
|
.parent = TYPE_DEVICE,
|
|
|
|
.instance_size = sizeof(PCDIMMDevice),
|
|
|
|
.instance_init = pc_dimm_init,
|
|
|
|
.class_init = pc_dimm_class_init,
|
|
|
|
.class_size = sizeof(PCDIMMDeviceClass),
|
|
|
|
};
|
|
|
|
|
|
|
|
static void pc_dimm_register_types(void)
|
|
|
|
{
|
|
|
|
type_register_static(&pc_dimm_info);
|
|
|
|
}
|
|
|
|
|
|
|
|
type_init(pc_dimm_register_types)
|