2 * Non-Volatile Dual In-line Memory Module Virtualization Implementation
4 * Copyright(C) 2015 Intel Corporation.
7 * Xiao Guangrong <guangrong.xiao@linux.intel.com>
9 * NVDIMM specifications and some documents can be found at:
10 * NVDIMM ACPI device and NFIT are introduced in ACPI 6:
11 * http://www.uefi.org/sites/default/files/resources/ACPI_6.0.pdf
12 * NVDIMM Namespace specification:
13 * http://pmem.io/documents/NVDIMM_Namespace_Spec.pdf
14 * DSM Interface Example:
15 * http://pmem.io/documents/NVDIMM_DSM_Interface_Example.pdf
16 * Driver Writer's Guide:
17 * http://pmem.io/documents/NVDIMM_Driver_Writers_Guide.pdf
19 * This work is licensed under the terms of the GNU GPL, version 2 or later.
20 * See the COPYING file in the top-level directory.
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"
33 * The minimum label data size is required by NVDIMM Namespace
34 * specification, see the chapter 2 Namespaces:
35 * "NVDIMMs following the NVDIMM Block Mode Specification use an area
36 * at least 128KB in size, which holds around 1000 labels."
38 #define MIN_NAMESPACE_LABEL_SIZE (128UL << 10)
40 #define TYPE_NVDIMM "nvdimm"
41 OBJECT_DECLARE_TYPE(NVDIMMDevice
, NVDIMMClass
, NVDIMM
)
43 #define NVDIMM_LABEL_SIZE_PROP "label-size"
44 #define NVDIMM_UUID_PROP "uuid"
45 #define NVDIMM_UNARMED_PROP "unarmed"
49 PCDIMMDevice parent_obj
;
54 * the size of label data in NVDIMM device which is presented to
55 * guest via __DSM "Get Namespace Label Size" function.
60 * the address of label data which is read by __DSM "Get Namespace
61 * Label Data" function and written by __DSM "Set Namespace Label
67 * it's the PMEM region in NVDIMM device, which is presented to
68 * guest via ACPI NFIT and _FIT method if NVDIMM hotplug is supported.
70 MemoryRegion
*nvdimm_mr
;
73 * The 'on' value results in the unarmed flag set in ACPI NFIT,
74 * which can be used to notify guest implicitly that the host
75 * backend (e.g., files on HDD, /dev/pmemX, etc.) cannot guarantee
76 * the guest write persistence.
81 * Whether our DIMM is backed by ROM, and even label data cannot be
82 * written. If set, implies that "unarmed" is also set.
87 * The PPC64 - spapr requires each nvdimm device have a uuid.
94 PCDIMMDeviceClass parent_class
;
98 /* read @size bytes from NVDIMM label data at @offset into @buf. */
99 void (*read_label_data
)(NVDIMMDevice
*nvdimm
, void *buf
,
100 uint64_t size
, uint64_t offset
);
101 /* write @size bytes from @buf to NVDIMM label data at @offset. */
102 void (*write_label_data
)(NVDIMMDevice
*nvdimm
, const void *buf
,
103 uint64_t size
, uint64_t offset
);
104 void (*realize
)(NVDIMMDevice
*nvdimm
, Error
**errp
);
105 void (*unrealize
)(NVDIMMDevice
*nvdimm
);
108 #define NVDIMM_DSM_MEM_FILE "etc/acpi/nvdimm-mem"
111 * 32 bits IO port starting from 0x0a18 in guest is reserved for
112 * NVDIMM ACPI emulation.
114 #define NVDIMM_ACPI_IO_BASE 0x0a18
115 #define NVDIMM_ACPI_IO_LEN 4
119 * @fit: FIT structures for present NVDIMMs. It is updated when
120 * the NVDIMM device is plugged or unplugged.
121 * @dirty: It allows OSPM to detect change and restart read in
122 * progress if there is any.
124 struct NvdimmFitBuffer
{
128 typedef struct NvdimmFitBuffer NvdimmFitBuffer
;
131 /* detect if NVDIMM support is enabled. */
134 /* the data of the fw_cfg file NVDIMM_DSM_MEM_FILE. */
137 NvdimmFitBuffer fit_buf
;
139 /* the IO region used by OSPM to transfer control to QEMU. */
143 * Platform capabilities, section 5.2.25.9 of ACPI 6.2 Errata A
146 char *persistence_string
;
147 struct AcpiGenericAddress dsm_io
;
149 typedef struct NVDIMMState NVDIMMState
;
151 void nvdimm_init_acpi_state(NVDIMMState
*state
, MemoryRegion
*io
,
152 struct AcpiGenericAddress dsm_io
,
153 FWCfgState
*fw_cfg
, Object
*owner
);
154 void nvdimm_build_srat(GArray
*table_data
);
155 void nvdimm_build_acpi(GArray
*table_offsets
, GArray
*table_data
,
156 BIOSLinker
*linker
, NVDIMMState
*state
,
157 uint32_t ram_slots
, const char *oem_id
,
158 const char *oem_table_id
);
159 void nvdimm_plug(NVDIMMState
*state
);
160 void nvdimm_acpi_plug_cb(HotplugHandler
*hotplug_dev
, DeviceState
*dev
);