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 345baa51277SDan Williams static int nfit_test_cmd_smart(struct nd_cmd_smart *smart, unsigned int buf_len) 346baa51277SDan Williams { 347baa51277SDan Williams static const struct nd_smart_payload smart_data = { 348baa51277SDan Williams .flags = ND_SMART_HEALTH_VALID | ND_SMART_TEMP_VALID 349baa51277SDan Williams | ND_SMART_SPARES_VALID | ND_SMART_ALARM_VALID 350baa51277SDan Williams | ND_SMART_USED_VALID | ND_SMART_SHUTDOWN_VALID, 351baa51277SDan Williams .health = ND_SMART_NON_CRITICAL_HEALTH, 352baa51277SDan Williams .temperature = 23 * 16, 353baa51277SDan Williams .spares = 75, 354baa51277SDan Williams .alarm_flags = ND_SMART_SPARE_TRIP | ND_SMART_TEMP_TRIP, 355baa51277SDan Williams .life_used = 5, 356baa51277SDan Williams .shutdown_state = 0, 357baa51277SDan Williams .vendor_size = 0, 358baa51277SDan Williams }; 359baa51277SDan Williams 360baa51277SDan Williams if (buf_len < sizeof(*smart)) 361baa51277SDan Williams return -EINVAL; 362baa51277SDan Williams memcpy(smart->data, &smart_data, sizeof(smart_data)); 363baa51277SDan Williams return 0; 364baa51277SDan Williams } 365baa51277SDan Williams 366baa51277SDan Williams static int nfit_test_cmd_smart_threshold(struct nd_cmd_smart_threshold *smart_t, 367baa51277SDan Williams unsigned int buf_len) 368baa51277SDan Williams { 369baa51277SDan Williams static const struct nd_smart_threshold_payload smart_t_data = { 370baa51277SDan Williams .alarm_control = ND_SMART_SPARE_TRIP | ND_SMART_TEMP_TRIP, 371baa51277SDan Williams .temperature = 40 * 16, 372baa51277SDan Williams .spares = 5, 373baa51277SDan Williams }; 374baa51277SDan Williams 375baa51277SDan Williams if (buf_len < sizeof(*smart_t)) 376baa51277SDan Williams return -EINVAL; 377baa51277SDan Williams memcpy(smart_t->data, &smart_t_data, sizeof(smart_t_data)); 378baa51277SDan Williams return 0; 379baa51277SDan Williams } 380baa51277SDan Williams 38139c686b8SVishal Verma static int nfit_test_ctl(struct nvdimm_bus_descriptor *nd_desc, 38239c686b8SVishal Verma struct nvdimm *nvdimm, unsigned int cmd, void *buf, 383aef25338SDan Williams unsigned int buf_len, int *cmd_rc) 38439c686b8SVishal Verma { 38539c686b8SVishal Verma struct acpi_nfit_desc *acpi_desc = to_acpi_desc(nd_desc); 38639c686b8SVishal Verma struct nfit_test *t = container_of(acpi_desc, typeof(*t), acpi_desc); 3876634fb06SDan Williams unsigned int func = cmd; 388f471f1a7SDan Williams int i, rc = 0, __cmd_rc; 389f471f1a7SDan Williams 390f471f1a7SDan Williams if (!cmd_rc) 391f471f1a7SDan Williams cmd_rc = &__cmd_rc; 392f471f1a7SDan Williams *cmd_rc = 0; 39339c686b8SVishal Verma 39439c686b8SVishal Verma if (nvdimm) { 39539c686b8SVishal Verma struct nfit_mem *nfit_mem = nvdimm_provider_data(nvdimm); 396e3654ecaSDan Williams unsigned long cmd_mask = nvdimm_cmd_mask(nvdimm); 39739c686b8SVishal Verma 3986634fb06SDan Williams if (!nfit_mem) 3996634fb06SDan Williams return -ENOTTY; 4006634fb06SDan Williams 4016634fb06SDan Williams if (cmd == ND_CMD_CALL) { 4026634fb06SDan Williams struct nd_cmd_pkg *call_pkg = buf; 4036634fb06SDan Williams 4046634fb06SDan Williams buf_len = call_pkg->nd_size_in + call_pkg->nd_size_out; 4056634fb06SDan Williams buf = (void *) call_pkg->nd_payload; 4066634fb06SDan Williams func = call_pkg->nd_command; 4076634fb06SDan Williams if (call_pkg->nd_family != nfit_mem->family) 4086634fb06SDan Williams return -ENOTTY; 4096634fb06SDan Williams } 4106634fb06SDan Williams 4116634fb06SDan Williams if (!test_bit(cmd, &cmd_mask) 4126634fb06SDan Williams || !test_bit(func, &nfit_mem->dsm_mask)) 41339c686b8SVishal Verma return -ENOTTY; 41439c686b8SVishal Verma 41539c686b8SVishal Verma /* lookup label space for the given dimm */ 41639c686b8SVishal Verma for (i = 0; i < ARRAY_SIZE(handle); i++) 41739c686b8SVishal Verma if (__to_nfit_memdev(nfit_mem)->device_handle == 41839c686b8SVishal Verma handle[i]) 41939c686b8SVishal Verma break; 42039c686b8SVishal Verma if (i >= ARRAY_SIZE(handle)) 42139c686b8SVishal Verma return -ENXIO; 42239c686b8SVishal Verma 42373606afdSDan Williams if ((1 << func) & dimm_fail_cmd_flags[i]) 42473606afdSDan Williams return -EIO; 42573606afdSDan Williams 4266634fb06SDan Williams switch (func) { 42739c686b8SVishal Verma case ND_CMD_GET_CONFIG_SIZE: 42839c686b8SVishal Verma rc = nfit_test_cmd_get_config_size(buf, buf_len); 42939c686b8SVishal Verma break; 43039c686b8SVishal Verma case ND_CMD_GET_CONFIG_DATA: 43139c686b8SVishal Verma rc = nfit_test_cmd_get_config_data(buf, buf_len, 432dafb1048SDan Williams t->label[i - t->dcr_idx]); 43339c686b8SVishal Verma break; 43439c686b8SVishal Verma case ND_CMD_SET_CONFIG_DATA: 43539c686b8SVishal Verma rc = nfit_test_cmd_set_config_data(buf, buf_len, 436dafb1048SDan Williams t->label[i - t->dcr_idx]); 43739c686b8SVishal Verma break; 438baa51277SDan Williams case ND_CMD_SMART: 439baa51277SDan Williams rc = nfit_test_cmd_smart(buf, buf_len); 440baa51277SDan Williams break; 441baa51277SDan Williams case ND_CMD_SMART_THRESHOLD: 442baa51277SDan Williams rc = nfit_test_cmd_smart_threshold(buf, buf_len); 443231bf117SDan Williams device_lock(&t->pdev.dev); 444231bf117SDan Williams __acpi_nvdimm_notify(t->dimm_dev[i], 0x81); 445231bf117SDan Williams device_unlock(&t->pdev.dev); 446baa51277SDan Williams break; 4476bc75619SDan Williams default: 4486bc75619SDan Williams return -ENOTTY; 4496bc75619SDan Williams } 45039c686b8SVishal Verma } else { 451f471f1a7SDan Williams struct ars_state *ars_state = &t->ars_state; 452f471f1a7SDan Williams 453e3654ecaSDan Williams if (!nd_desc || !test_bit(cmd, &nd_desc->cmd_mask)) 45439c686b8SVishal Verma return -ENOTTY; 45539c686b8SVishal Verma 4566634fb06SDan Williams switch (func) { 45739c686b8SVishal Verma case ND_CMD_ARS_CAP: 45839c686b8SVishal Verma rc = nfit_test_cmd_ars_cap(buf, buf_len); 45939c686b8SVishal Verma break; 46039c686b8SVishal Verma case ND_CMD_ARS_START: 461f471f1a7SDan Williams rc = nfit_test_cmd_ars_start(ars_state, buf, buf_len, 462f471f1a7SDan Williams cmd_rc); 46339c686b8SVishal Verma break; 46439c686b8SVishal Verma case ND_CMD_ARS_STATUS: 465f471f1a7SDan Williams rc = nfit_test_cmd_ars_status(ars_state, buf, buf_len, 466f471f1a7SDan Williams cmd_rc); 46739c686b8SVishal Verma break; 468d4f32367SDan Williams case ND_CMD_CLEAR_ERROR: 469d4f32367SDan Williams rc = nfit_test_cmd_clear_error(buf, buf_len, cmd_rc); 470d4f32367SDan Williams break; 47139c686b8SVishal Verma default: 47239c686b8SVishal Verma return -ENOTTY; 47339c686b8SVishal Verma } 47439c686b8SVishal Verma } 4756bc75619SDan Williams 4766bc75619SDan Williams return rc; 4776bc75619SDan Williams } 4786bc75619SDan Williams 4796bc75619SDan Williams static DEFINE_SPINLOCK(nfit_test_lock); 4806bc75619SDan Williams static struct nfit_test *instances[NUM_NFITS]; 4816bc75619SDan Williams 4826bc75619SDan Williams static void release_nfit_res(void *data) 4836bc75619SDan Williams { 4846bc75619SDan Williams struct nfit_test_resource *nfit_res = data; 4856bc75619SDan Williams 4866bc75619SDan Williams spin_lock(&nfit_test_lock); 4876bc75619SDan Williams list_del(&nfit_res->list); 4886bc75619SDan Williams spin_unlock(&nfit_test_lock); 4896bc75619SDan Williams 4906bc75619SDan Williams vfree(nfit_res->buf); 4916bc75619SDan Williams kfree(nfit_res); 4926bc75619SDan Williams } 4936bc75619SDan Williams 4946bc75619SDan Williams static void *__test_alloc(struct nfit_test *t, size_t size, dma_addr_t *dma, 4956bc75619SDan Williams void *buf) 4966bc75619SDan Williams { 4976bc75619SDan Williams struct device *dev = &t->pdev.dev; 4986bc75619SDan Williams struct nfit_test_resource *nfit_res = kzalloc(sizeof(*nfit_res), 4996bc75619SDan Williams GFP_KERNEL); 5006bc75619SDan Williams int rc; 5016bc75619SDan Williams 502bd4cd745SDan Williams if (!buf || !nfit_res) 5036bc75619SDan Williams goto err; 5046bc75619SDan Williams rc = devm_add_action(dev, release_nfit_res, nfit_res); 5056bc75619SDan Williams if (rc) 5066bc75619SDan Williams goto err; 5076bc75619SDan Williams INIT_LIST_HEAD(&nfit_res->list); 5086bc75619SDan Williams memset(buf, 0, size); 5096bc75619SDan Williams nfit_res->dev = dev; 5106bc75619SDan Williams nfit_res->buf = buf; 511bd4cd745SDan Williams nfit_res->res.start = *dma; 512bd4cd745SDan Williams nfit_res->res.end = *dma + size - 1; 513bd4cd745SDan Williams nfit_res->res.name = "NFIT"; 514bd4cd745SDan Williams spin_lock_init(&nfit_res->lock); 515bd4cd745SDan Williams INIT_LIST_HEAD(&nfit_res->requests); 5166bc75619SDan Williams spin_lock(&nfit_test_lock); 5176bc75619SDan Williams list_add(&nfit_res->list, &t->resources); 5186bc75619SDan Williams spin_unlock(&nfit_test_lock); 5196bc75619SDan Williams 5206bc75619SDan Williams return nfit_res->buf; 5216bc75619SDan Williams err: 522ee8520feSDan Williams if (buf) 5236bc75619SDan Williams vfree(buf); 5246bc75619SDan Williams kfree(nfit_res); 5256bc75619SDan Williams return NULL; 5266bc75619SDan Williams } 5276bc75619SDan Williams 5286bc75619SDan Williams static void *test_alloc(struct nfit_test *t, size_t size, dma_addr_t *dma) 5296bc75619SDan Williams { 5306bc75619SDan Williams void *buf = vmalloc(size); 5316bc75619SDan Williams 5326bc75619SDan Williams *dma = (unsigned long) buf; 5336bc75619SDan Williams return __test_alloc(t, size, dma, buf); 5346bc75619SDan Williams } 5356bc75619SDan Williams 5366bc75619SDan Williams static struct nfit_test_resource *nfit_test_lookup(resource_size_t addr) 5376bc75619SDan Williams { 5386bc75619SDan Williams int i; 5396bc75619SDan Williams 5406bc75619SDan Williams for (i = 0; i < ARRAY_SIZE(instances); i++) { 5416bc75619SDan Williams struct nfit_test_resource *n, *nfit_res = NULL; 5426bc75619SDan Williams struct nfit_test *t = instances[i]; 5436bc75619SDan Williams 5446bc75619SDan Williams if (!t) 5456bc75619SDan Williams continue; 5466bc75619SDan Williams spin_lock(&nfit_test_lock); 5476bc75619SDan Williams list_for_each_entry(n, &t->resources, list) { 548bd4cd745SDan Williams if (addr >= n->res.start && (addr < n->res.start 549bd4cd745SDan Williams + resource_size(&n->res))) { 5506bc75619SDan Williams nfit_res = n; 5516bc75619SDan Williams break; 5526bc75619SDan Williams } else if (addr >= (unsigned long) n->buf 5536bc75619SDan Williams && (addr < (unsigned long) n->buf 554bd4cd745SDan Williams + resource_size(&n->res))) { 5556bc75619SDan Williams nfit_res = n; 5566bc75619SDan Williams break; 5576bc75619SDan Williams } 5586bc75619SDan Williams } 5596bc75619SDan Williams spin_unlock(&nfit_test_lock); 5606bc75619SDan Williams if (nfit_res) 5616bc75619SDan Williams return nfit_res; 5626bc75619SDan Williams } 5636bc75619SDan Williams 5646bc75619SDan Williams return NULL; 5656bc75619SDan Williams } 5666bc75619SDan Williams 567f471f1a7SDan Williams static int ars_state_init(struct device *dev, struct ars_state *ars_state) 568f471f1a7SDan Williams { 569f471f1a7SDan Williams ars_state->ars_status = devm_kzalloc(dev, 570f471f1a7SDan Williams sizeof(struct nd_cmd_ars_status) 571f471f1a7SDan Williams + sizeof(struct nd_ars_record) * NFIT_TEST_ARS_RECORDS, 572f471f1a7SDan Williams GFP_KERNEL); 573f471f1a7SDan Williams if (!ars_state->ars_status) 574f471f1a7SDan Williams return -ENOMEM; 575f471f1a7SDan Williams spin_lock_init(&ars_state->lock); 576f471f1a7SDan Williams return 0; 577f471f1a7SDan Williams } 578f471f1a7SDan Williams 579231bf117SDan Williams static void put_dimms(void *data) 580231bf117SDan Williams { 581231bf117SDan Williams struct device **dimm_dev = data; 582231bf117SDan Williams int i; 583231bf117SDan Williams 584231bf117SDan Williams for (i = 0; i < NUM_DCR; i++) 585231bf117SDan Williams if (dimm_dev[i]) 586231bf117SDan Williams device_unregister(dimm_dev[i]); 587231bf117SDan Williams } 588231bf117SDan Williams 589231bf117SDan Williams static struct class *nfit_test_dimm; 590231bf117SDan Williams 59173606afdSDan Williams static int dimm_name_to_id(struct device *dev) 59273606afdSDan Williams { 59373606afdSDan Williams int dimm; 59473606afdSDan Williams 59573606afdSDan Williams if (sscanf(dev_name(dev), "test_dimm%d", &dimm) != 1 59673606afdSDan Williams || dimm >= NUM_DCR || dimm < 0) 59773606afdSDan Williams return -ENXIO; 59873606afdSDan Williams return dimm; 59973606afdSDan Williams } 60073606afdSDan Williams 60173606afdSDan Williams 60273606afdSDan Williams static ssize_t handle_show(struct device *dev, struct device_attribute *attr, 60373606afdSDan Williams char *buf) 60473606afdSDan Williams { 60573606afdSDan Williams int dimm = dimm_name_to_id(dev); 60673606afdSDan Williams 60773606afdSDan Williams if (dimm < 0) 60873606afdSDan Williams return dimm; 60973606afdSDan Williams 61073606afdSDan Williams return sprintf(buf, "%#x", handle[dimm]); 61173606afdSDan Williams } 61273606afdSDan Williams DEVICE_ATTR_RO(handle); 61373606afdSDan Williams 61473606afdSDan Williams static ssize_t fail_cmd_show(struct device *dev, struct device_attribute *attr, 61573606afdSDan Williams char *buf) 61673606afdSDan Williams { 61773606afdSDan Williams int dimm = dimm_name_to_id(dev); 61873606afdSDan Williams 61973606afdSDan Williams if (dimm < 0) 62073606afdSDan Williams return dimm; 62173606afdSDan Williams 62273606afdSDan Williams return sprintf(buf, "%#lx\n", dimm_fail_cmd_flags[dimm]); 62373606afdSDan Williams } 62473606afdSDan Williams 62573606afdSDan Williams static ssize_t fail_cmd_store(struct device *dev, struct device_attribute *attr, 62673606afdSDan Williams const char *buf, size_t size) 62773606afdSDan Williams { 62873606afdSDan Williams int dimm = dimm_name_to_id(dev); 62973606afdSDan Williams unsigned long val; 63073606afdSDan Williams ssize_t rc; 63173606afdSDan Williams 63273606afdSDan Williams if (dimm < 0) 63373606afdSDan Williams return dimm; 63473606afdSDan Williams 63573606afdSDan Williams rc = kstrtol(buf, 0, &val); 63673606afdSDan Williams if (rc) 63773606afdSDan Williams return rc; 63873606afdSDan Williams 63973606afdSDan Williams dimm_fail_cmd_flags[dimm] = val; 64073606afdSDan Williams return size; 64173606afdSDan Williams } 64273606afdSDan Williams static DEVICE_ATTR_RW(fail_cmd); 64373606afdSDan Williams 64473606afdSDan Williams static struct attribute *nfit_test_dimm_attributes[] = { 64573606afdSDan Williams &dev_attr_fail_cmd.attr, 64673606afdSDan Williams &dev_attr_handle.attr, 64773606afdSDan Williams NULL, 64873606afdSDan Williams }; 64973606afdSDan Williams 65073606afdSDan Williams static struct attribute_group nfit_test_dimm_attribute_group = { 65173606afdSDan Williams .attrs = nfit_test_dimm_attributes, 65273606afdSDan Williams }; 65373606afdSDan Williams 65473606afdSDan Williams static const struct attribute_group *nfit_test_dimm_attribute_groups[] = { 65573606afdSDan Williams &nfit_test_dimm_attribute_group, 65673606afdSDan Williams NULL, 65773606afdSDan Williams }; 65873606afdSDan Williams 6596bc75619SDan Williams static int nfit_test0_alloc(struct nfit_test *t) 6606bc75619SDan Williams { 6616b577c9dSLinda Knippers size_t nfit_size = sizeof(struct acpi_nfit_system_address) * NUM_SPA 6626bc75619SDan Williams + sizeof(struct acpi_nfit_memory_map) * NUM_MEM 6636bc75619SDan Williams + sizeof(struct acpi_nfit_control_region) * NUM_DCR 6643b87356fSDan Williams + offsetof(struct acpi_nfit_control_region, 6653b87356fSDan Williams window_size) * NUM_DCR 6669d27a87eSDan Williams + sizeof(struct acpi_nfit_data_region) * NUM_BDW 66785d3fa02SDan Williams + (sizeof(struct acpi_nfit_flush_address) 66885d3fa02SDan Williams + sizeof(u64) * NUM_HINTS) * NUM_DCR; 6696bc75619SDan Williams int i; 6706bc75619SDan Williams 6716bc75619SDan Williams t->nfit_buf = test_alloc(t, nfit_size, &t->nfit_dma); 6726bc75619SDan Williams if (!t->nfit_buf) 6736bc75619SDan Williams return -ENOMEM; 6746bc75619SDan Williams t->nfit_size = nfit_size; 6756bc75619SDan Williams 676ee8520feSDan Williams t->spa_set[0] = test_alloc(t, SPA0_SIZE, &t->spa_set_dma[0]); 6776bc75619SDan Williams if (!t->spa_set[0]) 6786bc75619SDan Williams return -ENOMEM; 6796bc75619SDan Williams 680ee8520feSDan Williams t->spa_set[1] = test_alloc(t, SPA1_SIZE, &t->spa_set_dma[1]); 6816bc75619SDan Williams if (!t->spa_set[1]) 6826bc75619SDan Williams return -ENOMEM; 6836bc75619SDan Williams 684ee8520feSDan Williams t->spa_set[2] = test_alloc(t, SPA0_SIZE, &t->spa_set_dma[2]); 68520985164SVishal Verma if (!t->spa_set[2]) 68620985164SVishal Verma return -ENOMEM; 68720985164SVishal Verma 688dafb1048SDan Williams for (i = 0; i < t->num_dcr; i++) { 6896bc75619SDan Williams t->dimm[i] = test_alloc(t, DIMM_SIZE, &t->dimm_dma[i]); 6906bc75619SDan Williams if (!t->dimm[i]) 6916bc75619SDan Williams return -ENOMEM; 6926bc75619SDan Williams 6936bc75619SDan Williams t->label[i] = test_alloc(t, LABEL_SIZE, &t->label_dma[i]); 6946bc75619SDan Williams if (!t->label[i]) 6956bc75619SDan Williams return -ENOMEM; 6966bc75619SDan Williams sprintf(t->label[i], "label%d", i); 6979d27a87eSDan Williams 6989d15ce9cSDan Williams t->flush[i] = test_alloc(t, max(PAGE_SIZE, 6999d15ce9cSDan Williams sizeof(u64) * NUM_HINTS), 70085d3fa02SDan Williams &t->flush_dma[i]); 7019d27a87eSDan Williams if (!t->flush[i]) 7029d27a87eSDan Williams return -ENOMEM; 7036bc75619SDan Williams } 7046bc75619SDan Williams 705dafb1048SDan Williams for (i = 0; i < t->num_dcr; i++) { 7066bc75619SDan Williams t->dcr[i] = test_alloc(t, LABEL_SIZE, &t->dcr_dma[i]); 7076bc75619SDan Williams if (!t->dcr[i]) 7086bc75619SDan Williams return -ENOMEM; 7096bc75619SDan Williams } 7106bc75619SDan Williams 711c14a868aSDan Williams t->_fit = test_alloc(t, sizeof(union acpi_object **), &t->_fit_dma); 712c14a868aSDan Williams if (!t->_fit) 713c14a868aSDan Williams return -ENOMEM; 714c14a868aSDan Williams 715231bf117SDan Williams if (devm_add_action_or_reset(&t->pdev.dev, put_dimms, t->dimm_dev)) 716231bf117SDan Williams return -ENOMEM; 717231bf117SDan Williams for (i = 0; i < NUM_DCR; i++) { 71873606afdSDan Williams t->dimm_dev[i] = device_create_with_groups(nfit_test_dimm, 71973606afdSDan Williams &t->pdev.dev, 0, NULL, 72073606afdSDan Williams nfit_test_dimm_attribute_groups, 72173606afdSDan Williams "test_dimm%d", i); 722231bf117SDan Williams if (!t->dimm_dev[i]) 723231bf117SDan Williams return -ENOMEM; 724231bf117SDan Williams } 725231bf117SDan Williams 726f471f1a7SDan Williams return ars_state_init(&t->pdev.dev, &t->ars_state); 7276bc75619SDan Williams } 7286bc75619SDan Williams 7296bc75619SDan Williams static int nfit_test1_alloc(struct nfit_test *t) 7306bc75619SDan Williams { 7317bfe97c7SDan Williams size_t nfit_size = sizeof(struct acpi_nfit_system_address) * 2 732ac40b675SDan Williams + sizeof(struct acpi_nfit_memory_map) * 2 733ac40b675SDan Williams + offsetof(struct acpi_nfit_control_region, window_size) * 2; 734dafb1048SDan Williams int i; 7356bc75619SDan Williams 7366bc75619SDan Williams t->nfit_buf = test_alloc(t, nfit_size, &t->nfit_dma); 7376bc75619SDan Williams if (!t->nfit_buf) 7386bc75619SDan Williams return -ENOMEM; 7396bc75619SDan Williams t->nfit_size = nfit_size; 7406bc75619SDan Williams 741ee8520feSDan Williams t->spa_set[0] = test_alloc(t, SPA2_SIZE, &t->spa_set_dma[0]); 7426bc75619SDan Williams if (!t->spa_set[0]) 7436bc75619SDan Williams return -ENOMEM; 7446bc75619SDan Williams 745dafb1048SDan Williams for (i = 0; i < t->num_dcr; i++) { 746dafb1048SDan Williams t->label[i] = test_alloc(t, LABEL_SIZE, &t->label_dma[i]); 747dafb1048SDan Williams if (!t->label[i]) 748dafb1048SDan Williams return -ENOMEM; 749dafb1048SDan Williams sprintf(t->label[i], "label%d", i); 750dafb1048SDan Williams } 751dafb1048SDan Williams 7527bfe97c7SDan Williams t->spa_set[1] = test_alloc(t, SPA_VCD_SIZE, &t->spa_set_dma[1]); 7537bfe97c7SDan Williams if (!t->spa_set[1]) 7547bfe97c7SDan Williams return -ENOMEM; 7557bfe97c7SDan Williams 756f471f1a7SDan Williams return ars_state_init(&t->pdev.dev, &t->ars_state); 7576bc75619SDan Williams } 7586bc75619SDan Williams 7595dc68e55SDan Williams static void dcr_common_init(struct acpi_nfit_control_region *dcr) 7605dc68e55SDan Williams { 7615dc68e55SDan Williams dcr->vendor_id = 0xabcd; 7625dc68e55SDan Williams dcr->device_id = 0; 7635dc68e55SDan Williams dcr->revision_id = 1; 7645dc68e55SDan Williams dcr->valid_fields = 1; 7655dc68e55SDan Williams dcr->manufacturing_location = 0xa; 7665dc68e55SDan Williams dcr->manufacturing_date = cpu_to_be16(2016); 7675dc68e55SDan Williams } 7685dc68e55SDan Williams 7696bc75619SDan Williams static void nfit_test0_setup(struct nfit_test *t) 7706bc75619SDan Williams { 77185d3fa02SDan Williams const int flush_hint_size = sizeof(struct acpi_nfit_flush_address) 77285d3fa02SDan Williams + (sizeof(u64) * NUM_HINTS); 7736bc75619SDan Williams struct acpi_nfit_desc *acpi_desc; 7746bc75619SDan Williams struct acpi_nfit_memory_map *memdev; 7756bc75619SDan Williams void *nfit_buf = t->nfit_buf; 7766bc75619SDan Williams struct acpi_nfit_system_address *spa; 7776bc75619SDan Williams struct acpi_nfit_control_region *dcr; 7786bc75619SDan Williams struct acpi_nfit_data_region *bdw; 7799d27a87eSDan Williams struct acpi_nfit_flush_address *flush; 78085d3fa02SDan Williams unsigned int offset, i; 7816bc75619SDan Williams 7826bc75619SDan Williams /* 7836bc75619SDan Williams * spa0 (interleave first half of dimm0 and dimm1, note storage 7846bc75619SDan Williams * does not actually alias the related block-data-window 7856bc75619SDan Williams * regions) 7866bc75619SDan Williams */ 7876b577c9dSLinda Knippers spa = nfit_buf; 7886bc75619SDan Williams spa->header.type = ACPI_NFIT_TYPE_SYSTEM_ADDRESS; 7896bc75619SDan Williams spa->header.length = sizeof(*spa); 7906bc75619SDan Williams memcpy(spa->range_guid, to_nfit_uuid(NFIT_SPA_PM), 16); 7916bc75619SDan Williams spa->range_index = 0+1; 7926bc75619SDan Williams spa->address = t->spa_set_dma[0]; 7936bc75619SDan Williams spa->length = SPA0_SIZE; 7946bc75619SDan Williams 7956bc75619SDan Williams /* 7966bc75619SDan Williams * spa1 (interleave last half of the 4 DIMMS, note storage 7976bc75619SDan Williams * does not actually alias the related block-data-window 7986bc75619SDan Williams * regions) 7996bc75619SDan Williams */ 8006b577c9dSLinda Knippers spa = nfit_buf + sizeof(*spa); 8016bc75619SDan Williams spa->header.type = ACPI_NFIT_TYPE_SYSTEM_ADDRESS; 8026bc75619SDan Williams spa->header.length = sizeof(*spa); 8036bc75619SDan Williams memcpy(spa->range_guid, to_nfit_uuid(NFIT_SPA_PM), 16); 8046bc75619SDan Williams spa->range_index = 1+1; 8056bc75619SDan Williams spa->address = t->spa_set_dma[1]; 8066bc75619SDan Williams spa->length = SPA1_SIZE; 8076bc75619SDan Williams 8086bc75619SDan Williams /* spa2 (dcr0) dimm0 */ 8096b577c9dSLinda Knippers spa = nfit_buf + sizeof(*spa) * 2; 8106bc75619SDan Williams spa->header.type = ACPI_NFIT_TYPE_SYSTEM_ADDRESS; 8116bc75619SDan Williams spa->header.length = sizeof(*spa); 8126bc75619SDan Williams memcpy(spa->range_guid, to_nfit_uuid(NFIT_SPA_DCR), 16); 8136bc75619SDan Williams spa->range_index = 2+1; 8146bc75619SDan Williams spa->address = t->dcr_dma[0]; 8156bc75619SDan Williams spa->length = DCR_SIZE; 8166bc75619SDan Williams 8176bc75619SDan Williams /* spa3 (dcr1) dimm1 */ 8186b577c9dSLinda Knippers spa = nfit_buf + sizeof(*spa) * 3; 8196bc75619SDan Williams spa->header.type = ACPI_NFIT_TYPE_SYSTEM_ADDRESS; 8206bc75619SDan Williams spa->header.length = sizeof(*spa); 8216bc75619SDan Williams memcpy(spa->range_guid, to_nfit_uuid(NFIT_SPA_DCR), 16); 8226bc75619SDan Williams spa->range_index = 3+1; 8236bc75619SDan Williams spa->address = t->dcr_dma[1]; 8246bc75619SDan Williams spa->length = DCR_SIZE; 8256bc75619SDan Williams 8266bc75619SDan Williams /* spa4 (dcr2) dimm2 */ 8276b577c9dSLinda Knippers spa = nfit_buf + sizeof(*spa) * 4; 8286bc75619SDan Williams spa->header.type = ACPI_NFIT_TYPE_SYSTEM_ADDRESS; 8296bc75619SDan Williams spa->header.length = sizeof(*spa); 8306bc75619SDan Williams memcpy(spa->range_guid, to_nfit_uuid(NFIT_SPA_DCR), 16); 8316bc75619SDan Williams spa->range_index = 4+1; 8326bc75619SDan Williams spa->address = t->dcr_dma[2]; 8336bc75619SDan Williams spa->length = DCR_SIZE; 8346bc75619SDan Williams 8356bc75619SDan Williams /* spa5 (dcr3) dimm3 */ 8366b577c9dSLinda Knippers spa = nfit_buf + sizeof(*spa) * 5; 8376bc75619SDan Williams spa->header.type = ACPI_NFIT_TYPE_SYSTEM_ADDRESS; 8386bc75619SDan Williams spa->header.length = sizeof(*spa); 8396bc75619SDan Williams memcpy(spa->range_guid, to_nfit_uuid(NFIT_SPA_DCR), 16); 8406bc75619SDan Williams spa->range_index = 5+1; 8416bc75619SDan Williams spa->address = t->dcr_dma[3]; 8426bc75619SDan Williams spa->length = DCR_SIZE; 8436bc75619SDan Williams 8446bc75619SDan Williams /* spa6 (bdw for dcr0) dimm0 */ 8456b577c9dSLinda Knippers spa = nfit_buf + sizeof(*spa) * 6; 8466bc75619SDan Williams spa->header.type = ACPI_NFIT_TYPE_SYSTEM_ADDRESS; 8476bc75619SDan Williams spa->header.length = sizeof(*spa); 8486bc75619SDan Williams memcpy(spa->range_guid, to_nfit_uuid(NFIT_SPA_BDW), 16); 8496bc75619SDan Williams spa->range_index = 6+1; 8506bc75619SDan Williams spa->address = t->dimm_dma[0]; 8516bc75619SDan Williams spa->length = DIMM_SIZE; 8526bc75619SDan Williams 8536bc75619SDan Williams /* spa7 (bdw for dcr1) dimm1 */ 8546b577c9dSLinda Knippers spa = nfit_buf + sizeof(*spa) * 7; 8556bc75619SDan Williams spa->header.type = ACPI_NFIT_TYPE_SYSTEM_ADDRESS; 8566bc75619SDan Williams spa->header.length = sizeof(*spa); 8576bc75619SDan Williams memcpy(spa->range_guid, to_nfit_uuid(NFIT_SPA_BDW), 16); 8586bc75619SDan Williams spa->range_index = 7+1; 8596bc75619SDan Williams spa->address = t->dimm_dma[1]; 8606bc75619SDan Williams spa->length = DIMM_SIZE; 8616bc75619SDan Williams 8626bc75619SDan Williams /* spa8 (bdw for dcr2) dimm2 */ 8636b577c9dSLinda Knippers spa = nfit_buf + sizeof(*spa) * 8; 8646bc75619SDan Williams spa->header.type = ACPI_NFIT_TYPE_SYSTEM_ADDRESS; 8656bc75619SDan Williams spa->header.length = sizeof(*spa); 8666bc75619SDan Williams memcpy(spa->range_guid, to_nfit_uuid(NFIT_SPA_BDW), 16); 8676bc75619SDan Williams spa->range_index = 8+1; 8686bc75619SDan Williams spa->address = t->dimm_dma[2]; 8696bc75619SDan Williams spa->length = DIMM_SIZE; 8706bc75619SDan Williams 8716bc75619SDan Williams /* spa9 (bdw for dcr3) dimm3 */ 8726b577c9dSLinda Knippers spa = nfit_buf + sizeof(*spa) * 9; 8736bc75619SDan Williams spa->header.type = ACPI_NFIT_TYPE_SYSTEM_ADDRESS; 8746bc75619SDan Williams spa->header.length = sizeof(*spa); 8756bc75619SDan Williams memcpy(spa->range_guid, to_nfit_uuid(NFIT_SPA_BDW), 16); 8766bc75619SDan Williams spa->range_index = 9+1; 8776bc75619SDan Williams spa->address = t->dimm_dma[3]; 8786bc75619SDan Williams spa->length = DIMM_SIZE; 8796bc75619SDan Williams 8806b577c9dSLinda Knippers offset = sizeof(*spa) * 10; 8816bc75619SDan Williams /* mem-region0 (spa0, dimm0) */ 8826bc75619SDan Williams memdev = nfit_buf + offset; 8836bc75619SDan Williams memdev->header.type = ACPI_NFIT_TYPE_MEMORY_MAP; 8846bc75619SDan Williams memdev->header.length = sizeof(*memdev); 8856bc75619SDan Williams memdev->device_handle = handle[0]; 8866bc75619SDan Williams memdev->physical_id = 0; 8876bc75619SDan Williams memdev->region_id = 0; 8886bc75619SDan Williams memdev->range_index = 0+1; 8893b87356fSDan Williams memdev->region_index = 4+1; 8906bc75619SDan Williams memdev->region_size = SPA0_SIZE/2; 891df06a2d5SDan Williams memdev->region_offset = 1; 8926bc75619SDan Williams memdev->address = 0; 8936bc75619SDan Williams memdev->interleave_index = 0; 8946bc75619SDan Williams memdev->interleave_ways = 2; 8956bc75619SDan Williams 8966bc75619SDan Williams /* mem-region1 (spa0, dimm1) */ 8976bc75619SDan Williams memdev = nfit_buf + offset + sizeof(struct acpi_nfit_memory_map); 8986bc75619SDan Williams memdev->header.type = ACPI_NFIT_TYPE_MEMORY_MAP; 8996bc75619SDan Williams memdev->header.length = sizeof(*memdev); 9006bc75619SDan Williams memdev->device_handle = handle[1]; 9016bc75619SDan Williams memdev->physical_id = 1; 9026bc75619SDan Williams memdev->region_id = 0; 9036bc75619SDan Williams memdev->range_index = 0+1; 9043b87356fSDan Williams memdev->region_index = 5+1; 9056bc75619SDan Williams memdev->region_size = SPA0_SIZE/2; 906df06a2d5SDan Williams memdev->region_offset = (1 << 8); 9076bc75619SDan Williams memdev->address = 0; 9086bc75619SDan Williams memdev->interleave_index = 0; 9096bc75619SDan Williams memdev->interleave_ways = 2; 910ac40b675SDan Williams memdev->flags = ACPI_NFIT_MEM_HEALTH_ENABLED; 9116bc75619SDan Williams 9126bc75619SDan Williams /* mem-region2 (spa1, dimm0) */ 9136bc75619SDan Williams memdev = nfit_buf + offset + sizeof(struct acpi_nfit_memory_map) * 2; 9146bc75619SDan Williams memdev->header.type = ACPI_NFIT_TYPE_MEMORY_MAP; 9156bc75619SDan Williams memdev->header.length = sizeof(*memdev); 9166bc75619SDan Williams memdev->device_handle = handle[0]; 9176bc75619SDan Williams memdev->physical_id = 0; 9186bc75619SDan Williams memdev->region_id = 1; 9196bc75619SDan Williams memdev->range_index = 1+1; 9203b87356fSDan Williams memdev->region_index = 4+1; 9216bc75619SDan Williams memdev->region_size = SPA1_SIZE/4; 922df06a2d5SDan Williams memdev->region_offset = (1 << 16); 9236bc75619SDan Williams memdev->address = SPA0_SIZE/2; 9246bc75619SDan Williams memdev->interleave_index = 0; 9256bc75619SDan Williams memdev->interleave_ways = 4; 926ac40b675SDan Williams memdev->flags = ACPI_NFIT_MEM_HEALTH_ENABLED; 9276bc75619SDan Williams 9286bc75619SDan Williams /* mem-region3 (spa1, dimm1) */ 9296bc75619SDan Williams memdev = nfit_buf + offset + sizeof(struct acpi_nfit_memory_map) * 3; 9306bc75619SDan Williams memdev->header.type = ACPI_NFIT_TYPE_MEMORY_MAP; 9316bc75619SDan Williams memdev->header.length = sizeof(*memdev); 9326bc75619SDan Williams memdev->device_handle = handle[1]; 9336bc75619SDan Williams memdev->physical_id = 1; 9346bc75619SDan Williams memdev->region_id = 1; 9356bc75619SDan Williams memdev->range_index = 1+1; 9363b87356fSDan Williams memdev->region_index = 5+1; 9376bc75619SDan Williams memdev->region_size = SPA1_SIZE/4; 938df06a2d5SDan Williams memdev->region_offset = (1 << 24); 9396bc75619SDan Williams memdev->address = SPA0_SIZE/2; 9406bc75619SDan Williams memdev->interleave_index = 0; 9416bc75619SDan Williams memdev->interleave_ways = 4; 9426bc75619SDan Williams 9436bc75619SDan Williams /* mem-region4 (spa1, dimm2) */ 9446bc75619SDan Williams memdev = nfit_buf + offset + sizeof(struct acpi_nfit_memory_map) * 4; 9456bc75619SDan Williams memdev->header.type = ACPI_NFIT_TYPE_MEMORY_MAP; 9466bc75619SDan Williams memdev->header.length = sizeof(*memdev); 9476bc75619SDan Williams memdev->device_handle = handle[2]; 9486bc75619SDan Williams memdev->physical_id = 2; 9496bc75619SDan Williams memdev->region_id = 0; 9506bc75619SDan Williams memdev->range_index = 1+1; 9513b87356fSDan Williams memdev->region_index = 6+1; 9526bc75619SDan Williams memdev->region_size = SPA1_SIZE/4; 953df06a2d5SDan Williams memdev->region_offset = (1ULL << 32); 9546bc75619SDan Williams memdev->address = SPA0_SIZE/2; 9556bc75619SDan Williams memdev->interleave_index = 0; 9566bc75619SDan Williams memdev->interleave_ways = 4; 957ac40b675SDan Williams memdev->flags = ACPI_NFIT_MEM_HEALTH_ENABLED; 9586bc75619SDan Williams 9596bc75619SDan Williams /* mem-region5 (spa1, dimm3) */ 9606bc75619SDan Williams memdev = nfit_buf + offset + sizeof(struct acpi_nfit_memory_map) * 5; 9616bc75619SDan Williams memdev->header.type = ACPI_NFIT_TYPE_MEMORY_MAP; 9626bc75619SDan Williams memdev->header.length = sizeof(*memdev); 9636bc75619SDan Williams memdev->device_handle = handle[3]; 9646bc75619SDan Williams memdev->physical_id = 3; 9656bc75619SDan Williams memdev->region_id = 0; 9666bc75619SDan Williams memdev->range_index = 1+1; 9673b87356fSDan Williams memdev->region_index = 7+1; 9686bc75619SDan Williams memdev->region_size = SPA1_SIZE/4; 969df06a2d5SDan Williams memdev->region_offset = (1ULL << 40); 9706bc75619SDan Williams memdev->address = SPA0_SIZE/2; 9716bc75619SDan Williams memdev->interleave_index = 0; 9726bc75619SDan Williams memdev->interleave_ways = 4; 9736bc75619SDan Williams 9746bc75619SDan Williams /* mem-region6 (spa/dcr0, dimm0) */ 9756bc75619SDan Williams memdev = nfit_buf + offset + sizeof(struct acpi_nfit_memory_map) * 6; 9766bc75619SDan Williams memdev->header.type = ACPI_NFIT_TYPE_MEMORY_MAP; 9776bc75619SDan Williams memdev->header.length = sizeof(*memdev); 9786bc75619SDan Williams memdev->device_handle = handle[0]; 9796bc75619SDan Williams memdev->physical_id = 0; 9806bc75619SDan Williams memdev->region_id = 0; 9816bc75619SDan Williams memdev->range_index = 2+1; 9826bc75619SDan Williams memdev->region_index = 0+1; 9836bc75619SDan Williams memdev->region_size = 0; 9846bc75619SDan Williams memdev->region_offset = 0; 9856bc75619SDan Williams memdev->address = 0; 9866bc75619SDan Williams memdev->interleave_index = 0; 9876bc75619SDan Williams memdev->interleave_ways = 1; 9886bc75619SDan Williams 9896bc75619SDan Williams /* mem-region7 (spa/dcr1, dimm1) */ 9906bc75619SDan Williams memdev = nfit_buf + offset + sizeof(struct acpi_nfit_memory_map) * 7; 9916bc75619SDan Williams memdev->header.type = ACPI_NFIT_TYPE_MEMORY_MAP; 9926bc75619SDan Williams memdev->header.length = sizeof(*memdev); 9936bc75619SDan Williams memdev->device_handle = handle[1]; 9946bc75619SDan Williams memdev->physical_id = 1; 9956bc75619SDan Williams memdev->region_id = 0; 9966bc75619SDan Williams memdev->range_index = 3+1; 9976bc75619SDan Williams memdev->region_index = 1+1; 9986bc75619SDan Williams memdev->region_size = 0; 9996bc75619SDan Williams memdev->region_offset = 0; 10006bc75619SDan Williams memdev->address = 0; 10016bc75619SDan Williams memdev->interleave_index = 0; 10026bc75619SDan Williams memdev->interleave_ways = 1; 10036bc75619SDan Williams 10046bc75619SDan Williams /* mem-region8 (spa/dcr2, dimm2) */ 10056bc75619SDan Williams memdev = nfit_buf + offset + sizeof(struct acpi_nfit_memory_map) * 8; 10066bc75619SDan Williams memdev->header.type = ACPI_NFIT_TYPE_MEMORY_MAP; 10076bc75619SDan Williams memdev->header.length = sizeof(*memdev); 10086bc75619SDan Williams memdev->device_handle = handle[2]; 10096bc75619SDan Williams memdev->physical_id = 2; 10106bc75619SDan Williams memdev->region_id = 0; 10116bc75619SDan Williams memdev->range_index = 4+1; 10126bc75619SDan Williams memdev->region_index = 2+1; 10136bc75619SDan Williams memdev->region_size = 0; 10146bc75619SDan Williams memdev->region_offset = 0; 10156bc75619SDan Williams memdev->address = 0; 10166bc75619SDan Williams memdev->interleave_index = 0; 10176bc75619SDan Williams memdev->interleave_ways = 1; 10186bc75619SDan Williams 10196bc75619SDan Williams /* mem-region9 (spa/dcr3, dimm3) */ 10206bc75619SDan Williams memdev = nfit_buf + offset + sizeof(struct acpi_nfit_memory_map) * 9; 10216bc75619SDan Williams memdev->header.type = ACPI_NFIT_TYPE_MEMORY_MAP; 10226bc75619SDan Williams memdev->header.length = sizeof(*memdev); 10236bc75619SDan Williams memdev->device_handle = handle[3]; 10246bc75619SDan Williams memdev->physical_id = 3; 10256bc75619SDan Williams memdev->region_id = 0; 10266bc75619SDan Williams memdev->range_index = 5+1; 10276bc75619SDan Williams memdev->region_index = 3+1; 10286bc75619SDan Williams memdev->region_size = 0; 10296bc75619SDan Williams memdev->region_offset = 0; 10306bc75619SDan Williams memdev->address = 0; 10316bc75619SDan Williams memdev->interleave_index = 0; 10326bc75619SDan Williams memdev->interleave_ways = 1; 10336bc75619SDan Williams 10346bc75619SDan Williams /* mem-region10 (spa/bdw0, dimm0) */ 10356bc75619SDan Williams memdev = nfit_buf + offset + sizeof(struct acpi_nfit_memory_map) * 10; 10366bc75619SDan Williams memdev->header.type = ACPI_NFIT_TYPE_MEMORY_MAP; 10376bc75619SDan Williams memdev->header.length = sizeof(*memdev); 10386bc75619SDan Williams memdev->device_handle = handle[0]; 10396bc75619SDan Williams memdev->physical_id = 0; 10406bc75619SDan Williams memdev->region_id = 0; 10416bc75619SDan Williams memdev->range_index = 6+1; 10426bc75619SDan Williams memdev->region_index = 0+1; 10436bc75619SDan Williams memdev->region_size = 0; 10446bc75619SDan Williams memdev->region_offset = 0; 10456bc75619SDan Williams memdev->address = 0; 10466bc75619SDan Williams memdev->interleave_index = 0; 10476bc75619SDan Williams memdev->interleave_ways = 1; 10486bc75619SDan Williams 10496bc75619SDan Williams /* mem-region11 (spa/bdw1, dimm1) */ 10506bc75619SDan Williams memdev = nfit_buf + offset + sizeof(struct acpi_nfit_memory_map) * 11; 10516bc75619SDan Williams memdev->header.type = ACPI_NFIT_TYPE_MEMORY_MAP; 10526bc75619SDan Williams memdev->header.length = sizeof(*memdev); 10536bc75619SDan Williams memdev->device_handle = handle[1]; 10546bc75619SDan Williams memdev->physical_id = 1; 10556bc75619SDan Williams memdev->region_id = 0; 10566bc75619SDan Williams memdev->range_index = 7+1; 10576bc75619SDan Williams memdev->region_index = 1+1; 10586bc75619SDan Williams memdev->region_size = 0; 10596bc75619SDan Williams memdev->region_offset = 0; 10606bc75619SDan Williams memdev->address = 0; 10616bc75619SDan Williams memdev->interleave_index = 0; 10626bc75619SDan Williams memdev->interleave_ways = 1; 10636bc75619SDan Williams 10646bc75619SDan Williams /* mem-region12 (spa/bdw2, dimm2) */ 10656bc75619SDan Williams memdev = nfit_buf + offset + sizeof(struct acpi_nfit_memory_map) * 12; 10666bc75619SDan Williams memdev->header.type = ACPI_NFIT_TYPE_MEMORY_MAP; 10676bc75619SDan Williams memdev->header.length = sizeof(*memdev); 10686bc75619SDan Williams memdev->device_handle = handle[2]; 10696bc75619SDan Williams memdev->physical_id = 2; 10706bc75619SDan Williams memdev->region_id = 0; 10716bc75619SDan Williams memdev->range_index = 8+1; 10726bc75619SDan Williams memdev->region_index = 2+1; 10736bc75619SDan Williams memdev->region_size = 0; 10746bc75619SDan Williams memdev->region_offset = 0; 10756bc75619SDan Williams memdev->address = 0; 10766bc75619SDan Williams memdev->interleave_index = 0; 10776bc75619SDan Williams memdev->interleave_ways = 1; 10786bc75619SDan Williams 10796bc75619SDan Williams /* mem-region13 (spa/dcr3, dimm3) */ 10806bc75619SDan Williams memdev = nfit_buf + offset + sizeof(struct acpi_nfit_memory_map) * 13; 10816bc75619SDan Williams memdev->header.type = ACPI_NFIT_TYPE_MEMORY_MAP; 10826bc75619SDan Williams memdev->header.length = sizeof(*memdev); 10836bc75619SDan Williams memdev->device_handle = handle[3]; 10846bc75619SDan Williams memdev->physical_id = 3; 10856bc75619SDan Williams memdev->region_id = 0; 10866bc75619SDan Williams memdev->range_index = 9+1; 10876bc75619SDan Williams memdev->region_index = 3+1; 10886bc75619SDan Williams memdev->region_size = 0; 10896bc75619SDan Williams memdev->region_offset = 0; 10906bc75619SDan Williams memdev->address = 0; 10916bc75619SDan Williams memdev->interleave_index = 0; 10926bc75619SDan Williams memdev->interleave_ways = 1; 1093ac40b675SDan Williams memdev->flags = ACPI_NFIT_MEM_HEALTH_ENABLED; 10946bc75619SDan Williams 10956bc75619SDan Williams offset = offset + sizeof(struct acpi_nfit_memory_map) * 14; 10963b87356fSDan Williams /* dcr-descriptor0: blk */ 10976bc75619SDan Williams dcr = nfit_buf + offset; 10986bc75619SDan Williams dcr->header.type = ACPI_NFIT_TYPE_CONTROL_REGION; 10996bc75619SDan Williams dcr->header.length = sizeof(struct acpi_nfit_control_region); 11006bc75619SDan Williams dcr->region_index = 0+1; 11015dc68e55SDan Williams dcr_common_init(dcr); 11026bc75619SDan Williams dcr->serial_number = ~handle[0]; 1103be26f9aeSDan Williams dcr->code = NFIT_FIC_BLK; 11046bc75619SDan Williams dcr->windows = 1; 11056bc75619SDan Williams dcr->window_size = DCR_SIZE; 11066bc75619SDan Williams dcr->command_offset = 0; 11076bc75619SDan Williams dcr->command_size = 8; 11086bc75619SDan Williams dcr->status_offset = 8; 11096bc75619SDan Williams dcr->status_size = 4; 11106bc75619SDan Williams 11113b87356fSDan Williams /* dcr-descriptor1: blk */ 11126bc75619SDan Williams dcr = nfit_buf + offset + sizeof(struct acpi_nfit_control_region); 11136bc75619SDan Williams dcr->header.type = ACPI_NFIT_TYPE_CONTROL_REGION; 11146bc75619SDan Williams dcr->header.length = sizeof(struct acpi_nfit_control_region); 11156bc75619SDan Williams dcr->region_index = 1+1; 11165dc68e55SDan Williams dcr_common_init(dcr); 11176bc75619SDan Williams dcr->serial_number = ~handle[1]; 1118be26f9aeSDan Williams dcr->code = NFIT_FIC_BLK; 11196bc75619SDan Williams dcr->windows = 1; 11206bc75619SDan Williams dcr->window_size = DCR_SIZE; 11216bc75619SDan Williams dcr->command_offset = 0; 11226bc75619SDan Williams dcr->command_size = 8; 11236bc75619SDan Williams dcr->status_offset = 8; 11246bc75619SDan Williams dcr->status_size = 4; 11256bc75619SDan Williams 11263b87356fSDan Williams /* dcr-descriptor2: blk */ 11276bc75619SDan Williams dcr = nfit_buf + offset + sizeof(struct acpi_nfit_control_region) * 2; 11286bc75619SDan Williams dcr->header.type = ACPI_NFIT_TYPE_CONTROL_REGION; 11296bc75619SDan Williams dcr->header.length = sizeof(struct acpi_nfit_control_region); 11306bc75619SDan Williams dcr->region_index = 2+1; 11315dc68e55SDan Williams dcr_common_init(dcr); 11326bc75619SDan Williams dcr->serial_number = ~handle[2]; 1133be26f9aeSDan Williams dcr->code = NFIT_FIC_BLK; 11346bc75619SDan Williams dcr->windows = 1; 11356bc75619SDan Williams dcr->window_size = DCR_SIZE; 11366bc75619SDan Williams dcr->command_offset = 0; 11376bc75619SDan Williams dcr->command_size = 8; 11386bc75619SDan Williams dcr->status_offset = 8; 11396bc75619SDan Williams dcr->status_size = 4; 11406bc75619SDan Williams 11413b87356fSDan Williams /* dcr-descriptor3: blk */ 11426bc75619SDan Williams dcr = nfit_buf + offset + sizeof(struct acpi_nfit_control_region) * 3; 11436bc75619SDan Williams dcr->header.type = ACPI_NFIT_TYPE_CONTROL_REGION; 11446bc75619SDan Williams dcr->header.length = sizeof(struct acpi_nfit_control_region); 11456bc75619SDan Williams dcr->region_index = 3+1; 11465dc68e55SDan Williams dcr_common_init(dcr); 11476bc75619SDan Williams dcr->serial_number = ~handle[3]; 1148be26f9aeSDan Williams dcr->code = NFIT_FIC_BLK; 11496bc75619SDan Williams dcr->windows = 1; 11506bc75619SDan Williams dcr->window_size = DCR_SIZE; 11516bc75619SDan Williams dcr->command_offset = 0; 11526bc75619SDan Williams dcr->command_size = 8; 11536bc75619SDan Williams dcr->status_offset = 8; 11546bc75619SDan Williams dcr->status_size = 4; 11556bc75619SDan Williams 11566bc75619SDan Williams offset = offset + sizeof(struct acpi_nfit_control_region) * 4; 11573b87356fSDan Williams /* dcr-descriptor0: pmem */ 11583b87356fSDan Williams dcr = nfit_buf + offset; 11593b87356fSDan Williams dcr->header.type = ACPI_NFIT_TYPE_CONTROL_REGION; 11603b87356fSDan Williams dcr->header.length = offsetof(struct acpi_nfit_control_region, 11613b87356fSDan Williams window_size); 11623b87356fSDan Williams dcr->region_index = 4+1; 11635dc68e55SDan Williams dcr_common_init(dcr); 11643b87356fSDan Williams dcr->serial_number = ~handle[0]; 11653b87356fSDan Williams dcr->code = NFIT_FIC_BYTEN; 11663b87356fSDan Williams dcr->windows = 0; 11673b87356fSDan Williams 11683b87356fSDan Williams /* dcr-descriptor1: pmem */ 11693b87356fSDan Williams dcr = nfit_buf + offset + offsetof(struct acpi_nfit_control_region, 11703b87356fSDan Williams window_size); 11713b87356fSDan Williams dcr->header.type = ACPI_NFIT_TYPE_CONTROL_REGION; 11723b87356fSDan Williams dcr->header.length = offsetof(struct acpi_nfit_control_region, 11733b87356fSDan Williams window_size); 11743b87356fSDan Williams dcr->region_index = 5+1; 11755dc68e55SDan Williams dcr_common_init(dcr); 11763b87356fSDan Williams dcr->serial_number = ~handle[1]; 11773b87356fSDan Williams dcr->code = NFIT_FIC_BYTEN; 11783b87356fSDan Williams dcr->windows = 0; 11793b87356fSDan Williams 11803b87356fSDan Williams /* dcr-descriptor2: pmem */ 11813b87356fSDan Williams dcr = nfit_buf + offset + offsetof(struct acpi_nfit_control_region, 11823b87356fSDan Williams window_size) * 2; 11833b87356fSDan Williams dcr->header.type = ACPI_NFIT_TYPE_CONTROL_REGION; 11843b87356fSDan Williams dcr->header.length = offsetof(struct acpi_nfit_control_region, 11853b87356fSDan Williams window_size); 11863b87356fSDan Williams dcr->region_index = 6+1; 11875dc68e55SDan Williams dcr_common_init(dcr); 11883b87356fSDan Williams dcr->serial_number = ~handle[2]; 11893b87356fSDan Williams dcr->code = NFIT_FIC_BYTEN; 11903b87356fSDan Williams dcr->windows = 0; 11913b87356fSDan Williams 11923b87356fSDan Williams /* dcr-descriptor3: pmem */ 11933b87356fSDan Williams dcr = nfit_buf + offset + offsetof(struct acpi_nfit_control_region, 11943b87356fSDan Williams window_size) * 3; 11953b87356fSDan Williams dcr->header.type = ACPI_NFIT_TYPE_CONTROL_REGION; 11963b87356fSDan Williams dcr->header.length = offsetof(struct acpi_nfit_control_region, 11973b87356fSDan Williams window_size); 11983b87356fSDan Williams dcr->region_index = 7+1; 11995dc68e55SDan Williams dcr_common_init(dcr); 12003b87356fSDan Williams dcr->serial_number = ~handle[3]; 12013b87356fSDan Williams dcr->code = NFIT_FIC_BYTEN; 12023b87356fSDan Williams dcr->windows = 0; 12033b87356fSDan Williams 12043b87356fSDan Williams offset = offset + offsetof(struct acpi_nfit_control_region, 12053b87356fSDan Williams window_size) * 4; 12066bc75619SDan Williams /* bdw0 (spa/dcr0, dimm0) */ 12076bc75619SDan Williams bdw = nfit_buf + offset; 12086bc75619SDan Williams bdw->header.type = ACPI_NFIT_TYPE_DATA_REGION; 12096bc75619SDan Williams bdw->header.length = sizeof(struct acpi_nfit_data_region); 12106bc75619SDan Williams bdw->region_index = 0+1; 12116bc75619SDan Williams bdw->windows = 1; 12126bc75619SDan Williams bdw->offset = 0; 12136bc75619SDan Williams bdw->size = BDW_SIZE; 12146bc75619SDan Williams bdw->capacity = DIMM_SIZE; 12156bc75619SDan Williams bdw->start_address = 0; 12166bc75619SDan Williams 12176bc75619SDan Williams /* bdw1 (spa/dcr1, dimm1) */ 12186bc75619SDan Williams bdw = nfit_buf + offset + sizeof(struct acpi_nfit_data_region); 12196bc75619SDan Williams bdw->header.type = ACPI_NFIT_TYPE_DATA_REGION; 12206bc75619SDan Williams bdw->header.length = sizeof(struct acpi_nfit_data_region); 12216bc75619SDan Williams bdw->region_index = 1+1; 12226bc75619SDan Williams bdw->windows = 1; 12236bc75619SDan Williams bdw->offset = 0; 12246bc75619SDan Williams bdw->size = BDW_SIZE; 12256bc75619SDan Williams bdw->capacity = DIMM_SIZE; 12266bc75619SDan Williams bdw->start_address = 0; 12276bc75619SDan Williams 12286bc75619SDan Williams /* bdw2 (spa/dcr2, dimm2) */ 12296bc75619SDan Williams bdw = nfit_buf + offset + sizeof(struct acpi_nfit_data_region) * 2; 12306bc75619SDan Williams bdw->header.type = ACPI_NFIT_TYPE_DATA_REGION; 12316bc75619SDan Williams bdw->header.length = sizeof(struct acpi_nfit_data_region); 12326bc75619SDan Williams bdw->region_index = 2+1; 12336bc75619SDan Williams bdw->windows = 1; 12346bc75619SDan Williams bdw->offset = 0; 12356bc75619SDan Williams bdw->size = BDW_SIZE; 12366bc75619SDan Williams bdw->capacity = DIMM_SIZE; 12376bc75619SDan Williams bdw->start_address = 0; 12386bc75619SDan Williams 12396bc75619SDan Williams /* bdw3 (spa/dcr3, dimm3) */ 12406bc75619SDan Williams bdw = nfit_buf + offset + sizeof(struct acpi_nfit_data_region) * 3; 12416bc75619SDan Williams bdw->header.type = ACPI_NFIT_TYPE_DATA_REGION; 12426bc75619SDan Williams bdw->header.length = sizeof(struct acpi_nfit_data_region); 12436bc75619SDan Williams bdw->region_index = 3+1; 12446bc75619SDan Williams bdw->windows = 1; 12456bc75619SDan Williams bdw->offset = 0; 12466bc75619SDan Williams bdw->size = BDW_SIZE; 12476bc75619SDan Williams bdw->capacity = DIMM_SIZE; 12486bc75619SDan Williams bdw->start_address = 0; 12496bc75619SDan Williams 12509d27a87eSDan Williams offset = offset + sizeof(struct acpi_nfit_data_region) * 4; 12519d27a87eSDan Williams /* flush0 (dimm0) */ 12529d27a87eSDan Williams flush = nfit_buf + offset; 12539d27a87eSDan Williams flush->header.type = ACPI_NFIT_TYPE_FLUSH_ADDRESS; 125485d3fa02SDan Williams flush->header.length = flush_hint_size; 12559d27a87eSDan Williams flush->device_handle = handle[0]; 125685d3fa02SDan Williams flush->hint_count = NUM_HINTS; 125785d3fa02SDan Williams for (i = 0; i < NUM_HINTS; i++) 125885d3fa02SDan Williams flush->hint_address[i] = t->flush_dma[0] + i * sizeof(u64); 12599d27a87eSDan Williams 12609d27a87eSDan Williams /* flush1 (dimm1) */ 126185d3fa02SDan Williams flush = nfit_buf + offset + flush_hint_size * 1; 12629d27a87eSDan Williams flush->header.type = ACPI_NFIT_TYPE_FLUSH_ADDRESS; 126385d3fa02SDan Williams flush->header.length = flush_hint_size; 12649d27a87eSDan Williams flush->device_handle = handle[1]; 126585d3fa02SDan Williams flush->hint_count = NUM_HINTS; 126685d3fa02SDan Williams for (i = 0; i < NUM_HINTS; i++) 126785d3fa02SDan Williams flush->hint_address[i] = t->flush_dma[1] + i * sizeof(u64); 12689d27a87eSDan Williams 12699d27a87eSDan Williams /* flush2 (dimm2) */ 127085d3fa02SDan Williams flush = nfit_buf + offset + flush_hint_size * 2; 12719d27a87eSDan Williams flush->header.type = ACPI_NFIT_TYPE_FLUSH_ADDRESS; 127285d3fa02SDan Williams flush->header.length = flush_hint_size; 12739d27a87eSDan Williams flush->device_handle = handle[2]; 127485d3fa02SDan Williams flush->hint_count = NUM_HINTS; 127585d3fa02SDan Williams for (i = 0; i < NUM_HINTS; i++) 127685d3fa02SDan Williams flush->hint_address[i] = t->flush_dma[2] + i * sizeof(u64); 12779d27a87eSDan Williams 12789d27a87eSDan Williams /* flush3 (dimm3) */ 127985d3fa02SDan Williams flush = nfit_buf + offset + flush_hint_size * 3; 12809d27a87eSDan Williams flush->header.type = ACPI_NFIT_TYPE_FLUSH_ADDRESS; 128185d3fa02SDan Williams flush->header.length = flush_hint_size; 12829d27a87eSDan Williams flush->device_handle = handle[3]; 128385d3fa02SDan Williams flush->hint_count = NUM_HINTS; 128485d3fa02SDan Williams for (i = 0; i < NUM_HINTS; i++) 128585d3fa02SDan Williams flush->hint_address[i] = t->flush_dma[3] + i * sizeof(u64); 12869d27a87eSDan Williams 128720985164SVishal Verma if (t->setup_hotplug) { 128885d3fa02SDan Williams offset = offset + flush_hint_size * 4; 12893b87356fSDan Williams /* dcr-descriptor4: blk */ 129020985164SVishal Verma dcr = nfit_buf + offset; 129120985164SVishal Verma dcr->header.type = ACPI_NFIT_TYPE_CONTROL_REGION; 129220985164SVishal Verma dcr->header.length = sizeof(struct acpi_nfit_control_region); 12933b87356fSDan Williams dcr->region_index = 8+1; 12945dc68e55SDan Williams dcr_common_init(dcr); 129520985164SVishal Verma dcr->serial_number = ~handle[4]; 1296be26f9aeSDan Williams dcr->code = NFIT_FIC_BLK; 129720985164SVishal Verma dcr->windows = 1; 129820985164SVishal Verma dcr->window_size = DCR_SIZE; 129920985164SVishal Verma dcr->command_offset = 0; 130020985164SVishal Verma dcr->command_size = 8; 130120985164SVishal Verma dcr->status_offset = 8; 130220985164SVishal Verma dcr->status_size = 4; 130320985164SVishal Verma 130420985164SVishal Verma offset = offset + sizeof(struct acpi_nfit_control_region); 13053b87356fSDan Williams /* dcr-descriptor4: pmem */ 13063b87356fSDan Williams dcr = nfit_buf + offset; 13073b87356fSDan Williams dcr->header.type = ACPI_NFIT_TYPE_CONTROL_REGION; 13083b87356fSDan Williams dcr->header.length = offsetof(struct acpi_nfit_control_region, 13093b87356fSDan Williams window_size); 13103b87356fSDan Williams dcr->region_index = 9+1; 13115dc68e55SDan Williams dcr_common_init(dcr); 13123b87356fSDan Williams dcr->serial_number = ~handle[4]; 13133b87356fSDan Williams dcr->code = NFIT_FIC_BYTEN; 13143b87356fSDan Williams dcr->windows = 0; 13153b87356fSDan Williams 13163b87356fSDan Williams offset = offset + offsetof(struct acpi_nfit_control_region, 13173b87356fSDan Williams window_size); 131820985164SVishal Verma /* bdw4 (spa/dcr4, dimm4) */ 131920985164SVishal Verma bdw = nfit_buf + offset; 132020985164SVishal Verma bdw->header.type = ACPI_NFIT_TYPE_DATA_REGION; 132120985164SVishal Verma bdw->header.length = sizeof(struct acpi_nfit_data_region); 13223b87356fSDan Williams bdw->region_index = 8+1; 132320985164SVishal Verma bdw->windows = 1; 132420985164SVishal Verma bdw->offset = 0; 132520985164SVishal Verma bdw->size = BDW_SIZE; 132620985164SVishal Verma bdw->capacity = DIMM_SIZE; 132720985164SVishal Verma bdw->start_address = 0; 132820985164SVishal Verma 132920985164SVishal Verma offset = offset + sizeof(struct acpi_nfit_data_region); 133020985164SVishal Verma /* spa10 (dcr4) dimm4 */ 133120985164SVishal Verma spa = nfit_buf + offset; 133220985164SVishal Verma spa->header.type = ACPI_NFIT_TYPE_SYSTEM_ADDRESS; 133320985164SVishal Verma spa->header.length = sizeof(*spa); 133420985164SVishal Verma memcpy(spa->range_guid, to_nfit_uuid(NFIT_SPA_DCR), 16); 133520985164SVishal Verma spa->range_index = 10+1; 133620985164SVishal Verma spa->address = t->dcr_dma[4]; 133720985164SVishal Verma spa->length = DCR_SIZE; 133820985164SVishal Verma 133920985164SVishal Verma /* 134020985164SVishal Verma * spa11 (single-dimm interleave for hotplug, note storage 134120985164SVishal Verma * does not actually alias the related block-data-window 134220985164SVishal Verma * regions) 134320985164SVishal Verma */ 134420985164SVishal Verma spa = nfit_buf + offset + sizeof(*spa); 134520985164SVishal Verma spa->header.type = ACPI_NFIT_TYPE_SYSTEM_ADDRESS; 134620985164SVishal Verma spa->header.length = sizeof(*spa); 134720985164SVishal Verma memcpy(spa->range_guid, to_nfit_uuid(NFIT_SPA_PM), 16); 134820985164SVishal Verma spa->range_index = 11+1; 134920985164SVishal Verma spa->address = t->spa_set_dma[2]; 135020985164SVishal Verma spa->length = SPA0_SIZE; 135120985164SVishal Verma 135220985164SVishal Verma /* spa12 (bdw for dcr4) dimm4 */ 135320985164SVishal Verma spa = nfit_buf + offset + sizeof(*spa) * 2; 135420985164SVishal Verma spa->header.type = ACPI_NFIT_TYPE_SYSTEM_ADDRESS; 135520985164SVishal Verma spa->header.length = sizeof(*spa); 135620985164SVishal Verma memcpy(spa->range_guid, to_nfit_uuid(NFIT_SPA_BDW), 16); 135720985164SVishal Verma spa->range_index = 12+1; 135820985164SVishal Verma spa->address = t->dimm_dma[4]; 135920985164SVishal Verma spa->length = DIMM_SIZE; 136020985164SVishal Verma 136120985164SVishal Verma offset = offset + sizeof(*spa) * 3; 136220985164SVishal Verma /* mem-region14 (spa/dcr4, dimm4) */ 136320985164SVishal Verma memdev = nfit_buf + offset; 136420985164SVishal Verma memdev->header.type = ACPI_NFIT_TYPE_MEMORY_MAP; 136520985164SVishal Verma memdev->header.length = sizeof(*memdev); 136620985164SVishal Verma memdev->device_handle = handle[4]; 136720985164SVishal Verma memdev->physical_id = 4; 136820985164SVishal Verma memdev->region_id = 0; 136920985164SVishal Verma memdev->range_index = 10+1; 13703b87356fSDan Williams memdev->region_index = 8+1; 137120985164SVishal Verma memdev->region_size = 0; 137220985164SVishal Verma memdev->region_offset = 0; 137320985164SVishal Verma memdev->address = 0; 137420985164SVishal Verma memdev->interleave_index = 0; 137520985164SVishal Verma memdev->interleave_ways = 1; 137620985164SVishal Verma 137720985164SVishal Verma /* mem-region15 (spa0, dimm4) */ 137820985164SVishal Verma memdev = nfit_buf + offset + 137920985164SVishal Verma sizeof(struct acpi_nfit_memory_map); 138020985164SVishal Verma memdev->header.type = ACPI_NFIT_TYPE_MEMORY_MAP; 138120985164SVishal Verma memdev->header.length = sizeof(*memdev); 138220985164SVishal Verma memdev->device_handle = handle[4]; 138320985164SVishal Verma memdev->physical_id = 4; 138420985164SVishal Verma memdev->region_id = 0; 138520985164SVishal Verma memdev->range_index = 11+1; 13863b87356fSDan Williams memdev->region_index = 9+1; 138720985164SVishal Verma memdev->region_size = SPA0_SIZE; 1388df06a2d5SDan Williams memdev->region_offset = (1ULL << 48); 138920985164SVishal Verma memdev->address = 0; 139020985164SVishal Verma memdev->interleave_index = 0; 139120985164SVishal Verma memdev->interleave_ways = 1; 1392ac40b675SDan Williams memdev->flags = ACPI_NFIT_MEM_HEALTH_ENABLED; 139320985164SVishal Verma 13943b87356fSDan Williams /* mem-region16 (spa/bdw4, dimm4) */ 139520985164SVishal Verma memdev = nfit_buf + offset + 139620985164SVishal Verma sizeof(struct acpi_nfit_memory_map) * 2; 139720985164SVishal Verma memdev->header.type = ACPI_NFIT_TYPE_MEMORY_MAP; 139820985164SVishal Verma memdev->header.length = sizeof(*memdev); 139920985164SVishal Verma memdev->device_handle = handle[4]; 140020985164SVishal Verma memdev->physical_id = 4; 140120985164SVishal Verma memdev->region_id = 0; 140220985164SVishal Verma memdev->range_index = 12+1; 14033b87356fSDan Williams memdev->region_index = 8+1; 140420985164SVishal Verma memdev->region_size = 0; 140520985164SVishal Verma memdev->region_offset = 0; 140620985164SVishal Verma memdev->address = 0; 140720985164SVishal Verma memdev->interleave_index = 0; 140820985164SVishal Verma memdev->interleave_ways = 1; 140920985164SVishal Verma 141020985164SVishal Verma offset = offset + sizeof(struct acpi_nfit_memory_map) * 3; 141120985164SVishal Verma /* flush3 (dimm4) */ 141220985164SVishal Verma flush = nfit_buf + offset; 141320985164SVishal Verma flush->header.type = ACPI_NFIT_TYPE_FLUSH_ADDRESS; 141485d3fa02SDan Williams flush->header.length = flush_hint_size; 141520985164SVishal Verma flush->device_handle = handle[4]; 141685d3fa02SDan Williams flush->hint_count = NUM_HINTS; 141785d3fa02SDan Williams for (i = 0; i < NUM_HINTS; i++) 141885d3fa02SDan Williams flush->hint_address[i] = t->flush_dma[4] 141985d3fa02SDan Williams + i * sizeof(u64); 142020985164SVishal Verma } 142120985164SVishal Verma 1422f471f1a7SDan Williams post_ars_status(&t->ars_state, t->spa_set_dma[0], SPA0_SIZE); 1423f471f1a7SDan Williams 14246bc75619SDan Williams acpi_desc = &t->acpi_desc; 1425e3654ecaSDan Williams set_bit(ND_CMD_GET_CONFIG_SIZE, &acpi_desc->dimm_cmd_force_en); 1426e3654ecaSDan Williams set_bit(ND_CMD_GET_CONFIG_DATA, &acpi_desc->dimm_cmd_force_en); 1427e3654ecaSDan Williams set_bit(ND_CMD_SET_CONFIG_DATA, &acpi_desc->dimm_cmd_force_en); 14281f716d05SDan Williams set_bit(ND_CMD_SMART, &acpi_desc->dimm_cmd_force_en); 1429e3654ecaSDan Williams set_bit(ND_CMD_ARS_CAP, &acpi_desc->bus_cmd_force_en); 1430e3654ecaSDan Williams set_bit(ND_CMD_ARS_START, &acpi_desc->bus_cmd_force_en); 1431e3654ecaSDan Williams set_bit(ND_CMD_ARS_STATUS, &acpi_desc->bus_cmd_force_en); 1432e3654ecaSDan Williams set_bit(ND_CMD_CLEAR_ERROR, &acpi_desc->bus_cmd_force_en); 14331f716d05SDan Williams set_bit(ND_CMD_SMART_THRESHOLD, &acpi_desc->dimm_cmd_force_en); 14346bc75619SDan Williams } 14356bc75619SDan Williams 14366bc75619SDan Williams static void nfit_test1_setup(struct nfit_test *t) 14376bc75619SDan Williams { 14386b577c9dSLinda Knippers size_t offset; 14396bc75619SDan Williams void *nfit_buf = t->nfit_buf; 14406bc75619SDan Williams struct acpi_nfit_memory_map *memdev; 14416bc75619SDan Williams struct acpi_nfit_control_region *dcr; 14426bc75619SDan Williams struct acpi_nfit_system_address *spa; 1443d26f73f0SDan Williams struct acpi_nfit_desc *acpi_desc; 14446bc75619SDan Williams 14456b577c9dSLinda Knippers offset = 0; 14466bc75619SDan Williams /* spa0 (flat range with no bdw aliasing) */ 14476bc75619SDan Williams spa = nfit_buf + offset; 14486bc75619SDan Williams spa->header.type = ACPI_NFIT_TYPE_SYSTEM_ADDRESS; 14496bc75619SDan Williams spa->header.length = sizeof(*spa); 14506bc75619SDan Williams memcpy(spa->range_guid, to_nfit_uuid(NFIT_SPA_PM), 16); 14516bc75619SDan Williams spa->range_index = 0+1; 14526bc75619SDan Williams spa->address = t->spa_set_dma[0]; 14536bc75619SDan Williams spa->length = SPA2_SIZE; 14546bc75619SDan Williams 14557bfe97c7SDan Williams /* virtual cd region */ 14567bfe97c7SDan Williams spa = nfit_buf + sizeof(*spa); 14577bfe97c7SDan Williams spa->header.type = ACPI_NFIT_TYPE_SYSTEM_ADDRESS; 14587bfe97c7SDan Williams spa->header.length = sizeof(*spa); 14597bfe97c7SDan Williams memcpy(spa->range_guid, to_nfit_uuid(NFIT_SPA_VCD), 16); 14607bfe97c7SDan Williams spa->range_index = 0; 14617bfe97c7SDan Williams spa->address = t->spa_set_dma[1]; 14627bfe97c7SDan Williams spa->length = SPA_VCD_SIZE; 14637bfe97c7SDan Williams 14647bfe97c7SDan Williams offset += sizeof(*spa) * 2; 14656bc75619SDan Williams /* mem-region0 (spa0, dimm0) */ 14666bc75619SDan Williams memdev = nfit_buf + offset; 14676bc75619SDan Williams memdev->header.type = ACPI_NFIT_TYPE_MEMORY_MAP; 14686bc75619SDan Williams memdev->header.length = sizeof(*memdev); 1469dafb1048SDan Williams memdev->device_handle = handle[5]; 14706bc75619SDan Williams memdev->physical_id = 0; 14716bc75619SDan Williams memdev->region_id = 0; 14726bc75619SDan Williams memdev->range_index = 0+1; 14736bc75619SDan Williams memdev->region_index = 0+1; 14746bc75619SDan Williams memdev->region_size = SPA2_SIZE; 14756bc75619SDan Williams memdev->region_offset = 0; 14766bc75619SDan Williams memdev->address = 0; 14776bc75619SDan Williams memdev->interleave_index = 0; 14786bc75619SDan Williams memdev->interleave_ways = 1; 147958138820SDan Williams memdev->flags = ACPI_NFIT_MEM_SAVE_FAILED | ACPI_NFIT_MEM_RESTORE_FAILED 148058138820SDan Williams | ACPI_NFIT_MEM_FLUSH_FAILED | ACPI_NFIT_MEM_HEALTH_OBSERVED 1481f4295796SDan Williams | ACPI_NFIT_MEM_NOT_ARMED; 14826bc75619SDan Williams 14836bc75619SDan Williams offset += sizeof(*memdev); 14846bc75619SDan Williams /* dcr-descriptor0 */ 14856bc75619SDan Williams dcr = nfit_buf + offset; 14866bc75619SDan Williams dcr->header.type = ACPI_NFIT_TYPE_CONTROL_REGION; 14873b87356fSDan Williams dcr->header.length = offsetof(struct acpi_nfit_control_region, 14883b87356fSDan Williams window_size); 14896bc75619SDan Williams dcr->region_index = 0+1; 14905dc68e55SDan Williams dcr_common_init(dcr); 1491dafb1048SDan Williams dcr->serial_number = ~handle[5]; 1492be26f9aeSDan Williams dcr->code = NFIT_FIC_BYTE; 14936bc75619SDan Williams dcr->windows = 0; 1494d26f73f0SDan Williams 1495ac40b675SDan Williams offset += dcr->header.length; 1496ac40b675SDan Williams memdev = nfit_buf + offset; 1497ac40b675SDan Williams memdev->header.type = ACPI_NFIT_TYPE_MEMORY_MAP; 1498ac40b675SDan Williams memdev->header.length = sizeof(*memdev); 1499ac40b675SDan Williams memdev->device_handle = handle[6]; 1500ac40b675SDan Williams memdev->physical_id = 0; 1501ac40b675SDan Williams memdev->region_id = 0; 1502ac40b675SDan Williams memdev->range_index = 0; 1503ac40b675SDan Williams memdev->region_index = 0+2; 1504ac40b675SDan Williams memdev->region_size = SPA2_SIZE; 1505ac40b675SDan Williams memdev->region_offset = 0; 1506ac40b675SDan Williams memdev->address = 0; 1507ac40b675SDan Williams memdev->interleave_index = 0; 1508ac40b675SDan Williams memdev->interleave_ways = 1; 1509ac40b675SDan Williams memdev->flags = ACPI_NFIT_MEM_MAP_FAILED; 1510ac40b675SDan Williams 1511ac40b675SDan Williams /* dcr-descriptor1 */ 1512ac40b675SDan Williams offset += sizeof(*memdev); 1513ac40b675SDan Williams dcr = nfit_buf + offset; 1514ac40b675SDan Williams dcr->header.type = ACPI_NFIT_TYPE_CONTROL_REGION; 1515ac40b675SDan Williams dcr->header.length = offsetof(struct acpi_nfit_control_region, 1516ac40b675SDan Williams window_size); 1517ac40b675SDan Williams dcr->region_index = 0+2; 1518ac40b675SDan Williams dcr_common_init(dcr); 1519ac40b675SDan Williams dcr->serial_number = ~handle[6]; 1520ac40b675SDan Williams dcr->code = NFIT_FIC_BYTE; 1521ac40b675SDan Williams dcr->windows = 0; 1522ac40b675SDan Williams 1523f471f1a7SDan Williams post_ars_status(&t->ars_state, t->spa_set_dma[0], SPA2_SIZE); 1524f471f1a7SDan Williams 1525d26f73f0SDan Williams acpi_desc = &t->acpi_desc; 1526e3654ecaSDan Williams set_bit(ND_CMD_ARS_CAP, &acpi_desc->bus_cmd_force_en); 1527e3654ecaSDan Williams set_bit(ND_CMD_ARS_START, &acpi_desc->bus_cmd_force_en); 1528e3654ecaSDan Williams set_bit(ND_CMD_ARS_STATUS, &acpi_desc->bus_cmd_force_en); 1529e3654ecaSDan Williams set_bit(ND_CMD_CLEAR_ERROR, &acpi_desc->bus_cmd_force_en); 1530dafb1048SDan Williams set_bit(ND_CMD_GET_CONFIG_SIZE, &acpi_desc->dimm_cmd_force_en); 1531dafb1048SDan Williams set_bit(ND_CMD_GET_CONFIG_DATA, &acpi_desc->dimm_cmd_force_en); 1532dafb1048SDan Williams set_bit(ND_CMD_SET_CONFIG_DATA, &acpi_desc->dimm_cmd_force_en); 15336bc75619SDan Williams } 15346bc75619SDan Williams 15356bc75619SDan Williams static int nfit_test_blk_do_io(struct nd_blk_region *ndbr, resource_size_t dpa, 15366bc75619SDan Williams void *iobuf, u64 len, int rw) 15376bc75619SDan Williams { 15386bc75619SDan Williams struct nfit_blk *nfit_blk = ndbr->blk_provider_data; 15396bc75619SDan Williams struct nfit_blk_mmio *mmio = &nfit_blk->mmio[BDW]; 15406bc75619SDan Williams struct nd_region *nd_region = &ndbr->nd_region; 15416bc75619SDan Williams unsigned int lane; 15426bc75619SDan Williams 15436bc75619SDan Williams lane = nd_region_acquire_lane(nd_region); 15446bc75619SDan Williams if (rw) 154567a3e8feSRoss Zwisler memcpy(mmio->addr.base + dpa, iobuf, len); 154667a3e8feSRoss Zwisler else { 154767a3e8feSRoss Zwisler memcpy(iobuf, mmio->addr.base + dpa, len); 154867a3e8feSRoss Zwisler 154967a3e8feSRoss Zwisler /* give us some some coverage of the mmio_flush_range() API */ 155067a3e8feSRoss Zwisler mmio_flush_range(mmio->addr.base + dpa, len); 155167a3e8feSRoss Zwisler } 15526bc75619SDan Williams nd_region_release_lane(nd_region, lane); 15536bc75619SDan Williams 15546bc75619SDan Williams return 0; 15556bc75619SDan Williams } 15566bc75619SDan Williams 1557a7de92daSDan Williams static unsigned long nfit_ctl_handle; 1558a7de92daSDan Williams 1559a7de92daSDan Williams union acpi_object *result; 1560a7de92daSDan Williams 1561a7de92daSDan Williams static union acpi_object *nfit_test_evaluate_dsm(acpi_handle handle, 156294116f81SAndy Shevchenko const guid_t *guid, u64 rev, u64 func, union acpi_object *argv4) 1563a7de92daSDan Williams { 1564a7de92daSDan Williams if (handle != &nfit_ctl_handle) 1565a7de92daSDan Williams return ERR_PTR(-ENXIO); 1566a7de92daSDan Williams 1567a7de92daSDan Williams return result; 1568a7de92daSDan Williams } 1569a7de92daSDan Williams 1570a7de92daSDan Williams static int setup_result(void *buf, size_t size) 1571a7de92daSDan Williams { 1572a7de92daSDan Williams result = kmalloc(sizeof(union acpi_object) + size, GFP_KERNEL); 1573a7de92daSDan Williams if (!result) 1574a7de92daSDan Williams return -ENOMEM; 1575a7de92daSDan Williams result->package.type = ACPI_TYPE_BUFFER, 1576a7de92daSDan Williams result->buffer.pointer = (void *) (result + 1); 1577a7de92daSDan Williams result->buffer.length = size; 1578a7de92daSDan Williams memcpy(result->buffer.pointer, buf, size); 1579a7de92daSDan Williams memset(buf, 0, size); 1580a7de92daSDan Williams return 0; 1581a7de92daSDan Williams } 1582a7de92daSDan Williams 1583a7de92daSDan Williams static int nfit_ctl_test(struct device *dev) 1584a7de92daSDan Williams { 1585a7de92daSDan Williams int rc, cmd_rc; 1586a7de92daSDan Williams struct nvdimm *nvdimm; 1587a7de92daSDan Williams struct acpi_device *adev; 1588a7de92daSDan Williams struct nfit_mem *nfit_mem; 1589a7de92daSDan Williams struct nd_ars_record *record; 1590a7de92daSDan Williams struct acpi_nfit_desc *acpi_desc; 1591a7de92daSDan Williams const u64 test_val = 0x0123456789abcdefULL; 1592a7de92daSDan Williams unsigned long mask, cmd_size, offset; 1593a7de92daSDan Williams union { 1594a7de92daSDan Williams struct nd_cmd_get_config_size cfg_size; 1595a7de92daSDan Williams struct nd_cmd_ars_status ars_stat; 1596a7de92daSDan Williams struct nd_cmd_ars_cap ars_cap; 1597a7de92daSDan Williams char buf[sizeof(struct nd_cmd_ars_status) 1598a7de92daSDan Williams + sizeof(struct nd_ars_record)]; 1599a7de92daSDan Williams } cmds; 1600a7de92daSDan Williams 1601a7de92daSDan Williams adev = devm_kzalloc(dev, sizeof(*adev), GFP_KERNEL); 1602a7de92daSDan Williams if (!adev) 1603a7de92daSDan Williams return -ENOMEM; 1604a7de92daSDan Williams *adev = (struct acpi_device) { 1605a7de92daSDan Williams .handle = &nfit_ctl_handle, 1606a7de92daSDan Williams .dev = { 1607a7de92daSDan Williams .init_name = "test-adev", 1608a7de92daSDan Williams }, 1609a7de92daSDan Williams }; 1610a7de92daSDan Williams 1611a7de92daSDan Williams acpi_desc = devm_kzalloc(dev, sizeof(*acpi_desc), GFP_KERNEL); 1612a7de92daSDan Williams if (!acpi_desc) 1613a7de92daSDan Williams return -ENOMEM; 1614a7de92daSDan Williams *acpi_desc = (struct acpi_nfit_desc) { 1615a7de92daSDan Williams .nd_desc = { 1616a7de92daSDan Williams .cmd_mask = 1UL << ND_CMD_ARS_CAP 1617a7de92daSDan Williams | 1UL << ND_CMD_ARS_START 1618a7de92daSDan Williams | 1UL << ND_CMD_ARS_STATUS 1619a7de92daSDan Williams | 1UL << ND_CMD_CLEAR_ERROR, 1620a7de92daSDan Williams .module = THIS_MODULE, 1621a7de92daSDan Williams .provider_name = "ACPI.NFIT", 1622a7de92daSDan Williams .ndctl = acpi_nfit_ctl, 1623a7de92daSDan Williams }, 1624a7de92daSDan Williams .dev = &adev->dev, 1625a7de92daSDan Williams }; 1626a7de92daSDan Williams 1627a7de92daSDan Williams nfit_mem = devm_kzalloc(dev, sizeof(*nfit_mem), GFP_KERNEL); 1628a7de92daSDan Williams if (!nfit_mem) 1629a7de92daSDan Williams return -ENOMEM; 1630a7de92daSDan Williams 1631a7de92daSDan Williams mask = 1UL << ND_CMD_SMART | 1UL << ND_CMD_SMART_THRESHOLD 1632a7de92daSDan Williams | 1UL << ND_CMD_DIMM_FLAGS | 1UL << ND_CMD_GET_CONFIG_SIZE 1633a7de92daSDan Williams | 1UL << ND_CMD_GET_CONFIG_DATA | 1UL << ND_CMD_SET_CONFIG_DATA 1634a7de92daSDan Williams | 1UL << ND_CMD_VENDOR; 1635a7de92daSDan Williams *nfit_mem = (struct nfit_mem) { 1636a7de92daSDan Williams .adev = adev, 1637a7de92daSDan Williams .family = NVDIMM_FAMILY_INTEL, 1638a7de92daSDan Williams .dsm_mask = mask, 1639a7de92daSDan Williams }; 1640a7de92daSDan Williams 1641a7de92daSDan Williams nvdimm = devm_kzalloc(dev, sizeof(*nvdimm), GFP_KERNEL); 1642a7de92daSDan Williams if (!nvdimm) 1643a7de92daSDan Williams return -ENOMEM; 1644a7de92daSDan Williams *nvdimm = (struct nvdimm) { 1645a7de92daSDan Williams .provider_data = nfit_mem, 1646a7de92daSDan Williams .cmd_mask = mask, 1647a7de92daSDan Williams .dev = { 1648a7de92daSDan Williams .init_name = "test-dimm", 1649a7de92daSDan Williams }, 1650a7de92daSDan Williams }; 1651a7de92daSDan Williams 1652a7de92daSDan Williams 1653a7de92daSDan Williams /* basic checkout of a typical 'get config size' command */ 1654a7de92daSDan Williams cmd_size = sizeof(cmds.cfg_size); 1655a7de92daSDan Williams cmds.cfg_size = (struct nd_cmd_get_config_size) { 1656a7de92daSDan Williams .status = 0, 1657a7de92daSDan Williams .config_size = SZ_128K, 1658a7de92daSDan Williams .max_xfer = SZ_4K, 1659a7de92daSDan Williams }; 1660a7de92daSDan Williams rc = setup_result(cmds.buf, cmd_size); 1661a7de92daSDan Williams if (rc) 1662a7de92daSDan Williams return rc; 1663a7de92daSDan Williams rc = acpi_nfit_ctl(&acpi_desc->nd_desc, nvdimm, ND_CMD_GET_CONFIG_SIZE, 1664a7de92daSDan Williams cmds.buf, cmd_size, &cmd_rc); 1665a7de92daSDan Williams 1666a7de92daSDan Williams if (rc < 0 || cmd_rc || cmds.cfg_size.status != 0 1667a7de92daSDan Williams || cmds.cfg_size.config_size != SZ_128K 1668a7de92daSDan Williams || cmds.cfg_size.max_xfer != SZ_4K) { 1669a7de92daSDan Williams dev_dbg(dev, "%s: failed at: %d rc: %d cmd_rc: %d\n", 1670a7de92daSDan Williams __func__, __LINE__, rc, cmd_rc); 1671a7de92daSDan Williams return -EIO; 1672a7de92daSDan Williams } 1673a7de92daSDan Williams 1674a7de92daSDan Williams 1675a7de92daSDan Williams /* test ars_status with zero output */ 1676a7de92daSDan Williams cmd_size = offsetof(struct nd_cmd_ars_status, address); 1677a7de92daSDan Williams cmds.ars_stat = (struct nd_cmd_ars_status) { 1678a7de92daSDan Williams .out_length = 0, 1679a7de92daSDan Williams }; 1680a7de92daSDan Williams rc = setup_result(cmds.buf, cmd_size); 1681a7de92daSDan Williams if (rc) 1682a7de92daSDan Williams return rc; 1683a7de92daSDan Williams rc = acpi_nfit_ctl(&acpi_desc->nd_desc, NULL, ND_CMD_ARS_STATUS, 1684a7de92daSDan Williams cmds.buf, cmd_size, &cmd_rc); 1685a7de92daSDan Williams 1686a7de92daSDan Williams if (rc < 0 || cmd_rc) { 1687a7de92daSDan Williams dev_dbg(dev, "%s: failed at: %d rc: %d cmd_rc: %d\n", 1688a7de92daSDan Williams __func__, __LINE__, rc, cmd_rc); 1689a7de92daSDan Williams return -EIO; 1690a7de92daSDan Williams } 1691a7de92daSDan Williams 1692a7de92daSDan Williams 1693a7de92daSDan Williams /* test ars_cap with benign extended status */ 1694a7de92daSDan Williams cmd_size = sizeof(cmds.ars_cap); 1695a7de92daSDan Williams cmds.ars_cap = (struct nd_cmd_ars_cap) { 1696a7de92daSDan Williams .status = ND_ARS_PERSISTENT << 16, 1697a7de92daSDan Williams }; 1698a7de92daSDan Williams offset = offsetof(struct nd_cmd_ars_cap, status); 1699a7de92daSDan Williams rc = setup_result(cmds.buf + offset, cmd_size - offset); 1700a7de92daSDan Williams if (rc) 1701a7de92daSDan Williams return rc; 1702a7de92daSDan Williams rc = acpi_nfit_ctl(&acpi_desc->nd_desc, NULL, ND_CMD_ARS_CAP, 1703a7de92daSDan Williams cmds.buf, cmd_size, &cmd_rc); 1704a7de92daSDan Williams 1705a7de92daSDan Williams if (rc < 0 || cmd_rc) { 1706a7de92daSDan Williams dev_dbg(dev, "%s: failed at: %d rc: %d cmd_rc: %d\n", 1707a7de92daSDan Williams __func__, __LINE__, rc, cmd_rc); 1708a7de92daSDan Williams return -EIO; 1709a7de92daSDan Williams } 1710a7de92daSDan Williams 1711a7de92daSDan Williams 1712a7de92daSDan Williams /* test ars_status with 'status' trimmed from 'out_length' */ 1713a7de92daSDan Williams cmd_size = sizeof(cmds.ars_stat) + sizeof(struct nd_ars_record); 1714a7de92daSDan Williams cmds.ars_stat = (struct nd_cmd_ars_status) { 1715a7de92daSDan Williams .out_length = cmd_size - 4, 1716a7de92daSDan Williams }; 1717a7de92daSDan Williams record = &cmds.ars_stat.records[0]; 1718a7de92daSDan Williams *record = (struct nd_ars_record) { 1719a7de92daSDan Williams .length = test_val, 1720a7de92daSDan Williams }; 1721a7de92daSDan Williams rc = setup_result(cmds.buf, cmd_size); 1722a7de92daSDan Williams if (rc) 1723a7de92daSDan Williams return rc; 1724a7de92daSDan Williams rc = acpi_nfit_ctl(&acpi_desc->nd_desc, NULL, ND_CMD_ARS_STATUS, 1725a7de92daSDan Williams cmds.buf, cmd_size, &cmd_rc); 1726a7de92daSDan Williams 1727a7de92daSDan Williams if (rc < 0 || cmd_rc || record->length != test_val) { 1728a7de92daSDan Williams dev_dbg(dev, "%s: failed at: %d rc: %d cmd_rc: %d\n", 1729a7de92daSDan Williams __func__, __LINE__, rc, cmd_rc); 1730a7de92daSDan Williams return -EIO; 1731a7de92daSDan Williams } 1732a7de92daSDan Williams 1733a7de92daSDan Williams 1734a7de92daSDan Williams /* test ars_status with 'Output (Size)' including 'status' */ 1735a7de92daSDan Williams cmd_size = sizeof(cmds.ars_stat) + sizeof(struct nd_ars_record); 1736a7de92daSDan Williams cmds.ars_stat = (struct nd_cmd_ars_status) { 1737a7de92daSDan Williams .out_length = cmd_size, 1738a7de92daSDan Williams }; 1739a7de92daSDan Williams record = &cmds.ars_stat.records[0]; 1740a7de92daSDan Williams *record = (struct nd_ars_record) { 1741a7de92daSDan Williams .length = test_val, 1742a7de92daSDan Williams }; 1743a7de92daSDan Williams rc = setup_result(cmds.buf, cmd_size); 1744a7de92daSDan Williams if (rc) 1745a7de92daSDan Williams return rc; 1746a7de92daSDan Williams rc = acpi_nfit_ctl(&acpi_desc->nd_desc, NULL, ND_CMD_ARS_STATUS, 1747a7de92daSDan Williams cmds.buf, cmd_size, &cmd_rc); 1748a7de92daSDan Williams 1749a7de92daSDan Williams if (rc < 0 || cmd_rc || record->length != test_val) { 1750a7de92daSDan Williams dev_dbg(dev, "%s: failed at: %d rc: %d cmd_rc: %d\n", 1751a7de92daSDan Williams __func__, __LINE__, rc, cmd_rc); 1752a7de92daSDan Williams return -EIO; 1753a7de92daSDan Williams } 1754a7de92daSDan Williams 1755a7de92daSDan Williams 1756a7de92daSDan Williams /* test extended status for get_config_size results in failure */ 1757a7de92daSDan Williams cmd_size = sizeof(cmds.cfg_size); 1758a7de92daSDan Williams cmds.cfg_size = (struct nd_cmd_get_config_size) { 1759a7de92daSDan Williams .status = 1 << 16, 1760a7de92daSDan Williams }; 1761a7de92daSDan Williams rc = setup_result(cmds.buf, cmd_size); 1762a7de92daSDan Williams if (rc) 1763a7de92daSDan Williams return rc; 1764a7de92daSDan Williams rc = acpi_nfit_ctl(&acpi_desc->nd_desc, nvdimm, ND_CMD_GET_CONFIG_SIZE, 1765a7de92daSDan Williams cmds.buf, cmd_size, &cmd_rc); 1766a7de92daSDan Williams 1767a7de92daSDan Williams if (rc < 0 || cmd_rc >= 0) { 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 return 0; 1774a7de92daSDan Williams } 1775a7de92daSDan Williams 17766bc75619SDan Williams static int nfit_test_probe(struct platform_device *pdev) 17776bc75619SDan Williams { 17786bc75619SDan Williams struct nvdimm_bus_descriptor *nd_desc; 17796bc75619SDan Williams struct acpi_nfit_desc *acpi_desc; 17806bc75619SDan Williams struct device *dev = &pdev->dev; 17816bc75619SDan Williams struct nfit_test *nfit_test; 1782231bf117SDan Williams struct nfit_mem *nfit_mem; 1783c14a868aSDan Williams union acpi_object *obj; 17846bc75619SDan Williams int rc; 17856bc75619SDan Williams 1786a7de92daSDan Williams if (strcmp(dev_name(&pdev->dev), "nfit_test.0") == 0) { 1787a7de92daSDan Williams rc = nfit_ctl_test(&pdev->dev); 1788a7de92daSDan Williams if (rc) 1789a7de92daSDan Williams return rc; 1790a7de92daSDan Williams } 1791a7de92daSDan Williams 17926bc75619SDan Williams nfit_test = to_nfit_test(&pdev->dev); 17936bc75619SDan Williams 17946bc75619SDan Williams /* common alloc */ 17956bc75619SDan Williams if (nfit_test->num_dcr) { 17966bc75619SDan Williams int num = nfit_test->num_dcr; 17976bc75619SDan Williams 17986bc75619SDan Williams nfit_test->dimm = devm_kcalloc(dev, num, sizeof(void *), 17996bc75619SDan Williams GFP_KERNEL); 18006bc75619SDan Williams nfit_test->dimm_dma = devm_kcalloc(dev, num, sizeof(dma_addr_t), 18016bc75619SDan Williams GFP_KERNEL); 18029d27a87eSDan Williams nfit_test->flush = devm_kcalloc(dev, num, sizeof(void *), 18039d27a87eSDan Williams GFP_KERNEL); 18049d27a87eSDan Williams nfit_test->flush_dma = devm_kcalloc(dev, num, sizeof(dma_addr_t), 18059d27a87eSDan Williams GFP_KERNEL); 18066bc75619SDan Williams nfit_test->label = devm_kcalloc(dev, num, sizeof(void *), 18076bc75619SDan Williams GFP_KERNEL); 18086bc75619SDan Williams nfit_test->label_dma = devm_kcalloc(dev, num, 18096bc75619SDan Williams sizeof(dma_addr_t), GFP_KERNEL); 18106bc75619SDan Williams nfit_test->dcr = devm_kcalloc(dev, num, 18116bc75619SDan Williams sizeof(struct nfit_test_dcr *), GFP_KERNEL); 18126bc75619SDan Williams nfit_test->dcr_dma = devm_kcalloc(dev, num, 18136bc75619SDan Williams sizeof(dma_addr_t), GFP_KERNEL); 18146bc75619SDan Williams if (nfit_test->dimm && nfit_test->dimm_dma && nfit_test->label 18156bc75619SDan Williams && nfit_test->label_dma && nfit_test->dcr 18169d27a87eSDan Williams && nfit_test->dcr_dma && nfit_test->flush 18179d27a87eSDan Williams && nfit_test->flush_dma) 18186bc75619SDan Williams /* pass */; 18196bc75619SDan Williams else 18206bc75619SDan Williams return -ENOMEM; 18216bc75619SDan Williams } 18226bc75619SDan Williams 18236bc75619SDan Williams if (nfit_test->num_pm) { 18246bc75619SDan Williams int num = nfit_test->num_pm; 18256bc75619SDan Williams 18266bc75619SDan Williams nfit_test->spa_set = devm_kcalloc(dev, num, sizeof(void *), 18276bc75619SDan Williams GFP_KERNEL); 18286bc75619SDan Williams nfit_test->spa_set_dma = devm_kcalloc(dev, num, 18296bc75619SDan Williams sizeof(dma_addr_t), GFP_KERNEL); 18306bc75619SDan Williams if (nfit_test->spa_set && nfit_test->spa_set_dma) 18316bc75619SDan Williams /* pass */; 18326bc75619SDan Williams else 18336bc75619SDan Williams return -ENOMEM; 18346bc75619SDan Williams } 18356bc75619SDan Williams 18366bc75619SDan Williams /* per-nfit specific alloc */ 18376bc75619SDan Williams if (nfit_test->alloc(nfit_test)) 18386bc75619SDan Williams return -ENOMEM; 18396bc75619SDan Williams 18406bc75619SDan Williams nfit_test->setup(nfit_test); 18416bc75619SDan Williams acpi_desc = &nfit_test->acpi_desc; 1842a61fe6f7SDan Williams acpi_nfit_desc_init(acpi_desc, &pdev->dev); 18436bc75619SDan Williams acpi_desc->blk_do_io = nfit_test_blk_do_io; 18446bc75619SDan Williams nd_desc = &acpi_desc->nd_desc; 1845a61fe6f7SDan Williams nd_desc->provider_name = NULL; 1846bc9775d8SDan Williams nd_desc->module = THIS_MODULE; 1847a61fe6f7SDan Williams nd_desc->ndctl = nfit_test_ctl; 18486bc75619SDan Williams 1849e7a11b44SDan Williams rc = acpi_nfit_init(acpi_desc, nfit_test->nfit_buf, 1850e7a11b44SDan Williams nfit_test->nfit_size); 185158cd71b4SDan Williams if (rc) 185220985164SVishal Verma return rc; 185320985164SVishal Verma 1854fbabd829SDan Williams rc = devm_add_action_or_reset(&pdev->dev, acpi_nfit_shutdown, acpi_desc); 1855fbabd829SDan Williams if (rc) 1856fbabd829SDan Williams return rc; 1857fbabd829SDan Williams 185820985164SVishal Verma if (nfit_test->setup != nfit_test0_setup) 185920985164SVishal Verma return 0; 186020985164SVishal Verma 186120985164SVishal Verma nfit_test->setup_hotplug = 1; 186220985164SVishal Verma nfit_test->setup(nfit_test); 186320985164SVishal Verma 1864c14a868aSDan Williams obj = kzalloc(sizeof(*obj), GFP_KERNEL); 1865c14a868aSDan Williams if (!obj) 1866c14a868aSDan Williams return -ENOMEM; 1867c14a868aSDan Williams obj->type = ACPI_TYPE_BUFFER; 1868c14a868aSDan Williams obj->buffer.length = nfit_test->nfit_size; 1869c14a868aSDan Williams obj->buffer.pointer = nfit_test->nfit_buf; 1870c14a868aSDan Williams *(nfit_test->_fit) = obj; 1871c14a868aSDan Williams __acpi_nfit_notify(&pdev->dev, nfit_test, 0x80); 1872231bf117SDan Williams 1873231bf117SDan Williams /* associate dimm devices with nfit_mem data for notification testing */ 1874231bf117SDan Williams mutex_lock(&acpi_desc->init_mutex); 1875231bf117SDan Williams list_for_each_entry(nfit_mem, &acpi_desc->dimms, list) { 1876231bf117SDan Williams u32 nfit_handle = __to_nfit_memdev(nfit_mem)->device_handle; 1877231bf117SDan Williams int i; 1878231bf117SDan Williams 1879231bf117SDan Williams for (i = 0; i < NUM_DCR; i++) 1880231bf117SDan Williams if (nfit_handle == handle[i]) 1881231bf117SDan Williams dev_set_drvdata(nfit_test->dimm_dev[i], 1882231bf117SDan Williams nfit_mem); 1883231bf117SDan Williams } 1884231bf117SDan Williams mutex_unlock(&acpi_desc->init_mutex); 18856bc75619SDan Williams 18866bc75619SDan Williams return 0; 18876bc75619SDan Williams } 18886bc75619SDan Williams 18896bc75619SDan Williams static int nfit_test_remove(struct platform_device *pdev) 18906bc75619SDan Williams { 18916bc75619SDan Williams return 0; 18926bc75619SDan Williams } 18936bc75619SDan Williams 18946bc75619SDan Williams static void nfit_test_release(struct device *dev) 18956bc75619SDan Williams { 18966bc75619SDan Williams struct nfit_test *nfit_test = to_nfit_test(dev); 18976bc75619SDan Williams 18986bc75619SDan Williams kfree(nfit_test); 18996bc75619SDan Williams } 19006bc75619SDan Williams 19016bc75619SDan Williams static const struct platform_device_id nfit_test_id[] = { 19026bc75619SDan Williams { KBUILD_MODNAME }, 19036bc75619SDan Williams { }, 19046bc75619SDan Williams }; 19056bc75619SDan Williams 19066bc75619SDan Williams static struct platform_driver nfit_test_driver = { 19076bc75619SDan Williams .probe = nfit_test_probe, 19086bc75619SDan Williams .remove = nfit_test_remove, 19096bc75619SDan Williams .driver = { 19106bc75619SDan Williams .name = KBUILD_MODNAME, 19116bc75619SDan Williams }, 19126bc75619SDan Williams .id_table = nfit_test_id, 19136bc75619SDan Williams }; 19146bc75619SDan Williams 19156bc75619SDan Williams static __init int nfit_test_init(void) 19166bc75619SDan Williams { 19176bc75619SDan Williams int rc, i; 19186bc75619SDan Williams 1919a7de92daSDan Williams nfit_test_setup(nfit_test_lookup, nfit_test_evaluate_dsm); 1920231bf117SDan Williams 1921a7de92daSDan Williams nfit_test_dimm = class_create(THIS_MODULE, "nfit_test_dimm"); 1922a7de92daSDan Williams if (IS_ERR(nfit_test_dimm)) { 1923a7de92daSDan Williams rc = PTR_ERR(nfit_test_dimm); 1924a7de92daSDan Williams goto err_register; 1925a7de92daSDan Williams } 19266bc75619SDan Williams 19276bc75619SDan Williams for (i = 0; i < NUM_NFITS; i++) { 19286bc75619SDan Williams struct nfit_test *nfit_test; 19296bc75619SDan Williams struct platform_device *pdev; 19306bc75619SDan Williams 19316bc75619SDan Williams nfit_test = kzalloc(sizeof(*nfit_test), GFP_KERNEL); 19326bc75619SDan Williams if (!nfit_test) { 19336bc75619SDan Williams rc = -ENOMEM; 19346bc75619SDan Williams goto err_register; 19356bc75619SDan Williams } 19366bc75619SDan Williams INIT_LIST_HEAD(&nfit_test->resources); 19376bc75619SDan Williams switch (i) { 19386bc75619SDan Williams case 0: 19396bc75619SDan Williams nfit_test->num_pm = NUM_PM; 1940dafb1048SDan Williams nfit_test->dcr_idx = 0; 19416bc75619SDan Williams nfit_test->num_dcr = NUM_DCR; 19426bc75619SDan Williams nfit_test->alloc = nfit_test0_alloc; 19436bc75619SDan Williams nfit_test->setup = nfit_test0_setup; 19446bc75619SDan Williams break; 19456bc75619SDan Williams case 1: 1946*a117699cSYasunori Goto nfit_test->num_pm = 2; 1947dafb1048SDan Williams nfit_test->dcr_idx = NUM_DCR; 1948ac40b675SDan Williams nfit_test->num_dcr = 2; 19496bc75619SDan Williams nfit_test->alloc = nfit_test1_alloc; 19506bc75619SDan Williams nfit_test->setup = nfit_test1_setup; 19516bc75619SDan Williams break; 19526bc75619SDan Williams default: 19536bc75619SDan Williams rc = -EINVAL; 19546bc75619SDan Williams goto err_register; 19556bc75619SDan Williams } 19566bc75619SDan Williams pdev = &nfit_test->pdev; 19576bc75619SDan Williams pdev->name = KBUILD_MODNAME; 19586bc75619SDan Williams pdev->id = i; 19596bc75619SDan Williams pdev->dev.release = nfit_test_release; 19606bc75619SDan Williams rc = platform_device_register(pdev); 19616bc75619SDan Williams if (rc) { 19626bc75619SDan Williams put_device(&pdev->dev); 19636bc75619SDan Williams goto err_register; 19646bc75619SDan Williams } 19658b06b884SDan Williams get_device(&pdev->dev); 19666bc75619SDan Williams 19676bc75619SDan Williams rc = dma_coerce_mask_and_coherent(&pdev->dev, DMA_BIT_MASK(64)); 19686bc75619SDan Williams if (rc) 19696bc75619SDan Williams goto err_register; 19706bc75619SDan Williams 19716bc75619SDan Williams instances[i] = nfit_test; 19726bc75619SDan Williams } 19736bc75619SDan Williams 19746bc75619SDan Williams rc = platform_driver_register(&nfit_test_driver); 19756bc75619SDan Williams if (rc) 19766bc75619SDan Williams goto err_register; 19776bc75619SDan Williams return 0; 19786bc75619SDan Williams 19796bc75619SDan Williams err_register: 19806bc75619SDan Williams for (i = 0; i < NUM_NFITS; i++) 19816bc75619SDan Williams if (instances[i]) 19826bc75619SDan Williams platform_device_unregister(&instances[i]->pdev); 19836bc75619SDan Williams nfit_test_teardown(); 19848b06b884SDan Williams for (i = 0; i < NUM_NFITS; i++) 19858b06b884SDan Williams if (instances[i]) 19868b06b884SDan Williams put_device(&instances[i]->pdev.dev); 19878b06b884SDan Williams 19886bc75619SDan Williams return rc; 19896bc75619SDan Williams } 19906bc75619SDan Williams 19916bc75619SDan Williams static __exit void nfit_test_exit(void) 19926bc75619SDan Williams { 19936bc75619SDan Williams int i; 19946bc75619SDan Williams 19956bc75619SDan Williams for (i = 0; i < NUM_NFITS; i++) 19966bc75619SDan Williams platform_device_unregister(&instances[i]->pdev); 19978b06b884SDan Williams platform_driver_unregister(&nfit_test_driver); 19986bc75619SDan Williams nfit_test_teardown(); 19998b06b884SDan Williams 20008b06b884SDan Williams for (i = 0; i < NUM_NFITS; i++) 20018b06b884SDan Williams put_device(&instances[i]->pdev.dev); 2002231bf117SDan Williams class_destroy(nfit_test_dimm); 20036bc75619SDan Williams } 20046bc75619SDan Williams 20056bc75619SDan Williams module_init(nfit_test_init); 20066bc75619SDan Williams module_exit(nfit_test_exit); 20076bc75619SDan Williams MODULE_LICENSE("GPL v2"); 20086bc75619SDan Williams MODULE_AUTHOR("Intel Corporation"); 2009