]>
Commit | Line | Data |
---|---|---|
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 | ||
25 | static 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 | ||
33 | static 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 | ||
46 | static void pc_dimm_init(Object *obj) | |
47 | { | |
48 | PCDIMMDevice *dimm = PC_DIMM(obj); | |
49 | ||
50 | object_property_add(obj, PC_DIMM_SIZE_PROP, "int", pc_dimm_get_size, | |
51 | NULL, NULL, NULL, &error_abort); | |
52 | object_property_add_link(obj, PC_DIMM_MEMDEV_PROP, TYPE_MEMORY_BACKEND, | |
53 | (Object **)&dimm->hostmem, | |
54 | qdev_prop_allow_set_link_before_realize, | |
55 | OBJ_PROP_LINK_UNREF_ON_RELEASE, | |
56 | &error_abort); | |
57 | } | |
58 | ||
59 | static void pc_dimm_realize(DeviceState *dev, Error **errp) | |
60 | { | |
61 | PCDIMMDevice *dimm = PC_DIMM(dev); | |
62 | ||
63 | if (!dimm->hostmem) { | |
64 | error_setg(errp, "'" PC_DIMM_MEMDEV_PROP "' property is not set"); | |
65 | return; | |
66 | } | |
67 | } | |
68 | ||
69 | static MemoryRegion *pc_dimm_get_memory_region(PCDIMMDevice *dimm) | |
70 | { | |
71 | return host_memory_backend_get_memory(dimm->hostmem, &error_abort); | |
72 | } | |
73 | ||
74 | static void pc_dimm_class_init(ObjectClass *oc, void *data) | |
75 | { | |
76 | DeviceClass *dc = DEVICE_CLASS(oc); | |
77 | PCDIMMDeviceClass *ddc = PC_DIMM_CLASS(oc); | |
78 | ||
79 | dc->realize = pc_dimm_realize; | |
80 | dc->props = pc_dimm_properties; | |
81 | ||
82 | ddc->get_memory_region = pc_dimm_get_memory_region; | |
83 | } | |
84 | ||
85 | static TypeInfo pc_dimm_info = { | |
86 | .name = TYPE_PC_DIMM, | |
87 | .parent = TYPE_DEVICE, | |
88 | .instance_size = sizeof(PCDIMMDevice), | |
89 | .instance_init = pc_dimm_init, | |
90 | .class_init = pc_dimm_class_init, | |
91 | .class_size = sizeof(PCDIMMDeviceClass), | |
92 | }; | |
93 | ||
94 | static void pc_dimm_register_types(void) | |
95 | { | |
96 | type_register_static(&pc_dimm_info); | |
97 | } | |
98 | ||
99 | type_init(pc_dimm_register_types) |