2 * Copyright(c) 2013-2015 Intel Corporation. All rights reserved.
4 * This program is free software; you can redistribute it and/or modify
5 * it under the terms of version 2 of the GNU General Public License as
6 * published by the Free Software Foundation.
8 * This program is distributed in the hope that it will be useful, but
9 * WITHOUT ANY WARRANTY; without even the implied warranty of
10 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
11 * General Public License for more details.
13 #include <linux/list_sort.h>
14 #include <linux/libnvdimm.h>
15 #include <linux/module.h>
16 #include <linux/mutex.h>
17 #include <linux/ndctl.h>
18 #include <linux/sysfs.h>
19 #include <linux/delay.h>
20 #include <linux/list.h>
21 #include <linux/acpi.h>
22 #include <linux/sort.h>
25 #include <asm/cacheflush.h>
26 #include <acpi/nfit.h>
31 * For readq() and writeq() on 32-bit builds, the hi-lo, lo-hi order is
34 #include <linux/io-64-nonatomic-hi-lo.h>
36 static bool force_enable_dimms;
37 module_param(force_enable_dimms, bool, S_IRUGO|S_IWUSR);
38 MODULE_PARM_DESC(force_enable_dimms, "Ignore _STA (ACPI DIMM device) status");
40 static bool disable_vendor_specific;
41 module_param(disable_vendor_specific, bool, S_IRUGO);
42 MODULE_PARM_DESC(disable_vendor_specific,
43 "Limit commands to the publicly specified set");
45 static unsigned long override_dsm_mask;
46 module_param(override_dsm_mask, ulong, S_IRUGO);
47 MODULE_PARM_DESC(override_dsm_mask, "Bitmask of allowed NVDIMM DSM functions");
49 static int default_dsm_family = -1;
50 module_param(default_dsm_family, int, S_IRUGO);
51 MODULE_PARM_DESC(default_dsm_family,
52 "Try this DSM type first when identifying NVDIMM family");
54 static bool no_init_ars;
55 module_param(no_init_ars, bool, 0644);
56 MODULE_PARM_DESC(no_init_ars, "Skip ARS run at nfit init time");
58 LIST_HEAD(acpi_descs);
59 DEFINE_MUTEX(acpi_desc_lock);
61 static struct workqueue_struct *nfit_wq;
63 struct nfit_table_prev {
64 struct list_head spas;
65 struct list_head memdevs;
66 struct list_head dcrs;
67 struct list_head bdws;
68 struct list_head idts;
69 struct list_head flushes;
72 static guid_t nfit_uuid[NFIT_UUID_MAX];
74 const guid_t *to_nfit_uuid(enum nfit_uuids id)
76 return &nfit_uuid[id];
78 EXPORT_SYMBOL(to_nfit_uuid);
80 static struct acpi_nfit_desc *to_acpi_nfit_desc(
81 struct nvdimm_bus_descriptor *nd_desc)
83 return container_of(nd_desc, struct acpi_nfit_desc, nd_desc);
86 static struct acpi_device *to_acpi_dev(struct acpi_nfit_desc *acpi_desc)
88 struct nvdimm_bus_descriptor *nd_desc = &acpi_desc->nd_desc;
91 * If provider == 'ACPI.NFIT' we can assume 'dev' is a struct
94 if (!nd_desc->provider_name
95 || strcmp(nd_desc->provider_name, "ACPI.NFIT") != 0)
98 return to_acpi_device(acpi_desc->dev);
101 static int xlat_bus_status(void *buf, unsigned int cmd, u32 status)
103 struct nd_cmd_clear_error *clear_err;
104 struct nd_cmd_ars_status *ars_status;
109 if ((status & 0xffff) == NFIT_ARS_CAP_NONE)
116 /* No supported scan types for this range */
117 flags = ND_ARS_PERSISTENT | ND_ARS_VOLATILE;
118 if ((status >> 16 & flags) == 0)
121 case ND_CMD_ARS_START:
122 /* ARS is in progress */
123 if ((status & 0xffff) == NFIT_ARS_START_BUSY)
130 case ND_CMD_ARS_STATUS:
135 /* Check extended status (Upper two bytes) */
136 if (status == NFIT_ARS_STATUS_DONE)
139 /* ARS is in progress */
140 if (status == NFIT_ARS_STATUS_BUSY)
143 /* No ARS performed for the current boot */
144 if (status == NFIT_ARS_STATUS_NONE)
148 * ARS interrupted, either we overflowed or some other
149 * agent wants the scan to stop. If we didn't overflow
150 * then just continue with the returned results.
152 if (status == NFIT_ARS_STATUS_INTR) {
153 if (ars_status->out_length >= 40 && (ars_status->flags
154 & NFIT_ARS_F_OVERFLOW))
163 case ND_CMD_CLEAR_ERROR:
167 if (!clear_err->cleared)
169 if (clear_err->length > clear_err->cleared)
170 return clear_err->cleared;
176 /* all other non-zero status results in an error */
182 #define ACPI_LABELS_LOCKED 3
184 static int xlat_nvdimm_status(struct nvdimm *nvdimm, void *buf, unsigned int cmd,
187 struct nfit_mem *nfit_mem = nvdimm_provider_data(nvdimm);
190 case ND_CMD_GET_CONFIG_SIZE:
192 * In the _LSI, _LSR, _LSW case the locked status is
193 * communicated via the read/write commands
195 if (test_bit(NFIT_MEM_LSR, &nfit_mem->flags))
198 if (status >> 16 & ND_CONFIG_LOCKED)
201 case ND_CMD_GET_CONFIG_DATA:
202 if (test_bit(NFIT_MEM_LSR, &nfit_mem->flags)
203 && status == ACPI_LABELS_LOCKED)
206 case ND_CMD_SET_CONFIG_DATA:
207 if (test_bit(NFIT_MEM_LSW, &nfit_mem->flags)
208 && status == ACPI_LABELS_LOCKED)
215 /* all other non-zero status results in an error */
221 static int xlat_status(struct nvdimm *nvdimm, void *buf, unsigned int cmd,
225 return xlat_bus_status(buf, cmd, status);
226 return xlat_nvdimm_status(nvdimm, buf, cmd, status);
229 /* convert _LS{I,R} packages to the buffer object acpi_nfit_ctl expects */
230 static union acpi_object *pkg_to_buf(union acpi_object *pkg)
235 union acpi_object *buf = NULL;
237 if (pkg->type != ACPI_TYPE_PACKAGE) {
238 WARN_ONCE(1, "BIOS bug, unexpected element type: %d\n",
243 for (i = 0; i < pkg->package.count; i++) {
244 union acpi_object *obj = &pkg->package.elements[i];
246 if (obj->type == ACPI_TYPE_INTEGER)
248 else if (obj->type == ACPI_TYPE_BUFFER)
249 size += obj->buffer.length;
251 WARN_ONCE(1, "BIOS bug, unexpected element type: %d\n",
257 buf = ACPI_ALLOCATE(sizeof(*buf) + size);
262 buf->type = ACPI_TYPE_BUFFER;
263 buf->buffer.length = size;
264 buf->buffer.pointer = dst;
265 for (i = 0; i < pkg->package.count; i++) {
266 union acpi_object *obj = &pkg->package.elements[i];
268 if (obj->type == ACPI_TYPE_INTEGER) {
269 memcpy(dst, &obj->integer.value, 4);
271 } else if (obj->type == ACPI_TYPE_BUFFER) {
272 memcpy(dst, obj->buffer.pointer, obj->buffer.length);
273 dst += obj->buffer.length;
281 static union acpi_object *int_to_buf(union acpi_object *integer)
283 union acpi_object *buf = ACPI_ALLOCATE(sizeof(*buf) + 4);
289 if (integer->type != ACPI_TYPE_INTEGER) {
290 WARN_ONCE(1, "BIOS bug, unexpected element type: %d\n",
296 buf->type = ACPI_TYPE_BUFFER;
297 buf->buffer.length = 4;
298 buf->buffer.pointer = dst;
299 memcpy(dst, &integer->integer.value, 4);
305 static union acpi_object *acpi_label_write(acpi_handle handle, u32 offset,
309 struct acpi_buffer buf = { ACPI_ALLOCATE_BUFFER, NULL };
310 struct acpi_object_list input = {
312 .pointer = (union acpi_object []) {
314 .integer.type = ACPI_TYPE_INTEGER,
315 .integer.value = offset,
318 .integer.type = ACPI_TYPE_INTEGER,
319 .integer.value = len,
322 .buffer.type = ACPI_TYPE_BUFFER,
323 .buffer.pointer = data,
324 .buffer.length = len,
329 rc = acpi_evaluate_object(handle, "_LSW", &input, &buf);
330 if (ACPI_FAILURE(rc))
332 return int_to_buf(buf.pointer);
335 static union acpi_object *acpi_label_read(acpi_handle handle, u32 offset,
339 struct acpi_buffer buf = { ACPI_ALLOCATE_BUFFER, NULL };
340 struct acpi_object_list input = {
342 .pointer = (union acpi_object []) {
344 .integer.type = ACPI_TYPE_INTEGER,
345 .integer.value = offset,
348 .integer.type = ACPI_TYPE_INTEGER,
349 .integer.value = len,
354 rc = acpi_evaluate_object(handle, "_LSR", &input, &buf);
355 if (ACPI_FAILURE(rc))
357 return pkg_to_buf(buf.pointer);
360 static union acpi_object *acpi_label_info(acpi_handle handle)
363 struct acpi_buffer buf = { ACPI_ALLOCATE_BUFFER, NULL };
365 rc = acpi_evaluate_object(handle, "_LSI", NULL, &buf);
366 if (ACPI_FAILURE(rc))
368 return pkg_to_buf(buf.pointer);
371 static u8 nfit_dsm_revid(unsigned family, unsigned func)
373 static const u8 revid_table[NVDIMM_FAMILY_MAX+1][32] = {
374 [NVDIMM_FAMILY_INTEL] = {
375 [NVDIMM_INTEL_GET_MODES] = 2,
376 [NVDIMM_INTEL_GET_FWINFO] = 2,
377 [NVDIMM_INTEL_START_FWUPDATE] = 2,
378 [NVDIMM_INTEL_SEND_FWUPDATE] = 2,
379 [NVDIMM_INTEL_FINISH_FWUPDATE] = 2,
380 [NVDIMM_INTEL_QUERY_FWUPDATE] = 2,
381 [NVDIMM_INTEL_SET_THRESHOLD] = 2,
382 [NVDIMM_INTEL_INJECT_ERROR] = 2,
387 if (family > NVDIMM_FAMILY_MAX)
391 id = revid_table[family][func];
393 return 1; /* default */
397 int acpi_nfit_ctl(struct nvdimm_bus_descriptor *nd_desc, struct nvdimm *nvdimm,
398 unsigned int cmd, void *buf, unsigned int buf_len, int *cmd_rc)
400 struct acpi_nfit_desc *acpi_desc = to_acpi_nfit_desc(nd_desc);
401 struct nfit_mem *nfit_mem = nvdimm_provider_data(nvdimm);
402 union acpi_object in_obj, in_buf, *out_obj;
403 const struct nd_cmd_desc *desc = NULL;
404 struct device *dev = acpi_desc->dev;
405 struct nd_cmd_pkg *call_pkg = NULL;
406 const char *cmd_name, *dimm_name;
407 unsigned long cmd_mask, dsm_mask;
408 u32 offset, fw_status = 0;
417 if (cmd == ND_CMD_CALL) {
419 func = call_pkg->nd_command;
421 for (i = 0; i < ARRAY_SIZE(call_pkg->nd_reserved2); i++)
422 if (call_pkg->nd_reserved2[i])
427 struct acpi_device *adev = nfit_mem->adev;
431 if (call_pkg && nfit_mem->family != call_pkg->nd_family)
434 dimm_name = nvdimm_name(nvdimm);
435 cmd_name = nvdimm_cmd_name(cmd);
436 cmd_mask = nvdimm_cmd_mask(nvdimm);
437 dsm_mask = nfit_mem->dsm_mask;
438 desc = nd_cmd_dimm_desc(cmd);
439 guid = to_nfit_uuid(nfit_mem->family);
440 handle = adev->handle;
442 struct acpi_device *adev = to_acpi_dev(acpi_desc);
444 cmd_name = nvdimm_bus_cmd_name(cmd);
445 cmd_mask = nd_desc->cmd_mask;
447 if (cmd == ND_CMD_CALL)
448 dsm_mask = nd_desc->bus_dsm_mask;
449 desc = nd_cmd_bus_desc(cmd);
450 guid = to_nfit_uuid(NFIT_DEV_BUS);
451 handle = adev->handle;
455 if (!desc || (cmd && (desc->out_num + desc->in_num == 0)))
458 if (!test_bit(cmd, &cmd_mask) || !test_bit(func, &dsm_mask))
461 in_obj.type = ACPI_TYPE_PACKAGE;
462 in_obj.package.count = 1;
463 in_obj.package.elements = &in_buf;
464 in_buf.type = ACPI_TYPE_BUFFER;
465 in_buf.buffer.pointer = buf;
466 in_buf.buffer.length = 0;
468 /* libnvdimm has already validated the input envelope */
469 for (i = 0; i < desc->in_num; i++)
470 in_buf.buffer.length += nd_cmd_in_size(nvdimm, cmd, desc,
474 /* skip over package wrapper */
475 in_buf.buffer.pointer = (void *) &call_pkg->nd_payload;
476 in_buf.buffer.length = call_pkg->nd_size_in;
479 dev_dbg(dev, "%s cmd: %d: func: %d input length: %d\n",
480 dimm_name, cmd, func, in_buf.buffer.length);
481 print_hex_dump_debug("nvdimm in ", DUMP_PREFIX_OFFSET, 4, 4,
482 in_buf.buffer.pointer,
483 min_t(u32, 256, in_buf.buffer.length), true);
485 /* call the BIOS, prefer the named methods over _DSM if available */
486 if (nvdimm && cmd == ND_CMD_GET_CONFIG_SIZE
487 && test_bit(NFIT_MEM_LSR, &nfit_mem->flags))
488 out_obj = acpi_label_info(handle);
489 else if (nvdimm && cmd == ND_CMD_GET_CONFIG_DATA
490 && test_bit(NFIT_MEM_LSR, &nfit_mem->flags)) {
491 struct nd_cmd_get_config_data_hdr *p = buf;
493 out_obj = acpi_label_read(handle, p->in_offset, p->in_length);
494 } else if (nvdimm && cmd == ND_CMD_SET_CONFIG_DATA
495 && test_bit(NFIT_MEM_LSW, &nfit_mem->flags)) {
496 struct nd_cmd_set_config_hdr *p = buf;
498 out_obj = acpi_label_write(handle, p->in_offset, p->in_length,
504 revid = nfit_dsm_revid(nfit_mem->family, func);
507 out_obj = acpi_evaluate_dsm(handle, guid, revid, func, &in_obj);
511 dev_dbg(dev, "%s _DSM failed cmd: %s\n", dimm_name, cmd_name);
516 call_pkg->nd_fw_size = out_obj->buffer.length;
517 memcpy(call_pkg->nd_payload + call_pkg->nd_size_in,
518 out_obj->buffer.pointer,
519 min(call_pkg->nd_fw_size, call_pkg->nd_size_out));
523 * Need to support FW function w/o known size in advance.
524 * Caller can determine required size based upon nd_fw_size.
525 * If we return an error (like elsewhere) then caller wouldn't
526 * be able to rely upon data returned to make calculation.
533 if (out_obj->package.type != ACPI_TYPE_BUFFER) {
534 dev_dbg(dev, "%s unexpected output object type cmd: %s type: %d\n",
535 dimm_name, cmd_name, out_obj->type);
540 dev_dbg(dev, "%s cmd: %s output length: %d\n", dimm_name,
541 cmd_name, out_obj->buffer.length);
542 print_hex_dump_debug(cmd_name, DUMP_PREFIX_OFFSET, 4, 4,
543 out_obj->buffer.pointer,
544 min_t(u32, 128, out_obj->buffer.length), true);
546 for (i = 0, offset = 0; i < desc->out_num; i++) {
547 u32 out_size = nd_cmd_out_size(nvdimm, cmd, desc, i, buf,
548 (u32 *) out_obj->buffer.pointer,
549 out_obj->buffer.length - offset);
551 if (offset + out_size > out_obj->buffer.length) {
552 dev_dbg(dev, "%s output object underflow cmd: %s field: %d\n",
553 dimm_name, cmd_name, i);
557 if (in_buf.buffer.length + offset + out_size > buf_len) {
558 dev_dbg(dev, "%s output overrun cmd: %s field: %d\n",
559 dimm_name, cmd_name, i);
563 memcpy(buf + in_buf.buffer.length + offset,
564 out_obj->buffer.pointer + offset, out_size);
569 * Set fw_status for all the commands with a known format to be
570 * later interpreted by xlat_status().
572 if (i >= 1 && ((!nvdimm && cmd >= ND_CMD_ARS_CAP
573 && cmd <= ND_CMD_CLEAR_ERROR)
574 || (nvdimm && cmd >= ND_CMD_SMART
575 && cmd <= ND_CMD_VENDOR)))
576 fw_status = *(u32 *) out_obj->buffer.pointer;
578 if (offset + in_buf.buffer.length < buf_len) {
581 * status valid, return the number of bytes left
582 * unfilled in the output buffer
584 rc = buf_len - offset - in_buf.buffer.length;
586 *cmd_rc = xlat_status(nvdimm, buf, cmd,
589 dev_err(dev, "%s:%s underrun cmd: %s buf_len: %d out_len: %d\n",
590 __func__, dimm_name, cmd_name, buf_len,
597 *cmd_rc = xlat_status(nvdimm, buf, cmd, fw_status);
605 EXPORT_SYMBOL_GPL(acpi_nfit_ctl);
607 static const char *spa_type_name(u16 type)
609 static const char *to_name[] = {
610 [NFIT_SPA_VOLATILE] = "volatile",
611 [NFIT_SPA_PM] = "pmem",
612 [NFIT_SPA_DCR] = "dimm-control-region",
613 [NFIT_SPA_BDW] = "block-data-window",
614 [NFIT_SPA_VDISK] = "volatile-disk",
615 [NFIT_SPA_VCD] = "volatile-cd",
616 [NFIT_SPA_PDISK] = "persistent-disk",
617 [NFIT_SPA_PCD] = "persistent-cd",
621 if (type > NFIT_SPA_PCD)
624 return to_name[type];
627 int nfit_spa_type(struct acpi_nfit_system_address *spa)
631 for (i = 0; i < NFIT_UUID_MAX; i++)
632 if (guid_equal(to_nfit_uuid(i), (guid_t *)&spa->range_guid))
637 static bool add_spa(struct acpi_nfit_desc *acpi_desc,
638 struct nfit_table_prev *prev,
639 struct acpi_nfit_system_address *spa)
641 struct device *dev = acpi_desc->dev;
642 struct nfit_spa *nfit_spa;
644 if (spa->header.length != sizeof(*spa))
647 list_for_each_entry(nfit_spa, &prev->spas, list) {
648 if (memcmp(nfit_spa->spa, spa, sizeof(*spa)) == 0) {
649 list_move_tail(&nfit_spa->list, &acpi_desc->spas);
654 nfit_spa = devm_kzalloc(dev, sizeof(*nfit_spa) + sizeof(*spa),
658 INIT_LIST_HEAD(&nfit_spa->list);
659 memcpy(nfit_spa->spa, spa, sizeof(*spa));
660 list_add_tail(&nfit_spa->list, &acpi_desc->spas);
661 dev_dbg(dev, "spa index: %d type: %s\n",
663 spa_type_name(nfit_spa_type(spa)));
667 static bool add_memdev(struct acpi_nfit_desc *acpi_desc,
668 struct nfit_table_prev *prev,
669 struct acpi_nfit_memory_map *memdev)
671 struct device *dev = acpi_desc->dev;
672 struct nfit_memdev *nfit_memdev;
674 if (memdev->header.length != sizeof(*memdev))
677 list_for_each_entry(nfit_memdev, &prev->memdevs, list)
678 if (memcmp(nfit_memdev->memdev, memdev, sizeof(*memdev)) == 0) {
679 list_move_tail(&nfit_memdev->list, &acpi_desc->memdevs);
683 nfit_memdev = devm_kzalloc(dev, sizeof(*nfit_memdev) + sizeof(*memdev),
687 INIT_LIST_HEAD(&nfit_memdev->list);
688 memcpy(nfit_memdev->memdev, memdev, sizeof(*memdev));
689 list_add_tail(&nfit_memdev->list, &acpi_desc->memdevs);
690 dev_dbg(dev, "memdev handle: %#x spa: %d dcr: %d flags: %#x\n",
691 memdev->device_handle, memdev->range_index,
692 memdev->region_index, memdev->flags);
696 int nfit_get_smbios_id(u32 device_handle, u16 *flags)
698 struct acpi_nfit_memory_map *memdev;
699 struct acpi_nfit_desc *acpi_desc;
700 struct nfit_mem *nfit_mem;
702 mutex_lock(&acpi_desc_lock);
703 list_for_each_entry(acpi_desc, &acpi_descs, list) {
704 mutex_lock(&acpi_desc->init_mutex);
705 list_for_each_entry(nfit_mem, &acpi_desc->dimms, list) {
706 memdev = __to_nfit_memdev(nfit_mem);
707 if (memdev->device_handle == device_handle) {
708 mutex_unlock(&acpi_desc->init_mutex);
709 mutex_unlock(&acpi_desc_lock);
710 *flags = memdev->flags;
711 return memdev->physical_id;
714 mutex_unlock(&acpi_desc->init_mutex);
716 mutex_unlock(&acpi_desc_lock);
720 EXPORT_SYMBOL_GPL(nfit_get_smbios_id);
723 * An implementation may provide a truncated control region if no block windows
726 static size_t sizeof_dcr(struct acpi_nfit_control_region *dcr)
728 if (dcr->header.length < offsetof(struct acpi_nfit_control_region,
733 return offsetof(struct acpi_nfit_control_region, window_size);
736 static bool add_dcr(struct acpi_nfit_desc *acpi_desc,
737 struct nfit_table_prev *prev,
738 struct acpi_nfit_control_region *dcr)
740 struct device *dev = acpi_desc->dev;
741 struct nfit_dcr *nfit_dcr;
743 if (!sizeof_dcr(dcr))
746 list_for_each_entry(nfit_dcr, &prev->dcrs, list)
747 if (memcmp(nfit_dcr->dcr, dcr, sizeof_dcr(dcr)) == 0) {
748 list_move_tail(&nfit_dcr->list, &acpi_desc->dcrs);
752 nfit_dcr = devm_kzalloc(dev, sizeof(*nfit_dcr) + sizeof(*dcr),
756 INIT_LIST_HEAD(&nfit_dcr->list);
757 memcpy(nfit_dcr->dcr, dcr, sizeof_dcr(dcr));
758 list_add_tail(&nfit_dcr->list, &acpi_desc->dcrs);
759 dev_dbg(dev, "dcr index: %d windows: %d\n",
760 dcr->region_index, dcr->windows);
764 static bool add_bdw(struct acpi_nfit_desc *acpi_desc,
765 struct nfit_table_prev *prev,
766 struct acpi_nfit_data_region *bdw)
768 struct device *dev = acpi_desc->dev;
769 struct nfit_bdw *nfit_bdw;
771 if (bdw->header.length != sizeof(*bdw))
773 list_for_each_entry(nfit_bdw, &prev->bdws, list)
774 if (memcmp(nfit_bdw->bdw, bdw, sizeof(*bdw)) == 0) {
775 list_move_tail(&nfit_bdw->list, &acpi_desc->bdws);
779 nfit_bdw = devm_kzalloc(dev, sizeof(*nfit_bdw) + sizeof(*bdw),
783 INIT_LIST_HEAD(&nfit_bdw->list);
784 memcpy(nfit_bdw->bdw, bdw, sizeof(*bdw));
785 list_add_tail(&nfit_bdw->list, &acpi_desc->bdws);
786 dev_dbg(dev, "bdw dcr: %d windows: %d\n",
787 bdw->region_index, bdw->windows);
791 static size_t sizeof_idt(struct acpi_nfit_interleave *idt)
793 if (idt->header.length < sizeof(*idt))
795 return sizeof(*idt) + sizeof(u32) * (idt->line_count - 1);
798 static bool add_idt(struct acpi_nfit_desc *acpi_desc,
799 struct nfit_table_prev *prev,
800 struct acpi_nfit_interleave *idt)
802 struct device *dev = acpi_desc->dev;
803 struct nfit_idt *nfit_idt;
805 if (!sizeof_idt(idt))
808 list_for_each_entry(nfit_idt, &prev->idts, list) {
809 if (sizeof_idt(nfit_idt->idt) != sizeof_idt(idt))
812 if (memcmp(nfit_idt->idt, idt, sizeof_idt(idt)) == 0) {
813 list_move_tail(&nfit_idt->list, &acpi_desc->idts);
818 nfit_idt = devm_kzalloc(dev, sizeof(*nfit_idt) + sizeof_idt(idt),
822 INIT_LIST_HEAD(&nfit_idt->list);
823 memcpy(nfit_idt->idt, idt, sizeof_idt(idt));
824 list_add_tail(&nfit_idt->list, &acpi_desc->idts);
825 dev_dbg(dev, "idt index: %d num_lines: %d\n",
826 idt->interleave_index, idt->line_count);
830 static size_t sizeof_flush(struct acpi_nfit_flush_address *flush)
832 if (flush->header.length < sizeof(*flush))
834 return sizeof(*flush) + sizeof(u64) * (flush->hint_count - 1);
837 static bool add_flush(struct acpi_nfit_desc *acpi_desc,
838 struct nfit_table_prev *prev,
839 struct acpi_nfit_flush_address *flush)
841 struct device *dev = acpi_desc->dev;
842 struct nfit_flush *nfit_flush;
844 if (!sizeof_flush(flush))
847 list_for_each_entry(nfit_flush, &prev->flushes, list) {
848 if (sizeof_flush(nfit_flush->flush) != sizeof_flush(flush))
851 if (memcmp(nfit_flush->flush, flush,
852 sizeof_flush(flush)) == 0) {
853 list_move_tail(&nfit_flush->list, &acpi_desc->flushes);
858 nfit_flush = devm_kzalloc(dev, sizeof(*nfit_flush)
859 + sizeof_flush(flush), GFP_KERNEL);
862 INIT_LIST_HEAD(&nfit_flush->list);
863 memcpy(nfit_flush->flush, flush, sizeof_flush(flush));
864 list_add_tail(&nfit_flush->list, &acpi_desc->flushes);
865 dev_dbg(dev, "nfit_flush handle: %d hint_count: %d\n",
866 flush->device_handle, flush->hint_count);
870 static bool add_platform_cap(struct acpi_nfit_desc *acpi_desc,
871 struct acpi_nfit_capabilities *pcap)
873 struct device *dev = acpi_desc->dev;
876 mask = (1 << (pcap->highest_capability + 1)) - 1;
877 acpi_desc->platform_cap = pcap->capabilities & mask;
878 dev_dbg(dev, "cap: %#x\n", acpi_desc->platform_cap);
882 static void *add_table(struct acpi_nfit_desc *acpi_desc,
883 struct nfit_table_prev *prev, void *table, const void *end)
885 struct device *dev = acpi_desc->dev;
886 struct acpi_nfit_header *hdr;
887 void *err = ERR_PTR(-ENOMEM);
894 dev_warn(dev, "found a zero length table '%d' parsing nfit\n",
900 case ACPI_NFIT_TYPE_SYSTEM_ADDRESS:
901 if (!add_spa(acpi_desc, prev, table))
904 case ACPI_NFIT_TYPE_MEMORY_MAP:
905 if (!add_memdev(acpi_desc, prev, table))
908 case ACPI_NFIT_TYPE_CONTROL_REGION:
909 if (!add_dcr(acpi_desc, prev, table))
912 case ACPI_NFIT_TYPE_DATA_REGION:
913 if (!add_bdw(acpi_desc, prev, table))
916 case ACPI_NFIT_TYPE_INTERLEAVE:
917 if (!add_idt(acpi_desc, prev, table))
920 case ACPI_NFIT_TYPE_FLUSH_ADDRESS:
921 if (!add_flush(acpi_desc, prev, table))
924 case ACPI_NFIT_TYPE_SMBIOS:
925 dev_dbg(dev, "smbios\n");
927 case ACPI_NFIT_TYPE_CAPABILITIES:
928 if (!add_platform_cap(acpi_desc, table))
932 dev_err(dev, "unknown table '%d' parsing nfit\n", hdr->type);
936 return table + hdr->length;
939 static void nfit_mem_find_spa_bdw(struct acpi_nfit_desc *acpi_desc,
940 struct nfit_mem *nfit_mem)
942 u32 device_handle = __to_nfit_memdev(nfit_mem)->device_handle;
943 u16 dcr = nfit_mem->dcr->region_index;
944 struct nfit_spa *nfit_spa;
946 list_for_each_entry(nfit_spa, &acpi_desc->spas, list) {
947 u16 range_index = nfit_spa->spa->range_index;
948 int type = nfit_spa_type(nfit_spa->spa);
949 struct nfit_memdev *nfit_memdev;
951 if (type != NFIT_SPA_BDW)
954 list_for_each_entry(nfit_memdev, &acpi_desc->memdevs, list) {
955 if (nfit_memdev->memdev->range_index != range_index)
957 if (nfit_memdev->memdev->device_handle != device_handle)
959 if (nfit_memdev->memdev->region_index != dcr)
962 nfit_mem->spa_bdw = nfit_spa->spa;
967 dev_dbg(acpi_desc->dev, "SPA-BDW not found for SPA-DCR %d\n",
968 nfit_mem->spa_dcr->range_index);
969 nfit_mem->bdw = NULL;
972 static void nfit_mem_init_bdw(struct acpi_nfit_desc *acpi_desc,
973 struct nfit_mem *nfit_mem, struct acpi_nfit_system_address *spa)
975 u16 dcr = __to_nfit_memdev(nfit_mem)->region_index;
976 struct nfit_memdev *nfit_memdev;
977 struct nfit_bdw *nfit_bdw;
978 struct nfit_idt *nfit_idt;
979 u16 idt_idx, range_index;
981 list_for_each_entry(nfit_bdw, &acpi_desc->bdws, list) {
982 if (nfit_bdw->bdw->region_index != dcr)
984 nfit_mem->bdw = nfit_bdw->bdw;
991 nfit_mem_find_spa_bdw(acpi_desc, nfit_mem);
993 if (!nfit_mem->spa_bdw)
996 range_index = nfit_mem->spa_bdw->range_index;
997 list_for_each_entry(nfit_memdev, &acpi_desc->memdevs, list) {
998 if (nfit_memdev->memdev->range_index != range_index ||
999 nfit_memdev->memdev->region_index != dcr)
1001 nfit_mem->memdev_bdw = nfit_memdev->memdev;
1002 idt_idx = nfit_memdev->memdev->interleave_index;
1003 list_for_each_entry(nfit_idt, &acpi_desc->idts, list) {
1004 if (nfit_idt->idt->interleave_index != idt_idx)
1006 nfit_mem->idt_bdw = nfit_idt->idt;
1013 static int __nfit_mem_init(struct acpi_nfit_desc *acpi_desc,
1014 struct acpi_nfit_system_address *spa)
1016 struct nfit_mem *nfit_mem, *found;
1017 struct nfit_memdev *nfit_memdev;
1018 int type = spa ? nfit_spa_type(spa) : 0;
1030 * This loop runs in two modes, when a dimm is mapped the loop
1031 * adds memdev associations to an existing dimm, or creates a
1032 * dimm. In the unmapped dimm case this loop sweeps for memdev
1033 * instances with an invalid / zero range_index and adds those
1034 * dimms without spa associations.
1036 list_for_each_entry(nfit_memdev, &acpi_desc->memdevs, list) {
1037 struct nfit_flush *nfit_flush;
1038 struct nfit_dcr *nfit_dcr;
1042 if (spa && nfit_memdev->memdev->range_index != spa->range_index)
1044 if (!spa && nfit_memdev->memdev->range_index)
1047 dcr = nfit_memdev->memdev->region_index;
1048 device_handle = nfit_memdev->memdev->device_handle;
1049 list_for_each_entry(nfit_mem, &acpi_desc->dimms, list)
1050 if (__to_nfit_memdev(nfit_mem)->device_handle
1059 nfit_mem = devm_kzalloc(acpi_desc->dev,
1060 sizeof(*nfit_mem), GFP_KERNEL);
1063 INIT_LIST_HEAD(&nfit_mem->list);
1064 nfit_mem->acpi_desc = acpi_desc;
1065 list_add(&nfit_mem->list, &acpi_desc->dimms);
1068 list_for_each_entry(nfit_dcr, &acpi_desc->dcrs, list) {
1069 if (nfit_dcr->dcr->region_index != dcr)
1072 * Record the control region for the dimm. For
1073 * the ACPI 6.1 case, where there are separate
1074 * control regions for the pmem vs blk
1075 * interfaces, be sure to record the extended
1079 nfit_mem->dcr = nfit_dcr->dcr;
1080 else if (nfit_mem->dcr->windows == 0
1081 && nfit_dcr->dcr->windows)
1082 nfit_mem->dcr = nfit_dcr->dcr;
1086 list_for_each_entry(nfit_flush, &acpi_desc->flushes, list) {
1087 struct acpi_nfit_flush_address *flush;
1090 if (nfit_flush->flush->device_handle != device_handle)
1092 nfit_mem->nfit_flush = nfit_flush;
1093 flush = nfit_flush->flush;
1094 nfit_mem->flush_wpq = devm_kcalloc(acpi_desc->dev,
1096 sizeof(struct resource),
1098 if (!nfit_mem->flush_wpq)
1100 for (i = 0; i < flush->hint_count; i++) {
1101 struct resource *res = &nfit_mem->flush_wpq[i];
1103 res->start = flush->hint_address[i];
1104 res->end = res->start + 8 - 1;
1109 if (dcr && !nfit_mem->dcr) {
1110 dev_err(acpi_desc->dev, "SPA %d missing DCR %d\n",
1111 spa->range_index, dcr);
1115 if (type == NFIT_SPA_DCR) {
1116 struct nfit_idt *nfit_idt;
1119 /* multiple dimms may share a SPA when interleaved */
1120 nfit_mem->spa_dcr = spa;
1121 nfit_mem->memdev_dcr = nfit_memdev->memdev;
1122 idt_idx = nfit_memdev->memdev->interleave_index;
1123 list_for_each_entry(nfit_idt, &acpi_desc->idts, list) {
1124 if (nfit_idt->idt->interleave_index != idt_idx)
1126 nfit_mem->idt_dcr = nfit_idt->idt;
1129 nfit_mem_init_bdw(acpi_desc, nfit_mem, spa);
1130 } else if (type == NFIT_SPA_PM) {
1132 * A single dimm may belong to multiple SPA-PM
1133 * ranges, record at least one in addition to
1134 * any SPA-DCR range.
1136 nfit_mem->memdev_pmem = nfit_memdev->memdev;
1138 nfit_mem->memdev_dcr = nfit_memdev->memdev;
1144 static int nfit_mem_cmp(void *priv, struct list_head *_a, struct list_head *_b)
1146 struct nfit_mem *a = container_of(_a, typeof(*a), list);
1147 struct nfit_mem *b = container_of(_b, typeof(*b), list);
1148 u32 handleA, handleB;
1150 handleA = __to_nfit_memdev(a)->device_handle;
1151 handleB = __to_nfit_memdev(b)->device_handle;
1152 if (handleA < handleB)
1154 else if (handleA > handleB)
1159 static int nfit_mem_init(struct acpi_nfit_desc *acpi_desc)
1161 struct nfit_spa *nfit_spa;
1166 * For each SPA-DCR or SPA-PMEM address range find its
1167 * corresponding MEMDEV(s). From each MEMDEV find the
1168 * corresponding DCR. Then, if we're operating on a SPA-DCR,
1169 * try to find a SPA-BDW and a corresponding BDW that references
1170 * the DCR. Throw it all into an nfit_mem object. Note, that
1171 * BDWs are optional.
1173 list_for_each_entry(nfit_spa, &acpi_desc->spas, list) {
1174 rc = __nfit_mem_init(acpi_desc, nfit_spa->spa);
1180 * If a DIMM has failed to be mapped into SPA there will be no
1181 * SPA entries above. Find and register all the unmapped DIMMs
1182 * for reporting and recovery purposes.
1184 rc = __nfit_mem_init(acpi_desc, NULL);
1188 list_sort(NULL, &acpi_desc->dimms, nfit_mem_cmp);
1193 static ssize_t bus_dsm_mask_show(struct device *dev,
1194 struct device_attribute *attr, char *buf)
1196 struct nvdimm_bus *nvdimm_bus = to_nvdimm_bus(dev);
1197 struct nvdimm_bus_descriptor *nd_desc = to_nd_desc(nvdimm_bus);
1199 return sprintf(buf, "%#lx\n", nd_desc->bus_dsm_mask);
1201 static struct device_attribute dev_attr_bus_dsm_mask =
1202 __ATTR(dsm_mask, 0444, bus_dsm_mask_show, NULL);
1204 static ssize_t revision_show(struct device *dev,
1205 struct device_attribute *attr, char *buf)
1207 struct nvdimm_bus *nvdimm_bus = to_nvdimm_bus(dev);
1208 struct nvdimm_bus_descriptor *nd_desc = to_nd_desc(nvdimm_bus);
1209 struct acpi_nfit_desc *acpi_desc = to_acpi_desc(nd_desc);
1211 return sprintf(buf, "%d\n", acpi_desc->acpi_header.revision);
1213 static DEVICE_ATTR_RO(revision);
1215 static ssize_t hw_error_scrub_show(struct device *dev,
1216 struct device_attribute *attr, char *buf)
1218 struct nvdimm_bus *nvdimm_bus = to_nvdimm_bus(dev);
1219 struct nvdimm_bus_descriptor *nd_desc = to_nd_desc(nvdimm_bus);
1220 struct acpi_nfit_desc *acpi_desc = to_acpi_desc(nd_desc);
1222 return sprintf(buf, "%d\n", acpi_desc->scrub_mode);
1226 * The 'hw_error_scrub' attribute can have the following values written to it:
1227 * '0': Switch to the default mode where an exception will only insert
1228 * the address of the memory error into the poison and badblocks lists.
1229 * '1': Enable a full scrub to happen if an exception for a memory error is
1232 static ssize_t hw_error_scrub_store(struct device *dev,
1233 struct device_attribute *attr, const char *buf, size_t size)
1235 struct nvdimm_bus_descriptor *nd_desc;
1239 rc = kstrtol(buf, 0, &val);
1244 nd_desc = dev_get_drvdata(dev);
1246 struct acpi_nfit_desc *acpi_desc = to_acpi_desc(nd_desc);
1249 case HW_ERROR_SCRUB_ON:
1250 acpi_desc->scrub_mode = HW_ERROR_SCRUB_ON;
1252 case HW_ERROR_SCRUB_OFF:
1253 acpi_desc->scrub_mode = HW_ERROR_SCRUB_OFF;
1265 static DEVICE_ATTR_RW(hw_error_scrub);
1268 * This shows the number of full Address Range Scrubs that have been
1269 * completed since driver load time. Userspace can wait on this using
1270 * select/poll etc. A '+' at the end indicates an ARS is in progress
1272 static ssize_t scrub_show(struct device *dev,
1273 struct device_attribute *attr, char *buf)
1275 struct nvdimm_bus_descriptor *nd_desc;
1276 ssize_t rc = -ENXIO;
1279 nd_desc = dev_get_drvdata(dev);
1281 struct acpi_nfit_desc *acpi_desc = to_acpi_desc(nd_desc);
1283 mutex_lock(&acpi_desc->init_mutex);
1284 rc = sprintf(buf, "%d%s", acpi_desc->scrub_count,
1285 acpi_desc->scrub_busy
1286 && !acpi_desc->cancel ? "+\n" : "\n");
1287 mutex_unlock(&acpi_desc->init_mutex);
1293 static ssize_t scrub_store(struct device *dev,
1294 struct device_attribute *attr, const char *buf, size_t size)
1296 struct nvdimm_bus_descriptor *nd_desc;
1300 rc = kstrtol(buf, 0, &val);
1307 nd_desc = dev_get_drvdata(dev);
1309 struct acpi_nfit_desc *acpi_desc = to_acpi_desc(nd_desc);
1311 rc = acpi_nfit_ars_rescan(acpi_desc, 0);
1318 static DEVICE_ATTR_RW(scrub);
1320 static bool ars_supported(struct nvdimm_bus *nvdimm_bus)
1322 struct nvdimm_bus_descriptor *nd_desc = to_nd_desc(nvdimm_bus);
1323 const unsigned long mask = 1 << ND_CMD_ARS_CAP | 1 << ND_CMD_ARS_START
1324 | 1 << ND_CMD_ARS_STATUS;
1326 return (nd_desc->cmd_mask & mask) == mask;
1329 static umode_t nfit_visible(struct kobject *kobj, struct attribute *a, int n)
1331 struct device *dev = container_of(kobj, struct device, kobj);
1332 struct nvdimm_bus *nvdimm_bus = to_nvdimm_bus(dev);
1334 if (a == &dev_attr_scrub.attr && !ars_supported(nvdimm_bus))
1339 static struct attribute *acpi_nfit_attributes[] = {
1340 &dev_attr_revision.attr,
1341 &dev_attr_scrub.attr,
1342 &dev_attr_hw_error_scrub.attr,
1343 &dev_attr_bus_dsm_mask.attr,
1347 static const struct attribute_group acpi_nfit_attribute_group = {
1349 .attrs = acpi_nfit_attributes,
1350 .is_visible = nfit_visible,
1353 static const struct attribute_group *acpi_nfit_attribute_groups[] = {
1354 &nvdimm_bus_attribute_group,
1355 &acpi_nfit_attribute_group,
1359 static struct acpi_nfit_memory_map *to_nfit_memdev(struct device *dev)
1361 struct nvdimm *nvdimm = to_nvdimm(dev);
1362 struct nfit_mem *nfit_mem = nvdimm_provider_data(nvdimm);
1364 return __to_nfit_memdev(nfit_mem);
1367 static struct acpi_nfit_control_region *to_nfit_dcr(struct device *dev)
1369 struct nvdimm *nvdimm = to_nvdimm(dev);
1370 struct nfit_mem *nfit_mem = nvdimm_provider_data(nvdimm);
1372 return nfit_mem->dcr;
1375 static ssize_t handle_show(struct device *dev,
1376 struct device_attribute *attr, char *buf)
1378 struct acpi_nfit_memory_map *memdev = to_nfit_memdev(dev);
1380 return sprintf(buf, "%#x\n", memdev->device_handle);
1382 static DEVICE_ATTR_RO(handle);
1384 static ssize_t phys_id_show(struct device *dev,
1385 struct device_attribute *attr, char *buf)
1387 struct acpi_nfit_memory_map *memdev = to_nfit_memdev(dev);
1389 return sprintf(buf, "%#x\n", memdev->physical_id);
1391 static DEVICE_ATTR_RO(phys_id);
1393 static ssize_t vendor_show(struct device *dev,
1394 struct device_attribute *attr, char *buf)
1396 struct acpi_nfit_control_region *dcr = to_nfit_dcr(dev);
1398 return sprintf(buf, "0x%04x\n", be16_to_cpu(dcr->vendor_id));
1400 static DEVICE_ATTR_RO(vendor);
1402 static ssize_t rev_id_show(struct device *dev,
1403 struct device_attribute *attr, char *buf)
1405 struct acpi_nfit_control_region *dcr = to_nfit_dcr(dev);
1407 return sprintf(buf, "0x%04x\n", be16_to_cpu(dcr->revision_id));
1409 static DEVICE_ATTR_RO(rev_id);
1411 static ssize_t device_show(struct device *dev,
1412 struct device_attribute *attr, char *buf)
1414 struct acpi_nfit_control_region *dcr = to_nfit_dcr(dev);
1416 return sprintf(buf, "0x%04x\n", be16_to_cpu(dcr->device_id));
1418 static DEVICE_ATTR_RO(device);
1420 static ssize_t subsystem_vendor_show(struct device *dev,
1421 struct device_attribute *attr, char *buf)
1423 struct acpi_nfit_control_region *dcr = to_nfit_dcr(dev);
1425 return sprintf(buf, "0x%04x\n", be16_to_cpu(dcr->subsystem_vendor_id));
1427 static DEVICE_ATTR_RO(subsystem_vendor);
1429 static ssize_t subsystem_rev_id_show(struct device *dev,
1430 struct device_attribute *attr, char *buf)
1432 struct acpi_nfit_control_region *dcr = to_nfit_dcr(dev);
1434 return sprintf(buf, "0x%04x\n",
1435 be16_to_cpu(dcr->subsystem_revision_id));
1437 static DEVICE_ATTR_RO(subsystem_rev_id);
1439 static ssize_t subsystem_device_show(struct device *dev,
1440 struct device_attribute *attr, char *buf)
1442 struct acpi_nfit_control_region *dcr = to_nfit_dcr(dev);
1444 return sprintf(buf, "0x%04x\n", be16_to_cpu(dcr->subsystem_device_id));
1446 static DEVICE_ATTR_RO(subsystem_device);
1448 static int num_nvdimm_formats(struct nvdimm *nvdimm)
1450 struct nfit_mem *nfit_mem = nvdimm_provider_data(nvdimm);
1453 if (nfit_mem->memdev_pmem)
1455 if (nfit_mem->memdev_bdw)
1460 static ssize_t format_show(struct device *dev,
1461 struct device_attribute *attr, char *buf)
1463 struct acpi_nfit_control_region *dcr = to_nfit_dcr(dev);
1465 return sprintf(buf, "0x%04x\n", le16_to_cpu(dcr->code));
1467 static DEVICE_ATTR_RO(format);
1469 static ssize_t format1_show(struct device *dev,
1470 struct device_attribute *attr, char *buf)
1473 ssize_t rc = -ENXIO;
1474 struct nfit_mem *nfit_mem;
1475 struct nfit_memdev *nfit_memdev;
1476 struct acpi_nfit_desc *acpi_desc;
1477 struct nvdimm *nvdimm = to_nvdimm(dev);
1478 struct acpi_nfit_control_region *dcr = to_nfit_dcr(dev);
1480 nfit_mem = nvdimm_provider_data(nvdimm);
1481 acpi_desc = nfit_mem->acpi_desc;
1482 handle = to_nfit_memdev(dev)->device_handle;
1484 /* assumes DIMMs have at most 2 published interface codes */
1485 mutex_lock(&acpi_desc->init_mutex);
1486 list_for_each_entry(nfit_memdev, &acpi_desc->memdevs, list) {
1487 struct acpi_nfit_memory_map *memdev = nfit_memdev->memdev;
1488 struct nfit_dcr *nfit_dcr;
1490 if (memdev->device_handle != handle)
1493 list_for_each_entry(nfit_dcr, &acpi_desc->dcrs, list) {
1494 if (nfit_dcr->dcr->region_index != memdev->region_index)
1496 if (nfit_dcr->dcr->code == dcr->code)
1498 rc = sprintf(buf, "0x%04x\n",
1499 le16_to_cpu(nfit_dcr->dcr->code));
1505 mutex_unlock(&acpi_desc->init_mutex);
1508 static DEVICE_ATTR_RO(format1);
1510 static ssize_t formats_show(struct device *dev,
1511 struct device_attribute *attr, char *buf)
1513 struct nvdimm *nvdimm = to_nvdimm(dev);
1515 return sprintf(buf, "%d\n", num_nvdimm_formats(nvdimm));
1517 static DEVICE_ATTR_RO(formats);
1519 static ssize_t serial_show(struct device *dev,
1520 struct device_attribute *attr, char *buf)
1522 struct acpi_nfit_control_region *dcr = to_nfit_dcr(dev);
1524 return sprintf(buf, "0x%08x\n", be32_to_cpu(dcr->serial_number));
1526 static DEVICE_ATTR_RO(serial);
1528 static ssize_t family_show(struct device *dev,
1529 struct device_attribute *attr, char *buf)
1531 struct nvdimm *nvdimm = to_nvdimm(dev);
1532 struct nfit_mem *nfit_mem = nvdimm_provider_data(nvdimm);
1534 if (nfit_mem->family < 0)
1536 return sprintf(buf, "%d\n", nfit_mem->family);
1538 static DEVICE_ATTR_RO(family);
1540 static ssize_t dsm_mask_show(struct device *dev,
1541 struct device_attribute *attr, char *buf)
1543 struct nvdimm *nvdimm = to_nvdimm(dev);
1544 struct nfit_mem *nfit_mem = nvdimm_provider_data(nvdimm);
1546 if (nfit_mem->family < 0)
1548 return sprintf(buf, "%#lx\n", nfit_mem->dsm_mask);
1550 static DEVICE_ATTR_RO(dsm_mask);
1552 static ssize_t flags_show(struct device *dev,
1553 struct device_attribute *attr, char *buf)
1555 struct nvdimm *nvdimm = to_nvdimm(dev);
1556 struct nfit_mem *nfit_mem = nvdimm_provider_data(nvdimm);
1557 u16 flags = __to_nfit_memdev(nfit_mem)->flags;
1559 if (test_bit(NFIT_MEM_DIRTY, &nfit_mem->flags))
1560 flags |= ACPI_NFIT_MEM_FLUSH_FAILED;
1562 return sprintf(buf, "%s%s%s%s%s%s%s\n",
1563 flags & ACPI_NFIT_MEM_SAVE_FAILED ? "save_fail " : "",
1564 flags & ACPI_NFIT_MEM_RESTORE_FAILED ? "restore_fail " : "",
1565 flags & ACPI_NFIT_MEM_FLUSH_FAILED ? "flush_fail " : "",
1566 flags & ACPI_NFIT_MEM_NOT_ARMED ? "not_armed " : "",
1567 flags & ACPI_NFIT_MEM_HEALTH_OBSERVED ? "smart_event " : "",
1568 flags & ACPI_NFIT_MEM_MAP_FAILED ? "map_fail " : "",
1569 flags & ACPI_NFIT_MEM_HEALTH_ENABLED ? "smart_notify " : "");
1571 static DEVICE_ATTR_RO(flags);
1573 static ssize_t id_show(struct device *dev,
1574 struct device_attribute *attr, char *buf)
1576 struct acpi_nfit_control_region *dcr = to_nfit_dcr(dev);
1578 if (dcr->valid_fields & ACPI_NFIT_CONTROL_MFG_INFO_VALID)
1579 return sprintf(buf, "%04x-%02x-%04x-%08x\n",
1580 be16_to_cpu(dcr->vendor_id),
1581 dcr->manufacturing_location,
1582 be16_to_cpu(dcr->manufacturing_date),
1583 be32_to_cpu(dcr->serial_number));
1585 return sprintf(buf, "%04x-%08x\n",
1586 be16_to_cpu(dcr->vendor_id),
1587 be32_to_cpu(dcr->serial_number));
1589 static DEVICE_ATTR_RO(id);
1591 static ssize_t dirty_shutdown_show(struct device *dev,
1592 struct device_attribute *attr, char *buf)
1594 struct nvdimm *nvdimm = to_nvdimm(dev);
1595 struct nfit_mem *nfit_mem = nvdimm_provider_data(nvdimm);
1597 return sprintf(buf, "%d\n", nfit_mem->dirty_shutdown);
1599 static DEVICE_ATTR_RO(dirty_shutdown);
1601 static struct attribute *acpi_nfit_dimm_attributes[] = {
1602 &dev_attr_handle.attr,
1603 &dev_attr_phys_id.attr,
1604 &dev_attr_vendor.attr,
1605 &dev_attr_device.attr,
1606 &dev_attr_rev_id.attr,
1607 &dev_attr_subsystem_vendor.attr,
1608 &dev_attr_subsystem_device.attr,
1609 &dev_attr_subsystem_rev_id.attr,
1610 &dev_attr_format.attr,
1611 &dev_attr_formats.attr,
1612 &dev_attr_format1.attr,
1613 &dev_attr_serial.attr,
1614 &dev_attr_flags.attr,
1616 &dev_attr_family.attr,
1617 &dev_attr_dsm_mask.attr,
1618 &dev_attr_dirty_shutdown.attr,
1622 static umode_t acpi_nfit_dimm_attr_visible(struct kobject *kobj,
1623 struct attribute *a, int n)
1625 struct device *dev = container_of(kobj, struct device, kobj);
1626 struct nvdimm *nvdimm = to_nvdimm(dev);
1627 struct nfit_mem *nfit_mem = nvdimm_provider_data(nvdimm);
1629 if (!to_nfit_dcr(dev)) {
1630 /* Without a dcr only the memdev attributes can be surfaced */
1631 if (a == &dev_attr_handle.attr || a == &dev_attr_phys_id.attr
1632 || a == &dev_attr_flags.attr
1633 || a == &dev_attr_family.attr
1634 || a == &dev_attr_dsm_mask.attr)
1639 if (a == &dev_attr_format1.attr && num_nvdimm_formats(nvdimm) <= 1)
1642 if (!test_bit(NFIT_MEM_DIRTY_COUNT, &nfit_mem->flags)
1643 && a == &dev_attr_dirty_shutdown.attr)
1649 static const struct attribute_group acpi_nfit_dimm_attribute_group = {
1651 .attrs = acpi_nfit_dimm_attributes,
1652 .is_visible = acpi_nfit_dimm_attr_visible,
1655 static const struct attribute_group *acpi_nfit_dimm_attribute_groups[] = {
1656 &nvdimm_attribute_group,
1657 &nd_device_attribute_group,
1658 &acpi_nfit_dimm_attribute_group,
1662 static struct nvdimm *acpi_nfit_dimm_by_handle(struct acpi_nfit_desc *acpi_desc,
1665 struct nfit_mem *nfit_mem;
1667 list_for_each_entry(nfit_mem, &acpi_desc->dimms, list)
1668 if (__to_nfit_memdev(nfit_mem)->device_handle == device_handle)
1669 return nfit_mem->nvdimm;
1674 void __acpi_nvdimm_notify(struct device *dev, u32 event)
1676 struct nfit_mem *nfit_mem;
1677 struct acpi_nfit_desc *acpi_desc;
1679 dev_dbg(dev->parent, "%s: event: %d\n", dev_name(dev),
1682 if (event != NFIT_NOTIFY_DIMM_HEALTH) {
1683 dev_dbg(dev->parent, "%s: unknown event: %d\n", dev_name(dev),
1688 acpi_desc = dev_get_drvdata(dev->parent);
1693 * If we successfully retrieved acpi_desc, then we know nfit_mem data
1696 nfit_mem = dev_get_drvdata(dev);
1697 if (nfit_mem && nfit_mem->flags_attr)
1698 sysfs_notify_dirent(nfit_mem->flags_attr);
1700 EXPORT_SYMBOL_GPL(__acpi_nvdimm_notify);
1702 static void acpi_nvdimm_notify(acpi_handle handle, u32 event, void *data)
1704 struct acpi_device *adev = data;
1705 struct device *dev = &adev->dev;
1707 device_lock(dev->parent);
1708 __acpi_nvdimm_notify(dev, event);
1709 device_unlock(dev->parent);
1712 static bool acpi_nvdimm_has_method(struct acpi_device *adev, char *method)
1717 status = acpi_get_handle(adev->handle, method, &handle);
1719 if (ACPI_SUCCESS(status))
1724 __weak void nfit_intel_shutdown_status(struct nfit_mem *nfit_mem)
1726 struct nd_intel_smart smart = { 0 };
1727 union acpi_object in_buf = {
1728 .type = ACPI_TYPE_BUFFER,
1729 .buffer.pointer = (char *) &smart,
1730 .buffer.length = sizeof(smart),
1732 union acpi_object in_obj = {
1733 .type = ACPI_TYPE_PACKAGE,
1735 .package.elements = &in_buf,
1737 const u8 func = ND_INTEL_SMART;
1738 const guid_t *guid = to_nfit_uuid(nfit_mem->family);
1739 u8 revid = nfit_dsm_revid(nfit_mem->family, func);
1740 struct acpi_device *adev = nfit_mem->adev;
1741 acpi_handle handle = adev->handle;
1742 union acpi_object *out_obj;
1744 if ((nfit_mem->dsm_mask & (1 << func)) == 0)
1747 out_obj = acpi_evaluate_dsm(handle, guid, revid, func, &in_obj);
1751 if (smart.flags & ND_INTEL_SMART_SHUTDOWN_VALID) {
1752 if (smart.shutdown_state)
1753 set_bit(NFIT_MEM_DIRTY, &nfit_mem->flags);
1756 if (smart.flags & ND_INTEL_SMART_SHUTDOWN_COUNT_VALID) {
1757 set_bit(NFIT_MEM_DIRTY_COUNT, &nfit_mem->flags);
1758 nfit_mem->dirty_shutdown = smart.shutdown_count;
1763 static void populate_shutdown_status(struct nfit_mem *nfit_mem)
1766 * For DIMMs that provide a dynamic facility to retrieve a
1767 * dirty-shutdown status and/or a dirty-shutdown count, cache
1768 * these values in nfit_mem.
1770 if (nfit_mem->family == NVDIMM_FAMILY_INTEL)
1771 nfit_intel_shutdown_status(nfit_mem);
1774 static int acpi_nfit_add_dimm(struct acpi_nfit_desc *acpi_desc,
1775 struct nfit_mem *nfit_mem, u32 device_handle)
1777 struct acpi_device *adev, *adev_dimm;
1778 struct device *dev = acpi_desc->dev;
1779 unsigned long dsm_mask, label_mask;
1784 /* nfit test assumes 1:1 relationship between commands and dsms */
1785 nfit_mem->dsm_mask = acpi_desc->dimm_cmd_force_en;
1786 nfit_mem->family = NVDIMM_FAMILY_INTEL;
1787 adev = to_acpi_dev(acpi_desc);
1789 /* unit test case */
1790 populate_shutdown_status(nfit_mem);
1794 adev_dimm = acpi_find_child_device(adev, device_handle, false);
1795 nfit_mem->adev = adev_dimm;
1797 dev_err(dev, "no ACPI.NFIT device with _ADR %#x, disabling...\n",
1799 return force_enable_dimms ? 0 : -ENODEV;
1802 if (ACPI_FAILURE(acpi_install_notify_handler(adev_dimm->handle,
1803 ACPI_DEVICE_NOTIFY, acpi_nvdimm_notify, adev_dimm))) {
1804 dev_err(dev, "%s: notification registration failed\n",
1805 dev_name(&adev_dimm->dev));
1809 * Record nfit_mem for the notification path to track back to
1810 * the nfit sysfs attributes for this dimm device object.
1812 dev_set_drvdata(&adev_dimm->dev, nfit_mem);
1815 * Until standardization materializes we need to consider 4
1816 * different command sets. Note, that checking for function0 (bit0)
1817 * tells us if any commands are reachable through this GUID.
1819 for (i = 0; i <= NVDIMM_FAMILY_MAX; i++)
1820 if (acpi_check_dsm(adev_dimm->handle, to_nfit_uuid(i), 1, 1))
1821 if (family < 0 || i == default_dsm_family)
1824 /* limit the supported commands to those that are publicly documented */
1825 nfit_mem->family = family;
1826 if (override_dsm_mask && !disable_vendor_specific)
1827 dsm_mask = override_dsm_mask;
1828 else if (nfit_mem->family == NVDIMM_FAMILY_INTEL) {
1829 dsm_mask = NVDIMM_INTEL_CMDMASK;
1830 if (disable_vendor_specific)
1831 dsm_mask &= ~(1 << ND_CMD_VENDOR);
1832 } else if (nfit_mem->family == NVDIMM_FAMILY_HPE1) {
1833 dsm_mask = 0x1c3c76;
1834 } else if (nfit_mem->family == NVDIMM_FAMILY_HPE2) {
1836 if (disable_vendor_specific)
1837 dsm_mask &= ~(1 << 8);
1838 } else if (nfit_mem->family == NVDIMM_FAMILY_MSFT) {
1839 dsm_mask = 0xffffffff;
1841 dev_dbg(dev, "unknown dimm command family\n");
1842 nfit_mem->family = -1;
1843 /* DSMs are optional, continue loading the driver... */
1847 guid = to_nfit_uuid(nfit_mem->family);
1848 for_each_set_bit(i, &dsm_mask, BITS_PER_LONG)
1849 if (acpi_check_dsm(adev_dimm->handle, guid,
1850 nfit_dsm_revid(nfit_mem->family, i),
1852 set_bit(i, &nfit_mem->dsm_mask);
1855 * Prefer the NVDIMM_FAMILY_INTEL label read commands if present
1856 * due to their better semantics handling locked capacity.
1858 label_mask = 1 << ND_CMD_GET_CONFIG_SIZE | 1 << ND_CMD_GET_CONFIG_DATA
1859 | 1 << ND_CMD_SET_CONFIG_DATA;
1860 if (family == NVDIMM_FAMILY_INTEL
1861 && (dsm_mask & label_mask) == label_mask)
1864 if (acpi_nvdimm_has_method(adev_dimm, "_LSI")
1865 && acpi_nvdimm_has_method(adev_dimm, "_LSR")) {
1866 dev_dbg(dev, "%s: has _LSR\n", dev_name(&adev_dimm->dev));
1867 set_bit(NFIT_MEM_LSR, &nfit_mem->flags);
1870 if (test_bit(NFIT_MEM_LSR, &nfit_mem->flags)
1871 && acpi_nvdimm_has_method(adev_dimm, "_LSW")) {
1872 dev_dbg(dev, "%s: has _LSW\n", dev_name(&adev_dimm->dev));
1873 set_bit(NFIT_MEM_LSW, &nfit_mem->flags);
1876 populate_shutdown_status(nfit_mem);
1881 static void shutdown_dimm_notify(void *data)
1883 struct acpi_nfit_desc *acpi_desc = data;
1884 struct nfit_mem *nfit_mem;
1886 mutex_lock(&acpi_desc->init_mutex);
1888 * Clear out the nfit_mem->flags_attr and shut down dimm event
1891 list_for_each_entry(nfit_mem, &acpi_desc->dimms, list) {
1892 struct acpi_device *adev_dimm = nfit_mem->adev;
1894 if (nfit_mem->flags_attr) {
1895 sysfs_put(nfit_mem->flags_attr);
1896 nfit_mem->flags_attr = NULL;
1899 acpi_remove_notify_handler(adev_dimm->handle,
1900 ACPI_DEVICE_NOTIFY, acpi_nvdimm_notify);
1901 dev_set_drvdata(&adev_dimm->dev, NULL);
1904 mutex_unlock(&acpi_desc->init_mutex);
1907 static int acpi_nfit_register_dimms(struct acpi_nfit_desc *acpi_desc)
1909 struct nfit_mem *nfit_mem;
1910 int dimm_count = 0, rc;
1911 struct nvdimm *nvdimm;
1913 list_for_each_entry(nfit_mem, &acpi_desc->dimms, list) {
1914 struct acpi_nfit_flush_address *flush;
1915 unsigned long flags = 0, cmd_mask;
1916 struct nfit_memdev *nfit_memdev;
1920 device_handle = __to_nfit_memdev(nfit_mem)->device_handle;
1921 nvdimm = acpi_nfit_dimm_by_handle(acpi_desc, device_handle);
1927 if (nfit_mem->bdw && nfit_mem->memdev_pmem)
1928 set_bit(NDD_ALIASING, &flags);
1930 /* collate flags across all memdevs for this dimm */
1931 list_for_each_entry(nfit_memdev, &acpi_desc->memdevs, list) {
1932 struct acpi_nfit_memory_map *dimm_memdev;
1934 dimm_memdev = __to_nfit_memdev(nfit_mem);
1935 if (dimm_memdev->device_handle
1936 != nfit_memdev->memdev->device_handle)
1938 dimm_memdev->flags |= nfit_memdev->memdev->flags;
1941 mem_flags = __to_nfit_memdev(nfit_mem)->flags;
1942 if (mem_flags & ACPI_NFIT_MEM_NOT_ARMED)
1943 set_bit(NDD_UNARMED, &flags);
1945 rc = acpi_nfit_add_dimm(acpi_desc, nfit_mem, device_handle);
1950 * TODO: provide translation for non-NVDIMM_FAMILY_INTEL
1951 * devices (i.e. from nd_cmd to acpi_dsm) to standardize the
1952 * userspace interface.
1954 cmd_mask = 1UL << ND_CMD_CALL;
1955 if (nfit_mem->family == NVDIMM_FAMILY_INTEL) {
1957 * These commands have a 1:1 correspondence
1958 * between DSM payload and libnvdimm ioctl
1961 cmd_mask |= nfit_mem->dsm_mask & NVDIMM_STANDARD_CMDMASK;
1964 if (test_bit(NFIT_MEM_LSR, &nfit_mem->flags)) {
1965 set_bit(ND_CMD_GET_CONFIG_SIZE, &cmd_mask);
1966 set_bit(ND_CMD_GET_CONFIG_DATA, &cmd_mask);
1968 if (test_bit(NFIT_MEM_LSW, &nfit_mem->flags))
1969 set_bit(ND_CMD_SET_CONFIG_DATA, &cmd_mask);
1971 flush = nfit_mem->nfit_flush ? nfit_mem->nfit_flush->flush
1973 nvdimm = nvdimm_create(acpi_desc->nvdimm_bus, nfit_mem,
1974 acpi_nfit_dimm_attribute_groups,
1975 flags, cmd_mask, flush ? flush->hint_count : 0,
1976 nfit_mem->flush_wpq);
1980 nfit_mem->nvdimm = nvdimm;
1983 if ((mem_flags & ACPI_NFIT_MEM_FAILED_MASK) == 0)
1986 dev_info(acpi_desc->dev, "%s flags:%s%s%s%s%s\n",
1987 nvdimm_name(nvdimm),
1988 mem_flags & ACPI_NFIT_MEM_SAVE_FAILED ? " save_fail" : "",
1989 mem_flags & ACPI_NFIT_MEM_RESTORE_FAILED ? " restore_fail":"",
1990 mem_flags & ACPI_NFIT_MEM_FLUSH_FAILED ? " flush_fail" : "",
1991 mem_flags & ACPI_NFIT_MEM_NOT_ARMED ? " not_armed" : "",
1992 mem_flags & ACPI_NFIT_MEM_MAP_FAILED ? " map_fail" : "");
1996 rc = nvdimm_bus_check_dimm_count(acpi_desc->nvdimm_bus, dimm_count);
2001 * Now that dimms are successfully registered, and async registration
2002 * is flushed, attempt to enable event notification.
2004 list_for_each_entry(nfit_mem, &acpi_desc->dimms, list) {
2005 struct kernfs_node *nfit_kernfs;
2007 nvdimm = nfit_mem->nvdimm;
2011 nfit_kernfs = sysfs_get_dirent(nvdimm_kobj(nvdimm)->sd, "nfit");
2013 nfit_mem->flags_attr = sysfs_get_dirent(nfit_kernfs,
2015 sysfs_put(nfit_kernfs);
2016 if (!nfit_mem->flags_attr)
2017 dev_warn(acpi_desc->dev, "%s: notifications disabled\n",
2018 nvdimm_name(nvdimm));
2021 return devm_add_action_or_reset(acpi_desc->dev, shutdown_dimm_notify,
2026 * These constants are private because there are no kernel consumers of
2029 enum nfit_aux_cmds {
2030 NFIT_CMD_TRANSLATE_SPA = 5,
2031 NFIT_CMD_ARS_INJECT_SET = 7,
2032 NFIT_CMD_ARS_INJECT_CLEAR = 8,
2033 NFIT_CMD_ARS_INJECT_GET = 9,
2036 static void acpi_nfit_init_dsms(struct acpi_nfit_desc *acpi_desc)
2038 struct nvdimm_bus_descriptor *nd_desc = &acpi_desc->nd_desc;
2039 const guid_t *guid = to_nfit_uuid(NFIT_DEV_BUS);
2040 struct acpi_device *adev;
2041 unsigned long dsm_mask;
2044 nd_desc->cmd_mask = acpi_desc->bus_cmd_force_en;
2045 nd_desc->bus_dsm_mask = acpi_desc->bus_nfit_cmd_force_en;
2046 adev = to_acpi_dev(acpi_desc);
2050 for (i = ND_CMD_ARS_CAP; i <= ND_CMD_CLEAR_ERROR; i++)
2051 if (acpi_check_dsm(adev->handle, guid, 1, 1ULL << i))
2052 set_bit(i, &nd_desc->cmd_mask);
2053 set_bit(ND_CMD_CALL, &nd_desc->cmd_mask);
2056 (1 << ND_CMD_ARS_CAP) |
2057 (1 << ND_CMD_ARS_START) |
2058 (1 << ND_CMD_ARS_STATUS) |
2059 (1 << ND_CMD_CLEAR_ERROR) |
2060 (1 << NFIT_CMD_TRANSLATE_SPA) |
2061 (1 << NFIT_CMD_ARS_INJECT_SET) |
2062 (1 << NFIT_CMD_ARS_INJECT_CLEAR) |
2063 (1 << NFIT_CMD_ARS_INJECT_GET);
2064 for_each_set_bit(i, &dsm_mask, BITS_PER_LONG)
2065 if (acpi_check_dsm(adev->handle, guid, 1, 1ULL << i))
2066 set_bit(i, &nd_desc->bus_dsm_mask);
2069 static ssize_t range_index_show(struct device *dev,
2070 struct device_attribute *attr, char *buf)
2072 struct nd_region *nd_region = to_nd_region(dev);
2073 struct nfit_spa *nfit_spa = nd_region_provider_data(nd_region);
2075 return sprintf(buf, "%d\n", nfit_spa->spa->range_index);
2077 static DEVICE_ATTR_RO(range_index);
2079 static struct attribute *acpi_nfit_region_attributes[] = {
2080 &dev_attr_range_index.attr,
2084 static const struct attribute_group acpi_nfit_region_attribute_group = {
2086 .attrs = acpi_nfit_region_attributes,
2089 static const struct attribute_group *acpi_nfit_region_attribute_groups[] = {
2090 &nd_region_attribute_group,
2091 &nd_mapping_attribute_group,
2092 &nd_device_attribute_group,
2093 &nd_numa_attribute_group,
2094 &acpi_nfit_region_attribute_group,
2098 /* enough info to uniquely specify an interleave set */
2099 struct nfit_set_info {
2100 struct nfit_set_info_map {
2107 struct nfit_set_info2 {
2108 struct nfit_set_info_map2 {
2112 u16 manufacturing_date;
2113 u8 manufacturing_location;
2118 static size_t sizeof_nfit_set_info(int num_mappings)
2120 return sizeof(struct nfit_set_info)
2121 + num_mappings * sizeof(struct nfit_set_info_map);
2124 static size_t sizeof_nfit_set_info2(int num_mappings)
2126 return sizeof(struct nfit_set_info2)
2127 + num_mappings * sizeof(struct nfit_set_info_map2);
2130 static int cmp_map_compat(const void *m0, const void *m1)
2132 const struct nfit_set_info_map *map0 = m0;
2133 const struct nfit_set_info_map *map1 = m1;
2135 return memcmp(&map0->region_offset, &map1->region_offset,
2139 static int cmp_map(const void *m0, const void *m1)
2141 const struct nfit_set_info_map *map0 = m0;
2142 const struct nfit_set_info_map *map1 = m1;
2144 if (map0->region_offset < map1->region_offset)
2146 else if (map0->region_offset > map1->region_offset)
2151 static int cmp_map2(const void *m0, const void *m1)
2153 const struct nfit_set_info_map2 *map0 = m0;
2154 const struct nfit_set_info_map2 *map1 = m1;
2156 if (map0->region_offset < map1->region_offset)
2158 else if (map0->region_offset > map1->region_offset)
2163 /* Retrieve the nth entry referencing this spa */
2164 static struct acpi_nfit_memory_map *memdev_from_spa(
2165 struct acpi_nfit_desc *acpi_desc, u16 range_index, int n)
2167 struct nfit_memdev *nfit_memdev;
2169 list_for_each_entry(nfit_memdev, &acpi_desc->memdevs, list)
2170 if (nfit_memdev->memdev->range_index == range_index)
2172 return nfit_memdev->memdev;
2176 static int acpi_nfit_init_interleave_set(struct acpi_nfit_desc *acpi_desc,
2177 struct nd_region_desc *ndr_desc,
2178 struct acpi_nfit_system_address *spa)
2180 struct device *dev = acpi_desc->dev;
2181 struct nd_interleave_set *nd_set;
2182 u16 nr = ndr_desc->num_mappings;
2183 struct nfit_set_info2 *info2;
2184 struct nfit_set_info *info;
2187 nd_set = devm_kzalloc(dev, sizeof(*nd_set), GFP_KERNEL);
2190 ndr_desc->nd_set = nd_set;
2191 guid_copy(&nd_set->type_guid, (guid_t *) spa->range_guid);
2193 info = devm_kzalloc(dev, sizeof_nfit_set_info(nr), GFP_KERNEL);
2197 info2 = devm_kzalloc(dev, sizeof_nfit_set_info2(nr), GFP_KERNEL);
2201 for (i = 0; i < nr; i++) {
2202 struct nd_mapping_desc *mapping = &ndr_desc->mapping[i];
2203 struct nfit_set_info_map *map = &info->mapping[i];
2204 struct nfit_set_info_map2 *map2 = &info2->mapping[i];
2205 struct nvdimm *nvdimm = mapping->nvdimm;
2206 struct nfit_mem *nfit_mem = nvdimm_provider_data(nvdimm);
2207 struct acpi_nfit_memory_map *memdev = memdev_from_spa(acpi_desc,
2208 spa->range_index, i);
2209 struct acpi_nfit_control_region *dcr = nfit_mem->dcr;
2211 if (!memdev || !nfit_mem->dcr) {
2212 dev_err(dev, "%s: failed to find DCR\n", __func__);
2216 map->region_offset = memdev->region_offset;
2217 map->serial_number = dcr->serial_number;
2219 map2->region_offset = memdev->region_offset;
2220 map2->serial_number = dcr->serial_number;
2221 map2->vendor_id = dcr->vendor_id;
2222 map2->manufacturing_date = dcr->manufacturing_date;
2223 map2->manufacturing_location = dcr->manufacturing_location;
2226 /* v1.1 namespaces */
2227 sort(&info->mapping[0], nr, sizeof(struct nfit_set_info_map),
2229 nd_set->cookie1 = nd_fletcher64(info, sizeof_nfit_set_info(nr), 0);
2231 /* v1.2 namespaces */
2232 sort(&info2->mapping[0], nr, sizeof(struct nfit_set_info_map2),
2234 nd_set->cookie2 = nd_fletcher64(info2, sizeof_nfit_set_info2(nr), 0);
2236 /* support v1.1 namespaces created with the wrong sort order */
2237 sort(&info->mapping[0], nr, sizeof(struct nfit_set_info_map),
2238 cmp_map_compat, NULL);
2239 nd_set->altcookie = nd_fletcher64(info, sizeof_nfit_set_info(nr), 0);
2241 /* record the result of the sort for the mapping position */
2242 for (i = 0; i < nr; i++) {
2243 struct nfit_set_info_map2 *map2 = &info2->mapping[i];
2246 for (j = 0; j < nr; j++) {
2247 struct nd_mapping_desc *mapping = &ndr_desc->mapping[j];
2248 struct nvdimm *nvdimm = mapping->nvdimm;
2249 struct nfit_mem *nfit_mem = nvdimm_provider_data(nvdimm);
2250 struct acpi_nfit_control_region *dcr = nfit_mem->dcr;
2252 if (map2->serial_number == dcr->serial_number &&
2253 map2->vendor_id == dcr->vendor_id &&
2254 map2->manufacturing_date == dcr->manufacturing_date &&
2255 map2->manufacturing_location
2256 == dcr->manufacturing_location) {
2257 mapping->position = i;
2263 ndr_desc->nd_set = nd_set;
2264 devm_kfree(dev, info);
2265 devm_kfree(dev, info2);
2270 static u64 to_interleave_offset(u64 offset, struct nfit_blk_mmio *mmio)
2272 struct acpi_nfit_interleave *idt = mmio->idt;
2273 u32 sub_line_offset, line_index, line_offset;
2274 u64 line_no, table_skip_count, table_offset;
2276 line_no = div_u64_rem(offset, mmio->line_size, &sub_line_offset);
2277 table_skip_count = div_u64_rem(line_no, mmio->num_lines, &line_index);
2278 line_offset = idt->line_offset[line_index]
2280 table_offset = table_skip_count * mmio->table_size;
2282 return mmio->base_offset + line_offset + table_offset + sub_line_offset;
2285 static u32 read_blk_stat(struct nfit_blk *nfit_blk, unsigned int bw)
2287 struct nfit_blk_mmio *mmio = &nfit_blk->mmio[DCR];
2288 u64 offset = nfit_blk->stat_offset + mmio->size * bw;
2289 const u32 STATUS_MASK = 0x80000037;
2291 if (mmio->num_lines)
2292 offset = to_interleave_offset(offset, mmio);
2294 return readl(mmio->addr.base + offset) & STATUS_MASK;
2297 static void write_blk_ctl(struct nfit_blk *nfit_blk, unsigned int bw,
2298 resource_size_t dpa, unsigned int len, unsigned int write)
2301 struct nfit_blk_mmio *mmio = &nfit_blk->mmio[DCR];
2304 BCW_OFFSET_MASK = (1ULL << 48)-1,
2306 BCW_LEN_MASK = (1ULL << 8) - 1,
2310 cmd = (dpa >> L1_CACHE_SHIFT) & BCW_OFFSET_MASK;
2311 len = len >> L1_CACHE_SHIFT;
2312 cmd |= ((u64) len & BCW_LEN_MASK) << BCW_LEN_SHIFT;
2313 cmd |= ((u64) write) << BCW_CMD_SHIFT;
2315 offset = nfit_blk->cmd_offset + mmio->size * bw;
2316 if (mmio->num_lines)
2317 offset = to_interleave_offset(offset, mmio);
2319 writeq(cmd, mmio->addr.base + offset);
2320 nvdimm_flush(nfit_blk->nd_region);
2322 if (nfit_blk->dimm_flags & NFIT_BLK_DCR_LATCH)
2323 readq(mmio->addr.base + offset);
2326 static int acpi_nfit_blk_single_io(struct nfit_blk *nfit_blk,
2327 resource_size_t dpa, void *iobuf, size_t len, int rw,
2330 struct nfit_blk_mmio *mmio = &nfit_blk->mmio[BDW];
2331 unsigned int copied = 0;
2335 base_offset = nfit_blk->bdw_offset + dpa % L1_CACHE_BYTES
2336 + lane * mmio->size;
2337 write_blk_ctl(nfit_blk, lane, dpa, len, rw);
2342 if (mmio->num_lines) {
2345 offset = to_interleave_offset(base_offset + copied,
2347 div_u64_rem(offset, mmio->line_size, &line_offset);
2348 c = min_t(size_t, len, mmio->line_size - line_offset);
2350 offset = base_offset + nfit_blk->bdw_offset;
2355 memcpy_flushcache(mmio->addr.aperture + offset, iobuf + copied, c);
2357 if (nfit_blk->dimm_flags & NFIT_BLK_READ_FLUSH)
2358 arch_invalidate_pmem((void __force *)
2359 mmio->addr.aperture + offset, c);
2361 memcpy(iobuf + copied, mmio->addr.aperture + offset, c);
2369 nvdimm_flush(nfit_blk->nd_region);
2371 rc = read_blk_stat(nfit_blk, lane) ? -EIO : 0;
2375 static int acpi_nfit_blk_region_do_io(struct nd_blk_region *ndbr,
2376 resource_size_t dpa, void *iobuf, u64 len, int rw)
2378 struct nfit_blk *nfit_blk = nd_blk_region_provider_data(ndbr);
2379 struct nfit_blk_mmio *mmio = &nfit_blk->mmio[BDW];
2380 struct nd_region *nd_region = nfit_blk->nd_region;
2381 unsigned int lane, copied = 0;
2384 lane = nd_region_acquire_lane(nd_region);
2386 u64 c = min(len, mmio->size);
2388 rc = acpi_nfit_blk_single_io(nfit_blk, dpa + copied,
2389 iobuf + copied, c, rw, lane);
2396 nd_region_release_lane(nd_region, lane);
2401 static int nfit_blk_init_interleave(struct nfit_blk_mmio *mmio,
2402 struct acpi_nfit_interleave *idt, u16 interleave_ways)
2405 mmio->num_lines = idt->line_count;
2406 mmio->line_size = idt->line_size;
2407 if (interleave_ways == 0)
2409 mmio->table_size = mmio->num_lines * interleave_ways
2416 static int acpi_nfit_blk_get_flags(struct nvdimm_bus_descriptor *nd_desc,
2417 struct nvdimm *nvdimm, struct nfit_blk *nfit_blk)
2419 struct nd_cmd_dimm_flags flags;
2422 memset(&flags, 0, sizeof(flags));
2423 rc = nd_desc->ndctl(nd_desc, nvdimm, ND_CMD_DIMM_FLAGS, &flags,
2424 sizeof(flags), NULL);
2426 if (rc >= 0 && flags.status == 0)
2427 nfit_blk->dimm_flags = flags.flags;
2428 else if (rc == -ENOTTY) {
2429 /* fall back to a conservative default */
2430 nfit_blk->dimm_flags = NFIT_BLK_DCR_LATCH | NFIT_BLK_READ_FLUSH;
2438 static int acpi_nfit_blk_region_enable(struct nvdimm_bus *nvdimm_bus,
2441 struct nvdimm_bus_descriptor *nd_desc = to_nd_desc(nvdimm_bus);
2442 struct nd_blk_region *ndbr = to_nd_blk_region(dev);
2443 struct nfit_blk_mmio *mmio;
2444 struct nfit_blk *nfit_blk;
2445 struct nfit_mem *nfit_mem;
2446 struct nvdimm *nvdimm;
2449 nvdimm = nd_blk_region_to_dimm(ndbr);
2450 nfit_mem = nvdimm_provider_data(nvdimm);
2451 if (!nfit_mem || !nfit_mem->dcr || !nfit_mem->bdw) {
2452 dev_dbg(dev, "missing%s%s%s\n",
2453 nfit_mem ? "" : " nfit_mem",
2454 (nfit_mem && nfit_mem->dcr) ? "" : " dcr",
2455 (nfit_mem && nfit_mem->bdw) ? "" : " bdw");
2459 nfit_blk = devm_kzalloc(dev, sizeof(*nfit_blk), GFP_KERNEL);
2462 nd_blk_region_set_provider_data(ndbr, nfit_blk);
2463 nfit_blk->nd_region = to_nd_region(dev);
2465 /* map block aperture memory */
2466 nfit_blk->bdw_offset = nfit_mem->bdw->offset;
2467 mmio = &nfit_blk->mmio[BDW];
2468 mmio->addr.base = devm_nvdimm_memremap(dev, nfit_mem->spa_bdw->address,
2469 nfit_mem->spa_bdw->length, nd_blk_memremap_flags(ndbr));
2470 if (!mmio->addr.base) {
2471 dev_dbg(dev, "%s failed to map bdw\n",
2472 nvdimm_name(nvdimm));
2475 mmio->size = nfit_mem->bdw->size;
2476 mmio->base_offset = nfit_mem->memdev_bdw->region_offset;
2477 mmio->idt = nfit_mem->idt_bdw;
2478 mmio->spa = nfit_mem->spa_bdw;
2479 rc = nfit_blk_init_interleave(mmio, nfit_mem->idt_bdw,
2480 nfit_mem->memdev_bdw->interleave_ways);
2482 dev_dbg(dev, "%s failed to init bdw interleave\n",
2483 nvdimm_name(nvdimm));
2487 /* map block control memory */
2488 nfit_blk->cmd_offset = nfit_mem->dcr->command_offset;
2489 nfit_blk->stat_offset = nfit_mem->dcr->status_offset;
2490 mmio = &nfit_blk->mmio[DCR];
2491 mmio->addr.base = devm_nvdimm_ioremap(dev, nfit_mem->spa_dcr->address,
2492 nfit_mem->spa_dcr->length);
2493 if (!mmio->addr.base) {
2494 dev_dbg(dev, "%s failed to map dcr\n",
2495 nvdimm_name(nvdimm));
2498 mmio->size = nfit_mem->dcr->window_size;
2499 mmio->base_offset = nfit_mem->memdev_dcr->region_offset;
2500 mmio->idt = nfit_mem->idt_dcr;
2501 mmio->spa = nfit_mem->spa_dcr;
2502 rc = nfit_blk_init_interleave(mmio, nfit_mem->idt_dcr,
2503 nfit_mem->memdev_dcr->interleave_ways);
2505 dev_dbg(dev, "%s failed to init dcr interleave\n",
2506 nvdimm_name(nvdimm));
2510 rc = acpi_nfit_blk_get_flags(nd_desc, nvdimm, nfit_blk);
2512 dev_dbg(dev, "%s failed get DIMM flags\n",
2513 nvdimm_name(nvdimm));
2517 if (nvdimm_has_flush(nfit_blk->nd_region) < 0)
2518 dev_warn(dev, "unable to guarantee persistence of writes\n");
2520 if (mmio->line_size == 0)
2523 if ((u32) nfit_blk->cmd_offset % mmio->line_size
2524 + 8 > mmio->line_size) {
2525 dev_dbg(dev, "cmd_offset crosses interleave boundary\n");
2527 } else if ((u32) nfit_blk->stat_offset % mmio->line_size
2528 + 8 > mmio->line_size) {
2529 dev_dbg(dev, "stat_offset crosses interleave boundary\n");
2536 static int ars_get_cap(struct acpi_nfit_desc *acpi_desc,
2537 struct nd_cmd_ars_cap *cmd, struct nfit_spa *nfit_spa)
2539 struct nvdimm_bus_descriptor *nd_desc = &acpi_desc->nd_desc;
2540 struct acpi_nfit_system_address *spa = nfit_spa->spa;
2543 cmd->address = spa->address;
2544 cmd->length = spa->length;
2545 rc = nd_desc->ndctl(nd_desc, NULL, ND_CMD_ARS_CAP, cmd,
2546 sizeof(*cmd), &cmd_rc);
2552 static int ars_start(struct acpi_nfit_desc *acpi_desc,
2553 struct nfit_spa *nfit_spa, enum nfit_ars_state req_type)
2557 struct nd_cmd_ars_start ars_start;
2558 struct acpi_nfit_system_address *spa = nfit_spa->spa;
2559 struct nvdimm_bus_descriptor *nd_desc = &acpi_desc->nd_desc;
2561 memset(&ars_start, 0, sizeof(ars_start));
2562 ars_start.address = spa->address;
2563 ars_start.length = spa->length;
2564 if (req_type == ARS_REQ_SHORT)
2565 ars_start.flags = ND_ARS_RETURN_PREV_DATA;
2566 if (nfit_spa_type(spa) == NFIT_SPA_PM)
2567 ars_start.type = ND_ARS_PERSISTENT;
2568 else if (nfit_spa_type(spa) == NFIT_SPA_VOLATILE)
2569 ars_start.type = ND_ARS_VOLATILE;
2573 rc = nd_desc->ndctl(nd_desc, NULL, ND_CMD_ARS_START, &ars_start,
2574 sizeof(ars_start), &cmd_rc);
2581 static int ars_continue(struct acpi_nfit_desc *acpi_desc)
2584 struct nd_cmd_ars_start ars_start;
2585 struct nvdimm_bus_descriptor *nd_desc = &acpi_desc->nd_desc;
2586 struct nd_cmd_ars_status *ars_status = acpi_desc->ars_status;
2588 memset(&ars_start, 0, sizeof(ars_start));
2589 ars_start.address = ars_status->restart_address;
2590 ars_start.length = ars_status->restart_length;
2591 ars_start.type = ars_status->type;
2592 ars_start.flags = acpi_desc->ars_start_flags;
2593 rc = nd_desc->ndctl(nd_desc, NULL, ND_CMD_ARS_START, &ars_start,
2594 sizeof(ars_start), &cmd_rc);
2600 static int ars_get_status(struct acpi_nfit_desc *acpi_desc)
2602 struct nvdimm_bus_descriptor *nd_desc = &acpi_desc->nd_desc;
2603 struct nd_cmd_ars_status *ars_status = acpi_desc->ars_status;
2606 rc = nd_desc->ndctl(nd_desc, NULL, ND_CMD_ARS_STATUS, ars_status,
2607 acpi_desc->max_ars, &cmd_rc);
2613 static void ars_complete(struct acpi_nfit_desc *acpi_desc,
2614 struct nfit_spa *nfit_spa)
2616 struct nd_cmd_ars_status *ars_status = acpi_desc->ars_status;
2617 struct acpi_nfit_system_address *spa = nfit_spa->spa;
2618 struct nd_region *nd_region = nfit_spa->nd_region;
2621 lockdep_assert_held(&acpi_desc->init_mutex);
2623 * Only advance the ARS state for ARS runs initiated by the
2624 * kernel, ignore ARS results from BIOS initiated runs for scrub
2625 * completion tracking.
2627 if (acpi_desc->scrub_spa != nfit_spa)
2630 if ((ars_status->address >= spa->address && ars_status->address
2631 < spa->address + spa->length)
2632 || (ars_status->address < spa->address)) {
2634 * Assume that if a scrub starts at an offset from the
2635 * start of nfit_spa that we are in the continuation
2638 * Otherwise, if the scrub covers the spa range, mark
2639 * any pending request complete.
2641 if (ars_status->address + ars_status->length
2642 >= spa->address + spa->length)
2649 acpi_desc->scrub_spa = NULL;
2651 dev = nd_region_dev(nd_region);
2652 nvdimm_region_notify(nd_region, NVDIMM_REVALIDATE_POISON);
2654 dev = acpi_desc->dev;
2655 dev_dbg(dev, "ARS: range %d complete\n", spa->range_index);
2658 static int ars_status_process_records(struct acpi_nfit_desc *acpi_desc)
2660 struct nvdimm_bus *nvdimm_bus = acpi_desc->nvdimm_bus;
2661 struct nd_cmd_ars_status *ars_status = acpi_desc->ars_status;
2666 * First record starts at 44 byte offset from the start of the
2669 if (ars_status->out_length < 44)
2671 for (i = 0; i < ars_status->num_records; i++) {
2672 /* only process full records */
2673 if (ars_status->out_length
2674 < 44 + sizeof(struct nd_ars_record) * (i + 1))
2676 rc = nvdimm_bus_add_badrange(nvdimm_bus,
2677 ars_status->records[i].err_address,
2678 ars_status->records[i].length);
2682 if (i < ars_status->num_records)
2683 dev_warn(acpi_desc->dev, "detected truncated ars results\n");
2688 static void acpi_nfit_remove_resource(void *data)
2690 struct resource *res = data;
2692 remove_resource(res);
2695 static int acpi_nfit_insert_resource(struct acpi_nfit_desc *acpi_desc,
2696 struct nd_region_desc *ndr_desc)
2698 struct resource *res, *nd_res = ndr_desc->res;
2701 /* No operation if the region is already registered as PMEM */
2702 is_pmem = region_intersects(nd_res->start, resource_size(nd_res),
2703 IORESOURCE_MEM, IORES_DESC_PERSISTENT_MEMORY);
2704 if (is_pmem == REGION_INTERSECTS)
2707 res = devm_kzalloc(acpi_desc->dev, sizeof(*res), GFP_KERNEL);
2711 res->name = "Persistent Memory";
2712 res->start = nd_res->start;
2713 res->end = nd_res->end;
2714 res->flags = IORESOURCE_MEM;
2715 res->desc = IORES_DESC_PERSISTENT_MEMORY;
2717 ret = insert_resource(&iomem_resource, res);
2721 ret = devm_add_action_or_reset(acpi_desc->dev,
2722 acpi_nfit_remove_resource,
2730 static int acpi_nfit_init_mapping(struct acpi_nfit_desc *acpi_desc,
2731 struct nd_mapping_desc *mapping, struct nd_region_desc *ndr_desc,
2732 struct acpi_nfit_memory_map *memdev,
2733 struct nfit_spa *nfit_spa)
2735 struct nvdimm *nvdimm = acpi_nfit_dimm_by_handle(acpi_desc,
2736 memdev->device_handle);
2737 struct acpi_nfit_system_address *spa = nfit_spa->spa;
2738 struct nd_blk_region_desc *ndbr_desc;
2739 struct nfit_mem *nfit_mem;
2743 dev_err(acpi_desc->dev, "spa%d dimm: %#x not found\n",
2744 spa->range_index, memdev->device_handle);
2748 mapping->nvdimm = nvdimm;
2749 switch (nfit_spa_type(spa)) {
2751 case NFIT_SPA_VOLATILE:
2752 mapping->start = memdev->address;
2753 mapping->size = memdev->region_size;
2756 nfit_mem = nvdimm_provider_data(nvdimm);
2757 if (!nfit_mem || !nfit_mem->bdw) {
2758 dev_dbg(acpi_desc->dev, "spa%d %s missing bdw\n",
2759 spa->range_index, nvdimm_name(nvdimm));
2763 mapping->size = nfit_mem->bdw->capacity;
2764 mapping->start = nfit_mem->bdw->start_address;
2765 ndr_desc->num_lanes = nfit_mem->bdw->windows;
2766 ndr_desc->mapping = mapping;
2767 ndr_desc->num_mappings = 1;
2768 ndbr_desc = to_blk_region_desc(ndr_desc);
2769 ndbr_desc->enable = acpi_nfit_blk_region_enable;
2770 ndbr_desc->do_io = acpi_desc->blk_do_io;
2771 rc = acpi_nfit_init_interleave_set(acpi_desc, ndr_desc, spa);
2774 nfit_spa->nd_region = nvdimm_blk_region_create(acpi_desc->nvdimm_bus,
2776 if (!nfit_spa->nd_region)
2784 static bool nfit_spa_is_virtual(struct acpi_nfit_system_address *spa)
2786 return (nfit_spa_type(spa) == NFIT_SPA_VDISK ||
2787 nfit_spa_type(spa) == NFIT_SPA_VCD ||
2788 nfit_spa_type(spa) == NFIT_SPA_PDISK ||
2789 nfit_spa_type(spa) == NFIT_SPA_PCD);
2792 static bool nfit_spa_is_volatile(struct acpi_nfit_system_address *spa)
2794 return (nfit_spa_type(spa) == NFIT_SPA_VDISK ||
2795 nfit_spa_type(spa) == NFIT_SPA_VCD ||
2796 nfit_spa_type(spa) == NFIT_SPA_VOLATILE);
2799 static int acpi_nfit_register_region(struct acpi_nfit_desc *acpi_desc,
2800 struct nfit_spa *nfit_spa)
2802 static struct nd_mapping_desc mappings[ND_MAX_MAPPINGS];
2803 struct acpi_nfit_system_address *spa = nfit_spa->spa;
2804 struct nd_blk_region_desc ndbr_desc;
2805 struct nd_region_desc *ndr_desc;
2806 struct nfit_memdev *nfit_memdev;
2807 struct nvdimm_bus *nvdimm_bus;
2808 struct resource res;
2811 if (nfit_spa->nd_region)
2814 if (spa->range_index == 0 && !nfit_spa_is_virtual(spa)) {
2815 dev_dbg(acpi_desc->dev, "detected invalid spa index\n");
2819 memset(&res, 0, sizeof(res));
2820 memset(&mappings, 0, sizeof(mappings));
2821 memset(&ndbr_desc, 0, sizeof(ndbr_desc));
2822 res.start = spa->address;
2823 res.end = res.start + spa->length - 1;
2824 ndr_desc = &ndbr_desc.ndr_desc;
2825 ndr_desc->res = &res;
2826 ndr_desc->provider_data = nfit_spa;
2827 ndr_desc->attr_groups = acpi_nfit_region_attribute_groups;
2828 if (spa->flags & ACPI_NFIT_PROXIMITY_VALID)
2829 ndr_desc->numa_node = acpi_map_pxm_to_online_node(
2830 spa->proximity_domain);
2832 ndr_desc->numa_node = NUMA_NO_NODE;
2835 * Persistence domain bits are hierarchical, if
2836 * ACPI_NFIT_CAPABILITY_CACHE_FLUSH is set then
2837 * ACPI_NFIT_CAPABILITY_MEM_FLUSH is implied.
2839 if (acpi_desc->platform_cap & ACPI_NFIT_CAPABILITY_CACHE_FLUSH)
2840 set_bit(ND_REGION_PERSIST_CACHE, &ndr_desc->flags);
2841 else if (acpi_desc->platform_cap & ACPI_NFIT_CAPABILITY_MEM_FLUSH)
2842 set_bit(ND_REGION_PERSIST_MEMCTRL, &ndr_desc->flags);
2844 list_for_each_entry(nfit_memdev, &acpi_desc->memdevs, list) {
2845 struct acpi_nfit_memory_map *memdev = nfit_memdev->memdev;
2846 struct nd_mapping_desc *mapping;
2848 if (memdev->range_index != spa->range_index)
2850 if (count >= ND_MAX_MAPPINGS) {
2851 dev_err(acpi_desc->dev, "spa%d exceeds max mappings %d\n",
2852 spa->range_index, ND_MAX_MAPPINGS);
2855 mapping = &mappings[count++];
2856 rc = acpi_nfit_init_mapping(acpi_desc, mapping, ndr_desc,
2862 ndr_desc->mapping = mappings;
2863 ndr_desc->num_mappings = count;
2864 rc = acpi_nfit_init_interleave_set(acpi_desc, ndr_desc, spa);
2868 nvdimm_bus = acpi_desc->nvdimm_bus;
2869 if (nfit_spa_type(spa) == NFIT_SPA_PM) {
2870 rc = acpi_nfit_insert_resource(acpi_desc, ndr_desc);
2872 dev_warn(acpi_desc->dev,
2873 "failed to insert pmem resource to iomem: %d\n",
2878 nfit_spa->nd_region = nvdimm_pmem_region_create(nvdimm_bus,
2880 if (!nfit_spa->nd_region)
2882 } else if (nfit_spa_is_volatile(spa)) {
2883 nfit_spa->nd_region = nvdimm_volatile_region_create(nvdimm_bus,
2885 if (!nfit_spa->nd_region)
2887 } else if (nfit_spa_is_virtual(spa)) {
2888 nfit_spa->nd_region = nvdimm_pmem_region_create(nvdimm_bus,
2890 if (!nfit_spa->nd_region)
2896 dev_err(acpi_desc->dev, "failed to register spa range %d\n",
2897 nfit_spa->spa->range_index);
2901 static int ars_status_alloc(struct acpi_nfit_desc *acpi_desc)
2903 struct device *dev = acpi_desc->dev;
2904 struct nd_cmd_ars_status *ars_status;
2906 if (acpi_desc->ars_status) {
2907 memset(acpi_desc->ars_status, 0, acpi_desc->max_ars);
2911 ars_status = devm_kzalloc(dev, acpi_desc->max_ars, GFP_KERNEL);
2914 acpi_desc->ars_status = ars_status;
2918 static int acpi_nfit_query_poison(struct acpi_nfit_desc *acpi_desc)
2922 if (ars_status_alloc(acpi_desc))
2925 rc = ars_get_status(acpi_desc);
2927 if (rc < 0 && rc != -ENOSPC)
2930 if (ars_status_process_records(acpi_desc))
2936 static int ars_register(struct acpi_nfit_desc *acpi_desc,
2937 struct nfit_spa *nfit_spa)
2941 if (no_init_ars || test_bit(ARS_FAILED, &nfit_spa->ars_state))
2942 return acpi_nfit_register_region(acpi_desc, nfit_spa);
2944 set_bit(ARS_REQ_SHORT, &nfit_spa->ars_state);
2945 set_bit(ARS_REQ_LONG, &nfit_spa->ars_state);
2947 switch (acpi_nfit_query_poison(acpi_desc)) {
2950 rc = ars_start(acpi_desc, nfit_spa, ARS_REQ_SHORT);
2951 /* shouldn't happen, try again later */
2955 set_bit(ARS_FAILED, &nfit_spa->ars_state);
2958 clear_bit(ARS_REQ_SHORT, &nfit_spa->ars_state);
2959 rc = acpi_nfit_query_poison(acpi_desc);
2962 acpi_desc->scrub_spa = nfit_spa;
2963 ars_complete(acpi_desc, nfit_spa);
2965 * If ars_complete() says we didn't complete the
2966 * short scrub, we'll try again with a long
2969 acpi_desc->scrub_spa = NULL;
2975 * BIOS was using ARS, wait for it to complete (or
2976 * resources to become available) and then perform our
2981 set_bit(ARS_FAILED, &nfit_spa->ars_state);
2985 return acpi_nfit_register_region(acpi_desc, nfit_spa);
2988 static void ars_complete_all(struct acpi_nfit_desc *acpi_desc)
2990 struct nfit_spa *nfit_spa;
2992 list_for_each_entry(nfit_spa, &acpi_desc->spas, list) {
2993 if (test_bit(ARS_FAILED, &nfit_spa->ars_state))
2995 ars_complete(acpi_desc, nfit_spa);
2999 static unsigned int __acpi_nfit_scrub(struct acpi_nfit_desc *acpi_desc,
3002 unsigned int tmo = acpi_desc->scrub_tmo;
3003 struct device *dev = acpi_desc->dev;
3004 struct nfit_spa *nfit_spa;
3006 lockdep_assert_held(&acpi_desc->init_mutex);
3008 if (acpi_desc->cancel)
3011 if (query_rc == -EBUSY) {
3012 dev_dbg(dev, "ARS: ARS busy\n");
3013 return min(30U * 60U, tmo * 2);
3015 if (query_rc == -ENOSPC) {
3016 dev_dbg(dev, "ARS: ARS continue\n");
3017 ars_continue(acpi_desc);
3020 if (query_rc && query_rc != -EAGAIN) {
3021 unsigned long long addr, end;
3023 addr = acpi_desc->ars_status->address;
3024 end = addr + acpi_desc->ars_status->length;
3025 dev_dbg(dev, "ARS: %llx-%llx failed (%d)\n", addr, end,
3029 ars_complete_all(acpi_desc);
3030 list_for_each_entry(nfit_spa, &acpi_desc->spas, list) {
3031 enum nfit_ars_state req_type;
3034 if (test_bit(ARS_FAILED, &nfit_spa->ars_state))
3037 /* prefer short ARS requests first */
3038 if (test_bit(ARS_REQ_SHORT, &nfit_spa->ars_state))
3039 req_type = ARS_REQ_SHORT;
3040 else if (test_bit(ARS_REQ_LONG, &nfit_spa->ars_state))
3041 req_type = ARS_REQ_LONG;
3044 rc = ars_start(acpi_desc, nfit_spa, req_type);
3046 dev = nd_region_dev(nfit_spa->nd_region);
3047 dev_dbg(dev, "ARS: range %d ARS start %s (%d)\n",
3048 nfit_spa->spa->range_index,
3049 req_type == ARS_REQ_SHORT ? "short" : "long",
3052 * Hmm, we raced someone else starting ARS? Try again in
3058 dev_WARN_ONCE(dev, acpi_desc->scrub_spa,
3059 "scrub start while range %d active\n",
3060 acpi_desc->scrub_spa->spa->range_index);
3061 clear_bit(req_type, &nfit_spa->ars_state);
3062 acpi_desc->scrub_spa = nfit_spa;
3064 * Consider this spa last for future scrub
3067 list_move_tail(&nfit_spa->list, &acpi_desc->spas);
3071 dev_err(dev, "ARS: range %d ARS failed (%d)\n",
3072 nfit_spa->spa->range_index, rc);
3073 set_bit(ARS_FAILED, &nfit_spa->ars_state);
3078 static void __sched_ars(struct acpi_nfit_desc *acpi_desc, unsigned int tmo)
3080 lockdep_assert_held(&acpi_desc->init_mutex);
3082 acpi_desc->scrub_busy = 1;
3083 /* note this should only be set from within the workqueue */
3085 acpi_desc->scrub_tmo = tmo;
3086 queue_delayed_work(nfit_wq, &acpi_desc->dwork, tmo * HZ);
3089 static void sched_ars(struct acpi_nfit_desc *acpi_desc)
3091 __sched_ars(acpi_desc, 0);
3094 static void notify_ars_done(struct acpi_nfit_desc *acpi_desc)
3096 lockdep_assert_held(&acpi_desc->init_mutex);
3098 acpi_desc->scrub_busy = 0;
3099 acpi_desc->scrub_count++;
3100 if (acpi_desc->scrub_count_state)
3101 sysfs_notify_dirent(acpi_desc->scrub_count_state);
3104 static void acpi_nfit_scrub(struct work_struct *work)
3106 struct acpi_nfit_desc *acpi_desc;
3110 acpi_desc = container_of(work, typeof(*acpi_desc), dwork.work);
3111 mutex_lock(&acpi_desc->init_mutex);
3112 query_rc = acpi_nfit_query_poison(acpi_desc);
3113 tmo = __acpi_nfit_scrub(acpi_desc, query_rc);
3115 __sched_ars(acpi_desc, tmo);
3117 notify_ars_done(acpi_desc);
3118 memset(acpi_desc->ars_status, 0, acpi_desc->max_ars);
3119 mutex_unlock(&acpi_desc->init_mutex);
3122 static void acpi_nfit_init_ars(struct acpi_nfit_desc *acpi_desc,
3123 struct nfit_spa *nfit_spa)
3125 int type = nfit_spa_type(nfit_spa->spa);
3126 struct nd_cmd_ars_cap ars_cap;
3129 set_bit(ARS_FAILED, &nfit_spa->ars_state);
3130 memset(&ars_cap, 0, sizeof(ars_cap));
3131 rc = ars_get_cap(acpi_desc, &ars_cap, nfit_spa);
3134 /* check that the supported scrub types match the spa type */
3135 if (type == NFIT_SPA_VOLATILE && ((ars_cap.status >> 16)
3136 & ND_ARS_VOLATILE) == 0)
3138 if (type == NFIT_SPA_PM && ((ars_cap.status >> 16)
3139 & ND_ARS_PERSISTENT) == 0)
3142 nfit_spa->max_ars = ars_cap.max_ars_out;
3143 nfit_spa->clear_err_unit = ars_cap.clear_err_unit;
3144 acpi_desc->max_ars = max(nfit_spa->max_ars, acpi_desc->max_ars);
3145 clear_bit(ARS_FAILED, &nfit_spa->ars_state);
3148 static int acpi_nfit_register_regions(struct acpi_nfit_desc *acpi_desc)
3150 struct nfit_spa *nfit_spa;
3153 list_for_each_entry(nfit_spa, &acpi_desc->spas, list) {
3154 switch (nfit_spa_type(nfit_spa->spa)) {
3155 case NFIT_SPA_VOLATILE:
3157 acpi_nfit_init_ars(acpi_desc, nfit_spa);
3162 list_for_each_entry(nfit_spa, &acpi_desc->spas, list)
3163 switch (nfit_spa_type(nfit_spa->spa)) {
3164 case NFIT_SPA_VOLATILE:
3166 /* register regions and kick off initial ARS run */
3167 rc = ars_register(acpi_desc, nfit_spa);
3172 /* nothing to register */
3175 case NFIT_SPA_VDISK:
3177 case NFIT_SPA_PDISK:
3179 /* register known regions that don't support ARS */
3180 rc = acpi_nfit_register_region(acpi_desc, nfit_spa);
3185 /* don't register unknown regions */
3189 sched_ars(acpi_desc);
3193 static int acpi_nfit_check_deletions(struct acpi_nfit_desc *acpi_desc,
3194 struct nfit_table_prev *prev)
3196 struct device *dev = acpi_desc->dev;
3198 if (!list_empty(&prev->spas) ||
3199 !list_empty(&prev->memdevs) ||
3200 !list_empty(&prev->dcrs) ||
3201 !list_empty(&prev->bdws) ||
3202 !list_empty(&prev->idts) ||
3203 !list_empty(&prev->flushes)) {
3204 dev_err(dev, "new nfit deletes entries (unsupported)\n");
3210 static int acpi_nfit_desc_init_scrub_attr(struct acpi_nfit_desc *acpi_desc)
3212 struct device *dev = acpi_desc->dev;
3213 struct kernfs_node *nfit;
3214 struct device *bus_dev;
3216 if (!ars_supported(acpi_desc->nvdimm_bus))
3219 bus_dev = to_nvdimm_bus_dev(acpi_desc->nvdimm_bus);
3220 nfit = sysfs_get_dirent(bus_dev->kobj.sd, "nfit");
3222 dev_err(dev, "sysfs_get_dirent 'nfit' failed\n");
3225 acpi_desc->scrub_count_state = sysfs_get_dirent(nfit, "scrub");
3227 if (!acpi_desc->scrub_count_state) {
3228 dev_err(dev, "sysfs_get_dirent 'scrub' failed\n");
3235 static void acpi_nfit_unregister(void *data)
3237 struct acpi_nfit_desc *acpi_desc = data;
3239 nvdimm_bus_unregister(acpi_desc->nvdimm_bus);
3242 int acpi_nfit_init(struct acpi_nfit_desc *acpi_desc, void *data, acpi_size sz)
3244 struct device *dev = acpi_desc->dev;
3245 struct nfit_table_prev prev;
3249 if (!acpi_desc->nvdimm_bus) {
3250 acpi_nfit_init_dsms(acpi_desc);
3252 acpi_desc->nvdimm_bus = nvdimm_bus_register(dev,
3253 &acpi_desc->nd_desc);
3254 if (!acpi_desc->nvdimm_bus)
3257 rc = devm_add_action_or_reset(dev, acpi_nfit_unregister,
3262 rc = acpi_nfit_desc_init_scrub_attr(acpi_desc);
3266 /* register this acpi_desc for mce notifications */
3267 mutex_lock(&acpi_desc_lock);
3268 list_add_tail(&acpi_desc->list, &acpi_descs);
3269 mutex_unlock(&acpi_desc_lock);
3272 mutex_lock(&acpi_desc->init_mutex);
3274 INIT_LIST_HEAD(&prev.spas);
3275 INIT_LIST_HEAD(&prev.memdevs);
3276 INIT_LIST_HEAD(&prev.dcrs);
3277 INIT_LIST_HEAD(&prev.bdws);
3278 INIT_LIST_HEAD(&prev.idts);
3279 INIT_LIST_HEAD(&prev.flushes);
3281 list_cut_position(&prev.spas, &acpi_desc->spas,
3282 acpi_desc->spas.prev);
3283 list_cut_position(&prev.memdevs, &acpi_desc->memdevs,
3284 acpi_desc->memdevs.prev);
3285 list_cut_position(&prev.dcrs, &acpi_desc->dcrs,
3286 acpi_desc->dcrs.prev);
3287 list_cut_position(&prev.bdws, &acpi_desc->bdws,
3288 acpi_desc->bdws.prev);
3289 list_cut_position(&prev.idts, &acpi_desc->idts,
3290 acpi_desc->idts.prev);
3291 list_cut_position(&prev.flushes, &acpi_desc->flushes,
3292 acpi_desc->flushes.prev);
3295 while (!IS_ERR_OR_NULL(data))
3296 data = add_table(acpi_desc, &prev, data, end);
3299 dev_dbg(dev, "nfit table parsing error: %ld\n", PTR_ERR(data));
3304 rc = acpi_nfit_check_deletions(acpi_desc, &prev);
3308 rc = nfit_mem_init(acpi_desc);
3312 rc = acpi_nfit_register_dimms(acpi_desc);
3316 rc = acpi_nfit_register_regions(acpi_desc);
3319 mutex_unlock(&acpi_desc->init_mutex);
3322 EXPORT_SYMBOL_GPL(acpi_nfit_init);
3324 static int acpi_nfit_flush_probe(struct nvdimm_bus_descriptor *nd_desc)
3326 struct acpi_nfit_desc *acpi_desc = to_acpi_nfit_desc(nd_desc);
3327 struct device *dev = acpi_desc->dev;
3329 /* Bounce the device lock to flush acpi_nfit_add / acpi_nfit_notify */
3333 /* Bounce the init_mutex to complete initial registration */
3334 mutex_lock(&acpi_desc->init_mutex);
3335 mutex_unlock(&acpi_desc->init_mutex);
3340 static int acpi_nfit_clear_to_send(struct nvdimm_bus_descriptor *nd_desc,
3341 struct nvdimm *nvdimm, unsigned int cmd)
3343 struct acpi_nfit_desc *acpi_desc = to_acpi_nfit_desc(nd_desc);
3344 struct nfit_spa *nfit_spa;
3349 if (cmd != ND_CMD_ARS_START)
3353 * The kernel and userspace may race to initiate a scrub, but
3354 * the scrub thread is prepared to lose that initial race. It
3355 * just needs guarantees that any ARS it initiates are not
3356 * interrupted by any intervening start requests from userspace.
3358 mutex_lock(&acpi_desc->init_mutex);
3359 list_for_each_entry(nfit_spa, &acpi_desc->spas, list)
3360 if (acpi_desc->scrub_spa
3361 || test_bit(ARS_REQ_SHORT, &nfit_spa->ars_state)
3362 || test_bit(ARS_REQ_LONG, &nfit_spa->ars_state)) {
3366 mutex_unlock(&acpi_desc->init_mutex);
3371 int acpi_nfit_ars_rescan(struct acpi_nfit_desc *acpi_desc,
3372 enum nfit_ars_state req_type)
3374 struct device *dev = acpi_desc->dev;
3375 int scheduled = 0, busy = 0;
3376 struct nfit_spa *nfit_spa;
3378 mutex_lock(&acpi_desc->init_mutex);
3379 if (acpi_desc->cancel) {
3380 mutex_unlock(&acpi_desc->init_mutex);
3384 list_for_each_entry(nfit_spa, &acpi_desc->spas, list) {
3385 int type = nfit_spa_type(nfit_spa->spa);
3387 if (type != NFIT_SPA_PM && type != NFIT_SPA_VOLATILE)
3389 if (test_bit(ARS_FAILED, &nfit_spa->ars_state))
3392 if (test_and_set_bit(req_type, &nfit_spa->ars_state))
3398 sched_ars(acpi_desc);
3399 dev_dbg(dev, "ars_scan triggered\n");
3401 mutex_unlock(&acpi_desc->init_mutex);
3410 void acpi_nfit_desc_init(struct acpi_nfit_desc *acpi_desc, struct device *dev)
3412 struct nvdimm_bus_descriptor *nd_desc;
3414 dev_set_drvdata(dev, acpi_desc);
3415 acpi_desc->dev = dev;
3416 acpi_desc->blk_do_io = acpi_nfit_blk_region_do_io;
3417 nd_desc = &acpi_desc->nd_desc;
3418 nd_desc->provider_name = "ACPI.NFIT";
3419 nd_desc->module = THIS_MODULE;
3420 nd_desc->ndctl = acpi_nfit_ctl;
3421 nd_desc->flush_probe = acpi_nfit_flush_probe;
3422 nd_desc->clear_to_send = acpi_nfit_clear_to_send;
3423 nd_desc->attr_groups = acpi_nfit_attribute_groups;
3425 INIT_LIST_HEAD(&acpi_desc->spas);
3426 INIT_LIST_HEAD(&acpi_desc->dcrs);
3427 INIT_LIST_HEAD(&acpi_desc->bdws);
3428 INIT_LIST_HEAD(&acpi_desc->idts);
3429 INIT_LIST_HEAD(&acpi_desc->flushes);
3430 INIT_LIST_HEAD(&acpi_desc->memdevs);
3431 INIT_LIST_HEAD(&acpi_desc->dimms);
3432 INIT_LIST_HEAD(&acpi_desc->list);
3433 mutex_init(&acpi_desc->init_mutex);
3434 acpi_desc->scrub_tmo = 1;
3435 INIT_DELAYED_WORK(&acpi_desc->dwork, acpi_nfit_scrub);
3437 EXPORT_SYMBOL_GPL(acpi_nfit_desc_init);
3439 static void acpi_nfit_put_table(void *table)
3441 acpi_put_table(table);
3444 void acpi_nfit_shutdown(void *data)
3446 struct acpi_nfit_desc *acpi_desc = data;
3447 struct device *bus_dev = to_nvdimm_bus_dev(acpi_desc->nvdimm_bus);
3450 * Destruct under acpi_desc_lock so that nfit_handle_mce does not
3453 mutex_lock(&acpi_desc_lock);
3454 list_del(&acpi_desc->list);
3455 mutex_unlock(&acpi_desc_lock);
3457 mutex_lock(&acpi_desc->init_mutex);
3458 acpi_desc->cancel = 1;
3459 cancel_delayed_work_sync(&acpi_desc->dwork);
3460 mutex_unlock(&acpi_desc->init_mutex);
3463 * Bounce the nvdimm bus lock to make sure any in-flight
3464 * acpi_nfit_ars_rescan() submissions have had a chance to
3465 * either submit or see ->cancel set.
3467 device_lock(bus_dev);
3468 device_unlock(bus_dev);
3470 flush_workqueue(nfit_wq);
3472 EXPORT_SYMBOL_GPL(acpi_nfit_shutdown);
3474 static int acpi_nfit_add(struct acpi_device *adev)
3476 struct acpi_buffer buf = { ACPI_ALLOCATE_BUFFER, NULL };
3477 struct acpi_nfit_desc *acpi_desc;
3478 struct device *dev = &adev->dev;
3479 struct acpi_table_header *tbl;
3480 acpi_status status = AE_OK;
3484 status = acpi_get_table(ACPI_SIG_NFIT, 0, &tbl);
3485 if (ACPI_FAILURE(status)) {
3486 /* This is ok, we could have an nvdimm hotplugged later */
3487 dev_dbg(dev, "failed to find NFIT at startup\n");
3491 rc = devm_add_action_or_reset(dev, acpi_nfit_put_table, tbl);
3496 acpi_desc = devm_kzalloc(dev, sizeof(*acpi_desc), GFP_KERNEL);
3499 acpi_nfit_desc_init(acpi_desc, &adev->dev);
3501 /* Save the acpi header for exporting the revision via sysfs */
3502 acpi_desc->acpi_header = *tbl;
3504 /* Evaluate _FIT and override with that if present */
3505 status = acpi_evaluate_object(adev->handle, "_FIT", NULL, &buf);
3506 if (ACPI_SUCCESS(status) && buf.length > 0) {
3507 union acpi_object *obj = buf.pointer;
3509 if (obj->type == ACPI_TYPE_BUFFER)
3510 rc = acpi_nfit_init(acpi_desc, obj->buffer.pointer,
3511 obj->buffer.length);
3513 dev_dbg(dev, "invalid type %d, ignoring _FIT\n",
3517 /* skip over the lead-in header table */
3518 rc = acpi_nfit_init(acpi_desc, (void *) tbl
3519 + sizeof(struct acpi_table_nfit),
3520 sz - sizeof(struct acpi_table_nfit));
3524 return devm_add_action_or_reset(dev, acpi_nfit_shutdown, acpi_desc);
3527 static int acpi_nfit_remove(struct acpi_device *adev)
3529 /* see acpi_nfit_unregister */
3533 static void acpi_nfit_update_notify(struct device *dev, acpi_handle handle)
3535 struct acpi_nfit_desc *acpi_desc = dev_get_drvdata(dev);
3536 struct acpi_buffer buf = { ACPI_ALLOCATE_BUFFER, NULL };
3537 union acpi_object *obj;
3542 /* dev->driver may be null if we're being removed */
3543 dev_dbg(dev, "no driver found for dev\n");
3548 acpi_desc = devm_kzalloc(dev, sizeof(*acpi_desc), GFP_KERNEL);
3551 acpi_nfit_desc_init(acpi_desc, dev);
3554 * Finish previous registration before considering new
3557 flush_workqueue(nfit_wq);
3561 status = acpi_evaluate_object(handle, "_FIT", NULL, &buf);
3562 if (ACPI_FAILURE(status)) {
3563 dev_err(dev, "failed to evaluate _FIT\n");
3568 if (obj->type == ACPI_TYPE_BUFFER) {
3569 ret = acpi_nfit_init(acpi_desc, obj->buffer.pointer,
3570 obj->buffer.length);
3572 dev_err(dev, "failed to merge updated NFIT\n");
3574 dev_err(dev, "Invalid _FIT\n");
3578 static void acpi_nfit_uc_error_notify(struct device *dev, acpi_handle handle)
3580 struct acpi_nfit_desc *acpi_desc = dev_get_drvdata(dev);
3582 if (acpi_desc->scrub_mode == HW_ERROR_SCRUB_ON)
3583 acpi_nfit_ars_rescan(acpi_desc, ARS_REQ_LONG);
3585 acpi_nfit_ars_rescan(acpi_desc, ARS_REQ_SHORT);
3588 void __acpi_nfit_notify(struct device *dev, acpi_handle handle, u32 event)
3590 dev_dbg(dev, "event: 0x%x\n", event);
3593 case NFIT_NOTIFY_UPDATE:
3594 return acpi_nfit_update_notify(dev, handle);
3595 case NFIT_NOTIFY_UC_MEMORY_ERROR:
3596 return acpi_nfit_uc_error_notify(dev, handle);
3601 EXPORT_SYMBOL_GPL(__acpi_nfit_notify);
3603 static void acpi_nfit_notify(struct acpi_device *adev, u32 event)
3605 device_lock(&adev->dev);
3606 __acpi_nfit_notify(&adev->dev, adev->handle, event);
3607 device_unlock(&adev->dev);
3610 static const struct acpi_device_id acpi_nfit_ids[] = {
3614 MODULE_DEVICE_TABLE(acpi, acpi_nfit_ids);
3616 static struct acpi_driver acpi_nfit_driver = {
3617 .name = KBUILD_MODNAME,
3618 .ids = acpi_nfit_ids,
3620 .add = acpi_nfit_add,
3621 .remove = acpi_nfit_remove,
3622 .notify = acpi_nfit_notify,
3626 static __init int nfit_init(void)
3630 BUILD_BUG_ON(sizeof(struct acpi_table_nfit) != 40);
3631 BUILD_BUG_ON(sizeof(struct acpi_nfit_system_address) != 56);
3632 BUILD_BUG_ON(sizeof(struct acpi_nfit_memory_map) != 48);
3633 BUILD_BUG_ON(sizeof(struct acpi_nfit_interleave) != 20);
3634 BUILD_BUG_ON(sizeof(struct acpi_nfit_smbios) != 9);
3635 BUILD_BUG_ON(sizeof(struct acpi_nfit_control_region) != 80);
3636 BUILD_BUG_ON(sizeof(struct acpi_nfit_data_region) != 40);
3637 BUILD_BUG_ON(sizeof(struct acpi_nfit_capabilities) != 16);
3639 guid_parse(UUID_VOLATILE_MEMORY, &nfit_uuid[NFIT_SPA_VOLATILE]);
3640 guid_parse(UUID_PERSISTENT_MEMORY, &nfit_uuid[NFIT_SPA_PM]);
3641 guid_parse(UUID_CONTROL_REGION, &nfit_uuid[NFIT_SPA_DCR]);
3642 guid_parse(UUID_DATA_REGION, &nfit_uuid[NFIT_SPA_BDW]);
3643 guid_parse(UUID_VOLATILE_VIRTUAL_DISK, &nfit_uuid[NFIT_SPA_VDISK]);
3644 guid_parse(UUID_VOLATILE_VIRTUAL_CD, &nfit_uuid[NFIT_SPA_VCD]);
3645 guid_parse(UUID_PERSISTENT_VIRTUAL_DISK, &nfit_uuid[NFIT_SPA_PDISK]);
3646 guid_parse(UUID_PERSISTENT_VIRTUAL_CD, &nfit_uuid[NFIT_SPA_PCD]);
3647 guid_parse(UUID_NFIT_BUS, &nfit_uuid[NFIT_DEV_BUS]);
3648 guid_parse(UUID_NFIT_DIMM, &nfit_uuid[NFIT_DEV_DIMM]);
3649 guid_parse(UUID_NFIT_DIMM_N_HPE1, &nfit_uuid[NFIT_DEV_DIMM_N_HPE1]);
3650 guid_parse(UUID_NFIT_DIMM_N_HPE2, &nfit_uuid[NFIT_DEV_DIMM_N_HPE2]);
3651 guid_parse(UUID_NFIT_DIMM_N_MSFT, &nfit_uuid[NFIT_DEV_DIMM_N_MSFT]);
3653 nfit_wq = create_singlethread_workqueue("nfit");
3657 nfit_mce_register();
3658 ret = acpi_bus_register_driver(&acpi_nfit_driver);
3660 nfit_mce_unregister();
3661 destroy_workqueue(nfit_wq);
3668 static __exit void nfit_exit(void)
3670 nfit_mce_unregister();
3671 acpi_bus_unregister_driver(&acpi_nfit_driver);
3672 destroy_workqueue(nfit_wq);
3673 WARN_ON(!list_empty(&acpi_descs));
3676 module_init(nfit_init);
3677 module_exit(nfit_exit);
3678 MODULE_LICENSE("GPL v2");
3679 MODULE_AUTHOR("Intel Corporation");