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" 300fb5c8dfSDan 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, 1079741a559SRoss Zwisler NUM_MEM = NUM_DCR + NUM_BDW + 2 /* spa0 iset */ 1089741a559SRoss Zwisler + 4 /* spa1 iset */ + 1 /* spa11 iset */, 1096bc75619SDan Williams DIMM_SIZE = SZ_32M, 1106bc75619SDan Williams LABEL_SIZE = SZ_128K, 1117bfe97c7SDan Williams SPA_VCD_SIZE = SZ_4M, 1126bc75619SDan Williams SPA0_SIZE = DIMM_SIZE, 1136bc75619SDan Williams SPA1_SIZE = DIMM_SIZE*2, 1146bc75619SDan Williams SPA2_SIZE = DIMM_SIZE, 1156bc75619SDan Williams BDW_SIZE = 64 << 8, 1166bc75619SDan Williams DCR_SIZE = 12, 1176bc75619SDan Williams NUM_NFITS = 2, /* permit testing multiple NFITs per system */ 1186bc75619SDan Williams }; 1196bc75619SDan Williams 1206bc75619SDan Williams struct nfit_test_dcr { 1216bc75619SDan Williams __le64 bdw_addr; 1226bc75619SDan Williams __le32 bdw_status; 1236bc75619SDan Williams __u8 aperature[BDW_SIZE]; 1246bc75619SDan Williams }; 1256bc75619SDan Williams 1266bc75619SDan Williams #define NFIT_DIMM_HANDLE(node, socket, imc, chan, dimm) \ 1276bc75619SDan Williams (((node & 0xfff) << 16) | ((socket & 0xf) << 12) \ 1286bc75619SDan Williams | ((imc & 0xf) << 8) | ((chan & 0xf) << 4) | (dimm & 0xf)) 1296bc75619SDan Williams 130dafb1048SDan Williams static u32 handle[] = { 1316bc75619SDan Williams [0] = NFIT_DIMM_HANDLE(0, 0, 0, 0, 0), 1326bc75619SDan Williams [1] = NFIT_DIMM_HANDLE(0, 0, 0, 0, 1), 1336bc75619SDan Williams [2] = NFIT_DIMM_HANDLE(0, 0, 1, 0, 0), 1346bc75619SDan Williams [3] = NFIT_DIMM_HANDLE(0, 0, 1, 0, 1), 13520985164SVishal Verma [4] = NFIT_DIMM_HANDLE(0, 1, 0, 0, 0), 136dafb1048SDan Williams [5] = NFIT_DIMM_HANDLE(1, 0, 0, 0, 0), 137ac40b675SDan Williams [6] = NFIT_DIMM_HANDLE(1, 0, 0, 0, 1), 1386bc75619SDan Williams }; 1396bc75619SDan Williams 14073606afdSDan Williams static unsigned long dimm_fail_cmd_flags[NUM_DCR]; 14173606afdSDan Williams 142bfbaa952SDave Jiang struct nfit_test_fw { 143bfbaa952SDave Jiang enum intel_fw_update_state state; 144bfbaa952SDave Jiang u32 context; 145bfbaa952SDave Jiang u64 version; 146bfbaa952SDave Jiang u32 size_received; 147bfbaa952SDave Jiang u64 end_time; 148bfbaa952SDave Jiang }; 149bfbaa952SDave Jiang 1506bc75619SDan Williams struct nfit_test { 1516bc75619SDan Williams struct acpi_nfit_desc acpi_desc; 1526bc75619SDan Williams struct platform_device pdev; 1536bc75619SDan Williams struct list_head resources; 1546bc75619SDan Williams void *nfit_buf; 1556bc75619SDan Williams dma_addr_t nfit_dma; 1566bc75619SDan Williams size_t nfit_size; 157*1526f9e2SRoss Zwisler size_t nfit_filled; 158dafb1048SDan Williams int dcr_idx; 1596bc75619SDan Williams int num_dcr; 1606bc75619SDan Williams int num_pm; 1616bc75619SDan Williams void **dimm; 1626bc75619SDan Williams dma_addr_t *dimm_dma; 1639d27a87eSDan Williams void **flush; 1649d27a87eSDan Williams dma_addr_t *flush_dma; 1656bc75619SDan Williams void **label; 1666bc75619SDan Williams dma_addr_t *label_dma; 1676bc75619SDan Williams void **spa_set; 1686bc75619SDan Williams dma_addr_t *spa_set_dma; 1696bc75619SDan Williams struct nfit_test_dcr **dcr; 1706bc75619SDan Williams dma_addr_t *dcr_dma; 1716bc75619SDan Williams int (*alloc)(struct nfit_test *t); 1726bc75619SDan Williams void (*setup)(struct nfit_test *t); 17320985164SVishal Verma int setup_hotplug; 174c14a868aSDan Williams union acpi_object **_fit; 175c14a868aSDan Williams dma_addr_t _fit_dma; 176f471f1a7SDan Williams struct ars_state { 177f471f1a7SDan Williams struct nd_cmd_ars_status *ars_status; 178f471f1a7SDan Williams unsigned long deadline; 179f471f1a7SDan Williams spinlock_t lock; 180f471f1a7SDan Williams } ars_state; 181231bf117SDan Williams struct device *dimm_dev[NUM_DCR]; 182ed07c433SDan Williams struct nd_intel_smart *smart; 183ed07c433SDan Williams struct nd_intel_smart_threshold *smart_threshold; 1849fb1a190SDave Jiang struct badrange badrange; 1859fb1a190SDave Jiang struct work_struct work; 186bfbaa952SDave Jiang struct nfit_test_fw *fw; 1876bc75619SDan Williams }; 1886bc75619SDan Williams 1899fb1a190SDave Jiang static struct workqueue_struct *nfit_wq; 1909fb1a190SDave Jiang 1916bc75619SDan Williams static struct nfit_test *to_nfit_test(struct device *dev) 1926bc75619SDan Williams { 1936bc75619SDan Williams struct platform_device *pdev = to_platform_device(dev); 1946bc75619SDan Williams 1956bc75619SDan Williams return container_of(pdev, struct nfit_test, pdev); 1966bc75619SDan Williams } 1976bc75619SDan Williams 198bfbaa952SDave Jiang static int nd_intel_test_get_fw_info(struct nfit_test *t, 199bfbaa952SDave Jiang struct nd_intel_fw_info *nd_cmd, unsigned int buf_len, 200bfbaa952SDave Jiang int idx) 201bfbaa952SDave Jiang { 202bfbaa952SDave Jiang struct device *dev = &t->pdev.dev; 203bfbaa952SDave Jiang struct nfit_test_fw *fw = &t->fw[idx]; 204bfbaa952SDave Jiang 205bfbaa952SDave Jiang dev_dbg(dev, "%s(nfit_test: %p nd_cmd: %p, buf_len: %u, idx: %d\n", 206bfbaa952SDave Jiang __func__, t, nd_cmd, buf_len, idx); 207bfbaa952SDave Jiang 208bfbaa952SDave Jiang if (buf_len < sizeof(*nd_cmd)) 209bfbaa952SDave Jiang return -EINVAL; 210bfbaa952SDave Jiang 211bfbaa952SDave Jiang nd_cmd->status = 0; 212bfbaa952SDave Jiang nd_cmd->storage_size = INTEL_FW_STORAGE_SIZE; 213bfbaa952SDave Jiang nd_cmd->max_send_len = INTEL_FW_MAX_SEND_LEN; 214bfbaa952SDave Jiang nd_cmd->query_interval = INTEL_FW_QUERY_INTERVAL; 215bfbaa952SDave Jiang nd_cmd->max_query_time = INTEL_FW_QUERY_MAX_TIME; 216bfbaa952SDave Jiang nd_cmd->update_cap = 0; 217bfbaa952SDave Jiang nd_cmd->fis_version = INTEL_FW_FIS_VERSION; 218bfbaa952SDave Jiang nd_cmd->run_version = 0; 219bfbaa952SDave Jiang nd_cmd->updated_version = fw->version; 220bfbaa952SDave Jiang 221bfbaa952SDave Jiang return 0; 222bfbaa952SDave Jiang } 223bfbaa952SDave Jiang 224bfbaa952SDave Jiang static int nd_intel_test_start_update(struct nfit_test *t, 225bfbaa952SDave Jiang struct nd_intel_fw_start *nd_cmd, unsigned int buf_len, 226bfbaa952SDave Jiang int idx) 227bfbaa952SDave Jiang { 228bfbaa952SDave Jiang struct device *dev = &t->pdev.dev; 229bfbaa952SDave Jiang struct nfit_test_fw *fw = &t->fw[idx]; 230bfbaa952SDave Jiang 231bfbaa952SDave Jiang dev_dbg(dev, "%s(nfit_test: %p nd_cmd: %p buf_len: %u idx: %d)\n", 232bfbaa952SDave Jiang __func__, t, nd_cmd, buf_len, idx); 233bfbaa952SDave Jiang 234bfbaa952SDave Jiang if (buf_len < sizeof(*nd_cmd)) 235bfbaa952SDave Jiang return -EINVAL; 236bfbaa952SDave Jiang 237bfbaa952SDave Jiang if (fw->state != FW_STATE_NEW) { 238bfbaa952SDave Jiang /* extended status, FW update in progress */ 239bfbaa952SDave Jiang nd_cmd->status = 0x10007; 240bfbaa952SDave Jiang return 0; 241bfbaa952SDave Jiang } 242bfbaa952SDave Jiang 243bfbaa952SDave Jiang fw->state = FW_STATE_IN_PROGRESS; 244bfbaa952SDave Jiang fw->context++; 245bfbaa952SDave Jiang fw->size_received = 0; 246bfbaa952SDave Jiang nd_cmd->status = 0; 247bfbaa952SDave Jiang nd_cmd->context = fw->context; 248bfbaa952SDave Jiang 249bfbaa952SDave Jiang dev_dbg(dev, "%s: context issued: %#x\n", __func__, nd_cmd->context); 250bfbaa952SDave Jiang 251bfbaa952SDave Jiang return 0; 252bfbaa952SDave Jiang } 253bfbaa952SDave Jiang 254bfbaa952SDave Jiang static int nd_intel_test_send_data(struct nfit_test *t, 255bfbaa952SDave Jiang struct nd_intel_fw_send_data *nd_cmd, unsigned int buf_len, 256bfbaa952SDave Jiang int idx) 257bfbaa952SDave Jiang { 258bfbaa952SDave Jiang struct device *dev = &t->pdev.dev; 259bfbaa952SDave Jiang struct nfit_test_fw *fw = &t->fw[idx]; 260bfbaa952SDave Jiang u32 *status = (u32 *)&nd_cmd->data[nd_cmd->length]; 261bfbaa952SDave Jiang 262bfbaa952SDave Jiang dev_dbg(dev, "%s(nfit_test: %p nd_cmd: %p buf_len: %u idx: %d)\n", 263bfbaa952SDave Jiang __func__, t, nd_cmd, buf_len, idx); 264bfbaa952SDave Jiang 265bfbaa952SDave Jiang if (buf_len < sizeof(*nd_cmd)) 266bfbaa952SDave Jiang return -EINVAL; 267bfbaa952SDave Jiang 268bfbaa952SDave Jiang 269bfbaa952SDave Jiang dev_dbg(dev, "%s: cmd->status: %#x\n", __func__, *status); 270bfbaa952SDave Jiang dev_dbg(dev, "%s: cmd->data[0]: %#x\n", __func__, nd_cmd->data[0]); 271bfbaa952SDave Jiang dev_dbg(dev, "%s: cmd->data[%u]: %#x\n", __func__, nd_cmd->length-1, 272bfbaa952SDave Jiang nd_cmd->data[nd_cmd->length-1]); 273bfbaa952SDave Jiang 274bfbaa952SDave Jiang if (fw->state != FW_STATE_IN_PROGRESS) { 275bfbaa952SDave Jiang dev_dbg(dev, "%s: not in IN_PROGRESS state\n", __func__); 276bfbaa952SDave Jiang *status = 0x5; 277bfbaa952SDave Jiang return 0; 278bfbaa952SDave Jiang } 279bfbaa952SDave Jiang 280bfbaa952SDave Jiang if (nd_cmd->context != fw->context) { 281bfbaa952SDave Jiang dev_dbg(dev, "%s: incorrect context: in: %#x correct: %#x\n", 282bfbaa952SDave Jiang __func__, nd_cmd->context, fw->context); 283bfbaa952SDave Jiang *status = 0x10007; 284bfbaa952SDave Jiang return 0; 285bfbaa952SDave Jiang } 286bfbaa952SDave Jiang 287bfbaa952SDave Jiang /* 288bfbaa952SDave Jiang * check offset + len > size of fw storage 289bfbaa952SDave Jiang * check length is > max send length 290bfbaa952SDave Jiang */ 291bfbaa952SDave Jiang if (nd_cmd->offset + nd_cmd->length > INTEL_FW_STORAGE_SIZE || 292bfbaa952SDave Jiang nd_cmd->length > INTEL_FW_MAX_SEND_LEN) { 293bfbaa952SDave Jiang *status = 0x3; 294bfbaa952SDave Jiang dev_dbg(dev, "%s: buffer boundary violation\n", __func__); 295bfbaa952SDave Jiang return 0; 296bfbaa952SDave Jiang } 297bfbaa952SDave Jiang 298bfbaa952SDave Jiang fw->size_received += nd_cmd->length; 299bfbaa952SDave Jiang dev_dbg(dev, "%s: copying %u bytes, %u bytes so far\n", 300bfbaa952SDave Jiang __func__, nd_cmd->length, fw->size_received); 301bfbaa952SDave Jiang *status = 0; 302bfbaa952SDave Jiang return 0; 303bfbaa952SDave Jiang } 304bfbaa952SDave Jiang 305bfbaa952SDave Jiang static int nd_intel_test_finish_fw(struct nfit_test *t, 306bfbaa952SDave Jiang struct nd_intel_fw_finish_update *nd_cmd, 307bfbaa952SDave Jiang unsigned int buf_len, int idx) 308bfbaa952SDave Jiang { 309bfbaa952SDave Jiang struct device *dev = &t->pdev.dev; 310bfbaa952SDave Jiang struct nfit_test_fw *fw = &t->fw[idx]; 311bfbaa952SDave Jiang 312bfbaa952SDave Jiang dev_dbg(dev, "%s(nfit_test: %p nd_cmd: %p buf_len: %u idx: %d)\n", 313bfbaa952SDave Jiang __func__, t, nd_cmd, buf_len, idx); 314bfbaa952SDave Jiang 315bfbaa952SDave Jiang if (fw->state == FW_STATE_UPDATED) { 316bfbaa952SDave Jiang /* update already done, need cold boot */ 317bfbaa952SDave Jiang nd_cmd->status = 0x20007; 318bfbaa952SDave Jiang return 0; 319bfbaa952SDave Jiang } 320bfbaa952SDave Jiang 321bfbaa952SDave Jiang dev_dbg(dev, "%s: context: %#x ctrl_flags: %#x\n", 322bfbaa952SDave Jiang __func__, nd_cmd->context, nd_cmd->ctrl_flags); 323bfbaa952SDave Jiang 324bfbaa952SDave Jiang switch (nd_cmd->ctrl_flags) { 325bfbaa952SDave Jiang case 0: /* finish */ 326bfbaa952SDave Jiang if (nd_cmd->context != fw->context) { 327bfbaa952SDave Jiang dev_dbg(dev, "%s: incorrect context: in: %#x correct: %#x\n", 328bfbaa952SDave Jiang __func__, nd_cmd->context, 329bfbaa952SDave Jiang fw->context); 330bfbaa952SDave Jiang nd_cmd->status = 0x10007; 331bfbaa952SDave Jiang return 0; 332bfbaa952SDave Jiang } 333bfbaa952SDave Jiang nd_cmd->status = 0; 334bfbaa952SDave Jiang fw->state = FW_STATE_VERIFY; 335bfbaa952SDave Jiang /* set 1 second of time for firmware "update" */ 336bfbaa952SDave Jiang fw->end_time = jiffies + HZ; 337bfbaa952SDave Jiang break; 338bfbaa952SDave Jiang 339bfbaa952SDave Jiang case 1: /* abort */ 340bfbaa952SDave Jiang fw->size_received = 0; 341bfbaa952SDave Jiang /* successfully aborted status */ 342bfbaa952SDave Jiang nd_cmd->status = 0x40007; 343bfbaa952SDave Jiang fw->state = FW_STATE_NEW; 344bfbaa952SDave Jiang dev_dbg(dev, "%s: abort successful\n", __func__); 345bfbaa952SDave Jiang break; 346bfbaa952SDave Jiang 347bfbaa952SDave Jiang default: /* bad control flag */ 348bfbaa952SDave Jiang dev_warn(dev, "%s: unknown control flag: %#x\n", 349bfbaa952SDave Jiang __func__, nd_cmd->ctrl_flags); 350bfbaa952SDave Jiang return -EINVAL; 351bfbaa952SDave Jiang } 352bfbaa952SDave Jiang 353bfbaa952SDave Jiang return 0; 354bfbaa952SDave Jiang } 355bfbaa952SDave Jiang 356bfbaa952SDave Jiang static int nd_intel_test_finish_query(struct nfit_test *t, 357bfbaa952SDave Jiang struct nd_intel_fw_finish_query *nd_cmd, 358bfbaa952SDave Jiang unsigned int buf_len, int idx) 359bfbaa952SDave Jiang { 360bfbaa952SDave Jiang struct device *dev = &t->pdev.dev; 361bfbaa952SDave Jiang struct nfit_test_fw *fw = &t->fw[idx]; 362bfbaa952SDave Jiang 363bfbaa952SDave Jiang dev_dbg(dev, "%s(nfit_test: %p nd_cmd: %p buf_len: %u idx: %d)\n", 364bfbaa952SDave Jiang __func__, t, nd_cmd, buf_len, idx); 365bfbaa952SDave Jiang 366bfbaa952SDave Jiang if (buf_len < sizeof(*nd_cmd)) 367bfbaa952SDave Jiang return -EINVAL; 368bfbaa952SDave Jiang 369bfbaa952SDave Jiang if (nd_cmd->context != fw->context) { 370bfbaa952SDave Jiang dev_dbg(dev, "%s: incorrect context: in: %#x correct: %#x\n", 371bfbaa952SDave Jiang __func__, nd_cmd->context, fw->context); 372bfbaa952SDave Jiang nd_cmd->status = 0x10007; 373bfbaa952SDave Jiang return 0; 374bfbaa952SDave Jiang } 375bfbaa952SDave Jiang 376bfbaa952SDave Jiang dev_dbg(dev, "%s context: %#x\n", __func__, nd_cmd->context); 377bfbaa952SDave Jiang 378bfbaa952SDave Jiang switch (fw->state) { 379bfbaa952SDave Jiang case FW_STATE_NEW: 380bfbaa952SDave Jiang nd_cmd->updated_fw_rev = 0; 381bfbaa952SDave Jiang nd_cmd->status = 0; 382bfbaa952SDave Jiang dev_dbg(dev, "%s: new state\n", __func__); 383bfbaa952SDave Jiang break; 384bfbaa952SDave Jiang 385bfbaa952SDave Jiang case FW_STATE_IN_PROGRESS: 386bfbaa952SDave Jiang /* sequencing error */ 387bfbaa952SDave Jiang nd_cmd->status = 0x40007; 388bfbaa952SDave Jiang nd_cmd->updated_fw_rev = 0; 389bfbaa952SDave Jiang dev_dbg(dev, "%s: sequence error\n", __func__); 390bfbaa952SDave Jiang break; 391bfbaa952SDave Jiang 392bfbaa952SDave Jiang case FW_STATE_VERIFY: 393bfbaa952SDave Jiang if (time_is_after_jiffies64(fw->end_time)) { 394bfbaa952SDave Jiang nd_cmd->updated_fw_rev = 0; 395bfbaa952SDave Jiang nd_cmd->status = 0x20007; 396bfbaa952SDave Jiang dev_dbg(dev, "%s: still verifying\n", __func__); 397bfbaa952SDave Jiang break; 398bfbaa952SDave Jiang } 399bfbaa952SDave Jiang 400bfbaa952SDave Jiang dev_dbg(dev, "%s: transition out verify\n", __func__); 401bfbaa952SDave Jiang fw->state = FW_STATE_UPDATED; 402bfbaa952SDave Jiang /* we are going to fall through if it's "done" */ 403bfbaa952SDave Jiang case FW_STATE_UPDATED: 404bfbaa952SDave Jiang nd_cmd->status = 0; 405bfbaa952SDave Jiang /* bogus test version */ 406bfbaa952SDave Jiang fw->version = nd_cmd->updated_fw_rev = 407bfbaa952SDave Jiang INTEL_FW_FAKE_VERSION; 408bfbaa952SDave Jiang dev_dbg(dev, "%s: updated\n", __func__); 409bfbaa952SDave Jiang break; 410bfbaa952SDave Jiang 411bfbaa952SDave Jiang default: /* we should never get here */ 412bfbaa952SDave Jiang return -EINVAL; 413bfbaa952SDave Jiang } 414bfbaa952SDave Jiang 415bfbaa952SDave Jiang return 0; 416bfbaa952SDave Jiang } 417bfbaa952SDave Jiang 41839c686b8SVishal Verma static int nfit_test_cmd_get_config_size(struct nd_cmd_get_config_size *nd_cmd, 4196bc75619SDan Williams unsigned int buf_len) 4206bc75619SDan Williams { 4216bc75619SDan Williams if (buf_len < sizeof(*nd_cmd)) 4226bc75619SDan Williams return -EINVAL; 42339c686b8SVishal Verma 4246bc75619SDan Williams nd_cmd->status = 0; 4256bc75619SDan Williams nd_cmd->config_size = LABEL_SIZE; 4266bc75619SDan Williams nd_cmd->max_xfer = SZ_4K; 42739c686b8SVishal Verma 42839c686b8SVishal Verma return 0; 4296bc75619SDan Williams } 43039c686b8SVishal Verma 43139c686b8SVishal Verma static int nfit_test_cmd_get_config_data(struct nd_cmd_get_config_data_hdr 43239c686b8SVishal Verma *nd_cmd, unsigned int buf_len, void *label) 43339c686b8SVishal Verma { 4346bc75619SDan Williams unsigned int len, offset = nd_cmd->in_offset; 43539c686b8SVishal Verma int rc; 4366bc75619SDan Williams 4376bc75619SDan Williams if (buf_len < sizeof(*nd_cmd)) 4386bc75619SDan Williams return -EINVAL; 4396bc75619SDan Williams if (offset >= LABEL_SIZE) 4406bc75619SDan Williams return -EINVAL; 4416bc75619SDan Williams if (nd_cmd->in_length + sizeof(*nd_cmd) > buf_len) 4426bc75619SDan Williams return -EINVAL; 4436bc75619SDan Williams 4446bc75619SDan Williams nd_cmd->status = 0; 4456bc75619SDan Williams len = min(nd_cmd->in_length, LABEL_SIZE - offset); 44639c686b8SVishal Verma memcpy(nd_cmd->out_buf, label + offset, len); 4476bc75619SDan Williams rc = buf_len - sizeof(*nd_cmd) - len; 44839c686b8SVishal Verma 44939c686b8SVishal Verma return rc; 4506bc75619SDan Williams } 45139c686b8SVishal Verma 45239c686b8SVishal Verma static int nfit_test_cmd_set_config_data(struct nd_cmd_set_config_hdr *nd_cmd, 45339c686b8SVishal Verma unsigned int buf_len, void *label) 45439c686b8SVishal Verma { 4556bc75619SDan Williams unsigned int len, offset = nd_cmd->in_offset; 4566bc75619SDan Williams u32 *status; 45739c686b8SVishal Verma int rc; 4586bc75619SDan Williams 4596bc75619SDan Williams if (buf_len < sizeof(*nd_cmd)) 4606bc75619SDan Williams return -EINVAL; 4616bc75619SDan Williams if (offset >= LABEL_SIZE) 4626bc75619SDan Williams return -EINVAL; 4636bc75619SDan Williams if (nd_cmd->in_length + sizeof(*nd_cmd) + 4 > buf_len) 4646bc75619SDan Williams return -EINVAL; 4656bc75619SDan Williams 46639c686b8SVishal Verma status = (void *)nd_cmd + nd_cmd->in_length + sizeof(*nd_cmd); 4676bc75619SDan Williams *status = 0; 4686bc75619SDan Williams len = min(nd_cmd->in_length, LABEL_SIZE - offset); 46939c686b8SVishal Verma memcpy(label + offset, nd_cmd->in_buf, len); 4706bc75619SDan Williams rc = buf_len - sizeof(*nd_cmd) - (len + 4); 47139c686b8SVishal Verma 47239c686b8SVishal Verma return rc; 4736bc75619SDan Williams } 47439c686b8SVishal Verma 475d4f32367SDan Williams #define NFIT_TEST_CLEAR_ERR_UNIT 256 476747ffe11SDan Williams 47739c686b8SVishal Verma static int nfit_test_cmd_ars_cap(struct nd_cmd_ars_cap *nd_cmd, 47839c686b8SVishal Verma unsigned int buf_len) 47939c686b8SVishal Verma { 4809fb1a190SDave Jiang int ars_recs; 4819fb1a190SDave Jiang 48239c686b8SVishal Verma if (buf_len < sizeof(*nd_cmd)) 48339c686b8SVishal Verma return -EINVAL; 48439c686b8SVishal Verma 4859fb1a190SDave Jiang /* for testing, only store up to n records that fit within 4k */ 4869fb1a190SDave Jiang ars_recs = SZ_4K / sizeof(struct nd_ars_record); 4879fb1a190SDave Jiang 488747ffe11SDan Williams nd_cmd->max_ars_out = sizeof(struct nd_cmd_ars_status) 4899fb1a190SDave Jiang + ars_recs * sizeof(struct nd_ars_record); 49039c686b8SVishal Verma nd_cmd->status = (ND_ARS_PERSISTENT | ND_ARS_VOLATILE) << 16; 491d4f32367SDan Williams nd_cmd->clear_err_unit = NFIT_TEST_CLEAR_ERR_UNIT; 49239c686b8SVishal Verma 49339c686b8SVishal Verma return 0; 49439c686b8SVishal Verma } 49539c686b8SVishal Verma 4969fb1a190SDave Jiang static void post_ars_status(struct ars_state *ars_state, 4979fb1a190SDave Jiang struct badrange *badrange, u64 addr, u64 len) 49839c686b8SVishal Verma { 499f471f1a7SDan Williams struct nd_cmd_ars_status *ars_status; 500f471f1a7SDan Williams struct nd_ars_record *ars_record; 5019fb1a190SDave Jiang struct badrange_entry *be; 5029fb1a190SDave Jiang u64 end = addr + len - 1; 5039fb1a190SDave Jiang int i = 0; 504f471f1a7SDan Williams 505f471f1a7SDan Williams ars_state->deadline = jiffies + 1*HZ; 506f471f1a7SDan Williams ars_status = ars_state->ars_status; 507f471f1a7SDan Williams ars_status->status = 0; 508f471f1a7SDan Williams ars_status->address = addr; 509f471f1a7SDan Williams ars_status->length = len; 510f471f1a7SDan Williams ars_status->type = ND_ARS_PERSISTENT; 5119fb1a190SDave Jiang 5129fb1a190SDave Jiang spin_lock(&badrange->lock); 5139fb1a190SDave Jiang list_for_each_entry(be, &badrange->list, list) { 5149fb1a190SDave Jiang u64 be_end = be->start + be->length - 1; 5159fb1a190SDave Jiang u64 rstart, rend; 5169fb1a190SDave Jiang 5179fb1a190SDave Jiang /* skip entries outside the range */ 5189fb1a190SDave Jiang if (be_end < addr || be->start > end) 5199fb1a190SDave Jiang continue; 5209fb1a190SDave Jiang 5219fb1a190SDave Jiang rstart = (be->start < addr) ? addr : be->start; 5229fb1a190SDave Jiang rend = (be_end < end) ? be_end : end; 5239fb1a190SDave Jiang ars_record = &ars_status->records[i]; 524f471f1a7SDan Williams ars_record->handle = 0; 5259fb1a190SDave Jiang ars_record->err_address = rstart; 5269fb1a190SDave Jiang ars_record->length = rend - rstart + 1; 5279fb1a190SDave Jiang i++; 5289fb1a190SDave Jiang } 5299fb1a190SDave Jiang spin_unlock(&badrange->lock); 5309fb1a190SDave Jiang ars_status->num_records = i; 5319fb1a190SDave Jiang ars_status->out_length = sizeof(struct nd_cmd_ars_status) 5329fb1a190SDave Jiang + i * sizeof(struct nd_ars_record); 533f471f1a7SDan Williams } 534f471f1a7SDan Williams 5359fb1a190SDave Jiang static int nfit_test_cmd_ars_start(struct nfit_test *t, 5369fb1a190SDave Jiang struct ars_state *ars_state, 537f471f1a7SDan Williams struct nd_cmd_ars_start *ars_start, unsigned int buf_len, 538f471f1a7SDan Williams int *cmd_rc) 539f471f1a7SDan Williams { 540f471f1a7SDan Williams if (buf_len < sizeof(*ars_start)) 54139c686b8SVishal Verma return -EINVAL; 54239c686b8SVishal Verma 543f471f1a7SDan Williams spin_lock(&ars_state->lock); 544f471f1a7SDan Williams if (time_before(jiffies, ars_state->deadline)) { 545f471f1a7SDan Williams ars_start->status = NFIT_ARS_START_BUSY; 546f471f1a7SDan Williams *cmd_rc = -EBUSY; 547f471f1a7SDan Williams } else { 548f471f1a7SDan Williams ars_start->status = 0; 549f471f1a7SDan Williams ars_start->scrub_time = 1; 5509fb1a190SDave Jiang post_ars_status(ars_state, &t->badrange, ars_start->address, 551f471f1a7SDan Williams ars_start->length); 552f471f1a7SDan Williams *cmd_rc = 0; 553f471f1a7SDan Williams } 554f471f1a7SDan Williams spin_unlock(&ars_state->lock); 55539c686b8SVishal Verma 55639c686b8SVishal Verma return 0; 55739c686b8SVishal Verma } 55839c686b8SVishal Verma 559f471f1a7SDan Williams static int nfit_test_cmd_ars_status(struct ars_state *ars_state, 560f471f1a7SDan Williams struct nd_cmd_ars_status *ars_status, unsigned int buf_len, 561f471f1a7SDan Williams int *cmd_rc) 56239c686b8SVishal Verma { 563f471f1a7SDan Williams if (buf_len < ars_state->ars_status->out_length) 56439c686b8SVishal Verma return -EINVAL; 56539c686b8SVishal Verma 566f471f1a7SDan Williams spin_lock(&ars_state->lock); 567f471f1a7SDan Williams if (time_before(jiffies, ars_state->deadline)) { 568f471f1a7SDan Williams memset(ars_status, 0, buf_len); 569f471f1a7SDan Williams ars_status->status = NFIT_ARS_STATUS_BUSY; 570f471f1a7SDan Williams ars_status->out_length = sizeof(*ars_status); 571f471f1a7SDan Williams *cmd_rc = -EBUSY; 572f471f1a7SDan Williams } else { 573f471f1a7SDan Williams memcpy(ars_status, ars_state->ars_status, 574f471f1a7SDan Williams ars_state->ars_status->out_length); 575f471f1a7SDan Williams *cmd_rc = 0; 576f471f1a7SDan Williams } 577f471f1a7SDan Williams spin_unlock(&ars_state->lock); 57839c686b8SVishal Verma return 0; 57939c686b8SVishal Verma } 58039c686b8SVishal Verma 5815e096ef3SVishal Verma static int nfit_test_cmd_clear_error(struct nfit_test *t, 5825e096ef3SVishal Verma struct nd_cmd_clear_error *clear_err, 583d4f32367SDan Williams unsigned int buf_len, int *cmd_rc) 584d4f32367SDan Williams { 585d4f32367SDan Williams const u64 mask = NFIT_TEST_CLEAR_ERR_UNIT - 1; 586d4f32367SDan Williams if (buf_len < sizeof(*clear_err)) 587d4f32367SDan Williams return -EINVAL; 588d4f32367SDan Williams 589d4f32367SDan Williams if ((clear_err->address & mask) || (clear_err->length & mask)) 590d4f32367SDan Williams return -EINVAL; 591d4f32367SDan Williams 5925e096ef3SVishal Verma badrange_forget(&t->badrange, clear_err->address, clear_err->length); 593d4f32367SDan Williams clear_err->status = 0; 594d4f32367SDan Williams clear_err->cleared = clear_err->length; 595d4f32367SDan Williams *cmd_rc = 0; 596d4f32367SDan Williams return 0; 597d4f32367SDan Williams } 598d4f32367SDan Williams 59910246dc8SYasunori Goto struct region_search_spa { 60010246dc8SYasunori Goto u64 addr; 60110246dc8SYasunori Goto struct nd_region *region; 60210246dc8SYasunori Goto }; 60310246dc8SYasunori Goto 60410246dc8SYasunori Goto static int is_region_device(struct device *dev) 60510246dc8SYasunori Goto { 60610246dc8SYasunori Goto return !strncmp(dev->kobj.name, "region", 6); 60710246dc8SYasunori Goto } 60810246dc8SYasunori Goto 60910246dc8SYasunori Goto static int nfit_test_search_region_spa(struct device *dev, void *data) 61010246dc8SYasunori Goto { 61110246dc8SYasunori Goto struct region_search_spa *ctx = data; 61210246dc8SYasunori Goto struct nd_region *nd_region; 61310246dc8SYasunori Goto resource_size_t ndr_end; 61410246dc8SYasunori Goto 61510246dc8SYasunori Goto if (!is_region_device(dev)) 61610246dc8SYasunori Goto return 0; 61710246dc8SYasunori Goto 61810246dc8SYasunori Goto nd_region = to_nd_region(dev); 61910246dc8SYasunori Goto ndr_end = nd_region->ndr_start + nd_region->ndr_size; 62010246dc8SYasunori Goto 62110246dc8SYasunori Goto if (ctx->addr >= nd_region->ndr_start && ctx->addr < ndr_end) { 62210246dc8SYasunori Goto ctx->region = nd_region; 62310246dc8SYasunori Goto return 1; 62410246dc8SYasunori Goto } 62510246dc8SYasunori Goto 62610246dc8SYasunori Goto return 0; 62710246dc8SYasunori Goto } 62810246dc8SYasunori Goto 62910246dc8SYasunori Goto static int nfit_test_search_spa(struct nvdimm_bus *bus, 63010246dc8SYasunori Goto struct nd_cmd_translate_spa *spa) 63110246dc8SYasunori Goto { 63210246dc8SYasunori Goto int ret; 63310246dc8SYasunori Goto struct nd_region *nd_region = NULL; 63410246dc8SYasunori Goto struct nvdimm *nvdimm = NULL; 63510246dc8SYasunori Goto struct nd_mapping *nd_mapping = NULL; 63610246dc8SYasunori Goto struct region_search_spa ctx = { 63710246dc8SYasunori Goto .addr = spa->spa, 63810246dc8SYasunori Goto .region = NULL, 63910246dc8SYasunori Goto }; 64010246dc8SYasunori Goto u64 dpa; 64110246dc8SYasunori Goto 64210246dc8SYasunori Goto ret = device_for_each_child(&bus->dev, &ctx, 64310246dc8SYasunori Goto nfit_test_search_region_spa); 64410246dc8SYasunori Goto 64510246dc8SYasunori Goto if (!ret) 64610246dc8SYasunori Goto return -ENODEV; 64710246dc8SYasunori Goto 64810246dc8SYasunori Goto nd_region = ctx.region; 64910246dc8SYasunori Goto 65010246dc8SYasunori Goto dpa = ctx.addr - nd_region->ndr_start; 65110246dc8SYasunori Goto 65210246dc8SYasunori Goto /* 65310246dc8SYasunori Goto * last dimm is selected for test 65410246dc8SYasunori Goto */ 65510246dc8SYasunori Goto nd_mapping = &nd_region->mapping[nd_region->ndr_mappings - 1]; 65610246dc8SYasunori Goto nvdimm = nd_mapping->nvdimm; 65710246dc8SYasunori Goto 65810246dc8SYasunori Goto spa->devices[0].nfit_device_handle = handle[nvdimm->id]; 65910246dc8SYasunori Goto spa->num_nvdimms = 1; 66010246dc8SYasunori Goto spa->devices[0].dpa = dpa; 66110246dc8SYasunori Goto 66210246dc8SYasunori Goto return 0; 66310246dc8SYasunori Goto } 66410246dc8SYasunori Goto 66510246dc8SYasunori Goto static int nfit_test_cmd_translate_spa(struct nvdimm_bus *bus, 66610246dc8SYasunori Goto struct nd_cmd_translate_spa *spa, unsigned int buf_len) 66710246dc8SYasunori Goto { 66810246dc8SYasunori Goto if (buf_len < spa->translate_length) 66910246dc8SYasunori Goto return -EINVAL; 67010246dc8SYasunori Goto 67110246dc8SYasunori Goto if (nfit_test_search_spa(bus, spa) < 0 || !spa->num_nvdimms) 67210246dc8SYasunori Goto spa->status = 2; 67310246dc8SYasunori Goto 67410246dc8SYasunori Goto return 0; 67510246dc8SYasunori Goto } 67610246dc8SYasunori Goto 677ed07c433SDan Williams static int nfit_test_cmd_smart(struct nd_intel_smart *smart, unsigned int buf_len, 678ed07c433SDan Williams struct nd_intel_smart *smart_data) 679baa51277SDan Williams { 680baa51277SDan Williams if (buf_len < sizeof(*smart)) 681baa51277SDan Williams return -EINVAL; 682ed07c433SDan Williams memcpy(smart, smart_data, sizeof(*smart)); 683baa51277SDan Williams return 0; 684baa51277SDan Williams } 685baa51277SDan Williams 686cdd77d3eSDan Williams static int nfit_test_cmd_smart_threshold( 687ed07c433SDan Williams struct nd_intel_smart_threshold *out, 688ed07c433SDan Williams unsigned int buf_len, 689ed07c433SDan Williams struct nd_intel_smart_threshold *smart_t) 690baa51277SDan Williams { 691baa51277SDan Williams if (buf_len < sizeof(*smart_t)) 692baa51277SDan Williams return -EINVAL; 693ed07c433SDan Williams memcpy(out, smart_t, sizeof(*smart_t)); 694ed07c433SDan Williams return 0; 695ed07c433SDan Williams } 696ed07c433SDan Williams 697ed07c433SDan Williams static void smart_notify(struct device *bus_dev, 698ed07c433SDan Williams struct device *dimm_dev, struct nd_intel_smart *smart, 699ed07c433SDan Williams struct nd_intel_smart_threshold *thresh) 700ed07c433SDan Williams { 701ed07c433SDan Williams dev_dbg(dimm_dev, "%s: alarm: %#x spares: %d (%d) mtemp: %d (%d) ctemp: %d (%d)\n", 702ed07c433SDan Williams __func__, thresh->alarm_control, thresh->spares, 703ed07c433SDan Williams smart->spares, thresh->media_temperature, 704ed07c433SDan Williams smart->media_temperature, thresh->ctrl_temperature, 705ed07c433SDan Williams smart->ctrl_temperature); 706ed07c433SDan Williams if (((thresh->alarm_control & ND_INTEL_SMART_SPARE_TRIP) 707ed07c433SDan Williams && smart->spares 708ed07c433SDan Williams <= thresh->spares) 709ed07c433SDan Williams || ((thresh->alarm_control & ND_INTEL_SMART_TEMP_TRIP) 710ed07c433SDan Williams && smart->media_temperature 711ed07c433SDan Williams >= thresh->media_temperature) 712ed07c433SDan Williams || ((thresh->alarm_control & ND_INTEL_SMART_CTEMP_TRIP) 713ed07c433SDan Williams && smart->ctrl_temperature 714ed07c433SDan Williams >= thresh->ctrl_temperature)) { 715ed07c433SDan Williams device_lock(bus_dev); 716ed07c433SDan Williams __acpi_nvdimm_notify(dimm_dev, 0x81); 717ed07c433SDan Williams device_unlock(bus_dev); 718ed07c433SDan Williams } 719ed07c433SDan Williams } 720ed07c433SDan Williams 721ed07c433SDan Williams static int nfit_test_cmd_smart_set_threshold( 722ed07c433SDan Williams struct nd_intel_smart_set_threshold *in, 723ed07c433SDan Williams unsigned int buf_len, 724ed07c433SDan Williams struct nd_intel_smart_threshold *thresh, 725ed07c433SDan Williams struct nd_intel_smart *smart, 726ed07c433SDan Williams struct device *bus_dev, struct device *dimm_dev) 727ed07c433SDan Williams { 728ed07c433SDan Williams unsigned int size; 729ed07c433SDan Williams 730ed07c433SDan Williams size = sizeof(*in) - 4; 731ed07c433SDan Williams if (buf_len < size) 732ed07c433SDan Williams return -EINVAL; 733ed07c433SDan Williams memcpy(thresh->data, in, size); 734ed07c433SDan Williams in->status = 0; 735ed07c433SDan Williams smart_notify(bus_dev, dimm_dev, smart, thresh); 736ed07c433SDan Williams 737baa51277SDan Williams return 0; 738baa51277SDan Williams } 739baa51277SDan Williams 7409fb1a190SDave Jiang static void uc_error_notify(struct work_struct *work) 7419fb1a190SDave Jiang { 7429fb1a190SDave Jiang struct nfit_test *t = container_of(work, typeof(*t), work); 7439fb1a190SDave Jiang 7449fb1a190SDave Jiang __acpi_nfit_notify(&t->pdev.dev, t, NFIT_NOTIFY_UC_MEMORY_ERROR); 7459fb1a190SDave Jiang } 7469fb1a190SDave Jiang 7479fb1a190SDave Jiang static int nfit_test_cmd_ars_error_inject(struct nfit_test *t, 7489fb1a190SDave Jiang struct nd_cmd_ars_err_inj *err_inj, unsigned int buf_len) 7499fb1a190SDave Jiang { 7509fb1a190SDave Jiang int rc; 7519fb1a190SDave Jiang 75241cb3301SVishal Verma if (buf_len != sizeof(*err_inj)) { 7539fb1a190SDave Jiang rc = -EINVAL; 7549fb1a190SDave Jiang goto err; 7559fb1a190SDave Jiang } 7569fb1a190SDave Jiang 7579fb1a190SDave Jiang if (err_inj->err_inj_spa_range_length <= 0) { 7589fb1a190SDave Jiang rc = -EINVAL; 7599fb1a190SDave Jiang goto err; 7609fb1a190SDave Jiang } 7619fb1a190SDave Jiang 7629fb1a190SDave Jiang rc = badrange_add(&t->badrange, err_inj->err_inj_spa_range_base, 7639fb1a190SDave Jiang err_inj->err_inj_spa_range_length); 7649fb1a190SDave Jiang if (rc < 0) 7659fb1a190SDave Jiang goto err; 7669fb1a190SDave Jiang 7679fb1a190SDave Jiang if (err_inj->err_inj_options & (1 << ND_ARS_ERR_INJ_OPT_NOTIFY)) 7689fb1a190SDave Jiang queue_work(nfit_wq, &t->work); 7699fb1a190SDave Jiang 7709fb1a190SDave Jiang err_inj->status = 0; 7719fb1a190SDave Jiang return 0; 7729fb1a190SDave Jiang 7739fb1a190SDave Jiang err: 7749fb1a190SDave Jiang err_inj->status = NFIT_ARS_INJECT_INVALID; 7759fb1a190SDave Jiang return rc; 7769fb1a190SDave Jiang } 7779fb1a190SDave Jiang 7789fb1a190SDave Jiang static int nfit_test_cmd_ars_inject_clear(struct nfit_test *t, 7799fb1a190SDave Jiang struct nd_cmd_ars_err_inj_clr *err_clr, unsigned int buf_len) 7809fb1a190SDave Jiang { 7819fb1a190SDave Jiang int rc; 7829fb1a190SDave Jiang 78341cb3301SVishal Verma if (buf_len != sizeof(*err_clr)) { 7849fb1a190SDave Jiang rc = -EINVAL; 7859fb1a190SDave Jiang goto err; 7869fb1a190SDave Jiang } 7879fb1a190SDave Jiang 7889fb1a190SDave Jiang if (err_clr->err_inj_clr_spa_range_length <= 0) { 7899fb1a190SDave Jiang rc = -EINVAL; 7909fb1a190SDave Jiang goto err; 7919fb1a190SDave Jiang } 7929fb1a190SDave Jiang 7939fb1a190SDave Jiang badrange_forget(&t->badrange, err_clr->err_inj_clr_spa_range_base, 7949fb1a190SDave Jiang err_clr->err_inj_clr_spa_range_length); 7959fb1a190SDave Jiang 7969fb1a190SDave Jiang err_clr->status = 0; 7979fb1a190SDave Jiang return 0; 7989fb1a190SDave Jiang 7999fb1a190SDave Jiang err: 8009fb1a190SDave Jiang err_clr->status = NFIT_ARS_INJECT_INVALID; 8019fb1a190SDave Jiang return rc; 8029fb1a190SDave Jiang } 8039fb1a190SDave Jiang 8049fb1a190SDave Jiang static int nfit_test_cmd_ars_inject_status(struct nfit_test *t, 8059fb1a190SDave Jiang struct nd_cmd_ars_err_inj_stat *err_stat, 8069fb1a190SDave Jiang unsigned int buf_len) 8079fb1a190SDave Jiang { 8089fb1a190SDave Jiang struct badrange_entry *be; 8099fb1a190SDave Jiang int max = SZ_4K / sizeof(struct nd_error_stat_query_record); 8109fb1a190SDave Jiang int i = 0; 8119fb1a190SDave Jiang 8129fb1a190SDave Jiang err_stat->status = 0; 8139fb1a190SDave Jiang spin_lock(&t->badrange.lock); 8149fb1a190SDave Jiang list_for_each_entry(be, &t->badrange.list, list) { 8159fb1a190SDave Jiang err_stat->record[i].err_inj_stat_spa_range_base = be->start; 8169fb1a190SDave Jiang err_stat->record[i].err_inj_stat_spa_range_length = be->length; 8179fb1a190SDave Jiang i++; 8189fb1a190SDave Jiang if (i > max) 8199fb1a190SDave Jiang break; 8209fb1a190SDave Jiang } 8219fb1a190SDave Jiang spin_unlock(&t->badrange.lock); 8229fb1a190SDave Jiang err_stat->inj_err_rec_count = i; 8239fb1a190SDave Jiang 8249fb1a190SDave Jiang return 0; 8259fb1a190SDave Jiang } 8269fb1a190SDave Jiang 827674d8bdeSDave Jiang static int nd_intel_test_cmd_set_lss_status(struct nfit_test *t, 828674d8bdeSDave Jiang struct nd_intel_lss *nd_cmd, unsigned int buf_len) 829674d8bdeSDave Jiang { 830674d8bdeSDave Jiang struct device *dev = &t->pdev.dev; 831674d8bdeSDave Jiang 832674d8bdeSDave Jiang if (buf_len < sizeof(*nd_cmd)) 833674d8bdeSDave Jiang return -EINVAL; 834674d8bdeSDave Jiang 835674d8bdeSDave Jiang switch (nd_cmd->enable) { 836674d8bdeSDave Jiang case 0: 837674d8bdeSDave Jiang nd_cmd->status = 0; 838674d8bdeSDave Jiang dev_dbg(dev, "%s: Latch System Shutdown Status disabled\n", 839674d8bdeSDave Jiang __func__); 840674d8bdeSDave Jiang break; 841674d8bdeSDave Jiang case 1: 842674d8bdeSDave Jiang nd_cmd->status = 0; 843674d8bdeSDave Jiang dev_dbg(dev, "%s: Latch System Shutdown Status enabled\n", 844674d8bdeSDave Jiang __func__); 845674d8bdeSDave Jiang break; 846674d8bdeSDave Jiang default: 847674d8bdeSDave Jiang dev_warn(dev, "Unknown enable value: %#x\n", nd_cmd->enable); 848674d8bdeSDave Jiang nd_cmd->status = 0x3; 849674d8bdeSDave Jiang break; 850674d8bdeSDave Jiang } 851674d8bdeSDave Jiang 852674d8bdeSDave Jiang 853674d8bdeSDave Jiang return 0; 854674d8bdeSDave Jiang } 855674d8bdeSDave Jiang 856bfbaa952SDave Jiang static int get_dimm(struct nfit_mem *nfit_mem, unsigned int func) 857bfbaa952SDave Jiang { 858bfbaa952SDave Jiang int i; 859bfbaa952SDave Jiang 860bfbaa952SDave Jiang /* lookup per-dimm data */ 861bfbaa952SDave Jiang for (i = 0; i < ARRAY_SIZE(handle); i++) 862bfbaa952SDave Jiang if (__to_nfit_memdev(nfit_mem)->device_handle == handle[i]) 863bfbaa952SDave Jiang break; 864bfbaa952SDave Jiang if (i >= ARRAY_SIZE(handle)) 865bfbaa952SDave Jiang return -ENXIO; 866bfbaa952SDave Jiang 867bfbaa952SDave Jiang if ((1 << func) & dimm_fail_cmd_flags[i]) 868bfbaa952SDave Jiang return -EIO; 869bfbaa952SDave Jiang 870bfbaa952SDave Jiang return i; 871bfbaa952SDave Jiang } 872bfbaa952SDave Jiang 87339c686b8SVishal Verma static int nfit_test_ctl(struct nvdimm_bus_descriptor *nd_desc, 87439c686b8SVishal Verma struct nvdimm *nvdimm, unsigned int cmd, void *buf, 875aef25338SDan Williams unsigned int buf_len, int *cmd_rc) 87639c686b8SVishal Verma { 87739c686b8SVishal Verma struct acpi_nfit_desc *acpi_desc = to_acpi_desc(nd_desc); 87839c686b8SVishal Verma struct nfit_test *t = container_of(acpi_desc, typeof(*t), acpi_desc); 8796634fb06SDan Williams unsigned int func = cmd; 880f471f1a7SDan Williams int i, rc = 0, __cmd_rc; 881f471f1a7SDan Williams 882f471f1a7SDan Williams if (!cmd_rc) 883f471f1a7SDan Williams cmd_rc = &__cmd_rc; 884f471f1a7SDan Williams *cmd_rc = 0; 88539c686b8SVishal Verma 88639c686b8SVishal Verma if (nvdimm) { 88739c686b8SVishal Verma struct nfit_mem *nfit_mem = nvdimm_provider_data(nvdimm); 888e3654ecaSDan Williams unsigned long cmd_mask = nvdimm_cmd_mask(nvdimm); 88939c686b8SVishal Verma 8906634fb06SDan Williams if (!nfit_mem) 8916634fb06SDan Williams return -ENOTTY; 8926634fb06SDan Williams 8936634fb06SDan Williams if (cmd == ND_CMD_CALL) { 8946634fb06SDan Williams struct nd_cmd_pkg *call_pkg = buf; 8956634fb06SDan Williams 8966634fb06SDan Williams buf_len = call_pkg->nd_size_in + call_pkg->nd_size_out; 8976634fb06SDan Williams buf = (void *) call_pkg->nd_payload; 8986634fb06SDan Williams func = call_pkg->nd_command; 8996634fb06SDan Williams if (call_pkg->nd_family != nfit_mem->family) 9006634fb06SDan Williams return -ENOTTY; 901bfbaa952SDave Jiang 902bfbaa952SDave Jiang i = get_dimm(nfit_mem, func); 903bfbaa952SDave Jiang if (i < 0) 904bfbaa952SDave Jiang return i; 905bfbaa952SDave Jiang 906bfbaa952SDave Jiang switch (func) { 907674d8bdeSDave Jiang case ND_INTEL_ENABLE_LSS_STATUS: 908674d8bdeSDave Jiang return nd_intel_test_cmd_set_lss_status(t, 909674d8bdeSDave Jiang buf, buf_len); 910bfbaa952SDave Jiang case ND_INTEL_FW_GET_INFO: 911bfbaa952SDave Jiang return nd_intel_test_get_fw_info(t, buf, 912bfbaa952SDave Jiang buf_len, i - t->dcr_idx); 913bfbaa952SDave Jiang case ND_INTEL_FW_START_UPDATE: 914bfbaa952SDave Jiang return nd_intel_test_start_update(t, buf, 915bfbaa952SDave Jiang buf_len, i - t->dcr_idx); 916bfbaa952SDave Jiang case ND_INTEL_FW_SEND_DATA: 917bfbaa952SDave Jiang return nd_intel_test_send_data(t, buf, 918bfbaa952SDave Jiang buf_len, i - t->dcr_idx); 919bfbaa952SDave Jiang case ND_INTEL_FW_FINISH_UPDATE: 920bfbaa952SDave Jiang return nd_intel_test_finish_fw(t, buf, 921bfbaa952SDave Jiang buf_len, i - t->dcr_idx); 922bfbaa952SDave Jiang case ND_INTEL_FW_FINISH_QUERY: 923bfbaa952SDave Jiang return nd_intel_test_finish_query(t, buf, 924bfbaa952SDave Jiang buf_len, i - t->dcr_idx); 925bfbaa952SDave Jiang case ND_INTEL_SMART: 926bfbaa952SDave Jiang return nfit_test_cmd_smart(buf, buf_len, 927bfbaa952SDave Jiang &t->smart[i - t->dcr_idx]); 928bfbaa952SDave Jiang case ND_INTEL_SMART_THRESHOLD: 929bfbaa952SDave Jiang return nfit_test_cmd_smart_threshold(buf, 930bfbaa952SDave Jiang buf_len, 931bfbaa952SDave Jiang &t->smart_threshold[i - 932bfbaa952SDave Jiang t->dcr_idx]); 933bfbaa952SDave Jiang case ND_INTEL_SMART_SET_THRESHOLD: 934bfbaa952SDave Jiang return nfit_test_cmd_smart_set_threshold(buf, 935bfbaa952SDave Jiang buf_len, 936bfbaa952SDave Jiang &t->smart_threshold[i - 937bfbaa952SDave Jiang t->dcr_idx], 938bfbaa952SDave Jiang &t->smart[i - t->dcr_idx], 939bfbaa952SDave Jiang &t->pdev.dev, t->dimm_dev[i]); 940bfbaa952SDave Jiang default: 941bfbaa952SDave Jiang return -ENOTTY; 942bfbaa952SDave Jiang } 9436634fb06SDan Williams } 9446634fb06SDan Williams 9456634fb06SDan Williams if (!test_bit(cmd, &cmd_mask) 9466634fb06SDan Williams || !test_bit(func, &nfit_mem->dsm_mask)) 94739c686b8SVishal Verma return -ENOTTY; 94839c686b8SVishal Verma 949bfbaa952SDave Jiang i = get_dimm(nfit_mem, func); 950bfbaa952SDave Jiang if (i < 0) 951bfbaa952SDave Jiang return i; 95273606afdSDan Williams 9536634fb06SDan Williams switch (func) { 95439c686b8SVishal Verma case ND_CMD_GET_CONFIG_SIZE: 95539c686b8SVishal Verma rc = nfit_test_cmd_get_config_size(buf, buf_len); 95639c686b8SVishal Verma break; 95739c686b8SVishal Verma case ND_CMD_GET_CONFIG_DATA: 95839c686b8SVishal Verma rc = nfit_test_cmd_get_config_data(buf, buf_len, 959dafb1048SDan Williams t->label[i - t->dcr_idx]); 96039c686b8SVishal Verma break; 96139c686b8SVishal Verma case ND_CMD_SET_CONFIG_DATA: 96239c686b8SVishal Verma rc = nfit_test_cmd_set_config_data(buf, buf_len, 963dafb1048SDan Williams t->label[i - t->dcr_idx]); 96439c686b8SVishal Verma break; 9656bc75619SDan Williams default: 9666bc75619SDan Williams return -ENOTTY; 9676bc75619SDan Williams } 96839c686b8SVishal Verma } else { 969f471f1a7SDan Williams struct ars_state *ars_state = &t->ars_state; 97010246dc8SYasunori Goto struct nd_cmd_pkg *call_pkg = buf; 97110246dc8SYasunori Goto 97210246dc8SYasunori Goto if (!nd_desc) 97310246dc8SYasunori Goto return -ENOTTY; 97410246dc8SYasunori Goto 97510246dc8SYasunori Goto if (cmd == ND_CMD_CALL) { 97610246dc8SYasunori Goto func = call_pkg->nd_command; 97710246dc8SYasunori Goto 97810246dc8SYasunori Goto buf_len = call_pkg->nd_size_in + call_pkg->nd_size_out; 97910246dc8SYasunori Goto buf = (void *) call_pkg->nd_payload; 98010246dc8SYasunori Goto 98110246dc8SYasunori Goto switch (func) { 98210246dc8SYasunori Goto case NFIT_CMD_TRANSLATE_SPA: 98310246dc8SYasunori Goto rc = nfit_test_cmd_translate_spa( 98410246dc8SYasunori Goto acpi_desc->nvdimm_bus, buf, buf_len); 98510246dc8SYasunori Goto return rc; 9869fb1a190SDave Jiang case NFIT_CMD_ARS_INJECT_SET: 9879fb1a190SDave Jiang rc = nfit_test_cmd_ars_error_inject(t, buf, 9889fb1a190SDave Jiang buf_len); 9899fb1a190SDave Jiang return rc; 9909fb1a190SDave Jiang case NFIT_CMD_ARS_INJECT_CLEAR: 9919fb1a190SDave Jiang rc = nfit_test_cmd_ars_inject_clear(t, buf, 9929fb1a190SDave Jiang buf_len); 9939fb1a190SDave Jiang return rc; 9949fb1a190SDave Jiang case NFIT_CMD_ARS_INJECT_GET: 9959fb1a190SDave Jiang rc = nfit_test_cmd_ars_inject_status(t, buf, 9969fb1a190SDave Jiang buf_len); 9979fb1a190SDave Jiang return rc; 99810246dc8SYasunori Goto default: 99910246dc8SYasunori Goto return -ENOTTY; 100010246dc8SYasunori Goto } 100110246dc8SYasunori Goto } 1002f471f1a7SDan Williams 1003e3654ecaSDan Williams if (!nd_desc || !test_bit(cmd, &nd_desc->cmd_mask)) 100439c686b8SVishal Verma return -ENOTTY; 100539c686b8SVishal Verma 10066634fb06SDan Williams switch (func) { 100739c686b8SVishal Verma case ND_CMD_ARS_CAP: 100839c686b8SVishal Verma rc = nfit_test_cmd_ars_cap(buf, buf_len); 100939c686b8SVishal Verma break; 101039c686b8SVishal Verma case ND_CMD_ARS_START: 10119fb1a190SDave Jiang rc = nfit_test_cmd_ars_start(t, ars_state, buf, 10129fb1a190SDave Jiang buf_len, cmd_rc); 101339c686b8SVishal Verma break; 101439c686b8SVishal Verma case ND_CMD_ARS_STATUS: 1015f471f1a7SDan Williams rc = nfit_test_cmd_ars_status(ars_state, buf, buf_len, 1016f471f1a7SDan Williams cmd_rc); 101739c686b8SVishal Verma break; 1018d4f32367SDan Williams case ND_CMD_CLEAR_ERROR: 10195e096ef3SVishal Verma rc = nfit_test_cmd_clear_error(t, buf, buf_len, cmd_rc); 1020d4f32367SDan Williams break; 102139c686b8SVishal Verma default: 102239c686b8SVishal Verma return -ENOTTY; 102339c686b8SVishal Verma } 102439c686b8SVishal Verma } 10256bc75619SDan Williams 10266bc75619SDan Williams return rc; 10276bc75619SDan Williams } 10286bc75619SDan Williams 10296bc75619SDan Williams static DEFINE_SPINLOCK(nfit_test_lock); 10306bc75619SDan Williams static struct nfit_test *instances[NUM_NFITS]; 10316bc75619SDan Williams 10326bc75619SDan Williams static void release_nfit_res(void *data) 10336bc75619SDan Williams { 10346bc75619SDan Williams struct nfit_test_resource *nfit_res = data; 10356bc75619SDan Williams 10366bc75619SDan Williams spin_lock(&nfit_test_lock); 10376bc75619SDan Williams list_del(&nfit_res->list); 10386bc75619SDan Williams spin_unlock(&nfit_test_lock); 10396bc75619SDan Williams 10406bc75619SDan Williams vfree(nfit_res->buf); 10416bc75619SDan Williams kfree(nfit_res); 10426bc75619SDan Williams } 10436bc75619SDan Williams 10446bc75619SDan Williams static void *__test_alloc(struct nfit_test *t, size_t size, dma_addr_t *dma, 10456bc75619SDan Williams void *buf) 10466bc75619SDan Williams { 10476bc75619SDan Williams struct device *dev = &t->pdev.dev; 10486bc75619SDan Williams struct nfit_test_resource *nfit_res = kzalloc(sizeof(*nfit_res), 10496bc75619SDan Williams GFP_KERNEL); 10506bc75619SDan Williams int rc; 10516bc75619SDan Williams 1052bd4cd745SDan Williams if (!buf || !nfit_res) 10536bc75619SDan Williams goto err; 10546bc75619SDan Williams rc = devm_add_action(dev, release_nfit_res, nfit_res); 10556bc75619SDan Williams if (rc) 10566bc75619SDan Williams goto err; 10576bc75619SDan Williams INIT_LIST_HEAD(&nfit_res->list); 10586bc75619SDan Williams memset(buf, 0, size); 10596bc75619SDan Williams nfit_res->dev = dev; 10606bc75619SDan Williams nfit_res->buf = buf; 1061bd4cd745SDan Williams nfit_res->res.start = *dma; 1062bd4cd745SDan Williams nfit_res->res.end = *dma + size - 1; 1063bd4cd745SDan Williams nfit_res->res.name = "NFIT"; 1064bd4cd745SDan Williams spin_lock_init(&nfit_res->lock); 1065bd4cd745SDan Williams INIT_LIST_HEAD(&nfit_res->requests); 10666bc75619SDan Williams spin_lock(&nfit_test_lock); 10676bc75619SDan Williams list_add(&nfit_res->list, &t->resources); 10686bc75619SDan Williams spin_unlock(&nfit_test_lock); 10696bc75619SDan Williams 10706bc75619SDan Williams return nfit_res->buf; 10716bc75619SDan Williams err: 1072ee8520feSDan Williams if (buf) 10736bc75619SDan Williams vfree(buf); 10746bc75619SDan Williams kfree(nfit_res); 10756bc75619SDan Williams return NULL; 10766bc75619SDan Williams } 10776bc75619SDan Williams 10786bc75619SDan Williams static void *test_alloc(struct nfit_test *t, size_t size, dma_addr_t *dma) 10796bc75619SDan Williams { 10806bc75619SDan Williams void *buf = vmalloc(size); 10816bc75619SDan Williams 10826bc75619SDan Williams *dma = (unsigned long) buf; 10836bc75619SDan Williams return __test_alloc(t, size, dma, buf); 10846bc75619SDan Williams } 10856bc75619SDan Williams 10866bc75619SDan Williams static struct nfit_test_resource *nfit_test_lookup(resource_size_t addr) 10876bc75619SDan Williams { 10886bc75619SDan Williams int i; 10896bc75619SDan Williams 10906bc75619SDan Williams for (i = 0; i < ARRAY_SIZE(instances); i++) { 10916bc75619SDan Williams struct nfit_test_resource *n, *nfit_res = NULL; 10926bc75619SDan Williams struct nfit_test *t = instances[i]; 10936bc75619SDan Williams 10946bc75619SDan Williams if (!t) 10956bc75619SDan Williams continue; 10966bc75619SDan Williams spin_lock(&nfit_test_lock); 10976bc75619SDan Williams list_for_each_entry(n, &t->resources, list) { 1098bd4cd745SDan Williams if (addr >= n->res.start && (addr < n->res.start 1099bd4cd745SDan Williams + resource_size(&n->res))) { 11006bc75619SDan Williams nfit_res = n; 11016bc75619SDan Williams break; 11026bc75619SDan Williams } else if (addr >= (unsigned long) n->buf 11036bc75619SDan Williams && (addr < (unsigned long) n->buf 1104bd4cd745SDan Williams + resource_size(&n->res))) { 11056bc75619SDan Williams nfit_res = n; 11066bc75619SDan Williams break; 11076bc75619SDan Williams } 11086bc75619SDan Williams } 11096bc75619SDan Williams spin_unlock(&nfit_test_lock); 11106bc75619SDan Williams if (nfit_res) 11116bc75619SDan Williams return nfit_res; 11126bc75619SDan Williams } 11136bc75619SDan Williams 11146bc75619SDan Williams return NULL; 11156bc75619SDan Williams } 11166bc75619SDan Williams 1117f471f1a7SDan Williams static int ars_state_init(struct device *dev, struct ars_state *ars_state) 1118f471f1a7SDan Williams { 11199fb1a190SDave Jiang /* for testing, only store up to n records that fit within 4k */ 1120f471f1a7SDan Williams ars_state->ars_status = devm_kzalloc(dev, 11219fb1a190SDave Jiang sizeof(struct nd_cmd_ars_status) + SZ_4K, GFP_KERNEL); 1122f471f1a7SDan Williams if (!ars_state->ars_status) 1123f471f1a7SDan Williams return -ENOMEM; 1124f471f1a7SDan Williams spin_lock_init(&ars_state->lock); 1125f471f1a7SDan Williams return 0; 1126f471f1a7SDan Williams } 1127f471f1a7SDan Williams 1128231bf117SDan Williams static void put_dimms(void *data) 1129231bf117SDan Williams { 1130231bf117SDan Williams struct device **dimm_dev = data; 1131231bf117SDan Williams int i; 1132231bf117SDan Williams 1133231bf117SDan Williams for (i = 0; i < NUM_DCR; i++) 1134231bf117SDan Williams if (dimm_dev[i]) 1135231bf117SDan Williams device_unregister(dimm_dev[i]); 1136231bf117SDan Williams } 1137231bf117SDan Williams 1138231bf117SDan Williams static struct class *nfit_test_dimm; 1139231bf117SDan Williams 114073606afdSDan Williams static int dimm_name_to_id(struct device *dev) 114173606afdSDan Williams { 114273606afdSDan Williams int dimm; 114373606afdSDan Williams 114473606afdSDan Williams if (sscanf(dev_name(dev), "test_dimm%d", &dimm) != 1 114573606afdSDan Williams || dimm >= NUM_DCR || dimm < 0) 114673606afdSDan Williams return -ENXIO; 114773606afdSDan Williams return dimm; 114873606afdSDan Williams } 114973606afdSDan Williams 115073606afdSDan Williams 115173606afdSDan Williams static ssize_t handle_show(struct device *dev, struct device_attribute *attr, 115273606afdSDan Williams char *buf) 115373606afdSDan Williams { 115473606afdSDan Williams int dimm = dimm_name_to_id(dev); 115573606afdSDan Williams 115673606afdSDan Williams if (dimm < 0) 115773606afdSDan Williams return dimm; 115873606afdSDan Williams 115973606afdSDan Williams return sprintf(buf, "%#x", handle[dimm]); 116073606afdSDan Williams } 116173606afdSDan Williams DEVICE_ATTR_RO(handle); 116273606afdSDan Williams 116373606afdSDan Williams static ssize_t fail_cmd_show(struct device *dev, struct device_attribute *attr, 116473606afdSDan Williams char *buf) 116573606afdSDan Williams { 116673606afdSDan Williams int dimm = dimm_name_to_id(dev); 116773606afdSDan Williams 116873606afdSDan Williams if (dimm < 0) 116973606afdSDan Williams return dimm; 117073606afdSDan Williams 117173606afdSDan Williams return sprintf(buf, "%#lx\n", dimm_fail_cmd_flags[dimm]); 117273606afdSDan Williams } 117373606afdSDan Williams 117473606afdSDan Williams static ssize_t fail_cmd_store(struct device *dev, struct device_attribute *attr, 117573606afdSDan Williams const char *buf, size_t size) 117673606afdSDan Williams { 117773606afdSDan Williams int dimm = dimm_name_to_id(dev); 117873606afdSDan Williams unsigned long val; 117973606afdSDan Williams ssize_t rc; 118073606afdSDan Williams 118173606afdSDan Williams if (dimm < 0) 118273606afdSDan Williams return dimm; 118373606afdSDan Williams 118473606afdSDan Williams rc = kstrtol(buf, 0, &val); 118573606afdSDan Williams if (rc) 118673606afdSDan Williams return rc; 118773606afdSDan Williams 118873606afdSDan Williams dimm_fail_cmd_flags[dimm] = val; 118973606afdSDan Williams return size; 119073606afdSDan Williams } 119173606afdSDan Williams static DEVICE_ATTR_RW(fail_cmd); 119273606afdSDan Williams 119373606afdSDan Williams static struct attribute *nfit_test_dimm_attributes[] = { 119473606afdSDan Williams &dev_attr_fail_cmd.attr, 119573606afdSDan Williams &dev_attr_handle.attr, 119673606afdSDan Williams NULL, 119773606afdSDan Williams }; 119873606afdSDan Williams 119973606afdSDan Williams static struct attribute_group nfit_test_dimm_attribute_group = { 120073606afdSDan Williams .attrs = nfit_test_dimm_attributes, 120173606afdSDan Williams }; 120273606afdSDan Williams 120373606afdSDan Williams static const struct attribute_group *nfit_test_dimm_attribute_groups[] = { 120473606afdSDan Williams &nfit_test_dimm_attribute_group, 120573606afdSDan Williams NULL, 120673606afdSDan Williams }; 120773606afdSDan Williams 1208ed07c433SDan Williams static void smart_init(struct nfit_test *t) 1209ed07c433SDan Williams { 1210ed07c433SDan Williams int i; 1211ed07c433SDan Williams const struct nd_intel_smart_threshold smart_t_data = { 1212ed07c433SDan Williams .alarm_control = ND_INTEL_SMART_SPARE_TRIP 1213ed07c433SDan Williams | ND_INTEL_SMART_TEMP_TRIP, 1214ed07c433SDan Williams .media_temperature = 40 * 16, 1215ed07c433SDan Williams .ctrl_temperature = 30 * 16, 1216ed07c433SDan Williams .spares = 5, 1217ed07c433SDan Williams }; 1218ed07c433SDan Williams const struct nd_intel_smart smart_data = { 1219ed07c433SDan Williams .flags = ND_INTEL_SMART_HEALTH_VALID 1220ed07c433SDan Williams | ND_INTEL_SMART_SPARES_VALID 1221ed07c433SDan Williams | ND_INTEL_SMART_ALARM_VALID 1222ed07c433SDan Williams | ND_INTEL_SMART_USED_VALID 1223ed07c433SDan Williams | ND_INTEL_SMART_SHUTDOWN_VALID 1224ed07c433SDan Williams | ND_INTEL_SMART_MTEMP_VALID, 1225ed07c433SDan Williams .health = ND_INTEL_SMART_NON_CRITICAL_HEALTH, 1226ed07c433SDan Williams .media_temperature = 23 * 16, 1227ed07c433SDan Williams .ctrl_temperature = 30 * 16, 1228ed07c433SDan Williams .pmic_temperature = 40 * 16, 1229ed07c433SDan Williams .spares = 75, 1230ed07c433SDan Williams .alarm_flags = ND_INTEL_SMART_SPARE_TRIP 1231ed07c433SDan Williams | ND_INTEL_SMART_TEMP_TRIP, 1232ed07c433SDan Williams .ait_status = 1, 1233ed07c433SDan Williams .life_used = 5, 1234ed07c433SDan Williams .shutdown_state = 0, 1235ed07c433SDan Williams .vendor_size = 0, 1236ed07c433SDan Williams .shutdown_count = 100, 1237ed07c433SDan Williams }; 1238ed07c433SDan Williams 1239ed07c433SDan Williams for (i = 0; i < t->num_dcr; i++) { 1240ed07c433SDan Williams memcpy(&t->smart[i], &smart_data, sizeof(smart_data)); 1241ed07c433SDan Williams memcpy(&t->smart_threshold[i], &smart_t_data, 1242ed07c433SDan Williams sizeof(smart_t_data)); 1243ed07c433SDan Williams } 1244ed07c433SDan Williams } 1245ed07c433SDan Williams 12466bc75619SDan Williams static int nfit_test0_alloc(struct nfit_test *t) 12476bc75619SDan Williams { 12486b577c9dSLinda Knippers size_t nfit_size = sizeof(struct acpi_nfit_system_address) * NUM_SPA 12496bc75619SDan Williams + sizeof(struct acpi_nfit_memory_map) * NUM_MEM 12506bc75619SDan Williams + sizeof(struct acpi_nfit_control_region) * NUM_DCR 12513b87356fSDan Williams + offsetof(struct acpi_nfit_control_region, 12523b87356fSDan Williams window_size) * NUM_DCR 12539d27a87eSDan Williams + sizeof(struct acpi_nfit_data_region) * NUM_BDW 125485d3fa02SDan Williams + (sizeof(struct acpi_nfit_flush_address) 1255f81e1d35SDave Jiang + sizeof(u64) * NUM_HINTS) * NUM_DCR 1256f81e1d35SDave Jiang + sizeof(struct acpi_nfit_capabilities); 12576bc75619SDan Williams int i; 12586bc75619SDan Williams 12596bc75619SDan Williams t->nfit_buf = test_alloc(t, nfit_size, &t->nfit_dma); 12606bc75619SDan Williams if (!t->nfit_buf) 12616bc75619SDan Williams return -ENOMEM; 12626bc75619SDan Williams t->nfit_size = nfit_size; 12636bc75619SDan Williams 1264ee8520feSDan Williams t->spa_set[0] = test_alloc(t, SPA0_SIZE, &t->spa_set_dma[0]); 12656bc75619SDan Williams if (!t->spa_set[0]) 12666bc75619SDan Williams return -ENOMEM; 12676bc75619SDan Williams 1268ee8520feSDan Williams t->spa_set[1] = test_alloc(t, SPA1_SIZE, &t->spa_set_dma[1]); 12696bc75619SDan Williams if (!t->spa_set[1]) 12706bc75619SDan Williams return -ENOMEM; 12716bc75619SDan Williams 1272ee8520feSDan Williams t->spa_set[2] = test_alloc(t, SPA0_SIZE, &t->spa_set_dma[2]); 127320985164SVishal Verma if (!t->spa_set[2]) 127420985164SVishal Verma return -ENOMEM; 127520985164SVishal Verma 1276dafb1048SDan Williams for (i = 0; i < t->num_dcr; i++) { 12776bc75619SDan Williams t->dimm[i] = test_alloc(t, DIMM_SIZE, &t->dimm_dma[i]); 12786bc75619SDan Williams if (!t->dimm[i]) 12796bc75619SDan Williams return -ENOMEM; 12806bc75619SDan Williams 12816bc75619SDan Williams t->label[i] = test_alloc(t, LABEL_SIZE, &t->label_dma[i]); 12826bc75619SDan Williams if (!t->label[i]) 12836bc75619SDan Williams return -ENOMEM; 12846bc75619SDan Williams sprintf(t->label[i], "label%d", i); 12859d27a87eSDan Williams 12869d15ce9cSDan Williams t->flush[i] = test_alloc(t, max(PAGE_SIZE, 12879d15ce9cSDan Williams sizeof(u64) * NUM_HINTS), 128885d3fa02SDan Williams &t->flush_dma[i]); 12899d27a87eSDan Williams if (!t->flush[i]) 12909d27a87eSDan Williams return -ENOMEM; 12916bc75619SDan Williams } 12926bc75619SDan Williams 1293dafb1048SDan Williams for (i = 0; i < t->num_dcr; i++) { 12946bc75619SDan Williams t->dcr[i] = test_alloc(t, LABEL_SIZE, &t->dcr_dma[i]); 12956bc75619SDan Williams if (!t->dcr[i]) 12966bc75619SDan Williams return -ENOMEM; 12976bc75619SDan Williams } 12986bc75619SDan Williams 1299c14a868aSDan Williams t->_fit = test_alloc(t, sizeof(union acpi_object **), &t->_fit_dma); 1300c14a868aSDan Williams if (!t->_fit) 1301c14a868aSDan Williams return -ENOMEM; 1302c14a868aSDan Williams 1303231bf117SDan Williams if (devm_add_action_or_reset(&t->pdev.dev, put_dimms, t->dimm_dev)) 1304231bf117SDan Williams return -ENOMEM; 1305231bf117SDan Williams for (i = 0; i < NUM_DCR; i++) { 130673606afdSDan Williams t->dimm_dev[i] = device_create_with_groups(nfit_test_dimm, 130773606afdSDan Williams &t->pdev.dev, 0, NULL, 130873606afdSDan Williams nfit_test_dimm_attribute_groups, 130973606afdSDan Williams "test_dimm%d", i); 1310231bf117SDan Williams if (!t->dimm_dev[i]) 1311231bf117SDan Williams return -ENOMEM; 1312231bf117SDan Williams } 1313231bf117SDan Williams 1314ed07c433SDan Williams smart_init(t); 1315f471f1a7SDan Williams return ars_state_init(&t->pdev.dev, &t->ars_state); 13166bc75619SDan Williams } 13176bc75619SDan Williams 13186bc75619SDan Williams static int nfit_test1_alloc(struct nfit_test *t) 13196bc75619SDan Williams { 13207bfe97c7SDan Williams size_t nfit_size = sizeof(struct acpi_nfit_system_address) * 2 1321ac40b675SDan Williams + sizeof(struct acpi_nfit_memory_map) * 2 1322ac40b675SDan Williams + offsetof(struct acpi_nfit_control_region, window_size) * 2; 1323dafb1048SDan Williams int i; 13246bc75619SDan Williams 13256bc75619SDan Williams t->nfit_buf = test_alloc(t, nfit_size, &t->nfit_dma); 13266bc75619SDan Williams if (!t->nfit_buf) 13276bc75619SDan Williams return -ENOMEM; 13286bc75619SDan Williams t->nfit_size = nfit_size; 13296bc75619SDan Williams 1330ee8520feSDan Williams t->spa_set[0] = test_alloc(t, SPA2_SIZE, &t->spa_set_dma[0]); 13316bc75619SDan Williams if (!t->spa_set[0]) 13326bc75619SDan Williams return -ENOMEM; 13336bc75619SDan Williams 1334dafb1048SDan Williams for (i = 0; i < t->num_dcr; i++) { 1335dafb1048SDan Williams t->label[i] = test_alloc(t, LABEL_SIZE, &t->label_dma[i]); 1336dafb1048SDan Williams if (!t->label[i]) 1337dafb1048SDan Williams return -ENOMEM; 1338dafb1048SDan Williams sprintf(t->label[i], "label%d", i); 1339dafb1048SDan Williams } 1340dafb1048SDan Williams 13417bfe97c7SDan Williams t->spa_set[1] = test_alloc(t, SPA_VCD_SIZE, &t->spa_set_dma[1]); 13427bfe97c7SDan Williams if (!t->spa_set[1]) 13437bfe97c7SDan Williams return -ENOMEM; 13447bfe97c7SDan Williams 1345ed07c433SDan Williams smart_init(t); 1346f471f1a7SDan Williams return ars_state_init(&t->pdev.dev, &t->ars_state); 13476bc75619SDan Williams } 13486bc75619SDan Williams 13495dc68e55SDan Williams static void dcr_common_init(struct acpi_nfit_control_region *dcr) 13505dc68e55SDan Williams { 13515dc68e55SDan Williams dcr->vendor_id = 0xabcd; 13525dc68e55SDan Williams dcr->device_id = 0; 13535dc68e55SDan Williams dcr->revision_id = 1; 13545dc68e55SDan Williams dcr->valid_fields = 1; 13555dc68e55SDan Williams dcr->manufacturing_location = 0xa; 13565dc68e55SDan Williams dcr->manufacturing_date = cpu_to_be16(2016); 13575dc68e55SDan Williams } 13585dc68e55SDan Williams 13596bc75619SDan Williams static void nfit_test0_setup(struct nfit_test *t) 13606bc75619SDan Williams { 136185d3fa02SDan Williams const int flush_hint_size = sizeof(struct acpi_nfit_flush_address) 136285d3fa02SDan Williams + (sizeof(u64) * NUM_HINTS); 13636bc75619SDan Williams struct acpi_nfit_desc *acpi_desc; 13646bc75619SDan Williams struct acpi_nfit_memory_map *memdev; 13656bc75619SDan Williams void *nfit_buf = t->nfit_buf; 13666bc75619SDan Williams struct acpi_nfit_system_address *spa; 13676bc75619SDan Williams struct acpi_nfit_control_region *dcr; 13686bc75619SDan Williams struct acpi_nfit_data_region *bdw; 13699d27a87eSDan Williams struct acpi_nfit_flush_address *flush; 1370f81e1d35SDave Jiang struct acpi_nfit_capabilities *pcap; 1371d7d8464dSRoss Zwisler unsigned int offset = 0, i; 13726bc75619SDan Williams 13736bc75619SDan Williams /* 13746bc75619SDan Williams * spa0 (interleave first half of dimm0 and dimm1, note storage 13756bc75619SDan Williams * does not actually alias the related block-data-window 13766bc75619SDan Williams * regions) 13776bc75619SDan Williams */ 13786b577c9dSLinda Knippers spa = nfit_buf; 13796bc75619SDan Williams spa->header.type = ACPI_NFIT_TYPE_SYSTEM_ADDRESS; 13806bc75619SDan Williams spa->header.length = sizeof(*spa); 13816bc75619SDan Williams memcpy(spa->range_guid, to_nfit_uuid(NFIT_SPA_PM), 16); 13826bc75619SDan Williams spa->range_index = 0+1; 13836bc75619SDan Williams spa->address = t->spa_set_dma[0]; 13846bc75619SDan Williams spa->length = SPA0_SIZE; 1385d7d8464dSRoss Zwisler offset += spa->header.length; 13866bc75619SDan Williams 13876bc75619SDan Williams /* 13886bc75619SDan Williams * spa1 (interleave last half of the 4 DIMMS, note storage 13896bc75619SDan Williams * does not actually alias the related block-data-window 13906bc75619SDan Williams * regions) 13916bc75619SDan Williams */ 1392d7d8464dSRoss Zwisler spa = nfit_buf + offset; 13936bc75619SDan Williams spa->header.type = ACPI_NFIT_TYPE_SYSTEM_ADDRESS; 13946bc75619SDan Williams spa->header.length = sizeof(*spa); 13956bc75619SDan Williams memcpy(spa->range_guid, to_nfit_uuid(NFIT_SPA_PM), 16); 13966bc75619SDan Williams spa->range_index = 1+1; 13976bc75619SDan Williams spa->address = t->spa_set_dma[1]; 13986bc75619SDan Williams spa->length = SPA1_SIZE; 1399d7d8464dSRoss Zwisler offset += spa->header.length; 14006bc75619SDan Williams 14016bc75619SDan Williams /* spa2 (dcr0) dimm0 */ 1402d7d8464dSRoss Zwisler spa = nfit_buf + offset; 14036bc75619SDan Williams spa->header.type = ACPI_NFIT_TYPE_SYSTEM_ADDRESS; 14046bc75619SDan Williams spa->header.length = sizeof(*spa); 14056bc75619SDan Williams memcpy(spa->range_guid, to_nfit_uuid(NFIT_SPA_DCR), 16); 14066bc75619SDan Williams spa->range_index = 2+1; 14076bc75619SDan Williams spa->address = t->dcr_dma[0]; 14086bc75619SDan Williams spa->length = DCR_SIZE; 1409d7d8464dSRoss Zwisler offset += spa->header.length; 14106bc75619SDan Williams 14116bc75619SDan Williams /* spa3 (dcr1) dimm1 */ 1412d7d8464dSRoss Zwisler spa = nfit_buf + offset; 14136bc75619SDan Williams spa->header.type = ACPI_NFIT_TYPE_SYSTEM_ADDRESS; 14146bc75619SDan Williams spa->header.length = sizeof(*spa); 14156bc75619SDan Williams memcpy(spa->range_guid, to_nfit_uuid(NFIT_SPA_DCR), 16); 14166bc75619SDan Williams spa->range_index = 3+1; 14176bc75619SDan Williams spa->address = t->dcr_dma[1]; 14186bc75619SDan Williams spa->length = DCR_SIZE; 1419d7d8464dSRoss Zwisler offset += spa->header.length; 14206bc75619SDan Williams 14216bc75619SDan Williams /* spa4 (dcr2) dimm2 */ 1422d7d8464dSRoss Zwisler spa = nfit_buf + offset; 14236bc75619SDan Williams spa->header.type = ACPI_NFIT_TYPE_SYSTEM_ADDRESS; 14246bc75619SDan Williams spa->header.length = sizeof(*spa); 14256bc75619SDan Williams memcpy(spa->range_guid, to_nfit_uuid(NFIT_SPA_DCR), 16); 14266bc75619SDan Williams spa->range_index = 4+1; 14276bc75619SDan Williams spa->address = t->dcr_dma[2]; 14286bc75619SDan Williams spa->length = DCR_SIZE; 1429d7d8464dSRoss Zwisler offset += spa->header.length; 14306bc75619SDan Williams 14316bc75619SDan Williams /* spa5 (dcr3) dimm3 */ 1432d7d8464dSRoss Zwisler spa = nfit_buf + offset; 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_DCR), 16); 14366bc75619SDan Williams spa->range_index = 5+1; 14376bc75619SDan Williams spa->address = t->dcr_dma[3]; 14386bc75619SDan Williams spa->length = DCR_SIZE; 1439d7d8464dSRoss Zwisler offset += spa->header.length; 14406bc75619SDan Williams 14416bc75619SDan Williams /* spa6 (bdw for dcr0) dimm0 */ 1442d7d8464dSRoss Zwisler spa = nfit_buf + offset; 14436bc75619SDan Williams spa->header.type = ACPI_NFIT_TYPE_SYSTEM_ADDRESS; 14446bc75619SDan Williams spa->header.length = sizeof(*spa); 14456bc75619SDan Williams memcpy(spa->range_guid, to_nfit_uuid(NFIT_SPA_BDW), 16); 14466bc75619SDan Williams spa->range_index = 6+1; 14476bc75619SDan Williams spa->address = t->dimm_dma[0]; 14486bc75619SDan Williams spa->length = DIMM_SIZE; 1449d7d8464dSRoss Zwisler offset += spa->header.length; 14506bc75619SDan Williams 14516bc75619SDan Williams /* spa7 (bdw for dcr1) dimm1 */ 1452d7d8464dSRoss Zwisler spa = nfit_buf + offset; 14536bc75619SDan Williams spa->header.type = ACPI_NFIT_TYPE_SYSTEM_ADDRESS; 14546bc75619SDan Williams spa->header.length = sizeof(*spa); 14556bc75619SDan Williams memcpy(spa->range_guid, to_nfit_uuid(NFIT_SPA_BDW), 16); 14566bc75619SDan Williams spa->range_index = 7+1; 14576bc75619SDan Williams spa->address = t->dimm_dma[1]; 14586bc75619SDan Williams spa->length = DIMM_SIZE; 1459d7d8464dSRoss Zwisler offset += spa->header.length; 14606bc75619SDan Williams 14616bc75619SDan Williams /* spa8 (bdw for dcr2) dimm2 */ 1462d7d8464dSRoss Zwisler spa = nfit_buf + offset; 14636bc75619SDan Williams spa->header.type = ACPI_NFIT_TYPE_SYSTEM_ADDRESS; 14646bc75619SDan Williams spa->header.length = sizeof(*spa); 14656bc75619SDan Williams memcpy(spa->range_guid, to_nfit_uuid(NFIT_SPA_BDW), 16); 14666bc75619SDan Williams spa->range_index = 8+1; 14676bc75619SDan Williams spa->address = t->dimm_dma[2]; 14686bc75619SDan Williams spa->length = DIMM_SIZE; 1469d7d8464dSRoss Zwisler offset += spa->header.length; 14706bc75619SDan Williams 14716bc75619SDan Williams /* spa9 (bdw for dcr3) dimm3 */ 1472d7d8464dSRoss Zwisler spa = nfit_buf + offset; 14736bc75619SDan Williams spa->header.type = ACPI_NFIT_TYPE_SYSTEM_ADDRESS; 14746bc75619SDan Williams spa->header.length = sizeof(*spa); 14756bc75619SDan Williams memcpy(spa->range_guid, to_nfit_uuid(NFIT_SPA_BDW), 16); 14766bc75619SDan Williams spa->range_index = 9+1; 14776bc75619SDan Williams spa->address = t->dimm_dma[3]; 14786bc75619SDan Williams spa->length = DIMM_SIZE; 1479d7d8464dSRoss Zwisler offset += spa->header.length; 14806bc75619SDan Williams 14816bc75619SDan Williams /* mem-region0 (spa0, dimm0) */ 14826bc75619SDan Williams memdev = nfit_buf + offset; 14836bc75619SDan Williams memdev->header.type = ACPI_NFIT_TYPE_MEMORY_MAP; 14846bc75619SDan Williams memdev->header.length = sizeof(*memdev); 14856bc75619SDan Williams memdev->device_handle = handle[0]; 14866bc75619SDan Williams memdev->physical_id = 0; 14876bc75619SDan Williams memdev->region_id = 0; 14886bc75619SDan Williams memdev->range_index = 0+1; 14893b87356fSDan Williams memdev->region_index = 4+1; 14906bc75619SDan Williams memdev->region_size = SPA0_SIZE/2; 1491df06a2d5SDan Williams memdev->region_offset = 1; 14926bc75619SDan Williams memdev->address = 0; 14936bc75619SDan Williams memdev->interleave_index = 0; 14946bc75619SDan Williams memdev->interleave_ways = 2; 1495d7d8464dSRoss Zwisler offset += memdev->header.length; 14966bc75619SDan Williams 14976bc75619SDan Williams /* mem-region1 (spa0, dimm1) */ 1498d7d8464dSRoss Zwisler memdev = nfit_buf + offset; 14996bc75619SDan Williams memdev->header.type = ACPI_NFIT_TYPE_MEMORY_MAP; 15006bc75619SDan Williams memdev->header.length = sizeof(*memdev); 15016bc75619SDan Williams memdev->device_handle = handle[1]; 15026bc75619SDan Williams memdev->physical_id = 1; 15036bc75619SDan Williams memdev->region_id = 0; 15046bc75619SDan Williams memdev->range_index = 0+1; 15053b87356fSDan Williams memdev->region_index = 5+1; 15066bc75619SDan Williams memdev->region_size = SPA0_SIZE/2; 1507df06a2d5SDan Williams memdev->region_offset = (1 << 8); 15086bc75619SDan Williams memdev->address = 0; 15096bc75619SDan Williams memdev->interleave_index = 0; 15106bc75619SDan Williams memdev->interleave_ways = 2; 1511ac40b675SDan Williams memdev->flags = ACPI_NFIT_MEM_HEALTH_ENABLED; 1512d7d8464dSRoss Zwisler offset += memdev->header.length; 15136bc75619SDan Williams 15146bc75619SDan Williams /* mem-region2 (spa1, dimm0) */ 1515d7d8464dSRoss Zwisler memdev = nfit_buf + offset; 15166bc75619SDan Williams memdev->header.type = ACPI_NFIT_TYPE_MEMORY_MAP; 15176bc75619SDan Williams memdev->header.length = sizeof(*memdev); 15186bc75619SDan Williams memdev->device_handle = handle[0]; 15196bc75619SDan Williams memdev->physical_id = 0; 15206bc75619SDan Williams memdev->region_id = 1; 15216bc75619SDan Williams memdev->range_index = 1+1; 15223b87356fSDan Williams memdev->region_index = 4+1; 15236bc75619SDan Williams memdev->region_size = SPA1_SIZE/4; 1524df06a2d5SDan Williams memdev->region_offset = (1 << 16); 15256bc75619SDan Williams memdev->address = SPA0_SIZE/2; 15266bc75619SDan Williams memdev->interleave_index = 0; 15276bc75619SDan Williams memdev->interleave_ways = 4; 1528ac40b675SDan Williams memdev->flags = ACPI_NFIT_MEM_HEALTH_ENABLED; 1529d7d8464dSRoss Zwisler offset += memdev->header.length; 15306bc75619SDan Williams 15316bc75619SDan Williams /* mem-region3 (spa1, dimm1) */ 1532d7d8464dSRoss Zwisler memdev = nfit_buf + offset; 15336bc75619SDan Williams memdev->header.type = ACPI_NFIT_TYPE_MEMORY_MAP; 15346bc75619SDan Williams memdev->header.length = sizeof(*memdev); 15356bc75619SDan Williams memdev->device_handle = handle[1]; 15366bc75619SDan Williams memdev->physical_id = 1; 15376bc75619SDan Williams memdev->region_id = 1; 15386bc75619SDan Williams memdev->range_index = 1+1; 15393b87356fSDan Williams memdev->region_index = 5+1; 15406bc75619SDan Williams memdev->region_size = SPA1_SIZE/4; 1541df06a2d5SDan Williams memdev->region_offset = (1 << 24); 15426bc75619SDan Williams memdev->address = SPA0_SIZE/2; 15436bc75619SDan Williams memdev->interleave_index = 0; 15446bc75619SDan Williams memdev->interleave_ways = 4; 1545d7d8464dSRoss Zwisler offset += memdev->header.length; 15466bc75619SDan Williams 15476bc75619SDan Williams /* mem-region4 (spa1, dimm2) */ 1548d7d8464dSRoss Zwisler memdev = nfit_buf + offset; 15496bc75619SDan Williams memdev->header.type = ACPI_NFIT_TYPE_MEMORY_MAP; 15506bc75619SDan Williams memdev->header.length = sizeof(*memdev); 15516bc75619SDan Williams memdev->device_handle = handle[2]; 15526bc75619SDan Williams memdev->physical_id = 2; 15536bc75619SDan Williams memdev->region_id = 0; 15546bc75619SDan Williams memdev->range_index = 1+1; 15553b87356fSDan Williams memdev->region_index = 6+1; 15566bc75619SDan Williams memdev->region_size = SPA1_SIZE/4; 1557df06a2d5SDan Williams memdev->region_offset = (1ULL << 32); 15586bc75619SDan Williams memdev->address = SPA0_SIZE/2; 15596bc75619SDan Williams memdev->interleave_index = 0; 15606bc75619SDan Williams memdev->interleave_ways = 4; 1561ac40b675SDan Williams memdev->flags = ACPI_NFIT_MEM_HEALTH_ENABLED; 1562d7d8464dSRoss Zwisler offset += memdev->header.length; 15636bc75619SDan Williams 15646bc75619SDan Williams /* mem-region5 (spa1, dimm3) */ 1565d7d8464dSRoss Zwisler memdev = nfit_buf + offset; 15666bc75619SDan Williams memdev->header.type = ACPI_NFIT_TYPE_MEMORY_MAP; 15676bc75619SDan Williams memdev->header.length = sizeof(*memdev); 15686bc75619SDan Williams memdev->device_handle = handle[3]; 15696bc75619SDan Williams memdev->physical_id = 3; 15706bc75619SDan Williams memdev->region_id = 0; 15716bc75619SDan Williams memdev->range_index = 1+1; 15723b87356fSDan Williams memdev->region_index = 7+1; 15736bc75619SDan Williams memdev->region_size = SPA1_SIZE/4; 1574df06a2d5SDan Williams memdev->region_offset = (1ULL << 40); 15756bc75619SDan Williams memdev->address = SPA0_SIZE/2; 15766bc75619SDan Williams memdev->interleave_index = 0; 15776bc75619SDan Williams memdev->interleave_ways = 4; 1578d7d8464dSRoss Zwisler offset += memdev->header.length; 15796bc75619SDan Williams 15806bc75619SDan Williams /* mem-region6 (spa/dcr0, dimm0) */ 1581d7d8464dSRoss Zwisler memdev = nfit_buf + offset; 15826bc75619SDan Williams memdev->header.type = ACPI_NFIT_TYPE_MEMORY_MAP; 15836bc75619SDan Williams memdev->header.length = sizeof(*memdev); 15846bc75619SDan Williams memdev->device_handle = handle[0]; 15856bc75619SDan Williams memdev->physical_id = 0; 15866bc75619SDan Williams memdev->region_id = 0; 15876bc75619SDan Williams memdev->range_index = 2+1; 15886bc75619SDan Williams memdev->region_index = 0+1; 15896bc75619SDan Williams memdev->region_size = 0; 15906bc75619SDan Williams memdev->region_offset = 0; 15916bc75619SDan Williams memdev->address = 0; 15926bc75619SDan Williams memdev->interleave_index = 0; 15936bc75619SDan Williams memdev->interleave_ways = 1; 1594d7d8464dSRoss Zwisler offset += memdev->header.length; 15956bc75619SDan Williams 15966bc75619SDan Williams /* mem-region7 (spa/dcr1, dimm1) */ 1597d7d8464dSRoss Zwisler memdev = nfit_buf + offset; 15986bc75619SDan Williams memdev->header.type = ACPI_NFIT_TYPE_MEMORY_MAP; 15996bc75619SDan Williams memdev->header.length = sizeof(*memdev); 16006bc75619SDan Williams memdev->device_handle = handle[1]; 16016bc75619SDan Williams memdev->physical_id = 1; 16026bc75619SDan Williams memdev->region_id = 0; 16036bc75619SDan Williams memdev->range_index = 3+1; 16046bc75619SDan Williams memdev->region_index = 1+1; 16056bc75619SDan Williams memdev->region_size = 0; 16066bc75619SDan Williams memdev->region_offset = 0; 16076bc75619SDan Williams memdev->address = 0; 16086bc75619SDan Williams memdev->interleave_index = 0; 16096bc75619SDan Williams memdev->interleave_ways = 1; 1610d7d8464dSRoss Zwisler offset += memdev->header.length; 16116bc75619SDan Williams 16126bc75619SDan Williams /* mem-region8 (spa/dcr2, dimm2) */ 1613d7d8464dSRoss Zwisler memdev = nfit_buf + offset; 16146bc75619SDan Williams memdev->header.type = ACPI_NFIT_TYPE_MEMORY_MAP; 16156bc75619SDan Williams memdev->header.length = sizeof(*memdev); 16166bc75619SDan Williams memdev->device_handle = handle[2]; 16176bc75619SDan Williams memdev->physical_id = 2; 16186bc75619SDan Williams memdev->region_id = 0; 16196bc75619SDan Williams memdev->range_index = 4+1; 16206bc75619SDan Williams memdev->region_index = 2+1; 16216bc75619SDan Williams memdev->region_size = 0; 16226bc75619SDan Williams memdev->region_offset = 0; 16236bc75619SDan Williams memdev->address = 0; 16246bc75619SDan Williams memdev->interleave_index = 0; 16256bc75619SDan Williams memdev->interleave_ways = 1; 1626d7d8464dSRoss Zwisler offset += memdev->header.length; 16276bc75619SDan Williams 16286bc75619SDan Williams /* mem-region9 (spa/dcr3, dimm3) */ 1629d7d8464dSRoss Zwisler memdev = nfit_buf + offset; 16306bc75619SDan Williams memdev->header.type = ACPI_NFIT_TYPE_MEMORY_MAP; 16316bc75619SDan Williams memdev->header.length = sizeof(*memdev); 16326bc75619SDan Williams memdev->device_handle = handle[3]; 16336bc75619SDan Williams memdev->physical_id = 3; 16346bc75619SDan Williams memdev->region_id = 0; 16356bc75619SDan Williams memdev->range_index = 5+1; 16366bc75619SDan Williams memdev->region_index = 3+1; 16376bc75619SDan Williams memdev->region_size = 0; 16386bc75619SDan Williams memdev->region_offset = 0; 16396bc75619SDan Williams memdev->address = 0; 16406bc75619SDan Williams memdev->interleave_index = 0; 16416bc75619SDan Williams memdev->interleave_ways = 1; 1642d7d8464dSRoss Zwisler offset += memdev->header.length; 16436bc75619SDan Williams 16446bc75619SDan Williams /* mem-region10 (spa/bdw0, dimm0) */ 1645d7d8464dSRoss Zwisler memdev = nfit_buf + offset; 16466bc75619SDan Williams memdev->header.type = ACPI_NFIT_TYPE_MEMORY_MAP; 16476bc75619SDan Williams memdev->header.length = sizeof(*memdev); 16486bc75619SDan Williams memdev->device_handle = handle[0]; 16496bc75619SDan Williams memdev->physical_id = 0; 16506bc75619SDan Williams memdev->region_id = 0; 16516bc75619SDan Williams memdev->range_index = 6+1; 16526bc75619SDan Williams memdev->region_index = 0+1; 16536bc75619SDan Williams memdev->region_size = 0; 16546bc75619SDan Williams memdev->region_offset = 0; 16556bc75619SDan Williams memdev->address = 0; 16566bc75619SDan Williams memdev->interleave_index = 0; 16576bc75619SDan Williams memdev->interleave_ways = 1; 1658d7d8464dSRoss Zwisler offset += memdev->header.length; 16596bc75619SDan Williams 16606bc75619SDan Williams /* mem-region11 (spa/bdw1, dimm1) */ 1661d7d8464dSRoss Zwisler memdev = nfit_buf + offset; 16626bc75619SDan Williams memdev->header.type = ACPI_NFIT_TYPE_MEMORY_MAP; 16636bc75619SDan Williams memdev->header.length = sizeof(*memdev); 16646bc75619SDan Williams memdev->device_handle = handle[1]; 16656bc75619SDan Williams memdev->physical_id = 1; 16666bc75619SDan Williams memdev->region_id = 0; 16676bc75619SDan Williams memdev->range_index = 7+1; 16686bc75619SDan Williams memdev->region_index = 1+1; 16696bc75619SDan Williams memdev->region_size = 0; 16706bc75619SDan Williams memdev->region_offset = 0; 16716bc75619SDan Williams memdev->address = 0; 16726bc75619SDan Williams memdev->interleave_index = 0; 16736bc75619SDan Williams memdev->interleave_ways = 1; 1674d7d8464dSRoss Zwisler offset += memdev->header.length; 16756bc75619SDan Williams 16766bc75619SDan Williams /* mem-region12 (spa/bdw2, dimm2) */ 1677d7d8464dSRoss Zwisler memdev = nfit_buf + offset; 16786bc75619SDan Williams memdev->header.type = ACPI_NFIT_TYPE_MEMORY_MAP; 16796bc75619SDan Williams memdev->header.length = sizeof(*memdev); 16806bc75619SDan Williams memdev->device_handle = handle[2]; 16816bc75619SDan Williams memdev->physical_id = 2; 16826bc75619SDan Williams memdev->region_id = 0; 16836bc75619SDan Williams memdev->range_index = 8+1; 16846bc75619SDan Williams memdev->region_index = 2+1; 16856bc75619SDan Williams memdev->region_size = 0; 16866bc75619SDan Williams memdev->region_offset = 0; 16876bc75619SDan Williams memdev->address = 0; 16886bc75619SDan Williams memdev->interleave_index = 0; 16896bc75619SDan Williams memdev->interleave_ways = 1; 1690d7d8464dSRoss Zwisler offset += memdev->header.length; 16916bc75619SDan Williams 16926bc75619SDan Williams /* mem-region13 (spa/dcr3, dimm3) */ 1693d7d8464dSRoss Zwisler memdev = nfit_buf + offset; 16946bc75619SDan Williams memdev->header.type = ACPI_NFIT_TYPE_MEMORY_MAP; 16956bc75619SDan Williams memdev->header.length = sizeof(*memdev); 16966bc75619SDan Williams memdev->device_handle = handle[3]; 16976bc75619SDan Williams memdev->physical_id = 3; 16986bc75619SDan Williams memdev->region_id = 0; 16996bc75619SDan Williams memdev->range_index = 9+1; 17006bc75619SDan Williams memdev->region_index = 3+1; 17016bc75619SDan Williams memdev->region_size = 0; 17026bc75619SDan Williams memdev->region_offset = 0; 17036bc75619SDan Williams memdev->address = 0; 17046bc75619SDan Williams memdev->interleave_index = 0; 17056bc75619SDan Williams memdev->interleave_ways = 1; 1706ac40b675SDan Williams memdev->flags = ACPI_NFIT_MEM_HEALTH_ENABLED; 1707d7d8464dSRoss Zwisler offset += memdev->header.length; 17086bc75619SDan Williams 17093b87356fSDan Williams /* dcr-descriptor0: blk */ 17106bc75619SDan Williams dcr = nfit_buf + offset; 17116bc75619SDan Williams dcr->header.type = ACPI_NFIT_TYPE_CONTROL_REGION; 1712d7d8464dSRoss Zwisler dcr->header.length = sizeof(*dcr); 17136bc75619SDan Williams dcr->region_index = 0+1; 17145dc68e55SDan Williams dcr_common_init(dcr); 17156bc75619SDan Williams dcr->serial_number = ~handle[0]; 1716be26f9aeSDan Williams dcr->code = NFIT_FIC_BLK; 17176bc75619SDan Williams dcr->windows = 1; 17186bc75619SDan Williams dcr->window_size = DCR_SIZE; 17196bc75619SDan Williams dcr->command_offset = 0; 17206bc75619SDan Williams dcr->command_size = 8; 17216bc75619SDan Williams dcr->status_offset = 8; 17226bc75619SDan Williams dcr->status_size = 4; 1723d7d8464dSRoss Zwisler offset += dcr->header.length; 17246bc75619SDan Williams 17253b87356fSDan Williams /* dcr-descriptor1: blk */ 1726d7d8464dSRoss Zwisler dcr = nfit_buf + offset; 17276bc75619SDan Williams dcr->header.type = ACPI_NFIT_TYPE_CONTROL_REGION; 1728d7d8464dSRoss Zwisler dcr->header.length = sizeof(*dcr); 17296bc75619SDan Williams dcr->region_index = 1+1; 17305dc68e55SDan Williams dcr_common_init(dcr); 17316bc75619SDan Williams dcr->serial_number = ~handle[1]; 1732be26f9aeSDan Williams dcr->code = NFIT_FIC_BLK; 17336bc75619SDan Williams dcr->windows = 1; 17346bc75619SDan Williams dcr->window_size = DCR_SIZE; 17356bc75619SDan Williams dcr->command_offset = 0; 17366bc75619SDan Williams dcr->command_size = 8; 17376bc75619SDan Williams dcr->status_offset = 8; 17386bc75619SDan Williams dcr->status_size = 4; 1739d7d8464dSRoss Zwisler offset += dcr->header.length; 17406bc75619SDan Williams 17413b87356fSDan Williams /* dcr-descriptor2: blk */ 1742d7d8464dSRoss Zwisler dcr = nfit_buf + offset; 17436bc75619SDan Williams dcr->header.type = ACPI_NFIT_TYPE_CONTROL_REGION; 1744d7d8464dSRoss Zwisler dcr->header.length = sizeof(*dcr); 17456bc75619SDan Williams dcr->region_index = 2+1; 17465dc68e55SDan Williams dcr_common_init(dcr); 17476bc75619SDan Williams dcr->serial_number = ~handle[2]; 1748be26f9aeSDan Williams dcr->code = NFIT_FIC_BLK; 17496bc75619SDan Williams dcr->windows = 1; 17506bc75619SDan Williams dcr->window_size = DCR_SIZE; 17516bc75619SDan Williams dcr->command_offset = 0; 17526bc75619SDan Williams dcr->command_size = 8; 17536bc75619SDan Williams dcr->status_offset = 8; 17546bc75619SDan Williams dcr->status_size = 4; 1755d7d8464dSRoss Zwisler offset += dcr->header.length; 17566bc75619SDan Williams 17573b87356fSDan Williams /* dcr-descriptor3: blk */ 1758d7d8464dSRoss Zwisler dcr = nfit_buf + offset; 17596bc75619SDan Williams dcr->header.type = ACPI_NFIT_TYPE_CONTROL_REGION; 1760d7d8464dSRoss Zwisler dcr->header.length = sizeof(*dcr); 17616bc75619SDan Williams dcr->region_index = 3+1; 17625dc68e55SDan Williams dcr_common_init(dcr); 17636bc75619SDan Williams dcr->serial_number = ~handle[3]; 1764be26f9aeSDan Williams dcr->code = NFIT_FIC_BLK; 17656bc75619SDan Williams dcr->windows = 1; 17666bc75619SDan Williams dcr->window_size = DCR_SIZE; 17676bc75619SDan Williams dcr->command_offset = 0; 17686bc75619SDan Williams dcr->command_size = 8; 17696bc75619SDan Williams dcr->status_offset = 8; 17706bc75619SDan Williams dcr->status_size = 4; 1771d7d8464dSRoss Zwisler offset += dcr->header.length; 17726bc75619SDan Williams 17733b87356fSDan Williams /* dcr-descriptor0: pmem */ 17743b87356fSDan Williams dcr = nfit_buf + offset; 17753b87356fSDan Williams dcr->header.type = ACPI_NFIT_TYPE_CONTROL_REGION; 17763b87356fSDan Williams dcr->header.length = offsetof(struct acpi_nfit_control_region, 17773b87356fSDan Williams window_size); 17783b87356fSDan Williams dcr->region_index = 4+1; 17795dc68e55SDan Williams dcr_common_init(dcr); 17803b87356fSDan Williams dcr->serial_number = ~handle[0]; 17813b87356fSDan Williams dcr->code = NFIT_FIC_BYTEN; 17823b87356fSDan Williams dcr->windows = 0; 1783d7d8464dSRoss Zwisler offset += dcr->header.length; 17843b87356fSDan Williams 17853b87356fSDan Williams /* dcr-descriptor1: pmem */ 1786d7d8464dSRoss Zwisler dcr = nfit_buf + offset; 17873b87356fSDan Williams dcr->header.type = ACPI_NFIT_TYPE_CONTROL_REGION; 17883b87356fSDan Williams dcr->header.length = offsetof(struct acpi_nfit_control_region, 17893b87356fSDan Williams window_size); 17903b87356fSDan Williams dcr->region_index = 5+1; 17915dc68e55SDan Williams dcr_common_init(dcr); 17923b87356fSDan Williams dcr->serial_number = ~handle[1]; 17933b87356fSDan Williams dcr->code = NFIT_FIC_BYTEN; 17943b87356fSDan Williams dcr->windows = 0; 1795d7d8464dSRoss Zwisler offset += dcr->header.length; 17963b87356fSDan Williams 17973b87356fSDan Williams /* dcr-descriptor2: pmem */ 1798d7d8464dSRoss Zwisler dcr = nfit_buf + offset; 17993b87356fSDan Williams dcr->header.type = ACPI_NFIT_TYPE_CONTROL_REGION; 18003b87356fSDan Williams dcr->header.length = offsetof(struct acpi_nfit_control_region, 18013b87356fSDan Williams window_size); 18023b87356fSDan Williams dcr->region_index = 6+1; 18035dc68e55SDan Williams dcr_common_init(dcr); 18043b87356fSDan Williams dcr->serial_number = ~handle[2]; 18053b87356fSDan Williams dcr->code = NFIT_FIC_BYTEN; 18063b87356fSDan Williams dcr->windows = 0; 1807d7d8464dSRoss Zwisler offset += dcr->header.length; 18083b87356fSDan Williams 18093b87356fSDan Williams /* dcr-descriptor3: pmem */ 1810d7d8464dSRoss Zwisler dcr = nfit_buf + offset; 18113b87356fSDan Williams dcr->header.type = ACPI_NFIT_TYPE_CONTROL_REGION; 18123b87356fSDan Williams dcr->header.length = offsetof(struct acpi_nfit_control_region, 18133b87356fSDan Williams window_size); 18143b87356fSDan Williams dcr->region_index = 7+1; 18155dc68e55SDan Williams dcr_common_init(dcr); 18163b87356fSDan Williams dcr->serial_number = ~handle[3]; 18173b87356fSDan Williams dcr->code = NFIT_FIC_BYTEN; 18183b87356fSDan Williams dcr->windows = 0; 1819d7d8464dSRoss Zwisler offset += dcr->header.length; 18203b87356fSDan Williams 18216bc75619SDan Williams /* bdw0 (spa/dcr0, dimm0) */ 18226bc75619SDan Williams bdw = nfit_buf + offset; 18236bc75619SDan Williams bdw->header.type = ACPI_NFIT_TYPE_DATA_REGION; 1824d7d8464dSRoss Zwisler bdw->header.length = sizeof(*bdw); 18256bc75619SDan Williams bdw->region_index = 0+1; 18266bc75619SDan Williams bdw->windows = 1; 18276bc75619SDan Williams bdw->offset = 0; 18286bc75619SDan Williams bdw->size = BDW_SIZE; 18296bc75619SDan Williams bdw->capacity = DIMM_SIZE; 18306bc75619SDan Williams bdw->start_address = 0; 1831d7d8464dSRoss Zwisler offset += bdw->header.length; 18326bc75619SDan Williams 18336bc75619SDan Williams /* bdw1 (spa/dcr1, dimm1) */ 1834d7d8464dSRoss Zwisler bdw = nfit_buf + offset; 18356bc75619SDan Williams bdw->header.type = ACPI_NFIT_TYPE_DATA_REGION; 1836d7d8464dSRoss Zwisler bdw->header.length = sizeof(*bdw); 18376bc75619SDan Williams bdw->region_index = 1+1; 18386bc75619SDan Williams bdw->windows = 1; 18396bc75619SDan Williams bdw->offset = 0; 18406bc75619SDan Williams bdw->size = BDW_SIZE; 18416bc75619SDan Williams bdw->capacity = DIMM_SIZE; 18426bc75619SDan Williams bdw->start_address = 0; 1843d7d8464dSRoss Zwisler offset += bdw->header.length; 18446bc75619SDan Williams 18456bc75619SDan Williams /* bdw2 (spa/dcr2, dimm2) */ 1846d7d8464dSRoss Zwisler bdw = nfit_buf + offset; 18476bc75619SDan Williams bdw->header.type = ACPI_NFIT_TYPE_DATA_REGION; 1848d7d8464dSRoss Zwisler bdw->header.length = sizeof(*bdw); 18496bc75619SDan Williams bdw->region_index = 2+1; 18506bc75619SDan Williams bdw->windows = 1; 18516bc75619SDan Williams bdw->offset = 0; 18526bc75619SDan Williams bdw->size = BDW_SIZE; 18536bc75619SDan Williams bdw->capacity = DIMM_SIZE; 18546bc75619SDan Williams bdw->start_address = 0; 1855d7d8464dSRoss Zwisler offset += bdw->header.length; 18566bc75619SDan Williams 18576bc75619SDan Williams /* bdw3 (spa/dcr3, dimm3) */ 1858d7d8464dSRoss Zwisler bdw = nfit_buf + offset; 18596bc75619SDan Williams bdw->header.type = ACPI_NFIT_TYPE_DATA_REGION; 1860d7d8464dSRoss Zwisler bdw->header.length = sizeof(*bdw); 18616bc75619SDan Williams bdw->region_index = 3+1; 18626bc75619SDan Williams bdw->windows = 1; 18636bc75619SDan Williams bdw->offset = 0; 18646bc75619SDan Williams bdw->size = BDW_SIZE; 18656bc75619SDan Williams bdw->capacity = DIMM_SIZE; 18666bc75619SDan Williams bdw->start_address = 0; 1867d7d8464dSRoss Zwisler offset += bdw->header.length; 18686bc75619SDan Williams 18699d27a87eSDan Williams /* flush0 (dimm0) */ 18709d27a87eSDan Williams flush = nfit_buf + offset; 18719d27a87eSDan Williams flush->header.type = ACPI_NFIT_TYPE_FLUSH_ADDRESS; 187285d3fa02SDan Williams flush->header.length = flush_hint_size; 18739d27a87eSDan Williams flush->device_handle = handle[0]; 187485d3fa02SDan Williams flush->hint_count = NUM_HINTS; 187585d3fa02SDan Williams for (i = 0; i < NUM_HINTS; i++) 187685d3fa02SDan Williams flush->hint_address[i] = t->flush_dma[0] + i * sizeof(u64); 1877d7d8464dSRoss Zwisler offset += flush->header.length; 18789d27a87eSDan Williams 18799d27a87eSDan Williams /* flush1 (dimm1) */ 1880d7d8464dSRoss Zwisler flush = nfit_buf + offset; 18819d27a87eSDan Williams flush->header.type = ACPI_NFIT_TYPE_FLUSH_ADDRESS; 188285d3fa02SDan Williams flush->header.length = flush_hint_size; 18839d27a87eSDan Williams flush->device_handle = handle[1]; 188485d3fa02SDan Williams flush->hint_count = NUM_HINTS; 188585d3fa02SDan Williams for (i = 0; i < NUM_HINTS; i++) 188685d3fa02SDan Williams flush->hint_address[i] = t->flush_dma[1] + i * sizeof(u64); 1887d7d8464dSRoss Zwisler offset += flush->header.length; 18889d27a87eSDan Williams 18899d27a87eSDan Williams /* flush2 (dimm2) */ 1890d7d8464dSRoss Zwisler flush = nfit_buf + offset; 18919d27a87eSDan Williams flush->header.type = ACPI_NFIT_TYPE_FLUSH_ADDRESS; 189285d3fa02SDan Williams flush->header.length = flush_hint_size; 18939d27a87eSDan Williams flush->device_handle = handle[2]; 189485d3fa02SDan Williams flush->hint_count = NUM_HINTS; 189585d3fa02SDan Williams for (i = 0; i < NUM_HINTS; i++) 189685d3fa02SDan Williams flush->hint_address[i] = t->flush_dma[2] + i * sizeof(u64); 1897d7d8464dSRoss Zwisler offset += flush->header.length; 18989d27a87eSDan Williams 18999d27a87eSDan Williams /* flush3 (dimm3) */ 1900d7d8464dSRoss Zwisler flush = nfit_buf + offset; 19019d27a87eSDan Williams flush->header.type = ACPI_NFIT_TYPE_FLUSH_ADDRESS; 190285d3fa02SDan Williams flush->header.length = flush_hint_size; 19039d27a87eSDan Williams flush->device_handle = handle[3]; 190485d3fa02SDan Williams flush->hint_count = NUM_HINTS; 190585d3fa02SDan Williams for (i = 0; i < NUM_HINTS; i++) 190685d3fa02SDan Williams flush->hint_address[i] = t->flush_dma[3] + i * sizeof(u64); 1907d7d8464dSRoss Zwisler offset += flush->header.length; 19089d27a87eSDan Williams 1909f81e1d35SDave Jiang /* platform capabilities */ 1910d7d8464dSRoss Zwisler pcap = nfit_buf + offset; 1911f81e1d35SDave Jiang pcap->header.type = ACPI_NFIT_TYPE_CAPABILITIES; 1912f81e1d35SDave Jiang pcap->header.length = sizeof(*pcap); 1913f81e1d35SDave Jiang pcap->highest_capability = 1; 1914f81e1d35SDave Jiang pcap->capabilities = ACPI_NFIT_CAPABILITY_CACHE_FLUSH | 1915f81e1d35SDave Jiang ACPI_NFIT_CAPABILITY_MEM_FLUSH; 1916d7d8464dSRoss Zwisler offset += pcap->header.length; 1917f81e1d35SDave Jiang 191820985164SVishal Verma if (t->setup_hotplug) { 19193b87356fSDan Williams /* dcr-descriptor4: blk */ 192020985164SVishal Verma dcr = nfit_buf + offset; 192120985164SVishal Verma dcr->header.type = ACPI_NFIT_TYPE_CONTROL_REGION; 1922d7d8464dSRoss Zwisler dcr->header.length = sizeof(*dcr); 19233b87356fSDan Williams dcr->region_index = 8+1; 19245dc68e55SDan Williams dcr_common_init(dcr); 192520985164SVishal Verma dcr->serial_number = ~handle[4]; 1926be26f9aeSDan Williams dcr->code = NFIT_FIC_BLK; 192720985164SVishal Verma dcr->windows = 1; 192820985164SVishal Verma dcr->window_size = DCR_SIZE; 192920985164SVishal Verma dcr->command_offset = 0; 193020985164SVishal Verma dcr->command_size = 8; 193120985164SVishal Verma dcr->status_offset = 8; 193220985164SVishal Verma dcr->status_size = 4; 1933d7d8464dSRoss Zwisler offset += dcr->header.length; 193420985164SVishal Verma 19353b87356fSDan Williams /* dcr-descriptor4: pmem */ 19363b87356fSDan Williams dcr = nfit_buf + offset; 19373b87356fSDan Williams dcr->header.type = ACPI_NFIT_TYPE_CONTROL_REGION; 19383b87356fSDan Williams dcr->header.length = offsetof(struct acpi_nfit_control_region, 19393b87356fSDan Williams window_size); 19403b87356fSDan Williams dcr->region_index = 9+1; 19415dc68e55SDan Williams dcr_common_init(dcr); 19423b87356fSDan Williams dcr->serial_number = ~handle[4]; 19433b87356fSDan Williams dcr->code = NFIT_FIC_BYTEN; 19443b87356fSDan Williams dcr->windows = 0; 1945d7d8464dSRoss Zwisler offset += dcr->header.length; 19463b87356fSDan Williams 194720985164SVishal Verma /* bdw4 (spa/dcr4, dimm4) */ 194820985164SVishal Verma bdw = nfit_buf + offset; 194920985164SVishal Verma bdw->header.type = ACPI_NFIT_TYPE_DATA_REGION; 1950d7d8464dSRoss Zwisler bdw->header.length = sizeof(*bdw); 19513b87356fSDan Williams bdw->region_index = 8+1; 195220985164SVishal Verma bdw->windows = 1; 195320985164SVishal Verma bdw->offset = 0; 195420985164SVishal Verma bdw->size = BDW_SIZE; 195520985164SVishal Verma bdw->capacity = DIMM_SIZE; 195620985164SVishal Verma bdw->start_address = 0; 1957d7d8464dSRoss Zwisler offset += bdw->header.length; 195820985164SVishal Verma 195920985164SVishal Verma /* spa10 (dcr4) dimm4 */ 196020985164SVishal Verma spa = nfit_buf + offset; 196120985164SVishal Verma spa->header.type = ACPI_NFIT_TYPE_SYSTEM_ADDRESS; 196220985164SVishal Verma spa->header.length = sizeof(*spa); 196320985164SVishal Verma memcpy(spa->range_guid, to_nfit_uuid(NFIT_SPA_DCR), 16); 196420985164SVishal Verma spa->range_index = 10+1; 196520985164SVishal Verma spa->address = t->dcr_dma[4]; 196620985164SVishal Verma spa->length = DCR_SIZE; 1967d7d8464dSRoss Zwisler offset += spa->header.length; 196820985164SVishal Verma 196920985164SVishal Verma /* 197020985164SVishal Verma * spa11 (single-dimm interleave for hotplug, note storage 197120985164SVishal Verma * does not actually alias the related block-data-window 197220985164SVishal Verma * regions) 197320985164SVishal Verma */ 1974d7d8464dSRoss Zwisler spa = nfit_buf + offset; 197520985164SVishal Verma spa->header.type = ACPI_NFIT_TYPE_SYSTEM_ADDRESS; 197620985164SVishal Verma spa->header.length = sizeof(*spa); 197720985164SVishal Verma memcpy(spa->range_guid, to_nfit_uuid(NFIT_SPA_PM), 16); 197820985164SVishal Verma spa->range_index = 11+1; 197920985164SVishal Verma spa->address = t->spa_set_dma[2]; 198020985164SVishal Verma spa->length = SPA0_SIZE; 1981d7d8464dSRoss Zwisler offset += spa->header.length; 198220985164SVishal Verma 198320985164SVishal Verma /* spa12 (bdw for dcr4) dimm4 */ 1984d7d8464dSRoss Zwisler spa = nfit_buf + offset; 198520985164SVishal Verma spa->header.type = ACPI_NFIT_TYPE_SYSTEM_ADDRESS; 198620985164SVishal Verma spa->header.length = sizeof(*spa); 198720985164SVishal Verma memcpy(spa->range_guid, to_nfit_uuid(NFIT_SPA_BDW), 16); 198820985164SVishal Verma spa->range_index = 12+1; 198920985164SVishal Verma spa->address = t->dimm_dma[4]; 199020985164SVishal Verma spa->length = DIMM_SIZE; 1991d7d8464dSRoss Zwisler offset += spa->header.length; 199220985164SVishal Verma 199320985164SVishal Verma /* mem-region14 (spa/dcr4, dimm4) */ 199420985164SVishal Verma memdev = nfit_buf + offset; 199520985164SVishal Verma memdev->header.type = ACPI_NFIT_TYPE_MEMORY_MAP; 199620985164SVishal Verma memdev->header.length = sizeof(*memdev); 199720985164SVishal Verma memdev->device_handle = handle[4]; 199820985164SVishal Verma memdev->physical_id = 4; 199920985164SVishal Verma memdev->region_id = 0; 200020985164SVishal Verma memdev->range_index = 10+1; 20013b87356fSDan Williams memdev->region_index = 8+1; 200220985164SVishal Verma memdev->region_size = 0; 200320985164SVishal Verma memdev->region_offset = 0; 200420985164SVishal Verma memdev->address = 0; 200520985164SVishal Verma memdev->interleave_index = 0; 200620985164SVishal Verma memdev->interleave_ways = 1; 2007d7d8464dSRoss Zwisler offset += memdev->header.length; 200820985164SVishal Verma 2009d7d8464dSRoss Zwisler /* mem-region15 (spa11, dimm4) */ 2010d7d8464dSRoss Zwisler memdev = nfit_buf + offset; 201120985164SVishal Verma memdev->header.type = ACPI_NFIT_TYPE_MEMORY_MAP; 201220985164SVishal Verma memdev->header.length = sizeof(*memdev); 201320985164SVishal Verma memdev->device_handle = handle[4]; 201420985164SVishal Verma memdev->physical_id = 4; 201520985164SVishal Verma memdev->region_id = 0; 201620985164SVishal Verma memdev->range_index = 11+1; 20173b87356fSDan Williams memdev->region_index = 9+1; 201820985164SVishal Verma memdev->region_size = SPA0_SIZE; 2019df06a2d5SDan Williams memdev->region_offset = (1ULL << 48); 202020985164SVishal Verma memdev->address = 0; 202120985164SVishal Verma memdev->interleave_index = 0; 202220985164SVishal Verma memdev->interleave_ways = 1; 2023ac40b675SDan Williams memdev->flags = ACPI_NFIT_MEM_HEALTH_ENABLED; 2024d7d8464dSRoss Zwisler offset += memdev->header.length; 202520985164SVishal Verma 20263b87356fSDan Williams /* mem-region16 (spa/bdw4, dimm4) */ 2027d7d8464dSRoss Zwisler memdev = nfit_buf + offset; 202820985164SVishal Verma memdev->header.type = ACPI_NFIT_TYPE_MEMORY_MAP; 202920985164SVishal Verma memdev->header.length = sizeof(*memdev); 203020985164SVishal Verma memdev->device_handle = handle[4]; 203120985164SVishal Verma memdev->physical_id = 4; 203220985164SVishal Verma memdev->region_id = 0; 203320985164SVishal Verma memdev->range_index = 12+1; 20343b87356fSDan Williams memdev->region_index = 8+1; 203520985164SVishal Verma memdev->region_size = 0; 203620985164SVishal Verma memdev->region_offset = 0; 203720985164SVishal Verma memdev->address = 0; 203820985164SVishal Verma memdev->interleave_index = 0; 203920985164SVishal Verma memdev->interleave_ways = 1; 2040d7d8464dSRoss Zwisler offset += memdev->header.length; 204120985164SVishal Verma 204220985164SVishal Verma /* flush3 (dimm4) */ 204320985164SVishal Verma flush = nfit_buf + offset; 204420985164SVishal Verma flush->header.type = ACPI_NFIT_TYPE_FLUSH_ADDRESS; 204585d3fa02SDan Williams flush->header.length = flush_hint_size; 204620985164SVishal Verma flush->device_handle = handle[4]; 204785d3fa02SDan Williams flush->hint_count = NUM_HINTS; 204885d3fa02SDan Williams for (i = 0; i < NUM_HINTS; i++) 204985d3fa02SDan Williams flush->hint_address[i] = t->flush_dma[4] 205085d3fa02SDan Williams + i * sizeof(u64); 2051d7d8464dSRoss Zwisler offset += flush->header.length; 20529741a559SRoss Zwisler 20539741a559SRoss Zwisler /* sanity check to make sure we've filled the buffer */ 20549741a559SRoss Zwisler WARN_ON(offset != t->nfit_size); 205520985164SVishal Verma } 205620985164SVishal Verma 2057*1526f9e2SRoss Zwisler t->nfit_filled = offset; 2058*1526f9e2SRoss Zwisler 20599fb1a190SDave Jiang post_ars_status(&t->ars_state, &t->badrange, t->spa_set_dma[0], 20609fb1a190SDave Jiang SPA0_SIZE); 2061f471f1a7SDan Williams 20626bc75619SDan Williams acpi_desc = &t->acpi_desc; 2063e3654ecaSDan Williams set_bit(ND_CMD_GET_CONFIG_SIZE, &acpi_desc->dimm_cmd_force_en); 2064e3654ecaSDan Williams set_bit(ND_CMD_GET_CONFIG_DATA, &acpi_desc->dimm_cmd_force_en); 2065e3654ecaSDan Williams set_bit(ND_CMD_SET_CONFIG_DATA, &acpi_desc->dimm_cmd_force_en); 2066ed07c433SDan Williams set_bit(ND_INTEL_SMART, &acpi_desc->dimm_cmd_force_en); 2067ed07c433SDan Williams set_bit(ND_INTEL_SMART_THRESHOLD, &acpi_desc->dimm_cmd_force_en); 2068ed07c433SDan Williams set_bit(ND_INTEL_SMART_SET_THRESHOLD, &acpi_desc->dimm_cmd_force_en); 2069e3654ecaSDan Williams set_bit(ND_CMD_ARS_CAP, &acpi_desc->bus_cmd_force_en); 2070e3654ecaSDan Williams set_bit(ND_CMD_ARS_START, &acpi_desc->bus_cmd_force_en); 2071e3654ecaSDan Williams set_bit(ND_CMD_ARS_STATUS, &acpi_desc->bus_cmd_force_en); 2072e3654ecaSDan Williams set_bit(ND_CMD_CLEAR_ERROR, &acpi_desc->bus_cmd_force_en); 207310246dc8SYasunori Goto set_bit(ND_CMD_CALL, &acpi_desc->bus_cmd_force_en); 207410246dc8SYasunori Goto set_bit(NFIT_CMD_TRANSLATE_SPA, &acpi_desc->bus_nfit_cmd_force_en); 20759fb1a190SDave Jiang set_bit(NFIT_CMD_ARS_INJECT_SET, &acpi_desc->bus_nfit_cmd_force_en); 20769fb1a190SDave Jiang set_bit(NFIT_CMD_ARS_INJECT_CLEAR, &acpi_desc->bus_nfit_cmd_force_en); 20779fb1a190SDave Jiang set_bit(NFIT_CMD_ARS_INJECT_GET, &acpi_desc->bus_nfit_cmd_force_en); 2078bfbaa952SDave Jiang set_bit(ND_INTEL_FW_GET_INFO, &acpi_desc->dimm_cmd_force_en); 2079bfbaa952SDave Jiang set_bit(ND_INTEL_FW_START_UPDATE, &acpi_desc->dimm_cmd_force_en); 2080bfbaa952SDave Jiang set_bit(ND_INTEL_FW_SEND_DATA, &acpi_desc->dimm_cmd_force_en); 2081bfbaa952SDave Jiang set_bit(ND_INTEL_FW_FINISH_UPDATE, &acpi_desc->dimm_cmd_force_en); 2082bfbaa952SDave Jiang set_bit(ND_INTEL_FW_FINISH_QUERY, &acpi_desc->dimm_cmd_force_en); 2083674d8bdeSDave Jiang set_bit(ND_INTEL_ENABLE_LSS_STATUS, &acpi_desc->dimm_cmd_force_en); 20846bc75619SDan Williams } 20856bc75619SDan Williams 20866bc75619SDan Williams static void nfit_test1_setup(struct nfit_test *t) 20876bc75619SDan Williams { 20886b577c9dSLinda Knippers size_t offset; 20896bc75619SDan Williams void *nfit_buf = t->nfit_buf; 20906bc75619SDan Williams struct acpi_nfit_memory_map *memdev; 20916bc75619SDan Williams struct acpi_nfit_control_region *dcr; 20926bc75619SDan Williams struct acpi_nfit_system_address *spa; 2093d26f73f0SDan Williams struct acpi_nfit_desc *acpi_desc; 20946bc75619SDan Williams 20956b577c9dSLinda Knippers offset = 0; 20966bc75619SDan Williams /* spa0 (flat range with no bdw aliasing) */ 20976bc75619SDan Williams spa = nfit_buf + offset; 20986bc75619SDan Williams spa->header.type = ACPI_NFIT_TYPE_SYSTEM_ADDRESS; 20996bc75619SDan Williams spa->header.length = sizeof(*spa); 21006bc75619SDan Williams memcpy(spa->range_guid, to_nfit_uuid(NFIT_SPA_PM), 16); 21016bc75619SDan Williams spa->range_index = 0+1; 21026bc75619SDan Williams spa->address = t->spa_set_dma[0]; 21036bc75619SDan Williams spa->length = SPA2_SIZE; 2104d7d8464dSRoss Zwisler offset += spa->header.length; 21056bc75619SDan Williams 21067bfe97c7SDan Williams /* virtual cd region */ 2107d7d8464dSRoss Zwisler spa = nfit_buf + offset; 21087bfe97c7SDan Williams spa->header.type = ACPI_NFIT_TYPE_SYSTEM_ADDRESS; 21097bfe97c7SDan Williams spa->header.length = sizeof(*spa); 21107bfe97c7SDan Williams memcpy(spa->range_guid, to_nfit_uuid(NFIT_SPA_VCD), 16); 21117bfe97c7SDan Williams spa->range_index = 0; 21127bfe97c7SDan Williams spa->address = t->spa_set_dma[1]; 21137bfe97c7SDan Williams spa->length = SPA_VCD_SIZE; 2114d7d8464dSRoss Zwisler offset += spa->header.length; 21157bfe97c7SDan Williams 21166bc75619SDan Williams /* mem-region0 (spa0, dimm0) */ 21176bc75619SDan Williams memdev = nfit_buf + offset; 21186bc75619SDan Williams memdev->header.type = ACPI_NFIT_TYPE_MEMORY_MAP; 21196bc75619SDan Williams memdev->header.length = sizeof(*memdev); 2120dafb1048SDan Williams memdev->device_handle = handle[5]; 21216bc75619SDan Williams memdev->physical_id = 0; 21226bc75619SDan Williams memdev->region_id = 0; 21236bc75619SDan Williams memdev->range_index = 0+1; 21246bc75619SDan Williams memdev->region_index = 0+1; 21256bc75619SDan Williams memdev->region_size = SPA2_SIZE; 21266bc75619SDan Williams memdev->region_offset = 0; 21276bc75619SDan Williams memdev->address = 0; 21286bc75619SDan Williams memdev->interleave_index = 0; 21296bc75619SDan Williams memdev->interleave_ways = 1; 213058138820SDan Williams memdev->flags = ACPI_NFIT_MEM_SAVE_FAILED | ACPI_NFIT_MEM_RESTORE_FAILED 213158138820SDan Williams | ACPI_NFIT_MEM_FLUSH_FAILED | ACPI_NFIT_MEM_HEALTH_OBSERVED 2132f4295796SDan Williams | ACPI_NFIT_MEM_NOT_ARMED; 2133d7d8464dSRoss Zwisler offset += memdev->header.length; 21346bc75619SDan Williams 21356bc75619SDan Williams /* dcr-descriptor0 */ 21366bc75619SDan Williams dcr = nfit_buf + offset; 21376bc75619SDan Williams dcr->header.type = ACPI_NFIT_TYPE_CONTROL_REGION; 21383b87356fSDan Williams dcr->header.length = offsetof(struct acpi_nfit_control_region, 21393b87356fSDan Williams window_size); 21406bc75619SDan Williams dcr->region_index = 0+1; 21415dc68e55SDan Williams dcr_common_init(dcr); 2142dafb1048SDan Williams dcr->serial_number = ~handle[5]; 2143be26f9aeSDan Williams dcr->code = NFIT_FIC_BYTE; 21446bc75619SDan Williams dcr->windows = 0; 2145ac40b675SDan Williams offset += dcr->header.length; 2146d7d8464dSRoss Zwisler 2147ac40b675SDan Williams memdev = nfit_buf + offset; 2148ac40b675SDan Williams memdev->header.type = ACPI_NFIT_TYPE_MEMORY_MAP; 2149ac40b675SDan Williams memdev->header.length = sizeof(*memdev); 2150ac40b675SDan Williams memdev->device_handle = handle[6]; 2151ac40b675SDan Williams memdev->physical_id = 0; 2152ac40b675SDan Williams memdev->region_id = 0; 2153ac40b675SDan Williams memdev->range_index = 0; 2154ac40b675SDan Williams memdev->region_index = 0+2; 2155ac40b675SDan Williams memdev->region_size = SPA2_SIZE; 2156ac40b675SDan Williams memdev->region_offset = 0; 2157ac40b675SDan Williams memdev->address = 0; 2158ac40b675SDan Williams memdev->interleave_index = 0; 2159ac40b675SDan Williams memdev->interleave_ways = 1; 2160ac40b675SDan Williams memdev->flags = ACPI_NFIT_MEM_MAP_FAILED; 2161d7d8464dSRoss Zwisler offset += memdev->header.length; 2162ac40b675SDan Williams 2163ac40b675SDan Williams /* dcr-descriptor1 */ 2164ac40b675SDan Williams dcr = nfit_buf + offset; 2165ac40b675SDan Williams dcr->header.type = ACPI_NFIT_TYPE_CONTROL_REGION; 2166ac40b675SDan Williams dcr->header.length = offsetof(struct acpi_nfit_control_region, 2167ac40b675SDan Williams window_size); 2168ac40b675SDan Williams dcr->region_index = 0+2; 2169ac40b675SDan Williams dcr_common_init(dcr); 2170ac40b675SDan Williams dcr->serial_number = ~handle[6]; 2171ac40b675SDan Williams dcr->code = NFIT_FIC_BYTE; 2172ac40b675SDan Williams dcr->windows = 0; 2173d7d8464dSRoss Zwisler offset += dcr->header.length; 2174ac40b675SDan Williams 21759741a559SRoss Zwisler /* sanity check to make sure we've filled the buffer */ 21769741a559SRoss Zwisler WARN_ON(offset != t->nfit_size); 21779741a559SRoss Zwisler 2178*1526f9e2SRoss Zwisler t->nfit_filled = offset; 2179*1526f9e2SRoss Zwisler 21809fb1a190SDave Jiang post_ars_status(&t->ars_state, &t->badrange, t->spa_set_dma[0], 21819fb1a190SDave Jiang SPA2_SIZE); 2182f471f1a7SDan Williams 2183d26f73f0SDan Williams acpi_desc = &t->acpi_desc; 2184e3654ecaSDan Williams set_bit(ND_CMD_ARS_CAP, &acpi_desc->bus_cmd_force_en); 2185e3654ecaSDan Williams set_bit(ND_CMD_ARS_START, &acpi_desc->bus_cmd_force_en); 2186e3654ecaSDan Williams set_bit(ND_CMD_ARS_STATUS, &acpi_desc->bus_cmd_force_en); 2187e3654ecaSDan Williams set_bit(ND_CMD_CLEAR_ERROR, &acpi_desc->bus_cmd_force_en); 2188674d8bdeSDave Jiang set_bit(ND_INTEL_ENABLE_LSS_STATUS, &acpi_desc->dimm_cmd_force_en); 21896bc75619SDan Williams } 21906bc75619SDan Williams 21916bc75619SDan Williams static int nfit_test_blk_do_io(struct nd_blk_region *ndbr, resource_size_t dpa, 21926bc75619SDan Williams void *iobuf, u64 len, int rw) 21936bc75619SDan Williams { 21946bc75619SDan Williams struct nfit_blk *nfit_blk = ndbr->blk_provider_data; 21956bc75619SDan Williams struct nfit_blk_mmio *mmio = &nfit_blk->mmio[BDW]; 21966bc75619SDan Williams struct nd_region *nd_region = &ndbr->nd_region; 21976bc75619SDan Williams unsigned int lane; 21986bc75619SDan Williams 21996bc75619SDan Williams lane = nd_region_acquire_lane(nd_region); 22006bc75619SDan Williams if (rw) 220167a3e8feSRoss Zwisler memcpy(mmio->addr.base + dpa, iobuf, len); 220267a3e8feSRoss Zwisler else { 220367a3e8feSRoss Zwisler memcpy(iobuf, mmio->addr.base + dpa, len); 220467a3e8feSRoss Zwisler 22055deb67f7SRobin Murphy /* give us some some coverage of the arch_invalidate_pmem() API */ 22065deb67f7SRobin Murphy arch_invalidate_pmem(mmio->addr.base + dpa, len); 220767a3e8feSRoss Zwisler } 22086bc75619SDan Williams nd_region_release_lane(nd_region, lane); 22096bc75619SDan Williams 22106bc75619SDan Williams return 0; 22116bc75619SDan Williams } 22126bc75619SDan Williams 2213a7de92daSDan Williams static unsigned long nfit_ctl_handle; 2214a7de92daSDan Williams 2215a7de92daSDan Williams union acpi_object *result; 2216a7de92daSDan Williams 2217a7de92daSDan Williams static union acpi_object *nfit_test_evaluate_dsm(acpi_handle handle, 221894116f81SAndy Shevchenko const guid_t *guid, u64 rev, u64 func, union acpi_object *argv4) 2219a7de92daSDan Williams { 2220a7de92daSDan Williams if (handle != &nfit_ctl_handle) 2221a7de92daSDan Williams return ERR_PTR(-ENXIO); 2222a7de92daSDan Williams 2223a7de92daSDan Williams return result; 2224a7de92daSDan Williams } 2225a7de92daSDan Williams 2226a7de92daSDan Williams static int setup_result(void *buf, size_t size) 2227a7de92daSDan Williams { 2228a7de92daSDan Williams result = kmalloc(sizeof(union acpi_object) + size, GFP_KERNEL); 2229a7de92daSDan Williams if (!result) 2230a7de92daSDan Williams return -ENOMEM; 2231a7de92daSDan Williams result->package.type = ACPI_TYPE_BUFFER, 2232a7de92daSDan Williams result->buffer.pointer = (void *) (result + 1); 2233a7de92daSDan Williams result->buffer.length = size; 2234a7de92daSDan Williams memcpy(result->buffer.pointer, buf, size); 2235a7de92daSDan Williams memset(buf, 0, size); 2236a7de92daSDan Williams return 0; 2237a7de92daSDan Williams } 2238a7de92daSDan Williams 2239a7de92daSDan Williams static int nfit_ctl_test(struct device *dev) 2240a7de92daSDan Williams { 2241a7de92daSDan Williams int rc, cmd_rc; 2242a7de92daSDan Williams struct nvdimm *nvdimm; 2243a7de92daSDan Williams struct acpi_device *adev; 2244a7de92daSDan Williams struct nfit_mem *nfit_mem; 2245a7de92daSDan Williams struct nd_ars_record *record; 2246a7de92daSDan Williams struct acpi_nfit_desc *acpi_desc; 2247a7de92daSDan Williams const u64 test_val = 0x0123456789abcdefULL; 2248a7de92daSDan Williams unsigned long mask, cmd_size, offset; 2249a7de92daSDan Williams union { 2250a7de92daSDan Williams struct nd_cmd_get_config_size cfg_size; 2251fb2a1748SDan Williams struct nd_cmd_clear_error clear_err; 2252a7de92daSDan Williams struct nd_cmd_ars_status ars_stat; 2253a7de92daSDan Williams struct nd_cmd_ars_cap ars_cap; 2254a7de92daSDan Williams char buf[sizeof(struct nd_cmd_ars_status) 2255a7de92daSDan Williams + sizeof(struct nd_ars_record)]; 2256a7de92daSDan Williams } cmds; 2257a7de92daSDan Williams 2258a7de92daSDan Williams adev = devm_kzalloc(dev, sizeof(*adev), GFP_KERNEL); 2259a7de92daSDan Williams if (!adev) 2260a7de92daSDan Williams return -ENOMEM; 2261a7de92daSDan Williams *adev = (struct acpi_device) { 2262a7de92daSDan Williams .handle = &nfit_ctl_handle, 2263a7de92daSDan Williams .dev = { 2264a7de92daSDan Williams .init_name = "test-adev", 2265a7de92daSDan Williams }, 2266a7de92daSDan Williams }; 2267a7de92daSDan Williams 2268a7de92daSDan Williams acpi_desc = devm_kzalloc(dev, sizeof(*acpi_desc), GFP_KERNEL); 2269a7de92daSDan Williams if (!acpi_desc) 2270a7de92daSDan Williams return -ENOMEM; 2271a7de92daSDan Williams *acpi_desc = (struct acpi_nfit_desc) { 2272a7de92daSDan Williams .nd_desc = { 2273a7de92daSDan Williams .cmd_mask = 1UL << ND_CMD_ARS_CAP 2274a7de92daSDan Williams | 1UL << ND_CMD_ARS_START 2275a7de92daSDan Williams | 1UL << ND_CMD_ARS_STATUS 227610246dc8SYasunori Goto | 1UL << ND_CMD_CLEAR_ERROR 227710246dc8SYasunori Goto | 1UL << ND_CMD_CALL, 2278a7de92daSDan Williams .module = THIS_MODULE, 2279a7de92daSDan Williams .provider_name = "ACPI.NFIT", 2280a7de92daSDan Williams .ndctl = acpi_nfit_ctl, 22819fb1a190SDave Jiang .bus_dsm_mask = 1UL << NFIT_CMD_TRANSLATE_SPA 22829fb1a190SDave Jiang | 1UL << NFIT_CMD_ARS_INJECT_SET 22839fb1a190SDave Jiang | 1UL << NFIT_CMD_ARS_INJECT_CLEAR 22849fb1a190SDave Jiang | 1UL << NFIT_CMD_ARS_INJECT_GET, 2285a7de92daSDan Williams }, 2286a7de92daSDan Williams .dev = &adev->dev, 2287a7de92daSDan Williams }; 2288a7de92daSDan Williams 2289a7de92daSDan Williams nfit_mem = devm_kzalloc(dev, sizeof(*nfit_mem), GFP_KERNEL); 2290a7de92daSDan Williams if (!nfit_mem) 2291a7de92daSDan Williams return -ENOMEM; 2292a7de92daSDan Williams 2293a7de92daSDan Williams mask = 1UL << ND_CMD_SMART | 1UL << ND_CMD_SMART_THRESHOLD 2294a7de92daSDan Williams | 1UL << ND_CMD_DIMM_FLAGS | 1UL << ND_CMD_GET_CONFIG_SIZE 2295a7de92daSDan Williams | 1UL << ND_CMD_GET_CONFIG_DATA | 1UL << ND_CMD_SET_CONFIG_DATA 2296a7de92daSDan Williams | 1UL << ND_CMD_VENDOR; 2297a7de92daSDan Williams *nfit_mem = (struct nfit_mem) { 2298a7de92daSDan Williams .adev = adev, 2299a7de92daSDan Williams .family = NVDIMM_FAMILY_INTEL, 2300a7de92daSDan Williams .dsm_mask = mask, 2301a7de92daSDan Williams }; 2302a7de92daSDan Williams 2303a7de92daSDan Williams nvdimm = devm_kzalloc(dev, sizeof(*nvdimm), GFP_KERNEL); 2304a7de92daSDan Williams if (!nvdimm) 2305a7de92daSDan Williams return -ENOMEM; 2306a7de92daSDan Williams *nvdimm = (struct nvdimm) { 2307a7de92daSDan Williams .provider_data = nfit_mem, 2308a7de92daSDan Williams .cmd_mask = mask, 2309a7de92daSDan Williams .dev = { 2310a7de92daSDan Williams .init_name = "test-dimm", 2311a7de92daSDan Williams }, 2312a7de92daSDan Williams }; 2313a7de92daSDan Williams 2314a7de92daSDan Williams 2315a7de92daSDan Williams /* basic checkout of a typical 'get config size' command */ 2316a7de92daSDan Williams cmd_size = sizeof(cmds.cfg_size); 2317a7de92daSDan Williams cmds.cfg_size = (struct nd_cmd_get_config_size) { 2318a7de92daSDan Williams .status = 0, 2319a7de92daSDan Williams .config_size = SZ_128K, 2320a7de92daSDan Williams .max_xfer = SZ_4K, 2321a7de92daSDan Williams }; 2322a7de92daSDan Williams rc = setup_result(cmds.buf, cmd_size); 2323a7de92daSDan Williams if (rc) 2324a7de92daSDan Williams return rc; 2325a7de92daSDan Williams rc = acpi_nfit_ctl(&acpi_desc->nd_desc, nvdimm, ND_CMD_GET_CONFIG_SIZE, 2326a7de92daSDan Williams cmds.buf, cmd_size, &cmd_rc); 2327a7de92daSDan Williams 2328a7de92daSDan Williams if (rc < 0 || cmd_rc || cmds.cfg_size.status != 0 2329a7de92daSDan Williams || cmds.cfg_size.config_size != SZ_128K 2330a7de92daSDan Williams || cmds.cfg_size.max_xfer != SZ_4K) { 2331a7de92daSDan Williams dev_dbg(dev, "%s: failed at: %d rc: %d cmd_rc: %d\n", 2332a7de92daSDan Williams __func__, __LINE__, rc, cmd_rc); 2333a7de92daSDan Williams return -EIO; 2334a7de92daSDan Williams } 2335a7de92daSDan Williams 2336a7de92daSDan Williams 2337a7de92daSDan Williams /* test ars_status with zero output */ 2338a7de92daSDan Williams cmd_size = offsetof(struct nd_cmd_ars_status, address); 2339a7de92daSDan Williams cmds.ars_stat = (struct nd_cmd_ars_status) { 2340a7de92daSDan Williams .out_length = 0, 2341a7de92daSDan Williams }; 2342a7de92daSDan Williams rc = setup_result(cmds.buf, cmd_size); 2343a7de92daSDan Williams if (rc) 2344a7de92daSDan Williams return rc; 2345a7de92daSDan Williams rc = acpi_nfit_ctl(&acpi_desc->nd_desc, NULL, ND_CMD_ARS_STATUS, 2346a7de92daSDan Williams cmds.buf, cmd_size, &cmd_rc); 2347a7de92daSDan Williams 2348a7de92daSDan Williams if (rc < 0 || cmd_rc) { 2349a7de92daSDan Williams dev_dbg(dev, "%s: failed at: %d rc: %d cmd_rc: %d\n", 2350a7de92daSDan Williams __func__, __LINE__, rc, cmd_rc); 2351a7de92daSDan Williams return -EIO; 2352a7de92daSDan Williams } 2353a7de92daSDan Williams 2354a7de92daSDan Williams 2355a7de92daSDan Williams /* test ars_cap with benign extended status */ 2356a7de92daSDan Williams cmd_size = sizeof(cmds.ars_cap); 2357a7de92daSDan Williams cmds.ars_cap = (struct nd_cmd_ars_cap) { 2358a7de92daSDan Williams .status = ND_ARS_PERSISTENT << 16, 2359a7de92daSDan Williams }; 2360a7de92daSDan Williams offset = offsetof(struct nd_cmd_ars_cap, status); 2361a7de92daSDan Williams rc = setup_result(cmds.buf + offset, cmd_size - offset); 2362a7de92daSDan Williams if (rc) 2363a7de92daSDan Williams return rc; 2364a7de92daSDan Williams rc = acpi_nfit_ctl(&acpi_desc->nd_desc, NULL, ND_CMD_ARS_CAP, 2365a7de92daSDan Williams cmds.buf, cmd_size, &cmd_rc); 2366a7de92daSDan Williams 2367a7de92daSDan Williams if (rc < 0 || cmd_rc) { 2368a7de92daSDan Williams dev_dbg(dev, "%s: failed at: %d rc: %d cmd_rc: %d\n", 2369a7de92daSDan Williams __func__, __LINE__, rc, cmd_rc); 2370a7de92daSDan Williams return -EIO; 2371a7de92daSDan Williams } 2372a7de92daSDan Williams 2373a7de92daSDan Williams 2374a7de92daSDan Williams /* test ars_status with 'status' trimmed from 'out_length' */ 2375a7de92daSDan Williams cmd_size = sizeof(cmds.ars_stat) + sizeof(struct nd_ars_record); 2376a7de92daSDan Williams cmds.ars_stat = (struct nd_cmd_ars_status) { 2377a7de92daSDan Williams .out_length = cmd_size - 4, 2378a7de92daSDan Williams }; 2379a7de92daSDan Williams record = &cmds.ars_stat.records[0]; 2380a7de92daSDan Williams *record = (struct nd_ars_record) { 2381a7de92daSDan Williams .length = test_val, 2382a7de92daSDan Williams }; 2383a7de92daSDan Williams rc = setup_result(cmds.buf, cmd_size); 2384a7de92daSDan Williams if (rc) 2385a7de92daSDan Williams return rc; 2386a7de92daSDan Williams rc = acpi_nfit_ctl(&acpi_desc->nd_desc, NULL, ND_CMD_ARS_STATUS, 2387a7de92daSDan Williams cmds.buf, cmd_size, &cmd_rc); 2388a7de92daSDan Williams 2389a7de92daSDan Williams if (rc < 0 || cmd_rc || record->length != test_val) { 2390a7de92daSDan Williams dev_dbg(dev, "%s: failed at: %d rc: %d cmd_rc: %d\n", 2391a7de92daSDan Williams __func__, __LINE__, rc, cmd_rc); 2392a7de92daSDan Williams return -EIO; 2393a7de92daSDan Williams } 2394a7de92daSDan Williams 2395a7de92daSDan Williams 2396a7de92daSDan Williams /* test ars_status with 'Output (Size)' including 'status' */ 2397a7de92daSDan Williams cmd_size = sizeof(cmds.ars_stat) + sizeof(struct nd_ars_record); 2398a7de92daSDan Williams cmds.ars_stat = (struct nd_cmd_ars_status) { 2399a7de92daSDan Williams .out_length = cmd_size, 2400a7de92daSDan Williams }; 2401a7de92daSDan Williams record = &cmds.ars_stat.records[0]; 2402a7de92daSDan Williams *record = (struct nd_ars_record) { 2403a7de92daSDan Williams .length = test_val, 2404a7de92daSDan Williams }; 2405a7de92daSDan Williams rc = setup_result(cmds.buf, cmd_size); 2406a7de92daSDan Williams if (rc) 2407a7de92daSDan Williams return rc; 2408a7de92daSDan Williams rc = acpi_nfit_ctl(&acpi_desc->nd_desc, NULL, ND_CMD_ARS_STATUS, 2409a7de92daSDan Williams cmds.buf, cmd_size, &cmd_rc); 2410a7de92daSDan Williams 2411a7de92daSDan Williams if (rc < 0 || cmd_rc || record->length != test_val) { 2412a7de92daSDan Williams dev_dbg(dev, "%s: failed at: %d rc: %d cmd_rc: %d\n", 2413a7de92daSDan Williams __func__, __LINE__, rc, cmd_rc); 2414a7de92daSDan Williams return -EIO; 2415a7de92daSDan Williams } 2416a7de92daSDan Williams 2417a7de92daSDan Williams 2418a7de92daSDan Williams /* test extended status for get_config_size results in failure */ 2419a7de92daSDan Williams cmd_size = sizeof(cmds.cfg_size); 2420a7de92daSDan Williams cmds.cfg_size = (struct nd_cmd_get_config_size) { 2421a7de92daSDan Williams .status = 1 << 16, 2422a7de92daSDan Williams }; 2423a7de92daSDan Williams rc = setup_result(cmds.buf, cmd_size); 2424a7de92daSDan Williams if (rc) 2425a7de92daSDan Williams return rc; 2426a7de92daSDan Williams rc = acpi_nfit_ctl(&acpi_desc->nd_desc, nvdimm, ND_CMD_GET_CONFIG_SIZE, 2427a7de92daSDan Williams cmds.buf, cmd_size, &cmd_rc); 2428a7de92daSDan Williams 2429a7de92daSDan Williams if (rc < 0 || cmd_rc >= 0) { 2430a7de92daSDan Williams dev_dbg(dev, "%s: failed at: %d rc: %d cmd_rc: %d\n", 2431a7de92daSDan Williams __func__, __LINE__, rc, cmd_rc); 2432a7de92daSDan Williams return -EIO; 2433a7de92daSDan Williams } 2434a7de92daSDan Williams 2435fb2a1748SDan Williams /* test clear error */ 2436fb2a1748SDan Williams cmd_size = sizeof(cmds.clear_err); 2437fb2a1748SDan Williams cmds.clear_err = (struct nd_cmd_clear_error) { 2438fb2a1748SDan Williams .length = 512, 2439fb2a1748SDan Williams .cleared = 512, 2440fb2a1748SDan Williams }; 2441fb2a1748SDan Williams rc = setup_result(cmds.buf, cmd_size); 2442fb2a1748SDan Williams if (rc) 2443fb2a1748SDan Williams return rc; 2444fb2a1748SDan Williams rc = acpi_nfit_ctl(&acpi_desc->nd_desc, NULL, ND_CMD_CLEAR_ERROR, 2445fb2a1748SDan Williams cmds.buf, cmd_size, &cmd_rc); 2446fb2a1748SDan Williams if (rc < 0 || cmd_rc) { 2447fb2a1748SDan Williams dev_dbg(dev, "%s: failed at: %d rc: %d cmd_rc: %d\n", 2448fb2a1748SDan Williams __func__, __LINE__, rc, cmd_rc); 2449fb2a1748SDan Williams return -EIO; 2450fb2a1748SDan Williams } 2451fb2a1748SDan Williams 2452a7de92daSDan Williams return 0; 2453a7de92daSDan Williams } 2454a7de92daSDan Williams 24556bc75619SDan Williams static int nfit_test_probe(struct platform_device *pdev) 24566bc75619SDan Williams { 24576bc75619SDan Williams struct nvdimm_bus_descriptor *nd_desc; 24586bc75619SDan Williams struct acpi_nfit_desc *acpi_desc; 24596bc75619SDan Williams struct device *dev = &pdev->dev; 24606bc75619SDan Williams struct nfit_test *nfit_test; 2461231bf117SDan Williams struct nfit_mem *nfit_mem; 2462c14a868aSDan Williams union acpi_object *obj; 24636bc75619SDan Williams int rc; 24646bc75619SDan Williams 2465a7de92daSDan Williams if (strcmp(dev_name(&pdev->dev), "nfit_test.0") == 0) { 2466a7de92daSDan Williams rc = nfit_ctl_test(&pdev->dev); 2467a7de92daSDan Williams if (rc) 2468a7de92daSDan Williams return rc; 2469a7de92daSDan Williams } 2470a7de92daSDan Williams 24716bc75619SDan Williams nfit_test = to_nfit_test(&pdev->dev); 24726bc75619SDan Williams 24736bc75619SDan Williams /* common alloc */ 24746bc75619SDan Williams if (nfit_test->num_dcr) { 24756bc75619SDan Williams int num = nfit_test->num_dcr; 24766bc75619SDan Williams 24776bc75619SDan Williams nfit_test->dimm = devm_kcalloc(dev, num, sizeof(void *), 24786bc75619SDan Williams GFP_KERNEL); 24796bc75619SDan Williams nfit_test->dimm_dma = devm_kcalloc(dev, num, sizeof(dma_addr_t), 24806bc75619SDan Williams GFP_KERNEL); 24819d27a87eSDan Williams nfit_test->flush = devm_kcalloc(dev, num, sizeof(void *), 24829d27a87eSDan Williams GFP_KERNEL); 24839d27a87eSDan Williams nfit_test->flush_dma = devm_kcalloc(dev, num, sizeof(dma_addr_t), 24849d27a87eSDan Williams GFP_KERNEL); 24856bc75619SDan Williams nfit_test->label = devm_kcalloc(dev, num, sizeof(void *), 24866bc75619SDan Williams GFP_KERNEL); 24876bc75619SDan Williams nfit_test->label_dma = devm_kcalloc(dev, num, 24886bc75619SDan Williams sizeof(dma_addr_t), GFP_KERNEL); 24896bc75619SDan Williams nfit_test->dcr = devm_kcalloc(dev, num, 24906bc75619SDan Williams sizeof(struct nfit_test_dcr *), GFP_KERNEL); 24916bc75619SDan Williams nfit_test->dcr_dma = devm_kcalloc(dev, num, 24926bc75619SDan Williams sizeof(dma_addr_t), GFP_KERNEL); 2493ed07c433SDan Williams nfit_test->smart = devm_kcalloc(dev, num, 2494ed07c433SDan Williams sizeof(struct nd_intel_smart), GFP_KERNEL); 2495ed07c433SDan Williams nfit_test->smart_threshold = devm_kcalloc(dev, num, 2496ed07c433SDan Williams sizeof(struct nd_intel_smart_threshold), 2497ed07c433SDan Williams GFP_KERNEL); 2498bfbaa952SDave Jiang nfit_test->fw = devm_kcalloc(dev, num, 2499bfbaa952SDave Jiang sizeof(struct nfit_test_fw), GFP_KERNEL); 25006bc75619SDan Williams if (nfit_test->dimm && nfit_test->dimm_dma && nfit_test->label 25016bc75619SDan Williams && nfit_test->label_dma && nfit_test->dcr 25029d27a87eSDan Williams && nfit_test->dcr_dma && nfit_test->flush 2503bfbaa952SDave Jiang && nfit_test->flush_dma 2504bfbaa952SDave Jiang && nfit_test->fw) 25056bc75619SDan Williams /* pass */; 25066bc75619SDan Williams else 25076bc75619SDan Williams return -ENOMEM; 25086bc75619SDan Williams } 25096bc75619SDan Williams 25106bc75619SDan Williams if (nfit_test->num_pm) { 25116bc75619SDan Williams int num = nfit_test->num_pm; 25126bc75619SDan Williams 25136bc75619SDan Williams nfit_test->spa_set = devm_kcalloc(dev, num, sizeof(void *), 25146bc75619SDan Williams GFP_KERNEL); 25156bc75619SDan Williams nfit_test->spa_set_dma = devm_kcalloc(dev, num, 25166bc75619SDan Williams sizeof(dma_addr_t), GFP_KERNEL); 25176bc75619SDan Williams if (nfit_test->spa_set && nfit_test->spa_set_dma) 25186bc75619SDan Williams /* pass */; 25196bc75619SDan Williams else 25206bc75619SDan Williams return -ENOMEM; 25216bc75619SDan Williams } 25226bc75619SDan Williams 25236bc75619SDan Williams /* per-nfit specific alloc */ 25246bc75619SDan Williams if (nfit_test->alloc(nfit_test)) 25256bc75619SDan Williams return -ENOMEM; 25266bc75619SDan Williams 25276bc75619SDan Williams nfit_test->setup(nfit_test); 25286bc75619SDan Williams acpi_desc = &nfit_test->acpi_desc; 2529a61fe6f7SDan Williams acpi_nfit_desc_init(acpi_desc, &pdev->dev); 25306bc75619SDan Williams acpi_desc->blk_do_io = nfit_test_blk_do_io; 25316bc75619SDan Williams nd_desc = &acpi_desc->nd_desc; 2532a61fe6f7SDan Williams nd_desc->provider_name = NULL; 2533bc9775d8SDan Williams nd_desc->module = THIS_MODULE; 2534a61fe6f7SDan Williams nd_desc->ndctl = nfit_test_ctl; 25356bc75619SDan Williams 2536e7a11b44SDan Williams rc = acpi_nfit_init(acpi_desc, nfit_test->nfit_buf, 2537*1526f9e2SRoss Zwisler nfit_test->nfit_filled); 253858cd71b4SDan Williams if (rc) 253920985164SVishal Verma return rc; 254020985164SVishal Verma 2541fbabd829SDan Williams rc = devm_add_action_or_reset(&pdev->dev, acpi_nfit_shutdown, acpi_desc); 2542fbabd829SDan Williams if (rc) 2543fbabd829SDan Williams return rc; 2544fbabd829SDan Williams 254520985164SVishal Verma if (nfit_test->setup != nfit_test0_setup) 254620985164SVishal Verma return 0; 254720985164SVishal Verma 254820985164SVishal Verma nfit_test->setup_hotplug = 1; 254920985164SVishal Verma nfit_test->setup(nfit_test); 255020985164SVishal Verma 2551c14a868aSDan Williams obj = kzalloc(sizeof(*obj), GFP_KERNEL); 2552c14a868aSDan Williams if (!obj) 2553c14a868aSDan Williams return -ENOMEM; 2554c14a868aSDan Williams obj->type = ACPI_TYPE_BUFFER; 2555c14a868aSDan Williams obj->buffer.length = nfit_test->nfit_size; 2556c14a868aSDan Williams obj->buffer.pointer = nfit_test->nfit_buf; 2557c14a868aSDan Williams *(nfit_test->_fit) = obj; 2558c14a868aSDan Williams __acpi_nfit_notify(&pdev->dev, nfit_test, 0x80); 2559231bf117SDan Williams 2560231bf117SDan Williams /* associate dimm devices with nfit_mem data for notification testing */ 2561231bf117SDan Williams mutex_lock(&acpi_desc->init_mutex); 2562231bf117SDan Williams list_for_each_entry(nfit_mem, &acpi_desc->dimms, list) { 2563231bf117SDan Williams u32 nfit_handle = __to_nfit_memdev(nfit_mem)->device_handle; 2564231bf117SDan Williams int i; 2565231bf117SDan Williams 2566231bf117SDan Williams for (i = 0; i < NUM_DCR; i++) 2567231bf117SDan Williams if (nfit_handle == handle[i]) 2568231bf117SDan Williams dev_set_drvdata(nfit_test->dimm_dev[i], 2569231bf117SDan Williams nfit_mem); 2570231bf117SDan Williams } 2571231bf117SDan Williams mutex_unlock(&acpi_desc->init_mutex); 25726bc75619SDan Williams 25736bc75619SDan Williams return 0; 25746bc75619SDan Williams } 25756bc75619SDan Williams 25766bc75619SDan Williams static int nfit_test_remove(struct platform_device *pdev) 25776bc75619SDan Williams { 25786bc75619SDan Williams return 0; 25796bc75619SDan Williams } 25806bc75619SDan Williams 25816bc75619SDan Williams static void nfit_test_release(struct device *dev) 25826bc75619SDan Williams { 25836bc75619SDan Williams struct nfit_test *nfit_test = to_nfit_test(dev); 25846bc75619SDan Williams 25856bc75619SDan Williams kfree(nfit_test); 25866bc75619SDan Williams } 25876bc75619SDan Williams 25886bc75619SDan Williams static const struct platform_device_id nfit_test_id[] = { 25896bc75619SDan Williams { KBUILD_MODNAME }, 25906bc75619SDan Williams { }, 25916bc75619SDan Williams }; 25926bc75619SDan Williams 25936bc75619SDan Williams static struct platform_driver nfit_test_driver = { 25946bc75619SDan Williams .probe = nfit_test_probe, 25956bc75619SDan Williams .remove = nfit_test_remove, 25966bc75619SDan Williams .driver = { 25976bc75619SDan Williams .name = KBUILD_MODNAME, 25986bc75619SDan Williams }, 25996bc75619SDan Williams .id_table = nfit_test_id, 26006bc75619SDan Williams }; 26016bc75619SDan Williams 26026bc75619SDan Williams static __init int nfit_test_init(void) 26036bc75619SDan Williams { 26046bc75619SDan Williams int rc, i; 26056bc75619SDan Williams 26060fb5c8dfSDan Williams pmem_test(); 26070fb5c8dfSDan Williams libnvdimm_test(); 26080fb5c8dfSDan Williams acpi_nfit_test(); 26090fb5c8dfSDan Williams device_dax_test(); 26100fb5c8dfSDan Williams 2611a7de92daSDan Williams nfit_test_setup(nfit_test_lookup, nfit_test_evaluate_dsm); 2612231bf117SDan Williams 26139fb1a190SDave Jiang nfit_wq = create_singlethread_workqueue("nfit"); 26149fb1a190SDave Jiang if (!nfit_wq) 26159fb1a190SDave Jiang return -ENOMEM; 26169fb1a190SDave Jiang 2617a7de92daSDan Williams nfit_test_dimm = class_create(THIS_MODULE, "nfit_test_dimm"); 2618a7de92daSDan Williams if (IS_ERR(nfit_test_dimm)) { 2619a7de92daSDan Williams rc = PTR_ERR(nfit_test_dimm); 2620a7de92daSDan Williams goto err_register; 2621a7de92daSDan Williams } 26226bc75619SDan Williams 26236bc75619SDan Williams for (i = 0; i < NUM_NFITS; i++) { 26246bc75619SDan Williams struct nfit_test *nfit_test; 26256bc75619SDan Williams struct platform_device *pdev; 26266bc75619SDan Williams 26276bc75619SDan Williams nfit_test = kzalloc(sizeof(*nfit_test), GFP_KERNEL); 26286bc75619SDan Williams if (!nfit_test) { 26296bc75619SDan Williams rc = -ENOMEM; 26306bc75619SDan Williams goto err_register; 26316bc75619SDan Williams } 26326bc75619SDan Williams INIT_LIST_HEAD(&nfit_test->resources); 26339fb1a190SDave Jiang badrange_init(&nfit_test->badrange); 26346bc75619SDan Williams switch (i) { 26356bc75619SDan Williams case 0: 26366bc75619SDan Williams nfit_test->num_pm = NUM_PM; 2637dafb1048SDan Williams nfit_test->dcr_idx = 0; 26386bc75619SDan Williams nfit_test->num_dcr = NUM_DCR; 26396bc75619SDan Williams nfit_test->alloc = nfit_test0_alloc; 26406bc75619SDan Williams nfit_test->setup = nfit_test0_setup; 26416bc75619SDan Williams break; 26426bc75619SDan Williams case 1: 2643a117699cSYasunori Goto nfit_test->num_pm = 2; 2644dafb1048SDan Williams nfit_test->dcr_idx = NUM_DCR; 2645ac40b675SDan Williams nfit_test->num_dcr = 2; 26466bc75619SDan Williams nfit_test->alloc = nfit_test1_alloc; 26476bc75619SDan Williams nfit_test->setup = nfit_test1_setup; 26486bc75619SDan Williams break; 26496bc75619SDan Williams default: 26506bc75619SDan Williams rc = -EINVAL; 26516bc75619SDan Williams goto err_register; 26526bc75619SDan Williams } 26536bc75619SDan Williams pdev = &nfit_test->pdev; 26546bc75619SDan Williams pdev->name = KBUILD_MODNAME; 26556bc75619SDan Williams pdev->id = i; 26566bc75619SDan Williams pdev->dev.release = nfit_test_release; 26576bc75619SDan Williams rc = platform_device_register(pdev); 26586bc75619SDan Williams if (rc) { 26596bc75619SDan Williams put_device(&pdev->dev); 26606bc75619SDan Williams goto err_register; 26616bc75619SDan Williams } 26628b06b884SDan Williams get_device(&pdev->dev); 26636bc75619SDan Williams 26646bc75619SDan Williams rc = dma_coerce_mask_and_coherent(&pdev->dev, DMA_BIT_MASK(64)); 26656bc75619SDan Williams if (rc) 26666bc75619SDan Williams goto err_register; 26676bc75619SDan Williams 26686bc75619SDan Williams instances[i] = nfit_test; 26699fb1a190SDave Jiang INIT_WORK(&nfit_test->work, uc_error_notify); 26706bc75619SDan Williams } 26716bc75619SDan Williams 26726bc75619SDan Williams rc = platform_driver_register(&nfit_test_driver); 26736bc75619SDan Williams if (rc) 26746bc75619SDan Williams goto err_register; 26756bc75619SDan Williams return 0; 26766bc75619SDan Williams 26776bc75619SDan Williams err_register: 26789fb1a190SDave Jiang destroy_workqueue(nfit_wq); 26796bc75619SDan Williams for (i = 0; i < NUM_NFITS; i++) 26806bc75619SDan Williams if (instances[i]) 26816bc75619SDan Williams platform_device_unregister(&instances[i]->pdev); 26826bc75619SDan Williams nfit_test_teardown(); 26838b06b884SDan Williams for (i = 0; i < NUM_NFITS; i++) 26848b06b884SDan Williams if (instances[i]) 26858b06b884SDan Williams put_device(&instances[i]->pdev.dev); 26868b06b884SDan Williams 26876bc75619SDan Williams return rc; 26886bc75619SDan Williams } 26896bc75619SDan Williams 26906bc75619SDan Williams static __exit void nfit_test_exit(void) 26916bc75619SDan Williams { 26926bc75619SDan Williams int i; 26936bc75619SDan Williams 26949fb1a190SDave Jiang flush_workqueue(nfit_wq); 26959fb1a190SDave Jiang destroy_workqueue(nfit_wq); 26966bc75619SDan Williams for (i = 0; i < NUM_NFITS; i++) 26976bc75619SDan Williams platform_device_unregister(&instances[i]->pdev); 26988b06b884SDan Williams platform_driver_unregister(&nfit_test_driver); 26996bc75619SDan Williams nfit_test_teardown(); 27008b06b884SDan Williams 27018b06b884SDan Williams for (i = 0; i < NUM_NFITS; i++) 27028b06b884SDan Williams put_device(&instances[i]->pdev.dev); 2703231bf117SDan Williams class_destroy(nfit_test_dimm); 27046bc75619SDan Williams } 27056bc75619SDan Williams 27066bc75619SDan Williams module_init(nfit_test_init); 27076bc75619SDan Williams module_exit(nfit_test_exit); 27086bc75619SDan Williams MODULE_LICENSE("GPL v2"); 27096bc75619SDan Williams MODULE_AUTHOR("Intel Corporation"); 2710