xref: /openbmc/qemu/include/hw/mem/pc-dimm.h (revision 966f2ec3)
1 /*
2  * PC DIMM device
3  *
4  * Copyright ProfitBricks GmbH 2012
5  * Copyright (C) 2013-2014 Red Hat Inc
6  *
7  * Authors:
8  *  Vasilis Liaskovitis <vasilis.liaskovitis@profitbricks.com>
9  *  Igor Mammedov <imammedo@redhat.com>
10  *
11  * This work is licensed under the terms of the GNU GPL, version 2 or later.
12  * See the COPYING file in the top-level directory.
13  *
14  */
15 
16 #ifndef QEMU_PC_DIMM_H
17 #define QEMU_PC_DIMM_H
18 
19 #include "exec/memory.h"
20 #include "sysemu/hostmem.h"
21 #include "hw/qdev.h"
22 #include "hw/boards.h"
23 
24 #define TYPE_PC_DIMM "pc-dimm"
25 #define PC_DIMM(obj) \
26     OBJECT_CHECK(PCDIMMDevice, (obj), TYPE_PC_DIMM)
27 #define PC_DIMM_CLASS(oc) \
28     OBJECT_CLASS_CHECK(PCDIMMDeviceClass, (oc), TYPE_PC_DIMM)
29 #define PC_DIMM_GET_CLASS(obj) \
30     OBJECT_GET_CLASS(PCDIMMDeviceClass, (obj), TYPE_PC_DIMM)
31 
32 #define PC_DIMM_ADDR_PROP "addr"
33 #define PC_DIMM_SLOT_PROP "slot"
34 #define PC_DIMM_NODE_PROP "node"
35 #define PC_DIMM_SIZE_PROP "size"
36 #define PC_DIMM_MEMDEV_PROP "memdev"
37 
38 #define PC_DIMM_UNASSIGNED_SLOT -1
39 
40 /**
41  * PCDIMMDevice:
42  * @addr: starting guest physical address, where @PCDIMMDevice is mapped.
43  *         Default value: 0, means that address is auto-allocated.
44  * @node: numa node to which @PCDIMMDevice is attached.
45  * @slot: slot number into which @PCDIMMDevice is plugged in.
46  *        Default value: -1, means that slot is auto-allocated.
47  * @hostmem: host memory backend providing memory for @PCDIMMDevice
48  */
49 typedef struct PCDIMMDevice {
50     /* private */
51     DeviceState parent_obj;
52 
53     /* public */
54     uint64_t addr;
55     uint32_t node;
56     int32_t slot;
57     HostMemoryBackend *hostmem;
58 } PCDIMMDevice;
59 
60 /**
61  * PCDIMMDeviceClass:
62  * @realize: called after common dimm is realized so that the dimm based
63  * devices get the chance to do specified operations.
64  * @get_memory_region: returns #MemoryRegion associated with @dimm which
65  * is directly mapped into the physical address space of guest. Will not
66  * fail after the device was realized.
67  * @get_vmstate_memory_region: returns #MemoryRegion which indicates the
68  * memory of @dimm should be kept during live migration. Will not fail
69  * after the device was realized.
70  */
71 typedef struct PCDIMMDeviceClass {
72     /* private */
73     DeviceClass parent_class;
74 
75     /* public */
76     void (*realize)(PCDIMMDevice *dimm, Error **errp);
77     MemoryRegion *(*get_memory_region)(PCDIMMDevice *dimm, Error **errp);
78     MemoryRegion *(*get_vmstate_memory_region)(PCDIMMDevice *dimm,
79                                                Error **errp);
80 } PCDIMMDeviceClass;
81 
82 void pc_dimm_pre_plug(DeviceState *dev, MachineState *machine,
83                       const uint64_t *legacy_align, Error **errp);
84 void pc_dimm_plug(DeviceState *dev, MachineState *machine, Error **errp);
85 void pc_dimm_unplug(DeviceState *dev, MachineState *machine);
86 #endif
87