qemu/include/hw/mem/nvdimm.h
<<
>>
Prefs
   1/*
   2 * Non-Volatile Dual In-line Memory Module Virtualization Implementation
   3 *
   4 * Copyright(C) 2015 Intel Corporation.
   5 *
   6 * Author:
   7 *  Xiao Guangrong <guangrong.xiao@linux.intel.com>
   8 *
   9 * NVDIMM specifications and some documents can be found at:
  10 * NVDIMM ACPI device and NFIT are introduced in ACPI 6:
  11 *      http://www.uefi.org/sites/default/files/resources/ACPI_6.0.pdf
  12 * NVDIMM Namespace specification:
  13 *      http://pmem.io/documents/NVDIMM_Namespace_Spec.pdf
  14 * DSM Interface Example:
  15 *      http://pmem.io/documents/NVDIMM_DSM_Interface_Example.pdf
  16 * Driver Writer's Guide:
  17 *      http://pmem.io/documents/NVDIMM_Driver_Writers_Guide.pdf
  18 *
  19 * This work is licensed under the terms of the GNU GPL, version 2 or later.
  20 * See the COPYING file in the top-level directory.
  21 */
  22
  23#ifndef QEMU_NVDIMM_H
  24#define QEMU_NVDIMM_H
  25
  26#include "hw/mem/pc-dimm.h"
  27#include "hw/acpi/bios-linker-loader.h"
  28
  29#define NVDIMM_DEBUG 0
  30#define nvdimm_debug(fmt, ...)                                \
  31    do {                                                      \
  32        if (NVDIMM_DEBUG) {                                   \
  33            fprintf(stderr, "nvdimm: " fmt, ## __VA_ARGS__);  \
  34        }                                                     \
  35    } while (0)
  36
  37/*
  38 * The minimum label data size is required by NVDIMM Namespace
  39 * specification, see the chapter 2 Namespaces:
  40 *   "NVDIMMs following the NVDIMM Block Mode Specification use an area
  41 *    at least 128KB in size, which holds around 1000 labels."
  42 */
  43#define MIN_NAMESPACE_LABEL_SIZE      (128UL << 10)
  44
  45#define TYPE_NVDIMM      "nvdimm"
  46#define NVDIMM(obj)      OBJECT_CHECK(NVDIMMDevice, (obj), TYPE_NVDIMM)
  47#define NVDIMM_CLASS(oc) OBJECT_CLASS_CHECK(NVDIMMClass, (oc), TYPE_NVDIMM)
  48#define NVDIMM_GET_CLASS(obj) OBJECT_GET_CLASS(NVDIMMClass, (obj), \
  49                                               TYPE_NVDIMM)
  50struct NVDIMMDevice {
  51    /* private */
  52    PCDIMMDevice parent_obj;
  53
  54    /* public */
  55
  56    /*
  57     * the size of label data in NVDIMM device which is presented to
  58     * guest via __DSM "Get Namespace Label Size" function.
  59     */
  60    uint64_t label_size;
  61
  62    /*
  63     * the address of label data which is read by __DSM "Get Namespace
  64     * Label Data" function and written by __DSM "Set Namespace Label
  65     * Data" function.
  66     */
  67    void *label_data;
  68
  69    /*
  70     * it's the PMEM region in NVDIMM device, which is presented to
  71     * guest via ACPI NFIT and _FIT method if NVDIMM hotplug is supported.
  72     */
  73    MemoryRegion nvdimm_mr;
  74};
  75typedef struct NVDIMMDevice NVDIMMDevice;
  76
  77struct NVDIMMClass {
  78    /* private */
  79    PCDIMMDeviceClass parent_class;
  80
  81    /* public */
  82
  83    /* read @size bytes from NVDIMM label data at @offset into @buf. */
  84    void (*read_label_data)(NVDIMMDevice *nvdimm, void *buf,
  85                            uint64_t size, uint64_t offset);
  86    /* write @size bytes from @buf to NVDIMM label data at @offset. */
  87    void (*write_label_data)(NVDIMMDevice *nvdimm, const void *buf,
  88                             uint64_t size, uint64_t offset);
  89};
  90typedef struct NVDIMMClass NVDIMMClass;
  91
  92#define NVDIMM_DSM_MEM_FILE     "etc/acpi/nvdimm-mem"
  93
  94/*
  95 * 32 bits IO port starting from 0x0a18 in guest is reserved for
  96 * NVDIMM ACPI emulation.
  97 */
  98#define NVDIMM_ACPI_IO_BASE     0x0a18
  99#define NVDIMM_ACPI_IO_LEN      4
 100
 101/*
 102 * NvdimmFitBuffer:
 103 * @fit: FIT structures for present NVDIMMs. It is updated when
 104 *   the NVDIMM device is plugged or unplugged.
 105 * @dirty: It allows OSPM to detect change and restart read in
 106 *   progress if there is any.
 107 */
 108struct NvdimmFitBuffer {
 109    GArray *fit;
 110    bool dirty;
 111};
 112typedef struct NvdimmFitBuffer NvdimmFitBuffer;
 113
 114struct AcpiNVDIMMState {
 115    /* detect if NVDIMM support is enabled. */
 116    bool is_enabled;
 117
 118    /* the data of the fw_cfg file NVDIMM_DSM_MEM_FILE. */
 119    GArray *dsm_mem;
 120
 121    NvdimmFitBuffer fit_buf;
 122
 123    /* the IO region used by OSPM to transfer control to QEMU. */
 124    MemoryRegion io_mr;
 125};
 126typedef struct AcpiNVDIMMState AcpiNVDIMMState;
 127
 128void nvdimm_init_acpi_state(AcpiNVDIMMState *state, MemoryRegion *io,
 129                            FWCfgState *fw_cfg, Object *owner);
 130void nvdimm_build_acpi(GArray *table_offsets, GArray *table_data,
 131                       BIOSLinker *linker, AcpiNVDIMMState *state,
 132                       uint32_t ram_slots);
 133void nvdimm_plug(AcpiNVDIMMState *state);
 134void nvdimm_acpi_plug_cb(HotplugHandler *hotplug_dev, DeviceState *dev);
 135#endif
 136