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 325d8beee2SDan Williams #include <asm/mcsafe_test.h> 335d8beee2SDan Williams 346bc75619SDan Williams /* 356bc75619SDan Williams * Generate an NFIT table to describe the following topology: 366bc75619SDan Williams * 376bc75619SDan Williams * BUS0: Interleaved PMEM regions, and aliasing with BLK regions 386bc75619SDan Williams * 396bc75619SDan Williams * (a) (b) DIMM BLK-REGION 406bc75619SDan Williams * +----------+--------------+----------+---------+ 416bc75619SDan Williams * +------+ | blk2.0 | pm0.0 | blk2.1 | pm1.0 | 0 region2 426bc75619SDan Williams * | imc0 +--+- - - - - region0 - - - -+----------+ + 436bc75619SDan Williams * +--+---+ | blk3.0 | pm0.0 | blk3.1 | pm1.0 | 1 region3 446bc75619SDan Williams * | +----------+--------------v----------v v 456bc75619SDan Williams * +--+---+ | | 466bc75619SDan Williams * | cpu0 | region1 476bc75619SDan Williams * +--+---+ | | 486bc75619SDan Williams * | +-------------------------^----------^ ^ 496bc75619SDan Williams * +--+---+ | blk4.0 | pm1.0 | 2 region4 506bc75619SDan Williams * | imc1 +--+-------------------------+----------+ + 516bc75619SDan Williams * +------+ | blk5.0 | pm1.0 | 3 region5 526bc75619SDan Williams * +-------------------------+----------+-+-------+ 536bc75619SDan Williams * 5420985164SVishal Verma * +--+---+ 5520985164SVishal Verma * | cpu1 | 5620985164SVishal Verma * +--+---+ (Hotplug DIMM) 5720985164SVishal Verma * | +----------------------------------------------+ 5820985164SVishal Verma * +--+---+ | blk6.0/pm7.0 | 4 region6/7 5920985164SVishal Verma * | imc0 +--+----------------------------------------------+ 6020985164SVishal Verma * +------+ 6120985164SVishal Verma * 6220985164SVishal Verma * 636bc75619SDan Williams * *) In this layout we have four dimms and two memory controllers in one 646bc75619SDan Williams * socket. Each unique interface (BLK or PMEM) to DPA space 656bc75619SDan Williams * is identified by a region device with a dynamically assigned id. 666bc75619SDan Williams * 676bc75619SDan Williams * *) The first portion of dimm0 and dimm1 are interleaved as REGION0. 686bc75619SDan Williams * A single PMEM namespace "pm0.0" is created using half of the 696bc75619SDan Williams * REGION0 SPA-range. REGION0 spans dimm0 and dimm1. PMEM namespace 706bc75619SDan Williams * allocate from from the bottom of a region. The unallocated 716bc75619SDan Williams * portion of REGION0 aliases with REGION2 and REGION3. That 726bc75619SDan Williams * unallacted capacity is reclaimed as BLK namespaces ("blk2.0" and 736bc75619SDan Williams * "blk3.0") starting at the base of each DIMM to offset (a) in those 746bc75619SDan Williams * DIMMs. "pm0.0", "blk2.0" and "blk3.0" are free-form readable 756bc75619SDan Williams * names that can be assigned to a namespace. 766bc75619SDan Williams * 776bc75619SDan Williams * *) In the last portion of dimm0 and dimm1 we have an interleaved 786bc75619SDan Williams * SPA range, REGION1, that spans those two dimms as well as dimm2 796bc75619SDan Williams * and dimm3. Some of REGION1 allocated to a PMEM namespace named 806bc75619SDan Williams * "pm1.0" the rest is reclaimed in 4 BLK namespaces (for each 816bc75619SDan Williams * dimm in the interleave set), "blk2.1", "blk3.1", "blk4.0", and 826bc75619SDan Williams * "blk5.0". 836bc75619SDan Williams * 846bc75619SDan Williams * *) The portion of dimm2 and dimm3 that do not participate in the 856bc75619SDan Williams * REGION1 interleaved SPA range (i.e. the DPA address below offset 866bc75619SDan Williams * (b) are also included in the "blk4.0" and "blk5.0" namespaces. 876bc75619SDan Williams * Note, that BLK namespaces need not be contiguous in DPA-space, and 886bc75619SDan Williams * can consume aliased capacity from multiple interleave sets. 896bc75619SDan Williams * 906bc75619SDan Williams * BUS1: Legacy NVDIMM (single contiguous range) 916bc75619SDan Williams * 926bc75619SDan Williams * region2 936bc75619SDan Williams * +---------------------+ 946bc75619SDan Williams * |---------------------| 956bc75619SDan Williams * || pm2.0 || 966bc75619SDan Williams * |---------------------| 976bc75619SDan Williams * +---------------------+ 986bc75619SDan Williams * 996bc75619SDan Williams * *) A NFIT-table may describe a simple system-physical-address range 1006bc75619SDan Williams * with no BLK aliasing. This type of region may optionally 1016bc75619SDan Williams * reference an NVDIMM. 1026bc75619SDan Williams */ 1036bc75619SDan Williams enum { 10420985164SVishal Verma NUM_PM = 3, 10520985164SVishal Verma NUM_DCR = 5, 10685d3fa02SDan Williams NUM_HINTS = 8, 1076bc75619SDan Williams NUM_BDW = NUM_DCR, 1086bc75619SDan Williams NUM_SPA = NUM_PM + NUM_DCR + NUM_BDW, 1099741a559SRoss Zwisler NUM_MEM = NUM_DCR + NUM_BDW + 2 /* spa0 iset */ 1109741a559SRoss Zwisler + 4 /* spa1 iset */ + 1 /* spa11 iset */, 1116bc75619SDan Williams DIMM_SIZE = SZ_32M, 1126bc75619SDan Williams LABEL_SIZE = SZ_128K, 1137bfe97c7SDan Williams SPA_VCD_SIZE = SZ_4M, 1146bc75619SDan Williams SPA0_SIZE = DIMM_SIZE, 1156bc75619SDan Williams SPA1_SIZE = DIMM_SIZE*2, 1166bc75619SDan Williams SPA2_SIZE = DIMM_SIZE, 1176bc75619SDan Williams BDW_SIZE = 64 << 8, 1186bc75619SDan Williams DCR_SIZE = 12, 1196bc75619SDan Williams NUM_NFITS = 2, /* permit testing multiple NFITs per system */ 1206bc75619SDan Williams }; 1216bc75619SDan Williams 1226bc75619SDan Williams struct nfit_test_dcr { 1236bc75619SDan Williams __le64 bdw_addr; 1246bc75619SDan Williams __le32 bdw_status; 1256bc75619SDan Williams __u8 aperature[BDW_SIZE]; 1266bc75619SDan Williams }; 1276bc75619SDan Williams 1286bc75619SDan Williams #define NFIT_DIMM_HANDLE(node, socket, imc, chan, dimm) \ 1296bc75619SDan Williams (((node & 0xfff) << 16) | ((socket & 0xf) << 12) \ 1306bc75619SDan Williams | ((imc & 0xf) << 8) | ((chan & 0xf) << 4) | (dimm & 0xf)) 1316bc75619SDan Williams 132dafb1048SDan Williams static u32 handle[] = { 1336bc75619SDan Williams [0] = NFIT_DIMM_HANDLE(0, 0, 0, 0, 0), 1346bc75619SDan Williams [1] = NFIT_DIMM_HANDLE(0, 0, 0, 0, 1), 1356bc75619SDan Williams [2] = NFIT_DIMM_HANDLE(0, 0, 1, 0, 0), 1366bc75619SDan Williams [3] = NFIT_DIMM_HANDLE(0, 0, 1, 0, 1), 13720985164SVishal Verma [4] = NFIT_DIMM_HANDLE(0, 1, 0, 0, 0), 138dafb1048SDan Williams [5] = NFIT_DIMM_HANDLE(1, 0, 0, 0, 0), 139ac40b675SDan Williams [6] = NFIT_DIMM_HANDLE(1, 0, 0, 0, 1), 1406bc75619SDan Williams }; 1416bc75619SDan Williams 14273606afdSDan Williams static unsigned long dimm_fail_cmd_flags[NUM_DCR]; 14355c72ab6SDan Williams static int dimm_fail_cmd_code[NUM_DCR]; 14473606afdSDan Williams 145*b4d4702fSVishal Verma static const struct nd_intel_smart smart_def = { 146*b4d4702fSVishal Verma .flags = ND_INTEL_SMART_HEALTH_VALID 147*b4d4702fSVishal Verma | ND_INTEL_SMART_SPARES_VALID 148*b4d4702fSVishal Verma | ND_INTEL_SMART_ALARM_VALID 149*b4d4702fSVishal Verma | ND_INTEL_SMART_USED_VALID 150*b4d4702fSVishal Verma | ND_INTEL_SMART_SHUTDOWN_VALID 151*b4d4702fSVishal Verma | ND_INTEL_SMART_MTEMP_VALID 152*b4d4702fSVishal Verma | ND_INTEL_SMART_CTEMP_VALID, 153*b4d4702fSVishal Verma .health = ND_INTEL_SMART_NON_CRITICAL_HEALTH, 154*b4d4702fSVishal Verma .media_temperature = 23 * 16, 155*b4d4702fSVishal Verma .ctrl_temperature = 25 * 16, 156*b4d4702fSVishal Verma .pmic_temperature = 40 * 16, 157*b4d4702fSVishal Verma .spares = 75, 158*b4d4702fSVishal Verma .alarm_flags = ND_INTEL_SMART_SPARE_TRIP 159*b4d4702fSVishal Verma | ND_INTEL_SMART_TEMP_TRIP, 160*b4d4702fSVishal Verma .ait_status = 1, 161*b4d4702fSVishal Verma .life_used = 5, 162*b4d4702fSVishal Verma .shutdown_state = 0, 163*b4d4702fSVishal Verma .vendor_size = 0, 164*b4d4702fSVishal Verma .shutdown_count = 100, 165*b4d4702fSVishal Verma }; 166*b4d4702fSVishal Verma 167bfbaa952SDave Jiang struct nfit_test_fw { 168bfbaa952SDave Jiang enum intel_fw_update_state state; 169bfbaa952SDave Jiang u32 context; 170bfbaa952SDave Jiang u64 version; 171bfbaa952SDave Jiang u32 size_received; 172bfbaa952SDave Jiang u64 end_time; 173bfbaa952SDave Jiang }; 174bfbaa952SDave Jiang 1756bc75619SDan Williams struct nfit_test { 1766bc75619SDan Williams struct acpi_nfit_desc acpi_desc; 1776bc75619SDan Williams struct platform_device pdev; 1786bc75619SDan Williams struct list_head resources; 1796bc75619SDan Williams void *nfit_buf; 1806bc75619SDan Williams dma_addr_t nfit_dma; 1816bc75619SDan Williams size_t nfit_size; 1821526f9e2SRoss Zwisler size_t nfit_filled; 183dafb1048SDan Williams int dcr_idx; 1846bc75619SDan Williams int num_dcr; 1856bc75619SDan Williams int num_pm; 1866bc75619SDan Williams void **dimm; 1876bc75619SDan Williams dma_addr_t *dimm_dma; 1889d27a87eSDan Williams void **flush; 1899d27a87eSDan Williams dma_addr_t *flush_dma; 1906bc75619SDan Williams void **label; 1916bc75619SDan Williams dma_addr_t *label_dma; 1926bc75619SDan Williams void **spa_set; 1936bc75619SDan Williams dma_addr_t *spa_set_dma; 1946bc75619SDan Williams struct nfit_test_dcr **dcr; 1956bc75619SDan Williams dma_addr_t *dcr_dma; 1966bc75619SDan Williams int (*alloc)(struct nfit_test *t); 1976bc75619SDan Williams void (*setup)(struct nfit_test *t); 19820985164SVishal Verma int setup_hotplug; 199c14a868aSDan Williams union acpi_object **_fit; 200c14a868aSDan Williams dma_addr_t _fit_dma; 201f471f1a7SDan Williams struct ars_state { 202f471f1a7SDan Williams struct nd_cmd_ars_status *ars_status; 203f471f1a7SDan Williams unsigned long deadline; 204f471f1a7SDan Williams spinlock_t lock; 205f471f1a7SDan Williams } ars_state; 206231bf117SDan Williams struct device *dimm_dev[NUM_DCR]; 207ed07c433SDan Williams struct nd_intel_smart *smart; 208ed07c433SDan Williams struct nd_intel_smart_threshold *smart_threshold; 2099fb1a190SDave Jiang struct badrange badrange; 2109fb1a190SDave Jiang struct work_struct work; 211bfbaa952SDave Jiang struct nfit_test_fw *fw; 2126bc75619SDan Williams }; 2136bc75619SDan Williams 2149fb1a190SDave Jiang static struct workqueue_struct *nfit_wq; 2159fb1a190SDave Jiang 2166bc75619SDan Williams static struct nfit_test *to_nfit_test(struct device *dev) 2176bc75619SDan Williams { 2186bc75619SDan Williams struct platform_device *pdev = to_platform_device(dev); 2196bc75619SDan Williams 2206bc75619SDan Williams return container_of(pdev, struct nfit_test, pdev); 2216bc75619SDan Williams } 2226bc75619SDan Williams 223bfbaa952SDave Jiang static int nd_intel_test_get_fw_info(struct nfit_test *t, 224bfbaa952SDave Jiang struct nd_intel_fw_info *nd_cmd, unsigned int buf_len, 225bfbaa952SDave Jiang int idx) 226bfbaa952SDave Jiang { 227bfbaa952SDave Jiang struct device *dev = &t->pdev.dev; 228bfbaa952SDave Jiang struct nfit_test_fw *fw = &t->fw[idx]; 229bfbaa952SDave Jiang 230bfbaa952SDave Jiang dev_dbg(dev, "%s(nfit_test: %p nd_cmd: %p, buf_len: %u, idx: %d\n", 231bfbaa952SDave Jiang __func__, t, nd_cmd, buf_len, idx); 232bfbaa952SDave Jiang 233bfbaa952SDave Jiang if (buf_len < sizeof(*nd_cmd)) 234bfbaa952SDave Jiang return -EINVAL; 235bfbaa952SDave Jiang 236bfbaa952SDave Jiang nd_cmd->status = 0; 237bfbaa952SDave Jiang nd_cmd->storage_size = INTEL_FW_STORAGE_SIZE; 238bfbaa952SDave Jiang nd_cmd->max_send_len = INTEL_FW_MAX_SEND_LEN; 239bfbaa952SDave Jiang nd_cmd->query_interval = INTEL_FW_QUERY_INTERVAL; 240bfbaa952SDave Jiang nd_cmd->max_query_time = INTEL_FW_QUERY_MAX_TIME; 241bfbaa952SDave Jiang nd_cmd->update_cap = 0; 242bfbaa952SDave Jiang nd_cmd->fis_version = INTEL_FW_FIS_VERSION; 243bfbaa952SDave Jiang nd_cmd->run_version = 0; 244bfbaa952SDave Jiang nd_cmd->updated_version = fw->version; 245bfbaa952SDave Jiang 246bfbaa952SDave Jiang return 0; 247bfbaa952SDave Jiang } 248bfbaa952SDave Jiang 249bfbaa952SDave Jiang static int nd_intel_test_start_update(struct nfit_test *t, 250bfbaa952SDave Jiang struct nd_intel_fw_start *nd_cmd, unsigned int buf_len, 251bfbaa952SDave Jiang int idx) 252bfbaa952SDave Jiang { 253bfbaa952SDave Jiang struct device *dev = &t->pdev.dev; 254bfbaa952SDave Jiang struct nfit_test_fw *fw = &t->fw[idx]; 255bfbaa952SDave Jiang 256bfbaa952SDave Jiang dev_dbg(dev, "%s(nfit_test: %p nd_cmd: %p buf_len: %u idx: %d)\n", 257bfbaa952SDave Jiang __func__, t, nd_cmd, buf_len, idx); 258bfbaa952SDave Jiang 259bfbaa952SDave Jiang if (buf_len < sizeof(*nd_cmd)) 260bfbaa952SDave Jiang return -EINVAL; 261bfbaa952SDave Jiang 262bfbaa952SDave Jiang if (fw->state != FW_STATE_NEW) { 263bfbaa952SDave Jiang /* extended status, FW update in progress */ 264bfbaa952SDave Jiang nd_cmd->status = 0x10007; 265bfbaa952SDave Jiang return 0; 266bfbaa952SDave Jiang } 267bfbaa952SDave Jiang 268bfbaa952SDave Jiang fw->state = FW_STATE_IN_PROGRESS; 269bfbaa952SDave Jiang fw->context++; 270bfbaa952SDave Jiang fw->size_received = 0; 271bfbaa952SDave Jiang nd_cmd->status = 0; 272bfbaa952SDave Jiang nd_cmd->context = fw->context; 273bfbaa952SDave Jiang 274bfbaa952SDave Jiang dev_dbg(dev, "%s: context issued: %#x\n", __func__, nd_cmd->context); 275bfbaa952SDave Jiang 276bfbaa952SDave Jiang return 0; 277bfbaa952SDave Jiang } 278bfbaa952SDave Jiang 279bfbaa952SDave Jiang static int nd_intel_test_send_data(struct nfit_test *t, 280bfbaa952SDave Jiang struct nd_intel_fw_send_data *nd_cmd, unsigned int buf_len, 281bfbaa952SDave Jiang int idx) 282bfbaa952SDave Jiang { 283bfbaa952SDave Jiang struct device *dev = &t->pdev.dev; 284bfbaa952SDave Jiang struct nfit_test_fw *fw = &t->fw[idx]; 285bfbaa952SDave Jiang u32 *status = (u32 *)&nd_cmd->data[nd_cmd->length]; 286bfbaa952SDave Jiang 287bfbaa952SDave Jiang dev_dbg(dev, "%s(nfit_test: %p nd_cmd: %p buf_len: %u idx: %d)\n", 288bfbaa952SDave Jiang __func__, t, nd_cmd, buf_len, idx); 289bfbaa952SDave Jiang 290bfbaa952SDave Jiang if (buf_len < sizeof(*nd_cmd)) 291bfbaa952SDave Jiang return -EINVAL; 292bfbaa952SDave Jiang 293bfbaa952SDave Jiang 294bfbaa952SDave Jiang dev_dbg(dev, "%s: cmd->status: %#x\n", __func__, *status); 295bfbaa952SDave Jiang dev_dbg(dev, "%s: cmd->data[0]: %#x\n", __func__, nd_cmd->data[0]); 296bfbaa952SDave Jiang dev_dbg(dev, "%s: cmd->data[%u]: %#x\n", __func__, nd_cmd->length-1, 297bfbaa952SDave Jiang nd_cmd->data[nd_cmd->length-1]); 298bfbaa952SDave Jiang 299bfbaa952SDave Jiang if (fw->state != FW_STATE_IN_PROGRESS) { 300bfbaa952SDave Jiang dev_dbg(dev, "%s: not in IN_PROGRESS state\n", __func__); 301bfbaa952SDave Jiang *status = 0x5; 302bfbaa952SDave Jiang return 0; 303bfbaa952SDave Jiang } 304bfbaa952SDave Jiang 305bfbaa952SDave Jiang if (nd_cmd->context != fw->context) { 306bfbaa952SDave Jiang dev_dbg(dev, "%s: incorrect context: in: %#x correct: %#x\n", 307bfbaa952SDave Jiang __func__, nd_cmd->context, fw->context); 308bfbaa952SDave Jiang *status = 0x10007; 309bfbaa952SDave Jiang return 0; 310bfbaa952SDave Jiang } 311bfbaa952SDave Jiang 312bfbaa952SDave Jiang /* 313bfbaa952SDave Jiang * check offset + len > size of fw storage 314bfbaa952SDave Jiang * check length is > max send length 315bfbaa952SDave Jiang */ 316bfbaa952SDave Jiang if (nd_cmd->offset + nd_cmd->length > INTEL_FW_STORAGE_SIZE || 317bfbaa952SDave Jiang nd_cmd->length > INTEL_FW_MAX_SEND_LEN) { 318bfbaa952SDave Jiang *status = 0x3; 319bfbaa952SDave Jiang dev_dbg(dev, "%s: buffer boundary violation\n", __func__); 320bfbaa952SDave Jiang return 0; 321bfbaa952SDave Jiang } 322bfbaa952SDave Jiang 323bfbaa952SDave Jiang fw->size_received += nd_cmd->length; 324bfbaa952SDave Jiang dev_dbg(dev, "%s: copying %u bytes, %u bytes so far\n", 325bfbaa952SDave Jiang __func__, nd_cmd->length, fw->size_received); 326bfbaa952SDave Jiang *status = 0; 327bfbaa952SDave Jiang return 0; 328bfbaa952SDave Jiang } 329bfbaa952SDave Jiang 330bfbaa952SDave Jiang static int nd_intel_test_finish_fw(struct nfit_test *t, 331bfbaa952SDave Jiang struct nd_intel_fw_finish_update *nd_cmd, 332bfbaa952SDave Jiang unsigned int buf_len, int idx) 333bfbaa952SDave Jiang { 334bfbaa952SDave Jiang struct device *dev = &t->pdev.dev; 335bfbaa952SDave Jiang struct nfit_test_fw *fw = &t->fw[idx]; 336bfbaa952SDave Jiang 337bfbaa952SDave Jiang dev_dbg(dev, "%s(nfit_test: %p nd_cmd: %p buf_len: %u idx: %d)\n", 338bfbaa952SDave Jiang __func__, t, nd_cmd, buf_len, idx); 339bfbaa952SDave Jiang 340bfbaa952SDave Jiang if (fw->state == FW_STATE_UPDATED) { 341bfbaa952SDave Jiang /* update already done, need cold boot */ 342bfbaa952SDave Jiang nd_cmd->status = 0x20007; 343bfbaa952SDave Jiang return 0; 344bfbaa952SDave Jiang } 345bfbaa952SDave Jiang 346bfbaa952SDave Jiang dev_dbg(dev, "%s: context: %#x ctrl_flags: %#x\n", 347bfbaa952SDave Jiang __func__, nd_cmd->context, nd_cmd->ctrl_flags); 348bfbaa952SDave Jiang 349bfbaa952SDave Jiang switch (nd_cmd->ctrl_flags) { 350bfbaa952SDave Jiang case 0: /* finish */ 351bfbaa952SDave Jiang if (nd_cmd->context != fw->context) { 352bfbaa952SDave Jiang dev_dbg(dev, "%s: incorrect context: in: %#x correct: %#x\n", 353bfbaa952SDave Jiang __func__, nd_cmd->context, 354bfbaa952SDave Jiang fw->context); 355bfbaa952SDave Jiang nd_cmd->status = 0x10007; 356bfbaa952SDave Jiang return 0; 357bfbaa952SDave Jiang } 358bfbaa952SDave Jiang nd_cmd->status = 0; 359bfbaa952SDave Jiang fw->state = FW_STATE_VERIFY; 360bfbaa952SDave Jiang /* set 1 second of time for firmware "update" */ 361bfbaa952SDave Jiang fw->end_time = jiffies + HZ; 362bfbaa952SDave Jiang break; 363bfbaa952SDave Jiang 364bfbaa952SDave Jiang case 1: /* abort */ 365bfbaa952SDave Jiang fw->size_received = 0; 366bfbaa952SDave Jiang /* successfully aborted status */ 367bfbaa952SDave Jiang nd_cmd->status = 0x40007; 368bfbaa952SDave Jiang fw->state = FW_STATE_NEW; 369bfbaa952SDave Jiang dev_dbg(dev, "%s: abort successful\n", __func__); 370bfbaa952SDave Jiang break; 371bfbaa952SDave Jiang 372bfbaa952SDave Jiang default: /* bad control flag */ 373bfbaa952SDave Jiang dev_warn(dev, "%s: unknown control flag: %#x\n", 374bfbaa952SDave Jiang __func__, nd_cmd->ctrl_flags); 375bfbaa952SDave Jiang return -EINVAL; 376bfbaa952SDave Jiang } 377bfbaa952SDave Jiang 378bfbaa952SDave Jiang return 0; 379bfbaa952SDave Jiang } 380bfbaa952SDave Jiang 381bfbaa952SDave Jiang static int nd_intel_test_finish_query(struct nfit_test *t, 382bfbaa952SDave Jiang struct nd_intel_fw_finish_query *nd_cmd, 383bfbaa952SDave Jiang unsigned int buf_len, int idx) 384bfbaa952SDave Jiang { 385bfbaa952SDave Jiang struct device *dev = &t->pdev.dev; 386bfbaa952SDave Jiang struct nfit_test_fw *fw = &t->fw[idx]; 387bfbaa952SDave Jiang 388bfbaa952SDave Jiang dev_dbg(dev, "%s(nfit_test: %p nd_cmd: %p buf_len: %u idx: %d)\n", 389bfbaa952SDave Jiang __func__, t, nd_cmd, buf_len, idx); 390bfbaa952SDave Jiang 391bfbaa952SDave Jiang if (buf_len < sizeof(*nd_cmd)) 392bfbaa952SDave Jiang return -EINVAL; 393bfbaa952SDave Jiang 394bfbaa952SDave Jiang if (nd_cmd->context != fw->context) { 395bfbaa952SDave Jiang dev_dbg(dev, "%s: incorrect context: in: %#x correct: %#x\n", 396bfbaa952SDave Jiang __func__, nd_cmd->context, fw->context); 397bfbaa952SDave Jiang nd_cmd->status = 0x10007; 398bfbaa952SDave Jiang return 0; 399bfbaa952SDave Jiang } 400bfbaa952SDave Jiang 401bfbaa952SDave Jiang dev_dbg(dev, "%s context: %#x\n", __func__, nd_cmd->context); 402bfbaa952SDave Jiang 403bfbaa952SDave Jiang switch (fw->state) { 404bfbaa952SDave Jiang case FW_STATE_NEW: 405bfbaa952SDave Jiang nd_cmd->updated_fw_rev = 0; 406bfbaa952SDave Jiang nd_cmd->status = 0; 407bfbaa952SDave Jiang dev_dbg(dev, "%s: new state\n", __func__); 408bfbaa952SDave Jiang break; 409bfbaa952SDave Jiang 410bfbaa952SDave Jiang case FW_STATE_IN_PROGRESS: 411bfbaa952SDave Jiang /* sequencing error */ 412bfbaa952SDave Jiang nd_cmd->status = 0x40007; 413bfbaa952SDave Jiang nd_cmd->updated_fw_rev = 0; 414bfbaa952SDave Jiang dev_dbg(dev, "%s: sequence error\n", __func__); 415bfbaa952SDave Jiang break; 416bfbaa952SDave Jiang 417bfbaa952SDave Jiang case FW_STATE_VERIFY: 418bfbaa952SDave Jiang if (time_is_after_jiffies64(fw->end_time)) { 419bfbaa952SDave Jiang nd_cmd->updated_fw_rev = 0; 420bfbaa952SDave Jiang nd_cmd->status = 0x20007; 421bfbaa952SDave Jiang dev_dbg(dev, "%s: still verifying\n", __func__); 422bfbaa952SDave Jiang break; 423bfbaa952SDave Jiang } 424bfbaa952SDave Jiang 425bfbaa952SDave Jiang dev_dbg(dev, "%s: transition out verify\n", __func__); 426bfbaa952SDave Jiang fw->state = FW_STATE_UPDATED; 427bfbaa952SDave Jiang /* we are going to fall through if it's "done" */ 428bfbaa952SDave Jiang case FW_STATE_UPDATED: 429bfbaa952SDave Jiang nd_cmd->status = 0; 430bfbaa952SDave Jiang /* bogus test version */ 431bfbaa952SDave Jiang fw->version = nd_cmd->updated_fw_rev = 432bfbaa952SDave Jiang INTEL_FW_FAKE_VERSION; 433bfbaa952SDave Jiang dev_dbg(dev, "%s: updated\n", __func__); 434bfbaa952SDave Jiang break; 435bfbaa952SDave Jiang 436bfbaa952SDave Jiang default: /* we should never get here */ 437bfbaa952SDave Jiang return -EINVAL; 438bfbaa952SDave Jiang } 439bfbaa952SDave Jiang 440bfbaa952SDave Jiang return 0; 441bfbaa952SDave Jiang } 442bfbaa952SDave Jiang 44339c686b8SVishal Verma static int nfit_test_cmd_get_config_size(struct nd_cmd_get_config_size *nd_cmd, 4446bc75619SDan Williams unsigned int buf_len) 4456bc75619SDan Williams { 4466bc75619SDan Williams if (buf_len < sizeof(*nd_cmd)) 4476bc75619SDan Williams return -EINVAL; 44839c686b8SVishal Verma 4496bc75619SDan Williams nd_cmd->status = 0; 4506bc75619SDan Williams nd_cmd->config_size = LABEL_SIZE; 4516bc75619SDan Williams nd_cmd->max_xfer = SZ_4K; 45239c686b8SVishal Verma 45339c686b8SVishal Verma return 0; 4546bc75619SDan Williams } 45539c686b8SVishal Verma 45639c686b8SVishal Verma static int nfit_test_cmd_get_config_data(struct nd_cmd_get_config_data_hdr 45739c686b8SVishal Verma *nd_cmd, unsigned int buf_len, void *label) 45839c686b8SVishal Verma { 4596bc75619SDan Williams unsigned int len, offset = nd_cmd->in_offset; 46039c686b8SVishal Verma int rc; 4616bc75619SDan Williams 4626bc75619SDan Williams if (buf_len < sizeof(*nd_cmd)) 4636bc75619SDan Williams return -EINVAL; 4646bc75619SDan Williams if (offset >= LABEL_SIZE) 4656bc75619SDan Williams return -EINVAL; 4666bc75619SDan Williams if (nd_cmd->in_length + sizeof(*nd_cmd) > buf_len) 4676bc75619SDan Williams return -EINVAL; 4686bc75619SDan Williams 4696bc75619SDan Williams nd_cmd->status = 0; 4706bc75619SDan Williams len = min(nd_cmd->in_length, LABEL_SIZE - offset); 47139c686b8SVishal Verma memcpy(nd_cmd->out_buf, label + offset, len); 4726bc75619SDan Williams rc = buf_len - sizeof(*nd_cmd) - len; 47339c686b8SVishal Verma 47439c686b8SVishal Verma return rc; 4756bc75619SDan Williams } 47639c686b8SVishal Verma 47739c686b8SVishal Verma static int nfit_test_cmd_set_config_data(struct nd_cmd_set_config_hdr *nd_cmd, 47839c686b8SVishal Verma unsigned int buf_len, void *label) 47939c686b8SVishal Verma { 4806bc75619SDan Williams unsigned int len, offset = nd_cmd->in_offset; 4816bc75619SDan Williams u32 *status; 48239c686b8SVishal Verma int rc; 4836bc75619SDan Williams 4846bc75619SDan Williams if (buf_len < sizeof(*nd_cmd)) 4856bc75619SDan Williams return -EINVAL; 4866bc75619SDan Williams if (offset >= LABEL_SIZE) 4876bc75619SDan Williams return -EINVAL; 4886bc75619SDan Williams if (nd_cmd->in_length + sizeof(*nd_cmd) + 4 > buf_len) 4896bc75619SDan Williams return -EINVAL; 4906bc75619SDan Williams 49139c686b8SVishal Verma status = (void *)nd_cmd + nd_cmd->in_length + sizeof(*nd_cmd); 4926bc75619SDan Williams *status = 0; 4936bc75619SDan Williams len = min(nd_cmd->in_length, LABEL_SIZE - offset); 49439c686b8SVishal Verma memcpy(label + offset, nd_cmd->in_buf, len); 4956bc75619SDan Williams rc = buf_len - sizeof(*nd_cmd) - (len + 4); 49639c686b8SVishal Verma 49739c686b8SVishal Verma return rc; 4986bc75619SDan Williams } 49939c686b8SVishal Verma 500d4f32367SDan Williams #define NFIT_TEST_CLEAR_ERR_UNIT 256 501747ffe11SDan Williams 50239c686b8SVishal Verma static int nfit_test_cmd_ars_cap(struct nd_cmd_ars_cap *nd_cmd, 50339c686b8SVishal Verma unsigned int buf_len) 50439c686b8SVishal Verma { 5059fb1a190SDave Jiang int ars_recs; 5069fb1a190SDave Jiang 50739c686b8SVishal Verma if (buf_len < sizeof(*nd_cmd)) 50839c686b8SVishal Verma return -EINVAL; 50939c686b8SVishal Verma 5109fb1a190SDave Jiang /* for testing, only store up to n records that fit within 4k */ 5119fb1a190SDave Jiang ars_recs = SZ_4K / sizeof(struct nd_ars_record); 5129fb1a190SDave Jiang 513747ffe11SDan Williams nd_cmd->max_ars_out = sizeof(struct nd_cmd_ars_status) 5149fb1a190SDave Jiang + ars_recs * sizeof(struct nd_ars_record); 51539c686b8SVishal Verma nd_cmd->status = (ND_ARS_PERSISTENT | ND_ARS_VOLATILE) << 16; 516d4f32367SDan Williams nd_cmd->clear_err_unit = NFIT_TEST_CLEAR_ERR_UNIT; 51739c686b8SVishal Verma 51839c686b8SVishal Verma return 0; 51939c686b8SVishal Verma } 52039c686b8SVishal Verma 5219fb1a190SDave Jiang static void post_ars_status(struct ars_state *ars_state, 5229fb1a190SDave Jiang struct badrange *badrange, u64 addr, u64 len) 52339c686b8SVishal Verma { 524f471f1a7SDan Williams struct nd_cmd_ars_status *ars_status; 525f471f1a7SDan Williams struct nd_ars_record *ars_record; 5269fb1a190SDave Jiang struct badrange_entry *be; 5279fb1a190SDave Jiang u64 end = addr + len - 1; 5289fb1a190SDave Jiang int i = 0; 529f471f1a7SDan Williams 530f471f1a7SDan Williams ars_state->deadline = jiffies + 1*HZ; 531f471f1a7SDan Williams ars_status = ars_state->ars_status; 532f471f1a7SDan Williams ars_status->status = 0; 533f471f1a7SDan Williams ars_status->address = addr; 534f471f1a7SDan Williams ars_status->length = len; 535f471f1a7SDan Williams ars_status->type = ND_ARS_PERSISTENT; 5369fb1a190SDave Jiang 5379fb1a190SDave Jiang spin_lock(&badrange->lock); 5389fb1a190SDave Jiang list_for_each_entry(be, &badrange->list, list) { 5399fb1a190SDave Jiang u64 be_end = be->start + be->length - 1; 5409fb1a190SDave Jiang u64 rstart, rend; 5419fb1a190SDave Jiang 5429fb1a190SDave Jiang /* skip entries outside the range */ 5439fb1a190SDave Jiang if (be_end < addr || be->start > end) 5449fb1a190SDave Jiang continue; 5459fb1a190SDave Jiang 5469fb1a190SDave Jiang rstart = (be->start < addr) ? addr : be->start; 5479fb1a190SDave Jiang rend = (be_end < end) ? be_end : end; 5489fb1a190SDave Jiang ars_record = &ars_status->records[i]; 549f471f1a7SDan Williams ars_record->handle = 0; 5509fb1a190SDave Jiang ars_record->err_address = rstart; 5519fb1a190SDave Jiang ars_record->length = rend - rstart + 1; 5529fb1a190SDave Jiang i++; 5539fb1a190SDave Jiang } 5549fb1a190SDave Jiang spin_unlock(&badrange->lock); 5559fb1a190SDave Jiang ars_status->num_records = i; 5569fb1a190SDave Jiang ars_status->out_length = sizeof(struct nd_cmd_ars_status) 5579fb1a190SDave Jiang + i * sizeof(struct nd_ars_record); 558f471f1a7SDan Williams } 559f471f1a7SDan Williams 5609fb1a190SDave Jiang static int nfit_test_cmd_ars_start(struct nfit_test *t, 5619fb1a190SDave Jiang struct ars_state *ars_state, 562f471f1a7SDan Williams struct nd_cmd_ars_start *ars_start, unsigned int buf_len, 563f471f1a7SDan Williams int *cmd_rc) 564f471f1a7SDan Williams { 565f471f1a7SDan Williams if (buf_len < sizeof(*ars_start)) 56639c686b8SVishal Verma return -EINVAL; 56739c686b8SVishal Verma 568f471f1a7SDan Williams spin_lock(&ars_state->lock); 569f471f1a7SDan Williams if (time_before(jiffies, ars_state->deadline)) { 570f471f1a7SDan Williams ars_start->status = NFIT_ARS_START_BUSY; 571f471f1a7SDan Williams *cmd_rc = -EBUSY; 572f471f1a7SDan Williams } else { 573f471f1a7SDan Williams ars_start->status = 0; 574f471f1a7SDan Williams ars_start->scrub_time = 1; 5759fb1a190SDave Jiang post_ars_status(ars_state, &t->badrange, ars_start->address, 576f471f1a7SDan Williams ars_start->length); 577f471f1a7SDan Williams *cmd_rc = 0; 578f471f1a7SDan Williams } 579f471f1a7SDan Williams spin_unlock(&ars_state->lock); 58039c686b8SVishal Verma 58139c686b8SVishal Verma return 0; 58239c686b8SVishal Verma } 58339c686b8SVishal Verma 584f471f1a7SDan Williams static int nfit_test_cmd_ars_status(struct ars_state *ars_state, 585f471f1a7SDan Williams struct nd_cmd_ars_status *ars_status, unsigned int buf_len, 586f471f1a7SDan Williams int *cmd_rc) 58739c686b8SVishal Verma { 588f471f1a7SDan Williams if (buf_len < ars_state->ars_status->out_length) 58939c686b8SVishal Verma return -EINVAL; 59039c686b8SVishal Verma 591f471f1a7SDan Williams spin_lock(&ars_state->lock); 592f471f1a7SDan Williams if (time_before(jiffies, ars_state->deadline)) { 593f471f1a7SDan Williams memset(ars_status, 0, buf_len); 594f471f1a7SDan Williams ars_status->status = NFIT_ARS_STATUS_BUSY; 595f471f1a7SDan Williams ars_status->out_length = sizeof(*ars_status); 596f471f1a7SDan Williams *cmd_rc = -EBUSY; 597f471f1a7SDan Williams } else { 598f471f1a7SDan Williams memcpy(ars_status, ars_state->ars_status, 599f471f1a7SDan Williams ars_state->ars_status->out_length); 600f471f1a7SDan Williams *cmd_rc = 0; 601f471f1a7SDan Williams } 602f471f1a7SDan Williams spin_unlock(&ars_state->lock); 60339c686b8SVishal Verma return 0; 60439c686b8SVishal Verma } 60539c686b8SVishal Verma 6065e096ef3SVishal Verma static int nfit_test_cmd_clear_error(struct nfit_test *t, 6075e096ef3SVishal Verma struct nd_cmd_clear_error *clear_err, 608d4f32367SDan Williams unsigned int buf_len, int *cmd_rc) 609d4f32367SDan Williams { 610d4f32367SDan Williams const u64 mask = NFIT_TEST_CLEAR_ERR_UNIT - 1; 611d4f32367SDan Williams if (buf_len < sizeof(*clear_err)) 612d4f32367SDan Williams return -EINVAL; 613d4f32367SDan Williams 614d4f32367SDan Williams if ((clear_err->address & mask) || (clear_err->length & mask)) 615d4f32367SDan Williams return -EINVAL; 616d4f32367SDan Williams 6175e096ef3SVishal Verma badrange_forget(&t->badrange, clear_err->address, clear_err->length); 618d4f32367SDan Williams clear_err->status = 0; 619d4f32367SDan Williams clear_err->cleared = clear_err->length; 620d4f32367SDan Williams *cmd_rc = 0; 621d4f32367SDan Williams return 0; 622d4f32367SDan Williams } 623d4f32367SDan Williams 62410246dc8SYasunori Goto struct region_search_spa { 62510246dc8SYasunori Goto u64 addr; 62610246dc8SYasunori Goto struct nd_region *region; 62710246dc8SYasunori Goto }; 62810246dc8SYasunori Goto 62910246dc8SYasunori Goto static int is_region_device(struct device *dev) 63010246dc8SYasunori Goto { 63110246dc8SYasunori Goto return !strncmp(dev->kobj.name, "region", 6); 63210246dc8SYasunori Goto } 63310246dc8SYasunori Goto 63410246dc8SYasunori Goto static int nfit_test_search_region_spa(struct device *dev, void *data) 63510246dc8SYasunori Goto { 63610246dc8SYasunori Goto struct region_search_spa *ctx = data; 63710246dc8SYasunori Goto struct nd_region *nd_region; 63810246dc8SYasunori Goto resource_size_t ndr_end; 63910246dc8SYasunori Goto 64010246dc8SYasunori Goto if (!is_region_device(dev)) 64110246dc8SYasunori Goto return 0; 64210246dc8SYasunori Goto 64310246dc8SYasunori Goto nd_region = to_nd_region(dev); 64410246dc8SYasunori Goto ndr_end = nd_region->ndr_start + nd_region->ndr_size; 64510246dc8SYasunori Goto 64610246dc8SYasunori Goto if (ctx->addr >= nd_region->ndr_start && ctx->addr < ndr_end) { 64710246dc8SYasunori Goto ctx->region = nd_region; 64810246dc8SYasunori Goto return 1; 64910246dc8SYasunori Goto } 65010246dc8SYasunori Goto 65110246dc8SYasunori Goto return 0; 65210246dc8SYasunori Goto } 65310246dc8SYasunori Goto 65410246dc8SYasunori Goto static int nfit_test_search_spa(struct nvdimm_bus *bus, 65510246dc8SYasunori Goto struct nd_cmd_translate_spa *spa) 65610246dc8SYasunori Goto { 65710246dc8SYasunori Goto int ret; 65810246dc8SYasunori Goto struct nd_region *nd_region = NULL; 65910246dc8SYasunori Goto struct nvdimm *nvdimm = NULL; 66010246dc8SYasunori Goto struct nd_mapping *nd_mapping = NULL; 66110246dc8SYasunori Goto struct region_search_spa ctx = { 66210246dc8SYasunori Goto .addr = spa->spa, 66310246dc8SYasunori Goto .region = NULL, 66410246dc8SYasunori Goto }; 66510246dc8SYasunori Goto u64 dpa; 66610246dc8SYasunori Goto 66710246dc8SYasunori Goto ret = device_for_each_child(&bus->dev, &ctx, 66810246dc8SYasunori Goto nfit_test_search_region_spa); 66910246dc8SYasunori Goto 67010246dc8SYasunori Goto if (!ret) 67110246dc8SYasunori Goto return -ENODEV; 67210246dc8SYasunori Goto 67310246dc8SYasunori Goto nd_region = ctx.region; 67410246dc8SYasunori Goto 67510246dc8SYasunori Goto dpa = ctx.addr - nd_region->ndr_start; 67610246dc8SYasunori Goto 67710246dc8SYasunori Goto /* 67810246dc8SYasunori Goto * last dimm is selected for test 67910246dc8SYasunori Goto */ 68010246dc8SYasunori Goto nd_mapping = &nd_region->mapping[nd_region->ndr_mappings - 1]; 68110246dc8SYasunori Goto nvdimm = nd_mapping->nvdimm; 68210246dc8SYasunori Goto 68310246dc8SYasunori Goto spa->devices[0].nfit_device_handle = handle[nvdimm->id]; 68410246dc8SYasunori Goto spa->num_nvdimms = 1; 68510246dc8SYasunori Goto spa->devices[0].dpa = dpa; 68610246dc8SYasunori Goto 68710246dc8SYasunori Goto return 0; 68810246dc8SYasunori Goto } 68910246dc8SYasunori Goto 69010246dc8SYasunori Goto static int nfit_test_cmd_translate_spa(struct nvdimm_bus *bus, 69110246dc8SYasunori Goto struct nd_cmd_translate_spa *spa, unsigned int buf_len) 69210246dc8SYasunori Goto { 69310246dc8SYasunori Goto if (buf_len < spa->translate_length) 69410246dc8SYasunori Goto return -EINVAL; 69510246dc8SYasunori Goto 69610246dc8SYasunori Goto if (nfit_test_search_spa(bus, spa) < 0 || !spa->num_nvdimms) 69710246dc8SYasunori Goto spa->status = 2; 69810246dc8SYasunori Goto 69910246dc8SYasunori Goto return 0; 70010246dc8SYasunori Goto } 70110246dc8SYasunori Goto 702ed07c433SDan Williams static int nfit_test_cmd_smart(struct nd_intel_smart *smart, unsigned int buf_len, 703ed07c433SDan Williams struct nd_intel_smart *smart_data) 704baa51277SDan Williams { 705baa51277SDan Williams if (buf_len < sizeof(*smart)) 706baa51277SDan Williams return -EINVAL; 707ed07c433SDan Williams memcpy(smart, smart_data, sizeof(*smart)); 708baa51277SDan Williams return 0; 709baa51277SDan Williams } 710baa51277SDan Williams 711cdd77d3eSDan Williams static int nfit_test_cmd_smart_threshold( 712ed07c433SDan Williams struct nd_intel_smart_threshold *out, 713ed07c433SDan Williams unsigned int buf_len, 714ed07c433SDan Williams struct nd_intel_smart_threshold *smart_t) 715baa51277SDan Williams { 716baa51277SDan Williams if (buf_len < sizeof(*smart_t)) 717baa51277SDan Williams return -EINVAL; 718ed07c433SDan Williams memcpy(out, smart_t, sizeof(*smart_t)); 719ed07c433SDan Williams return 0; 720ed07c433SDan Williams } 721ed07c433SDan Williams 722ed07c433SDan Williams static void smart_notify(struct device *bus_dev, 723ed07c433SDan Williams struct device *dimm_dev, struct nd_intel_smart *smart, 724ed07c433SDan Williams struct nd_intel_smart_threshold *thresh) 725ed07c433SDan Williams { 726ed07c433SDan Williams dev_dbg(dimm_dev, "%s: alarm: %#x spares: %d (%d) mtemp: %d (%d) ctemp: %d (%d)\n", 727ed07c433SDan Williams __func__, thresh->alarm_control, thresh->spares, 728ed07c433SDan Williams smart->spares, thresh->media_temperature, 729ed07c433SDan Williams smart->media_temperature, thresh->ctrl_temperature, 730ed07c433SDan Williams smart->ctrl_temperature); 731ed07c433SDan Williams if (((thresh->alarm_control & ND_INTEL_SMART_SPARE_TRIP) 732ed07c433SDan Williams && smart->spares 733ed07c433SDan Williams <= thresh->spares) 734ed07c433SDan Williams || ((thresh->alarm_control & ND_INTEL_SMART_TEMP_TRIP) 735ed07c433SDan Williams && smart->media_temperature 736ed07c433SDan Williams >= thresh->media_temperature) 737ed07c433SDan Williams || ((thresh->alarm_control & ND_INTEL_SMART_CTEMP_TRIP) 738ed07c433SDan Williams && smart->ctrl_temperature 7394cf260fcSVishal Verma >= thresh->ctrl_temperature) 7404cf260fcSVishal Verma || (smart->health != ND_INTEL_SMART_NON_CRITICAL_HEALTH) 7414cf260fcSVishal Verma || (smart->shutdown_state != 0)) { 742ed07c433SDan Williams device_lock(bus_dev); 743ed07c433SDan Williams __acpi_nvdimm_notify(dimm_dev, 0x81); 744ed07c433SDan Williams device_unlock(bus_dev); 745ed07c433SDan Williams } 746ed07c433SDan Williams } 747ed07c433SDan Williams 748ed07c433SDan Williams static int nfit_test_cmd_smart_set_threshold( 749ed07c433SDan Williams struct nd_intel_smart_set_threshold *in, 750ed07c433SDan Williams unsigned int buf_len, 751ed07c433SDan Williams struct nd_intel_smart_threshold *thresh, 752ed07c433SDan Williams struct nd_intel_smart *smart, 753ed07c433SDan Williams struct device *bus_dev, struct device *dimm_dev) 754ed07c433SDan Williams { 755ed07c433SDan Williams unsigned int size; 756ed07c433SDan Williams 757ed07c433SDan Williams size = sizeof(*in) - 4; 758ed07c433SDan Williams if (buf_len < size) 759ed07c433SDan Williams return -EINVAL; 760ed07c433SDan Williams memcpy(thresh->data, in, size); 761ed07c433SDan Williams in->status = 0; 762ed07c433SDan Williams smart_notify(bus_dev, dimm_dev, smart, thresh); 763ed07c433SDan Williams 764baa51277SDan Williams return 0; 765baa51277SDan Williams } 766baa51277SDan Williams 7674cf260fcSVishal Verma static int nfit_test_cmd_smart_inject( 7684cf260fcSVishal Verma struct nd_intel_smart_inject *inj, 7694cf260fcSVishal Verma unsigned int buf_len, 7704cf260fcSVishal Verma struct nd_intel_smart_threshold *thresh, 7714cf260fcSVishal Verma struct nd_intel_smart *smart, 7724cf260fcSVishal Verma struct device *bus_dev, struct device *dimm_dev) 7734cf260fcSVishal Verma { 7744cf260fcSVishal Verma if (buf_len != sizeof(*inj)) 7754cf260fcSVishal Verma return -EINVAL; 7764cf260fcSVishal Verma 777*b4d4702fSVishal Verma if (inj->flags & ND_INTEL_SMART_INJECT_MTEMP) { 7784cf260fcSVishal Verma if (inj->mtemp_enable) 7794cf260fcSVishal Verma smart->media_temperature = inj->media_temperature; 780*b4d4702fSVishal Verma else 781*b4d4702fSVishal Verma smart->media_temperature = smart_def.media_temperature; 782*b4d4702fSVishal Verma } 783*b4d4702fSVishal Verma if (inj->flags & ND_INTEL_SMART_INJECT_SPARE) { 7844cf260fcSVishal Verma if (inj->spare_enable) 7854cf260fcSVishal Verma smart->spares = inj->spares; 786*b4d4702fSVishal Verma else 787*b4d4702fSVishal Verma smart->spares = smart_def.spares; 788*b4d4702fSVishal Verma } 789*b4d4702fSVishal Verma if (inj->flags & ND_INTEL_SMART_INJECT_FATAL) { 7904cf260fcSVishal Verma if (inj->fatal_enable) 7914cf260fcSVishal Verma smart->health = ND_INTEL_SMART_FATAL_HEALTH; 792*b4d4702fSVishal Verma else 793*b4d4702fSVishal Verma smart->health = ND_INTEL_SMART_NON_CRITICAL_HEALTH; 794*b4d4702fSVishal Verma } 795*b4d4702fSVishal Verma if (inj->flags & ND_INTEL_SMART_INJECT_SHUTDOWN) { 7964cf260fcSVishal Verma if (inj->unsafe_shutdown_enable) { 7974cf260fcSVishal Verma smart->shutdown_state = 1; 7984cf260fcSVishal Verma smart->shutdown_count++; 799*b4d4702fSVishal Verma } else 800*b4d4702fSVishal Verma smart->shutdown_state = 0; 8014cf260fcSVishal Verma } 8024cf260fcSVishal Verma inj->status = 0; 8034cf260fcSVishal Verma smart_notify(bus_dev, dimm_dev, smart, thresh); 8044cf260fcSVishal Verma 8054cf260fcSVishal Verma return 0; 8064cf260fcSVishal Verma } 8074cf260fcSVishal Verma 8089fb1a190SDave Jiang static void uc_error_notify(struct work_struct *work) 8099fb1a190SDave Jiang { 8109fb1a190SDave Jiang struct nfit_test *t = container_of(work, typeof(*t), work); 8119fb1a190SDave Jiang 8129fb1a190SDave Jiang __acpi_nfit_notify(&t->pdev.dev, t, NFIT_NOTIFY_UC_MEMORY_ERROR); 8139fb1a190SDave Jiang } 8149fb1a190SDave Jiang 8159fb1a190SDave Jiang static int nfit_test_cmd_ars_error_inject(struct nfit_test *t, 8169fb1a190SDave Jiang struct nd_cmd_ars_err_inj *err_inj, unsigned int buf_len) 8179fb1a190SDave Jiang { 8189fb1a190SDave Jiang int rc; 8199fb1a190SDave Jiang 82041cb3301SVishal Verma if (buf_len != sizeof(*err_inj)) { 8219fb1a190SDave Jiang rc = -EINVAL; 8229fb1a190SDave Jiang goto err; 8239fb1a190SDave Jiang } 8249fb1a190SDave Jiang 8259fb1a190SDave Jiang if (err_inj->err_inj_spa_range_length <= 0) { 8269fb1a190SDave Jiang rc = -EINVAL; 8279fb1a190SDave Jiang goto err; 8289fb1a190SDave Jiang } 8299fb1a190SDave Jiang 8309fb1a190SDave Jiang rc = badrange_add(&t->badrange, err_inj->err_inj_spa_range_base, 8319fb1a190SDave Jiang err_inj->err_inj_spa_range_length); 8329fb1a190SDave Jiang if (rc < 0) 8339fb1a190SDave Jiang goto err; 8349fb1a190SDave Jiang 8359fb1a190SDave Jiang if (err_inj->err_inj_options & (1 << ND_ARS_ERR_INJ_OPT_NOTIFY)) 8369fb1a190SDave Jiang queue_work(nfit_wq, &t->work); 8379fb1a190SDave Jiang 8389fb1a190SDave Jiang err_inj->status = 0; 8399fb1a190SDave Jiang return 0; 8409fb1a190SDave Jiang 8419fb1a190SDave Jiang err: 8429fb1a190SDave Jiang err_inj->status = NFIT_ARS_INJECT_INVALID; 8439fb1a190SDave Jiang return rc; 8449fb1a190SDave Jiang } 8459fb1a190SDave Jiang 8469fb1a190SDave Jiang static int nfit_test_cmd_ars_inject_clear(struct nfit_test *t, 8479fb1a190SDave Jiang struct nd_cmd_ars_err_inj_clr *err_clr, unsigned int buf_len) 8489fb1a190SDave Jiang { 8499fb1a190SDave Jiang int rc; 8509fb1a190SDave Jiang 85141cb3301SVishal Verma if (buf_len != sizeof(*err_clr)) { 8529fb1a190SDave Jiang rc = -EINVAL; 8539fb1a190SDave Jiang goto err; 8549fb1a190SDave Jiang } 8559fb1a190SDave Jiang 8569fb1a190SDave Jiang if (err_clr->err_inj_clr_spa_range_length <= 0) { 8579fb1a190SDave Jiang rc = -EINVAL; 8589fb1a190SDave Jiang goto err; 8599fb1a190SDave Jiang } 8609fb1a190SDave Jiang 8619fb1a190SDave Jiang badrange_forget(&t->badrange, err_clr->err_inj_clr_spa_range_base, 8629fb1a190SDave Jiang err_clr->err_inj_clr_spa_range_length); 8639fb1a190SDave Jiang 8649fb1a190SDave Jiang err_clr->status = 0; 8659fb1a190SDave Jiang return 0; 8669fb1a190SDave Jiang 8679fb1a190SDave Jiang err: 8689fb1a190SDave Jiang err_clr->status = NFIT_ARS_INJECT_INVALID; 8699fb1a190SDave Jiang return rc; 8709fb1a190SDave Jiang } 8719fb1a190SDave Jiang 8729fb1a190SDave Jiang static int nfit_test_cmd_ars_inject_status(struct nfit_test *t, 8739fb1a190SDave Jiang struct nd_cmd_ars_err_inj_stat *err_stat, 8749fb1a190SDave Jiang unsigned int buf_len) 8759fb1a190SDave Jiang { 8769fb1a190SDave Jiang struct badrange_entry *be; 8779fb1a190SDave Jiang int max = SZ_4K / sizeof(struct nd_error_stat_query_record); 8789fb1a190SDave Jiang int i = 0; 8799fb1a190SDave Jiang 8809fb1a190SDave Jiang err_stat->status = 0; 8819fb1a190SDave Jiang spin_lock(&t->badrange.lock); 8829fb1a190SDave Jiang list_for_each_entry(be, &t->badrange.list, list) { 8839fb1a190SDave Jiang err_stat->record[i].err_inj_stat_spa_range_base = be->start; 8849fb1a190SDave Jiang err_stat->record[i].err_inj_stat_spa_range_length = be->length; 8859fb1a190SDave Jiang i++; 8869fb1a190SDave Jiang if (i > max) 8879fb1a190SDave Jiang break; 8889fb1a190SDave Jiang } 8899fb1a190SDave Jiang spin_unlock(&t->badrange.lock); 8909fb1a190SDave Jiang err_stat->inj_err_rec_count = i; 8919fb1a190SDave Jiang 8929fb1a190SDave Jiang return 0; 8939fb1a190SDave Jiang } 8949fb1a190SDave Jiang 895674d8bdeSDave Jiang static int nd_intel_test_cmd_set_lss_status(struct nfit_test *t, 896674d8bdeSDave Jiang struct nd_intel_lss *nd_cmd, unsigned int buf_len) 897674d8bdeSDave Jiang { 898674d8bdeSDave Jiang struct device *dev = &t->pdev.dev; 899674d8bdeSDave Jiang 900674d8bdeSDave Jiang if (buf_len < sizeof(*nd_cmd)) 901674d8bdeSDave Jiang return -EINVAL; 902674d8bdeSDave Jiang 903674d8bdeSDave Jiang switch (nd_cmd->enable) { 904674d8bdeSDave Jiang case 0: 905674d8bdeSDave Jiang nd_cmd->status = 0; 906674d8bdeSDave Jiang dev_dbg(dev, "%s: Latch System Shutdown Status disabled\n", 907674d8bdeSDave Jiang __func__); 908674d8bdeSDave Jiang break; 909674d8bdeSDave Jiang case 1: 910674d8bdeSDave Jiang nd_cmd->status = 0; 911674d8bdeSDave Jiang dev_dbg(dev, "%s: Latch System Shutdown Status enabled\n", 912674d8bdeSDave Jiang __func__); 913674d8bdeSDave Jiang break; 914674d8bdeSDave Jiang default: 915674d8bdeSDave Jiang dev_warn(dev, "Unknown enable value: %#x\n", nd_cmd->enable); 916674d8bdeSDave Jiang nd_cmd->status = 0x3; 917674d8bdeSDave Jiang break; 918674d8bdeSDave Jiang } 919674d8bdeSDave Jiang 920674d8bdeSDave Jiang 921674d8bdeSDave Jiang return 0; 922674d8bdeSDave Jiang } 923674d8bdeSDave Jiang 92439611e83SDan Williams static int override_return_code(int dimm, unsigned int func, int rc) 92539611e83SDan Williams { 92639611e83SDan Williams if ((1 << func) & dimm_fail_cmd_flags[dimm]) { 92739611e83SDan Williams if (dimm_fail_cmd_code[dimm]) 92839611e83SDan Williams return dimm_fail_cmd_code[dimm]; 92939611e83SDan Williams return -EIO; 93039611e83SDan Williams } 93139611e83SDan Williams return rc; 93239611e83SDan Williams } 93339611e83SDan Williams 934bfbaa952SDave Jiang static int get_dimm(struct nfit_mem *nfit_mem, unsigned int func) 935bfbaa952SDave Jiang { 936bfbaa952SDave Jiang int i; 937bfbaa952SDave Jiang 938bfbaa952SDave Jiang /* lookup per-dimm data */ 939bfbaa952SDave Jiang for (i = 0; i < ARRAY_SIZE(handle); i++) 940bfbaa952SDave Jiang if (__to_nfit_memdev(nfit_mem)->device_handle == handle[i]) 941bfbaa952SDave Jiang break; 942bfbaa952SDave Jiang if (i >= ARRAY_SIZE(handle)) 943bfbaa952SDave Jiang return -ENXIO; 944bfbaa952SDave Jiang return i; 945bfbaa952SDave Jiang } 946bfbaa952SDave Jiang 94739c686b8SVishal Verma static int nfit_test_ctl(struct nvdimm_bus_descriptor *nd_desc, 94839c686b8SVishal Verma struct nvdimm *nvdimm, unsigned int cmd, void *buf, 949aef25338SDan Williams unsigned int buf_len, int *cmd_rc) 95039c686b8SVishal Verma { 95139c686b8SVishal Verma struct acpi_nfit_desc *acpi_desc = to_acpi_desc(nd_desc); 95239c686b8SVishal Verma struct nfit_test *t = container_of(acpi_desc, typeof(*t), acpi_desc); 9536634fb06SDan Williams unsigned int func = cmd; 954f471f1a7SDan Williams int i, rc = 0, __cmd_rc; 955f471f1a7SDan Williams 956f471f1a7SDan Williams if (!cmd_rc) 957f471f1a7SDan Williams cmd_rc = &__cmd_rc; 958f471f1a7SDan Williams *cmd_rc = 0; 95939c686b8SVishal Verma 96039c686b8SVishal Verma if (nvdimm) { 96139c686b8SVishal Verma struct nfit_mem *nfit_mem = nvdimm_provider_data(nvdimm); 962e3654ecaSDan Williams unsigned long cmd_mask = nvdimm_cmd_mask(nvdimm); 96339c686b8SVishal Verma 9646634fb06SDan Williams if (!nfit_mem) 9656634fb06SDan Williams return -ENOTTY; 9666634fb06SDan Williams 9676634fb06SDan Williams if (cmd == ND_CMD_CALL) { 9686634fb06SDan Williams struct nd_cmd_pkg *call_pkg = buf; 9696634fb06SDan Williams 9706634fb06SDan Williams buf_len = call_pkg->nd_size_in + call_pkg->nd_size_out; 9716634fb06SDan Williams buf = (void *) call_pkg->nd_payload; 9726634fb06SDan Williams func = call_pkg->nd_command; 9736634fb06SDan Williams if (call_pkg->nd_family != nfit_mem->family) 9746634fb06SDan Williams return -ENOTTY; 975bfbaa952SDave Jiang 976bfbaa952SDave Jiang i = get_dimm(nfit_mem, func); 977bfbaa952SDave Jiang if (i < 0) 978bfbaa952SDave Jiang return i; 979bfbaa952SDave Jiang 980bfbaa952SDave Jiang switch (func) { 981674d8bdeSDave Jiang case ND_INTEL_ENABLE_LSS_STATUS: 98239611e83SDan Williams rc = nd_intel_test_cmd_set_lss_status(t, 983674d8bdeSDave Jiang buf, buf_len); 98439611e83SDan Williams break; 985bfbaa952SDave Jiang case ND_INTEL_FW_GET_INFO: 98639611e83SDan Williams rc = nd_intel_test_get_fw_info(t, buf, 987bfbaa952SDave Jiang buf_len, i - t->dcr_idx); 98839611e83SDan Williams break; 989bfbaa952SDave Jiang case ND_INTEL_FW_START_UPDATE: 99039611e83SDan Williams rc = nd_intel_test_start_update(t, buf, 991bfbaa952SDave Jiang buf_len, i - t->dcr_idx); 99239611e83SDan Williams break; 993bfbaa952SDave Jiang case ND_INTEL_FW_SEND_DATA: 99439611e83SDan Williams rc = nd_intel_test_send_data(t, buf, 995bfbaa952SDave Jiang buf_len, i - t->dcr_idx); 99639611e83SDan Williams break; 997bfbaa952SDave Jiang case ND_INTEL_FW_FINISH_UPDATE: 99839611e83SDan Williams rc = nd_intel_test_finish_fw(t, buf, 999bfbaa952SDave Jiang buf_len, i - t->dcr_idx); 100039611e83SDan Williams break; 1001bfbaa952SDave Jiang case ND_INTEL_FW_FINISH_QUERY: 100239611e83SDan Williams rc = nd_intel_test_finish_query(t, buf, 1003bfbaa952SDave Jiang buf_len, i - t->dcr_idx); 100439611e83SDan Williams break; 1005bfbaa952SDave Jiang case ND_INTEL_SMART: 100639611e83SDan Williams rc = nfit_test_cmd_smart(buf, buf_len, 1007bfbaa952SDave Jiang &t->smart[i - t->dcr_idx]); 100839611e83SDan Williams break; 1009bfbaa952SDave Jiang case ND_INTEL_SMART_THRESHOLD: 101039611e83SDan Williams rc = nfit_test_cmd_smart_threshold(buf, 1011bfbaa952SDave Jiang buf_len, 1012bfbaa952SDave Jiang &t->smart_threshold[i - 1013bfbaa952SDave Jiang t->dcr_idx]); 101439611e83SDan Williams break; 1015bfbaa952SDave Jiang case ND_INTEL_SMART_SET_THRESHOLD: 101639611e83SDan Williams rc = nfit_test_cmd_smart_set_threshold(buf, 1017bfbaa952SDave Jiang buf_len, 1018bfbaa952SDave Jiang &t->smart_threshold[i - 1019bfbaa952SDave Jiang t->dcr_idx], 1020bfbaa952SDave Jiang &t->smart[i - t->dcr_idx], 1021bfbaa952SDave Jiang &t->pdev.dev, t->dimm_dev[i]); 102239611e83SDan Williams break; 10234cf260fcSVishal Verma case ND_INTEL_SMART_INJECT: 102439611e83SDan Williams rc = nfit_test_cmd_smart_inject(buf, 10254cf260fcSVishal Verma buf_len, 10264cf260fcSVishal Verma &t->smart_threshold[i - 10274cf260fcSVishal Verma t->dcr_idx], 10284cf260fcSVishal Verma &t->smart[i - t->dcr_idx], 10294cf260fcSVishal Verma &t->pdev.dev, t->dimm_dev[i]); 103039611e83SDan Williams break; 1031bfbaa952SDave Jiang default: 1032bfbaa952SDave Jiang return -ENOTTY; 1033bfbaa952SDave Jiang } 103439611e83SDan Williams return override_return_code(i, func, rc); 10356634fb06SDan Williams } 10366634fb06SDan Williams 10376634fb06SDan Williams if (!test_bit(cmd, &cmd_mask) 10386634fb06SDan Williams || !test_bit(func, &nfit_mem->dsm_mask)) 103939c686b8SVishal Verma return -ENOTTY; 104039c686b8SVishal Verma 1041bfbaa952SDave Jiang i = get_dimm(nfit_mem, func); 1042bfbaa952SDave Jiang if (i < 0) 1043bfbaa952SDave Jiang return i; 104473606afdSDan Williams 10456634fb06SDan Williams switch (func) { 104639c686b8SVishal Verma case ND_CMD_GET_CONFIG_SIZE: 104739c686b8SVishal Verma rc = nfit_test_cmd_get_config_size(buf, buf_len); 104839c686b8SVishal Verma break; 104939c686b8SVishal Verma case ND_CMD_GET_CONFIG_DATA: 105039c686b8SVishal Verma rc = nfit_test_cmd_get_config_data(buf, buf_len, 1051dafb1048SDan Williams t->label[i - t->dcr_idx]); 105239c686b8SVishal Verma break; 105339c686b8SVishal Verma case ND_CMD_SET_CONFIG_DATA: 105439c686b8SVishal Verma rc = nfit_test_cmd_set_config_data(buf, buf_len, 1055dafb1048SDan Williams t->label[i - t->dcr_idx]); 105639c686b8SVishal Verma break; 10576bc75619SDan Williams default: 10586bc75619SDan Williams return -ENOTTY; 10596bc75619SDan Williams } 106039611e83SDan Williams return override_return_code(i, func, rc); 106139c686b8SVishal Verma } else { 1062f471f1a7SDan Williams struct ars_state *ars_state = &t->ars_state; 106310246dc8SYasunori Goto struct nd_cmd_pkg *call_pkg = buf; 106410246dc8SYasunori Goto 106510246dc8SYasunori Goto if (!nd_desc) 106610246dc8SYasunori Goto return -ENOTTY; 106710246dc8SYasunori Goto 106810246dc8SYasunori Goto if (cmd == ND_CMD_CALL) { 106910246dc8SYasunori Goto func = call_pkg->nd_command; 107010246dc8SYasunori Goto 107110246dc8SYasunori Goto buf_len = call_pkg->nd_size_in + call_pkg->nd_size_out; 107210246dc8SYasunori Goto buf = (void *) call_pkg->nd_payload; 107310246dc8SYasunori Goto 107410246dc8SYasunori Goto switch (func) { 107510246dc8SYasunori Goto case NFIT_CMD_TRANSLATE_SPA: 107610246dc8SYasunori Goto rc = nfit_test_cmd_translate_spa( 107710246dc8SYasunori Goto acpi_desc->nvdimm_bus, buf, buf_len); 107810246dc8SYasunori Goto return rc; 10799fb1a190SDave Jiang case NFIT_CMD_ARS_INJECT_SET: 10809fb1a190SDave Jiang rc = nfit_test_cmd_ars_error_inject(t, buf, 10819fb1a190SDave Jiang buf_len); 10829fb1a190SDave Jiang return rc; 10839fb1a190SDave Jiang case NFIT_CMD_ARS_INJECT_CLEAR: 10849fb1a190SDave Jiang rc = nfit_test_cmd_ars_inject_clear(t, buf, 10859fb1a190SDave Jiang buf_len); 10869fb1a190SDave Jiang return rc; 10879fb1a190SDave Jiang case NFIT_CMD_ARS_INJECT_GET: 10889fb1a190SDave Jiang rc = nfit_test_cmd_ars_inject_status(t, buf, 10899fb1a190SDave Jiang buf_len); 10909fb1a190SDave Jiang return rc; 109110246dc8SYasunori Goto default: 109210246dc8SYasunori Goto return -ENOTTY; 109310246dc8SYasunori Goto } 109410246dc8SYasunori Goto } 1095f471f1a7SDan Williams 1096e3654ecaSDan Williams if (!nd_desc || !test_bit(cmd, &nd_desc->cmd_mask)) 109739c686b8SVishal Verma return -ENOTTY; 109839c686b8SVishal Verma 10996634fb06SDan Williams switch (func) { 110039c686b8SVishal Verma case ND_CMD_ARS_CAP: 110139c686b8SVishal Verma rc = nfit_test_cmd_ars_cap(buf, buf_len); 110239c686b8SVishal Verma break; 110339c686b8SVishal Verma case ND_CMD_ARS_START: 11049fb1a190SDave Jiang rc = nfit_test_cmd_ars_start(t, ars_state, buf, 11059fb1a190SDave Jiang buf_len, cmd_rc); 110639c686b8SVishal Verma break; 110739c686b8SVishal Verma case ND_CMD_ARS_STATUS: 1108f471f1a7SDan Williams rc = nfit_test_cmd_ars_status(ars_state, buf, buf_len, 1109f471f1a7SDan Williams cmd_rc); 111039c686b8SVishal Verma break; 1111d4f32367SDan Williams case ND_CMD_CLEAR_ERROR: 11125e096ef3SVishal Verma rc = nfit_test_cmd_clear_error(t, buf, buf_len, cmd_rc); 1113d4f32367SDan Williams break; 111439c686b8SVishal Verma default: 111539c686b8SVishal Verma return -ENOTTY; 111639c686b8SVishal Verma } 111739c686b8SVishal Verma } 11186bc75619SDan Williams 11196bc75619SDan Williams return rc; 11206bc75619SDan Williams } 11216bc75619SDan Williams 11226bc75619SDan Williams static DEFINE_SPINLOCK(nfit_test_lock); 11236bc75619SDan Williams static struct nfit_test *instances[NUM_NFITS]; 11246bc75619SDan Williams 11256bc75619SDan Williams static void release_nfit_res(void *data) 11266bc75619SDan Williams { 11276bc75619SDan Williams struct nfit_test_resource *nfit_res = data; 11286bc75619SDan Williams 11296bc75619SDan Williams spin_lock(&nfit_test_lock); 11306bc75619SDan Williams list_del(&nfit_res->list); 11316bc75619SDan Williams spin_unlock(&nfit_test_lock); 11326bc75619SDan Williams 11336bc75619SDan Williams vfree(nfit_res->buf); 11346bc75619SDan Williams kfree(nfit_res); 11356bc75619SDan Williams } 11366bc75619SDan Williams 11376bc75619SDan Williams static void *__test_alloc(struct nfit_test *t, size_t size, dma_addr_t *dma, 11386bc75619SDan Williams void *buf) 11396bc75619SDan Williams { 11406bc75619SDan Williams struct device *dev = &t->pdev.dev; 11416bc75619SDan Williams struct nfit_test_resource *nfit_res = kzalloc(sizeof(*nfit_res), 11426bc75619SDan Williams GFP_KERNEL); 11436bc75619SDan Williams int rc; 11446bc75619SDan Williams 1145bd4cd745SDan Williams if (!buf || !nfit_res) 11466bc75619SDan Williams goto err; 11476bc75619SDan Williams rc = devm_add_action(dev, release_nfit_res, nfit_res); 11486bc75619SDan Williams if (rc) 11496bc75619SDan Williams goto err; 11506bc75619SDan Williams INIT_LIST_HEAD(&nfit_res->list); 11516bc75619SDan Williams memset(buf, 0, size); 11526bc75619SDan Williams nfit_res->dev = dev; 11536bc75619SDan Williams nfit_res->buf = buf; 1154bd4cd745SDan Williams nfit_res->res.start = *dma; 1155bd4cd745SDan Williams nfit_res->res.end = *dma + size - 1; 1156bd4cd745SDan Williams nfit_res->res.name = "NFIT"; 1157bd4cd745SDan Williams spin_lock_init(&nfit_res->lock); 1158bd4cd745SDan Williams INIT_LIST_HEAD(&nfit_res->requests); 11596bc75619SDan Williams spin_lock(&nfit_test_lock); 11606bc75619SDan Williams list_add(&nfit_res->list, &t->resources); 11616bc75619SDan Williams spin_unlock(&nfit_test_lock); 11626bc75619SDan Williams 11636bc75619SDan Williams return nfit_res->buf; 11646bc75619SDan Williams err: 1165ee8520feSDan Williams if (buf) 11666bc75619SDan Williams vfree(buf); 11676bc75619SDan Williams kfree(nfit_res); 11686bc75619SDan Williams return NULL; 11696bc75619SDan Williams } 11706bc75619SDan Williams 11716bc75619SDan Williams static void *test_alloc(struct nfit_test *t, size_t size, dma_addr_t *dma) 11726bc75619SDan Williams { 11736bc75619SDan Williams void *buf = vmalloc(size); 11746bc75619SDan Williams 11756bc75619SDan Williams *dma = (unsigned long) buf; 11766bc75619SDan Williams return __test_alloc(t, size, dma, buf); 11776bc75619SDan Williams } 11786bc75619SDan Williams 11796bc75619SDan Williams static struct nfit_test_resource *nfit_test_lookup(resource_size_t addr) 11806bc75619SDan Williams { 11816bc75619SDan Williams int i; 11826bc75619SDan Williams 11836bc75619SDan Williams for (i = 0; i < ARRAY_SIZE(instances); i++) { 11846bc75619SDan Williams struct nfit_test_resource *n, *nfit_res = NULL; 11856bc75619SDan Williams struct nfit_test *t = instances[i]; 11866bc75619SDan Williams 11876bc75619SDan Williams if (!t) 11886bc75619SDan Williams continue; 11896bc75619SDan Williams spin_lock(&nfit_test_lock); 11906bc75619SDan Williams list_for_each_entry(n, &t->resources, list) { 1191bd4cd745SDan Williams if (addr >= n->res.start && (addr < n->res.start 1192bd4cd745SDan Williams + resource_size(&n->res))) { 11936bc75619SDan Williams nfit_res = n; 11946bc75619SDan Williams break; 11956bc75619SDan Williams } else if (addr >= (unsigned long) n->buf 11966bc75619SDan Williams && (addr < (unsigned long) n->buf 1197bd4cd745SDan Williams + resource_size(&n->res))) { 11986bc75619SDan Williams nfit_res = n; 11996bc75619SDan Williams break; 12006bc75619SDan Williams } 12016bc75619SDan Williams } 12026bc75619SDan Williams spin_unlock(&nfit_test_lock); 12036bc75619SDan Williams if (nfit_res) 12046bc75619SDan Williams return nfit_res; 12056bc75619SDan Williams } 12066bc75619SDan Williams 12076bc75619SDan Williams return NULL; 12086bc75619SDan Williams } 12096bc75619SDan Williams 1210f471f1a7SDan Williams static int ars_state_init(struct device *dev, struct ars_state *ars_state) 1211f471f1a7SDan Williams { 12129fb1a190SDave Jiang /* for testing, only store up to n records that fit within 4k */ 1213f471f1a7SDan Williams ars_state->ars_status = devm_kzalloc(dev, 12149fb1a190SDave Jiang sizeof(struct nd_cmd_ars_status) + SZ_4K, GFP_KERNEL); 1215f471f1a7SDan Williams if (!ars_state->ars_status) 1216f471f1a7SDan Williams return -ENOMEM; 1217f471f1a7SDan Williams spin_lock_init(&ars_state->lock); 1218f471f1a7SDan Williams return 0; 1219f471f1a7SDan Williams } 1220f471f1a7SDan Williams 1221231bf117SDan Williams static void put_dimms(void *data) 1222231bf117SDan Williams { 1223718fda67SDan Williams struct nfit_test *t = data; 1224231bf117SDan Williams int i; 1225231bf117SDan Williams 1226718fda67SDan Williams for (i = 0; i < t->num_dcr; i++) 1227718fda67SDan Williams if (t->dimm_dev[i]) 1228718fda67SDan Williams device_unregister(t->dimm_dev[i]); 1229231bf117SDan Williams } 1230231bf117SDan Williams 1231231bf117SDan Williams static struct class *nfit_test_dimm; 1232231bf117SDan Williams 123373606afdSDan Williams static int dimm_name_to_id(struct device *dev) 123473606afdSDan Williams { 123573606afdSDan Williams int dimm; 123673606afdSDan Williams 1237718fda67SDan Williams if (sscanf(dev_name(dev), "test_dimm%d", &dimm) != 1) 123873606afdSDan Williams return -ENXIO; 123973606afdSDan Williams return dimm; 124073606afdSDan Williams } 124173606afdSDan Williams 124273606afdSDan Williams static ssize_t handle_show(struct device *dev, struct device_attribute *attr, 124373606afdSDan Williams char *buf) 124473606afdSDan Williams { 124573606afdSDan Williams int dimm = dimm_name_to_id(dev); 124673606afdSDan Williams 124773606afdSDan Williams if (dimm < 0) 124873606afdSDan Williams return dimm; 124973606afdSDan Williams 125019357a68SDan Williams return sprintf(buf, "%#x\n", handle[dimm]); 125173606afdSDan Williams } 125273606afdSDan Williams DEVICE_ATTR_RO(handle); 125373606afdSDan Williams 125473606afdSDan Williams static ssize_t fail_cmd_show(struct device *dev, struct device_attribute *attr, 125573606afdSDan Williams char *buf) 125673606afdSDan Williams { 125773606afdSDan Williams int dimm = dimm_name_to_id(dev); 125873606afdSDan Williams 125973606afdSDan Williams if (dimm < 0) 126073606afdSDan Williams return dimm; 126173606afdSDan Williams 126273606afdSDan Williams return sprintf(buf, "%#lx\n", dimm_fail_cmd_flags[dimm]); 126373606afdSDan Williams } 126473606afdSDan Williams 126573606afdSDan Williams static ssize_t fail_cmd_store(struct device *dev, struct device_attribute *attr, 126673606afdSDan Williams const char *buf, size_t size) 126773606afdSDan Williams { 126873606afdSDan Williams int dimm = dimm_name_to_id(dev); 126973606afdSDan Williams unsigned long val; 127073606afdSDan Williams ssize_t rc; 127173606afdSDan Williams 127273606afdSDan Williams if (dimm < 0) 127373606afdSDan Williams return dimm; 127473606afdSDan Williams 127573606afdSDan Williams rc = kstrtol(buf, 0, &val); 127673606afdSDan Williams if (rc) 127773606afdSDan Williams return rc; 127873606afdSDan Williams 127973606afdSDan Williams dimm_fail_cmd_flags[dimm] = val; 128073606afdSDan Williams return size; 128173606afdSDan Williams } 128273606afdSDan Williams static DEVICE_ATTR_RW(fail_cmd); 128373606afdSDan Williams 128455c72ab6SDan Williams static ssize_t fail_cmd_code_show(struct device *dev, struct device_attribute *attr, 128555c72ab6SDan Williams char *buf) 128655c72ab6SDan Williams { 128755c72ab6SDan Williams int dimm = dimm_name_to_id(dev); 128855c72ab6SDan Williams 128955c72ab6SDan Williams if (dimm < 0) 129055c72ab6SDan Williams return dimm; 129155c72ab6SDan Williams 129255c72ab6SDan Williams return sprintf(buf, "%d\n", dimm_fail_cmd_code[dimm]); 129355c72ab6SDan Williams } 129455c72ab6SDan Williams 129555c72ab6SDan Williams static ssize_t fail_cmd_code_store(struct device *dev, struct device_attribute *attr, 129655c72ab6SDan Williams const char *buf, size_t size) 129755c72ab6SDan Williams { 129855c72ab6SDan Williams int dimm = dimm_name_to_id(dev); 129955c72ab6SDan Williams unsigned long val; 130055c72ab6SDan Williams ssize_t rc; 130155c72ab6SDan Williams 130255c72ab6SDan Williams if (dimm < 0) 130355c72ab6SDan Williams return dimm; 130455c72ab6SDan Williams 130555c72ab6SDan Williams rc = kstrtol(buf, 0, &val); 130655c72ab6SDan Williams if (rc) 130755c72ab6SDan Williams return rc; 130855c72ab6SDan Williams 130955c72ab6SDan Williams dimm_fail_cmd_code[dimm] = val; 131055c72ab6SDan Williams return size; 131155c72ab6SDan Williams } 131255c72ab6SDan Williams static DEVICE_ATTR_RW(fail_cmd_code); 131355c72ab6SDan Williams 131473606afdSDan Williams static struct attribute *nfit_test_dimm_attributes[] = { 131573606afdSDan Williams &dev_attr_fail_cmd.attr, 131655c72ab6SDan Williams &dev_attr_fail_cmd_code.attr, 131773606afdSDan Williams &dev_attr_handle.attr, 131873606afdSDan Williams NULL, 131973606afdSDan Williams }; 132073606afdSDan Williams 132173606afdSDan Williams static struct attribute_group nfit_test_dimm_attribute_group = { 132273606afdSDan Williams .attrs = nfit_test_dimm_attributes, 132373606afdSDan Williams }; 132473606afdSDan Williams 132573606afdSDan Williams static const struct attribute_group *nfit_test_dimm_attribute_groups[] = { 132673606afdSDan Williams &nfit_test_dimm_attribute_group, 132773606afdSDan Williams NULL, 132873606afdSDan Williams }; 132973606afdSDan Williams 1330718fda67SDan Williams static int nfit_test_dimm_init(struct nfit_test *t) 1331718fda67SDan Williams { 1332718fda67SDan Williams int i; 1333718fda67SDan Williams 1334718fda67SDan Williams if (devm_add_action_or_reset(&t->pdev.dev, put_dimms, t)) 1335718fda67SDan Williams return -ENOMEM; 1336718fda67SDan Williams for (i = 0; i < t->num_dcr; i++) { 1337718fda67SDan Williams t->dimm_dev[i] = device_create_with_groups(nfit_test_dimm, 1338718fda67SDan Williams &t->pdev.dev, 0, NULL, 1339718fda67SDan Williams nfit_test_dimm_attribute_groups, 1340718fda67SDan Williams "test_dimm%d", i + t->dcr_idx); 1341718fda67SDan Williams if (!t->dimm_dev[i]) 1342718fda67SDan Williams return -ENOMEM; 1343718fda67SDan Williams } 1344718fda67SDan Williams return 0; 1345718fda67SDan Williams } 1346718fda67SDan Williams 1347ed07c433SDan Williams static void smart_init(struct nfit_test *t) 1348ed07c433SDan Williams { 1349ed07c433SDan Williams int i; 1350ed07c433SDan Williams const struct nd_intel_smart_threshold smart_t_data = { 1351ed07c433SDan Williams .alarm_control = ND_INTEL_SMART_SPARE_TRIP 1352ed07c433SDan Williams | ND_INTEL_SMART_TEMP_TRIP, 1353ed07c433SDan Williams .media_temperature = 40 * 16, 1354ed07c433SDan Williams .ctrl_temperature = 30 * 16, 1355ed07c433SDan Williams .spares = 5, 1356ed07c433SDan Williams }; 1357ed07c433SDan Williams 1358ed07c433SDan Williams for (i = 0; i < t->num_dcr; i++) { 1359*b4d4702fSVishal Verma memcpy(&t->smart[i], &smart_def, sizeof(smart_def)); 1360ed07c433SDan Williams memcpy(&t->smart_threshold[i], &smart_t_data, 1361ed07c433SDan Williams sizeof(smart_t_data)); 1362ed07c433SDan Williams } 1363ed07c433SDan Williams } 1364ed07c433SDan Williams 13656bc75619SDan Williams static int nfit_test0_alloc(struct nfit_test *t) 13666bc75619SDan Williams { 13676b577c9dSLinda Knippers size_t nfit_size = sizeof(struct acpi_nfit_system_address) * NUM_SPA 13686bc75619SDan Williams + sizeof(struct acpi_nfit_memory_map) * NUM_MEM 13696bc75619SDan Williams + sizeof(struct acpi_nfit_control_region) * NUM_DCR 13703b87356fSDan Williams + offsetof(struct acpi_nfit_control_region, 13713b87356fSDan Williams window_size) * NUM_DCR 13729d27a87eSDan Williams + sizeof(struct acpi_nfit_data_region) * NUM_BDW 137385d3fa02SDan Williams + (sizeof(struct acpi_nfit_flush_address) 1374f81e1d35SDave Jiang + sizeof(u64) * NUM_HINTS) * NUM_DCR 1375f81e1d35SDave Jiang + sizeof(struct acpi_nfit_capabilities); 13766bc75619SDan Williams int i; 13776bc75619SDan Williams 13786bc75619SDan Williams t->nfit_buf = test_alloc(t, nfit_size, &t->nfit_dma); 13796bc75619SDan Williams if (!t->nfit_buf) 13806bc75619SDan Williams return -ENOMEM; 13816bc75619SDan Williams t->nfit_size = nfit_size; 13826bc75619SDan Williams 1383ee8520feSDan Williams t->spa_set[0] = test_alloc(t, SPA0_SIZE, &t->spa_set_dma[0]); 13846bc75619SDan Williams if (!t->spa_set[0]) 13856bc75619SDan Williams return -ENOMEM; 13866bc75619SDan Williams 1387ee8520feSDan Williams t->spa_set[1] = test_alloc(t, SPA1_SIZE, &t->spa_set_dma[1]); 13886bc75619SDan Williams if (!t->spa_set[1]) 13896bc75619SDan Williams return -ENOMEM; 13906bc75619SDan Williams 1391ee8520feSDan Williams t->spa_set[2] = test_alloc(t, SPA0_SIZE, &t->spa_set_dma[2]); 139220985164SVishal Verma if (!t->spa_set[2]) 139320985164SVishal Verma return -ENOMEM; 139420985164SVishal Verma 1395dafb1048SDan Williams for (i = 0; i < t->num_dcr; i++) { 13966bc75619SDan Williams t->dimm[i] = test_alloc(t, DIMM_SIZE, &t->dimm_dma[i]); 13976bc75619SDan Williams if (!t->dimm[i]) 13986bc75619SDan Williams return -ENOMEM; 13996bc75619SDan Williams 14006bc75619SDan Williams t->label[i] = test_alloc(t, LABEL_SIZE, &t->label_dma[i]); 14016bc75619SDan Williams if (!t->label[i]) 14026bc75619SDan Williams return -ENOMEM; 14036bc75619SDan Williams sprintf(t->label[i], "label%d", i); 14049d27a87eSDan Williams 14059d15ce9cSDan Williams t->flush[i] = test_alloc(t, max(PAGE_SIZE, 14069d15ce9cSDan Williams sizeof(u64) * NUM_HINTS), 140785d3fa02SDan Williams &t->flush_dma[i]); 14089d27a87eSDan Williams if (!t->flush[i]) 14099d27a87eSDan Williams return -ENOMEM; 14106bc75619SDan Williams } 14116bc75619SDan Williams 1412dafb1048SDan Williams for (i = 0; i < t->num_dcr; i++) { 14136bc75619SDan Williams t->dcr[i] = test_alloc(t, LABEL_SIZE, &t->dcr_dma[i]); 14146bc75619SDan Williams if (!t->dcr[i]) 14156bc75619SDan Williams return -ENOMEM; 14166bc75619SDan Williams } 14176bc75619SDan Williams 1418c14a868aSDan Williams t->_fit = test_alloc(t, sizeof(union acpi_object **), &t->_fit_dma); 1419c14a868aSDan Williams if (!t->_fit) 1420c14a868aSDan Williams return -ENOMEM; 1421c14a868aSDan Williams 1422718fda67SDan Williams if (nfit_test_dimm_init(t)) 1423231bf117SDan Williams return -ENOMEM; 1424ed07c433SDan Williams smart_init(t); 1425f471f1a7SDan Williams return ars_state_init(&t->pdev.dev, &t->ars_state); 14266bc75619SDan Williams } 14276bc75619SDan Williams 14286bc75619SDan Williams static int nfit_test1_alloc(struct nfit_test *t) 14296bc75619SDan Williams { 14307bfe97c7SDan Williams size_t nfit_size = sizeof(struct acpi_nfit_system_address) * 2 1431ac40b675SDan Williams + sizeof(struct acpi_nfit_memory_map) * 2 1432ac40b675SDan Williams + offsetof(struct acpi_nfit_control_region, window_size) * 2; 1433dafb1048SDan Williams int i; 14346bc75619SDan Williams 14356bc75619SDan Williams t->nfit_buf = test_alloc(t, nfit_size, &t->nfit_dma); 14366bc75619SDan Williams if (!t->nfit_buf) 14376bc75619SDan Williams return -ENOMEM; 14386bc75619SDan Williams t->nfit_size = nfit_size; 14396bc75619SDan Williams 1440ee8520feSDan Williams t->spa_set[0] = test_alloc(t, SPA2_SIZE, &t->spa_set_dma[0]); 14416bc75619SDan Williams if (!t->spa_set[0]) 14426bc75619SDan Williams return -ENOMEM; 14436bc75619SDan Williams 1444dafb1048SDan Williams for (i = 0; i < t->num_dcr; i++) { 1445dafb1048SDan Williams t->label[i] = test_alloc(t, LABEL_SIZE, &t->label_dma[i]); 1446dafb1048SDan Williams if (!t->label[i]) 1447dafb1048SDan Williams return -ENOMEM; 1448dafb1048SDan Williams sprintf(t->label[i], "label%d", i); 1449dafb1048SDan Williams } 1450dafb1048SDan Williams 14517bfe97c7SDan Williams t->spa_set[1] = test_alloc(t, SPA_VCD_SIZE, &t->spa_set_dma[1]); 14527bfe97c7SDan Williams if (!t->spa_set[1]) 14537bfe97c7SDan Williams return -ENOMEM; 14547bfe97c7SDan Williams 1455718fda67SDan Williams if (nfit_test_dimm_init(t)) 1456718fda67SDan Williams return -ENOMEM; 1457ed07c433SDan Williams smart_init(t); 1458f471f1a7SDan Williams return ars_state_init(&t->pdev.dev, &t->ars_state); 14596bc75619SDan Williams } 14606bc75619SDan Williams 14615dc68e55SDan Williams static void dcr_common_init(struct acpi_nfit_control_region *dcr) 14625dc68e55SDan Williams { 14635dc68e55SDan Williams dcr->vendor_id = 0xabcd; 14645dc68e55SDan Williams dcr->device_id = 0; 14655dc68e55SDan Williams dcr->revision_id = 1; 14665dc68e55SDan Williams dcr->valid_fields = 1; 14675dc68e55SDan Williams dcr->manufacturing_location = 0xa; 14685dc68e55SDan Williams dcr->manufacturing_date = cpu_to_be16(2016); 14695dc68e55SDan Williams } 14705dc68e55SDan Williams 14716bc75619SDan Williams static void nfit_test0_setup(struct nfit_test *t) 14726bc75619SDan Williams { 147385d3fa02SDan Williams const int flush_hint_size = sizeof(struct acpi_nfit_flush_address) 147485d3fa02SDan Williams + (sizeof(u64) * NUM_HINTS); 14756bc75619SDan Williams struct acpi_nfit_desc *acpi_desc; 14766bc75619SDan Williams struct acpi_nfit_memory_map *memdev; 14776bc75619SDan Williams void *nfit_buf = t->nfit_buf; 14786bc75619SDan Williams struct acpi_nfit_system_address *spa; 14796bc75619SDan Williams struct acpi_nfit_control_region *dcr; 14806bc75619SDan Williams struct acpi_nfit_data_region *bdw; 14819d27a87eSDan Williams struct acpi_nfit_flush_address *flush; 1482f81e1d35SDave Jiang struct acpi_nfit_capabilities *pcap; 1483d7d8464dSRoss Zwisler unsigned int offset = 0, i; 14846bc75619SDan Williams 14856bc75619SDan Williams /* 14866bc75619SDan Williams * spa0 (interleave first half of dimm0 and dimm1, note storage 14876bc75619SDan Williams * does not actually alias the related block-data-window 14886bc75619SDan Williams * regions) 14896bc75619SDan Williams */ 14906b577c9dSLinda Knippers spa = nfit_buf; 14916bc75619SDan Williams spa->header.type = ACPI_NFIT_TYPE_SYSTEM_ADDRESS; 14926bc75619SDan Williams spa->header.length = sizeof(*spa); 14936bc75619SDan Williams memcpy(spa->range_guid, to_nfit_uuid(NFIT_SPA_PM), 16); 14946bc75619SDan Williams spa->range_index = 0+1; 14956bc75619SDan Williams spa->address = t->spa_set_dma[0]; 14966bc75619SDan Williams spa->length = SPA0_SIZE; 1497d7d8464dSRoss Zwisler offset += spa->header.length; 14986bc75619SDan Williams 14996bc75619SDan Williams /* 15006bc75619SDan Williams * spa1 (interleave last half of the 4 DIMMS, note storage 15016bc75619SDan Williams * does not actually alias the related block-data-window 15026bc75619SDan Williams * regions) 15036bc75619SDan Williams */ 1504d7d8464dSRoss Zwisler spa = nfit_buf + offset; 15056bc75619SDan Williams spa->header.type = ACPI_NFIT_TYPE_SYSTEM_ADDRESS; 15066bc75619SDan Williams spa->header.length = sizeof(*spa); 15076bc75619SDan Williams memcpy(spa->range_guid, to_nfit_uuid(NFIT_SPA_PM), 16); 15086bc75619SDan Williams spa->range_index = 1+1; 15096bc75619SDan Williams spa->address = t->spa_set_dma[1]; 15106bc75619SDan Williams spa->length = SPA1_SIZE; 1511d7d8464dSRoss Zwisler offset += spa->header.length; 15126bc75619SDan Williams 15136bc75619SDan Williams /* spa2 (dcr0) dimm0 */ 1514d7d8464dSRoss Zwisler spa = nfit_buf + offset; 15156bc75619SDan Williams spa->header.type = ACPI_NFIT_TYPE_SYSTEM_ADDRESS; 15166bc75619SDan Williams spa->header.length = sizeof(*spa); 15176bc75619SDan Williams memcpy(spa->range_guid, to_nfit_uuid(NFIT_SPA_DCR), 16); 15186bc75619SDan Williams spa->range_index = 2+1; 15196bc75619SDan Williams spa->address = t->dcr_dma[0]; 15206bc75619SDan Williams spa->length = DCR_SIZE; 1521d7d8464dSRoss Zwisler offset += spa->header.length; 15226bc75619SDan Williams 15236bc75619SDan Williams /* spa3 (dcr1) dimm1 */ 1524d7d8464dSRoss Zwisler spa = nfit_buf + offset; 15256bc75619SDan Williams spa->header.type = ACPI_NFIT_TYPE_SYSTEM_ADDRESS; 15266bc75619SDan Williams spa->header.length = sizeof(*spa); 15276bc75619SDan Williams memcpy(spa->range_guid, to_nfit_uuid(NFIT_SPA_DCR), 16); 15286bc75619SDan Williams spa->range_index = 3+1; 15296bc75619SDan Williams spa->address = t->dcr_dma[1]; 15306bc75619SDan Williams spa->length = DCR_SIZE; 1531d7d8464dSRoss Zwisler offset += spa->header.length; 15326bc75619SDan Williams 15336bc75619SDan Williams /* spa4 (dcr2) dimm2 */ 1534d7d8464dSRoss Zwisler spa = nfit_buf + offset; 15356bc75619SDan Williams spa->header.type = ACPI_NFIT_TYPE_SYSTEM_ADDRESS; 15366bc75619SDan Williams spa->header.length = sizeof(*spa); 15376bc75619SDan Williams memcpy(spa->range_guid, to_nfit_uuid(NFIT_SPA_DCR), 16); 15386bc75619SDan Williams spa->range_index = 4+1; 15396bc75619SDan Williams spa->address = t->dcr_dma[2]; 15406bc75619SDan Williams spa->length = DCR_SIZE; 1541d7d8464dSRoss Zwisler offset += spa->header.length; 15426bc75619SDan Williams 15436bc75619SDan Williams /* spa5 (dcr3) dimm3 */ 1544d7d8464dSRoss Zwisler spa = nfit_buf + offset; 15456bc75619SDan Williams spa->header.type = ACPI_NFIT_TYPE_SYSTEM_ADDRESS; 15466bc75619SDan Williams spa->header.length = sizeof(*spa); 15476bc75619SDan Williams memcpy(spa->range_guid, to_nfit_uuid(NFIT_SPA_DCR), 16); 15486bc75619SDan Williams spa->range_index = 5+1; 15496bc75619SDan Williams spa->address = t->dcr_dma[3]; 15506bc75619SDan Williams spa->length = DCR_SIZE; 1551d7d8464dSRoss Zwisler offset += spa->header.length; 15526bc75619SDan Williams 15536bc75619SDan Williams /* spa6 (bdw for dcr0) dimm0 */ 1554d7d8464dSRoss Zwisler spa = nfit_buf + offset; 15556bc75619SDan Williams spa->header.type = ACPI_NFIT_TYPE_SYSTEM_ADDRESS; 15566bc75619SDan Williams spa->header.length = sizeof(*spa); 15576bc75619SDan Williams memcpy(spa->range_guid, to_nfit_uuid(NFIT_SPA_BDW), 16); 15586bc75619SDan Williams spa->range_index = 6+1; 15596bc75619SDan Williams spa->address = t->dimm_dma[0]; 15606bc75619SDan Williams spa->length = DIMM_SIZE; 1561d7d8464dSRoss Zwisler offset += spa->header.length; 15626bc75619SDan Williams 15636bc75619SDan Williams /* spa7 (bdw for dcr1) dimm1 */ 1564d7d8464dSRoss Zwisler spa = nfit_buf + offset; 15656bc75619SDan Williams spa->header.type = ACPI_NFIT_TYPE_SYSTEM_ADDRESS; 15666bc75619SDan Williams spa->header.length = sizeof(*spa); 15676bc75619SDan Williams memcpy(spa->range_guid, to_nfit_uuid(NFIT_SPA_BDW), 16); 15686bc75619SDan Williams spa->range_index = 7+1; 15696bc75619SDan Williams spa->address = t->dimm_dma[1]; 15706bc75619SDan Williams spa->length = DIMM_SIZE; 1571d7d8464dSRoss Zwisler offset += spa->header.length; 15726bc75619SDan Williams 15736bc75619SDan Williams /* spa8 (bdw for dcr2) dimm2 */ 1574d7d8464dSRoss Zwisler spa = nfit_buf + offset; 15756bc75619SDan Williams spa->header.type = ACPI_NFIT_TYPE_SYSTEM_ADDRESS; 15766bc75619SDan Williams spa->header.length = sizeof(*spa); 15776bc75619SDan Williams memcpy(spa->range_guid, to_nfit_uuid(NFIT_SPA_BDW), 16); 15786bc75619SDan Williams spa->range_index = 8+1; 15796bc75619SDan Williams spa->address = t->dimm_dma[2]; 15806bc75619SDan Williams spa->length = DIMM_SIZE; 1581d7d8464dSRoss Zwisler offset += spa->header.length; 15826bc75619SDan Williams 15836bc75619SDan Williams /* spa9 (bdw for dcr3) dimm3 */ 1584d7d8464dSRoss Zwisler spa = nfit_buf + offset; 15856bc75619SDan Williams spa->header.type = ACPI_NFIT_TYPE_SYSTEM_ADDRESS; 15866bc75619SDan Williams spa->header.length = sizeof(*spa); 15876bc75619SDan Williams memcpy(spa->range_guid, to_nfit_uuid(NFIT_SPA_BDW), 16); 15886bc75619SDan Williams spa->range_index = 9+1; 15896bc75619SDan Williams spa->address = t->dimm_dma[3]; 15906bc75619SDan Williams spa->length = DIMM_SIZE; 1591d7d8464dSRoss Zwisler offset += spa->header.length; 15926bc75619SDan Williams 15936bc75619SDan Williams /* mem-region0 (spa0, dimm0) */ 15946bc75619SDan Williams memdev = nfit_buf + offset; 15956bc75619SDan Williams memdev->header.type = ACPI_NFIT_TYPE_MEMORY_MAP; 15966bc75619SDan Williams memdev->header.length = sizeof(*memdev); 15976bc75619SDan Williams memdev->device_handle = handle[0]; 15986bc75619SDan Williams memdev->physical_id = 0; 15996bc75619SDan Williams memdev->region_id = 0; 16006bc75619SDan Williams memdev->range_index = 0+1; 16013b87356fSDan Williams memdev->region_index = 4+1; 16026bc75619SDan Williams memdev->region_size = SPA0_SIZE/2; 1603df06a2d5SDan Williams memdev->region_offset = 1; 16046bc75619SDan Williams memdev->address = 0; 16056bc75619SDan Williams memdev->interleave_index = 0; 16066bc75619SDan Williams memdev->interleave_ways = 2; 1607d7d8464dSRoss Zwisler offset += memdev->header.length; 16086bc75619SDan Williams 16096bc75619SDan Williams /* mem-region1 (spa0, dimm1) */ 1610d7d8464dSRoss Zwisler memdev = nfit_buf + offset; 16116bc75619SDan Williams memdev->header.type = ACPI_NFIT_TYPE_MEMORY_MAP; 16126bc75619SDan Williams memdev->header.length = sizeof(*memdev); 16136bc75619SDan Williams memdev->device_handle = handle[1]; 16146bc75619SDan Williams memdev->physical_id = 1; 16156bc75619SDan Williams memdev->region_id = 0; 16166bc75619SDan Williams memdev->range_index = 0+1; 16173b87356fSDan Williams memdev->region_index = 5+1; 16186bc75619SDan Williams memdev->region_size = SPA0_SIZE/2; 1619df06a2d5SDan Williams memdev->region_offset = (1 << 8); 16206bc75619SDan Williams memdev->address = 0; 16216bc75619SDan Williams memdev->interleave_index = 0; 16226bc75619SDan Williams memdev->interleave_ways = 2; 1623ac40b675SDan Williams memdev->flags = ACPI_NFIT_MEM_HEALTH_ENABLED; 1624d7d8464dSRoss Zwisler offset += memdev->header.length; 16256bc75619SDan Williams 16266bc75619SDan Williams /* mem-region2 (spa1, dimm0) */ 1627d7d8464dSRoss Zwisler memdev = nfit_buf + offset; 16286bc75619SDan Williams memdev->header.type = ACPI_NFIT_TYPE_MEMORY_MAP; 16296bc75619SDan Williams memdev->header.length = sizeof(*memdev); 16306bc75619SDan Williams memdev->device_handle = handle[0]; 16316bc75619SDan Williams memdev->physical_id = 0; 16326bc75619SDan Williams memdev->region_id = 1; 16336bc75619SDan Williams memdev->range_index = 1+1; 16343b87356fSDan Williams memdev->region_index = 4+1; 16356bc75619SDan Williams memdev->region_size = SPA1_SIZE/4; 1636df06a2d5SDan Williams memdev->region_offset = (1 << 16); 16376bc75619SDan Williams memdev->address = SPA0_SIZE/2; 16386bc75619SDan Williams memdev->interleave_index = 0; 16396bc75619SDan Williams memdev->interleave_ways = 4; 1640ac40b675SDan Williams memdev->flags = ACPI_NFIT_MEM_HEALTH_ENABLED; 1641d7d8464dSRoss Zwisler offset += memdev->header.length; 16426bc75619SDan Williams 16436bc75619SDan Williams /* mem-region3 (spa1, dimm1) */ 1644d7d8464dSRoss Zwisler memdev = nfit_buf + offset; 16456bc75619SDan Williams memdev->header.type = ACPI_NFIT_TYPE_MEMORY_MAP; 16466bc75619SDan Williams memdev->header.length = sizeof(*memdev); 16476bc75619SDan Williams memdev->device_handle = handle[1]; 16486bc75619SDan Williams memdev->physical_id = 1; 16496bc75619SDan Williams memdev->region_id = 1; 16506bc75619SDan Williams memdev->range_index = 1+1; 16513b87356fSDan Williams memdev->region_index = 5+1; 16526bc75619SDan Williams memdev->region_size = SPA1_SIZE/4; 1653df06a2d5SDan Williams memdev->region_offset = (1 << 24); 16546bc75619SDan Williams memdev->address = SPA0_SIZE/2; 16556bc75619SDan Williams memdev->interleave_index = 0; 16566bc75619SDan Williams memdev->interleave_ways = 4; 1657d7d8464dSRoss Zwisler offset += memdev->header.length; 16586bc75619SDan Williams 16596bc75619SDan Williams /* mem-region4 (spa1, dimm2) */ 1660d7d8464dSRoss Zwisler memdev = nfit_buf + offset; 16616bc75619SDan Williams memdev->header.type = ACPI_NFIT_TYPE_MEMORY_MAP; 16626bc75619SDan Williams memdev->header.length = sizeof(*memdev); 16636bc75619SDan Williams memdev->device_handle = handle[2]; 16646bc75619SDan Williams memdev->physical_id = 2; 16656bc75619SDan Williams memdev->region_id = 0; 16666bc75619SDan Williams memdev->range_index = 1+1; 16673b87356fSDan Williams memdev->region_index = 6+1; 16686bc75619SDan Williams memdev->region_size = SPA1_SIZE/4; 1669df06a2d5SDan Williams memdev->region_offset = (1ULL << 32); 16706bc75619SDan Williams memdev->address = SPA0_SIZE/2; 16716bc75619SDan Williams memdev->interleave_index = 0; 16726bc75619SDan Williams memdev->interleave_ways = 4; 1673ac40b675SDan Williams memdev->flags = ACPI_NFIT_MEM_HEALTH_ENABLED; 1674d7d8464dSRoss Zwisler offset += memdev->header.length; 16756bc75619SDan Williams 16766bc75619SDan Williams /* mem-region5 (spa1, dimm3) */ 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[3]; 16816bc75619SDan Williams memdev->physical_id = 3; 16826bc75619SDan Williams memdev->region_id = 0; 16836bc75619SDan Williams memdev->range_index = 1+1; 16843b87356fSDan Williams memdev->region_index = 7+1; 16856bc75619SDan Williams memdev->region_size = SPA1_SIZE/4; 1686df06a2d5SDan Williams memdev->region_offset = (1ULL << 40); 16876bc75619SDan Williams memdev->address = SPA0_SIZE/2; 16886bc75619SDan Williams memdev->interleave_index = 0; 16896bc75619SDan Williams memdev->interleave_ways = 4; 1690d7d8464dSRoss Zwisler offset += memdev->header.length; 16916bc75619SDan Williams 16926bc75619SDan Williams /* mem-region6 (spa/dcr0, dimm0) */ 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[0]; 16976bc75619SDan Williams memdev->physical_id = 0; 16986bc75619SDan Williams memdev->region_id = 0; 16996bc75619SDan Williams memdev->range_index = 2+1; 17006bc75619SDan Williams memdev->region_index = 0+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; 1706d7d8464dSRoss Zwisler offset += memdev->header.length; 17076bc75619SDan Williams 17086bc75619SDan Williams /* mem-region7 (spa/dcr1, dimm1) */ 1709d7d8464dSRoss Zwisler memdev = nfit_buf + offset; 17106bc75619SDan Williams memdev->header.type = ACPI_NFIT_TYPE_MEMORY_MAP; 17116bc75619SDan Williams memdev->header.length = sizeof(*memdev); 17126bc75619SDan Williams memdev->device_handle = handle[1]; 17136bc75619SDan Williams memdev->physical_id = 1; 17146bc75619SDan Williams memdev->region_id = 0; 17156bc75619SDan Williams memdev->range_index = 3+1; 17166bc75619SDan Williams memdev->region_index = 1+1; 17176bc75619SDan Williams memdev->region_size = 0; 17186bc75619SDan Williams memdev->region_offset = 0; 17196bc75619SDan Williams memdev->address = 0; 17206bc75619SDan Williams memdev->interleave_index = 0; 17216bc75619SDan Williams memdev->interleave_ways = 1; 1722d7d8464dSRoss Zwisler offset += memdev->header.length; 17236bc75619SDan Williams 17246bc75619SDan Williams /* mem-region8 (spa/dcr2, dimm2) */ 1725d7d8464dSRoss Zwisler memdev = nfit_buf + offset; 17266bc75619SDan Williams memdev->header.type = ACPI_NFIT_TYPE_MEMORY_MAP; 17276bc75619SDan Williams memdev->header.length = sizeof(*memdev); 17286bc75619SDan Williams memdev->device_handle = handle[2]; 17296bc75619SDan Williams memdev->physical_id = 2; 17306bc75619SDan Williams memdev->region_id = 0; 17316bc75619SDan Williams memdev->range_index = 4+1; 17326bc75619SDan Williams memdev->region_index = 2+1; 17336bc75619SDan Williams memdev->region_size = 0; 17346bc75619SDan Williams memdev->region_offset = 0; 17356bc75619SDan Williams memdev->address = 0; 17366bc75619SDan Williams memdev->interleave_index = 0; 17376bc75619SDan Williams memdev->interleave_ways = 1; 1738d7d8464dSRoss Zwisler offset += memdev->header.length; 17396bc75619SDan Williams 17406bc75619SDan Williams /* mem-region9 (spa/dcr3, dimm3) */ 1741d7d8464dSRoss Zwisler memdev = nfit_buf + offset; 17426bc75619SDan Williams memdev->header.type = ACPI_NFIT_TYPE_MEMORY_MAP; 17436bc75619SDan Williams memdev->header.length = sizeof(*memdev); 17446bc75619SDan Williams memdev->device_handle = handle[3]; 17456bc75619SDan Williams memdev->physical_id = 3; 17466bc75619SDan Williams memdev->region_id = 0; 17476bc75619SDan Williams memdev->range_index = 5+1; 17486bc75619SDan Williams memdev->region_index = 3+1; 17496bc75619SDan Williams memdev->region_size = 0; 17506bc75619SDan Williams memdev->region_offset = 0; 17516bc75619SDan Williams memdev->address = 0; 17526bc75619SDan Williams memdev->interleave_index = 0; 17536bc75619SDan Williams memdev->interleave_ways = 1; 1754d7d8464dSRoss Zwisler offset += memdev->header.length; 17556bc75619SDan Williams 17566bc75619SDan Williams /* mem-region10 (spa/bdw0, dimm0) */ 1757d7d8464dSRoss Zwisler memdev = nfit_buf + offset; 17586bc75619SDan Williams memdev->header.type = ACPI_NFIT_TYPE_MEMORY_MAP; 17596bc75619SDan Williams memdev->header.length = sizeof(*memdev); 17606bc75619SDan Williams memdev->device_handle = handle[0]; 17616bc75619SDan Williams memdev->physical_id = 0; 17626bc75619SDan Williams memdev->region_id = 0; 17636bc75619SDan Williams memdev->range_index = 6+1; 17646bc75619SDan Williams memdev->region_index = 0+1; 17656bc75619SDan Williams memdev->region_size = 0; 17666bc75619SDan Williams memdev->region_offset = 0; 17676bc75619SDan Williams memdev->address = 0; 17686bc75619SDan Williams memdev->interleave_index = 0; 17696bc75619SDan Williams memdev->interleave_ways = 1; 1770d7d8464dSRoss Zwisler offset += memdev->header.length; 17716bc75619SDan Williams 17726bc75619SDan Williams /* mem-region11 (spa/bdw1, dimm1) */ 1773d7d8464dSRoss Zwisler memdev = nfit_buf + offset; 17746bc75619SDan Williams memdev->header.type = ACPI_NFIT_TYPE_MEMORY_MAP; 17756bc75619SDan Williams memdev->header.length = sizeof(*memdev); 17766bc75619SDan Williams memdev->device_handle = handle[1]; 17776bc75619SDan Williams memdev->physical_id = 1; 17786bc75619SDan Williams memdev->region_id = 0; 17796bc75619SDan Williams memdev->range_index = 7+1; 17806bc75619SDan Williams memdev->region_index = 1+1; 17816bc75619SDan Williams memdev->region_size = 0; 17826bc75619SDan Williams memdev->region_offset = 0; 17836bc75619SDan Williams memdev->address = 0; 17846bc75619SDan Williams memdev->interleave_index = 0; 17856bc75619SDan Williams memdev->interleave_ways = 1; 1786d7d8464dSRoss Zwisler offset += memdev->header.length; 17876bc75619SDan Williams 17886bc75619SDan Williams /* mem-region12 (spa/bdw2, dimm2) */ 1789d7d8464dSRoss Zwisler memdev = nfit_buf + offset; 17906bc75619SDan Williams memdev->header.type = ACPI_NFIT_TYPE_MEMORY_MAP; 17916bc75619SDan Williams memdev->header.length = sizeof(*memdev); 17926bc75619SDan Williams memdev->device_handle = handle[2]; 17936bc75619SDan Williams memdev->physical_id = 2; 17946bc75619SDan Williams memdev->region_id = 0; 17956bc75619SDan Williams memdev->range_index = 8+1; 17966bc75619SDan Williams memdev->region_index = 2+1; 17976bc75619SDan Williams memdev->region_size = 0; 17986bc75619SDan Williams memdev->region_offset = 0; 17996bc75619SDan Williams memdev->address = 0; 18006bc75619SDan Williams memdev->interleave_index = 0; 18016bc75619SDan Williams memdev->interleave_ways = 1; 1802d7d8464dSRoss Zwisler offset += memdev->header.length; 18036bc75619SDan Williams 18046bc75619SDan Williams /* mem-region13 (spa/dcr3, dimm3) */ 1805d7d8464dSRoss Zwisler memdev = nfit_buf + offset; 18066bc75619SDan Williams memdev->header.type = ACPI_NFIT_TYPE_MEMORY_MAP; 18076bc75619SDan Williams memdev->header.length = sizeof(*memdev); 18086bc75619SDan Williams memdev->device_handle = handle[3]; 18096bc75619SDan Williams memdev->physical_id = 3; 18106bc75619SDan Williams memdev->region_id = 0; 18116bc75619SDan Williams memdev->range_index = 9+1; 18126bc75619SDan Williams memdev->region_index = 3+1; 18136bc75619SDan Williams memdev->region_size = 0; 18146bc75619SDan Williams memdev->region_offset = 0; 18156bc75619SDan Williams memdev->address = 0; 18166bc75619SDan Williams memdev->interleave_index = 0; 18176bc75619SDan Williams memdev->interleave_ways = 1; 1818ac40b675SDan Williams memdev->flags = ACPI_NFIT_MEM_HEALTH_ENABLED; 1819d7d8464dSRoss Zwisler offset += memdev->header.length; 18206bc75619SDan Williams 18213b87356fSDan Williams /* dcr-descriptor0: blk */ 18226bc75619SDan Williams dcr = nfit_buf + offset; 18236bc75619SDan Williams dcr->header.type = ACPI_NFIT_TYPE_CONTROL_REGION; 1824d7d8464dSRoss Zwisler dcr->header.length = sizeof(*dcr); 18256bc75619SDan Williams dcr->region_index = 0+1; 18265dc68e55SDan Williams dcr_common_init(dcr); 18276bc75619SDan Williams dcr->serial_number = ~handle[0]; 1828be26f9aeSDan Williams dcr->code = NFIT_FIC_BLK; 18296bc75619SDan Williams dcr->windows = 1; 18306bc75619SDan Williams dcr->window_size = DCR_SIZE; 18316bc75619SDan Williams dcr->command_offset = 0; 18326bc75619SDan Williams dcr->command_size = 8; 18336bc75619SDan Williams dcr->status_offset = 8; 18346bc75619SDan Williams dcr->status_size = 4; 1835d7d8464dSRoss Zwisler offset += dcr->header.length; 18366bc75619SDan Williams 18373b87356fSDan Williams /* dcr-descriptor1: blk */ 1838d7d8464dSRoss Zwisler dcr = nfit_buf + offset; 18396bc75619SDan Williams dcr->header.type = ACPI_NFIT_TYPE_CONTROL_REGION; 1840d7d8464dSRoss Zwisler dcr->header.length = sizeof(*dcr); 18416bc75619SDan Williams dcr->region_index = 1+1; 18425dc68e55SDan Williams dcr_common_init(dcr); 18436bc75619SDan Williams dcr->serial_number = ~handle[1]; 1844be26f9aeSDan Williams dcr->code = NFIT_FIC_BLK; 18456bc75619SDan Williams dcr->windows = 1; 18466bc75619SDan Williams dcr->window_size = DCR_SIZE; 18476bc75619SDan Williams dcr->command_offset = 0; 18486bc75619SDan Williams dcr->command_size = 8; 18496bc75619SDan Williams dcr->status_offset = 8; 18506bc75619SDan Williams dcr->status_size = 4; 1851d7d8464dSRoss Zwisler offset += dcr->header.length; 18526bc75619SDan Williams 18533b87356fSDan Williams /* dcr-descriptor2: blk */ 1854d7d8464dSRoss Zwisler dcr = nfit_buf + offset; 18556bc75619SDan Williams dcr->header.type = ACPI_NFIT_TYPE_CONTROL_REGION; 1856d7d8464dSRoss Zwisler dcr->header.length = sizeof(*dcr); 18576bc75619SDan Williams dcr->region_index = 2+1; 18585dc68e55SDan Williams dcr_common_init(dcr); 18596bc75619SDan Williams dcr->serial_number = ~handle[2]; 1860be26f9aeSDan Williams dcr->code = NFIT_FIC_BLK; 18616bc75619SDan Williams dcr->windows = 1; 18626bc75619SDan Williams dcr->window_size = DCR_SIZE; 18636bc75619SDan Williams dcr->command_offset = 0; 18646bc75619SDan Williams dcr->command_size = 8; 18656bc75619SDan Williams dcr->status_offset = 8; 18666bc75619SDan Williams dcr->status_size = 4; 1867d7d8464dSRoss Zwisler offset += dcr->header.length; 18686bc75619SDan Williams 18693b87356fSDan Williams /* dcr-descriptor3: blk */ 1870d7d8464dSRoss Zwisler dcr = nfit_buf + offset; 18716bc75619SDan Williams dcr->header.type = ACPI_NFIT_TYPE_CONTROL_REGION; 1872d7d8464dSRoss Zwisler dcr->header.length = sizeof(*dcr); 18736bc75619SDan Williams dcr->region_index = 3+1; 18745dc68e55SDan Williams dcr_common_init(dcr); 18756bc75619SDan Williams dcr->serial_number = ~handle[3]; 1876be26f9aeSDan Williams dcr->code = NFIT_FIC_BLK; 18776bc75619SDan Williams dcr->windows = 1; 18786bc75619SDan Williams dcr->window_size = DCR_SIZE; 18796bc75619SDan Williams dcr->command_offset = 0; 18806bc75619SDan Williams dcr->command_size = 8; 18816bc75619SDan Williams dcr->status_offset = 8; 18826bc75619SDan Williams dcr->status_size = 4; 1883d7d8464dSRoss Zwisler offset += dcr->header.length; 18846bc75619SDan Williams 18853b87356fSDan Williams /* dcr-descriptor0: pmem */ 18863b87356fSDan Williams dcr = nfit_buf + offset; 18873b87356fSDan Williams dcr->header.type = ACPI_NFIT_TYPE_CONTROL_REGION; 18883b87356fSDan Williams dcr->header.length = offsetof(struct acpi_nfit_control_region, 18893b87356fSDan Williams window_size); 18903b87356fSDan Williams dcr->region_index = 4+1; 18915dc68e55SDan Williams dcr_common_init(dcr); 18923b87356fSDan Williams dcr->serial_number = ~handle[0]; 18933b87356fSDan Williams dcr->code = NFIT_FIC_BYTEN; 18943b87356fSDan Williams dcr->windows = 0; 1895d7d8464dSRoss Zwisler offset += dcr->header.length; 18963b87356fSDan Williams 18973b87356fSDan Williams /* dcr-descriptor1: pmem */ 1898d7d8464dSRoss Zwisler dcr = nfit_buf + offset; 18993b87356fSDan Williams dcr->header.type = ACPI_NFIT_TYPE_CONTROL_REGION; 19003b87356fSDan Williams dcr->header.length = offsetof(struct acpi_nfit_control_region, 19013b87356fSDan Williams window_size); 19023b87356fSDan Williams dcr->region_index = 5+1; 19035dc68e55SDan Williams dcr_common_init(dcr); 19043b87356fSDan Williams dcr->serial_number = ~handle[1]; 19053b87356fSDan Williams dcr->code = NFIT_FIC_BYTEN; 19063b87356fSDan Williams dcr->windows = 0; 1907d7d8464dSRoss Zwisler offset += dcr->header.length; 19083b87356fSDan Williams 19093b87356fSDan Williams /* dcr-descriptor2: pmem */ 1910d7d8464dSRoss Zwisler dcr = nfit_buf + offset; 19113b87356fSDan Williams dcr->header.type = ACPI_NFIT_TYPE_CONTROL_REGION; 19123b87356fSDan Williams dcr->header.length = offsetof(struct acpi_nfit_control_region, 19133b87356fSDan Williams window_size); 19143b87356fSDan Williams dcr->region_index = 6+1; 19155dc68e55SDan Williams dcr_common_init(dcr); 19163b87356fSDan Williams dcr->serial_number = ~handle[2]; 19173b87356fSDan Williams dcr->code = NFIT_FIC_BYTEN; 19183b87356fSDan Williams dcr->windows = 0; 1919d7d8464dSRoss Zwisler offset += dcr->header.length; 19203b87356fSDan Williams 19213b87356fSDan Williams /* dcr-descriptor3: pmem */ 1922d7d8464dSRoss Zwisler dcr = nfit_buf + offset; 19233b87356fSDan Williams dcr->header.type = ACPI_NFIT_TYPE_CONTROL_REGION; 19243b87356fSDan Williams dcr->header.length = offsetof(struct acpi_nfit_control_region, 19253b87356fSDan Williams window_size); 19263b87356fSDan Williams dcr->region_index = 7+1; 19275dc68e55SDan Williams dcr_common_init(dcr); 19283b87356fSDan Williams dcr->serial_number = ~handle[3]; 19293b87356fSDan Williams dcr->code = NFIT_FIC_BYTEN; 19303b87356fSDan Williams dcr->windows = 0; 1931d7d8464dSRoss Zwisler offset += dcr->header.length; 19323b87356fSDan Williams 19336bc75619SDan Williams /* bdw0 (spa/dcr0, dimm0) */ 19346bc75619SDan Williams bdw = nfit_buf + offset; 19356bc75619SDan Williams bdw->header.type = ACPI_NFIT_TYPE_DATA_REGION; 1936d7d8464dSRoss Zwisler bdw->header.length = sizeof(*bdw); 19376bc75619SDan Williams bdw->region_index = 0+1; 19386bc75619SDan Williams bdw->windows = 1; 19396bc75619SDan Williams bdw->offset = 0; 19406bc75619SDan Williams bdw->size = BDW_SIZE; 19416bc75619SDan Williams bdw->capacity = DIMM_SIZE; 19426bc75619SDan Williams bdw->start_address = 0; 1943d7d8464dSRoss Zwisler offset += bdw->header.length; 19446bc75619SDan Williams 19456bc75619SDan Williams /* bdw1 (spa/dcr1, dimm1) */ 1946d7d8464dSRoss Zwisler bdw = nfit_buf + offset; 19476bc75619SDan Williams bdw->header.type = ACPI_NFIT_TYPE_DATA_REGION; 1948d7d8464dSRoss Zwisler bdw->header.length = sizeof(*bdw); 19496bc75619SDan Williams bdw->region_index = 1+1; 19506bc75619SDan Williams bdw->windows = 1; 19516bc75619SDan Williams bdw->offset = 0; 19526bc75619SDan Williams bdw->size = BDW_SIZE; 19536bc75619SDan Williams bdw->capacity = DIMM_SIZE; 19546bc75619SDan Williams bdw->start_address = 0; 1955d7d8464dSRoss Zwisler offset += bdw->header.length; 19566bc75619SDan Williams 19576bc75619SDan Williams /* bdw2 (spa/dcr2, dimm2) */ 1958d7d8464dSRoss Zwisler bdw = nfit_buf + offset; 19596bc75619SDan Williams bdw->header.type = ACPI_NFIT_TYPE_DATA_REGION; 1960d7d8464dSRoss Zwisler bdw->header.length = sizeof(*bdw); 19616bc75619SDan Williams bdw->region_index = 2+1; 19626bc75619SDan Williams bdw->windows = 1; 19636bc75619SDan Williams bdw->offset = 0; 19646bc75619SDan Williams bdw->size = BDW_SIZE; 19656bc75619SDan Williams bdw->capacity = DIMM_SIZE; 19666bc75619SDan Williams bdw->start_address = 0; 1967d7d8464dSRoss Zwisler offset += bdw->header.length; 19686bc75619SDan Williams 19696bc75619SDan Williams /* bdw3 (spa/dcr3, dimm3) */ 1970d7d8464dSRoss Zwisler bdw = nfit_buf + offset; 19716bc75619SDan Williams bdw->header.type = ACPI_NFIT_TYPE_DATA_REGION; 1972d7d8464dSRoss Zwisler bdw->header.length = sizeof(*bdw); 19736bc75619SDan Williams bdw->region_index = 3+1; 19746bc75619SDan Williams bdw->windows = 1; 19756bc75619SDan Williams bdw->offset = 0; 19766bc75619SDan Williams bdw->size = BDW_SIZE; 19776bc75619SDan Williams bdw->capacity = DIMM_SIZE; 19786bc75619SDan Williams bdw->start_address = 0; 1979d7d8464dSRoss Zwisler offset += bdw->header.length; 19806bc75619SDan Williams 19819d27a87eSDan Williams /* flush0 (dimm0) */ 19829d27a87eSDan Williams flush = nfit_buf + offset; 19839d27a87eSDan Williams flush->header.type = ACPI_NFIT_TYPE_FLUSH_ADDRESS; 198485d3fa02SDan Williams flush->header.length = flush_hint_size; 19859d27a87eSDan Williams flush->device_handle = handle[0]; 198685d3fa02SDan Williams flush->hint_count = NUM_HINTS; 198785d3fa02SDan Williams for (i = 0; i < NUM_HINTS; i++) 198885d3fa02SDan Williams flush->hint_address[i] = t->flush_dma[0] + i * sizeof(u64); 1989d7d8464dSRoss Zwisler offset += flush->header.length; 19909d27a87eSDan Williams 19919d27a87eSDan Williams /* flush1 (dimm1) */ 1992d7d8464dSRoss Zwisler flush = nfit_buf + offset; 19939d27a87eSDan Williams flush->header.type = ACPI_NFIT_TYPE_FLUSH_ADDRESS; 199485d3fa02SDan Williams flush->header.length = flush_hint_size; 19959d27a87eSDan Williams flush->device_handle = handle[1]; 199685d3fa02SDan Williams flush->hint_count = NUM_HINTS; 199785d3fa02SDan Williams for (i = 0; i < NUM_HINTS; i++) 199885d3fa02SDan Williams flush->hint_address[i] = t->flush_dma[1] + i * sizeof(u64); 1999d7d8464dSRoss Zwisler offset += flush->header.length; 20009d27a87eSDan Williams 20019d27a87eSDan Williams /* flush2 (dimm2) */ 2002d7d8464dSRoss Zwisler flush = nfit_buf + offset; 20039d27a87eSDan Williams flush->header.type = ACPI_NFIT_TYPE_FLUSH_ADDRESS; 200485d3fa02SDan Williams flush->header.length = flush_hint_size; 20059d27a87eSDan Williams flush->device_handle = handle[2]; 200685d3fa02SDan Williams flush->hint_count = NUM_HINTS; 200785d3fa02SDan Williams for (i = 0; i < NUM_HINTS; i++) 200885d3fa02SDan Williams flush->hint_address[i] = t->flush_dma[2] + i * sizeof(u64); 2009d7d8464dSRoss Zwisler offset += flush->header.length; 20109d27a87eSDan Williams 20119d27a87eSDan Williams /* flush3 (dimm3) */ 2012d7d8464dSRoss Zwisler flush = nfit_buf + offset; 20139d27a87eSDan Williams flush->header.type = ACPI_NFIT_TYPE_FLUSH_ADDRESS; 201485d3fa02SDan Williams flush->header.length = flush_hint_size; 20159d27a87eSDan Williams flush->device_handle = handle[3]; 201685d3fa02SDan Williams flush->hint_count = NUM_HINTS; 201785d3fa02SDan Williams for (i = 0; i < NUM_HINTS; i++) 201885d3fa02SDan Williams flush->hint_address[i] = t->flush_dma[3] + i * sizeof(u64); 2019d7d8464dSRoss Zwisler offset += flush->header.length; 20209d27a87eSDan Williams 2021f81e1d35SDave Jiang /* platform capabilities */ 2022d7d8464dSRoss Zwisler pcap = nfit_buf + offset; 2023f81e1d35SDave Jiang pcap->header.type = ACPI_NFIT_TYPE_CAPABILITIES; 2024f81e1d35SDave Jiang pcap->header.length = sizeof(*pcap); 2025f81e1d35SDave Jiang pcap->highest_capability = 1; 20261273c253SVishal Verma pcap->capabilities = ACPI_NFIT_CAPABILITY_MEM_FLUSH; 2027d7d8464dSRoss Zwisler offset += pcap->header.length; 2028f81e1d35SDave Jiang 202920985164SVishal Verma if (t->setup_hotplug) { 20303b87356fSDan Williams /* dcr-descriptor4: blk */ 203120985164SVishal Verma dcr = nfit_buf + offset; 203220985164SVishal Verma dcr->header.type = ACPI_NFIT_TYPE_CONTROL_REGION; 2033d7d8464dSRoss Zwisler dcr->header.length = sizeof(*dcr); 20343b87356fSDan Williams dcr->region_index = 8+1; 20355dc68e55SDan Williams dcr_common_init(dcr); 203620985164SVishal Verma dcr->serial_number = ~handle[4]; 2037be26f9aeSDan Williams dcr->code = NFIT_FIC_BLK; 203820985164SVishal Verma dcr->windows = 1; 203920985164SVishal Verma dcr->window_size = DCR_SIZE; 204020985164SVishal Verma dcr->command_offset = 0; 204120985164SVishal Verma dcr->command_size = 8; 204220985164SVishal Verma dcr->status_offset = 8; 204320985164SVishal Verma dcr->status_size = 4; 2044d7d8464dSRoss Zwisler offset += dcr->header.length; 204520985164SVishal Verma 20463b87356fSDan Williams /* dcr-descriptor4: pmem */ 20473b87356fSDan Williams dcr = nfit_buf + offset; 20483b87356fSDan Williams dcr->header.type = ACPI_NFIT_TYPE_CONTROL_REGION; 20493b87356fSDan Williams dcr->header.length = offsetof(struct acpi_nfit_control_region, 20503b87356fSDan Williams window_size); 20513b87356fSDan Williams dcr->region_index = 9+1; 20525dc68e55SDan Williams dcr_common_init(dcr); 20533b87356fSDan Williams dcr->serial_number = ~handle[4]; 20543b87356fSDan Williams dcr->code = NFIT_FIC_BYTEN; 20553b87356fSDan Williams dcr->windows = 0; 2056d7d8464dSRoss Zwisler offset += dcr->header.length; 20573b87356fSDan Williams 205820985164SVishal Verma /* bdw4 (spa/dcr4, dimm4) */ 205920985164SVishal Verma bdw = nfit_buf + offset; 206020985164SVishal Verma bdw->header.type = ACPI_NFIT_TYPE_DATA_REGION; 2061d7d8464dSRoss Zwisler bdw->header.length = sizeof(*bdw); 20623b87356fSDan Williams bdw->region_index = 8+1; 206320985164SVishal Verma bdw->windows = 1; 206420985164SVishal Verma bdw->offset = 0; 206520985164SVishal Verma bdw->size = BDW_SIZE; 206620985164SVishal Verma bdw->capacity = DIMM_SIZE; 206720985164SVishal Verma bdw->start_address = 0; 2068d7d8464dSRoss Zwisler offset += bdw->header.length; 206920985164SVishal Verma 207020985164SVishal Verma /* spa10 (dcr4) dimm4 */ 207120985164SVishal Verma spa = nfit_buf + offset; 207220985164SVishal Verma spa->header.type = ACPI_NFIT_TYPE_SYSTEM_ADDRESS; 207320985164SVishal Verma spa->header.length = sizeof(*spa); 207420985164SVishal Verma memcpy(spa->range_guid, to_nfit_uuid(NFIT_SPA_DCR), 16); 207520985164SVishal Verma spa->range_index = 10+1; 207620985164SVishal Verma spa->address = t->dcr_dma[4]; 207720985164SVishal Verma spa->length = DCR_SIZE; 2078d7d8464dSRoss Zwisler offset += spa->header.length; 207920985164SVishal Verma 208020985164SVishal Verma /* 208120985164SVishal Verma * spa11 (single-dimm interleave for hotplug, note storage 208220985164SVishal Verma * does not actually alias the related block-data-window 208320985164SVishal Verma * regions) 208420985164SVishal Verma */ 2085d7d8464dSRoss Zwisler spa = nfit_buf + offset; 208620985164SVishal Verma spa->header.type = ACPI_NFIT_TYPE_SYSTEM_ADDRESS; 208720985164SVishal Verma spa->header.length = sizeof(*spa); 208820985164SVishal Verma memcpy(spa->range_guid, to_nfit_uuid(NFIT_SPA_PM), 16); 208920985164SVishal Verma spa->range_index = 11+1; 209020985164SVishal Verma spa->address = t->spa_set_dma[2]; 209120985164SVishal Verma spa->length = SPA0_SIZE; 2092d7d8464dSRoss Zwisler offset += spa->header.length; 209320985164SVishal Verma 209420985164SVishal Verma /* spa12 (bdw for dcr4) dimm4 */ 2095d7d8464dSRoss Zwisler spa = nfit_buf + offset; 209620985164SVishal Verma spa->header.type = ACPI_NFIT_TYPE_SYSTEM_ADDRESS; 209720985164SVishal Verma spa->header.length = sizeof(*spa); 209820985164SVishal Verma memcpy(spa->range_guid, to_nfit_uuid(NFIT_SPA_BDW), 16); 209920985164SVishal Verma spa->range_index = 12+1; 210020985164SVishal Verma spa->address = t->dimm_dma[4]; 210120985164SVishal Verma spa->length = DIMM_SIZE; 2102d7d8464dSRoss Zwisler offset += spa->header.length; 210320985164SVishal Verma 210420985164SVishal Verma /* mem-region14 (spa/dcr4, dimm4) */ 210520985164SVishal Verma memdev = nfit_buf + offset; 210620985164SVishal Verma memdev->header.type = ACPI_NFIT_TYPE_MEMORY_MAP; 210720985164SVishal Verma memdev->header.length = sizeof(*memdev); 210820985164SVishal Verma memdev->device_handle = handle[4]; 210920985164SVishal Verma memdev->physical_id = 4; 211020985164SVishal Verma memdev->region_id = 0; 211120985164SVishal Verma memdev->range_index = 10+1; 21123b87356fSDan Williams memdev->region_index = 8+1; 211320985164SVishal Verma memdev->region_size = 0; 211420985164SVishal Verma memdev->region_offset = 0; 211520985164SVishal Verma memdev->address = 0; 211620985164SVishal Verma memdev->interleave_index = 0; 211720985164SVishal Verma memdev->interleave_ways = 1; 2118d7d8464dSRoss Zwisler offset += memdev->header.length; 211920985164SVishal Verma 2120d7d8464dSRoss Zwisler /* mem-region15 (spa11, dimm4) */ 2121d7d8464dSRoss Zwisler memdev = nfit_buf + offset; 212220985164SVishal Verma memdev->header.type = ACPI_NFIT_TYPE_MEMORY_MAP; 212320985164SVishal Verma memdev->header.length = sizeof(*memdev); 212420985164SVishal Verma memdev->device_handle = handle[4]; 212520985164SVishal Verma memdev->physical_id = 4; 212620985164SVishal Verma memdev->region_id = 0; 212720985164SVishal Verma memdev->range_index = 11+1; 21283b87356fSDan Williams memdev->region_index = 9+1; 212920985164SVishal Verma memdev->region_size = SPA0_SIZE; 2130df06a2d5SDan Williams memdev->region_offset = (1ULL << 48); 213120985164SVishal Verma memdev->address = 0; 213220985164SVishal Verma memdev->interleave_index = 0; 213320985164SVishal Verma memdev->interleave_ways = 1; 2134ac40b675SDan Williams memdev->flags = ACPI_NFIT_MEM_HEALTH_ENABLED; 2135d7d8464dSRoss Zwisler offset += memdev->header.length; 213620985164SVishal Verma 21373b87356fSDan Williams /* mem-region16 (spa/bdw4, dimm4) */ 2138d7d8464dSRoss Zwisler memdev = nfit_buf + offset; 213920985164SVishal Verma memdev->header.type = ACPI_NFIT_TYPE_MEMORY_MAP; 214020985164SVishal Verma memdev->header.length = sizeof(*memdev); 214120985164SVishal Verma memdev->device_handle = handle[4]; 214220985164SVishal Verma memdev->physical_id = 4; 214320985164SVishal Verma memdev->region_id = 0; 214420985164SVishal Verma memdev->range_index = 12+1; 21453b87356fSDan Williams memdev->region_index = 8+1; 214620985164SVishal Verma memdev->region_size = 0; 214720985164SVishal Verma memdev->region_offset = 0; 214820985164SVishal Verma memdev->address = 0; 214920985164SVishal Verma memdev->interleave_index = 0; 215020985164SVishal Verma memdev->interleave_ways = 1; 2151d7d8464dSRoss Zwisler offset += memdev->header.length; 215220985164SVishal Verma 215320985164SVishal Verma /* flush3 (dimm4) */ 215420985164SVishal Verma flush = nfit_buf + offset; 215520985164SVishal Verma flush->header.type = ACPI_NFIT_TYPE_FLUSH_ADDRESS; 215685d3fa02SDan Williams flush->header.length = flush_hint_size; 215720985164SVishal Verma flush->device_handle = handle[4]; 215885d3fa02SDan Williams flush->hint_count = NUM_HINTS; 215985d3fa02SDan Williams for (i = 0; i < NUM_HINTS; i++) 216085d3fa02SDan Williams flush->hint_address[i] = t->flush_dma[4] 216185d3fa02SDan Williams + i * sizeof(u64); 2162d7d8464dSRoss Zwisler offset += flush->header.length; 21639741a559SRoss Zwisler 21649741a559SRoss Zwisler /* sanity check to make sure we've filled the buffer */ 21659741a559SRoss Zwisler WARN_ON(offset != t->nfit_size); 216620985164SVishal Verma } 216720985164SVishal Verma 21681526f9e2SRoss Zwisler t->nfit_filled = offset; 21691526f9e2SRoss Zwisler 21709fb1a190SDave Jiang post_ars_status(&t->ars_state, &t->badrange, t->spa_set_dma[0], 21719fb1a190SDave Jiang SPA0_SIZE); 2172f471f1a7SDan Williams 21736bc75619SDan Williams acpi_desc = &t->acpi_desc; 2174e3654ecaSDan Williams set_bit(ND_CMD_GET_CONFIG_SIZE, &acpi_desc->dimm_cmd_force_en); 2175e3654ecaSDan Williams set_bit(ND_CMD_GET_CONFIG_DATA, &acpi_desc->dimm_cmd_force_en); 2176e3654ecaSDan Williams set_bit(ND_CMD_SET_CONFIG_DATA, &acpi_desc->dimm_cmd_force_en); 2177ed07c433SDan Williams set_bit(ND_INTEL_SMART, &acpi_desc->dimm_cmd_force_en); 2178ed07c433SDan Williams set_bit(ND_INTEL_SMART_THRESHOLD, &acpi_desc->dimm_cmd_force_en); 2179ed07c433SDan Williams set_bit(ND_INTEL_SMART_SET_THRESHOLD, &acpi_desc->dimm_cmd_force_en); 21804cf260fcSVishal Verma set_bit(ND_INTEL_SMART_INJECT, &acpi_desc->dimm_cmd_force_en); 2181e3654ecaSDan Williams set_bit(ND_CMD_ARS_CAP, &acpi_desc->bus_cmd_force_en); 2182e3654ecaSDan Williams set_bit(ND_CMD_ARS_START, &acpi_desc->bus_cmd_force_en); 2183e3654ecaSDan Williams set_bit(ND_CMD_ARS_STATUS, &acpi_desc->bus_cmd_force_en); 2184e3654ecaSDan Williams set_bit(ND_CMD_CLEAR_ERROR, &acpi_desc->bus_cmd_force_en); 218510246dc8SYasunori Goto set_bit(ND_CMD_CALL, &acpi_desc->bus_cmd_force_en); 218610246dc8SYasunori Goto set_bit(NFIT_CMD_TRANSLATE_SPA, &acpi_desc->bus_nfit_cmd_force_en); 21879fb1a190SDave Jiang set_bit(NFIT_CMD_ARS_INJECT_SET, &acpi_desc->bus_nfit_cmd_force_en); 21889fb1a190SDave Jiang set_bit(NFIT_CMD_ARS_INJECT_CLEAR, &acpi_desc->bus_nfit_cmd_force_en); 21899fb1a190SDave Jiang set_bit(NFIT_CMD_ARS_INJECT_GET, &acpi_desc->bus_nfit_cmd_force_en); 2190bfbaa952SDave Jiang set_bit(ND_INTEL_FW_GET_INFO, &acpi_desc->dimm_cmd_force_en); 2191bfbaa952SDave Jiang set_bit(ND_INTEL_FW_START_UPDATE, &acpi_desc->dimm_cmd_force_en); 2192bfbaa952SDave Jiang set_bit(ND_INTEL_FW_SEND_DATA, &acpi_desc->dimm_cmd_force_en); 2193bfbaa952SDave Jiang set_bit(ND_INTEL_FW_FINISH_UPDATE, &acpi_desc->dimm_cmd_force_en); 2194bfbaa952SDave Jiang set_bit(ND_INTEL_FW_FINISH_QUERY, &acpi_desc->dimm_cmd_force_en); 2195674d8bdeSDave Jiang set_bit(ND_INTEL_ENABLE_LSS_STATUS, &acpi_desc->dimm_cmd_force_en); 21966bc75619SDan Williams } 21976bc75619SDan Williams 21986bc75619SDan Williams static void nfit_test1_setup(struct nfit_test *t) 21996bc75619SDan Williams { 22006b577c9dSLinda Knippers size_t offset; 22016bc75619SDan Williams void *nfit_buf = t->nfit_buf; 22026bc75619SDan Williams struct acpi_nfit_memory_map *memdev; 22036bc75619SDan Williams struct acpi_nfit_control_region *dcr; 22046bc75619SDan Williams struct acpi_nfit_system_address *spa; 2205d26f73f0SDan Williams struct acpi_nfit_desc *acpi_desc; 22066bc75619SDan Williams 22076b577c9dSLinda Knippers offset = 0; 22086bc75619SDan Williams /* spa0 (flat range with no bdw aliasing) */ 22096bc75619SDan Williams spa = nfit_buf + offset; 22106bc75619SDan Williams spa->header.type = ACPI_NFIT_TYPE_SYSTEM_ADDRESS; 22116bc75619SDan Williams spa->header.length = sizeof(*spa); 22126bc75619SDan Williams memcpy(spa->range_guid, to_nfit_uuid(NFIT_SPA_PM), 16); 22136bc75619SDan Williams spa->range_index = 0+1; 22146bc75619SDan Williams spa->address = t->spa_set_dma[0]; 22156bc75619SDan Williams spa->length = SPA2_SIZE; 2216d7d8464dSRoss Zwisler offset += spa->header.length; 22176bc75619SDan Williams 22187bfe97c7SDan Williams /* virtual cd region */ 2219d7d8464dSRoss Zwisler spa = nfit_buf + offset; 22207bfe97c7SDan Williams spa->header.type = ACPI_NFIT_TYPE_SYSTEM_ADDRESS; 22217bfe97c7SDan Williams spa->header.length = sizeof(*spa); 22227bfe97c7SDan Williams memcpy(spa->range_guid, to_nfit_uuid(NFIT_SPA_VCD), 16); 22237bfe97c7SDan Williams spa->range_index = 0; 22247bfe97c7SDan Williams spa->address = t->spa_set_dma[1]; 22257bfe97c7SDan Williams spa->length = SPA_VCD_SIZE; 2226d7d8464dSRoss Zwisler offset += spa->header.length; 22277bfe97c7SDan Williams 22286bc75619SDan Williams /* mem-region0 (spa0, dimm0) */ 22296bc75619SDan Williams memdev = nfit_buf + offset; 22306bc75619SDan Williams memdev->header.type = ACPI_NFIT_TYPE_MEMORY_MAP; 22316bc75619SDan Williams memdev->header.length = sizeof(*memdev); 2232dafb1048SDan Williams memdev->device_handle = handle[5]; 22336bc75619SDan Williams memdev->physical_id = 0; 22346bc75619SDan Williams memdev->region_id = 0; 22356bc75619SDan Williams memdev->range_index = 0+1; 22366bc75619SDan Williams memdev->region_index = 0+1; 22376bc75619SDan Williams memdev->region_size = SPA2_SIZE; 22386bc75619SDan Williams memdev->region_offset = 0; 22396bc75619SDan Williams memdev->address = 0; 22406bc75619SDan Williams memdev->interleave_index = 0; 22416bc75619SDan Williams memdev->interleave_ways = 1; 224258138820SDan Williams memdev->flags = ACPI_NFIT_MEM_SAVE_FAILED | ACPI_NFIT_MEM_RESTORE_FAILED 224358138820SDan Williams | ACPI_NFIT_MEM_FLUSH_FAILED | ACPI_NFIT_MEM_HEALTH_OBSERVED 2244f4295796SDan Williams | ACPI_NFIT_MEM_NOT_ARMED; 2245d7d8464dSRoss Zwisler offset += memdev->header.length; 22466bc75619SDan Williams 22476bc75619SDan Williams /* dcr-descriptor0 */ 22486bc75619SDan Williams dcr = nfit_buf + offset; 22496bc75619SDan Williams dcr->header.type = ACPI_NFIT_TYPE_CONTROL_REGION; 22503b87356fSDan Williams dcr->header.length = offsetof(struct acpi_nfit_control_region, 22513b87356fSDan Williams window_size); 22526bc75619SDan Williams dcr->region_index = 0+1; 22535dc68e55SDan Williams dcr_common_init(dcr); 2254dafb1048SDan Williams dcr->serial_number = ~handle[5]; 2255be26f9aeSDan Williams dcr->code = NFIT_FIC_BYTE; 22566bc75619SDan Williams dcr->windows = 0; 2257ac40b675SDan Williams offset += dcr->header.length; 2258d7d8464dSRoss Zwisler 2259ac40b675SDan Williams memdev = nfit_buf + offset; 2260ac40b675SDan Williams memdev->header.type = ACPI_NFIT_TYPE_MEMORY_MAP; 2261ac40b675SDan Williams memdev->header.length = sizeof(*memdev); 2262ac40b675SDan Williams memdev->device_handle = handle[6]; 2263ac40b675SDan Williams memdev->physical_id = 0; 2264ac40b675SDan Williams memdev->region_id = 0; 2265ac40b675SDan Williams memdev->range_index = 0; 2266ac40b675SDan Williams memdev->region_index = 0+2; 2267ac40b675SDan Williams memdev->region_size = SPA2_SIZE; 2268ac40b675SDan Williams memdev->region_offset = 0; 2269ac40b675SDan Williams memdev->address = 0; 2270ac40b675SDan Williams memdev->interleave_index = 0; 2271ac40b675SDan Williams memdev->interleave_ways = 1; 2272ac40b675SDan Williams memdev->flags = ACPI_NFIT_MEM_MAP_FAILED; 2273d7d8464dSRoss Zwisler offset += memdev->header.length; 2274ac40b675SDan Williams 2275ac40b675SDan Williams /* dcr-descriptor1 */ 2276ac40b675SDan Williams dcr = nfit_buf + offset; 2277ac40b675SDan Williams dcr->header.type = ACPI_NFIT_TYPE_CONTROL_REGION; 2278ac40b675SDan Williams dcr->header.length = offsetof(struct acpi_nfit_control_region, 2279ac40b675SDan Williams window_size); 2280ac40b675SDan Williams dcr->region_index = 0+2; 2281ac40b675SDan Williams dcr_common_init(dcr); 2282ac40b675SDan Williams dcr->serial_number = ~handle[6]; 2283ac40b675SDan Williams dcr->code = NFIT_FIC_BYTE; 2284ac40b675SDan Williams dcr->windows = 0; 2285d7d8464dSRoss Zwisler offset += dcr->header.length; 2286ac40b675SDan Williams 22879741a559SRoss Zwisler /* sanity check to make sure we've filled the buffer */ 22889741a559SRoss Zwisler WARN_ON(offset != t->nfit_size); 22899741a559SRoss Zwisler 22901526f9e2SRoss Zwisler t->nfit_filled = offset; 22911526f9e2SRoss Zwisler 22929fb1a190SDave Jiang post_ars_status(&t->ars_state, &t->badrange, t->spa_set_dma[0], 22939fb1a190SDave Jiang SPA2_SIZE); 2294f471f1a7SDan Williams 2295d26f73f0SDan Williams acpi_desc = &t->acpi_desc; 2296e3654ecaSDan Williams set_bit(ND_CMD_ARS_CAP, &acpi_desc->bus_cmd_force_en); 2297e3654ecaSDan Williams set_bit(ND_CMD_ARS_START, &acpi_desc->bus_cmd_force_en); 2298e3654ecaSDan Williams set_bit(ND_CMD_ARS_STATUS, &acpi_desc->bus_cmd_force_en); 2299e3654ecaSDan Williams set_bit(ND_CMD_CLEAR_ERROR, &acpi_desc->bus_cmd_force_en); 2300674d8bdeSDave Jiang set_bit(ND_INTEL_ENABLE_LSS_STATUS, &acpi_desc->dimm_cmd_force_en); 23019484e12dSDan Williams set_bit(ND_CMD_GET_CONFIG_SIZE, &acpi_desc->dimm_cmd_force_en); 23029484e12dSDan Williams set_bit(ND_CMD_GET_CONFIG_DATA, &acpi_desc->dimm_cmd_force_en); 23039484e12dSDan Williams set_bit(ND_CMD_SET_CONFIG_DATA, &acpi_desc->dimm_cmd_force_en); 23046bc75619SDan Williams } 23056bc75619SDan Williams 23066bc75619SDan Williams static int nfit_test_blk_do_io(struct nd_blk_region *ndbr, resource_size_t dpa, 23076bc75619SDan Williams void *iobuf, u64 len, int rw) 23086bc75619SDan Williams { 23096bc75619SDan Williams struct nfit_blk *nfit_blk = ndbr->blk_provider_data; 23106bc75619SDan Williams struct nfit_blk_mmio *mmio = &nfit_blk->mmio[BDW]; 23116bc75619SDan Williams struct nd_region *nd_region = &ndbr->nd_region; 23126bc75619SDan Williams unsigned int lane; 23136bc75619SDan Williams 23146bc75619SDan Williams lane = nd_region_acquire_lane(nd_region); 23156bc75619SDan Williams if (rw) 231667a3e8feSRoss Zwisler memcpy(mmio->addr.base + dpa, iobuf, len); 231767a3e8feSRoss Zwisler else { 231867a3e8feSRoss Zwisler memcpy(iobuf, mmio->addr.base + dpa, len); 231967a3e8feSRoss Zwisler 23205deb67f7SRobin Murphy /* give us some some coverage of the arch_invalidate_pmem() API */ 23215deb67f7SRobin Murphy arch_invalidate_pmem(mmio->addr.base + dpa, len); 232267a3e8feSRoss Zwisler } 23236bc75619SDan Williams nd_region_release_lane(nd_region, lane); 23246bc75619SDan Williams 23256bc75619SDan Williams return 0; 23266bc75619SDan Williams } 23276bc75619SDan Williams 2328a7de92daSDan Williams static unsigned long nfit_ctl_handle; 2329a7de92daSDan Williams 2330a7de92daSDan Williams union acpi_object *result; 2331a7de92daSDan Williams 2332a7de92daSDan Williams static union acpi_object *nfit_test_evaluate_dsm(acpi_handle handle, 233394116f81SAndy Shevchenko const guid_t *guid, u64 rev, u64 func, union acpi_object *argv4) 2334a7de92daSDan Williams { 2335a7de92daSDan Williams if (handle != &nfit_ctl_handle) 2336a7de92daSDan Williams return ERR_PTR(-ENXIO); 2337a7de92daSDan Williams 2338a7de92daSDan Williams return result; 2339a7de92daSDan Williams } 2340a7de92daSDan Williams 2341a7de92daSDan Williams static int setup_result(void *buf, size_t size) 2342a7de92daSDan Williams { 2343a7de92daSDan Williams result = kmalloc(sizeof(union acpi_object) + size, GFP_KERNEL); 2344a7de92daSDan Williams if (!result) 2345a7de92daSDan Williams return -ENOMEM; 2346a7de92daSDan Williams result->package.type = ACPI_TYPE_BUFFER, 2347a7de92daSDan Williams result->buffer.pointer = (void *) (result + 1); 2348a7de92daSDan Williams result->buffer.length = size; 2349a7de92daSDan Williams memcpy(result->buffer.pointer, buf, size); 2350a7de92daSDan Williams memset(buf, 0, size); 2351a7de92daSDan Williams return 0; 2352a7de92daSDan Williams } 2353a7de92daSDan Williams 2354a7de92daSDan Williams static int nfit_ctl_test(struct device *dev) 2355a7de92daSDan Williams { 2356a7de92daSDan Williams int rc, cmd_rc; 2357a7de92daSDan Williams struct nvdimm *nvdimm; 2358a7de92daSDan Williams struct acpi_device *adev; 2359a7de92daSDan Williams struct nfit_mem *nfit_mem; 2360a7de92daSDan Williams struct nd_ars_record *record; 2361a7de92daSDan Williams struct acpi_nfit_desc *acpi_desc; 2362a7de92daSDan Williams const u64 test_val = 0x0123456789abcdefULL; 2363a7de92daSDan Williams unsigned long mask, cmd_size, offset; 2364a7de92daSDan Williams union { 2365a7de92daSDan Williams struct nd_cmd_get_config_size cfg_size; 2366fb2a1748SDan Williams struct nd_cmd_clear_error clear_err; 2367a7de92daSDan Williams struct nd_cmd_ars_status ars_stat; 2368a7de92daSDan Williams struct nd_cmd_ars_cap ars_cap; 2369a7de92daSDan Williams char buf[sizeof(struct nd_cmd_ars_status) 2370a7de92daSDan Williams + sizeof(struct nd_ars_record)]; 2371a7de92daSDan Williams } cmds; 2372a7de92daSDan Williams 2373a7de92daSDan Williams adev = devm_kzalloc(dev, sizeof(*adev), GFP_KERNEL); 2374a7de92daSDan Williams if (!adev) 2375a7de92daSDan Williams return -ENOMEM; 2376a7de92daSDan Williams *adev = (struct acpi_device) { 2377a7de92daSDan Williams .handle = &nfit_ctl_handle, 2378a7de92daSDan Williams .dev = { 2379a7de92daSDan Williams .init_name = "test-adev", 2380a7de92daSDan Williams }, 2381a7de92daSDan Williams }; 2382a7de92daSDan Williams 2383a7de92daSDan Williams acpi_desc = devm_kzalloc(dev, sizeof(*acpi_desc), GFP_KERNEL); 2384a7de92daSDan Williams if (!acpi_desc) 2385a7de92daSDan Williams return -ENOMEM; 2386a7de92daSDan Williams *acpi_desc = (struct acpi_nfit_desc) { 2387a7de92daSDan Williams .nd_desc = { 2388a7de92daSDan Williams .cmd_mask = 1UL << ND_CMD_ARS_CAP 2389a7de92daSDan Williams | 1UL << ND_CMD_ARS_START 2390a7de92daSDan Williams | 1UL << ND_CMD_ARS_STATUS 239110246dc8SYasunori Goto | 1UL << ND_CMD_CLEAR_ERROR 239210246dc8SYasunori Goto | 1UL << ND_CMD_CALL, 2393a7de92daSDan Williams .module = THIS_MODULE, 2394a7de92daSDan Williams .provider_name = "ACPI.NFIT", 2395a7de92daSDan Williams .ndctl = acpi_nfit_ctl, 23969fb1a190SDave Jiang .bus_dsm_mask = 1UL << NFIT_CMD_TRANSLATE_SPA 23979fb1a190SDave Jiang | 1UL << NFIT_CMD_ARS_INJECT_SET 23989fb1a190SDave Jiang | 1UL << NFIT_CMD_ARS_INJECT_CLEAR 23999fb1a190SDave Jiang | 1UL << NFIT_CMD_ARS_INJECT_GET, 2400a7de92daSDan Williams }, 2401a7de92daSDan Williams .dev = &adev->dev, 2402a7de92daSDan Williams }; 2403a7de92daSDan Williams 2404a7de92daSDan Williams nfit_mem = devm_kzalloc(dev, sizeof(*nfit_mem), GFP_KERNEL); 2405a7de92daSDan Williams if (!nfit_mem) 2406a7de92daSDan Williams return -ENOMEM; 2407a7de92daSDan Williams 2408a7de92daSDan Williams mask = 1UL << ND_CMD_SMART | 1UL << ND_CMD_SMART_THRESHOLD 2409a7de92daSDan Williams | 1UL << ND_CMD_DIMM_FLAGS | 1UL << ND_CMD_GET_CONFIG_SIZE 2410a7de92daSDan Williams | 1UL << ND_CMD_GET_CONFIG_DATA | 1UL << ND_CMD_SET_CONFIG_DATA 2411a7de92daSDan Williams | 1UL << ND_CMD_VENDOR; 2412a7de92daSDan Williams *nfit_mem = (struct nfit_mem) { 2413a7de92daSDan Williams .adev = adev, 2414a7de92daSDan Williams .family = NVDIMM_FAMILY_INTEL, 2415a7de92daSDan Williams .dsm_mask = mask, 2416a7de92daSDan Williams }; 2417a7de92daSDan Williams 2418a7de92daSDan Williams nvdimm = devm_kzalloc(dev, sizeof(*nvdimm), GFP_KERNEL); 2419a7de92daSDan Williams if (!nvdimm) 2420a7de92daSDan Williams return -ENOMEM; 2421a7de92daSDan Williams *nvdimm = (struct nvdimm) { 2422a7de92daSDan Williams .provider_data = nfit_mem, 2423a7de92daSDan Williams .cmd_mask = mask, 2424a7de92daSDan Williams .dev = { 2425a7de92daSDan Williams .init_name = "test-dimm", 2426a7de92daSDan Williams }, 2427a7de92daSDan Williams }; 2428a7de92daSDan Williams 2429a7de92daSDan Williams 2430a7de92daSDan Williams /* basic checkout of a typical 'get config size' command */ 2431a7de92daSDan Williams cmd_size = sizeof(cmds.cfg_size); 2432a7de92daSDan Williams cmds.cfg_size = (struct nd_cmd_get_config_size) { 2433a7de92daSDan Williams .status = 0, 2434a7de92daSDan Williams .config_size = SZ_128K, 2435a7de92daSDan Williams .max_xfer = SZ_4K, 2436a7de92daSDan Williams }; 2437a7de92daSDan Williams rc = setup_result(cmds.buf, cmd_size); 2438a7de92daSDan Williams if (rc) 2439a7de92daSDan Williams return rc; 2440a7de92daSDan Williams rc = acpi_nfit_ctl(&acpi_desc->nd_desc, nvdimm, ND_CMD_GET_CONFIG_SIZE, 2441a7de92daSDan Williams cmds.buf, cmd_size, &cmd_rc); 2442a7de92daSDan Williams 2443a7de92daSDan Williams if (rc < 0 || cmd_rc || cmds.cfg_size.status != 0 2444a7de92daSDan Williams || cmds.cfg_size.config_size != SZ_128K 2445a7de92daSDan Williams || cmds.cfg_size.max_xfer != SZ_4K) { 2446a7de92daSDan Williams dev_dbg(dev, "%s: failed at: %d rc: %d cmd_rc: %d\n", 2447a7de92daSDan Williams __func__, __LINE__, rc, cmd_rc); 2448a7de92daSDan Williams return -EIO; 2449a7de92daSDan Williams } 2450a7de92daSDan Williams 2451a7de92daSDan Williams 2452a7de92daSDan Williams /* test ars_status with zero output */ 2453a7de92daSDan Williams cmd_size = offsetof(struct nd_cmd_ars_status, address); 2454a7de92daSDan Williams cmds.ars_stat = (struct nd_cmd_ars_status) { 2455a7de92daSDan Williams .out_length = 0, 2456a7de92daSDan Williams }; 2457a7de92daSDan Williams rc = setup_result(cmds.buf, cmd_size); 2458a7de92daSDan Williams if (rc) 2459a7de92daSDan Williams return rc; 2460a7de92daSDan Williams rc = acpi_nfit_ctl(&acpi_desc->nd_desc, NULL, ND_CMD_ARS_STATUS, 2461a7de92daSDan Williams cmds.buf, cmd_size, &cmd_rc); 2462a7de92daSDan Williams 2463a7de92daSDan Williams if (rc < 0 || cmd_rc) { 2464a7de92daSDan Williams dev_dbg(dev, "%s: failed at: %d rc: %d cmd_rc: %d\n", 2465a7de92daSDan Williams __func__, __LINE__, rc, cmd_rc); 2466a7de92daSDan Williams return -EIO; 2467a7de92daSDan Williams } 2468a7de92daSDan Williams 2469a7de92daSDan Williams 2470a7de92daSDan Williams /* test ars_cap with benign extended status */ 2471a7de92daSDan Williams cmd_size = sizeof(cmds.ars_cap); 2472a7de92daSDan Williams cmds.ars_cap = (struct nd_cmd_ars_cap) { 2473a7de92daSDan Williams .status = ND_ARS_PERSISTENT << 16, 2474a7de92daSDan Williams }; 2475a7de92daSDan Williams offset = offsetof(struct nd_cmd_ars_cap, status); 2476a7de92daSDan Williams rc = setup_result(cmds.buf + offset, cmd_size - offset); 2477a7de92daSDan Williams if (rc) 2478a7de92daSDan Williams return rc; 2479a7de92daSDan Williams rc = acpi_nfit_ctl(&acpi_desc->nd_desc, NULL, ND_CMD_ARS_CAP, 2480a7de92daSDan Williams cmds.buf, cmd_size, &cmd_rc); 2481a7de92daSDan Williams 2482a7de92daSDan Williams if (rc < 0 || cmd_rc) { 2483a7de92daSDan Williams dev_dbg(dev, "%s: failed at: %d rc: %d cmd_rc: %d\n", 2484a7de92daSDan Williams __func__, __LINE__, rc, cmd_rc); 2485a7de92daSDan Williams return -EIO; 2486a7de92daSDan Williams } 2487a7de92daSDan Williams 2488a7de92daSDan Williams 2489a7de92daSDan Williams /* test ars_status with 'status' trimmed from 'out_length' */ 2490a7de92daSDan Williams cmd_size = sizeof(cmds.ars_stat) + sizeof(struct nd_ars_record); 2491a7de92daSDan Williams cmds.ars_stat = (struct nd_cmd_ars_status) { 2492a7de92daSDan Williams .out_length = cmd_size - 4, 2493a7de92daSDan Williams }; 2494a7de92daSDan Williams record = &cmds.ars_stat.records[0]; 2495a7de92daSDan Williams *record = (struct nd_ars_record) { 2496a7de92daSDan Williams .length = test_val, 2497a7de92daSDan Williams }; 2498a7de92daSDan Williams rc = setup_result(cmds.buf, cmd_size); 2499a7de92daSDan Williams if (rc) 2500a7de92daSDan Williams return rc; 2501a7de92daSDan Williams rc = acpi_nfit_ctl(&acpi_desc->nd_desc, NULL, ND_CMD_ARS_STATUS, 2502a7de92daSDan Williams cmds.buf, cmd_size, &cmd_rc); 2503a7de92daSDan Williams 2504a7de92daSDan Williams if (rc < 0 || cmd_rc || record->length != test_val) { 2505a7de92daSDan Williams dev_dbg(dev, "%s: failed at: %d rc: %d cmd_rc: %d\n", 2506a7de92daSDan Williams __func__, __LINE__, rc, cmd_rc); 2507a7de92daSDan Williams return -EIO; 2508a7de92daSDan Williams } 2509a7de92daSDan Williams 2510a7de92daSDan Williams 2511a7de92daSDan Williams /* test ars_status with 'Output (Size)' including 'status' */ 2512a7de92daSDan Williams cmd_size = sizeof(cmds.ars_stat) + sizeof(struct nd_ars_record); 2513a7de92daSDan Williams cmds.ars_stat = (struct nd_cmd_ars_status) { 2514a7de92daSDan Williams .out_length = cmd_size, 2515a7de92daSDan Williams }; 2516a7de92daSDan Williams record = &cmds.ars_stat.records[0]; 2517a7de92daSDan Williams *record = (struct nd_ars_record) { 2518a7de92daSDan Williams .length = test_val, 2519a7de92daSDan Williams }; 2520a7de92daSDan Williams rc = setup_result(cmds.buf, cmd_size); 2521a7de92daSDan Williams if (rc) 2522a7de92daSDan Williams return rc; 2523a7de92daSDan Williams rc = acpi_nfit_ctl(&acpi_desc->nd_desc, NULL, ND_CMD_ARS_STATUS, 2524a7de92daSDan Williams cmds.buf, cmd_size, &cmd_rc); 2525a7de92daSDan Williams 2526a7de92daSDan Williams if (rc < 0 || cmd_rc || record->length != test_val) { 2527a7de92daSDan Williams dev_dbg(dev, "%s: failed at: %d rc: %d cmd_rc: %d\n", 2528a7de92daSDan Williams __func__, __LINE__, rc, cmd_rc); 2529a7de92daSDan Williams return -EIO; 2530a7de92daSDan Williams } 2531a7de92daSDan Williams 2532a7de92daSDan Williams 2533a7de92daSDan Williams /* test extended status for get_config_size results in failure */ 2534a7de92daSDan Williams cmd_size = sizeof(cmds.cfg_size); 2535a7de92daSDan Williams cmds.cfg_size = (struct nd_cmd_get_config_size) { 2536a7de92daSDan Williams .status = 1 << 16, 2537a7de92daSDan Williams }; 2538a7de92daSDan Williams rc = setup_result(cmds.buf, cmd_size); 2539a7de92daSDan Williams if (rc) 2540a7de92daSDan Williams return rc; 2541a7de92daSDan Williams rc = acpi_nfit_ctl(&acpi_desc->nd_desc, nvdimm, ND_CMD_GET_CONFIG_SIZE, 2542a7de92daSDan Williams cmds.buf, cmd_size, &cmd_rc); 2543a7de92daSDan Williams 2544a7de92daSDan Williams if (rc < 0 || cmd_rc >= 0) { 2545a7de92daSDan Williams dev_dbg(dev, "%s: failed at: %d rc: %d cmd_rc: %d\n", 2546a7de92daSDan Williams __func__, __LINE__, rc, cmd_rc); 2547a7de92daSDan Williams return -EIO; 2548a7de92daSDan Williams } 2549a7de92daSDan Williams 2550fb2a1748SDan Williams /* test clear error */ 2551fb2a1748SDan Williams cmd_size = sizeof(cmds.clear_err); 2552fb2a1748SDan Williams cmds.clear_err = (struct nd_cmd_clear_error) { 2553fb2a1748SDan Williams .length = 512, 2554fb2a1748SDan Williams .cleared = 512, 2555fb2a1748SDan Williams }; 2556fb2a1748SDan Williams rc = setup_result(cmds.buf, cmd_size); 2557fb2a1748SDan Williams if (rc) 2558fb2a1748SDan Williams return rc; 2559fb2a1748SDan Williams rc = acpi_nfit_ctl(&acpi_desc->nd_desc, NULL, ND_CMD_CLEAR_ERROR, 2560fb2a1748SDan Williams cmds.buf, cmd_size, &cmd_rc); 2561fb2a1748SDan Williams if (rc < 0 || cmd_rc) { 2562fb2a1748SDan Williams dev_dbg(dev, "%s: failed at: %d rc: %d cmd_rc: %d\n", 2563fb2a1748SDan Williams __func__, __LINE__, rc, cmd_rc); 2564fb2a1748SDan Williams return -EIO; 2565fb2a1748SDan Williams } 2566fb2a1748SDan Williams 2567a7de92daSDan Williams return 0; 2568a7de92daSDan Williams } 2569a7de92daSDan Williams 25706bc75619SDan Williams static int nfit_test_probe(struct platform_device *pdev) 25716bc75619SDan Williams { 25726bc75619SDan Williams struct nvdimm_bus_descriptor *nd_desc; 25736bc75619SDan Williams struct acpi_nfit_desc *acpi_desc; 25746bc75619SDan Williams struct device *dev = &pdev->dev; 25756bc75619SDan Williams struct nfit_test *nfit_test; 2576231bf117SDan Williams struct nfit_mem *nfit_mem; 2577c14a868aSDan Williams union acpi_object *obj; 25786bc75619SDan Williams int rc; 25796bc75619SDan Williams 2580a7de92daSDan Williams if (strcmp(dev_name(&pdev->dev), "nfit_test.0") == 0) { 2581a7de92daSDan Williams rc = nfit_ctl_test(&pdev->dev); 2582a7de92daSDan Williams if (rc) 2583a7de92daSDan Williams return rc; 2584a7de92daSDan Williams } 2585a7de92daSDan Williams 25866bc75619SDan Williams nfit_test = to_nfit_test(&pdev->dev); 25876bc75619SDan Williams 25886bc75619SDan Williams /* common alloc */ 25896bc75619SDan Williams if (nfit_test->num_dcr) { 25906bc75619SDan Williams int num = nfit_test->num_dcr; 25916bc75619SDan Williams 25926bc75619SDan Williams nfit_test->dimm = devm_kcalloc(dev, num, sizeof(void *), 25936bc75619SDan Williams GFP_KERNEL); 25946bc75619SDan Williams nfit_test->dimm_dma = devm_kcalloc(dev, num, sizeof(dma_addr_t), 25956bc75619SDan Williams GFP_KERNEL); 25969d27a87eSDan Williams nfit_test->flush = devm_kcalloc(dev, num, sizeof(void *), 25979d27a87eSDan Williams GFP_KERNEL); 25989d27a87eSDan Williams nfit_test->flush_dma = devm_kcalloc(dev, num, sizeof(dma_addr_t), 25999d27a87eSDan Williams GFP_KERNEL); 26006bc75619SDan Williams nfit_test->label = devm_kcalloc(dev, num, sizeof(void *), 26016bc75619SDan Williams GFP_KERNEL); 26026bc75619SDan Williams nfit_test->label_dma = devm_kcalloc(dev, num, 26036bc75619SDan Williams sizeof(dma_addr_t), GFP_KERNEL); 26046bc75619SDan Williams nfit_test->dcr = devm_kcalloc(dev, num, 26056bc75619SDan Williams sizeof(struct nfit_test_dcr *), GFP_KERNEL); 26066bc75619SDan Williams nfit_test->dcr_dma = devm_kcalloc(dev, num, 26076bc75619SDan Williams sizeof(dma_addr_t), GFP_KERNEL); 2608ed07c433SDan Williams nfit_test->smart = devm_kcalloc(dev, num, 2609ed07c433SDan Williams sizeof(struct nd_intel_smart), GFP_KERNEL); 2610ed07c433SDan Williams nfit_test->smart_threshold = devm_kcalloc(dev, num, 2611ed07c433SDan Williams sizeof(struct nd_intel_smart_threshold), 2612ed07c433SDan Williams GFP_KERNEL); 2613bfbaa952SDave Jiang nfit_test->fw = devm_kcalloc(dev, num, 2614bfbaa952SDave Jiang sizeof(struct nfit_test_fw), GFP_KERNEL); 26156bc75619SDan Williams if (nfit_test->dimm && nfit_test->dimm_dma && nfit_test->label 26166bc75619SDan Williams && nfit_test->label_dma && nfit_test->dcr 26179d27a87eSDan Williams && nfit_test->dcr_dma && nfit_test->flush 2618bfbaa952SDave Jiang && nfit_test->flush_dma 2619bfbaa952SDave Jiang && nfit_test->fw) 26206bc75619SDan Williams /* pass */; 26216bc75619SDan Williams else 26226bc75619SDan Williams return -ENOMEM; 26236bc75619SDan Williams } 26246bc75619SDan Williams 26256bc75619SDan Williams if (nfit_test->num_pm) { 26266bc75619SDan Williams int num = nfit_test->num_pm; 26276bc75619SDan Williams 26286bc75619SDan Williams nfit_test->spa_set = devm_kcalloc(dev, num, sizeof(void *), 26296bc75619SDan Williams GFP_KERNEL); 26306bc75619SDan Williams nfit_test->spa_set_dma = devm_kcalloc(dev, num, 26316bc75619SDan Williams sizeof(dma_addr_t), GFP_KERNEL); 26326bc75619SDan Williams if (nfit_test->spa_set && nfit_test->spa_set_dma) 26336bc75619SDan Williams /* pass */; 26346bc75619SDan Williams else 26356bc75619SDan Williams return -ENOMEM; 26366bc75619SDan Williams } 26376bc75619SDan Williams 26386bc75619SDan Williams /* per-nfit specific alloc */ 26396bc75619SDan Williams if (nfit_test->alloc(nfit_test)) 26406bc75619SDan Williams return -ENOMEM; 26416bc75619SDan Williams 26426bc75619SDan Williams nfit_test->setup(nfit_test); 26436bc75619SDan Williams acpi_desc = &nfit_test->acpi_desc; 2644a61fe6f7SDan Williams acpi_nfit_desc_init(acpi_desc, &pdev->dev); 26456bc75619SDan Williams acpi_desc->blk_do_io = nfit_test_blk_do_io; 26466bc75619SDan Williams nd_desc = &acpi_desc->nd_desc; 2647a61fe6f7SDan Williams nd_desc->provider_name = NULL; 2648bc9775d8SDan Williams nd_desc->module = THIS_MODULE; 2649a61fe6f7SDan Williams nd_desc->ndctl = nfit_test_ctl; 26506bc75619SDan Williams 2651e7a11b44SDan Williams rc = acpi_nfit_init(acpi_desc, nfit_test->nfit_buf, 26521526f9e2SRoss Zwisler nfit_test->nfit_filled); 265358cd71b4SDan Williams if (rc) 265420985164SVishal Verma return rc; 265520985164SVishal Verma 2656fbabd829SDan Williams rc = devm_add_action_or_reset(&pdev->dev, acpi_nfit_shutdown, acpi_desc); 2657fbabd829SDan Williams if (rc) 2658fbabd829SDan Williams return rc; 2659fbabd829SDan Williams 266020985164SVishal Verma if (nfit_test->setup != nfit_test0_setup) 266120985164SVishal Verma return 0; 266220985164SVishal Verma 266320985164SVishal Verma nfit_test->setup_hotplug = 1; 266420985164SVishal Verma nfit_test->setup(nfit_test); 266520985164SVishal Verma 2666c14a868aSDan Williams obj = kzalloc(sizeof(*obj), GFP_KERNEL); 2667c14a868aSDan Williams if (!obj) 2668c14a868aSDan Williams return -ENOMEM; 2669c14a868aSDan Williams obj->type = ACPI_TYPE_BUFFER; 2670c14a868aSDan Williams obj->buffer.length = nfit_test->nfit_size; 2671c14a868aSDan Williams obj->buffer.pointer = nfit_test->nfit_buf; 2672c14a868aSDan Williams *(nfit_test->_fit) = obj; 2673c14a868aSDan Williams __acpi_nfit_notify(&pdev->dev, nfit_test, 0x80); 2674231bf117SDan Williams 2675231bf117SDan Williams /* associate dimm devices with nfit_mem data for notification testing */ 2676231bf117SDan Williams mutex_lock(&acpi_desc->init_mutex); 2677231bf117SDan Williams list_for_each_entry(nfit_mem, &acpi_desc->dimms, list) { 2678231bf117SDan Williams u32 nfit_handle = __to_nfit_memdev(nfit_mem)->device_handle; 2679231bf117SDan Williams int i; 2680231bf117SDan Williams 2681231bf117SDan Williams for (i = 0; i < NUM_DCR; i++) 2682231bf117SDan Williams if (nfit_handle == handle[i]) 2683231bf117SDan Williams dev_set_drvdata(nfit_test->dimm_dev[i], 2684231bf117SDan Williams nfit_mem); 2685231bf117SDan Williams } 2686231bf117SDan Williams mutex_unlock(&acpi_desc->init_mutex); 26876bc75619SDan Williams 26886bc75619SDan Williams return 0; 26896bc75619SDan Williams } 26906bc75619SDan Williams 26916bc75619SDan Williams static int nfit_test_remove(struct platform_device *pdev) 26926bc75619SDan Williams { 26936bc75619SDan Williams return 0; 26946bc75619SDan Williams } 26956bc75619SDan Williams 26966bc75619SDan Williams static void nfit_test_release(struct device *dev) 26976bc75619SDan Williams { 26986bc75619SDan Williams struct nfit_test *nfit_test = to_nfit_test(dev); 26996bc75619SDan Williams 27006bc75619SDan Williams kfree(nfit_test); 27016bc75619SDan Williams } 27026bc75619SDan Williams 27036bc75619SDan Williams static const struct platform_device_id nfit_test_id[] = { 27046bc75619SDan Williams { KBUILD_MODNAME }, 27056bc75619SDan Williams { }, 27066bc75619SDan Williams }; 27076bc75619SDan Williams 27086bc75619SDan Williams static struct platform_driver nfit_test_driver = { 27096bc75619SDan Williams .probe = nfit_test_probe, 27106bc75619SDan Williams .remove = nfit_test_remove, 27116bc75619SDan Williams .driver = { 27126bc75619SDan Williams .name = KBUILD_MODNAME, 27136bc75619SDan Williams }, 27146bc75619SDan Williams .id_table = nfit_test_id, 27156bc75619SDan Williams }; 27166bc75619SDan Williams 27175d8beee2SDan Williams static char mcsafe_buf[PAGE_SIZE] __attribute__((__aligned__(PAGE_SIZE))); 27185d8beee2SDan Williams 27195d8beee2SDan Williams enum INJECT { 27205d8beee2SDan Williams INJECT_NONE, 27215d8beee2SDan Williams INJECT_SRC, 27225d8beee2SDan Williams INJECT_DST, 27235d8beee2SDan Williams }; 27245d8beee2SDan Williams 27255d8beee2SDan Williams static void mcsafe_test_init(char *dst, char *src, size_t size) 27265d8beee2SDan Williams { 27275d8beee2SDan Williams size_t i; 27285d8beee2SDan Williams 27295d8beee2SDan Williams memset(dst, 0xff, size); 27305d8beee2SDan Williams for (i = 0; i < size; i++) 27315d8beee2SDan Williams src[i] = (char) i; 27325d8beee2SDan Williams } 27335d8beee2SDan Williams 27345d8beee2SDan Williams static bool mcsafe_test_validate(unsigned char *dst, unsigned char *src, 27355d8beee2SDan Williams size_t size, unsigned long rem) 27365d8beee2SDan Williams { 27375d8beee2SDan Williams size_t i; 27385d8beee2SDan Williams 27395d8beee2SDan Williams for (i = 0; i < size - rem; i++) 27405d8beee2SDan Williams if (dst[i] != (unsigned char) i) { 27415d8beee2SDan Williams pr_info_once("%s:%d: offset: %zd got: %#x expect: %#x\n", 27425d8beee2SDan Williams __func__, __LINE__, i, dst[i], 27435d8beee2SDan Williams (unsigned char) i); 27445d8beee2SDan Williams return false; 27455d8beee2SDan Williams } 27465d8beee2SDan Williams for (i = size - rem; i < size; i++) 27475d8beee2SDan Williams if (dst[i] != 0xffU) { 27485d8beee2SDan Williams pr_info_once("%s:%d: offset: %zd got: %#x expect: 0xff\n", 27495d8beee2SDan Williams __func__, __LINE__, i, dst[i]); 27505d8beee2SDan Williams return false; 27515d8beee2SDan Williams } 27525d8beee2SDan Williams return true; 27535d8beee2SDan Williams } 27545d8beee2SDan Williams 27555d8beee2SDan Williams void mcsafe_test(void) 27565d8beee2SDan Williams { 27575d8beee2SDan Williams char *inject_desc[] = { "none", "source", "destination" }; 27585d8beee2SDan Williams enum INJECT inj; 27595d8beee2SDan Williams 27605d8beee2SDan Williams if (IS_ENABLED(CONFIG_MCSAFE_TEST)) { 27615d8beee2SDan Williams pr_info("%s: run...\n", __func__); 27625d8beee2SDan Williams } else { 27635d8beee2SDan Williams pr_info("%s: disabled, skip.\n", __func__); 27645d8beee2SDan Williams return; 27655d8beee2SDan Williams } 27665d8beee2SDan Williams 27675d8beee2SDan Williams for (inj = INJECT_NONE; inj <= INJECT_DST; inj++) { 27685d8beee2SDan Williams int i; 27695d8beee2SDan Williams 27705d8beee2SDan Williams pr_info("%s: inject: %s\n", __func__, inject_desc[inj]); 27715d8beee2SDan Williams for (i = 0; i < 512; i++) { 27725d8beee2SDan Williams unsigned long expect, rem; 27735d8beee2SDan Williams void *src, *dst; 27745d8beee2SDan Williams bool valid; 27755d8beee2SDan Williams 27765d8beee2SDan Williams switch (inj) { 27775d8beee2SDan Williams case INJECT_NONE: 27785d8beee2SDan Williams mcsafe_inject_src(NULL); 27795d8beee2SDan Williams mcsafe_inject_dst(NULL); 27805d8beee2SDan Williams dst = &mcsafe_buf[2048]; 27815d8beee2SDan Williams src = &mcsafe_buf[1024 - i]; 27825d8beee2SDan Williams expect = 0; 27835d8beee2SDan Williams break; 27845d8beee2SDan Williams case INJECT_SRC: 27855d8beee2SDan Williams mcsafe_inject_src(&mcsafe_buf[1024]); 27865d8beee2SDan Williams mcsafe_inject_dst(NULL); 27875d8beee2SDan Williams dst = &mcsafe_buf[2048]; 27885d8beee2SDan Williams src = &mcsafe_buf[1024 - i]; 27895d8beee2SDan Williams expect = 512 - i; 27905d8beee2SDan Williams break; 27915d8beee2SDan Williams case INJECT_DST: 27925d8beee2SDan Williams mcsafe_inject_src(NULL); 27935d8beee2SDan Williams mcsafe_inject_dst(&mcsafe_buf[2048]); 27945d8beee2SDan Williams dst = &mcsafe_buf[2048 - i]; 27955d8beee2SDan Williams src = &mcsafe_buf[1024]; 27965d8beee2SDan Williams expect = 512 - i; 27975d8beee2SDan Williams break; 27985d8beee2SDan Williams } 27995d8beee2SDan Williams 28005d8beee2SDan Williams mcsafe_test_init(dst, src, 512); 28015d8beee2SDan Williams rem = __memcpy_mcsafe(dst, src, 512); 28025d8beee2SDan Williams valid = mcsafe_test_validate(dst, src, 512, expect); 28035d8beee2SDan Williams if (rem == expect && valid) 28045d8beee2SDan Williams continue; 28055d8beee2SDan Williams pr_info("%s: copy(%#lx, %#lx, %d) off: %d rem: %ld %s expect: %ld\n", 28065d8beee2SDan Williams __func__, 28075d8beee2SDan Williams ((unsigned long) dst) & ~PAGE_MASK, 28085d8beee2SDan Williams ((unsigned long ) src) & ~PAGE_MASK, 28095d8beee2SDan Williams 512, i, rem, valid ? "valid" : "bad", 28105d8beee2SDan Williams expect); 28115d8beee2SDan Williams } 28125d8beee2SDan Williams } 28135d8beee2SDan Williams 28145d8beee2SDan Williams mcsafe_inject_src(NULL); 28155d8beee2SDan Williams mcsafe_inject_dst(NULL); 28165d8beee2SDan Williams } 28175d8beee2SDan Williams 28186bc75619SDan Williams static __init int nfit_test_init(void) 28196bc75619SDan Williams { 28206bc75619SDan Williams int rc, i; 28216bc75619SDan Williams 28220fb5c8dfSDan Williams pmem_test(); 28230fb5c8dfSDan Williams libnvdimm_test(); 28240fb5c8dfSDan Williams acpi_nfit_test(); 28250fb5c8dfSDan Williams device_dax_test(); 28265d8beee2SDan Williams mcsafe_test(); 28270fb5c8dfSDan Williams 2828a7de92daSDan Williams nfit_test_setup(nfit_test_lookup, nfit_test_evaluate_dsm); 2829231bf117SDan Williams 28309fb1a190SDave Jiang nfit_wq = create_singlethread_workqueue("nfit"); 28319fb1a190SDave Jiang if (!nfit_wq) 28329fb1a190SDave Jiang return -ENOMEM; 28339fb1a190SDave Jiang 2834a7de92daSDan Williams nfit_test_dimm = class_create(THIS_MODULE, "nfit_test_dimm"); 2835a7de92daSDan Williams if (IS_ERR(nfit_test_dimm)) { 2836a7de92daSDan Williams rc = PTR_ERR(nfit_test_dimm); 2837a7de92daSDan Williams goto err_register; 2838a7de92daSDan Williams } 28396bc75619SDan Williams 28406bc75619SDan Williams for (i = 0; i < NUM_NFITS; i++) { 28416bc75619SDan Williams struct nfit_test *nfit_test; 28426bc75619SDan Williams struct platform_device *pdev; 28436bc75619SDan Williams 28446bc75619SDan Williams nfit_test = kzalloc(sizeof(*nfit_test), GFP_KERNEL); 28456bc75619SDan Williams if (!nfit_test) { 28466bc75619SDan Williams rc = -ENOMEM; 28476bc75619SDan Williams goto err_register; 28486bc75619SDan Williams } 28496bc75619SDan Williams INIT_LIST_HEAD(&nfit_test->resources); 28509fb1a190SDave Jiang badrange_init(&nfit_test->badrange); 28516bc75619SDan Williams switch (i) { 28526bc75619SDan Williams case 0: 28536bc75619SDan Williams nfit_test->num_pm = NUM_PM; 2854dafb1048SDan Williams nfit_test->dcr_idx = 0; 28556bc75619SDan Williams nfit_test->num_dcr = NUM_DCR; 28566bc75619SDan Williams nfit_test->alloc = nfit_test0_alloc; 28576bc75619SDan Williams nfit_test->setup = nfit_test0_setup; 28586bc75619SDan Williams break; 28596bc75619SDan Williams case 1: 2860a117699cSYasunori Goto nfit_test->num_pm = 2; 2861dafb1048SDan Williams nfit_test->dcr_idx = NUM_DCR; 2862ac40b675SDan Williams nfit_test->num_dcr = 2; 28636bc75619SDan Williams nfit_test->alloc = nfit_test1_alloc; 28646bc75619SDan Williams nfit_test->setup = nfit_test1_setup; 28656bc75619SDan Williams break; 28666bc75619SDan Williams default: 28676bc75619SDan Williams rc = -EINVAL; 28686bc75619SDan Williams goto err_register; 28696bc75619SDan Williams } 28706bc75619SDan Williams pdev = &nfit_test->pdev; 28716bc75619SDan Williams pdev->name = KBUILD_MODNAME; 28726bc75619SDan Williams pdev->id = i; 28736bc75619SDan Williams pdev->dev.release = nfit_test_release; 28746bc75619SDan Williams rc = platform_device_register(pdev); 28756bc75619SDan Williams if (rc) { 28766bc75619SDan Williams put_device(&pdev->dev); 28776bc75619SDan Williams goto err_register; 28786bc75619SDan Williams } 28798b06b884SDan Williams get_device(&pdev->dev); 28806bc75619SDan Williams 28816bc75619SDan Williams rc = dma_coerce_mask_and_coherent(&pdev->dev, DMA_BIT_MASK(64)); 28826bc75619SDan Williams if (rc) 28836bc75619SDan Williams goto err_register; 28846bc75619SDan Williams 28856bc75619SDan Williams instances[i] = nfit_test; 28869fb1a190SDave Jiang INIT_WORK(&nfit_test->work, uc_error_notify); 28876bc75619SDan Williams } 28886bc75619SDan Williams 28896bc75619SDan Williams rc = platform_driver_register(&nfit_test_driver); 28906bc75619SDan Williams if (rc) 28916bc75619SDan Williams goto err_register; 28926bc75619SDan Williams return 0; 28936bc75619SDan Williams 28946bc75619SDan Williams err_register: 28959fb1a190SDave Jiang destroy_workqueue(nfit_wq); 28966bc75619SDan Williams for (i = 0; i < NUM_NFITS; i++) 28976bc75619SDan Williams if (instances[i]) 28986bc75619SDan Williams platform_device_unregister(&instances[i]->pdev); 28996bc75619SDan Williams nfit_test_teardown(); 29008b06b884SDan Williams for (i = 0; i < NUM_NFITS; i++) 29018b06b884SDan Williams if (instances[i]) 29028b06b884SDan Williams put_device(&instances[i]->pdev.dev); 29038b06b884SDan Williams 29046bc75619SDan Williams return rc; 29056bc75619SDan Williams } 29066bc75619SDan Williams 29076bc75619SDan Williams static __exit void nfit_test_exit(void) 29086bc75619SDan Williams { 29096bc75619SDan Williams int i; 29106bc75619SDan Williams 29119fb1a190SDave Jiang flush_workqueue(nfit_wq); 29129fb1a190SDave Jiang destroy_workqueue(nfit_wq); 29136bc75619SDan Williams for (i = 0; i < NUM_NFITS; i++) 29146bc75619SDan Williams platform_device_unregister(&instances[i]->pdev); 29158b06b884SDan Williams platform_driver_unregister(&nfit_test_driver); 29166bc75619SDan Williams nfit_test_teardown(); 29178b06b884SDan Williams 29188b06b884SDan Williams for (i = 0; i < NUM_NFITS; i++) 29198b06b884SDan Williams put_device(&instances[i]->pdev.dev); 2920231bf117SDan Williams class_destroy(nfit_test_dimm); 29216bc75619SDan Williams } 29226bc75619SDan Williams 29236bc75619SDan Williams module_init(nfit_test_init); 29246bc75619SDan Williams module_exit(nfit_test_exit); 29256bc75619SDan Williams MODULE_LICENSE("GPL v2"); 29266bc75619SDan Williams MODULE_AUTHOR("Intel Corporation"); 2927