2 * Copyright(c) 2013-2015 Intel Corporation. All rights reserved.
4 * This program is free software; you can redistribute it and/or modify
5 * it under the terms of version 2 of the GNU General Public License as
6 * published by the Free Software Foundation.
8 * This program is distributed in the hope that it will be useful, but
9 * WITHOUT ANY WARRANTY; without even the implied warranty of
10 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
11 * General Public License for more details.
13 #define pr_fmt(fmt) KBUILD_MODNAME ": " fmt
14 #include <linux/platform_device.h>
15 #include <linux/dma-mapping.h>
16 #include <linux/libnvdimm.h>
17 #include <linux/vmalloc.h>
18 #include <linux/device.h>
19 #include <linux/module.h>
20 #include <linux/mutex.h>
21 #include <linux/ndctl.h>
22 #include <linux/sizes.h>
23 #include <linux/list.h>
24 #include <linux/slab.h>
27 #include "nfit_test.h"
30 * Generate an NFIT table to describe the following topology:
32 * BUS0: Interleaved PMEM regions, and aliasing with BLK regions
34 * (a) (b) DIMM BLK-REGION
35 * +----------+--------------+----------+---------+
36 * +------+ | blk2.0 | pm0.0 | blk2.1 | pm1.0 | 0 region2
37 * | imc0 +--+- - - - - region0 - - - -+----------+ +
38 * +--+---+ | blk3.0 | pm0.0 | blk3.1 | pm1.0 | 1 region3
39 * | +----------+--------------v----------v v
43 * | +-------------------------^----------^ ^
44 * +--+---+ | blk4.0 | pm1.0 | 2 region4
45 * | imc1 +--+-------------------------+----------+ +
46 * +------+ | blk5.0 | pm1.0 | 3 region5
47 * +-------------------------+----------+-+-------+
51 * +--+---+ (Hotplug DIMM)
52 * | +----------------------------------------------+
53 * +--+---+ | blk6.0/pm7.0 | 4 region6/7
54 * | imc0 +--+----------------------------------------------+
58 * *) In this layout we have four dimms and two memory controllers in one
59 * socket. Each unique interface (BLK or PMEM) to DPA space
60 * is identified by a region device with a dynamically assigned id.
62 * *) The first portion of dimm0 and dimm1 are interleaved as REGION0.
63 * A single PMEM namespace "pm0.0" is created using half of the
64 * REGION0 SPA-range. REGION0 spans dimm0 and dimm1. PMEM namespace
65 * allocate from from the bottom of a region. The unallocated
66 * portion of REGION0 aliases with REGION2 and REGION3. That
67 * unallacted capacity is reclaimed as BLK namespaces ("blk2.0" and
68 * "blk3.0") starting at the base of each DIMM to offset (a) in those
69 * DIMMs. "pm0.0", "blk2.0" and "blk3.0" are free-form readable
70 * names that can be assigned to a namespace.
72 * *) In the last portion of dimm0 and dimm1 we have an interleaved
73 * SPA range, REGION1, that spans those two dimms as well as dimm2
74 * and dimm3. Some of REGION1 allocated to a PMEM namespace named
75 * "pm1.0" the rest is reclaimed in 4 BLK namespaces (for each
76 * dimm in the interleave set), "blk2.1", "blk3.1", "blk4.0", and
79 * *) The portion of dimm2 and dimm3 that do not participate in the
80 * REGION1 interleaved SPA range (i.e. the DPA address below offset
81 * (b) are also included in the "blk4.0" and "blk5.0" namespaces.
82 * Note, that BLK namespaces need not be contiguous in DPA-space, and
83 * can consume aliased capacity from multiple interleave sets.
85 * BUS1: Legacy NVDIMM (single contiguous range)
88 * +---------------------+
89 * |---------------------|
91 * |---------------------|
92 * +---------------------+
94 * *) A NFIT-table may describe a simple system-physical-address range
95 * with no BLK aliasing. This type of region may optionally
96 * reference an NVDIMM.
103 NUM_SPA = NUM_PM + NUM_DCR + NUM_BDW,
104 NUM_MEM = NUM_DCR + NUM_BDW + 2 /* spa0 iset */ + 4 /* spa1 iset */,
106 LABEL_SIZE = SZ_128K,
107 SPA0_SIZE = DIMM_SIZE,
108 SPA1_SIZE = DIMM_SIZE*2,
109 SPA2_SIZE = DIMM_SIZE,
112 NUM_NFITS = 2, /* permit testing multiple NFITs per system */
115 struct nfit_test_dcr {
118 __u8 aperature[BDW_SIZE];
121 #define NFIT_DIMM_HANDLE(node, socket, imc, chan, dimm) \
122 (((node & 0xfff) << 16) | ((socket & 0xf) << 12) \
123 | ((imc & 0xf) << 8) | ((chan & 0xf) << 4) | (dimm & 0xf))
125 static u32 handle[NUM_DCR] = {
126 [0] = NFIT_DIMM_HANDLE(0, 0, 0, 0, 0),
127 [1] = NFIT_DIMM_HANDLE(0, 0, 0, 0, 1),
128 [2] = NFIT_DIMM_HANDLE(0, 0, 1, 0, 0),
129 [3] = NFIT_DIMM_HANDLE(0, 0, 1, 0, 1),
130 [4] = NFIT_DIMM_HANDLE(0, 1, 0, 0, 0),
134 struct acpi_nfit_desc acpi_desc;
135 struct platform_device pdev;
136 struct list_head resources;
143 dma_addr_t *dimm_dma;
145 dma_addr_t *flush_dma;
147 dma_addr_t *label_dma;
149 dma_addr_t *spa_set_dma;
150 struct nfit_test_dcr **dcr;
152 int (*alloc)(struct nfit_test *t);
153 void (*setup)(struct nfit_test *t);
156 struct nd_cmd_ars_status *ars_status;
157 unsigned long deadline;
162 static struct nfit_test *to_nfit_test(struct device *dev)
164 struct platform_device *pdev = to_platform_device(dev);
166 return container_of(pdev, struct nfit_test, pdev);
169 static int nfit_test_cmd_get_config_size(struct nd_cmd_get_config_size *nd_cmd,
170 unsigned int buf_len)
172 if (buf_len < sizeof(*nd_cmd))
176 nd_cmd->config_size = LABEL_SIZE;
177 nd_cmd->max_xfer = SZ_4K;
182 static int nfit_test_cmd_get_config_data(struct nd_cmd_get_config_data_hdr
183 *nd_cmd, unsigned int buf_len, void *label)
185 unsigned int len, offset = nd_cmd->in_offset;
188 if (buf_len < sizeof(*nd_cmd))
190 if (offset >= LABEL_SIZE)
192 if (nd_cmd->in_length + sizeof(*nd_cmd) > buf_len)
196 len = min(nd_cmd->in_length, LABEL_SIZE - offset);
197 memcpy(nd_cmd->out_buf, label + offset, len);
198 rc = buf_len - sizeof(*nd_cmd) - len;
203 static int nfit_test_cmd_set_config_data(struct nd_cmd_set_config_hdr *nd_cmd,
204 unsigned int buf_len, void *label)
206 unsigned int len, offset = nd_cmd->in_offset;
210 if (buf_len < sizeof(*nd_cmd))
212 if (offset >= LABEL_SIZE)
214 if (nd_cmd->in_length + sizeof(*nd_cmd) + 4 > buf_len)
217 status = (void *)nd_cmd + nd_cmd->in_length + sizeof(*nd_cmd);
219 len = min(nd_cmd->in_length, LABEL_SIZE - offset);
220 memcpy(label + offset, nd_cmd->in_buf, len);
221 rc = buf_len - sizeof(*nd_cmd) - (len + 4);
226 #define NFIT_TEST_ARS_RECORDS 4
227 #define NFIT_TEST_CLEAR_ERR_UNIT 256
229 static int nfit_test_cmd_ars_cap(struct nd_cmd_ars_cap *nd_cmd,
230 unsigned int buf_len)
232 if (buf_len < sizeof(*nd_cmd))
235 nd_cmd->max_ars_out = sizeof(struct nd_cmd_ars_status)
236 + NFIT_TEST_ARS_RECORDS * sizeof(struct nd_ars_record);
237 nd_cmd->status = (ND_ARS_PERSISTENT | ND_ARS_VOLATILE) << 16;
238 nd_cmd->clear_err_unit = NFIT_TEST_CLEAR_ERR_UNIT;
244 * Initialize the ars_state to return an ars_result 1 second in the future with
245 * a 4K error range in the middle of the requested address range.
247 static void post_ars_status(struct ars_state *ars_state, u64 addr, u64 len)
249 struct nd_cmd_ars_status *ars_status;
250 struct nd_ars_record *ars_record;
252 ars_state->deadline = jiffies + 1*HZ;
253 ars_status = ars_state->ars_status;
254 ars_status->status = 0;
255 ars_status->out_length = sizeof(struct nd_cmd_ars_status)
256 + sizeof(struct nd_ars_record);
257 ars_status->address = addr;
258 ars_status->length = len;
259 ars_status->type = ND_ARS_PERSISTENT;
260 ars_status->num_records = 1;
261 ars_record = &ars_status->records[0];
262 ars_record->handle = 0;
263 ars_record->err_address = addr + len / 2;
264 ars_record->length = SZ_4K;
267 static int nfit_test_cmd_ars_start(struct ars_state *ars_state,
268 struct nd_cmd_ars_start *ars_start, unsigned int buf_len,
271 if (buf_len < sizeof(*ars_start))
274 spin_lock(&ars_state->lock);
275 if (time_before(jiffies, ars_state->deadline)) {
276 ars_start->status = NFIT_ARS_START_BUSY;
279 ars_start->status = 0;
280 ars_start->scrub_time = 1;
281 post_ars_status(ars_state, ars_start->address,
285 spin_unlock(&ars_state->lock);
290 static int nfit_test_cmd_ars_status(struct ars_state *ars_state,
291 struct nd_cmd_ars_status *ars_status, unsigned int buf_len,
294 if (buf_len < ars_state->ars_status->out_length)
297 spin_lock(&ars_state->lock);
298 if (time_before(jiffies, ars_state->deadline)) {
299 memset(ars_status, 0, buf_len);
300 ars_status->status = NFIT_ARS_STATUS_BUSY;
301 ars_status->out_length = sizeof(*ars_status);
304 memcpy(ars_status, ars_state->ars_status,
305 ars_state->ars_status->out_length);
308 spin_unlock(&ars_state->lock);
312 static int nfit_test_cmd_clear_error(struct nd_cmd_clear_error *clear_err,
313 unsigned int buf_len, int *cmd_rc)
315 const u64 mask = NFIT_TEST_CLEAR_ERR_UNIT - 1;
316 if (buf_len < sizeof(*clear_err))
319 if ((clear_err->address & mask) || (clear_err->length & mask))
323 * Report 'all clear' success for all commands even though a new
324 * scrub will find errors again. This is enough to have the
325 * error removed from the 'badblocks' tracking in the pmem
328 clear_err->status = 0;
329 clear_err->cleared = clear_err->length;
334 static int nfit_test_cmd_smart(struct nd_cmd_smart *smart, unsigned int buf_len)
336 static const struct nd_smart_payload smart_data = {
337 .flags = ND_SMART_HEALTH_VALID | ND_SMART_TEMP_VALID
338 | ND_SMART_SPARES_VALID | ND_SMART_ALARM_VALID
339 | ND_SMART_USED_VALID | ND_SMART_SHUTDOWN_VALID,
340 .health = ND_SMART_NON_CRITICAL_HEALTH,
341 .temperature = 23 * 16,
343 .alarm_flags = ND_SMART_SPARE_TRIP | ND_SMART_TEMP_TRIP,
349 if (buf_len < sizeof(*smart))
351 memcpy(smart->data, &smart_data, sizeof(smart_data));
355 static int nfit_test_cmd_smart_threshold(struct nd_cmd_smart_threshold *smart_t,
356 unsigned int buf_len)
358 static const struct nd_smart_threshold_payload smart_t_data = {
359 .alarm_control = ND_SMART_SPARE_TRIP | ND_SMART_TEMP_TRIP,
360 .temperature = 40 * 16,
364 if (buf_len < sizeof(*smart_t))
366 memcpy(smart_t->data, &smart_t_data, sizeof(smart_t_data));
370 static int nfit_test_ctl(struct nvdimm_bus_descriptor *nd_desc,
371 struct nvdimm *nvdimm, unsigned int cmd, void *buf,
372 unsigned int buf_len, int *cmd_rc)
374 struct acpi_nfit_desc *acpi_desc = to_acpi_desc(nd_desc);
375 struct nfit_test *t = container_of(acpi_desc, typeof(*t), acpi_desc);
376 unsigned int func = cmd;
377 int i, rc = 0, __cmd_rc;
384 struct nfit_mem *nfit_mem = nvdimm_provider_data(nvdimm);
385 unsigned long cmd_mask = nvdimm_cmd_mask(nvdimm);
390 if (cmd == ND_CMD_CALL) {
391 struct nd_cmd_pkg *call_pkg = buf;
393 buf_len = call_pkg->nd_size_in + call_pkg->nd_size_out;
394 buf = (void *) call_pkg->nd_payload;
395 func = call_pkg->nd_command;
396 if (call_pkg->nd_family != nfit_mem->family)
400 if (!test_bit(cmd, &cmd_mask)
401 || !test_bit(func, &nfit_mem->dsm_mask))
404 /* lookup label space for the given dimm */
405 for (i = 0; i < ARRAY_SIZE(handle); i++)
406 if (__to_nfit_memdev(nfit_mem)->device_handle ==
409 if (i >= ARRAY_SIZE(handle))
413 case ND_CMD_GET_CONFIG_SIZE:
414 rc = nfit_test_cmd_get_config_size(buf, buf_len);
416 case ND_CMD_GET_CONFIG_DATA:
417 rc = nfit_test_cmd_get_config_data(buf, buf_len,
420 case ND_CMD_SET_CONFIG_DATA:
421 rc = nfit_test_cmd_set_config_data(buf, buf_len,
425 rc = nfit_test_cmd_smart(buf, buf_len);
427 case ND_CMD_SMART_THRESHOLD:
428 rc = nfit_test_cmd_smart_threshold(buf, buf_len);
434 struct ars_state *ars_state = &t->ars_state;
436 if (!nd_desc || !test_bit(cmd, &nd_desc->cmd_mask))
441 rc = nfit_test_cmd_ars_cap(buf, buf_len);
443 case ND_CMD_ARS_START:
444 rc = nfit_test_cmd_ars_start(ars_state, buf, buf_len,
447 case ND_CMD_ARS_STATUS:
448 rc = nfit_test_cmd_ars_status(ars_state, buf, buf_len,
451 case ND_CMD_CLEAR_ERROR:
452 rc = nfit_test_cmd_clear_error(buf, buf_len, cmd_rc);
462 static DEFINE_SPINLOCK(nfit_test_lock);
463 static struct nfit_test *instances[NUM_NFITS];
465 static void release_nfit_res(void *data)
467 struct nfit_test_resource *nfit_res = data;
468 struct resource *res = nfit_res->res;
470 spin_lock(&nfit_test_lock);
471 list_del(&nfit_res->list);
472 spin_unlock(&nfit_test_lock);
474 vfree(nfit_res->buf);
479 static void *__test_alloc(struct nfit_test *t, size_t size, dma_addr_t *dma,
482 struct device *dev = &t->pdev.dev;
483 struct resource *res = kzalloc(sizeof(*res) * 2, GFP_KERNEL);
484 struct nfit_test_resource *nfit_res = kzalloc(sizeof(*nfit_res),
488 if (!res || !buf || !nfit_res)
490 rc = devm_add_action(dev, release_nfit_res, nfit_res);
493 INIT_LIST_HEAD(&nfit_res->list);
494 memset(buf, 0, size);
499 res->end = *dma + size - 1;
501 spin_lock(&nfit_test_lock);
502 list_add(&nfit_res->list, &t->resources);
503 spin_unlock(&nfit_test_lock);
505 return nfit_res->buf;
514 static void *test_alloc(struct nfit_test *t, size_t size, dma_addr_t *dma)
516 void *buf = vmalloc(size);
518 *dma = (unsigned long) buf;
519 return __test_alloc(t, size, dma, buf);
522 static struct nfit_test_resource *nfit_test_lookup(resource_size_t addr)
526 for (i = 0; i < ARRAY_SIZE(instances); i++) {
527 struct nfit_test_resource *n, *nfit_res = NULL;
528 struct nfit_test *t = instances[i];
532 spin_lock(&nfit_test_lock);
533 list_for_each_entry(n, &t->resources, list) {
534 if (addr >= n->res->start && (addr < n->res->start
535 + resource_size(n->res))) {
538 } else if (addr >= (unsigned long) n->buf
539 && (addr < (unsigned long) n->buf
540 + resource_size(n->res))) {
545 spin_unlock(&nfit_test_lock);
553 static int ars_state_init(struct device *dev, struct ars_state *ars_state)
555 ars_state->ars_status = devm_kzalloc(dev,
556 sizeof(struct nd_cmd_ars_status)
557 + sizeof(struct nd_ars_record) * NFIT_TEST_ARS_RECORDS,
559 if (!ars_state->ars_status)
561 spin_lock_init(&ars_state->lock);
565 static int nfit_test0_alloc(struct nfit_test *t)
567 size_t nfit_size = sizeof(struct acpi_nfit_system_address) * NUM_SPA
568 + sizeof(struct acpi_nfit_memory_map) * NUM_MEM
569 + sizeof(struct acpi_nfit_control_region) * NUM_DCR
570 + offsetof(struct acpi_nfit_control_region,
571 window_size) * NUM_DCR
572 + sizeof(struct acpi_nfit_data_region) * NUM_BDW
573 + (sizeof(struct acpi_nfit_flush_address)
574 + sizeof(u64) * NUM_HINTS) * NUM_DCR;
577 t->nfit_buf = test_alloc(t, nfit_size, &t->nfit_dma);
580 t->nfit_size = nfit_size;
582 t->spa_set[0] = test_alloc(t, SPA0_SIZE, &t->spa_set_dma[0]);
586 t->spa_set[1] = test_alloc(t, SPA1_SIZE, &t->spa_set_dma[1]);
590 t->spa_set[2] = test_alloc(t, SPA0_SIZE, &t->spa_set_dma[2]);
594 for (i = 0; i < NUM_DCR; i++) {
595 t->dimm[i] = test_alloc(t, DIMM_SIZE, &t->dimm_dma[i]);
599 t->label[i] = test_alloc(t, LABEL_SIZE, &t->label_dma[i]);
602 sprintf(t->label[i], "label%d", i);
604 t->flush[i] = test_alloc(t, sizeof(u64) * NUM_HINTS,
610 for (i = 0; i < NUM_DCR; i++) {
611 t->dcr[i] = test_alloc(t, LABEL_SIZE, &t->dcr_dma[i]);
616 return ars_state_init(&t->pdev.dev, &t->ars_state);
619 static int nfit_test1_alloc(struct nfit_test *t)
621 size_t nfit_size = sizeof(struct acpi_nfit_system_address)
622 + sizeof(struct acpi_nfit_memory_map)
623 + offsetof(struct acpi_nfit_control_region, window_size);
625 t->nfit_buf = test_alloc(t, nfit_size, &t->nfit_dma);
628 t->nfit_size = nfit_size;
630 t->spa_set[0] = test_alloc(t, SPA2_SIZE, &t->spa_set_dma[0]);
634 return ars_state_init(&t->pdev.dev, &t->ars_state);
637 static void nfit_test0_setup(struct nfit_test *t)
639 const int flush_hint_size = sizeof(struct acpi_nfit_flush_address)
640 + (sizeof(u64) * NUM_HINTS);
641 struct acpi_nfit_desc *acpi_desc;
642 struct acpi_nfit_memory_map *memdev;
643 void *nfit_buf = t->nfit_buf;
644 struct acpi_nfit_system_address *spa;
645 struct acpi_nfit_control_region *dcr;
646 struct acpi_nfit_data_region *bdw;
647 struct acpi_nfit_flush_address *flush;
648 unsigned int offset, i;
651 * spa0 (interleave first half of dimm0 and dimm1, note storage
652 * does not actually alias the related block-data-window
656 spa->header.type = ACPI_NFIT_TYPE_SYSTEM_ADDRESS;
657 spa->header.length = sizeof(*spa);
658 memcpy(spa->range_guid, to_nfit_uuid(NFIT_SPA_PM), 16);
659 spa->range_index = 0+1;
660 spa->address = t->spa_set_dma[0];
661 spa->length = SPA0_SIZE;
664 * spa1 (interleave last half of the 4 DIMMS, note storage
665 * does not actually alias the related block-data-window
668 spa = nfit_buf + sizeof(*spa);
669 spa->header.type = ACPI_NFIT_TYPE_SYSTEM_ADDRESS;
670 spa->header.length = sizeof(*spa);
671 memcpy(spa->range_guid, to_nfit_uuid(NFIT_SPA_PM), 16);
672 spa->range_index = 1+1;
673 spa->address = t->spa_set_dma[1];
674 spa->length = SPA1_SIZE;
676 /* spa2 (dcr0) dimm0 */
677 spa = nfit_buf + sizeof(*spa) * 2;
678 spa->header.type = ACPI_NFIT_TYPE_SYSTEM_ADDRESS;
679 spa->header.length = sizeof(*spa);
680 memcpy(spa->range_guid, to_nfit_uuid(NFIT_SPA_DCR), 16);
681 spa->range_index = 2+1;
682 spa->address = t->dcr_dma[0];
683 spa->length = DCR_SIZE;
685 /* spa3 (dcr1) dimm1 */
686 spa = nfit_buf + sizeof(*spa) * 3;
687 spa->header.type = ACPI_NFIT_TYPE_SYSTEM_ADDRESS;
688 spa->header.length = sizeof(*spa);
689 memcpy(spa->range_guid, to_nfit_uuid(NFIT_SPA_DCR), 16);
690 spa->range_index = 3+1;
691 spa->address = t->dcr_dma[1];
692 spa->length = DCR_SIZE;
694 /* spa4 (dcr2) dimm2 */
695 spa = nfit_buf + sizeof(*spa) * 4;
696 spa->header.type = ACPI_NFIT_TYPE_SYSTEM_ADDRESS;
697 spa->header.length = sizeof(*spa);
698 memcpy(spa->range_guid, to_nfit_uuid(NFIT_SPA_DCR), 16);
699 spa->range_index = 4+1;
700 spa->address = t->dcr_dma[2];
701 spa->length = DCR_SIZE;
703 /* spa5 (dcr3) dimm3 */
704 spa = nfit_buf + sizeof(*spa) * 5;
705 spa->header.type = ACPI_NFIT_TYPE_SYSTEM_ADDRESS;
706 spa->header.length = sizeof(*spa);
707 memcpy(spa->range_guid, to_nfit_uuid(NFIT_SPA_DCR), 16);
708 spa->range_index = 5+1;
709 spa->address = t->dcr_dma[3];
710 spa->length = DCR_SIZE;
712 /* spa6 (bdw for dcr0) dimm0 */
713 spa = nfit_buf + sizeof(*spa) * 6;
714 spa->header.type = ACPI_NFIT_TYPE_SYSTEM_ADDRESS;
715 spa->header.length = sizeof(*spa);
716 memcpy(spa->range_guid, to_nfit_uuid(NFIT_SPA_BDW), 16);
717 spa->range_index = 6+1;
718 spa->address = t->dimm_dma[0];
719 spa->length = DIMM_SIZE;
721 /* spa7 (bdw for dcr1) dimm1 */
722 spa = nfit_buf + sizeof(*spa) * 7;
723 spa->header.type = ACPI_NFIT_TYPE_SYSTEM_ADDRESS;
724 spa->header.length = sizeof(*spa);
725 memcpy(spa->range_guid, to_nfit_uuid(NFIT_SPA_BDW), 16);
726 spa->range_index = 7+1;
727 spa->address = t->dimm_dma[1];
728 spa->length = DIMM_SIZE;
730 /* spa8 (bdw for dcr2) dimm2 */
731 spa = nfit_buf + sizeof(*spa) * 8;
732 spa->header.type = ACPI_NFIT_TYPE_SYSTEM_ADDRESS;
733 spa->header.length = sizeof(*spa);
734 memcpy(spa->range_guid, to_nfit_uuid(NFIT_SPA_BDW), 16);
735 spa->range_index = 8+1;
736 spa->address = t->dimm_dma[2];
737 spa->length = DIMM_SIZE;
739 /* spa9 (bdw for dcr3) dimm3 */
740 spa = nfit_buf + sizeof(*spa) * 9;
741 spa->header.type = ACPI_NFIT_TYPE_SYSTEM_ADDRESS;
742 spa->header.length = sizeof(*spa);
743 memcpy(spa->range_guid, to_nfit_uuid(NFIT_SPA_BDW), 16);
744 spa->range_index = 9+1;
745 spa->address = t->dimm_dma[3];
746 spa->length = DIMM_SIZE;
748 offset = sizeof(*spa) * 10;
749 /* mem-region0 (spa0, dimm0) */
750 memdev = nfit_buf + offset;
751 memdev->header.type = ACPI_NFIT_TYPE_MEMORY_MAP;
752 memdev->header.length = sizeof(*memdev);
753 memdev->device_handle = handle[0];
754 memdev->physical_id = 0;
755 memdev->region_id = 0;
756 memdev->range_index = 0+1;
757 memdev->region_index = 4+1;
758 memdev->region_size = SPA0_SIZE/2;
759 memdev->region_offset = t->spa_set_dma[0];
761 memdev->interleave_index = 0;
762 memdev->interleave_ways = 2;
764 /* mem-region1 (spa0, dimm1) */
765 memdev = nfit_buf + offset + sizeof(struct acpi_nfit_memory_map);
766 memdev->header.type = ACPI_NFIT_TYPE_MEMORY_MAP;
767 memdev->header.length = sizeof(*memdev);
768 memdev->device_handle = handle[1];
769 memdev->physical_id = 1;
770 memdev->region_id = 0;
771 memdev->range_index = 0+1;
772 memdev->region_index = 5+1;
773 memdev->region_size = SPA0_SIZE/2;
774 memdev->region_offset = t->spa_set_dma[0] + SPA0_SIZE/2;
776 memdev->interleave_index = 0;
777 memdev->interleave_ways = 2;
779 /* mem-region2 (spa1, dimm0) */
780 memdev = nfit_buf + offset + sizeof(struct acpi_nfit_memory_map) * 2;
781 memdev->header.type = ACPI_NFIT_TYPE_MEMORY_MAP;
782 memdev->header.length = sizeof(*memdev);
783 memdev->device_handle = handle[0];
784 memdev->physical_id = 0;
785 memdev->region_id = 1;
786 memdev->range_index = 1+1;
787 memdev->region_index = 4+1;
788 memdev->region_size = SPA1_SIZE/4;
789 memdev->region_offset = t->spa_set_dma[1];
790 memdev->address = SPA0_SIZE/2;
791 memdev->interleave_index = 0;
792 memdev->interleave_ways = 4;
794 /* mem-region3 (spa1, dimm1) */
795 memdev = nfit_buf + offset + sizeof(struct acpi_nfit_memory_map) * 3;
796 memdev->header.type = ACPI_NFIT_TYPE_MEMORY_MAP;
797 memdev->header.length = sizeof(*memdev);
798 memdev->device_handle = handle[1];
799 memdev->physical_id = 1;
800 memdev->region_id = 1;
801 memdev->range_index = 1+1;
802 memdev->region_index = 5+1;
803 memdev->region_size = SPA1_SIZE/4;
804 memdev->region_offset = t->spa_set_dma[1] + SPA1_SIZE/4;
805 memdev->address = SPA0_SIZE/2;
806 memdev->interleave_index = 0;
807 memdev->interleave_ways = 4;
809 /* mem-region4 (spa1, dimm2) */
810 memdev = nfit_buf + offset + sizeof(struct acpi_nfit_memory_map) * 4;
811 memdev->header.type = ACPI_NFIT_TYPE_MEMORY_MAP;
812 memdev->header.length = sizeof(*memdev);
813 memdev->device_handle = handle[2];
814 memdev->physical_id = 2;
815 memdev->region_id = 0;
816 memdev->range_index = 1+1;
817 memdev->region_index = 6+1;
818 memdev->region_size = SPA1_SIZE/4;
819 memdev->region_offset = t->spa_set_dma[1] + 2*SPA1_SIZE/4;
820 memdev->address = SPA0_SIZE/2;
821 memdev->interleave_index = 0;
822 memdev->interleave_ways = 4;
824 /* mem-region5 (spa1, dimm3) */
825 memdev = nfit_buf + offset + sizeof(struct acpi_nfit_memory_map) * 5;
826 memdev->header.type = ACPI_NFIT_TYPE_MEMORY_MAP;
827 memdev->header.length = sizeof(*memdev);
828 memdev->device_handle = handle[3];
829 memdev->physical_id = 3;
830 memdev->region_id = 0;
831 memdev->range_index = 1+1;
832 memdev->region_index = 7+1;
833 memdev->region_size = SPA1_SIZE/4;
834 memdev->region_offset = t->spa_set_dma[1] + 3*SPA1_SIZE/4;
835 memdev->address = SPA0_SIZE/2;
836 memdev->interleave_index = 0;
837 memdev->interleave_ways = 4;
839 /* mem-region6 (spa/dcr0, dimm0) */
840 memdev = nfit_buf + offset + sizeof(struct acpi_nfit_memory_map) * 6;
841 memdev->header.type = ACPI_NFIT_TYPE_MEMORY_MAP;
842 memdev->header.length = sizeof(*memdev);
843 memdev->device_handle = handle[0];
844 memdev->physical_id = 0;
845 memdev->region_id = 0;
846 memdev->range_index = 2+1;
847 memdev->region_index = 0+1;
848 memdev->region_size = 0;
849 memdev->region_offset = 0;
851 memdev->interleave_index = 0;
852 memdev->interleave_ways = 1;
854 /* mem-region7 (spa/dcr1, dimm1) */
855 memdev = nfit_buf + offset + sizeof(struct acpi_nfit_memory_map) * 7;
856 memdev->header.type = ACPI_NFIT_TYPE_MEMORY_MAP;
857 memdev->header.length = sizeof(*memdev);
858 memdev->device_handle = handle[1];
859 memdev->physical_id = 1;
860 memdev->region_id = 0;
861 memdev->range_index = 3+1;
862 memdev->region_index = 1+1;
863 memdev->region_size = 0;
864 memdev->region_offset = 0;
866 memdev->interleave_index = 0;
867 memdev->interleave_ways = 1;
869 /* mem-region8 (spa/dcr2, dimm2) */
870 memdev = nfit_buf + offset + sizeof(struct acpi_nfit_memory_map) * 8;
871 memdev->header.type = ACPI_NFIT_TYPE_MEMORY_MAP;
872 memdev->header.length = sizeof(*memdev);
873 memdev->device_handle = handle[2];
874 memdev->physical_id = 2;
875 memdev->region_id = 0;
876 memdev->range_index = 4+1;
877 memdev->region_index = 2+1;
878 memdev->region_size = 0;
879 memdev->region_offset = 0;
881 memdev->interleave_index = 0;
882 memdev->interleave_ways = 1;
884 /* mem-region9 (spa/dcr3, dimm3) */
885 memdev = nfit_buf + offset + sizeof(struct acpi_nfit_memory_map) * 9;
886 memdev->header.type = ACPI_NFIT_TYPE_MEMORY_MAP;
887 memdev->header.length = sizeof(*memdev);
888 memdev->device_handle = handle[3];
889 memdev->physical_id = 3;
890 memdev->region_id = 0;
891 memdev->range_index = 5+1;
892 memdev->region_index = 3+1;
893 memdev->region_size = 0;
894 memdev->region_offset = 0;
896 memdev->interleave_index = 0;
897 memdev->interleave_ways = 1;
899 /* mem-region10 (spa/bdw0, dimm0) */
900 memdev = nfit_buf + offset + sizeof(struct acpi_nfit_memory_map) * 10;
901 memdev->header.type = ACPI_NFIT_TYPE_MEMORY_MAP;
902 memdev->header.length = sizeof(*memdev);
903 memdev->device_handle = handle[0];
904 memdev->physical_id = 0;
905 memdev->region_id = 0;
906 memdev->range_index = 6+1;
907 memdev->region_index = 0+1;
908 memdev->region_size = 0;
909 memdev->region_offset = 0;
911 memdev->interleave_index = 0;
912 memdev->interleave_ways = 1;
914 /* mem-region11 (spa/bdw1, dimm1) */
915 memdev = nfit_buf + offset + sizeof(struct acpi_nfit_memory_map) * 11;
916 memdev->header.type = ACPI_NFIT_TYPE_MEMORY_MAP;
917 memdev->header.length = sizeof(*memdev);
918 memdev->device_handle = handle[1];
919 memdev->physical_id = 1;
920 memdev->region_id = 0;
921 memdev->range_index = 7+1;
922 memdev->region_index = 1+1;
923 memdev->region_size = 0;
924 memdev->region_offset = 0;
926 memdev->interleave_index = 0;
927 memdev->interleave_ways = 1;
929 /* mem-region12 (spa/bdw2, dimm2) */
930 memdev = nfit_buf + offset + sizeof(struct acpi_nfit_memory_map) * 12;
931 memdev->header.type = ACPI_NFIT_TYPE_MEMORY_MAP;
932 memdev->header.length = sizeof(*memdev);
933 memdev->device_handle = handle[2];
934 memdev->physical_id = 2;
935 memdev->region_id = 0;
936 memdev->range_index = 8+1;
937 memdev->region_index = 2+1;
938 memdev->region_size = 0;
939 memdev->region_offset = 0;
941 memdev->interleave_index = 0;
942 memdev->interleave_ways = 1;
944 /* mem-region13 (spa/dcr3, dimm3) */
945 memdev = nfit_buf + offset + sizeof(struct acpi_nfit_memory_map) * 13;
946 memdev->header.type = ACPI_NFIT_TYPE_MEMORY_MAP;
947 memdev->header.length = sizeof(*memdev);
948 memdev->device_handle = handle[3];
949 memdev->physical_id = 3;
950 memdev->region_id = 0;
951 memdev->range_index = 9+1;
952 memdev->region_index = 3+1;
953 memdev->region_size = 0;
954 memdev->region_offset = 0;
956 memdev->interleave_index = 0;
957 memdev->interleave_ways = 1;
959 offset = offset + sizeof(struct acpi_nfit_memory_map) * 14;
960 /* dcr-descriptor0: blk */
961 dcr = nfit_buf + offset;
962 dcr->header.type = ACPI_NFIT_TYPE_CONTROL_REGION;
963 dcr->header.length = sizeof(struct acpi_nfit_control_region);
964 dcr->region_index = 0+1;
965 dcr->vendor_id = 0xabcd;
967 dcr->revision_id = 1;
968 dcr->serial_number = ~handle[0];
969 dcr->code = NFIT_FIC_BLK;
971 dcr->window_size = DCR_SIZE;
972 dcr->command_offset = 0;
973 dcr->command_size = 8;
974 dcr->status_offset = 8;
975 dcr->status_size = 4;
977 /* dcr-descriptor1: blk */
978 dcr = nfit_buf + offset + sizeof(struct acpi_nfit_control_region);
979 dcr->header.type = ACPI_NFIT_TYPE_CONTROL_REGION;
980 dcr->header.length = sizeof(struct acpi_nfit_control_region);
981 dcr->region_index = 1+1;
982 dcr->vendor_id = 0xabcd;
984 dcr->revision_id = 1;
985 dcr->serial_number = ~handle[1];
986 dcr->code = NFIT_FIC_BLK;
988 dcr->window_size = DCR_SIZE;
989 dcr->command_offset = 0;
990 dcr->command_size = 8;
991 dcr->status_offset = 8;
992 dcr->status_size = 4;
994 /* dcr-descriptor2: blk */
995 dcr = nfit_buf + offset + sizeof(struct acpi_nfit_control_region) * 2;
996 dcr->header.type = ACPI_NFIT_TYPE_CONTROL_REGION;
997 dcr->header.length = sizeof(struct acpi_nfit_control_region);
998 dcr->region_index = 2+1;
999 dcr->vendor_id = 0xabcd;
1001 dcr->revision_id = 1;
1002 dcr->serial_number = ~handle[2];
1003 dcr->code = NFIT_FIC_BLK;
1005 dcr->window_size = DCR_SIZE;
1006 dcr->command_offset = 0;
1007 dcr->command_size = 8;
1008 dcr->status_offset = 8;
1009 dcr->status_size = 4;
1011 /* dcr-descriptor3: blk */
1012 dcr = nfit_buf + offset + sizeof(struct acpi_nfit_control_region) * 3;
1013 dcr->header.type = ACPI_NFIT_TYPE_CONTROL_REGION;
1014 dcr->header.length = sizeof(struct acpi_nfit_control_region);
1015 dcr->region_index = 3+1;
1016 dcr->vendor_id = 0xabcd;
1018 dcr->revision_id = 1;
1019 dcr->serial_number = ~handle[3];
1020 dcr->code = NFIT_FIC_BLK;
1022 dcr->window_size = DCR_SIZE;
1023 dcr->command_offset = 0;
1024 dcr->command_size = 8;
1025 dcr->status_offset = 8;
1026 dcr->status_size = 4;
1028 offset = offset + sizeof(struct acpi_nfit_control_region) * 4;
1029 /* dcr-descriptor0: pmem */
1030 dcr = nfit_buf + offset;
1031 dcr->header.type = ACPI_NFIT_TYPE_CONTROL_REGION;
1032 dcr->header.length = offsetof(struct acpi_nfit_control_region,
1034 dcr->region_index = 4+1;
1035 dcr->vendor_id = 0xabcd;
1037 dcr->revision_id = 1;
1038 dcr->serial_number = ~handle[0];
1039 dcr->code = NFIT_FIC_BYTEN;
1042 /* dcr-descriptor1: pmem */
1043 dcr = nfit_buf + offset + offsetof(struct acpi_nfit_control_region,
1045 dcr->header.type = ACPI_NFIT_TYPE_CONTROL_REGION;
1046 dcr->header.length = offsetof(struct acpi_nfit_control_region,
1048 dcr->region_index = 5+1;
1049 dcr->vendor_id = 0xabcd;
1051 dcr->revision_id = 1;
1052 dcr->serial_number = ~handle[1];
1053 dcr->code = NFIT_FIC_BYTEN;
1056 /* dcr-descriptor2: pmem */
1057 dcr = nfit_buf + offset + offsetof(struct acpi_nfit_control_region,
1059 dcr->header.type = ACPI_NFIT_TYPE_CONTROL_REGION;
1060 dcr->header.length = offsetof(struct acpi_nfit_control_region,
1062 dcr->region_index = 6+1;
1063 dcr->vendor_id = 0xabcd;
1065 dcr->revision_id = 1;
1066 dcr->serial_number = ~handle[2];
1067 dcr->code = NFIT_FIC_BYTEN;
1070 /* dcr-descriptor3: pmem */
1071 dcr = nfit_buf + offset + offsetof(struct acpi_nfit_control_region,
1073 dcr->header.type = ACPI_NFIT_TYPE_CONTROL_REGION;
1074 dcr->header.length = offsetof(struct acpi_nfit_control_region,
1076 dcr->region_index = 7+1;
1077 dcr->vendor_id = 0xabcd;
1079 dcr->revision_id = 1;
1080 dcr->serial_number = ~handle[3];
1081 dcr->code = NFIT_FIC_BYTEN;
1084 offset = offset + offsetof(struct acpi_nfit_control_region,
1086 /* bdw0 (spa/dcr0, dimm0) */
1087 bdw = nfit_buf + offset;
1088 bdw->header.type = ACPI_NFIT_TYPE_DATA_REGION;
1089 bdw->header.length = sizeof(struct acpi_nfit_data_region);
1090 bdw->region_index = 0+1;
1093 bdw->size = BDW_SIZE;
1094 bdw->capacity = DIMM_SIZE;
1095 bdw->start_address = 0;
1097 /* bdw1 (spa/dcr1, dimm1) */
1098 bdw = nfit_buf + offset + sizeof(struct acpi_nfit_data_region);
1099 bdw->header.type = ACPI_NFIT_TYPE_DATA_REGION;
1100 bdw->header.length = sizeof(struct acpi_nfit_data_region);
1101 bdw->region_index = 1+1;
1104 bdw->size = BDW_SIZE;
1105 bdw->capacity = DIMM_SIZE;
1106 bdw->start_address = 0;
1108 /* bdw2 (spa/dcr2, dimm2) */
1109 bdw = nfit_buf + offset + sizeof(struct acpi_nfit_data_region) * 2;
1110 bdw->header.type = ACPI_NFIT_TYPE_DATA_REGION;
1111 bdw->header.length = sizeof(struct acpi_nfit_data_region);
1112 bdw->region_index = 2+1;
1115 bdw->size = BDW_SIZE;
1116 bdw->capacity = DIMM_SIZE;
1117 bdw->start_address = 0;
1119 /* bdw3 (spa/dcr3, dimm3) */
1120 bdw = nfit_buf + offset + sizeof(struct acpi_nfit_data_region) * 3;
1121 bdw->header.type = ACPI_NFIT_TYPE_DATA_REGION;
1122 bdw->header.length = sizeof(struct acpi_nfit_data_region);
1123 bdw->region_index = 3+1;
1126 bdw->size = BDW_SIZE;
1127 bdw->capacity = DIMM_SIZE;
1128 bdw->start_address = 0;
1130 offset = offset + sizeof(struct acpi_nfit_data_region) * 4;
1131 /* flush0 (dimm0) */
1132 flush = nfit_buf + offset;
1133 flush->header.type = ACPI_NFIT_TYPE_FLUSH_ADDRESS;
1134 flush->header.length = flush_hint_size;
1135 flush->device_handle = handle[0];
1136 flush->hint_count = NUM_HINTS;
1137 for (i = 0; i < NUM_HINTS; i++)
1138 flush->hint_address[i] = t->flush_dma[0] + i * sizeof(u64);
1140 /* flush1 (dimm1) */
1141 flush = nfit_buf + offset + flush_hint_size * 1;
1142 flush->header.type = ACPI_NFIT_TYPE_FLUSH_ADDRESS;
1143 flush->header.length = flush_hint_size;
1144 flush->device_handle = handle[1];
1145 flush->hint_count = NUM_HINTS;
1146 for (i = 0; i < NUM_HINTS; i++)
1147 flush->hint_address[i] = t->flush_dma[1] + i * sizeof(u64);
1149 /* flush2 (dimm2) */
1150 flush = nfit_buf + offset + flush_hint_size * 2;
1151 flush->header.type = ACPI_NFIT_TYPE_FLUSH_ADDRESS;
1152 flush->header.length = flush_hint_size;
1153 flush->device_handle = handle[2];
1154 flush->hint_count = NUM_HINTS;
1155 for (i = 0; i < NUM_HINTS; i++)
1156 flush->hint_address[i] = t->flush_dma[2] + i * sizeof(u64);
1158 /* flush3 (dimm3) */
1159 flush = nfit_buf + offset + flush_hint_size * 3;
1160 flush->header.type = ACPI_NFIT_TYPE_FLUSH_ADDRESS;
1161 flush->header.length = flush_hint_size;
1162 flush->device_handle = handle[3];
1163 flush->hint_count = NUM_HINTS;
1164 for (i = 0; i < NUM_HINTS; i++)
1165 flush->hint_address[i] = t->flush_dma[3] + i * sizeof(u64);
1167 if (t->setup_hotplug) {
1168 offset = offset + flush_hint_size * 4;
1169 /* dcr-descriptor4: blk */
1170 dcr = nfit_buf + offset;
1171 dcr->header.type = ACPI_NFIT_TYPE_CONTROL_REGION;
1172 dcr->header.length = sizeof(struct acpi_nfit_control_region);
1173 dcr->region_index = 8+1;
1174 dcr->vendor_id = 0xabcd;
1176 dcr->revision_id = 1;
1177 dcr->serial_number = ~handle[4];
1178 dcr->code = NFIT_FIC_BLK;
1180 dcr->window_size = DCR_SIZE;
1181 dcr->command_offset = 0;
1182 dcr->command_size = 8;
1183 dcr->status_offset = 8;
1184 dcr->status_size = 4;
1186 offset = offset + sizeof(struct acpi_nfit_control_region);
1187 /* dcr-descriptor4: pmem */
1188 dcr = nfit_buf + offset;
1189 dcr->header.type = ACPI_NFIT_TYPE_CONTROL_REGION;
1190 dcr->header.length = offsetof(struct acpi_nfit_control_region,
1192 dcr->region_index = 9+1;
1193 dcr->vendor_id = 0xabcd;
1195 dcr->revision_id = 1;
1196 dcr->serial_number = ~handle[4];
1197 dcr->code = NFIT_FIC_BYTEN;
1200 offset = offset + offsetof(struct acpi_nfit_control_region,
1202 /* bdw4 (spa/dcr4, dimm4) */
1203 bdw = nfit_buf + offset;
1204 bdw->header.type = ACPI_NFIT_TYPE_DATA_REGION;
1205 bdw->header.length = sizeof(struct acpi_nfit_data_region);
1206 bdw->region_index = 8+1;
1209 bdw->size = BDW_SIZE;
1210 bdw->capacity = DIMM_SIZE;
1211 bdw->start_address = 0;
1213 offset = offset + sizeof(struct acpi_nfit_data_region);
1214 /* spa10 (dcr4) dimm4 */
1215 spa = nfit_buf + offset;
1216 spa->header.type = ACPI_NFIT_TYPE_SYSTEM_ADDRESS;
1217 spa->header.length = sizeof(*spa);
1218 memcpy(spa->range_guid, to_nfit_uuid(NFIT_SPA_DCR), 16);
1219 spa->range_index = 10+1;
1220 spa->address = t->dcr_dma[4];
1221 spa->length = DCR_SIZE;
1224 * spa11 (single-dimm interleave for hotplug, note storage
1225 * does not actually alias the related block-data-window
1228 spa = nfit_buf + offset + sizeof(*spa);
1229 spa->header.type = ACPI_NFIT_TYPE_SYSTEM_ADDRESS;
1230 spa->header.length = sizeof(*spa);
1231 memcpy(spa->range_guid, to_nfit_uuid(NFIT_SPA_PM), 16);
1232 spa->range_index = 11+1;
1233 spa->address = t->spa_set_dma[2];
1234 spa->length = SPA0_SIZE;
1236 /* spa12 (bdw for dcr4) dimm4 */
1237 spa = nfit_buf + offset + sizeof(*spa) * 2;
1238 spa->header.type = ACPI_NFIT_TYPE_SYSTEM_ADDRESS;
1239 spa->header.length = sizeof(*spa);
1240 memcpy(spa->range_guid, to_nfit_uuid(NFIT_SPA_BDW), 16);
1241 spa->range_index = 12+1;
1242 spa->address = t->dimm_dma[4];
1243 spa->length = DIMM_SIZE;
1245 offset = offset + sizeof(*spa) * 3;
1246 /* mem-region14 (spa/dcr4, dimm4) */
1247 memdev = nfit_buf + offset;
1248 memdev->header.type = ACPI_NFIT_TYPE_MEMORY_MAP;
1249 memdev->header.length = sizeof(*memdev);
1250 memdev->device_handle = handle[4];
1251 memdev->physical_id = 4;
1252 memdev->region_id = 0;
1253 memdev->range_index = 10+1;
1254 memdev->region_index = 8+1;
1255 memdev->region_size = 0;
1256 memdev->region_offset = 0;
1257 memdev->address = 0;
1258 memdev->interleave_index = 0;
1259 memdev->interleave_ways = 1;
1261 /* mem-region15 (spa0, dimm4) */
1262 memdev = nfit_buf + offset +
1263 sizeof(struct acpi_nfit_memory_map);
1264 memdev->header.type = ACPI_NFIT_TYPE_MEMORY_MAP;
1265 memdev->header.length = sizeof(*memdev);
1266 memdev->device_handle = handle[4];
1267 memdev->physical_id = 4;
1268 memdev->region_id = 0;
1269 memdev->range_index = 11+1;
1270 memdev->region_index = 9+1;
1271 memdev->region_size = SPA0_SIZE;
1272 memdev->region_offset = t->spa_set_dma[2];
1273 memdev->address = 0;
1274 memdev->interleave_index = 0;
1275 memdev->interleave_ways = 1;
1277 /* mem-region16 (spa/bdw4, dimm4) */
1278 memdev = nfit_buf + offset +
1279 sizeof(struct acpi_nfit_memory_map) * 2;
1280 memdev->header.type = ACPI_NFIT_TYPE_MEMORY_MAP;
1281 memdev->header.length = sizeof(*memdev);
1282 memdev->device_handle = handle[4];
1283 memdev->physical_id = 4;
1284 memdev->region_id = 0;
1285 memdev->range_index = 12+1;
1286 memdev->region_index = 8+1;
1287 memdev->region_size = 0;
1288 memdev->region_offset = 0;
1289 memdev->address = 0;
1290 memdev->interleave_index = 0;
1291 memdev->interleave_ways = 1;
1293 offset = offset + sizeof(struct acpi_nfit_memory_map) * 3;
1294 /* flush3 (dimm4) */
1295 flush = nfit_buf + offset;
1296 flush->header.type = ACPI_NFIT_TYPE_FLUSH_ADDRESS;
1297 flush->header.length = flush_hint_size;
1298 flush->device_handle = handle[4];
1299 flush->hint_count = NUM_HINTS;
1300 for (i = 0; i < NUM_HINTS; i++)
1301 flush->hint_address[i] = t->flush_dma[4]
1305 post_ars_status(&t->ars_state, t->spa_set_dma[0], SPA0_SIZE);
1307 acpi_desc = &t->acpi_desc;
1308 set_bit(ND_CMD_GET_CONFIG_SIZE, &acpi_desc->dimm_cmd_force_en);
1309 set_bit(ND_CMD_GET_CONFIG_DATA, &acpi_desc->dimm_cmd_force_en);
1310 set_bit(ND_CMD_SET_CONFIG_DATA, &acpi_desc->dimm_cmd_force_en);
1311 set_bit(ND_CMD_SMART, &acpi_desc->dimm_cmd_force_en);
1312 set_bit(ND_CMD_ARS_CAP, &acpi_desc->bus_cmd_force_en);
1313 set_bit(ND_CMD_ARS_START, &acpi_desc->bus_cmd_force_en);
1314 set_bit(ND_CMD_ARS_STATUS, &acpi_desc->bus_cmd_force_en);
1315 set_bit(ND_CMD_CLEAR_ERROR, &acpi_desc->bus_cmd_force_en);
1316 set_bit(ND_CMD_SMART_THRESHOLD, &acpi_desc->dimm_cmd_force_en);
1319 static void nfit_test1_setup(struct nfit_test *t)
1322 void *nfit_buf = t->nfit_buf;
1323 struct acpi_nfit_memory_map *memdev;
1324 struct acpi_nfit_control_region *dcr;
1325 struct acpi_nfit_system_address *spa;
1326 struct acpi_nfit_desc *acpi_desc;
1329 /* spa0 (flat range with no bdw aliasing) */
1330 spa = nfit_buf + offset;
1331 spa->header.type = ACPI_NFIT_TYPE_SYSTEM_ADDRESS;
1332 spa->header.length = sizeof(*spa);
1333 memcpy(spa->range_guid, to_nfit_uuid(NFIT_SPA_PM), 16);
1334 spa->range_index = 0+1;
1335 spa->address = t->spa_set_dma[0];
1336 spa->length = SPA2_SIZE;
1338 offset += sizeof(*spa);
1339 /* mem-region0 (spa0, dimm0) */
1340 memdev = nfit_buf + offset;
1341 memdev->header.type = ACPI_NFIT_TYPE_MEMORY_MAP;
1342 memdev->header.length = sizeof(*memdev);
1343 memdev->device_handle = 0;
1344 memdev->physical_id = 0;
1345 memdev->region_id = 0;
1346 memdev->range_index = 0+1;
1347 memdev->region_index = 0+1;
1348 memdev->region_size = SPA2_SIZE;
1349 memdev->region_offset = 0;
1350 memdev->address = 0;
1351 memdev->interleave_index = 0;
1352 memdev->interleave_ways = 1;
1353 memdev->flags = ACPI_NFIT_MEM_SAVE_FAILED | ACPI_NFIT_MEM_RESTORE_FAILED
1354 | ACPI_NFIT_MEM_FLUSH_FAILED | ACPI_NFIT_MEM_HEALTH_OBSERVED
1355 | ACPI_NFIT_MEM_NOT_ARMED;
1357 offset += sizeof(*memdev);
1358 /* dcr-descriptor0 */
1359 dcr = nfit_buf + offset;
1360 dcr->header.type = ACPI_NFIT_TYPE_CONTROL_REGION;
1361 dcr->header.length = offsetof(struct acpi_nfit_control_region,
1363 dcr->region_index = 0+1;
1364 dcr->vendor_id = 0xabcd;
1366 dcr->revision_id = 1;
1367 dcr->serial_number = ~0;
1368 dcr->code = NFIT_FIC_BYTE;
1371 post_ars_status(&t->ars_state, t->spa_set_dma[0], SPA2_SIZE);
1373 acpi_desc = &t->acpi_desc;
1374 set_bit(ND_CMD_ARS_CAP, &acpi_desc->bus_cmd_force_en);
1375 set_bit(ND_CMD_ARS_START, &acpi_desc->bus_cmd_force_en);
1376 set_bit(ND_CMD_ARS_STATUS, &acpi_desc->bus_cmd_force_en);
1377 set_bit(ND_CMD_CLEAR_ERROR, &acpi_desc->bus_cmd_force_en);
1380 static int nfit_test_blk_do_io(struct nd_blk_region *ndbr, resource_size_t dpa,
1381 void *iobuf, u64 len, int rw)
1383 struct nfit_blk *nfit_blk = ndbr->blk_provider_data;
1384 struct nfit_blk_mmio *mmio = &nfit_blk->mmio[BDW];
1385 struct nd_region *nd_region = &ndbr->nd_region;
1388 lane = nd_region_acquire_lane(nd_region);
1390 memcpy(mmio->addr.base + dpa, iobuf, len);
1392 memcpy(iobuf, mmio->addr.base + dpa, len);
1394 /* give us some some coverage of the mmio_flush_range() API */
1395 mmio_flush_range(mmio->addr.base + dpa, len);
1397 nd_region_release_lane(nd_region, lane);
1402 static int nfit_test_probe(struct platform_device *pdev)
1404 struct nvdimm_bus_descriptor *nd_desc;
1405 struct acpi_nfit_desc *acpi_desc;
1406 struct device *dev = &pdev->dev;
1407 struct nfit_test *nfit_test;
1410 nfit_test = to_nfit_test(&pdev->dev);
1413 if (nfit_test->num_dcr) {
1414 int num = nfit_test->num_dcr;
1416 nfit_test->dimm = devm_kcalloc(dev, num, sizeof(void *),
1418 nfit_test->dimm_dma = devm_kcalloc(dev, num, sizeof(dma_addr_t),
1420 nfit_test->flush = devm_kcalloc(dev, num, sizeof(void *),
1422 nfit_test->flush_dma = devm_kcalloc(dev, num, sizeof(dma_addr_t),
1424 nfit_test->label = devm_kcalloc(dev, num, sizeof(void *),
1426 nfit_test->label_dma = devm_kcalloc(dev, num,
1427 sizeof(dma_addr_t), GFP_KERNEL);
1428 nfit_test->dcr = devm_kcalloc(dev, num,
1429 sizeof(struct nfit_test_dcr *), GFP_KERNEL);
1430 nfit_test->dcr_dma = devm_kcalloc(dev, num,
1431 sizeof(dma_addr_t), GFP_KERNEL);
1432 if (nfit_test->dimm && nfit_test->dimm_dma && nfit_test->label
1433 && nfit_test->label_dma && nfit_test->dcr
1434 && nfit_test->dcr_dma && nfit_test->flush
1435 && nfit_test->flush_dma)
1441 if (nfit_test->num_pm) {
1442 int num = nfit_test->num_pm;
1444 nfit_test->spa_set = devm_kcalloc(dev, num, sizeof(void *),
1446 nfit_test->spa_set_dma = devm_kcalloc(dev, num,
1447 sizeof(dma_addr_t), GFP_KERNEL);
1448 if (nfit_test->spa_set && nfit_test->spa_set_dma)
1454 /* per-nfit specific alloc */
1455 if (nfit_test->alloc(nfit_test))
1458 nfit_test->setup(nfit_test);
1459 acpi_desc = &nfit_test->acpi_desc;
1460 acpi_nfit_desc_init(acpi_desc, &pdev->dev);
1461 acpi_desc->nfit = nfit_test->nfit_buf;
1462 acpi_desc->blk_do_io = nfit_test_blk_do_io;
1463 nd_desc = &acpi_desc->nd_desc;
1464 nd_desc->provider_name = NULL;
1465 nd_desc->ndctl = nfit_test_ctl;
1466 acpi_desc->nvdimm_bus = nvdimm_bus_register(&pdev->dev, nd_desc);
1467 if (!acpi_desc->nvdimm_bus)
1470 rc = acpi_nfit_init(acpi_desc, nfit_test->nfit_size);
1472 nvdimm_bus_unregister(acpi_desc->nvdimm_bus);
1476 if (nfit_test->setup != nfit_test0_setup)
1479 nfit_test->setup_hotplug = 1;
1480 nfit_test->setup(nfit_test);
1482 rc = acpi_nfit_init(acpi_desc, nfit_test->nfit_size);
1484 nvdimm_bus_unregister(acpi_desc->nvdimm_bus);
1491 static int nfit_test_remove(struct platform_device *pdev)
1493 struct nfit_test *nfit_test = to_nfit_test(&pdev->dev);
1494 struct acpi_nfit_desc *acpi_desc = &nfit_test->acpi_desc;
1496 nvdimm_bus_unregister(acpi_desc->nvdimm_bus);
1501 static void nfit_test_release(struct device *dev)
1503 struct nfit_test *nfit_test = to_nfit_test(dev);
1508 static const struct platform_device_id nfit_test_id[] = {
1513 static struct platform_driver nfit_test_driver = {
1514 .probe = nfit_test_probe,
1515 .remove = nfit_test_remove,
1517 .name = KBUILD_MODNAME,
1519 .id_table = nfit_test_id,
1522 static __init int nfit_test_init(void)
1526 nfit_test_setup(nfit_test_lookup);
1528 for (i = 0; i < NUM_NFITS; i++) {
1529 struct nfit_test *nfit_test;
1530 struct platform_device *pdev;
1532 nfit_test = kzalloc(sizeof(*nfit_test), GFP_KERNEL);
1537 INIT_LIST_HEAD(&nfit_test->resources);
1540 nfit_test->num_pm = NUM_PM;
1541 nfit_test->num_dcr = NUM_DCR;
1542 nfit_test->alloc = nfit_test0_alloc;
1543 nfit_test->setup = nfit_test0_setup;
1546 nfit_test->num_pm = 1;
1547 nfit_test->alloc = nfit_test1_alloc;
1548 nfit_test->setup = nfit_test1_setup;
1554 pdev = &nfit_test->pdev;
1555 pdev->name = KBUILD_MODNAME;
1557 pdev->dev.release = nfit_test_release;
1558 rc = platform_device_register(pdev);
1560 put_device(&pdev->dev);
1564 rc = dma_coerce_mask_and_coherent(&pdev->dev, DMA_BIT_MASK(64));
1568 instances[i] = nfit_test;
1571 rc = platform_driver_register(&nfit_test_driver);
1577 for (i = 0; i < NUM_NFITS; i++)
1579 platform_device_unregister(&instances[i]->pdev);
1580 nfit_test_teardown();
1584 static __exit void nfit_test_exit(void)
1588 platform_driver_unregister(&nfit_test_driver);
1589 for (i = 0; i < NUM_NFITS; i++)
1590 platform_device_unregister(&instances[i]->pdev);
1591 nfit_test_teardown();
1594 module_init(nfit_test_init);
1595 module_exit(nfit_test_exit);
1596 MODULE_LICENSE("GPL v2");
1597 MODULE_AUTHOR("Intel Corporation");