xref: /openbmc/qemu/include/hw/mem/pc-dimm.h (revision 083fab02)
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 
23 #define TYPE_PC_DIMM "pc-dimm"
24 #define PC_DIMM(obj) \
25     OBJECT_CHECK(PCDIMMDevice, (obj), TYPE_PC_DIMM)
26 #define PC_DIMM_CLASS(oc) \
27     OBJECT_CLASS_CHECK(PCDIMMDeviceClass, (oc), TYPE_PC_DIMM)
28 #define PC_DIMM_GET_CLASS(obj) \
29     OBJECT_GET_CLASS(PCDIMMDeviceClass, (obj), TYPE_PC_DIMM)
30 
31 #define PC_DIMM_ADDR_PROP "addr"
32 #define PC_DIMM_SLOT_PROP "slot"
33 #define PC_DIMM_NODE_PROP "node"
34 #define PC_DIMM_SIZE_PROP "size"
35 #define PC_DIMM_MEMDEV_PROP "memdev"
36 
37 #define PC_DIMM_UNASSIGNED_SLOT -1
38 
39 /**
40  * PCDIMMDevice:
41  * @addr: starting guest physical address, where @PCDIMMDevice is mapped.
42  *         Default value: 0, means that address is auto-allocated.
43  * @node: numa node to which @PCDIMMDevice is attached.
44  * @slot: slot number into which @PCDIMMDevice is plugged in.
45  *        Default value: -1, means that slot is auto-allocated.
46  * @hostmem: host memory backend providing memory for @PCDIMMDevice
47  */
48 typedef struct PCDIMMDevice {
49     /* private */
50     DeviceState parent_obj;
51 
52     /* public */
53     uint64_t addr;
54     uint32_t node;
55     int32_t slot;
56     HostMemoryBackend *hostmem;
57 } PCDIMMDevice;
58 
59 /**
60  * PCDIMMDeviceClass:
61  * @realize: called after common dimm is realized so that the dimm based
62  * devices get the chance to do specified operations.
63  * @get_memory_region: returns #MemoryRegion associated with @dimm which
64  * is directly mapped into the physical address space of guest.
65  * @get_vmstate_memory_region: returns #MemoryRegion which indicates the
66  * memory of @dimm should be kept during live migration.
67  */
68 typedef struct PCDIMMDeviceClass {
69     /* private */
70     DeviceClass parent_class;
71 
72     /* public */
73     void (*realize)(PCDIMMDevice *dimm, Error **errp);
74     MemoryRegion *(*get_memory_region)(PCDIMMDevice *dimm, Error **errp);
75     MemoryRegion *(*get_vmstate_memory_region)(PCDIMMDevice *dimm);
76 } PCDIMMDeviceClass;
77 
78 /**
79  * MemoryHotplugState:
80  * @base: address in guest physical address space where hotplug memory
81  * address space begins.
82  * @mr: hotplug memory address space container
83  */
84 typedef struct MemoryHotplugState {
85     hwaddr base;
86     MemoryRegion mr;
87 } MemoryHotplugState;
88 
89 uint64_t pc_dimm_get_free_addr(uint64_t address_space_start,
90                                uint64_t address_space_size,
91                                uint64_t *hint, uint64_t align, uint64_t size,
92                                Error **errp);
93 
94 int pc_dimm_get_free_slot(const int *hint, int max_slots, Error **errp);
95 
96 int qmp_pc_dimm_device_list(Object *obj, void *opaque);
97 uint64_t pc_existing_dimms_capacity(Error **errp);
98 uint64_t get_plugged_memory_size(void);
99 void pc_dimm_memory_plug(DeviceState *dev, MemoryHotplugState *hpms,
100                          MemoryRegion *mr, uint64_t align, Error **errp);
101 void pc_dimm_memory_unplug(DeviceState *dev, MemoryHotplugState *hpms,
102                            MemoryRegion *mr);
103 #endif
104