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 07:20:58 +00:00
|
|
|
/*
|
|
|
|
* NVDIMM ACPI Implementation
|
|
|
|
*
|
|
|
|
* Copyright(C) 2015 Intel Corporation.
|
|
|
|
*
|
|
|
|
* Author:
|
|
|
|
* Xiao Guangrong <guangrong.xiao@linux.intel.com>
|
|
|
|
*
|
|
|
|
* NFIT is defined in ACPI 6.0: 5.2.25 NVDIMM Firmware Interface Table (NFIT)
|
|
|
|
* and the DSM specification can be found at:
|
|
|
|
* http://pmem.io/documents/NVDIMM_DSM_Interface_Example.pdf
|
|
|
|
*
|
|
|
|
* Currently, it only supports PMEM Virtualization.
|
|
|
|
*
|
|
|
|
* This library is free software; you can redistribute it and/or
|
|
|
|
* modify it under the terms of the GNU Lesser General Public
|
|
|
|
* License as published by the Free Software Foundation; either
|
2020-10-23 12:37:49 +00:00
|
|
|
* version 2.1 of the License, or (at your option) any later version.
|
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 07:20:58 +00:00
|
|
|
*
|
|
|
|
* This library is distributed in the hope that it will be useful,
|
|
|
|
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
|
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
|
|
|
* Lesser General Public License for more details.
|
|
|
|
*
|
|
|
|
* You should have received a copy of the GNU Lesser General Public
|
|
|
|
* License along with this library; if not, see <http://www.gnu.org/licenses/>
|
|
|
|
*/
|
|
|
|
|
2016-01-26 18:17:03 +00:00
|
|
|
#include "qemu/osdep.h"
|
2020-05-12 03:06:00 +00:00
|
|
|
#include "qemu/uuid.h"
|
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 00:09:10 +00:00
|
|
|
#include "qapi/error.h"
|
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 07:20:58 +00:00
|
|
|
#include "hw/acpi/acpi.h"
|
|
|
|
#include "hw/acpi/aml-build.h"
|
2016-03-04 16:00:33 +00:00
|
|
|
#include "hw/acpi/bios-linker-loader.h"
|
2016-03-04 16:00:32 +00:00
|
|
|
#include "hw/nvram/fw_cfg.h"
|
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 07:20:58 +00:00
|
|
|
#include "hw/mem/nvdimm.h"
|
2020-02-10 04:56:02 +00:00
|
|
|
#include "qemu/nvdimm-utils.h"
|
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 07:20:58 +00:00
|
|
|
|
|
|
|
/*
|
|
|
|
* define Byte Addressable Persistent Memory (PM) Region according to
|
|
|
|
* ACPI 6.0: 5.2.25.1 System Physical Address Range Structure.
|
|
|
|
*/
|
|
|
|
static const uint8_t nvdimm_nfit_spa_uuid[] =
|
2020-05-12 03:06:00 +00:00
|
|
|
UUID_LE(0x66f0d379, 0xb4f3, 0x4074, 0xac, 0x43, 0x0d, 0x33,
|
|
|
|
0x18, 0xb7, 0x8c, 0xdb);
|
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 07:20:58 +00:00
|
|
|
|
|
|
|
/*
|
|
|
|
* NVDIMM Firmware Interface Table
|
|
|
|
* @signature: "NFIT"
|
|
|
|
*
|
|
|
|
* It provides information that allows OSPM to enumerate NVDIMM present in
|
|
|
|
* the platform and associate system physical address ranges created by the
|
|
|
|
* NVDIMMs.
|
|
|
|
*
|
|
|
|
* It is defined in ACPI 6.0: 5.2.25 NVDIMM Firmware Interface Table (NFIT)
|
|
|
|
*/
|
|
|
|
struct NvdimmNfitHeader {
|
|
|
|
ACPI_TABLE_HEADER_DEF
|
|
|
|
uint32_t reserved;
|
|
|
|
} QEMU_PACKED;
|
|
|
|
typedef struct NvdimmNfitHeader NvdimmNfitHeader;
|
|
|
|
|
|
|
|
/*
|
|
|
|
* define NFIT structures according to ACPI 6.0: 5.2.25 NVDIMM Firmware
|
|
|
|
* Interface Table (NFIT).
|
|
|
|
*/
|
|
|
|
|
|
|
|
/*
|
|
|
|
* System Physical Address Range Structure
|
|
|
|
*
|
|
|
|
* It describes the system physical address ranges occupied by NVDIMMs and
|
|
|
|
* the types of the regions.
|
|
|
|
*/
|
|
|
|
struct NvdimmNfitSpa {
|
|
|
|
uint16_t type;
|
|
|
|
uint16_t length;
|
|
|
|
uint16_t spa_index;
|
|
|
|
uint16_t flags;
|
|
|
|
uint32_t reserved;
|
|
|
|
uint32_t proximity_domain;
|
|
|
|
uint8_t type_guid[16];
|
|
|
|
uint64_t spa_base;
|
|
|
|
uint64_t spa_length;
|
|
|
|
uint64_t mem_attr;
|
|
|
|
} QEMU_PACKED;
|
|
|
|
typedef struct NvdimmNfitSpa NvdimmNfitSpa;
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Memory Device to System Physical Address Range Mapping Structure
|
|
|
|
*
|
|
|
|
* It enables identifying each NVDIMM region and the corresponding SPA
|
|
|
|
* describing the memory interleave
|
|
|
|
*/
|
|
|
|
struct NvdimmNfitMemDev {
|
|
|
|
uint16_t type;
|
|
|
|
uint16_t length;
|
|
|
|
uint32_t nfit_handle;
|
|
|
|
uint16_t phys_id;
|
|
|
|
uint16_t region_id;
|
|
|
|
uint16_t spa_index;
|
|
|
|
uint16_t dcr_index;
|
|
|
|
uint64_t region_len;
|
|
|
|
uint64_t region_offset;
|
|
|
|
uint64_t region_dpa;
|
|
|
|
uint16_t interleave_index;
|
|
|
|
uint16_t interleave_ways;
|
|
|
|
uint16_t flags;
|
|
|
|
uint16_t reserved;
|
|
|
|
} QEMU_PACKED;
|
|
|
|
typedef struct NvdimmNfitMemDev NvdimmNfitMemDev;
|
|
|
|
|
2017-12-11 07:28:06 +00:00
|
|
|
#define ACPI_NFIT_MEM_NOT_ARMED (1 << 3)
|
|
|
|
|
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 07:20:58 +00:00
|
|
|
/*
|
|
|
|
* NVDIMM Control Region Structure
|
|
|
|
*
|
|
|
|
* It describes the NVDIMM and if applicable, Block Control Window.
|
|
|
|
*/
|
|
|
|
struct NvdimmNfitControlRegion {
|
|
|
|
uint16_t type;
|
|
|
|
uint16_t length;
|
|
|
|
uint16_t dcr_index;
|
|
|
|
uint16_t vendor_id;
|
|
|
|
uint16_t device_id;
|
|
|
|
uint16_t revision_id;
|
|
|
|
uint16_t sub_vendor_id;
|
|
|
|
uint16_t sub_device_id;
|
|
|
|
uint16_t sub_revision_id;
|
|
|
|
uint8_t reserved[6];
|
|
|
|
uint32_t serial_number;
|
|
|
|
uint16_t fic;
|
|
|
|
uint16_t num_bcw;
|
|
|
|
uint64_t bcw_size;
|
|
|
|
uint64_t cmd_offset;
|
|
|
|
uint64_t cmd_size;
|
|
|
|
uint64_t status_offset;
|
|
|
|
uint64_t status_size;
|
|
|
|
uint16_t flags;
|
|
|
|
uint8_t reserved2[6];
|
|
|
|
} QEMU_PACKED;
|
|
|
|
typedef struct NvdimmNfitControlRegion NvdimmNfitControlRegion;
|
|
|
|
|
2018-05-21 16:32:02 +00:00
|
|
|
/*
|
|
|
|
* NVDIMM Platform Capabilities Structure
|
|
|
|
*
|
|
|
|
* Defined in section 5.2.25.9 of ACPI 6.2 Errata A, September 2017
|
|
|
|
*/
|
|
|
|
struct NvdimmNfitPlatformCaps {
|
|
|
|
uint16_t type;
|
|
|
|
uint16_t length;
|
|
|
|
uint8_t highest_cap;
|
|
|
|
uint8_t reserved[3];
|
|
|
|
uint32_t capabilities;
|
|
|
|
uint8_t reserved2[4];
|
|
|
|
} QEMU_PACKED;
|
|
|
|
typedef struct NvdimmNfitPlatformCaps NvdimmNfitPlatformCaps;
|
|
|
|
|
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 07:20:58 +00:00
|
|
|
/*
|
|
|
|
* Module serial number is a unique number for each device. We use the
|
|
|
|
* slot id of NVDIMM device to generate this number so that each device
|
|
|
|
* associates with a different number.
|
|
|
|
*
|
|
|
|
* 0x123456 is a magic number we arbitrarily chose.
|
|
|
|
*/
|
|
|
|
static uint32_t nvdimm_slot_to_sn(int slot)
|
|
|
|
{
|
|
|
|
return 0x123456 + slot;
|
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
|
|
|
* handle is used to uniquely associate nfit_memdev structure with NVDIMM
|
|
|
|
* ACPI device - nfit_memdev.nfit_handle matches with the value returned
|
|
|
|
* by ACPI device _ADR method.
|
|
|
|
*
|
|
|
|
* We generate the handle with the slot id of NVDIMM device and reserve
|
|
|
|
* 0 for NVDIMM root device.
|
|
|
|
*/
|
|
|
|
static uint32_t nvdimm_slot_to_handle(int slot)
|
|
|
|
{
|
|
|
|
return slot + 1;
|
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
|
|
|
* index uniquely identifies the structure, 0 is reserved which indicates
|
|
|
|
* that the structure is not valid or the associated structure is not
|
|
|
|
* present.
|
|
|
|
*
|
|
|
|
* Each NVDIMM device needs two indexes, one for nfit_spa and another for
|
|
|
|
* nfit_dc which are generated by the slot id of NVDIMM device.
|
|
|
|
*/
|
|
|
|
static uint16_t nvdimm_slot_to_spa_index(int slot)
|
|
|
|
{
|
|
|
|
return (slot + 1) << 1;
|
|
|
|
}
|
|
|
|
|
|
|
|
/* See the comments of nvdimm_slot_to_spa_index(). */
|
|
|
|
static uint32_t nvdimm_slot_to_dcr_index(int slot)
|
|
|
|
{
|
|
|
|
return nvdimm_slot_to_spa_index(slot) + 1;
|
|
|
|
}
|
|
|
|
|
2016-06-07 12:22:06 +00:00
|
|
|
static NVDIMMDevice *nvdimm_get_device_by_handle(uint32_t handle)
|
|
|
|
{
|
|
|
|
NVDIMMDevice *nvdimm = NULL;
|
2016-11-07 11:13:42 +00:00
|
|
|
GSList *list, *device_list = nvdimm_get_device_list();
|
2016-06-07 12:22:06 +00:00
|
|
|
|
|
|
|
for (list = device_list; list; list = list->next) {
|
|
|
|
NVDIMMDevice *nvd = list->data;
|
|
|
|
int slot = object_property_get_int(OBJECT(nvd), PC_DIMM_SLOT_PROP,
|
|
|
|
NULL);
|
|
|
|
|
|
|
|
if (nvdimm_slot_to_handle(slot) == handle) {
|
|
|
|
nvdimm = nvd;
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
g_slist_free(device_list);
|
|
|
|
return nvdimm;
|
|
|
|
}
|
|
|
|
|
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 07:20:58 +00:00
|
|
|
/* ACPI 6.0: 5.2.25.1 System Physical Address Range Structure */
|
|
|
|
static void
|
|
|
|
nvdimm_build_structure_spa(GArray *structures, DeviceState *dev)
|
|
|
|
{
|
|
|
|
NvdimmNfitSpa *nfit_spa;
|
2017-06-07 16:36:13 +00:00
|
|
|
uint64_t addr = object_property_get_uint(OBJECT(dev), PC_DIMM_ADDR_PROP,
|
|
|
|
NULL);
|
2017-06-07 16:36:14 +00:00
|
|
|
uint64_t size = object_property_get_uint(OBJECT(dev), PC_DIMM_SIZE_PROP,
|
|
|
|
NULL);
|
2017-06-07 16:36:13 +00:00
|
|
|
uint32_t node = object_property_get_uint(OBJECT(dev), PC_DIMM_NODE_PROP,
|
|
|
|
NULL);
|
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 07:20:58 +00:00
|
|
|
int slot = object_property_get_int(OBJECT(dev), PC_DIMM_SLOT_PROP,
|
2017-06-07 16:36:13 +00:00
|
|
|
NULL);
|
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 07:20:58 +00:00
|
|
|
|
|
|
|
nfit_spa = acpi_data_push(structures, sizeof(*nfit_spa));
|
|
|
|
|
|
|
|
nfit_spa->type = cpu_to_le16(0 /* System Physical Address Range
|
|
|
|
Structure */);
|
|
|
|
nfit_spa->length = cpu_to_le16(sizeof(*nfit_spa));
|
|
|
|
nfit_spa->spa_index = cpu_to_le16(nvdimm_slot_to_spa_index(slot));
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Control region is strict as all the device info, such as SN, index,
|
|
|
|
* is associated with slot id.
|
|
|
|
*/
|
|
|
|
nfit_spa->flags = cpu_to_le16(1 /* Control region is strictly for
|
|
|
|
management during hot add/online
|
|
|
|
operation */ |
|
|
|
|
2 /* Data in Proximity Domain field is
|
|
|
|
valid*/);
|
|
|
|
|
|
|
|
/* NUMA node. */
|
|
|
|
nfit_spa->proximity_domain = cpu_to_le32(node);
|
|
|
|
/* the region reported as PMEM. */
|
|
|
|
memcpy(nfit_spa->type_guid, nvdimm_nfit_spa_uuid,
|
|
|
|
sizeof(nvdimm_nfit_spa_uuid));
|
|
|
|
|
|
|
|
nfit_spa->spa_base = cpu_to_le64(addr);
|
|
|
|
nfit_spa->spa_length = cpu_to_le64(size);
|
|
|
|
|
|
|
|
/* It is the PMEM and can be cached as writeback. */
|
|
|
|
nfit_spa->mem_attr = cpu_to_le64(0x8ULL /* EFI_MEMORY_WB */ |
|
|
|
|
0x8000ULL /* EFI_MEMORY_NV */);
|
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
|
|
|
* ACPI 6.0: 5.2.25.2 Memory Device to System Physical Address Range Mapping
|
|
|
|
* Structure
|
|
|
|
*/
|
|
|
|
static void
|
|
|
|
nvdimm_build_structure_memdev(GArray *structures, DeviceState *dev)
|
|
|
|
{
|
|
|
|
NvdimmNfitMemDev *nfit_memdev;
|
2017-12-11 07:28:06 +00:00
|
|
|
NVDIMMDevice *nvdimm = NVDIMM(OBJECT(dev));
|
2017-06-07 16:36:14 +00:00
|
|
|
uint64_t size = object_property_get_uint(OBJECT(dev), PC_DIMM_SIZE_PROP,
|
|
|
|
NULL);
|
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 07:20:58 +00:00
|
|
|
int slot = object_property_get_int(OBJECT(dev), PC_DIMM_SLOT_PROP,
|
|
|
|
NULL);
|
|
|
|
uint32_t handle = nvdimm_slot_to_handle(slot);
|
|
|
|
|
|
|
|
nfit_memdev = acpi_data_push(structures, sizeof(*nfit_memdev));
|
|
|
|
|
|
|
|
nfit_memdev->type = cpu_to_le16(1 /* Memory Device to System Address
|
|
|
|
Range Map Structure*/);
|
|
|
|
nfit_memdev->length = cpu_to_le16(sizeof(*nfit_memdev));
|
|
|
|
nfit_memdev->nfit_handle = cpu_to_le32(handle);
|
|
|
|
|
|
|
|
/*
|
|
|
|
* associate memory device with System Physical Address Range
|
|
|
|
* Structure.
|
|
|
|
*/
|
|
|
|
nfit_memdev->spa_index = cpu_to_le16(nvdimm_slot_to_spa_index(slot));
|
|
|
|
/* associate memory device with Control Region Structure. */
|
|
|
|
nfit_memdev->dcr_index = cpu_to_le16(nvdimm_slot_to_dcr_index(slot));
|
|
|
|
|
|
|
|
/* The memory region on the device. */
|
|
|
|
nfit_memdev->region_len = cpu_to_le64(size);
|
2016-10-28 16:11:50 +00:00
|
|
|
/* The device address starts from 0. */
|
|
|
|
nfit_memdev->region_dpa = cpu_to_le64(0);
|
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 07:20:58 +00:00
|
|
|
|
|
|
|
/* Only one interleave for PMEM. */
|
|
|
|
nfit_memdev->interleave_ways = cpu_to_le16(1);
|
2017-12-11 07:28:06 +00:00
|
|
|
|
|
|
|
if (nvdimm->unarmed) {
|
|
|
|
nfit_memdev->flags |= cpu_to_le16(ACPI_NFIT_MEM_NOT_ARMED);
|
|
|
|
}
|
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 07:20:58 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
|
|
|
* ACPI 6.0: 5.2.25.5 NVDIMM Control Region Structure.
|
|
|
|
*/
|
|
|
|
static void nvdimm_build_structure_dcr(GArray *structures, DeviceState *dev)
|
|
|
|
{
|
|
|
|
NvdimmNfitControlRegion *nfit_dcr;
|
|
|
|
int slot = object_property_get_int(OBJECT(dev), PC_DIMM_SLOT_PROP,
|
|
|
|
NULL);
|
|
|
|
uint32_t sn = nvdimm_slot_to_sn(slot);
|
|
|
|
|
|
|
|
nfit_dcr = acpi_data_push(structures, sizeof(*nfit_dcr));
|
|
|
|
|
|
|
|
nfit_dcr->type = cpu_to_le16(4 /* NVDIMM Control Region Structure */);
|
|
|
|
nfit_dcr->length = cpu_to_le16(sizeof(*nfit_dcr));
|
|
|
|
nfit_dcr->dcr_index = cpu_to_le16(nvdimm_slot_to_dcr_index(slot));
|
|
|
|
|
|
|
|
/* vendor: Intel. */
|
|
|
|
nfit_dcr->vendor_id = cpu_to_le16(0x8086);
|
|
|
|
nfit_dcr->device_id = cpu_to_le16(1);
|
|
|
|
|
|
|
|
/* The _DSM method is following Intel's DSM specification. */
|
|
|
|
nfit_dcr->revision_id = cpu_to_le16(1 /* Current Revision supported
|
|
|
|
in ACPI 6.0 is 1. */);
|
|
|
|
nfit_dcr->serial_number = cpu_to_le32(sn);
|
2017-06-07 08:06:39 +00:00
|
|
|
nfit_dcr->fic = cpu_to_le16(0x301 /* Format Interface Code:
|
|
|
|
Byte addressable, no energy backed.
|
|
|
|
See ACPI 6.2, sect 5.2.25.6 and
|
|
|
|
JEDEC Annex L Release 3. */);
|
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 07:20:58 +00:00
|
|
|
}
|
|
|
|
|
2018-05-21 16:32:02 +00:00
|
|
|
/*
|
|
|
|
* ACPI 6.2 Errata A: 5.2.25.9 NVDIMM Platform Capabilities Structure
|
|
|
|
*/
|
|
|
|
static void
|
|
|
|
nvdimm_build_structure_caps(GArray *structures, uint32_t capabilities)
|
|
|
|
{
|
|
|
|
NvdimmNfitPlatformCaps *nfit_caps;
|
|
|
|
|
|
|
|
nfit_caps = acpi_data_push(structures, sizeof(*nfit_caps));
|
|
|
|
|
|
|
|
nfit_caps->type = cpu_to_le16(7 /* NVDIMM Platform Capabilities */);
|
|
|
|
nfit_caps->length = cpu_to_le16(sizeof(*nfit_caps));
|
|
|
|
nfit_caps->highest_cap = 31 - clz32(capabilities);
|
|
|
|
nfit_caps->capabilities = cpu_to_le32(capabilities);
|
|
|
|
}
|
|
|
|
|
2019-03-08 18:20:52 +00:00
|
|
|
static GArray *nvdimm_build_device_structure(NVDIMMState *state)
|
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 07:20:58 +00:00
|
|
|
{
|
2016-11-07 11:13:42 +00:00
|
|
|
GSList *device_list = nvdimm_get_device_list();
|
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 07:20:58 +00:00
|
|
|
GArray *structures = g_array_new(false, true /* clear */, 1);
|
|
|
|
|
|
|
|
for (; device_list; device_list = device_list->next) {
|
|
|
|
DeviceState *dev = device_list->data;
|
|
|
|
|
|
|
|
/* build System Physical Address Range Structure. */
|
|
|
|
nvdimm_build_structure_spa(structures, dev);
|
|
|
|
|
|
|
|
/*
|
|
|
|
* build Memory Device to System Physical Address Range Mapping
|
|
|
|
* Structure.
|
|
|
|
*/
|
|
|
|
nvdimm_build_structure_memdev(structures, dev);
|
|
|
|
|
|
|
|
/* build NVDIMM Control Region Structure. */
|
|
|
|
nvdimm_build_structure_dcr(structures, dev);
|
|
|
|
}
|
2016-10-28 16:35:38 +00:00
|
|
|
g_slist_free(device_list);
|
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 07:20:58 +00:00
|
|
|
|
2018-06-07 22:31:11 +00:00
|
|
|
if (state->persistence) {
|
|
|
|
nvdimm_build_structure_caps(structures, state->persistence);
|
2018-05-21 16:32:02 +00: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 07:20:58 +00:00
|
|
|
return structures;
|
|
|
|
}
|
|
|
|
|
2016-10-28 16:35:38 +00:00
|
|
|
static void nvdimm_init_fit_buffer(NvdimmFitBuffer *fit_buf)
|
|
|
|
{
|
|
|
|
fit_buf->fit = g_array_new(false, true /* clear */, 1);
|
|
|
|
}
|
|
|
|
|
2019-03-08 18:20:52 +00:00
|
|
|
static void nvdimm_build_fit_buffer(NVDIMMState *state)
|
2016-10-28 16:35:38 +00:00
|
|
|
{
|
2018-05-21 16:32:02 +00:00
|
|
|
NvdimmFitBuffer *fit_buf = &state->fit_buf;
|
|
|
|
|
2016-10-28 16:35:38 +00:00
|
|
|
g_array_free(fit_buf->fit, true);
|
2018-05-21 16:32:02 +00:00
|
|
|
fit_buf->fit = nvdimm_build_device_structure(state);
|
2016-10-28 16:35:38 +00:00
|
|
|
fit_buf->dirty = true;
|
|
|
|
}
|
|
|
|
|
2019-03-08 18:20:52 +00:00
|
|
|
void nvdimm_plug(NVDIMMState *state)
|
2016-10-28 16:35:38 +00:00
|
|
|
{
|
2018-05-21 16:32:02 +00:00
|
|
|
nvdimm_build_fit_buffer(state);
|
2016-10-28 16:35:38 +00:00
|
|
|
}
|
|
|
|
|
2019-03-08 18:20:52 +00:00
|
|
|
static void nvdimm_build_nfit(NVDIMMState *state, GArray *table_offsets,
|
2021-01-19 00:32:13 +00:00
|
|
|
GArray *table_data, BIOSLinker *linker,
|
|
|
|
const char *oem_id, const char *oem_table_id)
|
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 07:20:58 +00:00
|
|
|
{
|
2016-10-28 16:35:38 +00:00
|
|
|
NvdimmFitBuffer *fit_buf = &state->fit_buf;
|
2015-12-25 02:57:42 +00:00
|
|
|
unsigned int header;
|
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 07:20:58 +00:00
|
|
|
|
|
|
|
acpi_add_table(table_offsets, table_data);
|
|
|
|
|
|
|
|
/* NFIT header. */
|
2015-12-25 02:57:42 +00:00
|
|
|
header = table_data->len;
|
|
|
|
acpi_data_push(table_data, sizeof(NvdimmNfitHeader));
|
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 07:20:58 +00:00
|
|
|
/* NVDIMM device structures. */
|
2016-10-28 16:35:38 +00:00
|
|
|
g_array_append_vals(table_data, fit_buf->fit->data, fit_buf->fit->len);
|
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 07:20:58 +00:00
|
|
|
|
2015-12-25 02:57:42 +00:00
|
|
|
build_header(linker, table_data,
|
|
|
|
(void *)(table_data->data + header), "NFIT",
|
2021-01-19 00:32:13 +00:00
|
|
|
sizeof(NvdimmNfitHeader) + fit_buf->fit->len, 1, oem_id,
|
|
|
|
oem_table_id);
|
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 07:20:58 +00:00
|
|
|
}
|
|
|
|
|
2016-11-07 11:13:49 +00:00
|
|
|
#define NVDIMM_DSM_MEMORY_SIZE 4096
|
|
|
|
|
2016-03-04 16:00:34 +00:00
|
|
|
struct NvdimmDsmIn {
|
|
|
|
uint32_t handle;
|
|
|
|
uint32_t revision;
|
|
|
|
uint32_t function;
|
|
|
|
/* the remaining size in the page is used by arg3. */
|
|
|
|
union {
|
2016-03-31 08:56:54 +00:00
|
|
|
uint8_t arg3[4084];
|
2016-03-04 16:00:34 +00:00
|
|
|
};
|
|
|
|
} QEMU_PACKED;
|
|
|
|
typedef struct NvdimmDsmIn NvdimmDsmIn;
|
2016-11-07 11:13:49 +00:00
|
|
|
QEMU_BUILD_BUG_ON(sizeof(NvdimmDsmIn) != NVDIMM_DSM_MEMORY_SIZE);
|
2016-03-04 16:00:34 +00:00
|
|
|
|
|
|
|
struct NvdimmDsmOut {
|
|
|
|
/* the size of buffer filled by QEMU. */
|
|
|
|
uint32_t len;
|
2016-03-31 08:56:54 +00:00
|
|
|
uint8_t data[4092];
|
2016-03-04 16:00:34 +00:00
|
|
|
} QEMU_PACKED;
|
|
|
|
typedef struct NvdimmDsmOut NvdimmDsmOut;
|
2016-11-07 11:13:49 +00:00
|
|
|
QEMU_BUILD_BUG_ON(sizeof(NvdimmDsmOut) != NVDIMM_DSM_MEMORY_SIZE);
|
2016-03-04 16:00:34 +00:00
|
|
|
|
2016-03-04 16:00:35 +00:00
|
|
|
struct NvdimmDsmFunc0Out {
|
|
|
|
/* the size of buffer filled by QEMU. */
|
|
|
|
uint32_t len;
|
|
|
|
uint32_t supported_func;
|
|
|
|
} QEMU_PACKED;
|
|
|
|
typedef struct NvdimmDsmFunc0Out NvdimmDsmFunc0Out;
|
|
|
|
|
|
|
|
struct NvdimmDsmFuncNoPayloadOut {
|
|
|
|
/* the size of buffer filled by QEMU. */
|
|
|
|
uint32_t len;
|
|
|
|
uint32_t func_ret_status;
|
|
|
|
} QEMU_PACKED;
|
|
|
|
typedef struct NvdimmDsmFuncNoPayloadOut NvdimmDsmFuncNoPayloadOut;
|
|
|
|
|
2016-06-07 12:22:06 +00:00
|
|
|
struct NvdimmFuncGetLabelSizeOut {
|
|
|
|
/* the size of buffer filled by QEMU. */
|
|
|
|
uint32_t len;
|
|
|
|
uint32_t func_ret_status; /* return status code. */
|
|
|
|
uint32_t label_size; /* the size of label data area. */
|
|
|
|
/*
|
|
|
|
* Maximum size of the namespace label data length supported by
|
|
|
|
* the platform in Get/Set Namespace Label Data functions.
|
|
|
|
*/
|
|
|
|
uint32_t max_xfer;
|
|
|
|
} QEMU_PACKED;
|
|
|
|
typedef struct NvdimmFuncGetLabelSizeOut NvdimmFuncGetLabelSizeOut;
|
2016-11-07 11:13:49 +00:00
|
|
|
QEMU_BUILD_BUG_ON(sizeof(NvdimmFuncGetLabelSizeOut) > NVDIMM_DSM_MEMORY_SIZE);
|
2016-06-07 12:22:06 +00:00
|
|
|
|
2016-06-07 12:22:07 +00:00
|
|
|
struct NvdimmFuncGetLabelDataIn {
|
|
|
|
uint32_t offset; /* the offset in the namespace label data area. */
|
|
|
|
uint32_t length; /* the size of data is to be read via the function. */
|
|
|
|
} QEMU_PACKED;
|
|
|
|
typedef struct NvdimmFuncGetLabelDataIn NvdimmFuncGetLabelDataIn;
|
|
|
|
QEMU_BUILD_BUG_ON(sizeof(NvdimmFuncGetLabelDataIn) +
|
2016-11-07 11:13:49 +00:00
|
|
|
offsetof(NvdimmDsmIn, arg3) > NVDIMM_DSM_MEMORY_SIZE);
|
2016-06-07 12:22:07 +00:00
|
|
|
|
2016-06-07 12:22:06 +00:00
|
|
|
struct NvdimmFuncGetLabelDataOut {
|
|
|
|
/* the size of buffer filled by QEMU. */
|
|
|
|
uint32_t len;
|
|
|
|
uint32_t func_ret_status; /* return status code. */
|
misc: Replace zero-length arrays with flexible array member (automatic)
Description copied from Linux kernel commit from Gustavo A. R. Silva
(see [3]):
--v-- description start --v--
The current codebase makes use of the zero-length array language
extension to the C90 standard, but the preferred mechanism to
declare variable-length types such as these ones is a flexible
array member [1], introduced in C99:
struct foo {
int stuff;
struct boo array[];
};
By making use of the mechanism above, we will get a compiler
warning in case the flexible array does not occur last in the
structure, which will help us prevent some kind of undefined
behavior bugs from being unadvertenly introduced [2] to the
Linux codebase from now on.
--^-- description end --^--
Do the similar housekeeping in the QEMU codebase (which uses
C99 since commit 7be41675f7cb).
All these instances of code were found with the help of the
following Coccinelle script:
@@
identifier s, m, a;
type t, T;
@@
struct s {
...
t m;
- T a[0];
+ T a[];
};
@@
identifier s, m, a;
type t, T;
@@
struct s {
...
t m;
- T a[0];
+ T a[];
} QEMU_PACKED;
[1] https://gcc.gnu.org/onlinedocs/gcc/Zero-Length.html
[2] https://git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git/commit/?id=76497732932f
[3] https://git.kernel.org/pub/scm/linux/kernel/git/gustavoars/linux.git/commit/?id=17642a2fbd2c1
Inspired-by: Gustavo A. R. Silva <gustavo@embeddedor.com>
Reviewed-by: David Hildenbrand <david@redhat.com>
Signed-off-by: Philippe Mathieu-Daudé <philmd@redhat.com>
Signed-off-by: Paolo Bonzini <pbonzini@redhat.com>
2020-03-04 15:38:15 +00:00
|
|
|
uint8_t out_buf[]; /* the data got via Get Namesapce Label function. */
|
2016-06-07 12:22:06 +00:00
|
|
|
} QEMU_PACKED;
|
|
|
|
typedef struct NvdimmFuncGetLabelDataOut NvdimmFuncGetLabelDataOut;
|
2016-11-07 11:13:49 +00:00
|
|
|
QEMU_BUILD_BUG_ON(sizeof(NvdimmFuncGetLabelDataOut) > NVDIMM_DSM_MEMORY_SIZE);
|
2016-06-07 12:22:06 +00:00
|
|
|
|
|
|
|
struct NvdimmFuncSetLabelDataIn {
|
|
|
|
uint32_t offset; /* the offset in the namespace label data area. */
|
|
|
|
uint32_t length; /* the size of data is to be written via the function. */
|
misc: Replace zero-length arrays with flexible array member (automatic)
Description copied from Linux kernel commit from Gustavo A. R. Silva
(see [3]):
--v-- description start --v--
The current codebase makes use of the zero-length array language
extension to the C90 standard, but the preferred mechanism to
declare variable-length types such as these ones is a flexible
array member [1], introduced in C99:
struct foo {
int stuff;
struct boo array[];
};
By making use of the mechanism above, we will get a compiler
warning in case the flexible array does not occur last in the
structure, which will help us prevent some kind of undefined
behavior bugs from being unadvertenly introduced [2] to the
Linux codebase from now on.
--^-- description end --^--
Do the similar housekeeping in the QEMU codebase (which uses
C99 since commit 7be41675f7cb).
All these instances of code were found with the help of the
following Coccinelle script:
@@
identifier s, m, a;
type t, T;
@@
struct s {
...
t m;
- T a[0];
+ T a[];
};
@@
identifier s, m, a;
type t, T;
@@
struct s {
...
t m;
- T a[0];
+ T a[];
} QEMU_PACKED;
[1] https://gcc.gnu.org/onlinedocs/gcc/Zero-Length.html
[2] https://git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git/commit/?id=76497732932f
[3] https://git.kernel.org/pub/scm/linux/kernel/git/gustavoars/linux.git/commit/?id=17642a2fbd2c1
Inspired-by: Gustavo A. R. Silva <gustavo@embeddedor.com>
Reviewed-by: David Hildenbrand <david@redhat.com>
Signed-off-by: Philippe Mathieu-Daudé <philmd@redhat.com>
Signed-off-by: Paolo Bonzini <pbonzini@redhat.com>
2020-03-04 15:38:15 +00:00
|
|
|
uint8_t in_buf[]; /* the data written to label data area. */
|
2016-06-07 12:22:06 +00:00
|
|
|
} QEMU_PACKED;
|
|
|
|
typedef struct NvdimmFuncSetLabelDataIn NvdimmFuncSetLabelDataIn;
|
2016-06-07 12:22:08 +00:00
|
|
|
QEMU_BUILD_BUG_ON(sizeof(NvdimmFuncSetLabelDataIn) +
|
2016-11-07 11:13:49 +00:00
|
|
|
offsetof(NvdimmDsmIn, arg3) > NVDIMM_DSM_MEMORY_SIZE);
|
2016-06-07 12:22:06 +00:00
|
|
|
|
2016-10-28 16:35:39 +00:00
|
|
|
struct NvdimmFuncReadFITIn {
|
2016-11-07 11:13:46 +00:00
|
|
|
uint32_t offset; /* the offset into FIT buffer. */
|
2016-10-28 16:35:39 +00:00
|
|
|
} QEMU_PACKED;
|
|
|
|
typedef struct NvdimmFuncReadFITIn NvdimmFuncReadFITIn;
|
|
|
|
QEMU_BUILD_BUG_ON(sizeof(NvdimmFuncReadFITIn) +
|
2016-11-07 11:13:49 +00:00
|
|
|
offsetof(NvdimmDsmIn, arg3) > NVDIMM_DSM_MEMORY_SIZE);
|
2016-10-28 16:35:39 +00:00
|
|
|
|
|
|
|
struct NvdimmFuncReadFITOut {
|
|
|
|
/* the size of buffer filled by QEMU. */
|
|
|
|
uint32_t len;
|
|
|
|
uint32_t func_ret_status; /* return status code. */
|
misc: Replace zero-length arrays with flexible array member (automatic)
Description copied from Linux kernel commit from Gustavo A. R. Silva
(see [3]):
--v-- description start --v--
The current codebase makes use of the zero-length array language
extension to the C90 standard, but the preferred mechanism to
declare variable-length types such as these ones is a flexible
array member [1], introduced in C99:
struct foo {
int stuff;
struct boo array[];
};
By making use of the mechanism above, we will get a compiler
warning in case the flexible array does not occur last in the
structure, which will help us prevent some kind of undefined
behavior bugs from being unadvertenly introduced [2] to the
Linux codebase from now on.
--^-- description end --^--
Do the similar housekeeping in the QEMU codebase (which uses
C99 since commit 7be41675f7cb).
All these instances of code were found with the help of the
following Coccinelle script:
@@
identifier s, m, a;
type t, T;
@@
struct s {
...
t m;
- T a[0];
+ T a[];
};
@@
identifier s, m, a;
type t, T;
@@
struct s {
...
t m;
- T a[0];
+ T a[];
} QEMU_PACKED;
[1] https://gcc.gnu.org/onlinedocs/gcc/Zero-Length.html
[2] https://git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git/commit/?id=76497732932f
[3] https://git.kernel.org/pub/scm/linux/kernel/git/gustavoars/linux.git/commit/?id=17642a2fbd2c1
Inspired-by: Gustavo A. R. Silva <gustavo@embeddedor.com>
Reviewed-by: David Hildenbrand <david@redhat.com>
Signed-off-by: Philippe Mathieu-Daudé <philmd@redhat.com>
Signed-off-by: Paolo Bonzini <pbonzini@redhat.com>
2020-03-04 15:38:15 +00:00
|
|
|
uint8_t fit[]; /* the FIT data. */
|
2016-10-28 16:35:39 +00:00
|
|
|
} QEMU_PACKED;
|
|
|
|
typedef struct NvdimmFuncReadFITOut NvdimmFuncReadFITOut;
|
2016-11-07 11:13:49 +00:00
|
|
|
QEMU_BUILD_BUG_ON(sizeof(NvdimmFuncReadFITOut) > NVDIMM_DSM_MEMORY_SIZE);
|
2016-10-28 16:35:39 +00:00
|
|
|
|
2016-06-07 12:22:04 +00:00
|
|
|
static void
|
|
|
|
nvdimm_dsm_function0(uint32_t supported_func, hwaddr dsm_mem_addr)
|
|
|
|
{
|
|
|
|
NvdimmDsmFunc0Out func0 = {
|
|
|
|
.len = cpu_to_le32(sizeof(func0)),
|
|
|
|
.supported_func = cpu_to_le32(supported_func),
|
|
|
|
};
|
|
|
|
cpu_physical_memory_write(dsm_mem_addr, &func0, sizeof(func0));
|
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
|
|
|
nvdimm_dsm_no_payload(uint32_t func_ret_status, hwaddr dsm_mem_addr)
|
|
|
|
{
|
|
|
|
NvdimmDsmFuncNoPayloadOut out = {
|
|
|
|
.len = cpu_to_le32(sizeof(out)),
|
|
|
|
.func_ret_status = cpu_to_le32(func_ret_status),
|
|
|
|
};
|
|
|
|
cpu_physical_memory_write(dsm_mem_addr, &out, sizeof(out));
|
|
|
|
}
|
|
|
|
|
2016-11-07 11:13:45 +00:00
|
|
|
#define NVDIMM_DSM_RET_STATUS_SUCCESS 0 /* Success */
|
|
|
|
#define NVDIMM_DSM_RET_STATUS_UNSUPPORT 1 /* Not Supported */
|
|
|
|
#define NVDIMM_DSM_RET_STATUS_NOMEMDEV 2 /* Non-Existing Memory Device */
|
|
|
|
#define NVDIMM_DSM_RET_STATUS_INVALID 3 /* Invalid Input Parameters */
|
|
|
|
#define NVDIMM_DSM_RET_STATUS_FIT_CHANGED 0x100 /* FIT Changed */
|
|
|
|
|
|
|
|
#define NVDIMM_QEMU_RSVD_HANDLE_ROOT 0x10000
|
2016-10-28 16:35:39 +00:00
|
|
|
|
|
|
|
/* Read FIT data, defined in docs/specs/acpi_nvdimm.txt. */
|
2019-03-08 18:20:52 +00:00
|
|
|
static void nvdimm_dsm_func_read_fit(NVDIMMState *state, NvdimmDsmIn *in,
|
2016-10-28 16:35:39 +00:00
|
|
|
hwaddr dsm_mem_addr)
|
|
|
|
{
|
|
|
|
NvdimmFitBuffer *fit_buf = &state->fit_buf;
|
|
|
|
NvdimmFuncReadFITIn *read_fit;
|
|
|
|
NvdimmFuncReadFITOut *read_fit_out;
|
|
|
|
GArray *fit;
|
|
|
|
uint32_t read_len = 0, func_ret_status;
|
|
|
|
int size;
|
|
|
|
|
|
|
|
read_fit = (NvdimmFuncReadFITIn *)in->arg3;
|
2018-10-16 17:52:36 +00:00
|
|
|
read_fit->offset = le32_to_cpu(read_fit->offset);
|
2016-10-28 16:35:39 +00:00
|
|
|
|
|
|
|
fit = fit_buf->fit;
|
|
|
|
|
2020-11-03 10:26:32 +00:00
|
|
|
nvdimm_debug("Read FIT: offset 0x%x FIT size 0x%x Dirty %s.\n",
|
2016-10-28 16:35:39 +00:00
|
|
|
read_fit->offset, fit->len, fit_buf->dirty ? "Yes" : "No");
|
|
|
|
|
|
|
|
if (read_fit->offset > fit->len) {
|
2016-11-07 11:13:45 +00:00
|
|
|
func_ret_status = NVDIMM_DSM_RET_STATUS_INVALID;
|
2016-10-28 16:35:39 +00:00
|
|
|
goto exit;
|
|
|
|
}
|
|
|
|
|
|
|
|
/* It is the first time to read FIT. */
|
|
|
|
if (!read_fit->offset) {
|
|
|
|
fit_buf->dirty = false;
|
|
|
|
} else if (fit_buf->dirty) { /* FIT has been changed during RFIT. */
|
2016-11-07 11:13:45 +00:00
|
|
|
func_ret_status = NVDIMM_DSM_RET_STATUS_FIT_CHANGED;
|
2016-10-28 16:35:39 +00:00
|
|
|
goto exit;
|
|
|
|
}
|
|
|
|
|
2016-11-07 11:13:45 +00:00
|
|
|
func_ret_status = NVDIMM_DSM_RET_STATUS_SUCCESS;
|
2016-10-28 16:35:39 +00:00
|
|
|
read_len = MIN(fit->len - read_fit->offset,
|
2016-11-07 11:13:49 +00:00
|
|
|
NVDIMM_DSM_MEMORY_SIZE - sizeof(NvdimmFuncReadFITOut));
|
2016-10-28 16:35:39 +00:00
|
|
|
|
|
|
|
exit:
|
|
|
|
size = sizeof(NvdimmFuncReadFITOut) + read_len;
|
|
|
|
read_fit_out = g_malloc(size);
|
|
|
|
|
|
|
|
read_fit_out->len = cpu_to_le32(size);
|
|
|
|
read_fit_out->func_ret_status = cpu_to_le32(func_ret_status);
|
|
|
|
memcpy(read_fit_out->fit, fit->data + read_fit->offset, read_len);
|
|
|
|
|
|
|
|
cpu_physical_memory_write(dsm_mem_addr, read_fit_out, size);
|
|
|
|
|
|
|
|
g_free(read_fit_out);
|
|
|
|
}
|
|
|
|
|
2016-11-07 11:13:47 +00:00
|
|
|
static void
|
2019-03-08 18:20:52 +00:00
|
|
|
nvdimm_dsm_handle_reserved_root_method(NVDIMMState *state,
|
2016-11-07 11:13:47 +00:00
|
|
|
NvdimmDsmIn *in, hwaddr dsm_mem_addr)
|
2016-10-28 16:35:39 +00:00
|
|
|
{
|
|
|
|
switch (in->function) {
|
|
|
|
case 0x0:
|
|
|
|
nvdimm_dsm_function0(0x1 | 1 << 1 /* Read FIT */, dsm_mem_addr);
|
|
|
|
return;
|
2016-11-07 11:13:46 +00:00
|
|
|
case 0x1 /* Read FIT */:
|
2016-10-28 16:35:39 +00:00
|
|
|
nvdimm_dsm_func_read_fit(state, in, dsm_mem_addr);
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2016-11-07 11:13:45 +00:00
|
|
|
nvdimm_dsm_no_payload(NVDIMM_DSM_RET_STATUS_UNSUPPORT, dsm_mem_addr);
|
2016-10-28 16:35:39 +00:00
|
|
|
}
|
|
|
|
|
2016-06-07 12:22:04 +00:00
|
|
|
static void nvdimm_dsm_root(NvdimmDsmIn *in, hwaddr dsm_mem_addr)
|
|
|
|
{
|
|
|
|
/*
|
|
|
|
* function 0 is called to inquire which functions are supported by
|
|
|
|
* OSPM
|
|
|
|
*/
|
|
|
|
if (!in->function) {
|
|
|
|
nvdimm_dsm_function0(0 /* No function supported other than
|
|
|
|
function 0 */, dsm_mem_addr);
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
/* No function except function 0 is supported yet. */
|
2016-11-07 11:13:45 +00:00
|
|
|
nvdimm_dsm_no_payload(NVDIMM_DSM_RET_STATUS_UNSUPPORT, dsm_mem_addr);
|
2016-06-07 12:22:04 +00:00
|
|
|
}
|
|
|
|
|
2016-06-07 12:22:06 +00:00
|
|
|
/*
|
|
|
|
* the max transfer size is the max size transferred by both a
|
|
|
|
* 'Get Namespace Label Data' function and a 'Set Namespace Label Data'
|
|
|
|
* function.
|
|
|
|
*/
|
|
|
|
static uint32_t nvdimm_get_max_xfer_label_size(void)
|
|
|
|
{
|
2016-11-07 11:13:49 +00:00
|
|
|
uint32_t max_get_size, max_set_size, dsm_memory_size;
|
|
|
|
|
|
|
|
dsm_memory_size = NVDIMM_DSM_MEMORY_SIZE;
|
2016-06-07 12:22:06 +00:00
|
|
|
|
|
|
|
/*
|
|
|
|
* the max data ACPI can read one time which is transferred by
|
|
|
|
* the response of 'Get Namespace Label Data' function.
|
|
|
|
*/
|
|
|
|
max_get_size = dsm_memory_size - sizeof(NvdimmFuncGetLabelDataOut);
|
|
|
|
|
|
|
|
/*
|
|
|
|
* the max data ACPI can write one time which is transferred by
|
|
|
|
* 'Set Namespace Label Data' function.
|
|
|
|
*/
|
|
|
|
max_set_size = dsm_memory_size - offsetof(NvdimmDsmIn, arg3) -
|
|
|
|
sizeof(NvdimmFuncSetLabelDataIn);
|
|
|
|
|
|
|
|
return MIN(max_get_size, max_set_size);
|
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
|
|
|
* DSM Spec Rev1 4.4 Get Namespace Label Size (Function Index 4).
|
|
|
|
*
|
|
|
|
* It gets the size of Namespace Label data area and the max data size
|
|
|
|
* that Get/Set Namespace Label Data functions can transfer.
|
|
|
|
*/
|
|
|
|
static void nvdimm_dsm_label_size(NVDIMMDevice *nvdimm, hwaddr dsm_mem_addr)
|
|
|
|
{
|
|
|
|
NvdimmFuncGetLabelSizeOut label_size_out = {
|
|
|
|
.len = cpu_to_le32(sizeof(label_size_out)),
|
|
|
|
};
|
|
|
|
uint32_t label_size, mxfer;
|
|
|
|
|
|
|
|
label_size = nvdimm->label_size;
|
|
|
|
mxfer = nvdimm_get_max_xfer_label_size();
|
|
|
|
|
2020-11-03 10:26:32 +00:00
|
|
|
nvdimm_debug("label_size 0x%x, max_xfer 0x%x.\n", label_size, mxfer);
|
2016-06-07 12:22:06 +00:00
|
|
|
|
2016-11-07 11:13:45 +00:00
|
|
|
label_size_out.func_ret_status = cpu_to_le32(NVDIMM_DSM_RET_STATUS_SUCCESS);
|
2016-06-07 12:22:06 +00:00
|
|
|
label_size_out.label_size = cpu_to_le32(label_size);
|
|
|
|
label_size_out.max_xfer = cpu_to_le32(mxfer);
|
|
|
|
|
|
|
|
cpu_physical_memory_write(dsm_mem_addr, &label_size_out,
|
|
|
|
sizeof(label_size_out));
|
|
|
|
}
|
|
|
|
|
2016-06-07 12:22:07 +00:00
|
|
|
static uint32_t nvdimm_rw_label_data_check(NVDIMMDevice *nvdimm,
|
|
|
|
uint32_t offset, uint32_t length)
|
|
|
|
{
|
2016-11-07 11:13:45 +00:00
|
|
|
uint32_t ret = NVDIMM_DSM_RET_STATUS_INVALID;
|
2016-06-07 12:22:07 +00:00
|
|
|
|
|
|
|
if (offset + length < offset) {
|
2020-11-03 10:26:32 +00:00
|
|
|
nvdimm_debug("offset 0x%x + length 0x%x is overflow.\n", offset,
|
2016-06-07 12:22:07 +00:00
|
|
|
length);
|
|
|
|
return ret;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (nvdimm->label_size < offset + length) {
|
2020-11-03 10:26:32 +00:00
|
|
|
nvdimm_debug("position 0x%x is beyond label data (len = %" PRIx64 ").\n",
|
2016-06-07 12:22:07 +00:00
|
|
|
offset + length, nvdimm->label_size);
|
|
|
|
return ret;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (length > nvdimm_get_max_xfer_label_size()) {
|
2020-11-03 10:26:32 +00:00
|
|
|
nvdimm_debug("length (0x%x) is larger than max_xfer (0x%x).\n",
|
2016-06-07 12:22:07 +00:00
|
|
|
length, nvdimm_get_max_xfer_label_size());
|
|
|
|
return ret;
|
|
|
|
}
|
|
|
|
|
2016-11-07 11:13:45 +00:00
|
|
|
return NVDIMM_DSM_RET_STATUS_SUCCESS;
|
2016-06-07 12:22:07 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
|
|
|
* DSM Spec Rev1 4.5 Get Namespace Label Data (Function Index 5).
|
|
|
|
*/
|
|
|
|
static void nvdimm_dsm_get_label_data(NVDIMMDevice *nvdimm, NvdimmDsmIn *in,
|
|
|
|
hwaddr dsm_mem_addr)
|
|
|
|
{
|
|
|
|
NVDIMMClass *nvc = NVDIMM_GET_CLASS(nvdimm);
|
|
|
|
NvdimmFuncGetLabelDataIn *get_label_data;
|
|
|
|
NvdimmFuncGetLabelDataOut *get_label_data_out;
|
|
|
|
uint32_t status;
|
|
|
|
int size;
|
|
|
|
|
|
|
|
get_label_data = (NvdimmFuncGetLabelDataIn *)in->arg3;
|
2018-10-16 17:52:36 +00:00
|
|
|
get_label_data->offset = le32_to_cpu(get_label_data->offset);
|
|
|
|
get_label_data->length = le32_to_cpu(get_label_data->length);
|
2016-06-07 12:22:07 +00:00
|
|
|
|
2020-11-03 10:26:32 +00:00
|
|
|
nvdimm_debug("Read Label Data: offset 0x%x length 0x%x.\n",
|
2016-06-07 12:22:07 +00:00
|
|
|
get_label_data->offset, get_label_data->length);
|
|
|
|
|
|
|
|
status = nvdimm_rw_label_data_check(nvdimm, get_label_data->offset,
|
|
|
|
get_label_data->length);
|
2016-11-07 11:13:45 +00:00
|
|
|
if (status != NVDIMM_DSM_RET_STATUS_SUCCESS) {
|
2016-06-07 12:22:07 +00:00
|
|
|
nvdimm_dsm_no_payload(status, dsm_mem_addr);
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
size = sizeof(*get_label_data_out) + get_label_data->length;
|
2016-11-07 11:13:49 +00:00
|
|
|
assert(size <= NVDIMM_DSM_MEMORY_SIZE);
|
2016-06-07 12:22:07 +00:00
|
|
|
get_label_data_out = g_malloc(size);
|
|
|
|
|
|
|
|
get_label_data_out->len = cpu_to_le32(size);
|
2016-11-07 11:13:45 +00:00
|
|
|
get_label_data_out->func_ret_status =
|
|
|
|
cpu_to_le32(NVDIMM_DSM_RET_STATUS_SUCCESS);
|
2016-06-07 12:22:07 +00:00
|
|
|
nvc->read_label_data(nvdimm, get_label_data_out->out_buf,
|
|
|
|
get_label_data->length, get_label_data->offset);
|
|
|
|
|
|
|
|
cpu_physical_memory_write(dsm_mem_addr, get_label_data_out, size);
|
|
|
|
g_free(get_label_data_out);
|
|
|
|
}
|
|
|
|
|
2016-06-07 12:22:08 +00:00
|
|
|
/*
|
|
|
|
* DSM Spec Rev1 4.6 Set Namespace Label Data (Function Index 6).
|
|
|
|
*/
|
|
|
|
static void nvdimm_dsm_set_label_data(NVDIMMDevice *nvdimm, NvdimmDsmIn *in,
|
|
|
|
hwaddr dsm_mem_addr)
|
|
|
|
{
|
|
|
|
NVDIMMClass *nvc = NVDIMM_GET_CLASS(nvdimm);
|
|
|
|
NvdimmFuncSetLabelDataIn *set_label_data;
|
|
|
|
uint32_t status;
|
|
|
|
|
|
|
|
set_label_data = (NvdimmFuncSetLabelDataIn *)in->arg3;
|
|
|
|
|
2018-10-16 17:52:36 +00:00
|
|
|
set_label_data->offset = le32_to_cpu(set_label_data->offset);
|
|
|
|
set_label_data->length = le32_to_cpu(set_label_data->length);
|
2016-06-07 12:22:08 +00:00
|
|
|
|
2020-11-03 10:26:32 +00:00
|
|
|
nvdimm_debug("Write Label Data: offset 0x%x length 0x%x.\n",
|
2016-06-07 12:22:08 +00:00
|
|
|
set_label_data->offset, set_label_data->length);
|
|
|
|
|
|
|
|
status = nvdimm_rw_label_data_check(nvdimm, set_label_data->offset,
|
|
|
|
set_label_data->length);
|
2016-11-07 11:13:45 +00:00
|
|
|
if (status != NVDIMM_DSM_RET_STATUS_SUCCESS) {
|
2016-06-07 12:22:08 +00:00
|
|
|
nvdimm_dsm_no_payload(status, dsm_mem_addr);
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2016-11-07 11:13:49 +00:00
|
|
|
assert(offsetof(NvdimmDsmIn, arg3) + sizeof(*set_label_data) +
|
|
|
|
set_label_data->length <= NVDIMM_DSM_MEMORY_SIZE);
|
2016-06-07 12:22:08 +00:00
|
|
|
|
|
|
|
nvc->write_label_data(nvdimm, set_label_data->in_buf,
|
|
|
|
set_label_data->length, set_label_data->offset);
|
2016-11-07 11:13:45 +00:00
|
|
|
nvdimm_dsm_no_payload(NVDIMM_DSM_RET_STATUS_SUCCESS, dsm_mem_addr);
|
2016-06-07 12:22:08 +00:00
|
|
|
}
|
|
|
|
|
2016-06-07 12:22:04 +00:00
|
|
|
static void nvdimm_dsm_device(NvdimmDsmIn *in, hwaddr dsm_mem_addr)
|
|
|
|
{
|
2016-06-07 12:22:06 +00:00
|
|
|
NVDIMMDevice *nvdimm = nvdimm_get_device_by_handle(in->handle);
|
|
|
|
|
2016-06-07 12:22:04 +00:00
|
|
|
/* See the comments in nvdimm_dsm_root(). */
|
|
|
|
if (!in->function) {
|
2016-06-07 12:22:06 +00:00
|
|
|
uint32_t supported_func = 0;
|
|
|
|
|
|
|
|
if (nvdimm && nvdimm->label_size) {
|
|
|
|
supported_func |= 0x1 /* Bit 0 indicates whether there is
|
|
|
|
support for any functions other
|
|
|
|
than function 0. */ |
|
2016-06-07 12:22:07 +00:00
|
|
|
1 << 4 /* Get Namespace Label Size */ |
|
2016-06-07 12:22:08 +00:00
|
|
|
1 << 5 /* Get Namespace Label Data */ |
|
|
|
|
1 << 6 /* Set Namespace Label Data */;
|
2016-06-07 12:22:06 +00:00
|
|
|
}
|
|
|
|
nvdimm_dsm_function0(supported_func, dsm_mem_addr);
|
2016-06-07 12:22:04 +00:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2016-06-07 12:22:06 +00:00
|
|
|
if (!nvdimm) {
|
2016-11-07 11:13:45 +00:00
|
|
|
nvdimm_dsm_no_payload(NVDIMM_DSM_RET_STATUS_NOMEMDEV,
|
2016-06-07 12:22:06 +00:00
|
|
|
dsm_mem_addr);
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
/* Encode DSM function according to DSM Spec Rev1. */
|
|
|
|
switch (in->function) {
|
|
|
|
case 4 /* Get Namespace Label Size */:
|
|
|
|
if (nvdimm->label_size) {
|
|
|
|
nvdimm_dsm_label_size(nvdimm, dsm_mem_addr);
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
break;
|
2016-06-07 12:22:07 +00:00
|
|
|
case 5 /* Get Namespace Label Data */:
|
|
|
|
if (nvdimm->label_size) {
|
|
|
|
nvdimm_dsm_get_label_data(nvdimm, in, dsm_mem_addr);
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
break;
|
2016-06-07 12:22:08 +00:00
|
|
|
case 0x6 /* Set Namespace Label Data */:
|
|
|
|
if (nvdimm->label_size) {
|
|
|
|
nvdimm_dsm_set_label_data(nvdimm, in, dsm_mem_addr);
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
break;
|
2016-06-07 12:22:06 +00:00
|
|
|
}
|
|
|
|
|
2016-11-07 11:13:45 +00:00
|
|
|
nvdimm_dsm_no_payload(NVDIMM_DSM_RET_STATUS_UNSUPPORT, dsm_mem_addr);
|
2016-06-07 12:22:04 +00:00
|
|
|
}
|
|
|
|
|
2016-03-04 16:00:32 +00:00
|
|
|
static uint64_t
|
|
|
|
nvdimm_dsm_read(void *opaque, hwaddr addr, unsigned size)
|
|
|
|
{
|
2016-03-04 16:00:35 +00:00
|
|
|
nvdimm_debug("BUG: we never read _DSM IO Port.\n");
|
2016-03-04 16:00:32 +00:00
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
|
|
|
nvdimm_dsm_write(void *opaque, hwaddr addr, uint64_t val, unsigned size)
|
|
|
|
{
|
2019-03-08 18:20:52 +00:00
|
|
|
NVDIMMState *state = opaque;
|
2016-03-04 16:00:35 +00:00
|
|
|
NvdimmDsmIn *in;
|
|
|
|
hwaddr dsm_mem_addr = val;
|
|
|
|
|
2020-11-03 10:26:32 +00:00
|
|
|
nvdimm_debug("dsm memory address 0x%" HWADDR_PRIx ".\n", dsm_mem_addr);
|
2016-03-04 16:00:35 +00:00
|
|
|
|
|
|
|
/*
|
|
|
|
* The DSM memory is mapped to guest address space so an evil guest
|
|
|
|
* can change its content while we are doing DSM emulation. Avoid
|
|
|
|
* this by copying DSM memory to QEMU local memory.
|
|
|
|
*/
|
2016-03-31 08:56:54 +00:00
|
|
|
in = g_new(NvdimmDsmIn, 1);
|
|
|
|
cpu_physical_memory_read(dsm_mem_addr, in, sizeof(*in));
|
2016-03-04 16:00:35 +00:00
|
|
|
|
2018-10-16 17:52:36 +00:00
|
|
|
in->revision = le32_to_cpu(in->revision);
|
|
|
|
in->function = le32_to_cpu(in->function);
|
|
|
|
in->handle = le32_to_cpu(in->handle);
|
2016-03-04 16:00:35 +00:00
|
|
|
|
2020-11-03 10:26:32 +00:00
|
|
|
nvdimm_debug("Revision 0x%x Handler 0x%x Function 0x%x.\n", in->revision,
|
2016-03-04 16:00:35 +00:00
|
|
|
in->handle, in->function);
|
|
|
|
|
2016-06-07 12:22:05 +00:00
|
|
|
if (in->revision != 0x1 /* Currently we only support DSM Spec Rev1. */) {
|
2020-11-03 10:26:32 +00:00
|
|
|
nvdimm_debug("Revision 0x%x is not supported, expect 0x%x.\n",
|
2016-06-07 12:22:05 +00:00
|
|
|
in->revision, 0x1);
|
2016-11-07 11:13:45 +00:00
|
|
|
nvdimm_dsm_no_payload(NVDIMM_DSM_RET_STATUS_UNSUPPORT, dsm_mem_addr);
|
2016-06-07 12:22:05 +00:00
|
|
|
goto exit;
|
|
|
|
}
|
|
|
|
|
2016-10-28 16:35:39 +00:00
|
|
|
if (in->handle == NVDIMM_QEMU_RSVD_HANDLE_ROOT) {
|
2016-11-07 11:13:47 +00:00
|
|
|
nvdimm_dsm_handle_reserved_root_method(state, in, dsm_mem_addr);
|
2016-10-28 16:35:39 +00:00
|
|
|
goto exit;
|
|
|
|
}
|
|
|
|
|
2016-06-07 12:22:04 +00:00
|
|
|
/* Handle 0 is reserved for NVDIMM Root Device. */
|
|
|
|
if (!in->handle) {
|
|
|
|
nvdimm_dsm_root(in, dsm_mem_addr);
|
|
|
|
goto exit;
|
2016-03-04 16:00:35 +00:00
|
|
|
}
|
|
|
|
|
2016-06-07 12:22:04 +00:00
|
|
|
nvdimm_dsm_device(in, dsm_mem_addr);
|
|
|
|
|
|
|
|
exit:
|
2016-03-04 16:00:35 +00:00
|
|
|
g_free(in);
|
2016-03-04 16:00:32 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
static const MemoryRegionOps nvdimm_dsm_ops = {
|
|
|
|
.read = nvdimm_dsm_read,
|
|
|
|
.write = nvdimm_dsm_write,
|
|
|
|
.endianness = DEVICE_LITTLE_ENDIAN,
|
|
|
|
.valid = {
|
|
|
|
.min_access_size = 4,
|
|
|
|
.max_access_size = 4,
|
|
|
|
},
|
|
|
|
};
|
|
|
|
|
2016-11-07 11:13:38 +00:00
|
|
|
void nvdimm_acpi_plug_cb(HotplugHandler *hotplug_dev, DeviceState *dev)
|
|
|
|
{
|
|
|
|
if (dev->hotplugged) {
|
|
|
|
acpi_send_event(DEVICE(hotplug_dev), ACPI_NVDIMM_HOTPLUG_STATUS);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2019-03-08 18:20:52 +00:00
|
|
|
void nvdimm_init_acpi_state(NVDIMMState *state, MemoryRegion *io,
|
2020-04-21 12:59:29 +00:00
|
|
|
struct AcpiGenericAddress dsm_io,
|
2016-03-04 16:00:32 +00:00
|
|
|
FWCfgState *fw_cfg, Object *owner)
|
|
|
|
{
|
2020-04-21 12:59:29 +00:00
|
|
|
state->dsm_io = dsm_io;
|
2016-03-04 16:00:32 +00:00
|
|
|
memory_region_init_io(&state->io_mr, owner, &nvdimm_dsm_ops, state,
|
2020-04-21 12:59:29 +00:00
|
|
|
"nvdimm-acpi-io", dsm_io.bit_width >> 3);
|
|
|
|
memory_region_add_subregion(io, dsm_io.address, &state->io_mr);
|
2016-03-04 16:00:32 +00:00
|
|
|
|
|
|
|
state->dsm_mem = g_array_new(false, true /* clear */, 1);
|
2016-03-31 08:56:54 +00:00
|
|
|
acpi_data_push(state->dsm_mem, sizeof(NvdimmDsmIn));
|
2016-03-04 16:00:32 +00:00
|
|
|
fw_cfg_add_file(fw_cfg, NVDIMM_DSM_MEM_FILE, state->dsm_mem->data,
|
|
|
|
state->dsm_mem->len);
|
2016-10-28 16:35:38 +00:00
|
|
|
|
|
|
|
nvdimm_init_fit_buffer(&state->fit_buf);
|
2016-03-04 16:00:32 +00:00
|
|
|
}
|
|
|
|
|
2016-10-28 16:11:56 +00:00
|
|
|
#define NVDIMM_COMMON_DSM "NCAL"
|
|
|
|
#define NVDIMM_ACPI_MEM_ADDR "MEMA"
|
|
|
|
|
|
|
|
#define NVDIMM_DSM_MEMORY "NRAM"
|
|
|
|
#define NVDIMM_DSM_IOPORT "NPIO"
|
|
|
|
|
|
|
|
#define NVDIMM_DSM_NOTIFY "NTFI"
|
|
|
|
#define NVDIMM_DSM_HANDLE "HDLE"
|
|
|
|
#define NVDIMM_DSM_REVISION "REVS"
|
|
|
|
#define NVDIMM_DSM_FUNCTION "FUNC"
|
|
|
|
#define NVDIMM_DSM_ARG3 "FARG"
|
|
|
|
|
|
|
|
#define NVDIMM_DSM_OUT_BUF_SIZE "RLEN"
|
|
|
|
#define NVDIMM_DSM_OUT_BUF "ODAT"
|
2015-12-02 07:20:59 +00:00
|
|
|
|
2016-10-28 16:35:39 +00:00
|
|
|
#define NVDIMM_DSM_RFIT_STATUS "RSTA"
|
|
|
|
|
|
|
|
#define NVDIMM_QEMU_RSVD_UUID "648B9CF2-CDA1-4312-8AD9-49C4AF32BD62"
|
|
|
|
|
2020-04-21 12:59:29 +00:00
|
|
|
static void nvdimm_build_common_dsm(Aml *dev,
|
|
|
|
NVDIMMState *nvdimm_state)
|
2015-12-02 07:20:59 +00:00
|
|
|
{
|
2016-10-28 16:35:39 +00:00
|
|
|
Aml *method, *ifctx, *function, *handle, *uuid, *dsm_mem, *elsectx2;
|
2016-06-07 12:22:03 +00:00
|
|
|
Aml *elsectx, *unsupport, *unpatched, *expected_uuid, *uuid_invalid;
|
2016-10-28 16:11:55 +00:00
|
|
|
Aml *pckg, *pckg_index, *pckg_buf, *field, *dsm_out_buf, *dsm_out_buf_size;
|
2020-04-21 12:59:28 +00:00
|
|
|
Aml *whilectx, *offset;
|
2015-12-02 07:20:59 +00:00
|
|
|
uint8_t byte_list[1];
|
2020-04-21 12:59:29 +00:00
|
|
|
AmlRegionSpace rs;
|
2015-12-02 07:20:59 +00:00
|
|
|
|
2016-06-07 12:22:01 +00:00
|
|
|
method = aml_method(NVDIMM_COMMON_DSM, 5, AML_SERIALIZED);
|
2016-06-07 12:22:03 +00:00
|
|
|
uuid = aml_arg(0);
|
2015-12-02 07:20:59 +00:00
|
|
|
function = aml_arg(2);
|
2016-06-07 12:22:03 +00:00
|
|
|
handle = aml_arg(4);
|
2016-10-28 16:11:51 +00:00
|
|
|
dsm_mem = aml_local(6);
|
2016-10-28 16:11:53 +00:00
|
|
|
dsm_out_buf = aml_local(7);
|
2016-10-28 16:11:51 +00:00
|
|
|
|
|
|
|
aml_append(method, aml_store(aml_name(NVDIMM_ACPI_MEM_ADDR), dsm_mem));
|
|
|
|
|
2020-04-21 12:59:29 +00:00
|
|
|
if (nvdimm_state->dsm_io.space_id == AML_AS_SYSTEM_IO) {
|
|
|
|
rs = AML_SYSTEM_IO;
|
|
|
|
} else {
|
|
|
|
rs = AML_SYSTEM_MEMORY;
|
|
|
|
}
|
|
|
|
|
2016-10-28 16:11:51 +00:00
|
|
|
/* map DSM memory and IO into ACPI namespace. */
|
2020-04-21 12:59:29 +00:00
|
|
|
aml_append(method, aml_operation_region(NVDIMM_DSM_IOPORT, rs,
|
|
|
|
aml_int(nvdimm_state->dsm_io.address),
|
|
|
|
nvdimm_state->dsm_io.bit_width >> 3));
|
2016-10-28 16:11:56 +00:00
|
|
|
aml_append(method, aml_operation_region(NVDIMM_DSM_MEMORY,
|
|
|
|
AML_SYSTEM_MEMORY, dsm_mem, sizeof(NvdimmDsmIn)));
|
2016-10-28 16:11:51 +00:00
|
|
|
|
|
|
|
/*
|
|
|
|
* DSM notifier:
|
2016-10-28 16:11:56 +00:00
|
|
|
* NVDIMM_DSM_NOTIFY: write the address of DSM memory and notify QEMU to
|
|
|
|
* emulate the access.
|
2016-10-28 16:11:51 +00:00
|
|
|
*
|
|
|
|
* It is the IO port so that accessing them will cause VM-exit, the
|
|
|
|
* control will be transferred to QEMU.
|
|
|
|
*/
|
2016-10-28 16:11:56 +00:00
|
|
|
field = aml_field(NVDIMM_DSM_IOPORT, AML_DWORD_ACC, AML_NOLOCK,
|
|
|
|
AML_PRESERVE);
|
|
|
|
aml_append(field, aml_named_field(NVDIMM_DSM_NOTIFY,
|
2020-04-21 12:59:29 +00:00
|
|
|
nvdimm_state->dsm_io.bit_width));
|
2016-10-28 16:11:51 +00:00
|
|
|
aml_append(method, field);
|
|
|
|
|
|
|
|
/*
|
|
|
|
* DSM input:
|
2016-10-28 16:11:56 +00:00
|
|
|
* NVDIMM_DSM_HANDLE: store device's handle, it's zero if the _DSM call
|
|
|
|
* happens on NVDIMM Root Device.
|
|
|
|
* NVDIMM_DSM_REVISION: store the Arg1 of _DSM call.
|
|
|
|
* NVDIMM_DSM_FUNCTION: store the Arg2 of _DSM call.
|
|
|
|
* NVDIMM_DSM_ARG3: store the Arg3 of _DSM call which is a Package
|
|
|
|
* containing function-specific arguments.
|
2016-10-28 16:11:51 +00:00
|
|
|
*
|
|
|
|
* They are RAM mapping on host so that these accesses never cause
|
|
|
|
* VM-EXIT.
|
|
|
|
*/
|
2016-10-28 16:11:56 +00:00
|
|
|
field = aml_field(NVDIMM_DSM_MEMORY, AML_DWORD_ACC, AML_NOLOCK,
|
|
|
|
AML_PRESERVE);
|
|
|
|
aml_append(field, aml_named_field(NVDIMM_DSM_HANDLE,
|
2016-10-28 16:11:51 +00:00
|
|
|
sizeof(typeof_field(NvdimmDsmIn, handle)) * BITS_PER_BYTE));
|
2016-10-28 16:11:56 +00:00
|
|
|
aml_append(field, aml_named_field(NVDIMM_DSM_REVISION,
|
2016-10-28 16:11:51 +00:00
|
|
|
sizeof(typeof_field(NvdimmDsmIn, revision)) * BITS_PER_BYTE));
|
2016-10-28 16:11:56 +00:00
|
|
|
aml_append(field, aml_named_field(NVDIMM_DSM_FUNCTION,
|
2016-10-28 16:11:51 +00:00
|
|
|
sizeof(typeof_field(NvdimmDsmIn, function)) * BITS_PER_BYTE));
|
2016-10-28 16:11:56 +00:00
|
|
|
aml_append(field, aml_named_field(NVDIMM_DSM_ARG3,
|
2016-10-28 16:11:51 +00:00
|
|
|
(sizeof(NvdimmDsmIn) - offsetof(NvdimmDsmIn, arg3)) * BITS_PER_BYTE));
|
|
|
|
aml_append(method, field);
|
|
|
|
|
|
|
|
/*
|
|
|
|
* DSM output:
|
2016-10-28 16:11:56 +00:00
|
|
|
* NVDIMM_DSM_OUT_BUF_SIZE: the size of the buffer filled by QEMU.
|
|
|
|
* NVDIMM_DSM_OUT_BUF: the buffer QEMU uses to store the result.
|
2016-10-28 16:11:51 +00:00
|
|
|
*
|
|
|
|
* Since the page is reused by both input and out, the input data
|
|
|
|
* will be lost after storing new result into ODAT so we should fetch
|
|
|
|
* all the input data before writing the result.
|
|
|
|
*/
|
2016-10-28 16:11:56 +00:00
|
|
|
field = aml_field(NVDIMM_DSM_MEMORY, AML_DWORD_ACC, AML_NOLOCK,
|
|
|
|
AML_PRESERVE);
|
|
|
|
aml_append(field, aml_named_field(NVDIMM_DSM_OUT_BUF_SIZE,
|
2016-10-28 16:11:51 +00:00
|
|
|
sizeof(typeof_field(NvdimmDsmOut, len)) * BITS_PER_BYTE));
|
2016-10-28 16:11:56 +00:00
|
|
|
aml_append(field, aml_named_field(NVDIMM_DSM_OUT_BUF,
|
2016-10-28 16:11:51 +00:00
|
|
|
(sizeof(NvdimmDsmOut) - offsetof(NvdimmDsmOut, data)) * BITS_PER_BYTE));
|
|
|
|
aml_append(method, field);
|
2016-03-04 16:00:34 +00:00
|
|
|
|
|
|
|
/*
|
|
|
|
* do not support any method if DSM memory address has not been
|
|
|
|
* patched.
|
|
|
|
*/
|
2016-06-07 12:22:03 +00:00
|
|
|
unpatched = aml_equal(dsm_mem, aml_int(0x0));
|
|
|
|
|
|
|
|
expected_uuid = aml_local(0);
|
|
|
|
|
|
|
|
ifctx = aml_if(aml_equal(handle, aml_int(0x0)));
|
|
|
|
aml_append(ifctx, aml_store(
|
|
|
|
aml_touuid("2F10E7A4-9E91-11E4-89D3-123B93F75CBA")
|
|
|
|
/* UUID for NVDIMM Root Device */, expected_uuid));
|
|
|
|
aml_append(method, ifctx);
|
|
|
|
elsectx = aml_else();
|
2016-10-28 16:35:39 +00:00
|
|
|
ifctx = aml_if(aml_equal(handle, aml_int(NVDIMM_QEMU_RSVD_HANDLE_ROOT)));
|
|
|
|
aml_append(ifctx, aml_store(aml_touuid(NVDIMM_QEMU_RSVD_UUID
|
|
|
|
/* UUID for QEMU internal use */), expected_uuid));
|
|
|
|
aml_append(elsectx, ifctx);
|
|
|
|
elsectx2 = aml_else();
|
|
|
|
aml_append(elsectx2, aml_store(
|
2016-06-07 12:22:03 +00:00
|
|
|
aml_touuid("4309AC30-0D11-11E4-9191-0800200C9A66")
|
|
|
|
/* UUID for NVDIMM Devices */, expected_uuid));
|
2016-10-28 16:35:39 +00:00
|
|
|
aml_append(elsectx, elsectx2);
|
2016-06-07 12:22:03 +00:00
|
|
|
aml_append(method, elsectx);
|
|
|
|
|
|
|
|
uuid_invalid = aml_lnot(aml_equal(uuid, expected_uuid));
|
|
|
|
|
|
|
|
unsupport = aml_if(aml_or(unpatched, uuid_invalid, NULL));
|
2015-12-02 07:20:59 +00:00
|
|
|
|
|
|
|
/*
|
|
|
|
* function 0 is called to inquire what functions are supported by
|
|
|
|
* OSPM
|
|
|
|
*/
|
|
|
|
ifctx = aml_if(aml_equal(function, aml_int(0)));
|
|
|
|
byte_list[0] = 0 /* No function Supported */;
|
|
|
|
aml_append(ifctx, aml_return(aml_buffer(1, byte_list)));
|
2016-06-07 12:22:03 +00:00
|
|
|
aml_append(unsupport, ifctx);
|
2015-12-02 07:20:59 +00:00
|
|
|
|
|
|
|
/* No function is supported yet. */
|
2016-11-07 11:13:45 +00:00
|
|
|
byte_list[0] = NVDIMM_DSM_RET_STATUS_UNSUPPORT;
|
2016-06-07 12:22:03 +00:00
|
|
|
aml_append(unsupport, aml_return(aml_buffer(1, byte_list)));
|
|
|
|
aml_append(method, unsupport);
|
2015-12-02 07:20:59 +00:00
|
|
|
|
2016-03-04 16:00:34 +00:00
|
|
|
/*
|
|
|
|
* The HDLE indicates the DSM function is issued from which device,
|
2016-06-07 12:22:01 +00:00
|
|
|
* it reserves 0 for root device and is the handle for NVDIMM devices.
|
|
|
|
* See the comments in nvdimm_slot_to_handle().
|
2016-03-04 16:00:34 +00:00
|
|
|
*/
|
2016-10-28 16:11:56 +00:00
|
|
|
aml_append(method, aml_store(handle, aml_name(NVDIMM_DSM_HANDLE)));
|
|
|
|
aml_append(method, aml_store(aml_arg(1), aml_name(NVDIMM_DSM_REVISION)));
|
2019-02-27 07:50:59 +00:00
|
|
|
aml_append(method, aml_store(function, aml_name(NVDIMM_DSM_FUNCTION)));
|
2016-03-04 16:00:34 +00:00
|
|
|
|
2016-06-07 12:22:02 +00:00
|
|
|
/*
|
|
|
|
* The fourth parameter (Arg3) of _DSM is a package which contains
|
|
|
|
* a buffer, the layout of the buffer is specified by UUID (Arg0),
|
|
|
|
* Revision ID (Arg1) and Function Index (Arg2) which are documented
|
|
|
|
* in the DSM Spec.
|
|
|
|
*/
|
|
|
|
pckg = aml_arg(3);
|
|
|
|
ifctx = aml_if(aml_and(aml_equal(aml_object_type(pckg),
|
|
|
|
aml_int(4 /* Package */)) /* It is a Package? */,
|
|
|
|
aml_equal(aml_sizeof(pckg), aml_int(1)) /* 1 element? */,
|
|
|
|
NULL));
|
|
|
|
|
|
|
|
pckg_index = aml_local(2);
|
|
|
|
pckg_buf = aml_local(3);
|
|
|
|
aml_append(ifctx, aml_store(aml_index(pckg, aml_int(0)), pckg_index));
|
|
|
|
aml_append(ifctx, aml_store(aml_derefof(pckg_index), pckg_buf));
|
2016-10-28 16:11:56 +00:00
|
|
|
aml_append(ifctx, aml_store(pckg_buf, aml_name(NVDIMM_DSM_ARG3)));
|
2016-06-07 12:22:02 +00:00
|
|
|
aml_append(method, ifctx);
|
|
|
|
|
2016-03-04 16:00:34 +00:00
|
|
|
/*
|
|
|
|
* tell QEMU about the real address of DSM memory, then QEMU
|
|
|
|
* gets the control and fills the result in DSM memory.
|
|
|
|
*/
|
2016-10-28 16:11:56 +00:00
|
|
|
aml_append(method, aml_store(dsm_mem, aml_name(NVDIMM_DSM_NOTIFY)));
|
2016-03-04 16:00:34 +00:00
|
|
|
|
2016-10-28 16:11:55 +00:00
|
|
|
dsm_out_buf_size = aml_local(1);
|
2016-10-28 16:11:49 +00:00
|
|
|
/* RLEN is not included in the payload returned to guest. */
|
2016-10-28 16:11:56 +00:00
|
|
|
aml_append(method, aml_subtract(aml_name(NVDIMM_DSM_OUT_BUF_SIZE),
|
|
|
|
aml_int(4), dsm_out_buf_size));
|
2020-04-21 12:59:28 +00:00
|
|
|
|
|
|
|
/*
|
|
|
|
* As per ACPI spec 6.3, Table 19-419 Object Conversion Rules, if
|
|
|
|
* the Buffer Field <= to the size of an Integer (in bits), it will
|
|
|
|
* be treated as an integer. Moreover, the integer size depends on
|
|
|
|
* DSDT tables revision number. If revision number is < 2, integer
|
|
|
|
* size is 32 bits, otherwise it is 64 bits.
|
|
|
|
* Because of this CreateField() canot be used if RLEN < Integer Size.
|
|
|
|
*
|
|
|
|
* Also please note that APCI ASL operator SizeOf() doesn't support
|
|
|
|
* Integer and there isn't any other way to figure out the Integer
|
|
|
|
* size. Hence we assume 8 byte as Integer size and if RLEN < 8 bytes,
|
|
|
|
* build dsm_out_buf byte by byte.
|
|
|
|
*/
|
|
|
|
ifctx = aml_if(aml_lless(dsm_out_buf_size, aml_int(8)));
|
|
|
|
offset = aml_local(2);
|
|
|
|
aml_append(ifctx, aml_store(aml_int(0), offset));
|
|
|
|
aml_append(ifctx, aml_name_decl("TBUF", aml_buffer(1, NULL)));
|
|
|
|
aml_append(ifctx, aml_store(aml_buffer(0, NULL), dsm_out_buf));
|
|
|
|
|
|
|
|
whilectx = aml_while(aml_lless(offset, dsm_out_buf_size));
|
|
|
|
/* Copy 1 byte at offset from ODAT to temporary buffer(TBUF). */
|
|
|
|
aml_append(whilectx, aml_store(aml_derefof(aml_index(
|
|
|
|
aml_name(NVDIMM_DSM_OUT_BUF), offset)),
|
|
|
|
aml_index(aml_name("TBUF"), aml_int(0))));
|
|
|
|
aml_append(whilectx, aml_concatenate(dsm_out_buf, aml_name("TBUF"),
|
|
|
|
dsm_out_buf));
|
|
|
|
aml_append(whilectx, aml_increment(offset));
|
|
|
|
aml_append(ifctx, whilectx);
|
|
|
|
|
|
|
|
aml_append(ifctx, aml_return(dsm_out_buf));
|
|
|
|
aml_append(method, ifctx);
|
|
|
|
|
|
|
|
/* If RLEN >= Integer size, just use CreateField() operator */
|
2016-10-28 16:11:55 +00:00
|
|
|
aml_append(method, aml_store(aml_shiftleft(dsm_out_buf_size, aml_int(3)),
|
|
|
|
dsm_out_buf_size));
|
2016-10-28 16:11:56 +00:00
|
|
|
aml_append(method, aml_create_field(aml_name(NVDIMM_DSM_OUT_BUF),
|
|
|
|
aml_int(0), dsm_out_buf_size, "OBUF"));
|
2020-04-21 12:59:28 +00:00
|
|
|
aml_append(method, aml_return(aml_name("OBUF")));
|
|
|
|
|
2015-12-02 07:20:59 +00:00
|
|
|
aml_append(dev, method);
|
|
|
|
}
|
|
|
|
|
2016-06-07 12:22:01 +00:00
|
|
|
static void nvdimm_build_device_dsm(Aml *dev, uint32_t handle)
|
2015-12-02 07:20:59 +00:00
|
|
|
{
|
|
|
|
Aml *method;
|
|
|
|
|
|
|
|
method = aml_method("_DSM", 4, AML_NOTSERIALIZED);
|
2016-06-07 12:22:01 +00:00
|
|
|
aml_append(method, aml_return(aml_call5(NVDIMM_COMMON_DSM, aml_arg(0),
|
|
|
|
aml_arg(1), aml_arg(2), aml_arg(3),
|
|
|
|
aml_int(handle))));
|
2015-12-02 07:20:59 +00:00
|
|
|
aml_append(dev, method);
|
|
|
|
}
|
|
|
|
|
2016-10-28 16:35:39 +00:00
|
|
|
static void nvdimm_build_fit(Aml *dev)
|
|
|
|
{
|
|
|
|
Aml *method, *pkg, *buf, *buf_size, *offset, *call_result;
|
|
|
|
Aml *whilectx, *ifcond, *ifctx, *elsectx, *fit;
|
|
|
|
|
|
|
|
buf = aml_local(0);
|
|
|
|
buf_size = aml_local(1);
|
|
|
|
fit = aml_local(2);
|
|
|
|
|
2016-11-07 11:13:48 +00:00
|
|
|
aml_append(dev, aml_name_decl(NVDIMM_DSM_RFIT_STATUS, aml_int(0)));
|
2016-10-28 16:35:39 +00:00
|
|
|
|
|
|
|
/* build helper function, RFIT. */
|
|
|
|
method = aml_method("RFIT", 1, AML_SERIALIZED);
|
2016-11-07 11:13:48 +00:00
|
|
|
aml_append(method, aml_name_decl("OFST", aml_int(0)));
|
2016-10-28 16:35:39 +00:00
|
|
|
|
|
|
|
/* prepare input package. */
|
|
|
|
pkg = aml_package(1);
|
|
|
|
aml_append(method, aml_store(aml_arg(0), aml_name("OFST")));
|
|
|
|
aml_append(pkg, aml_name("OFST"));
|
|
|
|
|
|
|
|
/* call Read_FIT function. */
|
|
|
|
call_result = aml_call5(NVDIMM_COMMON_DSM,
|
|
|
|
aml_touuid(NVDIMM_QEMU_RSVD_UUID),
|
|
|
|
aml_int(1) /* Revision 1 */,
|
|
|
|
aml_int(0x1) /* Read FIT */,
|
|
|
|
pkg, aml_int(NVDIMM_QEMU_RSVD_HANDLE_ROOT));
|
|
|
|
aml_append(method, aml_store(call_result, buf));
|
|
|
|
|
|
|
|
/* handle _DSM result. */
|
|
|
|
aml_append(method, aml_create_dword_field(buf,
|
|
|
|
aml_int(0) /* offset at byte 0 */, "STAU"));
|
|
|
|
|
|
|
|
aml_append(method, aml_store(aml_name("STAU"),
|
|
|
|
aml_name(NVDIMM_DSM_RFIT_STATUS)));
|
|
|
|
|
|
|
|
/* if something is wrong during _DSM. */
|
2016-11-07 11:13:45 +00:00
|
|
|
ifcond = aml_equal(aml_int(NVDIMM_DSM_RET_STATUS_SUCCESS),
|
|
|
|
aml_name("STAU"));
|
2016-10-28 16:35:39 +00:00
|
|
|
ifctx = aml_if(aml_lnot(ifcond));
|
|
|
|
aml_append(ifctx, aml_return(aml_buffer(0, NULL)));
|
|
|
|
aml_append(method, ifctx);
|
|
|
|
|
|
|
|
aml_append(method, aml_store(aml_sizeof(buf), buf_size));
|
|
|
|
aml_append(method, aml_subtract(buf_size,
|
|
|
|
aml_int(4) /* the size of "STAU" */,
|
|
|
|
buf_size));
|
|
|
|
|
|
|
|
/* if we read the end of fit. */
|
|
|
|
ifctx = aml_if(aml_equal(buf_size, aml_int(0)));
|
|
|
|
aml_append(ifctx, aml_return(aml_buffer(0, NULL)));
|
|
|
|
aml_append(method, ifctx);
|
|
|
|
|
|
|
|
aml_append(method, aml_create_field(buf,
|
|
|
|
aml_int(4 * BITS_PER_BYTE), /* offset at byte 4.*/
|
2016-11-07 11:13:43 +00:00
|
|
|
aml_shiftleft(buf_size, aml_int(3)), "BUFF"));
|
2016-10-28 16:35:39 +00:00
|
|
|
aml_append(method, aml_return(aml_name("BUFF")));
|
|
|
|
aml_append(dev, method);
|
|
|
|
|
|
|
|
/* build _FIT. */
|
|
|
|
method = aml_method("_FIT", 0, AML_SERIALIZED);
|
|
|
|
offset = aml_local(3);
|
|
|
|
|
|
|
|
aml_append(method, aml_store(aml_buffer(0, NULL), fit));
|
|
|
|
aml_append(method, aml_store(aml_int(0), offset));
|
|
|
|
|
|
|
|
whilectx = aml_while(aml_int(1));
|
|
|
|
aml_append(whilectx, aml_store(aml_call1("RFIT", offset), buf));
|
|
|
|
aml_append(whilectx, aml_store(aml_sizeof(buf), buf_size));
|
|
|
|
|
|
|
|
/*
|
|
|
|
* if fit buffer was changed during RFIT, read from the beginning
|
|
|
|
* again.
|
|
|
|
*/
|
|
|
|
ifctx = aml_if(aml_equal(aml_name(NVDIMM_DSM_RFIT_STATUS),
|
2016-11-07 11:13:45 +00:00
|
|
|
aml_int(NVDIMM_DSM_RET_STATUS_FIT_CHANGED)));
|
2016-10-28 16:35:39 +00:00
|
|
|
aml_append(ifctx, aml_store(aml_buffer(0, NULL), fit));
|
|
|
|
aml_append(ifctx, aml_store(aml_int(0), offset));
|
|
|
|
aml_append(whilectx, ifctx);
|
|
|
|
|
|
|
|
elsectx = aml_else();
|
|
|
|
|
|
|
|
/* finish fit read if no data is read out. */
|
|
|
|
ifctx = aml_if(aml_equal(buf_size, aml_int(0)));
|
|
|
|
aml_append(ifctx, aml_return(fit));
|
|
|
|
aml_append(elsectx, ifctx);
|
|
|
|
|
|
|
|
/* update the offset. */
|
|
|
|
aml_append(elsectx, aml_add(offset, buf_size, offset));
|
|
|
|
/* append the data we read out to the fit buffer. */
|
|
|
|
aml_append(elsectx, aml_concatenate(fit, buf, fit));
|
|
|
|
aml_append(whilectx, elsectx);
|
|
|
|
aml_append(method, whilectx);
|
|
|
|
|
|
|
|
aml_append(dev, method);
|
|
|
|
}
|
|
|
|
|
2016-10-28 16:35:37 +00:00
|
|
|
static void nvdimm_build_nvdimm_devices(Aml *root_dev, uint32_t ram_slots)
|
2015-12-02 07:20:59 +00:00
|
|
|
{
|
2016-10-28 16:35:37 +00:00
|
|
|
uint32_t slot;
|
|
|
|
|
|
|
|
for (slot = 0; slot < ram_slots; slot++) {
|
2015-12-02 07:20:59 +00:00
|
|
|
uint32_t handle = nvdimm_slot_to_handle(slot);
|
|
|
|
Aml *nvdimm_dev;
|
|
|
|
|
|
|
|
nvdimm_dev = aml_device("NV%02X", slot);
|
|
|
|
|
|
|
|
/*
|
|
|
|
* ACPI 6.0: 9.20 NVDIMM Devices:
|
|
|
|
*
|
|
|
|
* _ADR object that is used to supply OSPM with unique address
|
|
|
|
* of the NVDIMM device. This is done by returning the NFIT Device
|
|
|
|
* handle that is used to identify the associated entries in ACPI
|
|
|
|
* table NFIT or _FIT.
|
|
|
|
*/
|
|
|
|
aml_append(nvdimm_dev, aml_name_decl("_ADR", aml_int(handle)));
|
|
|
|
|
2016-06-07 12:22:01 +00:00
|
|
|
nvdimm_build_device_dsm(nvdimm_dev, handle);
|
2015-12-02 07:20:59 +00:00
|
|
|
aml_append(root_dev, nvdimm_dev);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2016-10-28 16:35:37 +00:00
|
|
|
static void nvdimm_build_ssdt(GArray *table_offsets, GArray *table_data,
|
2020-04-21 12:59:29 +00:00
|
|
|
BIOSLinker *linker,
|
|
|
|
NVDIMMState *nvdimm_state,
|
2021-01-19 00:32:13 +00:00
|
|
|
uint32_t ram_slots, const char *oem_id)
|
2015-12-02 07:20:59 +00:00
|
|
|
{
|
2016-10-28 16:11:51 +00:00
|
|
|
Aml *ssdt, *sb_scope, *dev;
|
2016-03-04 16:00:33 +00:00
|
|
|
int mem_addr_offset, nvdimm_ssdt;
|
2015-12-02 07:20:59 +00:00
|
|
|
|
|
|
|
acpi_add_table(table_offsets, table_data);
|
|
|
|
|
|
|
|
ssdt = init_aml_allocator();
|
|
|
|
acpi_data_push(ssdt->buf, sizeof(AcpiTableHeader));
|
|
|
|
|
|
|
|
sb_scope = aml_scope("\\_SB");
|
|
|
|
|
|
|
|
dev = aml_device("NVDR");
|
|
|
|
|
|
|
|
/*
|
|
|
|
* ACPI 6.0: 9.20 NVDIMM Devices:
|
|
|
|
*
|
|
|
|
* The ACPI Name Space device uses _HID of ACPI0012 to identify the root
|
|
|
|
* NVDIMM interface device. Platform firmware is required to contain one
|
|
|
|
* such device in _SB scope if NVDIMMs support is exposed by platform to
|
|
|
|
* OSPM.
|
|
|
|
* For each NVDIMM present or intended to be supported by platform,
|
|
|
|
* platform firmware also exposes an ACPI Namespace Device under the
|
|
|
|
* root device.
|
|
|
|
*/
|
|
|
|
aml_append(dev, aml_name_decl("_HID", aml_string("ACPI0012")));
|
|
|
|
|
2020-04-21 12:59:29 +00:00
|
|
|
nvdimm_build_common_dsm(dev, nvdimm_state);
|
2016-06-07 12:22:01 +00:00
|
|
|
|
|
|
|
/* 0 is reserved for root device. */
|
|
|
|
nvdimm_build_device_dsm(dev, 0);
|
2016-10-28 16:35:39 +00:00
|
|
|
nvdimm_build_fit(dev);
|
2015-12-02 07:20:59 +00:00
|
|
|
|
2016-10-28 16:35:37 +00:00
|
|
|
nvdimm_build_nvdimm_devices(dev, ram_slots);
|
2015-12-02 07:20:59 +00:00
|
|
|
|
|
|
|
aml_append(sb_scope, dev);
|
|
|
|
aml_append(ssdt, sb_scope);
|
2016-03-04 16:00:33 +00:00
|
|
|
|
|
|
|
nvdimm_ssdt = table_data->len;
|
|
|
|
|
2015-12-02 07:20:59 +00:00
|
|
|
/* copy AML table into ACPI tables blob and patch header there */
|
|
|
|
g_array_append_vals(table_data, ssdt->buf->data, ssdt->buf->len);
|
2016-03-04 16:00:33 +00:00
|
|
|
mem_addr_offset = build_append_named_dword(table_data,
|
|
|
|
NVDIMM_ACPI_MEM_ADDR);
|
|
|
|
|
2016-05-19 13:19:26 +00:00
|
|
|
bios_linker_loader_alloc(linker,
|
2020-04-21 12:59:29 +00:00
|
|
|
NVDIMM_DSM_MEM_FILE, nvdimm_state->dsm_mem,
|
2016-05-19 13:19:26 +00:00
|
|
|
sizeof(NvdimmDsmIn), false /* high memory */);
|
2016-05-19 13:19:29 +00:00
|
|
|
bios_linker_loader_add_pointer(linker,
|
|
|
|
ACPI_BUILD_TABLE_FILE, mem_addr_offset, sizeof(uint32_t),
|
|
|
|
NVDIMM_DSM_MEM_FILE, 0);
|
2015-12-02 07:20:59 +00:00
|
|
|
build_header(linker, table_data,
|
2016-03-04 16:00:33 +00:00
|
|
|
(void *)(table_data->data + nvdimm_ssdt),
|
2021-01-19 00:32:13 +00:00
|
|
|
"SSDT", table_data->len - nvdimm_ssdt, 1, oem_id, "NVDIMM");
|
2015-12-02 07:20:59 +00:00
|
|
|
free_aml_allocator();
|
|
|
|
}
|
|
|
|
|
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 00:09:10 +00:00
|
|
|
void nvdimm_build_srat(GArray *table_data)
|
|
|
|
{
|
|
|
|
GSList *device_list = nvdimm_get_device_list();
|
|
|
|
|
|
|
|
for (; device_list; device_list = device_list->next) {
|
|
|
|
AcpiSratMemoryAffinity *numamem = NULL;
|
|
|
|
DeviceState *dev = device_list->data;
|
|
|
|
Object *obj = OBJECT(dev);
|
|
|
|
uint64_t addr, size;
|
|
|
|
int node;
|
|
|
|
|
|
|
|
node = object_property_get_int(obj, PC_DIMM_NODE_PROP, &error_abort);
|
|
|
|
addr = object_property_get_uint(obj, PC_DIMM_ADDR_PROP, &error_abort);
|
|
|
|
size = object_property_get_uint(obj, PC_DIMM_SIZE_PROP, &error_abort);
|
|
|
|
|
|
|
|
numamem = acpi_data_push(table_data, sizeof *numamem);
|
|
|
|
build_srat_memory(numamem, addr, size, node,
|
|
|
|
MEM_AFFINITY_ENABLED | MEM_AFFINITY_NON_VOLATILE);
|
|
|
|
}
|
|
|
|
g_slist_free(device_list);
|
|
|
|
}
|
|
|
|
|
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 07:20:58 +00:00
|
|
|
void nvdimm_build_acpi(GArray *table_offsets, GArray *table_data,
|
2019-03-08 18:20:52 +00:00
|
|
|
BIOSLinker *linker, NVDIMMState *state,
|
2021-01-19 00:32:13 +00:00
|
|
|
uint32_t ram_slots, const char *oem_id,
|
|
|
|
const char *oem_table_id)
|
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 07:20:58 +00:00
|
|
|
{
|
2016-11-07 11:13:40 +00:00
|
|
|
GSList *device_list;
|
2016-10-28 16:35:37 +00:00
|
|
|
|
2016-11-07 11:13:40 +00:00
|
|
|
/* no nvdimm device can be plugged. */
|
|
|
|
if (!ram_slots) {
|
|
|
|
return;
|
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 07:20:58 +00:00
|
|
|
}
|
2016-11-07 11:13:40 +00:00
|
|
|
|
2020-04-21 12:59:29 +00:00
|
|
|
nvdimm_build_ssdt(table_offsets, table_data, linker, state,
|
2021-01-19 00:32:13 +00:00
|
|
|
ram_slots, oem_id);
|
2016-11-07 11:13:40 +00:00
|
|
|
|
2016-11-07 11:13:42 +00:00
|
|
|
device_list = nvdimm_get_device_list();
|
2016-11-07 11:13:40 +00:00
|
|
|
/* no NVDIMM device is plugged. */
|
|
|
|
if (!device_list) {
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2021-01-19 00:32:13 +00:00
|
|
|
nvdimm_build_nfit(state, table_offsets, table_data, linker,
|
|
|
|
oem_id, oem_table_id);
|
2016-11-07 11:13:40 +00:00
|
|
|
g_slist_free(device_list);
|
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 07:20:58 +00:00
|
|
|
}
|