16bc75619SDan Williams /* 26bc75619SDan Williams * Copyright(c) 2013-2015 Intel Corporation. All rights reserved. 36bc75619SDan Williams * 46bc75619SDan Williams * This program is free software; you can redistribute it and/or modify 56bc75619SDan Williams * it under the terms of version 2 of the GNU General Public License as 66bc75619SDan Williams * published by the Free Software Foundation. 76bc75619SDan Williams * 86bc75619SDan Williams * This program is distributed in the hope that it will be useful, but 96bc75619SDan Williams * WITHOUT ANY WARRANTY; without even the implied warranty of 106bc75619SDan Williams * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 116bc75619SDan Williams * General Public License for more details. 126bc75619SDan Williams */ 136bc75619SDan Williams #define pr_fmt(fmt) KBUILD_MODNAME ": " fmt 146bc75619SDan Williams #include <linux/platform_device.h> 156bc75619SDan Williams #include <linux/dma-mapping.h> 16d8d378faSDan Williams #include <linux/workqueue.h> 176bc75619SDan Williams #include <linux/libnvdimm.h> 186bc75619SDan Williams #include <linux/vmalloc.h> 196bc75619SDan Williams #include <linux/device.h> 206bc75619SDan Williams #include <linux/module.h> 2120985164SVishal Verma #include <linux/mutex.h> 226bc75619SDan Williams #include <linux/ndctl.h> 236bc75619SDan Williams #include <linux/sizes.h> 2420985164SVishal Verma #include <linux/list.h> 256bc75619SDan Williams #include <linux/slab.h> 26a7de92daSDan Williams #include <nd-core.h> 276bc75619SDan Williams #include <nfit.h> 286bc75619SDan Williams #include <nd.h> 296bc75619SDan Williams #include "nfit_test.h" 30*0fb5c8dfSDan Williams #include "../watermark.h" 316bc75619SDan Williams 326bc75619SDan Williams /* 336bc75619SDan Williams * Generate an NFIT table to describe the following topology: 346bc75619SDan Williams * 356bc75619SDan Williams * BUS0: Interleaved PMEM regions, and aliasing with BLK regions 366bc75619SDan Williams * 376bc75619SDan Williams * (a) (b) DIMM BLK-REGION 386bc75619SDan Williams * +----------+--------------+----------+---------+ 396bc75619SDan Williams * +------+ | blk2.0 | pm0.0 | blk2.1 | pm1.0 | 0 region2 406bc75619SDan Williams * | imc0 +--+- - - - - region0 - - - -+----------+ + 416bc75619SDan Williams * +--+---+ | blk3.0 | pm0.0 | blk3.1 | pm1.0 | 1 region3 426bc75619SDan Williams * | +----------+--------------v----------v v 436bc75619SDan Williams * +--+---+ | | 446bc75619SDan Williams * | cpu0 | region1 456bc75619SDan Williams * +--+---+ | | 466bc75619SDan Williams * | +-------------------------^----------^ ^ 476bc75619SDan Williams * +--+---+ | blk4.0 | pm1.0 | 2 region4 486bc75619SDan Williams * | imc1 +--+-------------------------+----------+ + 496bc75619SDan Williams * +------+ | blk5.0 | pm1.0 | 3 region5 506bc75619SDan Williams * +-------------------------+----------+-+-------+ 516bc75619SDan Williams * 5220985164SVishal Verma * +--+---+ 5320985164SVishal Verma * | cpu1 | 5420985164SVishal Verma * +--+---+ (Hotplug DIMM) 5520985164SVishal Verma * | +----------------------------------------------+ 5620985164SVishal Verma * +--+---+ | blk6.0/pm7.0 | 4 region6/7 5720985164SVishal Verma * | imc0 +--+----------------------------------------------+ 5820985164SVishal Verma * +------+ 5920985164SVishal Verma * 6020985164SVishal Verma * 616bc75619SDan Williams * *) In this layout we have four dimms and two memory controllers in one 626bc75619SDan Williams * socket. Each unique interface (BLK or PMEM) to DPA space 636bc75619SDan Williams * is identified by a region device with a dynamically assigned id. 646bc75619SDan Williams * 656bc75619SDan Williams * *) The first portion of dimm0 and dimm1 are interleaved as REGION0. 666bc75619SDan Williams * A single PMEM namespace "pm0.0" is created using half of the 676bc75619SDan Williams * REGION0 SPA-range. REGION0 spans dimm0 and dimm1. PMEM namespace 686bc75619SDan Williams * allocate from from the bottom of a region. The unallocated 696bc75619SDan Williams * portion of REGION0 aliases with REGION2 and REGION3. That 706bc75619SDan Williams * unallacted capacity is reclaimed as BLK namespaces ("blk2.0" and 716bc75619SDan Williams * "blk3.0") starting at the base of each DIMM to offset (a) in those 726bc75619SDan Williams * DIMMs. "pm0.0", "blk2.0" and "blk3.0" are free-form readable 736bc75619SDan Williams * names that can be assigned to a namespace. 746bc75619SDan Williams * 756bc75619SDan Williams * *) In the last portion of dimm0 and dimm1 we have an interleaved 766bc75619SDan Williams * SPA range, REGION1, that spans those two dimms as well as dimm2 776bc75619SDan Williams * and dimm3. Some of REGION1 allocated to a PMEM namespace named 786bc75619SDan Williams * "pm1.0" the rest is reclaimed in 4 BLK namespaces (for each 796bc75619SDan Williams * dimm in the interleave set), "blk2.1", "blk3.1", "blk4.0", and 806bc75619SDan Williams * "blk5.0". 816bc75619SDan Williams * 826bc75619SDan Williams * *) The portion of dimm2 and dimm3 that do not participate in the 836bc75619SDan Williams * REGION1 interleaved SPA range (i.e. the DPA address below offset 846bc75619SDan Williams * (b) are also included in the "blk4.0" and "blk5.0" namespaces. 856bc75619SDan Williams * Note, that BLK namespaces need not be contiguous in DPA-space, and 866bc75619SDan Williams * can consume aliased capacity from multiple interleave sets. 876bc75619SDan Williams * 886bc75619SDan Williams * BUS1: Legacy NVDIMM (single contiguous range) 896bc75619SDan Williams * 906bc75619SDan Williams * region2 916bc75619SDan Williams * +---------------------+ 926bc75619SDan Williams * |---------------------| 936bc75619SDan Williams * || pm2.0 || 946bc75619SDan Williams * |---------------------| 956bc75619SDan Williams * +---------------------+ 966bc75619SDan Williams * 976bc75619SDan Williams * *) A NFIT-table may describe a simple system-physical-address range 986bc75619SDan Williams * with no BLK aliasing. This type of region may optionally 996bc75619SDan Williams * reference an NVDIMM. 1006bc75619SDan Williams */ 1016bc75619SDan Williams enum { 10220985164SVishal Verma NUM_PM = 3, 10320985164SVishal Verma NUM_DCR = 5, 10485d3fa02SDan Williams NUM_HINTS = 8, 1056bc75619SDan Williams NUM_BDW = NUM_DCR, 1066bc75619SDan Williams NUM_SPA = NUM_PM + NUM_DCR + NUM_BDW, 1076bc75619SDan Williams NUM_MEM = NUM_DCR + NUM_BDW + 2 /* spa0 iset */ + 4 /* spa1 iset */, 1086bc75619SDan Williams DIMM_SIZE = SZ_32M, 1096bc75619SDan Williams LABEL_SIZE = SZ_128K, 1107bfe97c7SDan Williams SPA_VCD_SIZE = SZ_4M, 1116bc75619SDan Williams SPA0_SIZE = DIMM_SIZE, 1126bc75619SDan Williams SPA1_SIZE = DIMM_SIZE*2, 1136bc75619SDan Williams SPA2_SIZE = DIMM_SIZE, 1146bc75619SDan Williams BDW_SIZE = 64 << 8, 1156bc75619SDan Williams DCR_SIZE = 12, 1166bc75619SDan Williams NUM_NFITS = 2, /* permit testing multiple NFITs per system */ 1176bc75619SDan Williams }; 1186bc75619SDan Williams 1196bc75619SDan Williams struct nfit_test_dcr { 1206bc75619SDan Williams __le64 bdw_addr; 1216bc75619SDan Williams __le32 bdw_status; 1226bc75619SDan Williams __u8 aperature[BDW_SIZE]; 1236bc75619SDan Williams }; 1246bc75619SDan Williams 1256bc75619SDan Williams #define NFIT_DIMM_HANDLE(node, socket, imc, chan, dimm) \ 1266bc75619SDan Williams (((node & 0xfff) << 16) | ((socket & 0xf) << 12) \ 1276bc75619SDan Williams | ((imc & 0xf) << 8) | ((chan & 0xf) << 4) | (dimm & 0xf)) 1286bc75619SDan Williams 129dafb1048SDan Williams static u32 handle[] = { 1306bc75619SDan Williams [0] = NFIT_DIMM_HANDLE(0, 0, 0, 0, 0), 1316bc75619SDan Williams [1] = NFIT_DIMM_HANDLE(0, 0, 0, 0, 1), 1326bc75619SDan Williams [2] = NFIT_DIMM_HANDLE(0, 0, 1, 0, 0), 1336bc75619SDan Williams [3] = NFIT_DIMM_HANDLE(0, 0, 1, 0, 1), 13420985164SVishal Verma [4] = NFIT_DIMM_HANDLE(0, 1, 0, 0, 0), 135dafb1048SDan Williams [5] = NFIT_DIMM_HANDLE(1, 0, 0, 0, 0), 136ac40b675SDan Williams [6] = NFIT_DIMM_HANDLE(1, 0, 0, 0, 1), 1376bc75619SDan Williams }; 1386bc75619SDan Williams 13973606afdSDan Williams static unsigned long dimm_fail_cmd_flags[NUM_DCR]; 14073606afdSDan Williams 141bfbaa952SDave Jiang struct nfit_test_fw { 142bfbaa952SDave Jiang enum intel_fw_update_state state; 143bfbaa952SDave Jiang u32 context; 144bfbaa952SDave Jiang u64 version; 145bfbaa952SDave Jiang u32 size_received; 146bfbaa952SDave Jiang u64 end_time; 147bfbaa952SDave Jiang }; 148bfbaa952SDave Jiang 1496bc75619SDan Williams struct nfit_test { 1506bc75619SDan Williams struct acpi_nfit_desc acpi_desc; 1516bc75619SDan Williams struct platform_device pdev; 1526bc75619SDan Williams struct list_head resources; 1536bc75619SDan Williams void *nfit_buf; 1546bc75619SDan Williams dma_addr_t nfit_dma; 1556bc75619SDan Williams size_t nfit_size; 156dafb1048SDan Williams int dcr_idx; 1576bc75619SDan Williams int num_dcr; 1586bc75619SDan Williams int num_pm; 1596bc75619SDan Williams void **dimm; 1606bc75619SDan Williams dma_addr_t *dimm_dma; 1619d27a87eSDan Williams void **flush; 1629d27a87eSDan Williams dma_addr_t *flush_dma; 1636bc75619SDan Williams void **label; 1646bc75619SDan Williams dma_addr_t *label_dma; 1656bc75619SDan Williams void **spa_set; 1666bc75619SDan Williams dma_addr_t *spa_set_dma; 1676bc75619SDan Williams struct nfit_test_dcr **dcr; 1686bc75619SDan Williams dma_addr_t *dcr_dma; 1696bc75619SDan Williams int (*alloc)(struct nfit_test *t); 1706bc75619SDan Williams void (*setup)(struct nfit_test *t); 17120985164SVishal Verma int setup_hotplug; 172c14a868aSDan Williams union acpi_object **_fit; 173c14a868aSDan Williams dma_addr_t _fit_dma; 174f471f1a7SDan Williams struct ars_state { 175f471f1a7SDan Williams struct nd_cmd_ars_status *ars_status; 176f471f1a7SDan Williams unsigned long deadline; 177f471f1a7SDan Williams spinlock_t lock; 178f471f1a7SDan Williams } ars_state; 179231bf117SDan Williams struct device *dimm_dev[NUM_DCR]; 180ed07c433SDan Williams struct nd_intel_smart *smart; 181ed07c433SDan Williams struct nd_intel_smart_threshold *smart_threshold; 1829fb1a190SDave Jiang struct badrange badrange; 1839fb1a190SDave Jiang struct work_struct work; 184bfbaa952SDave Jiang struct nfit_test_fw *fw; 1856bc75619SDan Williams }; 1866bc75619SDan Williams 1879fb1a190SDave Jiang static struct workqueue_struct *nfit_wq; 1889fb1a190SDave Jiang 1896bc75619SDan Williams static struct nfit_test *to_nfit_test(struct device *dev) 1906bc75619SDan Williams { 1916bc75619SDan Williams struct platform_device *pdev = to_platform_device(dev); 1926bc75619SDan Williams 1936bc75619SDan Williams return container_of(pdev, struct nfit_test, pdev); 1946bc75619SDan Williams } 1956bc75619SDan Williams 196bfbaa952SDave Jiang static int nd_intel_test_get_fw_info(struct nfit_test *t, 197bfbaa952SDave Jiang struct nd_intel_fw_info *nd_cmd, unsigned int buf_len, 198bfbaa952SDave Jiang int idx) 199bfbaa952SDave Jiang { 200bfbaa952SDave Jiang struct device *dev = &t->pdev.dev; 201bfbaa952SDave Jiang struct nfit_test_fw *fw = &t->fw[idx]; 202bfbaa952SDave Jiang 203bfbaa952SDave Jiang dev_dbg(dev, "%s(nfit_test: %p nd_cmd: %p, buf_len: %u, idx: %d\n", 204bfbaa952SDave Jiang __func__, t, nd_cmd, buf_len, idx); 205bfbaa952SDave Jiang 206bfbaa952SDave Jiang if (buf_len < sizeof(*nd_cmd)) 207bfbaa952SDave Jiang return -EINVAL; 208bfbaa952SDave Jiang 209bfbaa952SDave Jiang nd_cmd->status = 0; 210bfbaa952SDave Jiang nd_cmd->storage_size = INTEL_FW_STORAGE_SIZE; 211bfbaa952SDave Jiang nd_cmd->max_send_len = INTEL_FW_MAX_SEND_LEN; 212bfbaa952SDave Jiang nd_cmd->query_interval = INTEL_FW_QUERY_INTERVAL; 213bfbaa952SDave Jiang nd_cmd->max_query_time = INTEL_FW_QUERY_MAX_TIME; 214bfbaa952SDave Jiang nd_cmd->update_cap = 0; 215bfbaa952SDave Jiang nd_cmd->fis_version = INTEL_FW_FIS_VERSION; 216bfbaa952SDave Jiang nd_cmd->run_version = 0; 217bfbaa952SDave Jiang nd_cmd->updated_version = fw->version; 218bfbaa952SDave Jiang 219bfbaa952SDave Jiang return 0; 220bfbaa952SDave Jiang } 221bfbaa952SDave Jiang 222bfbaa952SDave Jiang static int nd_intel_test_start_update(struct nfit_test *t, 223bfbaa952SDave Jiang struct nd_intel_fw_start *nd_cmd, unsigned int buf_len, 224bfbaa952SDave Jiang int idx) 225bfbaa952SDave Jiang { 226bfbaa952SDave Jiang struct device *dev = &t->pdev.dev; 227bfbaa952SDave Jiang struct nfit_test_fw *fw = &t->fw[idx]; 228bfbaa952SDave Jiang 229bfbaa952SDave Jiang dev_dbg(dev, "%s(nfit_test: %p nd_cmd: %p buf_len: %u idx: %d)\n", 230bfbaa952SDave Jiang __func__, t, nd_cmd, buf_len, idx); 231bfbaa952SDave Jiang 232bfbaa952SDave Jiang if (buf_len < sizeof(*nd_cmd)) 233bfbaa952SDave Jiang return -EINVAL; 234bfbaa952SDave Jiang 235bfbaa952SDave Jiang if (fw->state != FW_STATE_NEW) { 236bfbaa952SDave Jiang /* extended status, FW update in progress */ 237bfbaa952SDave Jiang nd_cmd->status = 0x10007; 238bfbaa952SDave Jiang return 0; 239bfbaa952SDave Jiang } 240bfbaa952SDave Jiang 241bfbaa952SDave Jiang fw->state = FW_STATE_IN_PROGRESS; 242bfbaa952SDave Jiang fw->context++; 243bfbaa952SDave Jiang fw->size_received = 0; 244bfbaa952SDave Jiang nd_cmd->status = 0; 245bfbaa952SDave Jiang nd_cmd->context = fw->context; 246bfbaa952SDave Jiang 247bfbaa952SDave Jiang dev_dbg(dev, "%s: context issued: %#x\n", __func__, nd_cmd->context); 248bfbaa952SDave Jiang 249bfbaa952SDave Jiang return 0; 250bfbaa952SDave Jiang } 251bfbaa952SDave Jiang 252bfbaa952SDave Jiang static int nd_intel_test_send_data(struct nfit_test *t, 253bfbaa952SDave Jiang struct nd_intel_fw_send_data *nd_cmd, unsigned int buf_len, 254bfbaa952SDave Jiang int idx) 255bfbaa952SDave Jiang { 256bfbaa952SDave Jiang struct device *dev = &t->pdev.dev; 257bfbaa952SDave Jiang struct nfit_test_fw *fw = &t->fw[idx]; 258bfbaa952SDave Jiang u32 *status = (u32 *)&nd_cmd->data[nd_cmd->length]; 259bfbaa952SDave Jiang 260bfbaa952SDave Jiang dev_dbg(dev, "%s(nfit_test: %p nd_cmd: %p buf_len: %u idx: %d)\n", 261bfbaa952SDave Jiang __func__, t, nd_cmd, buf_len, idx); 262bfbaa952SDave Jiang 263bfbaa952SDave Jiang if (buf_len < sizeof(*nd_cmd)) 264bfbaa952SDave Jiang return -EINVAL; 265bfbaa952SDave Jiang 266bfbaa952SDave Jiang 267bfbaa952SDave Jiang dev_dbg(dev, "%s: cmd->status: %#x\n", __func__, *status); 268bfbaa952SDave Jiang dev_dbg(dev, "%s: cmd->data[0]: %#x\n", __func__, nd_cmd->data[0]); 269bfbaa952SDave Jiang dev_dbg(dev, "%s: cmd->data[%u]: %#x\n", __func__, nd_cmd->length-1, 270bfbaa952SDave Jiang nd_cmd->data[nd_cmd->length-1]); 271bfbaa952SDave Jiang 272bfbaa952SDave Jiang if (fw->state != FW_STATE_IN_PROGRESS) { 273bfbaa952SDave Jiang dev_dbg(dev, "%s: not in IN_PROGRESS state\n", __func__); 274bfbaa952SDave Jiang *status = 0x5; 275bfbaa952SDave Jiang return 0; 276bfbaa952SDave Jiang } 277bfbaa952SDave Jiang 278bfbaa952SDave Jiang if (nd_cmd->context != fw->context) { 279bfbaa952SDave Jiang dev_dbg(dev, "%s: incorrect context: in: %#x correct: %#x\n", 280bfbaa952SDave Jiang __func__, nd_cmd->context, fw->context); 281bfbaa952SDave Jiang *status = 0x10007; 282bfbaa952SDave Jiang return 0; 283bfbaa952SDave Jiang } 284bfbaa952SDave Jiang 285bfbaa952SDave Jiang /* 286bfbaa952SDave Jiang * check offset + len > size of fw storage 287bfbaa952SDave Jiang * check length is > max send length 288bfbaa952SDave Jiang */ 289bfbaa952SDave Jiang if (nd_cmd->offset + nd_cmd->length > INTEL_FW_STORAGE_SIZE || 290bfbaa952SDave Jiang nd_cmd->length > INTEL_FW_MAX_SEND_LEN) { 291bfbaa952SDave Jiang *status = 0x3; 292bfbaa952SDave Jiang dev_dbg(dev, "%s: buffer boundary violation\n", __func__); 293bfbaa952SDave Jiang return 0; 294bfbaa952SDave Jiang } 295bfbaa952SDave Jiang 296bfbaa952SDave Jiang fw->size_received += nd_cmd->length; 297bfbaa952SDave Jiang dev_dbg(dev, "%s: copying %u bytes, %u bytes so far\n", 298bfbaa952SDave Jiang __func__, nd_cmd->length, fw->size_received); 299bfbaa952SDave Jiang *status = 0; 300bfbaa952SDave Jiang return 0; 301bfbaa952SDave Jiang } 302bfbaa952SDave Jiang 303bfbaa952SDave Jiang static int nd_intel_test_finish_fw(struct nfit_test *t, 304bfbaa952SDave Jiang struct nd_intel_fw_finish_update *nd_cmd, 305bfbaa952SDave Jiang unsigned int buf_len, int idx) 306bfbaa952SDave Jiang { 307bfbaa952SDave Jiang struct device *dev = &t->pdev.dev; 308bfbaa952SDave Jiang struct nfit_test_fw *fw = &t->fw[idx]; 309bfbaa952SDave Jiang 310bfbaa952SDave Jiang dev_dbg(dev, "%s(nfit_test: %p nd_cmd: %p buf_len: %u idx: %d)\n", 311bfbaa952SDave Jiang __func__, t, nd_cmd, buf_len, idx); 312bfbaa952SDave Jiang 313bfbaa952SDave Jiang if (fw->state == FW_STATE_UPDATED) { 314bfbaa952SDave Jiang /* update already done, need cold boot */ 315bfbaa952SDave Jiang nd_cmd->status = 0x20007; 316bfbaa952SDave Jiang return 0; 317bfbaa952SDave Jiang } 318bfbaa952SDave Jiang 319bfbaa952SDave Jiang dev_dbg(dev, "%s: context: %#x ctrl_flags: %#x\n", 320bfbaa952SDave Jiang __func__, nd_cmd->context, nd_cmd->ctrl_flags); 321bfbaa952SDave Jiang 322bfbaa952SDave Jiang switch (nd_cmd->ctrl_flags) { 323bfbaa952SDave Jiang case 0: /* finish */ 324bfbaa952SDave Jiang if (nd_cmd->context != fw->context) { 325bfbaa952SDave Jiang dev_dbg(dev, "%s: incorrect context: in: %#x correct: %#x\n", 326bfbaa952SDave Jiang __func__, nd_cmd->context, 327bfbaa952SDave Jiang fw->context); 328bfbaa952SDave Jiang nd_cmd->status = 0x10007; 329bfbaa952SDave Jiang return 0; 330bfbaa952SDave Jiang } 331bfbaa952SDave Jiang nd_cmd->status = 0; 332bfbaa952SDave Jiang fw->state = FW_STATE_VERIFY; 333bfbaa952SDave Jiang /* set 1 second of time for firmware "update" */ 334bfbaa952SDave Jiang fw->end_time = jiffies + HZ; 335bfbaa952SDave Jiang break; 336bfbaa952SDave Jiang 337bfbaa952SDave Jiang case 1: /* abort */ 338bfbaa952SDave Jiang fw->size_received = 0; 339bfbaa952SDave Jiang /* successfully aborted status */ 340bfbaa952SDave Jiang nd_cmd->status = 0x40007; 341bfbaa952SDave Jiang fw->state = FW_STATE_NEW; 342bfbaa952SDave Jiang dev_dbg(dev, "%s: abort successful\n", __func__); 343bfbaa952SDave Jiang break; 344bfbaa952SDave Jiang 345bfbaa952SDave Jiang default: /* bad control flag */ 346bfbaa952SDave Jiang dev_warn(dev, "%s: unknown control flag: %#x\n", 347bfbaa952SDave Jiang __func__, nd_cmd->ctrl_flags); 348bfbaa952SDave Jiang return -EINVAL; 349bfbaa952SDave Jiang } 350bfbaa952SDave Jiang 351bfbaa952SDave Jiang return 0; 352bfbaa952SDave Jiang } 353bfbaa952SDave Jiang 354bfbaa952SDave Jiang static int nd_intel_test_finish_query(struct nfit_test *t, 355bfbaa952SDave Jiang struct nd_intel_fw_finish_query *nd_cmd, 356bfbaa952SDave Jiang unsigned int buf_len, int idx) 357bfbaa952SDave Jiang { 358bfbaa952SDave Jiang struct device *dev = &t->pdev.dev; 359bfbaa952SDave Jiang struct nfit_test_fw *fw = &t->fw[idx]; 360bfbaa952SDave Jiang 361bfbaa952SDave Jiang dev_dbg(dev, "%s(nfit_test: %p nd_cmd: %p buf_len: %u idx: %d)\n", 362bfbaa952SDave Jiang __func__, t, nd_cmd, buf_len, idx); 363bfbaa952SDave Jiang 364bfbaa952SDave Jiang if (buf_len < sizeof(*nd_cmd)) 365bfbaa952SDave Jiang return -EINVAL; 366bfbaa952SDave Jiang 367bfbaa952SDave Jiang if (nd_cmd->context != fw->context) { 368bfbaa952SDave Jiang dev_dbg(dev, "%s: incorrect context: in: %#x correct: %#x\n", 369bfbaa952SDave Jiang __func__, nd_cmd->context, fw->context); 370bfbaa952SDave Jiang nd_cmd->status = 0x10007; 371bfbaa952SDave Jiang return 0; 372bfbaa952SDave Jiang } 373bfbaa952SDave Jiang 374bfbaa952SDave Jiang dev_dbg(dev, "%s context: %#x\n", __func__, nd_cmd->context); 375bfbaa952SDave Jiang 376bfbaa952SDave Jiang switch (fw->state) { 377bfbaa952SDave Jiang case FW_STATE_NEW: 378bfbaa952SDave Jiang nd_cmd->updated_fw_rev = 0; 379bfbaa952SDave Jiang nd_cmd->status = 0; 380bfbaa952SDave Jiang dev_dbg(dev, "%s: new state\n", __func__); 381bfbaa952SDave Jiang break; 382bfbaa952SDave Jiang 383bfbaa952SDave Jiang case FW_STATE_IN_PROGRESS: 384bfbaa952SDave Jiang /* sequencing error */ 385bfbaa952SDave Jiang nd_cmd->status = 0x40007; 386bfbaa952SDave Jiang nd_cmd->updated_fw_rev = 0; 387bfbaa952SDave Jiang dev_dbg(dev, "%s: sequence error\n", __func__); 388bfbaa952SDave Jiang break; 389bfbaa952SDave Jiang 390bfbaa952SDave Jiang case FW_STATE_VERIFY: 391bfbaa952SDave Jiang if (time_is_after_jiffies64(fw->end_time)) { 392bfbaa952SDave Jiang nd_cmd->updated_fw_rev = 0; 393bfbaa952SDave Jiang nd_cmd->status = 0x20007; 394bfbaa952SDave Jiang dev_dbg(dev, "%s: still verifying\n", __func__); 395bfbaa952SDave Jiang break; 396bfbaa952SDave Jiang } 397bfbaa952SDave Jiang 398bfbaa952SDave Jiang dev_dbg(dev, "%s: transition out verify\n", __func__); 399bfbaa952SDave Jiang fw->state = FW_STATE_UPDATED; 400bfbaa952SDave Jiang /* we are going to fall through if it's "done" */ 401bfbaa952SDave Jiang case FW_STATE_UPDATED: 402bfbaa952SDave Jiang nd_cmd->status = 0; 403bfbaa952SDave Jiang /* bogus test version */ 404bfbaa952SDave Jiang fw->version = nd_cmd->updated_fw_rev = 405bfbaa952SDave Jiang INTEL_FW_FAKE_VERSION; 406bfbaa952SDave Jiang dev_dbg(dev, "%s: updated\n", __func__); 407bfbaa952SDave Jiang break; 408bfbaa952SDave Jiang 409bfbaa952SDave Jiang default: /* we should never get here */ 410bfbaa952SDave Jiang return -EINVAL; 411bfbaa952SDave Jiang } 412bfbaa952SDave Jiang 413bfbaa952SDave Jiang return 0; 414bfbaa952SDave Jiang } 415bfbaa952SDave Jiang 41639c686b8SVishal Verma static int nfit_test_cmd_get_config_size(struct nd_cmd_get_config_size *nd_cmd, 4176bc75619SDan Williams unsigned int buf_len) 4186bc75619SDan Williams { 4196bc75619SDan Williams if (buf_len < sizeof(*nd_cmd)) 4206bc75619SDan Williams return -EINVAL; 42139c686b8SVishal Verma 4226bc75619SDan Williams nd_cmd->status = 0; 4236bc75619SDan Williams nd_cmd->config_size = LABEL_SIZE; 4246bc75619SDan Williams nd_cmd->max_xfer = SZ_4K; 42539c686b8SVishal Verma 42639c686b8SVishal Verma return 0; 4276bc75619SDan Williams } 42839c686b8SVishal Verma 42939c686b8SVishal Verma static int nfit_test_cmd_get_config_data(struct nd_cmd_get_config_data_hdr 43039c686b8SVishal Verma *nd_cmd, unsigned int buf_len, void *label) 43139c686b8SVishal Verma { 4326bc75619SDan Williams unsigned int len, offset = nd_cmd->in_offset; 43339c686b8SVishal Verma int rc; 4346bc75619SDan Williams 4356bc75619SDan Williams if (buf_len < sizeof(*nd_cmd)) 4366bc75619SDan Williams return -EINVAL; 4376bc75619SDan Williams if (offset >= LABEL_SIZE) 4386bc75619SDan Williams return -EINVAL; 4396bc75619SDan Williams if (nd_cmd->in_length + sizeof(*nd_cmd) > buf_len) 4406bc75619SDan Williams return -EINVAL; 4416bc75619SDan Williams 4426bc75619SDan Williams nd_cmd->status = 0; 4436bc75619SDan Williams len = min(nd_cmd->in_length, LABEL_SIZE - offset); 44439c686b8SVishal Verma memcpy(nd_cmd->out_buf, label + offset, len); 4456bc75619SDan Williams rc = buf_len - sizeof(*nd_cmd) - len; 44639c686b8SVishal Verma 44739c686b8SVishal Verma return rc; 4486bc75619SDan Williams } 44939c686b8SVishal Verma 45039c686b8SVishal Verma static int nfit_test_cmd_set_config_data(struct nd_cmd_set_config_hdr *nd_cmd, 45139c686b8SVishal Verma unsigned int buf_len, void *label) 45239c686b8SVishal Verma { 4536bc75619SDan Williams unsigned int len, offset = nd_cmd->in_offset; 4546bc75619SDan Williams u32 *status; 45539c686b8SVishal Verma int rc; 4566bc75619SDan Williams 4576bc75619SDan Williams if (buf_len < sizeof(*nd_cmd)) 4586bc75619SDan Williams return -EINVAL; 4596bc75619SDan Williams if (offset >= LABEL_SIZE) 4606bc75619SDan Williams return -EINVAL; 4616bc75619SDan Williams if (nd_cmd->in_length + sizeof(*nd_cmd) + 4 > buf_len) 4626bc75619SDan Williams return -EINVAL; 4636bc75619SDan Williams 46439c686b8SVishal Verma status = (void *)nd_cmd + nd_cmd->in_length + sizeof(*nd_cmd); 4656bc75619SDan Williams *status = 0; 4666bc75619SDan Williams len = min(nd_cmd->in_length, LABEL_SIZE - offset); 46739c686b8SVishal Verma memcpy(label + offset, nd_cmd->in_buf, len); 4686bc75619SDan Williams rc = buf_len - sizeof(*nd_cmd) - (len + 4); 46939c686b8SVishal Verma 47039c686b8SVishal Verma return rc; 4716bc75619SDan Williams } 47239c686b8SVishal Verma 473d4f32367SDan Williams #define NFIT_TEST_CLEAR_ERR_UNIT 256 474747ffe11SDan Williams 47539c686b8SVishal Verma static int nfit_test_cmd_ars_cap(struct nd_cmd_ars_cap *nd_cmd, 47639c686b8SVishal Verma unsigned int buf_len) 47739c686b8SVishal Verma { 4789fb1a190SDave Jiang int ars_recs; 4799fb1a190SDave Jiang 48039c686b8SVishal Verma if (buf_len < sizeof(*nd_cmd)) 48139c686b8SVishal Verma return -EINVAL; 48239c686b8SVishal Verma 4839fb1a190SDave Jiang /* for testing, only store up to n records that fit within 4k */ 4849fb1a190SDave Jiang ars_recs = SZ_4K / sizeof(struct nd_ars_record); 4859fb1a190SDave Jiang 486747ffe11SDan Williams nd_cmd->max_ars_out = sizeof(struct nd_cmd_ars_status) 4879fb1a190SDave Jiang + ars_recs * sizeof(struct nd_ars_record); 48839c686b8SVishal Verma nd_cmd->status = (ND_ARS_PERSISTENT | ND_ARS_VOLATILE) << 16; 489d4f32367SDan Williams nd_cmd->clear_err_unit = NFIT_TEST_CLEAR_ERR_UNIT; 49039c686b8SVishal Verma 49139c686b8SVishal Verma return 0; 49239c686b8SVishal Verma } 49339c686b8SVishal Verma 4949fb1a190SDave Jiang static void post_ars_status(struct ars_state *ars_state, 4959fb1a190SDave Jiang struct badrange *badrange, u64 addr, u64 len) 49639c686b8SVishal Verma { 497f471f1a7SDan Williams struct nd_cmd_ars_status *ars_status; 498f471f1a7SDan Williams struct nd_ars_record *ars_record; 4999fb1a190SDave Jiang struct badrange_entry *be; 5009fb1a190SDave Jiang u64 end = addr + len - 1; 5019fb1a190SDave Jiang int i = 0; 502f471f1a7SDan Williams 503f471f1a7SDan Williams ars_state->deadline = jiffies + 1*HZ; 504f471f1a7SDan Williams ars_status = ars_state->ars_status; 505f471f1a7SDan Williams ars_status->status = 0; 506f471f1a7SDan Williams ars_status->address = addr; 507f471f1a7SDan Williams ars_status->length = len; 508f471f1a7SDan Williams ars_status->type = ND_ARS_PERSISTENT; 5099fb1a190SDave Jiang 5109fb1a190SDave Jiang spin_lock(&badrange->lock); 5119fb1a190SDave Jiang list_for_each_entry(be, &badrange->list, list) { 5129fb1a190SDave Jiang u64 be_end = be->start + be->length - 1; 5139fb1a190SDave Jiang u64 rstart, rend; 5149fb1a190SDave Jiang 5159fb1a190SDave Jiang /* skip entries outside the range */ 5169fb1a190SDave Jiang if (be_end < addr || be->start > end) 5179fb1a190SDave Jiang continue; 5189fb1a190SDave Jiang 5199fb1a190SDave Jiang rstart = (be->start < addr) ? addr : be->start; 5209fb1a190SDave Jiang rend = (be_end < end) ? be_end : end; 5219fb1a190SDave Jiang ars_record = &ars_status->records[i]; 522f471f1a7SDan Williams ars_record->handle = 0; 5239fb1a190SDave Jiang ars_record->err_address = rstart; 5249fb1a190SDave Jiang ars_record->length = rend - rstart + 1; 5259fb1a190SDave Jiang i++; 5269fb1a190SDave Jiang } 5279fb1a190SDave Jiang spin_unlock(&badrange->lock); 5289fb1a190SDave Jiang ars_status->num_records = i; 5299fb1a190SDave Jiang ars_status->out_length = sizeof(struct nd_cmd_ars_status) 5309fb1a190SDave Jiang + i * sizeof(struct nd_ars_record); 531f471f1a7SDan Williams } 532f471f1a7SDan Williams 5339fb1a190SDave Jiang static int nfit_test_cmd_ars_start(struct nfit_test *t, 5349fb1a190SDave Jiang struct ars_state *ars_state, 535f471f1a7SDan Williams struct nd_cmd_ars_start *ars_start, unsigned int buf_len, 536f471f1a7SDan Williams int *cmd_rc) 537f471f1a7SDan Williams { 538f471f1a7SDan Williams if (buf_len < sizeof(*ars_start)) 53939c686b8SVishal Verma return -EINVAL; 54039c686b8SVishal Verma 541f471f1a7SDan Williams spin_lock(&ars_state->lock); 542f471f1a7SDan Williams if (time_before(jiffies, ars_state->deadline)) { 543f471f1a7SDan Williams ars_start->status = NFIT_ARS_START_BUSY; 544f471f1a7SDan Williams *cmd_rc = -EBUSY; 545f471f1a7SDan Williams } else { 546f471f1a7SDan Williams ars_start->status = 0; 547f471f1a7SDan Williams ars_start->scrub_time = 1; 5489fb1a190SDave Jiang post_ars_status(ars_state, &t->badrange, ars_start->address, 549f471f1a7SDan Williams ars_start->length); 550f471f1a7SDan Williams *cmd_rc = 0; 551f471f1a7SDan Williams } 552f471f1a7SDan Williams spin_unlock(&ars_state->lock); 55339c686b8SVishal Verma 55439c686b8SVishal Verma return 0; 55539c686b8SVishal Verma } 55639c686b8SVishal Verma 557f471f1a7SDan Williams static int nfit_test_cmd_ars_status(struct ars_state *ars_state, 558f471f1a7SDan Williams struct nd_cmd_ars_status *ars_status, unsigned int buf_len, 559f471f1a7SDan Williams int *cmd_rc) 56039c686b8SVishal Verma { 561f471f1a7SDan Williams if (buf_len < ars_state->ars_status->out_length) 56239c686b8SVishal Verma return -EINVAL; 56339c686b8SVishal Verma 564f471f1a7SDan Williams spin_lock(&ars_state->lock); 565f471f1a7SDan Williams if (time_before(jiffies, ars_state->deadline)) { 566f471f1a7SDan Williams memset(ars_status, 0, buf_len); 567f471f1a7SDan Williams ars_status->status = NFIT_ARS_STATUS_BUSY; 568f471f1a7SDan Williams ars_status->out_length = sizeof(*ars_status); 569f471f1a7SDan Williams *cmd_rc = -EBUSY; 570f471f1a7SDan Williams } else { 571f471f1a7SDan Williams memcpy(ars_status, ars_state->ars_status, 572f471f1a7SDan Williams ars_state->ars_status->out_length); 573f471f1a7SDan Williams *cmd_rc = 0; 574f471f1a7SDan Williams } 575f471f1a7SDan Williams spin_unlock(&ars_state->lock); 57639c686b8SVishal Verma return 0; 57739c686b8SVishal Verma } 57839c686b8SVishal Verma 5795e096ef3SVishal Verma static int nfit_test_cmd_clear_error(struct nfit_test *t, 5805e096ef3SVishal Verma struct nd_cmd_clear_error *clear_err, 581d4f32367SDan Williams unsigned int buf_len, int *cmd_rc) 582d4f32367SDan Williams { 583d4f32367SDan Williams const u64 mask = NFIT_TEST_CLEAR_ERR_UNIT - 1; 584d4f32367SDan Williams if (buf_len < sizeof(*clear_err)) 585d4f32367SDan Williams return -EINVAL; 586d4f32367SDan Williams 587d4f32367SDan Williams if ((clear_err->address & mask) || (clear_err->length & mask)) 588d4f32367SDan Williams return -EINVAL; 589d4f32367SDan Williams 5905e096ef3SVishal Verma badrange_forget(&t->badrange, clear_err->address, clear_err->length); 591d4f32367SDan Williams clear_err->status = 0; 592d4f32367SDan Williams clear_err->cleared = clear_err->length; 593d4f32367SDan Williams *cmd_rc = 0; 594d4f32367SDan Williams return 0; 595d4f32367SDan Williams } 596d4f32367SDan Williams 59710246dc8SYasunori Goto struct region_search_spa { 59810246dc8SYasunori Goto u64 addr; 59910246dc8SYasunori Goto struct nd_region *region; 60010246dc8SYasunori Goto }; 60110246dc8SYasunori Goto 60210246dc8SYasunori Goto static int is_region_device(struct device *dev) 60310246dc8SYasunori Goto { 60410246dc8SYasunori Goto return !strncmp(dev->kobj.name, "region", 6); 60510246dc8SYasunori Goto } 60610246dc8SYasunori Goto 60710246dc8SYasunori Goto static int nfit_test_search_region_spa(struct device *dev, void *data) 60810246dc8SYasunori Goto { 60910246dc8SYasunori Goto struct region_search_spa *ctx = data; 61010246dc8SYasunori Goto struct nd_region *nd_region; 61110246dc8SYasunori Goto resource_size_t ndr_end; 61210246dc8SYasunori Goto 61310246dc8SYasunori Goto if (!is_region_device(dev)) 61410246dc8SYasunori Goto return 0; 61510246dc8SYasunori Goto 61610246dc8SYasunori Goto nd_region = to_nd_region(dev); 61710246dc8SYasunori Goto ndr_end = nd_region->ndr_start + nd_region->ndr_size; 61810246dc8SYasunori Goto 61910246dc8SYasunori Goto if (ctx->addr >= nd_region->ndr_start && ctx->addr < ndr_end) { 62010246dc8SYasunori Goto ctx->region = nd_region; 62110246dc8SYasunori Goto return 1; 62210246dc8SYasunori Goto } 62310246dc8SYasunori Goto 62410246dc8SYasunori Goto return 0; 62510246dc8SYasunori Goto } 62610246dc8SYasunori Goto 62710246dc8SYasunori Goto static int nfit_test_search_spa(struct nvdimm_bus *bus, 62810246dc8SYasunori Goto struct nd_cmd_translate_spa *spa) 62910246dc8SYasunori Goto { 63010246dc8SYasunori Goto int ret; 63110246dc8SYasunori Goto struct nd_region *nd_region = NULL; 63210246dc8SYasunori Goto struct nvdimm *nvdimm = NULL; 63310246dc8SYasunori Goto struct nd_mapping *nd_mapping = NULL; 63410246dc8SYasunori Goto struct region_search_spa ctx = { 63510246dc8SYasunori Goto .addr = spa->spa, 63610246dc8SYasunori Goto .region = NULL, 63710246dc8SYasunori Goto }; 63810246dc8SYasunori Goto u64 dpa; 63910246dc8SYasunori Goto 64010246dc8SYasunori Goto ret = device_for_each_child(&bus->dev, &ctx, 64110246dc8SYasunori Goto nfit_test_search_region_spa); 64210246dc8SYasunori Goto 64310246dc8SYasunori Goto if (!ret) 64410246dc8SYasunori Goto return -ENODEV; 64510246dc8SYasunori Goto 64610246dc8SYasunori Goto nd_region = ctx.region; 64710246dc8SYasunori Goto 64810246dc8SYasunori Goto dpa = ctx.addr - nd_region->ndr_start; 64910246dc8SYasunori Goto 65010246dc8SYasunori Goto /* 65110246dc8SYasunori Goto * last dimm is selected for test 65210246dc8SYasunori Goto */ 65310246dc8SYasunori Goto nd_mapping = &nd_region->mapping[nd_region->ndr_mappings - 1]; 65410246dc8SYasunori Goto nvdimm = nd_mapping->nvdimm; 65510246dc8SYasunori Goto 65610246dc8SYasunori Goto spa->devices[0].nfit_device_handle = handle[nvdimm->id]; 65710246dc8SYasunori Goto spa->num_nvdimms = 1; 65810246dc8SYasunori Goto spa->devices[0].dpa = dpa; 65910246dc8SYasunori Goto 66010246dc8SYasunori Goto return 0; 66110246dc8SYasunori Goto } 66210246dc8SYasunori Goto 66310246dc8SYasunori Goto static int nfit_test_cmd_translate_spa(struct nvdimm_bus *bus, 66410246dc8SYasunori Goto struct nd_cmd_translate_spa *spa, unsigned int buf_len) 66510246dc8SYasunori Goto { 66610246dc8SYasunori Goto if (buf_len < spa->translate_length) 66710246dc8SYasunori Goto return -EINVAL; 66810246dc8SYasunori Goto 66910246dc8SYasunori Goto if (nfit_test_search_spa(bus, spa) < 0 || !spa->num_nvdimms) 67010246dc8SYasunori Goto spa->status = 2; 67110246dc8SYasunori Goto 67210246dc8SYasunori Goto return 0; 67310246dc8SYasunori Goto } 67410246dc8SYasunori Goto 675ed07c433SDan Williams static int nfit_test_cmd_smart(struct nd_intel_smart *smart, unsigned int buf_len, 676ed07c433SDan Williams struct nd_intel_smart *smart_data) 677baa51277SDan Williams { 678baa51277SDan Williams if (buf_len < sizeof(*smart)) 679baa51277SDan Williams return -EINVAL; 680ed07c433SDan Williams memcpy(smart, smart_data, sizeof(*smart)); 681baa51277SDan Williams return 0; 682baa51277SDan Williams } 683baa51277SDan Williams 684cdd77d3eSDan Williams static int nfit_test_cmd_smart_threshold( 685ed07c433SDan Williams struct nd_intel_smart_threshold *out, 686ed07c433SDan Williams unsigned int buf_len, 687ed07c433SDan Williams struct nd_intel_smart_threshold *smart_t) 688baa51277SDan Williams { 689baa51277SDan Williams if (buf_len < sizeof(*smart_t)) 690baa51277SDan Williams return -EINVAL; 691ed07c433SDan Williams memcpy(out, smart_t, sizeof(*smart_t)); 692ed07c433SDan Williams return 0; 693ed07c433SDan Williams } 694ed07c433SDan Williams 695ed07c433SDan Williams static void smart_notify(struct device *bus_dev, 696ed07c433SDan Williams struct device *dimm_dev, struct nd_intel_smart *smart, 697ed07c433SDan Williams struct nd_intel_smart_threshold *thresh) 698ed07c433SDan Williams { 699ed07c433SDan Williams dev_dbg(dimm_dev, "%s: alarm: %#x spares: %d (%d) mtemp: %d (%d) ctemp: %d (%d)\n", 700ed07c433SDan Williams __func__, thresh->alarm_control, thresh->spares, 701ed07c433SDan Williams smart->spares, thresh->media_temperature, 702ed07c433SDan Williams smart->media_temperature, thresh->ctrl_temperature, 703ed07c433SDan Williams smart->ctrl_temperature); 704ed07c433SDan Williams if (((thresh->alarm_control & ND_INTEL_SMART_SPARE_TRIP) 705ed07c433SDan Williams && smart->spares 706ed07c433SDan Williams <= thresh->spares) 707ed07c433SDan Williams || ((thresh->alarm_control & ND_INTEL_SMART_TEMP_TRIP) 708ed07c433SDan Williams && smart->media_temperature 709ed07c433SDan Williams >= thresh->media_temperature) 710ed07c433SDan Williams || ((thresh->alarm_control & ND_INTEL_SMART_CTEMP_TRIP) 711ed07c433SDan Williams && smart->ctrl_temperature 712ed07c433SDan Williams >= thresh->ctrl_temperature)) { 713ed07c433SDan Williams device_lock(bus_dev); 714ed07c433SDan Williams __acpi_nvdimm_notify(dimm_dev, 0x81); 715ed07c433SDan Williams device_unlock(bus_dev); 716ed07c433SDan Williams } 717ed07c433SDan Williams } 718ed07c433SDan Williams 719ed07c433SDan Williams static int nfit_test_cmd_smart_set_threshold( 720ed07c433SDan Williams struct nd_intel_smart_set_threshold *in, 721ed07c433SDan Williams unsigned int buf_len, 722ed07c433SDan Williams struct nd_intel_smart_threshold *thresh, 723ed07c433SDan Williams struct nd_intel_smart *smart, 724ed07c433SDan Williams struct device *bus_dev, struct device *dimm_dev) 725ed07c433SDan Williams { 726ed07c433SDan Williams unsigned int size; 727ed07c433SDan Williams 728ed07c433SDan Williams size = sizeof(*in) - 4; 729ed07c433SDan Williams if (buf_len < size) 730ed07c433SDan Williams return -EINVAL; 731ed07c433SDan Williams memcpy(thresh->data, in, size); 732ed07c433SDan Williams in->status = 0; 733ed07c433SDan Williams smart_notify(bus_dev, dimm_dev, smart, thresh); 734ed07c433SDan Williams 735baa51277SDan Williams return 0; 736baa51277SDan Williams } 737baa51277SDan Williams 7389fb1a190SDave Jiang static void uc_error_notify(struct work_struct *work) 7399fb1a190SDave Jiang { 7409fb1a190SDave Jiang struct nfit_test *t = container_of(work, typeof(*t), work); 7419fb1a190SDave Jiang 7429fb1a190SDave Jiang __acpi_nfit_notify(&t->pdev.dev, t, NFIT_NOTIFY_UC_MEMORY_ERROR); 7439fb1a190SDave Jiang } 7449fb1a190SDave Jiang 7459fb1a190SDave Jiang static int nfit_test_cmd_ars_error_inject(struct nfit_test *t, 7469fb1a190SDave Jiang struct nd_cmd_ars_err_inj *err_inj, unsigned int buf_len) 7479fb1a190SDave Jiang { 7489fb1a190SDave Jiang int rc; 7499fb1a190SDave Jiang 75041cb3301SVishal Verma if (buf_len != sizeof(*err_inj)) { 7519fb1a190SDave Jiang rc = -EINVAL; 7529fb1a190SDave Jiang goto err; 7539fb1a190SDave Jiang } 7549fb1a190SDave Jiang 7559fb1a190SDave Jiang if (err_inj->err_inj_spa_range_length <= 0) { 7569fb1a190SDave Jiang rc = -EINVAL; 7579fb1a190SDave Jiang goto err; 7589fb1a190SDave Jiang } 7599fb1a190SDave Jiang 7609fb1a190SDave Jiang rc = badrange_add(&t->badrange, err_inj->err_inj_spa_range_base, 7619fb1a190SDave Jiang err_inj->err_inj_spa_range_length); 7629fb1a190SDave Jiang if (rc < 0) 7639fb1a190SDave Jiang goto err; 7649fb1a190SDave Jiang 7659fb1a190SDave Jiang if (err_inj->err_inj_options & (1 << ND_ARS_ERR_INJ_OPT_NOTIFY)) 7669fb1a190SDave Jiang queue_work(nfit_wq, &t->work); 7679fb1a190SDave Jiang 7689fb1a190SDave Jiang err_inj->status = 0; 7699fb1a190SDave Jiang return 0; 7709fb1a190SDave Jiang 7719fb1a190SDave Jiang err: 7729fb1a190SDave Jiang err_inj->status = NFIT_ARS_INJECT_INVALID; 7739fb1a190SDave Jiang return rc; 7749fb1a190SDave Jiang } 7759fb1a190SDave Jiang 7769fb1a190SDave Jiang static int nfit_test_cmd_ars_inject_clear(struct nfit_test *t, 7779fb1a190SDave Jiang struct nd_cmd_ars_err_inj_clr *err_clr, unsigned int buf_len) 7789fb1a190SDave Jiang { 7799fb1a190SDave Jiang int rc; 7809fb1a190SDave Jiang 78141cb3301SVishal Verma if (buf_len != sizeof(*err_clr)) { 7829fb1a190SDave Jiang rc = -EINVAL; 7839fb1a190SDave Jiang goto err; 7849fb1a190SDave Jiang } 7859fb1a190SDave Jiang 7869fb1a190SDave Jiang if (err_clr->err_inj_clr_spa_range_length <= 0) { 7879fb1a190SDave Jiang rc = -EINVAL; 7889fb1a190SDave Jiang goto err; 7899fb1a190SDave Jiang } 7909fb1a190SDave Jiang 7919fb1a190SDave Jiang badrange_forget(&t->badrange, err_clr->err_inj_clr_spa_range_base, 7929fb1a190SDave Jiang err_clr->err_inj_clr_spa_range_length); 7939fb1a190SDave Jiang 7949fb1a190SDave Jiang err_clr->status = 0; 7959fb1a190SDave Jiang return 0; 7969fb1a190SDave Jiang 7979fb1a190SDave Jiang err: 7989fb1a190SDave Jiang err_clr->status = NFIT_ARS_INJECT_INVALID; 7999fb1a190SDave Jiang return rc; 8009fb1a190SDave Jiang } 8019fb1a190SDave Jiang 8029fb1a190SDave Jiang static int nfit_test_cmd_ars_inject_status(struct nfit_test *t, 8039fb1a190SDave Jiang struct nd_cmd_ars_err_inj_stat *err_stat, 8049fb1a190SDave Jiang unsigned int buf_len) 8059fb1a190SDave Jiang { 8069fb1a190SDave Jiang struct badrange_entry *be; 8079fb1a190SDave Jiang int max = SZ_4K / sizeof(struct nd_error_stat_query_record); 8089fb1a190SDave Jiang int i = 0; 8099fb1a190SDave Jiang 8109fb1a190SDave Jiang err_stat->status = 0; 8119fb1a190SDave Jiang spin_lock(&t->badrange.lock); 8129fb1a190SDave Jiang list_for_each_entry(be, &t->badrange.list, list) { 8139fb1a190SDave Jiang err_stat->record[i].err_inj_stat_spa_range_base = be->start; 8149fb1a190SDave Jiang err_stat->record[i].err_inj_stat_spa_range_length = be->length; 8159fb1a190SDave Jiang i++; 8169fb1a190SDave Jiang if (i > max) 8179fb1a190SDave Jiang break; 8189fb1a190SDave Jiang } 8199fb1a190SDave Jiang spin_unlock(&t->badrange.lock); 8209fb1a190SDave Jiang err_stat->inj_err_rec_count = i; 8219fb1a190SDave Jiang 8229fb1a190SDave Jiang return 0; 8239fb1a190SDave Jiang } 8249fb1a190SDave Jiang 825674d8bdeSDave Jiang static int nd_intel_test_cmd_set_lss_status(struct nfit_test *t, 826674d8bdeSDave Jiang struct nd_intel_lss *nd_cmd, unsigned int buf_len) 827674d8bdeSDave Jiang { 828674d8bdeSDave Jiang struct device *dev = &t->pdev.dev; 829674d8bdeSDave Jiang 830674d8bdeSDave Jiang if (buf_len < sizeof(*nd_cmd)) 831674d8bdeSDave Jiang return -EINVAL; 832674d8bdeSDave Jiang 833674d8bdeSDave Jiang switch (nd_cmd->enable) { 834674d8bdeSDave Jiang case 0: 835674d8bdeSDave Jiang nd_cmd->status = 0; 836674d8bdeSDave Jiang dev_dbg(dev, "%s: Latch System Shutdown Status disabled\n", 837674d8bdeSDave Jiang __func__); 838674d8bdeSDave Jiang break; 839674d8bdeSDave Jiang case 1: 840674d8bdeSDave Jiang nd_cmd->status = 0; 841674d8bdeSDave Jiang dev_dbg(dev, "%s: Latch System Shutdown Status enabled\n", 842674d8bdeSDave Jiang __func__); 843674d8bdeSDave Jiang break; 844674d8bdeSDave Jiang default: 845674d8bdeSDave Jiang dev_warn(dev, "Unknown enable value: %#x\n", nd_cmd->enable); 846674d8bdeSDave Jiang nd_cmd->status = 0x3; 847674d8bdeSDave Jiang break; 848674d8bdeSDave Jiang } 849674d8bdeSDave Jiang 850674d8bdeSDave Jiang 851674d8bdeSDave Jiang return 0; 852674d8bdeSDave Jiang } 853674d8bdeSDave Jiang 854bfbaa952SDave Jiang static int get_dimm(struct nfit_mem *nfit_mem, unsigned int func) 855bfbaa952SDave Jiang { 856bfbaa952SDave Jiang int i; 857bfbaa952SDave Jiang 858bfbaa952SDave Jiang /* lookup per-dimm data */ 859bfbaa952SDave Jiang for (i = 0; i < ARRAY_SIZE(handle); i++) 860bfbaa952SDave Jiang if (__to_nfit_memdev(nfit_mem)->device_handle == handle[i]) 861bfbaa952SDave Jiang break; 862bfbaa952SDave Jiang if (i >= ARRAY_SIZE(handle)) 863bfbaa952SDave Jiang return -ENXIO; 864bfbaa952SDave Jiang 865bfbaa952SDave Jiang if ((1 << func) & dimm_fail_cmd_flags[i]) 866bfbaa952SDave Jiang return -EIO; 867bfbaa952SDave Jiang 868bfbaa952SDave Jiang return i; 869bfbaa952SDave Jiang } 870bfbaa952SDave Jiang 87139c686b8SVishal Verma static int nfit_test_ctl(struct nvdimm_bus_descriptor *nd_desc, 87239c686b8SVishal Verma struct nvdimm *nvdimm, unsigned int cmd, void *buf, 873aef25338SDan Williams unsigned int buf_len, int *cmd_rc) 87439c686b8SVishal Verma { 87539c686b8SVishal Verma struct acpi_nfit_desc *acpi_desc = to_acpi_desc(nd_desc); 87639c686b8SVishal Verma struct nfit_test *t = container_of(acpi_desc, typeof(*t), acpi_desc); 8776634fb06SDan Williams unsigned int func = cmd; 878f471f1a7SDan Williams int i, rc = 0, __cmd_rc; 879f471f1a7SDan Williams 880f471f1a7SDan Williams if (!cmd_rc) 881f471f1a7SDan Williams cmd_rc = &__cmd_rc; 882f471f1a7SDan Williams *cmd_rc = 0; 88339c686b8SVishal Verma 88439c686b8SVishal Verma if (nvdimm) { 88539c686b8SVishal Verma struct nfit_mem *nfit_mem = nvdimm_provider_data(nvdimm); 886e3654ecaSDan Williams unsigned long cmd_mask = nvdimm_cmd_mask(nvdimm); 88739c686b8SVishal Verma 8886634fb06SDan Williams if (!nfit_mem) 8896634fb06SDan Williams return -ENOTTY; 8906634fb06SDan Williams 8916634fb06SDan Williams if (cmd == ND_CMD_CALL) { 8926634fb06SDan Williams struct nd_cmd_pkg *call_pkg = buf; 8936634fb06SDan Williams 8946634fb06SDan Williams buf_len = call_pkg->nd_size_in + call_pkg->nd_size_out; 8956634fb06SDan Williams buf = (void *) call_pkg->nd_payload; 8966634fb06SDan Williams func = call_pkg->nd_command; 8976634fb06SDan Williams if (call_pkg->nd_family != nfit_mem->family) 8986634fb06SDan Williams return -ENOTTY; 899bfbaa952SDave Jiang 900bfbaa952SDave Jiang i = get_dimm(nfit_mem, func); 901bfbaa952SDave Jiang if (i < 0) 902bfbaa952SDave Jiang return i; 903bfbaa952SDave Jiang 904bfbaa952SDave Jiang switch (func) { 905674d8bdeSDave Jiang case ND_INTEL_ENABLE_LSS_STATUS: 906674d8bdeSDave Jiang return nd_intel_test_cmd_set_lss_status(t, 907674d8bdeSDave Jiang buf, buf_len); 908bfbaa952SDave Jiang case ND_INTEL_FW_GET_INFO: 909bfbaa952SDave Jiang return nd_intel_test_get_fw_info(t, buf, 910bfbaa952SDave Jiang buf_len, i - t->dcr_idx); 911bfbaa952SDave Jiang case ND_INTEL_FW_START_UPDATE: 912bfbaa952SDave Jiang return nd_intel_test_start_update(t, buf, 913bfbaa952SDave Jiang buf_len, i - t->dcr_idx); 914bfbaa952SDave Jiang case ND_INTEL_FW_SEND_DATA: 915bfbaa952SDave Jiang return nd_intel_test_send_data(t, buf, 916bfbaa952SDave Jiang buf_len, i - t->dcr_idx); 917bfbaa952SDave Jiang case ND_INTEL_FW_FINISH_UPDATE: 918bfbaa952SDave Jiang return nd_intel_test_finish_fw(t, buf, 919bfbaa952SDave Jiang buf_len, i - t->dcr_idx); 920bfbaa952SDave Jiang case ND_INTEL_FW_FINISH_QUERY: 921bfbaa952SDave Jiang return nd_intel_test_finish_query(t, buf, 922bfbaa952SDave Jiang buf_len, i - t->dcr_idx); 923bfbaa952SDave Jiang case ND_INTEL_SMART: 924bfbaa952SDave Jiang return nfit_test_cmd_smart(buf, buf_len, 925bfbaa952SDave Jiang &t->smart[i - t->dcr_idx]); 926bfbaa952SDave Jiang case ND_INTEL_SMART_THRESHOLD: 927bfbaa952SDave Jiang return nfit_test_cmd_smart_threshold(buf, 928bfbaa952SDave Jiang buf_len, 929bfbaa952SDave Jiang &t->smart_threshold[i - 930bfbaa952SDave Jiang t->dcr_idx]); 931bfbaa952SDave Jiang case ND_INTEL_SMART_SET_THRESHOLD: 932bfbaa952SDave Jiang return nfit_test_cmd_smart_set_threshold(buf, 933bfbaa952SDave Jiang buf_len, 934bfbaa952SDave Jiang &t->smart_threshold[i - 935bfbaa952SDave Jiang t->dcr_idx], 936bfbaa952SDave Jiang &t->smart[i - t->dcr_idx], 937bfbaa952SDave Jiang &t->pdev.dev, t->dimm_dev[i]); 938bfbaa952SDave Jiang default: 939bfbaa952SDave Jiang return -ENOTTY; 940bfbaa952SDave Jiang } 9416634fb06SDan Williams } 9426634fb06SDan Williams 9436634fb06SDan Williams if (!test_bit(cmd, &cmd_mask) 9446634fb06SDan Williams || !test_bit(func, &nfit_mem->dsm_mask)) 94539c686b8SVishal Verma return -ENOTTY; 94639c686b8SVishal Verma 947bfbaa952SDave Jiang i = get_dimm(nfit_mem, func); 948bfbaa952SDave Jiang if (i < 0) 949bfbaa952SDave Jiang return i; 95073606afdSDan Williams 9516634fb06SDan Williams switch (func) { 95239c686b8SVishal Verma case ND_CMD_GET_CONFIG_SIZE: 95339c686b8SVishal Verma rc = nfit_test_cmd_get_config_size(buf, buf_len); 95439c686b8SVishal Verma break; 95539c686b8SVishal Verma case ND_CMD_GET_CONFIG_DATA: 95639c686b8SVishal Verma rc = nfit_test_cmd_get_config_data(buf, buf_len, 957dafb1048SDan Williams t->label[i - t->dcr_idx]); 95839c686b8SVishal Verma break; 95939c686b8SVishal Verma case ND_CMD_SET_CONFIG_DATA: 96039c686b8SVishal Verma rc = nfit_test_cmd_set_config_data(buf, buf_len, 961dafb1048SDan Williams t->label[i - t->dcr_idx]); 96239c686b8SVishal Verma break; 9636bc75619SDan Williams default: 9646bc75619SDan Williams return -ENOTTY; 9656bc75619SDan Williams } 96639c686b8SVishal Verma } else { 967f471f1a7SDan Williams struct ars_state *ars_state = &t->ars_state; 96810246dc8SYasunori Goto struct nd_cmd_pkg *call_pkg = buf; 96910246dc8SYasunori Goto 97010246dc8SYasunori Goto if (!nd_desc) 97110246dc8SYasunori Goto return -ENOTTY; 97210246dc8SYasunori Goto 97310246dc8SYasunori Goto if (cmd == ND_CMD_CALL) { 97410246dc8SYasunori Goto func = call_pkg->nd_command; 97510246dc8SYasunori Goto 97610246dc8SYasunori Goto buf_len = call_pkg->nd_size_in + call_pkg->nd_size_out; 97710246dc8SYasunori Goto buf = (void *) call_pkg->nd_payload; 97810246dc8SYasunori Goto 97910246dc8SYasunori Goto switch (func) { 98010246dc8SYasunori Goto case NFIT_CMD_TRANSLATE_SPA: 98110246dc8SYasunori Goto rc = nfit_test_cmd_translate_spa( 98210246dc8SYasunori Goto acpi_desc->nvdimm_bus, buf, buf_len); 98310246dc8SYasunori Goto return rc; 9849fb1a190SDave Jiang case NFIT_CMD_ARS_INJECT_SET: 9859fb1a190SDave Jiang rc = nfit_test_cmd_ars_error_inject(t, buf, 9869fb1a190SDave Jiang buf_len); 9879fb1a190SDave Jiang return rc; 9889fb1a190SDave Jiang case NFIT_CMD_ARS_INJECT_CLEAR: 9899fb1a190SDave Jiang rc = nfit_test_cmd_ars_inject_clear(t, buf, 9909fb1a190SDave Jiang buf_len); 9919fb1a190SDave Jiang return rc; 9929fb1a190SDave Jiang case NFIT_CMD_ARS_INJECT_GET: 9939fb1a190SDave Jiang rc = nfit_test_cmd_ars_inject_status(t, buf, 9949fb1a190SDave Jiang buf_len); 9959fb1a190SDave Jiang return rc; 99610246dc8SYasunori Goto default: 99710246dc8SYasunori Goto return -ENOTTY; 99810246dc8SYasunori Goto } 99910246dc8SYasunori Goto } 1000f471f1a7SDan Williams 1001e3654ecaSDan Williams if (!nd_desc || !test_bit(cmd, &nd_desc->cmd_mask)) 100239c686b8SVishal Verma return -ENOTTY; 100339c686b8SVishal Verma 10046634fb06SDan Williams switch (func) { 100539c686b8SVishal Verma case ND_CMD_ARS_CAP: 100639c686b8SVishal Verma rc = nfit_test_cmd_ars_cap(buf, buf_len); 100739c686b8SVishal Verma break; 100839c686b8SVishal Verma case ND_CMD_ARS_START: 10099fb1a190SDave Jiang rc = nfit_test_cmd_ars_start(t, ars_state, buf, 10109fb1a190SDave Jiang buf_len, cmd_rc); 101139c686b8SVishal Verma break; 101239c686b8SVishal Verma case ND_CMD_ARS_STATUS: 1013f471f1a7SDan Williams rc = nfit_test_cmd_ars_status(ars_state, buf, buf_len, 1014f471f1a7SDan Williams cmd_rc); 101539c686b8SVishal Verma break; 1016d4f32367SDan Williams case ND_CMD_CLEAR_ERROR: 10175e096ef3SVishal Verma rc = nfit_test_cmd_clear_error(t, buf, buf_len, cmd_rc); 1018d4f32367SDan Williams break; 101939c686b8SVishal Verma default: 102039c686b8SVishal Verma return -ENOTTY; 102139c686b8SVishal Verma } 102239c686b8SVishal Verma } 10236bc75619SDan Williams 10246bc75619SDan Williams return rc; 10256bc75619SDan Williams } 10266bc75619SDan Williams 10276bc75619SDan Williams static DEFINE_SPINLOCK(nfit_test_lock); 10286bc75619SDan Williams static struct nfit_test *instances[NUM_NFITS]; 10296bc75619SDan Williams 10306bc75619SDan Williams static void release_nfit_res(void *data) 10316bc75619SDan Williams { 10326bc75619SDan Williams struct nfit_test_resource *nfit_res = data; 10336bc75619SDan Williams 10346bc75619SDan Williams spin_lock(&nfit_test_lock); 10356bc75619SDan Williams list_del(&nfit_res->list); 10366bc75619SDan Williams spin_unlock(&nfit_test_lock); 10376bc75619SDan Williams 10386bc75619SDan Williams vfree(nfit_res->buf); 10396bc75619SDan Williams kfree(nfit_res); 10406bc75619SDan Williams } 10416bc75619SDan Williams 10426bc75619SDan Williams static void *__test_alloc(struct nfit_test *t, size_t size, dma_addr_t *dma, 10436bc75619SDan Williams void *buf) 10446bc75619SDan Williams { 10456bc75619SDan Williams struct device *dev = &t->pdev.dev; 10466bc75619SDan Williams struct nfit_test_resource *nfit_res = kzalloc(sizeof(*nfit_res), 10476bc75619SDan Williams GFP_KERNEL); 10486bc75619SDan Williams int rc; 10496bc75619SDan Williams 1050bd4cd745SDan Williams if (!buf || !nfit_res) 10516bc75619SDan Williams goto err; 10526bc75619SDan Williams rc = devm_add_action(dev, release_nfit_res, nfit_res); 10536bc75619SDan Williams if (rc) 10546bc75619SDan Williams goto err; 10556bc75619SDan Williams INIT_LIST_HEAD(&nfit_res->list); 10566bc75619SDan Williams memset(buf, 0, size); 10576bc75619SDan Williams nfit_res->dev = dev; 10586bc75619SDan Williams nfit_res->buf = buf; 1059bd4cd745SDan Williams nfit_res->res.start = *dma; 1060bd4cd745SDan Williams nfit_res->res.end = *dma + size - 1; 1061bd4cd745SDan Williams nfit_res->res.name = "NFIT"; 1062bd4cd745SDan Williams spin_lock_init(&nfit_res->lock); 1063bd4cd745SDan Williams INIT_LIST_HEAD(&nfit_res->requests); 10646bc75619SDan Williams spin_lock(&nfit_test_lock); 10656bc75619SDan Williams list_add(&nfit_res->list, &t->resources); 10666bc75619SDan Williams spin_unlock(&nfit_test_lock); 10676bc75619SDan Williams 10686bc75619SDan Williams return nfit_res->buf; 10696bc75619SDan Williams err: 1070ee8520feSDan Williams if (buf) 10716bc75619SDan Williams vfree(buf); 10726bc75619SDan Williams kfree(nfit_res); 10736bc75619SDan Williams return NULL; 10746bc75619SDan Williams } 10756bc75619SDan Williams 10766bc75619SDan Williams static void *test_alloc(struct nfit_test *t, size_t size, dma_addr_t *dma) 10776bc75619SDan Williams { 10786bc75619SDan Williams void *buf = vmalloc(size); 10796bc75619SDan Williams 10806bc75619SDan Williams *dma = (unsigned long) buf; 10816bc75619SDan Williams return __test_alloc(t, size, dma, buf); 10826bc75619SDan Williams } 10836bc75619SDan Williams 10846bc75619SDan Williams static struct nfit_test_resource *nfit_test_lookup(resource_size_t addr) 10856bc75619SDan Williams { 10866bc75619SDan Williams int i; 10876bc75619SDan Williams 10886bc75619SDan Williams for (i = 0; i < ARRAY_SIZE(instances); i++) { 10896bc75619SDan Williams struct nfit_test_resource *n, *nfit_res = NULL; 10906bc75619SDan Williams struct nfit_test *t = instances[i]; 10916bc75619SDan Williams 10926bc75619SDan Williams if (!t) 10936bc75619SDan Williams continue; 10946bc75619SDan Williams spin_lock(&nfit_test_lock); 10956bc75619SDan Williams list_for_each_entry(n, &t->resources, list) { 1096bd4cd745SDan Williams if (addr >= n->res.start && (addr < n->res.start 1097bd4cd745SDan Williams + resource_size(&n->res))) { 10986bc75619SDan Williams nfit_res = n; 10996bc75619SDan Williams break; 11006bc75619SDan Williams } else if (addr >= (unsigned long) n->buf 11016bc75619SDan Williams && (addr < (unsigned long) n->buf 1102bd4cd745SDan Williams + resource_size(&n->res))) { 11036bc75619SDan Williams nfit_res = n; 11046bc75619SDan Williams break; 11056bc75619SDan Williams } 11066bc75619SDan Williams } 11076bc75619SDan Williams spin_unlock(&nfit_test_lock); 11086bc75619SDan Williams if (nfit_res) 11096bc75619SDan Williams return nfit_res; 11106bc75619SDan Williams } 11116bc75619SDan Williams 11126bc75619SDan Williams return NULL; 11136bc75619SDan Williams } 11146bc75619SDan Williams 1115f471f1a7SDan Williams static int ars_state_init(struct device *dev, struct ars_state *ars_state) 1116f471f1a7SDan Williams { 11179fb1a190SDave Jiang /* for testing, only store up to n records that fit within 4k */ 1118f471f1a7SDan Williams ars_state->ars_status = devm_kzalloc(dev, 11199fb1a190SDave Jiang sizeof(struct nd_cmd_ars_status) + SZ_4K, GFP_KERNEL); 1120f471f1a7SDan Williams if (!ars_state->ars_status) 1121f471f1a7SDan Williams return -ENOMEM; 1122f471f1a7SDan Williams spin_lock_init(&ars_state->lock); 1123f471f1a7SDan Williams return 0; 1124f471f1a7SDan Williams } 1125f471f1a7SDan Williams 1126231bf117SDan Williams static void put_dimms(void *data) 1127231bf117SDan Williams { 1128231bf117SDan Williams struct device **dimm_dev = data; 1129231bf117SDan Williams int i; 1130231bf117SDan Williams 1131231bf117SDan Williams for (i = 0; i < NUM_DCR; i++) 1132231bf117SDan Williams if (dimm_dev[i]) 1133231bf117SDan Williams device_unregister(dimm_dev[i]); 1134231bf117SDan Williams } 1135231bf117SDan Williams 1136231bf117SDan Williams static struct class *nfit_test_dimm; 1137231bf117SDan Williams 113873606afdSDan Williams static int dimm_name_to_id(struct device *dev) 113973606afdSDan Williams { 114073606afdSDan Williams int dimm; 114173606afdSDan Williams 114273606afdSDan Williams if (sscanf(dev_name(dev), "test_dimm%d", &dimm) != 1 114373606afdSDan Williams || dimm >= NUM_DCR || dimm < 0) 114473606afdSDan Williams return -ENXIO; 114573606afdSDan Williams return dimm; 114673606afdSDan Williams } 114773606afdSDan Williams 114873606afdSDan Williams 114973606afdSDan Williams static ssize_t handle_show(struct device *dev, struct device_attribute *attr, 115073606afdSDan Williams char *buf) 115173606afdSDan Williams { 115273606afdSDan Williams int dimm = dimm_name_to_id(dev); 115373606afdSDan Williams 115473606afdSDan Williams if (dimm < 0) 115573606afdSDan Williams return dimm; 115673606afdSDan Williams 115773606afdSDan Williams return sprintf(buf, "%#x", handle[dimm]); 115873606afdSDan Williams } 115973606afdSDan Williams DEVICE_ATTR_RO(handle); 116073606afdSDan Williams 116173606afdSDan Williams static ssize_t fail_cmd_show(struct device *dev, struct device_attribute *attr, 116273606afdSDan Williams char *buf) 116373606afdSDan Williams { 116473606afdSDan Williams int dimm = dimm_name_to_id(dev); 116573606afdSDan Williams 116673606afdSDan Williams if (dimm < 0) 116773606afdSDan Williams return dimm; 116873606afdSDan Williams 116973606afdSDan Williams return sprintf(buf, "%#lx\n", dimm_fail_cmd_flags[dimm]); 117073606afdSDan Williams } 117173606afdSDan Williams 117273606afdSDan Williams static ssize_t fail_cmd_store(struct device *dev, struct device_attribute *attr, 117373606afdSDan Williams const char *buf, size_t size) 117473606afdSDan Williams { 117573606afdSDan Williams int dimm = dimm_name_to_id(dev); 117673606afdSDan Williams unsigned long val; 117773606afdSDan Williams ssize_t rc; 117873606afdSDan Williams 117973606afdSDan Williams if (dimm < 0) 118073606afdSDan Williams return dimm; 118173606afdSDan Williams 118273606afdSDan Williams rc = kstrtol(buf, 0, &val); 118373606afdSDan Williams if (rc) 118473606afdSDan Williams return rc; 118573606afdSDan Williams 118673606afdSDan Williams dimm_fail_cmd_flags[dimm] = val; 118773606afdSDan Williams return size; 118873606afdSDan Williams } 118973606afdSDan Williams static DEVICE_ATTR_RW(fail_cmd); 119073606afdSDan Williams 119173606afdSDan Williams static struct attribute *nfit_test_dimm_attributes[] = { 119273606afdSDan Williams &dev_attr_fail_cmd.attr, 119373606afdSDan Williams &dev_attr_handle.attr, 119473606afdSDan Williams NULL, 119573606afdSDan Williams }; 119673606afdSDan Williams 119773606afdSDan Williams static struct attribute_group nfit_test_dimm_attribute_group = { 119873606afdSDan Williams .attrs = nfit_test_dimm_attributes, 119973606afdSDan Williams }; 120073606afdSDan Williams 120173606afdSDan Williams static const struct attribute_group *nfit_test_dimm_attribute_groups[] = { 120273606afdSDan Williams &nfit_test_dimm_attribute_group, 120373606afdSDan Williams NULL, 120473606afdSDan Williams }; 120573606afdSDan Williams 1206ed07c433SDan Williams static void smart_init(struct nfit_test *t) 1207ed07c433SDan Williams { 1208ed07c433SDan Williams int i; 1209ed07c433SDan Williams const struct nd_intel_smart_threshold smart_t_data = { 1210ed07c433SDan Williams .alarm_control = ND_INTEL_SMART_SPARE_TRIP 1211ed07c433SDan Williams | ND_INTEL_SMART_TEMP_TRIP, 1212ed07c433SDan Williams .media_temperature = 40 * 16, 1213ed07c433SDan Williams .ctrl_temperature = 30 * 16, 1214ed07c433SDan Williams .spares = 5, 1215ed07c433SDan Williams }; 1216ed07c433SDan Williams const struct nd_intel_smart smart_data = { 1217ed07c433SDan Williams .flags = ND_INTEL_SMART_HEALTH_VALID 1218ed07c433SDan Williams | ND_INTEL_SMART_SPARES_VALID 1219ed07c433SDan Williams | ND_INTEL_SMART_ALARM_VALID 1220ed07c433SDan Williams | ND_INTEL_SMART_USED_VALID 1221ed07c433SDan Williams | ND_INTEL_SMART_SHUTDOWN_VALID 1222ed07c433SDan Williams | ND_INTEL_SMART_MTEMP_VALID, 1223ed07c433SDan Williams .health = ND_INTEL_SMART_NON_CRITICAL_HEALTH, 1224ed07c433SDan Williams .media_temperature = 23 * 16, 1225ed07c433SDan Williams .ctrl_temperature = 30 * 16, 1226ed07c433SDan Williams .pmic_temperature = 40 * 16, 1227ed07c433SDan Williams .spares = 75, 1228ed07c433SDan Williams .alarm_flags = ND_INTEL_SMART_SPARE_TRIP 1229ed07c433SDan Williams | ND_INTEL_SMART_TEMP_TRIP, 1230ed07c433SDan Williams .ait_status = 1, 1231ed07c433SDan Williams .life_used = 5, 1232ed07c433SDan Williams .shutdown_state = 0, 1233ed07c433SDan Williams .vendor_size = 0, 1234ed07c433SDan Williams .shutdown_count = 100, 1235ed07c433SDan Williams }; 1236ed07c433SDan Williams 1237ed07c433SDan Williams for (i = 0; i < t->num_dcr; i++) { 1238ed07c433SDan Williams memcpy(&t->smart[i], &smart_data, sizeof(smart_data)); 1239ed07c433SDan Williams memcpy(&t->smart_threshold[i], &smart_t_data, 1240ed07c433SDan Williams sizeof(smart_t_data)); 1241ed07c433SDan Williams } 1242ed07c433SDan Williams } 1243ed07c433SDan Williams 12446bc75619SDan Williams static int nfit_test0_alloc(struct nfit_test *t) 12456bc75619SDan Williams { 12466b577c9dSLinda Knippers size_t nfit_size = sizeof(struct acpi_nfit_system_address) * NUM_SPA 12476bc75619SDan Williams + sizeof(struct acpi_nfit_memory_map) * NUM_MEM 12486bc75619SDan Williams + sizeof(struct acpi_nfit_control_region) * NUM_DCR 12493b87356fSDan Williams + offsetof(struct acpi_nfit_control_region, 12503b87356fSDan Williams window_size) * NUM_DCR 12519d27a87eSDan Williams + sizeof(struct acpi_nfit_data_region) * NUM_BDW 125285d3fa02SDan Williams + (sizeof(struct acpi_nfit_flush_address) 125385d3fa02SDan Williams + sizeof(u64) * NUM_HINTS) * NUM_DCR; 12546bc75619SDan Williams int i; 12556bc75619SDan Williams 12566bc75619SDan Williams t->nfit_buf = test_alloc(t, nfit_size, &t->nfit_dma); 12576bc75619SDan Williams if (!t->nfit_buf) 12586bc75619SDan Williams return -ENOMEM; 12596bc75619SDan Williams t->nfit_size = nfit_size; 12606bc75619SDan Williams 1261ee8520feSDan Williams t->spa_set[0] = test_alloc(t, SPA0_SIZE, &t->spa_set_dma[0]); 12626bc75619SDan Williams if (!t->spa_set[0]) 12636bc75619SDan Williams return -ENOMEM; 12646bc75619SDan Williams 1265ee8520feSDan Williams t->spa_set[1] = test_alloc(t, SPA1_SIZE, &t->spa_set_dma[1]); 12666bc75619SDan Williams if (!t->spa_set[1]) 12676bc75619SDan Williams return -ENOMEM; 12686bc75619SDan Williams 1269ee8520feSDan Williams t->spa_set[2] = test_alloc(t, SPA0_SIZE, &t->spa_set_dma[2]); 127020985164SVishal Verma if (!t->spa_set[2]) 127120985164SVishal Verma return -ENOMEM; 127220985164SVishal Verma 1273dafb1048SDan Williams for (i = 0; i < t->num_dcr; i++) { 12746bc75619SDan Williams t->dimm[i] = test_alloc(t, DIMM_SIZE, &t->dimm_dma[i]); 12756bc75619SDan Williams if (!t->dimm[i]) 12766bc75619SDan Williams return -ENOMEM; 12776bc75619SDan Williams 12786bc75619SDan Williams t->label[i] = test_alloc(t, LABEL_SIZE, &t->label_dma[i]); 12796bc75619SDan Williams if (!t->label[i]) 12806bc75619SDan Williams return -ENOMEM; 12816bc75619SDan Williams sprintf(t->label[i], "label%d", i); 12829d27a87eSDan Williams 12839d15ce9cSDan Williams t->flush[i] = test_alloc(t, max(PAGE_SIZE, 12849d15ce9cSDan Williams sizeof(u64) * NUM_HINTS), 128585d3fa02SDan Williams &t->flush_dma[i]); 12869d27a87eSDan Williams if (!t->flush[i]) 12879d27a87eSDan Williams return -ENOMEM; 12886bc75619SDan Williams } 12896bc75619SDan Williams 1290dafb1048SDan Williams for (i = 0; i < t->num_dcr; i++) { 12916bc75619SDan Williams t->dcr[i] = test_alloc(t, LABEL_SIZE, &t->dcr_dma[i]); 12926bc75619SDan Williams if (!t->dcr[i]) 12936bc75619SDan Williams return -ENOMEM; 12946bc75619SDan Williams } 12956bc75619SDan Williams 1296c14a868aSDan Williams t->_fit = test_alloc(t, sizeof(union acpi_object **), &t->_fit_dma); 1297c14a868aSDan Williams if (!t->_fit) 1298c14a868aSDan Williams return -ENOMEM; 1299c14a868aSDan Williams 1300231bf117SDan Williams if (devm_add_action_or_reset(&t->pdev.dev, put_dimms, t->dimm_dev)) 1301231bf117SDan Williams return -ENOMEM; 1302231bf117SDan Williams for (i = 0; i < NUM_DCR; i++) { 130373606afdSDan Williams t->dimm_dev[i] = device_create_with_groups(nfit_test_dimm, 130473606afdSDan Williams &t->pdev.dev, 0, NULL, 130573606afdSDan Williams nfit_test_dimm_attribute_groups, 130673606afdSDan Williams "test_dimm%d", i); 1307231bf117SDan Williams if (!t->dimm_dev[i]) 1308231bf117SDan Williams return -ENOMEM; 1309231bf117SDan Williams } 1310231bf117SDan Williams 1311ed07c433SDan Williams smart_init(t); 1312f471f1a7SDan Williams return ars_state_init(&t->pdev.dev, &t->ars_state); 13136bc75619SDan Williams } 13146bc75619SDan Williams 13156bc75619SDan Williams static int nfit_test1_alloc(struct nfit_test *t) 13166bc75619SDan Williams { 13177bfe97c7SDan Williams size_t nfit_size = sizeof(struct acpi_nfit_system_address) * 2 1318ac40b675SDan Williams + sizeof(struct acpi_nfit_memory_map) * 2 1319ac40b675SDan Williams + offsetof(struct acpi_nfit_control_region, window_size) * 2; 1320dafb1048SDan Williams int i; 13216bc75619SDan Williams 13226bc75619SDan Williams t->nfit_buf = test_alloc(t, nfit_size, &t->nfit_dma); 13236bc75619SDan Williams if (!t->nfit_buf) 13246bc75619SDan Williams return -ENOMEM; 13256bc75619SDan Williams t->nfit_size = nfit_size; 13266bc75619SDan Williams 1327ee8520feSDan Williams t->spa_set[0] = test_alloc(t, SPA2_SIZE, &t->spa_set_dma[0]); 13286bc75619SDan Williams if (!t->spa_set[0]) 13296bc75619SDan Williams return -ENOMEM; 13306bc75619SDan Williams 1331dafb1048SDan Williams for (i = 0; i < t->num_dcr; i++) { 1332dafb1048SDan Williams t->label[i] = test_alloc(t, LABEL_SIZE, &t->label_dma[i]); 1333dafb1048SDan Williams if (!t->label[i]) 1334dafb1048SDan Williams return -ENOMEM; 1335dafb1048SDan Williams sprintf(t->label[i], "label%d", i); 1336dafb1048SDan Williams } 1337dafb1048SDan Williams 13387bfe97c7SDan Williams t->spa_set[1] = test_alloc(t, SPA_VCD_SIZE, &t->spa_set_dma[1]); 13397bfe97c7SDan Williams if (!t->spa_set[1]) 13407bfe97c7SDan Williams return -ENOMEM; 13417bfe97c7SDan Williams 1342ed07c433SDan Williams smart_init(t); 1343f471f1a7SDan Williams return ars_state_init(&t->pdev.dev, &t->ars_state); 13446bc75619SDan Williams } 13456bc75619SDan Williams 13465dc68e55SDan Williams static void dcr_common_init(struct acpi_nfit_control_region *dcr) 13475dc68e55SDan Williams { 13485dc68e55SDan Williams dcr->vendor_id = 0xabcd; 13495dc68e55SDan Williams dcr->device_id = 0; 13505dc68e55SDan Williams dcr->revision_id = 1; 13515dc68e55SDan Williams dcr->valid_fields = 1; 13525dc68e55SDan Williams dcr->manufacturing_location = 0xa; 13535dc68e55SDan Williams dcr->manufacturing_date = cpu_to_be16(2016); 13545dc68e55SDan Williams } 13555dc68e55SDan Williams 13566bc75619SDan Williams static void nfit_test0_setup(struct nfit_test *t) 13576bc75619SDan Williams { 135885d3fa02SDan Williams const int flush_hint_size = sizeof(struct acpi_nfit_flush_address) 135985d3fa02SDan Williams + (sizeof(u64) * NUM_HINTS); 13606bc75619SDan Williams struct acpi_nfit_desc *acpi_desc; 13616bc75619SDan Williams struct acpi_nfit_memory_map *memdev; 13626bc75619SDan Williams void *nfit_buf = t->nfit_buf; 13636bc75619SDan Williams struct acpi_nfit_system_address *spa; 13646bc75619SDan Williams struct acpi_nfit_control_region *dcr; 13656bc75619SDan Williams struct acpi_nfit_data_region *bdw; 13669d27a87eSDan Williams struct acpi_nfit_flush_address *flush; 136785d3fa02SDan Williams unsigned int offset, i; 13686bc75619SDan Williams 13696bc75619SDan Williams /* 13706bc75619SDan Williams * spa0 (interleave first half of dimm0 and dimm1, note storage 13716bc75619SDan Williams * does not actually alias the related block-data-window 13726bc75619SDan Williams * regions) 13736bc75619SDan Williams */ 13746b577c9dSLinda Knippers spa = nfit_buf; 13756bc75619SDan Williams spa->header.type = ACPI_NFIT_TYPE_SYSTEM_ADDRESS; 13766bc75619SDan Williams spa->header.length = sizeof(*spa); 13776bc75619SDan Williams memcpy(spa->range_guid, to_nfit_uuid(NFIT_SPA_PM), 16); 13786bc75619SDan Williams spa->range_index = 0+1; 13796bc75619SDan Williams spa->address = t->spa_set_dma[0]; 13806bc75619SDan Williams spa->length = SPA0_SIZE; 13816bc75619SDan Williams 13826bc75619SDan Williams /* 13836bc75619SDan Williams * spa1 (interleave last half of the 4 DIMMS, note storage 13846bc75619SDan Williams * does not actually alias the related block-data-window 13856bc75619SDan Williams * regions) 13866bc75619SDan Williams */ 13876b577c9dSLinda Knippers spa = nfit_buf + sizeof(*spa); 13886bc75619SDan Williams spa->header.type = ACPI_NFIT_TYPE_SYSTEM_ADDRESS; 13896bc75619SDan Williams spa->header.length = sizeof(*spa); 13906bc75619SDan Williams memcpy(spa->range_guid, to_nfit_uuid(NFIT_SPA_PM), 16); 13916bc75619SDan Williams spa->range_index = 1+1; 13926bc75619SDan Williams spa->address = t->spa_set_dma[1]; 13936bc75619SDan Williams spa->length = SPA1_SIZE; 13946bc75619SDan Williams 13956bc75619SDan Williams /* spa2 (dcr0) dimm0 */ 13966b577c9dSLinda Knippers spa = nfit_buf + sizeof(*spa) * 2; 13976bc75619SDan Williams spa->header.type = ACPI_NFIT_TYPE_SYSTEM_ADDRESS; 13986bc75619SDan Williams spa->header.length = sizeof(*spa); 13996bc75619SDan Williams memcpy(spa->range_guid, to_nfit_uuid(NFIT_SPA_DCR), 16); 14006bc75619SDan Williams spa->range_index = 2+1; 14016bc75619SDan Williams spa->address = t->dcr_dma[0]; 14026bc75619SDan Williams spa->length = DCR_SIZE; 14036bc75619SDan Williams 14046bc75619SDan Williams /* spa3 (dcr1) dimm1 */ 14056b577c9dSLinda Knippers spa = nfit_buf + sizeof(*spa) * 3; 14066bc75619SDan Williams spa->header.type = ACPI_NFIT_TYPE_SYSTEM_ADDRESS; 14076bc75619SDan Williams spa->header.length = sizeof(*spa); 14086bc75619SDan Williams memcpy(spa->range_guid, to_nfit_uuid(NFIT_SPA_DCR), 16); 14096bc75619SDan Williams spa->range_index = 3+1; 14106bc75619SDan Williams spa->address = t->dcr_dma[1]; 14116bc75619SDan Williams spa->length = DCR_SIZE; 14126bc75619SDan Williams 14136bc75619SDan Williams /* spa4 (dcr2) dimm2 */ 14146b577c9dSLinda Knippers spa = nfit_buf + sizeof(*spa) * 4; 14156bc75619SDan Williams spa->header.type = ACPI_NFIT_TYPE_SYSTEM_ADDRESS; 14166bc75619SDan Williams spa->header.length = sizeof(*spa); 14176bc75619SDan Williams memcpy(spa->range_guid, to_nfit_uuid(NFIT_SPA_DCR), 16); 14186bc75619SDan Williams spa->range_index = 4+1; 14196bc75619SDan Williams spa->address = t->dcr_dma[2]; 14206bc75619SDan Williams spa->length = DCR_SIZE; 14216bc75619SDan Williams 14226bc75619SDan Williams /* spa5 (dcr3) dimm3 */ 14236b577c9dSLinda Knippers spa = nfit_buf + sizeof(*spa) * 5; 14246bc75619SDan Williams spa->header.type = ACPI_NFIT_TYPE_SYSTEM_ADDRESS; 14256bc75619SDan Williams spa->header.length = sizeof(*spa); 14266bc75619SDan Williams memcpy(spa->range_guid, to_nfit_uuid(NFIT_SPA_DCR), 16); 14276bc75619SDan Williams spa->range_index = 5+1; 14286bc75619SDan Williams spa->address = t->dcr_dma[3]; 14296bc75619SDan Williams spa->length = DCR_SIZE; 14306bc75619SDan Williams 14316bc75619SDan Williams /* spa6 (bdw for dcr0) dimm0 */ 14326b577c9dSLinda Knippers spa = nfit_buf + sizeof(*spa) * 6; 14336bc75619SDan Williams spa->header.type = ACPI_NFIT_TYPE_SYSTEM_ADDRESS; 14346bc75619SDan Williams spa->header.length = sizeof(*spa); 14356bc75619SDan Williams memcpy(spa->range_guid, to_nfit_uuid(NFIT_SPA_BDW), 16); 14366bc75619SDan Williams spa->range_index = 6+1; 14376bc75619SDan Williams spa->address = t->dimm_dma[0]; 14386bc75619SDan Williams spa->length = DIMM_SIZE; 14396bc75619SDan Williams 14406bc75619SDan Williams /* spa7 (bdw for dcr1) dimm1 */ 14416b577c9dSLinda Knippers spa = nfit_buf + sizeof(*spa) * 7; 14426bc75619SDan Williams spa->header.type = ACPI_NFIT_TYPE_SYSTEM_ADDRESS; 14436bc75619SDan Williams spa->header.length = sizeof(*spa); 14446bc75619SDan Williams memcpy(spa->range_guid, to_nfit_uuid(NFIT_SPA_BDW), 16); 14456bc75619SDan Williams spa->range_index = 7+1; 14466bc75619SDan Williams spa->address = t->dimm_dma[1]; 14476bc75619SDan Williams spa->length = DIMM_SIZE; 14486bc75619SDan Williams 14496bc75619SDan Williams /* spa8 (bdw for dcr2) dimm2 */ 14506b577c9dSLinda Knippers spa = nfit_buf + sizeof(*spa) * 8; 14516bc75619SDan Williams spa->header.type = ACPI_NFIT_TYPE_SYSTEM_ADDRESS; 14526bc75619SDan Williams spa->header.length = sizeof(*spa); 14536bc75619SDan Williams memcpy(spa->range_guid, to_nfit_uuid(NFIT_SPA_BDW), 16); 14546bc75619SDan Williams spa->range_index = 8+1; 14556bc75619SDan Williams spa->address = t->dimm_dma[2]; 14566bc75619SDan Williams spa->length = DIMM_SIZE; 14576bc75619SDan Williams 14586bc75619SDan Williams /* spa9 (bdw for dcr3) dimm3 */ 14596b577c9dSLinda Knippers spa = nfit_buf + sizeof(*spa) * 9; 14606bc75619SDan Williams spa->header.type = ACPI_NFIT_TYPE_SYSTEM_ADDRESS; 14616bc75619SDan Williams spa->header.length = sizeof(*spa); 14626bc75619SDan Williams memcpy(spa->range_guid, to_nfit_uuid(NFIT_SPA_BDW), 16); 14636bc75619SDan Williams spa->range_index = 9+1; 14646bc75619SDan Williams spa->address = t->dimm_dma[3]; 14656bc75619SDan Williams spa->length = DIMM_SIZE; 14666bc75619SDan Williams 14676b577c9dSLinda Knippers offset = sizeof(*spa) * 10; 14686bc75619SDan Williams /* mem-region0 (spa0, dimm0) */ 14696bc75619SDan Williams memdev = nfit_buf + offset; 14706bc75619SDan Williams memdev->header.type = ACPI_NFIT_TYPE_MEMORY_MAP; 14716bc75619SDan Williams memdev->header.length = sizeof(*memdev); 14726bc75619SDan Williams memdev->device_handle = handle[0]; 14736bc75619SDan Williams memdev->physical_id = 0; 14746bc75619SDan Williams memdev->region_id = 0; 14756bc75619SDan Williams memdev->range_index = 0+1; 14763b87356fSDan Williams memdev->region_index = 4+1; 14776bc75619SDan Williams memdev->region_size = SPA0_SIZE/2; 1478df06a2d5SDan Williams memdev->region_offset = 1; 14796bc75619SDan Williams memdev->address = 0; 14806bc75619SDan Williams memdev->interleave_index = 0; 14816bc75619SDan Williams memdev->interleave_ways = 2; 14826bc75619SDan Williams 14836bc75619SDan Williams /* mem-region1 (spa0, dimm1) */ 14846bc75619SDan Williams memdev = nfit_buf + offset + sizeof(struct acpi_nfit_memory_map); 14856bc75619SDan Williams memdev->header.type = ACPI_NFIT_TYPE_MEMORY_MAP; 14866bc75619SDan Williams memdev->header.length = sizeof(*memdev); 14876bc75619SDan Williams memdev->device_handle = handle[1]; 14886bc75619SDan Williams memdev->physical_id = 1; 14896bc75619SDan Williams memdev->region_id = 0; 14906bc75619SDan Williams memdev->range_index = 0+1; 14913b87356fSDan Williams memdev->region_index = 5+1; 14926bc75619SDan Williams memdev->region_size = SPA0_SIZE/2; 1493df06a2d5SDan Williams memdev->region_offset = (1 << 8); 14946bc75619SDan Williams memdev->address = 0; 14956bc75619SDan Williams memdev->interleave_index = 0; 14966bc75619SDan Williams memdev->interleave_ways = 2; 1497ac40b675SDan Williams memdev->flags = ACPI_NFIT_MEM_HEALTH_ENABLED; 14986bc75619SDan Williams 14996bc75619SDan Williams /* mem-region2 (spa1, dimm0) */ 15006bc75619SDan Williams memdev = nfit_buf + offset + sizeof(struct acpi_nfit_memory_map) * 2; 15016bc75619SDan Williams memdev->header.type = ACPI_NFIT_TYPE_MEMORY_MAP; 15026bc75619SDan Williams memdev->header.length = sizeof(*memdev); 15036bc75619SDan Williams memdev->device_handle = handle[0]; 15046bc75619SDan Williams memdev->physical_id = 0; 15056bc75619SDan Williams memdev->region_id = 1; 15066bc75619SDan Williams memdev->range_index = 1+1; 15073b87356fSDan Williams memdev->region_index = 4+1; 15086bc75619SDan Williams memdev->region_size = SPA1_SIZE/4; 1509df06a2d5SDan Williams memdev->region_offset = (1 << 16); 15106bc75619SDan Williams memdev->address = SPA0_SIZE/2; 15116bc75619SDan Williams memdev->interleave_index = 0; 15126bc75619SDan Williams memdev->interleave_ways = 4; 1513ac40b675SDan Williams memdev->flags = ACPI_NFIT_MEM_HEALTH_ENABLED; 15146bc75619SDan Williams 15156bc75619SDan Williams /* mem-region3 (spa1, dimm1) */ 15166bc75619SDan Williams memdev = nfit_buf + offset + sizeof(struct acpi_nfit_memory_map) * 3; 15176bc75619SDan Williams memdev->header.type = ACPI_NFIT_TYPE_MEMORY_MAP; 15186bc75619SDan Williams memdev->header.length = sizeof(*memdev); 15196bc75619SDan Williams memdev->device_handle = handle[1]; 15206bc75619SDan Williams memdev->physical_id = 1; 15216bc75619SDan Williams memdev->region_id = 1; 15226bc75619SDan Williams memdev->range_index = 1+1; 15233b87356fSDan Williams memdev->region_index = 5+1; 15246bc75619SDan Williams memdev->region_size = SPA1_SIZE/4; 1525df06a2d5SDan Williams memdev->region_offset = (1 << 24); 15266bc75619SDan Williams memdev->address = SPA0_SIZE/2; 15276bc75619SDan Williams memdev->interleave_index = 0; 15286bc75619SDan Williams memdev->interleave_ways = 4; 15296bc75619SDan Williams 15306bc75619SDan Williams /* mem-region4 (spa1, dimm2) */ 15316bc75619SDan Williams memdev = nfit_buf + offset + sizeof(struct acpi_nfit_memory_map) * 4; 15326bc75619SDan Williams memdev->header.type = ACPI_NFIT_TYPE_MEMORY_MAP; 15336bc75619SDan Williams memdev->header.length = sizeof(*memdev); 15346bc75619SDan Williams memdev->device_handle = handle[2]; 15356bc75619SDan Williams memdev->physical_id = 2; 15366bc75619SDan Williams memdev->region_id = 0; 15376bc75619SDan Williams memdev->range_index = 1+1; 15383b87356fSDan Williams memdev->region_index = 6+1; 15396bc75619SDan Williams memdev->region_size = SPA1_SIZE/4; 1540df06a2d5SDan Williams memdev->region_offset = (1ULL << 32); 15416bc75619SDan Williams memdev->address = SPA0_SIZE/2; 15426bc75619SDan Williams memdev->interleave_index = 0; 15436bc75619SDan Williams memdev->interleave_ways = 4; 1544ac40b675SDan Williams memdev->flags = ACPI_NFIT_MEM_HEALTH_ENABLED; 15456bc75619SDan Williams 15466bc75619SDan Williams /* mem-region5 (spa1, dimm3) */ 15476bc75619SDan Williams memdev = nfit_buf + offset + sizeof(struct acpi_nfit_memory_map) * 5; 15486bc75619SDan Williams memdev->header.type = ACPI_NFIT_TYPE_MEMORY_MAP; 15496bc75619SDan Williams memdev->header.length = sizeof(*memdev); 15506bc75619SDan Williams memdev->device_handle = handle[3]; 15516bc75619SDan Williams memdev->physical_id = 3; 15526bc75619SDan Williams memdev->region_id = 0; 15536bc75619SDan Williams memdev->range_index = 1+1; 15543b87356fSDan Williams memdev->region_index = 7+1; 15556bc75619SDan Williams memdev->region_size = SPA1_SIZE/4; 1556df06a2d5SDan Williams memdev->region_offset = (1ULL << 40); 15576bc75619SDan Williams memdev->address = SPA0_SIZE/2; 15586bc75619SDan Williams memdev->interleave_index = 0; 15596bc75619SDan Williams memdev->interleave_ways = 4; 15606bc75619SDan Williams 15616bc75619SDan Williams /* mem-region6 (spa/dcr0, dimm0) */ 15626bc75619SDan Williams memdev = nfit_buf + offset + sizeof(struct acpi_nfit_memory_map) * 6; 15636bc75619SDan Williams memdev->header.type = ACPI_NFIT_TYPE_MEMORY_MAP; 15646bc75619SDan Williams memdev->header.length = sizeof(*memdev); 15656bc75619SDan Williams memdev->device_handle = handle[0]; 15666bc75619SDan Williams memdev->physical_id = 0; 15676bc75619SDan Williams memdev->region_id = 0; 15686bc75619SDan Williams memdev->range_index = 2+1; 15696bc75619SDan Williams memdev->region_index = 0+1; 15706bc75619SDan Williams memdev->region_size = 0; 15716bc75619SDan Williams memdev->region_offset = 0; 15726bc75619SDan Williams memdev->address = 0; 15736bc75619SDan Williams memdev->interleave_index = 0; 15746bc75619SDan Williams memdev->interleave_ways = 1; 15756bc75619SDan Williams 15766bc75619SDan Williams /* mem-region7 (spa/dcr1, dimm1) */ 15776bc75619SDan Williams memdev = nfit_buf + offset + sizeof(struct acpi_nfit_memory_map) * 7; 15786bc75619SDan Williams memdev->header.type = ACPI_NFIT_TYPE_MEMORY_MAP; 15796bc75619SDan Williams memdev->header.length = sizeof(*memdev); 15806bc75619SDan Williams memdev->device_handle = handle[1]; 15816bc75619SDan Williams memdev->physical_id = 1; 15826bc75619SDan Williams memdev->region_id = 0; 15836bc75619SDan Williams memdev->range_index = 3+1; 15846bc75619SDan Williams memdev->region_index = 1+1; 15856bc75619SDan Williams memdev->region_size = 0; 15866bc75619SDan Williams memdev->region_offset = 0; 15876bc75619SDan Williams memdev->address = 0; 15886bc75619SDan Williams memdev->interleave_index = 0; 15896bc75619SDan Williams memdev->interleave_ways = 1; 15906bc75619SDan Williams 15916bc75619SDan Williams /* mem-region8 (spa/dcr2, dimm2) */ 15926bc75619SDan Williams memdev = nfit_buf + offset + sizeof(struct acpi_nfit_memory_map) * 8; 15936bc75619SDan Williams memdev->header.type = ACPI_NFIT_TYPE_MEMORY_MAP; 15946bc75619SDan Williams memdev->header.length = sizeof(*memdev); 15956bc75619SDan Williams memdev->device_handle = handle[2]; 15966bc75619SDan Williams memdev->physical_id = 2; 15976bc75619SDan Williams memdev->region_id = 0; 15986bc75619SDan Williams memdev->range_index = 4+1; 15996bc75619SDan Williams memdev->region_index = 2+1; 16006bc75619SDan Williams memdev->region_size = 0; 16016bc75619SDan Williams memdev->region_offset = 0; 16026bc75619SDan Williams memdev->address = 0; 16036bc75619SDan Williams memdev->interleave_index = 0; 16046bc75619SDan Williams memdev->interleave_ways = 1; 16056bc75619SDan Williams 16066bc75619SDan Williams /* mem-region9 (spa/dcr3, dimm3) */ 16076bc75619SDan Williams memdev = nfit_buf + offset + sizeof(struct acpi_nfit_memory_map) * 9; 16086bc75619SDan Williams memdev->header.type = ACPI_NFIT_TYPE_MEMORY_MAP; 16096bc75619SDan Williams memdev->header.length = sizeof(*memdev); 16106bc75619SDan Williams memdev->device_handle = handle[3]; 16116bc75619SDan Williams memdev->physical_id = 3; 16126bc75619SDan Williams memdev->region_id = 0; 16136bc75619SDan Williams memdev->range_index = 5+1; 16146bc75619SDan Williams memdev->region_index = 3+1; 16156bc75619SDan Williams memdev->region_size = 0; 16166bc75619SDan Williams memdev->region_offset = 0; 16176bc75619SDan Williams memdev->address = 0; 16186bc75619SDan Williams memdev->interleave_index = 0; 16196bc75619SDan Williams memdev->interleave_ways = 1; 16206bc75619SDan Williams 16216bc75619SDan Williams /* mem-region10 (spa/bdw0, dimm0) */ 16226bc75619SDan Williams memdev = nfit_buf + offset + sizeof(struct acpi_nfit_memory_map) * 10; 16236bc75619SDan Williams memdev->header.type = ACPI_NFIT_TYPE_MEMORY_MAP; 16246bc75619SDan Williams memdev->header.length = sizeof(*memdev); 16256bc75619SDan Williams memdev->device_handle = handle[0]; 16266bc75619SDan Williams memdev->physical_id = 0; 16276bc75619SDan Williams memdev->region_id = 0; 16286bc75619SDan Williams memdev->range_index = 6+1; 16296bc75619SDan Williams memdev->region_index = 0+1; 16306bc75619SDan Williams memdev->region_size = 0; 16316bc75619SDan Williams memdev->region_offset = 0; 16326bc75619SDan Williams memdev->address = 0; 16336bc75619SDan Williams memdev->interleave_index = 0; 16346bc75619SDan Williams memdev->interleave_ways = 1; 16356bc75619SDan Williams 16366bc75619SDan Williams /* mem-region11 (spa/bdw1, dimm1) */ 16376bc75619SDan Williams memdev = nfit_buf + offset + sizeof(struct acpi_nfit_memory_map) * 11; 16386bc75619SDan Williams memdev->header.type = ACPI_NFIT_TYPE_MEMORY_MAP; 16396bc75619SDan Williams memdev->header.length = sizeof(*memdev); 16406bc75619SDan Williams memdev->device_handle = handle[1]; 16416bc75619SDan Williams memdev->physical_id = 1; 16426bc75619SDan Williams memdev->region_id = 0; 16436bc75619SDan Williams memdev->range_index = 7+1; 16446bc75619SDan Williams memdev->region_index = 1+1; 16456bc75619SDan Williams memdev->region_size = 0; 16466bc75619SDan Williams memdev->region_offset = 0; 16476bc75619SDan Williams memdev->address = 0; 16486bc75619SDan Williams memdev->interleave_index = 0; 16496bc75619SDan Williams memdev->interleave_ways = 1; 16506bc75619SDan Williams 16516bc75619SDan Williams /* mem-region12 (spa/bdw2, dimm2) */ 16526bc75619SDan Williams memdev = nfit_buf + offset + sizeof(struct acpi_nfit_memory_map) * 12; 16536bc75619SDan Williams memdev->header.type = ACPI_NFIT_TYPE_MEMORY_MAP; 16546bc75619SDan Williams memdev->header.length = sizeof(*memdev); 16556bc75619SDan Williams memdev->device_handle = handle[2]; 16566bc75619SDan Williams memdev->physical_id = 2; 16576bc75619SDan Williams memdev->region_id = 0; 16586bc75619SDan Williams memdev->range_index = 8+1; 16596bc75619SDan Williams memdev->region_index = 2+1; 16606bc75619SDan Williams memdev->region_size = 0; 16616bc75619SDan Williams memdev->region_offset = 0; 16626bc75619SDan Williams memdev->address = 0; 16636bc75619SDan Williams memdev->interleave_index = 0; 16646bc75619SDan Williams memdev->interleave_ways = 1; 16656bc75619SDan Williams 16666bc75619SDan Williams /* mem-region13 (spa/dcr3, dimm3) */ 16676bc75619SDan Williams memdev = nfit_buf + offset + sizeof(struct acpi_nfit_memory_map) * 13; 16686bc75619SDan Williams memdev->header.type = ACPI_NFIT_TYPE_MEMORY_MAP; 16696bc75619SDan Williams memdev->header.length = sizeof(*memdev); 16706bc75619SDan Williams memdev->device_handle = handle[3]; 16716bc75619SDan Williams memdev->physical_id = 3; 16726bc75619SDan Williams memdev->region_id = 0; 16736bc75619SDan Williams memdev->range_index = 9+1; 16746bc75619SDan Williams memdev->region_index = 3+1; 16756bc75619SDan Williams memdev->region_size = 0; 16766bc75619SDan Williams memdev->region_offset = 0; 16776bc75619SDan Williams memdev->address = 0; 16786bc75619SDan Williams memdev->interleave_index = 0; 16796bc75619SDan Williams memdev->interleave_ways = 1; 1680ac40b675SDan Williams memdev->flags = ACPI_NFIT_MEM_HEALTH_ENABLED; 16816bc75619SDan Williams 16826bc75619SDan Williams offset = offset + sizeof(struct acpi_nfit_memory_map) * 14; 16833b87356fSDan Williams /* dcr-descriptor0: blk */ 16846bc75619SDan Williams dcr = nfit_buf + offset; 16856bc75619SDan Williams dcr->header.type = ACPI_NFIT_TYPE_CONTROL_REGION; 16866bc75619SDan Williams dcr->header.length = sizeof(struct acpi_nfit_control_region); 16876bc75619SDan Williams dcr->region_index = 0+1; 16885dc68e55SDan Williams dcr_common_init(dcr); 16896bc75619SDan Williams dcr->serial_number = ~handle[0]; 1690be26f9aeSDan Williams dcr->code = NFIT_FIC_BLK; 16916bc75619SDan Williams dcr->windows = 1; 16926bc75619SDan Williams dcr->window_size = DCR_SIZE; 16936bc75619SDan Williams dcr->command_offset = 0; 16946bc75619SDan Williams dcr->command_size = 8; 16956bc75619SDan Williams dcr->status_offset = 8; 16966bc75619SDan Williams dcr->status_size = 4; 16976bc75619SDan Williams 16983b87356fSDan Williams /* dcr-descriptor1: blk */ 16996bc75619SDan Williams dcr = nfit_buf + offset + sizeof(struct acpi_nfit_control_region); 17006bc75619SDan Williams dcr->header.type = ACPI_NFIT_TYPE_CONTROL_REGION; 17016bc75619SDan Williams dcr->header.length = sizeof(struct acpi_nfit_control_region); 17026bc75619SDan Williams dcr->region_index = 1+1; 17035dc68e55SDan Williams dcr_common_init(dcr); 17046bc75619SDan Williams dcr->serial_number = ~handle[1]; 1705be26f9aeSDan Williams dcr->code = NFIT_FIC_BLK; 17066bc75619SDan Williams dcr->windows = 1; 17076bc75619SDan Williams dcr->window_size = DCR_SIZE; 17086bc75619SDan Williams dcr->command_offset = 0; 17096bc75619SDan Williams dcr->command_size = 8; 17106bc75619SDan Williams dcr->status_offset = 8; 17116bc75619SDan Williams dcr->status_size = 4; 17126bc75619SDan Williams 17133b87356fSDan Williams /* dcr-descriptor2: blk */ 17146bc75619SDan Williams dcr = nfit_buf + offset + sizeof(struct acpi_nfit_control_region) * 2; 17156bc75619SDan Williams dcr->header.type = ACPI_NFIT_TYPE_CONTROL_REGION; 17166bc75619SDan Williams dcr->header.length = sizeof(struct acpi_nfit_control_region); 17176bc75619SDan Williams dcr->region_index = 2+1; 17185dc68e55SDan Williams dcr_common_init(dcr); 17196bc75619SDan Williams dcr->serial_number = ~handle[2]; 1720be26f9aeSDan Williams dcr->code = NFIT_FIC_BLK; 17216bc75619SDan Williams dcr->windows = 1; 17226bc75619SDan Williams dcr->window_size = DCR_SIZE; 17236bc75619SDan Williams dcr->command_offset = 0; 17246bc75619SDan Williams dcr->command_size = 8; 17256bc75619SDan Williams dcr->status_offset = 8; 17266bc75619SDan Williams dcr->status_size = 4; 17276bc75619SDan Williams 17283b87356fSDan Williams /* dcr-descriptor3: blk */ 17296bc75619SDan Williams dcr = nfit_buf + offset + sizeof(struct acpi_nfit_control_region) * 3; 17306bc75619SDan Williams dcr->header.type = ACPI_NFIT_TYPE_CONTROL_REGION; 17316bc75619SDan Williams dcr->header.length = sizeof(struct acpi_nfit_control_region); 17326bc75619SDan Williams dcr->region_index = 3+1; 17335dc68e55SDan Williams dcr_common_init(dcr); 17346bc75619SDan Williams dcr->serial_number = ~handle[3]; 1735be26f9aeSDan Williams dcr->code = NFIT_FIC_BLK; 17366bc75619SDan Williams dcr->windows = 1; 17376bc75619SDan Williams dcr->window_size = DCR_SIZE; 17386bc75619SDan Williams dcr->command_offset = 0; 17396bc75619SDan Williams dcr->command_size = 8; 17406bc75619SDan Williams dcr->status_offset = 8; 17416bc75619SDan Williams dcr->status_size = 4; 17426bc75619SDan Williams 17436bc75619SDan Williams offset = offset + sizeof(struct acpi_nfit_control_region) * 4; 17443b87356fSDan Williams /* dcr-descriptor0: pmem */ 17453b87356fSDan Williams dcr = nfit_buf + offset; 17463b87356fSDan Williams dcr->header.type = ACPI_NFIT_TYPE_CONTROL_REGION; 17473b87356fSDan Williams dcr->header.length = offsetof(struct acpi_nfit_control_region, 17483b87356fSDan Williams window_size); 17493b87356fSDan Williams dcr->region_index = 4+1; 17505dc68e55SDan Williams dcr_common_init(dcr); 17513b87356fSDan Williams dcr->serial_number = ~handle[0]; 17523b87356fSDan Williams dcr->code = NFIT_FIC_BYTEN; 17533b87356fSDan Williams dcr->windows = 0; 17543b87356fSDan Williams 17553b87356fSDan Williams /* dcr-descriptor1: pmem */ 17563b87356fSDan Williams dcr = nfit_buf + offset + offsetof(struct acpi_nfit_control_region, 17573b87356fSDan Williams window_size); 17583b87356fSDan Williams dcr->header.type = ACPI_NFIT_TYPE_CONTROL_REGION; 17593b87356fSDan Williams dcr->header.length = offsetof(struct acpi_nfit_control_region, 17603b87356fSDan Williams window_size); 17613b87356fSDan Williams dcr->region_index = 5+1; 17625dc68e55SDan Williams dcr_common_init(dcr); 17633b87356fSDan Williams dcr->serial_number = ~handle[1]; 17643b87356fSDan Williams dcr->code = NFIT_FIC_BYTEN; 17653b87356fSDan Williams dcr->windows = 0; 17663b87356fSDan Williams 17673b87356fSDan Williams /* dcr-descriptor2: pmem */ 17683b87356fSDan Williams dcr = nfit_buf + offset + offsetof(struct acpi_nfit_control_region, 17693b87356fSDan Williams window_size) * 2; 17703b87356fSDan Williams dcr->header.type = ACPI_NFIT_TYPE_CONTROL_REGION; 17713b87356fSDan Williams dcr->header.length = offsetof(struct acpi_nfit_control_region, 17723b87356fSDan Williams window_size); 17733b87356fSDan Williams dcr->region_index = 6+1; 17745dc68e55SDan Williams dcr_common_init(dcr); 17753b87356fSDan Williams dcr->serial_number = ~handle[2]; 17763b87356fSDan Williams dcr->code = NFIT_FIC_BYTEN; 17773b87356fSDan Williams dcr->windows = 0; 17783b87356fSDan Williams 17793b87356fSDan Williams /* dcr-descriptor3: pmem */ 17803b87356fSDan Williams dcr = nfit_buf + offset + offsetof(struct acpi_nfit_control_region, 17813b87356fSDan Williams window_size) * 3; 17823b87356fSDan Williams dcr->header.type = ACPI_NFIT_TYPE_CONTROL_REGION; 17833b87356fSDan Williams dcr->header.length = offsetof(struct acpi_nfit_control_region, 17843b87356fSDan Williams window_size); 17853b87356fSDan Williams dcr->region_index = 7+1; 17865dc68e55SDan Williams dcr_common_init(dcr); 17873b87356fSDan Williams dcr->serial_number = ~handle[3]; 17883b87356fSDan Williams dcr->code = NFIT_FIC_BYTEN; 17893b87356fSDan Williams dcr->windows = 0; 17903b87356fSDan Williams 17913b87356fSDan Williams offset = offset + offsetof(struct acpi_nfit_control_region, 17923b87356fSDan Williams window_size) * 4; 17936bc75619SDan Williams /* bdw0 (spa/dcr0, dimm0) */ 17946bc75619SDan Williams bdw = nfit_buf + offset; 17956bc75619SDan Williams bdw->header.type = ACPI_NFIT_TYPE_DATA_REGION; 17966bc75619SDan Williams bdw->header.length = sizeof(struct acpi_nfit_data_region); 17976bc75619SDan Williams bdw->region_index = 0+1; 17986bc75619SDan Williams bdw->windows = 1; 17996bc75619SDan Williams bdw->offset = 0; 18006bc75619SDan Williams bdw->size = BDW_SIZE; 18016bc75619SDan Williams bdw->capacity = DIMM_SIZE; 18026bc75619SDan Williams bdw->start_address = 0; 18036bc75619SDan Williams 18046bc75619SDan Williams /* bdw1 (spa/dcr1, dimm1) */ 18056bc75619SDan Williams bdw = nfit_buf + offset + sizeof(struct acpi_nfit_data_region); 18066bc75619SDan Williams bdw->header.type = ACPI_NFIT_TYPE_DATA_REGION; 18076bc75619SDan Williams bdw->header.length = sizeof(struct acpi_nfit_data_region); 18086bc75619SDan Williams bdw->region_index = 1+1; 18096bc75619SDan Williams bdw->windows = 1; 18106bc75619SDan Williams bdw->offset = 0; 18116bc75619SDan Williams bdw->size = BDW_SIZE; 18126bc75619SDan Williams bdw->capacity = DIMM_SIZE; 18136bc75619SDan Williams bdw->start_address = 0; 18146bc75619SDan Williams 18156bc75619SDan Williams /* bdw2 (spa/dcr2, dimm2) */ 18166bc75619SDan Williams bdw = nfit_buf + offset + sizeof(struct acpi_nfit_data_region) * 2; 18176bc75619SDan Williams bdw->header.type = ACPI_NFIT_TYPE_DATA_REGION; 18186bc75619SDan Williams bdw->header.length = sizeof(struct acpi_nfit_data_region); 18196bc75619SDan Williams bdw->region_index = 2+1; 18206bc75619SDan Williams bdw->windows = 1; 18216bc75619SDan Williams bdw->offset = 0; 18226bc75619SDan Williams bdw->size = BDW_SIZE; 18236bc75619SDan Williams bdw->capacity = DIMM_SIZE; 18246bc75619SDan Williams bdw->start_address = 0; 18256bc75619SDan Williams 18266bc75619SDan Williams /* bdw3 (spa/dcr3, dimm3) */ 18276bc75619SDan Williams bdw = nfit_buf + offset + sizeof(struct acpi_nfit_data_region) * 3; 18286bc75619SDan Williams bdw->header.type = ACPI_NFIT_TYPE_DATA_REGION; 18296bc75619SDan Williams bdw->header.length = sizeof(struct acpi_nfit_data_region); 18306bc75619SDan Williams bdw->region_index = 3+1; 18316bc75619SDan Williams bdw->windows = 1; 18326bc75619SDan Williams bdw->offset = 0; 18336bc75619SDan Williams bdw->size = BDW_SIZE; 18346bc75619SDan Williams bdw->capacity = DIMM_SIZE; 18356bc75619SDan Williams bdw->start_address = 0; 18366bc75619SDan Williams 18379d27a87eSDan Williams offset = offset + sizeof(struct acpi_nfit_data_region) * 4; 18389d27a87eSDan Williams /* flush0 (dimm0) */ 18399d27a87eSDan Williams flush = nfit_buf + offset; 18409d27a87eSDan Williams flush->header.type = ACPI_NFIT_TYPE_FLUSH_ADDRESS; 184185d3fa02SDan Williams flush->header.length = flush_hint_size; 18429d27a87eSDan Williams flush->device_handle = handle[0]; 184385d3fa02SDan Williams flush->hint_count = NUM_HINTS; 184485d3fa02SDan Williams for (i = 0; i < NUM_HINTS; i++) 184585d3fa02SDan Williams flush->hint_address[i] = t->flush_dma[0] + i * sizeof(u64); 18469d27a87eSDan Williams 18479d27a87eSDan Williams /* flush1 (dimm1) */ 184885d3fa02SDan Williams flush = nfit_buf + offset + flush_hint_size * 1; 18499d27a87eSDan Williams flush->header.type = ACPI_NFIT_TYPE_FLUSH_ADDRESS; 185085d3fa02SDan Williams flush->header.length = flush_hint_size; 18519d27a87eSDan Williams flush->device_handle = handle[1]; 185285d3fa02SDan Williams flush->hint_count = NUM_HINTS; 185385d3fa02SDan Williams for (i = 0; i < NUM_HINTS; i++) 185485d3fa02SDan Williams flush->hint_address[i] = t->flush_dma[1] + i * sizeof(u64); 18559d27a87eSDan Williams 18569d27a87eSDan Williams /* flush2 (dimm2) */ 185785d3fa02SDan Williams flush = nfit_buf + offset + flush_hint_size * 2; 18589d27a87eSDan Williams flush->header.type = ACPI_NFIT_TYPE_FLUSH_ADDRESS; 185985d3fa02SDan Williams flush->header.length = flush_hint_size; 18609d27a87eSDan Williams flush->device_handle = handle[2]; 186185d3fa02SDan Williams flush->hint_count = NUM_HINTS; 186285d3fa02SDan Williams for (i = 0; i < NUM_HINTS; i++) 186385d3fa02SDan Williams flush->hint_address[i] = t->flush_dma[2] + i * sizeof(u64); 18649d27a87eSDan Williams 18659d27a87eSDan Williams /* flush3 (dimm3) */ 186685d3fa02SDan Williams flush = nfit_buf + offset + flush_hint_size * 3; 18679d27a87eSDan Williams flush->header.type = ACPI_NFIT_TYPE_FLUSH_ADDRESS; 186885d3fa02SDan Williams flush->header.length = flush_hint_size; 18699d27a87eSDan Williams flush->device_handle = handle[3]; 187085d3fa02SDan Williams flush->hint_count = NUM_HINTS; 187185d3fa02SDan Williams for (i = 0; i < NUM_HINTS; i++) 187285d3fa02SDan Williams flush->hint_address[i] = t->flush_dma[3] + i * sizeof(u64); 18739d27a87eSDan Williams 187420985164SVishal Verma if (t->setup_hotplug) { 187585d3fa02SDan Williams offset = offset + flush_hint_size * 4; 18763b87356fSDan Williams /* dcr-descriptor4: blk */ 187720985164SVishal Verma dcr = nfit_buf + offset; 187820985164SVishal Verma dcr->header.type = ACPI_NFIT_TYPE_CONTROL_REGION; 187920985164SVishal Verma dcr->header.length = sizeof(struct acpi_nfit_control_region); 18803b87356fSDan Williams dcr->region_index = 8+1; 18815dc68e55SDan Williams dcr_common_init(dcr); 188220985164SVishal Verma dcr->serial_number = ~handle[4]; 1883be26f9aeSDan Williams dcr->code = NFIT_FIC_BLK; 188420985164SVishal Verma dcr->windows = 1; 188520985164SVishal Verma dcr->window_size = DCR_SIZE; 188620985164SVishal Verma dcr->command_offset = 0; 188720985164SVishal Verma dcr->command_size = 8; 188820985164SVishal Verma dcr->status_offset = 8; 188920985164SVishal Verma dcr->status_size = 4; 189020985164SVishal Verma 189120985164SVishal Verma offset = offset + sizeof(struct acpi_nfit_control_region); 18923b87356fSDan Williams /* dcr-descriptor4: pmem */ 18933b87356fSDan Williams dcr = nfit_buf + offset; 18943b87356fSDan Williams dcr->header.type = ACPI_NFIT_TYPE_CONTROL_REGION; 18953b87356fSDan Williams dcr->header.length = offsetof(struct acpi_nfit_control_region, 18963b87356fSDan Williams window_size); 18973b87356fSDan Williams dcr->region_index = 9+1; 18985dc68e55SDan Williams dcr_common_init(dcr); 18993b87356fSDan Williams dcr->serial_number = ~handle[4]; 19003b87356fSDan Williams dcr->code = NFIT_FIC_BYTEN; 19013b87356fSDan Williams dcr->windows = 0; 19023b87356fSDan Williams 19033b87356fSDan Williams offset = offset + offsetof(struct acpi_nfit_control_region, 19043b87356fSDan Williams window_size); 190520985164SVishal Verma /* bdw4 (spa/dcr4, dimm4) */ 190620985164SVishal Verma bdw = nfit_buf + offset; 190720985164SVishal Verma bdw->header.type = ACPI_NFIT_TYPE_DATA_REGION; 190820985164SVishal Verma bdw->header.length = sizeof(struct acpi_nfit_data_region); 19093b87356fSDan Williams bdw->region_index = 8+1; 191020985164SVishal Verma bdw->windows = 1; 191120985164SVishal Verma bdw->offset = 0; 191220985164SVishal Verma bdw->size = BDW_SIZE; 191320985164SVishal Verma bdw->capacity = DIMM_SIZE; 191420985164SVishal Verma bdw->start_address = 0; 191520985164SVishal Verma 191620985164SVishal Verma offset = offset + sizeof(struct acpi_nfit_data_region); 191720985164SVishal Verma /* spa10 (dcr4) dimm4 */ 191820985164SVishal Verma spa = nfit_buf + offset; 191920985164SVishal Verma spa->header.type = ACPI_NFIT_TYPE_SYSTEM_ADDRESS; 192020985164SVishal Verma spa->header.length = sizeof(*spa); 192120985164SVishal Verma memcpy(spa->range_guid, to_nfit_uuid(NFIT_SPA_DCR), 16); 192220985164SVishal Verma spa->range_index = 10+1; 192320985164SVishal Verma spa->address = t->dcr_dma[4]; 192420985164SVishal Verma spa->length = DCR_SIZE; 192520985164SVishal Verma 192620985164SVishal Verma /* 192720985164SVishal Verma * spa11 (single-dimm interleave for hotplug, note storage 192820985164SVishal Verma * does not actually alias the related block-data-window 192920985164SVishal Verma * regions) 193020985164SVishal Verma */ 193120985164SVishal Verma spa = nfit_buf + offset + sizeof(*spa); 193220985164SVishal Verma spa->header.type = ACPI_NFIT_TYPE_SYSTEM_ADDRESS; 193320985164SVishal Verma spa->header.length = sizeof(*spa); 193420985164SVishal Verma memcpy(spa->range_guid, to_nfit_uuid(NFIT_SPA_PM), 16); 193520985164SVishal Verma spa->range_index = 11+1; 193620985164SVishal Verma spa->address = t->spa_set_dma[2]; 193720985164SVishal Verma spa->length = SPA0_SIZE; 193820985164SVishal Verma 193920985164SVishal Verma /* spa12 (bdw for dcr4) dimm4 */ 194020985164SVishal Verma spa = nfit_buf + offset + sizeof(*spa) * 2; 194120985164SVishal Verma spa->header.type = ACPI_NFIT_TYPE_SYSTEM_ADDRESS; 194220985164SVishal Verma spa->header.length = sizeof(*spa); 194320985164SVishal Verma memcpy(spa->range_guid, to_nfit_uuid(NFIT_SPA_BDW), 16); 194420985164SVishal Verma spa->range_index = 12+1; 194520985164SVishal Verma spa->address = t->dimm_dma[4]; 194620985164SVishal Verma spa->length = DIMM_SIZE; 194720985164SVishal Verma 194820985164SVishal Verma offset = offset + sizeof(*spa) * 3; 194920985164SVishal Verma /* mem-region14 (spa/dcr4, dimm4) */ 195020985164SVishal Verma memdev = nfit_buf + offset; 195120985164SVishal Verma memdev->header.type = ACPI_NFIT_TYPE_MEMORY_MAP; 195220985164SVishal Verma memdev->header.length = sizeof(*memdev); 195320985164SVishal Verma memdev->device_handle = handle[4]; 195420985164SVishal Verma memdev->physical_id = 4; 195520985164SVishal Verma memdev->region_id = 0; 195620985164SVishal Verma memdev->range_index = 10+1; 19573b87356fSDan Williams memdev->region_index = 8+1; 195820985164SVishal Verma memdev->region_size = 0; 195920985164SVishal Verma memdev->region_offset = 0; 196020985164SVishal Verma memdev->address = 0; 196120985164SVishal Verma memdev->interleave_index = 0; 196220985164SVishal Verma memdev->interleave_ways = 1; 196320985164SVishal Verma 196420985164SVishal Verma /* mem-region15 (spa0, dimm4) */ 196520985164SVishal Verma memdev = nfit_buf + offset + 196620985164SVishal Verma sizeof(struct acpi_nfit_memory_map); 196720985164SVishal Verma memdev->header.type = ACPI_NFIT_TYPE_MEMORY_MAP; 196820985164SVishal Verma memdev->header.length = sizeof(*memdev); 196920985164SVishal Verma memdev->device_handle = handle[4]; 197020985164SVishal Verma memdev->physical_id = 4; 197120985164SVishal Verma memdev->region_id = 0; 197220985164SVishal Verma memdev->range_index = 11+1; 19733b87356fSDan Williams memdev->region_index = 9+1; 197420985164SVishal Verma memdev->region_size = SPA0_SIZE; 1975df06a2d5SDan Williams memdev->region_offset = (1ULL << 48); 197620985164SVishal Verma memdev->address = 0; 197720985164SVishal Verma memdev->interleave_index = 0; 197820985164SVishal Verma memdev->interleave_ways = 1; 1979ac40b675SDan Williams memdev->flags = ACPI_NFIT_MEM_HEALTH_ENABLED; 198020985164SVishal Verma 19813b87356fSDan Williams /* mem-region16 (spa/bdw4, dimm4) */ 198220985164SVishal Verma memdev = nfit_buf + offset + 198320985164SVishal Verma sizeof(struct acpi_nfit_memory_map) * 2; 198420985164SVishal Verma memdev->header.type = ACPI_NFIT_TYPE_MEMORY_MAP; 198520985164SVishal Verma memdev->header.length = sizeof(*memdev); 198620985164SVishal Verma memdev->device_handle = handle[4]; 198720985164SVishal Verma memdev->physical_id = 4; 198820985164SVishal Verma memdev->region_id = 0; 198920985164SVishal Verma memdev->range_index = 12+1; 19903b87356fSDan Williams memdev->region_index = 8+1; 199120985164SVishal Verma memdev->region_size = 0; 199220985164SVishal Verma memdev->region_offset = 0; 199320985164SVishal Verma memdev->address = 0; 199420985164SVishal Verma memdev->interleave_index = 0; 199520985164SVishal Verma memdev->interleave_ways = 1; 199620985164SVishal Verma 199720985164SVishal Verma offset = offset + sizeof(struct acpi_nfit_memory_map) * 3; 199820985164SVishal Verma /* flush3 (dimm4) */ 199920985164SVishal Verma flush = nfit_buf + offset; 200020985164SVishal Verma flush->header.type = ACPI_NFIT_TYPE_FLUSH_ADDRESS; 200185d3fa02SDan Williams flush->header.length = flush_hint_size; 200220985164SVishal Verma flush->device_handle = handle[4]; 200385d3fa02SDan Williams flush->hint_count = NUM_HINTS; 200485d3fa02SDan Williams for (i = 0; i < NUM_HINTS; i++) 200585d3fa02SDan Williams flush->hint_address[i] = t->flush_dma[4] 200685d3fa02SDan Williams + i * sizeof(u64); 200720985164SVishal Verma } 200820985164SVishal Verma 20099fb1a190SDave Jiang post_ars_status(&t->ars_state, &t->badrange, t->spa_set_dma[0], 20109fb1a190SDave Jiang SPA0_SIZE); 2011f471f1a7SDan Williams 20126bc75619SDan Williams acpi_desc = &t->acpi_desc; 2013e3654ecaSDan Williams set_bit(ND_CMD_GET_CONFIG_SIZE, &acpi_desc->dimm_cmd_force_en); 2014e3654ecaSDan Williams set_bit(ND_CMD_GET_CONFIG_DATA, &acpi_desc->dimm_cmd_force_en); 2015e3654ecaSDan Williams set_bit(ND_CMD_SET_CONFIG_DATA, &acpi_desc->dimm_cmd_force_en); 2016ed07c433SDan Williams set_bit(ND_INTEL_SMART, &acpi_desc->dimm_cmd_force_en); 2017ed07c433SDan Williams set_bit(ND_INTEL_SMART_THRESHOLD, &acpi_desc->dimm_cmd_force_en); 2018ed07c433SDan Williams set_bit(ND_INTEL_SMART_SET_THRESHOLD, &acpi_desc->dimm_cmd_force_en); 2019e3654ecaSDan Williams set_bit(ND_CMD_ARS_CAP, &acpi_desc->bus_cmd_force_en); 2020e3654ecaSDan Williams set_bit(ND_CMD_ARS_START, &acpi_desc->bus_cmd_force_en); 2021e3654ecaSDan Williams set_bit(ND_CMD_ARS_STATUS, &acpi_desc->bus_cmd_force_en); 2022e3654ecaSDan Williams set_bit(ND_CMD_CLEAR_ERROR, &acpi_desc->bus_cmd_force_en); 202310246dc8SYasunori Goto set_bit(ND_CMD_CALL, &acpi_desc->bus_cmd_force_en); 202410246dc8SYasunori Goto set_bit(NFIT_CMD_TRANSLATE_SPA, &acpi_desc->bus_nfit_cmd_force_en); 20259fb1a190SDave Jiang set_bit(NFIT_CMD_ARS_INJECT_SET, &acpi_desc->bus_nfit_cmd_force_en); 20269fb1a190SDave Jiang set_bit(NFIT_CMD_ARS_INJECT_CLEAR, &acpi_desc->bus_nfit_cmd_force_en); 20279fb1a190SDave Jiang set_bit(NFIT_CMD_ARS_INJECT_GET, &acpi_desc->bus_nfit_cmd_force_en); 2028bfbaa952SDave Jiang set_bit(ND_INTEL_FW_GET_INFO, &acpi_desc->dimm_cmd_force_en); 2029bfbaa952SDave Jiang set_bit(ND_INTEL_FW_START_UPDATE, &acpi_desc->dimm_cmd_force_en); 2030bfbaa952SDave Jiang set_bit(ND_INTEL_FW_SEND_DATA, &acpi_desc->dimm_cmd_force_en); 2031bfbaa952SDave Jiang set_bit(ND_INTEL_FW_FINISH_UPDATE, &acpi_desc->dimm_cmd_force_en); 2032bfbaa952SDave Jiang set_bit(ND_INTEL_FW_FINISH_QUERY, &acpi_desc->dimm_cmd_force_en); 2033674d8bdeSDave Jiang set_bit(ND_INTEL_ENABLE_LSS_STATUS, &acpi_desc->dimm_cmd_force_en); 20346bc75619SDan Williams } 20356bc75619SDan Williams 20366bc75619SDan Williams static void nfit_test1_setup(struct nfit_test *t) 20376bc75619SDan Williams { 20386b577c9dSLinda Knippers size_t offset; 20396bc75619SDan Williams void *nfit_buf = t->nfit_buf; 20406bc75619SDan Williams struct acpi_nfit_memory_map *memdev; 20416bc75619SDan Williams struct acpi_nfit_control_region *dcr; 20426bc75619SDan Williams struct acpi_nfit_system_address *spa; 2043d26f73f0SDan Williams struct acpi_nfit_desc *acpi_desc; 20446bc75619SDan Williams 20456b577c9dSLinda Knippers offset = 0; 20466bc75619SDan Williams /* spa0 (flat range with no bdw aliasing) */ 20476bc75619SDan Williams spa = nfit_buf + offset; 20486bc75619SDan Williams spa->header.type = ACPI_NFIT_TYPE_SYSTEM_ADDRESS; 20496bc75619SDan Williams spa->header.length = sizeof(*spa); 20506bc75619SDan Williams memcpy(spa->range_guid, to_nfit_uuid(NFIT_SPA_PM), 16); 20516bc75619SDan Williams spa->range_index = 0+1; 20526bc75619SDan Williams spa->address = t->spa_set_dma[0]; 20536bc75619SDan Williams spa->length = SPA2_SIZE; 20546bc75619SDan Williams 20557bfe97c7SDan Williams /* virtual cd region */ 20567bfe97c7SDan Williams spa = nfit_buf + sizeof(*spa); 20577bfe97c7SDan Williams spa->header.type = ACPI_NFIT_TYPE_SYSTEM_ADDRESS; 20587bfe97c7SDan Williams spa->header.length = sizeof(*spa); 20597bfe97c7SDan Williams memcpy(spa->range_guid, to_nfit_uuid(NFIT_SPA_VCD), 16); 20607bfe97c7SDan Williams spa->range_index = 0; 20617bfe97c7SDan Williams spa->address = t->spa_set_dma[1]; 20627bfe97c7SDan Williams spa->length = SPA_VCD_SIZE; 20637bfe97c7SDan Williams 20647bfe97c7SDan Williams offset += sizeof(*spa) * 2; 20656bc75619SDan Williams /* mem-region0 (spa0, dimm0) */ 20666bc75619SDan Williams memdev = nfit_buf + offset; 20676bc75619SDan Williams memdev->header.type = ACPI_NFIT_TYPE_MEMORY_MAP; 20686bc75619SDan Williams memdev->header.length = sizeof(*memdev); 2069dafb1048SDan Williams memdev->device_handle = handle[5]; 20706bc75619SDan Williams memdev->physical_id = 0; 20716bc75619SDan Williams memdev->region_id = 0; 20726bc75619SDan Williams memdev->range_index = 0+1; 20736bc75619SDan Williams memdev->region_index = 0+1; 20746bc75619SDan Williams memdev->region_size = SPA2_SIZE; 20756bc75619SDan Williams memdev->region_offset = 0; 20766bc75619SDan Williams memdev->address = 0; 20776bc75619SDan Williams memdev->interleave_index = 0; 20786bc75619SDan Williams memdev->interleave_ways = 1; 207958138820SDan Williams memdev->flags = ACPI_NFIT_MEM_SAVE_FAILED | ACPI_NFIT_MEM_RESTORE_FAILED 208058138820SDan Williams | ACPI_NFIT_MEM_FLUSH_FAILED | ACPI_NFIT_MEM_HEALTH_OBSERVED 2081f4295796SDan Williams | ACPI_NFIT_MEM_NOT_ARMED; 20826bc75619SDan Williams 20836bc75619SDan Williams offset += sizeof(*memdev); 20846bc75619SDan Williams /* dcr-descriptor0 */ 20856bc75619SDan Williams dcr = nfit_buf + offset; 20866bc75619SDan Williams dcr->header.type = ACPI_NFIT_TYPE_CONTROL_REGION; 20873b87356fSDan Williams dcr->header.length = offsetof(struct acpi_nfit_control_region, 20883b87356fSDan Williams window_size); 20896bc75619SDan Williams dcr->region_index = 0+1; 20905dc68e55SDan Williams dcr_common_init(dcr); 2091dafb1048SDan Williams dcr->serial_number = ~handle[5]; 2092be26f9aeSDan Williams dcr->code = NFIT_FIC_BYTE; 20936bc75619SDan Williams dcr->windows = 0; 2094d26f73f0SDan Williams 2095ac40b675SDan Williams offset += dcr->header.length; 2096ac40b675SDan Williams memdev = nfit_buf + offset; 2097ac40b675SDan Williams memdev->header.type = ACPI_NFIT_TYPE_MEMORY_MAP; 2098ac40b675SDan Williams memdev->header.length = sizeof(*memdev); 2099ac40b675SDan Williams memdev->device_handle = handle[6]; 2100ac40b675SDan Williams memdev->physical_id = 0; 2101ac40b675SDan Williams memdev->region_id = 0; 2102ac40b675SDan Williams memdev->range_index = 0; 2103ac40b675SDan Williams memdev->region_index = 0+2; 2104ac40b675SDan Williams memdev->region_size = SPA2_SIZE; 2105ac40b675SDan Williams memdev->region_offset = 0; 2106ac40b675SDan Williams memdev->address = 0; 2107ac40b675SDan Williams memdev->interleave_index = 0; 2108ac40b675SDan Williams memdev->interleave_ways = 1; 2109ac40b675SDan Williams memdev->flags = ACPI_NFIT_MEM_MAP_FAILED; 2110ac40b675SDan Williams 2111ac40b675SDan Williams /* dcr-descriptor1 */ 2112ac40b675SDan Williams offset += sizeof(*memdev); 2113ac40b675SDan Williams dcr = nfit_buf + offset; 2114ac40b675SDan Williams dcr->header.type = ACPI_NFIT_TYPE_CONTROL_REGION; 2115ac40b675SDan Williams dcr->header.length = offsetof(struct acpi_nfit_control_region, 2116ac40b675SDan Williams window_size); 2117ac40b675SDan Williams dcr->region_index = 0+2; 2118ac40b675SDan Williams dcr_common_init(dcr); 2119ac40b675SDan Williams dcr->serial_number = ~handle[6]; 2120ac40b675SDan Williams dcr->code = NFIT_FIC_BYTE; 2121ac40b675SDan Williams dcr->windows = 0; 2122ac40b675SDan Williams 21239fb1a190SDave Jiang post_ars_status(&t->ars_state, &t->badrange, t->spa_set_dma[0], 21249fb1a190SDave Jiang SPA2_SIZE); 2125f471f1a7SDan Williams 2126d26f73f0SDan Williams acpi_desc = &t->acpi_desc; 2127e3654ecaSDan Williams set_bit(ND_CMD_ARS_CAP, &acpi_desc->bus_cmd_force_en); 2128e3654ecaSDan Williams set_bit(ND_CMD_ARS_START, &acpi_desc->bus_cmd_force_en); 2129e3654ecaSDan Williams set_bit(ND_CMD_ARS_STATUS, &acpi_desc->bus_cmd_force_en); 2130e3654ecaSDan Williams set_bit(ND_CMD_CLEAR_ERROR, &acpi_desc->bus_cmd_force_en); 2131674d8bdeSDave Jiang set_bit(ND_INTEL_ENABLE_LSS_STATUS, &acpi_desc->dimm_cmd_force_en); 21326bc75619SDan Williams } 21336bc75619SDan Williams 21346bc75619SDan Williams static int nfit_test_blk_do_io(struct nd_blk_region *ndbr, resource_size_t dpa, 21356bc75619SDan Williams void *iobuf, u64 len, int rw) 21366bc75619SDan Williams { 21376bc75619SDan Williams struct nfit_blk *nfit_blk = ndbr->blk_provider_data; 21386bc75619SDan Williams struct nfit_blk_mmio *mmio = &nfit_blk->mmio[BDW]; 21396bc75619SDan Williams struct nd_region *nd_region = &ndbr->nd_region; 21406bc75619SDan Williams unsigned int lane; 21416bc75619SDan Williams 21426bc75619SDan Williams lane = nd_region_acquire_lane(nd_region); 21436bc75619SDan Williams if (rw) 214467a3e8feSRoss Zwisler memcpy(mmio->addr.base + dpa, iobuf, len); 214567a3e8feSRoss Zwisler else { 214667a3e8feSRoss Zwisler memcpy(iobuf, mmio->addr.base + dpa, len); 214767a3e8feSRoss Zwisler 21485deb67f7SRobin Murphy /* give us some some coverage of the arch_invalidate_pmem() API */ 21495deb67f7SRobin Murphy arch_invalidate_pmem(mmio->addr.base + dpa, len); 215067a3e8feSRoss Zwisler } 21516bc75619SDan Williams nd_region_release_lane(nd_region, lane); 21526bc75619SDan Williams 21536bc75619SDan Williams return 0; 21546bc75619SDan Williams } 21556bc75619SDan Williams 2156a7de92daSDan Williams static unsigned long nfit_ctl_handle; 2157a7de92daSDan Williams 2158a7de92daSDan Williams union acpi_object *result; 2159a7de92daSDan Williams 2160a7de92daSDan Williams static union acpi_object *nfit_test_evaluate_dsm(acpi_handle handle, 216194116f81SAndy Shevchenko const guid_t *guid, u64 rev, u64 func, union acpi_object *argv4) 2162a7de92daSDan Williams { 2163a7de92daSDan Williams if (handle != &nfit_ctl_handle) 2164a7de92daSDan Williams return ERR_PTR(-ENXIO); 2165a7de92daSDan Williams 2166a7de92daSDan Williams return result; 2167a7de92daSDan Williams } 2168a7de92daSDan Williams 2169a7de92daSDan Williams static int setup_result(void *buf, size_t size) 2170a7de92daSDan Williams { 2171a7de92daSDan Williams result = kmalloc(sizeof(union acpi_object) + size, GFP_KERNEL); 2172a7de92daSDan Williams if (!result) 2173a7de92daSDan Williams return -ENOMEM; 2174a7de92daSDan Williams result->package.type = ACPI_TYPE_BUFFER, 2175a7de92daSDan Williams result->buffer.pointer = (void *) (result + 1); 2176a7de92daSDan Williams result->buffer.length = size; 2177a7de92daSDan Williams memcpy(result->buffer.pointer, buf, size); 2178a7de92daSDan Williams memset(buf, 0, size); 2179a7de92daSDan Williams return 0; 2180a7de92daSDan Williams } 2181a7de92daSDan Williams 2182a7de92daSDan Williams static int nfit_ctl_test(struct device *dev) 2183a7de92daSDan Williams { 2184a7de92daSDan Williams int rc, cmd_rc; 2185a7de92daSDan Williams struct nvdimm *nvdimm; 2186a7de92daSDan Williams struct acpi_device *adev; 2187a7de92daSDan Williams struct nfit_mem *nfit_mem; 2188a7de92daSDan Williams struct nd_ars_record *record; 2189a7de92daSDan Williams struct acpi_nfit_desc *acpi_desc; 2190a7de92daSDan Williams const u64 test_val = 0x0123456789abcdefULL; 2191a7de92daSDan Williams unsigned long mask, cmd_size, offset; 2192a7de92daSDan Williams union { 2193a7de92daSDan Williams struct nd_cmd_get_config_size cfg_size; 2194fb2a1748SDan Williams struct nd_cmd_clear_error clear_err; 2195a7de92daSDan Williams struct nd_cmd_ars_status ars_stat; 2196a7de92daSDan Williams struct nd_cmd_ars_cap ars_cap; 2197a7de92daSDan Williams char buf[sizeof(struct nd_cmd_ars_status) 2198a7de92daSDan Williams + sizeof(struct nd_ars_record)]; 2199a7de92daSDan Williams } cmds; 2200a7de92daSDan Williams 2201a7de92daSDan Williams adev = devm_kzalloc(dev, sizeof(*adev), GFP_KERNEL); 2202a7de92daSDan Williams if (!adev) 2203a7de92daSDan Williams return -ENOMEM; 2204a7de92daSDan Williams *adev = (struct acpi_device) { 2205a7de92daSDan Williams .handle = &nfit_ctl_handle, 2206a7de92daSDan Williams .dev = { 2207a7de92daSDan Williams .init_name = "test-adev", 2208a7de92daSDan Williams }, 2209a7de92daSDan Williams }; 2210a7de92daSDan Williams 2211a7de92daSDan Williams acpi_desc = devm_kzalloc(dev, sizeof(*acpi_desc), GFP_KERNEL); 2212a7de92daSDan Williams if (!acpi_desc) 2213a7de92daSDan Williams return -ENOMEM; 2214a7de92daSDan Williams *acpi_desc = (struct acpi_nfit_desc) { 2215a7de92daSDan Williams .nd_desc = { 2216a7de92daSDan Williams .cmd_mask = 1UL << ND_CMD_ARS_CAP 2217a7de92daSDan Williams | 1UL << ND_CMD_ARS_START 2218a7de92daSDan Williams | 1UL << ND_CMD_ARS_STATUS 221910246dc8SYasunori Goto | 1UL << ND_CMD_CLEAR_ERROR 222010246dc8SYasunori Goto | 1UL << ND_CMD_CALL, 2221a7de92daSDan Williams .module = THIS_MODULE, 2222a7de92daSDan Williams .provider_name = "ACPI.NFIT", 2223a7de92daSDan Williams .ndctl = acpi_nfit_ctl, 22249fb1a190SDave Jiang .bus_dsm_mask = 1UL << NFIT_CMD_TRANSLATE_SPA 22259fb1a190SDave Jiang | 1UL << NFIT_CMD_ARS_INJECT_SET 22269fb1a190SDave Jiang | 1UL << NFIT_CMD_ARS_INJECT_CLEAR 22279fb1a190SDave Jiang | 1UL << NFIT_CMD_ARS_INJECT_GET, 2228a7de92daSDan Williams }, 2229a7de92daSDan Williams .dev = &adev->dev, 2230a7de92daSDan Williams }; 2231a7de92daSDan Williams 2232a7de92daSDan Williams nfit_mem = devm_kzalloc(dev, sizeof(*nfit_mem), GFP_KERNEL); 2233a7de92daSDan Williams if (!nfit_mem) 2234a7de92daSDan Williams return -ENOMEM; 2235a7de92daSDan Williams 2236a7de92daSDan Williams mask = 1UL << ND_CMD_SMART | 1UL << ND_CMD_SMART_THRESHOLD 2237a7de92daSDan Williams | 1UL << ND_CMD_DIMM_FLAGS | 1UL << ND_CMD_GET_CONFIG_SIZE 2238a7de92daSDan Williams | 1UL << ND_CMD_GET_CONFIG_DATA | 1UL << ND_CMD_SET_CONFIG_DATA 2239a7de92daSDan Williams | 1UL << ND_CMD_VENDOR; 2240a7de92daSDan Williams *nfit_mem = (struct nfit_mem) { 2241a7de92daSDan Williams .adev = adev, 2242a7de92daSDan Williams .family = NVDIMM_FAMILY_INTEL, 2243a7de92daSDan Williams .dsm_mask = mask, 2244a7de92daSDan Williams }; 2245a7de92daSDan Williams 2246a7de92daSDan Williams nvdimm = devm_kzalloc(dev, sizeof(*nvdimm), GFP_KERNEL); 2247a7de92daSDan Williams if (!nvdimm) 2248a7de92daSDan Williams return -ENOMEM; 2249a7de92daSDan Williams *nvdimm = (struct nvdimm) { 2250a7de92daSDan Williams .provider_data = nfit_mem, 2251a7de92daSDan Williams .cmd_mask = mask, 2252a7de92daSDan Williams .dev = { 2253a7de92daSDan Williams .init_name = "test-dimm", 2254a7de92daSDan Williams }, 2255a7de92daSDan Williams }; 2256a7de92daSDan Williams 2257a7de92daSDan Williams 2258a7de92daSDan Williams /* basic checkout of a typical 'get config size' command */ 2259a7de92daSDan Williams cmd_size = sizeof(cmds.cfg_size); 2260a7de92daSDan Williams cmds.cfg_size = (struct nd_cmd_get_config_size) { 2261a7de92daSDan Williams .status = 0, 2262a7de92daSDan Williams .config_size = SZ_128K, 2263a7de92daSDan Williams .max_xfer = SZ_4K, 2264a7de92daSDan Williams }; 2265a7de92daSDan Williams rc = setup_result(cmds.buf, cmd_size); 2266a7de92daSDan Williams if (rc) 2267a7de92daSDan Williams return rc; 2268a7de92daSDan Williams rc = acpi_nfit_ctl(&acpi_desc->nd_desc, nvdimm, ND_CMD_GET_CONFIG_SIZE, 2269a7de92daSDan Williams cmds.buf, cmd_size, &cmd_rc); 2270a7de92daSDan Williams 2271a7de92daSDan Williams if (rc < 0 || cmd_rc || cmds.cfg_size.status != 0 2272a7de92daSDan Williams || cmds.cfg_size.config_size != SZ_128K 2273a7de92daSDan Williams || cmds.cfg_size.max_xfer != SZ_4K) { 2274a7de92daSDan Williams dev_dbg(dev, "%s: failed at: %d rc: %d cmd_rc: %d\n", 2275a7de92daSDan Williams __func__, __LINE__, rc, cmd_rc); 2276a7de92daSDan Williams return -EIO; 2277a7de92daSDan Williams } 2278a7de92daSDan Williams 2279a7de92daSDan Williams 2280a7de92daSDan Williams /* test ars_status with zero output */ 2281a7de92daSDan Williams cmd_size = offsetof(struct nd_cmd_ars_status, address); 2282a7de92daSDan Williams cmds.ars_stat = (struct nd_cmd_ars_status) { 2283a7de92daSDan Williams .out_length = 0, 2284a7de92daSDan Williams }; 2285a7de92daSDan Williams rc = setup_result(cmds.buf, cmd_size); 2286a7de92daSDan Williams if (rc) 2287a7de92daSDan Williams return rc; 2288a7de92daSDan Williams rc = acpi_nfit_ctl(&acpi_desc->nd_desc, NULL, ND_CMD_ARS_STATUS, 2289a7de92daSDan Williams cmds.buf, cmd_size, &cmd_rc); 2290a7de92daSDan Williams 2291a7de92daSDan Williams if (rc < 0 || cmd_rc) { 2292a7de92daSDan Williams dev_dbg(dev, "%s: failed at: %d rc: %d cmd_rc: %d\n", 2293a7de92daSDan Williams __func__, __LINE__, rc, cmd_rc); 2294a7de92daSDan Williams return -EIO; 2295a7de92daSDan Williams } 2296a7de92daSDan Williams 2297a7de92daSDan Williams 2298a7de92daSDan Williams /* test ars_cap with benign extended status */ 2299a7de92daSDan Williams cmd_size = sizeof(cmds.ars_cap); 2300a7de92daSDan Williams cmds.ars_cap = (struct nd_cmd_ars_cap) { 2301a7de92daSDan Williams .status = ND_ARS_PERSISTENT << 16, 2302a7de92daSDan Williams }; 2303a7de92daSDan Williams offset = offsetof(struct nd_cmd_ars_cap, status); 2304a7de92daSDan Williams rc = setup_result(cmds.buf + offset, cmd_size - offset); 2305a7de92daSDan Williams if (rc) 2306a7de92daSDan Williams return rc; 2307a7de92daSDan Williams rc = acpi_nfit_ctl(&acpi_desc->nd_desc, NULL, ND_CMD_ARS_CAP, 2308a7de92daSDan Williams cmds.buf, cmd_size, &cmd_rc); 2309a7de92daSDan Williams 2310a7de92daSDan Williams if (rc < 0 || cmd_rc) { 2311a7de92daSDan Williams dev_dbg(dev, "%s: failed at: %d rc: %d cmd_rc: %d\n", 2312a7de92daSDan Williams __func__, __LINE__, rc, cmd_rc); 2313a7de92daSDan Williams return -EIO; 2314a7de92daSDan Williams } 2315a7de92daSDan Williams 2316a7de92daSDan Williams 2317a7de92daSDan Williams /* test ars_status with 'status' trimmed from 'out_length' */ 2318a7de92daSDan Williams cmd_size = sizeof(cmds.ars_stat) + sizeof(struct nd_ars_record); 2319a7de92daSDan Williams cmds.ars_stat = (struct nd_cmd_ars_status) { 2320a7de92daSDan Williams .out_length = cmd_size - 4, 2321a7de92daSDan Williams }; 2322a7de92daSDan Williams record = &cmds.ars_stat.records[0]; 2323a7de92daSDan Williams *record = (struct nd_ars_record) { 2324a7de92daSDan Williams .length = test_val, 2325a7de92daSDan Williams }; 2326a7de92daSDan Williams rc = setup_result(cmds.buf, cmd_size); 2327a7de92daSDan Williams if (rc) 2328a7de92daSDan Williams return rc; 2329a7de92daSDan Williams rc = acpi_nfit_ctl(&acpi_desc->nd_desc, NULL, ND_CMD_ARS_STATUS, 2330a7de92daSDan Williams cmds.buf, cmd_size, &cmd_rc); 2331a7de92daSDan Williams 2332a7de92daSDan Williams if (rc < 0 || cmd_rc || record->length != test_val) { 2333a7de92daSDan Williams dev_dbg(dev, "%s: failed at: %d rc: %d cmd_rc: %d\n", 2334a7de92daSDan Williams __func__, __LINE__, rc, cmd_rc); 2335a7de92daSDan Williams return -EIO; 2336a7de92daSDan Williams } 2337a7de92daSDan Williams 2338a7de92daSDan Williams 2339a7de92daSDan Williams /* test ars_status with 'Output (Size)' including 'status' */ 2340a7de92daSDan Williams cmd_size = sizeof(cmds.ars_stat) + sizeof(struct nd_ars_record); 2341a7de92daSDan Williams cmds.ars_stat = (struct nd_cmd_ars_status) { 2342a7de92daSDan Williams .out_length = cmd_size, 2343a7de92daSDan Williams }; 2344a7de92daSDan Williams record = &cmds.ars_stat.records[0]; 2345a7de92daSDan Williams *record = (struct nd_ars_record) { 2346a7de92daSDan Williams .length = test_val, 2347a7de92daSDan Williams }; 2348a7de92daSDan Williams rc = setup_result(cmds.buf, cmd_size); 2349a7de92daSDan Williams if (rc) 2350a7de92daSDan Williams return rc; 2351a7de92daSDan Williams rc = acpi_nfit_ctl(&acpi_desc->nd_desc, NULL, ND_CMD_ARS_STATUS, 2352a7de92daSDan Williams cmds.buf, cmd_size, &cmd_rc); 2353a7de92daSDan Williams 2354a7de92daSDan Williams if (rc < 0 || cmd_rc || record->length != test_val) { 2355a7de92daSDan Williams dev_dbg(dev, "%s: failed at: %d rc: %d cmd_rc: %d\n", 2356a7de92daSDan Williams __func__, __LINE__, rc, cmd_rc); 2357a7de92daSDan Williams return -EIO; 2358a7de92daSDan Williams } 2359a7de92daSDan Williams 2360a7de92daSDan Williams 2361a7de92daSDan Williams /* test extended status for get_config_size results in failure */ 2362a7de92daSDan Williams cmd_size = sizeof(cmds.cfg_size); 2363a7de92daSDan Williams cmds.cfg_size = (struct nd_cmd_get_config_size) { 2364a7de92daSDan Williams .status = 1 << 16, 2365a7de92daSDan Williams }; 2366a7de92daSDan Williams rc = setup_result(cmds.buf, cmd_size); 2367a7de92daSDan Williams if (rc) 2368a7de92daSDan Williams return rc; 2369a7de92daSDan Williams rc = acpi_nfit_ctl(&acpi_desc->nd_desc, nvdimm, ND_CMD_GET_CONFIG_SIZE, 2370a7de92daSDan Williams cmds.buf, cmd_size, &cmd_rc); 2371a7de92daSDan Williams 2372a7de92daSDan Williams if (rc < 0 || cmd_rc >= 0) { 2373a7de92daSDan Williams dev_dbg(dev, "%s: failed at: %d rc: %d cmd_rc: %d\n", 2374a7de92daSDan Williams __func__, __LINE__, rc, cmd_rc); 2375a7de92daSDan Williams return -EIO; 2376a7de92daSDan Williams } 2377a7de92daSDan Williams 2378fb2a1748SDan Williams /* test clear error */ 2379fb2a1748SDan Williams cmd_size = sizeof(cmds.clear_err); 2380fb2a1748SDan Williams cmds.clear_err = (struct nd_cmd_clear_error) { 2381fb2a1748SDan Williams .length = 512, 2382fb2a1748SDan Williams .cleared = 512, 2383fb2a1748SDan Williams }; 2384fb2a1748SDan Williams rc = setup_result(cmds.buf, cmd_size); 2385fb2a1748SDan Williams if (rc) 2386fb2a1748SDan Williams return rc; 2387fb2a1748SDan Williams rc = acpi_nfit_ctl(&acpi_desc->nd_desc, NULL, ND_CMD_CLEAR_ERROR, 2388fb2a1748SDan Williams cmds.buf, cmd_size, &cmd_rc); 2389fb2a1748SDan Williams if (rc < 0 || cmd_rc) { 2390fb2a1748SDan Williams dev_dbg(dev, "%s: failed at: %d rc: %d cmd_rc: %d\n", 2391fb2a1748SDan Williams __func__, __LINE__, rc, cmd_rc); 2392fb2a1748SDan Williams return -EIO; 2393fb2a1748SDan Williams } 2394fb2a1748SDan Williams 2395a7de92daSDan Williams return 0; 2396a7de92daSDan Williams } 2397a7de92daSDan Williams 23986bc75619SDan Williams static int nfit_test_probe(struct platform_device *pdev) 23996bc75619SDan Williams { 24006bc75619SDan Williams struct nvdimm_bus_descriptor *nd_desc; 24016bc75619SDan Williams struct acpi_nfit_desc *acpi_desc; 24026bc75619SDan Williams struct device *dev = &pdev->dev; 24036bc75619SDan Williams struct nfit_test *nfit_test; 2404231bf117SDan Williams struct nfit_mem *nfit_mem; 2405c14a868aSDan Williams union acpi_object *obj; 24066bc75619SDan Williams int rc; 24076bc75619SDan Williams 2408a7de92daSDan Williams if (strcmp(dev_name(&pdev->dev), "nfit_test.0") == 0) { 2409a7de92daSDan Williams rc = nfit_ctl_test(&pdev->dev); 2410a7de92daSDan Williams if (rc) 2411a7de92daSDan Williams return rc; 2412a7de92daSDan Williams } 2413a7de92daSDan Williams 24146bc75619SDan Williams nfit_test = to_nfit_test(&pdev->dev); 24156bc75619SDan Williams 24166bc75619SDan Williams /* common alloc */ 24176bc75619SDan Williams if (nfit_test->num_dcr) { 24186bc75619SDan Williams int num = nfit_test->num_dcr; 24196bc75619SDan Williams 24206bc75619SDan Williams nfit_test->dimm = devm_kcalloc(dev, num, sizeof(void *), 24216bc75619SDan Williams GFP_KERNEL); 24226bc75619SDan Williams nfit_test->dimm_dma = devm_kcalloc(dev, num, sizeof(dma_addr_t), 24236bc75619SDan Williams GFP_KERNEL); 24249d27a87eSDan Williams nfit_test->flush = devm_kcalloc(dev, num, sizeof(void *), 24259d27a87eSDan Williams GFP_KERNEL); 24269d27a87eSDan Williams nfit_test->flush_dma = devm_kcalloc(dev, num, sizeof(dma_addr_t), 24279d27a87eSDan Williams GFP_KERNEL); 24286bc75619SDan Williams nfit_test->label = devm_kcalloc(dev, num, sizeof(void *), 24296bc75619SDan Williams GFP_KERNEL); 24306bc75619SDan Williams nfit_test->label_dma = devm_kcalloc(dev, num, 24316bc75619SDan Williams sizeof(dma_addr_t), GFP_KERNEL); 24326bc75619SDan Williams nfit_test->dcr = devm_kcalloc(dev, num, 24336bc75619SDan Williams sizeof(struct nfit_test_dcr *), GFP_KERNEL); 24346bc75619SDan Williams nfit_test->dcr_dma = devm_kcalloc(dev, num, 24356bc75619SDan Williams sizeof(dma_addr_t), GFP_KERNEL); 2436ed07c433SDan Williams nfit_test->smart = devm_kcalloc(dev, num, 2437ed07c433SDan Williams sizeof(struct nd_intel_smart), GFP_KERNEL); 2438ed07c433SDan Williams nfit_test->smart_threshold = devm_kcalloc(dev, num, 2439ed07c433SDan Williams sizeof(struct nd_intel_smart_threshold), 2440ed07c433SDan Williams GFP_KERNEL); 2441bfbaa952SDave Jiang nfit_test->fw = devm_kcalloc(dev, num, 2442bfbaa952SDave Jiang sizeof(struct nfit_test_fw), GFP_KERNEL); 24436bc75619SDan Williams if (nfit_test->dimm && nfit_test->dimm_dma && nfit_test->label 24446bc75619SDan Williams && nfit_test->label_dma && nfit_test->dcr 24459d27a87eSDan Williams && nfit_test->dcr_dma && nfit_test->flush 2446bfbaa952SDave Jiang && nfit_test->flush_dma 2447bfbaa952SDave Jiang && nfit_test->fw) 24486bc75619SDan Williams /* pass */; 24496bc75619SDan Williams else 24506bc75619SDan Williams return -ENOMEM; 24516bc75619SDan Williams } 24526bc75619SDan Williams 24536bc75619SDan Williams if (nfit_test->num_pm) { 24546bc75619SDan Williams int num = nfit_test->num_pm; 24556bc75619SDan Williams 24566bc75619SDan Williams nfit_test->spa_set = devm_kcalloc(dev, num, sizeof(void *), 24576bc75619SDan Williams GFP_KERNEL); 24586bc75619SDan Williams nfit_test->spa_set_dma = devm_kcalloc(dev, num, 24596bc75619SDan Williams sizeof(dma_addr_t), GFP_KERNEL); 24606bc75619SDan Williams if (nfit_test->spa_set && nfit_test->spa_set_dma) 24616bc75619SDan Williams /* pass */; 24626bc75619SDan Williams else 24636bc75619SDan Williams return -ENOMEM; 24646bc75619SDan Williams } 24656bc75619SDan Williams 24666bc75619SDan Williams /* per-nfit specific alloc */ 24676bc75619SDan Williams if (nfit_test->alloc(nfit_test)) 24686bc75619SDan Williams return -ENOMEM; 24696bc75619SDan Williams 24706bc75619SDan Williams nfit_test->setup(nfit_test); 24716bc75619SDan Williams acpi_desc = &nfit_test->acpi_desc; 2472a61fe6f7SDan Williams acpi_nfit_desc_init(acpi_desc, &pdev->dev); 24736bc75619SDan Williams acpi_desc->blk_do_io = nfit_test_blk_do_io; 24746bc75619SDan Williams nd_desc = &acpi_desc->nd_desc; 2475a61fe6f7SDan Williams nd_desc->provider_name = NULL; 2476bc9775d8SDan Williams nd_desc->module = THIS_MODULE; 2477a61fe6f7SDan Williams nd_desc->ndctl = nfit_test_ctl; 24786bc75619SDan Williams 2479e7a11b44SDan Williams rc = acpi_nfit_init(acpi_desc, nfit_test->nfit_buf, 2480e7a11b44SDan Williams nfit_test->nfit_size); 248158cd71b4SDan Williams if (rc) 248220985164SVishal Verma return rc; 248320985164SVishal Verma 2484fbabd829SDan Williams rc = devm_add_action_or_reset(&pdev->dev, acpi_nfit_shutdown, acpi_desc); 2485fbabd829SDan Williams if (rc) 2486fbabd829SDan Williams return rc; 2487fbabd829SDan Williams 248820985164SVishal Verma if (nfit_test->setup != nfit_test0_setup) 248920985164SVishal Verma return 0; 249020985164SVishal Verma 249120985164SVishal Verma nfit_test->setup_hotplug = 1; 249220985164SVishal Verma nfit_test->setup(nfit_test); 249320985164SVishal Verma 2494c14a868aSDan Williams obj = kzalloc(sizeof(*obj), GFP_KERNEL); 2495c14a868aSDan Williams if (!obj) 2496c14a868aSDan Williams return -ENOMEM; 2497c14a868aSDan Williams obj->type = ACPI_TYPE_BUFFER; 2498c14a868aSDan Williams obj->buffer.length = nfit_test->nfit_size; 2499c14a868aSDan Williams obj->buffer.pointer = nfit_test->nfit_buf; 2500c14a868aSDan Williams *(nfit_test->_fit) = obj; 2501c14a868aSDan Williams __acpi_nfit_notify(&pdev->dev, nfit_test, 0x80); 2502231bf117SDan Williams 2503231bf117SDan Williams /* associate dimm devices with nfit_mem data for notification testing */ 2504231bf117SDan Williams mutex_lock(&acpi_desc->init_mutex); 2505231bf117SDan Williams list_for_each_entry(nfit_mem, &acpi_desc->dimms, list) { 2506231bf117SDan Williams u32 nfit_handle = __to_nfit_memdev(nfit_mem)->device_handle; 2507231bf117SDan Williams int i; 2508231bf117SDan Williams 2509231bf117SDan Williams for (i = 0; i < NUM_DCR; i++) 2510231bf117SDan Williams if (nfit_handle == handle[i]) 2511231bf117SDan Williams dev_set_drvdata(nfit_test->dimm_dev[i], 2512231bf117SDan Williams nfit_mem); 2513231bf117SDan Williams } 2514231bf117SDan Williams mutex_unlock(&acpi_desc->init_mutex); 25156bc75619SDan Williams 25166bc75619SDan Williams return 0; 25176bc75619SDan Williams } 25186bc75619SDan Williams 25196bc75619SDan Williams static int nfit_test_remove(struct platform_device *pdev) 25206bc75619SDan Williams { 25216bc75619SDan Williams return 0; 25226bc75619SDan Williams } 25236bc75619SDan Williams 25246bc75619SDan Williams static void nfit_test_release(struct device *dev) 25256bc75619SDan Williams { 25266bc75619SDan Williams struct nfit_test *nfit_test = to_nfit_test(dev); 25276bc75619SDan Williams 25286bc75619SDan Williams kfree(nfit_test); 25296bc75619SDan Williams } 25306bc75619SDan Williams 25316bc75619SDan Williams static const struct platform_device_id nfit_test_id[] = { 25326bc75619SDan Williams { KBUILD_MODNAME }, 25336bc75619SDan Williams { }, 25346bc75619SDan Williams }; 25356bc75619SDan Williams 25366bc75619SDan Williams static struct platform_driver nfit_test_driver = { 25376bc75619SDan Williams .probe = nfit_test_probe, 25386bc75619SDan Williams .remove = nfit_test_remove, 25396bc75619SDan Williams .driver = { 25406bc75619SDan Williams .name = KBUILD_MODNAME, 25416bc75619SDan Williams }, 25426bc75619SDan Williams .id_table = nfit_test_id, 25436bc75619SDan Williams }; 25446bc75619SDan Williams 25456bc75619SDan Williams static __init int nfit_test_init(void) 25466bc75619SDan Williams { 25476bc75619SDan Williams int rc, i; 25486bc75619SDan Williams 2549*0fb5c8dfSDan Williams pmem_test(); 2550*0fb5c8dfSDan Williams libnvdimm_test(); 2551*0fb5c8dfSDan Williams acpi_nfit_test(); 2552*0fb5c8dfSDan Williams device_dax_test(); 2553*0fb5c8dfSDan Williams 2554a7de92daSDan Williams nfit_test_setup(nfit_test_lookup, nfit_test_evaluate_dsm); 2555231bf117SDan Williams 25569fb1a190SDave Jiang nfit_wq = create_singlethread_workqueue("nfit"); 25579fb1a190SDave Jiang if (!nfit_wq) 25589fb1a190SDave Jiang return -ENOMEM; 25599fb1a190SDave Jiang 2560a7de92daSDan Williams nfit_test_dimm = class_create(THIS_MODULE, "nfit_test_dimm"); 2561a7de92daSDan Williams if (IS_ERR(nfit_test_dimm)) { 2562a7de92daSDan Williams rc = PTR_ERR(nfit_test_dimm); 2563a7de92daSDan Williams goto err_register; 2564a7de92daSDan Williams } 25656bc75619SDan Williams 25666bc75619SDan Williams for (i = 0; i < NUM_NFITS; i++) { 25676bc75619SDan Williams struct nfit_test *nfit_test; 25686bc75619SDan Williams struct platform_device *pdev; 25696bc75619SDan Williams 25706bc75619SDan Williams nfit_test = kzalloc(sizeof(*nfit_test), GFP_KERNEL); 25716bc75619SDan Williams if (!nfit_test) { 25726bc75619SDan Williams rc = -ENOMEM; 25736bc75619SDan Williams goto err_register; 25746bc75619SDan Williams } 25756bc75619SDan Williams INIT_LIST_HEAD(&nfit_test->resources); 25769fb1a190SDave Jiang badrange_init(&nfit_test->badrange); 25776bc75619SDan Williams switch (i) { 25786bc75619SDan Williams case 0: 25796bc75619SDan Williams nfit_test->num_pm = NUM_PM; 2580dafb1048SDan Williams nfit_test->dcr_idx = 0; 25816bc75619SDan Williams nfit_test->num_dcr = NUM_DCR; 25826bc75619SDan Williams nfit_test->alloc = nfit_test0_alloc; 25836bc75619SDan Williams nfit_test->setup = nfit_test0_setup; 25846bc75619SDan Williams break; 25856bc75619SDan Williams case 1: 2586a117699cSYasunori Goto nfit_test->num_pm = 2; 2587dafb1048SDan Williams nfit_test->dcr_idx = NUM_DCR; 2588ac40b675SDan Williams nfit_test->num_dcr = 2; 25896bc75619SDan Williams nfit_test->alloc = nfit_test1_alloc; 25906bc75619SDan Williams nfit_test->setup = nfit_test1_setup; 25916bc75619SDan Williams break; 25926bc75619SDan Williams default: 25936bc75619SDan Williams rc = -EINVAL; 25946bc75619SDan Williams goto err_register; 25956bc75619SDan Williams } 25966bc75619SDan Williams pdev = &nfit_test->pdev; 25976bc75619SDan Williams pdev->name = KBUILD_MODNAME; 25986bc75619SDan Williams pdev->id = i; 25996bc75619SDan Williams pdev->dev.release = nfit_test_release; 26006bc75619SDan Williams rc = platform_device_register(pdev); 26016bc75619SDan Williams if (rc) { 26026bc75619SDan Williams put_device(&pdev->dev); 26036bc75619SDan Williams goto err_register; 26046bc75619SDan Williams } 26058b06b884SDan Williams get_device(&pdev->dev); 26066bc75619SDan Williams 26076bc75619SDan Williams rc = dma_coerce_mask_and_coherent(&pdev->dev, DMA_BIT_MASK(64)); 26086bc75619SDan Williams if (rc) 26096bc75619SDan Williams goto err_register; 26106bc75619SDan Williams 26116bc75619SDan Williams instances[i] = nfit_test; 26129fb1a190SDave Jiang INIT_WORK(&nfit_test->work, uc_error_notify); 26136bc75619SDan Williams } 26146bc75619SDan Williams 26156bc75619SDan Williams rc = platform_driver_register(&nfit_test_driver); 26166bc75619SDan Williams if (rc) 26176bc75619SDan Williams goto err_register; 26186bc75619SDan Williams return 0; 26196bc75619SDan Williams 26206bc75619SDan Williams err_register: 26219fb1a190SDave Jiang destroy_workqueue(nfit_wq); 26226bc75619SDan Williams for (i = 0; i < NUM_NFITS; i++) 26236bc75619SDan Williams if (instances[i]) 26246bc75619SDan Williams platform_device_unregister(&instances[i]->pdev); 26256bc75619SDan Williams nfit_test_teardown(); 26268b06b884SDan Williams for (i = 0; i < NUM_NFITS; i++) 26278b06b884SDan Williams if (instances[i]) 26288b06b884SDan Williams put_device(&instances[i]->pdev.dev); 26298b06b884SDan Williams 26306bc75619SDan Williams return rc; 26316bc75619SDan Williams } 26326bc75619SDan Williams 26336bc75619SDan Williams static __exit void nfit_test_exit(void) 26346bc75619SDan Williams { 26356bc75619SDan Williams int i; 26366bc75619SDan Williams 26379fb1a190SDave Jiang flush_workqueue(nfit_wq); 26389fb1a190SDave Jiang destroy_workqueue(nfit_wq); 26396bc75619SDan Williams for (i = 0; i < NUM_NFITS; i++) 26406bc75619SDan Williams platform_device_unregister(&instances[i]->pdev); 26418b06b884SDan Williams platform_driver_unregister(&nfit_test_driver); 26426bc75619SDan Williams nfit_test_teardown(); 26438b06b884SDan Williams 26448b06b884SDan Williams for (i = 0; i < NUM_NFITS; i++) 26458b06b884SDan Williams put_device(&instances[i]->pdev.dev); 2646231bf117SDan Williams class_destroy(nfit_test_dimm); 26476bc75619SDan Williams } 26486bc75619SDan Williams 26496bc75619SDan Williams module_init(nfit_test_init); 26506bc75619SDan Williams module_exit(nfit_test_exit); 26516bc75619SDan Williams MODULE_LICENSE("GPL v2"); 26526bc75619SDan Williams MODULE_AUTHOR("Intel Corporation"); 2653