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; 1546bc75619SDan Williams }; 1556bc75619SDan Williams 1566bc75619SDan Williams static struct nfit_test *to_nfit_test(struct device *dev) 1576bc75619SDan Williams { 1586bc75619SDan Williams struct platform_device *pdev = to_platform_device(dev); 1596bc75619SDan Williams 1606bc75619SDan Williams return container_of(pdev, struct nfit_test, pdev); 1616bc75619SDan Williams } 1626bc75619SDan Williams 16339c686b8SVishal Verma static int nfit_test_cmd_get_config_size(struct nd_cmd_get_config_size *nd_cmd, 1646bc75619SDan Williams unsigned int buf_len) 1656bc75619SDan Williams { 1666bc75619SDan Williams if (buf_len < sizeof(*nd_cmd)) 1676bc75619SDan Williams return -EINVAL; 16839c686b8SVishal Verma 1696bc75619SDan Williams nd_cmd->status = 0; 1706bc75619SDan Williams nd_cmd->config_size = LABEL_SIZE; 1716bc75619SDan Williams nd_cmd->max_xfer = SZ_4K; 17239c686b8SVishal Verma 17339c686b8SVishal Verma return 0; 1746bc75619SDan Williams } 17539c686b8SVishal Verma 17639c686b8SVishal Verma static int nfit_test_cmd_get_config_data(struct nd_cmd_get_config_data_hdr 17739c686b8SVishal Verma *nd_cmd, unsigned int buf_len, void *label) 17839c686b8SVishal Verma { 1796bc75619SDan Williams unsigned int len, offset = nd_cmd->in_offset; 18039c686b8SVishal Verma int rc; 1816bc75619SDan Williams 1826bc75619SDan Williams if (buf_len < sizeof(*nd_cmd)) 1836bc75619SDan Williams return -EINVAL; 1846bc75619SDan Williams if (offset >= LABEL_SIZE) 1856bc75619SDan Williams return -EINVAL; 1866bc75619SDan Williams if (nd_cmd->in_length + sizeof(*nd_cmd) > buf_len) 1876bc75619SDan Williams return -EINVAL; 1886bc75619SDan Williams 1896bc75619SDan Williams nd_cmd->status = 0; 1906bc75619SDan Williams len = min(nd_cmd->in_length, LABEL_SIZE - offset); 19139c686b8SVishal Verma memcpy(nd_cmd->out_buf, label + offset, len); 1926bc75619SDan Williams rc = buf_len - sizeof(*nd_cmd) - len; 19339c686b8SVishal Verma 19439c686b8SVishal Verma return rc; 1956bc75619SDan Williams } 19639c686b8SVishal Verma 19739c686b8SVishal Verma static int nfit_test_cmd_set_config_data(struct nd_cmd_set_config_hdr *nd_cmd, 19839c686b8SVishal Verma unsigned int buf_len, void *label) 19939c686b8SVishal Verma { 2006bc75619SDan Williams unsigned int len, offset = nd_cmd->in_offset; 2016bc75619SDan Williams u32 *status; 20239c686b8SVishal Verma int rc; 2036bc75619SDan Williams 2046bc75619SDan Williams if (buf_len < sizeof(*nd_cmd)) 2056bc75619SDan Williams return -EINVAL; 2066bc75619SDan Williams if (offset >= LABEL_SIZE) 2076bc75619SDan Williams return -EINVAL; 2086bc75619SDan Williams if (nd_cmd->in_length + sizeof(*nd_cmd) + 4 > buf_len) 2096bc75619SDan Williams return -EINVAL; 2106bc75619SDan Williams 21139c686b8SVishal Verma status = (void *)nd_cmd + nd_cmd->in_length + sizeof(*nd_cmd); 2126bc75619SDan Williams *status = 0; 2136bc75619SDan Williams len = min(nd_cmd->in_length, LABEL_SIZE - offset); 21439c686b8SVishal Verma memcpy(label + offset, nd_cmd->in_buf, len); 2156bc75619SDan Williams rc = buf_len - sizeof(*nd_cmd) - (len + 4); 21639c686b8SVishal Verma 21739c686b8SVishal Verma return rc; 2186bc75619SDan Williams } 21939c686b8SVishal Verma 220747ffe11SDan Williams #define NFIT_TEST_ARS_RECORDS 4 221747ffe11SDan Williams 22239c686b8SVishal Verma static int nfit_test_cmd_ars_cap(struct nd_cmd_ars_cap *nd_cmd, 22339c686b8SVishal Verma unsigned int buf_len) 22439c686b8SVishal Verma { 22539c686b8SVishal Verma if (buf_len < sizeof(*nd_cmd)) 22639c686b8SVishal Verma return -EINVAL; 22739c686b8SVishal Verma 228747ffe11SDan Williams nd_cmd->max_ars_out = sizeof(struct nd_cmd_ars_status) 229747ffe11SDan Williams + NFIT_TEST_ARS_RECORDS * sizeof(struct nd_ars_record); 23039c686b8SVishal Verma nd_cmd->status = (ND_ARS_PERSISTENT | ND_ARS_VOLATILE) << 16; 23139c686b8SVishal Verma 23239c686b8SVishal Verma return 0; 23339c686b8SVishal Verma } 23439c686b8SVishal Verma 23539c686b8SVishal Verma static int nfit_test_cmd_ars_start(struct nd_cmd_ars_start *nd_cmd, 23639c686b8SVishal Verma unsigned int buf_len) 23739c686b8SVishal Verma { 23839c686b8SVishal Verma if (buf_len < sizeof(*nd_cmd)) 23939c686b8SVishal Verma return -EINVAL; 24039c686b8SVishal Verma 24139c686b8SVishal Verma nd_cmd->status = 0; 24239c686b8SVishal Verma 24339c686b8SVishal Verma return 0; 24439c686b8SVishal Verma } 24539c686b8SVishal Verma 24639c686b8SVishal Verma static int nfit_test_cmd_ars_status(struct nd_cmd_ars_status *nd_cmd, 24739c686b8SVishal Verma unsigned int buf_len) 24839c686b8SVishal Verma { 24939c686b8SVishal Verma if (buf_len < sizeof(*nd_cmd)) 25039c686b8SVishal Verma return -EINVAL; 25139c686b8SVishal Verma 252747ffe11SDan Williams nd_cmd->out_length = sizeof(struct nd_cmd_ars_status); 253747ffe11SDan Williams /* TODO: emit error records */ 25439c686b8SVishal Verma nd_cmd->num_records = 0; 255d26f73f0SDan Williams nd_cmd->address = 0; 256d26f73f0SDan Williams nd_cmd->length = -1ULL; 25739c686b8SVishal Verma nd_cmd->status = 0; 25839c686b8SVishal Verma 25939c686b8SVishal Verma return 0; 26039c686b8SVishal Verma } 26139c686b8SVishal Verma 26239c686b8SVishal Verma static int nfit_test_ctl(struct nvdimm_bus_descriptor *nd_desc, 26339c686b8SVishal Verma struct nvdimm *nvdimm, unsigned int cmd, void *buf, 26439c686b8SVishal Verma unsigned int buf_len) 26539c686b8SVishal Verma { 26639c686b8SVishal Verma struct acpi_nfit_desc *acpi_desc = to_acpi_desc(nd_desc); 26739c686b8SVishal Verma struct nfit_test *t = container_of(acpi_desc, typeof(*t), acpi_desc); 26839c686b8SVishal Verma int i, rc = 0; 26939c686b8SVishal Verma 27039c686b8SVishal Verma if (nvdimm) { 27139c686b8SVishal Verma struct nfit_mem *nfit_mem = nvdimm_provider_data(nvdimm); 27239c686b8SVishal Verma 27339c686b8SVishal Verma if (!nfit_mem || !test_bit(cmd, &nfit_mem->dsm_mask)) 27439c686b8SVishal Verma return -ENOTTY; 27539c686b8SVishal Verma 27639c686b8SVishal Verma /* lookup label space for the given dimm */ 27739c686b8SVishal Verma for (i = 0; i < ARRAY_SIZE(handle); i++) 27839c686b8SVishal Verma if (__to_nfit_memdev(nfit_mem)->device_handle == 27939c686b8SVishal Verma handle[i]) 28039c686b8SVishal Verma break; 28139c686b8SVishal Verma if (i >= ARRAY_SIZE(handle)) 28239c686b8SVishal Verma return -ENXIO; 28339c686b8SVishal Verma 28439c686b8SVishal Verma switch (cmd) { 28539c686b8SVishal Verma case ND_CMD_GET_CONFIG_SIZE: 28639c686b8SVishal Verma rc = nfit_test_cmd_get_config_size(buf, buf_len); 28739c686b8SVishal Verma break; 28839c686b8SVishal Verma case ND_CMD_GET_CONFIG_DATA: 28939c686b8SVishal Verma rc = nfit_test_cmd_get_config_data(buf, buf_len, 29039c686b8SVishal Verma t->label[i]); 29139c686b8SVishal Verma break; 29239c686b8SVishal Verma case ND_CMD_SET_CONFIG_DATA: 29339c686b8SVishal Verma rc = nfit_test_cmd_set_config_data(buf, buf_len, 29439c686b8SVishal Verma t->label[i]); 29539c686b8SVishal Verma break; 2966bc75619SDan Williams default: 2976bc75619SDan Williams return -ENOTTY; 2986bc75619SDan Williams } 29939c686b8SVishal Verma } else { 30039c686b8SVishal Verma if (!nd_desc || !test_bit(cmd, &nd_desc->dsm_mask)) 30139c686b8SVishal Verma return -ENOTTY; 30239c686b8SVishal Verma 30339c686b8SVishal Verma switch (cmd) { 30439c686b8SVishal Verma case ND_CMD_ARS_CAP: 30539c686b8SVishal Verma rc = nfit_test_cmd_ars_cap(buf, buf_len); 30639c686b8SVishal Verma break; 30739c686b8SVishal Verma case ND_CMD_ARS_START: 30839c686b8SVishal Verma rc = nfit_test_cmd_ars_start(buf, buf_len); 30939c686b8SVishal Verma break; 31039c686b8SVishal Verma case ND_CMD_ARS_STATUS: 31139c686b8SVishal Verma rc = nfit_test_cmd_ars_status(buf, buf_len); 31239c686b8SVishal Verma break; 31339c686b8SVishal Verma default: 31439c686b8SVishal Verma return -ENOTTY; 31539c686b8SVishal Verma } 31639c686b8SVishal Verma } 3176bc75619SDan Williams 3186bc75619SDan Williams return rc; 3196bc75619SDan Williams } 3206bc75619SDan Williams 3216bc75619SDan Williams static DEFINE_SPINLOCK(nfit_test_lock); 3226bc75619SDan Williams static struct nfit_test *instances[NUM_NFITS]; 3236bc75619SDan Williams 3246bc75619SDan Williams static void release_nfit_res(void *data) 3256bc75619SDan Williams { 3266bc75619SDan Williams struct nfit_test_resource *nfit_res = data; 3276bc75619SDan Williams struct resource *res = nfit_res->res; 3286bc75619SDan Williams 3296bc75619SDan Williams spin_lock(&nfit_test_lock); 3306bc75619SDan Williams list_del(&nfit_res->list); 3316bc75619SDan Williams spin_unlock(&nfit_test_lock); 3326bc75619SDan Williams 3336bc75619SDan Williams if (is_vmalloc_addr(nfit_res->buf)) 3346bc75619SDan Williams vfree(nfit_res->buf); 3356bc75619SDan Williams else 3366bc75619SDan Williams dma_free_coherent(nfit_res->dev, resource_size(res), 3376bc75619SDan Williams nfit_res->buf, res->start); 3386bc75619SDan Williams kfree(res); 3396bc75619SDan Williams kfree(nfit_res); 3406bc75619SDan Williams } 3416bc75619SDan Williams 3426bc75619SDan Williams static void *__test_alloc(struct nfit_test *t, size_t size, dma_addr_t *dma, 3436bc75619SDan Williams void *buf) 3446bc75619SDan Williams { 3456bc75619SDan Williams struct device *dev = &t->pdev.dev; 3466bc75619SDan Williams struct resource *res = kzalloc(sizeof(*res) * 2, GFP_KERNEL); 3476bc75619SDan Williams struct nfit_test_resource *nfit_res = kzalloc(sizeof(*nfit_res), 3486bc75619SDan Williams GFP_KERNEL); 3496bc75619SDan Williams int rc; 3506bc75619SDan Williams 3516bc75619SDan Williams if (!res || !buf || !nfit_res) 3526bc75619SDan Williams goto err; 3536bc75619SDan Williams rc = devm_add_action(dev, release_nfit_res, nfit_res); 3546bc75619SDan Williams if (rc) 3556bc75619SDan Williams goto err; 3566bc75619SDan Williams INIT_LIST_HEAD(&nfit_res->list); 3576bc75619SDan Williams memset(buf, 0, size); 3586bc75619SDan Williams nfit_res->dev = dev; 3596bc75619SDan Williams nfit_res->buf = buf; 3606bc75619SDan Williams nfit_res->res = res; 3616bc75619SDan Williams res->start = *dma; 3626bc75619SDan Williams res->end = *dma + size - 1; 3636bc75619SDan Williams res->name = "NFIT"; 3646bc75619SDan Williams spin_lock(&nfit_test_lock); 3656bc75619SDan Williams list_add(&nfit_res->list, &t->resources); 3666bc75619SDan Williams spin_unlock(&nfit_test_lock); 3676bc75619SDan Williams 3686bc75619SDan Williams return nfit_res->buf; 3696bc75619SDan Williams err: 3706bc75619SDan Williams if (buf && !is_vmalloc_addr(buf)) 3716bc75619SDan Williams dma_free_coherent(dev, size, buf, *dma); 3726bc75619SDan Williams else if (buf) 3736bc75619SDan Williams vfree(buf); 3746bc75619SDan Williams kfree(res); 3756bc75619SDan Williams kfree(nfit_res); 3766bc75619SDan Williams return NULL; 3776bc75619SDan Williams } 3786bc75619SDan Williams 3796bc75619SDan Williams static void *test_alloc(struct nfit_test *t, size_t size, dma_addr_t *dma) 3806bc75619SDan Williams { 3816bc75619SDan Williams void *buf = vmalloc(size); 3826bc75619SDan Williams 3836bc75619SDan Williams *dma = (unsigned long) buf; 3846bc75619SDan Williams return __test_alloc(t, size, dma, buf); 3856bc75619SDan Williams } 3866bc75619SDan Williams 3876bc75619SDan Williams static void *test_alloc_coherent(struct nfit_test *t, size_t size, 3886bc75619SDan Williams dma_addr_t *dma) 3896bc75619SDan Williams { 3906bc75619SDan Williams struct device *dev = &t->pdev.dev; 3916bc75619SDan Williams void *buf = dma_alloc_coherent(dev, size, dma, GFP_KERNEL); 3926bc75619SDan Williams 3936bc75619SDan Williams return __test_alloc(t, size, dma, buf); 3946bc75619SDan Williams } 3956bc75619SDan Williams 3966bc75619SDan Williams static struct nfit_test_resource *nfit_test_lookup(resource_size_t addr) 3976bc75619SDan Williams { 3986bc75619SDan Williams int i; 3996bc75619SDan Williams 4006bc75619SDan Williams for (i = 0; i < ARRAY_SIZE(instances); i++) { 4016bc75619SDan Williams struct nfit_test_resource *n, *nfit_res = NULL; 4026bc75619SDan Williams struct nfit_test *t = instances[i]; 4036bc75619SDan Williams 4046bc75619SDan Williams if (!t) 4056bc75619SDan Williams continue; 4066bc75619SDan Williams spin_lock(&nfit_test_lock); 4076bc75619SDan Williams list_for_each_entry(n, &t->resources, list) { 4086bc75619SDan Williams if (addr >= n->res->start && (addr < n->res->start 4096bc75619SDan Williams + resource_size(n->res))) { 4106bc75619SDan Williams nfit_res = n; 4116bc75619SDan Williams break; 4126bc75619SDan Williams } else if (addr >= (unsigned long) n->buf 4136bc75619SDan Williams && (addr < (unsigned long) n->buf 4146bc75619SDan Williams + resource_size(n->res))) { 4156bc75619SDan Williams nfit_res = n; 4166bc75619SDan Williams break; 4176bc75619SDan Williams } 4186bc75619SDan Williams } 4196bc75619SDan Williams spin_unlock(&nfit_test_lock); 4206bc75619SDan Williams if (nfit_res) 4216bc75619SDan Williams return nfit_res; 4226bc75619SDan Williams } 4236bc75619SDan Williams 4246bc75619SDan Williams return NULL; 4256bc75619SDan Williams } 4266bc75619SDan Williams 4276bc75619SDan Williams static int nfit_test0_alloc(struct nfit_test *t) 4286bc75619SDan Williams { 4296b577c9dSLinda Knippers size_t nfit_size = sizeof(struct acpi_nfit_system_address) * NUM_SPA 4306bc75619SDan Williams + sizeof(struct acpi_nfit_memory_map) * NUM_MEM 4316bc75619SDan Williams + sizeof(struct acpi_nfit_control_region) * NUM_DCR 432*3b87356fSDan Williams + offsetof(struct acpi_nfit_control_region, 433*3b87356fSDan Williams window_size) * NUM_DCR 4349d27a87eSDan Williams + sizeof(struct acpi_nfit_data_region) * NUM_BDW 4359d27a87eSDan Williams + sizeof(struct acpi_nfit_flush_address) * NUM_DCR; 4366bc75619SDan Williams int i; 4376bc75619SDan Williams 4386bc75619SDan Williams t->nfit_buf = test_alloc(t, nfit_size, &t->nfit_dma); 4396bc75619SDan Williams if (!t->nfit_buf) 4406bc75619SDan Williams return -ENOMEM; 4416bc75619SDan Williams t->nfit_size = nfit_size; 4426bc75619SDan Williams 4436bc75619SDan Williams t->spa_set[0] = test_alloc_coherent(t, SPA0_SIZE, &t->spa_set_dma[0]); 4446bc75619SDan Williams if (!t->spa_set[0]) 4456bc75619SDan Williams return -ENOMEM; 4466bc75619SDan Williams 4476bc75619SDan Williams t->spa_set[1] = test_alloc_coherent(t, SPA1_SIZE, &t->spa_set_dma[1]); 4486bc75619SDan Williams if (!t->spa_set[1]) 4496bc75619SDan Williams return -ENOMEM; 4506bc75619SDan Williams 45120985164SVishal Verma t->spa_set[2] = test_alloc_coherent(t, SPA0_SIZE, &t->spa_set_dma[2]); 45220985164SVishal Verma if (!t->spa_set[2]) 45320985164SVishal Verma return -ENOMEM; 45420985164SVishal Verma 4556bc75619SDan Williams for (i = 0; i < NUM_DCR; i++) { 4566bc75619SDan Williams t->dimm[i] = test_alloc(t, DIMM_SIZE, &t->dimm_dma[i]); 4576bc75619SDan Williams if (!t->dimm[i]) 4586bc75619SDan Williams return -ENOMEM; 4596bc75619SDan Williams 4606bc75619SDan Williams t->label[i] = test_alloc(t, LABEL_SIZE, &t->label_dma[i]); 4616bc75619SDan Williams if (!t->label[i]) 4626bc75619SDan Williams return -ENOMEM; 4636bc75619SDan Williams sprintf(t->label[i], "label%d", i); 4649d27a87eSDan Williams 4659d27a87eSDan Williams t->flush[i] = test_alloc(t, 8, &t->flush_dma[i]); 4669d27a87eSDan Williams if (!t->flush[i]) 4679d27a87eSDan Williams return -ENOMEM; 4686bc75619SDan Williams } 4696bc75619SDan Williams 4706bc75619SDan Williams for (i = 0; i < NUM_DCR; i++) { 4716bc75619SDan Williams t->dcr[i] = test_alloc(t, LABEL_SIZE, &t->dcr_dma[i]); 4726bc75619SDan Williams if (!t->dcr[i]) 4736bc75619SDan Williams return -ENOMEM; 4746bc75619SDan Williams } 4756bc75619SDan Williams 4766bc75619SDan Williams return 0; 4776bc75619SDan Williams } 4786bc75619SDan Williams 4796bc75619SDan Williams static int nfit_test1_alloc(struct nfit_test *t) 4806bc75619SDan Williams { 4816b577c9dSLinda Knippers size_t nfit_size = sizeof(struct acpi_nfit_system_address) 4826bc75619SDan Williams + sizeof(struct acpi_nfit_memory_map) 483*3b87356fSDan Williams + offsetof(struct acpi_nfit_control_region, window_size); 4846bc75619SDan Williams 4856bc75619SDan Williams t->nfit_buf = test_alloc(t, nfit_size, &t->nfit_dma); 4866bc75619SDan Williams if (!t->nfit_buf) 4876bc75619SDan Williams return -ENOMEM; 4886bc75619SDan Williams t->nfit_size = nfit_size; 4896bc75619SDan Williams 4906bc75619SDan Williams t->spa_set[0] = test_alloc_coherent(t, SPA2_SIZE, &t->spa_set_dma[0]); 4916bc75619SDan Williams if (!t->spa_set[0]) 4926bc75619SDan Williams return -ENOMEM; 4936bc75619SDan Williams 4946bc75619SDan Williams return 0; 4956bc75619SDan Williams } 4966bc75619SDan Williams 4976bc75619SDan Williams static void nfit_test0_setup(struct nfit_test *t) 4986bc75619SDan Williams { 4996bc75619SDan Williams struct nvdimm_bus_descriptor *nd_desc; 5006bc75619SDan Williams struct acpi_nfit_desc *acpi_desc; 5016bc75619SDan Williams struct acpi_nfit_memory_map *memdev; 5026bc75619SDan Williams void *nfit_buf = t->nfit_buf; 5036bc75619SDan Williams struct acpi_nfit_system_address *spa; 5046bc75619SDan Williams struct acpi_nfit_control_region *dcr; 5056bc75619SDan Williams struct acpi_nfit_data_region *bdw; 5069d27a87eSDan Williams struct acpi_nfit_flush_address *flush; 5076bc75619SDan Williams unsigned int offset; 5086bc75619SDan Williams 5096bc75619SDan Williams /* 5106bc75619SDan Williams * spa0 (interleave first half of dimm0 and dimm1, note storage 5116bc75619SDan Williams * does not actually alias the related block-data-window 5126bc75619SDan Williams * regions) 5136bc75619SDan Williams */ 5146b577c9dSLinda Knippers spa = nfit_buf; 5156bc75619SDan Williams spa->header.type = ACPI_NFIT_TYPE_SYSTEM_ADDRESS; 5166bc75619SDan Williams spa->header.length = sizeof(*spa); 5176bc75619SDan Williams memcpy(spa->range_guid, to_nfit_uuid(NFIT_SPA_PM), 16); 5186bc75619SDan Williams spa->range_index = 0+1; 5196bc75619SDan Williams spa->address = t->spa_set_dma[0]; 5206bc75619SDan Williams spa->length = SPA0_SIZE; 5216bc75619SDan Williams 5226bc75619SDan Williams /* 5236bc75619SDan Williams * spa1 (interleave last half of the 4 DIMMS, note storage 5246bc75619SDan Williams * does not actually alias the related block-data-window 5256bc75619SDan Williams * regions) 5266bc75619SDan Williams */ 5276b577c9dSLinda Knippers spa = nfit_buf + sizeof(*spa); 5286bc75619SDan Williams spa->header.type = ACPI_NFIT_TYPE_SYSTEM_ADDRESS; 5296bc75619SDan Williams spa->header.length = sizeof(*spa); 5306bc75619SDan Williams memcpy(spa->range_guid, to_nfit_uuid(NFIT_SPA_PM), 16); 5316bc75619SDan Williams spa->range_index = 1+1; 5326bc75619SDan Williams spa->address = t->spa_set_dma[1]; 5336bc75619SDan Williams spa->length = SPA1_SIZE; 5346bc75619SDan Williams 5356bc75619SDan Williams /* spa2 (dcr0) dimm0 */ 5366b577c9dSLinda Knippers spa = nfit_buf + sizeof(*spa) * 2; 5376bc75619SDan Williams spa->header.type = ACPI_NFIT_TYPE_SYSTEM_ADDRESS; 5386bc75619SDan Williams spa->header.length = sizeof(*spa); 5396bc75619SDan Williams memcpy(spa->range_guid, to_nfit_uuid(NFIT_SPA_DCR), 16); 5406bc75619SDan Williams spa->range_index = 2+1; 5416bc75619SDan Williams spa->address = t->dcr_dma[0]; 5426bc75619SDan Williams spa->length = DCR_SIZE; 5436bc75619SDan Williams 5446bc75619SDan Williams /* spa3 (dcr1) dimm1 */ 5456b577c9dSLinda Knippers spa = nfit_buf + sizeof(*spa) * 3; 5466bc75619SDan Williams spa->header.type = ACPI_NFIT_TYPE_SYSTEM_ADDRESS; 5476bc75619SDan Williams spa->header.length = sizeof(*spa); 5486bc75619SDan Williams memcpy(spa->range_guid, to_nfit_uuid(NFIT_SPA_DCR), 16); 5496bc75619SDan Williams spa->range_index = 3+1; 5506bc75619SDan Williams spa->address = t->dcr_dma[1]; 5516bc75619SDan Williams spa->length = DCR_SIZE; 5526bc75619SDan Williams 5536bc75619SDan Williams /* spa4 (dcr2) dimm2 */ 5546b577c9dSLinda Knippers spa = nfit_buf + sizeof(*spa) * 4; 5556bc75619SDan Williams spa->header.type = ACPI_NFIT_TYPE_SYSTEM_ADDRESS; 5566bc75619SDan Williams spa->header.length = sizeof(*spa); 5576bc75619SDan Williams memcpy(spa->range_guid, to_nfit_uuid(NFIT_SPA_DCR), 16); 5586bc75619SDan Williams spa->range_index = 4+1; 5596bc75619SDan Williams spa->address = t->dcr_dma[2]; 5606bc75619SDan Williams spa->length = DCR_SIZE; 5616bc75619SDan Williams 5626bc75619SDan Williams /* spa5 (dcr3) dimm3 */ 5636b577c9dSLinda Knippers spa = nfit_buf + sizeof(*spa) * 5; 5646bc75619SDan Williams spa->header.type = ACPI_NFIT_TYPE_SYSTEM_ADDRESS; 5656bc75619SDan Williams spa->header.length = sizeof(*spa); 5666bc75619SDan Williams memcpy(spa->range_guid, to_nfit_uuid(NFIT_SPA_DCR), 16); 5676bc75619SDan Williams spa->range_index = 5+1; 5686bc75619SDan Williams spa->address = t->dcr_dma[3]; 5696bc75619SDan Williams spa->length = DCR_SIZE; 5706bc75619SDan Williams 5716bc75619SDan Williams /* spa6 (bdw for dcr0) dimm0 */ 5726b577c9dSLinda Knippers spa = nfit_buf + sizeof(*spa) * 6; 5736bc75619SDan Williams spa->header.type = ACPI_NFIT_TYPE_SYSTEM_ADDRESS; 5746bc75619SDan Williams spa->header.length = sizeof(*spa); 5756bc75619SDan Williams memcpy(spa->range_guid, to_nfit_uuid(NFIT_SPA_BDW), 16); 5766bc75619SDan Williams spa->range_index = 6+1; 5776bc75619SDan Williams spa->address = t->dimm_dma[0]; 5786bc75619SDan Williams spa->length = DIMM_SIZE; 5796bc75619SDan Williams 5806bc75619SDan Williams /* spa7 (bdw for dcr1) dimm1 */ 5816b577c9dSLinda Knippers spa = nfit_buf + sizeof(*spa) * 7; 5826bc75619SDan Williams spa->header.type = ACPI_NFIT_TYPE_SYSTEM_ADDRESS; 5836bc75619SDan Williams spa->header.length = sizeof(*spa); 5846bc75619SDan Williams memcpy(spa->range_guid, to_nfit_uuid(NFIT_SPA_BDW), 16); 5856bc75619SDan Williams spa->range_index = 7+1; 5866bc75619SDan Williams spa->address = t->dimm_dma[1]; 5876bc75619SDan Williams spa->length = DIMM_SIZE; 5886bc75619SDan Williams 5896bc75619SDan Williams /* spa8 (bdw for dcr2) dimm2 */ 5906b577c9dSLinda Knippers spa = nfit_buf + sizeof(*spa) * 8; 5916bc75619SDan Williams spa->header.type = ACPI_NFIT_TYPE_SYSTEM_ADDRESS; 5926bc75619SDan Williams spa->header.length = sizeof(*spa); 5936bc75619SDan Williams memcpy(spa->range_guid, to_nfit_uuid(NFIT_SPA_BDW), 16); 5946bc75619SDan Williams spa->range_index = 8+1; 5956bc75619SDan Williams spa->address = t->dimm_dma[2]; 5966bc75619SDan Williams spa->length = DIMM_SIZE; 5976bc75619SDan Williams 5986bc75619SDan Williams /* spa9 (bdw for dcr3) dimm3 */ 5996b577c9dSLinda Knippers spa = nfit_buf + sizeof(*spa) * 9; 6006bc75619SDan Williams spa->header.type = ACPI_NFIT_TYPE_SYSTEM_ADDRESS; 6016bc75619SDan Williams spa->header.length = sizeof(*spa); 6026bc75619SDan Williams memcpy(spa->range_guid, to_nfit_uuid(NFIT_SPA_BDW), 16); 6036bc75619SDan Williams spa->range_index = 9+1; 6046bc75619SDan Williams spa->address = t->dimm_dma[3]; 6056bc75619SDan Williams spa->length = DIMM_SIZE; 6066bc75619SDan Williams 6076b577c9dSLinda Knippers offset = sizeof(*spa) * 10; 6086bc75619SDan Williams /* mem-region0 (spa0, dimm0) */ 6096bc75619SDan Williams memdev = nfit_buf + offset; 6106bc75619SDan Williams memdev->header.type = ACPI_NFIT_TYPE_MEMORY_MAP; 6116bc75619SDan Williams memdev->header.length = sizeof(*memdev); 6126bc75619SDan Williams memdev->device_handle = handle[0]; 6136bc75619SDan Williams memdev->physical_id = 0; 6146bc75619SDan Williams memdev->region_id = 0; 6156bc75619SDan Williams memdev->range_index = 0+1; 616*3b87356fSDan Williams memdev->region_index = 4+1; 6176bc75619SDan Williams memdev->region_size = SPA0_SIZE/2; 6186bc75619SDan Williams memdev->region_offset = t->spa_set_dma[0]; 6196bc75619SDan Williams memdev->address = 0; 6206bc75619SDan Williams memdev->interleave_index = 0; 6216bc75619SDan Williams memdev->interleave_ways = 2; 6226bc75619SDan Williams 6236bc75619SDan Williams /* mem-region1 (spa0, dimm1) */ 6246bc75619SDan Williams memdev = nfit_buf + offset + sizeof(struct acpi_nfit_memory_map); 6256bc75619SDan Williams memdev->header.type = ACPI_NFIT_TYPE_MEMORY_MAP; 6266bc75619SDan Williams memdev->header.length = sizeof(*memdev); 6276bc75619SDan Williams memdev->device_handle = handle[1]; 6286bc75619SDan Williams memdev->physical_id = 1; 6296bc75619SDan Williams memdev->region_id = 0; 6306bc75619SDan Williams memdev->range_index = 0+1; 631*3b87356fSDan Williams memdev->region_index = 5+1; 6326bc75619SDan Williams memdev->region_size = SPA0_SIZE/2; 6336bc75619SDan Williams memdev->region_offset = t->spa_set_dma[0] + SPA0_SIZE/2; 6346bc75619SDan Williams memdev->address = 0; 6356bc75619SDan Williams memdev->interleave_index = 0; 6366bc75619SDan Williams memdev->interleave_ways = 2; 6376bc75619SDan Williams 6386bc75619SDan Williams /* mem-region2 (spa1, dimm0) */ 6396bc75619SDan Williams memdev = nfit_buf + offset + sizeof(struct acpi_nfit_memory_map) * 2; 6406bc75619SDan Williams memdev->header.type = ACPI_NFIT_TYPE_MEMORY_MAP; 6416bc75619SDan Williams memdev->header.length = sizeof(*memdev); 6426bc75619SDan Williams memdev->device_handle = handle[0]; 6436bc75619SDan Williams memdev->physical_id = 0; 6446bc75619SDan Williams memdev->region_id = 1; 6456bc75619SDan Williams memdev->range_index = 1+1; 646*3b87356fSDan Williams memdev->region_index = 4+1; 6476bc75619SDan Williams memdev->region_size = SPA1_SIZE/4; 6486bc75619SDan Williams memdev->region_offset = t->spa_set_dma[1]; 6496bc75619SDan Williams memdev->address = SPA0_SIZE/2; 6506bc75619SDan Williams memdev->interleave_index = 0; 6516bc75619SDan Williams memdev->interleave_ways = 4; 6526bc75619SDan Williams 6536bc75619SDan Williams /* mem-region3 (spa1, dimm1) */ 6546bc75619SDan Williams memdev = nfit_buf + offset + sizeof(struct acpi_nfit_memory_map) * 3; 6556bc75619SDan Williams memdev->header.type = ACPI_NFIT_TYPE_MEMORY_MAP; 6566bc75619SDan Williams memdev->header.length = sizeof(*memdev); 6576bc75619SDan Williams memdev->device_handle = handle[1]; 6586bc75619SDan Williams memdev->physical_id = 1; 6596bc75619SDan Williams memdev->region_id = 1; 6606bc75619SDan Williams memdev->range_index = 1+1; 661*3b87356fSDan Williams memdev->region_index = 5+1; 6626bc75619SDan Williams memdev->region_size = SPA1_SIZE/4; 6636bc75619SDan Williams memdev->region_offset = t->spa_set_dma[1] + SPA1_SIZE/4; 6646bc75619SDan Williams memdev->address = SPA0_SIZE/2; 6656bc75619SDan Williams memdev->interleave_index = 0; 6666bc75619SDan Williams memdev->interleave_ways = 4; 6676bc75619SDan Williams 6686bc75619SDan Williams /* mem-region4 (spa1, dimm2) */ 6696bc75619SDan Williams memdev = nfit_buf + offset + sizeof(struct acpi_nfit_memory_map) * 4; 6706bc75619SDan Williams memdev->header.type = ACPI_NFIT_TYPE_MEMORY_MAP; 6716bc75619SDan Williams memdev->header.length = sizeof(*memdev); 6726bc75619SDan Williams memdev->device_handle = handle[2]; 6736bc75619SDan Williams memdev->physical_id = 2; 6746bc75619SDan Williams memdev->region_id = 0; 6756bc75619SDan Williams memdev->range_index = 1+1; 676*3b87356fSDan Williams memdev->region_index = 6+1; 6776bc75619SDan Williams memdev->region_size = SPA1_SIZE/4; 6786bc75619SDan Williams memdev->region_offset = t->spa_set_dma[1] + 2*SPA1_SIZE/4; 6796bc75619SDan Williams memdev->address = SPA0_SIZE/2; 6806bc75619SDan Williams memdev->interleave_index = 0; 6816bc75619SDan Williams memdev->interleave_ways = 4; 6826bc75619SDan Williams 6836bc75619SDan Williams /* mem-region5 (spa1, dimm3) */ 6846bc75619SDan Williams memdev = nfit_buf + offset + sizeof(struct acpi_nfit_memory_map) * 5; 6856bc75619SDan Williams memdev->header.type = ACPI_NFIT_TYPE_MEMORY_MAP; 6866bc75619SDan Williams memdev->header.length = sizeof(*memdev); 6876bc75619SDan Williams memdev->device_handle = handle[3]; 6886bc75619SDan Williams memdev->physical_id = 3; 6896bc75619SDan Williams memdev->region_id = 0; 6906bc75619SDan Williams memdev->range_index = 1+1; 691*3b87356fSDan Williams memdev->region_index = 7+1; 6926bc75619SDan Williams memdev->region_size = SPA1_SIZE/4; 6936bc75619SDan Williams memdev->region_offset = t->spa_set_dma[1] + 3*SPA1_SIZE/4; 6946bc75619SDan Williams memdev->address = SPA0_SIZE/2; 6956bc75619SDan Williams memdev->interleave_index = 0; 6966bc75619SDan Williams memdev->interleave_ways = 4; 6976bc75619SDan Williams 6986bc75619SDan Williams /* mem-region6 (spa/dcr0, dimm0) */ 6996bc75619SDan Williams memdev = nfit_buf + offset + sizeof(struct acpi_nfit_memory_map) * 6; 7006bc75619SDan Williams memdev->header.type = ACPI_NFIT_TYPE_MEMORY_MAP; 7016bc75619SDan Williams memdev->header.length = sizeof(*memdev); 7026bc75619SDan Williams memdev->device_handle = handle[0]; 7036bc75619SDan Williams memdev->physical_id = 0; 7046bc75619SDan Williams memdev->region_id = 0; 7056bc75619SDan Williams memdev->range_index = 2+1; 7066bc75619SDan Williams memdev->region_index = 0+1; 7076bc75619SDan Williams memdev->region_size = 0; 7086bc75619SDan Williams memdev->region_offset = 0; 7096bc75619SDan Williams memdev->address = 0; 7106bc75619SDan Williams memdev->interleave_index = 0; 7116bc75619SDan Williams memdev->interleave_ways = 1; 7126bc75619SDan Williams 7136bc75619SDan Williams /* mem-region7 (spa/dcr1, dimm1) */ 7146bc75619SDan Williams memdev = nfit_buf + offset + sizeof(struct acpi_nfit_memory_map) * 7; 7156bc75619SDan Williams memdev->header.type = ACPI_NFIT_TYPE_MEMORY_MAP; 7166bc75619SDan Williams memdev->header.length = sizeof(*memdev); 7176bc75619SDan Williams memdev->device_handle = handle[1]; 7186bc75619SDan Williams memdev->physical_id = 1; 7196bc75619SDan Williams memdev->region_id = 0; 7206bc75619SDan Williams memdev->range_index = 3+1; 7216bc75619SDan Williams memdev->region_index = 1+1; 7226bc75619SDan Williams memdev->region_size = 0; 7236bc75619SDan Williams memdev->region_offset = 0; 7246bc75619SDan Williams memdev->address = 0; 7256bc75619SDan Williams memdev->interleave_index = 0; 7266bc75619SDan Williams memdev->interleave_ways = 1; 7276bc75619SDan Williams 7286bc75619SDan Williams /* mem-region8 (spa/dcr2, dimm2) */ 7296bc75619SDan Williams memdev = nfit_buf + offset + sizeof(struct acpi_nfit_memory_map) * 8; 7306bc75619SDan Williams memdev->header.type = ACPI_NFIT_TYPE_MEMORY_MAP; 7316bc75619SDan Williams memdev->header.length = sizeof(*memdev); 7326bc75619SDan Williams memdev->device_handle = handle[2]; 7336bc75619SDan Williams memdev->physical_id = 2; 7346bc75619SDan Williams memdev->region_id = 0; 7356bc75619SDan Williams memdev->range_index = 4+1; 7366bc75619SDan Williams memdev->region_index = 2+1; 7376bc75619SDan Williams memdev->region_size = 0; 7386bc75619SDan Williams memdev->region_offset = 0; 7396bc75619SDan Williams memdev->address = 0; 7406bc75619SDan Williams memdev->interleave_index = 0; 7416bc75619SDan Williams memdev->interleave_ways = 1; 7426bc75619SDan Williams 7436bc75619SDan Williams /* mem-region9 (spa/dcr3, dimm3) */ 7446bc75619SDan Williams memdev = nfit_buf + offset + sizeof(struct acpi_nfit_memory_map) * 9; 7456bc75619SDan Williams memdev->header.type = ACPI_NFIT_TYPE_MEMORY_MAP; 7466bc75619SDan Williams memdev->header.length = sizeof(*memdev); 7476bc75619SDan Williams memdev->device_handle = handle[3]; 7486bc75619SDan Williams memdev->physical_id = 3; 7496bc75619SDan Williams memdev->region_id = 0; 7506bc75619SDan Williams memdev->range_index = 5+1; 7516bc75619SDan Williams memdev->region_index = 3+1; 7526bc75619SDan Williams memdev->region_size = 0; 7536bc75619SDan Williams memdev->region_offset = 0; 7546bc75619SDan Williams memdev->address = 0; 7556bc75619SDan Williams memdev->interleave_index = 0; 7566bc75619SDan Williams memdev->interleave_ways = 1; 7576bc75619SDan Williams 7586bc75619SDan Williams /* mem-region10 (spa/bdw0, dimm0) */ 7596bc75619SDan Williams memdev = nfit_buf + offset + sizeof(struct acpi_nfit_memory_map) * 10; 7606bc75619SDan Williams memdev->header.type = ACPI_NFIT_TYPE_MEMORY_MAP; 7616bc75619SDan Williams memdev->header.length = sizeof(*memdev); 7626bc75619SDan Williams memdev->device_handle = handle[0]; 7636bc75619SDan Williams memdev->physical_id = 0; 7646bc75619SDan Williams memdev->region_id = 0; 7656bc75619SDan Williams memdev->range_index = 6+1; 7666bc75619SDan Williams memdev->region_index = 0+1; 7676bc75619SDan Williams memdev->region_size = 0; 7686bc75619SDan Williams memdev->region_offset = 0; 7696bc75619SDan Williams memdev->address = 0; 7706bc75619SDan Williams memdev->interleave_index = 0; 7716bc75619SDan Williams memdev->interleave_ways = 1; 7726bc75619SDan Williams 7736bc75619SDan Williams /* mem-region11 (spa/bdw1, dimm1) */ 7746bc75619SDan Williams memdev = nfit_buf + offset + sizeof(struct acpi_nfit_memory_map) * 11; 7756bc75619SDan Williams memdev->header.type = ACPI_NFIT_TYPE_MEMORY_MAP; 7766bc75619SDan Williams memdev->header.length = sizeof(*memdev); 7776bc75619SDan Williams memdev->device_handle = handle[1]; 7786bc75619SDan Williams memdev->physical_id = 1; 7796bc75619SDan Williams memdev->region_id = 0; 7806bc75619SDan Williams memdev->range_index = 7+1; 7816bc75619SDan Williams memdev->region_index = 1+1; 7826bc75619SDan Williams memdev->region_size = 0; 7836bc75619SDan Williams memdev->region_offset = 0; 7846bc75619SDan Williams memdev->address = 0; 7856bc75619SDan Williams memdev->interleave_index = 0; 7866bc75619SDan Williams memdev->interleave_ways = 1; 7876bc75619SDan Williams 7886bc75619SDan Williams /* mem-region12 (spa/bdw2, dimm2) */ 7896bc75619SDan Williams memdev = nfit_buf + offset + sizeof(struct acpi_nfit_memory_map) * 12; 7906bc75619SDan Williams memdev->header.type = ACPI_NFIT_TYPE_MEMORY_MAP; 7916bc75619SDan Williams memdev->header.length = sizeof(*memdev); 7926bc75619SDan Williams memdev->device_handle = handle[2]; 7936bc75619SDan Williams memdev->physical_id = 2; 7946bc75619SDan Williams memdev->region_id = 0; 7956bc75619SDan Williams memdev->range_index = 8+1; 7966bc75619SDan Williams memdev->region_index = 2+1; 7976bc75619SDan Williams memdev->region_size = 0; 7986bc75619SDan Williams memdev->region_offset = 0; 7996bc75619SDan Williams memdev->address = 0; 8006bc75619SDan Williams memdev->interleave_index = 0; 8016bc75619SDan Williams memdev->interleave_ways = 1; 8026bc75619SDan Williams 8036bc75619SDan Williams /* mem-region13 (spa/dcr3, dimm3) */ 8046bc75619SDan Williams memdev = nfit_buf + offset + sizeof(struct acpi_nfit_memory_map) * 13; 8056bc75619SDan Williams memdev->header.type = ACPI_NFIT_TYPE_MEMORY_MAP; 8066bc75619SDan Williams memdev->header.length = sizeof(*memdev); 8076bc75619SDan Williams memdev->device_handle = handle[3]; 8086bc75619SDan Williams memdev->physical_id = 3; 8096bc75619SDan Williams memdev->region_id = 0; 8106bc75619SDan Williams memdev->range_index = 9+1; 8116bc75619SDan Williams memdev->region_index = 3+1; 8126bc75619SDan Williams memdev->region_size = 0; 8136bc75619SDan Williams memdev->region_offset = 0; 8146bc75619SDan Williams memdev->address = 0; 8156bc75619SDan Williams memdev->interleave_index = 0; 8166bc75619SDan Williams memdev->interleave_ways = 1; 8176bc75619SDan Williams 8186bc75619SDan Williams offset = offset + sizeof(struct acpi_nfit_memory_map) * 14; 819*3b87356fSDan Williams /* dcr-descriptor0: blk */ 8206bc75619SDan Williams dcr = nfit_buf + offset; 8216bc75619SDan Williams dcr->header.type = ACPI_NFIT_TYPE_CONTROL_REGION; 8226bc75619SDan Williams dcr->header.length = sizeof(struct acpi_nfit_control_region); 8236bc75619SDan Williams dcr->region_index = 0+1; 8246bc75619SDan Williams dcr->vendor_id = 0xabcd; 8256bc75619SDan Williams dcr->device_id = 0; 8266bc75619SDan Williams dcr->revision_id = 1; 8276bc75619SDan Williams dcr->serial_number = ~handle[0]; 828be26f9aeSDan Williams dcr->code = NFIT_FIC_BLK; 8296bc75619SDan Williams dcr->windows = 1; 8306bc75619SDan Williams dcr->window_size = DCR_SIZE; 8316bc75619SDan Williams dcr->command_offset = 0; 8326bc75619SDan Williams dcr->command_size = 8; 8336bc75619SDan Williams dcr->status_offset = 8; 8346bc75619SDan Williams dcr->status_size = 4; 8356bc75619SDan Williams 836*3b87356fSDan Williams /* dcr-descriptor1: blk */ 8376bc75619SDan Williams dcr = nfit_buf + offset + sizeof(struct acpi_nfit_control_region); 8386bc75619SDan Williams dcr->header.type = ACPI_NFIT_TYPE_CONTROL_REGION; 8396bc75619SDan Williams dcr->header.length = sizeof(struct acpi_nfit_control_region); 8406bc75619SDan Williams dcr->region_index = 1+1; 8416bc75619SDan Williams dcr->vendor_id = 0xabcd; 8426bc75619SDan Williams dcr->device_id = 0; 8436bc75619SDan Williams dcr->revision_id = 1; 8446bc75619SDan Williams dcr->serial_number = ~handle[1]; 845be26f9aeSDan Williams dcr->code = NFIT_FIC_BLK; 8466bc75619SDan Williams dcr->windows = 1; 8476bc75619SDan Williams dcr->window_size = DCR_SIZE; 8486bc75619SDan Williams dcr->command_offset = 0; 8496bc75619SDan Williams dcr->command_size = 8; 8506bc75619SDan Williams dcr->status_offset = 8; 8516bc75619SDan Williams dcr->status_size = 4; 8526bc75619SDan Williams 853*3b87356fSDan Williams /* dcr-descriptor2: blk */ 8546bc75619SDan Williams dcr = nfit_buf + offset + sizeof(struct acpi_nfit_control_region) * 2; 8556bc75619SDan Williams dcr->header.type = ACPI_NFIT_TYPE_CONTROL_REGION; 8566bc75619SDan Williams dcr->header.length = sizeof(struct acpi_nfit_control_region); 8576bc75619SDan Williams dcr->region_index = 2+1; 8586bc75619SDan Williams dcr->vendor_id = 0xabcd; 8596bc75619SDan Williams dcr->device_id = 0; 8606bc75619SDan Williams dcr->revision_id = 1; 8616bc75619SDan Williams dcr->serial_number = ~handle[2]; 862be26f9aeSDan Williams dcr->code = NFIT_FIC_BLK; 8636bc75619SDan Williams dcr->windows = 1; 8646bc75619SDan Williams dcr->window_size = DCR_SIZE; 8656bc75619SDan Williams dcr->command_offset = 0; 8666bc75619SDan Williams dcr->command_size = 8; 8676bc75619SDan Williams dcr->status_offset = 8; 8686bc75619SDan Williams dcr->status_size = 4; 8696bc75619SDan Williams 870*3b87356fSDan Williams /* dcr-descriptor3: blk */ 8716bc75619SDan Williams dcr = nfit_buf + offset + sizeof(struct acpi_nfit_control_region) * 3; 8726bc75619SDan Williams dcr->header.type = ACPI_NFIT_TYPE_CONTROL_REGION; 8736bc75619SDan Williams dcr->header.length = sizeof(struct acpi_nfit_control_region); 8746bc75619SDan Williams dcr->region_index = 3+1; 8756bc75619SDan Williams dcr->vendor_id = 0xabcd; 8766bc75619SDan Williams dcr->device_id = 0; 8776bc75619SDan Williams dcr->revision_id = 1; 8786bc75619SDan Williams dcr->serial_number = ~handle[3]; 879be26f9aeSDan Williams dcr->code = NFIT_FIC_BLK; 8806bc75619SDan Williams dcr->windows = 1; 8816bc75619SDan Williams dcr->window_size = DCR_SIZE; 8826bc75619SDan Williams dcr->command_offset = 0; 8836bc75619SDan Williams dcr->command_size = 8; 8846bc75619SDan Williams dcr->status_offset = 8; 8856bc75619SDan Williams dcr->status_size = 4; 8866bc75619SDan Williams 8876bc75619SDan Williams offset = offset + sizeof(struct acpi_nfit_control_region) * 4; 888*3b87356fSDan Williams /* dcr-descriptor0: pmem */ 889*3b87356fSDan Williams dcr = nfit_buf + offset; 890*3b87356fSDan Williams dcr->header.type = ACPI_NFIT_TYPE_CONTROL_REGION; 891*3b87356fSDan Williams dcr->header.length = offsetof(struct acpi_nfit_control_region, 892*3b87356fSDan Williams window_size); 893*3b87356fSDan Williams dcr->region_index = 4+1; 894*3b87356fSDan Williams dcr->vendor_id = 0xabcd; 895*3b87356fSDan Williams dcr->device_id = 0; 896*3b87356fSDan Williams dcr->revision_id = 1; 897*3b87356fSDan Williams dcr->serial_number = ~handle[0]; 898*3b87356fSDan Williams dcr->code = NFIT_FIC_BYTEN; 899*3b87356fSDan Williams dcr->windows = 0; 900*3b87356fSDan Williams 901*3b87356fSDan Williams /* dcr-descriptor1: pmem */ 902*3b87356fSDan Williams dcr = nfit_buf + offset + offsetof(struct acpi_nfit_control_region, 903*3b87356fSDan Williams window_size); 904*3b87356fSDan Williams dcr->header.type = ACPI_NFIT_TYPE_CONTROL_REGION; 905*3b87356fSDan Williams dcr->header.length = offsetof(struct acpi_nfit_control_region, 906*3b87356fSDan Williams window_size); 907*3b87356fSDan Williams dcr->region_index = 5+1; 908*3b87356fSDan Williams dcr->vendor_id = 0xabcd; 909*3b87356fSDan Williams dcr->device_id = 0; 910*3b87356fSDan Williams dcr->revision_id = 1; 911*3b87356fSDan Williams dcr->serial_number = ~handle[1]; 912*3b87356fSDan Williams dcr->code = NFIT_FIC_BYTEN; 913*3b87356fSDan Williams dcr->windows = 0; 914*3b87356fSDan Williams 915*3b87356fSDan Williams /* dcr-descriptor2: pmem */ 916*3b87356fSDan Williams dcr = nfit_buf + offset + offsetof(struct acpi_nfit_control_region, 917*3b87356fSDan Williams window_size) * 2; 918*3b87356fSDan Williams dcr->header.type = ACPI_NFIT_TYPE_CONTROL_REGION; 919*3b87356fSDan Williams dcr->header.length = offsetof(struct acpi_nfit_control_region, 920*3b87356fSDan Williams window_size); 921*3b87356fSDan Williams dcr->region_index = 6+1; 922*3b87356fSDan Williams dcr->vendor_id = 0xabcd; 923*3b87356fSDan Williams dcr->device_id = 0; 924*3b87356fSDan Williams dcr->revision_id = 1; 925*3b87356fSDan Williams dcr->serial_number = ~handle[2]; 926*3b87356fSDan Williams dcr->code = NFIT_FIC_BYTEN; 927*3b87356fSDan Williams dcr->windows = 0; 928*3b87356fSDan Williams 929*3b87356fSDan Williams /* dcr-descriptor3: pmem */ 930*3b87356fSDan Williams dcr = nfit_buf + offset + offsetof(struct acpi_nfit_control_region, 931*3b87356fSDan Williams window_size) * 3; 932*3b87356fSDan Williams dcr->header.type = ACPI_NFIT_TYPE_CONTROL_REGION; 933*3b87356fSDan Williams dcr->header.length = offsetof(struct acpi_nfit_control_region, 934*3b87356fSDan Williams window_size); 935*3b87356fSDan Williams dcr->region_index = 7+1; 936*3b87356fSDan Williams dcr->vendor_id = 0xabcd; 937*3b87356fSDan Williams dcr->device_id = 0; 938*3b87356fSDan Williams dcr->revision_id = 1; 939*3b87356fSDan Williams dcr->serial_number = ~handle[3]; 940*3b87356fSDan Williams dcr->code = NFIT_FIC_BYTEN; 941*3b87356fSDan Williams dcr->windows = 0; 942*3b87356fSDan Williams 943*3b87356fSDan Williams offset = offset + offsetof(struct acpi_nfit_control_region, 944*3b87356fSDan Williams window_size) * 4; 9456bc75619SDan Williams /* bdw0 (spa/dcr0, dimm0) */ 9466bc75619SDan Williams bdw = nfit_buf + offset; 9476bc75619SDan Williams bdw->header.type = ACPI_NFIT_TYPE_DATA_REGION; 9486bc75619SDan Williams bdw->header.length = sizeof(struct acpi_nfit_data_region); 9496bc75619SDan Williams bdw->region_index = 0+1; 9506bc75619SDan Williams bdw->windows = 1; 9516bc75619SDan Williams bdw->offset = 0; 9526bc75619SDan Williams bdw->size = BDW_SIZE; 9536bc75619SDan Williams bdw->capacity = DIMM_SIZE; 9546bc75619SDan Williams bdw->start_address = 0; 9556bc75619SDan Williams 9566bc75619SDan Williams /* bdw1 (spa/dcr1, dimm1) */ 9576bc75619SDan Williams bdw = nfit_buf + offset + sizeof(struct acpi_nfit_data_region); 9586bc75619SDan Williams bdw->header.type = ACPI_NFIT_TYPE_DATA_REGION; 9596bc75619SDan Williams bdw->header.length = sizeof(struct acpi_nfit_data_region); 9606bc75619SDan Williams bdw->region_index = 1+1; 9616bc75619SDan Williams bdw->windows = 1; 9626bc75619SDan Williams bdw->offset = 0; 9636bc75619SDan Williams bdw->size = BDW_SIZE; 9646bc75619SDan Williams bdw->capacity = DIMM_SIZE; 9656bc75619SDan Williams bdw->start_address = 0; 9666bc75619SDan Williams 9676bc75619SDan Williams /* bdw2 (spa/dcr2, dimm2) */ 9686bc75619SDan Williams bdw = nfit_buf + offset + sizeof(struct acpi_nfit_data_region) * 2; 9696bc75619SDan Williams bdw->header.type = ACPI_NFIT_TYPE_DATA_REGION; 9706bc75619SDan Williams bdw->header.length = sizeof(struct acpi_nfit_data_region); 9716bc75619SDan Williams bdw->region_index = 2+1; 9726bc75619SDan Williams bdw->windows = 1; 9736bc75619SDan Williams bdw->offset = 0; 9746bc75619SDan Williams bdw->size = BDW_SIZE; 9756bc75619SDan Williams bdw->capacity = DIMM_SIZE; 9766bc75619SDan Williams bdw->start_address = 0; 9776bc75619SDan Williams 9786bc75619SDan Williams /* bdw3 (spa/dcr3, dimm3) */ 9796bc75619SDan Williams bdw = nfit_buf + offset + sizeof(struct acpi_nfit_data_region) * 3; 9806bc75619SDan Williams bdw->header.type = ACPI_NFIT_TYPE_DATA_REGION; 9816bc75619SDan Williams bdw->header.length = sizeof(struct acpi_nfit_data_region); 9826bc75619SDan Williams bdw->region_index = 3+1; 9836bc75619SDan Williams bdw->windows = 1; 9846bc75619SDan Williams bdw->offset = 0; 9856bc75619SDan Williams bdw->size = BDW_SIZE; 9866bc75619SDan Williams bdw->capacity = DIMM_SIZE; 9876bc75619SDan Williams bdw->start_address = 0; 9886bc75619SDan Williams 9899d27a87eSDan Williams offset = offset + sizeof(struct acpi_nfit_data_region) * 4; 9909d27a87eSDan Williams /* flush0 (dimm0) */ 9919d27a87eSDan Williams flush = nfit_buf + offset; 9929d27a87eSDan Williams flush->header.type = ACPI_NFIT_TYPE_FLUSH_ADDRESS; 9939d27a87eSDan Williams flush->header.length = sizeof(struct acpi_nfit_flush_address); 9949d27a87eSDan Williams flush->device_handle = handle[0]; 9959d27a87eSDan Williams flush->hint_count = 1; 9969d27a87eSDan Williams flush->hint_address[0] = t->flush_dma[0]; 9979d27a87eSDan Williams 9989d27a87eSDan Williams /* flush1 (dimm1) */ 9999d27a87eSDan Williams flush = nfit_buf + offset + sizeof(struct acpi_nfit_flush_address) * 1; 10009d27a87eSDan Williams flush->header.type = ACPI_NFIT_TYPE_FLUSH_ADDRESS; 10019d27a87eSDan Williams flush->header.length = sizeof(struct acpi_nfit_flush_address); 10029d27a87eSDan Williams flush->device_handle = handle[1]; 10039d27a87eSDan Williams flush->hint_count = 1; 10049d27a87eSDan Williams flush->hint_address[0] = t->flush_dma[1]; 10059d27a87eSDan Williams 10069d27a87eSDan Williams /* flush2 (dimm2) */ 10079d27a87eSDan Williams flush = nfit_buf + offset + sizeof(struct acpi_nfit_flush_address) * 2; 10089d27a87eSDan Williams flush->header.type = ACPI_NFIT_TYPE_FLUSH_ADDRESS; 10099d27a87eSDan Williams flush->header.length = sizeof(struct acpi_nfit_flush_address); 10109d27a87eSDan Williams flush->device_handle = handle[2]; 10119d27a87eSDan Williams flush->hint_count = 1; 10129d27a87eSDan Williams flush->hint_address[0] = t->flush_dma[2]; 10139d27a87eSDan Williams 10149d27a87eSDan Williams /* flush3 (dimm3) */ 10159d27a87eSDan Williams flush = nfit_buf + offset + sizeof(struct acpi_nfit_flush_address) * 3; 10169d27a87eSDan Williams flush->header.type = ACPI_NFIT_TYPE_FLUSH_ADDRESS; 10179d27a87eSDan Williams flush->header.length = sizeof(struct acpi_nfit_flush_address); 10189d27a87eSDan Williams flush->device_handle = handle[3]; 10199d27a87eSDan Williams flush->hint_count = 1; 10209d27a87eSDan Williams flush->hint_address[0] = t->flush_dma[3]; 10219d27a87eSDan Williams 102220985164SVishal Verma if (t->setup_hotplug) { 102320985164SVishal Verma offset = offset + sizeof(struct acpi_nfit_flush_address) * 4; 1024*3b87356fSDan Williams /* dcr-descriptor4: blk */ 102520985164SVishal Verma dcr = nfit_buf + offset; 102620985164SVishal Verma dcr->header.type = ACPI_NFIT_TYPE_CONTROL_REGION; 102720985164SVishal Verma dcr->header.length = sizeof(struct acpi_nfit_control_region); 1028*3b87356fSDan Williams dcr->region_index = 8+1; 102920985164SVishal Verma dcr->vendor_id = 0xabcd; 103020985164SVishal Verma dcr->device_id = 0; 103120985164SVishal Verma dcr->revision_id = 1; 103220985164SVishal Verma dcr->serial_number = ~handle[4]; 1033be26f9aeSDan Williams dcr->code = NFIT_FIC_BLK; 103420985164SVishal Verma dcr->windows = 1; 103520985164SVishal Verma dcr->window_size = DCR_SIZE; 103620985164SVishal Verma dcr->command_offset = 0; 103720985164SVishal Verma dcr->command_size = 8; 103820985164SVishal Verma dcr->status_offset = 8; 103920985164SVishal Verma dcr->status_size = 4; 104020985164SVishal Verma 104120985164SVishal Verma offset = offset + sizeof(struct acpi_nfit_control_region); 1042*3b87356fSDan Williams /* dcr-descriptor4: pmem */ 1043*3b87356fSDan Williams dcr = nfit_buf + offset; 1044*3b87356fSDan Williams dcr->header.type = ACPI_NFIT_TYPE_CONTROL_REGION; 1045*3b87356fSDan Williams dcr->header.length = offsetof(struct acpi_nfit_control_region, 1046*3b87356fSDan Williams window_size); 1047*3b87356fSDan Williams dcr->region_index = 9+1; 1048*3b87356fSDan Williams dcr->vendor_id = 0xabcd; 1049*3b87356fSDan Williams dcr->device_id = 0; 1050*3b87356fSDan Williams dcr->revision_id = 1; 1051*3b87356fSDan Williams dcr->serial_number = ~handle[4]; 1052*3b87356fSDan Williams dcr->code = NFIT_FIC_BYTEN; 1053*3b87356fSDan Williams dcr->windows = 0; 1054*3b87356fSDan Williams 1055*3b87356fSDan Williams offset = offset + offsetof(struct acpi_nfit_control_region, 1056*3b87356fSDan Williams window_size); 105720985164SVishal Verma /* bdw4 (spa/dcr4, dimm4) */ 105820985164SVishal Verma bdw = nfit_buf + offset; 105920985164SVishal Verma bdw->header.type = ACPI_NFIT_TYPE_DATA_REGION; 106020985164SVishal Verma bdw->header.length = sizeof(struct acpi_nfit_data_region); 1061*3b87356fSDan Williams bdw->region_index = 8+1; 106220985164SVishal Verma bdw->windows = 1; 106320985164SVishal Verma bdw->offset = 0; 106420985164SVishal Verma bdw->size = BDW_SIZE; 106520985164SVishal Verma bdw->capacity = DIMM_SIZE; 106620985164SVishal Verma bdw->start_address = 0; 106720985164SVishal Verma 106820985164SVishal Verma offset = offset + sizeof(struct acpi_nfit_data_region); 106920985164SVishal Verma /* spa10 (dcr4) dimm4 */ 107020985164SVishal Verma spa = nfit_buf + offset; 107120985164SVishal Verma spa->header.type = ACPI_NFIT_TYPE_SYSTEM_ADDRESS; 107220985164SVishal Verma spa->header.length = sizeof(*spa); 107320985164SVishal Verma memcpy(spa->range_guid, to_nfit_uuid(NFIT_SPA_DCR), 16); 107420985164SVishal Verma spa->range_index = 10+1; 107520985164SVishal Verma spa->address = t->dcr_dma[4]; 107620985164SVishal Verma spa->length = DCR_SIZE; 107720985164SVishal Verma 107820985164SVishal Verma /* 107920985164SVishal Verma * spa11 (single-dimm interleave for hotplug, note storage 108020985164SVishal Verma * does not actually alias the related block-data-window 108120985164SVishal Verma * regions) 108220985164SVishal Verma */ 108320985164SVishal Verma spa = nfit_buf + offset + sizeof(*spa); 108420985164SVishal Verma spa->header.type = ACPI_NFIT_TYPE_SYSTEM_ADDRESS; 108520985164SVishal Verma spa->header.length = sizeof(*spa); 108620985164SVishal Verma memcpy(spa->range_guid, to_nfit_uuid(NFIT_SPA_PM), 16); 108720985164SVishal Verma spa->range_index = 11+1; 108820985164SVishal Verma spa->address = t->spa_set_dma[2]; 108920985164SVishal Verma spa->length = SPA0_SIZE; 109020985164SVishal Verma 109120985164SVishal Verma /* spa12 (bdw for dcr4) dimm4 */ 109220985164SVishal Verma spa = nfit_buf + offset + sizeof(*spa) * 2; 109320985164SVishal Verma spa->header.type = ACPI_NFIT_TYPE_SYSTEM_ADDRESS; 109420985164SVishal Verma spa->header.length = sizeof(*spa); 109520985164SVishal Verma memcpy(spa->range_guid, to_nfit_uuid(NFIT_SPA_BDW), 16); 109620985164SVishal Verma spa->range_index = 12+1; 109720985164SVishal Verma spa->address = t->dimm_dma[4]; 109820985164SVishal Verma spa->length = DIMM_SIZE; 109920985164SVishal Verma 110020985164SVishal Verma offset = offset + sizeof(*spa) * 3; 110120985164SVishal Verma /* mem-region14 (spa/dcr4, dimm4) */ 110220985164SVishal Verma memdev = nfit_buf + offset; 110320985164SVishal Verma memdev->header.type = ACPI_NFIT_TYPE_MEMORY_MAP; 110420985164SVishal Verma memdev->header.length = sizeof(*memdev); 110520985164SVishal Verma memdev->device_handle = handle[4]; 110620985164SVishal Verma memdev->physical_id = 4; 110720985164SVishal Verma memdev->region_id = 0; 110820985164SVishal Verma memdev->range_index = 10+1; 1109*3b87356fSDan Williams memdev->region_index = 8+1; 111020985164SVishal Verma memdev->region_size = 0; 111120985164SVishal Verma memdev->region_offset = 0; 111220985164SVishal Verma memdev->address = 0; 111320985164SVishal Verma memdev->interleave_index = 0; 111420985164SVishal Verma memdev->interleave_ways = 1; 111520985164SVishal Verma 111620985164SVishal Verma /* mem-region15 (spa0, dimm4) */ 111720985164SVishal Verma memdev = nfit_buf + offset + 111820985164SVishal Verma sizeof(struct acpi_nfit_memory_map); 111920985164SVishal Verma memdev->header.type = ACPI_NFIT_TYPE_MEMORY_MAP; 112020985164SVishal Verma memdev->header.length = sizeof(*memdev); 112120985164SVishal Verma memdev->device_handle = handle[4]; 112220985164SVishal Verma memdev->physical_id = 4; 112320985164SVishal Verma memdev->region_id = 0; 112420985164SVishal Verma memdev->range_index = 11+1; 1125*3b87356fSDan Williams memdev->region_index = 9+1; 112620985164SVishal Verma memdev->region_size = SPA0_SIZE; 112720985164SVishal Verma memdev->region_offset = t->spa_set_dma[2]; 112820985164SVishal Verma memdev->address = 0; 112920985164SVishal Verma memdev->interleave_index = 0; 113020985164SVishal Verma memdev->interleave_ways = 1; 113120985164SVishal Verma 1132*3b87356fSDan Williams /* mem-region16 (spa/bdw4, dimm4) */ 113320985164SVishal Verma memdev = nfit_buf + offset + 113420985164SVishal Verma sizeof(struct acpi_nfit_memory_map) * 2; 113520985164SVishal Verma memdev->header.type = ACPI_NFIT_TYPE_MEMORY_MAP; 113620985164SVishal Verma memdev->header.length = sizeof(*memdev); 113720985164SVishal Verma memdev->device_handle = handle[4]; 113820985164SVishal Verma memdev->physical_id = 4; 113920985164SVishal Verma memdev->region_id = 0; 114020985164SVishal Verma memdev->range_index = 12+1; 1141*3b87356fSDan Williams memdev->region_index = 8+1; 114220985164SVishal Verma memdev->region_size = 0; 114320985164SVishal Verma memdev->region_offset = 0; 114420985164SVishal Verma memdev->address = 0; 114520985164SVishal Verma memdev->interleave_index = 0; 114620985164SVishal Verma memdev->interleave_ways = 1; 114720985164SVishal Verma 114820985164SVishal Verma offset = offset + sizeof(struct acpi_nfit_memory_map) * 3; 114920985164SVishal Verma /* flush3 (dimm4) */ 115020985164SVishal Verma flush = nfit_buf + offset; 115120985164SVishal Verma flush->header.type = ACPI_NFIT_TYPE_FLUSH_ADDRESS; 115220985164SVishal Verma flush->header.length = sizeof(struct acpi_nfit_flush_address); 115320985164SVishal Verma flush->device_handle = handle[4]; 115420985164SVishal Verma flush->hint_count = 1; 115520985164SVishal Verma flush->hint_address[0] = t->flush_dma[4]; 115620985164SVishal Verma } 115720985164SVishal Verma 11586bc75619SDan Williams acpi_desc = &t->acpi_desc; 11596bc75619SDan Williams set_bit(ND_CMD_GET_CONFIG_SIZE, &acpi_desc->dimm_dsm_force_en); 11606bc75619SDan Williams set_bit(ND_CMD_GET_CONFIG_DATA, &acpi_desc->dimm_dsm_force_en); 11616bc75619SDan Williams set_bit(ND_CMD_SET_CONFIG_DATA, &acpi_desc->dimm_dsm_force_en); 116239c686b8SVishal Verma set_bit(ND_CMD_ARS_CAP, &acpi_desc->bus_dsm_force_en); 116339c686b8SVishal Verma set_bit(ND_CMD_ARS_START, &acpi_desc->bus_dsm_force_en); 116439c686b8SVishal Verma set_bit(ND_CMD_ARS_STATUS, &acpi_desc->bus_dsm_force_en); 11656bc75619SDan Williams nd_desc = &acpi_desc->nd_desc; 11666bc75619SDan Williams nd_desc->ndctl = nfit_test_ctl; 11676bc75619SDan Williams } 11686bc75619SDan Williams 11696bc75619SDan Williams static void nfit_test1_setup(struct nfit_test *t) 11706bc75619SDan Williams { 11716b577c9dSLinda Knippers size_t offset; 11726bc75619SDan Williams void *nfit_buf = t->nfit_buf; 11736bc75619SDan Williams struct acpi_nfit_memory_map *memdev; 11746bc75619SDan Williams struct acpi_nfit_control_region *dcr; 11756bc75619SDan Williams struct acpi_nfit_system_address *spa; 1176d26f73f0SDan Williams struct nvdimm_bus_descriptor *nd_desc; 1177d26f73f0SDan Williams struct acpi_nfit_desc *acpi_desc; 11786bc75619SDan Williams 11796b577c9dSLinda Knippers offset = 0; 11806bc75619SDan Williams /* spa0 (flat range with no bdw aliasing) */ 11816bc75619SDan Williams spa = nfit_buf + offset; 11826bc75619SDan Williams spa->header.type = ACPI_NFIT_TYPE_SYSTEM_ADDRESS; 11836bc75619SDan Williams spa->header.length = sizeof(*spa); 11846bc75619SDan Williams memcpy(spa->range_guid, to_nfit_uuid(NFIT_SPA_PM), 16); 11856bc75619SDan Williams spa->range_index = 0+1; 11866bc75619SDan Williams spa->address = t->spa_set_dma[0]; 11876bc75619SDan Williams spa->length = SPA2_SIZE; 11886bc75619SDan Williams 11896bc75619SDan Williams offset += sizeof(*spa); 11906bc75619SDan Williams /* mem-region0 (spa0, dimm0) */ 11916bc75619SDan Williams memdev = nfit_buf + offset; 11926bc75619SDan Williams memdev->header.type = ACPI_NFIT_TYPE_MEMORY_MAP; 11936bc75619SDan Williams memdev->header.length = sizeof(*memdev); 11946bc75619SDan Williams memdev->device_handle = 0; 11956bc75619SDan Williams memdev->physical_id = 0; 11966bc75619SDan Williams memdev->region_id = 0; 11976bc75619SDan Williams memdev->range_index = 0+1; 11986bc75619SDan Williams memdev->region_index = 0+1; 11996bc75619SDan Williams memdev->region_size = SPA2_SIZE; 12006bc75619SDan Williams memdev->region_offset = 0; 12016bc75619SDan Williams memdev->address = 0; 12026bc75619SDan Williams memdev->interleave_index = 0; 12036bc75619SDan Williams memdev->interleave_ways = 1; 120458138820SDan Williams memdev->flags = ACPI_NFIT_MEM_SAVE_FAILED | ACPI_NFIT_MEM_RESTORE_FAILED 120558138820SDan Williams | ACPI_NFIT_MEM_FLUSH_FAILED | ACPI_NFIT_MEM_HEALTH_OBSERVED 1206f4295796SDan Williams | ACPI_NFIT_MEM_NOT_ARMED; 12076bc75619SDan Williams 12086bc75619SDan Williams offset += sizeof(*memdev); 12096bc75619SDan Williams /* dcr-descriptor0 */ 12106bc75619SDan Williams dcr = nfit_buf + offset; 12116bc75619SDan Williams dcr->header.type = ACPI_NFIT_TYPE_CONTROL_REGION; 1212*3b87356fSDan Williams dcr->header.length = offsetof(struct acpi_nfit_control_region, 1213*3b87356fSDan Williams window_size); 12146bc75619SDan Williams dcr->region_index = 0+1; 12156bc75619SDan Williams dcr->vendor_id = 0xabcd; 12166bc75619SDan Williams dcr->device_id = 0; 12176bc75619SDan Williams dcr->revision_id = 1; 12186bc75619SDan Williams dcr->serial_number = ~0; 1219be26f9aeSDan Williams dcr->code = NFIT_FIC_BYTE; 12206bc75619SDan Williams dcr->windows = 0; 1221d26f73f0SDan Williams 1222d26f73f0SDan Williams acpi_desc = &t->acpi_desc; 1223d26f73f0SDan Williams set_bit(ND_CMD_ARS_CAP, &acpi_desc->bus_dsm_force_en); 1224d26f73f0SDan Williams set_bit(ND_CMD_ARS_START, &acpi_desc->bus_dsm_force_en); 1225d26f73f0SDan Williams set_bit(ND_CMD_ARS_STATUS, &acpi_desc->bus_dsm_force_en); 1226d26f73f0SDan Williams nd_desc = &acpi_desc->nd_desc; 1227d26f73f0SDan Williams nd_desc->ndctl = nfit_test_ctl; 12286bc75619SDan Williams } 12296bc75619SDan Williams 12306bc75619SDan Williams static int nfit_test_blk_do_io(struct nd_blk_region *ndbr, resource_size_t dpa, 12316bc75619SDan Williams void *iobuf, u64 len, int rw) 12326bc75619SDan Williams { 12336bc75619SDan Williams struct nfit_blk *nfit_blk = ndbr->blk_provider_data; 12346bc75619SDan Williams struct nfit_blk_mmio *mmio = &nfit_blk->mmio[BDW]; 12356bc75619SDan Williams struct nd_region *nd_region = &ndbr->nd_region; 12366bc75619SDan Williams unsigned int lane; 12376bc75619SDan Williams 12386bc75619SDan Williams lane = nd_region_acquire_lane(nd_region); 12396bc75619SDan Williams if (rw) 124067a3e8feSRoss Zwisler memcpy(mmio->addr.base + dpa, iobuf, len); 124167a3e8feSRoss Zwisler else { 124267a3e8feSRoss Zwisler memcpy(iobuf, mmio->addr.base + dpa, len); 124367a3e8feSRoss Zwisler 124467a3e8feSRoss Zwisler /* give us some some coverage of the mmio_flush_range() API */ 124567a3e8feSRoss Zwisler mmio_flush_range(mmio->addr.base + dpa, len); 124667a3e8feSRoss Zwisler } 12476bc75619SDan Williams nd_region_release_lane(nd_region, lane); 12486bc75619SDan Williams 12496bc75619SDan Williams return 0; 12506bc75619SDan Williams } 12516bc75619SDan Williams 12526bc75619SDan Williams static int nfit_test_probe(struct platform_device *pdev) 12536bc75619SDan Williams { 12546bc75619SDan Williams struct nvdimm_bus_descriptor *nd_desc; 12556bc75619SDan Williams struct acpi_nfit_desc *acpi_desc; 12566bc75619SDan Williams struct device *dev = &pdev->dev; 12576bc75619SDan Williams struct nfit_test *nfit_test; 12586bc75619SDan Williams int rc; 12596bc75619SDan Williams 12606bc75619SDan Williams nfit_test = to_nfit_test(&pdev->dev); 12616bc75619SDan Williams 12626bc75619SDan Williams /* common alloc */ 12636bc75619SDan Williams if (nfit_test->num_dcr) { 12646bc75619SDan Williams int num = nfit_test->num_dcr; 12656bc75619SDan Williams 12666bc75619SDan Williams nfit_test->dimm = devm_kcalloc(dev, num, sizeof(void *), 12676bc75619SDan Williams GFP_KERNEL); 12686bc75619SDan Williams nfit_test->dimm_dma = devm_kcalloc(dev, num, sizeof(dma_addr_t), 12696bc75619SDan Williams GFP_KERNEL); 12709d27a87eSDan Williams nfit_test->flush = devm_kcalloc(dev, num, sizeof(void *), 12719d27a87eSDan Williams GFP_KERNEL); 12729d27a87eSDan Williams nfit_test->flush_dma = devm_kcalloc(dev, num, sizeof(dma_addr_t), 12739d27a87eSDan Williams GFP_KERNEL); 12746bc75619SDan Williams nfit_test->label = devm_kcalloc(dev, num, sizeof(void *), 12756bc75619SDan Williams GFP_KERNEL); 12766bc75619SDan Williams nfit_test->label_dma = devm_kcalloc(dev, num, 12776bc75619SDan Williams sizeof(dma_addr_t), GFP_KERNEL); 12786bc75619SDan Williams nfit_test->dcr = devm_kcalloc(dev, num, 12796bc75619SDan Williams sizeof(struct nfit_test_dcr *), GFP_KERNEL); 12806bc75619SDan Williams nfit_test->dcr_dma = devm_kcalloc(dev, num, 12816bc75619SDan Williams sizeof(dma_addr_t), GFP_KERNEL); 12826bc75619SDan Williams if (nfit_test->dimm && nfit_test->dimm_dma && nfit_test->label 12836bc75619SDan Williams && nfit_test->label_dma && nfit_test->dcr 12849d27a87eSDan Williams && nfit_test->dcr_dma && nfit_test->flush 12859d27a87eSDan Williams && nfit_test->flush_dma) 12866bc75619SDan Williams /* pass */; 12876bc75619SDan Williams else 12886bc75619SDan Williams return -ENOMEM; 12896bc75619SDan Williams } 12906bc75619SDan Williams 12916bc75619SDan Williams if (nfit_test->num_pm) { 12926bc75619SDan Williams int num = nfit_test->num_pm; 12936bc75619SDan Williams 12946bc75619SDan Williams nfit_test->spa_set = devm_kcalloc(dev, num, sizeof(void *), 12956bc75619SDan Williams GFP_KERNEL); 12966bc75619SDan Williams nfit_test->spa_set_dma = devm_kcalloc(dev, num, 12976bc75619SDan Williams sizeof(dma_addr_t), GFP_KERNEL); 12986bc75619SDan Williams if (nfit_test->spa_set && nfit_test->spa_set_dma) 12996bc75619SDan Williams /* pass */; 13006bc75619SDan Williams else 13016bc75619SDan Williams return -ENOMEM; 13026bc75619SDan Williams } 13036bc75619SDan Williams 13046bc75619SDan Williams /* per-nfit specific alloc */ 13056bc75619SDan Williams if (nfit_test->alloc(nfit_test)) 13066bc75619SDan Williams return -ENOMEM; 13076bc75619SDan Williams 13086bc75619SDan Williams nfit_test->setup(nfit_test); 13096bc75619SDan Williams acpi_desc = &nfit_test->acpi_desc; 13106bc75619SDan Williams acpi_desc->dev = &pdev->dev; 13116bc75619SDan Williams acpi_desc->nfit = nfit_test->nfit_buf; 13126bc75619SDan Williams acpi_desc->blk_do_io = nfit_test_blk_do_io; 13136bc75619SDan Williams nd_desc = &acpi_desc->nd_desc; 13146bc75619SDan Williams nd_desc->attr_groups = acpi_nfit_attribute_groups; 13156bc75619SDan Williams acpi_desc->nvdimm_bus = nvdimm_bus_register(&pdev->dev, nd_desc); 13166bc75619SDan Williams if (!acpi_desc->nvdimm_bus) 13176bc75619SDan Williams return -ENXIO; 13186bc75619SDan Williams 131920985164SVishal Verma INIT_LIST_HEAD(&acpi_desc->spa_maps); 132020985164SVishal Verma INIT_LIST_HEAD(&acpi_desc->spas); 132120985164SVishal Verma INIT_LIST_HEAD(&acpi_desc->dcrs); 132220985164SVishal Verma INIT_LIST_HEAD(&acpi_desc->bdws); 132320985164SVishal Verma INIT_LIST_HEAD(&acpi_desc->idts); 132420985164SVishal Verma INIT_LIST_HEAD(&acpi_desc->flushes); 132520985164SVishal Verma INIT_LIST_HEAD(&acpi_desc->memdevs); 132620985164SVishal Verma INIT_LIST_HEAD(&acpi_desc->dimms); 132720985164SVishal Verma mutex_init(&acpi_desc->spa_map_mutex); 132820985164SVishal Verma mutex_init(&acpi_desc->init_mutex); 132920985164SVishal Verma 133020985164SVishal Verma rc = acpi_nfit_init(acpi_desc, nfit_test->nfit_size); 133120985164SVishal Verma if (rc) { 133220985164SVishal Verma nvdimm_bus_unregister(acpi_desc->nvdimm_bus); 133320985164SVishal Verma return rc; 133420985164SVishal Verma } 133520985164SVishal Verma 133620985164SVishal Verma if (nfit_test->setup != nfit_test0_setup) 133720985164SVishal Verma return 0; 133820985164SVishal Verma 133920985164SVishal Verma nfit_test->setup_hotplug = 1; 134020985164SVishal Verma nfit_test->setup(nfit_test); 134120985164SVishal Verma 13426bc75619SDan Williams rc = acpi_nfit_init(acpi_desc, nfit_test->nfit_size); 13436bc75619SDan Williams if (rc) { 13446bc75619SDan Williams nvdimm_bus_unregister(acpi_desc->nvdimm_bus); 13456bc75619SDan Williams return rc; 13466bc75619SDan Williams } 13476bc75619SDan Williams 13486bc75619SDan Williams return 0; 13496bc75619SDan Williams } 13506bc75619SDan Williams 13516bc75619SDan Williams static int nfit_test_remove(struct platform_device *pdev) 13526bc75619SDan Williams { 13536bc75619SDan Williams struct nfit_test *nfit_test = to_nfit_test(&pdev->dev); 13546bc75619SDan Williams struct acpi_nfit_desc *acpi_desc = &nfit_test->acpi_desc; 13556bc75619SDan Williams 13566bc75619SDan Williams nvdimm_bus_unregister(acpi_desc->nvdimm_bus); 13576bc75619SDan Williams 13586bc75619SDan Williams return 0; 13596bc75619SDan Williams } 13606bc75619SDan Williams 13616bc75619SDan Williams static void nfit_test_release(struct device *dev) 13626bc75619SDan Williams { 13636bc75619SDan Williams struct nfit_test *nfit_test = to_nfit_test(dev); 13646bc75619SDan Williams 13656bc75619SDan Williams kfree(nfit_test); 13666bc75619SDan Williams } 13676bc75619SDan Williams 13686bc75619SDan Williams static const struct platform_device_id nfit_test_id[] = { 13696bc75619SDan Williams { KBUILD_MODNAME }, 13706bc75619SDan Williams { }, 13716bc75619SDan Williams }; 13726bc75619SDan Williams 13736bc75619SDan Williams static struct platform_driver nfit_test_driver = { 13746bc75619SDan Williams .probe = nfit_test_probe, 13756bc75619SDan Williams .remove = nfit_test_remove, 13766bc75619SDan Williams .driver = { 13776bc75619SDan Williams .name = KBUILD_MODNAME, 13786bc75619SDan Williams }, 13796bc75619SDan Williams .id_table = nfit_test_id, 13806bc75619SDan Williams }; 13816bc75619SDan Williams 13826bc75619SDan Williams #ifdef CONFIG_CMA_SIZE_MBYTES 13836bc75619SDan Williams #define CMA_SIZE_MBYTES CONFIG_CMA_SIZE_MBYTES 13846bc75619SDan Williams #else 13856bc75619SDan Williams #define CMA_SIZE_MBYTES 0 13866bc75619SDan Williams #endif 13876bc75619SDan Williams 13886bc75619SDan Williams static __init int nfit_test_init(void) 13896bc75619SDan Williams { 13906bc75619SDan Williams int rc, i; 13916bc75619SDan Williams 13926bc75619SDan Williams nfit_test_setup(nfit_test_lookup); 13936bc75619SDan Williams 13946bc75619SDan Williams for (i = 0; i < NUM_NFITS; i++) { 13956bc75619SDan Williams struct nfit_test *nfit_test; 13966bc75619SDan Williams struct platform_device *pdev; 13976bc75619SDan Williams static int once; 13986bc75619SDan Williams 13996bc75619SDan Williams nfit_test = kzalloc(sizeof(*nfit_test), GFP_KERNEL); 14006bc75619SDan Williams if (!nfit_test) { 14016bc75619SDan Williams rc = -ENOMEM; 14026bc75619SDan Williams goto err_register; 14036bc75619SDan Williams } 14046bc75619SDan Williams INIT_LIST_HEAD(&nfit_test->resources); 14056bc75619SDan Williams switch (i) { 14066bc75619SDan Williams case 0: 14076bc75619SDan Williams nfit_test->num_pm = NUM_PM; 14086bc75619SDan Williams nfit_test->num_dcr = NUM_DCR; 14096bc75619SDan Williams nfit_test->alloc = nfit_test0_alloc; 14106bc75619SDan Williams nfit_test->setup = nfit_test0_setup; 14116bc75619SDan Williams break; 14126bc75619SDan Williams case 1: 14136bc75619SDan Williams nfit_test->num_pm = 1; 14146bc75619SDan Williams nfit_test->alloc = nfit_test1_alloc; 14156bc75619SDan Williams nfit_test->setup = nfit_test1_setup; 14166bc75619SDan Williams break; 14176bc75619SDan Williams default: 14186bc75619SDan Williams rc = -EINVAL; 14196bc75619SDan Williams goto err_register; 14206bc75619SDan Williams } 14216bc75619SDan Williams pdev = &nfit_test->pdev; 14226bc75619SDan Williams pdev->name = KBUILD_MODNAME; 14236bc75619SDan Williams pdev->id = i; 14246bc75619SDan Williams pdev->dev.release = nfit_test_release; 14256bc75619SDan Williams rc = platform_device_register(pdev); 14266bc75619SDan Williams if (rc) { 14276bc75619SDan Williams put_device(&pdev->dev); 14286bc75619SDan Williams goto err_register; 14296bc75619SDan Williams } 14306bc75619SDan Williams 14316bc75619SDan Williams rc = dma_coerce_mask_and_coherent(&pdev->dev, DMA_BIT_MASK(64)); 14326bc75619SDan Williams if (rc) 14336bc75619SDan Williams goto err_register; 14346bc75619SDan Williams 14356bc75619SDan Williams instances[i] = nfit_test; 14366bc75619SDan Williams 14376bc75619SDan Williams if (!once++) { 14386bc75619SDan Williams dma_addr_t dma; 14396bc75619SDan Williams void *buf; 14406bc75619SDan Williams 14416bc75619SDan Williams buf = dma_alloc_coherent(&pdev->dev, SZ_128M, &dma, 14426bc75619SDan Williams GFP_KERNEL); 14436bc75619SDan Williams if (!buf) { 14446bc75619SDan Williams rc = -ENOMEM; 14456bc75619SDan Williams dev_warn(&pdev->dev, "need 128M of free cma\n"); 14466bc75619SDan Williams goto err_register; 14476bc75619SDan Williams } 14486bc75619SDan Williams dma_free_coherent(&pdev->dev, SZ_128M, buf, dma); 14496bc75619SDan Williams } 14506bc75619SDan Williams } 14516bc75619SDan Williams 14526bc75619SDan Williams rc = platform_driver_register(&nfit_test_driver); 14536bc75619SDan Williams if (rc) 14546bc75619SDan Williams goto err_register; 14556bc75619SDan Williams return 0; 14566bc75619SDan Williams 14576bc75619SDan Williams err_register: 14586bc75619SDan Williams for (i = 0; i < NUM_NFITS; i++) 14596bc75619SDan Williams if (instances[i]) 14606bc75619SDan Williams platform_device_unregister(&instances[i]->pdev); 14616bc75619SDan Williams nfit_test_teardown(); 14626bc75619SDan Williams return rc; 14636bc75619SDan Williams } 14646bc75619SDan Williams 14656bc75619SDan Williams static __exit void nfit_test_exit(void) 14666bc75619SDan Williams { 14676bc75619SDan Williams int i; 14686bc75619SDan Williams 14696bc75619SDan Williams platform_driver_unregister(&nfit_test_driver); 14706bc75619SDan Williams for (i = 0; i < NUM_NFITS; i++) 14716bc75619SDan Williams platform_device_unregister(&instances[i]->pdev); 14726bc75619SDan Williams nfit_test_teardown(); 14736bc75619SDan Williams } 14746bc75619SDan Williams 14756bc75619SDan Williams module_init(nfit_test_init); 14766bc75619SDan Williams module_exit(nfit_test_exit); 14776bc75619SDan Williams MODULE_LICENSE("GPL v2"); 14786bc75619SDan Williams MODULE_AUTHOR("Intel Corporation"); 1479