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" 306bc75619SDan Williams 316bc75619SDan Williams /* 326bc75619SDan Williams * Generate an NFIT table to describe the following topology: 336bc75619SDan Williams * 346bc75619SDan Williams * BUS0: Interleaved PMEM regions, and aliasing with BLK regions 356bc75619SDan Williams * 366bc75619SDan Williams * (a) (b) DIMM BLK-REGION 376bc75619SDan Williams * +----------+--------------+----------+---------+ 386bc75619SDan Williams * +------+ | blk2.0 | pm0.0 | blk2.1 | pm1.0 | 0 region2 396bc75619SDan Williams * | imc0 +--+- - - - - region0 - - - -+----------+ + 406bc75619SDan Williams * +--+---+ | blk3.0 | pm0.0 | blk3.1 | pm1.0 | 1 region3 416bc75619SDan Williams * | +----------+--------------v----------v v 426bc75619SDan Williams * +--+---+ | | 436bc75619SDan Williams * | cpu0 | region1 446bc75619SDan Williams * +--+---+ | | 456bc75619SDan Williams * | +-------------------------^----------^ ^ 466bc75619SDan Williams * +--+---+ | blk4.0 | pm1.0 | 2 region4 476bc75619SDan Williams * | imc1 +--+-------------------------+----------+ + 486bc75619SDan Williams * +------+ | blk5.0 | pm1.0 | 3 region5 496bc75619SDan Williams * +-------------------------+----------+-+-------+ 506bc75619SDan Williams * 5120985164SVishal Verma * +--+---+ 5220985164SVishal Verma * | cpu1 | 5320985164SVishal Verma * +--+---+ (Hotplug DIMM) 5420985164SVishal Verma * | +----------------------------------------------+ 5520985164SVishal Verma * +--+---+ | blk6.0/pm7.0 | 4 region6/7 5620985164SVishal Verma * | imc0 +--+----------------------------------------------+ 5720985164SVishal Verma * +------+ 5820985164SVishal Verma * 5920985164SVishal Verma * 606bc75619SDan Williams * *) In this layout we have four dimms and two memory controllers in one 616bc75619SDan Williams * socket. Each unique interface (BLK or PMEM) to DPA space 626bc75619SDan Williams * is identified by a region device with a dynamically assigned id. 636bc75619SDan Williams * 646bc75619SDan Williams * *) The first portion of dimm0 and dimm1 are interleaved as REGION0. 656bc75619SDan Williams * A single PMEM namespace "pm0.0" is created using half of the 666bc75619SDan Williams * REGION0 SPA-range. REGION0 spans dimm0 and dimm1. PMEM namespace 676bc75619SDan Williams * allocate from from the bottom of a region. The unallocated 686bc75619SDan Williams * portion of REGION0 aliases with REGION2 and REGION3. That 696bc75619SDan Williams * unallacted capacity is reclaimed as BLK namespaces ("blk2.0" and 706bc75619SDan Williams * "blk3.0") starting at the base of each DIMM to offset (a) in those 716bc75619SDan Williams * DIMMs. "pm0.0", "blk2.0" and "blk3.0" are free-form readable 726bc75619SDan Williams * names that can be assigned to a namespace. 736bc75619SDan Williams * 746bc75619SDan Williams * *) In the last portion of dimm0 and dimm1 we have an interleaved 756bc75619SDan Williams * SPA range, REGION1, that spans those two dimms as well as dimm2 766bc75619SDan Williams * and dimm3. Some of REGION1 allocated to a PMEM namespace named 776bc75619SDan Williams * "pm1.0" the rest is reclaimed in 4 BLK namespaces (for each 786bc75619SDan Williams * dimm in the interleave set), "blk2.1", "blk3.1", "blk4.0", and 796bc75619SDan Williams * "blk5.0". 806bc75619SDan Williams * 816bc75619SDan Williams * *) The portion of dimm2 and dimm3 that do not participate in the 826bc75619SDan Williams * REGION1 interleaved SPA range (i.e. the DPA address below offset 836bc75619SDan Williams * (b) are also included in the "blk4.0" and "blk5.0" namespaces. 846bc75619SDan Williams * Note, that BLK namespaces need not be contiguous in DPA-space, and 856bc75619SDan Williams * can consume aliased capacity from multiple interleave sets. 866bc75619SDan Williams * 876bc75619SDan Williams * BUS1: Legacy NVDIMM (single contiguous range) 886bc75619SDan Williams * 896bc75619SDan Williams * region2 906bc75619SDan Williams * +---------------------+ 916bc75619SDan Williams * |---------------------| 926bc75619SDan Williams * || pm2.0 || 936bc75619SDan Williams * |---------------------| 946bc75619SDan Williams * +---------------------+ 956bc75619SDan Williams * 966bc75619SDan Williams * *) A NFIT-table may describe a simple system-physical-address range 976bc75619SDan Williams * with no BLK aliasing. This type of region may optionally 986bc75619SDan Williams * reference an NVDIMM. 996bc75619SDan Williams */ 1006bc75619SDan Williams enum { 10120985164SVishal Verma NUM_PM = 3, 10220985164SVishal Verma NUM_DCR = 5, 10385d3fa02SDan Williams NUM_HINTS = 8, 1046bc75619SDan Williams NUM_BDW = NUM_DCR, 1056bc75619SDan Williams NUM_SPA = NUM_PM + NUM_DCR + NUM_BDW, 1066bc75619SDan Williams NUM_MEM = NUM_DCR + NUM_BDW + 2 /* spa0 iset */ + 4 /* spa1 iset */, 1076bc75619SDan Williams DIMM_SIZE = SZ_32M, 1086bc75619SDan Williams LABEL_SIZE = SZ_128K, 1097bfe97c7SDan Williams SPA_VCD_SIZE = SZ_4M, 1106bc75619SDan Williams SPA0_SIZE = DIMM_SIZE, 1116bc75619SDan Williams SPA1_SIZE = DIMM_SIZE*2, 1126bc75619SDan Williams SPA2_SIZE = DIMM_SIZE, 1136bc75619SDan Williams BDW_SIZE = 64 << 8, 1146bc75619SDan Williams DCR_SIZE = 12, 1156bc75619SDan Williams NUM_NFITS = 2, /* permit testing multiple NFITs per system */ 1166bc75619SDan Williams }; 1176bc75619SDan Williams 1186bc75619SDan Williams struct nfit_test_dcr { 1196bc75619SDan Williams __le64 bdw_addr; 1206bc75619SDan Williams __le32 bdw_status; 1216bc75619SDan Williams __u8 aperature[BDW_SIZE]; 1226bc75619SDan Williams }; 1236bc75619SDan Williams 1246bc75619SDan Williams #define NFIT_DIMM_HANDLE(node, socket, imc, chan, dimm) \ 1256bc75619SDan Williams (((node & 0xfff) << 16) | ((socket & 0xf) << 12) \ 1266bc75619SDan Williams | ((imc & 0xf) << 8) | ((chan & 0xf) << 4) | (dimm & 0xf)) 1276bc75619SDan Williams 128dafb1048SDan Williams static u32 handle[] = { 1296bc75619SDan Williams [0] = NFIT_DIMM_HANDLE(0, 0, 0, 0, 0), 1306bc75619SDan Williams [1] = NFIT_DIMM_HANDLE(0, 0, 0, 0, 1), 1316bc75619SDan Williams [2] = NFIT_DIMM_HANDLE(0, 0, 1, 0, 0), 1326bc75619SDan Williams [3] = NFIT_DIMM_HANDLE(0, 0, 1, 0, 1), 13320985164SVishal Verma [4] = NFIT_DIMM_HANDLE(0, 1, 0, 0, 0), 134dafb1048SDan Williams [5] = NFIT_DIMM_HANDLE(1, 0, 0, 0, 0), 135ac40b675SDan Williams [6] = NFIT_DIMM_HANDLE(1, 0, 0, 0, 1), 1366bc75619SDan Williams }; 1376bc75619SDan Williams 13873606afdSDan Williams static unsigned long dimm_fail_cmd_flags[NUM_DCR]; 13973606afdSDan Williams 1406bc75619SDan Williams struct nfit_test { 1416bc75619SDan Williams struct acpi_nfit_desc acpi_desc; 1426bc75619SDan Williams struct platform_device pdev; 1436bc75619SDan Williams struct list_head resources; 1446bc75619SDan Williams void *nfit_buf; 1456bc75619SDan Williams dma_addr_t nfit_dma; 1466bc75619SDan Williams size_t nfit_size; 147dafb1048SDan Williams int dcr_idx; 1486bc75619SDan Williams int num_dcr; 1496bc75619SDan Williams int num_pm; 1506bc75619SDan Williams void **dimm; 1516bc75619SDan Williams dma_addr_t *dimm_dma; 1529d27a87eSDan Williams void **flush; 1539d27a87eSDan Williams dma_addr_t *flush_dma; 1546bc75619SDan Williams void **label; 1556bc75619SDan Williams dma_addr_t *label_dma; 1566bc75619SDan Williams void **spa_set; 1576bc75619SDan Williams dma_addr_t *spa_set_dma; 1586bc75619SDan Williams struct nfit_test_dcr **dcr; 1596bc75619SDan Williams dma_addr_t *dcr_dma; 1606bc75619SDan Williams int (*alloc)(struct nfit_test *t); 1616bc75619SDan Williams void (*setup)(struct nfit_test *t); 16220985164SVishal Verma int setup_hotplug; 163c14a868aSDan Williams union acpi_object **_fit; 164c14a868aSDan Williams dma_addr_t _fit_dma; 165f471f1a7SDan Williams struct ars_state { 166f471f1a7SDan Williams struct nd_cmd_ars_status *ars_status; 167f471f1a7SDan Williams unsigned long deadline; 168f471f1a7SDan Williams spinlock_t lock; 169f471f1a7SDan Williams } ars_state; 170231bf117SDan Williams struct device *dimm_dev[NUM_DCR]; 1716bc75619SDan Williams }; 1726bc75619SDan Williams 1736bc75619SDan Williams static struct nfit_test *to_nfit_test(struct device *dev) 1746bc75619SDan Williams { 1756bc75619SDan Williams struct platform_device *pdev = to_platform_device(dev); 1766bc75619SDan Williams 1776bc75619SDan Williams return container_of(pdev, struct nfit_test, pdev); 1786bc75619SDan Williams } 1796bc75619SDan Williams 18039c686b8SVishal Verma static int nfit_test_cmd_get_config_size(struct nd_cmd_get_config_size *nd_cmd, 1816bc75619SDan Williams unsigned int buf_len) 1826bc75619SDan Williams { 1836bc75619SDan Williams if (buf_len < sizeof(*nd_cmd)) 1846bc75619SDan Williams return -EINVAL; 18539c686b8SVishal Verma 1866bc75619SDan Williams nd_cmd->status = 0; 1876bc75619SDan Williams nd_cmd->config_size = LABEL_SIZE; 1886bc75619SDan Williams nd_cmd->max_xfer = SZ_4K; 18939c686b8SVishal Verma 19039c686b8SVishal Verma return 0; 1916bc75619SDan Williams } 19239c686b8SVishal Verma 19339c686b8SVishal Verma static int nfit_test_cmd_get_config_data(struct nd_cmd_get_config_data_hdr 19439c686b8SVishal Verma *nd_cmd, unsigned int buf_len, void *label) 19539c686b8SVishal Verma { 1966bc75619SDan Williams unsigned int len, offset = nd_cmd->in_offset; 19739c686b8SVishal Verma int rc; 1986bc75619SDan Williams 1996bc75619SDan Williams if (buf_len < sizeof(*nd_cmd)) 2006bc75619SDan Williams return -EINVAL; 2016bc75619SDan Williams if (offset >= LABEL_SIZE) 2026bc75619SDan Williams return -EINVAL; 2036bc75619SDan Williams if (nd_cmd->in_length + sizeof(*nd_cmd) > buf_len) 2046bc75619SDan Williams return -EINVAL; 2056bc75619SDan Williams 2066bc75619SDan Williams nd_cmd->status = 0; 2076bc75619SDan Williams len = min(nd_cmd->in_length, LABEL_SIZE - offset); 20839c686b8SVishal Verma memcpy(nd_cmd->out_buf, label + offset, len); 2096bc75619SDan Williams rc = buf_len - sizeof(*nd_cmd) - len; 21039c686b8SVishal Verma 21139c686b8SVishal Verma return rc; 2126bc75619SDan Williams } 21339c686b8SVishal Verma 21439c686b8SVishal Verma static int nfit_test_cmd_set_config_data(struct nd_cmd_set_config_hdr *nd_cmd, 21539c686b8SVishal Verma unsigned int buf_len, void *label) 21639c686b8SVishal Verma { 2176bc75619SDan Williams unsigned int len, offset = nd_cmd->in_offset; 2186bc75619SDan Williams u32 *status; 21939c686b8SVishal Verma int rc; 2206bc75619SDan Williams 2216bc75619SDan Williams if (buf_len < sizeof(*nd_cmd)) 2226bc75619SDan Williams return -EINVAL; 2236bc75619SDan Williams if (offset >= LABEL_SIZE) 2246bc75619SDan Williams return -EINVAL; 2256bc75619SDan Williams if (nd_cmd->in_length + sizeof(*nd_cmd) + 4 > buf_len) 2266bc75619SDan Williams return -EINVAL; 2276bc75619SDan Williams 22839c686b8SVishal Verma status = (void *)nd_cmd + nd_cmd->in_length + sizeof(*nd_cmd); 2296bc75619SDan Williams *status = 0; 2306bc75619SDan Williams len = min(nd_cmd->in_length, LABEL_SIZE - offset); 23139c686b8SVishal Verma memcpy(label + offset, nd_cmd->in_buf, len); 2326bc75619SDan Williams rc = buf_len - sizeof(*nd_cmd) - (len + 4); 23339c686b8SVishal Verma 23439c686b8SVishal Verma return rc; 2356bc75619SDan Williams } 23639c686b8SVishal Verma 237747ffe11SDan Williams #define NFIT_TEST_ARS_RECORDS 4 238d4f32367SDan Williams #define NFIT_TEST_CLEAR_ERR_UNIT 256 239747ffe11SDan Williams 24039c686b8SVishal Verma static int nfit_test_cmd_ars_cap(struct nd_cmd_ars_cap *nd_cmd, 24139c686b8SVishal Verma unsigned int buf_len) 24239c686b8SVishal Verma { 24339c686b8SVishal Verma if (buf_len < sizeof(*nd_cmd)) 24439c686b8SVishal Verma return -EINVAL; 24539c686b8SVishal Verma 246747ffe11SDan Williams nd_cmd->max_ars_out = sizeof(struct nd_cmd_ars_status) 247747ffe11SDan Williams + NFIT_TEST_ARS_RECORDS * sizeof(struct nd_ars_record); 24839c686b8SVishal Verma nd_cmd->status = (ND_ARS_PERSISTENT | ND_ARS_VOLATILE) << 16; 249d4f32367SDan Williams nd_cmd->clear_err_unit = NFIT_TEST_CLEAR_ERR_UNIT; 25039c686b8SVishal Verma 25139c686b8SVishal Verma return 0; 25239c686b8SVishal Verma } 25339c686b8SVishal Verma 254f471f1a7SDan Williams /* 255f471f1a7SDan Williams * Initialize the ars_state to return an ars_result 1 second in the future with 256f471f1a7SDan Williams * a 4K error range in the middle of the requested address range. 257f471f1a7SDan Williams */ 258f471f1a7SDan Williams static void post_ars_status(struct ars_state *ars_state, u64 addr, u64 len) 25939c686b8SVishal Verma { 260f471f1a7SDan Williams struct nd_cmd_ars_status *ars_status; 261f471f1a7SDan Williams struct nd_ars_record *ars_record; 262f471f1a7SDan Williams 263f471f1a7SDan Williams ars_state->deadline = jiffies + 1*HZ; 264f471f1a7SDan Williams ars_status = ars_state->ars_status; 265f471f1a7SDan Williams ars_status->status = 0; 266f471f1a7SDan Williams ars_status->out_length = sizeof(struct nd_cmd_ars_status) 267f471f1a7SDan Williams + sizeof(struct nd_ars_record); 268f471f1a7SDan Williams ars_status->address = addr; 269f471f1a7SDan Williams ars_status->length = len; 270f471f1a7SDan Williams ars_status->type = ND_ARS_PERSISTENT; 271f471f1a7SDan Williams ars_status->num_records = 1; 272f471f1a7SDan Williams ars_record = &ars_status->records[0]; 273f471f1a7SDan Williams ars_record->handle = 0; 274f471f1a7SDan Williams ars_record->err_address = addr + len / 2; 275f471f1a7SDan Williams ars_record->length = SZ_4K; 276f471f1a7SDan Williams } 277f471f1a7SDan Williams 278f471f1a7SDan Williams static int nfit_test_cmd_ars_start(struct ars_state *ars_state, 279f471f1a7SDan Williams struct nd_cmd_ars_start *ars_start, unsigned int buf_len, 280f471f1a7SDan Williams int *cmd_rc) 281f471f1a7SDan Williams { 282f471f1a7SDan Williams if (buf_len < sizeof(*ars_start)) 28339c686b8SVishal Verma return -EINVAL; 28439c686b8SVishal Verma 285f471f1a7SDan Williams spin_lock(&ars_state->lock); 286f471f1a7SDan Williams if (time_before(jiffies, ars_state->deadline)) { 287f471f1a7SDan Williams ars_start->status = NFIT_ARS_START_BUSY; 288f471f1a7SDan Williams *cmd_rc = -EBUSY; 289f471f1a7SDan Williams } else { 290f471f1a7SDan Williams ars_start->status = 0; 291f471f1a7SDan Williams ars_start->scrub_time = 1; 292f471f1a7SDan Williams post_ars_status(ars_state, ars_start->address, 293f471f1a7SDan Williams ars_start->length); 294f471f1a7SDan Williams *cmd_rc = 0; 295f471f1a7SDan Williams } 296f471f1a7SDan Williams spin_unlock(&ars_state->lock); 29739c686b8SVishal Verma 29839c686b8SVishal Verma return 0; 29939c686b8SVishal Verma } 30039c686b8SVishal Verma 301f471f1a7SDan Williams static int nfit_test_cmd_ars_status(struct ars_state *ars_state, 302f471f1a7SDan Williams struct nd_cmd_ars_status *ars_status, unsigned int buf_len, 303f471f1a7SDan Williams int *cmd_rc) 30439c686b8SVishal Verma { 305f471f1a7SDan Williams if (buf_len < ars_state->ars_status->out_length) 30639c686b8SVishal Verma return -EINVAL; 30739c686b8SVishal Verma 308f471f1a7SDan Williams spin_lock(&ars_state->lock); 309f471f1a7SDan Williams if (time_before(jiffies, ars_state->deadline)) { 310f471f1a7SDan Williams memset(ars_status, 0, buf_len); 311f471f1a7SDan Williams ars_status->status = NFIT_ARS_STATUS_BUSY; 312f471f1a7SDan Williams ars_status->out_length = sizeof(*ars_status); 313f471f1a7SDan Williams *cmd_rc = -EBUSY; 314f471f1a7SDan Williams } else { 315f471f1a7SDan Williams memcpy(ars_status, ars_state->ars_status, 316f471f1a7SDan Williams ars_state->ars_status->out_length); 317f471f1a7SDan Williams *cmd_rc = 0; 318f471f1a7SDan Williams } 319f471f1a7SDan Williams spin_unlock(&ars_state->lock); 32039c686b8SVishal Verma return 0; 32139c686b8SVishal Verma } 32239c686b8SVishal Verma 323d4f32367SDan Williams static int nfit_test_cmd_clear_error(struct nd_cmd_clear_error *clear_err, 324d4f32367SDan Williams unsigned int buf_len, int *cmd_rc) 325d4f32367SDan Williams { 326d4f32367SDan Williams const u64 mask = NFIT_TEST_CLEAR_ERR_UNIT - 1; 327d4f32367SDan Williams if (buf_len < sizeof(*clear_err)) 328d4f32367SDan Williams return -EINVAL; 329d4f32367SDan Williams 330d4f32367SDan Williams if ((clear_err->address & mask) || (clear_err->length & mask)) 331d4f32367SDan Williams return -EINVAL; 332d4f32367SDan Williams 333d4f32367SDan Williams /* 334d4f32367SDan Williams * Report 'all clear' success for all commands even though a new 335d4f32367SDan Williams * scrub will find errors again. This is enough to have the 336d4f32367SDan Williams * error removed from the 'badblocks' tracking in the pmem 337d4f32367SDan Williams * driver. 338d4f32367SDan Williams */ 339d4f32367SDan Williams clear_err->status = 0; 340d4f32367SDan Williams clear_err->cleared = clear_err->length; 341d4f32367SDan Williams *cmd_rc = 0; 342d4f32367SDan Williams return 0; 343d4f32367SDan Williams } 344d4f32367SDan Williams 345*10246dc8SYasunori Goto struct region_search_spa { 346*10246dc8SYasunori Goto u64 addr; 347*10246dc8SYasunori Goto struct nd_region *region; 348*10246dc8SYasunori Goto }; 349*10246dc8SYasunori Goto 350*10246dc8SYasunori Goto static int is_region_device(struct device *dev) 351*10246dc8SYasunori Goto { 352*10246dc8SYasunori Goto return !strncmp(dev->kobj.name, "region", 6); 353*10246dc8SYasunori Goto } 354*10246dc8SYasunori Goto 355*10246dc8SYasunori Goto static int nfit_test_search_region_spa(struct device *dev, void *data) 356*10246dc8SYasunori Goto { 357*10246dc8SYasunori Goto struct region_search_spa *ctx = data; 358*10246dc8SYasunori Goto struct nd_region *nd_region; 359*10246dc8SYasunori Goto resource_size_t ndr_end; 360*10246dc8SYasunori Goto 361*10246dc8SYasunori Goto if (!is_region_device(dev)) 362*10246dc8SYasunori Goto return 0; 363*10246dc8SYasunori Goto 364*10246dc8SYasunori Goto nd_region = to_nd_region(dev); 365*10246dc8SYasunori Goto ndr_end = nd_region->ndr_start + nd_region->ndr_size; 366*10246dc8SYasunori Goto 367*10246dc8SYasunori Goto if (ctx->addr >= nd_region->ndr_start && ctx->addr < ndr_end) { 368*10246dc8SYasunori Goto ctx->region = nd_region; 369*10246dc8SYasunori Goto return 1; 370*10246dc8SYasunori Goto } 371*10246dc8SYasunori Goto 372*10246dc8SYasunori Goto return 0; 373*10246dc8SYasunori Goto } 374*10246dc8SYasunori Goto 375*10246dc8SYasunori Goto static int nfit_test_search_spa(struct nvdimm_bus *bus, 376*10246dc8SYasunori Goto struct nd_cmd_translate_spa *spa) 377*10246dc8SYasunori Goto { 378*10246dc8SYasunori Goto int ret; 379*10246dc8SYasunori Goto struct nd_region *nd_region = NULL; 380*10246dc8SYasunori Goto struct nvdimm *nvdimm = NULL; 381*10246dc8SYasunori Goto struct nd_mapping *nd_mapping = NULL; 382*10246dc8SYasunori Goto struct region_search_spa ctx = { 383*10246dc8SYasunori Goto .addr = spa->spa, 384*10246dc8SYasunori Goto .region = NULL, 385*10246dc8SYasunori Goto }; 386*10246dc8SYasunori Goto u64 dpa; 387*10246dc8SYasunori Goto 388*10246dc8SYasunori Goto ret = device_for_each_child(&bus->dev, &ctx, 389*10246dc8SYasunori Goto nfit_test_search_region_spa); 390*10246dc8SYasunori Goto 391*10246dc8SYasunori Goto if (!ret) 392*10246dc8SYasunori Goto return -ENODEV; 393*10246dc8SYasunori Goto 394*10246dc8SYasunori Goto nd_region = ctx.region; 395*10246dc8SYasunori Goto 396*10246dc8SYasunori Goto dpa = ctx.addr - nd_region->ndr_start; 397*10246dc8SYasunori Goto 398*10246dc8SYasunori Goto /* 399*10246dc8SYasunori Goto * last dimm is selected for test 400*10246dc8SYasunori Goto */ 401*10246dc8SYasunori Goto nd_mapping = &nd_region->mapping[nd_region->ndr_mappings - 1]; 402*10246dc8SYasunori Goto nvdimm = nd_mapping->nvdimm; 403*10246dc8SYasunori Goto 404*10246dc8SYasunori Goto spa->devices[0].nfit_device_handle = handle[nvdimm->id]; 405*10246dc8SYasunori Goto spa->num_nvdimms = 1; 406*10246dc8SYasunori Goto spa->devices[0].dpa = dpa; 407*10246dc8SYasunori Goto 408*10246dc8SYasunori Goto return 0; 409*10246dc8SYasunori Goto } 410*10246dc8SYasunori Goto 411*10246dc8SYasunori Goto static int nfit_test_cmd_translate_spa(struct nvdimm_bus *bus, 412*10246dc8SYasunori Goto struct nd_cmd_translate_spa *spa, unsigned int buf_len) 413*10246dc8SYasunori Goto { 414*10246dc8SYasunori Goto if (buf_len < spa->translate_length) 415*10246dc8SYasunori Goto return -EINVAL; 416*10246dc8SYasunori Goto 417*10246dc8SYasunori Goto if (nfit_test_search_spa(bus, spa) < 0 || !spa->num_nvdimms) 418*10246dc8SYasunori Goto spa->status = 2; 419*10246dc8SYasunori Goto 420*10246dc8SYasunori Goto return 0; 421*10246dc8SYasunori Goto } 422*10246dc8SYasunori Goto 423baa51277SDan Williams static int nfit_test_cmd_smart(struct nd_cmd_smart *smart, unsigned int buf_len) 424baa51277SDan Williams { 425baa51277SDan Williams static const struct nd_smart_payload smart_data = { 426baa51277SDan Williams .flags = ND_SMART_HEALTH_VALID | ND_SMART_TEMP_VALID 427baa51277SDan Williams | ND_SMART_SPARES_VALID | ND_SMART_ALARM_VALID 428baa51277SDan Williams | ND_SMART_USED_VALID | ND_SMART_SHUTDOWN_VALID, 429baa51277SDan Williams .health = ND_SMART_NON_CRITICAL_HEALTH, 430baa51277SDan Williams .temperature = 23 * 16, 431baa51277SDan Williams .spares = 75, 432baa51277SDan Williams .alarm_flags = ND_SMART_SPARE_TRIP | ND_SMART_TEMP_TRIP, 433baa51277SDan Williams .life_used = 5, 434baa51277SDan Williams .shutdown_state = 0, 435baa51277SDan Williams .vendor_size = 0, 436baa51277SDan Williams }; 437baa51277SDan Williams 438baa51277SDan Williams if (buf_len < sizeof(*smart)) 439baa51277SDan Williams return -EINVAL; 440baa51277SDan Williams memcpy(smart->data, &smart_data, sizeof(smart_data)); 441baa51277SDan Williams return 0; 442baa51277SDan Williams } 443baa51277SDan Williams 444baa51277SDan Williams static int nfit_test_cmd_smart_threshold(struct nd_cmd_smart_threshold *smart_t, 445baa51277SDan Williams unsigned int buf_len) 446baa51277SDan Williams { 447baa51277SDan Williams static const struct nd_smart_threshold_payload smart_t_data = { 448baa51277SDan Williams .alarm_control = ND_SMART_SPARE_TRIP | ND_SMART_TEMP_TRIP, 449baa51277SDan Williams .temperature = 40 * 16, 450baa51277SDan Williams .spares = 5, 451baa51277SDan Williams }; 452baa51277SDan Williams 453baa51277SDan Williams if (buf_len < sizeof(*smart_t)) 454baa51277SDan Williams return -EINVAL; 455baa51277SDan Williams memcpy(smart_t->data, &smart_t_data, sizeof(smart_t_data)); 456baa51277SDan Williams return 0; 457baa51277SDan Williams } 458baa51277SDan Williams 45939c686b8SVishal Verma static int nfit_test_ctl(struct nvdimm_bus_descriptor *nd_desc, 46039c686b8SVishal Verma struct nvdimm *nvdimm, unsigned int cmd, void *buf, 461aef25338SDan Williams unsigned int buf_len, int *cmd_rc) 46239c686b8SVishal Verma { 46339c686b8SVishal Verma struct acpi_nfit_desc *acpi_desc = to_acpi_desc(nd_desc); 46439c686b8SVishal Verma struct nfit_test *t = container_of(acpi_desc, typeof(*t), acpi_desc); 4656634fb06SDan Williams unsigned int func = cmd; 466f471f1a7SDan Williams int i, rc = 0, __cmd_rc; 467f471f1a7SDan Williams 468f471f1a7SDan Williams if (!cmd_rc) 469f471f1a7SDan Williams cmd_rc = &__cmd_rc; 470f471f1a7SDan Williams *cmd_rc = 0; 47139c686b8SVishal Verma 47239c686b8SVishal Verma if (nvdimm) { 47339c686b8SVishal Verma struct nfit_mem *nfit_mem = nvdimm_provider_data(nvdimm); 474e3654ecaSDan Williams unsigned long cmd_mask = nvdimm_cmd_mask(nvdimm); 47539c686b8SVishal Verma 4766634fb06SDan Williams if (!nfit_mem) 4776634fb06SDan Williams return -ENOTTY; 4786634fb06SDan Williams 4796634fb06SDan Williams if (cmd == ND_CMD_CALL) { 4806634fb06SDan Williams struct nd_cmd_pkg *call_pkg = buf; 4816634fb06SDan Williams 4826634fb06SDan Williams buf_len = call_pkg->nd_size_in + call_pkg->nd_size_out; 4836634fb06SDan Williams buf = (void *) call_pkg->nd_payload; 4846634fb06SDan Williams func = call_pkg->nd_command; 4856634fb06SDan Williams if (call_pkg->nd_family != nfit_mem->family) 4866634fb06SDan Williams return -ENOTTY; 4876634fb06SDan Williams } 4886634fb06SDan Williams 4896634fb06SDan Williams if (!test_bit(cmd, &cmd_mask) 4906634fb06SDan Williams || !test_bit(func, &nfit_mem->dsm_mask)) 49139c686b8SVishal Verma return -ENOTTY; 49239c686b8SVishal Verma 49339c686b8SVishal Verma /* lookup label space for the given dimm */ 49439c686b8SVishal Verma for (i = 0; i < ARRAY_SIZE(handle); i++) 49539c686b8SVishal Verma if (__to_nfit_memdev(nfit_mem)->device_handle == 49639c686b8SVishal Verma handle[i]) 49739c686b8SVishal Verma break; 49839c686b8SVishal Verma if (i >= ARRAY_SIZE(handle)) 49939c686b8SVishal Verma return -ENXIO; 50039c686b8SVishal Verma 50173606afdSDan Williams if ((1 << func) & dimm_fail_cmd_flags[i]) 50273606afdSDan Williams return -EIO; 50373606afdSDan Williams 5046634fb06SDan Williams switch (func) { 50539c686b8SVishal Verma case ND_CMD_GET_CONFIG_SIZE: 50639c686b8SVishal Verma rc = nfit_test_cmd_get_config_size(buf, buf_len); 50739c686b8SVishal Verma break; 50839c686b8SVishal Verma case ND_CMD_GET_CONFIG_DATA: 50939c686b8SVishal Verma rc = nfit_test_cmd_get_config_data(buf, buf_len, 510dafb1048SDan Williams t->label[i - t->dcr_idx]); 51139c686b8SVishal Verma break; 51239c686b8SVishal Verma case ND_CMD_SET_CONFIG_DATA: 51339c686b8SVishal Verma rc = nfit_test_cmd_set_config_data(buf, buf_len, 514dafb1048SDan Williams t->label[i - t->dcr_idx]); 51539c686b8SVishal Verma break; 516baa51277SDan Williams case ND_CMD_SMART: 517baa51277SDan Williams rc = nfit_test_cmd_smart(buf, buf_len); 518baa51277SDan Williams break; 519baa51277SDan Williams case ND_CMD_SMART_THRESHOLD: 520baa51277SDan Williams rc = nfit_test_cmd_smart_threshold(buf, buf_len); 521231bf117SDan Williams device_lock(&t->pdev.dev); 522231bf117SDan Williams __acpi_nvdimm_notify(t->dimm_dev[i], 0x81); 523231bf117SDan Williams device_unlock(&t->pdev.dev); 524baa51277SDan Williams break; 5256bc75619SDan Williams default: 5266bc75619SDan Williams return -ENOTTY; 5276bc75619SDan Williams } 52839c686b8SVishal Verma } else { 529f471f1a7SDan Williams struct ars_state *ars_state = &t->ars_state; 530*10246dc8SYasunori Goto struct nd_cmd_pkg *call_pkg = buf; 531*10246dc8SYasunori Goto 532*10246dc8SYasunori Goto if (!nd_desc) 533*10246dc8SYasunori Goto return -ENOTTY; 534*10246dc8SYasunori Goto 535*10246dc8SYasunori Goto if (cmd == ND_CMD_CALL) { 536*10246dc8SYasunori Goto func = call_pkg->nd_command; 537*10246dc8SYasunori Goto 538*10246dc8SYasunori Goto buf_len = call_pkg->nd_size_in + call_pkg->nd_size_out; 539*10246dc8SYasunori Goto buf = (void *) call_pkg->nd_payload; 540*10246dc8SYasunori Goto 541*10246dc8SYasunori Goto switch (func) { 542*10246dc8SYasunori Goto case NFIT_CMD_TRANSLATE_SPA: 543*10246dc8SYasunori Goto rc = nfit_test_cmd_translate_spa( 544*10246dc8SYasunori Goto acpi_desc->nvdimm_bus, buf, buf_len); 545*10246dc8SYasunori Goto return rc; 546*10246dc8SYasunori Goto default: 547*10246dc8SYasunori Goto return -ENOTTY; 548*10246dc8SYasunori Goto } 549*10246dc8SYasunori Goto } 550f471f1a7SDan Williams 551e3654ecaSDan Williams if (!nd_desc || !test_bit(cmd, &nd_desc->cmd_mask)) 55239c686b8SVishal Verma return -ENOTTY; 55339c686b8SVishal Verma 5546634fb06SDan Williams switch (func) { 55539c686b8SVishal Verma case ND_CMD_ARS_CAP: 55639c686b8SVishal Verma rc = nfit_test_cmd_ars_cap(buf, buf_len); 55739c686b8SVishal Verma break; 55839c686b8SVishal Verma case ND_CMD_ARS_START: 559f471f1a7SDan Williams rc = nfit_test_cmd_ars_start(ars_state, buf, buf_len, 560f471f1a7SDan Williams cmd_rc); 56139c686b8SVishal Verma break; 56239c686b8SVishal Verma case ND_CMD_ARS_STATUS: 563f471f1a7SDan Williams rc = nfit_test_cmd_ars_status(ars_state, buf, buf_len, 564f471f1a7SDan Williams cmd_rc); 56539c686b8SVishal Verma break; 566d4f32367SDan Williams case ND_CMD_CLEAR_ERROR: 567d4f32367SDan Williams rc = nfit_test_cmd_clear_error(buf, buf_len, cmd_rc); 568d4f32367SDan Williams break; 56939c686b8SVishal Verma default: 57039c686b8SVishal Verma return -ENOTTY; 57139c686b8SVishal Verma } 57239c686b8SVishal Verma } 5736bc75619SDan Williams 5746bc75619SDan Williams return rc; 5756bc75619SDan Williams } 5766bc75619SDan Williams 5776bc75619SDan Williams static DEFINE_SPINLOCK(nfit_test_lock); 5786bc75619SDan Williams static struct nfit_test *instances[NUM_NFITS]; 5796bc75619SDan Williams 5806bc75619SDan Williams static void release_nfit_res(void *data) 5816bc75619SDan Williams { 5826bc75619SDan Williams struct nfit_test_resource *nfit_res = data; 5836bc75619SDan Williams 5846bc75619SDan Williams spin_lock(&nfit_test_lock); 5856bc75619SDan Williams list_del(&nfit_res->list); 5866bc75619SDan Williams spin_unlock(&nfit_test_lock); 5876bc75619SDan Williams 5886bc75619SDan Williams vfree(nfit_res->buf); 5896bc75619SDan Williams kfree(nfit_res); 5906bc75619SDan Williams } 5916bc75619SDan Williams 5926bc75619SDan Williams static void *__test_alloc(struct nfit_test *t, size_t size, dma_addr_t *dma, 5936bc75619SDan Williams void *buf) 5946bc75619SDan Williams { 5956bc75619SDan Williams struct device *dev = &t->pdev.dev; 5966bc75619SDan Williams struct nfit_test_resource *nfit_res = kzalloc(sizeof(*nfit_res), 5976bc75619SDan Williams GFP_KERNEL); 5986bc75619SDan Williams int rc; 5996bc75619SDan Williams 600bd4cd745SDan Williams if (!buf || !nfit_res) 6016bc75619SDan Williams goto err; 6026bc75619SDan Williams rc = devm_add_action(dev, release_nfit_res, nfit_res); 6036bc75619SDan Williams if (rc) 6046bc75619SDan Williams goto err; 6056bc75619SDan Williams INIT_LIST_HEAD(&nfit_res->list); 6066bc75619SDan Williams memset(buf, 0, size); 6076bc75619SDan Williams nfit_res->dev = dev; 6086bc75619SDan Williams nfit_res->buf = buf; 609bd4cd745SDan Williams nfit_res->res.start = *dma; 610bd4cd745SDan Williams nfit_res->res.end = *dma + size - 1; 611bd4cd745SDan Williams nfit_res->res.name = "NFIT"; 612bd4cd745SDan Williams spin_lock_init(&nfit_res->lock); 613bd4cd745SDan Williams INIT_LIST_HEAD(&nfit_res->requests); 6146bc75619SDan Williams spin_lock(&nfit_test_lock); 6156bc75619SDan Williams list_add(&nfit_res->list, &t->resources); 6166bc75619SDan Williams spin_unlock(&nfit_test_lock); 6176bc75619SDan Williams 6186bc75619SDan Williams return nfit_res->buf; 6196bc75619SDan Williams err: 620ee8520feSDan Williams if (buf) 6216bc75619SDan Williams vfree(buf); 6226bc75619SDan Williams kfree(nfit_res); 6236bc75619SDan Williams return NULL; 6246bc75619SDan Williams } 6256bc75619SDan Williams 6266bc75619SDan Williams static void *test_alloc(struct nfit_test *t, size_t size, dma_addr_t *dma) 6276bc75619SDan Williams { 6286bc75619SDan Williams void *buf = vmalloc(size); 6296bc75619SDan Williams 6306bc75619SDan Williams *dma = (unsigned long) buf; 6316bc75619SDan Williams return __test_alloc(t, size, dma, buf); 6326bc75619SDan Williams } 6336bc75619SDan Williams 6346bc75619SDan Williams static struct nfit_test_resource *nfit_test_lookup(resource_size_t addr) 6356bc75619SDan Williams { 6366bc75619SDan Williams int i; 6376bc75619SDan Williams 6386bc75619SDan Williams for (i = 0; i < ARRAY_SIZE(instances); i++) { 6396bc75619SDan Williams struct nfit_test_resource *n, *nfit_res = NULL; 6406bc75619SDan Williams struct nfit_test *t = instances[i]; 6416bc75619SDan Williams 6426bc75619SDan Williams if (!t) 6436bc75619SDan Williams continue; 6446bc75619SDan Williams spin_lock(&nfit_test_lock); 6456bc75619SDan Williams list_for_each_entry(n, &t->resources, list) { 646bd4cd745SDan Williams if (addr >= n->res.start && (addr < n->res.start 647bd4cd745SDan Williams + resource_size(&n->res))) { 6486bc75619SDan Williams nfit_res = n; 6496bc75619SDan Williams break; 6506bc75619SDan Williams } else if (addr >= (unsigned long) n->buf 6516bc75619SDan Williams && (addr < (unsigned long) n->buf 652bd4cd745SDan Williams + resource_size(&n->res))) { 6536bc75619SDan Williams nfit_res = n; 6546bc75619SDan Williams break; 6556bc75619SDan Williams } 6566bc75619SDan Williams } 6576bc75619SDan Williams spin_unlock(&nfit_test_lock); 6586bc75619SDan Williams if (nfit_res) 6596bc75619SDan Williams return nfit_res; 6606bc75619SDan Williams } 6616bc75619SDan Williams 6626bc75619SDan Williams return NULL; 6636bc75619SDan Williams } 6646bc75619SDan Williams 665f471f1a7SDan Williams static int ars_state_init(struct device *dev, struct ars_state *ars_state) 666f471f1a7SDan Williams { 667f471f1a7SDan Williams ars_state->ars_status = devm_kzalloc(dev, 668f471f1a7SDan Williams sizeof(struct nd_cmd_ars_status) 669f471f1a7SDan Williams + sizeof(struct nd_ars_record) * NFIT_TEST_ARS_RECORDS, 670f471f1a7SDan Williams GFP_KERNEL); 671f471f1a7SDan Williams if (!ars_state->ars_status) 672f471f1a7SDan Williams return -ENOMEM; 673f471f1a7SDan Williams spin_lock_init(&ars_state->lock); 674f471f1a7SDan Williams return 0; 675f471f1a7SDan Williams } 676f471f1a7SDan Williams 677231bf117SDan Williams static void put_dimms(void *data) 678231bf117SDan Williams { 679231bf117SDan Williams struct device **dimm_dev = data; 680231bf117SDan Williams int i; 681231bf117SDan Williams 682231bf117SDan Williams for (i = 0; i < NUM_DCR; i++) 683231bf117SDan Williams if (dimm_dev[i]) 684231bf117SDan Williams device_unregister(dimm_dev[i]); 685231bf117SDan Williams } 686231bf117SDan Williams 687231bf117SDan Williams static struct class *nfit_test_dimm; 688231bf117SDan Williams 68973606afdSDan Williams static int dimm_name_to_id(struct device *dev) 69073606afdSDan Williams { 69173606afdSDan Williams int dimm; 69273606afdSDan Williams 69373606afdSDan Williams if (sscanf(dev_name(dev), "test_dimm%d", &dimm) != 1 69473606afdSDan Williams || dimm >= NUM_DCR || dimm < 0) 69573606afdSDan Williams return -ENXIO; 69673606afdSDan Williams return dimm; 69773606afdSDan Williams } 69873606afdSDan Williams 69973606afdSDan Williams 70073606afdSDan Williams static ssize_t handle_show(struct device *dev, struct device_attribute *attr, 70173606afdSDan Williams char *buf) 70273606afdSDan Williams { 70373606afdSDan Williams int dimm = dimm_name_to_id(dev); 70473606afdSDan Williams 70573606afdSDan Williams if (dimm < 0) 70673606afdSDan Williams return dimm; 70773606afdSDan Williams 70873606afdSDan Williams return sprintf(buf, "%#x", handle[dimm]); 70973606afdSDan Williams } 71073606afdSDan Williams DEVICE_ATTR_RO(handle); 71173606afdSDan Williams 71273606afdSDan Williams static ssize_t fail_cmd_show(struct device *dev, struct device_attribute *attr, 71373606afdSDan Williams char *buf) 71473606afdSDan Williams { 71573606afdSDan Williams int dimm = dimm_name_to_id(dev); 71673606afdSDan Williams 71773606afdSDan Williams if (dimm < 0) 71873606afdSDan Williams return dimm; 71973606afdSDan Williams 72073606afdSDan Williams return sprintf(buf, "%#lx\n", dimm_fail_cmd_flags[dimm]); 72173606afdSDan Williams } 72273606afdSDan Williams 72373606afdSDan Williams static ssize_t fail_cmd_store(struct device *dev, struct device_attribute *attr, 72473606afdSDan Williams const char *buf, size_t size) 72573606afdSDan Williams { 72673606afdSDan Williams int dimm = dimm_name_to_id(dev); 72773606afdSDan Williams unsigned long val; 72873606afdSDan Williams ssize_t rc; 72973606afdSDan Williams 73073606afdSDan Williams if (dimm < 0) 73173606afdSDan Williams return dimm; 73273606afdSDan Williams 73373606afdSDan Williams rc = kstrtol(buf, 0, &val); 73473606afdSDan Williams if (rc) 73573606afdSDan Williams return rc; 73673606afdSDan Williams 73773606afdSDan Williams dimm_fail_cmd_flags[dimm] = val; 73873606afdSDan Williams return size; 73973606afdSDan Williams } 74073606afdSDan Williams static DEVICE_ATTR_RW(fail_cmd); 74173606afdSDan Williams 74273606afdSDan Williams static struct attribute *nfit_test_dimm_attributes[] = { 74373606afdSDan Williams &dev_attr_fail_cmd.attr, 74473606afdSDan Williams &dev_attr_handle.attr, 74573606afdSDan Williams NULL, 74673606afdSDan Williams }; 74773606afdSDan Williams 74873606afdSDan Williams static struct attribute_group nfit_test_dimm_attribute_group = { 74973606afdSDan Williams .attrs = nfit_test_dimm_attributes, 75073606afdSDan Williams }; 75173606afdSDan Williams 75273606afdSDan Williams static const struct attribute_group *nfit_test_dimm_attribute_groups[] = { 75373606afdSDan Williams &nfit_test_dimm_attribute_group, 75473606afdSDan Williams NULL, 75573606afdSDan Williams }; 75673606afdSDan Williams 7576bc75619SDan Williams static int nfit_test0_alloc(struct nfit_test *t) 7586bc75619SDan Williams { 7596b577c9dSLinda Knippers size_t nfit_size = sizeof(struct acpi_nfit_system_address) * NUM_SPA 7606bc75619SDan Williams + sizeof(struct acpi_nfit_memory_map) * NUM_MEM 7616bc75619SDan Williams + sizeof(struct acpi_nfit_control_region) * NUM_DCR 7623b87356fSDan Williams + offsetof(struct acpi_nfit_control_region, 7633b87356fSDan Williams window_size) * NUM_DCR 7649d27a87eSDan Williams + sizeof(struct acpi_nfit_data_region) * NUM_BDW 76585d3fa02SDan Williams + (sizeof(struct acpi_nfit_flush_address) 76685d3fa02SDan Williams + sizeof(u64) * NUM_HINTS) * NUM_DCR; 7676bc75619SDan Williams int i; 7686bc75619SDan Williams 7696bc75619SDan Williams t->nfit_buf = test_alloc(t, nfit_size, &t->nfit_dma); 7706bc75619SDan Williams if (!t->nfit_buf) 7716bc75619SDan Williams return -ENOMEM; 7726bc75619SDan Williams t->nfit_size = nfit_size; 7736bc75619SDan Williams 774ee8520feSDan Williams t->spa_set[0] = test_alloc(t, SPA0_SIZE, &t->spa_set_dma[0]); 7756bc75619SDan Williams if (!t->spa_set[0]) 7766bc75619SDan Williams return -ENOMEM; 7776bc75619SDan Williams 778ee8520feSDan Williams t->spa_set[1] = test_alloc(t, SPA1_SIZE, &t->spa_set_dma[1]); 7796bc75619SDan Williams if (!t->spa_set[1]) 7806bc75619SDan Williams return -ENOMEM; 7816bc75619SDan Williams 782ee8520feSDan Williams t->spa_set[2] = test_alloc(t, SPA0_SIZE, &t->spa_set_dma[2]); 78320985164SVishal Verma if (!t->spa_set[2]) 78420985164SVishal Verma return -ENOMEM; 78520985164SVishal Verma 786dafb1048SDan Williams for (i = 0; i < t->num_dcr; i++) { 7876bc75619SDan Williams t->dimm[i] = test_alloc(t, DIMM_SIZE, &t->dimm_dma[i]); 7886bc75619SDan Williams if (!t->dimm[i]) 7896bc75619SDan Williams return -ENOMEM; 7906bc75619SDan Williams 7916bc75619SDan Williams t->label[i] = test_alloc(t, LABEL_SIZE, &t->label_dma[i]); 7926bc75619SDan Williams if (!t->label[i]) 7936bc75619SDan Williams return -ENOMEM; 7946bc75619SDan Williams sprintf(t->label[i], "label%d", i); 7959d27a87eSDan Williams 7969d15ce9cSDan Williams t->flush[i] = test_alloc(t, max(PAGE_SIZE, 7979d15ce9cSDan Williams sizeof(u64) * NUM_HINTS), 79885d3fa02SDan Williams &t->flush_dma[i]); 7999d27a87eSDan Williams if (!t->flush[i]) 8009d27a87eSDan Williams return -ENOMEM; 8016bc75619SDan Williams } 8026bc75619SDan Williams 803dafb1048SDan Williams for (i = 0; i < t->num_dcr; i++) { 8046bc75619SDan Williams t->dcr[i] = test_alloc(t, LABEL_SIZE, &t->dcr_dma[i]); 8056bc75619SDan Williams if (!t->dcr[i]) 8066bc75619SDan Williams return -ENOMEM; 8076bc75619SDan Williams } 8086bc75619SDan Williams 809c14a868aSDan Williams t->_fit = test_alloc(t, sizeof(union acpi_object **), &t->_fit_dma); 810c14a868aSDan Williams if (!t->_fit) 811c14a868aSDan Williams return -ENOMEM; 812c14a868aSDan Williams 813231bf117SDan Williams if (devm_add_action_or_reset(&t->pdev.dev, put_dimms, t->dimm_dev)) 814231bf117SDan Williams return -ENOMEM; 815231bf117SDan Williams for (i = 0; i < NUM_DCR; i++) { 81673606afdSDan Williams t->dimm_dev[i] = device_create_with_groups(nfit_test_dimm, 81773606afdSDan Williams &t->pdev.dev, 0, NULL, 81873606afdSDan Williams nfit_test_dimm_attribute_groups, 81973606afdSDan Williams "test_dimm%d", i); 820231bf117SDan Williams if (!t->dimm_dev[i]) 821231bf117SDan Williams return -ENOMEM; 822231bf117SDan Williams } 823231bf117SDan Williams 824f471f1a7SDan Williams return ars_state_init(&t->pdev.dev, &t->ars_state); 8256bc75619SDan Williams } 8266bc75619SDan Williams 8276bc75619SDan Williams static int nfit_test1_alloc(struct nfit_test *t) 8286bc75619SDan Williams { 8297bfe97c7SDan Williams size_t nfit_size = sizeof(struct acpi_nfit_system_address) * 2 830ac40b675SDan Williams + sizeof(struct acpi_nfit_memory_map) * 2 831ac40b675SDan Williams + offsetof(struct acpi_nfit_control_region, window_size) * 2; 832dafb1048SDan Williams int i; 8336bc75619SDan Williams 8346bc75619SDan Williams t->nfit_buf = test_alloc(t, nfit_size, &t->nfit_dma); 8356bc75619SDan Williams if (!t->nfit_buf) 8366bc75619SDan Williams return -ENOMEM; 8376bc75619SDan Williams t->nfit_size = nfit_size; 8386bc75619SDan Williams 839ee8520feSDan Williams t->spa_set[0] = test_alloc(t, SPA2_SIZE, &t->spa_set_dma[0]); 8406bc75619SDan Williams if (!t->spa_set[0]) 8416bc75619SDan Williams return -ENOMEM; 8426bc75619SDan Williams 843dafb1048SDan Williams for (i = 0; i < t->num_dcr; i++) { 844dafb1048SDan Williams t->label[i] = test_alloc(t, LABEL_SIZE, &t->label_dma[i]); 845dafb1048SDan Williams if (!t->label[i]) 846dafb1048SDan Williams return -ENOMEM; 847dafb1048SDan Williams sprintf(t->label[i], "label%d", i); 848dafb1048SDan Williams } 849dafb1048SDan Williams 8507bfe97c7SDan Williams t->spa_set[1] = test_alloc(t, SPA_VCD_SIZE, &t->spa_set_dma[1]); 8517bfe97c7SDan Williams if (!t->spa_set[1]) 8527bfe97c7SDan Williams return -ENOMEM; 8537bfe97c7SDan Williams 854f471f1a7SDan Williams return ars_state_init(&t->pdev.dev, &t->ars_state); 8556bc75619SDan Williams } 8566bc75619SDan Williams 8575dc68e55SDan Williams static void dcr_common_init(struct acpi_nfit_control_region *dcr) 8585dc68e55SDan Williams { 8595dc68e55SDan Williams dcr->vendor_id = 0xabcd; 8605dc68e55SDan Williams dcr->device_id = 0; 8615dc68e55SDan Williams dcr->revision_id = 1; 8625dc68e55SDan Williams dcr->valid_fields = 1; 8635dc68e55SDan Williams dcr->manufacturing_location = 0xa; 8645dc68e55SDan Williams dcr->manufacturing_date = cpu_to_be16(2016); 8655dc68e55SDan Williams } 8665dc68e55SDan Williams 8676bc75619SDan Williams static void nfit_test0_setup(struct nfit_test *t) 8686bc75619SDan Williams { 86985d3fa02SDan Williams const int flush_hint_size = sizeof(struct acpi_nfit_flush_address) 87085d3fa02SDan Williams + (sizeof(u64) * NUM_HINTS); 8716bc75619SDan Williams struct acpi_nfit_desc *acpi_desc; 8726bc75619SDan Williams struct acpi_nfit_memory_map *memdev; 8736bc75619SDan Williams void *nfit_buf = t->nfit_buf; 8746bc75619SDan Williams struct acpi_nfit_system_address *spa; 8756bc75619SDan Williams struct acpi_nfit_control_region *dcr; 8766bc75619SDan Williams struct acpi_nfit_data_region *bdw; 8779d27a87eSDan Williams struct acpi_nfit_flush_address *flush; 87885d3fa02SDan Williams unsigned int offset, i; 8796bc75619SDan Williams 8806bc75619SDan Williams /* 8816bc75619SDan Williams * spa0 (interleave first half of dimm0 and dimm1, note storage 8826bc75619SDan Williams * does not actually alias the related block-data-window 8836bc75619SDan Williams * regions) 8846bc75619SDan Williams */ 8856b577c9dSLinda Knippers spa = nfit_buf; 8866bc75619SDan Williams spa->header.type = ACPI_NFIT_TYPE_SYSTEM_ADDRESS; 8876bc75619SDan Williams spa->header.length = sizeof(*spa); 8886bc75619SDan Williams memcpy(spa->range_guid, to_nfit_uuid(NFIT_SPA_PM), 16); 8896bc75619SDan Williams spa->range_index = 0+1; 8906bc75619SDan Williams spa->address = t->spa_set_dma[0]; 8916bc75619SDan Williams spa->length = SPA0_SIZE; 8926bc75619SDan Williams 8936bc75619SDan Williams /* 8946bc75619SDan Williams * spa1 (interleave last half of the 4 DIMMS, note storage 8956bc75619SDan Williams * does not actually alias the related block-data-window 8966bc75619SDan Williams * regions) 8976bc75619SDan Williams */ 8986b577c9dSLinda Knippers spa = nfit_buf + sizeof(*spa); 8996bc75619SDan Williams spa->header.type = ACPI_NFIT_TYPE_SYSTEM_ADDRESS; 9006bc75619SDan Williams spa->header.length = sizeof(*spa); 9016bc75619SDan Williams memcpy(spa->range_guid, to_nfit_uuid(NFIT_SPA_PM), 16); 9026bc75619SDan Williams spa->range_index = 1+1; 9036bc75619SDan Williams spa->address = t->spa_set_dma[1]; 9046bc75619SDan Williams spa->length = SPA1_SIZE; 9056bc75619SDan Williams 9066bc75619SDan Williams /* spa2 (dcr0) dimm0 */ 9076b577c9dSLinda Knippers spa = nfit_buf + sizeof(*spa) * 2; 9086bc75619SDan Williams spa->header.type = ACPI_NFIT_TYPE_SYSTEM_ADDRESS; 9096bc75619SDan Williams spa->header.length = sizeof(*spa); 9106bc75619SDan Williams memcpy(spa->range_guid, to_nfit_uuid(NFIT_SPA_DCR), 16); 9116bc75619SDan Williams spa->range_index = 2+1; 9126bc75619SDan Williams spa->address = t->dcr_dma[0]; 9136bc75619SDan Williams spa->length = DCR_SIZE; 9146bc75619SDan Williams 9156bc75619SDan Williams /* spa3 (dcr1) dimm1 */ 9166b577c9dSLinda Knippers spa = nfit_buf + sizeof(*spa) * 3; 9176bc75619SDan Williams spa->header.type = ACPI_NFIT_TYPE_SYSTEM_ADDRESS; 9186bc75619SDan Williams spa->header.length = sizeof(*spa); 9196bc75619SDan Williams memcpy(spa->range_guid, to_nfit_uuid(NFIT_SPA_DCR), 16); 9206bc75619SDan Williams spa->range_index = 3+1; 9216bc75619SDan Williams spa->address = t->dcr_dma[1]; 9226bc75619SDan Williams spa->length = DCR_SIZE; 9236bc75619SDan Williams 9246bc75619SDan Williams /* spa4 (dcr2) dimm2 */ 9256b577c9dSLinda Knippers spa = nfit_buf + sizeof(*spa) * 4; 9266bc75619SDan Williams spa->header.type = ACPI_NFIT_TYPE_SYSTEM_ADDRESS; 9276bc75619SDan Williams spa->header.length = sizeof(*spa); 9286bc75619SDan Williams memcpy(spa->range_guid, to_nfit_uuid(NFIT_SPA_DCR), 16); 9296bc75619SDan Williams spa->range_index = 4+1; 9306bc75619SDan Williams spa->address = t->dcr_dma[2]; 9316bc75619SDan Williams spa->length = DCR_SIZE; 9326bc75619SDan Williams 9336bc75619SDan Williams /* spa5 (dcr3) dimm3 */ 9346b577c9dSLinda Knippers spa = nfit_buf + sizeof(*spa) * 5; 9356bc75619SDan Williams spa->header.type = ACPI_NFIT_TYPE_SYSTEM_ADDRESS; 9366bc75619SDan Williams spa->header.length = sizeof(*spa); 9376bc75619SDan Williams memcpy(spa->range_guid, to_nfit_uuid(NFIT_SPA_DCR), 16); 9386bc75619SDan Williams spa->range_index = 5+1; 9396bc75619SDan Williams spa->address = t->dcr_dma[3]; 9406bc75619SDan Williams spa->length = DCR_SIZE; 9416bc75619SDan Williams 9426bc75619SDan Williams /* spa6 (bdw for dcr0) dimm0 */ 9436b577c9dSLinda Knippers spa = nfit_buf + sizeof(*spa) * 6; 9446bc75619SDan Williams spa->header.type = ACPI_NFIT_TYPE_SYSTEM_ADDRESS; 9456bc75619SDan Williams spa->header.length = sizeof(*spa); 9466bc75619SDan Williams memcpy(spa->range_guid, to_nfit_uuid(NFIT_SPA_BDW), 16); 9476bc75619SDan Williams spa->range_index = 6+1; 9486bc75619SDan Williams spa->address = t->dimm_dma[0]; 9496bc75619SDan Williams spa->length = DIMM_SIZE; 9506bc75619SDan Williams 9516bc75619SDan Williams /* spa7 (bdw for dcr1) dimm1 */ 9526b577c9dSLinda Knippers spa = nfit_buf + sizeof(*spa) * 7; 9536bc75619SDan Williams spa->header.type = ACPI_NFIT_TYPE_SYSTEM_ADDRESS; 9546bc75619SDan Williams spa->header.length = sizeof(*spa); 9556bc75619SDan Williams memcpy(spa->range_guid, to_nfit_uuid(NFIT_SPA_BDW), 16); 9566bc75619SDan Williams spa->range_index = 7+1; 9576bc75619SDan Williams spa->address = t->dimm_dma[1]; 9586bc75619SDan Williams spa->length = DIMM_SIZE; 9596bc75619SDan Williams 9606bc75619SDan Williams /* spa8 (bdw for dcr2) dimm2 */ 9616b577c9dSLinda Knippers spa = nfit_buf + sizeof(*spa) * 8; 9626bc75619SDan Williams spa->header.type = ACPI_NFIT_TYPE_SYSTEM_ADDRESS; 9636bc75619SDan Williams spa->header.length = sizeof(*spa); 9646bc75619SDan Williams memcpy(spa->range_guid, to_nfit_uuid(NFIT_SPA_BDW), 16); 9656bc75619SDan Williams spa->range_index = 8+1; 9666bc75619SDan Williams spa->address = t->dimm_dma[2]; 9676bc75619SDan Williams spa->length = DIMM_SIZE; 9686bc75619SDan Williams 9696bc75619SDan Williams /* spa9 (bdw for dcr3) dimm3 */ 9706b577c9dSLinda Knippers spa = nfit_buf + sizeof(*spa) * 9; 9716bc75619SDan Williams spa->header.type = ACPI_NFIT_TYPE_SYSTEM_ADDRESS; 9726bc75619SDan Williams spa->header.length = sizeof(*spa); 9736bc75619SDan Williams memcpy(spa->range_guid, to_nfit_uuid(NFIT_SPA_BDW), 16); 9746bc75619SDan Williams spa->range_index = 9+1; 9756bc75619SDan Williams spa->address = t->dimm_dma[3]; 9766bc75619SDan Williams spa->length = DIMM_SIZE; 9776bc75619SDan Williams 9786b577c9dSLinda Knippers offset = sizeof(*spa) * 10; 9796bc75619SDan Williams /* mem-region0 (spa0, dimm0) */ 9806bc75619SDan Williams memdev = nfit_buf + offset; 9816bc75619SDan Williams memdev->header.type = ACPI_NFIT_TYPE_MEMORY_MAP; 9826bc75619SDan Williams memdev->header.length = sizeof(*memdev); 9836bc75619SDan Williams memdev->device_handle = handle[0]; 9846bc75619SDan Williams memdev->physical_id = 0; 9856bc75619SDan Williams memdev->region_id = 0; 9866bc75619SDan Williams memdev->range_index = 0+1; 9873b87356fSDan Williams memdev->region_index = 4+1; 9886bc75619SDan Williams memdev->region_size = SPA0_SIZE/2; 989df06a2d5SDan Williams memdev->region_offset = 1; 9906bc75619SDan Williams memdev->address = 0; 9916bc75619SDan Williams memdev->interleave_index = 0; 9926bc75619SDan Williams memdev->interleave_ways = 2; 9936bc75619SDan Williams 9946bc75619SDan Williams /* mem-region1 (spa0, dimm1) */ 9956bc75619SDan Williams memdev = nfit_buf + offset + sizeof(struct acpi_nfit_memory_map); 9966bc75619SDan Williams memdev->header.type = ACPI_NFIT_TYPE_MEMORY_MAP; 9976bc75619SDan Williams memdev->header.length = sizeof(*memdev); 9986bc75619SDan Williams memdev->device_handle = handle[1]; 9996bc75619SDan Williams memdev->physical_id = 1; 10006bc75619SDan Williams memdev->region_id = 0; 10016bc75619SDan Williams memdev->range_index = 0+1; 10023b87356fSDan Williams memdev->region_index = 5+1; 10036bc75619SDan Williams memdev->region_size = SPA0_SIZE/2; 1004df06a2d5SDan Williams memdev->region_offset = (1 << 8); 10056bc75619SDan Williams memdev->address = 0; 10066bc75619SDan Williams memdev->interleave_index = 0; 10076bc75619SDan Williams memdev->interleave_ways = 2; 1008ac40b675SDan Williams memdev->flags = ACPI_NFIT_MEM_HEALTH_ENABLED; 10096bc75619SDan Williams 10106bc75619SDan Williams /* mem-region2 (spa1, dimm0) */ 10116bc75619SDan Williams memdev = nfit_buf + offset + sizeof(struct acpi_nfit_memory_map) * 2; 10126bc75619SDan Williams memdev->header.type = ACPI_NFIT_TYPE_MEMORY_MAP; 10136bc75619SDan Williams memdev->header.length = sizeof(*memdev); 10146bc75619SDan Williams memdev->device_handle = handle[0]; 10156bc75619SDan Williams memdev->physical_id = 0; 10166bc75619SDan Williams memdev->region_id = 1; 10176bc75619SDan Williams memdev->range_index = 1+1; 10183b87356fSDan Williams memdev->region_index = 4+1; 10196bc75619SDan Williams memdev->region_size = SPA1_SIZE/4; 1020df06a2d5SDan Williams memdev->region_offset = (1 << 16); 10216bc75619SDan Williams memdev->address = SPA0_SIZE/2; 10226bc75619SDan Williams memdev->interleave_index = 0; 10236bc75619SDan Williams memdev->interleave_ways = 4; 1024ac40b675SDan Williams memdev->flags = ACPI_NFIT_MEM_HEALTH_ENABLED; 10256bc75619SDan Williams 10266bc75619SDan Williams /* mem-region3 (spa1, dimm1) */ 10276bc75619SDan Williams memdev = nfit_buf + offset + sizeof(struct acpi_nfit_memory_map) * 3; 10286bc75619SDan Williams memdev->header.type = ACPI_NFIT_TYPE_MEMORY_MAP; 10296bc75619SDan Williams memdev->header.length = sizeof(*memdev); 10306bc75619SDan Williams memdev->device_handle = handle[1]; 10316bc75619SDan Williams memdev->physical_id = 1; 10326bc75619SDan Williams memdev->region_id = 1; 10336bc75619SDan Williams memdev->range_index = 1+1; 10343b87356fSDan Williams memdev->region_index = 5+1; 10356bc75619SDan Williams memdev->region_size = SPA1_SIZE/4; 1036df06a2d5SDan Williams memdev->region_offset = (1 << 24); 10376bc75619SDan Williams memdev->address = SPA0_SIZE/2; 10386bc75619SDan Williams memdev->interleave_index = 0; 10396bc75619SDan Williams memdev->interleave_ways = 4; 10406bc75619SDan Williams 10416bc75619SDan Williams /* mem-region4 (spa1, dimm2) */ 10426bc75619SDan Williams memdev = nfit_buf + offset + sizeof(struct acpi_nfit_memory_map) * 4; 10436bc75619SDan Williams memdev->header.type = ACPI_NFIT_TYPE_MEMORY_MAP; 10446bc75619SDan Williams memdev->header.length = sizeof(*memdev); 10456bc75619SDan Williams memdev->device_handle = handle[2]; 10466bc75619SDan Williams memdev->physical_id = 2; 10476bc75619SDan Williams memdev->region_id = 0; 10486bc75619SDan Williams memdev->range_index = 1+1; 10493b87356fSDan Williams memdev->region_index = 6+1; 10506bc75619SDan Williams memdev->region_size = SPA1_SIZE/4; 1051df06a2d5SDan Williams memdev->region_offset = (1ULL << 32); 10526bc75619SDan Williams memdev->address = SPA0_SIZE/2; 10536bc75619SDan Williams memdev->interleave_index = 0; 10546bc75619SDan Williams memdev->interleave_ways = 4; 1055ac40b675SDan Williams memdev->flags = ACPI_NFIT_MEM_HEALTH_ENABLED; 10566bc75619SDan Williams 10576bc75619SDan Williams /* mem-region5 (spa1, dimm3) */ 10586bc75619SDan Williams memdev = nfit_buf + offset + sizeof(struct acpi_nfit_memory_map) * 5; 10596bc75619SDan Williams memdev->header.type = ACPI_NFIT_TYPE_MEMORY_MAP; 10606bc75619SDan Williams memdev->header.length = sizeof(*memdev); 10616bc75619SDan Williams memdev->device_handle = handle[3]; 10626bc75619SDan Williams memdev->physical_id = 3; 10636bc75619SDan Williams memdev->region_id = 0; 10646bc75619SDan Williams memdev->range_index = 1+1; 10653b87356fSDan Williams memdev->region_index = 7+1; 10666bc75619SDan Williams memdev->region_size = SPA1_SIZE/4; 1067df06a2d5SDan Williams memdev->region_offset = (1ULL << 40); 10686bc75619SDan Williams memdev->address = SPA0_SIZE/2; 10696bc75619SDan Williams memdev->interleave_index = 0; 10706bc75619SDan Williams memdev->interleave_ways = 4; 10716bc75619SDan Williams 10726bc75619SDan Williams /* mem-region6 (spa/dcr0, dimm0) */ 10736bc75619SDan Williams memdev = nfit_buf + offset + sizeof(struct acpi_nfit_memory_map) * 6; 10746bc75619SDan Williams memdev->header.type = ACPI_NFIT_TYPE_MEMORY_MAP; 10756bc75619SDan Williams memdev->header.length = sizeof(*memdev); 10766bc75619SDan Williams memdev->device_handle = handle[0]; 10776bc75619SDan Williams memdev->physical_id = 0; 10786bc75619SDan Williams memdev->region_id = 0; 10796bc75619SDan Williams memdev->range_index = 2+1; 10806bc75619SDan Williams memdev->region_index = 0+1; 10816bc75619SDan Williams memdev->region_size = 0; 10826bc75619SDan Williams memdev->region_offset = 0; 10836bc75619SDan Williams memdev->address = 0; 10846bc75619SDan Williams memdev->interleave_index = 0; 10856bc75619SDan Williams memdev->interleave_ways = 1; 10866bc75619SDan Williams 10876bc75619SDan Williams /* mem-region7 (spa/dcr1, dimm1) */ 10886bc75619SDan Williams memdev = nfit_buf + offset + sizeof(struct acpi_nfit_memory_map) * 7; 10896bc75619SDan Williams memdev->header.type = ACPI_NFIT_TYPE_MEMORY_MAP; 10906bc75619SDan Williams memdev->header.length = sizeof(*memdev); 10916bc75619SDan Williams memdev->device_handle = handle[1]; 10926bc75619SDan Williams memdev->physical_id = 1; 10936bc75619SDan Williams memdev->region_id = 0; 10946bc75619SDan Williams memdev->range_index = 3+1; 10956bc75619SDan Williams memdev->region_index = 1+1; 10966bc75619SDan Williams memdev->region_size = 0; 10976bc75619SDan Williams memdev->region_offset = 0; 10986bc75619SDan Williams memdev->address = 0; 10996bc75619SDan Williams memdev->interleave_index = 0; 11006bc75619SDan Williams memdev->interleave_ways = 1; 11016bc75619SDan Williams 11026bc75619SDan Williams /* mem-region8 (spa/dcr2, dimm2) */ 11036bc75619SDan Williams memdev = nfit_buf + offset + sizeof(struct acpi_nfit_memory_map) * 8; 11046bc75619SDan Williams memdev->header.type = ACPI_NFIT_TYPE_MEMORY_MAP; 11056bc75619SDan Williams memdev->header.length = sizeof(*memdev); 11066bc75619SDan Williams memdev->device_handle = handle[2]; 11076bc75619SDan Williams memdev->physical_id = 2; 11086bc75619SDan Williams memdev->region_id = 0; 11096bc75619SDan Williams memdev->range_index = 4+1; 11106bc75619SDan Williams memdev->region_index = 2+1; 11116bc75619SDan Williams memdev->region_size = 0; 11126bc75619SDan Williams memdev->region_offset = 0; 11136bc75619SDan Williams memdev->address = 0; 11146bc75619SDan Williams memdev->interleave_index = 0; 11156bc75619SDan Williams memdev->interleave_ways = 1; 11166bc75619SDan Williams 11176bc75619SDan Williams /* mem-region9 (spa/dcr3, dimm3) */ 11186bc75619SDan Williams memdev = nfit_buf + offset + sizeof(struct acpi_nfit_memory_map) * 9; 11196bc75619SDan Williams memdev->header.type = ACPI_NFIT_TYPE_MEMORY_MAP; 11206bc75619SDan Williams memdev->header.length = sizeof(*memdev); 11216bc75619SDan Williams memdev->device_handle = handle[3]; 11226bc75619SDan Williams memdev->physical_id = 3; 11236bc75619SDan Williams memdev->region_id = 0; 11246bc75619SDan Williams memdev->range_index = 5+1; 11256bc75619SDan Williams memdev->region_index = 3+1; 11266bc75619SDan Williams memdev->region_size = 0; 11276bc75619SDan Williams memdev->region_offset = 0; 11286bc75619SDan Williams memdev->address = 0; 11296bc75619SDan Williams memdev->interleave_index = 0; 11306bc75619SDan Williams memdev->interleave_ways = 1; 11316bc75619SDan Williams 11326bc75619SDan Williams /* mem-region10 (spa/bdw0, dimm0) */ 11336bc75619SDan Williams memdev = nfit_buf + offset + sizeof(struct acpi_nfit_memory_map) * 10; 11346bc75619SDan Williams memdev->header.type = ACPI_NFIT_TYPE_MEMORY_MAP; 11356bc75619SDan Williams memdev->header.length = sizeof(*memdev); 11366bc75619SDan Williams memdev->device_handle = handle[0]; 11376bc75619SDan Williams memdev->physical_id = 0; 11386bc75619SDan Williams memdev->region_id = 0; 11396bc75619SDan Williams memdev->range_index = 6+1; 11406bc75619SDan Williams memdev->region_index = 0+1; 11416bc75619SDan Williams memdev->region_size = 0; 11426bc75619SDan Williams memdev->region_offset = 0; 11436bc75619SDan Williams memdev->address = 0; 11446bc75619SDan Williams memdev->interleave_index = 0; 11456bc75619SDan Williams memdev->interleave_ways = 1; 11466bc75619SDan Williams 11476bc75619SDan Williams /* mem-region11 (spa/bdw1, dimm1) */ 11486bc75619SDan Williams memdev = nfit_buf + offset + sizeof(struct acpi_nfit_memory_map) * 11; 11496bc75619SDan Williams memdev->header.type = ACPI_NFIT_TYPE_MEMORY_MAP; 11506bc75619SDan Williams memdev->header.length = sizeof(*memdev); 11516bc75619SDan Williams memdev->device_handle = handle[1]; 11526bc75619SDan Williams memdev->physical_id = 1; 11536bc75619SDan Williams memdev->region_id = 0; 11546bc75619SDan Williams memdev->range_index = 7+1; 11556bc75619SDan Williams memdev->region_index = 1+1; 11566bc75619SDan Williams memdev->region_size = 0; 11576bc75619SDan Williams memdev->region_offset = 0; 11586bc75619SDan Williams memdev->address = 0; 11596bc75619SDan Williams memdev->interleave_index = 0; 11606bc75619SDan Williams memdev->interleave_ways = 1; 11616bc75619SDan Williams 11626bc75619SDan Williams /* mem-region12 (spa/bdw2, dimm2) */ 11636bc75619SDan Williams memdev = nfit_buf + offset + sizeof(struct acpi_nfit_memory_map) * 12; 11646bc75619SDan Williams memdev->header.type = ACPI_NFIT_TYPE_MEMORY_MAP; 11656bc75619SDan Williams memdev->header.length = sizeof(*memdev); 11666bc75619SDan Williams memdev->device_handle = handle[2]; 11676bc75619SDan Williams memdev->physical_id = 2; 11686bc75619SDan Williams memdev->region_id = 0; 11696bc75619SDan Williams memdev->range_index = 8+1; 11706bc75619SDan Williams memdev->region_index = 2+1; 11716bc75619SDan Williams memdev->region_size = 0; 11726bc75619SDan Williams memdev->region_offset = 0; 11736bc75619SDan Williams memdev->address = 0; 11746bc75619SDan Williams memdev->interleave_index = 0; 11756bc75619SDan Williams memdev->interleave_ways = 1; 11766bc75619SDan Williams 11776bc75619SDan Williams /* mem-region13 (spa/dcr3, dimm3) */ 11786bc75619SDan Williams memdev = nfit_buf + offset + sizeof(struct acpi_nfit_memory_map) * 13; 11796bc75619SDan Williams memdev->header.type = ACPI_NFIT_TYPE_MEMORY_MAP; 11806bc75619SDan Williams memdev->header.length = sizeof(*memdev); 11816bc75619SDan Williams memdev->device_handle = handle[3]; 11826bc75619SDan Williams memdev->physical_id = 3; 11836bc75619SDan Williams memdev->region_id = 0; 11846bc75619SDan Williams memdev->range_index = 9+1; 11856bc75619SDan Williams memdev->region_index = 3+1; 11866bc75619SDan Williams memdev->region_size = 0; 11876bc75619SDan Williams memdev->region_offset = 0; 11886bc75619SDan Williams memdev->address = 0; 11896bc75619SDan Williams memdev->interleave_index = 0; 11906bc75619SDan Williams memdev->interleave_ways = 1; 1191ac40b675SDan Williams memdev->flags = ACPI_NFIT_MEM_HEALTH_ENABLED; 11926bc75619SDan Williams 11936bc75619SDan Williams offset = offset + sizeof(struct acpi_nfit_memory_map) * 14; 11943b87356fSDan Williams /* dcr-descriptor0: blk */ 11956bc75619SDan Williams dcr = nfit_buf + offset; 11966bc75619SDan Williams dcr->header.type = ACPI_NFIT_TYPE_CONTROL_REGION; 11976bc75619SDan Williams dcr->header.length = sizeof(struct acpi_nfit_control_region); 11986bc75619SDan Williams dcr->region_index = 0+1; 11995dc68e55SDan Williams dcr_common_init(dcr); 12006bc75619SDan Williams dcr->serial_number = ~handle[0]; 1201be26f9aeSDan Williams dcr->code = NFIT_FIC_BLK; 12026bc75619SDan Williams dcr->windows = 1; 12036bc75619SDan Williams dcr->window_size = DCR_SIZE; 12046bc75619SDan Williams dcr->command_offset = 0; 12056bc75619SDan Williams dcr->command_size = 8; 12066bc75619SDan Williams dcr->status_offset = 8; 12076bc75619SDan Williams dcr->status_size = 4; 12086bc75619SDan Williams 12093b87356fSDan Williams /* dcr-descriptor1: blk */ 12106bc75619SDan Williams dcr = nfit_buf + offset + sizeof(struct acpi_nfit_control_region); 12116bc75619SDan Williams dcr->header.type = ACPI_NFIT_TYPE_CONTROL_REGION; 12126bc75619SDan Williams dcr->header.length = sizeof(struct acpi_nfit_control_region); 12136bc75619SDan Williams dcr->region_index = 1+1; 12145dc68e55SDan Williams dcr_common_init(dcr); 12156bc75619SDan Williams dcr->serial_number = ~handle[1]; 1216be26f9aeSDan Williams dcr->code = NFIT_FIC_BLK; 12176bc75619SDan Williams dcr->windows = 1; 12186bc75619SDan Williams dcr->window_size = DCR_SIZE; 12196bc75619SDan Williams dcr->command_offset = 0; 12206bc75619SDan Williams dcr->command_size = 8; 12216bc75619SDan Williams dcr->status_offset = 8; 12226bc75619SDan Williams dcr->status_size = 4; 12236bc75619SDan Williams 12243b87356fSDan Williams /* dcr-descriptor2: blk */ 12256bc75619SDan Williams dcr = nfit_buf + offset + sizeof(struct acpi_nfit_control_region) * 2; 12266bc75619SDan Williams dcr->header.type = ACPI_NFIT_TYPE_CONTROL_REGION; 12276bc75619SDan Williams dcr->header.length = sizeof(struct acpi_nfit_control_region); 12286bc75619SDan Williams dcr->region_index = 2+1; 12295dc68e55SDan Williams dcr_common_init(dcr); 12306bc75619SDan Williams dcr->serial_number = ~handle[2]; 1231be26f9aeSDan Williams dcr->code = NFIT_FIC_BLK; 12326bc75619SDan Williams dcr->windows = 1; 12336bc75619SDan Williams dcr->window_size = DCR_SIZE; 12346bc75619SDan Williams dcr->command_offset = 0; 12356bc75619SDan Williams dcr->command_size = 8; 12366bc75619SDan Williams dcr->status_offset = 8; 12376bc75619SDan Williams dcr->status_size = 4; 12386bc75619SDan Williams 12393b87356fSDan Williams /* dcr-descriptor3: blk */ 12406bc75619SDan Williams dcr = nfit_buf + offset + sizeof(struct acpi_nfit_control_region) * 3; 12416bc75619SDan Williams dcr->header.type = ACPI_NFIT_TYPE_CONTROL_REGION; 12426bc75619SDan Williams dcr->header.length = sizeof(struct acpi_nfit_control_region); 12436bc75619SDan Williams dcr->region_index = 3+1; 12445dc68e55SDan Williams dcr_common_init(dcr); 12456bc75619SDan Williams dcr->serial_number = ~handle[3]; 1246be26f9aeSDan Williams dcr->code = NFIT_FIC_BLK; 12476bc75619SDan Williams dcr->windows = 1; 12486bc75619SDan Williams dcr->window_size = DCR_SIZE; 12496bc75619SDan Williams dcr->command_offset = 0; 12506bc75619SDan Williams dcr->command_size = 8; 12516bc75619SDan Williams dcr->status_offset = 8; 12526bc75619SDan Williams dcr->status_size = 4; 12536bc75619SDan Williams 12546bc75619SDan Williams offset = offset + sizeof(struct acpi_nfit_control_region) * 4; 12553b87356fSDan Williams /* dcr-descriptor0: pmem */ 12563b87356fSDan Williams dcr = nfit_buf + offset; 12573b87356fSDan Williams dcr->header.type = ACPI_NFIT_TYPE_CONTROL_REGION; 12583b87356fSDan Williams dcr->header.length = offsetof(struct acpi_nfit_control_region, 12593b87356fSDan Williams window_size); 12603b87356fSDan Williams dcr->region_index = 4+1; 12615dc68e55SDan Williams dcr_common_init(dcr); 12623b87356fSDan Williams dcr->serial_number = ~handle[0]; 12633b87356fSDan Williams dcr->code = NFIT_FIC_BYTEN; 12643b87356fSDan Williams dcr->windows = 0; 12653b87356fSDan Williams 12663b87356fSDan Williams /* dcr-descriptor1: pmem */ 12673b87356fSDan Williams dcr = nfit_buf + offset + offsetof(struct acpi_nfit_control_region, 12683b87356fSDan Williams window_size); 12693b87356fSDan Williams dcr->header.type = ACPI_NFIT_TYPE_CONTROL_REGION; 12703b87356fSDan Williams dcr->header.length = offsetof(struct acpi_nfit_control_region, 12713b87356fSDan Williams window_size); 12723b87356fSDan Williams dcr->region_index = 5+1; 12735dc68e55SDan Williams dcr_common_init(dcr); 12743b87356fSDan Williams dcr->serial_number = ~handle[1]; 12753b87356fSDan Williams dcr->code = NFIT_FIC_BYTEN; 12763b87356fSDan Williams dcr->windows = 0; 12773b87356fSDan Williams 12783b87356fSDan Williams /* dcr-descriptor2: pmem */ 12793b87356fSDan Williams dcr = nfit_buf + offset + offsetof(struct acpi_nfit_control_region, 12803b87356fSDan Williams window_size) * 2; 12813b87356fSDan Williams dcr->header.type = ACPI_NFIT_TYPE_CONTROL_REGION; 12823b87356fSDan Williams dcr->header.length = offsetof(struct acpi_nfit_control_region, 12833b87356fSDan Williams window_size); 12843b87356fSDan Williams dcr->region_index = 6+1; 12855dc68e55SDan Williams dcr_common_init(dcr); 12863b87356fSDan Williams dcr->serial_number = ~handle[2]; 12873b87356fSDan Williams dcr->code = NFIT_FIC_BYTEN; 12883b87356fSDan Williams dcr->windows = 0; 12893b87356fSDan Williams 12903b87356fSDan Williams /* dcr-descriptor3: pmem */ 12913b87356fSDan Williams dcr = nfit_buf + offset + offsetof(struct acpi_nfit_control_region, 12923b87356fSDan Williams window_size) * 3; 12933b87356fSDan Williams dcr->header.type = ACPI_NFIT_TYPE_CONTROL_REGION; 12943b87356fSDan Williams dcr->header.length = offsetof(struct acpi_nfit_control_region, 12953b87356fSDan Williams window_size); 12963b87356fSDan Williams dcr->region_index = 7+1; 12975dc68e55SDan Williams dcr_common_init(dcr); 12983b87356fSDan Williams dcr->serial_number = ~handle[3]; 12993b87356fSDan Williams dcr->code = NFIT_FIC_BYTEN; 13003b87356fSDan Williams dcr->windows = 0; 13013b87356fSDan Williams 13023b87356fSDan Williams offset = offset + offsetof(struct acpi_nfit_control_region, 13033b87356fSDan Williams window_size) * 4; 13046bc75619SDan Williams /* bdw0 (spa/dcr0, dimm0) */ 13056bc75619SDan Williams bdw = nfit_buf + offset; 13066bc75619SDan Williams bdw->header.type = ACPI_NFIT_TYPE_DATA_REGION; 13076bc75619SDan Williams bdw->header.length = sizeof(struct acpi_nfit_data_region); 13086bc75619SDan Williams bdw->region_index = 0+1; 13096bc75619SDan Williams bdw->windows = 1; 13106bc75619SDan Williams bdw->offset = 0; 13116bc75619SDan Williams bdw->size = BDW_SIZE; 13126bc75619SDan Williams bdw->capacity = DIMM_SIZE; 13136bc75619SDan Williams bdw->start_address = 0; 13146bc75619SDan Williams 13156bc75619SDan Williams /* bdw1 (spa/dcr1, dimm1) */ 13166bc75619SDan Williams bdw = nfit_buf + offset + sizeof(struct acpi_nfit_data_region); 13176bc75619SDan Williams bdw->header.type = ACPI_NFIT_TYPE_DATA_REGION; 13186bc75619SDan Williams bdw->header.length = sizeof(struct acpi_nfit_data_region); 13196bc75619SDan Williams bdw->region_index = 1+1; 13206bc75619SDan Williams bdw->windows = 1; 13216bc75619SDan Williams bdw->offset = 0; 13226bc75619SDan Williams bdw->size = BDW_SIZE; 13236bc75619SDan Williams bdw->capacity = DIMM_SIZE; 13246bc75619SDan Williams bdw->start_address = 0; 13256bc75619SDan Williams 13266bc75619SDan Williams /* bdw2 (spa/dcr2, dimm2) */ 13276bc75619SDan Williams bdw = nfit_buf + offset + sizeof(struct acpi_nfit_data_region) * 2; 13286bc75619SDan Williams bdw->header.type = ACPI_NFIT_TYPE_DATA_REGION; 13296bc75619SDan Williams bdw->header.length = sizeof(struct acpi_nfit_data_region); 13306bc75619SDan Williams bdw->region_index = 2+1; 13316bc75619SDan Williams bdw->windows = 1; 13326bc75619SDan Williams bdw->offset = 0; 13336bc75619SDan Williams bdw->size = BDW_SIZE; 13346bc75619SDan Williams bdw->capacity = DIMM_SIZE; 13356bc75619SDan Williams bdw->start_address = 0; 13366bc75619SDan Williams 13376bc75619SDan Williams /* bdw3 (spa/dcr3, dimm3) */ 13386bc75619SDan Williams bdw = nfit_buf + offset + sizeof(struct acpi_nfit_data_region) * 3; 13396bc75619SDan Williams bdw->header.type = ACPI_NFIT_TYPE_DATA_REGION; 13406bc75619SDan Williams bdw->header.length = sizeof(struct acpi_nfit_data_region); 13416bc75619SDan Williams bdw->region_index = 3+1; 13426bc75619SDan Williams bdw->windows = 1; 13436bc75619SDan Williams bdw->offset = 0; 13446bc75619SDan Williams bdw->size = BDW_SIZE; 13456bc75619SDan Williams bdw->capacity = DIMM_SIZE; 13466bc75619SDan Williams bdw->start_address = 0; 13476bc75619SDan Williams 13489d27a87eSDan Williams offset = offset + sizeof(struct acpi_nfit_data_region) * 4; 13499d27a87eSDan Williams /* flush0 (dimm0) */ 13509d27a87eSDan Williams flush = nfit_buf + offset; 13519d27a87eSDan Williams flush->header.type = ACPI_NFIT_TYPE_FLUSH_ADDRESS; 135285d3fa02SDan Williams flush->header.length = flush_hint_size; 13539d27a87eSDan Williams flush->device_handle = handle[0]; 135485d3fa02SDan Williams flush->hint_count = NUM_HINTS; 135585d3fa02SDan Williams for (i = 0; i < NUM_HINTS; i++) 135685d3fa02SDan Williams flush->hint_address[i] = t->flush_dma[0] + i * sizeof(u64); 13579d27a87eSDan Williams 13589d27a87eSDan Williams /* flush1 (dimm1) */ 135985d3fa02SDan Williams flush = nfit_buf + offset + flush_hint_size * 1; 13609d27a87eSDan Williams flush->header.type = ACPI_NFIT_TYPE_FLUSH_ADDRESS; 136185d3fa02SDan Williams flush->header.length = flush_hint_size; 13629d27a87eSDan Williams flush->device_handle = handle[1]; 136385d3fa02SDan Williams flush->hint_count = NUM_HINTS; 136485d3fa02SDan Williams for (i = 0; i < NUM_HINTS; i++) 136585d3fa02SDan Williams flush->hint_address[i] = t->flush_dma[1] + i * sizeof(u64); 13669d27a87eSDan Williams 13679d27a87eSDan Williams /* flush2 (dimm2) */ 136885d3fa02SDan Williams flush = nfit_buf + offset + flush_hint_size * 2; 13699d27a87eSDan Williams flush->header.type = ACPI_NFIT_TYPE_FLUSH_ADDRESS; 137085d3fa02SDan Williams flush->header.length = flush_hint_size; 13719d27a87eSDan Williams flush->device_handle = handle[2]; 137285d3fa02SDan Williams flush->hint_count = NUM_HINTS; 137385d3fa02SDan Williams for (i = 0; i < NUM_HINTS; i++) 137485d3fa02SDan Williams flush->hint_address[i] = t->flush_dma[2] + i * sizeof(u64); 13759d27a87eSDan Williams 13769d27a87eSDan Williams /* flush3 (dimm3) */ 137785d3fa02SDan Williams flush = nfit_buf + offset + flush_hint_size * 3; 13789d27a87eSDan Williams flush->header.type = ACPI_NFIT_TYPE_FLUSH_ADDRESS; 137985d3fa02SDan Williams flush->header.length = flush_hint_size; 13809d27a87eSDan Williams flush->device_handle = handle[3]; 138185d3fa02SDan Williams flush->hint_count = NUM_HINTS; 138285d3fa02SDan Williams for (i = 0; i < NUM_HINTS; i++) 138385d3fa02SDan Williams flush->hint_address[i] = t->flush_dma[3] + i * sizeof(u64); 13849d27a87eSDan Williams 138520985164SVishal Verma if (t->setup_hotplug) { 138685d3fa02SDan Williams offset = offset + flush_hint_size * 4; 13873b87356fSDan Williams /* dcr-descriptor4: blk */ 138820985164SVishal Verma dcr = nfit_buf + offset; 138920985164SVishal Verma dcr->header.type = ACPI_NFIT_TYPE_CONTROL_REGION; 139020985164SVishal Verma dcr->header.length = sizeof(struct acpi_nfit_control_region); 13913b87356fSDan Williams dcr->region_index = 8+1; 13925dc68e55SDan Williams dcr_common_init(dcr); 139320985164SVishal Verma dcr->serial_number = ~handle[4]; 1394be26f9aeSDan Williams dcr->code = NFIT_FIC_BLK; 139520985164SVishal Verma dcr->windows = 1; 139620985164SVishal Verma dcr->window_size = DCR_SIZE; 139720985164SVishal Verma dcr->command_offset = 0; 139820985164SVishal Verma dcr->command_size = 8; 139920985164SVishal Verma dcr->status_offset = 8; 140020985164SVishal Verma dcr->status_size = 4; 140120985164SVishal Verma 140220985164SVishal Verma offset = offset + sizeof(struct acpi_nfit_control_region); 14033b87356fSDan Williams /* dcr-descriptor4: pmem */ 14043b87356fSDan Williams dcr = nfit_buf + offset; 14053b87356fSDan Williams dcr->header.type = ACPI_NFIT_TYPE_CONTROL_REGION; 14063b87356fSDan Williams dcr->header.length = offsetof(struct acpi_nfit_control_region, 14073b87356fSDan Williams window_size); 14083b87356fSDan Williams dcr->region_index = 9+1; 14095dc68e55SDan Williams dcr_common_init(dcr); 14103b87356fSDan Williams dcr->serial_number = ~handle[4]; 14113b87356fSDan Williams dcr->code = NFIT_FIC_BYTEN; 14123b87356fSDan Williams dcr->windows = 0; 14133b87356fSDan Williams 14143b87356fSDan Williams offset = offset + offsetof(struct acpi_nfit_control_region, 14153b87356fSDan Williams window_size); 141620985164SVishal Verma /* bdw4 (spa/dcr4, dimm4) */ 141720985164SVishal Verma bdw = nfit_buf + offset; 141820985164SVishal Verma bdw->header.type = ACPI_NFIT_TYPE_DATA_REGION; 141920985164SVishal Verma bdw->header.length = sizeof(struct acpi_nfit_data_region); 14203b87356fSDan Williams bdw->region_index = 8+1; 142120985164SVishal Verma bdw->windows = 1; 142220985164SVishal Verma bdw->offset = 0; 142320985164SVishal Verma bdw->size = BDW_SIZE; 142420985164SVishal Verma bdw->capacity = DIMM_SIZE; 142520985164SVishal Verma bdw->start_address = 0; 142620985164SVishal Verma 142720985164SVishal Verma offset = offset + sizeof(struct acpi_nfit_data_region); 142820985164SVishal Verma /* spa10 (dcr4) dimm4 */ 142920985164SVishal Verma spa = nfit_buf + offset; 143020985164SVishal Verma spa->header.type = ACPI_NFIT_TYPE_SYSTEM_ADDRESS; 143120985164SVishal Verma spa->header.length = sizeof(*spa); 143220985164SVishal Verma memcpy(spa->range_guid, to_nfit_uuid(NFIT_SPA_DCR), 16); 143320985164SVishal Verma spa->range_index = 10+1; 143420985164SVishal Verma spa->address = t->dcr_dma[4]; 143520985164SVishal Verma spa->length = DCR_SIZE; 143620985164SVishal Verma 143720985164SVishal Verma /* 143820985164SVishal Verma * spa11 (single-dimm interleave for hotplug, note storage 143920985164SVishal Verma * does not actually alias the related block-data-window 144020985164SVishal Verma * regions) 144120985164SVishal Verma */ 144220985164SVishal Verma spa = nfit_buf + offset + sizeof(*spa); 144320985164SVishal Verma spa->header.type = ACPI_NFIT_TYPE_SYSTEM_ADDRESS; 144420985164SVishal Verma spa->header.length = sizeof(*spa); 144520985164SVishal Verma memcpy(spa->range_guid, to_nfit_uuid(NFIT_SPA_PM), 16); 144620985164SVishal Verma spa->range_index = 11+1; 144720985164SVishal Verma spa->address = t->spa_set_dma[2]; 144820985164SVishal Verma spa->length = SPA0_SIZE; 144920985164SVishal Verma 145020985164SVishal Verma /* spa12 (bdw for dcr4) dimm4 */ 145120985164SVishal Verma spa = nfit_buf + offset + sizeof(*spa) * 2; 145220985164SVishal Verma spa->header.type = ACPI_NFIT_TYPE_SYSTEM_ADDRESS; 145320985164SVishal Verma spa->header.length = sizeof(*spa); 145420985164SVishal Verma memcpy(spa->range_guid, to_nfit_uuid(NFIT_SPA_BDW), 16); 145520985164SVishal Verma spa->range_index = 12+1; 145620985164SVishal Verma spa->address = t->dimm_dma[4]; 145720985164SVishal Verma spa->length = DIMM_SIZE; 145820985164SVishal Verma 145920985164SVishal Verma offset = offset + sizeof(*spa) * 3; 146020985164SVishal Verma /* mem-region14 (spa/dcr4, dimm4) */ 146120985164SVishal Verma memdev = nfit_buf + offset; 146220985164SVishal Verma memdev->header.type = ACPI_NFIT_TYPE_MEMORY_MAP; 146320985164SVishal Verma memdev->header.length = sizeof(*memdev); 146420985164SVishal Verma memdev->device_handle = handle[4]; 146520985164SVishal Verma memdev->physical_id = 4; 146620985164SVishal Verma memdev->region_id = 0; 146720985164SVishal Verma memdev->range_index = 10+1; 14683b87356fSDan Williams memdev->region_index = 8+1; 146920985164SVishal Verma memdev->region_size = 0; 147020985164SVishal Verma memdev->region_offset = 0; 147120985164SVishal Verma memdev->address = 0; 147220985164SVishal Verma memdev->interleave_index = 0; 147320985164SVishal Verma memdev->interleave_ways = 1; 147420985164SVishal Verma 147520985164SVishal Verma /* mem-region15 (spa0, dimm4) */ 147620985164SVishal Verma memdev = nfit_buf + offset + 147720985164SVishal Verma sizeof(struct acpi_nfit_memory_map); 147820985164SVishal Verma memdev->header.type = ACPI_NFIT_TYPE_MEMORY_MAP; 147920985164SVishal Verma memdev->header.length = sizeof(*memdev); 148020985164SVishal Verma memdev->device_handle = handle[4]; 148120985164SVishal Verma memdev->physical_id = 4; 148220985164SVishal Verma memdev->region_id = 0; 148320985164SVishal Verma memdev->range_index = 11+1; 14843b87356fSDan Williams memdev->region_index = 9+1; 148520985164SVishal Verma memdev->region_size = SPA0_SIZE; 1486df06a2d5SDan Williams memdev->region_offset = (1ULL << 48); 148720985164SVishal Verma memdev->address = 0; 148820985164SVishal Verma memdev->interleave_index = 0; 148920985164SVishal Verma memdev->interleave_ways = 1; 1490ac40b675SDan Williams memdev->flags = ACPI_NFIT_MEM_HEALTH_ENABLED; 149120985164SVishal Verma 14923b87356fSDan Williams /* mem-region16 (spa/bdw4, dimm4) */ 149320985164SVishal Verma memdev = nfit_buf + offset + 149420985164SVishal Verma sizeof(struct acpi_nfit_memory_map) * 2; 149520985164SVishal Verma memdev->header.type = ACPI_NFIT_TYPE_MEMORY_MAP; 149620985164SVishal Verma memdev->header.length = sizeof(*memdev); 149720985164SVishal Verma memdev->device_handle = handle[4]; 149820985164SVishal Verma memdev->physical_id = 4; 149920985164SVishal Verma memdev->region_id = 0; 150020985164SVishal Verma memdev->range_index = 12+1; 15013b87356fSDan Williams memdev->region_index = 8+1; 150220985164SVishal Verma memdev->region_size = 0; 150320985164SVishal Verma memdev->region_offset = 0; 150420985164SVishal Verma memdev->address = 0; 150520985164SVishal Verma memdev->interleave_index = 0; 150620985164SVishal Verma memdev->interleave_ways = 1; 150720985164SVishal Verma 150820985164SVishal Verma offset = offset + sizeof(struct acpi_nfit_memory_map) * 3; 150920985164SVishal Verma /* flush3 (dimm4) */ 151020985164SVishal Verma flush = nfit_buf + offset; 151120985164SVishal Verma flush->header.type = ACPI_NFIT_TYPE_FLUSH_ADDRESS; 151285d3fa02SDan Williams flush->header.length = flush_hint_size; 151320985164SVishal Verma flush->device_handle = handle[4]; 151485d3fa02SDan Williams flush->hint_count = NUM_HINTS; 151585d3fa02SDan Williams for (i = 0; i < NUM_HINTS; i++) 151685d3fa02SDan Williams flush->hint_address[i] = t->flush_dma[4] 151785d3fa02SDan Williams + i * sizeof(u64); 151820985164SVishal Verma } 151920985164SVishal Verma 1520f471f1a7SDan Williams post_ars_status(&t->ars_state, t->spa_set_dma[0], SPA0_SIZE); 1521f471f1a7SDan Williams 15226bc75619SDan Williams acpi_desc = &t->acpi_desc; 1523e3654ecaSDan Williams set_bit(ND_CMD_GET_CONFIG_SIZE, &acpi_desc->dimm_cmd_force_en); 1524e3654ecaSDan Williams set_bit(ND_CMD_GET_CONFIG_DATA, &acpi_desc->dimm_cmd_force_en); 1525e3654ecaSDan Williams set_bit(ND_CMD_SET_CONFIG_DATA, &acpi_desc->dimm_cmd_force_en); 15261f716d05SDan Williams set_bit(ND_CMD_SMART, &acpi_desc->dimm_cmd_force_en); 1527e3654ecaSDan Williams set_bit(ND_CMD_ARS_CAP, &acpi_desc->bus_cmd_force_en); 1528e3654ecaSDan Williams set_bit(ND_CMD_ARS_START, &acpi_desc->bus_cmd_force_en); 1529e3654ecaSDan Williams set_bit(ND_CMD_ARS_STATUS, &acpi_desc->bus_cmd_force_en); 1530e3654ecaSDan Williams set_bit(ND_CMD_CLEAR_ERROR, &acpi_desc->bus_cmd_force_en); 1531*10246dc8SYasunori Goto set_bit(ND_CMD_CALL, &acpi_desc->bus_cmd_force_en); 15321f716d05SDan Williams set_bit(ND_CMD_SMART_THRESHOLD, &acpi_desc->dimm_cmd_force_en); 1533*10246dc8SYasunori Goto set_bit(NFIT_CMD_TRANSLATE_SPA, &acpi_desc->bus_nfit_cmd_force_en); 15346bc75619SDan Williams } 15356bc75619SDan Williams 15366bc75619SDan Williams static void nfit_test1_setup(struct nfit_test *t) 15376bc75619SDan Williams { 15386b577c9dSLinda Knippers size_t offset; 15396bc75619SDan Williams void *nfit_buf = t->nfit_buf; 15406bc75619SDan Williams struct acpi_nfit_memory_map *memdev; 15416bc75619SDan Williams struct acpi_nfit_control_region *dcr; 15426bc75619SDan Williams struct acpi_nfit_system_address *spa; 1543d26f73f0SDan Williams struct acpi_nfit_desc *acpi_desc; 15446bc75619SDan Williams 15456b577c9dSLinda Knippers offset = 0; 15466bc75619SDan Williams /* spa0 (flat range with no bdw aliasing) */ 15476bc75619SDan Williams spa = nfit_buf + offset; 15486bc75619SDan Williams spa->header.type = ACPI_NFIT_TYPE_SYSTEM_ADDRESS; 15496bc75619SDan Williams spa->header.length = sizeof(*spa); 15506bc75619SDan Williams memcpy(spa->range_guid, to_nfit_uuid(NFIT_SPA_PM), 16); 15516bc75619SDan Williams spa->range_index = 0+1; 15526bc75619SDan Williams spa->address = t->spa_set_dma[0]; 15536bc75619SDan Williams spa->length = SPA2_SIZE; 15546bc75619SDan Williams 15557bfe97c7SDan Williams /* virtual cd region */ 15567bfe97c7SDan Williams spa = nfit_buf + sizeof(*spa); 15577bfe97c7SDan Williams spa->header.type = ACPI_NFIT_TYPE_SYSTEM_ADDRESS; 15587bfe97c7SDan Williams spa->header.length = sizeof(*spa); 15597bfe97c7SDan Williams memcpy(spa->range_guid, to_nfit_uuid(NFIT_SPA_VCD), 16); 15607bfe97c7SDan Williams spa->range_index = 0; 15617bfe97c7SDan Williams spa->address = t->spa_set_dma[1]; 15627bfe97c7SDan Williams spa->length = SPA_VCD_SIZE; 15637bfe97c7SDan Williams 15647bfe97c7SDan Williams offset += sizeof(*spa) * 2; 15656bc75619SDan Williams /* mem-region0 (spa0, dimm0) */ 15666bc75619SDan Williams memdev = nfit_buf + offset; 15676bc75619SDan Williams memdev->header.type = ACPI_NFIT_TYPE_MEMORY_MAP; 15686bc75619SDan Williams memdev->header.length = sizeof(*memdev); 1569dafb1048SDan Williams memdev->device_handle = handle[5]; 15706bc75619SDan Williams memdev->physical_id = 0; 15716bc75619SDan Williams memdev->region_id = 0; 15726bc75619SDan Williams memdev->range_index = 0+1; 15736bc75619SDan Williams memdev->region_index = 0+1; 15746bc75619SDan Williams memdev->region_size = SPA2_SIZE; 15756bc75619SDan Williams memdev->region_offset = 0; 15766bc75619SDan Williams memdev->address = 0; 15776bc75619SDan Williams memdev->interleave_index = 0; 15786bc75619SDan Williams memdev->interleave_ways = 1; 157958138820SDan Williams memdev->flags = ACPI_NFIT_MEM_SAVE_FAILED | ACPI_NFIT_MEM_RESTORE_FAILED 158058138820SDan Williams | ACPI_NFIT_MEM_FLUSH_FAILED | ACPI_NFIT_MEM_HEALTH_OBSERVED 1581f4295796SDan Williams | ACPI_NFIT_MEM_NOT_ARMED; 15826bc75619SDan Williams 15836bc75619SDan Williams offset += sizeof(*memdev); 15846bc75619SDan Williams /* dcr-descriptor0 */ 15856bc75619SDan Williams dcr = nfit_buf + offset; 15866bc75619SDan Williams dcr->header.type = ACPI_NFIT_TYPE_CONTROL_REGION; 15873b87356fSDan Williams dcr->header.length = offsetof(struct acpi_nfit_control_region, 15883b87356fSDan Williams window_size); 15896bc75619SDan Williams dcr->region_index = 0+1; 15905dc68e55SDan Williams dcr_common_init(dcr); 1591dafb1048SDan Williams dcr->serial_number = ~handle[5]; 1592be26f9aeSDan Williams dcr->code = NFIT_FIC_BYTE; 15936bc75619SDan Williams dcr->windows = 0; 1594d26f73f0SDan Williams 1595ac40b675SDan Williams offset += dcr->header.length; 1596ac40b675SDan Williams memdev = nfit_buf + offset; 1597ac40b675SDan Williams memdev->header.type = ACPI_NFIT_TYPE_MEMORY_MAP; 1598ac40b675SDan Williams memdev->header.length = sizeof(*memdev); 1599ac40b675SDan Williams memdev->device_handle = handle[6]; 1600ac40b675SDan Williams memdev->physical_id = 0; 1601ac40b675SDan Williams memdev->region_id = 0; 1602ac40b675SDan Williams memdev->range_index = 0; 1603ac40b675SDan Williams memdev->region_index = 0+2; 1604ac40b675SDan Williams memdev->region_size = SPA2_SIZE; 1605ac40b675SDan Williams memdev->region_offset = 0; 1606ac40b675SDan Williams memdev->address = 0; 1607ac40b675SDan Williams memdev->interleave_index = 0; 1608ac40b675SDan Williams memdev->interleave_ways = 1; 1609ac40b675SDan Williams memdev->flags = ACPI_NFIT_MEM_MAP_FAILED; 1610ac40b675SDan Williams 1611ac40b675SDan Williams /* dcr-descriptor1 */ 1612ac40b675SDan Williams offset += sizeof(*memdev); 1613ac40b675SDan Williams dcr = nfit_buf + offset; 1614ac40b675SDan Williams dcr->header.type = ACPI_NFIT_TYPE_CONTROL_REGION; 1615ac40b675SDan Williams dcr->header.length = offsetof(struct acpi_nfit_control_region, 1616ac40b675SDan Williams window_size); 1617ac40b675SDan Williams dcr->region_index = 0+2; 1618ac40b675SDan Williams dcr_common_init(dcr); 1619ac40b675SDan Williams dcr->serial_number = ~handle[6]; 1620ac40b675SDan Williams dcr->code = NFIT_FIC_BYTE; 1621ac40b675SDan Williams dcr->windows = 0; 1622ac40b675SDan Williams 1623f471f1a7SDan Williams post_ars_status(&t->ars_state, t->spa_set_dma[0], SPA2_SIZE); 1624f471f1a7SDan Williams 1625d26f73f0SDan Williams acpi_desc = &t->acpi_desc; 1626e3654ecaSDan Williams set_bit(ND_CMD_ARS_CAP, &acpi_desc->bus_cmd_force_en); 1627e3654ecaSDan Williams set_bit(ND_CMD_ARS_START, &acpi_desc->bus_cmd_force_en); 1628e3654ecaSDan Williams set_bit(ND_CMD_ARS_STATUS, &acpi_desc->bus_cmd_force_en); 1629e3654ecaSDan Williams set_bit(ND_CMD_CLEAR_ERROR, &acpi_desc->bus_cmd_force_en); 16306bc75619SDan Williams } 16316bc75619SDan Williams 16326bc75619SDan Williams static int nfit_test_blk_do_io(struct nd_blk_region *ndbr, resource_size_t dpa, 16336bc75619SDan Williams void *iobuf, u64 len, int rw) 16346bc75619SDan Williams { 16356bc75619SDan Williams struct nfit_blk *nfit_blk = ndbr->blk_provider_data; 16366bc75619SDan Williams struct nfit_blk_mmio *mmio = &nfit_blk->mmio[BDW]; 16376bc75619SDan Williams struct nd_region *nd_region = &ndbr->nd_region; 16386bc75619SDan Williams unsigned int lane; 16396bc75619SDan Williams 16406bc75619SDan Williams lane = nd_region_acquire_lane(nd_region); 16416bc75619SDan Williams if (rw) 164267a3e8feSRoss Zwisler memcpy(mmio->addr.base + dpa, iobuf, len); 164367a3e8feSRoss Zwisler else { 164467a3e8feSRoss Zwisler memcpy(iobuf, mmio->addr.base + dpa, len); 164567a3e8feSRoss Zwisler 16465deb67f7SRobin Murphy /* give us some some coverage of the arch_invalidate_pmem() API */ 16475deb67f7SRobin Murphy arch_invalidate_pmem(mmio->addr.base + dpa, len); 164867a3e8feSRoss Zwisler } 16496bc75619SDan Williams nd_region_release_lane(nd_region, lane); 16506bc75619SDan Williams 16516bc75619SDan Williams return 0; 16526bc75619SDan Williams } 16536bc75619SDan Williams 1654a7de92daSDan Williams static unsigned long nfit_ctl_handle; 1655a7de92daSDan Williams 1656a7de92daSDan Williams union acpi_object *result; 1657a7de92daSDan Williams 1658a7de92daSDan Williams static union acpi_object *nfit_test_evaluate_dsm(acpi_handle handle, 165994116f81SAndy Shevchenko const guid_t *guid, u64 rev, u64 func, union acpi_object *argv4) 1660a7de92daSDan Williams { 1661a7de92daSDan Williams if (handle != &nfit_ctl_handle) 1662a7de92daSDan Williams return ERR_PTR(-ENXIO); 1663a7de92daSDan Williams 1664a7de92daSDan Williams return result; 1665a7de92daSDan Williams } 1666a7de92daSDan Williams 1667a7de92daSDan Williams static int setup_result(void *buf, size_t size) 1668a7de92daSDan Williams { 1669a7de92daSDan Williams result = kmalloc(sizeof(union acpi_object) + size, GFP_KERNEL); 1670a7de92daSDan Williams if (!result) 1671a7de92daSDan Williams return -ENOMEM; 1672a7de92daSDan Williams result->package.type = ACPI_TYPE_BUFFER, 1673a7de92daSDan Williams result->buffer.pointer = (void *) (result + 1); 1674a7de92daSDan Williams result->buffer.length = size; 1675a7de92daSDan Williams memcpy(result->buffer.pointer, buf, size); 1676a7de92daSDan Williams memset(buf, 0, size); 1677a7de92daSDan Williams return 0; 1678a7de92daSDan Williams } 1679a7de92daSDan Williams 1680a7de92daSDan Williams static int nfit_ctl_test(struct device *dev) 1681a7de92daSDan Williams { 1682a7de92daSDan Williams int rc, cmd_rc; 1683a7de92daSDan Williams struct nvdimm *nvdimm; 1684a7de92daSDan Williams struct acpi_device *adev; 1685a7de92daSDan Williams struct nfit_mem *nfit_mem; 1686a7de92daSDan Williams struct nd_ars_record *record; 1687a7de92daSDan Williams struct acpi_nfit_desc *acpi_desc; 1688a7de92daSDan Williams const u64 test_val = 0x0123456789abcdefULL; 1689a7de92daSDan Williams unsigned long mask, cmd_size, offset; 1690a7de92daSDan Williams union { 1691a7de92daSDan Williams struct nd_cmd_get_config_size cfg_size; 1692a7de92daSDan Williams struct nd_cmd_ars_status ars_stat; 1693a7de92daSDan Williams struct nd_cmd_ars_cap ars_cap; 1694a7de92daSDan Williams char buf[sizeof(struct nd_cmd_ars_status) 1695a7de92daSDan Williams + sizeof(struct nd_ars_record)]; 1696a7de92daSDan Williams } cmds; 1697a7de92daSDan Williams 1698a7de92daSDan Williams adev = devm_kzalloc(dev, sizeof(*adev), GFP_KERNEL); 1699a7de92daSDan Williams if (!adev) 1700a7de92daSDan Williams return -ENOMEM; 1701a7de92daSDan Williams *adev = (struct acpi_device) { 1702a7de92daSDan Williams .handle = &nfit_ctl_handle, 1703a7de92daSDan Williams .dev = { 1704a7de92daSDan Williams .init_name = "test-adev", 1705a7de92daSDan Williams }, 1706a7de92daSDan Williams }; 1707a7de92daSDan Williams 1708a7de92daSDan Williams acpi_desc = devm_kzalloc(dev, sizeof(*acpi_desc), GFP_KERNEL); 1709a7de92daSDan Williams if (!acpi_desc) 1710a7de92daSDan Williams return -ENOMEM; 1711a7de92daSDan Williams *acpi_desc = (struct acpi_nfit_desc) { 1712a7de92daSDan Williams .nd_desc = { 1713a7de92daSDan Williams .cmd_mask = 1UL << ND_CMD_ARS_CAP 1714a7de92daSDan Williams | 1UL << ND_CMD_ARS_START 1715a7de92daSDan Williams | 1UL << ND_CMD_ARS_STATUS 1716*10246dc8SYasunori Goto | 1UL << ND_CMD_CLEAR_ERROR 1717*10246dc8SYasunori Goto | 1UL << ND_CMD_CALL, 1718a7de92daSDan Williams .module = THIS_MODULE, 1719a7de92daSDan Williams .provider_name = "ACPI.NFIT", 1720a7de92daSDan Williams .ndctl = acpi_nfit_ctl, 1721*10246dc8SYasunori Goto .bus_dsm_mask = 1UL << NFIT_CMD_TRANSLATE_SPA, 1722a7de92daSDan Williams }, 1723a7de92daSDan Williams .dev = &adev->dev, 1724a7de92daSDan Williams }; 1725a7de92daSDan Williams 1726a7de92daSDan Williams nfit_mem = devm_kzalloc(dev, sizeof(*nfit_mem), GFP_KERNEL); 1727a7de92daSDan Williams if (!nfit_mem) 1728a7de92daSDan Williams return -ENOMEM; 1729a7de92daSDan Williams 1730a7de92daSDan Williams mask = 1UL << ND_CMD_SMART | 1UL << ND_CMD_SMART_THRESHOLD 1731a7de92daSDan Williams | 1UL << ND_CMD_DIMM_FLAGS | 1UL << ND_CMD_GET_CONFIG_SIZE 1732a7de92daSDan Williams | 1UL << ND_CMD_GET_CONFIG_DATA | 1UL << ND_CMD_SET_CONFIG_DATA 1733a7de92daSDan Williams | 1UL << ND_CMD_VENDOR; 1734a7de92daSDan Williams *nfit_mem = (struct nfit_mem) { 1735a7de92daSDan Williams .adev = adev, 1736a7de92daSDan Williams .family = NVDIMM_FAMILY_INTEL, 1737a7de92daSDan Williams .dsm_mask = mask, 1738a7de92daSDan Williams }; 1739a7de92daSDan Williams 1740a7de92daSDan Williams nvdimm = devm_kzalloc(dev, sizeof(*nvdimm), GFP_KERNEL); 1741a7de92daSDan Williams if (!nvdimm) 1742a7de92daSDan Williams return -ENOMEM; 1743a7de92daSDan Williams *nvdimm = (struct nvdimm) { 1744a7de92daSDan Williams .provider_data = nfit_mem, 1745a7de92daSDan Williams .cmd_mask = mask, 1746a7de92daSDan Williams .dev = { 1747a7de92daSDan Williams .init_name = "test-dimm", 1748a7de92daSDan Williams }, 1749a7de92daSDan Williams }; 1750a7de92daSDan Williams 1751a7de92daSDan Williams 1752a7de92daSDan Williams /* basic checkout of a typical 'get config size' command */ 1753a7de92daSDan Williams cmd_size = sizeof(cmds.cfg_size); 1754a7de92daSDan Williams cmds.cfg_size = (struct nd_cmd_get_config_size) { 1755a7de92daSDan Williams .status = 0, 1756a7de92daSDan Williams .config_size = SZ_128K, 1757a7de92daSDan Williams .max_xfer = SZ_4K, 1758a7de92daSDan Williams }; 1759a7de92daSDan Williams rc = setup_result(cmds.buf, cmd_size); 1760a7de92daSDan Williams if (rc) 1761a7de92daSDan Williams return rc; 1762a7de92daSDan Williams rc = acpi_nfit_ctl(&acpi_desc->nd_desc, nvdimm, ND_CMD_GET_CONFIG_SIZE, 1763a7de92daSDan Williams cmds.buf, cmd_size, &cmd_rc); 1764a7de92daSDan Williams 1765a7de92daSDan Williams if (rc < 0 || cmd_rc || cmds.cfg_size.status != 0 1766a7de92daSDan Williams || cmds.cfg_size.config_size != SZ_128K 1767a7de92daSDan Williams || cmds.cfg_size.max_xfer != SZ_4K) { 1768a7de92daSDan Williams dev_dbg(dev, "%s: failed at: %d rc: %d cmd_rc: %d\n", 1769a7de92daSDan Williams __func__, __LINE__, rc, cmd_rc); 1770a7de92daSDan Williams return -EIO; 1771a7de92daSDan Williams } 1772a7de92daSDan Williams 1773a7de92daSDan Williams 1774a7de92daSDan Williams /* test ars_status with zero output */ 1775a7de92daSDan Williams cmd_size = offsetof(struct nd_cmd_ars_status, address); 1776a7de92daSDan Williams cmds.ars_stat = (struct nd_cmd_ars_status) { 1777a7de92daSDan Williams .out_length = 0, 1778a7de92daSDan Williams }; 1779a7de92daSDan Williams rc = setup_result(cmds.buf, cmd_size); 1780a7de92daSDan Williams if (rc) 1781a7de92daSDan Williams return rc; 1782a7de92daSDan Williams rc = acpi_nfit_ctl(&acpi_desc->nd_desc, NULL, ND_CMD_ARS_STATUS, 1783a7de92daSDan Williams cmds.buf, cmd_size, &cmd_rc); 1784a7de92daSDan Williams 1785a7de92daSDan Williams if (rc < 0 || cmd_rc) { 1786a7de92daSDan Williams dev_dbg(dev, "%s: failed at: %d rc: %d cmd_rc: %d\n", 1787a7de92daSDan Williams __func__, __LINE__, rc, cmd_rc); 1788a7de92daSDan Williams return -EIO; 1789a7de92daSDan Williams } 1790a7de92daSDan Williams 1791a7de92daSDan Williams 1792a7de92daSDan Williams /* test ars_cap with benign extended status */ 1793a7de92daSDan Williams cmd_size = sizeof(cmds.ars_cap); 1794a7de92daSDan Williams cmds.ars_cap = (struct nd_cmd_ars_cap) { 1795a7de92daSDan Williams .status = ND_ARS_PERSISTENT << 16, 1796a7de92daSDan Williams }; 1797a7de92daSDan Williams offset = offsetof(struct nd_cmd_ars_cap, status); 1798a7de92daSDan Williams rc = setup_result(cmds.buf + offset, cmd_size - offset); 1799a7de92daSDan Williams if (rc) 1800a7de92daSDan Williams return rc; 1801a7de92daSDan Williams rc = acpi_nfit_ctl(&acpi_desc->nd_desc, NULL, ND_CMD_ARS_CAP, 1802a7de92daSDan Williams cmds.buf, cmd_size, &cmd_rc); 1803a7de92daSDan Williams 1804a7de92daSDan Williams if (rc < 0 || cmd_rc) { 1805a7de92daSDan Williams dev_dbg(dev, "%s: failed at: %d rc: %d cmd_rc: %d\n", 1806a7de92daSDan Williams __func__, __LINE__, rc, cmd_rc); 1807a7de92daSDan Williams return -EIO; 1808a7de92daSDan Williams } 1809a7de92daSDan Williams 1810a7de92daSDan Williams 1811a7de92daSDan Williams /* test ars_status with 'status' trimmed from 'out_length' */ 1812a7de92daSDan Williams cmd_size = sizeof(cmds.ars_stat) + sizeof(struct nd_ars_record); 1813a7de92daSDan Williams cmds.ars_stat = (struct nd_cmd_ars_status) { 1814a7de92daSDan Williams .out_length = cmd_size - 4, 1815a7de92daSDan Williams }; 1816a7de92daSDan Williams record = &cmds.ars_stat.records[0]; 1817a7de92daSDan Williams *record = (struct nd_ars_record) { 1818a7de92daSDan Williams .length = test_val, 1819a7de92daSDan Williams }; 1820a7de92daSDan Williams rc = setup_result(cmds.buf, cmd_size); 1821a7de92daSDan Williams if (rc) 1822a7de92daSDan Williams return rc; 1823a7de92daSDan Williams rc = acpi_nfit_ctl(&acpi_desc->nd_desc, NULL, ND_CMD_ARS_STATUS, 1824a7de92daSDan Williams cmds.buf, cmd_size, &cmd_rc); 1825a7de92daSDan Williams 1826a7de92daSDan Williams if (rc < 0 || cmd_rc || record->length != test_val) { 1827a7de92daSDan Williams dev_dbg(dev, "%s: failed at: %d rc: %d cmd_rc: %d\n", 1828a7de92daSDan Williams __func__, __LINE__, rc, cmd_rc); 1829a7de92daSDan Williams return -EIO; 1830a7de92daSDan Williams } 1831a7de92daSDan Williams 1832a7de92daSDan Williams 1833a7de92daSDan Williams /* test ars_status with 'Output (Size)' including 'status' */ 1834a7de92daSDan Williams cmd_size = sizeof(cmds.ars_stat) + sizeof(struct nd_ars_record); 1835a7de92daSDan Williams cmds.ars_stat = (struct nd_cmd_ars_status) { 1836a7de92daSDan Williams .out_length = cmd_size, 1837a7de92daSDan Williams }; 1838a7de92daSDan Williams record = &cmds.ars_stat.records[0]; 1839a7de92daSDan Williams *record = (struct nd_ars_record) { 1840a7de92daSDan Williams .length = test_val, 1841a7de92daSDan Williams }; 1842a7de92daSDan Williams rc = setup_result(cmds.buf, cmd_size); 1843a7de92daSDan Williams if (rc) 1844a7de92daSDan Williams return rc; 1845a7de92daSDan Williams rc = acpi_nfit_ctl(&acpi_desc->nd_desc, NULL, ND_CMD_ARS_STATUS, 1846a7de92daSDan Williams cmds.buf, cmd_size, &cmd_rc); 1847a7de92daSDan Williams 1848a7de92daSDan Williams if (rc < 0 || cmd_rc || record->length != test_val) { 1849a7de92daSDan Williams dev_dbg(dev, "%s: failed at: %d rc: %d cmd_rc: %d\n", 1850a7de92daSDan Williams __func__, __LINE__, rc, cmd_rc); 1851a7de92daSDan Williams return -EIO; 1852a7de92daSDan Williams } 1853a7de92daSDan Williams 1854a7de92daSDan Williams 1855a7de92daSDan Williams /* test extended status for get_config_size results in failure */ 1856a7de92daSDan Williams cmd_size = sizeof(cmds.cfg_size); 1857a7de92daSDan Williams cmds.cfg_size = (struct nd_cmd_get_config_size) { 1858a7de92daSDan Williams .status = 1 << 16, 1859a7de92daSDan Williams }; 1860a7de92daSDan Williams rc = setup_result(cmds.buf, cmd_size); 1861a7de92daSDan Williams if (rc) 1862a7de92daSDan Williams return rc; 1863a7de92daSDan Williams rc = acpi_nfit_ctl(&acpi_desc->nd_desc, nvdimm, ND_CMD_GET_CONFIG_SIZE, 1864a7de92daSDan Williams cmds.buf, cmd_size, &cmd_rc); 1865a7de92daSDan Williams 1866a7de92daSDan Williams if (rc < 0 || cmd_rc >= 0) { 1867a7de92daSDan Williams dev_dbg(dev, "%s: failed at: %d rc: %d cmd_rc: %d\n", 1868a7de92daSDan Williams __func__, __LINE__, rc, cmd_rc); 1869a7de92daSDan Williams return -EIO; 1870a7de92daSDan Williams } 1871a7de92daSDan Williams 1872a7de92daSDan Williams return 0; 1873a7de92daSDan Williams } 1874a7de92daSDan Williams 18756bc75619SDan Williams static int nfit_test_probe(struct platform_device *pdev) 18766bc75619SDan Williams { 18776bc75619SDan Williams struct nvdimm_bus_descriptor *nd_desc; 18786bc75619SDan Williams struct acpi_nfit_desc *acpi_desc; 18796bc75619SDan Williams struct device *dev = &pdev->dev; 18806bc75619SDan Williams struct nfit_test *nfit_test; 1881231bf117SDan Williams struct nfit_mem *nfit_mem; 1882c14a868aSDan Williams union acpi_object *obj; 18836bc75619SDan Williams int rc; 18846bc75619SDan Williams 1885a7de92daSDan Williams if (strcmp(dev_name(&pdev->dev), "nfit_test.0") == 0) { 1886a7de92daSDan Williams rc = nfit_ctl_test(&pdev->dev); 1887a7de92daSDan Williams if (rc) 1888a7de92daSDan Williams return rc; 1889a7de92daSDan Williams } 1890a7de92daSDan Williams 18916bc75619SDan Williams nfit_test = to_nfit_test(&pdev->dev); 18926bc75619SDan Williams 18936bc75619SDan Williams /* common alloc */ 18946bc75619SDan Williams if (nfit_test->num_dcr) { 18956bc75619SDan Williams int num = nfit_test->num_dcr; 18966bc75619SDan Williams 18976bc75619SDan Williams nfit_test->dimm = devm_kcalloc(dev, num, sizeof(void *), 18986bc75619SDan Williams GFP_KERNEL); 18996bc75619SDan Williams nfit_test->dimm_dma = devm_kcalloc(dev, num, sizeof(dma_addr_t), 19006bc75619SDan Williams GFP_KERNEL); 19019d27a87eSDan Williams nfit_test->flush = devm_kcalloc(dev, num, sizeof(void *), 19029d27a87eSDan Williams GFP_KERNEL); 19039d27a87eSDan Williams nfit_test->flush_dma = devm_kcalloc(dev, num, sizeof(dma_addr_t), 19049d27a87eSDan Williams GFP_KERNEL); 19056bc75619SDan Williams nfit_test->label = devm_kcalloc(dev, num, sizeof(void *), 19066bc75619SDan Williams GFP_KERNEL); 19076bc75619SDan Williams nfit_test->label_dma = devm_kcalloc(dev, num, 19086bc75619SDan Williams sizeof(dma_addr_t), GFP_KERNEL); 19096bc75619SDan Williams nfit_test->dcr = devm_kcalloc(dev, num, 19106bc75619SDan Williams sizeof(struct nfit_test_dcr *), GFP_KERNEL); 19116bc75619SDan Williams nfit_test->dcr_dma = devm_kcalloc(dev, num, 19126bc75619SDan Williams sizeof(dma_addr_t), GFP_KERNEL); 19136bc75619SDan Williams if (nfit_test->dimm && nfit_test->dimm_dma && nfit_test->label 19146bc75619SDan Williams && nfit_test->label_dma && nfit_test->dcr 19159d27a87eSDan Williams && nfit_test->dcr_dma && nfit_test->flush 19169d27a87eSDan Williams && nfit_test->flush_dma) 19176bc75619SDan Williams /* pass */; 19186bc75619SDan Williams else 19196bc75619SDan Williams return -ENOMEM; 19206bc75619SDan Williams } 19216bc75619SDan Williams 19226bc75619SDan Williams if (nfit_test->num_pm) { 19236bc75619SDan Williams int num = nfit_test->num_pm; 19246bc75619SDan Williams 19256bc75619SDan Williams nfit_test->spa_set = devm_kcalloc(dev, num, sizeof(void *), 19266bc75619SDan Williams GFP_KERNEL); 19276bc75619SDan Williams nfit_test->spa_set_dma = devm_kcalloc(dev, num, 19286bc75619SDan Williams sizeof(dma_addr_t), GFP_KERNEL); 19296bc75619SDan Williams if (nfit_test->spa_set && nfit_test->spa_set_dma) 19306bc75619SDan Williams /* pass */; 19316bc75619SDan Williams else 19326bc75619SDan Williams return -ENOMEM; 19336bc75619SDan Williams } 19346bc75619SDan Williams 19356bc75619SDan Williams /* per-nfit specific alloc */ 19366bc75619SDan Williams if (nfit_test->alloc(nfit_test)) 19376bc75619SDan Williams return -ENOMEM; 19386bc75619SDan Williams 19396bc75619SDan Williams nfit_test->setup(nfit_test); 19406bc75619SDan Williams acpi_desc = &nfit_test->acpi_desc; 1941a61fe6f7SDan Williams acpi_nfit_desc_init(acpi_desc, &pdev->dev); 19426bc75619SDan Williams acpi_desc->blk_do_io = nfit_test_blk_do_io; 19436bc75619SDan Williams nd_desc = &acpi_desc->nd_desc; 1944a61fe6f7SDan Williams nd_desc->provider_name = NULL; 1945bc9775d8SDan Williams nd_desc->module = THIS_MODULE; 1946a61fe6f7SDan Williams nd_desc->ndctl = nfit_test_ctl; 19476bc75619SDan Williams 1948e7a11b44SDan Williams rc = acpi_nfit_init(acpi_desc, nfit_test->nfit_buf, 1949e7a11b44SDan Williams nfit_test->nfit_size); 195058cd71b4SDan Williams if (rc) 195120985164SVishal Verma return rc; 195220985164SVishal Verma 1953fbabd829SDan Williams rc = devm_add_action_or_reset(&pdev->dev, acpi_nfit_shutdown, acpi_desc); 1954fbabd829SDan Williams if (rc) 1955fbabd829SDan Williams return rc; 1956fbabd829SDan Williams 195720985164SVishal Verma if (nfit_test->setup != nfit_test0_setup) 195820985164SVishal Verma return 0; 195920985164SVishal Verma 196020985164SVishal Verma nfit_test->setup_hotplug = 1; 196120985164SVishal Verma nfit_test->setup(nfit_test); 196220985164SVishal Verma 1963c14a868aSDan Williams obj = kzalloc(sizeof(*obj), GFP_KERNEL); 1964c14a868aSDan Williams if (!obj) 1965c14a868aSDan Williams return -ENOMEM; 1966c14a868aSDan Williams obj->type = ACPI_TYPE_BUFFER; 1967c14a868aSDan Williams obj->buffer.length = nfit_test->nfit_size; 1968c14a868aSDan Williams obj->buffer.pointer = nfit_test->nfit_buf; 1969c14a868aSDan Williams *(nfit_test->_fit) = obj; 1970c14a868aSDan Williams __acpi_nfit_notify(&pdev->dev, nfit_test, 0x80); 1971231bf117SDan Williams 1972231bf117SDan Williams /* associate dimm devices with nfit_mem data for notification testing */ 1973231bf117SDan Williams mutex_lock(&acpi_desc->init_mutex); 1974231bf117SDan Williams list_for_each_entry(nfit_mem, &acpi_desc->dimms, list) { 1975231bf117SDan Williams u32 nfit_handle = __to_nfit_memdev(nfit_mem)->device_handle; 1976231bf117SDan Williams int i; 1977231bf117SDan Williams 1978231bf117SDan Williams for (i = 0; i < NUM_DCR; i++) 1979231bf117SDan Williams if (nfit_handle == handle[i]) 1980231bf117SDan Williams dev_set_drvdata(nfit_test->dimm_dev[i], 1981231bf117SDan Williams nfit_mem); 1982231bf117SDan Williams } 1983231bf117SDan Williams mutex_unlock(&acpi_desc->init_mutex); 19846bc75619SDan Williams 19856bc75619SDan Williams return 0; 19866bc75619SDan Williams } 19876bc75619SDan Williams 19886bc75619SDan Williams static int nfit_test_remove(struct platform_device *pdev) 19896bc75619SDan Williams { 19906bc75619SDan Williams return 0; 19916bc75619SDan Williams } 19926bc75619SDan Williams 19936bc75619SDan Williams static void nfit_test_release(struct device *dev) 19946bc75619SDan Williams { 19956bc75619SDan Williams struct nfit_test *nfit_test = to_nfit_test(dev); 19966bc75619SDan Williams 19976bc75619SDan Williams kfree(nfit_test); 19986bc75619SDan Williams } 19996bc75619SDan Williams 20006bc75619SDan Williams static const struct platform_device_id nfit_test_id[] = { 20016bc75619SDan Williams { KBUILD_MODNAME }, 20026bc75619SDan Williams { }, 20036bc75619SDan Williams }; 20046bc75619SDan Williams 20056bc75619SDan Williams static struct platform_driver nfit_test_driver = { 20066bc75619SDan Williams .probe = nfit_test_probe, 20076bc75619SDan Williams .remove = nfit_test_remove, 20086bc75619SDan Williams .driver = { 20096bc75619SDan Williams .name = KBUILD_MODNAME, 20106bc75619SDan Williams }, 20116bc75619SDan Williams .id_table = nfit_test_id, 20126bc75619SDan Williams }; 20136bc75619SDan Williams 20146bc75619SDan Williams static __init int nfit_test_init(void) 20156bc75619SDan Williams { 20166bc75619SDan Williams int rc, i; 20176bc75619SDan Williams 2018a7de92daSDan Williams nfit_test_setup(nfit_test_lookup, nfit_test_evaluate_dsm); 2019231bf117SDan Williams 2020a7de92daSDan Williams nfit_test_dimm = class_create(THIS_MODULE, "nfit_test_dimm"); 2021a7de92daSDan Williams if (IS_ERR(nfit_test_dimm)) { 2022a7de92daSDan Williams rc = PTR_ERR(nfit_test_dimm); 2023a7de92daSDan Williams goto err_register; 2024a7de92daSDan Williams } 20256bc75619SDan Williams 20266bc75619SDan Williams for (i = 0; i < NUM_NFITS; i++) { 20276bc75619SDan Williams struct nfit_test *nfit_test; 20286bc75619SDan Williams struct platform_device *pdev; 20296bc75619SDan Williams 20306bc75619SDan Williams nfit_test = kzalloc(sizeof(*nfit_test), GFP_KERNEL); 20316bc75619SDan Williams if (!nfit_test) { 20326bc75619SDan Williams rc = -ENOMEM; 20336bc75619SDan Williams goto err_register; 20346bc75619SDan Williams } 20356bc75619SDan Williams INIT_LIST_HEAD(&nfit_test->resources); 20366bc75619SDan Williams switch (i) { 20376bc75619SDan Williams case 0: 20386bc75619SDan Williams nfit_test->num_pm = NUM_PM; 2039dafb1048SDan Williams nfit_test->dcr_idx = 0; 20406bc75619SDan Williams nfit_test->num_dcr = NUM_DCR; 20416bc75619SDan Williams nfit_test->alloc = nfit_test0_alloc; 20426bc75619SDan Williams nfit_test->setup = nfit_test0_setup; 20436bc75619SDan Williams break; 20446bc75619SDan Williams case 1: 2045a117699cSYasunori Goto nfit_test->num_pm = 2; 2046dafb1048SDan Williams nfit_test->dcr_idx = NUM_DCR; 2047ac40b675SDan Williams nfit_test->num_dcr = 2; 20486bc75619SDan Williams nfit_test->alloc = nfit_test1_alloc; 20496bc75619SDan Williams nfit_test->setup = nfit_test1_setup; 20506bc75619SDan Williams break; 20516bc75619SDan Williams default: 20526bc75619SDan Williams rc = -EINVAL; 20536bc75619SDan Williams goto err_register; 20546bc75619SDan Williams } 20556bc75619SDan Williams pdev = &nfit_test->pdev; 20566bc75619SDan Williams pdev->name = KBUILD_MODNAME; 20576bc75619SDan Williams pdev->id = i; 20586bc75619SDan Williams pdev->dev.release = nfit_test_release; 20596bc75619SDan Williams rc = platform_device_register(pdev); 20606bc75619SDan Williams if (rc) { 20616bc75619SDan Williams put_device(&pdev->dev); 20626bc75619SDan Williams goto err_register; 20636bc75619SDan Williams } 20648b06b884SDan Williams get_device(&pdev->dev); 20656bc75619SDan Williams 20666bc75619SDan Williams rc = dma_coerce_mask_and_coherent(&pdev->dev, DMA_BIT_MASK(64)); 20676bc75619SDan Williams if (rc) 20686bc75619SDan Williams goto err_register; 20696bc75619SDan Williams 20706bc75619SDan Williams instances[i] = nfit_test; 20716bc75619SDan Williams } 20726bc75619SDan Williams 20736bc75619SDan Williams rc = platform_driver_register(&nfit_test_driver); 20746bc75619SDan Williams if (rc) 20756bc75619SDan Williams goto err_register; 20766bc75619SDan Williams return 0; 20776bc75619SDan Williams 20786bc75619SDan Williams err_register: 20796bc75619SDan Williams for (i = 0; i < NUM_NFITS; i++) 20806bc75619SDan Williams if (instances[i]) 20816bc75619SDan Williams platform_device_unregister(&instances[i]->pdev); 20826bc75619SDan Williams nfit_test_teardown(); 20838b06b884SDan Williams for (i = 0; i < NUM_NFITS; i++) 20848b06b884SDan Williams if (instances[i]) 20858b06b884SDan Williams put_device(&instances[i]->pdev.dev); 20868b06b884SDan Williams 20876bc75619SDan Williams return rc; 20886bc75619SDan Williams } 20896bc75619SDan Williams 20906bc75619SDan Williams static __exit void nfit_test_exit(void) 20916bc75619SDan Williams { 20926bc75619SDan Williams int i; 20936bc75619SDan Williams 20946bc75619SDan Williams for (i = 0; i < NUM_NFITS; i++) 20956bc75619SDan Williams platform_device_unregister(&instances[i]->pdev); 20968b06b884SDan Williams platform_driver_unregister(&nfit_test_driver); 20976bc75619SDan Williams nfit_test_teardown(); 20988b06b884SDan Williams 20998b06b884SDan Williams for (i = 0; i < NUM_NFITS; i++) 21008b06b884SDan Williams put_device(&instances[i]->pdev.dev); 2101231bf117SDan Williams class_destroy(nfit_test_dimm); 21026bc75619SDan Williams } 21036bc75619SDan Williams 21046bc75619SDan Williams module_init(nfit_test_init); 21056bc75619SDan Williams module_exit(nfit_test_exit); 21066bc75619SDan Williams MODULE_LICENSE("GPL v2"); 21076bc75619SDan Williams MODULE_AUTHOR("Intel Corporation"); 2108