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> 166bc75619SDan Williams #include <linux/libnvdimm.h> 176bc75619SDan Williams #include <linux/vmalloc.h> 186bc75619SDan Williams #include <linux/device.h> 196bc75619SDan Williams #include <linux/module.h> 2020985164SVishal Verma #include <linux/mutex.h> 216bc75619SDan Williams #include <linux/ndctl.h> 226bc75619SDan Williams #include <linux/sizes.h> 2320985164SVishal Verma #include <linux/list.h> 246bc75619SDan Williams #include <linux/slab.h> 256bc75619SDan Williams #include <nfit.h> 266bc75619SDan Williams #include <nd.h> 276bc75619SDan Williams #include "nfit_test.h" 286bc75619SDan Williams 296bc75619SDan Williams /* 306bc75619SDan Williams * Generate an NFIT table to describe the following topology: 316bc75619SDan Williams * 326bc75619SDan Williams * BUS0: Interleaved PMEM regions, and aliasing with BLK regions 336bc75619SDan Williams * 346bc75619SDan Williams * (a) (b) DIMM BLK-REGION 356bc75619SDan Williams * +----------+--------------+----------+---------+ 366bc75619SDan Williams * +------+ | blk2.0 | pm0.0 | blk2.1 | pm1.0 | 0 region2 376bc75619SDan Williams * | imc0 +--+- - - - - region0 - - - -+----------+ + 386bc75619SDan Williams * +--+---+ | blk3.0 | pm0.0 | blk3.1 | pm1.0 | 1 region3 396bc75619SDan Williams * | +----------+--------------v----------v v 406bc75619SDan Williams * +--+---+ | | 416bc75619SDan Williams * | cpu0 | region1 426bc75619SDan Williams * +--+---+ | | 436bc75619SDan Williams * | +-------------------------^----------^ ^ 446bc75619SDan Williams * +--+---+ | blk4.0 | pm1.0 | 2 region4 456bc75619SDan Williams * | imc1 +--+-------------------------+----------+ + 466bc75619SDan Williams * +------+ | blk5.0 | pm1.0 | 3 region5 476bc75619SDan Williams * +-------------------------+----------+-+-------+ 486bc75619SDan Williams * 4920985164SVishal Verma * +--+---+ 5020985164SVishal Verma * | cpu1 | 5120985164SVishal Verma * +--+---+ (Hotplug DIMM) 5220985164SVishal Verma * | +----------------------------------------------+ 5320985164SVishal Verma * +--+---+ | blk6.0/pm7.0 | 4 region6/7 5420985164SVishal Verma * | imc0 +--+----------------------------------------------+ 5520985164SVishal Verma * +------+ 5620985164SVishal Verma * 5720985164SVishal Verma * 586bc75619SDan Williams * *) In this layout we have four dimms and two memory controllers in one 596bc75619SDan Williams * socket. Each unique interface (BLK or PMEM) to DPA space 606bc75619SDan Williams * is identified by a region device with a dynamically assigned id. 616bc75619SDan Williams * 626bc75619SDan Williams * *) The first portion of dimm0 and dimm1 are interleaved as REGION0. 636bc75619SDan Williams * A single PMEM namespace "pm0.0" is created using half of the 646bc75619SDan Williams * REGION0 SPA-range. REGION0 spans dimm0 and dimm1. PMEM namespace 656bc75619SDan Williams * allocate from from the bottom of a region. The unallocated 666bc75619SDan Williams * portion of REGION0 aliases with REGION2 and REGION3. That 676bc75619SDan Williams * unallacted capacity is reclaimed as BLK namespaces ("blk2.0" and 686bc75619SDan Williams * "blk3.0") starting at the base of each DIMM to offset (a) in those 696bc75619SDan Williams * DIMMs. "pm0.0", "blk2.0" and "blk3.0" are free-form readable 706bc75619SDan Williams * names that can be assigned to a namespace. 716bc75619SDan Williams * 726bc75619SDan Williams * *) In the last portion of dimm0 and dimm1 we have an interleaved 736bc75619SDan Williams * SPA range, REGION1, that spans those two dimms as well as dimm2 746bc75619SDan Williams * and dimm3. Some of REGION1 allocated to a PMEM namespace named 756bc75619SDan Williams * "pm1.0" the rest is reclaimed in 4 BLK namespaces (for each 766bc75619SDan Williams * dimm in the interleave set), "blk2.1", "blk3.1", "blk4.0", and 776bc75619SDan Williams * "blk5.0". 786bc75619SDan Williams * 796bc75619SDan Williams * *) The portion of dimm2 and dimm3 that do not participate in the 806bc75619SDan Williams * REGION1 interleaved SPA range (i.e. the DPA address below offset 816bc75619SDan Williams * (b) are also included in the "blk4.0" and "blk5.0" namespaces. 826bc75619SDan Williams * Note, that BLK namespaces need not be contiguous in DPA-space, and 836bc75619SDan Williams * can consume aliased capacity from multiple interleave sets. 846bc75619SDan Williams * 856bc75619SDan Williams * BUS1: Legacy NVDIMM (single contiguous range) 866bc75619SDan Williams * 876bc75619SDan Williams * region2 886bc75619SDan Williams * +---------------------+ 896bc75619SDan Williams * |---------------------| 906bc75619SDan Williams * || pm2.0 || 916bc75619SDan Williams * |---------------------| 926bc75619SDan Williams * +---------------------+ 936bc75619SDan Williams * 946bc75619SDan Williams * *) A NFIT-table may describe a simple system-physical-address range 956bc75619SDan Williams * with no BLK aliasing. This type of region may optionally 966bc75619SDan Williams * reference an NVDIMM. 976bc75619SDan Williams */ 986bc75619SDan Williams enum { 9920985164SVishal Verma NUM_PM = 3, 10020985164SVishal Verma NUM_DCR = 5, 1016bc75619SDan Williams NUM_BDW = NUM_DCR, 1026bc75619SDan Williams NUM_SPA = NUM_PM + NUM_DCR + NUM_BDW, 1036bc75619SDan Williams NUM_MEM = NUM_DCR + NUM_BDW + 2 /* spa0 iset */ + 4 /* spa1 iset */, 1046bc75619SDan Williams DIMM_SIZE = SZ_32M, 1056bc75619SDan Williams LABEL_SIZE = SZ_128K, 1066bc75619SDan Williams SPA0_SIZE = DIMM_SIZE, 1076bc75619SDan Williams SPA1_SIZE = DIMM_SIZE*2, 1086bc75619SDan Williams SPA2_SIZE = DIMM_SIZE, 1096bc75619SDan Williams BDW_SIZE = 64 << 8, 1106bc75619SDan Williams DCR_SIZE = 12, 1116bc75619SDan Williams NUM_NFITS = 2, /* permit testing multiple NFITs per system */ 1126bc75619SDan Williams }; 1136bc75619SDan Williams 1146bc75619SDan Williams struct nfit_test_dcr { 1156bc75619SDan Williams __le64 bdw_addr; 1166bc75619SDan Williams __le32 bdw_status; 1176bc75619SDan Williams __u8 aperature[BDW_SIZE]; 1186bc75619SDan Williams }; 1196bc75619SDan Williams 1206bc75619SDan Williams #define NFIT_DIMM_HANDLE(node, socket, imc, chan, dimm) \ 1216bc75619SDan Williams (((node & 0xfff) << 16) | ((socket & 0xf) << 12) \ 1226bc75619SDan Williams | ((imc & 0xf) << 8) | ((chan & 0xf) << 4) | (dimm & 0xf)) 1236bc75619SDan Williams 1246bc75619SDan Williams static u32 handle[NUM_DCR] = { 1256bc75619SDan Williams [0] = NFIT_DIMM_HANDLE(0, 0, 0, 0, 0), 1266bc75619SDan Williams [1] = NFIT_DIMM_HANDLE(0, 0, 0, 0, 1), 1276bc75619SDan Williams [2] = NFIT_DIMM_HANDLE(0, 0, 1, 0, 0), 1286bc75619SDan Williams [3] = NFIT_DIMM_HANDLE(0, 0, 1, 0, 1), 12920985164SVishal Verma [4] = NFIT_DIMM_HANDLE(0, 1, 0, 0, 0), 1306bc75619SDan Williams }; 1316bc75619SDan Williams 1326bc75619SDan Williams struct nfit_test { 1336bc75619SDan Williams struct acpi_nfit_desc acpi_desc; 1346bc75619SDan Williams struct platform_device pdev; 1356bc75619SDan Williams struct list_head resources; 1366bc75619SDan Williams void *nfit_buf; 1376bc75619SDan Williams dma_addr_t nfit_dma; 1386bc75619SDan Williams size_t nfit_size; 1396bc75619SDan Williams int num_dcr; 1406bc75619SDan Williams int num_pm; 1416bc75619SDan Williams void **dimm; 1426bc75619SDan Williams dma_addr_t *dimm_dma; 1439d27a87eSDan Williams void **flush; 1449d27a87eSDan Williams dma_addr_t *flush_dma; 1456bc75619SDan Williams void **label; 1466bc75619SDan Williams dma_addr_t *label_dma; 1476bc75619SDan Williams void **spa_set; 1486bc75619SDan Williams dma_addr_t *spa_set_dma; 1496bc75619SDan Williams struct nfit_test_dcr **dcr; 1506bc75619SDan Williams dma_addr_t *dcr_dma; 1516bc75619SDan Williams int (*alloc)(struct nfit_test *t); 1526bc75619SDan Williams void (*setup)(struct nfit_test *t); 15320985164SVishal Verma int setup_hotplug; 154f471f1a7SDan Williams struct ars_state { 155f471f1a7SDan Williams struct nd_cmd_ars_status *ars_status; 156f471f1a7SDan Williams unsigned long deadline; 157f471f1a7SDan Williams spinlock_t lock; 158f471f1a7SDan Williams } ars_state; 1596bc75619SDan Williams }; 1606bc75619SDan Williams 1616bc75619SDan Williams static struct nfit_test *to_nfit_test(struct device *dev) 1626bc75619SDan Williams { 1636bc75619SDan Williams struct platform_device *pdev = to_platform_device(dev); 1646bc75619SDan Williams 1656bc75619SDan Williams return container_of(pdev, struct nfit_test, pdev); 1666bc75619SDan Williams } 1676bc75619SDan Williams 16839c686b8SVishal Verma static int nfit_test_cmd_get_config_size(struct nd_cmd_get_config_size *nd_cmd, 1696bc75619SDan Williams unsigned int buf_len) 1706bc75619SDan Williams { 1716bc75619SDan Williams if (buf_len < sizeof(*nd_cmd)) 1726bc75619SDan Williams return -EINVAL; 17339c686b8SVishal Verma 1746bc75619SDan Williams nd_cmd->status = 0; 1756bc75619SDan Williams nd_cmd->config_size = LABEL_SIZE; 1766bc75619SDan Williams nd_cmd->max_xfer = SZ_4K; 17739c686b8SVishal Verma 17839c686b8SVishal Verma return 0; 1796bc75619SDan Williams } 18039c686b8SVishal Verma 18139c686b8SVishal Verma static int nfit_test_cmd_get_config_data(struct nd_cmd_get_config_data_hdr 18239c686b8SVishal Verma *nd_cmd, unsigned int buf_len, void *label) 18339c686b8SVishal Verma { 1846bc75619SDan Williams unsigned int len, offset = nd_cmd->in_offset; 18539c686b8SVishal Verma int rc; 1866bc75619SDan Williams 1876bc75619SDan Williams if (buf_len < sizeof(*nd_cmd)) 1886bc75619SDan Williams return -EINVAL; 1896bc75619SDan Williams if (offset >= LABEL_SIZE) 1906bc75619SDan Williams return -EINVAL; 1916bc75619SDan Williams if (nd_cmd->in_length + sizeof(*nd_cmd) > buf_len) 1926bc75619SDan Williams return -EINVAL; 1936bc75619SDan Williams 1946bc75619SDan Williams nd_cmd->status = 0; 1956bc75619SDan Williams len = min(nd_cmd->in_length, LABEL_SIZE - offset); 19639c686b8SVishal Verma memcpy(nd_cmd->out_buf, label + offset, len); 1976bc75619SDan Williams rc = buf_len - sizeof(*nd_cmd) - len; 19839c686b8SVishal Verma 19939c686b8SVishal Verma return rc; 2006bc75619SDan Williams } 20139c686b8SVishal Verma 20239c686b8SVishal Verma static int nfit_test_cmd_set_config_data(struct nd_cmd_set_config_hdr *nd_cmd, 20339c686b8SVishal Verma unsigned int buf_len, void *label) 20439c686b8SVishal Verma { 2056bc75619SDan Williams unsigned int len, offset = nd_cmd->in_offset; 2066bc75619SDan Williams u32 *status; 20739c686b8SVishal Verma int rc; 2086bc75619SDan Williams 2096bc75619SDan Williams if (buf_len < sizeof(*nd_cmd)) 2106bc75619SDan Williams return -EINVAL; 2116bc75619SDan Williams if (offset >= LABEL_SIZE) 2126bc75619SDan Williams return -EINVAL; 2136bc75619SDan Williams if (nd_cmd->in_length + sizeof(*nd_cmd) + 4 > buf_len) 2146bc75619SDan Williams return -EINVAL; 2156bc75619SDan Williams 21639c686b8SVishal Verma status = (void *)nd_cmd + nd_cmd->in_length + sizeof(*nd_cmd); 2176bc75619SDan Williams *status = 0; 2186bc75619SDan Williams len = min(nd_cmd->in_length, LABEL_SIZE - offset); 21939c686b8SVishal Verma memcpy(label + offset, nd_cmd->in_buf, len); 2206bc75619SDan Williams rc = buf_len - sizeof(*nd_cmd) - (len + 4); 22139c686b8SVishal Verma 22239c686b8SVishal Verma return rc; 2236bc75619SDan Williams } 22439c686b8SVishal Verma 225747ffe11SDan Williams #define NFIT_TEST_ARS_RECORDS 4 226d4f32367SDan Williams #define NFIT_TEST_CLEAR_ERR_UNIT 256 227747ffe11SDan Williams 22839c686b8SVishal Verma static int nfit_test_cmd_ars_cap(struct nd_cmd_ars_cap *nd_cmd, 22939c686b8SVishal Verma unsigned int buf_len) 23039c686b8SVishal Verma { 23139c686b8SVishal Verma if (buf_len < sizeof(*nd_cmd)) 23239c686b8SVishal Verma return -EINVAL; 23339c686b8SVishal Verma 234747ffe11SDan Williams nd_cmd->max_ars_out = sizeof(struct nd_cmd_ars_status) 235747ffe11SDan Williams + NFIT_TEST_ARS_RECORDS * sizeof(struct nd_ars_record); 23639c686b8SVishal Verma nd_cmd->status = (ND_ARS_PERSISTENT | ND_ARS_VOLATILE) << 16; 237d4f32367SDan Williams nd_cmd->clear_err_unit = NFIT_TEST_CLEAR_ERR_UNIT; 23839c686b8SVishal Verma 23939c686b8SVishal Verma return 0; 24039c686b8SVishal Verma } 24139c686b8SVishal Verma 242f471f1a7SDan Williams /* 243f471f1a7SDan Williams * Initialize the ars_state to return an ars_result 1 second in the future with 244f471f1a7SDan Williams * a 4K error range in the middle of the requested address range. 245f471f1a7SDan Williams */ 246f471f1a7SDan Williams static void post_ars_status(struct ars_state *ars_state, u64 addr, u64 len) 24739c686b8SVishal Verma { 248f471f1a7SDan Williams struct nd_cmd_ars_status *ars_status; 249f471f1a7SDan Williams struct nd_ars_record *ars_record; 250f471f1a7SDan Williams 251f471f1a7SDan Williams ars_state->deadline = jiffies + 1*HZ; 252f471f1a7SDan Williams ars_status = ars_state->ars_status; 253f471f1a7SDan Williams ars_status->status = 0; 254f471f1a7SDan Williams ars_status->out_length = sizeof(struct nd_cmd_ars_status) 255f471f1a7SDan Williams + sizeof(struct nd_ars_record); 256f471f1a7SDan Williams ars_status->address = addr; 257f471f1a7SDan Williams ars_status->length = len; 258f471f1a7SDan Williams ars_status->type = ND_ARS_PERSISTENT; 259f471f1a7SDan Williams ars_status->num_records = 1; 260f471f1a7SDan Williams ars_record = &ars_status->records[0]; 261f471f1a7SDan Williams ars_record->handle = 0; 262f471f1a7SDan Williams ars_record->err_address = addr + len / 2; 263f471f1a7SDan Williams ars_record->length = SZ_4K; 264f471f1a7SDan Williams } 265f471f1a7SDan Williams 266f471f1a7SDan Williams static int nfit_test_cmd_ars_start(struct ars_state *ars_state, 267f471f1a7SDan Williams struct nd_cmd_ars_start *ars_start, unsigned int buf_len, 268f471f1a7SDan Williams int *cmd_rc) 269f471f1a7SDan Williams { 270f471f1a7SDan Williams if (buf_len < sizeof(*ars_start)) 27139c686b8SVishal Verma return -EINVAL; 27239c686b8SVishal Verma 273f471f1a7SDan Williams spin_lock(&ars_state->lock); 274f471f1a7SDan Williams if (time_before(jiffies, ars_state->deadline)) { 275f471f1a7SDan Williams ars_start->status = NFIT_ARS_START_BUSY; 276f471f1a7SDan Williams *cmd_rc = -EBUSY; 277f471f1a7SDan Williams } else { 278f471f1a7SDan Williams ars_start->status = 0; 279f471f1a7SDan Williams ars_start->scrub_time = 1; 280f471f1a7SDan Williams post_ars_status(ars_state, ars_start->address, 281f471f1a7SDan Williams ars_start->length); 282f471f1a7SDan Williams *cmd_rc = 0; 283f471f1a7SDan Williams } 284f471f1a7SDan Williams spin_unlock(&ars_state->lock); 28539c686b8SVishal Verma 28639c686b8SVishal Verma return 0; 28739c686b8SVishal Verma } 28839c686b8SVishal Verma 289f471f1a7SDan Williams static int nfit_test_cmd_ars_status(struct ars_state *ars_state, 290f471f1a7SDan Williams struct nd_cmd_ars_status *ars_status, unsigned int buf_len, 291f471f1a7SDan Williams int *cmd_rc) 29239c686b8SVishal Verma { 293f471f1a7SDan Williams if (buf_len < ars_state->ars_status->out_length) 29439c686b8SVishal Verma return -EINVAL; 29539c686b8SVishal Verma 296f471f1a7SDan Williams spin_lock(&ars_state->lock); 297f471f1a7SDan Williams if (time_before(jiffies, ars_state->deadline)) { 298f471f1a7SDan Williams memset(ars_status, 0, buf_len); 299f471f1a7SDan Williams ars_status->status = NFIT_ARS_STATUS_BUSY; 300f471f1a7SDan Williams ars_status->out_length = sizeof(*ars_status); 301f471f1a7SDan Williams *cmd_rc = -EBUSY; 302f471f1a7SDan Williams } else { 303f471f1a7SDan Williams memcpy(ars_status, ars_state->ars_status, 304f471f1a7SDan Williams ars_state->ars_status->out_length); 305f471f1a7SDan Williams *cmd_rc = 0; 306f471f1a7SDan Williams } 307f471f1a7SDan Williams spin_unlock(&ars_state->lock); 30839c686b8SVishal Verma return 0; 30939c686b8SVishal Verma } 31039c686b8SVishal Verma 311d4f32367SDan Williams static int nfit_test_cmd_clear_error(struct nd_cmd_clear_error *clear_err, 312d4f32367SDan Williams unsigned int buf_len, int *cmd_rc) 313d4f32367SDan Williams { 314d4f32367SDan Williams const u64 mask = NFIT_TEST_CLEAR_ERR_UNIT - 1; 315d4f32367SDan Williams if (buf_len < sizeof(*clear_err)) 316d4f32367SDan Williams return -EINVAL; 317d4f32367SDan Williams 318d4f32367SDan Williams if ((clear_err->address & mask) || (clear_err->length & mask)) 319d4f32367SDan Williams return -EINVAL; 320d4f32367SDan Williams 321d4f32367SDan Williams /* 322d4f32367SDan Williams * Report 'all clear' success for all commands even though a new 323d4f32367SDan Williams * scrub will find errors again. This is enough to have the 324d4f32367SDan Williams * error removed from the 'badblocks' tracking in the pmem 325d4f32367SDan Williams * driver. 326d4f32367SDan Williams */ 327d4f32367SDan Williams clear_err->status = 0; 328d4f32367SDan Williams clear_err->cleared = clear_err->length; 329d4f32367SDan Williams *cmd_rc = 0; 330d4f32367SDan Williams return 0; 331d4f32367SDan Williams } 332d4f32367SDan Williams 33339c686b8SVishal Verma static int nfit_test_ctl(struct nvdimm_bus_descriptor *nd_desc, 33439c686b8SVishal Verma struct nvdimm *nvdimm, unsigned int cmd, void *buf, 335aef25338SDan Williams unsigned int buf_len, int *cmd_rc) 33639c686b8SVishal Verma { 33739c686b8SVishal Verma struct acpi_nfit_desc *acpi_desc = to_acpi_desc(nd_desc); 33839c686b8SVishal Verma struct nfit_test *t = container_of(acpi_desc, typeof(*t), acpi_desc); 339f471f1a7SDan Williams int i, rc = 0, __cmd_rc; 340f471f1a7SDan Williams 341f471f1a7SDan Williams if (!cmd_rc) 342f471f1a7SDan Williams cmd_rc = &__cmd_rc; 343f471f1a7SDan Williams *cmd_rc = 0; 34439c686b8SVishal Verma 34539c686b8SVishal Verma if (nvdimm) { 34639c686b8SVishal Verma struct nfit_mem *nfit_mem = nvdimm_provider_data(nvdimm); 347*e3654ecaSDan Williams unsigned long cmd_mask = nvdimm_cmd_mask(nvdimm); 34839c686b8SVishal Verma 349*e3654ecaSDan Williams if (!nfit_mem || !test_bit(cmd, &cmd_mask)) 35039c686b8SVishal Verma return -ENOTTY; 35139c686b8SVishal Verma 35239c686b8SVishal Verma /* lookup label space for the given dimm */ 35339c686b8SVishal Verma for (i = 0; i < ARRAY_SIZE(handle); i++) 35439c686b8SVishal Verma if (__to_nfit_memdev(nfit_mem)->device_handle == 35539c686b8SVishal Verma handle[i]) 35639c686b8SVishal Verma break; 35739c686b8SVishal Verma if (i >= ARRAY_SIZE(handle)) 35839c686b8SVishal Verma return -ENXIO; 35939c686b8SVishal Verma 36039c686b8SVishal Verma switch (cmd) { 36139c686b8SVishal Verma case ND_CMD_GET_CONFIG_SIZE: 36239c686b8SVishal Verma rc = nfit_test_cmd_get_config_size(buf, buf_len); 36339c686b8SVishal Verma break; 36439c686b8SVishal Verma case ND_CMD_GET_CONFIG_DATA: 36539c686b8SVishal Verma rc = nfit_test_cmd_get_config_data(buf, buf_len, 36639c686b8SVishal Verma t->label[i]); 36739c686b8SVishal Verma break; 36839c686b8SVishal Verma case ND_CMD_SET_CONFIG_DATA: 36939c686b8SVishal Verma rc = nfit_test_cmd_set_config_data(buf, buf_len, 37039c686b8SVishal Verma t->label[i]); 37139c686b8SVishal Verma break; 3726bc75619SDan Williams default: 3736bc75619SDan Williams return -ENOTTY; 3746bc75619SDan Williams } 37539c686b8SVishal Verma } else { 376f471f1a7SDan Williams struct ars_state *ars_state = &t->ars_state; 377f471f1a7SDan Williams 378*e3654ecaSDan Williams if (!nd_desc || !test_bit(cmd, &nd_desc->cmd_mask)) 37939c686b8SVishal Verma return -ENOTTY; 38039c686b8SVishal Verma 38139c686b8SVishal Verma switch (cmd) { 38239c686b8SVishal Verma case ND_CMD_ARS_CAP: 38339c686b8SVishal Verma rc = nfit_test_cmd_ars_cap(buf, buf_len); 38439c686b8SVishal Verma break; 38539c686b8SVishal Verma case ND_CMD_ARS_START: 386f471f1a7SDan Williams rc = nfit_test_cmd_ars_start(ars_state, buf, buf_len, 387f471f1a7SDan Williams cmd_rc); 38839c686b8SVishal Verma break; 38939c686b8SVishal Verma case ND_CMD_ARS_STATUS: 390f471f1a7SDan Williams rc = nfit_test_cmd_ars_status(ars_state, buf, buf_len, 391f471f1a7SDan Williams cmd_rc); 39239c686b8SVishal Verma break; 393d4f32367SDan Williams case ND_CMD_CLEAR_ERROR: 394d4f32367SDan Williams rc = nfit_test_cmd_clear_error(buf, buf_len, cmd_rc); 395d4f32367SDan Williams break; 39639c686b8SVishal Verma default: 39739c686b8SVishal Verma return -ENOTTY; 39839c686b8SVishal Verma } 39939c686b8SVishal Verma } 4006bc75619SDan Williams 4016bc75619SDan Williams return rc; 4026bc75619SDan Williams } 4036bc75619SDan Williams 4046bc75619SDan Williams static DEFINE_SPINLOCK(nfit_test_lock); 4056bc75619SDan Williams static struct nfit_test *instances[NUM_NFITS]; 4066bc75619SDan Williams 4076bc75619SDan Williams static void release_nfit_res(void *data) 4086bc75619SDan Williams { 4096bc75619SDan Williams struct nfit_test_resource *nfit_res = data; 4106bc75619SDan Williams struct resource *res = nfit_res->res; 4116bc75619SDan Williams 4126bc75619SDan Williams spin_lock(&nfit_test_lock); 4136bc75619SDan Williams list_del(&nfit_res->list); 4146bc75619SDan Williams spin_unlock(&nfit_test_lock); 4156bc75619SDan Williams 4166bc75619SDan Williams if (is_vmalloc_addr(nfit_res->buf)) 4176bc75619SDan Williams vfree(nfit_res->buf); 4186bc75619SDan Williams else 4196bc75619SDan Williams dma_free_coherent(nfit_res->dev, resource_size(res), 4206bc75619SDan Williams nfit_res->buf, res->start); 4216bc75619SDan Williams kfree(res); 4226bc75619SDan Williams kfree(nfit_res); 4236bc75619SDan Williams } 4246bc75619SDan Williams 4256bc75619SDan Williams static void *__test_alloc(struct nfit_test *t, size_t size, dma_addr_t *dma, 4266bc75619SDan Williams void *buf) 4276bc75619SDan Williams { 4286bc75619SDan Williams struct device *dev = &t->pdev.dev; 4296bc75619SDan Williams struct resource *res = kzalloc(sizeof(*res) * 2, GFP_KERNEL); 4306bc75619SDan Williams struct nfit_test_resource *nfit_res = kzalloc(sizeof(*nfit_res), 4316bc75619SDan Williams GFP_KERNEL); 4326bc75619SDan Williams int rc; 4336bc75619SDan Williams 4346bc75619SDan Williams if (!res || !buf || !nfit_res) 4356bc75619SDan Williams goto err; 4366bc75619SDan Williams rc = devm_add_action(dev, release_nfit_res, nfit_res); 4376bc75619SDan Williams if (rc) 4386bc75619SDan Williams goto err; 4396bc75619SDan Williams INIT_LIST_HEAD(&nfit_res->list); 4406bc75619SDan Williams memset(buf, 0, size); 4416bc75619SDan Williams nfit_res->dev = dev; 4426bc75619SDan Williams nfit_res->buf = buf; 4436bc75619SDan Williams nfit_res->res = res; 4446bc75619SDan Williams res->start = *dma; 4456bc75619SDan Williams res->end = *dma + size - 1; 4466bc75619SDan Williams res->name = "NFIT"; 4476bc75619SDan Williams spin_lock(&nfit_test_lock); 4486bc75619SDan Williams list_add(&nfit_res->list, &t->resources); 4496bc75619SDan Williams spin_unlock(&nfit_test_lock); 4506bc75619SDan Williams 4516bc75619SDan Williams return nfit_res->buf; 4526bc75619SDan Williams err: 4536bc75619SDan Williams if (buf && !is_vmalloc_addr(buf)) 4546bc75619SDan Williams dma_free_coherent(dev, size, buf, *dma); 4556bc75619SDan Williams else if (buf) 4566bc75619SDan Williams vfree(buf); 4576bc75619SDan Williams kfree(res); 4586bc75619SDan Williams kfree(nfit_res); 4596bc75619SDan Williams return NULL; 4606bc75619SDan Williams } 4616bc75619SDan Williams 4626bc75619SDan Williams static void *test_alloc(struct nfit_test *t, size_t size, dma_addr_t *dma) 4636bc75619SDan Williams { 4646bc75619SDan Williams void *buf = vmalloc(size); 4656bc75619SDan Williams 4666bc75619SDan Williams *dma = (unsigned long) buf; 4676bc75619SDan Williams return __test_alloc(t, size, dma, buf); 4686bc75619SDan Williams } 4696bc75619SDan Williams 4706bc75619SDan Williams static void *test_alloc_coherent(struct nfit_test *t, size_t size, 4716bc75619SDan Williams dma_addr_t *dma) 4726bc75619SDan Williams { 4736bc75619SDan Williams struct device *dev = &t->pdev.dev; 4746bc75619SDan Williams void *buf = dma_alloc_coherent(dev, size, dma, GFP_KERNEL); 4756bc75619SDan Williams 4766bc75619SDan Williams return __test_alloc(t, size, dma, buf); 4776bc75619SDan Williams } 4786bc75619SDan Williams 4796bc75619SDan Williams static struct nfit_test_resource *nfit_test_lookup(resource_size_t addr) 4806bc75619SDan Williams { 4816bc75619SDan Williams int i; 4826bc75619SDan Williams 4836bc75619SDan Williams for (i = 0; i < ARRAY_SIZE(instances); i++) { 4846bc75619SDan Williams struct nfit_test_resource *n, *nfit_res = NULL; 4856bc75619SDan Williams struct nfit_test *t = instances[i]; 4866bc75619SDan Williams 4876bc75619SDan Williams if (!t) 4886bc75619SDan Williams continue; 4896bc75619SDan Williams spin_lock(&nfit_test_lock); 4906bc75619SDan Williams list_for_each_entry(n, &t->resources, list) { 4916bc75619SDan Williams if (addr >= n->res->start && (addr < n->res->start 4926bc75619SDan Williams + resource_size(n->res))) { 4936bc75619SDan Williams nfit_res = n; 4946bc75619SDan Williams break; 4956bc75619SDan Williams } else if (addr >= (unsigned long) n->buf 4966bc75619SDan Williams && (addr < (unsigned long) n->buf 4976bc75619SDan Williams + resource_size(n->res))) { 4986bc75619SDan Williams nfit_res = n; 4996bc75619SDan Williams break; 5006bc75619SDan Williams } 5016bc75619SDan Williams } 5026bc75619SDan Williams spin_unlock(&nfit_test_lock); 5036bc75619SDan Williams if (nfit_res) 5046bc75619SDan Williams return nfit_res; 5056bc75619SDan Williams } 5066bc75619SDan Williams 5076bc75619SDan Williams return NULL; 5086bc75619SDan Williams } 5096bc75619SDan Williams 510f471f1a7SDan Williams static int ars_state_init(struct device *dev, struct ars_state *ars_state) 511f471f1a7SDan Williams { 512f471f1a7SDan Williams ars_state->ars_status = devm_kzalloc(dev, 513f471f1a7SDan Williams sizeof(struct nd_cmd_ars_status) 514f471f1a7SDan Williams + sizeof(struct nd_ars_record) * NFIT_TEST_ARS_RECORDS, 515f471f1a7SDan Williams GFP_KERNEL); 516f471f1a7SDan Williams if (!ars_state->ars_status) 517f471f1a7SDan Williams return -ENOMEM; 518f471f1a7SDan Williams spin_lock_init(&ars_state->lock); 519f471f1a7SDan Williams return 0; 520f471f1a7SDan Williams } 521f471f1a7SDan Williams 5226bc75619SDan Williams static int nfit_test0_alloc(struct nfit_test *t) 5236bc75619SDan Williams { 5246b577c9dSLinda Knippers size_t nfit_size = sizeof(struct acpi_nfit_system_address) * NUM_SPA 5256bc75619SDan Williams + sizeof(struct acpi_nfit_memory_map) * NUM_MEM 5266bc75619SDan Williams + sizeof(struct acpi_nfit_control_region) * NUM_DCR 5273b87356fSDan Williams + offsetof(struct acpi_nfit_control_region, 5283b87356fSDan Williams window_size) * NUM_DCR 5299d27a87eSDan Williams + sizeof(struct acpi_nfit_data_region) * NUM_BDW 5309d27a87eSDan Williams + sizeof(struct acpi_nfit_flush_address) * NUM_DCR; 5316bc75619SDan Williams int i; 5326bc75619SDan Williams 5336bc75619SDan Williams t->nfit_buf = test_alloc(t, nfit_size, &t->nfit_dma); 5346bc75619SDan Williams if (!t->nfit_buf) 5356bc75619SDan Williams return -ENOMEM; 5366bc75619SDan Williams t->nfit_size = nfit_size; 5376bc75619SDan Williams 5386bc75619SDan Williams t->spa_set[0] = test_alloc_coherent(t, SPA0_SIZE, &t->spa_set_dma[0]); 5396bc75619SDan Williams if (!t->spa_set[0]) 5406bc75619SDan Williams return -ENOMEM; 5416bc75619SDan Williams 5426bc75619SDan Williams t->spa_set[1] = test_alloc_coherent(t, SPA1_SIZE, &t->spa_set_dma[1]); 5436bc75619SDan Williams if (!t->spa_set[1]) 5446bc75619SDan Williams return -ENOMEM; 5456bc75619SDan Williams 54620985164SVishal Verma t->spa_set[2] = test_alloc_coherent(t, SPA0_SIZE, &t->spa_set_dma[2]); 54720985164SVishal Verma if (!t->spa_set[2]) 54820985164SVishal Verma return -ENOMEM; 54920985164SVishal Verma 5506bc75619SDan Williams for (i = 0; i < NUM_DCR; i++) { 5516bc75619SDan Williams t->dimm[i] = test_alloc(t, DIMM_SIZE, &t->dimm_dma[i]); 5526bc75619SDan Williams if (!t->dimm[i]) 5536bc75619SDan Williams return -ENOMEM; 5546bc75619SDan Williams 5556bc75619SDan Williams t->label[i] = test_alloc(t, LABEL_SIZE, &t->label_dma[i]); 5566bc75619SDan Williams if (!t->label[i]) 5576bc75619SDan Williams return -ENOMEM; 5586bc75619SDan Williams sprintf(t->label[i], "label%d", i); 5599d27a87eSDan Williams 5609d27a87eSDan Williams t->flush[i] = test_alloc(t, 8, &t->flush_dma[i]); 5619d27a87eSDan Williams if (!t->flush[i]) 5629d27a87eSDan Williams return -ENOMEM; 5636bc75619SDan Williams } 5646bc75619SDan Williams 5656bc75619SDan Williams for (i = 0; i < NUM_DCR; i++) { 5666bc75619SDan Williams t->dcr[i] = test_alloc(t, LABEL_SIZE, &t->dcr_dma[i]); 5676bc75619SDan Williams if (!t->dcr[i]) 5686bc75619SDan Williams return -ENOMEM; 5696bc75619SDan Williams } 5706bc75619SDan Williams 571f471f1a7SDan Williams return ars_state_init(&t->pdev.dev, &t->ars_state); 5726bc75619SDan Williams } 5736bc75619SDan Williams 5746bc75619SDan Williams static int nfit_test1_alloc(struct nfit_test *t) 5756bc75619SDan Williams { 5766b577c9dSLinda Knippers size_t nfit_size = sizeof(struct acpi_nfit_system_address) 5776bc75619SDan Williams + sizeof(struct acpi_nfit_memory_map) 5783b87356fSDan Williams + offsetof(struct acpi_nfit_control_region, window_size); 5796bc75619SDan Williams 5806bc75619SDan Williams t->nfit_buf = test_alloc(t, nfit_size, &t->nfit_dma); 5816bc75619SDan Williams if (!t->nfit_buf) 5826bc75619SDan Williams return -ENOMEM; 5836bc75619SDan Williams t->nfit_size = nfit_size; 5846bc75619SDan Williams 5856bc75619SDan Williams t->spa_set[0] = test_alloc_coherent(t, SPA2_SIZE, &t->spa_set_dma[0]); 5866bc75619SDan Williams if (!t->spa_set[0]) 5876bc75619SDan Williams return -ENOMEM; 5886bc75619SDan Williams 589f471f1a7SDan Williams return ars_state_init(&t->pdev.dev, &t->ars_state); 5906bc75619SDan Williams } 5916bc75619SDan Williams 5926bc75619SDan Williams static void nfit_test0_setup(struct nfit_test *t) 5936bc75619SDan Williams { 5946bc75619SDan Williams struct acpi_nfit_desc *acpi_desc; 5956bc75619SDan Williams struct acpi_nfit_memory_map *memdev; 5966bc75619SDan Williams void *nfit_buf = t->nfit_buf; 5976bc75619SDan Williams struct acpi_nfit_system_address *spa; 5986bc75619SDan Williams struct acpi_nfit_control_region *dcr; 5996bc75619SDan Williams struct acpi_nfit_data_region *bdw; 6009d27a87eSDan Williams struct acpi_nfit_flush_address *flush; 6016bc75619SDan Williams unsigned int offset; 6026bc75619SDan Williams 6036bc75619SDan Williams /* 6046bc75619SDan Williams * spa0 (interleave first half of dimm0 and dimm1, note storage 6056bc75619SDan Williams * does not actually alias the related block-data-window 6066bc75619SDan Williams * regions) 6076bc75619SDan Williams */ 6086b577c9dSLinda Knippers spa = nfit_buf; 6096bc75619SDan Williams spa->header.type = ACPI_NFIT_TYPE_SYSTEM_ADDRESS; 6106bc75619SDan Williams spa->header.length = sizeof(*spa); 6116bc75619SDan Williams memcpy(spa->range_guid, to_nfit_uuid(NFIT_SPA_PM), 16); 6126bc75619SDan Williams spa->range_index = 0+1; 6136bc75619SDan Williams spa->address = t->spa_set_dma[0]; 6146bc75619SDan Williams spa->length = SPA0_SIZE; 6156bc75619SDan Williams 6166bc75619SDan Williams /* 6176bc75619SDan Williams * spa1 (interleave last half of the 4 DIMMS, note storage 6186bc75619SDan Williams * does not actually alias the related block-data-window 6196bc75619SDan Williams * regions) 6206bc75619SDan Williams */ 6216b577c9dSLinda Knippers spa = nfit_buf + sizeof(*spa); 6226bc75619SDan Williams spa->header.type = ACPI_NFIT_TYPE_SYSTEM_ADDRESS; 6236bc75619SDan Williams spa->header.length = sizeof(*spa); 6246bc75619SDan Williams memcpy(spa->range_guid, to_nfit_uuid(NFIT_SPA_PM), 16); 6256bc75619SDan Williams spa->range_index = 1+1; 6266bc75619SDan Williams spa->address = t->spa_set_dma[1]; 6276bc75619SDan Williams spa->length = SPA1_SIZE; 6286bc75619SDan Williams 6296bc75619SDan Williams /* spa2 (dcr0) dimm0 */ 6306b577c9dSLinda Knippers spa = nfit_buf + sizeof(*spa) * 2; 6316bc75619SDan Williams spa->header.type = ACPI_NFIT_TYPE_SYSTEM_ADDRESS; 6326bc75619SDan Williams spa->header.length = sizeof(*spa); 6336bc75619SDan Williams memcpy(spa->range_guid, to_nfit_uuid(NFIT_SPA_DCR), 16); 6346bc75619SDan Williams spa->range_index = 2+1; 6356bc75619SDan Williams spa->address = t->dcr_dma[0]; 6366bc75619SDan Williams spa->length = DCR_SIZE; 6376bc75619SDan Williams 6386bc75619SDan Williams /* spa3 (dcr1) dimm1 */ 6396b577c9dSLinda Knippers spa = nfit_buf + sizeof(*spa) * 3; 6406bc75619SDan Williams spa->header.type = ACPI_NFIT_TYPE_SYSTEM_ADDRESS; 6416bc75619SDan Williams spa->header.length = sizeof(*spa); 6426bc75619SDan Williams memcpy(spa->range_guid, to_nfit_uuid(NFIT_SPA_DCR), 16); 6436bc75619SDan Williams spa->range_index = 3+1; 6446bc75619SDan Williams spa->address = t->dcr_dma[1]; 6456bc75619SDan Williams spa->length = DCR_SIZE; 6466bc75619SDan Williams 6476bc75619SDan Williams /* spa4 (dcr2) dimm2 */ 6486b577c9dSLinda Knippers spa = nfit_buf + sizeof(*spa) * 4; 6496bc75619SDan Williams spa->header.type = ACPI_NFIT_TYPE_SYSTEM_ADDRESS; 6506bc75619SDan Williams spa->header.length = sizeof(*spa); 6516bc75619SDan Williams memcpy(spa->range_guid, to_nfit_uuid(NFIT_SPA_DCR), 16); 6526bc75619SDan Williams spa->range_index = 4+1; 6536bc75619SDan Williams spa->address = t->dcr_dma[2]; 6546bc75619SDan Williams spa->length = DCR_SIZE; 6556bc75619SDan Williams 6566bc75619SDan Williams /* spa5 (dcr3) dimm3 */ 6576b577c9dSLinda Knippers spa = nfit_buf + sizeof(*spa) * 5; 6586bc75619SDan Williams spa->header.type = ACPI_NFIT_TYPE_SYSTEM_ADDRESS; 6596bc75619SDan Williams spa->header.length = sizeof(*spa); 6606bc75619SDan Williams memcpy(spa->range_guid, to_nfit_uuid(NFIT_SPA_DCR), 16); 6616bc75619SDan Williams spa->range_index = 5+1; 6626bc75619SDan Williams spa->address = t->dcr_dma[3]; 6636bc75619SDan Williams spa->length = DCR_SIZE; 6646bc75619SDan Williams 6656bc75619SDan Williams /* spa6 (bdw for dcr0) dimm0 */ 6666b577c9dSLinda Knippers spa = nfit_buf + sizeof(*spa) * 6; 6676bc75619SDan Williams spa->header.type = ACPI_NFIT_TYPE_SYSTEM_ADDRESS; 6686bc75619SDan Williams spa->header.length = sizeof(*spa); 6696bc75619SDan Williams memcpy(spa->range_guid, to_nfit_uuid(NFIT_SPA_BDW), 16); 6706bc75619SDan Williams spa->range_index = 6+1; 6716bc75619SDan Williams spa->address = t->dimm_dma[0]; 6726bc75619SDan Williams spa->length = DIMM_SIZE; 6736bc75619SDan Williams 6746bc75619SDan Williams /* spa7 (bdw for dcr1) dimm1 */ 6756b577c9dSLinda Knippers spa = nfit_buf + sizeof(*spa) * 7; 6766bc75619SDan Williams spa->header.type = ACPI_NFIT_TYPE_SYSTEM_ADDRESS; 6776bc75619SDan Williams spa->header.length = sizeof(*spa); 6786bc75619SDan Williams memcpy(spa->range_guid, to_nfit_uuid(NFIT_SPA_BDW), 16); 6796bc75619SDan Williams spa->range_index = 7+1; 6806bc75619SDan Williams spa->address = t->dimm_dma[1]; 6816bc75619SDan Williams spa->length = DIMM_SIZE; 6826bc75619SDan Williams 6836bc75619SDan Williams /* spa8 (bdw for dcr2) dimm2 */ 6846b577c9dSLinda Knippers spa = nfit_buf + sizeof(*spa) * 8; 6856bc75619SDan Williams spa->header.type = ACPI_NFIT_TYPE_SYSTEM_ADDRESS; 6866bc75619SDan Williams spa->header.length = sizeof(*spa); 6876bc75619SDan Williams memcpy(spa->range_guid, to_nfit_uuid(NFIT_SPA_BDW), 16); 6886bc75619SDan Williams spa->range_index = 8+1; 6896bc75619SDan Williams spa->address = t->dimm_dma[2]; 6906bc75619SDan Williams spa->length = DIMM_SIZE; 6916bc75619SDan Williams 6926bc75619SDan Williams /* spa9 (bdw for dcr3) dimm3 */ 6936b577c9dSLinda Knippers spa = nfit_buf + sizeof(*spa) * 9; 6946bc75619SDan Williams spa->header.type = ACPI_NFIT_TYPE_SYSTEM_ADDRESS; 6956bc75619SDan Williams spa->header.length = sizeof(*spa); 6966bc75619SDan Williams memcpy(spa->range_guid, to_nfit_uuid(NFIT_SPA_BDW), 16); 6976bc75619SDan Williams spa->range_index = 9+1; 6986bc75619SDan Williams spa->address = t->dimm_dma[3]; 6996bc75619SDan Williams spa->length = DIMM_SIZE; 7006bc75619SDan Williams 7016b577c9dSLinda Knippers offset = sizeof(*spa) * 10; 7026bc75619SDan Williams /* mem-region0 (spa0, dimm0) */ 7036bc75619SDan Williams memdev = nfit_buf + offset; 7046bc75619SDan Williams memdev->header.type = ACPI_NFIT_TYPE_MEMORY_MAP; 7056bc75619SDan Williams memdev->header.length = sizeof(*memdev); 7066bc75619SDan Williams memdev->device_handle = handle[0]; 7076bc75619SDan Williams memdev->physical_id = 0; 7086bc75619SDan Williams memdev->region_id = 0; 7096bc75619SDan Williams memdev->range_index = 0+1; 7103b87356fSDan Williams memdev->region_index = 4+1; 7116bc75619SDan Williams memdev->region_size = SPA0_SIZE/2; 7126bc75619SDan Williams memdev->region_offset = t->spa_set_dma[0]; 7136bc75619SDan Williams memdev->address = 0; 7146bc75619SDan Williams memdev->interleave_index = 0; 7156bc75619SDan Williams memdev->interleave_ways = 2; 7166bc75619SDan Williams 7176bc75619SDan Williams /* mem-region1 (spa0, dimm1) */ 7186bc75619SDan Williams memdev = nfit_buf + offset + sizeof(struct acpi_nfit_memory_map); 7196bc75619SDan Williams memdev->header.type = ACPI_NFIT_TYPE_MEMORY_MAP; 7206bc75619SDan Williams memdev->header.length = sizeof(*memdev); 7216bc75619SDan Williams memdev->device_handle = handle[1]; 7226bc75619SDan Williams memdev->physical_id = 1; 7236bc75619SDan Williams memdev->region_id = 0; 7246bc75619SDan Williams memdev->range_index = 0+1; 7253b87356fSDan Williams memdev->region_index = 5+1; 7266bc75619SDan Williams memdev->region_size = SPA0_SIZE/2; 7276bc75619SDan Williams memdev->region_offset = t->spa_set_dma[0] + SPA0_SIZE/2; 7286bc75619SDan Williams memdev->address = 0; 7296bc75619SDan Williams memdev->interleave_index = 0; 7306bc75619SDan Williams memdev->interleave_ways = 2; 7316bc75619SDan Williams 7326bc75619SDan Williams /* mem-region2 (spa1, dimm0) */ 7336bc75619SDan Williams memdev = nfit_buf + offset + sizeof(struct acpi_nfit_memory_map) * 2; 7346bc75619SDan Williams memdev->header.type = ACPI_NFIT_TYPE_MEMORY_MAP; 7356bc75619SDan Williams memdev->header.length = sizeof(*memdev); 7366bc75619SDan Williams memdev->device_handle = handle[0]; 7376bc75619SDan Williams memdev->physical_id = 0; 7386bc75619SDan Williams memdev->region_id = 1; 7396bc75619SDan Williams memdev->range_index = 1+1; 7403b87356fSDan Williams memdev->region_index = 4+1; 7416bc75619SDan Williams memdev->region_size = SPA1_SIZE/4; 7426bc75619SDan Williams memdev->region_offset = t->spa_set_dma[1]; 7436bc75619SDan Williams memdev->address = SPA0_SIZE/2; 7446bc75619SDan Williams memdev->interleave_index = 0; 7456bc75619SDan Williams memdev->interleave_ways = 4; 7466bc75619SDan Williams 7476bc75619SDan Williams /* mem-region3 (spa1, dimm1) */ 7486bc75619SDan Williams memdev = nfit_buf + offset + sizeof(struct acpi_nfit_memory_map) * 3; 7496bc75619SDan Williams memdev->header.type = ACPI_NFIT_TYPE_MEMORY_MAP; 7506bc75619SDan Williams memdev->header.length = sizeof(*memdev); 7516bc75619SDan Williams memdev->device_handle = handle[1]; 7526bc75619SDan Williams memdev->physical_id = 1; 7536bc75619SDan Williams memdev->region_id = 1; 7546bc75619SDan Williams memdev->range_index = 1+1; 7553b87356fSDan Williams memdev->region_index = 5+1; 7566bc75619SDan Williams memdev->region_size = SPA1_SIZE/4; 7576bc75619SDan Williams memdev->region_offset = t->spa_set_dma[1] + SPA1_SIZE/4; 7586bc75619SDan Williams memdev->address = SPA0_SIZE/2; 7596bc75619SDan Williams memdev->interleave_index = 0; 7606bc75619SDan Williams memdev->interleave_ways = 4; 7616bc75619SDan Williams 7626bc75619SDan Williams /* mem-region4 (spa1, dimm2) */ 7636bc75619SDan Williams memdev = nfit_buf + offset + sizeof(struct acpi_nfit_memory_map) * 4; 7646bc75619SDan Williams memdev->header.type = ACPI_NFIT_TYPE_MEMORY_MAP; 7656bc75619SDan Williams memdev->header.length = sizeof(*memdev); 7666bc75619SDan Williams memdev->device_handle = handle[2]; 7676bc75619SDan Williams memdev->physical_id = 2; 7686bc75619SDan Williams memdev->region_id = 0; 7696bc75619SDan Williams memdev->range_index = 1+1; 7703b87356fSDan Williams memdev->region_index = 6+1; 7716bc75619SDan Williams memdev->region_size = SPA1_SIZE/4; 7726bc75619SDan Williams memdev->region_offset = t->spa_set_dma[1] + 2*SPA1_SIZE/4; 7736bc75619SDan Williams memdev->address = SPA0_SIZE/2; 7746bc75619SDan Williams memdev->interleave_index = 0; 7756bc75619SDan Williams memdev->interleave_ways = 4; 7766bc75619SDan Williams 7776bc75619SDan Williams /* mem-region5 (spa1, dimm3) */ 7786bc75619SDan Williams memdev = nfit_buf + offset + sizeof(struct acpi_nfit_memory_map) * 5; 7796bc75619SDan Williams memdev->header.type = ACPI_NFIT_TYPE_MEMORY_MAP; 7806bc75619SDan Williams memdev->header.length = sizeof(*memdev); 7816bc75619SDan Williams memdev->device_handle = handle[3]; 7826bc75619SDan Williams memdev->physical_id = 3; 7836bc75619SDan Williams memdev->region_id = 0; 7846bc75619SDan Williams memdev->range_index = 1+1; 7853b87356fSDan Williams memdev->region_index = 7+1; 7866bc75619SDan Williams memdev->region_size = SPA1_SIZE/4; 7876bc75619SDan Williams memdev->region_offset = t->spa_set_dma[1] + 3*SPA1_SIZE/4; 7886bc75619SDan Williams memdev->address = SPA0_SIZE/2; 7896bc75619SDan Williams memdev->interleave_index = 0; 7906bc75619SDan Williams memdev->interleave_ways = 4; 7916bc75619SDan Williams 7926bc75619SDan Williams /* mem-region6 (spa/dcr0, dimm0) */ 7936bc75619SDan Williams memdev = nfit_buf + offset + sizeof(struct acpi_nfit_memory_map) * 6; 7946bc75619SDan Williams memdev->header.type = ACPI_NFIT_TYPE_MEMORY_MAP; 7956bc75619SDan Williams memdev->header.length = sizeof(*memdev); 7966bc75619SDan Williams memdev->device_handle = handle[0]; 7976bc75619SDan Williams memdev->physical_id = 0; 7986bc75619SDan Williams memdev->region_id = 0; 7996bc75619SDan Williams memdev->range_index = 2+1; 8006bc75619SDan Williams memdev->region_index = 0+1; 8016bc75619SDan Williams memdev->region_size = 0; 8026bc75619SDan Williams memdev->region_offset = 0; 8036bc75619SDan Williams memdev->address = 0; 8046bc75619SDan Williams memdev->interleave_index = 0; 8056bc75619SDan Williams memdev->interleave_ways = 1; 8066bc75619SDan Williams 8076bc75619SDan Williams /* mem-region7 (spa/dcr1, dimm1) */ 8086bc75619SDan Williams memdev = nfit_buf + offset + sizeof(struct acpi_nfit_memory_map) * 7; 8096bc75619SDan Williams memdev->header.type = ACPI_NFIT_TYPE_MEMORY_MAP; 8106bc75619SDan Williams memdev->header.length = sizeof(*memdev); 8116bc75619SDan Williams memdev->device_handle = handle[1]; 8126bc75619SDan Williams memdev->physical_id = 1; 8136bc75619SDan Williams memdev->region_id = 0; 8146bc75619SDan Williams memdev->range_index = 3+1; 8156bc75619SDan Williams memdev->region_index = 1+1; 8166bc75619SDan Williams memdev->region_size = 0; 8176bc75619SDan Williams memdev->region_offset = 0; 8186bc75619SDan Williams memdev->address = 0; 8196bc75619SDan Williams memdev->interleave_index = 0; 8206bc75619SDan Williams memdev->interleave_ways = 1; 8216bc75619SDan Williams 8226bc75619SDan Williams /* mem-region8 (spa/dcr2, dimm2) */ 8236bc75619SDan Williams memdev = nfit_buf + offset + sizeof(struct acpi_nfit_memory_map) * 8; 8246bc75619SDan Williams memdev->header.type = ACPI_NFIT_TYPE_MEMORY_MAP; 8256bc75619SDan Williams memdev->header.length = sizeof(*memdev); 8266bc75619SDan Williams memdev->device_handle = handle[2]; 8276bc75619SDan Williams memdev->physical_id = 2; 8286bc75619SDan Williams memdev->region_id = 0; 8296bc75619SDan Williams memdev->range_index = 4+1; 8306bc75619SDan Williams memdev->region_index = 2+1; 8316bc75619SDan Williams memdev->region_size = 0; 8326bc75619SDan Williams memdev->region_offset = 0; 8336bc75619SDan Williams memdev->address = 0; 8346bc75619SDan Williams memdev->interleave_index = 0; 8356bc75619SDan Williams memdev->interleave_ways = 1; 8366bc75619SDan Williams 8376bc75619SDan Williams /* mem-region9 (spa/dcr3, dimm3) */ 8386bc75619SDan Williams memdev = nfit_buf + offset + sizeof(struct acpi_nfit_memory_map) * 9; 8396bc75619SDan Williams memdev->header.type = ACPI_NFIT_TYPE_MEMORY_MAP; 8406bc75619SDan Williams memdev->header.length = sizeof(*memdev); 8416bc75619SDan Williams memdev->device_handle = handle[3]; 8426bc75619SDan Williams memdev->physical_id = 3; 8436bc75619SDan Williams memdev->region_id = 0; 8446bc75619SDan Williams memdev->range_index = 5+1; 8456bc75619SDan Williams memdev->region_index = 3+1; 8466bc75619SDan Williams memdev->region_size = 0; 8476bc75619SDan Williams memdev->region_offset = 0; 8486bc75619SDan Williams memdev->address = 0; 8496bc75619SDan Williams memdev->interleave_index = 0; 8506bc75619SDan Williams memdev->interleave_ways = 1; 8516bc75619SDan Williams 8526bc75619SDan Williams /* mem-region10 (spa/bdw0, dimm0) */ 8536bc75619SDan Williams memdev = nfit_buf + offset + sizeof(struct acpi_nfit_memory_map) * 10; 8546bc75619SDan Williams memdev->header.type = ACPI_NFIT_TYPE_MEMORY_MAP; 8556bc75619SDan Williams memdev->header.length = sizeof(*memdev); 8566bc75619SDan Williams memdev->device_handle = handle[0]; 8576bc75619SDan Williams memdev->physical_id = 0; 8586bc75619SDan Williams memdev->region_id = 0; 8596bc75619SDan Williams memdev->range_index = 6+1; 8606bc75619SDan Williams memdev->region_index = 0+1; 8616bc75619SDan Williams memdev->region_size = 0; 8626bc75619SDan Williams memdev->region_offset = 0; 8636bc75619SDan Williams memdev->address = 0; 8646bc75619SDan Williams memdev->interleave_index = 0; 8656bc75619SDan Williams memdev->interleave_ways = 1; 8666bc75619SDan Williams 8676bc75619SDan Williams /* mem-region11 (spa/bdw1, dimm1) */ 8686bc75619SDan Williams memdev = nfit_buf + offset + sizeof(struct acpi_nfit_memory_map) * 11; 8696bc75619SDan Williams memdev->header.type = ACPI_NFIT_TYPE_MEMORY_MAP; 8706bc75619SDan Williams memdev->header.length = sizeof(*memdev); 8716bc75619SDan Williams memdev->device_handle = handle[1]; 8726bc75619SDan Williams memdev->physical_id = 1; 8736bc75619SDan Williams memdev->region_id = 0; 8746bc75619SDan Williams memdev->range_index = 7+1; 8756bc75619SDan Williams memdev->region_index = 1+1; 8766bc75619SDan Williams memdev->region_size = 0; 8776bc75619SDan Williams memdev->region_offset = 0; 8786bc75619SDan Williams memdev->address = 0; 8796bc75619SDan Williams memdev->interleave_index = 0; 8806bc75619SDan Williams memdev->interleave_ways = 1; 8816bc75619SDan Williams 8826bc75619SDan Williams /* mem-region12 (spa/bdw2, dimm2) */ 8836bc75619SDan Williams memdev = nfit_buf + offset + sizeof(struct acpi_nfit_memory_map) * 12; 8846bc75619SDan Williams memdev->header.type = ACPI_NFIT_TYPE_MEMORY_MAP; 8856bc75619SDan Williams memdev->header.length = sizeof(*memdev); 8866bc75619SDan Williams memdev->device_handle = handle[2]; 8876bc75619SDan Williams memdev->physical_id = 2; 8886bc75619SDan Williams memdev->region_id = 0; 8896bc75619SDan Williams memdev->range_index = 8+1; 8906bc75619SDan Williams memdev->region_index = 2+1; 8916bc75619SDan Williams memdev->region_size = 0; 8926bc75619SDan Williams memdev->region_offset = 0; 8936bc75619SDan Williams memdev->address = 0; 8946bc75619SDan Williams memdev->interleave_index = 0; 8956bc75619SDan Williams memdev->interleave_ways = 1; 8966bc75619SDan Williams 8976bc75619SDan Williams /* mem-region13 (spa/dcr3, dimm3) */ 8986bc75619SDan Williams memdev = nfit_buf + offset + sizeof(struct acpi_nfit_memory_map) * 13; 8996bc75619SDan Williams memdev->header.type = ACPI_NFIT_TYPE_MEMORY_MAP; 9006bc75619SDan Williams memdev->header.length = sizeof(*memdev); 9016bc75619SDan Williams memdev->device_handle = handle[3]; 9026bc75619SDan Williams memdev->physical_id = 3; 9036bc75619SDan Williams memdev->region_id = 0; 9046bc75619SDan Williams memdev->range_index = 9+1; 9056bc75619SDan Williams memdev->region_index = 3+1; 9066bc75619SDan Williams memdev->region_size = 0; 9076bc75619SDan Williams memdev->region_offset = 0; 9086bc75619SDan Williams memdev->address = 0; 9096bc75619SDan Williams memdev->interleave_index = 0; 9106bc75619SDan Williams memdev->interleave_ways = 1; 9116bc75619SDan Williams 9126bc75619SDan Williams offset = offset + sizeof(struct acpi_nfit_memory_map) * 14; 9133b87356fSDan Williams /* dcr-descriptor0: blk */ 9146bc75619SDan Williams dcr = nfit_buf + offset; 9156bc75619SDan Williams dcr->header.type = ACPI_NFIT_TYPE_CONTROL_REGION; 9166bc75619SDan Williams dcr->header.length = sizeof(struct acpi_nfit_control_region); 9176bc75619SDan Williams dcr->region_index = 0+1; 9186bc75619SDan Williams dcr->vendor_id = 0xabcd; 9196bc75619SDan Williams dcr->device_id = 0; 9206bc75619SDan Williams dcr->revision_id = 1; 9216bc75619SDan Williams dcr->serial_number = ~handle[0]; 922be26f9aeSDan Williams dcr->code = NFIT_FIC_BLK; 9236bc75619SDan Williams dcr->windows = 1; 9246bc75619SDan Williams dcr->window_size = DCR_SIZE; 9256bc75619SDan Williams dcr->command_offset = 0; 9266bc75619SDan Williams dcr->command_size = 8; 9276bc75619SDan Williams dcr->status_offset = 8; 9286bc75619SDan Williams dcr->status_size = 4; 9296bc75619SDan Williams 9303b87356fSDan Williams /* dcr-descriptor1: blk */ 9316bc75619SDan Williams dcr = nfit_buf + offset + sizeof(struct acpi_nfit_control_region); 9326bc75619SDan Williams dcr->header.type = ACPI_NFIT_TYPE_CONTROL_REGION; 9336bc75619SDan Williams dcr->header.length = sizeof(struct acpi_nfit_control_region); 9346bc75619SDan Williams dcr->region_index = 1+1; 9356bc75619SDan Williams dcr->vendor_id = 0xabcd; 9366bc75619SDan Williams dcr->device_id = 0; 9376bc75619SDan Williams dcr->revision_id = 1; 9386bc75619SDan Williams dcr->serial_number = ~handle[1]; 939be26f9aeSDan Williams dcr->code = NFIT_FIC_BLK; 9406bc75619SDan Williams dcr->windows = 1; 9416bc75619SDan Williams dcr->window_size = DCR_SIZE; 9426bc75619SDan Williams dcr->command_offset = 0; 9436bc75619SDan Williams dcr->command_size = 8; 9446bc75619SDan Williams dcr->status_offset = 8; 9456bc75619SDan Williams dcr->status_size = 4; 9466bc75619SDan Williams 9473b87356fSDan Williams /* dcr-descriptor2: blk */ 9486bc75619SDan Williams dcr = nfit_buf + offset + sizeof(struct acpi_nfit_control_region) * 2; 9496bc75619SDan Williams dcr->header.type = ACPI_NFIT_TYPE_CONTROL_REGION; 9506bc75619SDan Williams dcr->header.length = sizeof(struct acpi_nfit_control_region); 9516bc75619SDan Williams dcr->region_index = 2+1; 9526bc75619SDan Williams dcr->vendor_id = 0xabcd; 9536bc75619SDan Williams dcr->device_id = 0; 9546bc75619SDan Williams dcr->revision_id = 1; 9556bc75619SDan Williams dcr->serial_number = ~handle[2]; 956be26f9aeSDan Williams dcr->code = NFIT_FIC_BLK; 9576bc75619SDan Williams dcr->windows = 1; 9586bc75619SDan Williams dcr->window_size = DCR_SIZE; 9596bc75619SDan Williams dcr->command_offset = 0; 9606bc75619SDan Williams dcr->command_size = 8; 9616bc75619SDan Williams dcr->status_offset = 8; 9626bc75619SDan Williams dcr->status_size = 4; 9636bc75619SDan Williams 9643b87356fSDan Williams /* dcr-descriptor3: blk */ 9656bc75619SDan Williams dcr = nfit_buf + offset + sizeof(struct acpi_nfit_control_region) * 3; 9666bc75619SDan Williams dcr->header.type = ACPI_NFIT_TYPE_CONTROL_REGION; 9676bc75619SDan Williams dcr->header.length = sizeof(struct acpi_nfit_control_region); 9686bc75619SDan Williams dcr->region_index = 3+1; 9696bc75619SDan Williams dcr->vendor_id = 0xabcd; 9706bc75619SDan Williams dcr->device_id = 0; 9716bc75619SDan Williams dcr->revision_id = 1; 9726bc75619SDan Williams dcr->serial_number = ~handle[3]; 973be26f9aeSDan Williams dcr->code = NFIT_FIC_BLK; 9746bc75619SDan Williams dcr->windows = 1; 9756bc75619SDan Williams dcr->window_size = DCR_SIZE; 9766bc75619SDan Williams dcr->command_offset = 0; 9776bc75619SDan Williams dcr->command_size = 8; 9786bc75619SDan Williams dcr->status_offset = 8; 9796bc75619SDan Williams dcr->status_size = 4; 9806bc75619SDan Williams 9816bc75619SDan Williams offset = offset + sizeof(struct acpi_nfit_control_region) * 4; 9823b87356fSDan Williams /* dcr-descriptor0: pmem */ 9833b87356fSDan Williams dcr = nfit_buf + offset; 9843b87356fSDan Williams dcr->header.type = ACPI_NFIT_TYPE_CONTROL_REGION; 9853b87356fSDan Williams dcr->header.length = offsetof(struct acpi_nfit_control_region, 9863b87356fSDan Williams window_size); 9873b87356fSDan Williams dcr->region_index = 4+1; 9883b87356fSDan Williams dcr->vendor_id = 0xabcd; 9893b87356fSDan Williams dcr->device_id = 0; 9903b87356fSDan Williams dcr->revision_id = 1; 9913b87356fSDan Williams dcr->serial_number = ~handle[0]; 9923b87356fSDan Williams dcr->code = NFIT_FIC_BYTEN; 9933b87356fSDan Williams dcr->windows = 0; 9943b87356fSDan Williams 9953b87356fSDan Williams /* dcr-descriptor1: pmem */ 9963b87356fSDan Williams dcr = nfit_buf + offset + offsetof(struct acpi_nfit_control_region, 9973b87356fSDan Williams window_size); 9983b87356fSDan Williams dcr->header.type = ACPI_NFIT_TYPE_CONTROL_REGION; 9993b87356fSDan Williams dcr->header.length = offsetof(struct acpi_nfit_control_region, 10003b87356fSDan Williams window_size); 10013b87356fSDan Williams dcr->region_index = 5+1; 10023b87356fSDan Williams dcr->vendor_id = 0xabcd; 10033b87356fSDan Williams dcr->device_id = 0; 10043b87356fSDan Williams dcr->revision_id = 1; 10053b87356fSDan Williams dcr->serial_number = ~handle[1]; 10063b87356fSDan Williams dcr->code = NFIT_FIC_BYTEN; 10073b87356fSDan Williams dcr->windows = 0; 10083b87356fSDan Williams 10093b87356fSDan Williams /* dcr-descriptor2: pmem */ 10103b87356fSDan Williams dcr = nfit_buf + offset + offsetof(struct acpi_nfit_control_region, 10113b87356fSDan Williams window_size) * 2; 10123b87356fSDan Williams dcr->header.type = ACPI_NFIT_TYPE_CONTROL_REGION; 10133b87356fSDan Williams dcr->header.length = offsetof(struct acpi_nfit_control_region, 10143b87356fSDan Williams window_size); 10153b87356fSDan Williams dcr->region_index = 6+1; 10163b87356fSDan Williams dcr->vendor_id = 0xabcd; 10173b87356fSDan Williams dcr->device_id = 0; 10183b87356fSDan Williams dcr->revision_id = 1; 10193b87356fSDan Williams dcr->serial_number = ~handle[2]; 10203b87356fSDan Williams dcr->code = NFIT_FIC_BYTEN; 10213b87356fSDan Williams dcr->windows = 0; 10223b87356fSDan Williams 10233b87356fSDan Williams /* dcr-descriptor3: pmem */ 10243b87356fSDan Williams dcr = nfit_buf + offset + offsetof(struct acpi_nfit_control_region, 10253b87356fSDan Williams window_size) * 3; 10263b87356fSDan Williams dcr->header.type = ACPI_NFIT_TYPE_CONTROL_REGION; 10273b87356fSDan Williams dcr->header.length = offsetof(struct acpi_nfit_control_region, 10283b87356fSDan Williams window_size); 10293b87356fSDan Williams dcr->region_index = 7+1; 10303b87356fSDan Williams dcr->vendor_id = 0xabcd; 10313b87356fSDan Williams dcr->device_id = 0; 10323b87356fSDan Williams dcr->revision_id = 1; 10333b87356fSDan Williams dcr->serial_number = ~handle[3]; 10343b87356fSDan Williams dcr->code = NFIT_FIC_BYTEN; 10353b87356fSDan Williams dcr->windows = 0; 10363b87356fSDan Williams 10373b87356fSDan Williams offset = offset + offsetof(struct acpi_nfit_control_region, 10383b87356fSDan Williams window_size) * 4; 10396bc75619SDan Williams /* bdw0 (spa/dcr0, dimm0) */ 10406bc75619SDan Williams bdw = nfit_buf + offset; 10416bc75619SDan Williams bdw->header.type = ACPI_NFIT_TYPE_DATA_REGION; 10426bc75619SDan Williams bdw->header.length = sizeof(struct acpi_nfit_data_region); 10436bc75619SDan Williams bdw->region_index = 0+1; 10446bc75619SDan Williams bdw->windows = 1; 10456bc75619SDan Williams bdw->offset = 0; 10466bc75619SDan Williams bdw->size = BDW_SIZE; 10476bc75619SDan Williams bdw->capacity = DIMM_SIZE; 10486bc75619SDan Williams bdw->start_address = 0; 10496bc75619SDan Williams 10506bc75619SDan Williams /* bdw1 (spa/dcr1, dimm1) */ 10516bc75619SDan Williams bdw = nfit_buf + offset + sizeof(struct acpi_nfit_data_region); 10526bc75619SDan Williams bdw->header.type = ACPI_NFIT_TYPE_DATA_REGION; 10536bc75619SDan Williams bdw->header.length = sizeof(struct acpi_nfit_data_region); 10546bc75619SDan Williams bdw->region_index = 1+1; 10556bc75619SDan Williams bdw->windows = 1; 10566bc75619SDan Williams bdw->offset = 0; 10576bc75619SDan Williams bdw->size = BDW_SIZE; 10586bc75619SDan Williams bdw->capacity = DIMM_SIZE; 10596bc75619SDan Williams bdw->start_address = 0; 10606bc75619SDan Williams 10616bc75619SDan Williams /* bdw2 (spa/dcr2, dimm2) */ 10626bc75619SDan Williams bdw = nfit_buf + offset + sizeof(struct acpi_nfit_data_region) * 2; 10636bc75619SDan Williams bdw->header.type = ACPI_NFIT_TYPE_DATA_REGION; 10646bc75619SDan Williams bdw->header.length = sizeof(struct acpi_nfit_data_region); 10656bc75619SDan Williams bdw->region_index = 2+1; 10666bc75619SDan Williams bdw->windows = 1; 10676bc75619SDan Williams bdw->offset = 0; 10686bc75619SDan Williams bdw->size = BDW_SIZE; 10696bc75619SDan Williams bdw->capacity = DIMM_SIZE; 10706bc75619SDan Williams bdw->start_address = 0; 10716bc75619SDan Williams 10726bc75619SDan Williams /* bdw3 (spa/dcr3, dimm3) */ 10736bc75619SDan Williams bdw = nfit_buf + offset + sizeof(struct acpi_nfit_data_region) * 3; 10746bc75619SDan Williams bdw->header.type = ACPI_NFIT_TYPE_DATA_REGION; 10756bc75619SDan Williams bdw->header.length = sizeof(struct acpi_nfit_data_region); 10766bc75619SDan Williams bdw->region_index = 3+1; 10776bc75619SDan Williams bdw->windows = 1; 10786bc75619SDan Williams bdw->offset = 0; 10796bc75619SDan Williams bdw->size = BDW_SIZE; 10806bc75619SDan Williams bdw->capacity = DIMM_SIZE; 10816bc75619SDan Williams bdw->start_address = 0; 10826bc75619SDan Williams 10839d27a87eSDan Williams offset = offset + sizeof(struct acpi_nfit_data_region) * 4; 10849d27a87eSDan Williams /* flush0 (dimm0) */ 10859d27a87eSDan Williams flush = nfit_buf + offset; 10869d27a87eSDan Williams flush->header.type = ACPI_NFIT_TYPE_FLUSH_ADDRESS; 10879d27a87eSDan Williams flush->header.length = sizeof(struct acpi_nfit_flush_address); 10889d27a87eSDan Williams flush->device_handle = handle[0]; 10899d27a87eSDan Williams flush->hint_count = 1; 10909d27a87eSDan Williams flush->hint_address[0] = t->flush_dma[0]; 10919d27a87eSDan Williams 10929d27a87eSDan Williams /* flush1 (dimm1) */ 10939d27a87eSDan Williams flush = nfit_buf + offset + sizeof(struct acpi_nfit_flush_address) * 1; 10949d27a87eSDan Williams flush->header.type = ACPI_NFIT_TYPE_FLUSH_ADDRESS; 10959d27a87eSDan Williams flush->header.length = sizeof(struct acpi_nfit_flush_address); 10969d27a87eSDan Williams flush->device_handle = handle[1]; 10979d27a87eSDan Williams flush->hint_count = 1; 10989d27a87eSDan Williams flush->hint_address[0] = t->flush_dma[1]; 10999d27a87eSDan Williams 11009d27a87eSDan Williams /* flush2 (dimm2) */ 11019d27a87eSDan Williams flush = nfit_buf + offset + sizeof(struct acpi_nfit_flush_address) * 2; 11029d27a87eSDan Williams flush->header.type = ACPI_NFIT_TYPE_FLUSH_ADDRESS; 11039d27a87eSDan Williams flush->header.length = sizeof(struct acpi_nfit_flush_address); 11049d27a87eSDan Williams flush->device_handle = handle[2]; 11059d27a87eSDan Williams flush->hint_count = 1; 11069d27a87eSDan Williams flush->hint_address[0] = t->flush_dma[2]; 11079d27a87eSDan Williams 11089d27a87eSDan Williams /* flush3 (dimm3) */ 11099d27a87eSDan Williams flush = nfit_buf + offset + sizeof(struct acpi_nfit_flush_address) * 3; 11109d27a87eSDan Williams flush->header.type = ACPI_NFIT_TYPE_FLUSH_ADDRESS; 11119d27a87eSDan Williams flush->header.length = sizeof(struct acpi_nfit_flush_address); 11129d27a87eSDan Williams flush->device_handle = handle[3]; 11139d27a87eSDan Williams flush->hint_count = 1; 11149d27a87eSDan Williams flush->hint_address[0] = t->flush_dma[3]; 11159d27a87eSDan Williams 111620985164SVishal Verma if (t->setup_hotplug) { 111720985164SVishal Verma offset = offset + sizeof(struct acpi_nfit_flush_address) * 4; 11183b87356fSDan Williams /* dcr-descriptor4: blk */ 111920985164SVishal Verma dcr = nfit_buf + offset; 112020985164SVishal Verma dcr->header.type = ACPI_NFIT_TYPE_CONTROL_REGION; 112120985164SVishal Verma dcr->header.length = sizeof(struct acpi_nfit_control_region); 11223b87356fSDan Williams dcr->region_index = 8+1; 112320985164SVishal Verma dcr->vendor_id = 0xabcd; 112420985164SVishal Verma dcr->device_id = 0; 112520985164SVishal Verma dcr->revision_id = 1; 112620985164SVishal Verma dcr->serial_number = ~handle[4]; 1127be26f9aeSDan Williams dcr->code = NFIT_FIC_BLK; 112820985164SVishal Verma dcr->windows = 1; 112920985164SVishal Verma dcr->window_size = DCR_SIZE; 113020985164SVishal Verma dcr->command_offset = 0; 113120985164SVishal Verma dcr->command_size = 8; 113220985164SVishal Verma dcr->status_offset = 8; 113320985164SVishal Verma dcr->status_size = 4; 113420985164SVishal Verma 113520985164SVishal Verma offset = offset + sizeof(struct acpi_nfit_control_region); 11363b87356fSDan Williams /* dcr-descriptor4: pmem */ 11373b87356fSDan Williams dcr = nfit_buf + offset; 11383b87356fSDan Williams dcr->header.type = ACPI_NFIT_TYPE_CONTROL_REGION; 11393b87356fSDan Williams dcr->header.length = offsetof(struct acpi_nfit_control_region, 11403b87356fSDan Williams window_size); 11413b87356fSDan Williams dcr->region_index = 9+1; 11423b87356fSDan Williams dcr->vendor_id = 0xabcd; 11433b87356fSDan Williams dcr->device_id = 0; 11443b87356fSDan Williams dcr->revision_id = 1; 11453b87356fSDan Williams dcr->serial_number = ~handle[4]; 11463b87356fSDan Williams dcr->code = NFIT_FIC_BYTEN; 11473b87356fSDan Williams dcr->windows = 0; 11483b87356fSDan Williams 11493b87356fSDan Williams offset = offset + offsetof(struct acpi_nfit_control_region, 11503b87356fSDan Williams window_size); 115120985164SVishal Verma /* bdw4 (spa/dcr4, dimm4) */ 115220985164SVishal Verma bdw = nfit_buf + offset; 115320985164SVishal Verma bdw->header.type = ACPI_NFIT_TYPE_DATA_REGION; 115420985164SVishal Verma bdw->header.length = sizeof(struct acpi_nfit_data_region); 11553b87356fSDan Williams bdw->region_index = 8+1; 115620985164SVishal Verma bdw->windows = 1; 115720985164SVishal Verma bdw->offset = 0; 115820985164SVishal Verma bdw->size = BDW_SIZE; 115920985164SVishal Verma bdw->capacity = DIMM_SIZE; 116020985164SVishal Verma bdw->start_address = 0; 116120985164SVishal Verma 116220985164SVishal Verma offset = offset + sizeof(struct acpi_nfit_data_region); 116320985164SVishal Verma /* spa10 (dcr4) dimm4 */ 116420985164SVishal Verma spa = nfit_buf + offset; 116520985164SVishal Verma spa->header.type = ACPI_NFIT_TYPE_SYSTEM_ADDRESS; 116620985164SVishal Verma spa->header.length = sizeof(*spa); 116720985164SVishal Verma memcpy(spa->range_guid, to_nfit_uuid(NFIT_SPA_DCR), 16); 116820985164SVishal Verma spa->range_index = 10+1; 116920985164SVishal Verma spa->address = t->dcr_dma[4]; 117020985164SVishal Verma spa->length = DCR_SIZE; 117120985164SVishal Verma 117220985164SVishal Verma /* 117320985164SVishal Verma * spa11 (single-dimm interleave for hotplug, note storage 117420985164SVishal Verma * does not actually alias the related block-data-window 117520985164SVishal Verma * regions) 117620985164SVishal Verma */ 117720985164SVishal Verma spa = nfit_buf + offset + sizeof(*spa); 117820985164SVishal Verma spa->header.type = ACPI_NFIT_TYPE_SYSTEM_ADDRESS; 117920985164SVishal Verma spa->header.length = sizeof(*spa); 118020985164SVishal Verma memcpy(spa->range_guid, to_nfit_uuid(NFIT_SPA_PM), 16); 118120985164SVishal Verma spa->range_index = 11+1; 118220985164SVishal Verma spa->address = t->spa_set_dma[2]; 118320985164SVishal Verma spa->length = SPA0_SIZE; 118420985164SVishal Verma 118520985164SVishal Verma /* spa12 (bdw for dcr4) dimm4 */ 118620985164SVishal Verma spa = nfit_buf + offset + sizeof(*spa) * 2; 118720985164SVishal Verma spa->header.type = ACPI_NFIT_TYPE_SYSTEM_ADDRESS; 118820985164SVishal Verma spa->header.length = sizeof(*spa); 118920985164SVishal Verma memcpy(spa->range_guid, to_nfit_uuid(NFIT_SPA_BDW), 16); 119020985164SVishal Verma spa->range_index = 12+1; 119120985164SVishal Verma spa->address = t->dimm_dma[4]; 119220985164SVishal Verma spa->length = DIMM_SIZE; 119320985164SVishal Verma 119420985164SVishal Verma offset = offset + sizeof(*spa) * 3; 119520985164SVishal Verma /* mem-region14 (spa/dcr4, dimm4) */ 119620985164SVishal Verma memdev = nfit_buf + offset; 119720985164SVishal Verma memdev->header.type = ACPI_NFIT_TYPE_MEMORY_MAP; 119820985164SVishal Verma memdev->header.length = sizeof(*memdev); 119920985164SVishal Verma memdev->device_handle = handle[4]; 120020985164SVishal Verma memdev->physical_id = 4; 120120985164SVishal Verma memdev->region_id = 0; 120220985164SVishal Verma memdev->range_index = 10+1; 12033b87356fSDan Williams memdev->region_index = 8+1; 120420985164SVishal Verma memdev->region_size = 0; 120520985164SVishal Verma memdev->region_offset = 0; 120620985164SVishal Verma memdev->address = 0; 120720985164SVishal Verma memdev->interleave_index = 0; 120820985164SVishal Verma memdev->interleave_ways = 1; 120920985164SVishal Verma 121020985164SVishal Verma /* mem-region15 (spa0, dimm4) */ 121120985164SVishal Verma memdev = nfit_buf + offset + 121220985164SVishal Verma sizeof(struct acpi_nfit_memory_map); 121320985164SVishal Verma memdev->header.type = ACPI_NFIT_TYPE_MEMORY_MAP; 121420985164SVishal Verma memdev->header.length = sizeof(*memdev); 121520985164SVishal Verma memdev->device_handle = handle[4]; 121620985164SVishal Verma memdev->physical_id = 4; 121720985164SVishal Verma memdev->region_id = 0; 121820985164SVishal Verma memdev->range_index = 11+1; 12193b87356fSDan Williams memdev->region_index = 9+1; 122020985164SVishal Verma memdev->region_size = SPA0_SIZE; 122120985164SVishal Verma memdev->region_offset = t->spa_set_dma[2]; 122220985164SVishal Verma memdev->address = 0; 122320985164SVishal Verma memdev->interleave_index = 0; 122420985164SVishal Verma memdev->interleave_ways = 1; 122520985164SVishal Verma 12263b87356fSDan Williams /* mem-region16 (spa/bdw4, dimm4) */ 122720985164SVishal Verma memdev = nfit_buf + offset + 122820985164SVishal Verma sizeof(struct acpi_nfit_memory_map) * 2; 122920985164SVishal Verma memdev->header.type = ACPI_NFIT_TYPE_MEMORY_MAP; 123020985164SVishal Verma memdev->header.length = sizeof(*memdev); 123120985164SVishal Verma memdev->device_handle = handle[4]; 123220985164SVishal Verma memdev->physical_id = 4; 123320985164SVishal Verma memdev->region_id = 0; 123420985164SVishal Verma memdev->range_index = 12+1; 12353b87356fSDan Williams memdev->region_index = 8+1; 123620985164SVishal Verma memdev->region_size = 0; 123720985164SVishal Verma memdev->region_offset = 0; 123820985164SVishal Verma memdev->address = 0; 123920985164SVishal Verma memdev->interleave_index = 0; 124020985164SVishal Verma memdev->interleave_ways = 1; 124120985164SVishal Verma 124220985164SVishal Verma offset = offset + sizeof(struct acpi_nfit_memory_map) * 3; 124320985164SVishal Verma /* flush3 (dimm4) */ 124420985164SVishal Verma flush = nfit_buf + offset; 124520985164SVishal Verma flush->header.type = ACPI_NFIT_TYPE_FLUSH_ADDRESS; 124620985164SVishal Verma flush->header.length = sizeof(struct acpi_nfit_flush_address); 124720985164SVishal Verma flush->device_handle = handle[4]; 124820985164SVishal Verma flush->hint_count = 1; 124920985164SVishal Verma flush->hint_address[0] = t->flush_dma[4]; 125020985164SVishal Verma } 125120985164SVishal Verma 1252f471f1a7SDan Williams post_ars_status(&t->ars_state, t->spa_set_dma[0], SPA0_SIZE); 1253f471f1a7SDan Williams 12546bc75619SDan Williams acpi_desc = &t->acpi_desc; 1255*e3654ecaSDan Williams set_bit(ND_CMD_GET_CONFIG_SIZE, &acpi_desc->dimm_cmd_force_en); 1256*e3654ecaSDan Williams set_bit(ND_CMD_GET_CONFIG_DATA, &acpi_desc->dimm_cmd_force_en); 1257*e3654ecaSDan Williams set_bit(ND_CMD_SET_CONFIG_DATA, &acpi_desc->dimm_cmd_force_en); 1258*e3654ecaSDan Williams set_bit(ND_CMD_ARS_CAP, &acpi_desc->bus_cmd_force_en); 1259*e3654ecaSDan Williams set_bit(ND_CMD_ARS_START, &acpi_desc->bus_cmd_force_en); 1260*e3654ecaSDan Williams set_bit(ND_CMD_ARS_STATUS, &acpi_desc->bus_cmd_force_en); 1261*e3654ecaSDan Williams set_bit(ND_CMD_CLEAR_ERROR, &acpi_desc->bus_cmd_force_en); 12626bc75619SDan Williams } 12636bc75619SDan Williams 12646bc75619SDan Williams static void nfit_test1_setup(struct nfit_test *t) 12656bc75619SDan Williams { 12666b577c9dSLinda Knippers size_t offset; 12676bc75619SDan Williams void *nfit_buf = t->nfit_buf; 12686bc75619SDan Williams struct acpi_nfit_memory_map *memdev; 12696bc75619SDan Williams struct acpi_nfit_control_region *dcr; 12706bc75619SDan Williams struct acpi_nfit_system_address *spa; 1271d26f73f0SDan Williams struct acpi_nfit_desc *acpi_desc; 12726bc75619SDan Williams 12736b577c9dSLinda Knippers offset = 0; 12746bc75619SDan Williams /* spa0 (flat range with no bdw aliasing) */ 12756bc75619SDan Williams spa = nfit_buf + offset; 12766bc75619SDan Williams spa->header.type = ACPI_NFIT_TYPE_SYSTEM_ADDRESS; 12776bc75619SDan Williams spa->header.length = sizeof(*spa); 12786bc75619SDan Williams memcpy(spa->range_guid, to_nfit_uuid(NFIT_SPA_PM), 16); 12796bc75619SDan Williams spa->range_index = 0+1; 12806bc75619SDan Williams spa->address = t->spa_set_dma[0]; 12816bc75619SDan Williams spa->length = SPA2_SIZE; 12826bc75619SDan Williams 12836bc75619SDan Williams offset += sizeof(*spa); 12846bc75619SDan Williams /* mem-region0 (spa0, dimm0) */ 12856bc75619SDan Williams memdev = nfit_buf + offset; 12866bc75619SDan Williams memdev->header.type = ACPI_NFIT_TYPE_MEMORY_MAP; 12876bc75619SDan Williams memdev->header.length = sizeof(*memdev); 12886bc75619SDan Williams memdev->device_handle = 0; 12896bc75619SDan Williams memdev->physical_id = 0; 12906bc75619SDan Williams memdev->region_id = 0; 12916bc75619SDan Williams memdev->range_index = 0+1; 12926bc75619SDan Williams memdev->region_index = 0+1; 12936bc75619SDan Williams memdev->region_size = SPA2_SIZE; 12946bc75619SDan Williams memdev->region_offset = 0; 12956bc75619SDan Williams memdev->address = 0; 12966bc75619SDan Williams memdev->interleave_index = 0; 12976bc75619SDan Williams memdev->interleave_ways = 1; 129858138820SDan Williams memdev->flags = ACPI_NFIT_MEM_SAVE_FAILED | ACPI_NFIT_MEM_RESTORE_FAILED 129958138820SDan Williams | ACPI_NFIT_MEM_FLUSH_FAILED | ACPI_NFIT_MEM_HEALTH_OBSERVED 1300f4295796SDan Williams | ACPI_NFIT_MEM_NOT_ARMED; 13016bc75619SDan Williams 13026bc75619SDan Williams offset += sizeof(*memdev); 13036bc75619SDan Williams /* dcr-descriptor0 */ 13046bc75619SDan Williams dcr = nfit_buf + offset; 13056bc75619SDan Williams dcr->header.type = ACPI_NFIT_TYPE_CONTROL_REGION; 13063b87356fSDan Williams dcr->header.length = offsetof(struct acpi_nfit_control_region, 13073b87356fSDan Williams window_size); 13086bc75619SDan Williams dcr->region_index = 0+1; 13096bc75619SDan Williams dcr->vendor_id = 0xabcd; 13106bc75619SDan Williams dcr->device_id = 0; 13116bc75619SDan Williams dcr->revision_id = 1; 13126bc75619SDan Williams dcr->serial_number = ~0; 1313be26f9aeSDan Williams dcr->code = NFIT_FIC_BYTE; 13146bc75619SDan Williams dcr->windows = 0; 1315d26f73f0SDan Williams 1316f471f1a7SDan Williams post_ars_status(&t->ars_state, t->spa_set_dma[0], SPA2_SIZE); 1317f471f1a7SDan Williams 1318d26f73f0SDan Williams acpi_desc = &t->acpi_desc; 1319*e3654ecaSDan Williams set_bit(ND_CMD_ARS_CAP, &acpi_desc->bus_cmd_force_en); 1320*e3654ecaSDan Williams set_bit(ND_CMD_ARS_START, &acpi_desc->bus_cmd_force_en); 1321*e3654ecaSDan Williams set_bit(ND_CMD_ARS_STATUS, &acpi_desc->bus_cmd_force_en); 1322*e3654ecaSDan Williams set_bit(ND_CMD_CLEAR_ERROR, &acpi_desc->bus_cmd_force_en); 13236bc75619SDan Williams } 13246bc75619SDan Williams 13256bc75619SDan Williams static int nfit_test_blk_do_io(struct nd_blk_region *ndbr, resource_size_t dpa, 13266bc75619SDan Williams void *iobuf, u64 len, int rw) 13276bc75619SDan Williams { 13286bc75619SDan Williams struct nfit_blk *nfit_blk = ndbr->blk_provider_data; 13296bc75619SDan Williams struct nfit_blk_mmio *mmio = &nfit_blk->mmio[BDW]; 13306bc75619SDan Williams struct nd_region *nd_region = &ndbr->nd_region; 13316bc75619SDan Williams unsigned int lane; 13326bc75619SDan Williams 13336bc75619SDan Williams lane = nd_region_acquire_lane(nd_region); 13346bc75619SDan Williams if (rw) 133567a3e8feSRoss Zwisler memcpy(mmio->addr.base + dpa, iobuf, len); 133667a3e8feSRoss Zwisler else { 133767a3e8feSRoss Zwisler memcpy(iobuf, mmio->addr.base + dpa, len); 133867a3e8feSRoss Zwisler 133967a3e8feSRoss Zwisler /* give us some some coverage of the mmio_flush_range() API */ 134067a3e8feSRoss Zwisler mmio_flush_range(mmio->addr.base + dpa, len); 134167a3e8feSRoss Zwisler } 13426bc75619SDan Williams nd_region_release_lane(nd_region, lane); 13436bc75619SDan Williams 13446bc75619SDan Williams return 0; 13456bc75619SDan Williams } 13466bc75619SDan Williams 13476bc75619SDan Williams static int nfit_test_probe(struct platform_device *pdev) 13486bc75619SDan Williams { 13496bc75619SDan Williams struct nvdimm_bus_descriptor *nd_desc; 13506bc75619SDan Williams struct acpi_nfit_desc *acpi_desc; 13516bc75619SDan Williams struct device *dev = &pdev->dev; 13526bc75619SDan Williams struct nfit_test *nfit_test; 13536bc75619SDan Williams int rc; 13546bc75619SDan Williams 13556bc75619SDan Williams nfit_test = to_nfit_test(&pdev->dev); 13566bc75619SDan Williams 13576bc75619SDan Williams /* common alloc */ 13586bc75619SDan Williams if (nfit_test->num_dcr) { 13596bc75619SDan Williams int num = nfit_test->num_dcr; 13606bc75619SDan Williams 13616bc75619SDan Williams nfit_test->dimm = devm_kcalloc(dev, num, sizeof(void *), 13626bc75619SDan Williams GFP_KERNEL); 13636bc75619SDan Williams nfit_test->dimm_dma = devm_kcalloc(dev, num, sizeof(dma_addr_t), 13646bc75619SDan Williams GFP_KERNEL); 13659d27a87eSDan Williams nfit_test->flush = devm_kcalloc(dev, num, sizeof(void *), 13669d27a87eSDan Williams GFP_KERNEL); 13679d27a87eSDan Williams nfit_test->flush_dma = devm_kcalloc(dev, num, sizeof(dma_addr_t), 13689d27a87eSDan Williams GFP_KERNEL); 13696bc75619SDan Williams nfit_test->label = devm_kcalloc(dev, num, sizeof(void *), 13706bc75619SDan Williams GFP_KERNEL); 13716bc75619SDan Williams nfit_test->label_dma = devm_kcalloc(dev, num, 13726bc75619SDan Williams sizeof(dma_addr_t), GFP_KERNEL); 13736bc75619SDan Williams nfit_test->dcr = devm_kcalloc(dev, num, 13746bc75619SDan Williams sizeof(struct nfit_test_dcr *), GFP_KERNEL); 13756bc75619SDan Williams nfit_test->dcr_dma = devm_kcalloc(dev, num, 13766bc75619SDan Williams sizeof(dma_addr_t), GFP_KERNEL); 13776bc75619SDan Williams if (nfit_test->dimm && nfit_test->dimm_dma && nfit_test->label 13786bc75619SDan Williams && nfit_test->label_dma && nfit_test->dcr 13799d27a87eSDan Williams && nfit_test->dcr_dma && nfit_test->flush 13809d27a87eSDan Williams && nfit_test->flush_dma) 13816bc75619SDan Williams /* pass */; 13826bc75619SDan Williams else 13836bc75619SDan Williams return -ENOMEM; 13846bc75619SDan Williams } 13856bc75619SDan Williams 13866bc75619SDan Williams if (nfit_test->num_pm) { 13876bc75619SDan Williams int num = nfit_test->num_pm; 13886bc75619SDan Williams 13896bc75619SDan Williams nfit_test->spa_set = devm_kcalloc(dev, num, sizeof(void *), 13906bc75619SDan Williams GFP_KERNEL); 13916bc75619SDan Williams nfit_test->spa_set_dma = devm_kcalloc(dev, num, 13926bc75619SDan Williams sizeof(dma_addr_t), GFP_KERNEL); 13936bc75619SDan Williams if (nfit_test->spa_set && nfit_test->spa_set_dma) 13946bc75619SDan Williams /* pass */; 13956bc75619SDan Williams else 13966bc75619SDan Williams return -ENOMEM; 13976bc75619SDan Williams } 13986bc75619SDan Williams 13996bc75619SDan Williams /* per-nfit specific alloc */ 14006bc75619SDan Williams if (nfit_test->alloc(nfit_test)) 14016bc75619SDan Williams return -ENOMEM; 14026bc75619SDan Williams 14036bc75619SDan Williams nfit_test->setup(nfit_test); 14046bc75619SDan Williams acpi_desc = &nfit_test->acpi_desc; 1405a61fe6f7SDan Williams acpi_nfit_desc_init(acpi_desc, &pdev->dev); 14066bc75619SDan Williams acpi_desc->nfit = nfit_test->nfit_buf; 14076bc75619SDan Williams acpi_desc->blk_do_io = nfit_test_blk_do_io; 14086bc75619SDan Williams nd_desc = &acpi_desc->nd_desc; 1409a61fe6f7SDan Williams nd_desc->provider_name = NULL; 1410a61fe6f7SDan Williams nd_desc->ndctl = nfit_test_ctl; 14116bc75619SDan Williams acpi_desc->nvdimm_bus = nvdimm_bus_register(&pdev->dev, nd_desc); 14126bc75619SDan Williams if (!acpi_desc->nvdimm_bus) 14136bc75619SDan Williams return -ENXIO; 14146bc75619SDan Williams 141520985164SVishal Verma rc = acpi_nfit_init(acpi_desc, nfit_test->nfit_size); 141620985164SVishal Verma if (rc) { 141720985164SVishal Verma nvdimm_bus_unregister(acpi_desc->nvdimm_bus); 141820985164SVishal Verma return rc; 141920985164SVishal Verma } 142020985164SVishal Verma 142120985164SVishal Verma if (nfit_test->setup != nfit_test0_setup) 142220985164SVishal Verma return 0; 142320985164SVishal Verma 142420985164SVishal Verma nfit_test->setup_hotplug = 1; 142520985164SVishal Verma nfit_test->setup(nfit_test); 142620985164SVishal Verma 14276bc75619SDan Williams rc = acpi_nfit_init(acpi_desc, nfit_test->nfit_size); 14286bc75619SDan Williams if (rc) { 14296bc75619SDan Williams nvdimm_bus_unregister(acpi_desc->nvdimm_bus); 14306bc75619SDan Williams return rc; 14316bc75619SDan Williams } 14326bc75619SDan Williams 14336bc75619SDan Williams return 0; 14346bc75619SDan Williams } 14356bc75619SDan Williams 14366bc75619SDan Williams static int nfit_test_remove(struct platform_device *pdev) 14376bc75619SDan Williams { 14386bc75619SDan Williams struct nfit_test *nfit_test = to_nfit_test(&pdev->dev); 14396bc75619SDan Williams struct acpi_nfit_desc *acpi_desc = &nfit_test->acpi_desc; 14406bc75619SDan Williams 14416bc75619SDan Williams nvdimm_bus_unregister(acpi_desc->nvdimm_bus); 14426bc75619SDan Williams 14436bc75619SDan Williams return 0; 14446bc75619SDan Williams } 14456bc75619SDan Williams 14466bc75619SDan Williams static void nfit_test_release(struct device *dev) 14476bc75619SDan Williams { 14486bc75619SDan Williams struct nfit_test *nfit_test = to_nfit_test(dev); 14496bc75619SDan Williams 14506bc75619SDan Williams kfree(nfit_test); 14516bc75619SDan Williams } 14526bc75619SDan Williams 14536bc75619SDan Williams static const struct platform_device_id nfit_test_id[] = { 14546bc75619SDan Williams { KBUILD_MODNAME }, 14556bc75619SDan Williams { }, 14566bc75619SDan Williams }; 14576bc75619SDan Williams 14586bc75619SDan Williams static struct platform_driver nfit_test_driver = { 14596bc75619SDan Williams .probe = nfit_test_probe, 14606bc75619SDan Williams .remove = nfit_test_remove, 14616bc75619SDan Williams .driver = { 14626bc75619SDan Williams .name = KBUILD_MODNAME, 14636bc75619SDan Williams }, 14646bc75619SDan Williams .id_table = nfit_test_id, 14656bc75619SDan Williams }; 14666bc75619SDan Williams 14676bc75619SDan Williams #ifdef CONFIG_CMA_SIZE_MBYTES 14686bc75619SDan Williams #define CMA_SIZE_MBYTES CONFIG_CMA_SIZE_MBYTES 14696bc75619SDan Williams #else 14706bc75619SDan Williams #define CMA_SIZE_MBYTES 0 14716bc75619SDan Williams #endif 14726bc75619SDan Williams 14736bc75619SDan Williams static __init int nfit_test_init(void) 14746bc75619SDan Williams { 14756bc75619SDan Williams int rc, i; 14766bc75619SDan Williams 14776bc75619SDan Williams nfit_test_setup(nfit_test_lookup); 14786bc75619SDan Williams 14796bc75619SDan Williams for (i = 0; i < NUM_NFITS; i++) { 14806bc75619SDan Williams struct nfit_test *nfit_test; 14816bc75619SDan Williams struct platform_device *pdev; 14826bc75619SDan Williams static int once; 14836bc75619SDan Williams 14846bc75619SDan Williams nfit_test = kzalloc(sizeof(*nfit_test), GFP_KERNEL); 14856bc75619SDan Williams if (!nfit_test) { 14866bc75619SDan Williams rc = -ENOMEM; 14876bc75619SDan Williams goto err_register; 14886bc75619SDan Williams } 14896bc75619SDan Williams INIT_LIST_HEAD(&nfit_test->resources); 14906bc75619SDan Williams switch (i) { 14916bc75619SDan Williams case 0: 14926bc75619SDan Williams nfit_test->num_pm = NUM_PM; 14936bc75619SDan Williams nfit_test->num_dcr = NUM_DCR; 14946bc75619SDan Williams nfit_test->alloc = nfit_test0_alloc; 14956bc75619SDan Williams nfit_test->setup = nfit_test0_setup; 14966bc75619SDan Williams break; 14976bc75619SDan Williams case 1: 14986bc75619SDan Williams nfit_test->num_pm = 1; 14996bc75619SDan Williams nfit_test->alloc = nfit_test1_alloc; 15006bc75619SDan Williams nfit_test->setup = nfit_test1_setup; 15016bc75619SDan Williams break; 15026bc75619SDan Williams default: 15036bc75619SDan Williams rc = -EINVAL; 15046bc75619SDan Williams goto err_register; 15056bc75619SDan Williams } 15066bc75619SDan Williams pdev = &nfit_test->pdev; 15076bc75619SDan Williams pdev->name = KBUILD_MODNAME; 15086bc75619SDan Williams pdev->id = i; 15096bc75619SDan Williams pdev->dev.release = nfit_test_release; 15106bc75619SDan Williams rc = platform_device_register(pdev); 15116bc75619SDan Williams if (rc) { 15126bc75619SDan Williams put_device(&pdev->dev); 15136bc75619SDan Williams goto err_register; 15146bc75619SDan Williams } 15156bc75619SDan Williams 15166bc75619SDan Williams rc = dma_coerce_mask_and_coherent(&pdev->dev, DMA_BIT_MASK(64)); 15176bc75619SDan Williams if (rc) 15186bc75619SDan Williams goto err_register; 15196bc75619SDan Williams 15206bc75619SDan Williams instances[i] = nfit_test; 15216bc75619SDan Williams 15226bc75619SDan Williams if (!once++) { 15236bc75619SDan Williams dma_addr_t dma; 15246bc75619SDan Williams void *buf; 15256bc75619SDan Williams 15266bc75619SDan Williams buf = dma_alloc_coherent(&pdev->dev, SZ_128M, &dma, 15276bc75619SDan Williams GFP_KERNEL); 15286bc75619SDan Williams if (!buf) { 15296bc75619SDan Williams rc = -ENOMEM; 15306bc75619SDan Williams dev_warn(&pdev->dev, "need 128M of free cma\n"); 15316bc75619SDan Williams goto err_register; 15326bc75619SDan Williams } 15336bc75619SDan Williams dma_free_coherent(&pdev->dev, SZ_128M, buf, dma); 15346bc75619SDan Williams } 15356bc75619SDan Williams } 15366bc75619SDan Williams 15376bc75619SDan Williams rc = platform_driver_register(&nfit_test_driver); 15386bc75619SDan Williams if (rc) 15396bc75619SDan Williams goto err_register; 15406bc75619SDan Williams return 0; 15416bc75619SDan Williams 15426bc75619SDan Williams err_register: 15436bc75619SDan Williams for (i = 0; i < NUM_NFITS; i++) 15446bc75619SDan Williams if (instances[i]) 15456bc75619SDan Williams platform_device_unregister(&instances[i]->pdev); 15466bc75619SDan Williams nfit_test_teardown(); 15476bc75619SDan Williams return rc; 15486bc75619SDan Williams } 15496bc75619SDan Williams 15506bc75619SDan Williams static __exit void nfit_test_exit(void) 15516bc75619SDan Williams { 15526bc75619SDan Williams int i; 15536bc75619SDan Williams 15546bc75619SDan Williams platform_driver_unregister(&nfit_test_driver); 15556bc75619SDan Williams for (i = 0; i < NUM_NFITS; i++) 15566bc75619SDan Williams platform_device_unregister(&instances[i]->pdev); 15576bc75619SDan Williams nfit_test_teardown(); 15586bc75619SDan Williams } 15596bc75619SDan Williams 15606bc75619SDan Williams module_init(nfit_test_init); 15616bc75619SDan Williams module_exit(nfit_test_exit); 15626bc75619SDan Williams MODULE_LICENSE("GPL v2"); 15636bc75619SDan Williams MODULE_AUTHOR("Intel Corporation"); 1564