1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23#ifndef QEMU_NVDIMM_H
24#define QEMU_NVDIMM_H
25
26#include "hw/mem/pc-dimm.h"
27#include "hw/acpi/bios-linker-loader.h"
28#include "qemu/uuid.h"
29#include "hw/acpi/aml-build.h"
30#include "qom/object.h"
31
32#define NVDIMM_DEBUG 0
33#define nvdimm_debug(fmt, ...) \
34 do { \
35 if (NVDIMM_DEBUG) { \
36 fprintf(stderr, "nvdimm: " fmt, ## __VA_ARGS__); \
37 } \
38 } while (0)
39
40
41
42
43
44
45
46#define MIN_NAMESPACE_LABEL_SIZE (128UL << 10)
47
48#define TYPE_NVDIMM "nvdimm"
49OBJECT_DECLARE_TYPE(NVDIMMDevice, NVDIMMClass, NVDIMM)
50
51#define NVDIMM_LABEL_SIZE_PROP "label-size"
52#define NVDIMM_UUID_PROP "uuid"
53#define NVDIMM_UNARMED_PROP "unarmed"
54
55struct NVDIMMDevice {
56
57 PCDIMMDevice parent_obj;
58
59
60
61
62
63
64
65 uint64_t label_size;
66
67
68
69
70
71
72 void *label_data;
73
74
75
76
77
78 MemoryRegion *nvdimm_mr;
79
80
81
82
83
84
85
86 bool unarmed;
87
88
89
90
91 QemuUUID uuid;
92};
93
94struct NVDIMMClass {
95
96 PCDIMMDeviceClass parent_class;
97
98
99
100
101 void (*read_label_data)(NVDIMMDevice *nvdimm, void *buf,
102 uint64_t size, uint64_t offset);
103
104 void (*write_label_data)(NVDIMMDevice *nvdimm, const void *buf,
105 uint64_t size, uint64_t offset);
106 void (*realize)(NVDIMMDevice *nvdimm, Error **errp);
107 void (*unrealize)(NVDIMMDevice *nvdimm);
108};
109
110#define NVDIMM_DSM_MEM_FILE "etc/acpi/nvdimm-mem"
111
112
113
114
115
116#define NVDIMM_ACPI_IO_BASE 0x0a18
117#define NVDIMM_ACPI_IO_LEN 4
118
119
120
121
122
123
124
125
126struct NvdimmFitBuffer {
127 GArray *fit;
128 bool dirty;
129};
130typedef struct NvdimmFitBuffer NvdimmFitBuffer;
131
132struct NVDIMMState {
133
134 bool is_enabled;
135
136
137 GArray *dsm_mem;
138
139 NvdimmFitBuffer fit_buf;
140
141
142 MemoryRegion io_mr;
143
144
145
146
147 int32_t persistence;
148 char *persistence_string;
149 struct AcpiGenericAddress dsm_io;
150};
151typedef struct NVDIMMState NVDIMMState;
152
153void nvdimm_init_acpi_state(NVDIMMState *state, MemoryRegion *io,
154 struct AcpiGenericAddress dsm_io,
155 FWCfgState *fw_cfg, Object *owner);
156void nvdimm_build_srat(GArray *table_data);
157void nvdimm_build_acpi(GArray *table_offsets, GArray *table_data,
158 BIOSLinker *linker, NVDIMMState *state,
159 uint32_t ram_slots, const char *oem_id,
160 const char *oem_table_id);
161void nvdimm_plug(NVDIMMState *state);
162void nvdimm_acpi_plug_cb(HotplugHandler *hotplug_dev, DeviceState *dev);
163#endif
164