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]; 171*ed07c433SDan Williams struct nd_intel_smart *smart; 172*ed07c433SDan Williams struct nd_intel_smart_threshold *smart_threshold; 1739fb1a190SDave Jiang struct badrange badrange; 1749fb1a190SDave Jiang struct work_struct work; 1756bc75619SDan Williams }; 1766bc75619SDan Williams 1779fb1a190SDave Jiang static struct workqueue_struct *nfit_wq; 1789fb1a190SDave Jiang 1796bc75619SDan Williams static struct nfit_test *to_nfit_test(struct device *dev) 1806bc75619SDan Williams { 1816bc75619SDan Williams struct platform_device *pdev = to_platform_device(dev); 1826bc75619SDan Williams 1836bc75619SDan Williams return container_of(pdev, struct nfit_test, pdev); 1846bc75619SDan Williams } 1856bc75619SDan Williams 18639c686b8SVishal Verma static int nfit_test_cmd_get_config_size(struct nd_cmd_get_config_size *nd_cmd, 1876bc75619SDan Williams unsigned int buf_len) 1886bc75619SDan Williams { 1896bc75619SDan Williams if (buf_len < sizeof(*nd_cmd)) 1906bc75619SDan Williams return -EINVAL; 19139c686b8SVishal Verma 1926bc75619SDan Williams nd_cmd->status = 0; 1936bc75619SDan Williams nd_cmd->config_size = LABEL_SIZE; 1946bc75619SDan Williams nd_cmd->max_xfer = SZ_4K; 19539c686b8SVishal Verma 19639c686b8SVishal Verma return 0; 1976bc75619SDan Williams } 19839c686b8SVishal Verma 19939c686b8SVishal Verma static int nfit_test_cmd_get_config_data(struct nd_cmd_get_config_data_hdr 20039c686b8SVishal Verma *nd_cmd, unsigned int buf_len, void *label) 20139c686b8SVishal Verma { 2026bc75619SDan Williams unsigned int len, offset = nd_cmd->in_offset; 20339c686b8SVishal Verma int rc; 2046bc75619SDan Williams 2056bc75619SDan Williams if (buf_len < sizeof(*nd_cmd)) 2066bc75619SDan Williams return -EINVAL; 2076bc75619SDan Williams if (offset >= LABEL_SIZE) 2086bc75619SDan Williams return -EINVAL; 2096bc75619SDan Williams if (nd_cmd->in_length + sizeof(*nd_cmd) > buf_len) 2106bc75619SDan Williams return -EINVAL; 2116bc75619SDan Williams 2126bc75619SDan Williams nd_cmd->status = 0; 2136bc75619SDan Williams len = min(nd_cmd->in_length, LABEL_SIZE - offset); 21439c686b8SVishal Verma memcpy(nd_cmd->out_buf, label + offset, len); 2156bc75619SDan Williams rc = buf_len - sizeof(*nd_cmd) - len; 21639c686b8SVishal Verma 21739c686b8SVishal Verma return rc; 2186bc75619SDan Williams } 21939c686b8SVishal Verma 22039c686b8SVishal Verma static int nfit_test_cmd_set_config_data(struct nd_cmd_set_config_hdr *nd_cmd, 22139c686b8SVishal Verma unsigned int buf_len, void *label) 22239c686b8SVishal Verma { 2236bc75619SDan Williams unsigned int len, offset = nd_cmd->in_offset; 2246bc75619SDan Williams u32 *status; 22539c686b8SVishal Verma int rc; 2266bc75619SDan Williams 2276bc75619SDan Williams if (buf_len < sizeof(*nd_cmd)) 2286bc75619SDan Williams return -EINVAL; 2296bc75619SDan Williams if (offset >= LABEL_SIZE) 2306bc75619SDan Williams return -EINVAL; 2316bc75619SDan Williams if (nd_cmd->in_length + sizeof(*nd_cmd) + 4 > buf_len) 2326bc75619SDan Williams return -EINVAL; 2336bc75619SDan Williams 23439c686b8SVishal Verma status = (void *)nd_cmd + nd_cmd->in_length + sizeof(*nd_cmd); 2356bc75619SDan Williams *status = 0; 2366bc75619SDan Williams len = min(nd_cmd->in_length, LABEL_SIZE - offset); 23739c686b8SVishal Verma memcpy(label + offset, nd_cmd->in_buf, len); 2386bc75619SDan Williams rc = buf_len - sizeof(*nd_cmd) - (len + 4); 23939c686b8SVishal Verma 24039c686b8SVishal Verma return rc; 2416bc75619SDan Williams } 24239c686b8SVishal Verma 243d4f32367SDan Williams #define NFIT_TEST_CLEAR_ERR_UNIT 256 244747ffe11SDan Williams 24539c686b8SVishal Verma static int nfit_test_cmd_ars_cap(struct nd_cmd_ars_cap *nd_cmd, 24639c686b8SVishal Verma unsigned int buf_len) 24739c686b8SVishal Verma { 2489fb1a190SDave Jiang int ars_recs; 2499fb1a190SDave Jiang 25039c686b8SVishal Verma if (buf_len < sizeof(*nd_cmd)) 25139c686b8SVishal Verma return -EINVAL; 25239c686b8SVishal Verma 2539fb1a190SDave Jiang /* for testing, only store up to n records that fit within 4k */ 2549fb1a190SDave Jiang ars_recs = SZ_4K / sizeof(struct nd_ars_record); 2559fb1a190SDave Jiang 256747ffe11SDan Williams nd_cmd->max_ars_out = sizeof(struct nd_cmd_ars_status) 2579fb1a190SDave Jiang + ars_recs * sizeof(struct nd_ars_record); 25839c686b8SVishal Verma nd_cmd->status = (ND_ARS_PERSISTENT | ND_ARS_VOLATILE) << 16; 259d4f32367SDan Williams nd_cmd->clear_err_unit = NFIT_TEST_CLEAR_ERR_UNIT; 26039c686b8SVishal Verma 26139c686b8SVishal Verma return 0; 26239c686b8SVishal Verma } 26339c686b8SVishal Verma 2649fb1a190SDave Jiang static void post_ars_status(struct ars_state *ars_state, 2659fb1a190SDave Jiang struct badrange *badrange, u64 addr, u64 len) 26639c686b8SVishal Verma { 267f471f1a7SDan Williams struct nd_cmd_ars_status *ars_status; 268f471f1a7SDan Williams struct nd_ars_record *ars_record; 2699fb1a190SDave Jiang struct badrange_entry *be; 2709fb1a190SDave Jiang u64 end = addr + len - 1; 2719fb1a190SDave Jiang int i = 0; 272f471f1a7SDan Williams 273f471f1a7SDan Williams ars_state->deadline = jiffies + 1*HZ; 274f471f1a7SDan Williams ars_status = ars_state->ars_status; 275f471f1a7SDan Williams ars_status->status = 0; 276f471f1a7SDan Williams ars_status->address = addr; 277f471f1a7SDan Williams ars_status->length = len; 278f471f1a7SDan Williams ars_status->type = ND_ARS_PERSISTENT; 2799fb1a190SDave Jiang 2809fb1a190SDave Jiang spin_lock(&badrange->lock); 2819fb1a190SDave Jiang list_for_each_entry(be, &badrange->list, list) { 2829fb1a190SDave Jiang u64 be_end = be->start + be->length - 1; 2839fb1a190SDave Jiang u64 rstart, rend; 2849fb1a190SDave Jiang 2859fb1a190SDave Jiang /* skip entries outside the range */ 2869fb1a190SDave Jiang if (be_end < addr || be->start > end) 2879fb1a190SDave Jiang continue; 2889fb1a190SDave Jiang 2899fb1a190SDave Jiang rstart = (be->start < addr) ? addr : be->start; 2909fb1a190SDave Jiang rend = (be_end < end) ? be_end : end; 2919fb1a190SDave Jiang ars_record = &ars_status->records[i]; 292f471f1a7SDan Williams ars_record->handle = 0; 2939fb1a190SDave Jiang ars_record->err_address = rstart; 2949fb1a190SDave Jiang ars_record->length = rend - rstart + 1; 2959fb1a190SDave Jiang i++; 2969fb1a190SDave Jiang } 2979fb1a190SDave Jiang spin_unlock(&badrange->lock); 2989fb1a190SDave Jiang ars_status->num_records = i; 2999fb1a190SDave Jiang ars_status->out_length = sizeof(struct nd_cmd_ars_status) 3009fb1a190SDave Jiang + i * sizeof(struct nd_ars_record); 301f471f1a7SDan Williams } 302f471f1a7SDan Williams 3039fb1a190SDave Jiang static int nfit_test_cmd_ars_start(struct nfit_test *t, 3049fb1a190SDave Jiang struct ars_state *ars_state, 305f471f1a7SDan Williams struct nd_cmd_ars_start *ars_start, unsigned int buf_len, 306f471f1a7SDan Williams int *cmd_rc) 307f471f1a7SDan Williams { 308f471f1a7SDan Williams if (buf_len < sizeof(*ars_start)) 30939c686b8SVishal Verma return -EINVAL; 31039c686b8SVishal Verma 311f471f1a7SDan Williams spin_lock(&ars_state->lock); 312f471f1a7SDan Williams if (time_before(jiffies, ars_state->deadline)) { 313f471f1a7SDan Williams ars_start->status = NFIT_ARS_START_BUSY; 314f471f1a7SDan Williams *cmd_rc = -EBUSY; 315f471f1a7SDan Williams } else { 316f471f1a7SDan Williams ars_start->status = 0; 317f471f1a7SDan Williams ars_start->scrub_time = 1; 3189fb1a190SDave Jiang post_ars_status(ars_state, &t->badrange, ars_start->address, 319f471f1a7SDan Williams ars_start->length); 320f471f1a7SDan Williams *cmd_rc = 0; 321f471f1a7SDan Williams } 322f471f1a7SDan Williams spin_unlock(&ars_state->lock); 32339c686b8SVishal Verma 32439c686b8SVishal Verma return 0; 32539c686b8SVishal Verma } 32639c686b8SVishal Verma 327f471f1a7SDan Williams static int nfit_test_cmd_ars_status(struct ars_state *ars_state, 328f471f1a7SDan Williams struct nd_cmd_ars_status *ars_status, unsigned int buf_len, 329f471f1a7SDan Williams int *cmd_rc) 33039c686b8SVishal Verma { 331f471f1a7SDan Williams if (buf_len < ars_state->ars_status->out_length) 33239c686b8SVishal Verma return -EINVAL; 33339c686b8SVishal Verma 334f471f1a7SDan Williams spin_lock(&ars_state->lock); 335f471f1a7SDan Williams if (time_before(jiffies, ars_state->deadline)) { 336f471f1a7SDan Williams memset(ars_status, 0, buf_len); 337f471f1a7SDan Williams ars_status->status = NFIT_ARS_STATUS_BUSY; 338f471f1a7SDan Williams ars_status->out_length = sizeof(*ars_status); 339f471f1a7SDan Williams *cmd_rc = -EBUSY; 340f471f1a7SDan Williams } else { 341f471f1a7SDan Williams memcpy(ars_status, ars_state->ars_status, 342f471f1a7SDan Williams ars_state->ars_status->out_length); 343f471f1a7SDan Williams *cmd_rc = 0; 344f471f1a7SDan Williams } 345f471f1a7SDan Williams spin_unlock(&ars_state->lock); 34639c686b8SVishal Verma return 0; 34739c686b8SVishal Verma } 34839c686b8SVishal Verma 3495e096ef3SVishal Verma static int nfit_test_cmd_clear_error(struct nfit_test *t, 3505e096ef3SVishal Verma struct nd_cmd_clear_error *clear_err, 351d4f32367SDan Williams unsigned int buf_len, int *cmd_rc) 352d4f32367SDan Williams { 353d4f32367SDan Williams const u64 mask = NFIT_TEST_CLEAR_ERR_UNIT - 1; 354d4f32367SDan Williams if (buf_len < sizeof(*clear_err)) 355d4f32367SDan Williams return -EINVAL; 356d4f32367SDan Williams 357d4f32367SDan Williams if ((clear_err->address & mask) || (clear_err->length & mask)) 358d4f32367SDan Williams return -EINVAL; 359d4f32367SDan Williams 3605e096ef3SVishal Verma badrange_forget(&t->badrange, clear_err->address, clear_err->length); 361d4f32367SDan Williams clear_err->status = 0; 362d4f32367SDan Williams clear_err->cleared = clear_err->length; 363d4f32367SDan Williams *cmd_rc = 0; 364d4f32367SDan Williams return 0; 365d4f32367SDan Williams } 366d4f32367SDan Williams 36710246dc8SYasunori Goto struct region_search_spa { 36810246dc8SYasunori Goto u64 addr; 36910246dc8SYasunori Goto struct nd_region *region; 37010246dc8SYasunori Goto }; 37110246dc8SYasunori Goto 37210246dc8SYasunori Goto static int is_region_device(struct device *dev) 37310246dc8SYasunori Goto { 37410246dc8SYasunori Goto return !strncmp(dev->kobj.name, "region", 6); 37510246dc8SYasunori Goto } 37610246dc8SYasunori Goto 37710246dc8SYasunori Goto static int nfit_test_search_region_spa(struct device *dev, void *data) 37810246dc8SYasunori Goto { 37910246dc8SYasunori Goto struct region_search_spa *ctx = data; 38010246dc8SYasunori Goto struct nd_region *nd_region; 38110246dc8SYasunori Goto resource_size_t ndr_end; 38210246dc8SYasunori Goto 38310246dc8SYasunori Goto if (!is_region_device(dev)) 38410246dc8SYasunori Goto return 0; 38510246dc8SYasunori Goto 38610246dc8SYasunori Goto nd_region = to_nd_region(dev); 38710246dc8SYasunori Goto ndr_end = nd_region->ndr_start + nd_region->ndr_size; 38810246dc8SYasunori Goto 38910246dc8SYasunori Goto if (ctx->addr >= nd_region->ndr_start && ctx->addr < ndr_end) { 39010246dc8SYasunori Goto ctx->region = nd_region; 39110246dc8SYasunori Goto return 1; 39210246dc8SYasunori Goto } 39310246dc8SYasunori Goto 39410246dc8SYasunori Goto return 0; 39510246dc8SYasunori Goto } 39610246dc8SYasunori Goto 39710246dc8SYasunori Goto static int nfit_test_search_spa(struct nvdimm_bus *bus, 39810246dc8SYasunori Goto struct nd_cmd_translate_spa *spa) 39910246dc8SYasunori Goto { 40010246dc8SYasunori Goto int ret; 40110246dc8SYasunori Goto struct nd_region *nd_region = NULL; 40210246dc8SYasunori Goto struct nvdimm *nvdimm = NULL; 40310246dc8SYasunori Goto struct nd_mapping *nd_mapping = NULL; 40410246dc8SYasunori Goto struct region_search_spa ctx = { 40510246dc8SYasunori Goto .addr = spa->spa, 40610246dc8SYasunori Goto .region = NULL, 40710246dc8SYasunori Goto }; 40810246dc8SYasunori Goto u64 dpa; 40910246dc8SYasunori Goto 41010246dc8SYasunori Goto ret = device_for_each_child(&bus->dev, &ctx, 41110246dc8SYasunori Goto nfit_test_search_region_spa); 41210246dc8SYasunori Goto 41310246dc8SYasunori Goto if (!ret) 41410246dc8SYasunori Goto return -ENODEV; 41510246dc8SYasunori Goto 41610246dc8SYasunori Goto nd_region = ctx.region; 41710246dc8SYasunori Goto 41810246dc8SYasunori Goto dpa = ctx.addr - nd_region->ndr_start; 41910246dc8SYasunori Goto 42010246dc8SYasunori Goto /* 42110246dc8SYasunori Goto * last dimm is selected for test 42210246dc8SYasunori Goto */ 42310246dc8SYasunori Goto nd_mapping = &nd_region->mapping[nd_region->ndr_mappings - 1]; 42410246dc8SYasunori Goto nvdimm = nd_mapping->nvdimm; 42510246dc8SYasunori Goto 42610246dc8SYasunori Goto spa->devices[0].nfit_device_handle = handle[nvdimm->id]; 42710246dc8SYasunori Goto spa->num_nvdimms = 1; 42810246dc8SYasunori Goto spa->devices[0].dpa = dpa; 42910246dc8SYasunori Goto 43010246dc8SYasunori Goto return 0; 43110246dc8SYasunori Goto } 43210246dc8SYasunori Goto 43310246dc8SYasunori Goto static int nfit_test_cmd_translate_spa(struct nvdimm_bus *bus, 43410246dc8SYasunori Goto struct nd_cmd_translate_spa *spa, unsigned int buf_len) 43510246dc8SYasunori Goto { 43610246dc8SYasunori Goto if (buf_len < spa->translate_length) 43710246dc8SYasunori Goto return -EINVAL; 43810246dc8SYasunori Goto 43910246dc8SYasunori Goto if (nfit_test_search_spa(bus, spa) < 0 || !spa->num_nvdimms) 44010246dc8SYasunori Goto spa->status = 2; 44110246dc8SYasunori Goto 44210246dc8SYasunori Goto return 0; 44310246dc8SYasunori Goto } 44410246dc8SYasunori Goto 445*ed07c433SDan Williams static int nfit_test_cmd_smart(struct nd_intel_smart *smart, unsigned int buf_len, 446*ed07c433SDan Williams struct nd_intel_smart *smart_data) 447baa51277SDan Williams { 448baa51277SDan Williams if (buf_len < sizeof(*smart)) 449baa51277SDan Williams return -EINVAL; 450*ed07c433SDan Williams memcpy(smart, smart_data, sizeof(*smart)); 451baa51277SDan Williams return 0; 452baa51277SDan Williams } 453baa51277SDan Williams 454cdd77d3eSDan Williams static int nfit_test_cmd_smart_threshold( 455*ed07c433SDan Williams struct nd_intel_smart_threshold *out, 456*ed07c433SDan Williams unsigned int buf_len, 457*ed07c433SDan Williams struct nd_intel_smart_threshold *smart_t) 458baa51277SDan Williams { 459baa51277SDan Williams if (buf_len < sizeof(*smart_t)) 460baa51277SDan Williams return -EINVAL; 461*ed07c433SDan Williams memcpy(out, smart_t, sizeof(*smart_t)); 462*ed07c433SDan Williams return 0; 463*ed07c433SDan Williams } 464*ed07c433SDan Williams 465*ed07c433SDan Williams static void smart_notify(struct device *bus_dev, 466*ed07c433SDan Williams struct device *dimm_dev, struct nd_intel_smart *smart, 467*ed07c433SDan Williams struct nd_intel_smart_threshold *thresh) 468*ed07c433SDan Williams { 469*ed07c433SDan Williams dev_dbg(dimm_dev, "%s: alarm: %#x spares: %d (%d) mtemp: %d (%d) ctemp: %d (%d)\n", 470*ed07c433SDan Williams __func__, thresh->alarm_control, thresh->spares, 471*ed07c433SDan Williams smart->spares, thresh->media_temperature, 472*ed07c433SDan Williams smart->media_temperature, thresh->ctrl_temperature, 473*ed07c433SDan Williams smart->ctrl_temperature); 474*ed07c433SDan Williams if (((thresh->alarm_control & ND_INTEL_SMART_SPARE_TRIP) 475*ed07c433SDan Williams && smart->spares 476*ed07c433SDan Williams <= thresh->spares) 477*ed07c433SDan Williams || ((thresh->alarm_control & ND_INTEL_SMART_TEMP_TRIP) 478*ed07c433SDan Williams && smart->media_temperature 479*ed07c433SDan Williams >= thresh->media_temperature) 480*ed07c433SDan Williams || ((thresh->alarm_control & ND_INTEL_SMART_CTEMP_TRIP) 481*ed07c433SDan Williams && smart->ctrl_temperature 482*ed07c433SDan Williams >= thresh->ctrl_temperature)) { 483*ed07c433SDan Williams device_lock(bus_dev); 484*ed07c433SDan Williams __acpi_nvdimm_notify(dimm_dev, 0x81); 485*ed07c433SDan Williams device_unlock(bus_dev); 486*ed07c433SDan Williams } 487*ed07c433SDan Williams } 488*ed07c433SDan Williams 489*ed07c433SDan Williams static int nfit_test_cmd_smart_set_threshold( 490*ed07c433SDan Williams struct nd_intel_smart_set_threshold *in, 491*ed07c433SDan Williams unsigned int buf_len, 492*ed07c433SDan Williams struct nd_intel_smart_threshold *thresh, 493*ed07c433SDan Williams struct nd_intel_smart *smart, 494*ed07c433SDan Williams struct device *bus_dev, struct device *dimm_dev) 495*ed07c433SDan Williams { 496*ed07c433SDan Williams unsigned int size; 497*ed07c433SDan Williams 498*ed07c433SDan Williams size = sizeof(*in) - 4; 499*ed07c433SDan Williams if (buf_len < size) 500*ed07c433SDan Williams return -EINVAL; 501*ed07c433SDan Williams memcpy(thresh->data, in, size); 502*ed07c433SDan Williams in->status = 0; 503*ed07c433SDan Williams smart_notify(bus_dev, dimm_dev, smart, thresh); 504*ed07c433SDan Williams 505baa51277SDan Williams return 0; 506baa51277SDan Williams } 507baa51277SDan Williams 5089fb1a190SDave Jiang static void uc_error_notify(struct work_struct *work) 5099fb1a190SDave Jiang { 5109fb1a190SDave Jiang struct nfit_test *t = container_of(work, typeof(*t), work); 5119fb1a190SDave Jiang 5129fb1a190SDave Jiang __acpi_nfit_notify(&t->pdev.dev, t, NFIT_NOTIFY_UC_MEMORY_ERROR); 5139fb1a190SDave Jiang } 5149fb1a190SDave Jiang 5159fb1a190SDave Jiang static int nfit_test_cmd_ars_error_inject(struct nfit_test *t, 5169fb1a190SDave Jiang struct nd_cmd_ars_err_inj *err_inj, unsigned int buf_len) 5179fb1a190SDave Jiang { 5189fb1a190SDave Jiang int rc; 5199fb1a190SDave Jiang 52041cb3301SVishal Verma if (buf_len != sizeof(*err_inj)) { 5219fb1a190SDave Jiang rc = -EINVAL; 5229fb1a190SDave Jiang goto err; 5239fb1a190SDave Jiang } 5249fb1a190SDave Jiang 5259fb1a190SDave Jiang if (err_inj->err_inj_spa_range_length <= 0) { 5269fb1a190SDave Jiang rc = -EINVAL; 5279fb1a190SDave Jiang goto err; 5289fb1a190SDave Jiang } 5299fb1a190SDave Jiang 5309fb1a190SDave Jiang rc = badrange_add(&t->badrange, err_inj->err_inj_spa_range_base, 5319fb1a190SDave Jiang err_inj->err_inj_spa_range_length); 5329fb1a190SDave Jiang if (rc < 0) 5339fb1a190SDave Jiang goto err; 5349fb1a190SDave Jiang 5359fb1a190SDave Jiang if (err_inj->err_inj_options & (1 << ND_ARS_ERR_INJ_OPT_NOTIFY)) 5369fb1a190SDave Jiang queue_work(nfit_wq, &t->work); 5379fb1a190SDave Jiang 5389fb1a190SDave Jiang err_inj->status = 0; 5399fb1a190SDave Jiang return 0; 5409fb1a190SDave Jiang 5419fb1a190SDave Jiang err: 5429fb1a190SDave Jiang err_inj->status = NFIT_ARS_INJECT_INVALID; 5439fb1a190SDave Jiang return rc; 5449fb1a190SDave Jiang } 5459fb1a190SDave Jiang 5469fb1a190SDave Jiang static int nfit_test_cmd_ars_inject_clear(struct nfit_test *t, 5479fb1a190SDave Jiang struct nd_cmd_ars_err_inj_clr *err_clr, unsigned int buf_len) 5489fb1a190SDave Jiang { 5499fb1a190SDave Jiang int rc; 5509fb1a190SDave Jiang 55141cb3301SVishal Verma if (buf_len != sizeof(*err_clr)) { 5529fb1a190SDave Jiang rc = -EINVAL; 5539fb1a190SDave Jiang goto err; 5549fb1a190SDave Jiang } 5559fb1a190SDave Jiang 5569fb1a190SDave Jiang if (err_clr->err_inj_clr_spa_range_length <= 0) { 5579fb1a190SDave Jiang rc = -EINVAL; 5589fb1a190SDave Jiang goto err; 5599fb1a190SDave Jiang } 5609fb1a190SDave Jiang 5619fb1a190SDave Jiang badrange_forget(&t->badrange, err_clr->err_inj_clr_spa_range_base, 5629fb1a190SDave Jiang err_clr->err_inj_clr_spa_range_length); 5639fb1a190SDave Jiang 5649fb1a190SDave Jiang err_clr->status = 0; 5659fb1a190SDave Jiang return 0; 5669fb1a190SDave Jiang 5679fb1a190SDave Jiang err: 5689fb1a190SDave Jiang err_clr->status = NFIT_ARS_INJECT_INVALID; 5699fb1a190SDave Jiang return rc; 5709fb1a190SDave Jiang } 5719fb1a190SDave Jiang 5729fb1a190SDave Jiang static int nfit_test_cmd_ars_inject_status(struct nfit_test *t, 5739fb1a190SDave Jiang struct nd_cmd_ars_err_inj_stat *err_stat, 5749fb1a190SDave Jiang unsigned int buf_len) 5759fb1a190SDave Jiang { 5769fb1a190SDave Jiang struct badrange_entry *be; 5779fb1a190SDave Jiang int max = SZ_4K / sizeof(struct nd_error_stat_query_record); 5789fb1a190SDave Jiang int i = 0; 5799fb1a190SDave Jiang 5809fb1a190SDave Jiang err_stat->status = 0; 5819fb1a190SDave Jiang spin_lock(&t->badrange.lock); 5829fb1a190SDave Jiang list_for_each_entry(be, &t->badrange.list, list) { 5839fb1a190SDave Jiang err_stat->record[i].err_inj_stat_spa_range_base = be->start; 5849fb1a190SDave Jiang err_stat->record[i].err_inj_stat_spa_range_length = be->length; 5859fb1a190SDave Jiang i++; 5869fb1a190SDave Jiang if (i > max) 5879fb1a190SDave Jiang break; 5889fb1a190SDave Jiang } 5899fb1a190SDave Jiang spin_unlock(&t->badrange.lock); 5909fb1a190SDave Jiang err_stat->inj_err_rec_count = i; 5919fb1a190SDave Jiang 5929fb1a190SDave Jiang return 0; 5939fb1a190SDave Jiang } 5949fb1a190SDave Jiang 59539c686b8SVishal Verma static int nfit_test_ctl(struct nvdimm_bus_descriptor *nd_desc, 59639c686b8SVishal Verma struct nvdimm *nvdimm, unsigned int cmd, void *buf, 597aef25338SDan Williams unsigned int buf_len, int *cmd_rc) 59839c686b8SVishal Verma { 59939c686b8SVishal Verma struct acpi_nfit_desc *acpi_desc = to_acpi_desc(nd_desc); 60039c686b8SVishal Verma struct nfit_test *t = container_of(acpi_desc, typeof(*t), acpi_desc); 6016634fb06SDan Williams unsigned int func = cmd; 602f471f1a7SDan Williams int i, rc = 0, __cmd_rc; 603f471f1a7SDan Williams 604f471f1a7SDan Williams if (!cmd_rc) 605f471f1a7SDan Williams cmd_rc = &__cmd_rc; 606f471f1a7SDan Williams *cmd_rc = 0; 60739c686b8SVishal Verma 60839c686b8SVishal Verma if (nvdimm) { 60939c686b8SVishal Verma struct nfit_mem *nfit_mem = nvdimm_provider_data(nvdimm); 610e3654ecaSDan Williams unsigned long cmd_mask = nvdimm_cmd_mask(nvdimm); 61139c686b8SVishal Verma 6126634fb06SDan Williams if (!nfit_mem) 6136634fb06SDan Williams return -ENOTTY; 6146634fb06SDan Williams 6156634fb06SDan Williams if (cmd == ND_CMD_CALL) { 6166634fb06SDan Williams struct nd_cmd_pkg *call_pkg = buf; 6176634fb06SDan Williams 6186634fb06SDan Williams buf_len = call_pkg->nd_size_in + call_pkg->nd_size_out; 6196634fb06SDan Williams buf = (void *) call_pkg->nd_payload; 6206634fb06SDan Williams func = call_pkg->nd_command; 6216634fb06SDan Williams if (call_pkg->nd_family != nfit_mem->family) 6226634fb06SDan Williams return -ENOTTY; 6236634fb06SDan Williams } 6246634fb06SDan Williams 6256634fb06SDan Williams if (!test_bit(cmd, &cmd_mask) 6266634fb06SDan Williams || !test_bit(func, &nfit_mem->dsm_mask)) 62739c686b8SVishal Verma return -ENOTTY; 62839c686b8SVishal Verma 629*ed07c433SDan Williams /* lookup per-dimm data */ 63039c686b8SVishal Verma for (i = 0; i < ARRAY_SIZE(handle); i++) 63139c686b8SVishal Verma if (__to_nfit_memdev(nfit_mem)->device_handle == 63239c686b8SVishal Verma handle[i]) 63339c686b8SVishal Verma break; 63439c686b8SVishal Verma if (i >= ARRAY_SIZE(handle)) 63539c686b8SVishal Verma return -ENXIO; 63639c686b8SVishal Verma 63773606afdSDan Williams if ((1 << func) & dimm_fail_cmd_flags[i]) 63873606afdSDan Williams return -EIO; 63973606afdSDan Williams 6406634fb06SDan Williams switch (func) { 64139c686b8SVishal Verma case ND_CMD_GET_CONFIG_SIZE: 64239c686b8SVishal Verma rc = nfit_test_cmd_get_config_size(buf, buf_len); 64339c686b8SVishal Verma break; 64439c686b8SVishal Verma case ND_CMD_GET_CONFIG_DATA: 64539c686b8SVishal Verma rc = nfit_test_cmd_get_config_data(buf, buf_len, 646dafb1048SDan Williams t->label[i - t->dcr_idx]); 64739c686b8SVishal Verma break; 64839c686b8SVishal Verma case ND_CMD_SET_CONFIG_DATA: 64939c686b8SVishal Verma rc = nfit_test_cmd_set_config_data(buf, buf_len, 650dafb1048SDan Williams t->label[i - t->dcr_idx]); 65139c686b8SVishal Verma break; 652*ed07c433SDan Williams case ND_INTEL_SMART: 653*ed07c433SDan Williams rc = nfit_test_cmd_smart(buf, buf_len, 654*ed07c433SDan Williams &t->smart[i - t->dcr_idx]); 655baa51277SDan Williams break; 656*ed07c433SDan Williams case ND_INTEL_SMART_THRESHOLD: 657*ed07c433SDan Williams rc = nfit_test_cmd_smart_threshold(buf, buf_len, 658*ed07c433SDan Williams &t->smart_threshold[i - t->dcr_idx]); 659*ed07c433SDan Williams break; 660*ed07c433SDan Williams case ND_INTEL_SMART_SET_THRESHOLD: 661*ed07c433SDan Williams rc = nfit_test_cmd_smart_set_threshold(buf, buf_len, 662*ed07c433SDan Williams &t->smart_threshold[i - t->dcr_idx], 663*ed07c433SDan Williams &t->smart[i - t->dcr_idx], 664*ed07c433SDan Williams &t->pdev.dev, t->dimm_dev[i]); 665baa51277SDan Williams break; 6666bc75619SDan Williams default: 6676bc75619SDan Williams return -ENOTTY; 6686bc75619SDan Williams } 66939c686b8SVishal Verma } else { 670f471f1a7SDan Williams struct ars_state *ars_state = &t->ars_state; 67110246dc8SYasunori Goto struct nd_cmd_pkg *call_pkg = buf; 67210246dc8SYasunori Goto 67310246dc8SYasunori Goto if (!nd_desc) 67410246dc8SYasunori Goto return -ENOTTY; 67510246dc8SYasunori Goto 67610246dc8SYasunori Goto if (cmd == ND_CMD_CALL) { 67710246dc8SYasunori Goto func = call_pkg->nd_command; 67810246dc8SYasunori Goto 67910246dc8SYasunori Goto buf_len = call_pkg->nd_size_in + call_pkg->nd_size_out; 68010246dc8SYasunori Goto buf = (void *) call_pkg->nd_payload; 68110246dc8SYasunori Goto 68210246dc8SYasunori Goto switch (func) { 68310246dc8SYasunori Goto case NFIT_CMD_TRANSLATE_SPA: 68410246dc8SYasunori Goto rc = nfit_test_cmd_translate_spa( 68510246dc8SYasunori Goto acpi_desc->nvdimm_bus, buf, buf_len); 68610246dc8SYasunori Goto return rc; 6879fb1a190SDave Jiang case NFIT_CMD_ARS_INJECT_SET: 6889fb1a190SDave Jiang rc = nfit_test_cmd_ars_error_inject(t, buf, 6899fb1a190SDave Jiang buf_len); 6909fb1a190SDave Jiang return rc; 6919fb1a190SDave Jiang case NFIT_CMD_ARS_INJECT_CLEAR: 6929fb1a190SDave Jiang rc = nfit_test_cmd_ars_inject_clear(t, buf, 6939fb1a190SDave Jiang buf_len); 6949fb1a190SDave Jiang return rc; 6959fb1a190SDave Jiang case NFIT_CMD_ARS_INJECT_GET: 6969fb1a190SDave Jiang rc = nfit_test_cmd_ars_inject_status(t, buf, 6979fb1a190SDave Jiang buf_len); 6989fb1a190SDave Jiang return rc; 69910246dc8SYasunori Goto default: 70010246dc8SYasunori Goto return -ENOTTY; 70110246dc8SYasunori Goto } 70210246dc8SYasunori Goto } 703f471f1a7SDan Williams 704e3654ecaSDan Williams if (!nd_desc || !test_bit(cmd, &nd_desc->cmd_mask)) 70539c686b8SVishal Verma return -ENOTTY; 70639c686b8SVishal Verma 7076634fb06SDan Williams switch (func) { 70839c686b8SVishal Verma case ND_CMD_ARS_CAP: 70939c686b8SVishal Verma rc = nfit_test_cmd_ars_cap(buf, buf_len); 71039c686b8SVishal Verma break; 71139c686b8SVishal Verma case ND_CMD_ARS_START: 7129fb1a190SDave Jiang rc = nfit_test_cmd_ars_start(t, ars_state, buf, 7139fb1a190SDave Jiang buf_len, cmd_rc); 71439c686b8SVishal Verma break; 71539c686b8SVishal Verma case ND_CMD_ARS_STATUS: 716f471f1a7SDan Williams rc = nfit_test_cmd_ars_status(ars_state, buf, buf_len, 717f471f1a7SDan Williams cmd_rc); 71839c686b8SVishal Verma break; 719d4f32367SDan Williams case ND_CMD_CLEAR_ERROR: 7205e096ef3SVishal Verma rc = nfit_test_cmd_clear_error(t, buf, buf_len, cmd_rc); 721d4f32367SDan Williams break; 72239c686b8SVishal Verma default: 72339c686b8SVishal Verma return -ENOTTY; 72439c686b8SVishal Verma } 72539c686b8SVishal Verma } 7266bc75619SDan Williams 7276bc75619SDan Williams return rc; 7286bc75619SDan Williams } 7296bc75619SDan Williams 7306bc75619SDan Williams static DEFINE_SPINLOCK(nfit_test_lock); 7316bc75619SDan Williams static struct nfit_test *instances[NUM_NFITS]; 7326bc75619SDan Williams 7336bc75619SDan Williams static void release_nfit_res(void *data) 7346bc75619SDan Williams { 7356bc75619SDan Williams struct nfit_test_resource *nfit_res = data; 7366bc75619SDan Williams 7376bc75619SDan Williams spin_lock(&nfit_test_lock); 7386bc75619SDan Williams list_del(&nfit_res->list); 7396bc75619SDan Williams spin_unlock(&nfit_test_lock); 7406bc75619SDan Williams 7416bc75619SDan Williams vfree(nfit_res->buf); 7426bc75619SDan Williams kfree(nfit_res); 7436bc75619SDan Williams } 7446bc75619SDan Williams 7456bc75619SDan Williams static void *__test_alloc(struct nfit_test *t, size_t size, dma_addr_t *dma, 7466bc75619SDan Williams void *buf) 7476bc75619SDan Williams { 7486bc75619SDan Williams struct device *dev = &t->pdev.dev; 7496bc75619SDan Williams struct nfit_test_resource *nfit_res = kzalloc(sizeof(*nfit_res), 7506bc75619SDan Williams GFP_KERNEL); 7516bc75619SDan Williams int rc; 7526bc75619SDan Williams 753bd4cd745SDan Williams if (!buf || !nfit_res) 7546bc75619SDan Williams goto err; 7556bc75619SDan Williams rc = devm_add_action(dev, release_nfit_res, nfit_res); 7566bc75619SDan Williams if (rc) 7576bc75619SDan Williams goto err; 7586bc75619SDan Williams INIT_LIST_HEAD(&nfit_res->list); 7596bc75619SDan Williams memset(buf, 0, size); 7606bc75619SDan Williams nfit_res->dev = dev; 7616bc75619SDan Williams nfit_res->buf = buf; 762bd4cd745SDan Williams nfit_res->res.start = *dma; 763bd4cd745SDan Williams nfit_res->res.end = *dma + size - 1; 764bd4cd745SDan Williams nfit_res->res.name = "NFIT"; 765bd4cd745SDan Williams spin_lock_init(&nfit_res->lock); 766bd4cd745SDan Williams INIT_LIST_HEAD(&nfit_res->requests); 7676bc75619SDan Williams spin_lock(&nfit_test_lock); 7686bc75619SDan Williams list_add(&nfit_res->list, &t->resources); 7696bc75619SDan Williams spin_unlock(&nfit_test_lock); 7706bc75619SDan Williams 7716bc75619SDan Williams return nfit_res->buf; 7726bc75619SDan Williams err: 773ee8520feSDan Williams if (buf) 7746bc75619SDan Williams vfree(buf); 7756bc75619SDan Williams kfree(nfit_res); 7766bc75619SDan Williams return NULL; 7776bc75619SDan Williams } 7786bc75619SDan Williams 7796bc75619SDan Williams static void *test_alloc(struct nfit_test *t, size_t size, dma_addr_t *dma) 7806bc75619SDan Williams { 7816bc75619SDan Williams void *buf = vmalloc(size); 7826bc75619SDan Williams 7836bc75619SDan Williams *dma = (unsigned long) buf; 7846bc75619SDan Williams return __test_alloc(t, size, dma, buf); 7856bc75619SDan Williams } 7866bc75619SDan Williams 7876bc75619SDan Williams static struct nfit_test_resource *nfit_test_lookup(resource_size_t addr) 7886bc75619SDan Williams { 7896bc75619SDan Williams int i; 7906bc75619SDan Williams 7916bc75619SDan Williams for (i = 0; i < ARRAY_SIZE(instances); i++) { 7926bc75619SDan Williams struct nfit_test_resource *n, *nfit_res = NULL; 7936bc75619SDan Williams struct nfit_test *t = instances[i]; 7946bc75619SDan Williams 7956bc75619SDan Williams if (!t) 7966bc75619SDan Williams continue; 7976bc75619SDan Williams spin_lock(&nfit_test_lock); 7986bc75619SDan Williams list_for_each_entry(n, &t->resources, list) { 799bd4cd745SDan Williams if (addr >= n->res.start && (addr < n->res.start 800bd4cd745SDan Williams + resource_size(&n->res))) { 8016bc75619SDan Williams nfit_res = n; 8026bc75619SDan Williams break; 8036bc75619SDan Williams } else if (addr >= (unsigned long) n->buf 8046bc75619SDan Williams && (addr < (unsigned long) n->buf 805bd4cd745SDan Williams + resource_size(&n->res))) { 8066bc75619SDan Williams nfit_res = n; 8076bc75619SDan Williams break; 8086bc75619SDan Williams } 8096bc75619SDan Williams } 8106bc75619SDan Williams spin_unlock(&nfit_test_lock); 8116bc75619SDan Williams if (nfit_res) 8126bc75619SDan Williams return nfit_res; 8136bc75619SDan Williams } 8146bc75619SDan Williams 8156bc75619SDan Williams return NULL; 8166bc75619SDan Williams } 8176bc75619SDan Williams 818f471f1a7SDan Williams static int ars_state_init(struct device *dev, struct ars_state *ars_state) 819f471f1a7SDan Williams { 8209fb1a190SDave Jiang /* for testing, only store up to n records that fit within 4k */ 821f471f1a7SDan Williams ars_state->ars_status = devm_kzalloc(dev, 8229fb1a190SDave Jiang sizeof(struct nd_cmd_ars_status) + SZ_4K, GFP_KERNEL); 823f471f1a7SDan Williams if (!ars_state->ars_status) 824f471f1a7SDan Williams return -ENOMEM; 825f471f1a7SDan Williams spin_lock_init(&ars_state->lock); 826f471f1a7SDan Williams return 0; 827f471f1a7SDan Williams } 828f471f1a7SDan Williams 829231bf117SDan Williams static void put_dimms(void *data) 830231bf117SDan Williams { 831231bf117SDan Williams struct device **dimm_dev = data; 832231bf117SDan Williams int i; 833231bf117SDan Williams 834231bf117SDan Williams for (i = 0; i < NUM_DCR; i++) 835231bf117SDan Williams if (dimm_dev[i]) 836231bf117SDan Williams device_unregister(dimm_dev[i]); 837231bf117SDan Williams } 838231bf117SDan Williams 839231bf117SDan Williams static struct class *nfit_test_dimm; 840231bf117SDan Williams 84173606afdSDan Williams static int dimm_name_to_id(struct device *dev) 84273606afdSDan Williams { 84373606afdSDan Williams int dimm; 84473606afdSDan Williams 84573606afdSDan Williams if (sscanf(dev_name(dev), "test_dimm%d", &dimm) != 1 84673606afdSDan Williams || dimm >= NUM_DCR || dimm < 0) 84773606afdSDan Williams return -ENXIO; 84873606afdSDan Williams return dimm; 84973606afdSDan Williams } 85073606afdSDan Williams 85173606afdSDan Williams 85273606afdSDan Williams static ssize_t handle_show(struct device *dev, struct device_attribute *attr, 85373606afdSDan Williams char *buf) 85473606afdSDan Williams { 85573606afdSDan Williams int dimm = dimm_name_to_id(dev); 85673606afdSDan Williams 85773606afdSDan Williams if (dimm < 0) 85873606afdSDan Williams return dimm; 85973606afdSDan Williams 86073606afdSDan Williams return sprintf(buf, "%#x", handle[dimm]); 86173606afdSDan Williams } 86273606afdSDan Williams DEVICE_ATTR_RO(handle); 86373606afdSDan Williams 86473606afdSDan Williams static ssize_t fail_cmd_show(struct device *dev, struct device_attribute *attr, 86573606afdSDan Williams char *buf) 86673606afdSDan Williams { 86773606afdSDan Williams int dimm = dimm_name_to_id(dev); 86873606afdSDan Williams 86973606afdSDan Williams if (dimm < 0) 87073606afdSDan Williams return dimm; 87173606afdSDan Williams 87273606afdSDan Williams return sprintf(buf, "%#lx\n", dimm_fail_cmd_flags[dimm]); 87373606afdSDan Williams } 87473606afdSDan Williams 87573606afdSDan Williams static ssize_t fail_cmd_store(struct device *dev, struct device_attribute *attr, 87673606afdSDan Williams const char *buf, size_t size) 87773606afdSDan Williams { 87873606afdSDan Williams int dimm = dimm_name_to_id(dev); 87973606afdSDan Williams unsigned long val; 88073606afdSDan Williams ssize_t rc; 88173606afdSDan Williams 88273606afdSDan Williams if (dimm < 0) 88373606afdSDan Williams return dimm; 88473606afdSDan Williams 88573606afdSDan Williams rc = kstrtol(buf, 0, &val); 88673606afdSDan Williams if (rc) 88773606afdSDan Williams return rc; 88873606afdSDan Williams 88973606afdSDan Williams dimm_fail_cmd_flags[dimm] = val; 89073606afdSDan Williams return size; 89173606afdSDan Williams } 89273606afdSDan Williams static DEVICE_ATTR_RW(fail_cmd); 89373606afdSDan Williams 89473606afdSDan Williams static struct attribute *nfit_test_dimm_attributes[] = { 89573606afdSDan Williams &dev_attr_fail_cmd.attr, 89673606afdSDan Williams &dev_attr_handle.attr, 89773606afdSDan Williams NULL, 89873606afdSDan Williams }; 89973606afdSDan Williams 90073606afdSDan Williams static struct attribute_group nfit_test_dimm_attribute_group = { 90173606afdSDan Williams .attrs = nfit_test_dimm_attributes, 90273606afdSDan Williams }; 90373606afdSDan Williams 90473606afdSDan Williams static const struct attribute_group *nfit_test_dimm_attribute_groups[] = { 90573606afdSDan Williams &nfit_test_dimm_attribute_group, 90673606afdSDan Williams NULL, 90773606afdSDan Williams }; 90873606afdSDan Williams 909*ed07c433SDan Williams static void smart_init(struct nfit_test *t) 910*ed07c433SDan Williams { 911*ed07c433SDan Williams int i; 912*ed07c433SDan Williams const struct nd_intel_smart_threshold smart_t_data = { 913*ed07c433SDan Williams .alarm_control = ND_INTEL_SMART_SPARE_TRIP 914*ed07c433SDan Williams | ND_INTEL_SMART_TEMP_TRIP, 915*ed07c433SDan Williams .media_temperature = 40 * 16, 916*ed07c433SDan Williams .ctrl_temperature = 30 * 16, 917*ed07c433SDan Williams .spares = 5, 918*ed07c433SDan Williams }; 919*ed07c433SDan Williams const struct nd_intel_smart smart_data = { 920*ed07c433SDan Williams .flags = ND_INTEL_SMART_HEALTH_VALID 921*ed07c433SDan Williams | ND_INTEL_SMART_SPARES_VALID 922*ed07c433SDan Williams | ND_INTEL_SMART_ALARM_VALID 923*ed07c433SDan Williams | ND_INTEL_SMART_USED_VALID 924*ed07c433SDan Williams | ND_INTEL_SMART_SHUTDOWN_VALID 925*ed07c433SDan Williams | ND_INTEL_SMART_MTEMP_VALID, 926*ed07c433SDan Williams .health = ND_INTEL_SMART_NON_CRITICAL_HEALTH, 927*ed07c433SDan Williams .media_temperature = 23 * 16, 928*ed07c433SDan Williams .ctrl_temperature = 30 * 16, 929*ed07c433SDan Williams .pmic_temperature = 40 * 16, 930*ed07c433SDan Williams .spares = 75, 931*ed07c433SDan Williams .alarm_flags = ND_INTEL_SMART_SPARE_TRIP 932*ed07c433SDan Williams | ND_INTEL_SMART_TEMP_TRIP, 933*ed07c433SDan Williams .ait_status = 1, 934*ed07c433SDan Williams .life_used = 5, 935*ed07c433SDan Williams .shutdown_state = 0, 936*ed07c433SDan Williams .vendor_size = 0, 937*ed07c433SDan Williams .shutdown_count = 100, 938*ed07c433SDan Williams }; 939*ed07c433SDan Williams 940*ed07c433SDan Williams for (i = 0; i < t->num_dcr; i++) { 941*ed07c433SDan Williams memcpy(&t->smart[i], &smart_data, sizeof(smart_data)); 942*ed07c433SDan Williams memcpy(&t->smart_threshold[i], &smart_t_data, 943*ed07c433SDan Williams sizeof(smart_t_data)); 944*ed07c433SDan Williams } 945*ed07c433SDan Williams } 946*ed07c433SDan Williams 9476bc75619SDan Williams static int nfit_test0_alloc(struct nfit_test *t) 9486bc75619SDan Williams { 9496b577c9dSLinda Knippers size_t nfit_size = sizeof(struct acpi_nfit_system_address) * NUM_SPA 9506bc75619SDan Williams + sizeof(struct acpi_nfit_memory_map) * NUM_MEM 9516bc75619SDan Williams + sizeof(struct acpi_nfit_control_region) * NUM_DCR 9523b87356fSDan Williams + offsetof(struct acpi_nfit_control_region, 9533b87356fSDan Williams window_size) * NUM_DCR 9549d27a87eSDan Williams + sizeof(struct acpi_nfit_data_region) * NUM_BDW 95585d3fa02SDan Williams + (sizeof(struct acpi_nfit_flush_address) 95685d3fa02SDan Williams + sizeof(u64) * NUM_HINTS) * NUM_DCR; 9576bc75619SDan Williams int i; 9586bc75619SDan Williams 9596bc75619SDan Williams t->nfit_buf = test_alloc(t, nfit_size, &t->nfit_dma); 9606bc75619SDan Williams if (!t->nfit_buf) 9616bc75619SDan Williams return -ENOMEM; 9626bc75619SDan Williams t->nfit_size = nfit_size; 9636bc75619SDan Williams 964ee8520feSDan Williams t->spa_set[0] = test_alloc(t, SPA0_SIZE, &t->spa_set_dma[0]); 9656bc75619SDan Williams if (!t->spa_set[0]) 9666bc75619SDan Williams return -ENOMEM; 9676bc75619SDan Williams 968ee8520feSDan Williams t->spa_set[1] = test_alloc(t, SPA1_SIZE, &t->spa_set_dma[1]); 9696bc75619SDan Williams if (!t->spa_set[1]) 9706bc75619SDan Williams return -ENOMEM; 9716bc75619SDan Williams 972ee8520feSDan Williams t->spa_set[2] = test_alloc(t, SPA0_SIZE, &t->spa_set_dma[2]); 97320985164SVishal Verma if (!t->spa_set[2]) 97420985164SVishal Verma return -ENOMEM; 97520985164SVishal Verma 976dafb1048SDan Williams for (i = 0; i < t->num_dcr; i++) { 9776bc75619SDan Williams t->dimm[i] = test_alloc(t, DIMM_SIZE, &t->dimm_dma[i]); 9786bc75619SDan Williams if (!t->dimm[i]) 9796bc75619SDan Williams return -ENOMEM; 9806bc75619SDan Williams 9816bc75619SDan Williams t->label[i] = test_alloc(t, LABEL_SIZE, &t->label_dma[i]); 9826bc75619SDan Williams if (!t->label[i]) 9836bc75619SDan Williams return -ENOMEM; 9846bc75619SDan Williams sprintf(t->label[i], "label%d", i); 9859d27a87eSDan Williams 9869d15ce9cSDan Williams t->flush[i] = test_alloc(t, max(PAGE_SIZE, 9879d15ce9cSDan Williams sizeof(u64) * NUM_HINTS), 98885d3fa02SDan Williams &t->flush_dma[i]); 9899d27a87eSDan Williams if (!t->flush[i]) 9909d27a87eSDan Williams return -ENOMEM; 9916bc75619SDan Williams } 9926bc75619SDan Williams 993dafb1048SDan Williams for (i = 0; i < t->num_dcr; i++) { 9946bc75619SDan Williams t->dcr[i] = test_alloc(t, LABEL_SIZE, &t->dcr_dma[i]); 9956bc75619SDan Williams if (!t->dcr[i]) 9966bc75619SDan Williams return -ENOMEM; 9976bc75619SDan Williams } 9986bc75619SDan Williams 999c14a868aSDan Williams t->_fit = test_alloc(t, sizeof(union acpi_object **), &t->_fit_dma); 1000c14a868aSDan Williams if (!t->_fit) 1001c14a868aSDan Williams return -ENOMEM; 1002c14a868aSDan Williams 1003231bf117SDan Williams if (devm_add_action_or_reset(&t->pdev.dev, put_dimms, t->dimm_dev)) 1004231bf117SDan Williams return -ENOMEM; 1005231bf117SDan Williams for (i = 0; i < NUM_DCR; i++) { 100673606afdSDan Williams t->dimm_dev[i] = device_create_with_groups(nfit_test_dimm, 100773606afdSDan Williams &t->pdev.dev, 0, NULL, 100873606afdSDan Williams nfit_test_dimm_attribute_groups, 100973606afdSDan Williams "test_dimm%d", i); 1010231bf117SDan Williams if (!t->dimm_dev[i]) 1011231bf117SDan Williams return -ENOMEM; 1012231bf117SDan Williams } 1013231bf117SDan Williams 1014*ed07c433SDan Williams smart_init(t); 1015f471f1a7SDan Williams return ars_state_init(&t->pdev.dev, &t->ars_state); 10166bc75619SDan Williams } 10176bc75619SDan Williams 10186bc75619SDan Williams static int nfit_test1_alloc(struct nfit_test *t) 10196bc75619SDan Williams { 10207bfe97c7SDan Williams size_t nfit_size = sizeof(struct acpi_nfit_system_address) * 2 1021ac40b675SDan Williams + sizeof(struct acpi_nfit_memory_map) * 2 1022ac40b675SDan Williams + offsetof(struct acpi_nfit_control_region, window_size) * 2; 1023dafb1048SDan Williams int i; 10246bc75619SDan Williams 10256bc75619SDan Williams t->nfit_buf = test_alloc(t, nfit_size, &t->nfit_dma); 10266bc75619SDan Williams if (!t->nfit_buf) 10276bc75619SDan Williams return -ENOMEM; 10286bc75619SDan Williams t->nfit_size = nfit_size; 10296bc75619SDan Williams 1030ee8520feSDan Williams t->spa_set[0] = test_alloc(t, SPA2_SIZE, &t->spa_set_dma[0]); 10316bc75619SDan Williams if (!t->spa_set[0]) 10326bc75619SDan Williams return -ENOMEM; 10336bc75619SDan Williams 1034dafb1048SDan Williams for (i = 0; i < t->num_dcr; i++) { 1035dafb1048SDan Williams t->label[i] = test_alloc(t, LABEL_SIZE, &t->label_dma[i]); 1036dafb1048SDan Williams if (!t->label[i]) 1037dafb1048SDan Williams return -ENOMEM; 1038dafb1048SDan Williams sprintf(t->label[i], "label%d", i); 1039dafb1048SDan Williams } 1040dafb1048SDan Williams 10417bfe97c7SDan Williams t->spa_set[1] = test_alloc(t, SPA_VCD_SIZE, &t->spa_set_dma[1]); 10427bfe97c7SDan Williams if (!t->spa_set[1]) 10437bfe97c7SDan Williams return -ENOMEM; 10447bfe97c7SDan Williams 1045*ed07c433SDan Williams smart_init(t); 1046f471f1a7SDan Williams return ars_state_init(&t->pdev.dev, &t->ars_state); 10476bc75619SDan Williams } 10486bc75619SDan Williams 10495dc68e55SDan Williams static void dcr_common_init(struct acpi_nfit_control_region *dcr) 10505dc68e55SDan Williams { 10515dc68e55SDan Williams dcr->vendor_id = 0xabcd; 10525dc68e55SDan Williams dcr->device_id = 0; 10535dc68e55SDan Williams dcr->revision_id = 1; 10545dc68e55SDan Williams dcr->valid_fields = 1; 10555dc68e55SDan Williams dcr->manufacturing_location = 0xa; 10565dc68e55SDan Williams dcr->manufacturing_date = cpu_to_be16(2016); 10575dc68e55SDan Williams } 10585dc68e55SDan Williams 10596bc75619SDan Williams static void nfit_test0_setup(struct nfit_test *t) 10606bc75619SDan Williams { 106185d3fa02SDan Williams const int flush_hint_size = sizeof(struct acpi_nfit_flush_address) 106285d3fa02SDan Williams + (sizeof(u64) * NUM_HINTS); 10636bc75619SDan Williams struct acpi_nfit_desc *acpi_desc; 10646bc75619SDan Williams struct acpi_nfit_memory_map *memdev; 10656bc75619SDan Williams void *nfit_buf = t->nfit_buf; 10666bc75619SDan Williams struct acpi_nfit_system_address *spa; 10676bc75619SDan Williams struct acpi_nfit_control_region *dcr; 10686bc75619SDan Williams struct acpi_nfit_data_region *bdw; 10699d27a87eSDan Williams struct acpi_nfit_flush_address *flush; 107085d3fa02SDan Williams unsigned int offset, i; 10716bc75619SDan Williams 10726bc75619SDan Williams /* 10736bc75619SDan Williams * spa0 (interleave first half of dimm0 and dimm1, note storage 10746bc75619SDan Williams * does not actually alias the related block-data-window 10756bc75619SDan Williams * regions) 10766bc75619SDan Williams */ 10776b577c9dSLinda Knippers spa = nfit_buf; 10786bc75619SDan Williams spa->header.type = ACPI_NFIT_TYPE_SYSTEM_ADDRESS; 10796bc75619SDan Williams spa->header.length = sizeof(*spa); 10806bc75619SDan Williams memcpy(spa->range_guid, to_nfit_uuid(NFIT_SPA_PM), 16); 10816bc75619SDan Williams spa->range_index = 0+1; 10826bc75619SDan Williams spa->address = t->spa_set_dma[0]; 10836bc75619SDan Williams spa->length = SPA0_SIZE; 10846bc75619SDan Williams 10856bc75619SDan Williams /* 10866bc75619SDan Williams * spa1 (interleave last half of the 4 DIMMS, note storage 10876bc75619SDan Williams * does not actually alias the related block-data-window 10886bc75619SDan Williams * regions) 10896bc75619SDan Williams */ 10906b577c9dSLinda Knippers spa = nfit_buf + sizeof(*spa); 10916bc75619SDan Williams spa->header.type = ACPI_NFIT_TYPE_SYSTEM_ADDRESS; 10926bc75619SDan Williams spa->header.length = sizeof(*spa); 10936bc75619SDan Williams memcpy(spa->range_guid, to_nfit_uuid(NFIT_SPA_PM), 16); 10946bc75619SDan Williams spa->range_index = 1+1; 10956bc75619SDan Williams spa->address = t->spa_set_dma[1]; 10966bc75619SDan Williams spa->length = SPA1_SIZE; 10976bc75619SDan Williams 10986bc75619SDan Williams /* spa2 (dcr0) dimm0 */ 10996b577c9dSLinda Knippers spa = nfit_buf + sizeof(*spa) * 2; 11006bc75619SDan Williams spa->header.type = ACPI_NFIT_TYPE_SYSTEM_ADDRESS; 11016bc75619SDan Williams spa->header.length = sizeof(*spa); 11026bc75619SDan Williams memcpy(spa->range_guid, to_nfit_uuid(NFIT_SPA_DCR), 16); 11036bc75619SDan Williams spa->range_index = 2+1; 11046bc75619SDan Williams spa->address = t->dcr_dma[0]; 11056bc75619SDan Williams spa->length = DCR_SIZE; 11066bc75619SDan Williams 11076bc75619SDan Williams /* spa3 (dcr1) dimm1 */ 11086b577c9dSLinda Knippers spa = nfit_buf + sizeof(*spa) * 3; 11096bc75619SDan Williams spa->header.type = ACPI_NFIT_TYPE_SYSTEM_ADDRESS; 11106bc75619SDan Williams spa->header.length = sizeof(*spa); 11116bc75619SDan Williams memcpy(spa->range_guid, to_nfit_uuid(NFIT_SPA_DCR), 16); 11126bc75619SDan Williams spa->range_index = 3+1; 11136bc75619SDan Williams spa->address = t->dcr_dma[1]; 11146bc75619SDan Williams spa->length = DCR_SIZE; 11156bc75619SDan Williams 11166bc75619SDan Williams /* spa4 (dcr2) dimm2 */ 11176b577c9dSLinda Knippers spa = nfit_buf + sizeof(*spa) * 4; 11186bc75619SDan Williams spa->header.type = ACPI_NFIT_TYPE_SYSTEM_ADDRESS; 11196bc75619SDan Williams spa->header.length = sizeof(*spa); 11206bc75619SDan Williams memcpy(spa->range_guid, to_nfit_uuid(NFIT_SPA_DCR), 16); 11216bc75619SDan Williams spa->range_index = 4+1; 11226bc75619SDan Williams spa->address = t->dcr_dma[2]; 11236bc75619SDan Williams spa->length = DCR_SIZE; 11246bc75619SDan Williams 11256bc75619SDan Williams /* spa5 (dcr3) dimm3 */ 11266b577c9dSLinda Knippers spa = nfit_buf + sizeof(*spa) * 5; 11276bc75619SDan Williams spa->header.type = ACPI_NFIT_TYPE_SYSTEM_ADDRESS; 11286bc75619SDan Williams spa->header.length = sizeof(*spa); 11296bc75619SDan Williams memcpy(spa->range_guid, to_nfit_uuid(NFIT_SPA_DCR), 16); 11306bc75619SDan Williams spa->range_index = 5+1; 11316bc75619SDan Williams spa->address = t->dcr_dma[3]; 11326bc75619SDan Williams spa->length = DCR_SIZE; 11336bc75619SDan Williams 11346bc75619SDan Williams /* spa6 (bdw for dcr0) dimm0 */ 11356b577c9dSLinda Knippers spa = nfit_buf + sizeof(*spa) * 6; 11366bc75619SDan Williams spa->header.type = ACPI_NFIT_TYPE_SYSTEM_ADDRESS; 11376bc75619SDan Williams spa->header.length = sizeof(*spa); 11386bc75619SDan Williams memcpy(spa->range_guid, to_nfit_uuid(NFIT_SPA_BDW), 16); 11396bc75619SDan Williams spa->range_index = 6+1; 11406bc75619SDan Williams spa->address = t->dimm_dma[0]; 11416bc75619SDan Williams spa->length = DIMM_SIZE; 11426bc75619SDan Williams 11436bc75619SDan Williams /* spa7 (bdw for dcr1) dimm1 */ 11446b577c9dSLinda Knippers spa = nfit_buf + sizeof(*spa) * 7; 11456bc75619SDan Williams spa->header.type = ACPI_NFIT_TYPE_SYSTEM_ADDRESS; 11466bc75619SDan Williams spa->header.length = sizeof(*spa); 11476bc75619SDan Williams memcpy(spa->range_guid, to_nfit_uuid(NFIT_SPA_BDW), 16); 11486bc75619SDan Williams spa->range_index = 7+1; 11496bc75619SDan Williams spa->address = t->dimm_dma[1]; 11506bc75619SDan Williams spa->length = DIMM_SIZE; 11516bc75619SDan Williams 11526bc75619SDan Williams /* spa8 (bdw for dcr2) dimm2 */ 11536b577c9dSLinda Knippers spa = nfit_buf + sizeof(*spa) * 8; 11546bc75619SDan Williams spa->header.type = ACPI_NFIT_TYPE_SYSTEM_ADDRESS; 11556bc75619SDan Williams spa->header.length = sizeof(*spa); 11566bc75619SDan Williams memcpy(spa->range_guid, to_nfit_uuid(NFIT_SPA_BDW), 16); 11576bc75619SDan Williams spa->range_index = 8+1; 11586bc75619SDan Williams spa->address = t->dimm_dma[2]; 11596bc75619SDan Williams spa->length = DIMM_SIZE; 11606bc75619SDan Williams 11616bc75619SDan Williams /* spa9 (bdw for dcr3) dimm3 */ 11626b577c9dSLinda Knippers spa = nfit_buf + sizeof(*spa) * 9; 11636bc75619SDan Williams spa->header.type = ACPI_NFIT_TYPE_SYSTEM_ADDRESS; 11646bc75619SDan Williams spa->header.length = sizeof(*spa); 11656bc75619SDan Williams memcpy(spa->range_guid, to_nfit_uuid(NFIT_SPA_BDW), 16); 11666bc75619SDan Williams spa->range_index = 9+1; 11676bc75619SDan Williams spa->address = t->dimm_dma[3]; 11686bc75619SDan Williams spa->length = DIMM_SIZE; 11696bc75619SDan Williams 11706b577c9dSLinda Knippers offset = sizeof(*spa) * 10; 11716bc75619SDan Williams /* mem-region0 (spa0, dimm0) */ 11726bc75619SDan Williams memdev = nfit_buf + offset; 11736bc75619SDan Williams memdev->header.type = ACPI_NFIT_TYPE_MEMORY_MAP; 11746bc75619SDan Williams memdev->header.length = sizeof(*memdev); 11756bc75619SDan Williams memdev->device_handle = handle[0]; 11766bc75619SDan Williams memdev->physical_id = 0; 11776bc75619SDan Williams memdev->region_id = 0; 11786bc75619SDan Williams memdev->range_index = 0+1; 11793b87356fSDan Williams memdev->region_index = 4+1; 11806bc75619SDan Williams memdev->region_size = SPA0_SIZE/2; 1181df06a2d5SDan Williams memdev->region_offset = 1; 11826bc75619SDan Williams memdev->address = 0; 11836bc75619SDan Williams memdev->interleave_index = 0; 11846bc75619SDan Williams memdev->interleave_ways = 2; 11856bc75619SDan Williams 11866bc75619SDan Williams /* mem-region1 (spa0, dimm1) */ 11876bc75619SDan Williams memdev = nfit_buf + offset + sizeof(struct acpi_nfit_memory_map); 11886bc75619SDan Williams memdev->header.type = ACPI_NFIT_TYPE_MEMORY_MAP; 11896bc75619SDan Williams memdev->header.length = sizeof(*memdev); 11906bc75619SDan Williams memdev->device_handle = handle[1]; 11916bc75619SDan Williams memdev->physical_id = 1; 11926bc75619SDan Williams memdev->region_id = 0; 11936bc75619SDan Williams memdev->range_index = 0+1; 11943b87356fSDan Williams memdev->region_index = 5+1; 11956bc75619SDan Williams memdev->region_size = SPA0_SIZE/2; 1196df06a2d5SDan Williams memdev->region_offset = (1 << 8); 11976bc75619SDan Williams memdev->address = 0; 11986bc75619SDan Williams memdev->interleave_index = 0; 11996bc75619SDan Williams memdev->interleave_ways = 2; 1200ac40b675SDan Williams memdev->flags = ACPI_NFIT_MEM_HEALTH_ENABLED; 12016bc75619SDan Williams 12026bc75619SDan Williams /* mem-region2 (spa1, dimm0) */ 12036bc75619SDan Williams memdev = nfit_buf + offset + sizeof(struct acpi_nfit_memory_map) * 2; 12046bc75619SDan Williams memdev->header.type = ACPI_NFIT_TYPE_MEMORY_MAP; 12056bc75619SDan Williams memdev->header.length = sizeof(*memdev); 12066bc75619SDan Williams memdev->device_handle = handle[0]; 12076bc75619SDan Williams memdev->physical_id = 0; 12086bc75619SDan Williams memdev->region_id = 1; 12096bc75619SDan Williams memdev->range_index = 1+1; 12103b87356fSDan Williams memdev->region_index = 4+1; 12116bc75619SDan Williams memdev->region_size = SPA1_SIZE/4; 1212df06a2d5SDan Williams memdev->region_offset = (1 << 16); 12136bc75619SDan Williams memdev->address = SPA0_SIZE/2; 12146bc75619SDan Williams memdev->interleave_index = 0; 12156bc75619SDan Williams memdev->interleave_ways = 4; 1216ac40b675SDan Williams memdev->flags = ACPI_NFIT_MEM_HEALTH_ENABLED; 12176bc75619SDan Williams 12186bc75619SDan Williams /* mem-region3 (spa1, dimm1) */ 12196bc75619SDan Williams memdev = nfit_buf + offset + sizeof(struct acpi_nfit_memory_map) * 3; 12206bc75619SDan Williams memdev->header.type = ACPI_NFIT_TYPE_MEMORY_MAP; 12216bc75619SDan Williams memdev->header.length = sizeof(*memdev); 12226bc75619SDan Williams memdev->device_handle = handle[1]; 12236bc75619SDan Williams memdev->physical_id = 1; 12246bc75619SDan Williams memdev->region_id = 1; 12256bc75619SDan Williams memdev->range_index = 1+1; 12263b87356fSDan Williams memdev->region_index = 5+1; 12276bc75619SDan Williams memdev->region_size = SPA1_SIZE/4; 1228df06a2d5SDan Williams memdev->region_offset = (1 << 24); 12296bc75619SDan Williams memdev->address = SPA0_SIZE/2; 12306bc75619SDan Williams memdev->interleave_index = 0; 12316bc75619SDan Williams memdev->interleave_ways = 4; 12326bc75619SDan Williams 12336bc75619SDan Williams /* mem-region4 (spa1, dimm2) */ 12346bc75619SDan Williams memdev = nfit_buf + offset + sizeof(struct acpi_nfit_memory_map) * 4; 12356bc75619SDan Williams memdev->header.type = ACPI_NFIT_TYPE_MEMORY_MAP; 12366bc75619SDan Williams memdev->header.length = sizeof(*memdev); 12376bc75619SDan Williams memdev->device_handle = handle[2]; 12386bc75619SDan Williams memdev->physical_id = 2; 12396bc75619SDan Williams memdev->region_id = 0; 12406bc75619SDan Williams memdev->range_index = 1+1; 12413b87356fSDan Williams memdev->region_index = 6+1; 12426bc75619SDan Williams memdev->region_size = SPA1_SIZE/4; 1243df06a2d5SDan Williams memdev->region_offset = (1ULL << 32); 12446bc75619SDan Williams memdev->address = SPA0_SIZE/2; 12456bc75619SDan Williams memdev->interleave_index = 0; 12466bc75619SDan Williams memdev->interleave_ways = 4; 1247ac40b675SDan Williams memdev->flags = ACPI_NFIT_MEM_HEALTH_ENABLED; 12486bc75619SDan Williams 12496bc75619SDan Williams /* mem-region5 (spa1, dimm3) */ 12506bc75619SDan Williams memdev = nfit_buf + offset + sizeof(struct acpi_nfit_memory_map) * 5; 12516bc75619SDan Williams memdev->header.type = ACPI_NFIT_TYPE_MEMORY_MAP; 12526bc75619SDan Williams memdev->header.length = sizeof(*memdev); 12536bc75619SDan Williams memdev->device_handle = handle[3]; 12546bc75619SDan Williams memdev->physical_id = 3; 12556bc75619SDan Williams memdev->region_id = 0; 12566bc75619SDan Williams memdev->range_index = 1+1; 12573b87356fSDan Williams memdev->region_index = 7+1; 12586bc75619SDan Williams memdev->region_size = SPA1_SIZE/4; 1259df06a2d5SDan Williams memdev->region_offset = (1ULL << 40); 12606bc75619SDan Williams memdev->address = SPA0_SIZE/2; 12616bc75619SDan Williams memdev->interleave_index = 0; 12626bc75619SDan Williams memdev->interleave_ways = 4; 12636bc75619SDan Williams 12646bc75619SDan Williams /* mem-region6 (spa/dcr0, dimm0) */ 12656bc75619SDan Williams memdev = nfit_buf + offset + sizeof(struct acpi_nfit_memory_map) * 6; 12666bc75619SDan Williams memdev->header.type = ACPI_NFIT_TYPE_MEMORY_MAP; 12676bc75619SDan Williams memdev->header.length = sizeof(*memdev); 12686bc75619SDan Williams memdev->device_handle = handle[0]; 12696bc75619SDan Williams memdev->physical_id = 0; 12706bc75619SDan Williams memdev->region_id = 0; 12716bc75619SDan Williams memdev->range_index = 2+1; 12726bc75619SDan Williams memdev->region_index = 0+1; 12736bc75619SDan Williams memdev->region_size = 0; 12746bc75619SDan Williams memdev->region_offset = 0; 12756bc75619SDan Williams memdev->address = 0; 12766bc75619SDan Williams memdev->interleave_index = 0; 12776bc75619SDan Williams memdev->interleave_ways = 1; 12786bc75619SDan Williams 12796bc75619SDan Williams /* mem-region7 (spa/dcr1, dimm1) */ 12806bc75619SDan Williams memdev = nfit_buf + offset + sizeof(struct acpi_nfit_memory_map) * 7; 12816bc75619SDan Williams memdev->header.type = ACPI_NFIT_TYPE_MEMORY_MAP; 12826bc75619SDan Williams memdev->header.length = sizeof(*memdev); 12836bc75619SDan Williams memdev->device_handle = handle[1]; 12846bc75619SDan Williams memdev->physical_id = 1; 12856bc75619SDan Williams memdev->region_id = 0; 12866bc75619SDan Williams memdev->range_index = 3+1; 12876bc75619SDan Williams memdev->region_index = 1+1; 12886bc75619SDan Williams memdev->region_size = 0; 12896bc75619SDan Williams memdev->region_offset = 0; 12906bc75619SDan Williams memdev->address = 0; 12916bc75619SDan Williams memdev->interleave_index = 0; 12926bc75619SDan Williams memdev->interleave_ways = 1; 12936bc75619SDan Williams 12946bc75619SDan Williams /* mem-region8 (spa/dcr2, dimm2) */ 12956bc75619SDan Williams memdev = nfit_buf + offset + sizeof(struct acpi_nfit_memory_map) * 8; 12966bc75619SDan Williams memdev->header.type = ACPI_NFIT_TYPE_MEMORY_MAP; 12976bc75619SDan Williams memdev->header.length = sizeof(*memdev); 12986bc75619SDan Williams memdev->device_handle = handle[2]; 12996bc75619SDan Williams memdev->physical_id = 2; 13006bc75619SDan Williams memdev->region_id = 0; 13016bc75619SDan Williams memdev->range_index = 4+1; 13026bc75619SDan Williams memdev->region_index = 2+1; 13036bc75619SDan Williams memdev->region_size = 0; 13046bc75619SDan Williams memdev->region_offset = 0; 13056bc75619SDan Williams memdev->address = 0; 13066bc75619SDan Williams memdev->interleave_index = 0; 13076bc75619SDan Williams memdev->interleave_ways = 1; 13086bc75619SDan Williams 13096bc75619SDan Williams /* mem-region9 (spa/dcr3, dimm3) */ 13106bc75619SDan Williams memdev = nfit_buf + offset + sizeof(struct acpi_nfit_memory_map) * 9; 13116bc75619SDan Williams memdev->header.type = ACPI_NFIT_TYPE_MEMORY_MAP; 13126bc75619SDan Williams memdev->header.length = sizeof(*memdev); 13136bc75619SDan Williams memdev->device_handle = handle[3]; 13146bc75619SDan Williams memdev->physical_id = 3; 13156bc75619SDan Williams memdev->region_id = 0; 13166bc75619SDan Williams memdev->range_index = 5+1; 13176bc75619SDan Williams memdev->region_index = 3+1; 13186bc75619SDan Williams memdev->region_size = 0; 13196bc75619SDan Williams memdev->region_offset = 0; 13206bc75619SDan Williams memdev->address = 0; 13216bc75619SDan Williams memdev->interleave_index = 0; 13226bc75619SDan Williams memdev->interleave_ways = 1; 13236bc75619SDan Williams 13246bc75619SDan Williams /* mem-region10 (spa/bdw0, dimm0) */ 13256bc75619SDan Williams memdev = nfit_buf + offset + sizeof(struct acpi_nfit_memory_map) * 10; 13266bc75619SDan Williams memdev->header.type = ACPI_NFIT_TYPE_MEMORY_MAP; 13276bc75619SDan Williams memdev->header.length = sizeof(*memdev); 13286bc75619SDan Williams memdev->device_handle = handle[0]; 13296bc75619SDan Williams memdev->physical_id = 0; 13306bc75619SDan Williams memdev->region_id = 0; 13316bc75619SDan Williams memdev->range_index = 6+1; 13326bc75619SDan Williams memdev->region_index = 0+1; 13336bc75619SDan Williams memdev->region_size = 0; 13346bc75619SDan Williams memdev->region_offset = 0; 13356bc75619SDan Williams memdev->address = 0; 13366bc75619SDan Williams memdev->interleave_index = 0; 13376bc75619SDan Williams memdev->interleave_ways = 1; 13386bc75619SDan Williams 13396bc75619SDan Williams /* mem-region11 (spa/bdw1, dimm1) */ 13406bc75619SDan Williams memdev = nfit_buf + offset + sizeof(struct acpi_nfit_memory_map) * 11; 13416bc75619SDan Williams memdev->header.type = ACPI_NFIT_TYPE_MEMORY_MAP; 13426bc75619SDan Williams memdev->header.length = sizeof(*memdev); 13436bc75619SDan Williams memdev->device_handle = handle[1]; 13446bc75619SDan Williams memdev->physical_id = 1; 13456bc75619SDan Williams memdev->region_id = 0; 13466bc75619SDan Williams memdev->range_index = 7+1; 13476bc75619SDan Williams memdev->region_index = 1+1; 13486bc75619SDan Williams memdev->region_size = 0; 13496bc75619SDan Williams memdev->region_offset = 0; 13506bc75619SDan Williams memdev->address = 0; 13516bc75619SDan Williams memdev->interleave_index = 0; 13526bc75619SDan Williams memdev->interleave_ways = 1; 13536bc75619SDan Williams 13546bc75619SDan Williams /* mem-region12 (spa/bdw2, dimm2) */ 13556bc75619SDan Williams memdev = nfit_buf + offset + sizeof(struct acpi_nfit_memory_map) * 12; 13566bc75619SDan Williams memdev->header.type = ACPI_NFIT_TYPE_MEMORY_MAP; 13576bc75619SDan Williams memdev->header.length = sizeof(*memdev); 13586bc75619SDan Williams memdev->device_handle = handle[2]; 13596bc75619SDan Williams memdev->physical_id = 2; 13606bc75619SDan Williams memdev->region_id = 0; 13616bc75619SDan Williams memdev->range_index = 8+1; 13626bc75619SDan Williams memdev->region_index = 2+1; 13636bc75619SDan Williams memdev->region_size = 0; 13646bc75619SDan Williams memdev->region_offset = 0; 13656bc75619SDan Williams memdev->address = 0; 13666bc75619SDan Williams memdev->interleave_index = 0; 13676bc75619SDan Williams memdev->interleave_ways = 1; 13686bc75619SDan Williams 13696bc75619SDan Williams /* mem-region13 (spa/dcr3, dimm3) */ 13706bc75619SDan Williams memdev = nfit_buf + offset + sizeof(struct acpi_nfit_memory_map) * 13; 13716bc75619SDan Williams memdev->header.type = ACPI_NFIT_TYPE_MEMORY_MAP; 13726bc75619SDan Williams memdev->header.length = sizeof(*memdev); 13736bc75619SDan Williams memdev->device_handle = handle[3]; 13746bc75619SDan Williams memdev->physical_id = 3; 13756bc75619SDan Williams memdev->region_id = 0; 13766bc75619SDan Williams memdev->range_index = 9+1; 13776bc75619SDan Williams memdev->region_index = 3+1; 13786bc75619SDan Williams memdev->region_size = 0; 13796bc75619SDan Williams memdev->region_offset = 0; 13806bc75619SDan Williams memdev->address = 0; 13816bc75619SDan Williams memdev->interleave_index = 0; 13826bc75619SDan Williams memdev->interleave_ways = 1; 1383ac40b675SDan Williams memdev->flags = ACPI_NFIT_MEM_HEALTH_ENABLED; 13846bc75619SDan Williams 13856bc75619SDan Williams offset = offset + sizeof(struct acpi_nfit_memory_map) * 14; 13863b87356fSDan Williams /* dcr-descriptor0: blk */ 13876bc75619SDan Williams dcr = nfit_buf + offset; 13886bc75619SDan Williams dcr->header.type = ACPI_NFIT_TYPE_CONTROL_REGION; 13896bc75619SDan Williams dcr->header.length = sizeof(struct acpi_nfit_control_region); 13906bc75619SDan Williams dcr->region_index = 0+1; 13915dc68e55SDan Williams dcr_common_init(dcr); 13926bc75619SDan Williams dcr->serial_number = ~handle[0]; 1393be26f9aeSDan Williams dcr->code = NFIT_FIC_BLK; 13946bc75619SDan Williams dcr->windows = 1; 13956bc75619SDan Williams dcr->window_size = DCR_SIZE; 13966bc75619SDan Williams dcr->command_offset = 0; 13976bc75619SDan Williams dcr->command_size = 8; 13986bc75619SDan Williams dcr->status_offset = 8; 13996bc75619SDan Williams dcr->status_size = 4; 14006bc75619SDan Williams 14013b87356fSDan Williams /* dcr-descriptor1: blk */ 14026bc75619SDan Williams dcr = nfit_buf + offset + sizeof(struct acpi_nfit_control_region); 14036bc75619SDan Williams dcr->header.type = ACPI_NFIT_TYPE_CONTROL_REGION; 14046bc75619SDan Williams dcr->header.length = sizeof(struct acpi_nfit_control_region); 14056bc75619SDan Williams dcr->region_index = 1+1; 14065dc68e55SDan Williams dcr_common_init(dcr); 14076bc75619SDan Williams dcr->serial_number = ~handle[1]; 1408be26f9aeSDan Williams dcr->code = NFIT_FIC_BLK; 14096bc75619SDan Williams dcr->windows = 1; 14106bc75619SDan Williams dcr->window_size = DCR_SIZE; 14116bc75619SDan Williams dcr->command_offset = 0; 14126bc75619SDan Williams dcr->command_size = 8; 14136bc75619SDan Williams dcr->status_offset = 8; 14146bc75619SDan Williams dcr->status_size = 4; 14156bc75619SDan Williams 14163b87356fSDan Williams /* dcr-descriptor2: blk */ 14176bc75619SDan Williams dcr = nfit_buf + offset + sizeof(struct acpi_nfit_control_region) * 2; 14186bc75619SDan Williams dcr->header.type = ACPI_NFIT_TYPE_CONTROL_REGION; 14196bc75619SDan Williams dcr->header.length = sizeof(struct acpi_nfit_control_region); 14206bc75619SDan Williams dcr->region_index = 2+1; 14215dc68e55SDan Williams dcr_common_init(dcr); 14226bc75619SDan Williams dcr->serial_number = ~handle[2]; 1423be26f9aeSDan Williams dcr->code = NFIT_FIC_BLK; 14246bc75619SDan Williams dcr->windows = 1; 14256bc75619SDan Williams dcr->window_size = DCR_SIZE; 14266bc75619SDan Williams dcr->command_offset = 0; 14276bc75619SDan Williams dcr->command_size = 8; 14286bc75619SDan Williams dcr->status_offset = 8; 14296bc75619SDan Williams dcr->status_size = 4; 14306bc75619SDan Williams 14313b87356fSDan Williams /* dcr-descriptor3: blk */ 14326bc75619SDan Williams dcr = nfit_buf + offset + sizeof(struct acpi_nfit_control_region) * 3; 14336bc75619SDan Williams dcr->header.type = ACPI_NFIT_TYPE_CONTROL_REGION; 14346bc75619SDan Williams dcr->header.length = sizeof(struct acpi_nfit_control_region); 14356bc75619SDan Williams dcr->region_index = 3+1; 14365dc68e55SDan Williams dcr_common_init(dcr); 14376bc75619SDan Williams dcr->serial_number = ~handle[3]; 1438be26f9aeSDan Williams dcr->code = NFIT_FIC_BLK; 14396bc75619SDan Williams dcr->windows = 1; 14406bc75619SDan Williams dcr->window_size = DCR_SIZE; 14416bc75619SDan Williams dcr->command_offset = 0; 14426bc75619SDan Williams dcr->command_size = 8; 14436bc75619SDan Williams dcr->status_offset = 8; 14446bc75619SDan Williams dcr->status_size = 4; 14456bc75619SDan Williams 14466bc75619SDan Williams offset = offset + sizeof(struct acpi_nfit_control_region) * 4; 14473b87356fSDan Williams /* dcr-descriptor0: pmem */ 14483b87356fSDan Williams dcr = nfit_buf + offset; 14493b87356fSDan Williams dcr->header.type = ACPI_NFIT_TYPE_CONTROL_REGION; 14503b87356fSDan Williams dcr->header.length = offsetof(struct acpi_nfit_control_region, 14513b87356fSDan Williams window_size); 14523b87356fSDan Williams dcr->region_index = 4+1; 14535dc68e55SDan Williams dcr_common_init(dcr); 14543b87356fSDan Williams dcr->serial_number = ~handle[0]; 14553b87356fSDan Williams dcr->code = NFIT_FIC_BYTEN; 14563b87356fSDan Williams dcr->windows = 0; 14573b87356fSDan Williams 14583b87356fSDan Williams /* dcr-descriptor1: pmem */ 14593b87356fSDan Williams dcr = nfit_buf + offset + offsetof(struct acpi_nfit_control_region, 14603b87356fSDan Williams window_size); 14613b87356fSDan Williams dcr->header.type = ACPI_NFIT_TYPE_CONTROL_REGION; 14623b87356fSDan Williams dcr->header.length = offsetof(struct acpi_nfit_control_region, 14633b87356fSDan Williams window_size); 14643b87356fSDan Williams dcr->region_index = 5+1; 14655dc68e55SDan Williams dcr_common_init(dcr); 14663b87356fSDan Williams dcr->serial_number = ~handle[1]; 14673b87356fSDan Williams dcr->code = NFIT_FIC_BYTEN; 14683b87356fSDan Williams dcr->windows = 0; 14693b87356fSDan Williams 14703b87356fSDan Williams /* dcr-descriptor2: pmem */ 14713b87356fSDan Williams dcr = nfit_buf + offset + offsetof(struct acpi_nfit_control_region, 14723b87356fSDan Williams window_size) * 2; 14733b87356fSDan Williams dcr->header.type = ACPI_NFIT_TYPE_CONTROL_REGION; 14743b87356fSDan Williams dcr->header.length = offsetof(struct acpi_nfit_control_region, 14753b87356fSDan Williams window_size); 14763b87356fSDan Williams dcr->region_index = 6+1; 14775dc68e55SDan Williams dcr_common_init(dcr); 14783b87356fSDan Williams dcr->serial_number = ~handle[2]; 14793b87356fSDan Williams dcr->code = NFIT_FIC_BYTEN; 14803b87356fSDan Williams dcr->windows = 0; 14813b87356fSDan Williams 14823b87356fSDan Williams /* dcr-descriptor3: pmem */ 14833b87356fSDan Williams dcr = nfit_buf + offset + offsetof(struct acpi_nfit_control_region, 14843b87356fSDan Williams window_size) * 3; 14853b87356fSDan Williams dcr->header.type = ACPI_NFIT_TYPE_CONTROL_REGION; 14863b87356fSDan Williams dcr->header.length = offsetof(struct acpi_nfit_control_region, 14873b87356fSDan Williams window_size); 14883b87356fSDan Williams dcr->region_index = 7+1; 14895dc68e55SDan Williams dcr_common_init(dcr); 14903b87356fSDan Williams dcr->serial_number = ~handle[3]; 14913b87356fSDan Williams dcr->code = NFIT_FIC_BYTEN; 14923b87356fSDan Williams dcr->windows = 0; 14933b87356fSDan Williams 14943b87356fSDan Williams offset = offset + offsetof(struct acpi_nfit_control_region, 14953b87356fSDan Williams window_size) * 4; 14966bc75619SDan Williams /* bdw0 (spa/dcr0, dimm0) */ 14976bc75619SDan Williams bdw = nfit_buf + offset; 14986bc75619SDan Williams bdw->header.type = ACPI_NFIT_TYPE_DATA_REGION; 14996bc75619SDan Williams bdw->header.length = sizeof(struct acpi_nfit_data_region); 15006bc75619SDan Williams bdw->region_index = 0+1; 15016bc75619SDan Williams bdw->windows = 1; 15026bc75619SDan Williams bdw->offset = 0; 15036bc75619SDan Williams bdw->size = BDW_SIZE; 15046bc75619SDan Williams bdw->capacity = DIMM_SIZE; 15056bc75619SDan Williams bdw->start_address = 0; 15066bc75619SDan Williams 15076bc75619SDan Williams /* bdw1 (spa/dcr1, dimm1) */ 15086bc75619SDan Williams bdw = nfit_buf + offset + sizeof(struct acpi_nfit_data_region); 15096bc75619SDan Williams bdw->header.type = ACPI_NFIT_TYPE_DATA_REGION; 15106bc75619SDan Williams bdw->header.length = sizeof(struct acpi_nfit_data_region); 15116bc75619SDan Williams bdw->region_index = 1+1; 15126bc75619SDan Williams bdw->windows = 1; 15136bc75619SDan Williams bdw->offset = 0; 15146bc75619SDan Williams bdw->size = BDW_SIZE; 15156bc75619SDan Williams bdw->capacity = DIMM_SIZE; 15166bc75619SDan Williams bdw->start_address = 0; 15176bc75619SDan Williams 15186bc75619SDan Williams /* bdw2 (spa/dcr2, dimm2) */ 15196bc75619SDan Williams bdw = nfit_buf + offset + sizeof(struct acpi_nfit_data_region) * 2; 15206bc75619SDan Williams bdw->header.type = ACPI_NFIT_TYPE_DATA_REGION; 15216bc75619SDan Williams bdw->header.length = sizeof(struct acpi_nfit_data_region); 15226bc75619SDan Williams bdw->region_index = 2+1; 15236bc75619SDan Williams bdw->windows = 1; 15246bc75619SDan Williams bdw->offset = 0; 15256bc75619SDan Williams bdw->size = BDW_SIZE; 15266bc75619SDan Williams bdw->capacity = DIMM_SIZE; 15276bc75619SDan Williams bdw->start_address = 0; 15286bc75619SDan Williams 15296bc75619SDan Williams /* bdw3 (spa/dcr3, dimm3) */ 15306bc75619SDan Williams bdw = nfit_buf + offset + sizeof(struct acpi_nfit_data_region) * 3; 15316bc75619SDan Williams bdw->header.type = ACPI_NFIT_TYPE_DATA_REGION; 15326bc75619SDan Williams bdw->header.length = sizeof(struct acpi_nfit_data_region); 15336bc75619SDan Williams bdw->region_index = 3+1; 15346bc75619SDan Williams bdw->windows = 1; 15356bc75619SDan Williams bdw->offset = 0; 15366bc75619SDan Williams bdw->size = BDW_SIZE; 15376bc75619SDan Williams bdw->capacity = DIMM_SIZE; 15386bc75619SDan Williams bdw->start_address = 0; 15396bc75619SDan Williams 15409d27a87eSDan Williams offset = offset + sizeof(struct acpi_nfit_data_region) * 4; 15419d27a87eSDan Williams /* flush0 (dimm0) */ 15429d27a87eSDan Williams flush = nfit_buf + offset; 15439d27a87eSDan Williams flush->header.type = ACPI_NFIT_TYPE_FLUSH_ADDRESS; 154485d3fa02SDan Williams flush->header.length = flush_hint_size; 15459d27a87eSDan Williams flush->device_handle = handle[0]; 154685d3fa02SDan Williams flush->hint_count = NUM_HINTS; 154785d3fa02SDan Williams for (i = 0; i < NUM_HINTS; i++) 154885d3fa02SDan Williams flush->hint_address[i] = t->flush_dma[0] + i * sizeof(u64); 15499d27a87eSDan Williams 15509d27a87eSDan Williams /* flush1 (dimm1) */ 155185d3fa02SDan Williams flush = nfit_buf + offset + flush_hint_size * 1; 15529d27a87eSDan Williams flush->header.type = ACPI_NFIT_TYPE_FLUSH_ADDRESS; 155385d3fa02SDan Williams flush->header.length = flush_hint_size; 15549d27a87eSDan Williams flush->device_handle = handle[1]; 155585d3fa02SDan Williams flush->hint_count = NUM_HINTS; 155685d3fa02SDan Williams for (i = 0; i < NUM_HINTS; i++) 155785d3fa02SDan Williams flush->hint_address[i] = t->flush_dma[1] + i * sizeof(u64); 15589d27a87eSDan Williams 15599d27a87eSDan Williams /* flush2 (dimm2) */ 156085d3fa02SDan Williams flush = nfit_buf + offset + flush_hint_size * 2; 15619d27a87eSDan Williams flush->header.type = ACPI_NFIT_TYPE_FLUSH_ADDRESS; 156285d3fa02SDan Williams flush->header.length = flush_hint_size; 15639d27a87eSDan Williams flush->device_handle = handle[2]; 156485d3fa02SDan Williams flush->hint_count = NUM_HINTS; 156585d3fa02SDan Williams for (i = 0; i < NUM_HINTS; i++) 156685d3fa02SDan Williams flush->hint_address[i] = t->flush_dma[2] + i * sizeof(u64); 15679d27a87eSDan Williams 15689d27a87eSDan Williams /* flush3 (dimm3) */ 156985d3fa02SDan Williams flush = nfit_buf + offset + flush_hint_size * 3; 15709d27a87eSDan Williams flush->header.type = ACPI_NFIT_TYPE_FLUSH_ADDRESS; 157185d3fa02SDan Williams flush->header.length = flush_hint_size; 15729d27a87eSDan Williams flush->device_handle = handle[3]; 157385d3fa02SDan Williams flush->hint_count = NUM_HINTS; 157485d3fa02SDan Williams for (i = 0; i < NUM_HINTS; i++) 157585d3fa02SDan Williams flush->hint_address[i] = t->flush_dma[3] + i * sizeof(u64); 15769d27a87eSDan Williams 157720985164SVishal Verma if (t->setup_hotplug) { 157885d3fa02SDan Williams offset = offset + flush_hint_size * 4; 15793b87356fSDan Williams /* dcr-descriptor4: blk */ 158020985164SVishal Verma dcr = nfit_buf + offset; 158120985164SVishal Verma dcr->header.type = ACPI_NFIT_TYPE_CONTROL_REGION; 158220985164SVishal Verma dcr->header.length = sizeof(struct acpi_nfit_control_region); 15833b87356fSDan Williams dcr->region_index = 8+1; 15845dc68e55SDan Williams dcr_common_init(dcr); 158520985164SVishal Verma dcr->serial_number = ~handle[4]; 1586be26f9aeSDan Williams dcr->code = NFIT_FIC_BLK; 158720985164SVishal Verma dcr->windows = 1; 158820985164SVishal Verma dcr->window_size = DCR_SIZE; 158920985164SVishal Verma dcr->command_offset = 0; 159020985164SVishal Verma dcr->command_size = 8; 159120985164SVishal Verma dcr->status_offset = 8; 159220985164SVishal Verma dcr->status_size = 4; 159320985164SVishal Verma 159420985164SVishal Verma offset = offset + sizeof(struct acpi_nfit_control_region); 15953b87356fSDan Williams /* dcr-descriptor4: pmem */ 15963b87356fSDan Williams dcr = nfit_buf + offset; 15973b87356fSDan Williams dcr->header.type = ACPI_NFIT_TYPE_CONTROL_REGION; 15983b87356fSDan Williams dcr->header.length = offsetof(struct acpi_nfit_control_region, 15993b87356fSDan Williams window_size); 16003b87356fSDan Williams dcr->region_index = 9+1; 16015dc68e55SDan Williams dcr_common_init(dcr); 16023b87356fSDan Williams dcr->serial_number = ~handle[4]; 16033b87356fSDan Williams dcr->code = NFIT_FIC_BYTEN; 16043b87356fSDan Williams dcr->windows = 0; 16053b87356fSDan Williams 16063b87356fSDan Williams offset = offset + offsetof(struct acpi_nfit_control_region, 16073b87356fSDan Williams window_size); 160820985164SVishal Verma /* bdw4 (spa/dcr4, dimm4) */ 160920985164SVishal Verma bdw = nfit_buf + offset; 161020985164SVishal Verma bdw->header.type = ACPI_NFIT_TYPE_DATA_REGION; 161120985164SVishal Verma bdw->header.length = sizeof(struct acpi_nfit_data_region); 16123b87356fSDan Williams bdw->region_index = 8+1; 161320985164SVishal Verma bdw->windows = 1; 161420985164SVishal Verma bdw->offset = 0; 161520985164SVishal Verma bdw->size = BDW_SIZE; 161620985164SVishal Verma bdw->capacity = DIMM_SIZE; 161720985164SVishal Verma bdw->start_address = 0; 161820985164SVishal Verma 161920985164SVishal Verma offset = offset + sizeof(struct acpi_nfit_data_region); 162020985164SVishal Verma /* spa10 (dcr4) dimm4 */ 162120985164SVishal Verma spa = nfit_buf + offset; 162220985164SVishal Verma spa->header.type = ACPI_NFIT_TYPE_SYSTEM_ADDRESS; 162320985164SVishal Verma spa->header.length = sizeof(*spa); 162420985164SVishal Verma memcpy(spa->range_guid, to_nfit_uuid(NFIT_SPA_DCR), 16); 162520985164SVishal Verma spa->range_index = 10+1; 162620985164SVishal Verma spa->address = t->dcr_dma[4]; 162720985164SVishal Verma spa->length = DCR_SIZE; 162820985164SVishal Verma 162920985164SVishal Verma /* 163020985164SVishal Verma * spa11 (single-dimm interleave for hotplug, note storage 163120985164SVishal Verma * does not actually alias the related block-data-window 163220985164SVishal Verma * regions) 163320985164SVishal Verma */ 163420985164SVishal Verma spa = nfit_buf + offset + sizeof(*spa); 163520985164SVishal Verma spa->header.type = ACPI_NFIT_TYPE_SYSTEM_ADDRESS; 163620985164SVishal Verma spa->header.length = sizeof(*spa); 163720985164SVishal Verma memcpy(spa->range_guid, to_nfit_uuid(NFIT_SPA_PM), 16); 163820985164SVishal Verma spa->range_index = 11+1; 163920985164SVishal Verma spa->address = t->spa_set_dma[2]; 164020985164SVishal Verma spa->length = SPA0_SIZE; 164120985164SVishal Verma 164220985164SVishal Verma /* spa12 (bdw for dcr4) dimm4 */ 164320985164SVishal Verma spa = nfit_buf + offset + sizeof(*spa) * 2; 164420985164SVishal Verma spa->header.type = ACPI_NFIT_TYPE_SYSTEM_ADDRESS; 164520985164SVishal Verma spa->header.length = sizeof(*spa); 164620985164SVishal Verma memcpy(spa->range_guid, to_nfit_uuid(NFIT_SPA_BDW), 16); 164720985164SVishal Verma spa->range_index = 12+1; 164820985164SVishal Verma spa->address = t->dimm_dma[4]; 164920985164SVishal Verma spa->length = DIMM_SIZE; 165020985164SVishal Verma 165120985164SVishal Verma offset = offset + sizeof(*spa) * 3; 165220985164SVishal Verma /* mem-region14 (spa/dcr4, dimm4) */ 165320985164SVishal Verma memdev = nfit_buf + offset; 165420985164SVishal Verma memdev->header.type = ACPI_NFIT_TYPE_MEMORY_MAP; 165520985164SVishal Verma memdev->header.length = sizeof(*memdev); 165620985164SVishal Verma memdev->device_handle = handle[4]; 165720985164SVishal Verma memdev->physical_id = 4; 165820985164SVishal Verma memdev->region_id = 0; 165920985164SVishal Verma memdev->range_index = 10+1; 16603b87356fSDan Williams memdev->region_index = 8+1; 166120985164SVishal Verma memdev->region_size = 0; 166220985164SVishal Verma memdev->region_offset = 0; 166320985164SVishal Verma memdev->address = 0; 166420985164SVishal Verma memdev->interleave_index = 0; 166520985164SVishal Verma memdev->interleave_ways = 1; 166620985164SVishal Verma 166720985164SVishal Verma /* mem-region15 (spa0, dimm4) */ 166820985164SVishal Verma memdev = nfit_buf + offset + 166920985164SVishal Verma sizeof(struct acpi_nfit_memory_map); 167020985164SVishal Verma memdev->header.type = ACPI_NFIT_TYPE_MEMORY_MAP; 167120985164SVishal Verma memdev->header.length = sizeof(*memdev); 167220985164SVishal Verma memdev->device_handle = handle[4]; 167320985164SVishal Verma memdev->physical_id = 4; 167420985164SVishal Verma memdev->region_id = 0; 167520985164SVishal Verma memdev->range_index = 11+1; 16763b87356fSDan Williams memdev->region_index = 9+1; 167720985164SVishal Verma memdev->region_size = SPA0_SIZE; 1678df06a2d5SDan Williams memdev->region_offset = (1ULL << 48); 167920985164SVishal Verma memdev->address = 0; 168020985164SVishal Verma memdev->interleave_index = 0; 168120985164SVishal Verma memdev->interleave_ways = 1; 1682ac40b675SDan Williams memdev->flags = ACPI_NFIT_MEM_HEALTH_ENABLED; 168320985164SVishal Verma 16843b87356fSDan Williams /* mem-region16 (spa/bdw4, dimm4) */ 168520985164SVishal Verma memdev = nfit_buf + offset + 168620985164SVishal Verma sizeof(struct acpi_nfit_memory_map) * 2; 168720985164SVishal Verma memdev->header.type = ACPI_NFIT_TYPE_MEMORY_MAP; 168820985164SVishal Verma memdev->header.length = sizeof(*memdev); 168920985164SVishal Verma memdev->device_handle = handle[4]; 169020985164SVishal Verma memdev->physical_id = 4; 169120985164SVishal Verma memdev->region_id = 0; 169220985164SVishal Verma memdev->range_index = 12+1; 16933b87356fSDan Williams memdev->region_index = 8+1; 169420985164SVishal Verma memdev->region_size = 0; 169520985164SVishal Verma memdev->region_offset = 0; 169620985164SVishal Verma memdev->address = 0; 169720985164SVishal Verma memdev->interleave_index = 0; 169820985164SVishal Verma memdev->interleave_ways = 1; 169920985164SVishal Verma 170020985164SVishal Verma offset = offset + sizeof(struct acpi_nfit_memory_map) * 3; 170120985164SVishal Verma /* flush3 (dimm4) */ 170220985164SVishal Verma flush = nfit_buf + offset; 170320985164SVishal Verma flush->header.type = ACPI_NFIT_TYPE_FLUSH_ADDRESS; 170485d3fa02SDan Williams flush->header.length = flush_hint_size; 170520985164SVishal Verma flush->device_handle = handle[4]; 170685d3fa02SDan Williams flush->hint_count = NUM_HINTS; 170785d3fa02SDan Williams for (i = 0; i < NUM_HINTS; i++) 170885d3fa02SDan Williams flush->hint_address[i] = t->flush_dma[4] 170985d3fa02SDan Williams + i * sizeof(u64); 171020985164SVishal Verma } 171120985164SVishal Verma 17129fb1a190SDave Jiang post_ars_status(&t->ars_state, &t->badrange, t->spa_set_dma[0], 17139fb1a190SDave Jiang SPA0_SIZE); 1714f471f1a7SDan Williams 17156bc75619SDan Williams acpi_desc = &t->acpi_desc; 1716e3654ecaSDan Williams set_bit(ND_CMD_GET_CONFIG_SIZE, &acpi_desc->dimm_cmd_force_en); 1717e3654ecaSDan Williams set_bit(ND_CMD_GET_CONFIG_DATA, &acpi_desc->dimm_cmd_force_en); 1718e3654ecaSDan Williams set_bit(ND_CMD_SET_CONFIG_DATA, &acpi_desc->dimm_cmd_force_en); 1719*ed07c433SDan Williams set_bit(ND_INTEL_SMART, &acpi_desc->dimm_cmd_force_en); 1720*ed07c433SDan Williams set_bit(ND_INTEL_SMART_THRESHOLD, &acpi_desc->dimm_cmd_force_en); 1721*ed07c433SDan Williams set_bit(ND_INTEL_SMART_SET_THRESHOLD, &acpi_desc->dimm_cmd_force_en); 1722e3654ecaSDan Williams set_bit(ND_CMD_ARS_CAP, &acpi_desc->bus_cmd_force_en); 1723e3654ecaSDan Williams set_bit(ND_CMD_ARS_START, &acpi_desc->bus_cmd_force_en); 1724e3654ecaSDan Williams set_bit(ND_CMD_ARS_STATUS, &acpi_desc->bus_cmd_force_en); 1725e3654ecaSDan Williams set_bit(ND_CMD_CLEAR_ERROR, &acpi_desc->bus_cmd_force_en); 172610246dc8SYasunori Goto set_bit(ND_CMD_CALL, &acpi_desc->bus_cmd_force_en); 172710246dc8SYasunori Goto set_bit(NFIT_CMD_TRANSLATE_SPA, &acpi_desc->bus_nfit_cmd_force_en); 17289fb1a190SDave Jiang set_bit(NFIT_CMD_ARS_INJECT_SET, &acpi_desc->bus_nfit_cmd_force_en); 17299fb1a190SDave Jiang set_bit(NFIT_CMD_ARS_INJECT_CLEAR, &acpi_desc->bus_nfit_cmd_force_en); 17309fb1a190SDave Jiang set_bit(NFIT_CMD_ARS_INJECT_GET, &acpi_desc->bus_nfit_cmd_force_en); 17316bc75619SDan Williams } 17326bc75619SDan Williams 17336bc75619SDan Williams static void nfit_test1_setup(struct nfit_test *t) 17346bc75619SDan Williams { 17356b577c9dSLinda Knippers size_t offset; 17366bc75619SDan Williams void *nfit_buf = t->nfit_buf; 17376bc75619SDan Williams struct acpi_nfit_memory_map *memdev; 17386bc75619SDan Williams struct acpi_nfit_control_region *dcr; 17396bc75619SDan Williams struct acpi_nfit_system_address *spa; 1740d26f73f0SDan Williams struct acpi_nfit_desc *acpi_desc; 17416bc75619SDan Williams 17426b577c9dSLinda Knippers offset = 0; 17436bc75619SDan Williams /* spa0 (flat range with no bdw aliasing) */ 17446bc75619SDan Williams spa = nfit_buf + offset; 17456bc75619SDan Williams spa->header.type = ACPI_NFIT_TYPE_SYSTEM_ADDRESS; 17466bc75619SDan Williams spa->header.length = sizeof(*spa); 17476bc75619SDan Williams memcpy(spa->range_guid, to_nfit_uuid(NFIT_SPA_PM), 16); 17486bc75619SDan Williams spa->range_index = 0+1; 17496bc75619SDan Williams spa->address = t->spa_set_dma[0]; 17506bc75619SDan Williams spa->length = SPA2_SIZE; 17516bc75619SDan Williams 17527bfe97c7SDan Williams /* virtual cd region */ 17537bfe97c7SDan Williams spa = nfit_buf + sizeof(*spa); 17547bfe97c7SDan Williams spa->header.type = ACPI_NFIT_TYPE_SYSTEM_ADDRESS; 17557bfe97c7SDan Williams spa->header.length = sizeof(*spa); 17567bfe97c7SDan Williams memcpy(spa->range_guid, to_nfit_uuid(NFIT_SPA_VCD), 16); 17577bfe97c7SDan Williams spa->range_index = 0; 17587bfe97c7SDan Williams spa->address = t->spa_set_dma[1]; 17597bfe97c7SDan Williams spa->length = SPA_VCD_SIZE; 17607bfe97c7SDan Williams 17617bfe97c7SDan Williams offset += sizeof(*spa) * 2; 17626bc75619SDan Williams /* mem-region0 (spa0, dimm0) */ 17636bc75619SDan Williams memdev = nfit_buf + offset; 17646bc75619SDan Williams memdev->header.type = ACPI_NFIT_TYPE_MEMORY_MAP; 17656bc75619SDan Williams memdev->header.length = sizeof(*memdev); 1766dafb1048SDan Williams memdev->device_handle = handle[5]; 17676bc75619SDan Williams memdev->physical_id = 0; 17686bc75619SDan Williams memdev->region_id = 0; 17696bc75619SDan Williams memdev->range_index = 0+1; 17706bc75619SDan Williams memdev->region_index = 0+1; 17716bc75619SDan Williams memdev->region_size = SPA2_SIZE; 17726bc75619SDan Williams memdev->region_offset = 0; 17736bc75619SDan Williams memdev->address = 0; 17746bc75619SDan Williams memdev->interleave_index = 0; 17756bc75619SDan Williams memdev->interleave_ways = 1; 177658138820SDan Williams memdev->flags = ACPI_NFIT_MEM_SAVE_FAILED | ACPI_NFIT_MEM_RESTORE_FAILED 177758138820SDan Williams | ACPI_NFIT_MEM_FLUSH_FAILED | ACPI_NFIT_MEM_HEALTH_OBSERVED 1778f4295796SDan Williams | ACPI_NFIT_MEM_NOT_ARMED; 17796bc75619SDan Williams 17806bc75619SDan Williams offset += sizeof(*memdev); 17816bc75619SDan Williams /* dcr-descriptor0 */ 17826bc75619SDan Williams dcr = nfit_buf + offset; 17836bc75619SDan Williams dcr->header.type = ACPI_NFIT_TYPE_CONTROL_REGION; 17843b87356fSDan Williams dcr->header.length = offsetof(struct acpi_nfit_control_region, 17853b87356fSDan Williams window_size); 17866bc75619SDan Williams dcr->region_index = 0+1; 17875dc68e55SDan Williams dcr_common_init(dcr); 1788dafb1048SDan Williams dcr->serial_number = ~handle[5]; 1789be26f9aeSDan Williams dcr->code = NFIT_FIC_BYTE; 17906bc75619SDan Williams dcr->windows = 0; 1791d26f73f0SDan Williams 1792ac40b675SDan Williams offset += dcr->header.length; 1793ac40b675SDan Williams memdev = nfit_buf + offset; 1794ac40b675SDan Williams memdev->header.type = ACPI_NFIT_TYPE_MEMORY_MAP; 1795ac40b675SDan Williams memdev->header.length = sizeof(*memdev); 1796ac40b675SDan Williams memdev->device_handle = handle[6]; 1797ac40b675SDan Williams memdev->physical_id = 0; 1798ac40b675SDan Williams memdev->region_id = 0; 1799ac40b675SDan Williams memdev->range_index = 0; 1800ac40b675SDan Williams memdev->region_index = 0+2; 1801ac40b675SDan Williams memdev->region_size = SPA2_SIZE; 1802ac40b675SDan Williams memdev->region_offset = 0; 1803ac40b675SDan Williams memdev->address = 0; 1804ac40b675SDan Williams memdev->interleave_index = 0; 1805ac40b675SDan Williams memdev->interleave_ways = 1; 1806ac40b675SDan Williams memdev->flags = ACPI_NFIT_MEM_MAP_FAILED; 1807ac40b675SDan Williams 1808ac40b675SDan Williams /* dcr-descriptor1 */ 1809ac40b675SDan Williams offset += sizeof(*memdev); 1810ac40b675SDan Williams dcr = nfit_buf + offset; 1811ac40b675SDan Williams dcr->header.type = ACPI_NFIT_TYPE_CONTROL_REGION; 1812ac40b675SDan Williams dcr->header.length = offsetof(struct acpi_nfit_control_region, 1813ac40b675SDan Williams window_size); 1814ac40b675SDan Williams dcr->region_index = 0+2; 1815ac40b675SDan Williams dcr_common_init(dcr); 1816ac40b675SDan Williams dcr->serial_number = ~handle[6]; 1817ac40b675SDan Williams dcr->code = NFIT_FIC_BYTE; 1818ac40b675SDan Williams dcr->windows = 0; 1819ac40b675SDan Williams 18209fb1a190SDave Jiang post_ars_status(&t->ars_state, &t->badrange, t->spa_set_dma[0], 18219fb1a190SDave Jiang SPA2_SIZE); 1822f471f1a7SDan Williams 1823d26f73f0SDan Williams acpi_desc = &t->acpi_desc; 1824e3654ecaSDan Williams set_bit(ND_CMD_ARS_CAP, &acpi_desc->bus_cmd_force_en); 1825e3654ecaSDan Williams set_bit(ND_CMD_ARS_START, &acpi_desc->bus_cmd_force_en); 1826e3654ecaSDan Williams set_bit(ND_CMD_ARS_STATUS, &acpi_desc->bus_cmd_force_en); 1827e3654ecaSDan Williams set_bit(ND_CMD_CLEAR_ERROR, &acpi_desc->bus_cmd_force_en); 18286bc75619SDan Williams } 18296bc75619SDan Williams 18306bc75619SDan Williams static int nfit_test_blk_do_io(struct nd_blk_region *ndbr, resource_size_t dpa, 18316bc75619SDan Williams void *iobuf, u64 len, int rw) 18326bc75619SDan Williams { 18336bc75619SDan Williams struct nfit_blk *nfit_blk = ndbr->blk_provider_data; 18346bc75619SDan Williams struct nfit_blk_mmio *mmio = &nfit_blk->mmio[BDW]; 18356bc75619SDan Williams struct nd_region *nd_region = &ndbr->nd_region; 18366bc75619SDan Williams unsigned int lane; 18376bc75619SDan Williams 18386bc75619SDan Williams lane = nd_region_acquire_lane(nd_region); 18396bc75619SDan Williams if (rw) 184067a3e8feSRoss Zwisler memcpy(mmio->addr.base + dpa, iobuf, len); 184167a3e8feSRoss Zwisler else { 184267a3e8feSRoss Zwisler memcpy(iobuf, mmio->addr.base + dpa, len); 184367a3e8feSRoss Zwisler 18445deb67f7SRobin Murphy /* give us some some coverage of the arch_invalidate_pmem() API */ 18455deb67f7SRobin Murphy arch_invalidate_pmem(mmio->addr.base + dpa, len); 184667a3e8feSRoss Zwisler } 18476bc75619SDan Williams nd_region_release_lane(nd_region, lane); 18486bc75619SDan Williams 18496bc75619SDan Williams return 0; 18506bc75619SDan Williams } 18516bc75619SDan Williams 1852a7de92daSDan Williams static unsigned long nfit_ctl_handle; 1853a7de92daSDan Williams 1854a7de92daSDan Williams union acpi_object *result; 1855a7de92daSDan Williams 1856a7de92daSDan Williams static union acpi_object *nfit_test_evaluate_dsm(acpi_handle handle, 185794116f81SAndy Shevchenko const guid_t *guid, u64 rev, u64 func, union acpi_object *argv4) 1858a7de92daSDan Williams { 1859a7de92daSDan Williams if (handle != &nfit_ctl_handle) 1860a7de92daSDan Williams return ERR_PTR(-ENXIO); 1861a7de92daSDan Williams 1862a7de92daSDan Williams return result; 1863a7de92daSDan Williams } 1864a7de92daSDan Williams 1865a7de92daSDan Williams static int setup_result(void *buf, size_t size) 1866a7de92daSDan Williams { 1867a7de92daSDan Williams result = kmalloc(sizeof(union acpi_object) + size, GFP_KERNEL); 1868a7de92daSDan Williams if (!result) 1869a7de92daSDan Williams return -ENOMEM; 1870a7de92daSDan Williams result->package.type = ACPI_TYPE_BUFFER, 1871a7de92daSDan Williams result->buffer.pointer = (void *) (result + 1); 1872a7de92daSDan Williams result->buffer.length = size; 1873a7de92daSDan Williams memcpy(result->buffer.pointer, buf, size); 1874a7de92daSDan Williams memset(buf, 0, size); 1875a7de92daSDan Williams return 0; 1876a7de92daSDan Williams } 1877a7de92daSDan Williams 1878a7de92daSDan Williams static int nfit_ctl_test(struct device *dev) 1879a7de92daSDan Williams { 1880a7de92daSDan Williams int rc, cmd_rc; 1881a7de92daSDan Williams struct nvdimm *nvdimm; 1882a7de92daSDan Williams struct acpi_device *adev; 1883a7de92daSDan Williams struct nfit_mem *nfit_mem; 1884a7de92daSDan Williams struct nd_ars_record *record; 1885a7de92daSDan Williams struct acpi_nfit_desc *acpi_desc; 1886a7de92daSDan Williams const u64 test_val = 0x0123456789abcdefULL; 1887a7de92daSDan Williams unsigned long mask, cmd_size, offset; 1888a7de92daSDan Williams union { 1889a7de92daSDan Williams struct nd_cmd_get_config_size cfg_size; 1890fb2a1748SDan Williams struct nd_cmd_clear_error clear_err; 1891a7de92daSDan Williams struct nd_cmd_ars_status ars_stat; 1892a7de92daSDan Williams struct nd_cmd_ars_cap ars_cap; 1893a7de92daSDan Williams char buf[sizeof(struct nd_cmd_ars_status) 1894a7de92daSDan Williams + sizeof(struct nd_ars_record)]; 1895a7de92daSDan Williams } cmds; 1896a7de92daSDan Williams 1897a7de92daSDan Williams adev = devm_kzalloc(dev, sizeof(*adev), GFP_KERNEL); 1898a7de92daSDan Williams if (!adev) 1899a7de92daSDan Williams return -ENOMEM; 1900a7de92daSDan Williams *adev = (struct acpi_device) { 1901a7de92daSDan Williams .handle = &nfit_ctl_handle, 1902a7de92daSDan Williams .dev = { 1903a7de92daSDan Williams .init_name = "test-adev", 1904a7de92daSDan Williams }, 1905a7de92daSDan Williams }; 1906a7de92daSDan Williams 1907a7de92daSDan Williams acpi_desc = devm_kzalloc(dev, sizeof(*acpi_desc), GFP_KERNEL); 1908a7de92daSDan Williams if (!acpi_desc) 1909a7de92daSDan Williams return -ENOMEM; 1910a7de92daSDan Williams *acpi_desc = (struct acpi_nfit_desc) { 1911a7de92daSDan Williams .nd_desc = { 1912a7de92daSDan Williams .cmd_mask = 1UL << ND_CMD_ARS_CAP 1913a7de92daSDan Williams | 1UL << ND_CMD_ARS_START 1914a7de92daSDan Williams | 1UL << ND_CMD_ARS_STATUS 191510246dc8SYasunori Goto | 1UL << ND_CMD_CLEAR_ERROR 191610246dc8SYasunori Goto | 1UL << ND_CMD_CALL, 1917a7de92daSDan Williams .module = THIS_MODULE, 1918a7de92daSDan Williams .provider_name = "ACPI.NFIT", 1919a7de92daSDan Williams .ndctl = acpi_nfit_ctl, 19209fb1a190SDave Jiang .bus_dsm_mask = 1UL << NFIT_CMD_TRANSLATE_SPA 19219fb1a190SDave Jiang | 1UL << NFIT_CMD_ARS_INJECT_SET 19229fb1a190SDave Jiang | 1UL << NFIT_CMD_ARS_INJECT_CLEAR 19239fb1a190SDave Jiang | 1UL << NFIT_CMD_ARS_INJECT_GET, 1924a7de92daSDan Williams }, 1925a7de92daSDan Williams .dev = &adev->dev, 1926a7de92daSDan Williams }; 1927a7de92daSDan Williams 1928a7de92daSDan Williams nfit_mem = devm_kzalloc(dev, sizeof(*nfit_mem), GFP_KERNEL); 1929a7de92daSDan Williams if (!nfit_mem) 1930a7de92daSDan Williams return -ENOMEM; 1931a7de92daSDan Williams 1932a7de92daSDan Williams mask = 1UL << ND_CMD_SMART | 1UL << ND_CMD_SMART_THRESHOLD 1933a7de92daSDan Williams | 1UL << ND_CMD_DIMM_FLAGS | 1UL << ND_CMD_GET_CONFIG_SIZE 1934a7de92daSDan Williams | 1UL << ND_CMD_GET_CONFIG_DATA | 1UL << ND_CMD_SET_CONFIG_DATA 1935a7de92daSDan Williams | 1UL << ND_CMD_VENDOR; 1936a7de92daSDan Williams *nfit_mem = (struct nfit_mem) { 1937a7de92daSDan Williams .adev = adev, 1938a7de92daSDan Williams .family = NVDIMM_FAMILY_INTEL, 1939a7de92daSDan Williams .dsm_mask = mask, 1940a7de92daSDan Williams }; 1941a7de92daSDan Williams 1942a7de92daSDan Williams nvdimm = devm_kzalloc(dev, sizeof(*nvdimm), GFP_KERNEL); 1943a7de92daSDan Williams if (!nvdimm) 1944a7de92daSDan Williams return -ENOMEM; 1945a7de92daSDan Williams *nvdimm = (struct nvdimm) { 1946a7de92daSDan Williams .provider_data = nfit_mem, 1947a7de92daSDan Williams .cmd_mask = mask, 1948a7de92daSDan Williams .dev = { 1949a7de92daSDan Williams .init_name = "test-dimm", 1950a7de92daSDan Williams }, 1951a7de92daSDan Williams }; 1952a7de92daSDan Williams 1953a7de92daSDan Williams 1954a7de92daSDan Williams /* basic checkout of a typical 'get config size' command */ 1955a7de92daSDan Williams cmd_size = sizeof(cmds.cfg_size); 1956a7de92daSDan Williams cmds.cfg_size = (struct nd_cmd_get_config_size) { 1957a7de92daSDan Williams .status = 0, 1958a7de92daSDan Williams .config_size = SZ_128K, 1959a7de92daSDan Williams .max_xfer = SZ_4K, 1960a7de92daSDan Williams }; 1961a7de92daSDan Williams rc = setup_result(cmds.buf, cmd_size); 1962a7de92daSDan Williams if (rc) 1963a7de92daSDan Williams return rc; 1964a7de92daSDan Williams rc = acpi_nfit_ctl(&acpi_desc->nd_desc, nvdimm, ND_CMD_GET_CONFIG_SIZE, 1965a7de92daSDan Williams cmds.buf, cmd_size, &cmd_rc); 1966a7de92daSDan Williams 1967a7de92daSDan Williams if (rc < 0 || cmd_rc || cmds.cfg_size.status != 0 1968a7de92daSDan Williams || cmds.cfg_size.config_size != SZ_128K 1969a7de92daSDan Williams || cmds.cfg_size.max_xfer != SZ_4K) { 1970a7de92daSDan Williams dev_dbg(dev, "%s: failed at: %d rc: %d cmd_rc: %d\n", 1971a7de92daSDan Williams __func__, __LINE__, rc, cmd_rc); 1972a7de92daSDan Williams return -EIO; 1973a7de92daSDan Williams } 1974a7de92daSDan Williams 1975a7de92daSDan Williams 1976a7de92daSDan Williams /* test ars_status with zero output */ 1977a7de92daSDan Williams cmd_size = offsetof(struct nd_cmd_ars_status, address); 1978a7de92daSDan Williams cmds.ars_stat = (struct nd_cmd_ars_status) { 1979a7de92daSDan Williams .out_length = 0, 1980a7de92daSDan Williams }; 1981a7de92daSDan Williams rc = setup_result(cmds.buf, cmd_size); 1982a7de92daSDan Williams if (rc) 1983a7de92daSDan Williams return rc; 1984a7de92daSDan Williams rc = acpi_nfit_ctl(&acpi_desc->nd_desc, NULL, ND_CMD_ARS_STATUS, 1985a7de92daSDan Williams cmds.buf, cmd_size, &cmd_rc); 1986a7de92daSDan Williams 1987a7de92daSDan Williams if (rc < 0 || cmd_rc) { 1988a7de92daSDan Williams dev_dbg(dev, "%s: failed at: %d rc: %d cmd_rc: %d\n", 1989a7de92daSDan Williams __func__, __LINE__, rc, cmd_rc); 1990a7de92daSDan Williams return -EIO; 1991a7de92daSDan Williams } 1992a7de92daSDan Williams 1993a7de92daSDan Williams 1994a7de92daSDan Williams /* test ars_cap with benign extended status */ 1995a7de92daSDan Williams cmd_size = sizeof(cmds.ars_cap); 1996a7de92daSDan Williams cmds.ars_cap = (struct nd_cmd_ars_cap) { 1997a7de92daSDan Williams .status = ND_ARS_PERSISTENT << 16, 1998a7de92daSDan Williams }; 1999a7de92daSDan Williams offset = offsetof(struct nd_cmd_ars_cap, status); 2000a7de92daSDan Williams rc = setup_result(cmds.buf + offset, cmd_size - offset); 2001a7de92daSDan Williams if (rc) 2002a7de92daSDan Williams return rc; 2003a7de92daSDan Williams rc = acpi_nfit_ctl(&acpi_desc->nd_desc, NULL, ND_CMD_ARS_CAP, 2004a7de92daSDan Williams cmds.buf, cmd_size, &cmd_rc); 2005a7de92daSDan Williams 2006a7de92daSDan Williams if (rc < 0 || cmd_rc) { 2007a7de92daSDan Williams dev_dbg(dev, "%s: failed at: %d rc: %d cmd_rc: %d\n", 2008a7de92daSDan Williams __func__, __LINE__, rc, cmd_rc); 2009a7de92daSDan Williams return -EIO; 2010a7de92daSDan Williams } 2011a7de92daSDan Williams 2012a7de92daSDan Williams 2013a7de92daSDan Williams /* test ars_status with 'status' trimmed from 'out_length' */ 2014a7de92daSDan Williams cmd_size = sizeof(cmds.ars_stat) + sizeof(struct nd_ars_record); 2015a7de92daSDan Williams cmds.ars_stat = (struct nd_cmd_ars_status) { 2016a7de92daSDan Williams .out_length = cmd_size - 4, 2017a7de92daSDan Williams }; 2018a7de92daSDan Williams record = &cmds.ars_stat.records[0]; 2019a7de92daSDan Williams *record = (struct nd_ars_record) { 2020a7de92daSDan Williams .length = test_val, 2021a7de92daSDan Williams }; 2022a7de92daSDan Williams rc = setup_result(cmds.buf, cmd_size); 2023a7de92daSDan Williams if (rc) 2024a7de92daSDan Williams return rc; 2025a7de92daSDan Williams rc = acpi_nfit_ctl(&acpi_desc->nd_desc, NULL, ND_CMD_ARS_STATUS, 2026a7de92daSDan Williams cmds.buf, cmd_size, &cmd_rc); 2027a7de92daSDan Williams 2028a7de92daSDan Williams if (rc < 0 || cmd_rc || record->length != test_val) { 2029a7de92daSDan Williams dev_dbg(dev, "%s: failed at: %d rc: %d cmd_rc: %d\n", 2030a7de92daSDan Williams __func__, __LINE__, rc, cmd_rc); 2031a7de92daSDan Williams return -EIO; 2032a7de92daSDan Williams } 2033a7de92daSDan Williams 2034a7de92daSDan Williams 2035a7de92daSDan Williams /* test ars_status with 'Output (Size)' including 'status' */ 2036a7de92daSDan Williams cmd_size = sizeof(cmds.ars_stat) + sizeof(struct nd_ars_record); 2037a7de92daSDan Williams cmds.ars_stat = (struct nd_cmd_ars_status) { 2038a7de92daSDan Williams .out_length = cmd_size, 2039a7de92daSDan Williams }; 2040a7de92daSDan Williams record = &cmds.ars_stat.records[0]; 2041a7de92daSDan Williams *record = (struct nd_ars_record) { 2042a7de92daSDan Williams .length = test_val, 2043a7de92daSDan Williams }; 2044a7de92daSDan Williams rc = setup_result(cmds.buf, cmd_size); 2045a7de92daSDan Williams if (rc) 2046a7de92daSDan Williams return rc; 2047a7de92daSDan Williams rc = acpi_nfit_ctl(&acpi_desc->nd_desc, NULL, ND_CMD_ARS_STATUS, 2048a7de92daSDan Williams cmds.buf, cmd_size, &cmd_rc); 2049a7de92daSDan Williams 2050a7de92daSDan Williams if (rc < 0 || cmd_rc || record->length != test_val) { 2051a7de92daSDan Williams dev_dbg(dev, "%s: failed at: %d rc: %d cmd_rc: %d\n", 2052a7de92daSDan Williams __func__, __LINE__, rc, cmd_rc); 2053a7de92daSDan Williams return -EIO; 2054a7de92daSDan Williams } 2055a7de92daSDan Williams 2056a7de92daSDan Williams 2057a7de92daSDan Williams /* test extended status for get_config_size results in failure */ 2058a7de92daSDan Williams cmd_size = sizeof(cmds.cfg_size); 2059a7de92daSDan Williams cmds.cfg_size = (struct nd_cmd_get_config_size) { 2060a7de92daSDan Williams .status = 1 << 16, 2061a7de92daSDan Williams }; 2062a7de92daSDan Williams rc = setup_result(cmds.buf, cmd_size); 2063a7de92daSDan Williams if (rc) 2064a7de92daSDan Williams return rc; 2065a7de92daSDan Williams rc = acpi_nfit_ctl(&acpi_desc->nd_desc, nvdimm, ND_CMD_GET_CONFIG_SIZE, 2066a7de92daSDan Williams cmds.buf, cmd_size, &cmd_rc); 2067a7de92daSDan Williams 2068a7de92daSDan Williams if (rc < 0 || cmd_rc >= 0) { 2069a7de92daSDan Williams dev_dbg(dev, "%s: failed at: %d rc: %d cmd_rc: %d\n", 2070a7de92daSDan Williams __func__, __LINE__, rc, cmd_rc); 2071a7de92daSDan Williams return -EIO; 2072a7de92daSDan Williams } 2073a7de92daSDan Williams 2074fb2a1748SDan Williams /* test clear error */ 2075fb2a1748SDan Williams cmd_size = sizeof(cmds.clear_err); 2076fb2a1748SDan Williams cmds.clear_err = (struct nd_cmd_clear_error) { 2077fb2a1748SDan Williams .length = 512, 2078fb2a1748SDan Williams .cleared = 512, 2079fb2a1748SDan Williams }; 2080fb2a1748SDan Williams rc = setup_result(cmds.buf, cmd_size); 2081fb2a1748SDan Williams if (rc) 2082fb2a1748SDan Williams return rc; 2083fb2a1748SDan Williams rc = acpi_nfit_ctl(&acpi_desc->nd_desc, NULL, ND_CMD_CLEAR_ERROR, 2084fb2a1748SDan Williams cmds.buf, cmd_size, &cmd_rc); 2085fb2a1748SDan Williams if (rc < 0 || cmd_rc) { 2086fb2a1748SDan Williams dev_dbg(dev, "%s: failed at: %d rc: %d cmd_rc: %d\n", 2087fb2a1748SDan Williams __func__, __LINE__, rc, cmd_rc); 2088fb2a1748SDan Williams return -EIO; 2089fb2a1748SDan Williams } 2090fb2a1748SDan Williams 2091a7de92daSDan Williams return 0; 2092a7de92daSDan Williams } 2093a7de92daSDan Williams 20946bc75619SDan Williams static int nfit_test_probe(struct platform_device *pdev) 20956bc75619SDan Williams { 20966bc75619SDan Williams struct nvdimm_bus_descriptor *nd_desc; 20976bc75619SDan Williams struct acpi_nfit_desc *acpi_desc; 20986bc75619SDan Williams struct device *dev = &pdev->dev; 20996bc75619SDan Williams struct nfit_test *nfit_test; 2100231bf117SDan Williams struct nfit_mem *nfit_mem; 2101c14a868aSDan Williams union acpi_object *obj; 21026bc75619SDan Williams int rc; 21036bc75619SDan Williams 2104a7de92daSDan Williams if (strcmp(dev_name(&pdev->dev), "nfit_test.0") == 0) { 2105a7de92daSDan Williams rc = nfit_ctl_test(&pdev->dev); 2106a7de92daSDan Williams if (rc) 2107a7de92daSDan Williams return rc; 2108a7de92daSDan Williams } 2109a7de92daSDan Williams 21106bc75619SDan Williams nfit_test = to_nfit_test(&pdev->dev); 21116bc75619SDan Williams 21126bc75619SDan Williams /* common alloc */ 21136bc75619SDan Williams if (nfit_test->num_dcr) { 21146bc75619SDan Williams int num = nfit_test->num_dcr; 21156bc75619SDan Williams 21166bc75619SDan Williams nfit_test->dimm = devm_kcalloc(dev, num, sizeof(void *), 21176bc75619SDan Williams GFP_KERNEL); 21186bc75619SDan Williams nfit_test->dimm_dma = devm_kcalloc(dev, num, sizeof(dma_addr_t), 21196bc75619SDan Williams GFP_KERNEL); 21209d27a87eSDan Williams nfit_test->flush = devm_kcalloc(dev, num, sizeof(void *), 21219d27a87eSDan Williams GFP_KERNEL); 21229d27a87eSDan Williams nfit_test->flush_dma = devm_kcalloc(dev, num, sizeof(dma_addr_t), 21239d27a87eSDan Williams GFP_KERNEL); 21246bc75619SDan Williams nfit_test->label = devm_kcalloc(dev, num, sizeof(void *), 21256bc75619SDan Williams GFP_KERNEL); 21266bc75619SDan Williams nfit_test->label_dma = devm_kcalloc(dev, num, 21276bc75619SDan Williams sizeof(dma_addr_t), GFP_KERNEL); 21286bc75619SDan Williams nfit_test->dcr = devm_kcalloc(dev, num, 21296bc75619SDan Williams sizeof(struct nfit_test_dcr *), GFP_KERNEL); 21306bc75619SDan Williams nfit_test->dcr_dma = devm_kcalloc(dev, num, 21316bc75619SDan Williams sizeof(dma_addr_t), GFP_KERNEL); 2132*ed07c433SDan Williams nfit_test->smart = devm_kcalloc(dev, num, 2133*ed07c433SDan Williams sizeof(struct nd_intel_smart), GFP_KERNEL); 2134*ed07c433SDan Williams nfit_test->smart_threshold = devm_kcalloc(dev, num, 2135*ed07c433SDan Williams sizeof(struct nd_intel_smart_threshold), 2136*ed07c433SDan Williams GFP_KERNEL); 21376bc75619SDan Williams if (nfit_test->dimm && nfit_test->dimm_dma && nfit_test->label 21386bc75619SDan Williams && nfit_test->label_dma && nfit_test->dcr 21399d27a87eSDan Williams && nfit_test->dcr_dma && nfit_test->flush 21409d27a87eSDan Williams && nfit_test->flush_dma) 21416bc75619SDan Williams /* pass */; 21426bc75619SDan Williams else 21436bc75619SDan Williams return -ENOMEM; 21446bc75619SDan Williams } 21456bc75619SDan Williams 21466bc75619SDan Williams if (nfit_test->num_pm) { 21476bc75619SDan Williams int num = nfit_test->num_pm; 21486bc75619SDan Williams 21496bc75619SDan Williams nfit_test->spa_set = devm_kcalloc(dev, num, sizeof(void *), 21506bc75619SDan Williams GFP_KERNEL); 21516bc75619SDan Williams nfit_test->spa_set_dma = devm_kcalloc(dev, num, 21526bc75619SDan Williams sizeof(dma_addr_t), GFP_KERNEL); 21536bc75619SDan Williams if (nfit_test->spa_set && nfit_test->spa_set_dma) 21546bc75619SDan Williams /* pass */; 21556bc75619SDan Williams else 21566bc75619SDan Williams return -ENOMEM; 21576bc75619SDan Williams } 21586bc75619SDan Williams 21596bc75619SDan Williams /* per-nfit specific alloc */ 21606bc75619SDan Williams if (nfit_test->alloc(nfit_test)) 21616bc75619SDan Williams return -ENOMEM; 21626bc75619SDan Williams 21636bc75619SDan Williams nfit_test->setup(nfit_test); 21646bc75619SDan Williams acpi_desc = &nfit_test->acpi_desc; 2165a61fe6f7SDan Williams acpi_nfit_desc_init(acpi_desc, &pdev->dev); 21666bc75619SDan Williams acpi_desc->blk_do_io = nfit_test_blk_do_io; 21676bc75619SDan Williams nd_desc = &acpi_desc->nd_desc; 2168a61fe6f7SDan Williams nd_desc->provider_name = NULL; 2169bc9775d8SDan Williams nd_desc->module = THIS_MODULE; 2170a61fe6f7SDan Williams nd_desc->ndctl = nfit_test_ctl; 21716bc75619SDan Williams 2172e7a11b44SDan Williams rc = acpi_nfit_init(acpi_desc, nfit_test->nfit_buf, 2173e7a11b44SDan Williams nfit_test->nfit_size); 217458cd71b4SDan Williams if (rc) 217520985164SVishal Verma return rc; 217620985164SVishal Verma 2177fbabd829SDan Williams rc = devm_add_action_or_reset(&pdev->dev, acpi_nfit_shutdown, acpi_desc); 2178fbabd829SDan Williams if (rc) 2179fbabd829SDan Williams return rc; 2180fbabd829SDan Williams 218120985164SVishal Verma if (nfit_test->setup != nfit_test0_setup) 218220985164SVishal Verma return 0; 218320985164SVishal Verma 218420985164SVishal Verma nfit_test->setup_hotplug = 1; 218520985164SVishal Verma nfit_test->setup(nfit_test); 218620985164SVishal Verma 2187c14a868aSDan Williams obj = kzalloc(sizeof(*obj), GFP_KERNEL); 2188c14a868aSDan Williams if (!obj) 2189c14a868aSDan Williams return -ENOMEM; 2190c14a868aSDan Williams obj->type = ACPI_TYPE_BUFFER; 2191c14a868aSDan Williams obj->buffer.length = nfit_test->nfit_size; 2192c14a868aSDan Williams obj->buffer.pointer = nfit_test->nfit_buf; 2193c14a868aSDan Williams *(nfit_test->_fit) = obj; 2194c14a868aSDan Williams __acpi_nfit_notify(&pdev->dev, nfit_test, 0x80); 2195231bf117SDan Williams 2196231bf117SDan Williams /* associate dimm devices with nfit_mem data for notification testing */ 2197231bf117SDan Williams mutex_lock(&acpi_desc->init_mutex); 2198231bf117SDan Williams list_for_each_entry(nfit_mem, &acpi_desc->dimms, list) { 2199231bf117SDan Williams u32 nfit_handle = __to_nfit_memdev(nfit_mem)->device_handle; 2200231bf117SDan Williams int i; 2201231bf117SDan Williams 2202231bf117SDan Williams for (i = 0; i < NUM_DCR; i++) 2203231bf117SDan Williams if (nfit_handle == handle[i]) 2204231bf117SDan Williams dev_set_drvdata(nfit_test->dimm_dev[i], 2205231bf117SDan Williams nfit_mem); 2206231bf117SDan Williams } 2207231bf117SDan Williams mutex_unlock(&acpi_desc->init_mutex); 22086bc75619SDan Williams 22096bc75619SDan Williams return 0; 22106bc75619SDan Williams } 22116bc75619SDan Williams 22126bc75619SDan Williams static int nfit_test_remove(struct platform_device *pdev) 22136bc75619SDan Williams { 22146bc75619SDan Williams return 0; 22156bc75619SDan Williams } 22166bc75619SDan Williams 22176bc75619SDan Williams static void nfit_test_release(struct device *dev) 22186bc75619SDan Williams { 22196bc75619SDan Williams struct nfit_test *nfit_test = to_nfit_test(dev); 22206bc75619SDan Williams 22216bc75619SDan Williams kfree(nfit_test); 22226bc75619SDan Williams } 22236bc75619SDan Williams 22246bc75619SDan Williams static const struct platform_device_id nfit_test_id[] = { 22256bc75619SDan Williams { KBUILD_MODNAME }, 22266bc75619SDan Williams { }, 22276bc75619SDan Williams }; 22286bc75619SDan Williams 22296bc75619SDan Williams static struct platform_driver nfit_test_driver = { 22306bc75619SDan Williams .probe = nfit_test_probe, 22316bc75619SDan Williams .remove = nfit_test_remove, 22326bc75619SDan Williams .driver = { 22336bc75619SDan Williams .name = KBUILD_MODNAME, 22346bc75619SDan Williams }, 22356bc75619SDan Williams .id_table = nfit_test_id, 22366bc75619SDan Williams }; 22376bc75619SDan Williams 22386bc75619SDan Williams static __init int nfit_test_init(void) 22396bc75619SDan Williams { 22406bc75619SDan Williams int rc, i; 22416bc75619SDan Williams 2242a7de92daSDan Williams nfit_test_setup(nfit_test_lookup, nfit_test_evaluate_dsm); 2243231bf117SDan Williams 22449fb1a190SDave Jiang nfit_wq = create_singlethread_workqueue("nfit"); 22459fb1a190SDave Jiang if (!nfit_wq) 22469fb1a190SDave Jiang return -ENOMEM; 22479fb1a190SDave Jiang 2248a7de92daSDan Williams nfit_test_dimm = class_create(THIS_MODULE, "nfit_test_dimm"); 2249a7de92daSDan Williams if (IS_ERR(nfit_test_dimm)) { 2250a7de92daSDan Williams rc = PTR_ERR(nfit_test_dimm); 2251a7de92daSDan Williams goto err_register; 2252a7de92daSDan Williams } 22536bc75619SDan Williams 22546bc75619SDan Williams for (i = 0; i < NUM_NFITS; i++) { 22556bc75619SDan Williams struct nfit_test *nfit_test; 22566bc75619SDan Williams struct platform_device *pdev; 22576bc75619SDan Williams 22586bc75619SDan Williams nfit_test = kzalloc(sizeof(*nfit_test), GFP_KERNEL); 22596bc75619SDan Williams if (!nfit_test) { 22606bc75619SDan Williams rc = -ENOMEM; 22616bc75619SDan Williams goto err_register; 22626bc75619SDan Williams } 22636bc75619SDan Williams INIT_LIST_HEAD(&nfit_test->resources); 22649fb1a190SDave Jiang badrange_init(&nfit_test->badrange); 22656bc75619SDan Williams switch (i) { 22666bc75619SDan Williams case 0: 22676bc75619SDan Williams nfit_test->num_pm = NUM_PM; 2268dafb1048SDan Williams nfit_test->dcr_idx = 0; 22696bc75619SDan Williams nfit_test->num_dcr = NUM_DCR; 22706bc75619SDan Williams nfit_test->alloc = nfit_test0_alloc; 22716bc75619SDan Williams nfit_test->setup = nfit_test0_setup; 22726bc75619SDan Williams break; 22736bc75619SDan Williams case 1: 2274a117699cSYasunori Goto nfit_test->num_pm = 2; 2275dafb1048SDan Williams nfit_test->dcr_idx = NUM_DCR; 2276ac40b675SDan Williams nfit_test->num_dcr = 2; 22776bc75619SDan Williams nfit_test->alloc = nfit_test1_alloc; 22786bc75619SDan Williams nfit_test->setup = nfit_test1_setup; 22796bc75619SDan Williams break; 22806bc75619SDan Williams default: 22816bc75619SDan Williams rc = -EINVAL; 22826bc75619SDan Williams goto err_register; 22836bc75619SDan Williams } 22846bc75619SDan Williams pdev = &nfit_test->pdev; 22856bc75619SDan Williams pdev->name = KBUILD_MODNAME; 22866bc75619SDan Williams pdev->id = i; 22876bc75619SDan Williams pdev->dev.release = nfit_test_release; 22886bc75619SDan Williams rc = platform_device_register(pdev); 22896bc75619SDan Williams if (rc) { 22906bc75619SDan Williams put_device(&pdev->dev); 22916bc75619SDan Williams goto err_register; 22926bc75619SDan Williams } 22938b06b884SDan Williams get_device(&pdev->dev); 22946bc75619SDan Williams 22956bc75619SDan Williams rc = dma_coerce_mask_and_coherent(&pdev->dev, DMA_BIT_MASK(64)); 22966bc75619SDan Williams if (rc) 22976bc75619SDan Williams goto err_register; 22986bc75619SDan Williams 22996bc75619SDan Williams instances[i] = nfit_test; 23009fb1a190SDave Jiang INIT_WORK(&nfit_test->work, uc_error_notify); 23016bc75619SDan Williams } 23026bc75619SDan Williams 23036bc75619SDan Williams rc = platform_driver_register(&nfit_test_driver); 23046bc75619SDan Williams if (rc) 23056bc75619SDan Williams goto err_register; 23066bc75619SDan Williams return 0; 23076bc75619SDan Williams 23086bc75619SDan Williams err_register: 23099fb1a190SDave Jiang destroy_workqueue(nfit_wq); 23106bc75619SDan Williams for (i = 0; i < NUM_NFITS; i++) 23116bc75619SDan Williams if (instances[i]) 23126bc75619SDan Williams platform_device_unregister(&instances[i]->pdev); 23136bc75619SDan Williams nfit_test_teardown(); 23148b06b884SDan Williams for (i = 0; i < NUM_NFITS; i++) 23158b06b884SDan Williams if (instances[i]) 23168b06b884SDan Williams put_device(&instances[i]->pdev.dev); 23178b06b884SDan Williams 23186bc75619SDan Williams return rc; 23196bc75619SDan Williams } 23206bc75619SDan Williams 23216bc75619SDan Williams static __exit void nfit_test_exit(void) 23226bc75619SDan Williams { 23236bc75619SDan Williams int i; 23246bc75619SDan Williams 23259fb1a190SDave Jiang flush_workqueue(nfit_wq); 23269fb1a190SDave Jiang destroy_workqueue(nfit_wq); 23276bc75619SDan Williams for (i = 0; i < NUM_NFITS; i++) 23286bc75619SDan Williams platform_device_unregister(&instances[i]->pdev); 23298b06b884SDan Williams platform_driver_unregister(&nfit_test_driver); 23306bc75619SDan Williams nfit_test_teardown(); 23318b06b884SDan Williams 23328b06b884SDan Williams for (i = 0; i < NUM_NFITS; i++) 23338b06b884SDan Williams put_device(&instances[i]->pdev.dev); 2334231bf117SDan Williams class_destroy(nfit_test_dimm); 23356bc75619SDan Williams } 23366bc75619SDan Williams 23376bc75619SDan Williams module_init(nfit_test_init); 23386bc75619SDan Williams module_exit(nfit_test_exit); 23396bc75619SDan Williams MODULE_LICENSE("GPL v2"); 23406bc75619SDan Williams MODULE_AUTHOR("Intel Corporation"); 2341