]> Git Repo - qemu.git/blame - hw/mem/pc-dimm.c
pc-dimm: do not allow setting an in-use memdev
[qemu.git] / hw / mem / pc-dimm.c
CommitLineData
10b7e74b
VL
1/*
2 * Dimm device for Memory Hotplug
3 *
4 * Copyright ProfitBricks GmbH 2012
5 * Copyright (C) 2014 Red Hat Inc
6 *
7 * This library is free software; you can redistribute it and/or
8 * modify it under the terms of the GNU Lesser General Public
9 * License as published by the Free Software Foundation; either
10 * version 2 of the License, or (at your option) any later version.
11 *
12 * This library is distributed in the hope that it will be useful,
13 * but WITHOUT ANY WARRANTY; without even the implied warranty of
14 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
15 * Lesser General Public License for more details.
16 *
17 * You should have received a copy of the GNU Lesser General Public
18 * License along with this library; if not, see <http://www.gnu.org/licenses/>
19 */
20
21#include "hw/mem/pc-dimm.h"
22#include "qemu/config-file.h"
23#include "qapi/visitor.h"
24
25static Property pc_dimm_properties[] = {
26 DEFINE_PROP_UINT64(PC_DIMM_ADDR_PROP, PCDIMMDevice, addr, 0),
27 DEFINE_PROP_UINT32(PC_DIMM_NODE_PROP, PCDIMMDevice, node, 0),
28 DEFINE_PROP_INT32(PC_DIMM_SLOT_PROP, PCDIMMDevice, slot,
29 PC_DIMM_UNASSIGNED_SLOT),
30 DEFINE_PROP_END_OF_LIST(),
31};
32
33static void pc_dimm_get_size(Object *obj, Visitor *v, void *opaque,
34 const char *name, Error **errp)
35{
36 int64_t value;
37 MemoryRegion *mr;
38 PCDIMMDevice *dimm = PC_DIMM(obj);
39
40 mr = host_memory_backend_get_memory(dimm->hostmem, errp);
41 value = memory_region_size(mr);
42
43 visit_type_int(v, &value, name, errp);
44}
45
7bb5d6ad
IM
46static void pc_dimm_check_memdev_is_busy(Object *obj, const char *name,
47 Object *val, Error **errp)
48{
49 MemoryRegion *mr;
50
51 mr = host_memory_backend_get_memory(MEMORY_BACKEND(val), errp);
52 if (memory_region_is_mapped(mr)) {
53 char *path = object_get_canonical_path_component(val);
54 error_setg(errp, "can't use already busy memdev: %s", path);
55 g_free(path);
56 } else {
57 qdev_prop_allow_set_link_before_realize(obj, name, val, errp);
58 }
59}
60
10b7e74b
VL
61static void pc_dimm_init(Object *obj)
62{
63 PCDIMMDevice *dimm = PC_DIMM(obj);
64
65 object_property_add(obj, PC_DIMM_SIZE_PROP, "int", pc_dimm_get_size,
66 NULL, NULL, NULL, &error_abort);
67 object_property_add_link(obj, PC_DIMM_MEMDEV_PROP, TYPE_MEMORY_BACKEND,
68 (Object **)&dimm->hostmem,
7bb5d6ad 69 pc_dimm_check_memdev_is_busy,
10b7e74b
VL
70 OBJ_PROP_LINK_UNREF_ON_RELEASE,
71 &error_abort);
72}
73
74static void pc_dimm_realize(DeviceState *dev, Error **errp)
75{
76 PCDIMMDevice *dimm = PC_DIMM(dev);
77
78 if (!dimm->hostmem) {
79 error_setg(errp, "'" PC_DIMM_MEMDEV_PROP "' property is not set");
80 return;
81 }
82}
83
84static MemoryRegion *pc_dimm_get_memory_region(PCDIMMDevice *dimm)
85{
86 return host_memory_backend_get_memory(dimm->hostmem, &error_abort);
87}
88
89static void pc_dimm_class_init(ObjectClass *oc, void *data)
90{
91 DeviceClass *dc = DEVICE_CLASS(oc);
92 PCDIMMDeviceClass *ddc = PC_DIMM_CLASS(oc);
93
94 dc->realize = pc_dimm_realize;
95 dc->props = pc_dimm_properties;
96
97 ddc->get_memory_region = pc_dimm_get_memory_region;
98}
99
100static TypeInfo pc_dimm_info = {
101 .name = TYPE_PC_DIMM,
102 .parent = TYPE_DEVICE,
103 .instance_size = sizeof(PCDIMMDevice),
104 .instance_init = pc_dimm_init,
105 .class_init = pc_dimm_class_init,
106 .class_size = sizeof(PCDIMMDeviceClass),
107};
108
109static void pc_dimm_register_types(void)
110{
111 type_register_static(&pc_dimm_info);
112}
113
114type_init(pc_dimm_register_types)
This page took 0.034784 seconds and 4 git commands to generate.