2015-12-02 10:20:56 +03:00
|
|
|
/*
|
|
|
|
* Non-Volatile Dual In-line Memory Module Virtualization Implementation
|
|
|
|
*
|
|
|
|
* Copyright(C) 2015 Intel Corporation.
|
|
|
|
*
|
|
|
|
* Author:
|
|
|
|
* Xiao Guangrong <guangrong.xiao@linux.intel.com>
|
|
|
|
*
|
|
|
|
* NVDIMM specifications and some documents can be found at:
|
|
|
|
* NVDIMM ACPI device and NFIT are introduced in ACPI 6:
|
|
|
|
* http://www.uefi.org/sites/default/files/resources/ACPI_6.0.pdf
|
|
|
|
* NVDIMM Namespace specification:
|
|
|
|
* http://pmem.io/documents/NVDIMM_Namespace_Spec.pdf
|
|
|
|
* DSM Interface Example:
|
|
|
|
* http://pmem.io/documents/NVDIMM_DSM_Interface_Example.pdf
|
|
|
|
* Driver Writer's Guide:
|
|
|
|
* http://pmem.io/documents/NVDIMM_Driver_Writers_Guide.pdf
|
|
|
|
*
|
|
|
|
* This work is licensed under the terms of the GNU GPL, version 2 or later.
|
|
|
|
* See the COPYING file in the top-level directory.
|
|
|
|
*/
|
|
|
|
|
|
|
|
#ifndef QEMU_NVDIMM_H
|
|
|
|
#define QEMU_NVDIMM_H
|
|
|
|
|
|
|
|
#include "hw/mem/pc-dimm.h"
|
2016-05-19 16:19:25 +03:00
|
|
|
#include "hw/acpi/bios-linker-loader.h"
|
2020-02-10 07:56:13 +03:00
|
|
|
#include "qemu/uuid.h"
|
2020-04-21 15:59:29 +03:00
|
|
|
#include "hw/acpi/aml-build.h"
|
2020-09-03 23:43:22 +03:00
|
|
|
#include "qom/object.h"
|
2015-12-02 10:20:56 +03:00
|
|
|
|
2016-03-04 19:00:35 +03:00
|
|
|
#define NVDIMM_DEBUG 0
|
|
|
|
#define nvdimm_debug(fmt, ...) \
|
|
|
|
do { \
|
|
|
|
if (NVDIMM_DEBUG) { \
|
|
|
|
fprintf(stderr, "nvdimm: " fmt, ## __VA_ARGS__); \
|
|
|
|
} \
|
|
|
|
} while (0)
|
|
|
|
|
2016-06-07 15:21:58 +03:00
|
|
|
/*
|
|
|
|
* The minimum label data size is required by NVDIMM Namespace
|
|
|
|
* specification, see the chapter 2 Namespaces:
|
|
|
|
* "NVDIMMs following the NVDIMM Block Mode Specification use an area
|
|
|
|
* at least 128KB in size, which holds around 1000 labels."
|
|
|
|
*/
|
|
|
|
#define MIN_NAMESPACE_LABEL_SIZE (128UL << 10)
|
|
|
|
|
|
|
|
#define TYPE_NVDIMM "nvdimm"
|
2020-09-16 21:25:18 +03:00
|
|
|
OBJECT_DECLARE_TYPE(NVDIMMDevice, NVDIMMClass, NVDIMM)
|
2017-12-11 10:28:05 +03:00
|
|
|
|
2018-05-21 19:32:00 +03:00
|
|
|
#define NVDIMM_LABEL_SIZE_PROP "label-size"
|
2020-02-10 07:56:13 +03:00
|
|
|
#define NVDIMM_UUID_PROP "uuid"
|
2017-12-11 10:28:06 +03:00
|
|
|
#define NVDIMM_UNARMED_PROP "unarmed"
|
2017-12-11 10:28:05 +03:00
|
|
|
|
2016-06-07 15:21:58 +03:00
|
|
|
struct NVDIMMDevice {
|
|
|
|
/* private */
|
|
|
|
PCDIMMDevice parent_obj;
|
|
|
|
|
|
|
|
/* public */
|
|
|
|
|
|
|
|
/*
|
|
|
|
* the size of label data in NVDIMM device which is presented to
|
|
|
|
* guest via __DSM "Get Namespace Label Size" function.
|
|
|
|
*/
|
|
|
|
uint64_t label_size;
|
|
|
|
|
|
|
|
/*
|
|
|
|
* the address of label data which is read by __DSM "Get Namespace
|
|
|
|
* Label Data" function and written by __DSM "Set Namespace Label
|
|
|
|
* Data" function.
|
|
|
|
*/
|
|
|
|
void *label_data;
|
|
|
|
|
|
|
|
/*
|
|
|
|
* it's the PMEM region in NVDIMM device, which is presented to
|
|
|
|
* guest via ACPI NFIT and _FIT method if NVDIMM hotplug is supported.
|
|
|
|
*/
|
2018-06-19 16:41:39 +03:00
|
|
|
MemoryRegion *nvdimm_mr;
|
2017-12-11 10:28:06 +03:00
|
|
|
|
|
|
|
/*
|
|
|
|
* The 'on' value results in the unarmed flag set in ACPI NFIT,
|
|
|
|
* which can be used to notify guest implicitly that the host
|
|
|
|
* backend (e.g., files on HDD, /dev/pmemX, etc.) cannot guarantee
|
|
|
|
* the guest write persistence.
|
|
|
|
*/
|
|
|
|
bool unarmed;
|
2020-02-10 07:56:13 +03:00
|
|
|
|
|
|
|
/*
|
|
|
|
* The PPC64 - spapr requires each nvdimm device have a uuid.
|
|
|
|
*/
|
|
|
|
QemuUUID uuid;
|
2016-06-07 15:21:58 +03:00
|
|
|
};
|
|
|
|
|
|
|
|
struct NVDIMMClass {
|
|
|
|
/* private */
|
|
|
|
PCDIMMDeviceClass parent_class;
|
|
|
|
|
|
|
|
/* public */
|
|
|
|
|
|
|
|
/* read @size bytes from NVDIMM label data at @offset into @buf. */
|
|
|
|
void (*read_label_data)(NVDIMMDevice *nvdimm, void *buf,
|
|
|
|
uint64_t size, uint64_t offset);
|
|
|
|
/* write @size bytes from @buf to NVDIMM label data at @offset. */
|
|
|
|
void (*write_label_data)(NVDIMMDevice *nvdimm, const void *buf,
|
|
|
|
uint64_t size, uint64_t offset);
|
2022-02-18 10:34:13 +03:00
|
|
|
void (*realize)(NVDIMMDevice *nvdimm, Error **errp);
|
|
|
|
void (*unrealize)(NVDIMMDevice *nvdimm);
|
2016-06-07 15:21:58 +03:00
|
|
|
};
|
nvdimm acpi: build ACPI NFIT table
NFIT is defined in ACPI 6.0: 5.2.25 NVDIMM Firmware Interface Table (NFIT)
Currently, we only support PMEM mode. Each device has 3 structures:
- SPA structure, defines the PMEM region info
- MEM DEV structure, it has the @handle which is used to associate specified
ACPI NVDIMM device we will introduce in later patch.
Also we can happily ignored the memory device's interleave, the real
nvdimm hardware access is hidden behind host
- DCR structure, it defines vendor ID used to associate specified vendor
nvdimm driver. Since we only implement PMEM mode this time, Command
window and Data window are not needed
The NVDIMM functionality is controlled by the parameter, 'nvdimm', which
is introduced for the machine, there is a example to enable it:
-machine pc,nvdimm -m 8G,maxmem=100G,slots=100 -object \
memory-backend-file,id=mem1,share,mem-path=/tmp/nvdimm1,size=10G -device \
nvdimm,memdev=mem1,id=nv1
It is disabled on default
Reviewed-by: Stefan Hajnoczi <stefanha@redhat.com>
Signed-off-by: Xiao Guangrong <guangrong.xiao@linux.intel.com>
Reviewed-by: Michael S. Tsirkin <mst@redhat.com>
Signed-off-by: Michael S. Tsirkin <mst@redhat.com>
2015-12-02 10:20:58 +03:00
|
|
|
|
2016-03-04 19:00:32 +03:00
|
|
|
#define NVDIMM_DSM_MEM_FILE "etc/acpi/nvdimm-mem"
|
|
|
|
|
|
|
|
/*
|
|
|
|
* 32 bits IO port starting from 0x0a18 in guest is reserved for
|
|
|
|
* NVDIMM ACPI emulation.
|
|
|
|
*/
|
|
|
|
#define NVDIMM_ACPI_IO_BASE 0x0a18
|
|
|
|
#define NVDIMM_ACPI_IO_LEN 4
|
|
|
|
|
2016-10-28 19:35:38 +03:00
|
|
|
/*
|
2016-11-07 14:13:37 +03:00
|
|
|
* NvdimmFitBuffer:
|
|
|
|
* @fit: FIT structures for present NVDIMMs. It is updated when
|
|
|
|
* the NVDIMM device is plugged or unplugged.
|
|
|
|
* @dirty: It allows OSPM to detect change and restart read in
|
|
|
|
* progress if there is any.
|
2016-10-28 19:35:38 +03:00
|
|
|
*/
|
|
|
|
struct NvdimmFitBuffer {
|
|
|
|
GArray *fit;
|
|
|
|
bool dirty;
|
|
|
|
};
|
|
|
|
typedef struct NvdimmFitBuffer NvdimmFitBuffer;
|
|
|
|
|
2019-03-08 21:20:52 +03:00
|
|
|
struct NVDIMMState {
|
2016-03-04 19:00:32 +03:00
|
|
|
/* detect if NVDIMM support is enabled. */
|
|
|
|
bool is_enabled;
|
|
|
|
|
|
|
|
/* the data of the fw_cfg file NVDIMM_DSM_MEM_FILE. */
|
|
|
|
GArray *dsm_mem;
|
2016-10-28 19:35:38 +03:00
|
|
|
|
|
|
|
NvdimmFitBuffer fit_buf;
|
|
|
|
|
2016-03-04 19:00:32 +03:00
|
|
|
/* the IO region used by OSPM to transfer control to QEMU. */
|
|
|
|
MemoryRegion io_mr;
|
2018-05-21 19:32:02 +03:00
|
|
|
|
|
|
|
/*
|
|
|
|
* Platform capabilities, section 5.2.25.9 of ACPI 6.2 Errata A
|
|
|
|
*/
|
2018-06-08 01:31:11 +03:00
|
|
|
int32_t persistence;
|
|
|
|
char *persistence_string;
|
2020-04-21 15:59:29 +03:00
|
|
|
struct AcpiGenericAddress dsm_io;
|
2016-03-04 19:00:32 +03:00
|
|
|
};
|
2019-03-08 21:20:52 +03:00
|
|
|
typedef struct NVDIMMState NVDIMMState;
|
2016-03-04 19:00:32 +03:00
|
|
|
|
2019-03-08 21:20:52 +03:00
|
|
|
void nvdimm_init_acpi_state(NVDIMMState *state, MemoryRegion *io,
|
2020-04-21 15:59:29 +03:00
|
|
|
struct AcpiGenericAddress dsm_io,
|
2016-03-04 19:00:32 +03:00
|
|
|
FWCfgState *fw_cfg, Object *owner);
|
hw/acpi/nvdimm: add a helper to augment SRAT generation
NVDIMMs can belong to their own proximity domains, as described by the
NFIT. In such cases, the SRAT needs to have Memory Affinity structures
in the SRAT for these NVDIMMs, otherwise Linux doesn't populate node
data structures properly during NUMA initialization. See the following
for an example failure case.
https://lore.kernel.org/linux-nvdimm/20200416225438.15208-1-vishal.l.verma@intel.com/
Introduce a new helper, nvdimm_build_srat(), and call it for both the
i386 and arm versions of 'build_srat()' to augment the SRAT with
memory affinity information for NVDIMMs.
The relevant command line options to exercise this are below. Nodes 0-1
contain CPUs and regular memory, and nodes 2-3 are the NVDIMM address
space.
-object memory-backend-ram,id=mem0,size=2048M
-numa node,nodeid=0,memdev=mem0,
-numa cpu,node-id=0,socket-id=0
-object memory-backend-ram,id=mem1,size=2048M
-numa node,nodeid=1,memdev=mem1,
-numa cpu,node-id=1,socket-id=1
-numa node,nodeid=2,
-object memory-backend-file,id=nvmem0,share,mem-path=nvdimm-0,size=16384M,align=1G
-device nvdimm,memdev=nvmem0,id=nv0,label-size=2M,node=2
-numa node,nodeid=3,
-object memory-backend-file,id=nvmem1,share,mem-path=nvdimm-1,size=16384M,align=1G
-device nvdimm,memdev=nvmem1,id=nv1,label-size=2M,node=3
Cc: Jingqi Liu <jingqi.liu@intel.com>
Cc: Michael S. Tsirkin <mst@redhat.com>
Reviewed-by: Jingqi Liu <jingqi.liu@intel.com>
Reviewed-by: Igor Mammedov <imammedo@redhat.com>
Signed-off-by: Vishal Verma <vishal.l.verma@intel.com>
Message-Id: <20200606000911.9896-3-vishal.l.verma@intel.com>
Reviewed-by: Michael S. Tsirkin <mst@redhat.com>
Signed-off-by: Michael S. Tsirkin <mst@redhat.com>
2020-06-06 03:09:10 +03:00
|
|
|
void nvdimm_build_srat(GArray *table_data);
|
nvdimm acpi: build ACPI NFIT table
NFIT is defined in ACPI 6.0: 5.2.25 NVDIMM Firmware Interface Table (NFIT)
Currently, we only support PMEM mode. Each device has 3 structures:
- SPA structure, defines the PMEM region info
- MEM DEV structure, it has the @handle which is used to associate specified
ACPI NVDIMM device we will introduce in later patch.
Also we can happily ignored the memory device's interleave, the real
nvdimm hardware access is hidden behind host
- DCR structure, it defines vendor ID used to associate specified vendor
nvdimm driver. Since we only implement PMEM mode this time, Command
window and Data window are not needed
The NVDIMM functionality is controlled by the parameter, 'nvdimm', which
is introduced for the machine, there is a example to enable it:
-machine pc,nvdimm -m 8G,maxmem=100G,slots=100 -object \
memory-backend-file,id=mem1,share,mem-path=/tmp/nvdimm1,size=10G -device \
nvdimm,memdev=mem1,id=nv1
It is disabled on default
Reviewed-by: Stefan Hajnoczi <stefanha@redhat.com>
Signed-off-by: Xiao Guangrong <guangrong.xiao@linux.intel.com>
Reviewed-by: Michael S. Tsirkin <mst@redhat.com>
Signed-off-by: Michael S. Tsirkin <mst@redhat.com>
2015-12-02 10:20:58 +03:00
|
|
|
void nvdimm_build_acpi(GArray *table_offsets, GArray *table_data,
|
2019-03-08 21:20:52 +03:00
|
|
|
BIOSLinker *linker, NVDIMMState *state,
|
2021-01-19 03:32:13 +03:00
|
|
|
uint32_t ram_slots, const char *oem_id,
|
|
|
|
const char *oem_table_id);
|
2019-03-08 21:20:52 +03:00
|
|
|
void nvdimm_plug(NVDIMMState *state);
|
2016-11-07 14:13:38 +03:00
|
|
|
void nvdimm_acpi_plug_cb(HotplugHandler *hotplug_dev, DeviceState *dev);
|
2015-12-02 10:20:56 +03:00
|
|
|
#endif
|