nfit-test: Add platform cap support from ACPI 6.2a to test
[sfrench/cifs-2.6.git] / tools / testing / nvdimm / test / nfit.c
1 /*
2  * Copyright(c) 2013-2015 Intel Corporation. All rights reserved.
3  *
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.
7  *
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.
12  */
13 #define pr_fmt(fmt) KBUILD_MODNAME ": " fmt
14 #include <linux/platform_device.h>
15 #include <linux/dma-mapping.h>
16 #include <linux/workqueue.h>
17 #include <linux/libnvdimm.h>
18 #include <linux/vmalloc.h>
19 #include <linux/device.h>
20 #include <linux/module.h>
21 #include <linux/mutex.h>
22 #include <linux/ndctl.h>
23 #include <linux/sizes.h>
24 #include <linux/list.h>
25 #include <linux/slab.h>
26 #include <nd-core.h>
27 #include <nfit.h>
28 #include <nd.h>
29 #include "nfit_test.h"
30
31 /*
32  * Generate an NFIT table to describe the following topology:
33  *
34  * BUS0: Interleaved PMEM regions, and aliasing with BLK regions
35  *
36  *                     (a)                       (b)            DIMM   BLK-REGION
37  *           +----------+--------------+----------+---------+
38  * +------+  |  blk2.0  |     pm0.0    |  blk2.1  |  pm1.0  |    0      region2
39  * | imc0 +--+- - - - - region0 - - - -+----------+         +
40  * +--+---+  |  blk3.0  |     pm0.0    |  blk3.1  |  pm1.0  |    1      region3
41  *    |      +----------+--------------v----------v         v
42  * +--+---+                            |                    |
43  * | cpu0 |                                    region1
44  * +--+---+                            |                    |
45  *    |      +-------------------------^----------^         ^
46  * +--+---+  |                 blk4.0             |  pm1.0  |    2      region4
47  * | imc1 +--+-------------------------+----------+         +
48  * +------+  |                 blk5.0             |  pm1.0  |    3      region5
49  *           +-------------------------+----------+-+-------+
50  *
51  * +--+---+
52  * | cpu1 |
53  * +--+---+                   (Hotplug DIMM)
54  *    |      +----------------------------------------------+
55  * +--+---+  |                 blk6.0/pm7.0                 |    4      region6/7
56  * | imc0 +--+----------------------------------------------+
57  * +------+
58  *
59  *
60  * *) In this layout we have four dimms and two memory controllers in one
61  *    socket.  Each unique interface (BLK or PMEM) to DPA space
62  *    is identified by a region device with a dynamically assigned id.
63  *
64  * *) The first portion of dimm0 and dimm1 are interleaved as REGION0.
65  *    A single PMEM namespace "pm0.0" is created using half of the
66  *    REGION0 SPA-range.  REGION0 spans dimm0 and dimm1.  PMEM namespace
67  *    allocate from from the bottom of a region.  The unallocated
68  *    portion of REGION0 aliases with REGION2 and REGION3.  That
69  *    unallacted capacity is reclaimed as BLK namespaces ("blk2.0" and
70  *    "blk3.0") starting at the base of each DIMM to offset (a) in those
71  *    DIMMs.  "pm0.0", "blk2.0" and "blk3.0" are free-form readable
72  *    names that can be assigned to a namespace.
73  *
74  * *) In the last portion of dimm0 and dimm1 we have an interleaved
75  *    SPA range, REGION1, that spans those two dimms as well as dimm2
76  *    and dimm3.  Some of REGION1 allocated to a PMEM namespace named
77  *    "pm1.0" the rest is reclaimed in 4 BLK namespaces (for each
78  *    dimm in the interleave set), "blk2.1", "blk3.1", "blk4.0", and
79  *    "blk5.0".
80  *
81  * *) The portion of dimm2 and dimm3 that do not participate in the
82  *    REGION1 interleaved SPA range (i.e. the DPA address below offset
83  *    (b) are also included in the "blk4.0" and "blk5.0" namespaces.
84  *    Note, that BLK namespaces need not be contiguous in DPA-space, and
85  *    can consume aliased capacity from multiple interleave sets.
86  *
87  * BUS1: Legacy NVDIMM (single contiguous range)
88  *
89  *  region2
90  * +---------------------+
91  * |---------------------|
92  * ||       pm2.0       ||
93  * |---------------------|
94  * +---------------------+
95  *
96  * *) A NFIT-table may describe a simple system-physical-address range
97  *    with no BLK aliasing.  This type of region may optionally
98  *    reference an NVDIMM.
99  */
100 enum {
101         NUM_PM  = 3,
102         NUM_DCR = 5,
103         NUM_HINTS = 8,
104         NUM_BDW = NUM_DCR,
105         NUM_SPA = NUM_PM + NUM_DCR + NUM_BDW,
106         NUM_MEM = NUM_DCR + NUM_BDW + 2 /* spa0 iset */ + 4 /* spa1 iset */,
107         DIMM_SIZE = SZ_32M,
108         LABEL_SIZE = SZ_128K,
109         SPA_VCD_SIZE = SZ_4M,
110         SPA0_SIZE = DIMM_SIZE,
111         SPA1_SIZE = DIMM_SIZE*2,
112         SPA2_SIZE = DIMM_SIZE,
113         BDW_SIZE = 64 << 8,
114         DCR_SIZE = 12,
115         NUM_NFITS = 2, /* permit testing multiple NFITs per system */
116 };
117
118 struct nfit_test_dcr {
119         __le64 bdw_addr;
120         __le32 bdw_status;
121         __u8 aperature[BDW_SIZE];
122 };
123
124 #define NFIT_DIMM_HANDLE(node, socket, imc, chan, dimm) \
125         (((node & 0xfff) << 16) | ((socket & 0xf) << 12) \
126          | ((imc & 0xf) << 8) | ((chan & 0xf) << 4) | (dimm & 0xf))
127
128 static u32 handle[] = {
129         [0] = NFIT_DIMM_HANDLE(0, 0, 0, 0, 0),
130         [1] = NFIT_DIMM_HANDLE(0, 0, 0, 0, 1),
131         [2] = NFIT_DIMM_HANDLE(0, 0, 1, 0, 0),
132         [3] = NFIT_DIMM_HANDLE(0, 0, 1, 0, 1),
133         [4] = NFIT_DIMM_HANDLE(0, 1, 0, 0, 0),
134         [5] = NFIT_DIMM_HANDLE(1, 0, 0, 0, 0),
135         [6] = NFIT_DIMM_HANDLE(1, 0, 0, 0, 1),
136 };
137
138 static unsigned long dimm_fail_cmd_flags[NUM_DCR];
139
140 struct nfit_test {
141         struct acpi_nfit_desc acpi_desc;
142         struct platform_device pdev;
143         struct list_head resources;
144         void *nfit_buf;
145         dma_addr_t nfit_dma;
146         size_t nfit_size;
147         int dcr_idx;
148         int num_dcr;
149         int num_pm;
150         void **dimm;
151         dma_addr_t *dimm_dma;
152         void **flush;
153         dma_addr_t *flush_dma;
154         void **label;
155         dma_addr_t *label_dma;
156         void **spa_set;
157         dma_addr_t *spa_set_dma;
158         struct nfit_test_dcr **dcr;
159         dma_addr_t *dcr_dma;
160         int (*alloc)(struct nfit_test *t);
161         void (*setup)(struct nfit_test *t);
162         int setup_hotplug;
163         union acpi_object **_fit;
164         dma_addr_t _fit_dma;
165         struct ars_state {
166                 struct nd_cmd_ars_status *ars_status;
167                 unsigned long deadline;
168                 spinlock_t lock;
169         } ars_state;
170         struct device *dimm_dev[NUM_DCR];
171         struct badrange badrange;
172         struct work_struct work;
173 };
174
175 static struct workqueue_struct *nfit_wq;
176
177 static struct nfit_test *to_nfit_test(struct device *dev)
178 {
179         struct platform_device *pdev = to_platform_device(dev);
180
181         return container_of(pdev, struct nfit_test, pdev);
182 }
183
184 static int nfit_test_cmd_get_config_size(struct nd_cmd_get_config_size *nd_cmd,
185                 unsigned int buf_len)
186 {
187         if (buf_len < sizeof(*nd_cmd))
188                 return -EINVAL;
189
190         nd_cmd->status = 0;
191         nd_cmd->config_size = LABEL_SIZE;
192         nd_cmd->max_xfer = SZ_4K;
193
194         return 0;
195 }
196
197 static int nfit_test_cmd_get_config_data(struct nd_cmd_get_config_data_hdr
198                 *nd_cmd, unsigned int buf_len, void *label)
199 {
200         unsigned int len, offset = nd_cmd->in_offset;
201         int rc;
202
203         if (buf_len < sizeof(*nd_cmd))
204                 return -EINVAL;
205         if (offset >= LABEL_SIZE)
206                 return -EINVAL;
207         if (nd_cmd->in_length + sizeof(*nd_cmd) > buf_len)
208                 return -EINVAL;
209
210         nd_cmd->status = 0;
211         len = min(nd_cmd->in_length, LABEL_SIZE - offset);
212         memcpy(nd_cmd->out_buf, label + offset, len);
213         rc = buf_len - sizeof(*nd_cmd) - len;
214
215         return rc;
216 }
217
218 static int nfit_test_cmd_set_config_data(struct nd_cmd_set_config_hdr *nd_cmd,
219                 unsigned int buf_len, void *label)
220 {
221         unsigned int len, offset = nd_cmd->in_offset;
222         u32 *status;
223         int rc;
224
225         if (buf_len < sizeof(*nd_cmd))
226                 return -EINVAL;
227         if (offset >= LABEL_SIZE)
228                 return -EINVAL;
229         if (nd_cmd->in_length + sizeof(*nd_cmd) + 4 > buf_len)
230                 return -EINVAL;
231
232         status = (void *)nd_cmd + nd_cmd->in_length + sizeof(*nd_cmd);
233         *status = 0;
234         len = min(nd_cmd->in_length, LABEL_SIZE - offset);
235         memcpy(label + offset, nd_cmd->in_buf, len);
236         rc = buf_len - sizeof(*nd_cmd) - (len + 4);
237
238         return rc;
239 }
240
241 #define NFIT_TEST_CLEAR_ERR_UNIT 256
242
243 static int nfit_test_cmd_ars_cap(struct nd_cmd_ars_cap *nd_cmd,
244                 unsigned int buf_len)
245 {
246         int ars_recs;
247
248         if (buf_len < sizeof(*nd_cmd))
249                 return -EINVAL;
250
251         /* for testing, only store up to n records that fit within 4k */
252         ars_recs = SZ_4K / sizeof(struct nd_ars_record);
253
254         nd_cmd->max_ars_out = sizeof(struct nd_cmd_ars_status)
255                 + ars_recs * sizeof(struct nd_ars_record);
256         nd_cmd->status = (ND_ARS_PERSISTENT | ND_ARS_VOLATILE) << 16;
257         nd_cmd->clear_err_unit = NFIT_TEST_CLEAR_ERR_UNIT;
258
259         return 0;
260 }
261
262 static void post_ars_status(struct ars_state *ars_state,
263                 struct badrange *badrange, u64 addr, u64 len)
264 {
265         struct nd_cmd_ars_status *ars_status;
266         struct nd_ars_record *ars_record;
267         struct badrange_entry *be;
268         u64 end = addr + len - 1;
269         int i = 0;
270
271         ars_state->deadline = jiffies + 1*HZ;
272         ars_status = ars_state->ars_status;
273         ars_status->status = 0;
274         ars_status->address = addr;
275         ars_status->length = len;
276         ars_status->type = ND_ARS_PERSISTENT;
277
278         spin_lock(&badrange->lock);
279         list_for_each_entry(be, &badrange->list, list) {
280                 u64 be_end = be->start + be->length - 1;
281                 u64 rstart, rend;
282
283                 /* skip entries outside the range */
284                 if (be_end < addr || be->start > end)
285                         continue;
286
287                 rstart = (be->start < addr) ? addr : be->start;
288                 rend = (be_end < end) ? be_end : end;
289                 ars_record = &ars_status->records[i];
290                 ars_record->handle = 0;
291                 ars_record->err_address = rstart;
292                 ars_record->length = rend - rstart + 1;
293                 i++;
294         }
295         spin_unlock(&badrange->lock);
296         ars_status->num_records = i;
297         ars_status->out_length = sizeof(struct nd_cmd_ars_status)
298                 + i * sizeof(struct nd_ars_record);
299 }
300
301 static int nfit_test_cmd_ars_start(struct nfit_test *t,
302                 struct ars_state *ars_state,
303                 struct nd_cmd_ars_start *ars_start, unsigned int buf_len,
304                 int *cmd_rc)
305 {
306         if (buf_len < sizeof(*ars_start))
307                 return -EINVAL;
308
309         spin_lock(&ars_state->lock);
310         if (time_before(jiffies, ars_state->deadline)) {
311                 ars_start->status = NFIT_ARS_START_BUSY;
312                 *cmd_rc = -EBUSY;
313         } else {
314                 ars_start->status = 0;
315                 ars_start->scrub_time = 1;
316                 post_ars_status(ars_state, &t->badrange, ars_start->address,
317                                 ars_start->length);
318                 *cmd_rc = 0;
319         }
320         spin_unlock(&ars_state->lock);
321
322         return 0;
323 }
324
325 static int nfit_test_cmd_ars_status(struct ars_state *ars_state,
326                 struct nd_cmd_ars_status *ars_status, unsigned int buf_len,
327                 int *cmd_rc)
328 {
329         if (buf_len < ars_state->ars_status->out_length)
330                 return -EINVAL;
331
332         spin_lock(&ars_state->lock);
333         if (time_before(jiffies, ars_state->deadline)) {
334                 memset(ars_status, 0, buf_len);
335                 ars_status->status = NFIT_ARS_STATUS_BUSY;
336                 ars_status->out_length = sizeof(*ars_status);
337                 *cmd_rc = -EBUSY;
338         } else {
339                 memcpy(ars_status, ars_state->ars_status,
340                                 ars_state->ars_status->out_length);
341                 *cmd_rc = 0;
342         }
343         spin_unlock(&ars_state->lock);
344         return 0;
345 }
346
347 static int nfit_test_cmd_clear_error(struct nfit_test *t,
348                 struct nd_cmd_clear_error *clear_err,
349                 unsigned int buf_len, int *cmd_rc)
350 {
351         const u64 mask = NFIT_TEST_CLEAR_ERR_UNIT - 1;
352         if (buf_len < sizeof(*clear_err))
353                 return -EINVAL;
354
355         if ((clear_err->address & mask) || (clear_err->length & mask))
356                 return -EINVAL;
357
358         badrange_forget(&t->badrange, clear_err->address, clear_err->length);
359         clear_err->status = 0;
360         clear_err->cleared = clear_err->length;
361         *cmd_rc = 0;
362         return 0;
363 }
364
365 struct region_search_spa {
366         u64 addr;
367         struct nd_region *region;
368 };
369
370 static int is_region_device(struct device *dev)
371 {
372         return !strncmp(dev->kobj.name, "region", 6);
373 }
374
375 static int nfit_test_search_region_spa(struct device *dev, void *data)
376 {
377         struct region_search_spa *ctx = data;
378         struct nd_region *nd_region;
379         resource_size_t ndr_end;
380
381         if (!is_region_device(dev))
382                 return 0;
383
384         nd_region = to_nd_region(dev);
385         ndr_end = nd_region->ndr_start + nd_region->ndr_size;
386
387         if (ctx->addr >= nd_region->ndr_start && ctx->addr < ndr_end) {
388                 ctx->region = nd_region;
389                 return 1;
390         }
391
392         return 0;
393 }
394
395 static int nfit_test_search_spa(struct nvdimm_bus *bus,
396                 struct nd_cmd_translate_spa *spa)
397 {
398         int ret;
399         struct nd_region *nd_region = NULL;
400         struct nvdimm *nvdimm = NULL;
401         struct nd_mapping *nd_mapping = NULL;
402         struct region_search_spa ctx = {
403                 .addr = spa->spa,
404                 .region = NULL,
405         };
406         u64 dpa;
407
408         ret = device_for_each_child(&bus->dev, &ctx,
409                                 nfit_test_search_region_spa);
410
411         if (!ret)
412                 return -ENODEV;
413
414         nd_region = ctx.region;
415
416         dpa = ctx.addr - nd_region->ndr_start;
417
418         /*
419          * last dimm is selected for test
420          */
421         nd_mapping = &nd_region->mapping[nd_region->ndr_mappings - 1];
422         nvdimm = nd_mapping->nvdimm;
423
424         spa->devices[0].nfit_device_handle = handle[nvdimm->id];
425         spa->num_nvdimms = 1;
426         spa->devices[0].dpa = dpa;
427
428         return 0;
429 }
430
431 static int nfit_test_cmd_translate_spa(struct nvdimm_bus *bus,
432                 struct nd_cmd_translate_spa *spa, unsigned int buf_len)
433 {
434         if (buf_len < spa->translate_length)
435                 return -EINVAL;
436
437         if (nfit_test_search_spa(bus, spa) < 0 || !spa->num_nvdimms)
438                 spa->status = 2;
439
440         return 0;
441 }
442
443 static int nfit_test_cmd_smart(struct nd_cmd_smart *smart, unsigned int buf_len)
444 {
445         static const struct nd_smart_payload smart_data = {
446                 .flags = ND_SMART_HEALTH_VALID | ND_SMART_TEMP_VALID
447                         | ND_SMART_SPARES_VALID | ND_SMART_ALARM_VALID
448                         | ND_SMART_USED_VALID | ND_SMART_SHUTDOWN_VALID,
449                 .health = ND_SMART_NON_CRITICAL_HEALTH,
450                 .temperature = 23 * 16,
451                 .spares = 75,
452                 .alarm_flags = ND_SMART_SPARE_TRIP | ND_SMART_TEMP_TRIP,
453                 .life_used = 5,
454                 .shutdown_state = 0,
455                 .vendor_size = 0,
456         };
457
458         if (buf_len < sizeof(*smart))
459                 return -EINVAL;
460         memcpy(smart->data, &smart_data, sizeof(smart_data));
461         return 0;
462 }
463
464 static int nfit_test_cmd_smart_threshold(struct nd_cmd_smart_threshold *smart_t,
465                 unsigned int buf_len)
466 {
467         static const struct nd_smart_threshold_payload smart_t_data = {
468                 .alarm_control = ND_SMART_SPARE_TRIP | ND_SMART_TEMP_TRIP,
469                 .temperature = 40 * 16,
470                 .spares = 5,
471         };
472
473         if (buf_len < sizeof(*smart_t))
474                 return -EINVAL;
475         memcpy(smart_t->data, &smart_t_data, sizeof(smart_t_data));
476         return 0;
477 }
478
479 static void uc_error_notify(struct work_struct *work)
480 {
481         struct nfit_test *t = container_of(work, typeof(*t), work);
482
483         __acpi_nfit_notify(&t->pdev.dev, t, NFIT_NOTIFY_UC_MEMORY_ERROR);
484 }
485
486 static int nfit_test_cmd_ars_error_inject(struct nfit_test *t,
487                 struct nd_cmd_ars_err_inj *err_inj, unsigned int buf_len)
488 {
489         int rc;
490
491         if (buf_len != sizeof(*err_inj)) {
492                 rc = -EINVAL;
493                 goto err;
494         }
495
496         if (err_inj->err_inj_spa_range_length <= 0) {
497                 rc = -EINVAL;
498                 goto err;
499         }
500
501         rc =  badrange_add(&t->badrange, err_inj->err_inj_spa_range_base,
502                         err_inj->err_inj_spa_range_length);
503         if (rc < 0)
504                 goto err;
505
506         if (err_inj->err_inj_options & (1 << ND_ARS_ERR_INJ_OPT_NOTIFY))
507                 queue_work(nfit_wq, &t->work);
508
509         err_inj->status = 0;
510         return 0;
511
512 err:
513         err_inj->status = NFIT_ARS_INJECT_INVALID;
514         return rc;
515 }
516
517 static int nfit_test_cmd_ars_inject_clear(struct nfit_test *t,
518                 struct nd_cmd_ars_err_inj_clr *err_clr, unsigned int buf_len)
519 {
520         int rc;
521
522         if (buf_len != sizeof(*err_clr)) {
523                 rc = -EINVAL;
524                 goto err;
525         }
526
527         if (err_clr->err_inj_clr_spa_range_length <= 0) {
528                 rc = -EINVAL;
529                 goto err;
530         }
531
532         badrange_forget(&t->badrange, err_clr->err_inj_clr_spa_range_base,
533                         err_clr->err_inj_clr_spa_range_length);
534
535         err_clr->status = 0;
536         return 0;
537
538 err:
539         err_clr->status = NFIT_ARS_INJECT_INVALID;
540         return rc;
541 }
542
543 static int nfit_test_cmd_ars_inject_status(struct nfit_test *t,
544                 struct nd_cmd_ars_err_inj_stat *err_stat,
545                 unsigned int buf_len)
546 {
547         struct badrange_entry *be;
548         int max = SZ_4K / sizeof(struct nd_error_stat_query_record);
549         int i = 0;
550
551         err_stat->status = 0;
552         spin_lock(&t->badrange.lock);
553         list_for_each_entry(be, &t->badrange.list, list) {
554                 err_stat->record[i].err_inj_stat_spa_range_base = be->start;
555                 err_stat->record[i].err_inj_stat_spa_range_length = be->length;
556                 i++;
557                 if (i > max)
558                         break;
559         }
560         spin_unlock(&t->badrange.lock);
561         err_stat->inj_err_rec_count = i;
562
563         return 0;
564 }
565
566 static int nfit_test_ctl(struct nvdimm_bus_descriptor *nd_desc,
567                 struct nvdimm *nvdimm, unsigned int cmd, void *buf,
568                 unsigned int buf_len, int *cmd_rc)
569 {
570         struct acpi_nfit_desc *acpi_desc = to_acpi_desc(nd_desc);
571         struct nfit_test *t = container_of(acpi_desc, typeof(*t), acpi_desc);
572         unsigned int func = cmd;
573         int i, rc = 0, __cmd_rc;
574
575         if (!cmd_rc)
576                 cmd_rc = &__cmd_rc;
577         *cmd_rc = 0;
578
579         if (nvdimm) {
580                 struct nfit_mem *nfit_mem = nvdimm_provider_data(nvdimm);
581                 unsigned long cmd_mask = nvdimm_cmd_mask(nvdimm);
582
583                 if (!nfit_mem)
584                         return -ENOTTY;
585
586                 if (cmd == ND_CMD_CALL) {
587                         struct nd_cmd_pkg *call_pkg = buf;
588
589                         buf_len = call_pkg->nd_size_in + call_pkg->nd_size_out;
590                         buf = (void *) call_pkg->nd_payload;
591                         func = call_pkg->nd_command;
592                         if (call_pkg->nd_family != nfit_mem->family)
593                                 return -ENOTTY;
594                 }
595
596                 if (!test_bit(cmd, &cmd_mask)
597                                 || !test_bit(func, &nfit_mem->dsm_mask))
598                         return -ENOTTY;
599
600                 /* lookup label space for the given dimm */
601                 for (i = 0; i < ARRAY_SIZE(handle); i++)
602                         if (__to_nfit_memdev(nfit_mem)->device_handle ==
603                                         handle[i])
604                                 break;
605                 if (i >= ARRAY_SIZE(handle))
606                         return -ENXIO;
607
608                 if ((1 << func) & dimm_fail_cmd_flags[i])
609                         return -EIO;
610
611                 switch (func) {
612                 case ND_CMD_GET_CONFIG_SIZE:
613                         rc = nfit_test_cmd_get_config_size(buf, buf_len);
614                         break;
615                 case ND_CMD_GET_CONFIG_DATA:
616                         rc = nfit_test_cmd_get_config_data(buf, buf_len,
617                                 t->label[i - t->dcr_idx]);
618                         break;
619                 case ND_CMD_SET_CONFIG_DATA:
620                         rc = nfit_test_cmd_set_config_data(buf, buf_len,
621                                 t->label[i - t->dcr_idx]);
622                         break;
623                 case ND_CMD_SMART:
624                         rc = nfit_test_cmd_smart(buf, buf_len);
625                         break;
626                 case ND_CMD_SMART_THRESHOLD:
627                         rc = nfit_test_cmd_smart_threshold(buf, buf_len);
628                         device_lock(&t->pdev.dev);
629                         __acpi_nvdimm_notify(t->dimm_dev[i], 0x81);
630                         device_unlock(&t->pdev.dev);
631                         break;
632                 default:
633                         return -ENOTTY;
634                 }
635         } else {
636                 struct ars_state *ars_state = &t->ars_state;
637                 struct nd_cmd_pkg *call_pkg = buf;
638
639                 if (!nd_desc)
640                         return -ENOTTY;
641
642                 if (cmd == ND_CMD_CALL) {
643                         func = call_pkg->nd_command;
644
645                         buf_len = call_pkg->nd_size_in + call_pkg->nd_size_out;
646                         buf = (void *) call_pkg->nd_payload;
647
648                         switch (func) {
649                         case NFIT_CMD_TRANSLATE_SPA:
650                                 rc = nfit_test_cmd_translate_spa(
651                                         acpi_desc->nvdimm_bus, buf, buf_len);
652                                 return rc;
653                         case NFIT_CMD_ARS_INJECT_SET:
654                                 rc = nfit_test_cmd_ars_error_inject(t, buf,
655                                         buf_len);
656                                 return rc;
657                         case NFIT_CMD_ARS_INJECT_CLEAR:
658                                 rc = nfit_test_cmd_ars_inject_clear(t, buf,
659                                         buf_len);
660                                 return rc;
661                         case NFIT_CMD_ARS_INJECT_GET:
662                                 rc = nfit_test_cmd_ars_inject_status(t, buf,
663                                         buf_len);
664                                 return rc;
665                         default:
666                                 return -ENOTTY;
667                         }
668                 }
669
670                 if (!nd_desc || !test_bit(cmd, &nd_desc->cmd_mask))
671                         return -ENOTTY;
672
673                 switch (func) {
674                 case ND_CMD_ARS_CAP:
675                         rc = nfit_test_cmd_ars_cap(buf, buf_len);
676                         break;
677                 case ND_CMD_ARS_START:
678                         rc = nfit_test_cmd_ars_start(t, ars_state, buf,
679                                         buf_len, cmd_rc);
680                         break;
681                 case ND_CMD_ARS_STATUS:
682                         rc = nfit_test_cmd_ars_status(ars_state, buf, buf_len,
683                                         cmd_rc);
684                         break;
685                 case ND_CMD_CLEAR_ERROR:
686                         rc = nfit_test_cmd_clear_error(t, buf, buf_len, cmd_rc);
687                         break;
688                 default:
689                         return -ENOTTY;
690                 }
691         }
692
693         return rc;
694 }
695
696 static DEFINE_SPINLOCK(nfit_test_lock);
697 static struct nfit_test *instances[NUM_NFITS];
698
699 static void release_nfit_res(void *data)
700 {
701         struct nfit_test_resource *nfit_res = data;
702
703         spin_lock(&nfit_test_lock);
704         list_del(&nfit_res->list);
705         spin_unlock(&nfit_test_lock);
706
707         vfree(nfit_res->buf);
708         kfree(nfit_res);
709 }
710
711 static void *__test_alloc(struct nfit_test *t, size_t size, dma_addr_t *dma,
712                 void *buf)
713 {
714         struct device *dev = &t->pdev.dev;
715         struct nfit_test_resource *nfit_res = kzalloc(sizeof(*nfit_res),
716                         GFP_KERNEL);
717         int rc;
718
719         if (!buf || !nfit_res)
720                 goto err;
721         rc = devm_add_action(dev, release_nfit_res, nfit_res);
722         if (rc)
723                 goto err;
724         INIT_LIST_HEAD(&nfit_res->list);
725         memset(buf, 0, size);
726         nfit_res->dev = dev;
727         nfit_res->buf = buf;
728         nfit_res->res.start = *dma;
729         nfit_res->res.end = *dma + size - 1;
730         nfit_res->res.name = "NFIT";
731         spin_lock_init(&nfit_res->lock);
732         INIT_LIST_HEAD(&nfit_res->requests);
733         spin_lock(&nfit_test_lock);
734         list_add(&nfit_res->list, &t->resources);
735         spin_unlock(&nfit_test_lock);
736
737         return nfit_res->buf;
738  err:
739         if (buf)
740                 vfree(buf);
741         kfree(nfit_res);
742         return NULL;
743 }
744
745 static void *test_alloc(struct nfit_test *t, size_t size, dma_addr_t *dma)
746 {
747         void *buf = vmalloc(size);
748
749         *dma = (unsigned long) buf;
750         return __test_alloc(t, size, dma, buf);
751 }
752
753 static struct nfit_test_resource *nfit_test_lookup(resource_size_t addr)
754 {
755         int i;
756
757         for (i = 0; i < ARRAY_SIZE(instances); i++) {
758                 struct nfit_test_resource *n, *nfit_res = NULL;
759                 struct nfit_test *t = instances[i];
760
761                 if (!t)
762                         continue;
763                 spin_lock(&nfit_test_lock);
764                 list_for_each_entry(n, &t->resources, list) {
765                         if (addr >= n->res.start && (addr < n->res.start
766                                                 + resource_size(&n->res))) {
767                                 nfit_res = n;
768                                 break;
769                         } else if (addr >= (unsigned long) n->buf
770                                         && (addr < (unsigned long) n->buf
771                                                 + resource_size(&n->res))) {
772                                 nfit_res = n;
773                                 break;
774                         }
775                 }
776                 spin_unlock(&nfit_test_lock);
777                 if (nfit_res)
778                         return nfit_res;
779         }
780
781         return NULL;
782 }
783
784 static int ars_state_init(struct device *dev, struct ars_state *ars_state)
785 {
786         /* for testing, only store up to n records that fit within 4k */
787         ars_state->ars_status = devm_kzalloc(dev,
788                         sizeof(struct nd_cmd_ars_status) + SZ_4K, GFP_KERNEL);
789         if (!ars_state->ars_status)
790                 return -ENOMEM;
791         spin_lock_init(&ars_state->lock);
792         return 0;
793 }
794
795 static void put_dimms(void *data)
796 {
797         struct device **dimm_dev = data;
798         int i;
799
800         for (i = 0; i < NUM_DCR; i++)
801                 if (dimm_dev[i])
802                         device_unregister(dimm_dev[i]);
803 }
804
805 static struct class *nfit_test_dimm;
806
807 static int dimm_name_to_id(struct device *dev)
808 {
809         int dimm;
810
811         if (sscanf(dev_name(dev), "test_dimm%d", &dimm) != 1
812                         || dimm >= NUM_DCR || dimm < 0)
813                 return -ENXIO;
814         return dimm;
815 }
816
817
818 static ssize_t handle_show(struct device *dev, struct device_attribute *attr,
819                 char *buf)
820 {
821         int dimm = dimm_name_to_id(dev);
822
823         if (dimm < 0)
824                 return dimm;
825
826         return sprintf(buf, "%#x", handle[dimm]);
827 }
828 DEVICE_ATTR_RO(handle);
829
830 static ssize_t fail_cmd_show(struct device *dev, struct device_attribute *attr,
831                 char *buf)
832 {
833         int dimm = dimm_name_to_id(dev);
834
835         if (dimm < 0)
836                 return dimm;
837
838         return sprintf(buf, "%#lx\n", dimm_fail_cmd_flags[dimm]);
839 }
840
841 static ssize_t fail_cmd_store(struct device *dev, struct device_attribute *attr,
842                 const char *buf, size_t size)
843 {
844         int dimm = dimm_name_to_id(dev);
845         unsigned long val;
846         ssize_t rc;
847
848         if (dimm < 0)
849                 return dimm;
850
851         rc = kstrtol(buf, 0, &val);
852         if (rc)
853                 return rc;
854
855         dimm_fail_cmd_flags[dimm] = val;
856         return size;
857 }
858 static DEVICE_ATTR_RW(fail_cmd);
859
860 static struct attribute *nfit_test_dimm_attributes[] = {
861         &dev_attr_fail_cmd.attr,
862         &dev_attr_handle.attr,
863         NULL,
864 };
865
866 static struct attribute_group nfit_test_dimm_attribute_group = {
867         .attrs = nfit_test_dimm_attributes,
868 };
869
870 static const struct attribute_group *nfit_test_dimm_attribute_groups[] = {
871         &nfit_test_dimm_attribute_group,
872         NULL,
873 };
874
875 static int nfit_test0_alloc(struct nfit_test *t)
876 {
877         size_t nfit_size = sizeof(struct acpi_nfit_system_address) * NUM_SPA
878                         + sizeof(struct acpi_nfit_memory_map) * NUM_MEM
879                         + sizeof(struct acpi_nfit_control_region) * NUM_DCR
880                         + offsetof(struct acpi_nfit_control_region,
881                                         window_size) * NUM_DCR
882                         + sizeof(struct acpi_nfit_data_region) * NUM_BDW
883                         + (sizeof(struct acpi_nfit_flush_address)
884                                         + sizeof(u64) * NUM_HINTS) * NUM_DCR
885                         + sizeof(struct acpi_nfit_capabilities);
886         int i;
887
888         t->nfit_buf = test_alloc(t, nfit_size, &t->nfit_dma);
889         if (!t->nfit_buf)
890                 return -ENOMEM;
891         t->nfit_size = nfit_size;
892
893         t->spa_set[0] = test_alloc(t, SPA0_SIZE, &t->spa_set_dma[0]);
894         if (!t->spa_set[0])
895                 return -ENOMEM;
896
897         t->spa_set[1] = test_alloc(t, SPA1_SIZE, &t->spa_set_dma[1]);
898         if (!t->spa_set[1])
899                 return -ENOMEM;
900
901         t->spa_set[2] = test_alloc(t, SPA0_SIZE, &t->spa_set_dma[2]);
902         if (!t->spa_set[2])
903                 return -ENOMEM;
904
905         for (i = 0; i < t->num_dcr; i++) {
906                 t->dimm[i] = test_alloc(t, DIMM_SIZE, &t->dimm_dma[i]);
907                 if (!t->dimm[i])
908                         return -ENOMEM;
909
910                 t->label[i] = test_alloc(t, LABEL_SIZE, &t->label_dma[i]);
911                 if (!t->label[i])
912                         return -ENOMEM;
913                 sprintf(t->label[i], "label%d", i);
914
915                 t->flush[i] = test_alloc(t, max(PAGE_SIZE,
916                                         sizeof(u64) * NUM_HINTS),
917                                 &t->flush_dma[i]);
918                 if (!t->flush[i])
919                         return -ENOMEM;
920         }
921
922         for (i = 0; i < t->num_dcr; i++) {
923                 t->dcr[i] = test_alloc(t, LABEL_SIZE, &t->dcr_dma[i]);
924                 if (!t->dcr[i])
925                         return -ENOMEM;
926         }
927
928         t->_fit = test_alloc(t, sizeof(union acpi_object **), &t->_fit_dma);
929         if (!t->_fit)
930                 return -ENOMEM;
931
932         if (devm_add_action_or_reset(&t->pdev.dev, put_dimms, t->dimm_dev))
933                 return -ENOMEM;
934         for (i = 0; i < NUM_DCR; i++) {
935                 t->dimm_dev[i] = device_create_with_groups(nfit_test_dimm,
936                                 &t->pdev.dev, 0, NULL,
937                                 nfit_test_dimm_attribute_groups,
938                                 "test_dimm%d", i);
939                 if (!t->dimm_dev[i])
940                         return -ENOMEM;
941         }
942
943         return ars_state_init(&t->pdev.dev, &t->ars_state);
944 }
945
946 static int nfit_test1_alloc(struct nfit_test *t)
947 {
948         size_t nfit_size = sizeof(struct acpi_nfit_system_address) * 2
949                 + sizeof(struct acpi_nfit_memory_map) * 2
950                 + offsetof(struct acpi_nfit_control_region, window_size) * 2;
951         int i;
952
953         t->nfit_buf = test_alloc(t, nfit_size, &t->nfit_dma);
954         if (!t->nfit_buf)
955                 return -ENOMEM;
956         t->nfit_size = nfit_size;
957
958         t->spa_set[0] = test_alloc(t, SPA2_SIZE, &t->spa_set_dma[0]);
959         if (!t->spa_set[0])
960                 return -ENOMEM;
961
962         for (i = 0; i < t->num_dcr; i++) {
963                 t->label[i] = test_alloc(t, LABEL_SIZE, &t->label_dma[i]);
964                 if (!t->label[i])
965                         return -ENOMEM;
966                 sprintf(t->label[i], "label%d", i);
967         }
968
969         t->spa_set[1] = test_alloc(t, SPA_VCD_SIZE, &t->spa_set_dma[1]);
970         if (!t->spa_set[1])
971                 return -ENOMEM;
972
973         return ars_state_init(&t->pdev.dev, &t->ars_state);
974 }
975
976 static void dcr_common_init(struct acpi_nfit_control_region *dcr)
977 {
978         dcr->vendor_id = 0xabcd;
979         dcr->device_id = 0;
980         dcr->revision_id = 1;
981         dcr->valid_fields = 1;
982         dcr->manufacturing_location = 0xa;
983         dcr->manufacturing_date = cpu_to_be16(2016);
984 }
985
986 static void nfit_test0_setup(struct nfit_test *t)
987 {
988         const int flush_hint_size = sizeof(struct acpi_nfit_flush_address)
989                 + (sizeof(u64) * NUM_HINTS);
990         struct acpi_nfit_desc *acpi_desc;
991         struct acpi_nfit_memory_map *memdev;
992         void *nfit_buf = t->nfit_buf;
993         struct acpi_nfit_system_address *spa;
994         struct acpi_nfit_control_region *dcr;
995         struct acpi_nfit_data_region *bdw;
996         struct acpi_nfit_flush_address *flush;
997         struct acpi_nfit_capabilities *pcap;
998         unsigned int offset, i;
999
1000         /*
1001          * spa0 (interleave first half of dimm0 and dimm1, note storage
1002          * does not actually alias the related block-data-window
1003          * regions)
1004          */
1005         spa = nfit_buf;
1006         spa->header.type = ACPI_NFIT_TYPE_SYSTEM_ADDRESS;
1007         spa->header.length = sizeof(*spa);
1008         memcpy(spa->range_guid, to_nfit_uuid(NFIT_SPA_PM), 16);
1009         spa->range_index = 0+1;
1010         spa->address = t->spa_set_dma[0];
1011         spa->length = SPA0_SIZE;
1012
1013         /*
1014          * spa1 (interleave last half of the 4 DIMMS, note storage
1015          * does not actually alias the related block-data-window
1016          * regions)
1017          */
1018         spa = nfit_buf + sizeof(*spa);
1019         spa->header.type = ACPI_NFIT_TYPE_SYSTEM_ADDRESS;
1020         spa->header.length = sizeof(*spa);
1021         memcpy(spa->range_guid, to_nfit_uuid(NFIT_SPA_PM), 16);
1022         spa->range_index = 1+1;
1023         spa->address = t->spa_set_dma[1];
1024         spa->length = SPA1_SIZE;
1025
1026         /* spa2 (dcr0) dimm0 */
1027         spa = nfit_buf + sizeof(*spa) * 2;
1028         spa->header.type = ACPI_NFIT_TYPE_SYSTEM_ADDRESS;
1029         spa->header.length = sizeof(*spa);
1030         memcpy(spa->range_guid, to_nfit_uuid(NFIT_SPA_DCR), 16);
1031         spa->range_index = 2+1;
1032         spa->address = t->dcr_dma[0];
1033         spa->length = DCR_SIZE;
1034
1035         /* spa3 (dcr1) dimm1 */
1036         spa = nfit_buf + sizeof(*spa) * 3;
1037         spa->header.type = ACPI_NFIT_TYPE_SYSTEM_ADDRESS;
1038         spa->header.length = sizeof(*spa);
1039         memcpy(spa->range_guid, to_nfit_uuid(NFIT_SPA_DCR), 16);
1040         spa->range_index = 3+1;
1041         spa->address = t->dcr_dma[1];
1042         spa->length = DCR_SIZE;
1043
1044         /* spa4 (dcr2) dimm2 */
1045         spa = nfit_buf + sizeof(*spa) * 4;
1046         spa->header.type = ACPI_NFIT_TYPE_SYSTEM_ADDRESS;
1047         spa->header.length = sizeof(*spa);
1048         memcpy(spa->range_guid, to_nfit_uuid(NFIT_SPA_DCR), 16);
1049         spa->range_index = 4+1;
1050         spa->address = t->dcr_dma[2];
1051         spa->length = DCR_SIZE;
1052
1053         /* spa5 (dcr3) dimm3 */
1054         spa = nfit_buf + sizeof(*spa) * 5;
1055         spa->header.type = ACPI_NFIT_TYPE_SYSTEM_ADDRESS;
1056         spa->header.length = sizeof(*spa);
1057         memcpy(spa->range_guid, to_nfit_uuid(NFIT_SPA_DCR), 16);
1058         spa->range_index = 5+1;
1059         spa->address = t->dcr_dma[3];
1060         spa->length = DCR_SIZE;
1061
1062         /* spa6 (bdw for dcr0) dimm0 */
1063         spa = nfit_buf + sizeof(*spa) * 6;
1064         spa->header.type = ACPI_NFIT_TYPE_SYSTEM_ADDRESS;
1065         spa->header.length = sizeof(*spa);
1066         memcpy(spa->range_guid, to_nfit_uuid(NFIT_SPA_BDW), 16);
1067         spa->range_index = 6+1;
1068         spa->address = t->dimm_dma[0];
1069         spa->length = DIMM_SIZE;
1070
1071         /* spa7 (bdw for dcr1) dimm1 */
1072         spa = nfit_buf + sizeof(*spa) * 7;
1073         spa->header.type = ACPI_NFIT_TYPE_SYSTEM_ADDRESS;
1074         spa->header.length = sizeof(*spa);
1075         memcpy(spa->range_guid, to_nfit_uuid(NFIT_SPA_BDW), 16);
1076         spa->range_index = 7+1;
1077         spa->address = t->dimm_dma[1];
1078         spa->length = DIMM_SIZE;
1079
1080         /* spa8 (bdw for dcr2) dimm2 */
1081         spa = nfit_buf + sizeof(*spa) * 8;
1082         spa->header.type = ACPI_NFIT_TYPE_SYSTEM_ADDRESS;
1083         spa->header.length = sizeof(*spa);
1084         memcpy(spa->range_guid, to_nfit_uuid(NFIT_SPA_BDW), 16);
1085         spa->range_index = 8+1;
1086         spa->address = t->dimm_dma[2];
1087         spa->length = DIMM_SIZE;
1088
1089         /* spa9 (bdw for dcr3) dimm3 */
1090         spa = nfit_buf + sizeof(*spa) * 9;
1091         spa->header.type = ACPI_NFIT_TYPE_SYSTEM_ADDRESS;
1092         spa->header.length = sizeof(*spa);
1093         memcpy(spa->range_guid, to_nfit_uuid(NFIT_SPA_BDW), 16);
1094         spa->range_index = 9+1;
1095         spa->address = t->dimm_dma[3];
1096         spa->length = DIMM_SIZE;
1097
1098         offset = sizeof(*spa) * 10;
1099         /* mem-region0 (spa0, dimm0) */
1100         memdev = nfit_buf + offset;
1101         memdev->header.type = ACPI_NFIT_TYPE_MEMORY_MAP;
1102         memdev->header.length = sizeof(*memdev);
1103         memdev->device_handle = handle[0];
1104         memdev->physical_id = 0;
1105         memdev->region_id = 0;
1106         memdev->range_index = 0+1;
1107         memdev->region_index = 4+1;
1108         memdev->region_size = SPA0_SIZE/2;
1109         memdev->region_offset = 1;
1110         memdev->address = 0;
1111         memdev->interleave_index = 0;
1112         memdev->interleave_ways = 2;
1113
1114         /* mem-region1 (spa0, dimm1) */
1115         memdev = nfit_buf + offset + sizeof(struct acpi_nfit_memory_map);
1116         memdev->header.type = ACPI_NFIT_TYPE_MEMORY_MAP;
1117         memdev->header.length = sizeof(*memdev);
1118         memdev->device_handle = handle[1];
1119         memdev->physical_id = 1;
1120         memdev->region_id = 0;
1121         memdev->range_index = 0+1;
1122         memdev->region_index = 5+1;
1123         memdev->region_size = SPA0_SIZE/2;
1124         memdev->region_offset = (1 << 8);
1125         memdev->address = 0;
1126         memdev->interleave_index = 0;
1127         memdev->interleave_ways = 2;
1128         memdev->flags = ACPI_NFIT_MEM_HEALTH_ENABLED;
1129
1130         /* mem-region2 (spa1, dimm0) */
1131         memdev = nfit_buf + offset + sizeof(struct acpi_nfit_memory_map) * 2;
1132         memdev->header.type = ACPI_NFIT_TYPE_MEMORY_MAP;
1133         memdev->header.length = sizeof(*memdev);
1134         memdev->device_handle = handle[0];
1135         memdev->physical_id = 0;
1136         memdev->region_id = 1;
1137         memdev->range_index = 1+1;
1138         memdev->region_index = 4+1;
1139         memdev->region_size = SPA1_SIZE/4;
1140         memdev->region_offset = (1 << 16);
1141         memdev->address = SPA0_SIZE/2;
1142         memdev->interleave_index = 0;
1143         memdev->interleave_ways = 4;
1144         memdev->flags = ACPI_NFIT_MEM_HEALTH_ENABLED;
1145
1146         /* mem-region3 (spa1, dimm1) */
1147         memdev = nfit_buf + offset + sizeof(struct acpi_nfit_memory_map) * 3;
1148         memdev->header.type = ACPI_NFIT_TYPE_MEMORY_MAP;
1149         memdev->header.length = sizeof(*memdev);
1150         memdev->device_handle = handle[1];
1151         memdev->physical_id = 1;
1152         memdev->region_id = 1;
1153         memdev->range_index = 1+1;
1154         memdev->region_index = 5+1;
1155         memdev->region_size = SPA1_SIZE/4;
1156         memdev->region_offset = (1 << 24);
1157         memdev->address = SPA0_SIZE/2;
1158         memdev->interleave_index = 0;
1159         memdev->interleave_ways = 4;
1160
1161         /* mem-region4 (spa1, dimm2) */
1162         memdev = nfit_buf + offset + sizeof(struct acpi_nfit_memory_map) * 4;
1163         memdev->header.type = ACPI_NFIT_TYPE_MEMORY_MAP;
1164         memdev->header.length = sizeof(*memdev);
1165         memdev->device_handle = handle[2];
1166         memdev->physical_id = 2;
1167         memdev->region_id = 0;
1168         memdev->range_index = 1+1;
1169         memdev->region_index = 6+1;
1170         memdev->region_size = SPA1_SIZE/4;
1171         memdev->region_offset = (1ULL << 32);
1172         memdev->address = SPA0_SIZE/2;
1173         memdev->interleave_index = 0;
1174         memdev->interleave_ways = 4;
1175         memdev->flags = ACPI_NFIT_MEM_HEALTH_ENABLED;
1176
1177         /* mem-region5 (spa1, dimm3) */
1178         memdev = nfit_buf + offset + sizeof(struct acpi_nfit_memory_map) * 5;
1179         memdev->header.type = ACPI_NFIT_TYPE_MEMORY_MAP;
1180         memdev->header.length = sizeof(*memdev);
1181         memdev->device_handle = handle[3];
1182         memdev->physical_id = 3;
1183         memdev->region_id = 0;
1184         memdev->range_index = 1+1;
1185         memdev->region_index = 7+1;
1186         memdev->region_size = SPA1_SIZE/4;
1187         memdev->region_offset = (1ULL << 40);
1188         memdev->address = SPA0_SIZE/2;
1189         memdev->interleave_index = 0;
1190         memdev->interleave_ways = 4;
1191
1192         /* mem-region6 (spa/dcr0, dimm0) */
1193         memdev = nfit_buf + offset + sizeof(struct acpi_nfit_memory_map) * 6;
1194         memdev->header.type = ACPI_NFIT_TYPE_MEMORY_MAP;
1195         memdev->header.length = sizeof(*memdev);
1196         memdev->device_handle = handle[0];
1197         memdev->physical_id = 0;
1198         memdev->region_id = 0;
1199         memdev->range_index = 2+1;
1200         memdev->region_index = 0+1;
1201         memdev->region_size = 0;
1202         memdev->region_offset = 0;
1203         memdev->address = 0;
1204         memdev->interleave_index = 0;
1205         memdev->interleave_ways = 1;
1206
1207         /* mem-region7 (spa/dcr1, dimm1) */
1208         memdev = nfit_buf + offset + sizeof(struct acpi_nfit_memory_map) * 7;
1209         memdev->header.type = ACPI_NFIT_TYPE_MEMORY_MAP;
1210         memdev->header.length = sizeof(*memdev);
1211         memdev->device_handle = handle[1];
1212         memdev->physical_id = 1;
1213         memdev->region_id = 0;
1214         memdev->range_index = 3+1;
1215         memdev->region_index = 1+1;
1216         memdev->region_size = 0;
1217         memdev->region_offset = 0;
1218         memdev->address = 0;
1219         memdev->interleave_index = 0;
1220         memdev->interleave_ways = 1;
1221
1222         /* mem-region8 (spa/dcr2, dimm2) */
1223         memdev = nfit_buf + offset + sizeof(struct acpi_nfit_memory_map) * 8;
1224         memdev->header.type = ACPI_NFIT_TYPE_MEMORY_MAP;
1225         memdev->header.length = sizeof(*memdev);
1226         memdev->device_handle = handle[2];
1227         memdev->physical_id = 2;
1228         memdev->region_id = 0;
1229         memdev->range_index = 4+1;
1230         memdev->region_index = 2+1;
1231         memdev->region_size = 0;
1232         memdev->region_offset = 0;
1233         memdev->address = 0;
1234         memdev->interleave_index = 0;
1235         memdev->interleave_ways = 1;
1236
1237         /* mem-region9 (spa/dcr3, dimm3) */
1238         memdev = nfit_buf + offset + sizeof(struct acpi_nfit_memory_map) * 9;
1239         memdev->header.type = ACPI_NFIT_TYPE_MEMORY_MAP;
1240         memdev->header.length = sizeof(*memdev);
1241         memdev->device_handle = handle[3];
1242         memdev->physical_id = 3;
1243         memdev->region_id = 0;
1244         memdev->range_index = 5+1;
1245         memdev->region_index = 3+1;
1246         memdev->region_size = 0;
1247         memdev->region_offset = 0;
1248         memdev->address = 0;
1249         memdev->interleave_index = 0;
1250         memdev->interleave_ways = 1;
1251
1252         /* mem-region10 (spa/bdw0, dimm0) */
1253         memdev = nfit_buf + offset + sizeof(struct acpi_nfit_memory_map) * 10;
1254         memdev->header.type = ACPI_NFIT_TYPE_MEMORY_MAP;
1255         memdev->header.length = sizeof(*memdev);
1256         memdev->device_handle = handle[0];
1257         memdev->physical_id = 0;
1258         memdev->region_id = 0;
1259         memdev->range_index = 6+1;
1260         memdev->region_index = 0+1;
1261         memdev->region_size = 0;
1262         memdev->region_offset = 0;
1263         memdev->address = 0;
1264         memdev->interleave_index = 0;
1265         memdev->interleave_ways = 1;
1266
1267         /* mem-region11 (spa/bdw1, dimm1) */
1268         memdev = nfit_buf + offset + sizeof(struct acpi_nfit_memory_map) * 11;
1269         memdev->header.type = ACPI_NFIT_TYPE_MEMORY_MAP;
1270         memdev->header.length = sizeof(*memdev);
1271         memdev->device_handle = handle[1];
1272         memdev->physical_id = 1;
1273         memdev->region_id = 0;
1274         memdev->range_index = 7+1;
1275         memdev->region_index = 1+1;
1276         memdev->region_size = 0;
1277         memdev->region_offset = 0;
1278         memdev->address = 0;
1279         memdev->interleave_index = 0;
1280         memdev->interleave_ways = 1;
1281
1282         /* mem-region12 (spa/bdw2, dimm2) */
1283         memdev = nfit_buf + offset + sizeof(struct acpi_nfit_memory_map) * 12;
1284         memdev->header.type = ACPI_NFIT_TYPE_MEMORY_MAP;
1285         memdev->header.length = sizeof(*memdev);
1286         memdev->device_handle = handle[2];
1287         memdev->physical_id = 2;
1288         memdev->region_id = 0;
1289         memdev->range_index = 8+1;
1290         memdev->region_index = 2+1;
1291         memdev->region_size = 0;
1292         memdev->region_offset = 0;
1293         memdev->address = 0;
1294         memdev->interleave_index = 0;
1295         memdev->interleave_ways = 1;
1296
1297         /* mem-region13 (spa/dcr3, dimm3) */
1298         memdev = nfit_buf + offset + sizeof(struct acpi_nfit_memory_map) * 13;
1299         memdev->header.type = ACPI_NFIT_TYPE_MEMORY_MAP;
1300         memdev->header.length = sizeof(*memdev);
1301         memdev->device_handle = handle[3];
1302         memdev->physical_id = 3;
1303         memdev->region_id = 0;
1304         memdev->range_index = 9+1;
1305         memdev->region_index = 3+1;
1306         memdev->region_size = 0;
1307         memdev->region_offset = 0;
1308         memdev->address = 0;
1309         memdev->interleave_index = 0;
1310         memdev->interleave_ways = 1;
1311         memdev->flags = ACPI_NFIT_MEM_HEALTH_ENABLED;
1312
1313         offset = offset + sizeof(struct acpi_nfit_memory_map) * 14;
1314         /* dcr-descriptor0: blk */
1315         dcr = nfit_buf + offset;
1316         dcr->header.type = ACPI_NFIT_TYPE_CONTROL_REGION;
1317         dcr->header.length = sizeof(struct acpi_nfit_control_region);
1318         dcr->region_index = 0+1;
1319         dcr_common_init(dcr);
1320         dcr->serial_number = ~handle[0];
1321         dcr->code = NFIT_FIC_BLK;
1322         dcr->windows = 1;
1323         dcr->window_size = DCR_SIZE;
1324         dcr->command_offset = 0;
1325         dcr->command_size = 8;
1326         dcr->status_offset = 8;
1327         dcr->status_size = 4;
1328
1329         /* dcr-descriptor1: blk */
1330         dcr = nfit_buf + offset + sizeof(struct acpi_nfit_control_region);
1331         dcr->header.type = ACPI_NFIT_TYPE_CONTROL_REGION;
1332         dcr->header.length = sizeof(struct acpi_nfit_control_region);
1333         dcr->region_index = 1+1;
1334         dcr_common_init(dcr);
1335         dcr->serial_number = ~handle[1];
1336         dcr->code = NFIT_FIC_BLK;
1337         dcr->windows = 1;
1338         dcr->window_size = DCR_SIZE;
1339         dcr->command_offset = 0;
1340         dcr->command_size = 8;
1341         dcr->status_offset = 8;
1342         dcr->status_size = 4;
1343
1344         /* dcr-descriptor2: blk */
1345         dcr = nfit_buf + offset + sizeof(struct acpi_nfit_control_region) * 2;
1346         dcr->header.type = ACPI_NFIT_TYPE_CONTROL_REGION;
1347         dcr->header.length = sizeof(struct acpi_nfit_control_region);
1348         dcr->region_index = 2+1;
1349         dcr_common_init(dcr);
1350         dcr->serial_number = ~handle[2];
1351         dcr->code = NFIT_FIC_BLK;
1352         dcr->windows = 1;
1353         dcr->window_size = DCR_SIZE;
1354         dcr->command_offset = 0;
1355         dcr->command_size = 8;
1356         dcr->status_offset = 8;
1357         dcr->status_size = 4;
1358
1359         /* dcr-descriptor3: blk */
1360         dcr = nfit_buf + offset + sizeof(struct acpi_nfit_control_region) * 3;
1361         dcr->header.type = ACPI_NFIT_TYPE_CONTROL_REGION;
1362         dcr->header.length = sizeof(struct acpi_nfit_control_region);
1363         dcr->region_index = 3+1;
1364         dcr_common_init(dcr);
1365         dcr->serial_number = ~handle[3];
1366         dcr->code = NFIT_FIC_BLK;
1367         dcr->windows = 1;
1368         dcr->window_size = DCR_SIZE;
1369         dcr->command_offset = 0;
1370         dcr->command_size = 8;
1371         dcr->status_offset = 8;
1372         dcr->status_size = 4;
1373
1374         offset = offset + sizeof(struct acpi_nfit_control_region) * 4;
1375         /* dcr-descriptor0: pmem */
1376         dcr = nfit_buf + offset;
1377         dcr->header.type = ACPI_NFIT_TYPE_CONTROL_REGION;
1378         dcr->header.length = offsetof(struct acpi_nfit_control_region,
1379                         window_size);
1380         dcr->region_index = 4+1;
1381         dcr_common_init(dcr);
1382         dcr->serial_number = ~handle[0];
1383         dcr->code = NFIT_FIC_BYTEN;
1384         dcr->windows = 0;
1385
1386         /* dcr-descriptor1: pmem */
1387         dcr = nfit_buf + offset + offsetof(struct acpi_nfit_control_region,
1388                         window_size);
1389         dcr->header.type = ACPI_NFIT_TYPE_CONTROL_REGION;
1390         dcr->header.length = offsetof(struct acpi_nfit_control_region,
1391                         window_size);
1392         dcr->region_index = 5+1;
1393         dcr_common_init(dcr);
1394         dcr->serial_number = ~handle[1];
1395         dcr->code = NFIT_FIC_BYTEN;
1396         dcr->windows = 0;
1397
1398         /* dcr-descriptor2: pmem */
1399         dcr = nfit_buf + offset + offsetof(struct acpi_nfit_control_region,
1400                         window_size) * 2;
1401         dcr->header.type = ACPI_NFIT_TYPE_CONTROL_REGION;
1402         dcr->header.length = offsetof(struct acpi_nfit_control_region,
1403                         window_size);
1404         dcr->region_index = 6+1;
1405         dcr_common_init(dcr);
1406         dcr->serial_number = ~handle[2];
1407         dcr->code = NFIT_FIC_BYTEN;
1408         dcr->windows = 0;
1409
1410         /* dcr-descriptor3: pmem */
1411         dcr = nfit_buf + offset + offsetof(struct acpi_nfit_control_region,
1412                         window_size) * 3;
1413         dcr->header.type = ACPI_NFIT_TYPE_CONTROL_REGION;
1414         dcr->header.length = offsetof(struct acpi_nfit_control_region,
1415                         window_size);
1416         dcr->region_index = 7+1;
1417         dcr_common_init(dcr);
1418         dcr->serial_number = ~handle[3];
1419         dcr->code = NFIT_FIC_BYTEN;
1420         dcr->windows = 0;
1421
1422         offset = offset + offsetof(struct acpi_nfit_control_region,
1423                         window_size) * 4;
1424         /* bdw0 (spa/dcr0, dimm0) */
1425         bdw = nfit_buf + offset;
1426         bdw->header.type = ACPI_NFIT_TYPE_DATA_REGION;
1427         bdw->header.length = sizeof(struct acpi_nfit_data_region);
1428         bdw->region_index = 0+1;
1429         bdw->windows = 1;
1430         bdw->offset = 0;
1431         bdw->size = BDW_SIZE;
1432         bdw->capacity = DIMM_SIZE;
1433         bdw->start_address = 0;
1434
1435         /* bdw1 (spa/dcr1, dimm1) */
1436         bdw = nfit_buf + offset + sizeof(struct acpi_nfit_data_region);
1437         bdw->header.type = ACPI_NFIT_TYPE_DATA_REGION;
1438         bdw->header.length = sizeof(struct acpi_nfit_data_region);
1439         bdw->region_index = 1+1;
1440         bdw->windows = 1;
1441         bdw->offset = 0;
1442         bdw->size = BDW_SIZE;
1443         bdw->capacity = DIMM_SIZE;
1444         bdw->start_address = 0;
1445
1446         /* bdw2 (spa/dcr2, dimm2) */
1447         bdw = nfit_buf + offset + sizeof(struct acpi_nfit_data_region) * 2;
1448         bdw->header.type = ACPI_NFIT_TYPE_DATA_REGION;
1449         bdw->header.length = sizeof(struct acpi_nfit_data_region);
1450         bdw->region_index = 2+1;
1451         bdw->windows = 1;
1452         bdw->offset = 0;
1453         bdw->size = BDW_SIZE;
1454         bdw->capacity = DIMM_SIZE;
1455         bdw->start_address = 0;
1456
1457         /* bdw3 (spa/dcr3, dimm3) */
1458         bdw = nfit_buf + offset + sizeof(struct acpi_nfit_data_region) * 3;
1459         bdw->header.type = ACPI_NFIT_TYPE_DATA_REGION;
1460         bdw->header.length = sizeof(struct acpi_nfit_data_region);
1461         bdw->region_index = 3+1;
1462         bdw->windows = 1;
1463         bdw->offset = 0;
1464         bdw->size = BDW_SIZE;
1465         bdw->capacity = DIMM_SIZE;
1466         bdw->start_address = 0;
1467
1468         offset = offset + sizeof(struct acpi_nfit_data_region) * 4;
1469         /* flush0 (dimm0) */
1470         flush = nfit_buf + offset;
1471         flush->header.type = ACPI_NFIT_TYPE_FLUSH_ADDRESS;
1472         flush->header.length = flush_hint_size;
1473         flush->device_handle = handle[0];
1474         flush->hint_count = NUM_HINTS;
1475         for (i = 0; i < NUM_HINTS; i++)
1476                 flush->hint_address[i] = t->flush_dma[0] + i * sizeof(u64);
1477
1478         /* flush1 (dimm1) */
1479         flush = nfit_buf + offset + flush_hint_size * 1;
1480         flush->header.type = ACPI_NFIT_TYPE_FLUSH_ADDRESS;
1481         flush->header.length = flush_hint_size;
1482         flush->device_handle = handle[1];
1483         flush->hint_count = NUM_HINTS;
1484         for (i = 0; i < NUM_HINTS; i++)
1485                 flush->hint_address[i] = t->flush_dma[1] + i * sizeof(u64);
1486
1487         /* flush2 (dimm2) */
1488         flush = nfit_buf + offset + flush_hint_size  * 2;
1489         flush->header.type = ACPI_NFIT_TYPE_FLUSH_ADDRESS;
1490         flush->header.length = flush_hint_size;
1491         flush->device_handle = handle[2];
1492         flush->hint_count = NUM_HINTS;
1493         for (i = 0; i < NUM_HINTS; i++)
1494                 flush->hint_address[i] = t->flush_dma[2] + i * sizeof(u64);
1495
1496         /* flush3 (dimm3) */
1497         flush = nfit_buf + offset + flush_hint_size * 3;
1498         flush->header.type = ACPI_NFIT_TYPE_FLUSH_ADDRESS;
1499         flush->header.length = flush_hint_size;
1500         flush->device_handle = handle[3];
1501         flush->hint_count = NUM_HINTS;
1502         for (i = 0; i < NUM_HINTS; i++)
1503                 flush->hint_address[i] = t->flush_dma[3] + i * sizeof(u64);
1504
1505         /* platform capabilities */
1506         pcap = nfit_buf + offset + flush_hint_size * 4;
1507         pcap->header.type = ACPI_NFIT_TYPE_CAPABILITIES;
1508         pcap->header.length = sizeof(*pcap);
1509         pcap->highest_capability = 1;
1510         pcap->capabilities = ACPI_NFIT_CAPABILITY_CACHE_FLUSH |
1511                 ACPI_NFIT_CAPABILITY_MEM_FLUSH;
1512
1513         if (t->setup_hotplug) {
1514                 offset = offset + flush_hint_size * 4 + sizeof(*pcap);
1515                 /* dcr-descriptor4: blk */
1516                 dcr = nfit_buf + offset;
1517                 dcr->header.type = ACPI_NFIT_TYPE_CONTROL_REGION;
1518                 dcr->header.length = sizeof(struct acpi_nfit_control_region);
1519                 dcr->region_index = 8+1;
1520                 dcr_common_init(dcr);
1521                 dcr->serial_number = ~handle[4];
1522                 dcr->code = NFIT_FIC_BLK;
1523                 dcr->windows = 1;
1524                 dcr->window_size = DCR_SIZE;
1525                 dcr->command_offset = 0;
1526                 dcr->command_size = 8;
1527                 dcr->status_offset = 8;
1528                 dcr->status_size = 4;
1529
1530                 offset = offset + sizeof(struct acpi_nfit_control_region);
1531                 /* dcr-descriptor4: pmem */
1532                 dcr = nfit_buf + offset;
1533                 dcr->header.type = ACPI_NFIT_TYPE_CONTROL_REGION;
1534                 dcr->header.length = offsetof(struct acpi_nfit_control_region,
1535                                 window_size);
1536                 dcr->region_index = 9+1;
1537                 dcr_common_init(dcr);
1538                 dcr->serial_number = ~handle[4];
1539                 dcr->code = NFIT_FIC_BYTEN;
1540                 dcr->windows = 0;
1541
1542                 offset = offset + offsetof(struct acpi_nfit_control_region,
1543                                 window_size);
1544                 /* bdw4 (spa/dcr4, dimm4) */
1545                 bdw = nfit_buf + offset;
1546                 bdw->header.type = ACPI_NFIT_TYPE_DATA_REGION;
1547                 bdw->header.length = sizeof(struct acpi_nfit_data_region);
1548                 bdw->region_index = 8+1;
1549                 bdw->windows = 1;
1550                 bdw->offset = 0;
1551                 bdw->size = BDW_SIZE;
1552                 bdw->capacity = DIMM_SIZE;
1553                 bdw->start_address = 0;
1554
1555                 offset = offset + sizeof(struct acpi_nfit_data_region);
1556                 /* spa10 (dcr4) dimm4 */
1557                 spa = nfit_buf + offset;
1558                 spa->header.type = ACPI_NFIT_TYPE_SYSTEM_ADDRESS;
1559                 spa->header.length = sizeof(*spa);
1560                 memcpy(spa->range_guid, to_nfit_uuid(NFIT_SPA_DCR), 16);
1561                 spa->range_index = 10+1;
1562                 spa->address = t->dcr_dma[4];
1563                 spa->length = DCR_SIZE;
1564
1565                 /*
1566                  * spa11 (single-dimm interleave for hotplug, note storage
1567                  * does not actually alias the related block-data-window
1568                  * regions)
1569                  */
1570                 spa = nfit_buf + offset + sizeof(*spa);
1571                 spa->header.type = ACPI_NFIT_TYPE_SYSTEM_ADDRESS;
1572                 spa->header.length = sizeof(*spa);
1573                 memcpy(spa->range_guid, to_nfit_uuid(NFIT_SPA_PM), 16);
1574                 spa->range_index = 11+1;
1575                 spa->address = t->spa_set_dma[2];
1576                 spa->length = SPA0_SIZE;
1577
1578                 /* spa12 (bdw for dcr4) dimm4 */
1579                 spa = nfit_buf + offset + sizeof(*spa) * 2;
1580                 spa->header.type = ACPI_NFIT_TYPE_SYSTEM_ADDRESS;
1581                 spa->header.length = sizeof(*spa);
1582                 memcpy(spa->range_guid, to_nfit_uuid(NFIT_SPA_BDW), 16);
1583                 spa->range_index = 12+1;
1584                 spa->address = t->dimm_dma[4];
1585                 spa->length = DIMM_SIZE;
1586
1587                 offset = offset + sizeof(*spa) * 3;
1588                 /* mem-region14 (spa/dcr4, dimm4) */
1589                 memdev = nfit_buf + offset;
1590                 memdev->header.type = ACPI_NFIT_TYPE_MEMORY_MAP;
1591                 memdev->header.length = sizeof(*memdev);
1592                 memdev->device_handle = handle[4];
1593                 memdev->physical_id = 4;
1594                 memdev->region_id = 0;
1595                 memdev->range_index = 10+1;
1596                 memdev->region_index = 8+1;
1597                 memdev->region_size = 0;
1598                 memdev->region_offset = 0;
1599                 memdev->address = 0;
1600                 memdev->interleave_index = 0;
1601                 memdev->interleave_ways = 1;
1602
1603                 /* mem-region15 (spa0, dimm4) */
1604                 memdev = nfit_buf + offset +
1605                                 sizeof(struct acpi_nfit_memory_map);
1606                 memdev->header.type = ACPI_NFIT_TYPE_MEMORY_MAP;
1607                 memdev->header.length = sizeof(*memdev);
1608                 memdev->device_handle = handle[4];
1609                 memdev->physical_id = 4;
1610                 memdev->region_id = 0;
1611                 memdev->range_index = 11+1;
1612                 memdev->region_index = 9+1;
1613                 memdev->region_size = SPA0_SIZE;
1614                 memdev->region_offset = (1ULL << 48);
1615                 memdev->address = 0;
1616                 memdev->interleave_index = 0;
1617                 memdev->interleave_ways = 1;
1618                 memdev->flags = ACPI_NFIT_MEM_HEALTH_ENABLED;
1619
1620                 /* mem-region16 (spa/bdw4, dimm4) */
1621                 memdev = nfit_buf + offset +
1622                                 sizeof(struct acpi_nfit_memory_map) * 2;
1623                 memdev->header.type = ACPI_NFIT_TYPE_MEMORY_MAP;
1624                 memdev->header.length = sizeof(*memdev);
1625                 memdev->device_handle = handle[4];
1626                 memdev->physical_id = 4;
1627                 memdev->region_id = 0;
1628                 memdev->range_index = 12+1;
1629                 memdev->region_index = 8+1;
1630                 memdev->region_size = 0;
1631                 memdev->region_offset = 0;
1632                 memdev->address = 0;
1633                 memdev->interleave_index = 0;
1634                 memdev->interleave_ways = 1;
1635
1636                 offset = offset + sizeof(struct acpi_nfit_memory_map) * 3;
1637                 /* flush3 (dimm4) */
1638                 flush = nfit_buf + offset;
1639                 flush->header.type = ACPI_NFIT_TYPE_FLUSH_ADDRESS;
1640                 flush->header.length = flush_hint_size;
1641                 flush->device_handle = handle[4];
1642                 flush->hint_count = NUM_HINTS;
1643                 for (i = 0; i < NUM_HINTS; i++)
1644                         flush->hint_address[i] = t->flush_dma[4]
1645                                 + i * sizeof(u64);
1646         }
1647
1648         post_ars_status(&t->ars_state, &t->badrange, t->spa_set_dma[0],
1649                         SPA0_SIZE);
1650
1651         acpi_desc = &t->acpi_desc;
1652         set_bit(ND_CMD_GET_CONFIG_SIZE, &acpi_desc->dimm_cmd_force_en);
1653         set_bit(ND_CMD_GET_CONFIG_DATA, &acpi_desc->dimm_cmd_force_en);
1654         set_bit(ND_CMD_SET_CONFIG_DATA, &acpi_desc->dimm_cmd_force_en);
1655         set_bit(ND_CMD_SMART, &acpi_desc->dimm_cmd_force_en);
1656         set_bit(ND_CMD_ARS_CAP, &acpi_desc->bus_cmd_force_en);
1657         set_bit(ND_CMD_ARS_START, &acpi_desc->bus_cmd_force_en);
1658         set_bit(ND_CMD_ARS_STATUS, &acpi_desc->bus_cmd_force_en);
1659         set_bit(ND_CMD_CLEAR_ERROR, &acpi_desc->bus_cmd_force_en);
1660         set_bit(ND_CMD_CALL, &acpi_desc->bus_cmd_force_en);
1661         set_bit(ND_CMD_SMART_THRESHOLD, &acpi_desc->dimm_cmd_force_en);
1662         set_bit(NFIT_CMD_TRANSLATE_SPA, &acpi_desc->bus_nfit_cmd_force_en);
1663         set_bit(NFIT_CMD_ARS_INJECT_SET, &acpi_desc->bus_nfit_cmd_force_en);
1664         set_bit(NFIT_CMD_ARS_INJECT_CLEAR, &acpi_desc->bus_nfit_cmd_force_en);
1665         set_bit(NFIT_CMD_ARS_INJECT_GET, &acpi_desc->bus_nfit_cmd_force_en);
1666 }
1667
1668 static void nfit_test1_setup(struct nfit_test *t)
1669 {
1670         size_t offset;
1671         void *nfit_buf = t->nfit_buf;
1672         struct acpi_nfit_memory_map *memdev;
1673         struct acpi_nfit_control_region *dcr;
1674         struct acpi_nfit_system_address *spa;
1675         struct acpi_nfit_desc *acpi_desc;
1676
1677         offset = 0;
1678         /* spa0 (flat range with no bdw aliasing) */
1679         spa = nfit_buf + offset;
1680         spa->header.type = ACPI_NFIT_TYPE_SYSTEM_ADDRESS;
1681         spa->header.length = sizeof(*spa);
1682         memcpy(spa->range_guid, to_nfit_uuid(NFIT_SPA_PM), 16);
1683         spa->range_index = 0+1;
1684         spa->address = t->spa_set_dma[0];
1685         spa->length = SPA2_SIZE;
1686
1687         /* virtual cd region */
1688         spa = nfit_buf + sizeof(*spa);
1689         spa->header.type = ACPI_NFIT_TYPE_SYSTEM_ADDRESS;
1690         spa->header.length = sizeof(*spa);
1691         memcpy(spa->range_guid, to_nfit_uuid(NFIT_SPA_VCD), 16);
1692         spa->range_index = 0;
1693         spa->address = t->spa_set_dma[1];
1694         spa->length = SPA_VCD_SIZE;
1695
1696         offset += sizeof(*spa) * 2;
1697         /* mem-region0 (spa0, dimm0) */
1698         memdev = nfit_buf + offset;
1699         memdev->header.type = ACPI_NFIT_TYPE_MEMORY_MAP;
1700         memdev->header.length = sizeof(*memdev);
1701         memdev->device_handle = handle[5];
1702         memdev->physical_id = 0;
1703         memdev->region_id = 0;
1704         memdev->range_index = 0+1;
1705         memdev->region_index = 0+1;
1706         memdev->region_size = SPA2_SIZE;
1707         memdev->region_offset = 0;
1708         memdev->address = 0;
1709         memdev->interleave_index = 0;
1710         memdev->interleave_ways = 1;
1711         memdev->flags = ACPI_NFIT_MEM_SAVE_FAILED | ACPI_NFIT_MEM_RESTORE_FAILED
1712                 | ACPI_NFIT_MEM_FLUSH_FAILED | ACPI_NFIT_MEM_HEALTH_OBSERVED
1713                 | ACPI_NFIT_MEM_NOT_ARMED;
1714
1715         offset += sizeof(*memdev);
1716         /* dcr-descriptor0 */
1717         dcr = nfit_buf + offset;
1718         dcr->header.type = ACPI_NFIT_TYPE_CONTROL_REGION;
1719         dcr->header.length = offsetof(struct acpi_nfit_control_region,
1720                         window_size);
1721         dcr->region_index = 0+1;
1722         dcr_common_init(dcr);
1723         dcr->serial_number = ~handle[5];
1724         dcr->code = NFIT_FIC_BYTE;
1725         dcr->windows = 0;
1726
1727         offset += dcr->header.length;
1728         memdev = nfit_buf + offset;
1729         memdev->header.type = ACPI_NFIT_TYPE_MEMORY_MAP;
1730         memdev->header.length = sizeof(*memdev);
1731         memdev->device_handle = handle[6];
1732         memdev->physical_id = 0;
1733         memdev->region_id = 0;
1734         memdev->range_index = 0;
1735         memdev->region_index = 0+2;
1736         memdev->region_size = SPA2_SIZE;
1737         memdev->region_offset = 0;
1738         memdev->address = 0;
1739         memdev->interleave_index = 0;
1740         memdev->interleave_ways = 1;
1741         memdev->flags = ACPI_NFIT_MEM_MAP_FAILED;
1742
1743         /* dcr-descriptor1 */
1744         offset += sizeof(*memdev);
1745         dcr = nfit_buf + offset;
1746         dcr->header.type = ACPI_NFIT_TYPE_CONTROL_REGION;
1747         dcr->header.length = offsetof(struct acpi_nfit_control_region,
1748                         window_size);
1749         dcr->region_index = 0+2;
1750         dcr_common_init(dcr);
1751         dcr->serial_number = ~handle[6];
1752         dcr->code = NFIT_FIC_BYTE;
1753         dcr->windows = 0;
1754
1755         post_ars_status(&t->ars_state, &t->badrange, t->spa_set_dma[0],
1756                         SPA2_SIZE);
1757
1758         acpi_desc = &t->acpi_desc;
1759         set_bit(ND_CMD_ARS_CAP, &acpi_desc->bus_cmd_force_en);
1760         set_bit(ND_CMD_ARS_START, &acpi_desc->bus_cmd_force_en);
1761         set_bit(ND_CMD_ARS_STATUS, &acpi_desc->bus_cmd_force_en);
1762         set_bit(ND_CMD_CLEAR_ERROR, &acpi_desc->bus_cmd_force_en);
1763 }
1764
1765 static int nfit_test_blk_do_io(struct nd_blk_region *ndbr, resource_size_t dpa,
1766                 void *iobuf, u64 len, int rw)
1767 {
1768         struct nfit_blk *nfit_blk = ndbr->blk_provider_data;
1769         struct nfit_blk_mmio *mmio = &nfit_blk->mmio[BDW];
1770         struct nd_region *nd_region = &ndbr->nd_region;
1771         unsigned int lane;
1772
1773         lane = nd_region_acquire_lane(nd_region);
1774         if (rw)
1775                 memcpy(mmio->addr.base + dpa, iobuf, len);
1776         else {
1777                 memcpy(iobuf, mmio->addr.base + dpa, len);
1778
1779                 /* give us some some coverage of the arch_invalidate_pmem() API */
1780                 arch_invalidate_pmem(mmio->addr.base + dpa, len);
1781         }
1782         nd_region_release_lane(nd_region, lane);
1783
1784         return 0;
1785 }
1786
1787 static unsigned long nfit_ctl_handle;
1788
1789 union acpi_object *result;
1790
1791 static union acpi_object *nfit_test_evaluate_dsm(acpi_handle handle,
1792                 const guid_t *guid, u64 rev, u64 func, union acpi_object *argv4)
1793 {
1794         if (handle != &nfit_ctl_handle)
1795                 return ERR_PTR(-ENXIO);
1796
1797         return result;
1798 }
1799
1800 static int setup_result(void *buf, size_t size)
1801 {
1802         result = kmalloc(sizeof(union acpi_object) + size, GFP_KERNEL);
1803         if (!result)
1804                 return -ENOMEM;
1805         result->package.type = ACPI_TYPE_BUFFER,
1806         result->buffer.pointer = (void *) (result + 1);
1807         result->buffer.length = size;
1808         memcpy(result->buffer.pointer, buf, size);
1809         memset(buf, 0, size);
1810         return 0;
1811 }
1812
1813 static int nfit_ctl_test(struct device *dev)
1814 {
1815         int rc, cmd_rc;
1816         struct nvdimm *nvdimm;
1817         struct acpi_device *adev;
1818         struct nfit_mem *nfit_mem;
1819         struct nd_ars_record *record;
1820         struct acpi_nfit_desc *acpi_desc;
1821         const u64 test_val = 0x0123456789abcdefULL;
1822         unsigned long mask, cmd_size, offset;
1823         union {
1824                 struct nd_cmd_get_config_size cfg_size;
1825                 struct nd_cmd_clear_error clear_err;
1826                 struct nd_cmd_ars_status ars_stat;
1827                 struct nd_cmd_ars_cap ars_cap;
1828                 char buf[sizeof(struct nd_cmd_ars_status)
1829                         + sizeof(struct nd_ars_record)];
1830         } cmds;
1831
1832         adev = devm_kzalloc(dev, sizeof(*adev), GFP_KERNEL);
1833         if (!adev)
1834                 return -ENOMEM;
1835         *adev = (struct acpi_device) {
1836                 .handle = &nfit_ctl_handle,
1837                 .dev = {
1838                         .init_name = "test-adev",
1839                 },
1840         };
1841
1842         acpi_desc = devm_kzalloc(dev, sizeof(*acpi_desc), GFP_KERNEL);
1843         if (!acpi_desc)
1844                 return -ENOMEM;
1845         *acpi_desc = (struct acpi_nfit_desc) {
1846                 .nd_desc = {
1847                         .cmd_mask = 1UL << ND_CMD_ARS_CAP
1848                                 | 1UL << ND_CMD_ARS_START
1849                                 | 1UL << ND_CMD_ARS_STATUS
1850                                 | 1UL << ND_CMD_CLEAR_ERROR
1851                                 | 1UL << ND_CMD_CALL,
1852                         .module = THIS_MODULE,
1853                         .provider_name = "ACPI.NFIT",
1854                         .ndctl = acpi_nfit_ctl,
1855                         .bus_dsm_mask = 1UL << NFIT_CMD_TRANSLATE_SPA
1856                                 | 1UL << NFIT_CMD_ARS_INJECT_SET
1857                                 | 1UL << NFIT_CMD_ARS_INJECT_CLEAR
1858                                 | 1UL << NFIT_CMD_ARS_INJECT_GET,
1859                 },
1860                 .dev = &adev->dev,
1861         };
1862
1863         nfit_mem = devm_kzalloc(dev, sizeof(*nfit_mem), GFP_KERNEL);
1864         if (!nfit_mem)
1865                 return -ENOMEM;
1866
1867         mask = 1UL << ND_CMD_SMART | 1UL << ND_CMD_SMART_THRESHOLD
1868                 | 1UL << ND_CMD_DIMM_FLAGS | 1UL << ND_CMD_GET_CONFIG_SIZE
1869                 | 1UL << ND_CMD_GET_CONFIG_DATA | 1UL << ND_CMD_SET_CONFIG_DATA
1870                 | 1UL << ND_CMD_VENDOR;
1871         *nfit_mem = (struct nfit_mem) {
1872                 .adev = adev,
1873                 .family = NVDIMM_FAMILY_INTEL,
1874                 .dsm_mask = mask,
1875         };
1876
1877         nvdimm = devm_kzalloc(dev, sizeof(*nvdimm), GFP_KERNEL);
1878         if (!nvdimm)
1879                 return -ENOMEM;
1880         *nvdimm = (struct nvdimm) {
1881                 .provider_data = nfit_mem,
1882                 .cmd_mask = mask,
1883                 .dev = {
1884                         .init_name = "test-dimm",
1885                 },
1886         };
1887
1888
1889         /* basic checkout of a typical 'get config size' command */
1890         cmd_size = sizeof(cmds.cfg_size);
1891         cmds.cfg_size = (struct nd_cmd_get_config_size) {
1892                 .status = 0,
1893                 .config_size = SZ_128K,
1894                 .max_xfer = SZ_4K,
1895         };
1896         rc = setup_result(cmds.buf, cmd_size);
1897         if (rc)
1898                 return rc;
1899         rc = acpi_nfit_ctl(&acpi_desc->nd_desc, nvdimm, ND_CMD_GET_CONFIG_SIZE,
1900                         cmds.buf, cmd_size, &cmd_rc);
1901
1902         if (rc < 0 || cmd_rc || cmds.cfg_size.status != 0
1903                         || cmds.cfg_size.config_size != SZ_128K
1904                         || cmds.cfg_size.max_xfer != SZ_4K) {
1905                 dev_dbg(dev, "%s: failed at: %d rc: %d cmd_rc: %d\n",
1906                                 __func__, __LINE__, rc, cmd_rc);
1907                 return -EIO;
1908         }
1909
1910
1911         /* test ars_status with zero output */
1912         cmd_size = offsetof(struct nd_cmd_ars_status, address);
1913         cmds.ars_stat = (struct nd_cmd_ars_status) {
1914                 .out_length = 0,
1915         };
1916         rc = setup_result(cmds.buf, cmd_size);
1917         if (rc)
1918                 return rc;
1919         rc = acpi_nfit_ctl(&acpi_desc->nd_desc, NULL, ND_CMD_ARS_STATUS,
1920                         cmds.buf, cmd_size, &cmd_rc);
1921
1922         if (rc < 0 || cmd_rc) {
1923                 dev_dbg(dev, "%s: failed at: %d rc: %d cmd_rc: %d\n",
1924                                 __func__, __LINE__, rc, cmd_rc);
1925                 return -EIO;
1926         }
1927
1928
1929         /* test ars_cap with benign extended status */
1930         cmd_size = sizeof(cmds.ars_cap);
1931         cmds.ars_cap = (struct nd_cmd_ars_cap) {
1932                 .status = ND_ARS_PERSISTENT << 16,
1933         };
1934         offset = offsetof(struct nd_cmd_ars_cap, status);
1935         rc = setup_result(cmds.buf + offset, cmd_size - offset);
1936         if (rc)
1937                 return rc;
1938         rc = acpi_nfit_ctl(&acpi_desc->nd_desc, NULL, ND_CMD_ARS_CAP,
1939                         cmds.buf, cmd_size, &cmd_rc);
1940
1941         if (rc < 0 || cmd_rc) {
1942                 dev_dbg(dev, "%s: failed at: %d rc: %d cmd_rc: %d\n",
1943                                 __func__, __LINE__, rc, cmd_rc);
1944                 return -EIO;
1945         }
1946
1947
1948         /* test ars_status with 'status' trimmed from 'out_length' */
1949         cmd_size = sizeof(cmds.ars_stat) + sizeof(struct nd_ars_record);
1950         cmds.ars_stat = (struct nd_cmd_ars_status) {
1951                 .out_length = cmd_size - 4,
1952         };
1953         record = &cmds.ars_stat.records[0];
1954         *record = (struct nd_ars_record) {
1955                 .length = test_val,
1956         };
1957         rc = setup_result(cmds.buf, cmd_size);
1958         if (rc)
1959                 return rc;
1960         rc = acpi_nfit_ctl(&acpi_desc->nd_desc, NULL, ND_CMD_ARS_STATUS,
1961                         cmds.buf, cmd_size, &cmd_rc);
1962
1963         if (rc < 0 || cmd_rc || record->length != test_val) {
1964                 dev_dbg(dev, "%s: failed at: %d rc: %d cmd_rc: %d\n",
1965                                 __func__, __LINE__, rc, cmd_rc);
1966                 return -EIO;
1967         }
1968
1969
1970         /* test ars_status with 'Output (Size)' including 'status' */
1971         cmd_size = sizeof(cmds.ars_stat) + sizeof(struct nd_ars_record);
1972         cmds.ars_stat = (struct nd_cmd_ars_status) {
1973                 .out_length = cmd_size,
1974         };
1975         record = &cmds.ars_stat.records[0];
1976         *record = (struct nd_ars_record) {
1977                 .length = test_val,
1978         };
1979         rc = setup_result(cmds.buf, cmd_size);
1980         if (rc)
1981                 return rc;
1982         rc = acpi_nfit_ctl(&acpi_desc->nd_desc, NULL, ND_CMD_ARS_STATUS,
1983                         cmds.buf, cmd_size, &cmd_rc);
1984
1985         if (rc < 0 || cmd_rc || record->length != test_val) {
1986                 dev_dbg(dev, "%s: failed at: %d rc: %d cmd_rc: %d\n",
1987                                 __func__, __LINE__, rc, cmd_rc);
1988                 return -EIO;
1989         }
1990
1991
1992         /* test extended status for get_config_size results in failure */
1993         cmd_size = sizeof(cmds.cfg_size);
1994         cmds.cfg_size = (struct nd_cmd_get_config_size) {
1995                 .status = 1 << 16,
1996         };
1997         rc = setup_result(cmds.buf, cmd_size);
1998         if (rc)
1999                 return rc;
2000         rc = acpi_nfit_ctl(&acpi_desc->nd_desc, nvdimm, ND_CMD_GET_CONFIG_SIZE,
2001                         cmds.buf, cmd_size, &cmd_rc);
2002
2003         if (rc < 0 || cmd_rc >= 0) {
2004                 dev_dbg(dev, "%s: failed at: %d rc: %d cmd_rc: %d\n",
2005                                 __func__, __LINE__, rc, cmd_rc);
2006                 return -EIO;
2007         }
2008
2009         /* test clear error */
2010         cmd_size = sizeof(cmds.clear_err);
2011         cmds.clear_err = (struct nd_cmd_clear_error) {
2012                 .length = 512,
2013                 .cleared = 512,
2014         };
2015         rc = setup_result(cmds.buf, cmd_size);
2016         if (rc)
2017                 return rc;
2018         rc = acpi_nfit_ctl(&acpi_desc->nd_desc, NULL, ND_CMD_CLEAR_ERROR,
2019                         cmds.buf, cmd_size, &cmd_rc);
2020         if (rc < 0 || cmd_rc) {
2021                 dev_dbg(dev, "%s: failed at: %d rc: %d cmd_rc: %d\n",
2022                                 __func__, __LINE__, rc, cmd_rc);
2023                 return -EIO;
2024         }
2025
2026         return 0;
2027 }
2028
2029 static int nfit_test_probe(struct platform_device *pdev)
2030 {
2031         struct nvdimm_bus_descriptor *nd_desc;
2032         struct acpi_nfit_desc *acpi_desc;
2033         struct device *dev = &pdev->dev;
2034         struct nfit_test *nfit_test;
2035         struct nfit_mem *nfit_mem;
2036         union acpi_object *obj;
2037         int rc;
2038
2039         if (strcmp(dev_name(&pdev->dev), "nfit_test.0") == 0) {
2040                 rc = nfit_ctl_test(&pdev->dev);
2041                 if (rc)
2042                         return rc;
2043         }
2044
2045         nfit_test = to_nfit_test(&pdev->dev);
2046
2047         /* common alloc */
2048         if (nfit_test->num_dcr) {
2049                 int num = nfit_test->num_dcr;
2050
2051                 nfit_test->dimm = devm_kcalloc(dev, num, sizeof(void *),
2052                                 GFP_KERNEL);
2053                 nfit_test->dimm_dma = devm_kcalloc(dev, num, sizeof(dma_addr_t),
2054                                 GFP_KERNEL);
2055                 nfit_test->flush = devm_kcalloc(dev, num, sizeof(void *),
2056                                 GFP_KERNEL);
2057                 nfit_test->flush_dma = devm_kcalloc(dev, num, sizeof(dma_addr_t),
2058                                 GFP_KERNEL);
2059                 nfit_test->label = devm_kcalloc(dev, num, sizeof(void *),
2060                                 GFP_KERNEL);
2061                 nfit_test->label_dma = devm_kcalloc(dev, num,
2062                                 sizeof(dma_addr_t), GFP_KERNEL);
2063                 nfit_test->dcr = devm_kcalloc(dev, num,
2064                                 sizeof(struct nfit_test_dcr *), GFP_KERNEL);
2065                 nfit_test->dcr_dma = devm_kcalloc(dev, num,
2066                                 sizeof(dma_addr_t), GFP_KERNEL);
2067                 if (nfit_test->dimm && nfit_test->dimm_dma && nfit_test->label
2068                                 && nfit_test->label_dma && nfit_test->dcr
2069                                 && nfit_test->dcr_dma && nfit_test->flush
2070                                 && nfit_test->flush_dma)
2071                         /* pass */;
2072                 else
2073                         return -ENOMEM;
2074         }
2075
2076         if (nfit_test->num_pm) {
2077                 int num = nfit_test->num_pm;
2078
2079                 nfit_test->spa_set = devm_kcalloc(dev, num, sizeof(void *),
2080                                 GFP_KERNEL);
2081                 nfit_test->spa_set_dma = devm_kcalloc(dev, num,
2082                                 sizeof(dma_addr_t), GFP_KERNEL);
2083                 if (nfit_test->spa_set && nfit_test->spa_set_dma)
2084                         /* pass */;
2085                 else
2086                         return -ENOMEM;
2087         }
2088
2089         /* per-nfit specific alloc */
2090         if (nfit_test->alloc(nfit_test))
2091                 return -ENOMEM;
2092
2093         nfit_test->setup(nfit_test);
2094         acpi_desc = &nfit_test->acpi_desc;
2095         acpi_nfit_desc_init(acpi_desc, &pdev->dev);
2096         acpi_desc->blk_do_io = nfit_test_blk_do_io;
2097         nd_desc = &acpi_desc->nd_desc;
2098         nd_desc->provider_name = NULL;
2099         nd_desc->module = THIS_MODULE;
2100         nd_desc->ndctl = nfit_test_ctl;
2101
2102         rc = acpi_nfit_init(acpi_desc, nfit_test->nfit_buf,
2103                         nfit_test->nfit_size);
2104         if (rc)
2105                 return rc;
2106
2107         rc = devm_add_action_or_reset(&pdev->dev, acpi_nfit_shutdown, acpi_desc);
2108         if (rc)
2109                 return rc;
2110
2111         if (nfit_test->setup != nfit_test0_setup)
2112                 return 0;
2113
2114         nfit_test->setup_hotplug = 1;
2115         nfit_test->setup(nfit_test);
2116
2117         obj = kzalloc(sizeof(*obj), GFP_KERNEL);
2118         if (!obj)
2119                 return -ENOMEM;
2120         obj->type = ACPI_TYPE_BUFFER;
2121         obj->buffer.length = nfit_test->nfit_size;
2122         obj->buffer.pointer = nfit_test->nfit_buf;
2123         *(nfit_test->_fit) = obj;
2124         __acpi_nfit_notify(&pdev->dev, nfit_test, 0x80);
2125
2126         /* associate dimm devices with nfit_mem data for notification testing */
2127         mutex_lock(&acpi_desc->init_mutex);
2128         list_for_each_entry(nfit_mem, &acpi_desc->dimms, list) {
2129                 u32 nfit_handle = __to_nfit_memdev(nfit_mem)->device_handle;
2130                 int i;
2131
2132                 for (i = 0; i < NUM_DCR; i++)
2133                         if (nfit_handle == handle[i])
2134                                 dev_set_drvdata(nfit_test->dimm_dev[i],
2135                                                 nfit_mem);
2136         }
2137         mutex_unlock(&acpi_desc->init_mutex);
2138
2139         return 0;
2140 }
2141
2142 static int nfit_test_remove(struct platform_device *pdev)
2143 {
2144         return 0;
2145 }
2146
2147 static void nfit_test_release(struct device *dev)
2148 {
2149         struct nfit_test *nfit_test = to_nfit_test(dev);
2150
2151         kfree(nfit_test);
2152 }
2153
2154 static const struct platform_device_id nfit_test_id[] = {
2155         { KBUILD_MODNAME },
2156         { },
2157 };
2158
2159 static struct platform_driver nfit_test_driver = {
2160         .probe = nfit_test_probe,
2161         .remove = nfit_test_remove,
2162         .driver = {
2163                 .name = KBUILD_MODNAME,
2164         },
2165         .id_table = nfit_test_id,
2166 };
2167
2168 static __init int nfit_test_init(void)
2169 {
2170         int rc, i;
2171
2172         nfit_test_setup(nfit_test_lookup, nfit_test_evaluate_dsm);
2173
2174         nfit_wq = create_singlethread_workqueue("nfit");
2175         if (!nfit_wq)
2176                 return -ENOMEM;
2177
2178         nfit_test_dimm = class_create(THIS_MODULE, "nfit_test_dimm");
2179         if (IS_ERR(nfit_test_dimm)) {
2180                 rc = PTR_ERR(nfit_test_dimm);
2181                 goto err_register;
2182         }
2183
2184         for (i = 0; i < NUM_NFITS; i++) {
2185                 struct nfit_test *nfit_test;
2186                 struct platform_device *pdev;
2187
2188                 nfit_test = kzalloc(sizeof(*nfit_test), GFP_KERNEL);
2189                 if (!nfit_test) {
2190                         rc = -ENOMEM;
2191                         goto err_register;
2192                 }
2193                 INIT_LIST_HEAD(&nfit_test->resources);
2194                 badrange_init(&nfit_test->badrange);
2195                 switch (i) {
2196                 case 0:
2197                         nfit_test->num_pm = NUM_PM;
2198                         nfit_test->dcr_idx = 0;
2199                         nfit_test->num_dcr = NUM_DCR;
2200                         nfit_test->alloc = nfit_test0_alloc;
2201                         nfit_test->setup = nfit_test0_setup;
2202                         break;
2203                 case 1:
2204                         nfit_test->num_pm = 2;
2205                         nfit_test->dcr_idx = NUM_DCR;
2206                         nfit_test->num_dcr = 2;
2207                         nfit_test->alloc = nfit_test1_alloc;
2208                         nfit_test->setup = nfit_test1_setup;
2209                         break;
2210                 default:
2211                         rc = -EINVAL;
2212                         goto err_register;
2213                 }
2214                 pdev = &nfit_test->pdev;
2215                 pdev->name = KBUILD_MODNAME;
2216                 pdev->id = i;
2217                 pdev->dev.release = nfit_test_release;
2218                 rc = platform_device_register(pdev);
2219                 if (rc) {
2220                         put_device(&pdev->dev);
2221                         goto err_register;
2222                 }
2223                 get_device(&pdev->dev);
2224
2225                 rc = dma_coerce_mask_and_coherent(&pdev->dev, DMA_BIT_MASK(64));
2226                 if (rc)
2227                         goto err_register;
2228
2229                 instances[i] = nfit_test;
2230                 INIT_WORK(&nfit_test->work, uc_error_notify);
2231         }
2232
2233         rc = platform_driver_register(&nfit_test_driver);
2234         if (rc)
2235                 goto err_register;
2236         return 0;
2237
2238  err_register:
2239         destroy_workqueue(nfit_wq);
2240         for (i = 0; i < NUM_NFITS; i++)
2241                 if (instances[i])
2242                         platform_device_unregister(&instances[i]->pdev);
2243         nfit_test_teardown();
2244         for (i = 0; i < NUM_NFITS; i++)
2245                 if (instances[i])
2246                         put_device(&instances[i]->pdev.dev);
2247
2248         return rc;
2249 }
2250
2251 static __exit void nfit_test_exit(void)
2252 {
2253         int i;
2254
2255         flush_workqueue(nfit_wq);
2256         destroy_workqueue(nfit_wq);
2257         for (i = 0; i < NUM_NFITS; i++)
2258                 platform_device_unregister(&instances[i]->pdev);
2259         platform_driver_unregister(&nfit_test_driver);
2260         nfit_test_teardown();
2261
2262         for (i = 0; i < NUM_NFITS; i++)
2263                 put_device(&instances[i]->pdev.dev);
2264         class_destroy(nfit_test_dimm);
2265 }
2266
2267 module_init(nfit_test_init);
2268 module_exit(nfit_test_exit);
2269 MODULE_LICENSE("GPL v2");
2270 MODULE_AUTHOR("Intel Corporation");