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> 266bc75619SDan Williams #include <nfit.h> 276bc75619SDan Williams #include <nd.h> 286bc75619SDan Williams #include "nfit_test.h" 296bc75619SDan Williams 306bc75619SDan Williams /* 316bc75619SDan Williams * Generate an NFIT table to describe the following topology: 326bc75619SDan Williams * 336bc75619SDan Williams * BUS0: Interleaved PMEM regions, and aliasing with BLK regions 346bc75619SDan Williams * 356bc75619SDan Williams * (a) (b) DIMM BLK-REGION 366bc75619SDan Williams * +----------+--------------+----------+---------+ 376bc75619SDan Williams * +------+ | blk2.0 | pm0.0 | blk2.1 | pm1.0 | 0 region2 386bc75619SDan Williams * | imc0 +--+- - - - - region0 - - - -+----------+ + 396bc75619SDan Williams * +--+---+ | blk3.0 | pm0.0 | blk3.1 | pm1.0 | 1 region3 406bc75619SDan Williams * | +----------+--------------v----------v v 416bc75619SDan Williams * +--+---+ | | 426bc75619SDan Williams * | cpu0 | region1 436bc75619SDan Williams * +--+---+ | | 446bc75619SDan Williams * | +-------------------------^----------^ ^ 456bc75619SDan Williams * +--+---+ | blk4.0 | pm1.0 | 2 region4 466bc75619SDan Williams * | imc1 +--+-------------------------+----------+ + 476bc75619SDan Williams * +------+ | blk5.0 | pm1.0 | 3 region5 486bc75619SDan Williams * +-------------------------+----------+-+-------+ 496bc75619SDan Williams * 5020985164SVishal Verma * +--+---+ 5120985164SVishal Verma * | cpu1 | 5220985164SVishal Verma * +--+---+ (Hotplug DIMM) 5320985164SVishal Verma * | +----------------------------------------------+ 5420985164SVishal Verma * +--+---+ | blk6.0/pm7.0 | 4 region6/7 5520985164SVishal Verma * | imc0 +--+----------------------------------------------+ 5620985164SVishal Verma * +------+ 5720985164SVishal Verma * 5820985164SVishal Verma * 596bc75619SDan Williams * *) In this layout we have four dimms and two memory controllers in one 606bc75619SDan Williams * socket. Each unique interface (BLK or PMEM) to DPA space 616bc75619SDan Williams * is identified by a region device with a dynamically assigned id. 626bc75619SDan Williams * 636bc75619SDan Williams * *) The first portion of dimm0 and dimm1 are interleaved as REGION0. 646bc75619SDan Williams * A single PMEM namespace "pm0.0" is created using half of the 656bc75619SDan Williams * REGION0 SPA-range. REGION0 spans dimm0 and dimm1. PMEM namespace 666bc75619SDan Williams * allocate from from the bottom of a region. The unallocated 676bc75619SDan Williams * portion of REGION0 aliases with REGION2 and REGION3. That 686bc75619SDan Williams * unallacted capacity is reclaimed as BLK namespaces ("blk2.0" and 696bc75619SDan Williams * "blk3.0") starting at the base of each DIMM to offset (a) in those 706bc75619SDan Williams * DIMMs. "pm0.0", "blk2.0" and "blk3.0" are free-form readable 716bc75619SDan Williams * names that can be assigned to a namespace. 726bc75619SDan Williams * 736bc75619SDan Williams * *) In the last portion of dimm0 and dimm1 we have an interleaved 746bc75619SDan Williams * SPA range, REGION1, that spans those two dimms as well as dimm2 756bc75619SDan Williams * and dimm3. Some of REGION1 allocated to a PMEM namespace named 766bc75619SDan Williams * "pm1.0" the rest is reclaimed in 4 BLK namespaces (for each 776bc75619SDan Williams * dimm in the interleave set), "blk2.1", "blk3.1", "blk4.0", and 786bc75619SDan Williams * "blk5.0". 796bc75619SDan Williams * 806bc75619SDan Williams * *) The portion of dimm2 and dimm3 that do not participate in the 816bc75619SDan Williams * REGION1 interleaved SPA range (i.e. the DPA address below offset 826bc75619SDan Williams * (b) are also included in the "blk4.0" and "blk5.0" namespaces. 836bc75619SDan Williams * Note, that BLK namespaces need not be contiguous in DPA-space, and 846bc75619SDan Williams * can consume aliased capacity from multiple interleave sets. 856bc75619SDan Williams * 866bc75619SDan Williams * BUS1: Legacy NVDIMM (single contiguous range) 876bc75619SDan Williams * 886bc75619SDan Williams * region2 896bc75619SDan Williams * +---------------------+ 906bc75619SDan Williams * |---------------------| 916bc75619SDan Williams * || pm2.0 || 926bc75619SDan Williams * |---------------------| 936bc75619SDan Williams * +---------------------+ 946bc75619SDan Williams * 956bc75619SDan Williams * *) A NFIT-table may describe a simple system-physical-address range 966bc75619SDan Williams * with no BLK aliasing. This type of region may optionally 976bc75619SDan Williams * reference an NVDIMM. 986bc75619SDan Williams */ 996bc75619SDan Williams enum { 10020985164SVishal Verma NUM_PM = 3, 10120985164SVishal Verma NUM_DCR = 5, 10285d3fa02SDan Williams NUM_HINTS = 8, 1036bc75619SDan Williams NUM_BDW = NUM_DCR, 1046bc75619SDan Williams NUM_SPA = NUM_PM + NUM_DCR + NUM_BDW, 1056bc75619SDan Williams NUM_MEM = NUM_DCR + NUM_BDW + 2 /* spa0 iset */ + 4 /* spa1 iset */, 1066bc75619SDan Williams DIMM_SIZE = SZ_32M, 1076bc75619SDan Williams LABEL_SIZE = SZ_128K, 1087bfe97c7SDan Williams SPA_VCD_SIZE = SZ_4M, 1096bc75619SDan Williams SPA0_SIZE = DIMM_SIZE, 1106bc75619SDan Williams SPA1_SIZE = DIMM_SIZE*2, 1116bc75619SDan Williams SPA2_SIZE = DIMM_SIZE, 1126bc75619SDan Williams BDW_SIZE = 64 << 8, 1136bc75619SDan Williams DCR_SIZE = 12, 1146bc75619SDan Williams NUM_NFITS = 2, /* permit testing multiple NFITs per system */ 1156bc75619SDan Williams }; 1166bc75619SDan Williams 1176bc75619SDan Williams struct nfit_test_dcr { 1186bc75619SDan Williams __le64 bdw_addr; 1196bc75619SDan Williams __le32 bdw_status; 1206bc75619SDan Williams __u8 aperature[BDW_SIZE]; 1216bc75619SDan Williams }; 1226bc75619SDan Williams 1236bc75619SDan Williams #define NFIT_DIMM_HANDLE(node, socket, imc, chan, dimm) \ 1246bc75619SDan Williams (((node & 0xfff) << 16) | ((socket & 0xf) << 12) \ 1256bc75619SDan Williams | ((imc & 0xf) << 8) | ((chan & 0xf) << 4) | (dimm & 0xf)) 1266bc75619SDan Williams 1276bc75619SDan Williams static u32 handle[NUM_DCR] = { 1286bc75619SDan Williams [0] = NFIT_DIMM_HANDLE(0, 0, 0, 0, 0), 1296bc75619SDan Williams [1] = NFIT_DIMM_HANDLE(0, 0, 0, 0, 1), 1306bc75619SDan Williams [2] = NFIT_DIMM_HANDLE(0, 0, 1, 0, 0), 1316bc75619SDan Williams [3] = NFIT_DIMM_HANDLE(0, 0, 1, 0, 1), 13220985164SVishal Verma [4] = NFIT_DIMM_HANDLE(0, 1, 0, 0, 0), 1336bc75619SDan Williams }; 1346bc75619SDan Williams 135*73606afdSDan Williams static unsigned long dimm_fail_cmd_flags[NUM_DCR]; 136*73606afdSDan Williams 1376bc75619SDan Williams struct nfit_test { 1386bc75619SDan Williams struct acpi_nfit_desc acpi_desc; 1396bc75619SDan Williams struct platform_device pdev; 1406bc75619SDan Williams struct list_head resources; 1416bc75619SDan Williams void *nfit_buf; 1426bc75619SDan Williams dma_addr_t nfit_dma; 1436bc75619SDan Williams size_t nfit_size; 1446bc75619SDan Williams int num_dcr; 1456bc75619SDan Williams int num_pm; 1466bc75619SDan Williams void **dimm; 1476bc75619SDan Williams dma_addr_t *dimm_dma; 1489d27a87eSDan Williams void **flush; 1499d27a87eSDan Williams dma_addr_t *flush_dma; 1506bc75619SDan Williams void **label; 1516bc75619SDan Williams dma_addr_t *label_dma; 1526bc75619SDan Williams void **spa_set; 1536bc75619SDan Williams dma_addr_t *spa_set_dma; 1546bc75619SDan Williams struct nfit_test_dcr **dcr; 1556bc75619SDan Williams dma_addr_t *dcr_dma; 1566bc75619SDan Williams int (*alloc)(struct nfit_test *t); 1576bc75619SDan Williams void (*setup)(struct nfit_test *t); 15820985164SVishal Verma int setup_hotplug; 159c14a868aSDan Williams union acpi_object **_fit; 160c14a868aSDan Williams dma_addr_t _fit_dma; 161f471f1a7SDan Williams struct ars_state { 162f471f1a7SDan Williams struct nd_cmd_ars_status *ars_status; 163f471f1a7SDan Williams unsigned long deadline; 164f471f1a7SDan Williams spinlock_t lock; 165f471f1a7SDan Williams } ars_state; 166231bf117SDan Williams struct device *dimm_dev[NUM_DCR]; 1676bc75619SDan Williams }; 1686bc75619SDan Williams 1696bc75619SDan Williams static struct nfit_test *to_nfit_test(struct device *dev) 1706bc75619SDan Williams { 1716bc75619SDan Williams struct platform_device *pdev = to_platform_device(dev); 1726bc75619SDan Williams 1736bc75619SDan Williams return container_of(pdev, struct nfit_test, pdev); 1746bc75619SDan Williams } 1756bc75619SDan Williams 17639c686b8SVishal Verma static int nfit_test_cmd_get_config_size(struct nd_cmd_get_config_size *nd_cmd, 1776bc75619SDan Williams unsigned int buf_len) 1786bc75619SDan Williams { 1796bc75619SDan Williams if (buf_len < sizeof(*nd_cmd)) 1806bc75619SDan Williams return -EINVAL; 18139c686b8SVishal Verma 1826bc75619SDan Williams nd_cmd->status = 0; 1836bc75619SDan Williams nd_cmd->config_size = LABEL_SIZE; 1846bc75619SDan Williams nd_cmd->max_xfer = SZ_4K; 18539c686b8SVishal Verma 18639c686b8SVishal Verma return 0; 1876bc75619SDan Williams } 18839c686b8SVishal Verma 18939c686b8SVishal Verma static int nfit_test_cmd_get_config_data(struct nd_cmd_get_config_data_hdr 19039c686b8SVishal Verma *nd_cmd, unsigned int buf_len, void *label) 19139c686b8SVishal Verma { 1926bc75619SDan Williams unsigned int len, offset = nd_cmd->in_offset; 19339c686b8SVishal Verma int rc; 1946bc75619SDan Williams 1956bc75619SDan Williams if (buf_len < sizeof(*nd_cmd)) 1966bc75619SDan Williams return -EINVAL; 1976bc75619SDan Williams if (offset >= LABEL_SIZE) 1986bc75619SDan Williams return -EINVAL; 1996bc75619SDan Williams if (nd_cmd->in_length + sizeof(*nd_cmd) > buf_len) 2006bc75619SDan Williams return -EINVAL; 2016bc75619SDan Williams 2026bc75619SDan Williams nd_cmd->status = 0; 2036bc75619SDan Williams len = min(nd_cmd->in_length, LABEL_SIZE - offset); 20439c686b8SVishal Verma memcpy(nd_cmd->out_buf, label + offset, len); 2056bc75619SDan Williams rc = buf_len - sizeof(*nd_cmd) - len; 20639c686b8SVishal Verma 20739c686b8SVishal Verma return rc; 2086bc75619SDan Williams } 20939c686b8SVishal Verma 21039c686b8SVishal Verma static int nfit_test_cmd_set_config_data(struct nd_cmd_set_config_hdr *nd_cmd, 21139c686b8SVishal Verma unsigned int buf_len, void *label) 21239c686b8SVishal Verma { 2136bc75619SDan Williams unsigned int len, offset = nd_cmd->in_offset; 2146bc75619SDan Williams u32 *status; 21539c686b8SVishal Verma int rc; 2166bc75619SDan Williams 2176bc75619SDan Williams if (buf_len < sizeof(*nd_cmd)) 2186bc75619SDan Williams return -EINVAL; 2196bc75619SDan Williams if (offset >= LABEL_SIZE) 2206bc75619SDan Williams return -EINVAL; 2216bc75619SDan Williams if (nd_cmd->in_length + sizeof(*nd_cmd) + 4 > buf_len) 2226bc75619SDan Williams return -EINVAL; 2236bc75619SDan Williams 22439c686b8SVishal Verma status = (void *)nd_cmd + nd_cmd->in_length + sizeof(*nd_cmd); 2256bc75619SDan Williams *status = 0; 2266bc75619SDan Williams len = min(nd_cmd->in_length, LABEL_SIZE - offset); 22739c686b8SVishal Verma memcpy(label + offset, nd_cmd->in_buf, len); 2286bc75619SDan Williams rc = buf_len - sizeof(*nd_cmd) - (len + 4); 22939c686b8SVishal Verma 23039c686b8SVishal Verma return rc; 2316bc75619SDan Williams } 23239c686b8SVishal Verma 233747ffe11SDan Williams #define NFIT_TEST_ARS_RECORDS 4 234d4f32367SDan Williams #define NFIT_TEST_CLEAR_ERR_UNIT 256 235747ffe11SDan Williams 23639c686b8SVishal Verma static int nfit_test_cmd_ars_cap(struct nd_cmd_ars_cap *nd_cmd, 23739c686b8SVishal Verma unsigned int buf_len) 23839c686b8SVishal Verma { 23939c686b8SVishal Verma if (buf_len < sizeof(*nd_cmd)) 24039c686b8SVishal Verma return -EINVAL; 24139c686b8SVishal Verma 242747ffe11SDan Williams nd_cmd->max_ars_out = sizeof(struct nd_cmd_ars_status) 243747ffe11SDan Williams + NFIT_TEST_ARS_RECORDS * sizeof(struct nd_ars_record); 24439c686b8SVishal Verma nd_cmd->status = (ND_ARS_PERSISTENT | ND_ARS_VOLATILE) << 16; 245d4f32367SDan Williams nd_cmd->clear_err_unit = NFIT_TEST_CLEAR_ERR_UNIT; 24639c686b8SVishal Verma 24739c686b8SVishal Verma return 0; 24839c686b8SVishal Verma } 24939c686b8SVishal Verma 250f471f1a7SDan Williams /* 251f471f1a7SDan Williams * Initialize the ars_state to return an ars_result 1 second in the future with 252f471f1a7SDan Williams * a 4K error range in the middle of the requested address range. 253f471f1a7SDan Williams */ 254f471f1a7SDan Williams static void post_ars_status(struct ars_state *ars_state, u64 addr, u64 len) 25539c686b8SVishal Verma { 256f471f1a7SDan Williams struct nd_cmd_ars_status *ars_status; 257f471f1a7SDan Williams struct nd_ars_record *ars_record; 258f471f1a7SDan Williams 259f471f1a7SDan Williams ars_state->deadline = jiffies + 1*HZ; 260f471f1a7SDan Williams ars_status = ars_state->ars_status; 261f471f1a7SDan Williams ars_status->status = 0; 262f471f1a7SDan Williams ars_status->out_length = sizeof(struct nd_cmd_ars_status) 263f471f1a7SDan Williams + sizeof(struct nd_ars_record); 264f471f1a7SDan Williams ars_status->address = addr; 265f471f1a7SDan Williams ars_status->length = len; 266f471f1a7SDan Williams ars_status->type = ND_ARS_PERSISTENT; 267f471f1a7SDan Williams ars_status->num_records = 1; 268f471f1a7SDan Williams ars_record = &ars_status->records[0]; 269f471f1a7SDan Williams ars_record->handle = 0; 270f471f1a7SDan Williams ars_record->err_address = addr + len / 2; 271f471f1a7SDan Williams ars_record->length = SZ_4K; 272f471f1a7SDan Williams } 273f471f1a7SDan Williams 274f471f1a7SDan Williams static int nfit_test_cmd_ars_start(struct ars_state *ars_state, 275f471f1a7SDan Williams struct nd_cmd_ars_start *ars_start, unsigned int buf_len, 276f471f1a7SDan Williams int *cmd_rc) 277f471f1a7SDan Williams { 278f471f1a7SDan Williams if (buf_len < sizeof(*ars_start)) 27939c686b8SVishal Verma return -EINVAL; 28039c686b8SVishal Verma 281f471f1a7SDan Williams spin_lock(&ars_state->lock); 282f471f1a7SDan Williams if (time_before(jiffies, ars_state->deadline)) { 283f471f1a7SDan Williams ars_start->status = NFIT_ARS_START_BUSY; 284f471f1a7SDan Williams *cmd_rc = -EBUSY; 285f471f1a7SDan Williams } else { 286f471f1a7SDan Williams ars_start->status = 0; 287f471f1a7SDan Williams ars_start->scrub_time = 1; 288f471f1a7SDan Williams post_ars_status(ars_state, ars_start->address, 289f471f1a7SDan Williams ars_start->length); 290f471f1a7SDan Williams *cmd_rc = 0; 291f471f1a7SDan Williams } 292f471f1a7SDan Williams spin_unlock(&ars_state->lock); 29339c686b8SVishal Verma 29439c686b8SVishal Verma return 0; 29539c686b8SVishal Verma } 29639c686b8SVishal Verma 297f471f1a7SDan Williams static int nfit_test_cmd_ars_status(struct ars_state *ars_state, 298f471f1a7SDan Williams struct nd_cmd_ars_status *ars_status, unsigned int buf_len, 299f471f1a7SDan Williams int *cmd_rc) 30039c686b8SVishal Verma { 301f471f1a7SDan Williams if (buf_len < ars_state->ars_status->out_length) 30239c686b8SVishal Verma return -EINVAL; 30339c686b8SVishal Verma 304f471f1a7SDan Williams spin_lock(&ars_state->lock); 305f471f1a7SDan Williams if (time_before(jiffies, ars_state->deadline)) { 306f471f1a7SDan Williams memset(ars_status, 0, buf_len); 307f471f1a7SDan Williams ars_status->status = NFIT_ARS_STATUS_BUSY; 308f471f1a7SDan Williams ars_status->out_length = sizeof(*ars_status); 309f471f1a7SDan Williams *cmd_rc = -EBUSY; 310f471f1a7SDan Williams } else { 311f471f1a7SDan Williams memcpy(ars_status, ars_state->ars_status, 312f471f1a7SDan Williams ars_state->ars_status->out_length); 313f471f1a7SDan Williams *cmd_rc = 0; 314f471f1a7SDan Williams } 315f471f1a7SDan Williams spin_unlock(&ars_state->lock); 31639c686b8SVishal Verma return 0; 31739c686b8SVishal Verma } 31839c686b8SVishal Verma 319d4f32367SDan Williams static int nfit_test_cmd_clear_error(struct nd_cmd_clear_error *clear_err, 320d4f32367SDan Williams unsigned int buf_len, int *cmd_rc) 321d4f32367SDan Williams { 322d4f32367SDan Williams const u64 mask = NFIT_TEST_CLEAR_ERR_UNIT - 1; 323d4f32367SDan Williams if (buf_len < sizeof(*clear_err)) 324d4f32367SDan Williams return -EINVAL; 325d4f32367SDan Williams 326d4f32367SDan Williams if ((clear_err->address & mask) || (clear_err->length & mask)) 327d4f32367SDan Williams return -EINVAL; 328d4f32367SDan Williams 329d4f32367SDan Williams /* 330d4f32367SDan Williams * Report 'all clear' success for all commands even though a new 331d4f32367SDan Williams * scrub will find errors again. This is enough to have the 332d4f32367SDan Williams * error removed from the 'badblocks' tracking in the pmem 333d4f32367SDan Williams * driver. 334d4f32367SDan Williams */ 335d4f32367SDan Williams clear_err->status = 0; 336d4f32367SDan Williams clear_err->cleared = clear_err->length; 337d4f32367SDan Williams *cmd_rc = 0; 338d4f32367SDan Williams return 0; 339d4f32367SDan Williams } 340d4f32367SDan Williams 341baa51277SDan Williams static int nfit_test_cmd_smart(struct nd_cmd_smart *smart, unsigned int buf_len) 342baa51277SDan Williams { 343baa51277SDan Williams static const struct nd_smart_payload smart_data = { 344baa51277SDan Williams .flags = ND_SMART_HEALTH_VALID | ND_SMART_TEMP_VALID 345baa51277SDan Williams | ND_SMART_SPARES_VALID | ND_SMART_ALARM_VALID 346baa51277SDan Williams | ND_SMART_USED_VALID | ND_SMART_SHUTDOWN_VALID, 347baa51277SDan Williams .health = ND_SMART_NON_CRITICAL_HEALTH, 348baa51277SDan Williams .temperature = 23 * 16, 349baa51277SDan Williams .spares = 75, 350baa51277SDan Williams .alarm_flags = ND_SMART_SPARE_TRIP | ND_SMART_TEMP_TRIP, 351baa51277SDan Williams .life_used = 5, 352baa51277SDan Williams .shutdown_state = 0, 353baa51277SDan Williams .vendor_size = 0, 354baa51277SDan Williams }; 355baa51277SDan Williams 356baa51277SDan Williams if (buf_len < sizeof(*smart)) 357baa51277SDan Williams return -EINVAL; 358baa51277SDan Williams memcpy(smart->data, &smart_data, sizeof(smart_data)); 359baa51277SDan Williams return 0; 360baa51277SDan Williams } 361baa51277SDan Williams 362baa51277SDan Williams static int nfit_test_cmd_smart_threshold(struct nd_cmd_smart_threshold *smart_t, 363baa51277SDan Williams unsigned int buf_len) 364baa51277SDan Williams { 365baa51277SDan Williams static const struct nd_smart_threshold_payload smart_t_data = { 366baa51277SDan Williams .alarm_control = ND_SMART_SPARE_TRIP | ND_SMART_TEMP_TRIP, 367baa51277SDan Williams .temperature = 40 * 16, 368baa51277SDan Williams .spares = 5, 369baa51277SDan Williams }; 370baa51277SDan Williams 371baa51277SDan Williams if (buf_len < sizeof(*smart_t)) 372baa51277SDan Williams return -EINVAL; 373baa51277SDan Williams memcpy(smart_t->data, &smart_t_data, sizeof(smart_t_data)); 374baa51277SDan Williams return 0; 375baa51277SDan Williams } 376baa51277SDan Williams 37739c686b8SVishal Verma static int nfit_test_ctl(struct nvdimm_bus_descriptor *nd_desc, 37839c686b8SVishal Verma struct nvdimm *nvdimm, unsigned int cmd, void *buf, 379aef25338SDan Williams unsigned int buf_len, int *cmd_rc) 38039c686b8SVishal Verma { 38139c686b8SVishal Verma struct acpi_nfit_desc *acpi_desc = to_acpi_desc(nd_desc); 38239c686b8SVishal Verma struct nfit_test *t = container_of(acpi_desc, typeof(*t), acpi_desc); 3836634fb06SDan Williams unsigned int func = cmd; 384f471f1a7SDan Williams int i, rc = 0, __cmd_rc; 385f471f1a7SDan Williams 386f471f1a7SDan Williams if (!cmd_rc) 387f471f1a7SDan Williams cmd_rc = &__cmd_rc; 388f471f1a7SDan Williams *cmd_rc = 0; 38939c686b8SVishal Verma 39039c686b8SVishal Verma if (nvdimm) { 39139c686b8SVishal Verma struct nfit_mem *nfit_mem = nvdimm_provider_data(nvdimm); 392e3654ecaSDan Williams unsigned long cmd_mask = nvdimm_cmd_mask(nvdimm); 39339c686b8SVishal Verma 3946634fb06SDan Williams if (!nfit_mem) 3956634fb06SDan Williams return -ENOTTY; 3966634fb06SDan Williams 3976634fb06SDan Williams if (cmd == ND_CMD_CALL) { 3986634fb06SDan Williams struct nd_cmd_pkg *call_pkg = buf; 3996634fb06SDan Williams 4006634fb06SDan Williams buf_len = call_pkg->nd_size_in + call_pkg->nd_size_out; 4016634fb06SDan Williams buf = (void *) call_pkg->nd_payload; 4026634fb06SDan Williams func = call_pkg->nd_command; 4036634fb06SDan Williams if (call_pkg->nd_family != nfit_mem->family) 4046634fb06SDan Williams return -ENOTTY; 4056634fb06SDan Williams } 4066634fb06SDan Williams 4076634fb06SDan Williams if (!test_bit(cmd, &cmd_mask) 4086634fb06SDan Williams || !test_bit(func, &nfit_mem->dsm_mask)) 40939c686b8SVishal Verma return -ENOTTY; 41039c686b8SVishal Verma 41139c686b8SVishal Verma /* lookup label space for the given dimm */ 41239c686b8SVishal Verma for (i = 0; i < ARRAY_SIZE(handle); i++) 41339c686b8SVishal Verma if (__to_nfit_memdev(nfit_mem)->device_handle == 41439c686b8SVishal Verma handle[i]) 41539c686b8SVishal Verma break; 41639c686b8SVishal Verma if (i >= ARRAY_SIZE(handle)) 41739c686b8SVishal Verma return -ENXIO; 41839c686b8SVishal Verma 419*73606afdSDan Williams if ((1 << func) & dimm_fail_cmd_flags[i]) 420*73606afdSDan Williams return -EIO; 421*73606afdSDan Williams 4226634fb06SDan Williams switch (func) { 42339c686b8SVishal Verma case ND_CMD_GET_CONFIG_SIZE: 42439c686b8SVishal Verma rc = nfit_test_cmd_get_config_size(buf, buf_len); 42539c686b8SVishal Verma break; 42639c686b8SVishal Verma case ND_CMD_GET_CONFIG_DATA: 42739c686b8SVishal Verma rc = nfit_test_cmd_get_config_data(buf, buf_len, 42839c686b8SVishal Verma t->label[i]); 42939c686b8SVishal Verma break; 43039c686b8SVishal Verma case ND_CMD_SET_CONFIG_DATA: 43139c686b8SVishal Verma rc = nfit_test_cmd_set_config_data(buf, buf_len, 43239c686b8SVishal Verma t->label[i]); 43339c686b8SVishal Verma break; 434baa51277SDan Williams case ND_CMD_SMART: 435baa51277SDan Williams rc = nfit_test_cmd_smart(buf, buf_len); 436baa51277SDan Williams break; 437baa51277SDan Williams case ND_CMD_SMART_THRESHOLD: 438baa51277SDan Williams rc = nfit_test_cmd_smart_threshold(buf, buf_len); 439231bf117SDan Williams device_lock(&t->pdev.dev); 440231bf117SDan Williams __acpi_nvdimm_notify(t->dimm_dev[i], 0x81); 441231bf117SDan Williams device_unlock(&t->pdev.dev); 442baa51277SDan Williams break; 4436bc75619SDan Williams default: 4446bc75619SDan Williams return -ENOTTY; 4456bc75619SDan Williams } 44639c686b8SVishal Verma } else { 447f471f1a7SDan Williams struct ars_state *ars_state = &t->ars_state; 448f471f1a7SDan Williams 449e3654ecaSDan Williams if (!nd_desc || !test_bit(cmd, &nd_desc->cmd_mask)) 45039c686b8SVishal Verma return -ENOTTY; 45139c686b8SVishal Verma 4526634fb06SDan Williams switch (func) { 45339c686b8SVishal Verma case ND_CMD_ARS_CAP: 45439c686b8SVishal Verma rc = nfit_test_cmd_ars_cap(buf, buf_len); 45539c686b8SVishal Verma break; 45639c686b8SVishal Verma case ND_CMD_ARS_START: 457f471f1a7SDan Williams rc = nfit_test_cmd_ars_start(ars_state, buf, buf_len, 458f471f1a7SDan Williams cmd_rc); 45939c686b8SVishal Verma break; 46039c686b8SVishal Verma case ND_CMD_ARS_STATUS: 461f471f1a7SDan Williams rc = nfit_test_cmd_ars_status(ars_state, buf, buf_len, 462f471f1a7SDan Williams cmd_rc); 46339c686b8SVishal Verma break; 464d4f32367SDan Williams case ND_CMD_CLEAR_ERROR: 465d4f32367SDan Williams rc = nfit_test_cmd_clear_error(buf, buf_len, cmd_rc); 466d4f32367SDan Williams break; 46739c686b8SVishal Verma default: 46839c686b8SVishal Verma return -ENOTTY; 46939c686b8SVishal Verma } 47039c686b8SVishal Verma } 4716bc75619SDan Williams 4726bc75619SDan Williams return rc; 4736bc75619SDan Williams } 4746bc75619SDan Williams 4756bc75619SDan Williams static DEFINE_SPINLOCK(nfit_test_lock); 4766bc75619SDan Williams static struct nfit_test *instances[NUM_NFITS]; 4776bc75619SDan Williams 4786bc75619SDan Williams static void release_nfit_res(void *data) 4796bc75619SDan Williams { 4806bc75619SDan Williams struct nfit_test_resource *nfit_res = data; 4816bc75619SDan Williams struct resource *res = nfit_res->res; 4826bc75619SDan Williams 4836bc75619SDan Williams spin_lock(&nfit_test_lock); 4846bc75619SDan Williams list_del(&nfit_res->list); 4856bc75619SDan Williams spin_unlock(&nfit_test_lock); 4866bc75619SDan Williams 4876bc75619SDan Williams vfree(nfit_res->buf); 4886bc75619SDan Williams kfree(res); 4896bc75619SDan Williams kfree(nfit_res); 4906bc75619SDan Williams } 4916bc75619SDan Williams 4926bc75619SDan Williams static void *__test_alloc(struct nfit_test *t, size_t size, dma_addr_t *dma, 4936bc75619SDan Williams void *buf) 4946bc75619SDan Williams { 4956bc75619SDan Williams struct device *dev = &t->pdev.dev; 4966bc75619SDan Williams struct resource *res = kzalloc(sizeof(*res) * 2, GFP_KERNEL); 4976bc75619SDan Williams struct nfit_test_resource *nfit_res = kzalloc(sizeof(*nfit_res), 4986bc75619SDan Williams GFP_KERNEL); 4996bc75619SDan Williams int rc; 5006bc75619SDan Williams 5016bc75619SDan Williams if (!res || !buf || !nfit_res) 5026bc75619SDan Williams goto err; 5036bc75619SDan Williams rc = devm_add_action(dev, release_nfit_res, nfit_res); 5046bc75619SDan Williams if (rc) 5056bc75619SDan Williams goto err; 5066bc75619SDan Williams INIT_LIST_HEAD(&nfit_res->list); 5076bc75619SDan Williams memset(buf, 0, size); 5086bc75619SDan Williams nfit_res->dev = dev; 5096bc75619SDan Williams nfit_res->buf = buf; 5106bc75619SDan Williams nfit_res->res = res; 5116bc75619SDan Williams res->start = *dma; 5126bc75619SDan Williams res->end = *dma + size - 1; 5136bc75619SDan Williams res->name = "NFIT"; 5146bc75619SDan Williams spin_lock(&nfit_test_lock); 5156bc75619SDan Williams list_add(&nfit_res->list, &t->resources); 5166bc75619SDan Williams spin_unlock(&nfit_test_lock); 5176bc75619SDan Williams 5186bc75619SDan Williams return nfit_res->buf; 5196bc75619SDan Williams err: 520ee8520feSDan Williams if (buf) 5216bc75619SDan Williams vfree(buf); 5226bc75619SDan Williams kfree(res); 5236bc75619SDan Williams kfree(nfit_res); 5246bc75619SDan Williams return NULL; 5256bc75619SDan Williams } 5266bc75619SDan Williams 5276bc75619SDan Williams static void *test_alloc(struct nfit_test *t, size_t size, dma_addr_t *dma) 5286bc75619SDan Williams { 5296bc75619SDan Williams void *buf = vmalloc(size); 5306bc75619SDan Williams 5316bc75619SDan Williams *dma = (unsigned long) buf; 5326bc75619SDan Williams return __test_alloc(t, size, dma, buf); 5336bc75619SDan Williams } 5346bc75619SDan Williams 5356bc75619SDan Williams static struct nfit_test_resource *nfit_test_lookup(resource_size_t addr) 5366bc75619SDan Williams { 5376bc75619SDan Williams int i; 5386bc75619SDan Williams 5396bc75619SDan Williams for (i = 0; i < ARRAY_SIZE(instances); i++) { 5406bc75619SDan Williams struct nfit_test_resource *n, *nfit_res = NULL; 5416bc75619SDan Williams struct nfit_test *t = instances[i]; 5426bc75619SDan Williams 5436bc75619SDan Williams if (!t) 5446bc75619SDan Williams continue; 5456bc75619SDan Williams spin_lock(&nfit_test_lock); 5466bc75619SDan Williams list_for_each_entry(n, &t->resources, list) { 5476bc75619SDan Williams if (addr >= n->res->start && (addr < n->res->start 5486bc75619SDan Williams + resource_size(n->res))) { 5496bc75619SDan Williams nfit_res = n; 5506bc75619SDan Williams break; 5516bc75619SDan Williams } else if (addr >= (unsigned long) n->buf 5526bc75619SDan Williams && (addr < (unsigned long) n->buf 5536bc75619SDan Williams + resource_size(n->res))) { 5546bc75619SDan Williams nfit_res = n; 5556bc75619SDan Williams break; 5566bc75619SDan Williams } 5576bc75619SDan Williams } 5586bc75619SDan Williams spin_unlock(&nfit_test_lock); 5596bc75619SDan Williams if (nfit_res) 5606bc75619SDan Williams return nfit_res; 5616bc75619SDan Williams } 5626bc75619SDan Williams 5636bc75619SDan Williams return NULL; 5646bc75619SDan Williams } 5656bc75619SDan Williams 566f471f1a7SDan Williams static int ars_state_init(struct device *dev, struct ars_state *ars_state) 567f471f1a7SDan Williams { 568f471f1a7SDan Williams ars_state->ars_status = devm_kzalloc(dev, 569f471f1a7SDan Williams sizeof(struct nd_cmd_ars_status) 570f471f1a7SDan Williams + sizeof(struct nd_ars_record) * NFIT_TEST_ARS_RECORDS, 571f471f1a7SDan Williams GFP_KERNEL); 572f471f1a7SDan Williams if (!ars_state->ars_status) 573f471f1a7SDan Williams return -ENOMEM; 574f471f1a7SDan Williams spin_lock_init(&ars_state->lock); 575f471f1a7SDan Williams return 0; 576f471f1a7SDan Williams } 577f471f1a7SDan Williams 578231bf117SDan Williams static void put_dimms(void *data) 579231bf117SDan Williams { 580231bf117SDan Williams struct device **dimm_dev = data; 581231bf117SDan Williams int i; 582231bf117SDan Williams 583231bf117SDan Williams for (i = 0; i < NUM_DCR; i++) 584231bf117SDan Williams if (dimm_dev[i]) 585231bf117SDan Williams device_unregister(dimm_dev[i]); 586231bf117SDan Williams } 587231bf117SDan Williams 588231bf117SDan Williams static struct class *nfit_test_dimm; 589231bf117SDan Williams 590*73606afdSDan Williams static int dimm_name_to_id(struct device *dev) 591*73606afdSDan Williams { 592*73606afdSDan Williams int dimm; 593*73606afdSDan Williams 594*73606afdSDan Williams if (sscanf(dev_name(dev), "test_dimm%d", &dimm) != 1 595*73606afdSDan Williams || dimm >= NUM_DCR || dimm < 0) 596*73606afdSDan Williams return -ENXIO; 597*73606afdSDan Williams return dimm; 598*73606afdSDan Williams } 599*73606afdSDan Williams 600*73606afdSDan Williams 601*73606afdSDan Williams static ssize_t handle_show(struct device *dev, struct device_attribute *attr, 602*73606afdSDan Williams char *buf) 603*73606afdSDan Williams { 604*73606afdSDan Williams int dimm = dimm_name_to_id(dev); 605*73606afdSDan Williams 606*73606afdSDan Williams if (dimm < 0) 607*73606afdSDan Williams return dimm; 608*73606afdSDan Williams 609*73606afdSDan Williams return sprintf(buf, "%#x", handle[dimm]); 610*73606afdSDan Williams } 611*73606afdSDan Williams DEVICE_ATTR_RO(handle); 612*73606afdSDan Williams 613*73606afdSDan Williams static ssize_t fail_cmd_show(struct device *dev, struct device_attribute *attr, 614*73606afdSDan Williams char *buf) 615*73606afdSDan Williams { 616*73606afdSDan Williams int dimm = dimm_name_to_id(dev); 617*73606afdSDan Williams 618*73606afdSDan Williams if (dimm < 0) 619*73606afdSDan Williams return dimm; 620*73606afdSDan Williams 621*73606afdSDan Williams return sprintf(buf, "%#lx\n", dimm_fail_cmd_flags[dimm]); 622*73606afdSDan Williams } 623*73606afdSDan Williams 624*73606afdSDan Williams static ssize_t fail_cmd_store(struct device *dev, struct device_attribute *attr, 625*73606afdSDan Williams const char *buf, size_t size) 626*73606afdSDan Williams { 627*73606afdSDan Williams int dimm = dimm_name_to_id(dev); 628*73606afdSDan Williams unsigned long val; 629*73606afdSDan Williams ssize_t rc; 630*73606afdSDan Williams 631*73606afdSDan Williams if (dimm < 0) 632*73606afdSDan Williams return dimm; 633*73606afdSDan Williams 634*73606afdSDan Williams rc = kstrtol(buf, 0, &val); 635*73606afdSDan Williams if (rc) 636*73606afdSDan Williams return rc; 637*73606afdSDan Williams 638*73606afdSDan Williams dimm_fail_cmd_flags[dimm] = val; 639*73606afdSDan Williams return size; 640*73606afdSDan Williams } 641*73606afdSDan Williams static DEVICE_ATTR_RW(fail_cmd); 642*73606afdSDan Williams 643*73606afdSDan Williams static struct attribute *nfit_test_dimm_attributes[] = { 644*73606afdSDan Williams &dev_attr_fail_cmd.attr, 645*73606afdSDan Williams &dev_attr_handle.attr, 646*73606afdSDan Williams NULL, 647*73606afdSDan Williams }; 648*73606afdSDan Williams 649*73606afdSDan Williams static struct attribute_group nfit_test_dimm_attribute_group = { 650*73606afdSDan Williams .attrs = nfit_test_dimm_attributes, 651*73606afdSDan Williams }; 652*73606afdSDan Williams 653*73606afdSDan Williams static const struct attribute_group *nfit_test_dimm_attribute_groups[] = { 654*73606afdSDan Williams &nfit_test_dimm_attribute_group, 655*73606afdSDan Williams NULL, 656*73606afdSDan Williams }; 657*73606afdSDan Williams 6586bc75619SDan Williams static int nfit_test0_alloc(struct nfit_test *t) 6596bc75619SDan Williams { 6606b577c9dSLinda Knippers size_t nfit_size = sizeof(struct acpi_nfit_system_address) * NUM_SPA 6616bc75619SDan Williams + sizeof(struct acpi_nfit_memory_map) * NUM_MEM 6626bc75619SDan Williams + sizeof(struct acpi_nfit_control_region) * NUM_DCR 6633b87356fSDan Williams + offsetof(struct acpi_nfit_control_region, 6643b87356fSDan Williams window_size) * NUM_DCR 6659d27a87eSDan Williams + sizeof(struct acpi_nfit_data_region) * NUM_BDW 66685d3fa02SDan Williams + (sizeof(struct acpi_nfit_flush_address) 66785d3fa02SDan Williams + sizeof(u64) * NUM_HINTS) * NUM_DCR; 6686bc75619SDan Williams int i; 6696bc75619SDan Williams 6706bc75619SDan Williams t->nfit_buf = test_alloc(t, nfit_size, &t->nfit_dma); 6716bc75619SDan Williams if (!t->nfit_buf) 6726bc75619SDan Williams return -ENOMEM; 6736bc75619SDan Williams t->nfit_size = nfit_size; 6746bc75619SDan Williams 675ee8520feSDan Williams t->spa_set[0] = test_alloc(t, SPA0_SIZE, &t->spa_set_dma[0]); 6766bc75619SDan Williams if (!t->spa_set[0]) 6776bc75619SDan Williams return -ENOMEM; 6786bc75619SDan Williams 679ee8520feSDan Williams t->spa_set[1] = test_alloc(t, SPA1_SIZE, &t->spa_set_dma[1]); 6806bc75619SDan Williams if (!t->spa_set[1]) 6816bc75619SDan Williams return -ENOMEM; 6826bc75619SDan Williams 683ee8520feSDan Williams t->spa_set[2] = test_alloc(t, SPA0_SIZE, &t->spa_set_dma[2]); 68420985164SVishal Verma if (!t->spa_set[2]) 68520985164SVishal Verma return -ENOMEM; 68620985164SVishal Verma 6876bc75619SDan Williams for (i = 0; i < NUM_DCR; i++) { 6886bc75619SDan Williams t->dimm[i] = test_alloc(t, DIMM_SIZE, &t->dimm_dma[i]); 6896bc75619SDan Williams if (!t->dimm[i]) 6906bc75619SDan Williams return -ENOMEM; 6916bc75619SDan Williams 6926bc75619SDan Williams t->label[i] = test_alloc(t, LABEL_SIZE, &t->label_dma[i]); 6936bc75619SDan Williams if (!t->label[i]) 6946bc75619SDan Williams return -ENOMEM; 6956bc75619SDan Williams sprintf(t->label[i], "label%d", i); 6969d27a87eSDan Williams 69785d3fa02SDan Williams t->flush[i] = test_alloc(t, sizeof(u64) * NUM_HINTS, 69885d3fa02SDan Williams &t->flush_dma[i]); 6999d27a87eSDan Williams if (!t->flush[i]) 7009d27a87eSDan Williams return -ENOMEM; 7016bc75619SDan Williams } 7026bc75619SDan Williams 7036bc75619SDan Williams for (i = 0; i < NUM_DCR; i++) { 7046bc75619SDan Williams t->dcr[i] = test_alloc(t, LABEL_SIZE, &t->dcr_dma[i]); 7056bc75619SDan Williams if (!t->dcr[i]) 7066bc75619SDan Williams return -ENOMEM; 7076bc75619SDan Williams } 7086bc75619SDan Williams 709c14a868aSDan Williams t->_fit = test_alloc(t, sizeof(union acpi_object **), &t->_fit_dma); 710c14a868aSDan Williams if (!t->_fit) 711c14a868aSDan Williams return -ENOMEM; 712c14a868aSDan Williams 713231bf117SDan Williams if (devm_add_action_or_reset(&t->pdev.dev, put_dimms, t->dimm_dev)) 714231bf117SDan Williams return -ENOMEM; 715231bf117SDan Williams for (i = 0; i < NUM_DCR; i++) { 716*73606afdSDan Williams t->dimm_dev[i] = device_create_with_groups(nfit_test_dimm, 717*73606afdSDan Williams &t->pdev.dev, 0, NULL, 718*73606afdSDan Williams nfit_test_dimm_attribute_groups, 719*73606afdSDan Williams "test_dimm%d", i); 720231bf117SDan Williams if (!t->dimm_dev[i]) 721231bf117SDan Williams return -ENOMEM; 722231bf117SDan Williams } 723231bf117SDan Williams 724f471f1a7SDan Williams return ars_state_init(&t->pdev.dev, &t->ars_state); 7256bc75619SDan Williams } 7266bc75619SDan Williams 7276bc75619SDan Williams static int nfit_test1_alloc(struct nfit_test *t) 7286bc75619SDan Williams { 7297bfe97c7SDan Williams size_t nfit_size = sizeof(struct acpi_nfit_system_address) * 2 7306bc75619SDan Williams + sizeof(struct acpi_nfit_memory_map) 7313b87356fSDan Williams + offsetof(struct acpi_nfit_control_region, window_size); 7326bc75619SDan Williams 7336bc75619SDan Williams t->nfit_buf = test_alloc(t, nfit_size, &t->nfit_dma); 7346bc75619SDan Williams if (!t->nfit_buf) 7356bc75619SDan Williams return -ENOMEM; 7366bc75619SDan Williams t->nfit_size = nfit_size; 7376bc75619SDan Williams 738ee8520feSDan Williams t->spa_set[0] = test_alloc(t, SPA2_SIZE, &t->spa_set_dma[0]); 7396bc75619SDan Williams if (!t->spa_set[0]) 7406bc75619SDan Williams return -ENOMEM; 7416bc75619SDan Williams 7427bfe97c7SDan Williams t->spa_set[1] = test_alloc(t, SPA_VCD_SIZE, &t->spa_set_dma[1]); 7437bfe97c7SDan Williams if (!t->spa_set[1]) 7447bfe97c7SDan Williams return -ENOMEM; 7457bfe97c7SDan Williams 746f471f1a7SDan Williams return ars_state_init(&t->pdev.dev, &t->ars_state); 7476bc75619SDan Williams } 7486bc75619SDan Williams 7495dc68e55SDan Williams static void dcr_common_init(struct acpi_nfit_control_region *dcr) 7505dc68e55SDan Williams { 7515dc68e55SDan Williams dcr->vendor_id = 0xabcd; 7525dc68e55SDan Williams dcr->device_id = 0; 7535dc68e55SDan Williams dcr->revision_id = 1; 7545dc68e55SDan Williams dcr->valid_fields = 1; 7555dc68e55SDan Williams dcr->manufacturing_location = 0xa; 7565dc68e55SDan Williams dcr->manufacturing_date = cpu_to_be16(2016); 7575dc68e55SDan Williams } 7585dc68e55SDan Williams 7596bc75619SDan Williams static void nfit_test0_setup(struct nfit_test *t) 7606bc75619SDan Williams { 76185d3fa02SDan Williams const int flush_hint_size = sizeof(struct acpi_nfit_flush_address) 76285d3fa02SDan Williams + (sizeof(u64) * NUM_HINTS); 7636bc75619SDan Williams struct acpi_nfit_desc *acpi_desc; 7646bc75619SDan Williams struct acpi_nfit_memory_map *memdev; 7656bc75619SDan Williams void *nfit_buf = t->nfit_buf; 7666bc75619SDan Williams struct acpi_nfit_system_address *spa; 7676bc75619SDan Williams struct acpi_nfit_control_region *dcr; 7686bc75619SDan Williams struct acpi_nfit_data_region *bdw; 7699d27a87eSDan Williams struct acpi_nfit_flush_address *flush; 77085d3fa02SDan Williams unsigned int offset, i; 7716bc75619SDan Williams 7726bc75619SDan Williams /* 7736bc75619SDan Williams * spa0 (interleave first half of dimm0 and dimm1, note storage 7746bc75619SDan Williams * does not actually alias the related block-data-window 7756bc75619SDan Williams * regions) 7766bc75619SDan Williams */ 7776b577c9dSLinda Knippers spa = nfit_buf; 7786bc75619SDan Williams spa->header.type = ACPI_NFIT_TYPE_SYSTEM_ADDRESS; 7796bc75619SDan Williams spa->header.length = sizeof(*spa); 7806bc75619SDan Williams memcpy(spa->range_guid, to_nfit_uuid(NFIT_SPA_PM), 16); 7816bc75619SDan Williams spa->range_index = 0+1; 7826bc75619SDan Williams spa->address = t->spa_set_dma[0]; 7836bc75619SDan Williams spa->length = SPA0_SIZE; 7846bc75619SDan Williams 7856bc75619SDan Williams /* 7866bc75619SDan Williams * spa1 (interleave last half of the 4 DIMMS, note storage 7876bc75619SDan Williams * does not actually alias the related block-data-window 7886bc75619SDan Williams * regions) 7896bc75619SDan Williams */ 7906b577c9dSLinda Knippers spa = nfit_buf + sizeof(*spa); 7916bc75619SDan Williams spa->header.type = ACPI_NFIT_TYPE_SYSTEM_ADDRESS; 7926bc75619SDan Williams spa->header.length = sizeof(*spa); 7936bc75619SDan Williams memcpy(spa->range_guid, to_nfit_uuid(NFIT_SPA_PM), 16); 7946bc75619SDan Williams spa->range_index = 1+1; 7956bc75619SDan Williams spa->address = t->spa_set_dma[1]; 7966bc75619SDan Williams spa->length = SPA1_SIZE; 7976bc75619SDan Williams 7986bc75619SDan Williams /* spa2 (dcr0) dimm0 */ 7996b577c9dSLinda Knippers spa = nfit_buf + sizeof(*spa) * 2; 8006bc75619SDan Williams spa->header.type = ACPI_NFIT_TYPE_SYSTEM_ADDRESS; 8016bc75619SDan Williams spa->header.length = sizeof(*spa); 8026bc75619SDan Williams memcpy(spa->range_guid, to_nfit_uuid(NFIT_SPA_DCR), 16); 8036bc75619SDan Williams spa->range_index = 2+1; 8046bc75619SDan Williams spa->address = t->dcr_dma[0]; 8056bc75619SDan Williams spa->length = DCR_SIZE; 8066bc75619SDan Williams 8076bc75619SDan Williams /* spa3 (dcr1) dimm1 */ 8086b577c9dSLinda Knippers spa = nfit_buf + sizeof(*spa) * 3; 8096bc75619SDan Williams spa->header.type = ACPI_NFIT_TYPE_SYSTEM_ADDRESS; 8106bc75619SDan Williams spa->header.length = sizeof(*spa); 8116bc75619SDan Williams memcpy(spa->range_guid, to_nfit_uuid(NFIT_SPA_DCR), 16); 8126bc75619SDan Williams spa->range_index = 3+1; 8136bc75619SDan Williams spa->address = t->dcr_dma[1]; 8146bc75619SDan Williams spa->length = DCR_SIZE; 8156bc75619SDan Williams 8166bc75619SDan Williams /* spa4 (dcr2) dimm2 */ 8176b577c9dSLinda Knippers spa = nfit_buf + sizeof(*spa) * 4; 8186bc75619SDan Williams spa->header.type = ACPI_NFIT_TYPE_SYSTEM_ADDRESS; 8196bc75619SDan Williams spa->header.length = sizeof(*spa); 8206bc75619SDan Williams memcpy(spa->range_guid, to_nfit_uuid(NFIT_SPA_DCR), 16); 8216bc75619SDan Williams spa->range_index = 4+1; 8226bc75619SDan Williams spa->address = t->dcr_dma[2]; 8236bc75619SDan Williams spa->length = DCR_SIZE; 8246bc75619SDan Williams 8256bc75619SDan Williams /* spa5 (dcr3) dimm3 */ 8266b577c9dSLinda Knippers spa = nfit_buf + sizeof(*spa) * 5; 8276bc75619SDan Williams spa->header.type = ACPI_NFIT_TYPE_SYSTEM_ADDRESS; 8286bc75619SDan Williams spa->header.length = sizeof(*spa); 8296bc75619SDan Williams memcpy(spa->range_guid, to_nfit_uuid(NFIT_SPA_DCR), 16); 8306bc75619SDan Williams spa->range_index = 5+1; 8316bc75619SDan Williams spa->address = t->dcr_dma[3]; 8326bc75619SDan Williams spa->length = DCR_SIZE; 8336bc75619SDan Williams 8346bc75619SDan Williams /* spa6 (bdw for dcr0) dimm0 */ 8356b577c9dSLinda Knippers spa = nfit_buf + sizeof(*spa) * 6; 8366bc75619SDan Williams spa->header.type = ACPI_NFIT_TYPE_SYSTEM_ADDRESS; 8376bc75619SDan Williams spa->header.length = sizeof(*spa); 8386bc75619SDan Williams memcpy(spa->range_guid, to_nfit_uuid(NFIT_SPA_BDW), 16); 8396bc75619SDan Williams spa->range_index = 6+1; 8406bc75619SDan Williams spa->address = t->dimm_dma[0]; 8416bc75619SDan Williams spa->length = DIMM_SIZE; 8426bc75619SDan Williams 8436bc75619SDan Williams /* spa7 (bdw for dcr1) dimm1 */ 8446b577c9dSLinda Knippers spa = nfit_buf + sizeof(*spa) * 7; 8456bc75619SDan Williams spa->header.type = ACPI_NFIT_TYPE_SYSTEM_ADDRESS; 8466bc75619SDan Williams spa->header.length = sizeof(*spa); 8476bc75619SDan Williams memcpy(spa->range_guid, to_nfit_uuid(NFIT_SPA_BDW), 16); 8486bc75619SDan Williams spa->range_index = 7+1; 8496bc75619SDan Williams spa->address = t->dimm_dma[1]; 8506bc75619SDan Williams spa->length = DIMM_SIZE; 8516bc75619SDan Williams 8526bc75619SDan Williams /* spa8 (bdw for dcr2) dimm2 */ 8536b577c9dSLinda Knippers spa = nfit_buf + sizeof(*spa) * 8; 8546bc75619SDan Williams spa->header.type = ACPI_NFIT_TYPE_SYSTEM_ADDRESS; 8556bc75619SDan Williams spa->header.length = sizeof(*spa); 8566bc75619SDan Williams memcpy(spa->range_guid, to_nfit_uuid(NFIT_SPA_BDW), 16); 8576bc75619SDan Williams spa->range_index = 8+1; 8586bc75619SDan Williams spa->address = t->dimm_dma[2]; 8596bc75619SDan Williams spa->length = DIMM_SIZE; 8606bc75619SDan Williams 8616bc75619SDan Williams /* spa9 (bdw for dcr3) dimm3 */ 8626b577c9dSLinda Knippers spa = nfit_buf + sizeof(*spa) * 9; 8636bc75619SDan Williams spa->header.type = ACPI_NFIT_TYPE_SYSTEM_ADDRESS; 8646bc75619SDan Williams spa->header.length = sizeof(*spa); 8656bc75619SDan Williams memcpy(spa->range_guid, to_nfit_uuid(NFIT_SPA_BDW), 16); 8666bc75619SDan Williams spa->range_index = 9+1; 8676bc75619SDan Williams spa->address = t->dimm_dma[3]; 8686bc75619SDan Williams spa->length = DIMM_SIZE; 8696bc75619SDan Williams 8706b577c9dSLinda Knippers offset = sizeof(*spa) * 10; 8716bc75619SDan Williams /* mem-region0 (spa0, dimm0) */ 8726bc75619SDan Williams memdev = nfit_buf + offset; 8736bc75619SDan Williams memdev->header.type = ACPI_NFIT_TYPE_MEMORY_MAP; 8746bc75619SDan Williams memdev->header.length = sizeof(*memdev); 8756bc75619SDan Williams memdev->device_handle = handle[0]; 8766bc75619SDan Williams memdev->physical_id = 0; 8776bc75619SDan Williams memdev->region_id = 0; 8786bc75619SDan Williams memdev->range_index = 0+1; 8793b87356fSDan Williams memdev->region_index = 4+1; 8806bc75619SDan Williams memdev->region_size = SPA0_SIZE/2; 8816bc75619SDan Williams memdev->region_offset = t->spa_set_dma[0]; 8826bc75619SDan Williams memdev->address = 0; 8836bc75619SDan Williams memdev->interleave_index = 0; 8846bc75619SDan Williams memdev->interleave_ways = 2; 8856bc75619SDan Williams 8866bc75619SDan Williams /* mem-region1 (spa0, dimm1) */ 8876bc75619SDan Williams memdev = nfit_buf + offset + sizeof(struct acpi_nfit_memory_map); 8886bc75619SDan Williams memdev->header.type = ACPI_NFIT_TYPE_MEMORY_MAP; 8896bc75619SDan Williams memdev->header.length = sizeof(*memdev); 8906bc75619SDan Williams memdev->device_handle = handle[1]; 8916bc75619SDan Williams memdev->physical_id = 1; 8926bc75619SDan Williams memdev->region_id = 0; 8936bc75619SDan Williams memdev->range_index = 0+1; 8943b87356fSDan Williams memdev->region_index = 5+1; 8956bc75619SDan Williams memdev->region_size = SPA0_SIZE/2; 8966bc75619SDan Williams memdev->region_offset = t->spa_set_dma[0] + SPA0_SIZE/2; 8976bc75619SDan Williams memdev->address = 0; 8986bc75619SDan Williams memdev->interleave_index = 0; 8996bc75619SDan Williams memdev->interleave_ways = 2; 9006bc75619SDan Williams 9016bc75619SDan Williams /* mem-region2 (spa1, dimm0) */ 9026bc75619SDan Williams memdev = nfit_buf + offset + sizeof(struct acpi_nfit_memory_map) * 2; 9036bc75619SDan Williams memdev->header.type = ACPI_NFIT_TYPE_MEMORY_MAP; 9046bc75619SDan Williams memdev->header.length = sizeof(*memdev); 9056bc75619SDan Williams memdev->device_handle = handle[0]; 9066bc75619SDan Williams memdev->physical_id = 0; 9076bc75619SDan Williams memdev->region_id = 1; 9086bc75619SDan Williams memdev->range_index = 1+1; 9093b87356fSDan Williams memdev->region_index = 4+1; 9106bc75619SDan Williams memdev->region_size = SPA1_SIZE/4; 9116bc75619SDan Williams memdev->region_offset = t->spa_set_dma[1]; 9126bc75619SDan Williams memdev->address = SPA0_SIZE/2; 9136bc75619SDan Williams memdev->interleave_index = 0; 9146bc75619SDan Williams memdev->interleave_ways = 4; 9156bc75619SDan Williams 9166bc75619SDan Williams /* mem-region3 (spa1, dimm1) */ 9176bc75619SDan Williams memdev = nfit_buf + offset + sizeof(struct acpi_nfit_memory_map) * 3; 9186bc75619SDan Williams memdev->header.type = ACPI_NFIT_TYPE_MEMORY_MAP; 9196bc75619SDan Williams memdev->header.length = sizeof(*memdev); 9206bc75619SDan Williams memdev->device_handle = handle[1]; 9216bc75619SDan Williams memdev->physical_id = 1; 9226bc75619SDan Williams memdev->region_id = 1; 9236bc75619SDan Williams memdev->range_index = 1+1; 9243b87356fSDan Williams memdev->region_index = 5+1; 9256bc75619SDan Williams memdev->region_size = SPA1_SIZE/4; 9266bc75619SDan Williams memdev->region_offset = t->spa_set_dma[1] + SPA1_SIZE/4; 9276bc75619SDan Williams memdev->address = SPA0_SIZE/2; 9286bc75619SDan Williams memdev->interleave_index = 0; 9296bc75619SDan Williams memdev->interleave_ways = 4; 9306bc75619SDan Williams 9316bc75619SDan Williams /* mem-region4 (spa1, dimm2) */ 9326bc75619SDan Williams memdev = nfit_buf + offset + sizeof(struct acpi_nfit_memory_map) * 4; 9336bc75619SDan Williams memdev->header.type = ACPI_NFIT_TYPE_MEMORY_MAP; 9346bc75619SDan Williams memdev->header.length = sizeof(*memdev); 9356bc75619SDan Williams memdev->device_handle = handle[2]; 9366bc75619SDan Williams memdev->physical_id = 2; 9376bc75619SDan Williams memdev->region_id = 0; 9386bc75619SDan Williams memdev->range_index = 1+1; 9393b87356fSDan Williams memdev->region_index = 6+1; 9406bc75619SDan Williams memdev->region_size = SPA1_SIZE/4; 9416bc75619SDan Williams memdev->region_offset = t->spa_set_dma[1] + 2*SPA1_SIZE/4; 9426bc75619SDan Williams memdev->address = SPA0_SIZE/2; 9436bc75619SDan Williams memdev->interleave_index = 0; 9446bc75619SDan Williams memdev->interleave_ways = 4; 9456bc75619SDan Williams 9466bc75619SDan Williams /* mem-region5 (spa1, dimm3) */ 9476bc75619SDan Williams memdev = nfit_buf + offset + sizeof(struct acpi_nfit_memory_map) * 5; 9486bc75619SDan Williams memdev->header.type = ACPI_NFIT_TYPE_MEMORY_MAP; 9496bc75619SDan Williams memdev->header.length = sizeof(*memdev); 9506bc75619SDan Williams memdev->device_handle = handle[3]; 9516bc75619SDan Williams memdev->physical_id = 3; 9526bc75619SDan Williams memdev->region_id = 0; 9536bc75619SDan Williams memdev->range_index = 1+1; 9543b87356fSDan Williams memdev->region_index = 7+1; 9556bc75619SDan Williams memdev->region_size = SPA1_SIZE/4; 9566bc75619SDan Williams memdev->region_offset = t->spa_set_dma[1] + 3*SPA1_SIZE/4; 9576bc75619SDan Williams memdev->address = SPA0_SIZE/2; 9586bc75619SDan Williams memdev->interleave_index = 0; 9596bc75619SDan Williams memdev->interleave_ways = 4; 9606bc75619SDan Williams 9616bc75619SDan Williams /* mem-region6 (spa/dcr0, dimm0) */ 9626bc75619SDan Williams memdev = nfit_buf + offset + sizeof(struct acpi_nfit_memory_map) * 6; 9636bc75619SDan Williams memdev->header.type = ACPI_NFIT_TYPE_MEMORY_MAP; 9646bc75619SDan Williams memdev->header.length = sizeof(*memdev); 9656bc75619SDan Williams memdev->device_handle = handle[0]; 9666bc75619SDan Williams memdev->physical_id = 0; 9676bc75619SDan Williams memdev->region_id = 0; 9686bc75619SDan Williams memdev->range_index = 2+1; 9696bc75619SDan Williams memdev->region_index = 0+1; 9706bc75619SDan Williams memdev->region_size = 0; 9716bc75619SDan Williams memdev->region_offset = 0; 9726bc75619SDan Williams memdev->address = 0; 9736bc75619SDan Williams memdev->interleave_index = 0; 9746bc75619SDan Williams memdev->interleave_ways = 1; 9756bc75619SDan Williams 9766bc75619SDan Williams /* mem-region7 (spa/dcr1, dimm1) */ 9776bc75619SDan Williams memdev = nfit_buf + offset + sizeof(struct acpi_nfit_memory_map) * 7; 9786bc75619SDan Williams memdev->header.type = ACPI_NFIT_TYPE_MEMORY_MAP; 9796bc75619SDan Williams memdev->header.length = sizeof(*memdev); 9806bc75619SDan Williams memdev->device_handle = handle[1]; 9816bc75619SDan Williams memdev->physical_id = 1; 9826bc75619SDan Williams memdev->region_id = 0; 9836bc75619SDan Williams memdev->range_index = 3+1; 9846bc75619SDan Williams memdev->region_index = 1+1; 9856bc75619SDan Williams memdev->region_size = 0; 9866bc75619SDan Williams memdev->region_offset = 0; 9876bc75619SDan Williams memdev->address = 0; 9886bc75619SDan Williams memdev->interleave_index = 0; 9896bc75619SDan Williams memdev->interleave_ways = 1; 9906bc75619SDan Williams 9916bc75619SDan Williams /* mem-region8 (spa/dcr2, dimm2) */ 9926bc75619SDan Williams memdev = nfit_buf + offset + sizeof(struct acpi_nfit_memory_map) * 8; 9936bc75619SDan Williams memdev->header.type = ACPI_NFIT_TYPE_MEMORY_MAP; 9946bc75619SDan Williams memdev->header.length = sizeof(*memdev); 9956bc75619SDan Williams memdev->device_handle = handle[2]; 9966bc75619SDan Williams memdev->physical_id = 2; 9976bc75619SDan Williams memdev->region_id = 0; 9986bc75619SDan Williams memdev->range_index = 4+1; 9996bc75619SDan Williams memdev->region_index = 2+1; 10006bc75619SDan Williams memdev->region_size = 0; 10016bc75619SDan Williams memdev->region_offset = 0; 10026bc75619SDan Williams memdev->address = 0; 10036bc75619SDan Williams memdev->interleave_index = 0; 10046bc75619SDan Williams memdev->interleave_ways = 1; 10056bc75619SDan Williams 10066bc75619SDan Williams /* mem-region9 (spa/dcr3, dimm3) */ 10076bc75619SDan Williams memdev = nfit_buf + offset + sizeof(struct acpi_nfit_memory_map) * 9; 10086bc75619SDan Williams memdev->header.type = ACPI_NFIT_TYPE_MEMORY_MAP; 10096bc75619SDan Williams memdev->header.length = sizeof(*memdev); 10106bc75619SDan Williams memdev->device_handle = handle[3]; 10116bc75619SDan Williams memdev->physical_id = 3; 10126bc75619SDan Williams memdev->region_id = 0; 10136bc75619SDan Williams memdev->range_index = 5+1; 10146bc75619SDan Williams memdev->region_index = 3+1; 10156bc75619SDan Williams memdev->region_size = 0; 10166bc75619SDan Williams memdev->region_offset = 0; 10176bc75619SDan Williams memdev->address = 0; 10186bc75619SDan Williams memdev->interleave_index = 0; 10196bc75619SDan Williams memdev->interleave_ways = 1; 10206bc75619SDan Williams 10216bc75619SDan Williams /* mem-region10 (spa/bdw0, dimm0) */ 10226bc75619SDan Williams memdev = nfit_buf + offset + sizeof(struct acpi_nfit_memory_map) * 10; 10236bc75619SDan Williams memdev->header.type = ACPI_NFIT_TYPE_MEMORY_MAP; 10246bc75619SDan Williams memdev->header.length = sizeof(*memdev); 10256bc75619SDan Williams memdev->device_handle = handle[0]; 10266bc75619SDan Williams memdev->physical_id = 0; 10276bc75619SDan Williams memdev->region_id = 0; 10286bc75619SDan Williams memdev->range_index = 6+1; 10296bc75619SDan Williams memdev->region_index = 0+1; 10306bc75619SDan Williams memdev->region_size = 0; 10316bc75619SDan Williams memdev->region_offset = 0; 10326bc75619SDan Williams memdev->address = 0; 10336bc75619SDan Williams memdev->interleave_index = 0; 10346bc75619SDan Williams memdev->interleave_ways = 1; 10356bc75619SDan Williams 10366bc75619SDan Williams /* mem-region11 (spa/bdw1, dimm1) */ 10376bc75619SDan Williams memdev = nfit_buf + offset + sizeof(struct acpi_nfit_memory_map) * 11; 10386bc75619SDan Williams memdev->header.type = ACPI_NFIT_TYPE_MEMORY_MAP; 10396bc75619SDan Williams memdev->header.length = sizeof(*memdev); 10406bc75619SDan Williams memdev->device_handle = handle[1]; 10416bc75619SDan Williams memdev->physical_id = 1; 10426bc75619SDan Williams memdev->region_id = 0; 10436bc75619SDan Williams memdev->range_index = 7+1; 10446bc75619SDan Williams memdev->region_index = 1+1; 10456bc75619SDan Williams memdev->region_size = 0; 10466bc75619SDan Williams memdev->region_offset = 0; 10476bc75619SDan Williams memdev->address = 0; 10486bc75619SDan Williams memdev->interleave_index = 0; 10496bc75619SDan Williams memdev->interleave_ways = 1; 10506bc75619SDan Williams 10516bc75619SDan Williams /* mem-region12 (spa/bdw2, dimm2) */ 10526bc75619SDan Williams memdev = nfit_buf + offset + sizeof(struct acpi_nfit_memory_map) * 12; 10536bc75619SDan Williams memdev->header.type = ACPI_NFIT_TYPE_MEMORY_MAP; 10546bc75619SDan Williams memdev->header.length = sizeof(*memdev); 10556bc75619SDan Williams memdev->device_handle = handle[2]; 10566bc75619SDan Williams memdev->physical_id = 2; 10576bc75619SDan Williams memdev->region_id = 0; 10586bc75619SDan Williams memdev->range_index = 8+1; 10596bc75619SDan Williams memdev->region_index = 2+1; 10606bc75619SDan Williams memdev->region_size = 0; 10616bc75619SDan Williams memdev->region_offset = 0; 10626bc75619SDan Williams memdev->address = 0; 10636bc75619SDan Williams memdev->interleave_index = 0; 10646bc75619SDan Williams memdev->interleave_ways = 1; 10656bc75619SDan Williams 10666bc75619SDan Williams /* mem-region13 (spa/dcr3, dimm3) */ 10676bc75619SDan Williams memdev = nfit_buf + offset + sizeof(struct acpi_nfit_memory_map) * 13; 10686bc75619SDan Williams memdev->header.type = ACPI_NFIT_TYPE_MEMORY_MAP; 10696bc75619SDan Williams memdev->header.length = sizeof(*memdev); 10706bc75619SDan Williams memdev->device_handle = handle[3]; 10716bc75619SDan Williams memdev->physical_id = 3; 10726bc75619SDan Williams memdev->region_id = 0; 10736bc75619SDan Williams memdev->range_index = 9+1; 10746bc75619SDan Williams memdev->region_index = 3+1; 10756bc75619SDan Williams memdev->region_size = 0; 10766bc75619SDan Williams memdev->region_offset = 0; 10776bc75619SDan Williams memdev->address = 0; 10786bc75619SDan Williams memdev->interleave_index = 0; 10796bc75619SDan Williams memdev->interleave_ways = 1; 10806bc75619SDan Williams 10816bc75619SDan Williams offset = offset + sizeof(struct acpi_nfit_memory_map) * 14; 10823b87356fSDan Williams /* dcr-descriptor0: blk */ 10836bc75619SDan Williams dcr = nfit_buf + offset; 10846bc75619SDan Williams dcr->header.type = ACPI_NFIT_TYPE_CONTROL_REGION; 10856bc75619SDan Williams dcr->header.length = sizeof(struct acpi_nfit_control_region); 10866bc75619SDan Williams dcr->region_index = 0+1; 10875dc68e55SDan Williams dcr_common_init(dcr); 10886bc75619SDan Williams dcr->serial_number = ~handle[0]; 1089be26f9aeSDan Williams dcr->code = NFIT_FIC_BLK; 10906bc75619SDan Williams dcr->windows = 1; 10916bc75619SDan Williams dcr->window_size = DCR_SIZE; 10926bc75619SDan Williams dcr->command_offset = 0; 10936bc75619SDan Williams dcr->command_size = 8; 10946bc75619SDan Williams dcr->status_offset = 8; 10956bc75619SDan Williams dcr->status_size = 4; 10966bc75619SDan Williams 10973b87356fSDan Williams /* dcr-descriptor1: blk */ 10986bc75619SDan Williams dcr = nfit_buf + offset + sizeof(struct acpi_nfit_control_region); 10996bc75619SDan Williams dcr->header.type = ACPI_NFIT_TYPE_CONTROL_REGION; 11006bc75619SDan Williams dcr->header.length = sizeof(struct acpi_nfit_control_region); 11016bc75619SDan Williams dcr->region_index = 1+1; 11025dc68e55SDan Williams dcr_common_init(dcr); 11036bc75619SDan Williams dcr->serial_number = ~handle[1]; 1104be26f9aeSDan Williams dcr->code = NFIT_FIC_BLK; 11056bc75619SDan Williams dcr->windows = 1; 11066bc75619SDan Williams dcr->window_size = DCR_SIZE; 11076bc75619SDan Williams dcr->command_offset = 0; 11086bc75619SDan Williams dcr->command_size = 8; 11096bc75619SDan Williams dcr->status_offset = 8; 11106bc75619SDan Williams dcr->status_size = 4; 11116bc75619SDan Williams 11123b87356fSDan Williams /* dcr-descriptor2: blk */ 11136bc75619SDan Williams dcr = nfit_buf + offset + sizeof(struct acpi_nfit_control_region) * 2; 11146bc75619SDan Williams dcr->header.type = ACPI_NFIT_TYPE_CONTROL_REGION; 11156bc75619SDan Williams dcr->header.length = sizeof(struct acpi_nfit_control_region); 11166bc75619SDan Williams dcr->region_index = 2+1; 11175dc68e55SDan Williams dcr_common_init(dcr); 11186bc75619SDan Williams dcr->serial_number = ~handle[2]; 1119be26f9aeSDan Williams dcr->code = NFIT_FIC_BLK; 11206bc75619SDan Williams dcr->windows = 1; 11216bc75619SDan Williams dcr->window_size = DCR_SIZE; 11226bc75619SDan Williams dcr->command_offset = 0; 11236bc75619SDan Williams dcr->command_size = 8; 11246bc75619SDan Williams dcr->status_offset = 8; 11256bc75619SDan Williams dcr->status_size = 4; 11266bc75619SDan Williams 11273b87356fSDan Williams /* dcr-descriptor3: blk */ 11286bc75619SDan Williams dcr = nfit_buf + offset + sizeof(struct acpi_nfit_control_region) * 3; 11296bc75619SDan Williams dcr->header.type = ACPI_NFIT_TYPE_CONTROL_REGION; 11306bc75619SDan Williams dcr->header.length = sizeof(struct acpi_nfit_control_region); 11316bc75619SDan Williams dcr->region_index = 3+1; 11325dc68e55SDan Williams dcr_common_init(dcr); 11336bc75619SDan Williams dcr->serial_number = ~handle[3]; 1134be26f9aeSDan Williams dcr->code = NFIT_FIC_BLK; 11356bc75619SDan Williams dcr->windows = 1; 11366bc75619SDan Williams dcr->window_size = DCR_SIZE; 11376bc75619SDan Williams dcr->command_offset = 0; 11386bc75619SDan Williams dcr->command_size = 8; 11396bc75619SDan Williams dcr->status_offset = 8; 11406bc75619SDan Williams dcr->status_size = 4; 11416bc75619SDan Williams 11426bc75619SDan Williams offset = offset + sizeof(struct acpi_nfit_control_region) * 4; 11433b87356fSDan Williams /* dcr-descriptor0: pmem */ 11443b87356fSDan Williams dcr = nfit_buf + offset; 11453b87356fSDan Williams dcr->header.type = ACPI_NFIT_TYPE_CONTROL_REGION; 11463b87356fSDan Williams dcr->header.length = offsetof(struct acpi_nfit_control_region, 11473b87356fSDan Williams window_size); 11483b87356fSDan Williams dcr->region_index = 4+1; 11495dc68e55SDan Williams dcr_common_init(dcr); 11503b87356fSDan Williams dcr->serial_number = ~handle[0]; 11513b87356fSDan Williams dcr->code = NFIT_FIC_BYTEN; 11523b87356fSDan Williams dcr->windows = 0; 11533b87356fSDan Williams 11543b87356fSDan Williams /* dcr-descriptor1: pmem */ 11553b87356fSDan Williams dcr = nfit_buf + offset + offsetof(struct acpi_nfit_control_region, 11563b87356fSDan Williams window_size); 11573b87356fSDan Williams dcr->header.type = ACPI_NFIT_TYPE_CONTROL_REGION; 11583b87356fSDan Williams dcr->header.length = offsetof(struct acpi_nfit_control_region, 11593b87356fSDan Williams window_size); 11603b87356fSDan Williams dcr->region_index = 5+1; 11615dc68e55SDan Williams dcr_common_init(dcr); 11623b87356fSDan Williams dcr->serial_number = ~handle[1]; 11633b87356fSDan Williams dcr->code = NFIT_FIC_BYTEN; 11643b87356fSDan Williams dcr->windows = 0; 11653b87356fSDan Williams 11663b87356fSDan Williams /* dcr-descriptor2: pmem */ 11673b87356fSDan Williams dcr = nfit_buf + offset + offsetof(struct acpi_nfit_control_region, 11683b87356fSDan Williams window_size) * 2; 11693b87356fSDan Williams dcr->header.type = ACPI_NFIT_TYPE_CONTROL_REGION; 11703b87356fSDan Williams dcr->header.length = offsetof(struct acpi_nfit_control_region, 11713b87356fSDan Williams window_size); 11723b87356fSDan Williams dcr->region_index = 6+1; 11735dc68e55SDan Williams dcr_common_init(dcr); 11743b87356fSDan Williams dcr->serial_number = ~handle[2]; 11753b87356fSDan Williams dcr->code = NFIT_FIC_BYTEN; 11763b87356fSDan Williams dcr->windows = 0; 11773b87356fSDan Williams 11783b87356fSDan Williams /* dcr-descriptor3: pmem */ 11793b87356fSDan Williams dcr = nfit_buf + offset + offsetof(struct acpi_nfit_control_region, 11803b87356fSDan Williams window_size) * 3; 11813b87356fSDan Williams dcr->header.type = ACPI_NFIT_TYPE_CONTROL_REGION; 11823b87356fSDan Williams dcr->header.length = offsetof(struct acpi_nfit_control_region, 11833b87356fSDan Williams window_size); 11843b87356fSDan Williams dcr->region_index = 7+1; 11855dc68e55SDan Williams dcr_common_init(dcr); 11863b87356fSDan Williams dcr->serial_number = ~handle[3]; 11873b87356fSDan Williams dcr->code = NFIT_FIC_BYTEN; 11883b87356fSDan Williams dcr->windows = 0; 11893b87356fSDan Williams 11903b87356fSDan Williams offset = offset + offsetof(struct acpi_nfit_control_region, 11913b87356fSDan Williams window_size) * 4; 11926bc75619SDan Williams /* bdw0 (spa/dcr0, dimm0) */ 11936bc75619SDan Williams bdw = nfit_buf + offset; 11946bc75619SDan Williams bdw->header.type = ACPI_NFIT_TYPE_DATA_REGION; 11956bc75619SDan Williams bdw->header.length = sizeof(struct acpi_nfit_data_region); 11966bc75619SDan Williams bdw->region_index = 0+1; 11976bc75619SDan Williams bdw->windows = 1; 11986bc75619SDan Williams bdw->offset = 0; 11996bc75619SDan Williams bdw->size = BDW_SIZE; 12006bc75619SDan Williams bdw->capacity = DIMM_SIZE; 12016bc75619SDan Williams bdw->start_address = 0; 12026bc75619SDan Williams 12036bc75619SDan Williams /* bdw1 (spa/dcr1, dimm1) */ 12046bc75619SDan Williams bdw = nfit_buf + offset + sizeof(struct acpi_nfit_data_region); 12056bc75619SDan Williams bdw->header.type = ACPI_NFIT_TYPE_DATA_REGION; 12066bc75619SDan Williams bdw->header.length = sizeof(struct acpi_nfit_data_region); 12076bc75619SDan Williams bdw->region_index = 1+1; 12086bc75619SDan Williams bdw->windows = 1; 12096bc75619SDan Williams bdw->offset = 0; 12106bc75619SDan Williams bdw->size = BDW_SIZE; 12116bc75619SDan Williams bdw->capacity = DIMM_SIZE; 12126bc75619SDan Williams bdw->start_address = 0; 12136bc75619SDan Williams 12146bc75619SDan Williams /* bdw2 (spa/dcr2, dimm2) */ 12156bc75619SDan Williams bdw = nfit_buf + offset + sizeof(struct acpi_nfit_data_region) * 2; 12166bc75619SDan Williams bdw->header.type = ACPI_NFIT_TYPE_DATA_REGION; 12176bc75619SDan Williams bdw->header.length = sizeof(struct acpi_nfit_data_region); 12186bc75619SDan Williams bdw->region_index = 2+1; 12196bc75619SDan Williams bdw->windows = 1; 12206bc75619SDan Williams bdw->offset = 0; 12216bc75619SDan Williams bdw->size = BDW_SIZE; 12226bc75619SDan Williams bdw->capacity = DIMM_SIZE; 12236bc75619SDan Williams bdw->start_address = 0; 12246bc75619SDan Williams 12256bc75619SDan Williams /* bdw3 (spa/dcr3, dimm3) */ 12266bc75619SDan Williams bdw = nfit_buf + offset + sizeof(struct acpi_nfit_data_region) * 3; 12276bc75619SDan Williams bdw->header.type = ACPI_NFIT_TYPE_DATA_REGION; 12286bc75619SDan Williams bdw->header.length = sizeof(struct acpi_nfit_data_region); 12296bc75619SDan Williams bdw->region_index = 3+1; 12306bc75619SDan Williams bdw->windows = 1; 12316bc75619SDan Williams bdw->offset = 0; 12326bc75619SDan Williams bdw->size = BDW_SIZE; 12336bc75619SDan Williams bdw->capacity = DIMM_SIZE; 12346bc75619SDan Williams bdw->start_address = 0; 12356bc75619SDan Williams 12369d27a87eSDan Williams offset = offset + sizeof(struct acpi_nfit_data_region) * 4; 12379d27a87eSDan Williams /* flush0 (dimm0) */ 12389d27a87eSDan Williams flush = nfit_buf + offset; 12399d27a87eSDan Williams flush->header.type = ACPI_NFIT_TYPE_FLUSH_ADDRESS; 124085d3fa02SDan Williams flush->header.length = flush_hint_size; 12419d27a87eSDan Williams flush->device_handle = handle[0]; 124285d3fa02SDan Williams flush->hint_count = NUM_HINTS; 124385d3fa02SDan Williams for (i = 0; i < NUM_HINTS; i++) 124485d3fa02SDan Williams flush->hint_address[i] = t->flush_dma[0] + i * sizeof(u64); 12459d27a87eSDan Williams 12469d27a87eSDan Williams /* flush1 (dimm1) */ 124785d3fa02SDan Williams flush = nfit_buf + offset + flush_hint_size * 1; 12489d27a87eSDan Williams flush->header.type = ACPI_NFIT_TYPE_FLUSH_ADDRESS; 124985d3fa02SDan Williams flush->header.length = flush_hint_size; 12509d27a87eSDan Williams flush->device_handle = handle[1]; 125185d3fa02SDan Williams flush->hint_count = NUM_HINTS; 125285d3fa02SDan Williams for (i = 0; i < NUM_HINTS; i++) 125385d3fa02SDan Williams flush->hint_address[i] = t->flush_dma[1] + i * sizeof(u64); 12549d27a87eSDan Williams 12559d27a87eSDan Williams /* flush2 (dimm2) */ 125685d3fa02SDan Williams flush = nfit_buf + offset + flush_hint_size * 2; 12579d27a87eSDan Williams flush->header.type = ACPI_NFIT_TYPE_FLUSH_ADDRESS; 125885d3fa02SDan Williams flush->header.length = flush_hint_size; 12599d27a87eSDan Williams flush->device_handle = handle[2]; 126085d3fa02SDan Williams flush->hint_count = NUM_HINTS; 126185d3fa02SDan Williams for (i = 0; i < NUM_HINTS; i++) 126285d3fa02SDan Williams flush->hint_address[i] = t->flush_dma[2] + i * sizeof(u64); 12639d27a87eSDan Williams 12649d27a87eSDan Williams /* flush3 (dimm3) */ 126585d3fa02SDan Williams flush = nfit_buf + offset + flush_hint_size * 3; 12669d27a87eSDan Williams flush->header.type = ACPI_NFIT_TYPE_FLUSH_ADDRESS; 126785d3fa02SDan Williams flush->header.length = flush_hint_size; 12689d27a87eSDan Williams flush->device_handle = handle[3]; 126985d3fa02SDan Williams flush->hint_count = NUM_HINTS; 127085d3fa02SDan Williams for (i = 0; i < NUM_HINTS; i++) 127185d3fa02SDan Williams flush->hint_address[i] = t->flush_dma[3] + i * sizeof(u64); 12729d27a87eSDan Williams 127320985164SVishal Verma if (t->setup_hotplug) { 127485d3fa02SDan Williams offset = offset + flush_hint_size * 4; 12753b87356fSDan Williams /* dcr-descriptor4: blk */ 127620985164SVishal Verma dcr = nfit_buf + offset; 127720985164SVishal Verma dcr->header.type = ACPI_NFIT_TYPE_CONTROL_REGION; 127820985164SVishal Verma dcr->header.length = sizeof(struct acpi_nfit_control_region); 12793b87356fSDan Williams dcr->region_index = 8+1; 12805dc68e55SDan Williams dcr_common_init(dcr); 128120985164SVishal Verma dcr->serial_number = ~handle[4]; 1282be26f9aeSDan Williams dcr->code = NFIT_FIC_BLK; 128320985164SVishal Verma dcr->windows = 1; 128420985164SVishal Verma dcr->window_size = DCR_SIZE; 128520985164SVishal Verma dcr->command_offset = 0; 128620985164SVishal Verma dcr->command_size = 8; 128720985164SVishal Verma dcr->status_offset = 8; 128820985164SVishal Verma dcr->status_size = 4; 128920985164SVishal Verma 129020985164SVishal Verma offset = offset + sizeof(struct acpi_nfit_control_region); 12913b87356fSDan Williams /* dcr-descriptor4: pmem */ 12923b87356fSDan Williams dcr = nfit_buf + offset; 12933b87356fSDan Williams dcr->header.type = ACPI_NFIT_TYPE_CONTROL_REGION; 12943b87356fSDan Williams dcr->header.length = offsetof(struct acpi_nfit_control_region, 12953b87356fSDan Williams window_size); 12963b87356fSDan Williams dcr->region_index = 9+1; 12975dc68e55SDan Williams dcr_common_init(dcr); 12983b87356fSDan Williams dcr->serial_number = ~handle[4]; 12993b87356fSDan Williams dcr->code = NFIT_FIC_BYTEN; 13003b87356fSDan Williams dcr->windows = 0; 13013b87356fSDan Williams 13023b87356fSDan Williams offset = offset + offsetof(struct acpi_nfit_control_region, 13033b87356fSDan Williams window_size); 130420985164SVishal Verma /* bdw4 (spa/dcr4, dimm4) */ 130520985164SVishal Verma bdw = nfit_buf + offset; 130620985164SVishal Verma bdw->header.type = ACPI_NFIT_TYPE_DATA_REGION; 130720985164SVishal Verma bdw->header.length = sizeof(struct acpi_nfit_data_region); 13083b87356fSDan Williams bdw->region_index = 8+1; 130920985164SVishal Verma bdw->windows = 1; 131020985164SVishal Verma bdw->offset = 0; 131120985164SVishal Verma bdw->size = BDW_SIZE; 131220985164SVishal Verma bdw->capacity = DIMM_SIZE; 131320985164SVishal Verma bdw->start_address = 0; 131420985164SVishal Verma 131520985164SVishal Verma offset = offset + sizeof(struct acpi_nfit_data_region); 131620985164SVishal Verma /* spa10 (dcr4) dimm4 */ 131720985164SVishal Verma spa = nfit_buf + offset; 131820985164SVishal Verma spa->header.type = ACPI_NFIT_TYPE_SYSTEM_ADDRESS; 131920985164SVishal Verma spa->header.length = sizeof(*spa); 132020985164SVishal Verma memcpy(spa->range_guid, to_nfit_uuid(NFIT_SPA_DCR), 16); 132120985164SVishal Verma spa->range_index = 10+1; 132220985164SVishal Verma spa->address = t->dcr_dma[4]; 132320985164SVishal Verma spa->length = DCR_SIZE; 132420985164SVishal Verma 132520985164SVishal Verma /* 132620985164SVishal Verma * spa11 (single-dimm interleave for hotplug, note storage 132720985164SVishal Verma * does not actually alias the related block-data-window 132820985164SVishal Verma * regions) 132920985164SVishal Verma */ 133020985164SVishal Verma spa = nfit_buf + offset + sizeof(*spa); 133120985164SVishal Verma spa->header.type = ACPI_NFIT_TYPE_SYSTEM_ADDRESS; 133220985164SVishal Verma spa->header.length = sizeof(*spa); 133320985164SVishal Verma memcpy(spa->range_guid, to_nfit_uuid(NFIT_SPA_PM), 16); 133420985164SVishal Verma spa->range_index = 11+1; 133520985164SVishal Verma spa->address = t->spa_set_dma[2]; 133620985164SVishal Verma spa->length = SPA0_SIZE; 133720985164SVishal Verma 133820985164SVishal Verma /* spa12 (bdw for dcr4) dimm4 */ 133920985164SVishal Verma spa = nfit_buf + offset + sizeof(*spa) * 2; 134020985164SVishal Verma spa->header.type = ACPI_NFIT_TYPE_SYSTEM_ADDRESS; 134120985164SVishal Verma spa->header.length = sizeof(*spa); 134220985164SVishal Verma memcpy(spa->range_guid, to_nfit_uuid(NFIT_SPA_BDW), 16); 134320985164SVishal Verma spa->range_index = 12+1; 134420985164SVishal Verma spa->address = t->dimm_dma[4]; 134520985164SVishal Verma spa->length = DIMM_SIZE; 134620985164SVishal Verma 134720985164SVishal Verma offset = offset + sizeof(*spa) * 3; 134820985164SVishal Verma /* mem-region14 (spa/dcr4, dimm4) */ 134920985164SVishal Verma memdev = nfit_buf + offset; 135020985164SVishal Verma memdev->header.type = ACPI_NFIT_TYPE_MEMORY_MAP; 135120985164SVishal Verma memdev->header.length = sizeof(*memdev); 135220985164SVishal Verma memdev->device_handle = handle[4]; 135320985164SVishal Verma memdev->physical_id = 4; 135420985164SVishal Verma memdev->region_id = 0; 135520985164SVishal Verma memdev->range_index = 10+1; 13563b87356fSDan Williams memdev->region_index = 8+1; 135720985164SVishal Verma memdev->region_size = 0; 135820985164SVishal Verma memdev->region_offset = 0; 135920985164SVishal Verma memdev->address = 0; 136020985164SVishal Verma memdev->interleave_index = 0; 136120985164SVishal Verma memdev->interleave_ways = 1; 136220985164SVishal Verma 136320985164SVishal Verma /* mem-region15 (spa0, dimm4) */ 136420985164SVishal Verma memdev = nfit_buf + offset + 136520985164SVishal Verma sizeof(struct acpi_nfit_memory_map); 136620985164SVishal Verma memdev->header.type = ACPI_NFIT_TYPE_MEMORY_MAP; 136720985164SVishal Verma memdev->header.length = sizeof(*memdev); 136820985164SVishal Verma memdev->device_handle = handle[4]; 136920985164SVishal Verma memdev->physical_id = 4; 137020985164SVishal Verma memdev->region_id = 0; 137120985164SVishal Verma memdev->range_index = 11+1; 13723b87356fSDan Williams memdev->region_index = 9+1; 137320985164SVishal Verma memdev->region_size = SPA0_SIZE; 137420985164SVishal Verma memdev->region_offset = t->spa_set_dma[2]; 137520985164SVishal Verma memdev->address = 0; 137620985164SVishal Verma memdev->interleave_index = 0; 137720985164SVishal Verma memdev->interleave_ways = 1; 137820985164SVishal Verma 13793b87356fSDan Williams /* mem-region16 (spa/bdw4, dimm4) */ 138020985164SVishal Verma memdev = nfit_buf + offset + 138120985164SVishal Verma sizeof(struct acpi_nfit_memory_map) * 2; 138220985164SVishal Verma memdev->header.type = ACPI_NFIT_TYPE_MEMORY_MAP; 138320985164SVishal Verma memdev->header.length = sizeof(*memdev); 138420985164SVishal Verma memdev->device_handle = handle[4]; 138520985164SVishal Verma memdev->physical_id = 4; 138620985164SVishal Verma memdev->region_id = 0; 138720985164SVishal Verma memdev->range_index = 12+1; 13883b87356fSDan Williams memdev->region_index = 8+1; 138920985164SVishal Verma memdev->region_size = 0; 139020985164SVishal Verma memdev->region_offset = 0; 139120985164SVishal Verma memdev->address = 0; 139220985164SVishal Verma memdev->interleave_index = 0; 139320985164SVishal Verma memdev->interleave_ways = 1; 139420985164SVishal Verma 139520985164SVishal Verma offset = offset + sizeof(struct acpi_nfit_memory_map) * 3; 139620985164SVishal Verma /* flush3 (dimm4) */ 139720985164SVishal Verma flush = nfit_buf + offset; 139820985164SVishal Verma flush->header.type = ACPI_NFIT_TYPE_FLUSH_ADDRESS; 139985d3fa02SDan Williams flush->header.length = flush_hint_size; 140020985164SVishal Verma flush->device_handle = handle[4]; 140185d3fa02SDan Williams flush->hint_count = NUM_HINTS; 140285d3fa02SDan Williams for (i = 0; i < NUM_HINTS; i++) 140385d3fa02SDan Williams flush->hint_address[i] = t->flush_dma[4] 140485d3fa02SDan Williams + i * sizeof(u64); 140520985164SVishal Verma } 140620985164SVishal Verma 1407f471f1a7SDan Williams post_ars_status(&t->ars_state, t->spa_set_dma[0], SPA0_SIZE); 1408f471f1a7SDan Williams 14096bc75619SDan Williams acpi_desc = &t->acpi_desc; 1410e3654ecaSDan Williams set_bit(ND_CMD_GET_CONFIG_SIZE, &acpi_desc->dimm_cmd_force_en); 1411e3654ecaSDan Williams set_bit(ND_CMD_GET_CONFIG_DATA, &acpi_desc->dimm_cmd_force_en); 1412e3654ecaSDan Williams set_bit(ND_CMD_SET_CONFIG_DATA, &acpi_desc->dimm_cmd_force_en); 14131f716d05SDan Williams set_bit(ND_CMD_SMART, &acpi_desc->dimm_cmd_force_en); 1414e3654ecaSDan Williams set_bit(ND_CMD_ARS_CAP, &acpi_desc->bus_cmd_force_en); 1415e3654ecaSDan Williams set_bit(ND_CMD_ARS_START, &acpi_desc->bus_cmd_force_en); 1416e3654ecaSDan Williams set_bit(ND_CMD_ARS_STATUS, &acpi_desc->bus_cmd_force_en); 1417e3654ecaSDan Williams set_bit(ND_CMD_CLEAR_ERROR, &acpi_desc->bus_cmd_force_en); 14181f716d05SDan Williams set_bit(ND_CMD_SMART_THRESHOLD, &acpi_desc->dimm_cmd_force_en); 14196bc75619SDan Williams } 14206bc75619SDan Williams 14216bc75619SDan Williams static void nfit_test1_setup(struct nfit_test *t) 14226bc75619SDan Williams { 14236b577c9dSLinda Knippers size_t offset; 14246bc75619SDan Williams void *nfit_buf = t->nfit_buf; 14256bc75619SDan Williams struct acpi_nfit_memory_map *memdev; 14266bc75619SDan Williams struct acpi_nfit_control_region *dcr; 14276bc75619SDan Williams struct acpi_nfit_system_address *spa; 1428d26f73f0SDan Williams struct acpi_nfit_desc *acpi_desc; 14296bc75619SDan Williams 14306b577c9dSLinda Knippers offset = 0; 14316bc75619SDan Williams /* spa0 (flat range with no bdw aliasing) */ 14326bc75619SDan Williams spa = nfit_buf + offset; 14336bc75619SDan Williams spa->header.type = ACPI_NFIT_TYPE_SYSTEM_ADDRESS; 14346bc75619SDan Williams spa->header.length = sizeof(*spa); 14356bc75619SDan Williams memcpy(spa->range_guid, to_nfit_uuid(NFIT_SPA_PM), 16); 14366bc75619SDan Williams spa->range_index = 0+1; 14376bc75619SDan Williams spa->address = t->spa_set_dma[0]; 14386bc75619SDan Williams spa->length = SPA2_SIZE; 14396bc75619SDan Williams 14407bfe97c7SDan Williams /* virtual cd region */ 14417bfe97c7SDan Williams spa = nfit_buf + sizeof(*spa); 14427bfe97c7SDan Williams spa->header.type = ACPI_NFIT_TYPE_SYSTEM_ADDRESS; 14437bfe97c7SDan Williams spa->header.length = sizeof(*spa); 14447bfe97c7SDan Williams memcpy(spa->range_guid, to_nfit_uuid(NFIT_SPA_VCD), 16); 14457bfe97c7SDan Williams spa->range_index = 0; 14467bfe97c7SDan Williams spa->address = t->spa_set_dma[1]; 14477bfe97c7SDan Williams spa->length = SPA_VCD_SIZE; 14487bfe97c7SDan Williams 14497bfe97c7SDan Williams offset += sizeof(*spa) * 2; 14506bc75619SDan Williams /* mem-region0 (spa0, dimm0) */ 14516bc75619SDan Williams memdev = nfit_buf + offset; 14526bc75619SDan Williams memdev->header.type = ACPI_NFIT_TYPE_MEMORY_MAP; 14536bc75619SDan Williams memdev->header.length = sizeof(*memdev); 14546bc75619SDan Williams memdev->device_handle = 0; 14556bc75619SDan Williams memdev->physical_id = 0; 14566bc75619SDan Williams memdev->region_id = 0; 14576bc75619SDan Williams memdev->range_index = 0+1; 14586bc75619SDan Williams memdev->region_index = 0+1; 14596bc75619SDan Williams memdev->region_size = SPA2_SIZE; 14606bc75619SDan Williams memdev->region_offset = 0; 14616bc75619SDan Williams memdev->address = 0; 14626bc75619SDan Williams memdev->interleave_index = 0; 14636bc75619SDan Williams memdev->interleave_ways = 1; 146458138820SDan Williams memdev->flags = ACPI_NFIT_MEM_SAVE_FAILED | ACPI_NFIT_MEM_RESTORE_FAILED 146558138820SDan Williams | ACPI_NFIT_MEM_FLUSH_FAILED | ACPI_NFIT_MEM_HEALTH_OBSERVED 1466f4295796SDan Williams | ACPI_NFIT_MEM_NOT_ARMED; 14676bc75619SDan Williams 14686bc75619SDan Williams offset += sizeof(*memdev); 14696bc75619SDan Williams /* dcr-descriptor0 */ 14706bc75619SDan Williams dcr = nfit_buf + offset; 14716bc75619SDan Williams dcr->header.type = ACPI_NFIT_TYPE_CONTROL_REGION; 14723b87356fSDan Williams dcr->header.length = offsetof(struct acpi_nfit_control_region, 14733b87356fSDan Williams window_size); 14746bc75619SDan Williams dcr->region_index = 0+1; 14755dc68e55SDan Williams dcr_common_init(dcr); 14766bc75619SDan Williams dcr->serial_number = ~0; 1477be26f9aeSDan Williams dcr->code = NFIT_FIC_BYTE; 14786bc75619SDan Williams dcr->windows = 0; 1479d26f73f0SDan Williams 1480f471f1a7SDan Williams post_ars_status(&t->ars_state, t->spa_set_dma[0], SPA2_SIZE); 1481f471f1a7SDan Williams 1482d26f73f0SDan Williams acpi_desc = &t->acpi_desc; 1483e3654ecaSDan Williams set_bit(ND_CMD_ARS_CAP, &acpi_desc->bus_cmd_force_en); 1484e3654ecaSDan Williams set_bit(ND_CMD_ARS_START, &acpi_desc->bus_cmd_force_en); 1485e3654ecaSDan Williams set_bit(ND_CMD_ARS_STATUS, &acpi_desc->bus_cmd_force_en); 1486e3654ecaSDan Williams set_bit(ND_CMD_CLEAR_ERROR, &acpi_desc->bus_cmd_force_en); 14876bc75619SDan Williams } 14886bc75619SDan Williams 14896bc75619SDan Williams static int nfit_test_blk_do_io(struct nd_blk_region *ndbr, resource_size_t dpa, 14906bc75619SDan Williams void *iobuf, u64 len, int rw) 14916bc75619SDan Williams { 14926bc75619SDan Williams struct nfit_blk *nfit_blk = ndbr->blk_provider_data; 14936bc75619SDan Williams struct nfit_blk_mmio *mmio = &nfit_blk->mmio[BDW]; 14946bc75619SDan Williams struct nd_region *nd_region = &ndbr->nd_region; 14956bc75619SDan Williams unsigned int lane; 14966bc75619SDan Williams 14976bc75619SDan Williams lane = nd_region_acquire_lane(nd_region); 14986bc75619SDan Williams if (rw) 149967a3e8feSRoss Zwisler memcpy(mmio->addr.base + dpa, iobuf, len); 150067a3e8feSRoss Zwisler else { 150167a3e8feSRoss Zwisler memcpy(iobuf, mmio->addr.base + dpa, len); 150267a3e8feSRoss Zwisler 150367a3e8feSRoss Zwisler /* give us some some coverage of the mmio_flush_range() API */ 150467a3e8feSRoss Zwisler mmio_flush_range(mmio->addr.base + dpa, len); 150567a3e8feSRoss Zwisler } 15066bc75619SDan Williams nd_region_release_lane(nd_region, lane); 15076bc75619SDan Williams 15086bc75619SDan Williams return 0; 15096bc75619SDan Williams } 15106bc75619SDan Williams 15116bc75619SDan Williams static int nfit_test_probe(struct platform_device *pdev) 15126bc75619SDan Williams { 15136bc75619SDan Williams struct nvdimm_bus_descriptor *nd_desc; 15146bc75619SDan Williams struct acpi_nfit_desc *acpi_desc; 15156bc75619SDan Williams struct device *dev = &pdev->dev; 15166bc75619SDan Williams struct nfit_test *nfit_test; 1517231bf117SDan Williams struct nfit_mem *nfit_mem; 1518c14a868aSDan Williams union acpi_object *obj; 15196bc75619SDan Williams int rc; 15206bc75619SDan Williams 15216bc75619SDan Williams nfit_test = to_nfit_test(&pdev->dev); 15226bc75619SDan Williams 15236bc75619SDan Williams /* common alloc */ 15246bc75619SDan Williams if (nfit_test->num_dcr) { 15256bc75619SDan Williams int num = nfit_test->num_dcr; 15266bc75619SDan Williams 15276bc75619SDan Williams nfit_test->dimm = devm_kcalloc(dev, num, sizeof(void *), 15286bc75619SDan Williams GFP_KERNEL); 15296bc75619SDan Williams nfit_test->dimm_dma = devm_kcalloc(dev, num, sizeof(dma_addr_t), 15306bc75619SDan Williams GFP_KERNEL); 15319d27a87eSDan Williams nfit_test->flush = devm_kcalloc(dev, num, sizeof(void *), 15329d27a87eSDan Williams GFP_KERNEL); 15339d27a87eSDan Williams nfit_test->flush_dma = devm_kcalloc(dev, num, sizeof(dma_addr_t), 15349d27a87eSDan Williams GFP_KERNEL); 15356bc75619SDan Williams nfit_test->label = devm_kcalloc(dev, num, sizeof(void *), 15366bc75619SDan Williams GFP_KERNEL); 15376bc75619SDan Williams nfit_test->label_dma = devm_kcalloc(dev, num, 15386bc75619SDan Williams sizeof(dma_addr_t), GFP_KERNEL); 15396bc75619SDan Williams nfit_test->dcr = devm_kcalloc(dev, num, 15406bc75619SDan Williams sizeof(struct nfit_test_dcr *), GFP_KERNEL); 15416bc75619SDan Williams nfit_test->dcr_dma = devm_kcalloc(dev, num, 15426bc75619SDan Williams sizeof(dma_addr_t), GFP_KERNEL); 15436bc75619SDan Williams if (nfit_test->dimm && nfit_test->dimm_dma && nfit_test->label 15446bc75619SDan Williams && nfit_test->label_dma && nfit_test->dcr 15459d27a87eSDan Williams && nfit_test->dcr_dma && nfit_test->flush 15469d27a87eSDan Williams && nfit_test->flush_dma) 15476bc75619SDan Williams /* pass */; 15486bc75619SDan Williams else 15496bc75619SDan Williams return -ENOMEM; 15506bc75619SDan Williams } 15516bc75619SDan Williams 15526bc75619SDan Williams if (nfit_test->num_pm) { 15536bc75619SDan Williams int num = nfit_test->num_pm; 15546bc75619SDan Williams 15556bc75619SDan Williams nfit_test->spa_set = devm_kcalloc(dev, num, sizeof(void *), 15566bc75619SDan Williams GFP_KERNEL); 15576bc75619SDan Williams nfit_test->spa_set_dma = devm_kcalloc(dev, num, 15586bc75619SDan Williams sizeof(dma_addr_t), GFP_KERNEL); 15596bc75619SDan Williams if (nfit_test->spa_set && nfit_test->spa_set_dma) 15606bc75619SDan Williams /* pass */; 15616bc75619SDan Williams else 15626bc75619SDan Williams return -ENOMEM; 15636bc75619SDan Williams } 15646bc75619SDan Williams 15656bc75619SDan Williams /* per-nfit specific alloc */ 15666bc75619SDan Williams if (nfit_test->alloc(nfit_test)) 15676bc75619SDan Williams return -ENOMEM; 15686bc75619SDan Williams 15696bc75619SDan Williams nfit_test->setup(nfit_test); 15706bc75619SDan Williams acpi_desc = &nfit_test->acpi_desc; 1571a61fe6f7SDan Williams acpi_nfit_desc_init(acpi_desc, &pdev->dev); 15726bc75619SDan Williams acpi_desc->blk_do_io = nfit_test_blk_do_io; 15736bc75619SDan Williams nd_desc = &acpi_desc->nd_desc; 1574a61fe6f7SDan Williams nd_desc->provider_name = NULL; 1575bc9775d8SDan Williams nd_desc->module = THIS_MODULE; 1576a61fe6f7SDan Williams nd_desc->ndctl = nfit_test_ctl; 15776bc75619SDan Williams 1578e7a11b44SDan Williams rc = acpi_nfit_init(acpi_desc, nfit_test->nfit_buf, 1579e7a11b44SDan Williams nfit_test->nfit_size); 158058cd71b4SDan Williams if (rc) 158120985164SVishal Verma return rc; 158220985164SVishal Verma 158320985164SVishal Verma if (nfit_test->setup != nfit_test0_setup) 158420985164SVishal Verma return 0; 158520985164SVishal Verma 158620985164SVishal Verma nfit_test->setup_hotplug = 1; 158720985164SVishal Verma nfit_test->setup(nfit_test); 158820985164SVishal Verma 1589c14a868aSDan Williams obj = kzalloc(sizeof(*obj), GFP_KERNEL); 1590c14a868aSDan Williams if (!obj) 1591c14a868aSDan Williams return -ENOMEM; 1592c14a868aSDan Williams obj->type = ACPI_TYPE_BUFFER; 1593c14a868aSDan Williams obj->buffer.length = nfit_test->nfit_size; 1594c14a868aSDan Williams obj->buffer.pointer = nfit_test->nfit_buf; 1595c14a868aSDan Williams *(nfit_test->_fit) = obj; 1596c14a868aSDan Williams __acpi_nfit_notify(&pdev->dev, nfit_test, 0x80); 1597231bf117SDan Williams 1598231bf117SDan Williams /* associate dimm devices with nfit_mem data for notification testing */ 1599231bf117SDan Williams mutex_lock(&acpi_desc->init_mutex); 1600231bf117SDan Williams list_for_each_entry(nfit_mem, &acpi_desc->dimms, list) { 1601231bf117SDan Williams u32 nfit_handle = __to_nfit_memdev(nfit_mem)->device_handle; 1602231bf117SDan Williams int i; 1603231bf117SDan Williams 1604231bf117SDan Williams for (i = 0; i < NUM_DCR; i++) 1605231bf117SDan Williams if (nfit_handle == handle[i]) 1606231bf117SDan Williams dev_set_drvdata(nfit_test->dimm_dev[i], 1607231bf117SDan Williams nfit_mem); 1608231bf117SDan Williams } 1609231bf117SDan Williams mutex_unlock(&acpi_desc->init_mutex); 1610231bf117SDan Williams 16116bc75619SDan Williams return 0; 16126bc75619SDan Williams } 16136bc75619SDan Williams 16146bc75619SDan Williams static int nfit_test_remove(struct platform_device *pdev) 16156bc75619SDan Williams { 16166bc75619SDan Williams return 0; 16176bc75619SDan Williams } 16186bc75619SDan Williams 16196bc75619SDan Williams static void nfit_test_release(struct device *dev) 16206bc75619SDan Williams { 16216bc75619SDan Williams struct nfit_test *nfit_test = to_nfit_test(dev); 16226bc75619SDan Williams 16236bc75619SDan Williams kfree(nfit_test); 16246bc75619SDan Williams } 16256bc75619SDan Williams 16266bc75619SDan Williams static const struct platform_device_id nfit_test_id[] = { 16276bc75619SDan Williams { KBUILD_MODNAME }, 16286bc75619SDan Williams { }, 16296bc75619SDan Williams }; 16306bc75619SDan Williams 16316bc75619SDan Williams static struct platform_driver nfit_test_driver = { 16326bc75619SDan Williams .probe = nfit_test_probe, 16336bc75619SDan Williams .remove = nfit_test_remove, 16346bc75619SDan Williams .driver = { 16356bc75619SDan Williams .name = KBUILD_MODNAME, 16366bc75619SDan Williams }, 16376bc75619SDan Williams .id_table = nfit_test_id, 16386bc75619SDan Williams }; 16396bc75619SDan Williams 16406bc75619SDan Williams static __init int nfit_test_init(void) 16416bc75619SDan Williams { 16426bc75619SDan Williams int rc, i; 16436bc75619SDan Williams 1644231bf117SDan Williams nfit_test_dimm = class_create(THIS_MODULE, "nfit_test_dimm"); 1645231bf117SDan Williams if (IS_ERR(nfit_test_dimm)) 1646231bf117SDan Williams return PTR_ERR(nfit_test_dimm); 1647231bf117SDan Williams 16486bc75619SDan Williams nfit_test_setup(nfit_test_lookup); 16496bc75619SDan Williams 16506bc75619SDan Williams for (i = 0; i < NUM_NFITS; i++) { 16516bc75619SDan Williams struct nfit_test *nfit_test; 16526bc75619SDan Williams struct platform_device *pdev; 16536bc75619SDan Williams 16546bc75619SDan Williams nfit_test = kzalloc(sizeof(*nfit_test), GFP_KERNEL); 16556bc75619SDan Williams if (!nfit_test) { 16566bc75619SDan Williams rc = -ENOMEM; 16576bc75619SDan Williams goto err_register; 16586bc75619SDan Williams } 16596bc75619SDan Williams INIT_LIST_HEAD(&nfit_test->resources); 16606bc75619SDan Williams switch (i) { 16616bc75619SDan Williams case 0: 16626bc75619SDan Williams nfit_test->num_pm = NUM_PM; 16636bc75619SDan Williams nfit_test->num_dcr = NUM_DCR; 16646bc75619SDan Williams nfit_test->alloc = nfit_test0_alloc; 16656bc75619SDan Williams nfit_test->setup = nfit_test0_setup; 16666bc75619SDan Williams break; 16676bc75619SDan Williams case 1: 16686bc75619SDan Williams nfit_test->num_pm = 1; 16696bc75619SDan Williams nfit_test->alloc = nfit_test1_alloc; 16706bc75619SDan Williams nfit_test->setup = nfit_test1_setup; 16716bc75619SDan Williams break; 16726bc75619SDan Williams default: 16736bc75619SDan Williams rc = -EINVAL; 16746bc75619SDan Williams goto err_register; 16756bc75619SDan Williams } 16766bc75619SDan Williams pdev = &nfit_test->pdev; 16776bc75619SDan Williams pdev->name = KBUILD_MODNAME; 16786bc75619SDan Williams pdev->id = i; 16796bc75619SDan Williams pdev->dev.release = nfit_test_release; 16806bc75619SDan Williams rc = platform_device_register(pdev); 16816bc75619SDan Williams if (rc) { 16826bc75619SDan Williams put_device(&pdev->dev); 16836bc75619SDan Williams goto err_register; 16846bc75619SDan Williams } 16856bc75619SDan Williams 16866bc75619SDan Williams rc = dma_coerce_mask_and_coherent(&pdev->dev, DMA_BIT_MASK(64)); 16876bc75619SDan Williams if (rc) 16886bc75619SDan Williams goto err_register; 16896bc75619SDan Williams 16906bc75619SDan Williams instances[i] = nfit_test; 16916bc75619SDan Williams } 16926bc75619SDan Williams 16936bc75619SDan Williams rc = platform_driver_register(&nfit_test_driver); 16946bc75619SDan Williams if (rc) 16956bc75619SDan Williams goto err_register; 16966bc75619SDan Williams return 0; 16976bc75619SDan Williams 16986bc75619SDan Williams err_register: 16996bc75619SDan Williams for (i = 0; i < NUM_NFITS; i++) 17006bc75619SDan Williams if (instances[i]) 17016bc75619SDan Williams platform_device_unregister(&instances[i]->pdev); 17026bc75619SDan Williams nfit_test_teardown(); 17036bc75619SDan Williams return rc; 17046bc75619SDan Williams } 17056bc75619SDan Williams 17066bc75619SDan Williams static __exit void nfit_test_exit(void) 17076bc75619SDan Williams { 17086bc75619SDan Williams int i; 17096bc75619SDan Williams 17106bc75619SDan Williams platform_driver_unregister(&nfit_test_driver); 17116bc75619SDan Williams for (i = 0; i < NUM_NFITS; i++) 17126bc75619SDan Williams platform_device_unregister(&instances[i]->pdev); 17136bc75619SDan Williams nfit_test_teardown(); 1714231bf117SDan Williams class_destroy(nfit_test_dimm); 17156bc75619SDan Williams } 17166bc75619SDan Williams 17176bc75619SDan Williams module_init(nfit_test_init); 17186bc75619SDan Williams module_exit(nfit_test_exit); 17196bc75619SDan Williams MODULE_LICENSE("GPL v2"); 17206bc75619SDan Williams MODULE_AUTHOR("Intel Corporation"); 1721