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>
30 * For readq() and writeq() on 32-bit builds, the hi-lo, lo-hi order is
33 #include <linux/io-64-nonatomic-hi-lo.h>
35 static bool force_enable_dimms;
36 module_param(force_enable_dimms, bool, S_IRUGO|S_IWUSR);
37 MODULE_PARM_DESC(force_enable_dimms, "Ignore _STA (ACPI DIMM device) status");
39 static bool disable_vendor_specific;
40 module_param(disable_vendor_specific, bool, S_IRUGO);
41 MODULE_PARM_DESC(disable_vendor_specific,
42 "Limit commands to the publicly specified set");
44 static unsigned long override_dsm_mask;
45 module_param(override_dsm_mask, ulong, S_IRUGO);
46 MODULE_PARM_DESC(override_dsm_mask, "Bitmask of allowed NVDIMM DSM functions");
48 static int default_dsm_family = -1;
49 module_param(default_dsm_family, int, S_IRUGO);
50 MODULE_PARM_DESC(default_dsm_family,
51 "Try this DSM type first when identifying NVDIMM family");
53 static bool no_init_ars;
54 module_param(no_init_ars, bool, 0644);
55 MODULE_PARM_DESC(no_init_ars, "Skip ARS run at nfit init time");
57 LIST_HEAD(acpi_descs);
58 DEFINE_MUTEX(acpi_desc_lock);
60 static struct workqueue_struct *nfit_wq;
62 struct nfit_table_prev {
63 struct list_head spas;
64 struct list_head memdevs;
65 struct list_head dcrs;
66 struct list_head bdws;
67 struct list_head idts;
68 struct list_head flushes;
71 static guid_t nfit_uuid[NFIT_UUID_MAX];
73 const guid_t *to_nfit_uuid(enum nfit_uuids id)
75 return &nfit_uuid[id];
77 EXPORT_SYMBOL(to_nfit_uuid);
79 static struct acpi_nfit_desc *to_acpi_nfit_desc(
80 struct nvdimm_bus_descriptor *nd_desc)
82 return container_of(nd_desc, struct acpi_nfit_desc, nd_desc);
85 static struct acpi_device *to_acpi_dev(struct acpi_nfit_desc *acpi_desc)
87 struct nvdimm_bus_descriptor *nd_desc = &acpi_desc->nd_desc;
90 * If provider == 'ACPI.NFIT' we can assume 'dev' is a struct
93 if (!nd_desc->provider_name
94 || strcmp(nd_desc->provider_name, "ACPI.NFIT") != 0)
97 return to_acpi_device(acpi_desc->dev);
100 static int xlat_bus_status(void *buf, unsigned int cmd, u32 status)
102 struct nd_cmd_clear_error *clear_err;
103 struct nd_cmd_ars_status *ars_status;
108 if ((status & 0xffff) == NFIT_ARS_CAP_NONE)
115 /* No supported scan types for this range */
116 flags = ND_ARS_PERSISTENT | ND_ARS_VOLATILE;
117 if ((status >> 16 & flags) == 0)
120 case ND_CMD_ARS_START:
121 /* ARS is in progress */
122 if ((status & 0xffff) == NFIT_ARS_START_BUSY)
129 case ND_CMD_ARS_STATUS:
134 /* Check extended status (Upper two bytes) */
135 if (status == NFIT_ARS_STATUS_DONE)
138 /* ARS is in progress */
139 if (status == NFIT_ARS_STATUS_BUSY)
142 /* No ARS performed for the current boot */
143 if (status == NFIT_ARS_STATUS_NONE)
147 * ARS interrupted, either we overflowed or some other
148 * agent wants the scan to stop. If we didn't overflow
149 * then just continue with the returned results.
151 if (status == NFIT_ARS_STATUS_INTR) {
152 if (ars_status->out_length >= 40 && (ars_status->flags
153 & NFIT_ARS_F_OVERFLOW))
162 case ND_CMD_CLEAR_ERROR:
166 if (!clear_err->cleared)
168 if (clear_err->length > clear_err->cleared)
169 return clear_err->cleared;
175 /* all other non-zero status results in an error */
181 #define ACPI_LABELS_LOCKED 3
183 static int xlat_nvdimm_status(struct nvdimm *nvdimm, void *buf, unsigned int cmd,
186 struct nfit_mem *nfit_mem = nvdimm_provider_data(nvdimm);
189 case ND_CMD_GET_CONFIG_SIZE:
191 * In the _LSI, _LSR, _LSW case the locked status is
192 * communicated via the read/write commands
194 if (nfit_mem->has_lsr)
197 if (status >> 16 & ND_CONFIG_LOCKED)
200 case ND_CMD_GET_CONFIG_DATA:
201 if (nfit_mem->has_lsr && status == ACPI_LABELS_LOCKED)
204 case ND_CMD_SET_CONFIG_DATA:
205 if (nfit_mem->has_lsw && status == ACPI_LABELS_LOCKED)
212 /* all other non-zero status results in an error */
218 static int xlat_status(struct nvdimm *nvdimm, void *buf, unsigned int cmd,
222 return xlat_bus_status(buf, cmd, status);
223 return xlat_nvdimm_status(nvdimm, buf, cmd, status);
226 /* convert _LS{I,R} packages to the buffer object acpi_nfit_ctl expects */
227 static union acpi_object *pkg_to_buf(union acpi_object *pkg)
232 union acpi_object *buf = NULL;
234 if (pkg->type != ACPI_TYPE_PACKAGE) {
235 WARN_ONCE(1, "BIOS bug, unexpected element type: %d\n",
240 for (i = 0; i < pkg->package.count; i++) {
241 union acpi_object *obj = &pkg->package.elements[i];
243 if (obj->type == ACPI_TYPE_INTEGER)
245 else if (obj->type == ACPI_TYPE_BUFFER)
246 size += obj->buffer.length;
248 WARN_ONCE(1, "BIOS bug, unexpected element type: %d\n",
254 buf = ACPI_ALLOCATE(sizeof(*buf) + size);
259 buf->type = ACPI_TYPE_BUFFER;
260 buf->buffer.length = size;
261 buf->buffer.pointer = dst;
262 for (i = 0; i < pkg->package.count; i++) {
263 union acpi_object *obj = &pkg->package.elements[i];
265 if (obj->type == ACPI_TYPE_INTEGER) {
266 memcpy(dst, &obj->integer.value, 4);
268 } else if (obj->type == ACPI_TYPE_BUFFER) {
269 memcpy(dst, obj->buffer.pointer, obj->buffer.length);
270 dst += obj->buffer.length;
278 static union acpi_object *int_to_buf(union acpi_object *integer)
280 union acpi_object *buf = ACPI_ALLOCATE(sizeof(*buf) + 4);
286 if (integer->type != ACPI_TYPE_INTEGER) {
287 WARN_ONCE(1, "BIOS bug, unexpected element type: %d\n",
293 buf->type = ACPI_TYPE_BUFFER;
294 buf->buffer.length = 4;
295 buf->buffer.pointer = dst;
296 memcpy(dst, &integer->integer.value, 4);
302 static union acpi_object *acpi_label_write(acpi_handle handle, u32 offset,
306 struct acpi_buffer buf = { ACPI_ALLOCATE_BUFFER, NULL };
307 struct acpi_object_list input = {
309 .pointer = (union acpi_object []) {
311 .integer.type = ACPI_TYPE_INTEGER,
312 .integer.value = offset,
315 .integer.type = ACPI_TYPE_INTEGER,
316 .integer.value = len,
319 .buffer.type = ACPI_TYPE_BUFFER,
320 .buffer.pointer = data,
321 .buffer.length = len,
326 rc = acpi_evaluate_object(handle, "_LSW", &input, &buf);
327 if (ACPI_FAILURE(rc))
329 return int_to_buf(buf.pointer);
332 static union acpi_object *acpi_label_read(acpi_handle handle, u32 offset,
336 struct acpi_buffer buf = { ACPI_ALLOCATE_BUFFER, NULL };
337 struct acpi_object_list input = {
339 .pointer = (union acpi_object []) {
341 .integer.type = ACPI_TYPE_INTEGER,
342 .integer.value = offset,
345 .integer.type = ACPI_TYPE_INTEGER,
346 .integer.value = len,
351 rc = acpi_evaluate_object(handle, "_LSR", &input, &buf);
352 if (ACPI_FAILURE(rc))
354 return pkg_to_buf(buf.pointer);
357 static union acpi_object *acpi_label_info(acpi_handle handle)
360 struct acpi_buffer buf = { ACPI_ALLOCATE_BUFFER, NULL };
362 rc = acpi_evaluate_object(handle, "_LSI", NULL, &buf);
363 if (ACPI_FAILURE(rc))
365 return pkg_to_buf(buf.pointer);
368 static u8 nfit_dsm_revid(unsigned family, unsigned func)
370 static const u8 revid_table[NVDIMM_FAMILY_MAX+1][32] = {
371 [NVDIMM_FAMILY_INTEL] = {
372 [NVDIMM_INTEL_GET_MODES] = 2,
373 [NVDIMM_INTEL_GET_FWINFO] = 2,
374 [NVDIMM_INTEL_START_FWUPDATE] = 2,
375 [NVDIMM_INTEL_SEND_FWUPDATE] = 2,
376 [NVDIMM_INTEL_FINISH_FWUPDATE] = 2,
377 [NVDIMM_INTEL_QUERY_FWUPDATE] = 2,
378 [NVDIMM_INTEL_SET_THRESHOLD] = 2,
379 [NVDIMM_INTEL_INJECT_ERROR] = 2,
384 if (family > NVDIMM_FAMILY_MAX)
388 id = revid_table[family][func];
390 return 1; /* default */
394 static int cmd_to_func(struct nfit_mem *nfit_mem, unsigned int cmd,
395 struct nd_cmd_pkg *call_pkg)
400 if (nfit_mem && nfit_mem->family != call_pkg->nd_family)
403 for (i = 0; i < ARRAY_SIZE(call_pkg->nd_reserved2); i++)
404 if (call_pkg->nd_reserved2[i])
406 return call_pkg->nd_command;
409 /* In the !call_pkg case, bus commands == bus functions */
413 /* Linux ND commands == NVDIMM_FAMILY_INTEL function numbers */
414 if (nfit_mem->family == NVDIMM_FAMILY_INTEL)
418 * Force function number validation to fail since 0 is never
419 * published as a valid function in dsm_mask.
424 int acpi_nfit_ctl(struct nvdimm_bus_descriptor *nd_desc, struct nvdimm *nvdimm,
425 unsigned int cmd, void *buf, unsigned int buf_len, int *cmd_rc)
427 struct acpi_nfit_desc *acpi_desc = to_acpi_nfit_desc(nd_desc);
428 struct nfit_mem *nfit_mem = nvdimm_provider_data(nvdimm);
429 union acpi_object in_obj, in_buf, *out_obj;
430 const struct nd_cmd_desc *desc = NULL;
431 struct device *dev = acpi_desc->dev;
432 struct nd_cmd_pkg *call_pkg = NULL;
433 const char *cmd_name, *dimm_name;
434 unsigned long cmd_mask, dsm_mask;
435 u32 offset, fw_status = 0;
443 if (cmd == ND_CMD_CALL)
445 func = cmd_to_func(nfit_mem, cmd, call_pkg);
450 struct acpi_device *adev = nfit_mem->adev;
455 dimm_name = nvdimm_name(nvdimm);
456 cmd_name = nvdimm_cmd_name(cmd);
457 cmd_mask = nvdimm_cmd_mask(nvdimm);
458 dsm_mask = nfit_mem->dsm_mask;
459 desc = nd_cmd_dimm_desc(cmd);
460 guid = to_nfit_uuid(nfit_mem->family);
461 handle = adev->handle;
463 struct acpi_device *adev = to_acpi_dev(acpi_desc);
465 cmd_name = nvdimm_bus_cmd_name(cmd);
466 cmd_mask = nd_desc->cmd_mask;
467 dsm_mask = nd_desc->bus_dsm_mask;
468 desc = nd_cmd_bus_desc(cmd);
469 guid = to_nfit_uuid(NFIT_DEV_BUS);
470 handle = adev->handle;
474 if (!desc || (cmd && (desc->out_num + desc->in_num == 0)))
478 * Check for a valid command. For ND_CMD_CALL, we also have to
479 * make sure that the DSM function is supported.
481 if (cmd == ND_CMD_CALL && !test_bit(func, &dsm_mask))
483 else if (!test_bit(cmd, &cmd_mask))
486 in_obj.type = ACPI_TYPE_PACKAGE;
487 in_obj.package.count = 1;
488 in_obj.package.elements = &in_buf;
489 in_buf.type = ACPI_TYPE_BUFFER;
490 in_buf.buffer.pointer = buf;
491 in_buf.buffer.length = 0;
493 /* libnvdimm has already validated the input envelope */
494 for (i = 0; i < desc->in_num; i++)
495 in_buf.buffer.length += nd_cmd_in_size(nvdimm, cmd, desc,
499 /* skip over package wrapper */
500 in_buf.buffer.pointer = (void *) &call_pkg->nd_payload;
501 in_buf.buffer.length = call_pkg->nd_size_in;
504 dev_dbg(dev, "%s cmd: %d: func: %d input length: %d\n",
505 dimm_name, cmd, func, in_buf.buffer.length);
506 print_hex_dump_debug("nvdimm in ", DUMP_PREFIX_OFFSET, 4, 4,
507 in_buf.buffer.pointer,
508 min_t(u32, 256, in_buf.buffer.length), true);
510 /* call the BIOS, prefer the named methods over _DSM if available */
511 if (nvdimm && cmd == ND_CMD_GET_CONFIG_SIZE && nfit_mem->has_lsr)
512 out_obj = acpi_label_info(handle);
513 else if (nvdimm && cmd == ND_CMD_GET_CONFIG_DATA && nfit_mem->has_lsr) {
514 struct nd_cmd_get_config_data_hdr *p = buf;
516 out_obj = acpi_label_read(handle, p->in_offset, p->in_length);
517 } else if (nvdimm && cmd == ND_CMD_SET_CONFIG_DATA
518 && nfit_mem->has_lsw) {
519 struct nd_cmd_set_config_hdr *p = buf;
521 out_obj = acpi_label_write(handle, p->in_offset, p->in_length,
527 revid = nfit_dsm_revid(nfit_mem->family, func);
530 out_obj = acpi_evaluate_dsm(handle, guid, revid, func, &in_obj);
534 dev_dbg(dev, "%s _DSM failed cmd: %s\n", dimm_name, cmd_name);
538 if (out_obj->type != ACPI_TYPE_BUFFER) {
539 dev_dbg(dev, "%s unexpected output object type cmd: %s type: %d\n",
540 dimm_name, cmd_name, out_obj->type);
545 dev_dbg(dev, "%s cmd: %s output length: %d\n", dimm_name,
546 cmd_name, out_obj->buffer.length);
547 print_hex_dump_debug(cmd_name, DUMP_PREFIX_OFFSET, 4, 4,
548 out_obj->buffer.pointer,
549 min_t(u32, 128, out_obj->buffer.length), true);
552 call_pkg->nd_fw_size = out_obj->buffer.length;
553 memcpy(call_pkg->nd_payload + call_pkg->nd_size_in,
554 out_obj->buffer.pointer,
555 min(call_pkg->nd_fw_size, call_pkg->nd_size_out));
559 * Need to support FW function w/o known size in advance.
560 * Caller can determine required size based upon nd_fw_size.
561 * If we return an error (like elsewhere) then caller wouldn't
562 * be able to rely upon data returned to make calculation.
569 for (i = 0, offset = 0; i < desc->out_num; i++) {
570 u32 out_size = nd_cmd_out_size(nvdimm, cmd, desc, i, buf,
571 (u32 *) out_obj->buffer.pointer,
572 out_obj->buffer.length - offset);
574 if (offset + out_size > out_obj->buffer.length) {
575 dev_dbg(dev, "%s output object underflow cmd: %s field: %d\n",
576 dimm_name, cmd_name, i);
580 if (in_buf.buffer.length + offset + out_size > buf_len) {
581 dev_dbg(dev, "%s output overrun cmd: %s field: %d\n",
582 dimm_name, cmd_name, i);
586 memcpy(buf + in_buf.buffer.length + offset,
587 out_obj->buffer.pointer + offset, out_size);
592 * Set fw_status for all the commands with a known format to be
593 * later interpreted by xlat_status().
595 if (i >= 1 && ((!nvdimm && cmd >= ND_CMD_ARS_CAP
596 && cmd <= ND_CMD_CLEAR_ERROR)
597 || (nvdimm && cmd >= ND_CMD_SMART
598 && cmd <= ND_CMD_VENDOR)))
599 fw_status = *(u32 *) out_obj->buffer.pointer;
601 if (offset + in_buf.buffer.length < buf_len) {
604 * status valid, return the number of bytes left
605 * unfilled in the output buffer
607 rc = buf_len - offset - in_buf.buffer.length;
609 *cmd_rc = xlat_status(nvdimm, buf, cmd,
612 dev_err(dev, "%s:%s underrun cmd: %s buf_len: %d out_len: %d\n",
613 __func__, dimm_name, cmd_name, buf_len,
620 *cmd_rc = xlat_status(nvdimm, buf, cmd, fw_status);
628 EXPORT_SYMBOL_GPL(acpi_nfit_ctl);
630 static const char *spa_type_name(u16 type)
632 static const char *to_name[] = {
633 [NFIT_SPA_VOLATILE] = "volatile",
634 [NFIT_SPA_PM] = "pmem",
635 [NFIT_SPA_DCR] = "dimm-control-region",
636 [NFIT_SPA_BDW] = "block-data-window",
637 [NFIT_SPA_VDISK] = "volatile-disk",
638 [NFIT_SPA_VCD] = "volatile-cd",
639 [NFIT_SPA_PDISK] = "persistent-disk",
640 [NFIT_SPA_PCD] = "persistent-cd",
644 if (type > NFIT_SPA_PCD)
647 return to_name[type];
650 int nfit_spa_type(struct acpi_nfit_system_address *spa)
654 for (i = 0; i < NFIT_UUID_MAX; i++)
655 if (guid_equal(to_nfit_uuid(i), (guid_t *)&spa->range_guid))
660 static bool add_spa(struct acpi_nfit_desc *acpi_desc,
661 struct nfit_table_prev *prev,
662 struct acpi_nfit_system_address *spa)
664 struct device *dev = acpi_desc->dev;
665 struct nfit_spa *nfit_spa;
667 if (spa->header.length != sizeof(*spa))
670 list_for_each_entry(nfit_spa, &prev->spas, list) {
671 if (memcmp(nfit_spa->spa, spa, sizeof(*spa)) == 0) {
672 list_move_tail(&nfit_spa->list, &acpi_desc->spas);
677 nfit_spa = devm_kzalloc(dev, sizeof(*nfit_spa) + sizeof(*spa),
681 INIT_LIST_HEAD(&nfit_spa->list);
682 memcpy(nfit_spa->spa, spa, sizeof(*spa));
683 list_add_tail(&nfit_spa->list, &acpi_desc->spas);
684 dev_dbg(dev, "spa index: %d type: %s\n",
686 spa_type_name(nfit_spa_type(spa)));
690 static bool add_memdev(struct acpi_nfit_desc *acpi_desc,
691 struct nfit_table_prev *prev,
692 struct acpi_nfit_memory_map *memdev)
694 struct device *dev = acpi_desc->dev;
695 struct nfit_memdev *nfit_memdev;
697 if (memdev->header.length != sizeof(*memdev))
700 list_for_each_entry(nfit_memdev, &prev->memdevs, list)
701 if (memcmp(nfit_memdev->memdev, memdev, sizeof(*memdev)) == 0) {
702 list_move_tail(&nfit_memdev->list, &acpi_desc->memdevs);
706 nfit_memdev = devm_kzalloc(dev, sizeof(*nfit_memdev) + sizeof(*memdev),
710 INIT_LIST_HEAD(&nfit_memdev->list);
711 memcpy(nfit_memdev->memdev, memdev, sizeof(*memdev));
712 list_add_tail(&nfit_memdev->list, &acpi_desc->memdevs);
713 dev_dbg(dev, "memdev handle: %#x spa: %d dcr: %d flags: %#x\n",
714 memdev->device_handle, memdev->range_index,
715 memdev->region_index, memdev->flags);
719 int nfit_get_smbios_id(u32 device_handle, u16 *flags)
721 struct acpi_nfit_memory_map *memdev;
722 struct acpi_nfit_desc *acpi_desc;
723 struct nfit_mem *nfit_mem;
726 mutex_lock(&acpi_desc_lock);
727 list_for_each_entry(acpi_desc, &acpi_descs, list) {
728 mutex_lock(&acpi_desc->init_mutex);
729 list_for_each_entry(nfit_mem, &acpi_desc->dimms, list) {
730 memdev = __to_nfit_memdev(nfit_mem);
731 if (memdev->device_handle == device_handle) {
732 *flags = memdev->flags;
733 physical_id = memdev->physical_id;
734 mutex_unlock(&acpi_desc->init_mutex);
735 mutex_unlock(&acpi_desc_lock);
739 mutex_unlock(&acpi_desc->init_mutex);
741 mutex_unlock(&acpi_desc_lock);
745 EXPORT_SYMBOL_GPL(nfit_get_smbios_id);
748 * An implementation may provide a truncated control region if no block windows
751 static size_t sizeof_dcr(struct acpi_nfit_control_region *dcr)
753 if (dcr->header.length < offsetof(struct acpi_nfit_control_region,
758 return offsetof(struct acpi_nfit_control_region, window_size);
761 static bool add_dcr(struct acpi_nfit_desc *acpi_desc,
762 struct nfit_table_prev *prev,
763 struct acpi_nfit_control_region *dcr)
765 struct device *dev = acpi_desc->dev;
766 struct nfit_dcr *nfit_dcr;
768 if (!sizeof_dcr(dcr))
771 list_for_each_entry(nfit_dcr, &prev->dcrs, list)
772 if (memcmp(nfit_dcr->dcr, dcr, sizeof_dcr(dcr)) == 0) {
773 list_move_tail(&nfit_dcr->list, &acpi_desc->dcrs);
777 nfit_dcr = devm_kzalloc(dev, sizeof(*nfit_dcr) + sizeof(*dcr),
781 INIT_LIST_HEAD(&nfit_dcr->list);
782 memcpy(nfit_dcr->dcr, dcr, sizeof_dcr(dcr));
783 list_add_tail(&nfit_dcr->list, &acpi_desc->dcrs);
784 dev_dbg(dev, "dcr index: %d windows: %d\n",
785 dcr->region_index, dcr->windows);
789 static bool add_bdw(struct acpi_nfit_desc *acpi_desc,
790 struct nfit_table_prev *prev,
791 struct acpi_nfit_data_region *bdw)
793 struct device *dev = acpi_desc->dev;
794 struct nfit_bdw *nfit_bdw;
796 if (bdw->header.length != sizeof(*bdw))
798 list_for_each_entry(nfit_bdw, &prev->bdws, list)
799 if (memcmp(nfit_bdw->bdw, bdw, sizeof(*bdw)) == 0) {
800 list_move_tail(&nfit_bdw->list, &acpi_desc->bdws);
804 nfit_bdw = devm_kzalloc(dev, sizeof(*nfit_bdw) + sizeof(*bdw),
808 INIT_LIST_HEAD(&nfit_bdw->list);
809 memcpy(nfit_bdw->bdw, bdw, sizeof(*bdw));
810 list_add_tail(&nfit_bdw->list, &acpi_desc->bdws);
811 dev_dbg(dev, "bdw dcr: %d windows: %d\n",
812 bdw->region_index, bdw->windows);
816 static size_t sizeof_idt(struct acpi_nfit_interleave *idt)
818 if (idt->header.length < sizeof(*idt))
820 return sizeof(*idt) + sizeof(u32) * (idt->line_count - 1);
823 static bool add_idt(struct acpi_nfit_desc *acpi_desc,
824 struct nfit_table_prev *prev,
825 struct acpi_nfit_interleave *idt)
827 struct device *dev = acpi_desc->dev;
828 struct nfit_idt *nfit_idt;
830 if (!sizeof_idt(idt))
833 list_for_each_entry(nfit_idt, &prev->idts, list) {
834 if (sizeof_idt(nfit_idt->idt) != sizeof_idt(idt))
837 if (memcmp(nfit_idt->idt, idt, sizeof_idt(idt)) == 0) {
838 list_move_tail(&nfit_idt->list, &acpi_desc->idts);
843 nfit_idt = devm_kzalloc(dev, sizeof(*nfit_idt) + sizeof_idt(idt),
847 INIT_LIST_HEAD(&nfit_idt->list);
848 memcpy(nfit_idt->idt, idt, sizeof_idt(idt));
849 list_add_tail(&nfit_idt->list, &acpi_desc->idts);
850 dev_dbg(dev, "idt index: %d num_lines: %d\n",
851 idt->interleave_index, idt->line_count);
855 static size_t sizeof_flush(struct acpi_nfit_flush_address *flush)
857 if (flush->header.length < sizeof(*flush))
859 return sizeof(*flush) + sizeof(u64) * (flush->hint_count - 1);
862 static bool add_flush(struct acpi_nfit_desc *acpi_desc,
863 struct nfit_table_prev *prev,
864 struct acpi_nfit_flush_address *flush)
866 struct device *dev = acpi_desc->dev;
867 struct nfit_flush *nfit_flush;
869 if (!sizeof_flush(flush))
872 list_for_each_entry(nfit_flush, &prev->flushes, list) {
873 if (sizeof_flush(nfit_flush->flush) != sizeof_flush(flush))
876 if (memcmp(nfit_flush->flush, flush,
877 sizeof_flush(flush)) == 0) {
878 list_move_tail(&nfit_flush->list, &acpi_desc->flushes);
883 nfit_flush = devm_kzalloc(dev, sizeof(*nfit_flush)
884 + sizeof_flush(flush), GFP_KERNEL);
887 INIT_LIST_HEAD(&nfit_flush->list);
888 memcpy(nfit_flush->flush, flush, sizeof_flush(flush));
889 list_add_tail(&nfit_flush->list, &acpi_desc->flushes);
890 dev_dbg(dev, "nfit_flush handle: %d hint_count: %d\n",
891 flush->device_handle, flush->hint_count);
895 static bool add_platform_cap(struct acpi_nfit_desc *acpi_desc,
896 struct acpi_nfit_capabilities *pcap)
898 struct device *dev = acpi_desc->dev;
901 mask = (1 << (pcap->highest_capability + 1)) - 1;
902 acpi_desc->platform_cap = pcap->capabilities & mask;
903 dev_dbg(dev, "cap: %#x\n", acpi_desc->platform_cap);
907 static void *add_table(struct acpi_nfit_desc *acpi_desc,
908 struct nfit_table_prev *prev, void *table, const void *end)
910 struct device *dev = acpi_desc->dev;
911 struct acpi_nfit_header *hdr;
912 void *err = ERR_PTR(-ENOMEM);
919 dev_warn(dev, "found a zero length table '%d' parsing nfit\n",
925 case ACPI_NFIT_TYPE_SYSTEM_ADDRESS:
926 if (!add_spa(acpi_desc, prev, table))
929 case ACPI_NFIT_TYPE_MEMORY_MAP:
930 if (!add_memdev(acpi_desc, prev, table))
933 case ACPI_NFIT_TYPE_CONTROL_REGION:
934 if (!add_dcr(acpi_desc, prev, table))
937 case ACPI_NFIT_TYPE_DATA_REGION:
938 if (!add_bdw(acpi_desc, prev, table))
941 case ACPI_NFIT_TYPE_INTERLEAVE:
942 if (!add_idt(acpi_desc, prev, table))
945 case ACPI_NFIT_TYPE_FLUSH_ADDRESS:
946 if (!add_flush(acpi_desc, prev, table))
949 case ACPI_NFIT_TYPE_SMBIOS:
950 dev_dbg(dev, "smbios\n");
952 case ACPI_NFIT_TYPE_CAPABILITIES:
953 if (!add_platform_cap(acpi_desc, table))
957 dev_err(dev, "unknown table '%d' parsing nfit\n", hdr->type);
961 return table + hdr->length;
964 static void nfit_mem_find_spa_bdw(struct acpi_nfit_desc *acpi_desc,
965 struct nfit_mem *nfit_mem)
967 u32 device_handle = __to_nfit_memdev(nfit_mem)->device_handle;
968 u16 dcr = nfit_mem->dcr->region_index;
969 struct nfit_spa *nfit_spa;
971 list_for_each_entry(nfit_spa, &acpi_desc->spas, list) {
972 u16 range_index = nfit_spa->spa->range_index;
973 int type = nfit_spa_type(nfit_spa->spa);
974 struct nfit_memdev *nfit_memdev;
976 if (type != NFIT_SPA_BDW)
979 list_for_each_entry(nfit_memdev, &acpi_desc->memdevs, list) {
980 if (nfit_memdev->memdev->range_index != range_index)
982 if (nfit_memdev->memdev->device_handle != device_handle)
984 if (nfit_memdev->memdev->region_index != dcr)
987 nfit_mem->spa_bdw = nfit_spa->spa;
992 dev_dbg(acpi_desc->dev, "SPA-BDW not found for SPA-DCR %d\n",
993 nfit_mem->spa_dcr->range_index);
994 nfit_mem->bdw = NULL;
997 static void nfit_mem_init_bdw(struct acpi_nfit_desc *acpi_desc,
998 struct nfit_mem *nfit_mem, struct acpi_nfit_system_address *spa)
1000 u16 dcr = __to_nfit_memdev(nfit_mem)->region_index;
1001 struct nfit_memdev *nfit_memdev;
1002 struct nfit_bdw *nfit_bdw;
1003 struct nfit_idt *nfit_idt;
1004 u16 idt_idx, range_index;
1006 list_for_each_entry(nfit_bdw, &acpi_desc->bdws, list) {
1007 if (nfit_bdw->bdw->region_index != dcr)
1009 nfit_mem->bdw = nfit_bdw->bdw;
1016 nfit_mem_find_spa_bdw(acpi_desc, nfit_mem);
1018 if (!nfit_mem->spa_bdw)
1021 range_index = nfit_mem->spa_bdw->range_index;
1022 list_for_each_entry(nfit_memdev, &acpi_desc->memdevs, list) {
1023 if (nfit_memdev->memdev->range_index != range_index ||
1024 nfit_memdev->memdev->region_index != dcr)
1026 nfit_mem->memdev_bdw = nfit_memdev->memdev;
1027 idt_idx = nfit_memdev->memdev->interleave_index;
1028 list_for_each_entry(nfit_idt, &acpi_desc->idts, list) {
1029 if (nfit_idt->idt->interleave_index != idt_idx)
1031 nfit_mem->idt_bdw = nfit_idt->idt;
1038 static int __nfit_mem_init(struct acpi_nfit_desc *acpi_desc,
1039 struct acpi_nfit_system_address *spa)
1041 struct nfit_mem *nfit_mem, *found;
1042 struct nfit_memdev *nfit_memdev;
1043 int type = spa ? nfit_spa_type(spa) : 0;
1055 * This loop runs in two modes, when a dimm is mapped the loop
1056 * adds memdev associations to an existing dimm, or creates a
1057 * dimm. In the unmapped dimm case this loop sweeps for memdev
1058 * instances with an invalid / zero range_index and adds those
1059 * dimms without spa associations.
1061 list_for_each_entry(nfit_memdev, &acpi_desc->memdevs, list) {
1062 struct nfit_flush *nfit_flush;
1063 struct nfit_dcr *nfit_dcr;
1067 if (spa && nfit_memdev->memdev->range_index != spa->range_index)
1069 if (!spa && nfit_memdev->memdev->range_index)
1072 dcr = nfit_memdev->memdev->region_index;
1073 device_handle = nfit_memdev->memdev->device_handle;
1074 list_for_each_entry(nfit_mem, &acpi_desc->dimms, list)
1075 if (__to_nfit_memdev(nfit_mem)->device_handle
1084 nfit_mem = devm_kzalloc(acpi_desc->dev,
1085 sizeof(*nfit_mem), GFP_KERNEL);
1088 INIT_LIST_HEAD(&nfit_mem->list);
1089 nfit_mem->acpi_desc = acpi_desc;
1090 list_add(&nfit_mem->list, &acpi_desc->dimms);
1093 list_for_each_entry(nfit_dcr, &acpi_desc->dcrs, list) {
1094 if (nfit_dcr->dcr->region_index != dcr)
1097 * Record the control region for the dimm. For
1098 * the ACPI 6.1 case, where there are separate
1099 * control regions for the pmem vs blk
1100 * interfaces, be sure to record the extended
1104 nfit_mem->dcr = nfit_dcr->dcr;
1105 else if (nfit_mem->dcr->windows == 0
1106 && nfit_dcr->dcr->windows)
1107 nfit_mem->dcr = nfit_dcr->dcr;
1111 list_for_each_entry(nfit_flush, &acpi_desc->flushes, list) {
1112 struct acpi_nfit_flush_address *flush;
1115 if (nfit_flush->flush->device_handle != device_handle)
1117 nfit_mem->nfit_flush = nfit_flush;
1118 flush = nfit_flush->flush;
1119 nfit_mem->flush_wpq = devm_kcalloc(acpi_desc->dev,
1121 sizeof(struct resource),
1123 if (!nfit_mem->flush_wpq)
1125 for (i = 0; i < flush->hint_count; i++) {
1126 struct resource *res = &nfit_mem->flush_wpq[i];
1128 res->start = flush->hint_address[i];
1129 res->end = res->start + 8 - 1;
1134 if (dcr && !nfit_mem->dcr) {
1135 dev_err(acpi_desc->dev, "SPA %d missing DCR %d\n",
1136 spa->range_index, dcr);
1140 if (type == NFIT_SPA_DCR) {
1141 struct nfit_idt *nfit_idt;
1144 /* multiple dimms may share a SPA when interleaved */
1145 nfit_mem->spa_dcr = spa;
1146 nfit_mem->memdev_dcr = nfit_memdev->memdev;
1147 idt_idx = nfit_memdev->memdev->interleave_index;
1148 list_for_each_entry(nfit_idt, &acpi_desc->idts, list) {
1149 if (nfit_idt->idt->interleave_index != idt_idx)
1151 nfit_mem->idt_dcr = nfit_idt->idt;
1154 nfit_mem_init_bdw(acpi_desc, nfit_mem, spa);
1155 } else if (type == NFIT_SPA_PM) {
1157 * A single dimm may belong to multiple SPA-PM
1158 * ranges, record at least one in addition to
1159 * any SPA-DCR range.
1161 nfit_mem->memdev_pmem = nfit_memdev->memdev;
1163 nfit_mem->memdev_dcr = nfit_memdev->memdev;
1169 static int nfit_mem_cmp(void *priv, struct list_head *_a, struct list_head *_b)
1171 struct nfit_mem *a = container_of(_a, typeof(*a), list);
1172 struct nfit_mem *b = container_of(_b, typeof(*b), list);
1173 u32 handleA, handleB;
1175 handleA = __to_nfit_memdev(a)->device_handle;
1176 handleB = __to_nfit_memdev(b)->device_handle;
1177 if (handleA < handleB)
1179 else if (handleA > handleB)
1184 static int nfit_mem_init(struct acpi_nfit_desc *acpi_desc)
1186 struct nfit_spa *nfit_spa;
1191 * For each SPA-DCR or SPA-PMEM address range find its
1192 * corresponding MEMDEV(s). From each MEMDEV find the
1193 * corresponding DCR. Then, if we're operating on a SPA-DCR,
1194 * try to find a SPA-BDW and a corresponding BDW that references
1195 * the DCR. Throw it all into an nfit_mem object. Note, that
1196 * BDWs are optional.
1198 list_for_each_entry(nfit_spa, &acpi_desc->spas, list) {
1199 rc = __nfit_mem_init(acpi_desc, nfit_spa->spa);
1205 * If a DIMM has failed to be mapped into SPA there will be no
1206 * SPA entries above. Find and register all the unmapped DIMMs
1207 * for reporting and recovery purposes.
1209 rc = __nfit_mem_init(acpi_desc, NULL);
1213 list_sort(NULL, &acpi_desc->dimms, nfit_mem_cmp);
1218 static ssize_t bus_dsm_mask_show(struct device *dev,
1219 struct device_attribute *attr, char *buf)
1221 struct nvdimm_bus *nvdimm_bus = to_nvdimm_bus(dev);
1222 struct nvdimm_bus_descriptor *nd_desc = to_nd_desc(nvdimm_bus);
1224 return sprintf(buf, "%#lx\n", nd_desc->bus_dsm_mask);
1226 static struct device_attribute dev_attr_bus_dsm_mask =
1227 __ATTR(dsm_mask, 0444, bus_dsm_mask_show, NULL);
1229 static ssize_t revision_show(struct device *dev,
1230 struct device_attribute *attr, char *buf)
1232 struct nvdimm_bus *nvdimm_bus = to_nvdimm_bus(dev);
1233 struct nvdimm_bus_descriptor *nd_desc = to_nd_desc(nvdimm_bus);
1234 struct acpi_nfit_desc *acpi_desc = to_acpi_desc(nd_desc);
1236 return sprintf(buf, "%d\n", acpi_desc->acpi_header.revision);
1238 static DEVICE_ATTR_RO(revision);
1240 static ssize_t hw_error_scrub_show(struct device *dev,
1241 struct device_attribute *attr, char *buf)
1243 struct nvdimm_bus *nvdimm_bus = to_nvdimm_bus(dev);
1244 struct nvdimm_bus_descriptor *nd_desc = to_nd_desc(nvdimm_bus);
1245 struct acpi_nfit_desc *acpi_desc = to_acpi_desc(nd_desc);
1247 return sprintf(buf, "%d\n", acpi_desc->scrub_mode);
1251 * The 'hw_error_scrub' attribute can have the following values written to it:
1252 * '0': Switch to the default mode where an exception will only insert
1253 * the address of the memory error into the poison and badblocks lists.
1254 * '1': Enable a full scrub to happen if an exception for a memory error is
1257 static ssize_t hw_error_scrub_store(struct device *dev,
1258 struct device_attribute *attr, const char *buf, size_t size)
1260 struct nvdimm_bus_descriptor *nd_desc;
1264 rc = kstrtol(buf, 0, &val);
1269 nd_desc = dev_get_drvdata(dev);
1271 struct acpi_nfit_desc *acpi_desc = to_acpi_desc(nd_desc);
1274 case HW_ERROR_SCRUB_ON:
1275 acpi_desc->scrub_mode = HW_ERROR_SCRUB_ON;
1277 case HW_ERROR_SCRUB_OFF:
1278 acpi_desc->scrub_mode = HW_ERROR_SCRUB_OFF;
1290 static DEVICE_ATTR_RW(hw_error_scrub);
1293 * This shows the number of full Address Range Scrubs that have been
1294 * completed since driver load time. Userspace can wait on this using
1295 * select/poll etc. A '+' at the end indicates an ARS is in progress
1297 static ssize_t scrub_show(struct device *dev,
1298 struct device_attribute *attr, char *buf)
1300 struct nvdimm_bus_descriptor *nd_desc;
1301 struct acpi_nfit_desc *acpi_desc;
1302 ssize_t rc = -ENXIO;
1306 nd_desc = dev_get_drvdata(dev);
1311 acpi_desc = to_acpi_desc(nd_desc);
1313 mutex_lock(&acpi_desc->init_mutex);
1314 busy = test_bit(ARS_BUSY, &acpi_desc->scrub_flags)
1315 && !test_bit(ARS_CANCEL, &acpi_desc->scrub_flags);
1316 rc = sprintf(buf, "%d%s", acpi_desc->scrub_count, busy ? "+\n" : "\n");
1317 /* Allow an admin to poll the busy state at a higher rate */
1318 if (busy && capable(CAP_SYS_RAWIO) && !test_and_set_bit(ARS_POLL,
1319 &acpi_desc->scrub_flags)) {
1320 acpi_desc->scrub_tmo = 1;
1321 mod_delayed_work(nfit_wq, &acpi_desc->dwork, HZ);
1324 mutex_unlock(&acpi_desc->init_mutex);
1329 static ssize_t scrub_store(struct device *dev,
1330 struct device_attribute *attr, const char *buf, size_t size)
1332 struct nvdimm_bus_descriptor *nd_desc;
1336 rc = kstrtol(buf, 0, &val);
1343 nd_desc = dev_get_drvdata(dev);
1345 struct acpi_nfit_desc *acpi_desc = to_acpi_desc(nd_desc);
1347 rc = acpi_nfit_ars_rescan(acpi_desc, ARS_REQ_LONG);
1354 static DEVICE_ATTR_RW(scrub);
1356 static bool ars_supported(struct nvdimm_bus *nvdimm_bus)
1358 struct nvdimm_bus_descriptor *nd_desc = to_nd_desc(nvdimm_bus);
1359 const unsigned long mask = 1 << ND_CMD_ARS_CAP | 1 << ND_CMD_ARS_START
1360 | 1 << ND_CMD_ARS_STATUS;
1362 return (nd_desc->cmd_mask & mask) == mask;
1365 static umode_t nfit_visible(struct kobject *kobj, struct attribute *a, int n)
1367 struct device *dev = container_of(kobj, struct device, kobj);
1368 struct nvdimm_bus *nvdimm_bus = to_nvdimm_bus(dev);
1370 if (a == &dev_attr_scrub.attr && !ars_supported(nvdimm_bus))
1375 static struct attribute *acpi_nfit_attributes[] = {
1376 &dev_attr_revision.attr,
1377 &dev_attr_scrub.attr,
1378 &dev_attr_hw_error_scrub.attr,
1379 &dev_attr_bus_dsm_mask.attr,
1383 static const struct attribute_group acpi_nfit_attribute_group = {
1385 .attrs = acpi_nfit_attributes,
1386 .is_visible = nfit_visible,
1389 static const struct attribute_group *acpi_nfit_attribute_groups[] = {
1390 &nvdimm_bus_attribute_group,
1391 &acpi_nfit_attribute_group,
1395 static struct acpi_nfit_memory_map *to_nfit_memdev(struct device *dev)
1397 struct nvdimm *nvdimm = to_nvdimm(dev);
1398 struct nfit_mem *nfit_mem = nvdimm_provider_data(nvdimm);
1400 return __to_nfit_memdev(nfit_mem);
1403 static struct acpi_nfit_control_region *to_nfit_dcr(struct device *dev)
1405 struct nvdimm *nvdimm = to_nvdimm(dev);
1406 struct nfit_mem *nfit_mem = nvdimm_provider_data(nvdimm);
1408 return nfit_mem->dcr;
1411 static ssize_t handle_show(struct device *dev,
1412 struct device_attribute *attr, char *buf)
1414 struct acpi_nfit_memory_map *memdev = to_nfit_memdev(dev);
1416 return sprintf(buf, "%#x\n", memdev->device_handle);
1418 static DEVICE_ATTR_RO(handle);
1420 static ssize_t phys_id_show(struct device *dev,
1421 struct device_attribute *attr, char *buf)
1423 struct acpi_nfit_memory_map *memdev = to_nfit_memdev(dev);
1425 return sprintf(buf, "%#x\n", memdev->physical_id);
1427 static DEVICE_ATTR_RO(phys_id);
1429 static ssize_t vendor_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", be16_to_cpu(dcr->vendor_id));
1436 static DEVICE_ATTR_RO(vendor);
1438 static ssize_t rev_id_show(struct device *dev,
1439 struct device_attribute *attr, char *buf)
1441 struct acpi_nfit_control_region *dcr = to_nfit_dcr(dev);
1443 return sprintf(buf, "0x%04x\n", be16_to_cpu(dcr->revision_id));
1445 static DEVICE_ATTR_RO(rev_id);
1447 static ssize_t device_show(struct device *dev,
1448 struct device_attribute *attr, char *buf)
1450 struct acpi_nfit_control_region *dcr = to_nfit_dcr(dev);
1452 return sprintf(buf, "0x%04x\n", be16_to_cpu(dcr->device_id));
1454 static DEVICE_ATTR_RO(device);
1456 static ssize_t subsystem_vendor_show(struct device *dev,
1457 struct device_attribute *attr, char *buf)
1459 struct acpi_nfit_control_region *dcr = to_nfit_dcr(dev);
1461 return sprintf(buf, "0x%04x\n", be16_to_cpu(dcr->subsystem_vendor_id));
1463 static DEVICE_ATTR_RO(subsystem_vendor);
1465 static ssize_t subsystem_rev_id_show(struct device *dev,
1466 struct device_attribute *attr, char *buf)
1468 struct acpi_nfit_control_region *dcr = to_nfit_dcr(dev);
1470 return sprintf(buf, "0x%04x\n",
1471 be16_to_cpu(dcr->subsystem_revision_id));
1473 static DEVICE_ATTR_RO(subsystem_rev_id);
1475 static ssize_t subsystem_device_show(struct device *dev,
1476 struct device_attribute *attr, char *buf)
1478 struct acpi_nfit_control_region *dcr = to_nfit_dcr(dev);
1480 return sprintf(buf, "0x%04x\n", be16_to_cpu(dcr->subsystem_device_id));
1482 static DEVICE_ATTR_RO(subsystem_device);
1484 static int num_nvdimm_formats(struct nvdimm *nvdimm)
1486 struct nfit_mem *nfit_mem = nvdimm_provider_data(nvdimm);
1489 if (nfit_mem->memdev_pmem)
1491 if (nfit_mem->memdev_bdw)
1496 static ssize_t format_show(struct device *dev,
1497 struct device_attribute *attr, char *buf)
1499 struct acpi_nfit_control_region *dcr = to_nfit_dcr(dev);
1501 return sprintf(buf, "0x%04x\n", le16_to_cpu(dcr->code));
1503 static DEVICE_ATTR_RO(format);
1505 static ssize_t format1_show(struct device *dev,
1506 struct device_attribute *attr, char *buf)
1509 ssize_t rc = -ENXIO;
1510 struct nfit_mem *nfit_mem;
1511 struct nfit_memdev *nfit_memdev;
1512 struct acpi_nfit_desc *acpi_desc;
1513 struct nvdimm *nvdimm = to_nvdimm(dev);
1514 struct acpi_nfit_control_region *dcr = to_nfit_dcr(dev);
1516 nfit_mem = nvdimm_provider_data(nvdimm);
1517 acpi_desc = nfit_mem->acpi_desc;
1518 handle = to_nfit_memdev(dev)->device_handle;
1520 /* assumes DIMMs have at most 2 published interface codes */
1521 mutex_lock(&acpi_desc->init_mutex);
1522 list_for_each_entry(nfit_memdev, &acpi_desc->memdevs, list) {
1523 struct acpi_nfit_memory_map *memdev = nfit_memdev->memdev;
1524 struct nfit_dcr *nfit_dcr;
1526 if (memdev->device_handle != handle)
1529 list_for_each_entry(nfit_dcr, &acpi_desc->dcrs, list) {
1530 if (nfit_dcr->dcr->region_index != memdev->region_index)
1532 if (nfit_dcr->dcr->code == dcr->code)
1534 rc = sprintf(buf, "0x%04x\n",
1535 le16_to_cpu(nfit_dcr->dcr->code));
1541 mutex_unlock(&acpi_desc->init_mutex);
1544 static DEVICE_ATTR_RO(format1);
1546 static ssize_t formats_show(struct device *dev,
1547 struct device_attribute *attr, char *buf)
1549 struct nvdimm *nvdimm = to_nvdimm(dev);
1551 return sprintf(buf, "%d\n", num_nvdimm_formats(nvdimm));
1553 static DEVICE_ATTR_RO(formats);
1555 static ssize_t serial_show(struct device *dev,
1556 struct device_attribute *attr, char *buf)
1558 struct acpi_nfit_control_region *dcr = to_nfit_dcr(dev);
1560 return sprintf(buf, "0x%08x\n", be32_to_cpu(dcr->serial_number));
1562 static DEVICE_ATTR_RO(serial);
1564 static ssize_t family_show(struct device *dev,
1565 struct device_attribute *attr, char *buf)
1567 struct nvdimm *nvdimm = to_nvdimm(dev);
1568 struct nfit_mem *nfit_mem = nvdimm_provider_data(nvdimm);
1570 if (nfit_mem->family < 0)
1572 return sprintf(buf, "%d\n", nfit_mem->family);
1574 static DEVICE_ATTR_RO(family);
1576 static ssize_t dsm_mask_show(struct device *dev,
1577 struct device_attribute *attr, char *buf)
1579 struct nvdimm *nvdimm = to_nvdimm(dev);
1580 struct nfit_mem *nfit_mem = nvdimm_provider_data(nvdimm);
1582 if (nfit_mem->family < 0)
1584 return sprintf(buf, "%#lx\n", nfit_mem->dsm_mask);
1586 static DEVICE_ATTR_RO(dsm_mask);
1588 static ssize_t flags_show(struct device *dev,
1589 struct device_attribute *attr, char *buf)
1591 u16 flags = to_nfit_memdev(dev)->flags;
1593 return sprintf(buf, "%s%s%s%s%s%s%s\n",
1594 flags & ACPI_NFIT_MEM_SAVE_FAILED ? "save_fail " : "",
1595 flags & ACPI_NFIT_MEM_RESTORE_FAILED ? "restore_fail " : "",
1596 flags & ACPI_NFIT_MEM_FLUSH_FAILED ? "flush_fail " : "",
1597 flags & ACPI_NFIT_MEM_NOT_ARMED ? "not_armed " : "",
1598 flags & ACPI_NFIT_MEM_HEALTH_OBSERVED ? "smart_event " : "",
1599 flags & ACPI_NFIT_MEM_MAP_FAILED ? "map_fail " : "",
1600 flags & ACPI_NFIT_MEM_HEALTH_ENABLED ? "smart_notify " : "");
1602 static DEVICE_ATTR_RO(flags);
1604 static ssize_t id_show(struct device *dev,
1605 struct device_attribute *attr, char *buf)
1607 struct acpi_nfit_control_region *dcr = to_nfit_dcr(dev);
1609 if (dcr->valid_fields & ACPI_NFIT_CONTROL_MFG_INFO_VALID)
1610 return sprintf(buf, "%04x-%02x-%04x-%08x\n",
1611 be16_to_cpu(dcr->vendor_id),
1612 dcr->manufacturing_location,
1613 be16_to_cpu(dcr->manufacturing_date),
1614 be32_to_cpu(dcr->serial_number));
1616 return sprintf(buf, "%04x-%08x\n",
1617 be16_to_cpu(dcr->vendor_id),
1618 be32_to_cpu(dcr->serial_number));
1620 static DEVICE_ATTR_RO(id);
1622 static struct attribute *acpi_nfit_dimm_attributes[] = {
1623 &dev_attr_handle.attr,
1624 &dev_attr_phys_id.attr,
1625 &dev_attr_vendor.attr,
1626 &dev_attr_device.attr,
1627 &dev_attr_rev_id.attr,
1628 &dev_attr_subsystem_vendor.attr,
1629 &dev_attr_subsystem_device.attr,
1630 &dev_attr_subsystem_rev_id.attr,
1631 &dev_attr_format.attr,
1632 &dev_attr_formats.attr,
1633 &dev_attr_format1.attr,
1634 &dev_attr_serial.attr,
1635 &dev_attr_flags.attr,
1637 &dev_attr_family.attr,
1638 &dev_attr_dsm_mask.attr,
1642 static umode_t acpi_nfit_dimm_attr_visible(struct kobject *kobj,
1643 struct attribute *a, int n)
1645 struct device *dev = container_of(kobj, struct device, kobj);
1646 struct nvdimm *nvdimm = to_nvdimm(dev);
1648 if (!to_nfit_dcr(dev)) {
1649 /* Without a dcr only the memdev attributes can be surfaced */
1650 if (a == &dev_attr_handle.attr || a == &dev_attr_phys_id.attr
1651 || a == &dev_attr_flags.attr
1652 || a == &dev_attr_family.attr
1653 || a == &dev_attr_dsm_mask.attr)
1658 if (a == &dev_attr_format1.attr && num_nvdimm_formats(nvdimm) <= 1)
1663 static const struct attribute_group acpi_nfit_dimm_attribute_group = {
1665 .attrs = acpi_nfit_dimm_attributes,
1666 .is_visible = acpi_nfit_dimm_attr_visible,
1669 static const struct attribute_group *acpi_nfit_dimm_attribute_groups[] = {
1670 &nvdimm_attribute_group,
1671 &nd_device_attribute_group,
1672 &acpi_nfit_dimm_attribute_group,
1676 static struct nvdimm *acpi_nfit_dimm_by_handle(struct acpi_nfit_desc *acpi_desc,
1679 struct nfit_mem *nfit_mem;
1681 list_for_each_entry(nfit_mem, &acpi_desc->dimms, list)
1682 if (__to_nfit_memdev(nfit_mem)->device_handle == device_handle)
1683 return nfit_mem->nvdimm;
1688 void __acpi_nvdimm_notify(struct device *dev, u32 event)
1690 struct nfit_mem *nfit_mem;
1691 struct acpi_nfit_desc *acpi_desc;
1693 dev_dbg(dev->parent, "%s: event: %d\n", dev_name(dev),
1696 if (event != NFIT_NOTIFY_DIMM_HEALTH) {
1697 dev_dbg(dev->parent, "%s: unknown event: %d\n", dev_name(dev),
1702 acpi_desc = dev_get_drvdata(dev->parent);
1707 * If we successfully retrieved acpi_desc, then we know nfit_mem data
1710 nfit_mem = dev_get_drvdata(dev);
1711 if (nfit_mem && nfit_mem->flags_attr)
1712 sysfs_notify_dirent(nfit_mem->flags_attr);
1714 EXPORT_SYMBOL_GPL(__acpi_nvdimm_notify);
1716 static void acpi_nvdimm_notify(acpi_handle handle, u32 event, void *data)
1718 struct acpi_device *adev = data;
1719 struct device *dev = &adev->dev;
1721 device_lock(dev->parent);
1722 __acpi_nvdimm_notify(dev, event);
1723 device_unlock(dev->parent);
1726 static bool acpi_nvdimm_has_method(struct acpi_device *adev, char *method)
1731 status = acpi_get_handle(adev->handle, method, &handle);
1733 if (ACPI_SUCCESS(status))
1738 static int acpi_nfit_add_dimm(struct acpi_nfit_desc *acpi_desc,
1739 struct nfit_mem *nfit_mem, u32 device_handle)
1741 struct acpi_device *adev, *adev_dimm;
1742 struct device *dev = acpi_desc->dev;
1743 unsigned long dsm_mask, label_mask;
1748 /* nfit test assumes 1:1 relationship between commands and dsms */
1749 nfit_mem->dsm_mask = acpi_desc->dimm_cmd_force_en;
1750 nfit_mem->family = NVDIMM_FAMILY_INTEL;
1751 adev = to_acpi_dev(acpi_desc);
1755 adev_dimm = acpi_find_child_device(adev, device_handle, false);
1756 nfit_mem->adev = adev_dimm;
1758 dev_err(dev, "no ACPI.NFIT device with _ADR %#x, disabling...\n",
1760 return force_enable_dimms ? 0 : -ENODEV;
1763 if (ACPI_FAILURE(acpi_install_notify_handler(adev_dimm->handle,
1764 ACPI_DEVICE_NOTIFY, acpi_nvdimm_notify, adev_dimm))) {
1765 dev_err(dev, "%s: notification registration failed\n",
1766 dev_name(&adev_dimm->dev));
1770 * Record nfit_mem for the notification path to track back to
1771 * the nfit sysfs attributes for this dimm device object.
1773 dev_set_drvdata(&adev_dimm->dev, nfit_mem);
1776 * There are 4 "legacy" NVDIMM command sets
1777 * (NVDIMM_FAMILY_{INTEL,MSFT,HPE1,HPE2}) that were created before
1778 * an EFI working group was established to constrain this
1779 * proliferation. The nfit driver probes for the supported command
1780 * set by GUID. Note, if you're a platform developer looking to add
1781 * a new command set to this probe, consider using an existing set,
1782 * or otherwise seek approval to publish the command set at
1783 * http://www.uefi.org/RFIC_LIST.
1785 * Note, that checking for function0 (bit0) tells us if any commands
1786 * are reachable through this GUID.
1788 for (i = 0; i <= NVDIMM_FAMILY_MAX; i++)
1789 if (acpi_check_dsm(adev_dimm->handle, to_nfit_uuid(i), 1, 1))
1790 if (family < 0 || i == default_dsm_family)
1793 /* limit the supported commands to those that are publicly documented */
1794 nfit_mem->family = family;
1795 if (override_dsm_mask && !disable_vendor_specific)
1796 dsm_mask = override_dsm_mask;
1797 else if (nfit_mem->family == NVDIMM_FAMILY_INTEL) {
1798 dsm_mask = NVDIMM_INTEL_CMDMASK;
1799 if (disable_vendor_specific)
1800 dsm_mask &= ~(1 << ND_CMD_VENDOR);
1801 } else if (nfit_mem->family == NVDIMM_FAMILY_HPE1) {
1802 dsm_mask = 0x1c3c76;
1803 } else if (nfit_mem->family == NVDIMM_FAMILY_HPE2) {
1805 if (disable_vendor_specific)
1806 dsm_mask &= ~(1 << 8);
1807 } else if (nfit_mem->family == NVDIMM_FAMILY_MSFT) {
1808 dsm_mask = 0xffffffff;
1809 } else if (nfit_mem->family == NVDIMM_FAMILY_HYPERV) {
1812 dev_dbg(dev, "unknown dimm command family\n");
1813 nfit_mem->family = -1;
1814 /* DSMs are optional, continue loading the driver... */
1819 * Function 0 is the command interrogation function, don't
1820 * export it to potential userspace use, and enable it to be
1821 * used as an error value in acpi_nfit_ctl().
1825 guid = to_nfit_uuid(nfit_mem->family);
1826 for_each_set_bit(i, &dsm_mask, BITS_PER_LONG)
1827 if (acpi_check_dsm(adev_dimm->handle, guid,
1828 nfit_dsm_revid(nfit_mem->family, i),
1830 set_bit(i, &nfit_mem->dsm_mask);
1833 * Prefer the NVDIMM_FAMILY_INTEL label read commands if present
1834 * due to their better semantics handling locked capacity.
1836 label_mask = 1 << ND_CMD_GET_CONFIG_SIZE | 1 << ND_CMD_GET_CONFIG_DATA
1837 | 1 << ND_CMD_SET_CONFIG_DATA;
1838 if (family == NVDIMM_FAMILY_INTEL
1839 && (dsm_mask & label_mask) == label_mask)
1842 if (acpi_nvdimm_has_method(adev_dimm, "_LSI")
1843 && acpi_nvdimm_has_method(adev_dimm, "_LSR")) {
1844 dev_dbg(dev, "%s: has _LSR\n", dev_name(&adev_dimm->dev));
1845 nfit_mem->has_lsr = true;
1848 if (nfit_mem->has_lsr && acpi_nvdimm_has_method(adev_dimm, "_LSW")) {
1849 dev_dbg(dev, "%s: has _LSW\n", dev_name(&adev_dimm->dev));
1850 nfit_mem->has_lsw = true;
1856 static void shutdown_dimm_notify(void *data)
1858 struct acpi_nfit_desc *acpi_desc = data;
1859 struct nfit_mem *nfit_mem;
1861 mutex_lock(&acpi_desc->init_mutex);
1863 * Clear out the nfit_mem->flags_attr and shut down dimm event
1866 list_for_each_entry(nfit_mem, &acpi_desc->dimms, list) {
1867 struct acpi_device *adev_dimm = nfit_mem->adev;
1869 if (nfit_mem->flags_attr) {
1870 sysfs_put(nfit_mem->flags_attr);
1871 nfit_mem->flags_attr = NULL;
1874 acpi_remove_notify_handler(adev_dimm->handle,
1875 ACPI_DEVICE_NOTIFY, acpi_nvdimm_notify);
1876 dev_set_drvdata(&adev_dimm->dev, NULL);
1879 mutex_unlock(&acpi_desc->init_mutex);
1882 static int acpi_nfit_register_dimms(struct acpi_nfit_desc *acpi_desc)
1884 struct nfit_mem *nfit_mem;
1885 int dimm_count = 0, rc;
1886 struct nvdimm *nvdimm;
1888 list_for_each_entry(nfit_mem, &acpi_desc->dimms, list) {
1889 struct acpi_nfit_flush_address *flush;
1890 unsigned long flags = 0, cmd_mask;
1891 struct nfit_memdev *nfit_memdev;
1895 device_handle = __to_nfit_memdev(nfit_mem)->device_handle;
1896 nvdimm = acpi_nfit_dimm_by_handle(acpi_desc, device_handle);
1902 if (nfit_mem->bdw && nfit_mem->memdev_pmem)
1903 set_bit(NDD_ALIASING, &flags);
1905 /* collate flags across all memdevs for this dimm */
1906 list_for_each_entry(nfit_memdev, &acpi_desc->memdevs, list) {
1907 struct acpi_nfit_memory_map *dimm_memdev;
1909 dimm_memdev = __to_nfit_memdev(nfit_mem);
1910 if (dimm_memdev->device_handle
1911 != nfit_memdev->memdev->device_handle)
1913 dimm_memdev->flags |= nfit_memdev->memdev->flags;
1916 mem_flags = __to_nfit_memdev(nfit_mem)->flags;
1917 if (mem_flags & ACPI_NFIT_MEM_NOT_ARMED)
1918 set_bit(NDD_UNARMED, &flags);
1920 rc = acpi_nfit_add_dimm(acpi_desc, nfit_mem, device_handle);
1925 * TODO: provide translation for non-NVDIMM_FAMILY_INTEL
1926 * devices (i.e. from nd_cmd to acpi_dsm) to standardize the
1927 * userspace interface.
1929 cmd_mask = 1UL << ND_CMD_CALL;
1930 if (nfit_mem->family == NVDIMM_FAMILY_INTEL) {
1932 * These commands have a 1:1 correspondence
1933 * between DSM payload and libnvdimm ioctl
1936 cmd_mask |= nfit_mem->dsm_mask & NVDIMM_STANDARD_CMDMASK;
1939 if (nfit_mem->has_lsr) {
1940 set_bit(ND_CMD_GET_CONFIG_SIZE, &cmd_mask);
1941 set_bit(ND_CMD_GET_CONFIG_DATA, &cmd_mask);
1943 if (nfit_mem->has_lsw)
1944 set_bit(ND_CMD_SET_CONFIG_DATA, &cmd_mask);
1946 flush = nfit_mem->nfit_flush ? nfit_mem->nfit_flush->flush
1948 nvdimm = nvdimm_create(acpi_desc->nvdimm_bus, nfit_mem,
1949 acpi_nfit_dimm_attribute_groups,
1950 flags, cmd_mask, flush ? flush->hint_count : 0,
1951 nfit_mem->flush_wpq);
1955 nfit_mem->nvdimm = nvdimm;
1958 if ((mem_flags & ACPI_NFIT_MEM_FAILED_MASK) == 0)
1961 dev_info(acpi_desc->dev, "%s flags:%s%s%s%s%s\n",
1962 nvdimm_name(nvdimm),
1963 mem_flags & ACPI_NFIT_MEM_SAVE_FAILED ? " save_fail" : "",
1964 mem_flags & ACPI_NFIT_MEM_RESTORE_FAILED ? " restore_fail":"",
1965 mem_flags & ACPI_NFIT_MEM_FLUSH_FAILED ? " flush_fail" : "",
1966 mem_flags & ACPI_NFIT_MEM_NOT_ARMED ? " not_armed" : "",
1967 mem_flags & ACPI_NFIT_MEM_MAP_FAILED ? " map_fail" : "");
1971 rc = nvdimm_bus_check_dimm_count(acpi_desc->nvdimm_bus, dimm_count);
1976 * Now that dimms are successfully registered, and async registration
1977 * is flushed, attempt to enable event notification.
1979 list_for_each_entry(nfit_mem, &acpi_desc->dimms, list) {
1980 struct kernfs_node *nfit_kernfs;
1982 nvdimm = nfit_mem->nvdimm;
1986 nfit_kernfs = sysfs_get_dirent(nvdimm_kobj(nvdimm)->sd, "nfit");
1988 nfit_mem->flags_attr = sysfs_get_dirent(nfit_kernfs,
1990 sysfs_put(nfit_kernfs);
1991 if (!nfit_mem->flags_attr)
1992 dev_warn(acpi_desc->dev, "%s: notifications disabled\n",
1993 nvdimm_name(nvdimm));
1996 return devm_add_action_or_reset(acpi_desc->dev, shutdown_dimm_notify,
2001 * These constants are private because there are no kernel consumers of
2004 enum nfit_aux_cmds {
2005 NFIT_CMD_TRANSLATE_SPA = 5,
2006 NFIT_CMD_ARS_INJECT_SET = 7,
2007 NFIT_CMD_ARS_INJECT_CLEAR = 8,
2008 NFIT_CMD_ARS_INJECT_GET = 9,
2011 static void acpi_nfit_init_dsms(struct acpi_nfit_desc *acpi_desc)
2013 struct nvdimm_bus_descriptor *nd_desc = &acpi_desc->nd_desc;
2014 const guid_t *guid = to_nfit_uuid(NFIT_DEV_BUS);
2015 struct acpi_device *adev;
2016 unsigned long dsm_mask;
2019 nd_desc->cmd_mask = acpi_desc->bus_cmd_force_en;
2020 nd_desc->bus_dsm_mask = acpi_desc->bus_nfit_cmd_force_en;
2021 adev = to_acpi_dev(acpi_desc);
2025 for (i = ND_CMD_ARS_CAP; i <= ND_CMD_CLEAR_ERROR; i++)
2026 if (acpi_check_dsm(adev->handle, guid, 1, 1ULL << i))
2027 set_bit(i, &nd_desc->cmd_mask);
2028 set_bit(ND_CMD_CALL, &nd_desc->cmd_mask);
2031 (1 << ND_CMD_ARS_CAP) |
2032 (1 << ND_CMD_ARS_START) |
2033 (1 << ND_CMD_ARS_STATUS) |
2034 (1 << ND_CMD_CLEAR_ERROR) |
2035 (1 << NFIT_CMD_TRANSLATE_SPA) |
2036 (1 << NFIT_CMD_ARS_INJECT_SET) |
2037 (1 << NFIT_CMD_ARS_INJECT_CLEAR) |
2038 (1 << NFIT_CMD_ARS_INJECT_GET);
2039 for_each_set_bit(i, &dsm_mask, BITS_PER_LONG)
2040 if (acpi_check_dsm(adev->handle, guid, 1, 1ULL << i))
2041 set_bit(i, &nd_desc->bus_dsm_mask);
2044 static ssize_t range_index_show(struct device *dev,
2045 struct device_attribute *attr, char *buf)
2047 struct nd_region *nd_region = to_nd_region(dev);
2048 struct nfit_spa *nfit_spa = nd_region_provider_data(nd_region);
2050 return sprintf(buf, "%d\n", nfit_spa->spa->range_index);
2052 static DEVICE_ATTR_RO(range_index);
2054 static struct attribute *acpi_nfit_region_attributes[] = {
2055 &dev_attr_range_index.attr,
2059 static const struct attribute_group acpi_nfit_region_attribute_group = {
2061 .attrs = acpi_nfit_region_attributes,
2064 static const struct attribute_group *acpi_nfit_region_attribute_groups[] = {
2065 &nd_region_attribute_group,
2066 &nd_mapping_attribute_group,
2067 &nd_device_attribute_group,
2068 &nd_numa_attribute_group,
2069 &acpi_nfit_region_attribute_group,
2073 /* enough info to uniquely specify an interleave set */
2074 struct nfit_set_info {
2075 struct nfit_set_info_map {
2082 struct nfit_set_info2 {
2083 struct nfit_set_info_map2 {
2087 u16 manufacturing_date;
2088 u8 manufacturing_location;
2093 static size_t sizeof_nfit_set_info(int num_mappings)
2095 return sizeof(struct nfit_set_info)
2096 + num_mappings * sizeof(struct nfit_set_info_map);
2099 static size_t sizeof_nfit_set_info2(int num_mappings)
2101 return sizeof(struct nfit_set_info2)
2102 + num_mappings * sizeof(struct nfit_set_info_map2);
2105 static int cmp_map_compat(const void *m0, const void *m1)
2107 const struct nfit_set_info_map *map0 = m0;
2108 const struct nfit_set_info_map *map1 = m1;
2110 return memcmp(&map0->region_offset, &map1->region_offset,
2114 static int cmp_map(const void *m0, const void *m1)
2116 const struct nfit_set_info_map *map0 = m0;
2117 const struct nfit_set_info_map *map1 = m1;
2119 if (map0->region_offset < map1->region_offset)
2121 else if (map0->region_offset > map1->region_offset)
2126 static int cmp_map2(const void *m0, const void *m1)
2128 const struct nfit_set_info_map2 *map0 = m0;
2129 const struct nfit_set_info_map2 *map1 = m1;
2131 if (map0->region_offset < map1->region_offset)
2133 else if (map0->region_offset > map1->region_offset)
2138 /* Retrieve the nth entry referencing this spa */
2139 static struct acpi_nfit_memory_map *memdev_from_spa(
2140 struct acpi_nfit_desc *acpi_desc, u16 range_index, int n)
2142 struct nfit_memdev *nfit_memdev;
2144 list_for_each_entry(nfit_memdev, &acpi_desc->memdevs, list)
2145 if (nfit_memdev->memdev->range_index == range_index)
2147 return nfit_memdev->memdev;
2151 static int acpi_nfit_init_interleave_set(struct acpi_nfit_desc *acpi_desc,
2152 struct nd_region_desc *ndr_desc,
2153 struct acpi_nfit_system_address *spa)
2155 struct device *dev = acpi_desc->dev;
2156 struct nd_interleave_set *nd_set;
2157 u16 nr = ndr_desc->num_mappings;
2158 struct nfit_set_info2 *info2;
2159 struct nfit_set_info *info;
2162 nd_set = devm_kzalloc(dev, sizeof(*nd_set), GFP_KERNEL);
2165 ndr_desc->nd_set = nd_set;
2166 guid_copy(&nd_set->type_guid, (guid_t *) spa->range_guid);
2168 info = devm_kzalloc(dev, sizeof_nfit_set_info(nr), GFP_KERNEL);
2172 info2 = devm_kzalloc(dev, sizeof_nfit_set_info2(nr), GFP_KERNEL);
2176 for (i = 0; i < nr; i++) {
2177 struct nd_mapping_desc *mapping = &ndr_desc->mapping[i];
2178 struct nfit_set_info_map *map = &info->mapping[i];
2179 struct nfit_set_info_map2 *map2 = &info2->mapping[i];
2180 struct nvdimm *nvdimm = mapping->nvdimm;
2181 struct nfit_mem *nfit_mem = nvdimm_provider_data(nvdimm);
2182 struct acpi_nfit_memory_map *memdev = memdev_from_spa(acpi_desc,
2183 spa->range_index, i);
2184 struct acpi_nfit_control_region *dcr = nfit_mem->dcr;
2186 if (!memdev || !nfit_mem->dcr) {
2187 dev_err(dev, "%s: failed to find DCR\n", __func__);
2191 map->region_offset = memdev->region_offset;
2192 map->serial_number = dcr->serial_number;
2194 map2->region_offset = memdev->region_offset;
2195 map2->serial_number = dcr->serial_number;
2196 map2->vendor_id = dcr->vendor_id;
2197 map2->manufacturing_date = dcr->manufacturing_date;
2198 map2->manufacturing_location = dcr->manufacturing_location;
2201 /* v1.1 namespaces */
2202 sort(&info->mapping[0], nr, sizeof(struct nfit_set_info_map),
2204 nd_set->cookie1 = nd_fletcher64(info, sizeof_nfit_set_info(nr), 0);
2206 /* v1.2 namespaces */
2207 sort(&info2->mapping[0], nr, sizeof(struct nfit_set_info_map2),
2209 nd_set->cookie2 = nd_fletcher64(info2, sizeof_nfit_set_info2(nr), 0);
2211 /* support v1.1 namespaces created with the wrong sort order */
2212 sort(&info->mapping[0], nr, sizeof(struct nfit_set_info_map),
2213 cmp_map_compat, NULL);
2214 nd_set->altcookie = nd_fletcher64(info, sizeof_nfit_set_info(nr), 0);
2216 /* record the result of the sort for the mapping position */
2217 for (i = 0; i < nr; i++) {
2218 struct nfit_set_info_map2 *map2 = &info2->mapping[i];
2221 for (j = 0; j < nr; j++) {
2222 struct nd_mapping_desc *mapping = &ndr_desc->mapping[j];
2223 struct nvdimm *nvdimm = mapping->nvdimm;
2224 struct nfit_mem *nfit_mem = nvdimm_provider_data(nvdimm);
2225 struct acpi_nfit_control_region *dcr = nfit_mem->dcr;
2227 if (map2->serial_number == dcr->serial_number &&
2228 map2->vendor_id == dcr->vendor_id &&
2229 map2->manufacturing_date == dcr->manufacturing_date &&
2230 map2->manufacturing_location
2231 == dcr->manufacturing_location) {
2232 mapping->position = i;
2238 ndr_desc->nd_set = nd_set;
2239 devm_kfree(dev, info);
2240 devm_kfree(dev, info2);
2245 static u64 to_interleave_offset(u64 offset, struct nfit_blk_mmio *mmio)
2247 struct acpi_nfit_interleave *idt = mmio->idt;
2248 u32 sub_line_offset, line_index, line_offset;
2249 u64 line_no, table_skip_count, table_offset;
2251 line_no = div_u64_rem(offset, mmio->line_size, &sub_line_offset);
2252 table_skip_count = div_u64_rem(line_no, mmio->num_lines, &line_index);
2253 line_offset = idt->line_offset[line_index]
2255 table_offset = table_skip_count * mmio->table_size;
2257 return mmio->base_offset + line_offset + table_offset + sub_line_offset;
2260 static u32 read_blk_stat(struct nfit_blk *nfit_blk, unsigned int bw)
2262 struct nfit_blk_mmio *mmio = &nfit_blk->mmio[DCR];
2263 u64 offset = nfit_blk->stat_offset + mmio->size * bw;
2264 const u32 STATUS_MASK = 0x80000037;
2266 if (mmio->num_lines)
2267 offset = to_interleave_offset(offset, mmio);
2269 return readl(mmio->addr.base + offset) & STATUS_MASK;
2272 static void write_blk_ctl(struct nfit_blk *nfit_blk, unsigned int bw,
2273 resource_size_t dpa, unsigned int len, unsigned int write)
2276 struct nfit_blk_mmio *mmio = &nfit_blk->mmio[DCR];
2279 BCW_OFFSET_MASK = (1ULL << 48)-1,
2281 BCW_LEN_MASK = (1ULL << 8) - 1,
2285 cmd = (dpa >> L1_CACHE_SHIFT) & BCW_OFFSET_MASK;
2286 len = len >> L1_CACHE_SHIFT;
2287 cmd |= ((u64) len & BCW_LEN_MASK) << BCW_LEN_SHIFT;
2288 cmd |= ((u64) write) << BCW_CMD_SHIFT;
2290 offset = nfit_blk->cmd_offset + mmio->size * bw;
2291 if (mmio->num_lines)
2292 offset = to_interleave_offset(offset, mmio);
2294 writeq(cmd, mmio->addr.base + offset);
2295 nvdimm_flush(nfit_blk->nd_region);
2297 if (nfit_blk->dimm_flags & NFIT_BLK_DCR_LATCH)
2298 readq(mmio->addr.base + offset);
2301 static int acpi_nfit_blk_single_io(struct nfit_blk *nfit_blk,
2302 resource_size_t dpa, void *iobuf, size_t len, int rw,
2305 struct nfit_blk_mmio *mmio = &nfit_blk->mmio[BDW];
2306 unsigned int copied = 0;
2310 base_offset = nfit_blk->bdw_offset + dpa % L1_CACHE_BYTES
2311 + lane * mmio->size;
2312 write_blk_ctl(nfit_blk, lane, dpa, len, rw);
2317 if (mmio->num_lines) {
2320 offset = to_interleave_offset(base_offset + copied,
2322 div_u64_rem(offset, mmio->line_size, &line_offset);
2323 c = min_t(size_t, len, mmio->line_size - line_offset);
2325 offset = base_offset + nfit_blk->bdw_offset;
2330 memcpy_flushcache(mmio->addr.aperture + offset, iobuf + copied, c);
2332 if (nfit_blk->dimm_flags & NFIT_BLK_READ_FLUSH)
2333 arch_invalidate_pmem((void __force *)
2334 mmio->addr.aperture + offset, c);
2336 memcpy(iobuf + copied, mmio->addr.aperture + offset, c);
2344 nvdimm_flush(nfit_blk->nd_region);
2346 rc = read_blk_stat(nfit_blk, lane) ? -EIO : 0;
2350 static int acpi_nfit_blk_region_do_io(struct nd_blk_region *ndbr,
2351 resource_size_t dpa, void *iobuf, u64 len, int rw)
2353 struct nfit_blk *nfit_blk = nd_blk_region_provider_data(ndbr);
2354 struct nfit_blk_mmio *mmio = &nfit_blk->mmio[BDW];
2355 struct nd_region *nd_region = nfit_blk->nd_region;
2356 unsigned int lane, copied = 0;
2359 lane = nd_region_acquire_lane(nd_region);
2361 u64 c = min(len, mmio->size);
2363 rc = acpi_nfit_blk_single_io(nfit_blk, dpa + copied,
2364 iobuf + copied, c, rw, lane);
2371 nd_region_release_lane(nd_region, lane);
2376 static int nfit_blk_init_interleave(struct nfit_blk_mmio *mmio,
2377 struct acpi_nfit_interleave *idt, u16 interleave_ways)
2380 mmio->num_lines = idt->line_count;
2381 mmio->line_size = idt->line_size;
2382 if (interleave_ways == 0)
2384 mmio->table_size = mmio->num_lines * interleave_ways
2391 static int acpi_nfit_blk_get_flags(struct nvdimm_bus_descriptor *nd_desc,
2392 struct nvdimm *nvdimm, struct nfit_blk *nfit_blk)
2394 struct nd_cmd_dimm_flags flags;
2397 memset(&flags, 0, sizeof(flags));
2398 rc = nd_desc->ndctl(nd_desc, nvdimm, ND_CMD_DIMM_FLAGS, &flags,
2399 sizeof(flags), NULL);
2401 if (rc >= 0 && flags.status == 0)
2402 nfit_blk->dimm_flags = flags.flags;
2403 else if (rc == -ENOTTY) {
2404 /* fall back to a conservative default */
2405 nfit_blk->dimm_flags = NFIT_BLK_DCR_LATCH | NFIT_BLK_READ_FLUSH;
2413 static int acpi_nfit_blk_region_enable(struct nvdimm_bus *nvdimm_bus,
2416 struct nvdimm_bus_descriptor *nd_desc = to_nd_desc(nvdimm_bus);
2417 struct nd_blk_region *ndbr = to_nd_blk_region(dev);
2418 struct nfit_blk_mmio *mmio;
2419 struct nfit_blk *nfit_blk;
2420 struct nfit_mem *nfit_mem;
2421 struct nvdimm *nvdimm;
2424 nvdimm = nd_blk_region_to_dimm(ndbr);
2425 nfit_mem = nvdimm_provider_data(nvdimm);
2426 if (!nfit_mem || !nfit_mem->dcr || !nfit_mem->bdw) {
2427 dev_dbg(dev, "missing%s%s%s\n",
2428 nfit_mem ? "" : " nfit_mem",
2429 (nfit_mem && nfit_mem->dcr) ? "" : " dcr",
2430 (nfit_mem && nfit_mem->bdw) ? "" : " bdw");
2434 nfit_blk = devm_kzalloc(dev, sizeof(*nfit_blk), GFP_KERNEL);
2437 nd_blk_region_set_provider_data(ndbr, nfit_blk);
2438 nfit_blk->nd_region = to_nd_region(dev);
2440 /* map block aperture memory */
2441 nfit_blk->bdw_offset = nfit_mem->bdw->offset;
2442 mmio = &nfit_blk->mmio[BDW];
2443 mmio->addr.base = devm_nvdimm_memremap(dev, nfit_mem->spa_bdw->address,
2444 nfit_mem->spa_bdw->length, nd_blk_memremap_flags(ndbr));
2445 if (!mmio->addr.base) {
2446 dev_dbg(dev, "%s failed to map bdw\n",
2447 nvdimm_name(nvdimm));
2450 mmio->size = nfit_mem->bdw->size;
2451 mmio->base_offset = nfit_mem->memdev_bdw->region_offset;
2452 mmio->idt = nfit_mem->idt_bdw;
2453 mmio->spa = nfit_mem->spa_bdw;
2454 rc = nfit_blk_init_interleave(mmio, nfit_mem->idt_bdw,
2455 nfit_mem->memdev_bdw->interleave_ways);
2457 dev_dbg(dev, "%s failed to init bdw interleave\n",
2458 nvdimm_name(nvdimm));
2462 /* map block control memory */
2463 nfit_blk->cmd_offset = nfit_mem->dcr->command_offset;
2464 nfit_blk->stat_offset = nfit_mem->dcr->status_offset;
2465 mmio = &nfit_blk->mmio[DCR];
2466 mmio->addr.base = devm_nvdimm_ioremap(dev, nfit_mem->spa_dcr->address,
2467 nfit_mem->spa_dcr->length);
2468 if (!mmio->addr.base) {
2469 dev_dbg(dev, "%s failed to map dcr\n",
2470 nvdimm_name(nvdimm));
2473 mmio->size = nfit_mem->dcr->window_size;
2474 mmio->base_offset = nfit_mem->memdev_dcr->region_offset;
2475 mmio->idt = nfit_mem->idt_dcr;
2476 mmio->spa = nfit_mem->spa_dcr;
2477 rc = nfit_blk_init_interleave(mmio, nfit_mem->idt_dcr,
2478 nfit_mem->memdev_dcr->interleave_ways);
2480 dev_dbg(dev, "%s failed to init dcr interleave\n",
2481 nvdimm_name(nvdimm));
2485 rc = acpi_nfit_blk_get_flags(nd_desc, nvdimm, nfit_blk);
2487 dev_dbg(dev, "%s failed get DIMM flags\n",
2488 nvdimm_name(nvdimm));
2492 if (nvdimm_has_flush(nfit_blk->nd_region) < 0)
2493 dev_warn(dev, "unable to guarantee persistence of writes\n");
2495 if (mmio->line_size == 0)
2498 if ((u32) nfit_blk->cmd_offset % mmio->line_size
2499 + 8 > mmio->line_size) {
2500 dev_dbg(dev, "cmd_offset crosses interleave boundary\n");
2502 } else if ((u32) nfit_blk->stat_offset % mmio->line_size
2503 + 8 > mmio->line_size) {
2504 dev_dbg(dev, "stat_offset crosses interleave boundary\n");
2511 static int ars_get_cap(struct acpi_nfit_desc *acpi_desc,
2512 struct nd_cmd_ars_cap *cmd, struct nfit_spa *nfit_spa)
2514 struct nvdimm_bus_descriptor *nd_desc = &acpi_desc->nd_desc;
2515 struct acpi_nfit_system_address *spa = nfit_spa->spa;
2518 cmd->address = spa->address;
2519 cmd->length = spa->length;
2520 rc = nd_desc->ndctl(nd_desc, NULL, ND_CMD_ARS_CAP, cmd,
2521 sizeof(*cmd), &cmd_rc);
2527 static int ars_start(struct acpi_nfit_desc *acpi_desc,
2528 struct nfit_spa *nfit_spa, enum nfit_ars_state req_type)
2532 struct nd_cmd_ars_start ars_start;
2533 struct acpi_nfit_system_address *spa = nfit_spa->spa;
2534 struct nvdimm_bus_descriptor *nd_desc = &acpi_desc->nd_desc;
2536 memset(&ars_start, 0, sizeof(ars_start));
2537 ars_start.address = spa->address;
2538 ars_start.length = spa->length;
2539 if (req_type == ARS_REQ_SHORT)
2540 ars_start.flags = ND_ARS_RETURN_PREV_DATA;
2541 if (nfit_spa_type(spa) == NFIT_SPA_PM)
2542 ars_start.type = ND_ARS_PERSISTENT;
2543 else if (nfit_spa_type(spa) == NFIT_SPA_VOLATILE)
2544 ars_start.type = ND_ARS_VOLATILE;
2548 rc = nd_desc->ndctl(nd_desc, NULL, ND_CMD_ARS_START, &ars_start,
2549 sizeof(ars_start), &cmd_rc);
2555 set_bit(ARS_VALID, &acpi_desc->scrub_flags);
2559 static int ars_continue(struct acpi_nfit_desc *acpi_desc)
2562 struct nd_cmd_ars_start ars_start;
2563 struct nvdimm_bus_descriptor *nd_desc = &acpi_desc->nd_desc;
2564 struct nd_cmd_ars_status *ars_status = acpi_desc->ars_status;
2566 ars_start = (struct nd_cmd_ars_start) {
2567 .address = ars_status->restart_address,
2568 .length = ars_status->restart_length,
2569 .type = ars_status->type,
2571 rc = nd_desc->ndctl(nd_desc, NULL, ND_CMD_ARS_START, &ars_start,
2572 sizeof(ars_start), &cmd_rc);
2578 static int ars_get_status(struct acpi_nfit_desc *acpi_desc)
2580 struct nvdimm_bus_descriptor *nd_desc = &acpi_desc->nd_desc;
2581 struct nd_cmd_ars_status *ars_status = acpi_desc->ars_status;
2584 rc = nd_desc->ndctl(nd_desc, NULL, ND_CMD_ARS_STATUS, ars_status,
2585 acpi_desc->max_ars, &cmd_rc);
2591 static void ars_complete(struct acpi_nfit_desc *acpi_desc,
2592 struct nfit_spa *nfit_spa)
2594 struct nd_cmd_ars_status *ars_status = acpi_desc->ars_status;
2595 struct acpi_nfit_system_address *spa = nfit_spa->spa;
2596 struct nd_region *nd_region = nfit_spa->nd_region;
2599 lockdep_assert_held(&acpi_desc->init_mutex);
2601 * Only advance the ARS state for ARS runs initiated by the
2602 * kernel, ignore ARS results from BIOS initiated runs for scrub
2603 * completion tracking.
2605 if (acpi_desc->scrub_spa != nfit_spa)
2608 if ((ars_status->address >= spa->address && ars_status->address
2609 < spa->address + spa->length)
2610 || (ars_status->address < spa->address)) {
2612 * Assume that if a scrub starts at an offset from the
2613 * start of nfit_spa that we are in the continuation
2616 * Otherwise, if the scrub covers the spa range, mark
2617 * any pending request complete.
2619 if (ars_status->address + ars_status->length
2620 >= spa->address + spa->length)
2627 acpi_desc->scrub_spa = NULL;
2629 dev = nd_region_dev(nd_region);
2630 nvdimm_region_notify(nd_region, NVDIMM_REVALIDATE_POISON);
2632 dev = acpi_desc->dev;
2633 dev_dbg(dev, "ARS: range %d complete\n", spa->range_index);
2636 static int ars_status_process_records(struct acpi_nfit_desc *acpi_desc)
2638 struct nvdimm_bus *nvdimm_bus = acpi_desc->nvdimm_bus;
2639 struct nd_cmd_ars_status *ars_status = acpi_desc->ars_status;
2644 * First record starts at 44 byte offset from the start of the
2647 if (ars_status->out_length < 44)
2651 * Ignore potentially stale results that are only refreshed
2652 * after a start-ARS event.
2654 if (!test_and_clear_bit(ARS_VALID, &acpi_desc->scrub_flags)) {
2655 dev_dbg(acpi_desc->dev, "skip %d stale records\n",
2656 ars_status->num_records);
2660 for (i = 0; i < ars_status->num_records; i++) {
2661 /* only process full records */
2662 if (ars_status->out_length
2663 < 44 + sizeof(struct nd_ars_record) * (i + 1))
2665 rc = nvdimm_bus_add_badrange(nvdimm_bus,
2666 ars_status->records[i].err_address,
2667 ars_status->records[i].length);
2671 if (i < ars_status->num_records)
2672 dev_warn(acpi_desc->dev, "detected truncated ars results\n");
2677 static void acpi_nfit_remove_resource(void *data)
2679 struct resource *res = data;
2681 remove_resource(res);
2684 static int acpi_nfit_insert_resource(struct acpi_nfit_desc *acpi_desc,
2685 struct nd_region_desc *ndr_desc)
2687 struct resource *res, *nd_res = ndr_desc->res;
2690 /* No operation if the region is already registered as PMEM */
2691 is_pmem = region_intersects(nd_res->start, resource_size(nd_res),
2692 IORESOURCE_MEM, IORES_DESC_PERSISTENT_MEMORY);
2693 if (is_pmem == REGION_INTERSECTS)
2696 res = devm_kzalloc(acpi_desc->dev, sizeof(*res), GFP_KERNEL);
2700 res->name = "Persistent Memory";
2701 res->start = nd_res->start;
2702 res->end = nd_res->end;
2703 res->flags = IORESOURCE_MEM;
2704 res->desc = IORES_DESC_PERSISTENT_MEMORY;
2706 ret = insert_resource(&iomem_resource, res);
2710 ret = devm_add_action_or_reset(acpi_desc->dev,
2711 acpi_nfit_remove_resource,
2719 static int acpi_nfit_init_mapping(struct acpi_nfit_desc *acpi_desc,
2720 struct nd_mapping_desc *mapping, struct nd_region_desc *ndr_desc,
2721 struct acpi_nfit_memory_map *memdev,
2722 struct nfit_spa *nfit_spa)
2724 struct nvdimm *nvdimm = acpi_nfit_dimm_by_handle(acpi_desc,
2725 memdev->device_handle);
2726 struct acpi_nfit_system_address *spa = nfit_spa->spa;
2727 struct nd_blk_region_desc *ndbr_desc;
2728 struct nfit_mem *nfit_mem;
2732 dev_err(acpi_desc->dev, "spa%d dimm: %#x not found\n",
2733 spa->range_index, memdev->device_handle);
2737 mapping->nvdimm = nvdimm;
2738 switch (nfit_spa_type(spa)) {
2740 case NFIT_SPA_VOLATILE:
2741 mapping->start = memdev->address;
2742 mapping->size = memdev->region_size;
2745 nfit_mem = nvdimm_provider_data(nvdimm);
2746 if (!nfit_mem || !nfit_mem->bdw) {
2747 dev_dbg(acpi_desc->dev, "spa%d %s missing bdw\n",
2748 spa->range_index, nvdimm_name(nvdimm));
2752 mapping->size = nfit_mem->bdw->capacity;
2753 mapping->start = nfit_mem->bdw->start_address;
2754 ndr_desc->num_lanes = nfit_mem->bdw->windows;
2755 ndr_desc->mapping = mapping;
2756 ndr_desc->num_mappings = 1;
2757 ndbr_desc = to_blk_region_desc(ndr_desc);
2758 ndbr_desc->enable = acpi_nfit_blk_region_enable;
2759 ndbr_desc->do_io = acpi_desc->blk_do_io;
2760 rc = acpi_nfit_init_interleave_set(acpi_desc, ndr_desc, spa);
2763 nfit_spa->nd_region = nvdimm_blk_region_create(acpi_desc->nvdimm_bus,
2765 if (!nfit_spa->nd_region)
2773 static bool nfit_spa_is_virtual(struct acpi_nfit_system_address *spa)
2775 return (nfit_spa_type(spa) == NFIT_SPA_VDISK ||
2776 nfit_spa_type(spa) == NFIT_SPA_VCD ||
2777 nfit_spa_type(spa) == NFIT_SPA_PDISK ||
2778 nfit_spa_type(spa) == NFIT_SPA_PCD);
2781 static bool nfit_spa_is_volatile(struct acpi_nfit_system_address *spa)
2783 return (nfit_spa_type(spa) == NFIT_SPA_VDISK ||
2784 nfit_spa_type(spa) == NFIT_SPA_VCD ||
2785 nfit_spa_type(spa) == NFIT_SPA_VOLATILE);
2788 static int acpi_nfit_register_region(struct acpi_nfit_desc *acpi_desc,
2789 struct nfit_spa *nfit_spa)
2791 static struct nd_mapping_desc mappings[ND_MAX_MAPPINGS];
2792 struct acpi_nfit_system_address *spa = nfit_spa->spa;
2793 struct nd_blk_region_desc ndbr_desc;
2794 struct nd_region_desc *ndr_desc;
2795 struct nfit_memdev *nfit_memdev;
2796 struct nvdimm_bus *nvdimm_bus;
2797 struct resource res;
2800 if (nfit_spa->nd_region)
2803 if (spa->range_index == 0 && !nfit_spa_is_virtual(spa)) {
2804 dev_dbg(acpi_desc->dev, "detected invalid spa index\n");
2808 memset(&res, 0, sizeof(res));
2809 memset(&mappings, 0, sizeof(mappings));
2810 memset(&ndbr_desc, 0, sizeof(ndbr_desc));
2811 res.start = spa->address;
2812 res.end = res.start + spa->length - 1;
2813 ndr_desc = &ndbr_desc.ndr_desc;
2814 ndr_desc->res = &res;
2815 ndr_desc->provider_data = nfit_spa;
2816 ndr_desc->attr_groups = acpi_nfit_region_attribute_groups;
2817 if (spa->flags & ACPI_NFIT_PROXIMITY_VALID)
2818 ndr_desc->numa_node = acpi_map_pxm_to_online_node(
2819 spa->proximity_domain);
2821 ndr_desc->numa_node = NUMA_NO_NODE;
2824 * Persistence domain bits are hierarchical, if
2825 * ACPI_NFIT_CAPABILITY_CACHE_FLUSH is set then
2826 * ACPI_NFIT_CAPABILITY_MEM_FLUSH is implied.
2828 if (acpi_desc->platform_cap & ACPI_NFIT_CAPABILITY_CACHE_FLUSH)
2829 set_bit(ND_REGION_PERSIST_CACHE, &ndr_desc->flags);
2830 else if (acpi_desc->platform_cap & ACPI_NFIT_CAPABILITY_MEM_FLUSH)
2831 set_bit(ND_REGION_PERSIST_MEMCTRL, &ndr_desc->flags);
2833 list_for_each_entry(nfit_memdev, &acpi_desc->memdevs, list) {
2834 struct acpi_nfit_memory_map *memdev = nfit_memdev->memdev;
2835 struct nd_mapping_desc *mapping;
2837 /* range index 0 == unmapped in SPA or invalid-SPA */
2838 if (memdev->range_index == 0 || spa->range_index == 0)
2840 if (memdev->range_index != spa->range_index)
2842 if (count >= ND_MAX_MAPPINGS) {
2843 dev_err(acpi_desc->dev, "spa%d exceeds max mappings %d\n",
2844 spa->range_index, ND_MAX_MAPPINGS);
2847 mapping = &mappings[count++];
2848 rc = acpi_nfit_init_mapping(acpi_desc, mapping, ndr_desc,
2854 ndr_desc->mapping = mappings;
2855 ndr_desc->num_mappings = count;
2856 rc = acpi_nfit_init_interleave_set(acpi_desc, ndr_desc, spa);
2860 nvdimm_bus = acpi_desc->nvdimm_bus;
2861 if (nfit_spa_type(spa) == NFIT_SPA_PM) {
2862 rc = acpi_nfit_insert_resource(acpi_desc, ndr_desc);
2864 dev_warn(acpi_desc->dev,
2865 "failed to insert pmem resource to iomem: %d\n",
2870 nfit_spa->nd_region = nvdimm_pmem_region_create(nvdimm_bus,
2872 if (!nfit_spa->nd_region)
2874 } else if (nfit_spa_is_volatile(spa)) {
2875 nfit_spa->nd_region = nvdimm_volatile_region_create(nvdimm_bus,
2877 if (!nfit_spa->nd_region)
2879 } else if (nfit_spa_is_virtual(spa)) {
2880 nfit_spa->nd_region = nvdimm_pmem_region_create(nvdimm_bus,
2882 if (!nfit_spa->nd_region)
2888 dev_err(acpi_desc->dev, "failed to register spa range %d\n",
2889 nfit_spa->spa->range_index);
2893 static int ars_status_alloc(struct acpi_nfit_desc *acpi_desc)
2895 struct device *dev = acpi_desc->dev;
2896 struct nd_cmd_ars_status *ars_status;
2898 if (acpi_desc->ars_status) {
2899 memset(acpi_desc->ars_status, 0, acpi_desc->max_ars);
2903 ars_status = devm_kzalloc(dev, acpi_desc->max_ars, GFP_KERNEL);
2906 acpi_desc->ars_status = ars_status;
2910 static int acpi_nfit_query_poison(struct acpi_nfit_desc *acpi_desc)
2914 if (ars_status_alloc(acpi_desc))
2917 rc = ars_get_status(acpi_desc);
2919 if (rc < 0 && rc != -ENOSPC)
2922 if (ars_status_process_records(acpi_desc))
2923 dev_err(acpi_desc->dev, "Failed to process ARS records\n");
2928 static int ars_register(struct acpi_nfit_desc *acpi_desc,
2929 struct nfit_spa *nfit_spa)
2933 if (test_bit(ARS_FAILED, &nfit_spa->ars_state))
2934 return acpi_nfit_register_region(acpi_desc, nfit_spa);
2936 set_bit(ARS_REQ_SHORT, &nfit_spa->ars_state);
2938 set_bit(ARS_REQ_LONG, &nfit_spa->ars_state);
2940 switch (acpi_nfit_query_poison(acpi_desc)) {
2944 rc = ars_start(acpi_desc, nfit_spa, ARS_REQ_SHORT);
2945 /* shouldn't happen, try again later */
2949 set_bit(ARS_FAILED, &nfit_spa->ars_state);
2952 clear_bit(ARS_REQ_SHORT, &nfit_spa->ars_state);
2953 rc = acpi_nfit_query_poison(acpi_desc);
2956 acpi_desc->scrub_spa = nfit_spa;
2957 ars_complete(acpi_desc, nfit_spa);
2959 * If ars_complete() says we didn't complete the
2960 * short scrub, we'll try again with a long
2963 acpi_desc->scrub_spa = NULL;
2968 * BIOS was using ARS, wait for it to complete (or
2969 * resources to become available) and then perform our
2974 set_bit(ARS_FAILED, &nfit_spa->ars_state);
2978 return acpi_nfit_register_region(acpi_desc, nfit_spa);
2981 static void ars_complete_all(struct acpi_nfit_desc *acpi_desc)
2983 struct nfit_spa *nfit_spa;
2985 list_for_each_entry(nfit_spa, &acpi_desc->spas, list) {
2986 if (test_bit(ARS_FAILED, &nfit_spa->ars_state))
2988 ars_complete(acpi_desc, nfit_spa);
2992 static unsigned int __acpi_nfit_scrub(struct acpi_nfit_desc *acpi_desc,
2995 unsigned int tmo = acpi_desc->scrub_tmo;
2996 struct device *dev = acpi_desc->dev;
2997 struct nfit_spa *nfit_spa;
2999 lockdep_assert_held(&acpi_desc->init_mutex);
3001 if (test_bit(ARS_CANCEL, &acpi_desc->scrub_flags))
3004 if (query_rc == -EBUSY) {
3005 dev_dbg(dev, "ARS: ARS busy\n");
3006 return min(30U * 60U, tmo * 2);
3008 if (query_rc == -ENOSPC) {
3009 dev_dbg(dev, "ARS: ARS continue\n");
3010 ars_continue(acpi_desc);
3013 if (query_rc && query_rc != -EAGAIN) {
3014 unsigned long long addr, end;
3016 addr = acpi_desc->ars_status->address;
3017 end = addr + acpi_desc->ars_status->length;
3018 dev_dbg(dev, "ARS: %llx-%llx failed (%d)\n", addr, end,
3022 ars_complete_all(acpi_desc);
3023 list_for_each_entry(nfit_spa, &acpi_desc->spas, list) {
3024 enum nfit_ars_state req_type;
3027 if (test_bit(ARS_FAILED, &nfit_spa->ars_state))
3030 /* prefer short ARS requests first */
3031 if (test_bit(ARS_REQ_SHORT, &nfit_spa->ars_state))
3032 req_type = ARS_REQ_SHORT;
3033 else if (test_bit(ARS_REQ_LONG, &nfit_spa->ars_state))
3034 req_type = ARS_REQ_LONG;
3037 rc = ars_start(acpi_desc, nfit_spa, req_type);
3039 dev = nd_region_dev(nfit_spa->nd_region);
3040 dev_dbg(dev, "ARS: range %d ARS start %s (%d)\n",
3041 nfit_spa->spa->range_index,
3042 req_type == ARS_REQ_SHORT ? "short" : "long",
3045 * Hmm, we raced someone else starting ARS? Try again in
3051 dev_WARN_ONCE(dev, acpi_desc->scrub_spa,
3052 "scrub start while range %d active\n",
3053 acpi_desc->scrub_spa->spa->range_index);
3054 clear_bit(req_type, &nfit_spa->ars_state);
3055 acpi_desc->scrub_spa = nfit_spa;
3057 * Consider this spa last for future scrub
3060 list_move_tail(&nfit_spa->list, &acpi_desc->spas);
3064 dev_err(dev, "ARS: range %d ARS failed (%d)\n",
3065 nfit_spa->spa->range_index, rc);
3066 set_bit(ARS_FAILED, &nfit_spa->ars_state);
3071 static void __sched_ars(struct acpi_nfit_desc *acpi_desc, unsigned int tmo)
3073 lockdep_assert_held(&acpi_desc->init_mutex);
3075 set_bit(ARS_BUSY, &acpi_desc->scrub_flags);
3076 /* note this should only be set from within the workqueue */
3078 acpi_desc->scrub_tmo = tmo;
3079 queue_delayed_work(nfit_wq, &acpi_desc->dwork, tmo * HZ);
3082 static void sched_ars(struct acpi_nfit_desc *acpi_desc)
3084 __sched_ars(acpi_desc, 0);
3087 static void notify_ars_done(struct acpi_nfit_desc *acpi_desc)
3089 lockdep_assert_held(&acpi_desc->init_mutex);
3091 clear_bit(ARS_BUSY, &acpi_desc->scrub_flags);
3092 acpi_desc->scrub_count++;
3093 if (acpi_desc->scrub_count_state)
3094 sysfs_notify_dirent(acpi_desc->scrub_count_state);
3097 static void acpi_nfit_scrub(struct work_struct *work)
3099 struct acpi_nfit_desc *acpi_desc;
3103 acpi_desc = container_of(work, typeof(*acpi_desc), dwork.work);
3104 mutex_lock(&acpi_desc->init_mutex);
3105 query_rc = acpi_nfit_query_poison(acpi_desc);
3106 tmo = __acpi_nfit_scrub(acpi_desc, query_rc);
3108 __sched_ars(acpi_desc, tmo);
3110 notify_ars_done(acpi_desc);
3111 memset(acpi_desc->ars_status, 0, acpi_desc->max_ars);
3112 clear_bit(ARS_POLL, &acpi_desc->scrub_flags);
3113 mutex_unlock(&acpi_desc->init_mutex);
3116 static void acpi_nfit_init_ars(struct acpi_nfit_desc *acpi_desc,
3117 struct nfit_spa *nfit_spa)
3119 int type = nfit_spa_type(nfit_spa->spa);
3120 struct nd_cmd_ars_cap ars_cap;
3123 set_bit(ARS_FAILED, &nfit_spa->ars_state);
3124 memset(&ars_cap, 0, sizeof(ars_cap));
3125 rc = ars_get_cap(acpi_desc, &ars_cap, nfit_spa);
3128 /* check that the supported scrub types match the spa type */
3129 if (type == NFIT_SPA_VOLATILE && ((ars_cap.status >> 16)
3130 & ND_ARS_VOLATILE) == 0)
3132 if (type == NFIT_SPA_PM && ((ars_cap.status >> 16)
3133 & ND_ARS_PERSISTENT) == 0)
3136 nfit_spa->max_ars = ars_cap.max_ars_out;
3137 nfit_spa->clear_err_unit = ars_cap.clear_err_unit;
3138 acpi_desc->max_ars = max(nfit_spa->max_ars, acpi_desc->max_ars);
3139 clear_bit(ARS_FAILED, &nfit_spa->ars_state);
3142 static int acpi_nfit_register_regions(struct acpi_nfit_desc *acpi_desc)
3144 struct nfit_spa *nfit_spa;
3147 set_bit(ARS_VALID, &acpi_desc->scrub_flags);
3148 list_for_each_entry(nfit_spa, &acpi_desc->spas, list) {
3149 switch (nfit_spa_type(nfit_spa->spa)) {
3150 case NFIT_SPA_VOLATILE:
3152 acpi_nfit_init_ars(acpi_desc, nfit_spa);
3157 list_for_each_entry(nfit_spa, &acpi_desc->spas, list)
3158 switch (nfit_spa_type(nfit_spa->spa)) {
3159 case NFIT_SPA_VOLATILE:
3161 /* register regions and kick off initial ARS run */
3162 rc = ars_register(acpi_desc, nfit_spa);
3167 /* nothing to register */
3170 case NFIT_SPA_VDISK:
3172 case NFIT_SPA_PDISK:
3174 /* register known regions that don't support ARS */
3175 rc = acpi_nfit_register_region(acpi_desc, nfit_spa);
3180 /* don't register unknown regions */
3184 sched_ars(acpi_desc);
3188 static int acpi_nfit_check_deletions(struct acpi_nfit_desc *acpi_desc,
3189 struct nfit_table_prev *prev)
3191 struct device *dev = acpi_desc->dev;
3193 if (!list_empty(&prev->spas) ||
3194 !list_empty(&prev->memdevs) ||
3195 !list_empty(&prev->dcrs) ||
3196 !list_empty(&prev->bdws) ||
3197 !list_empty(&prev->idts) ||
3198 !list_empty(&prev->flushes)) {
3199 dev_err(dev, "new nfit deletes entries (unsupported)\n");
3205 static int acpi_nfit_desc_init_scrub_attr(struct acpi_nfit_desc *acpi_desc)
3207 struct device *dev = acpi_desc->dev;
3208 struct kernfs_node *nfit;
3209 struct device *bus_dev;
3211 if (!ars_supported(acpi_desc->nvdimm_bus))
3214 bus_dev = to_nvdimm_bus_dev(acpi_desc->nvdimm_bus);
3215 nfit = sysfs_get_dirent(bus_dev->kobj.sd, "nfit");
3217 dev_err(dev, "sysfs_get_dirent 'nfit' failed\n");
3220 acpi_desc->scrub_count_state = sysfs_get_dirent(nfit, "scrub");
3222 if (!acpi_desc->scrub_count_state) {
3223 dev_err(dev, "sysfs_get_dirent 'scrub' failed\n");
3230 static void acpi_nfit_unregister(void *data)
3232 struct acpi_nfit_desc *acpi_desc = data;
3234 nvdimm_bus_unregister(acpi_desc->nvdimm_bus);
3237 int acpi_nfit_init(struct acpi_nfit_desc *acpi_desc, void *data, acpi_size sz)
3239 struct device *dev = acpi_desc->dev;
3240 struct nfit_table_prev prev;
3244 if (!acpi_desc->nvdimm_bus) {
3245 acpi_nfit_init_dsms(acpi_desc);
3247 acpi_desc->nvdimm_bus = nvdimm_bus_register(dev,
3248 &acpi_desc->nd_desc);
3249 if (!acpi_desc->nvdimm_bus)
3252 rc = devm_add_action_or_reset(dev, acpi_nfit_unregister,
3257 rc = acpi_nfit_desc_init_scrub_attr(acpi_desc);
3261 /* register this acpi_desc for mce notifications */
3262 mutex_lock(&acpi_desc_lock);
3263 list_add_tail(&acpi_desc->list, &acpi_descs);
3264 mutex_unlock(&acpi_desc_lock);
3267 mutex_lock(&acpi_desc->init_mutex);
3269 INIT_LIST_HEAD(&prev.spas);
3270 INIT_LIST_HEAD(&prev.memdevs);
3271 INIT_LIST_HEAD(&prev.dcrs);
3272 INIT_LIST_HEAD(&prev.bdws);
3273 INIT_LIST_HEAD(&prev.idts);
3274 INIT_LIST_HEAD(&prev.flushes);
3276 list_cut_position(&prev.spas, &acpi_desc->spas,
3277 acpi_desc->spas.prev);
3278 list_cut_position(&prev.memdevs, &acpi_desc->memdevs,
3279 acpi_desc->memdevs.prev);
3280 list_cut_position(&prev.dcrs, &acpi_desc->dcrs,
3281 acpi_desc->dcrs.prev);
3282 list_cut_position(&prev.bdws, &acpi_desc->bdws,
3283 acpi_desc->bdws.prev);
3284 list_cut_position(&prev.idts, &acpi_desc->idts,
3285 acpi_desc->idts.prev);
3286 list_cut_position(&prev.flushes, &acpi_desc->flushes,
3287 acpi_desc->flushes.prev);
3290 while (!IS_ERR_OR_NULL(data))
3291 data = add_table(acpi_desc, &prev, data, end);
3294 dev_dbg(dev, "nfit table parsing error: %ld\n", PTR_ERR(data));
3299 rc = acpi_nfit_check_deletions(acpi_desc, &prev);
3303 rc = nfit_mem_init(acpi_desc);
3307 rc = acpi_nfit_register_dimms(acpi_desc);
3311 rc = acpi_nfit_register_regions(acpi_desc);
3314 mutex_unlock(&acpi_desc->init_mutex);
3317 EXPORT_SYMBOL_GPL(acpi_nfit_init);
3319 static int acpi_nfit_flush_probe(struct nvdimm_bus_descriptor *nd_desc)
3321 struct acpi_nfit_desc *acpi_desc = to_acpi_nfit_desc(nd_desc);
3322 struct device *dev = acpi_desc->dev;
3324 /* Bounce the device lock to flush acpi_nfit_add / acpi_nfit_notify */
3328 /* Bounce the init_mutex to complete initial registration */
3329 mutex_lock(&acpi_desc->init_mutex);
3330 mutex_unlock(&acpi_desc->init_mutex);
3335 static int acpi_nfit_clear_to_send(struct nvdimm_bus_descriptor *nd_desc,
3336 struct nvdimm *nvdimm, unsigned int cmd)
3338 struct acpi_nfit_desc *acpi_desc = to_acpi_nfit_desc(nd_desc);
3342 if (cmd != ND_CMD_ARS_START)
3346 * The kernel and userspace may race to initiate a scrub, but
3347 * the scrub thread is prepared to lose that initial race. It
3348 * just needs guarantees that any ars it initiates are not
3349 * interrupted by any intervening start reqeusts from userspace.
3351 if (work_busy(&acpi_desc->dwork.work))
3357 int acpi_nfit_ars_rescan(struct acpi_nfit_desc *acpi_desc,
3358 enum nfit_ars_state req_type)
3360 struct device *dev = acpi_desc->dev;
3361 int scheduled = 0, busy = 0;
3362 struct nfit_spa *nfit_spa;
3364 mutex_lock(&acpi_desc->init_mutex);
3365 if (test_bit(ARS_CANCEL, &acpi_desc->scrub_flags)) {
3366 mutex_unlock(&acpi_desc->init_mutex);
3370 list_for_each_entry(nfit_spa, &acpi_desc->spas, list) {
3371 int type = nfit_spa_type(nfit_spa->spa);
3373 if (type != NFIT_SPA_PM && type != NFIT_SPA_VOLATILE)
3375 if (test_bit(ARS_FAILED, &nfit_spa->ars_state))
3378 if (test_and_set_bit(req_type, &nfit_spa->ars_state))
3384 sched_ars(acpi_desc);
3385 dev_dbg(dev, "ars_scan triggered\n");
3387 mutex_unlock(&acpi_desc->init_mutex);
3396 void acpi_nfit_desc_init(struct acpi_nfit_desc *acpi_desc, struct device *dev)
3398 struct nvdimm_bus_descriptor *nd_desc;
3400 dev_set_drvdata(dev, acpi_desc);
3401 acpi_desc->dev = dev;
3402 acpi_desc->blk_do_io = acpi_nfit_blk_region_do_io;
3403 nd_desc = &acpi_desc->nd_desc;
3404 nd_desc->provider_name = "ACPI.NFIT";
3405 nd_desc->module = THIS_MODULE;
3406 nd_desc->ndctl = acpi_nfit_ctl;
3407 nd_desc->flush_probe = acpi_nfit_flush_probe;
3408 nd_desc->clear_to_send = acpi_nfit_clear_to_send;
3409 nd_desc->attr_groups = acpi_nfit_attribute_groups;
3411 INIT_LIST_HEAD(&acpi_desc->spas);
3412 INIT_LIST_HEAD(&acpi_desc->dcrs);
3413 INIT_LIST_HEAD(&acpi_desc->bdws);
3414 INIT_LIST_HEAD(&acpi_desc->idts);
3415 INIT_LIST_HEAD(&acpi_desc->flushes);
3416 INIT_LIST_HEAD(&acpi_desc->memdevs);
3417 INIT_LIST_HEAD(&acpi_desc->dimms);
3418 INIT_LIST_HEAD(&acpi_desc->list);
3419 mutex_init(&acpi_desc->init_mutex);
3420 acpi_desc->scrub_tmo = 1;
3421 INIT_DELAYED_WORK(&acpi_desc->dwork, acpi_nfit_scrub);
3423 EXPORT_SYMBOL_GPL(acpi_nfit_desc_init);
3425 static void acpi_nfit_put_table(void *table)
3427 acpi_put_table(table);
3430 void acpi_nfit_shutdown(void *data)
3432 struct acpi_nfit_desc *acpi_desc = data;
3433 struct device *bus_dev = to_nvdimm_bus_dev(acpi_desc->nvdimm_bus);
3436 * Destruct under acpi_desc_lock so that nfit_handle_mce does not
3439 mutex_lock(&acpi_desc_lock);
3440 list_del(&acpi_desc->list);
3441 mutex_unlock(&acpi_desc_lock);
3443 mutex_lock(&acpi_desc->init_mutex);
3444 set_bit(ARS_CANCEL, &acpi_desc->scrub_flags);
3445 cancel_delayed_work_sync(&acpi_desc->dwork);
3446 mutex_unlock(&acpi_desc->init_mutex);
3449 * Bounce the nvdimm bus lock to make sure any in-flight
3450 * acpi_nfit_ars_rescan() submissions have had a chance to
3451 * either submit or see ->cancel set.
3453 device_lock(bus_dev);
3454 device_unlock(bus_dev);
3456 flush_workqueue(nfit_wq);
3458 EXPORT_SYMBOL_GPL(acpi_nfit_shutdown);
3460 static int acpi_nfit_add(struct acpi_device *adev)
3462 struct acpi_buffer buf = { ACPI_ALLOCATE_BUFFER, NULL };
3463 struct acpi_nfit_desc *acpi_desc;
3464 struct device *dev = &adev->dev;
3465 struct acpi_table_header *tbl;
3466 acpi_status status = AE_OK;
3470 status = acpi_get_table(ACPI_SIG_NFIT, 0, &tbl);
3471 if (ACPI_FAILURE(status)) {
3472 /* This is ok, we could have an nvdimm hotplugged later */
3473 dev_dbg(dev, "failed to find NFIT at startup\n");
3477 rc = devm_add_action_or_reset(dev, acpi_nfit_put_table, tbl);
3482 acpi_desc = devm_kzalloc(dev, sizeof(*acpi_desc), GFP_KERNEL);
3485 acpi_nfit_desc_init(acpi_desc, &adev->dev);
3487 /* Save the acpi header for exporting the revision via sysfs */
3488 acpi_desc->acpi_header = *tbl;
3490 /* Evaluate _FIT and override with that if present */
3491 status = acpi_evaluate_object(adev->handle, "_FIT", NULL, &buf);
3492 if (ACPI_SUCCESS(status) && buf.length > 0) {
3493 union acpi_object *obj = buf.pointer;
3495 if (obj->type == ACPI_TYPE_BUFFER)
3496 rc = acpi_nfit_init(acpi_desc, obj->buffer.pointer,
3497 obj->buffer.length);
3499 dev_dbg(dev, "invalid type %d, ignoring _FIT\n",
3503 /* skip over the lead-in header table */
3504 rc = acpi_nfit_init(acpi_desc, (void *) tbl
3505 + sizeof(struct acpi_table_nfit),
3506 sz - sizeof(struct acpi_table_nfit));
3510 return devm_add_action_or_reset(dev, acpi_nfit_shutdown, acpi_desc);
3513 static int acpi_nfit_remove(struct acpi_device *adev)
3515 /* see acpi_nfit_unregister */
3519 static void acpi_nfit_update_notify(struct device *dev, acpi_handle handle)
3521 struct acpi_nfit_desc *acpi_desc = dev_get_drvdata(dev);
3522 struct acpi_buffer buf = { ACPI_ALLOCATE_BUFFER, NULL };
3523 union acpi_object *obj;
3528 /* dev->driver may be null if we're being removed */
3529 dev_dbg(dev, "no driver found for dev\n");
3534 acpi_desc = devm_kzalloc(dev, sizeof(*acpi_desc), GFP_KERNEL);
3537 acpi_nfit_desc_init(acpi_desc, dev);
3540 * Finish previous registration before considering new
3543 flush_workqueue(nfit_wq);
3547 status = acpi_evaluate_object(handle, "_FIT", NULL, &buf);
3548 if (ACPI_FAILURE(status)) {
3549 dev_err(dev, "failed to evaluate _FIT\n");
3554 if (obj->type == ACPI_TYPE_BUFFER) {
3555 ret = acpi_nfit_init(acpi_desc, obj->buffer.pointer,
3556 obj->buffer.length);
3558 dev_err(dev, "failed to merge updated NFIT\n");
3560 dev_err(dev, "Invalid _FIT\n");
3564 static void acpi_nfit_uc_error_notify(struct device *dev, acpi_handle handle)
3566 struct acpi_nfit_desc *acpi_desc = dev_get_drvdata(dev);
3568 if (acpi_desc->scrub_mode == HW_ERROR_SCRUB_ON)
3569 acpi_nfit_ars_rescan(acpi_desc, ARS_REQ_LONG);
3571 acpi_nfit_ars_rescan(acpi_desc, ARS_REQ_SHORT);
3574 void __acpi_nfit_notify(struct device *dev, acpi_handle handle, u32 event)
3576 dev_dbg(dev, "event: 0x%x\n", event);
3579 case NFIT_NOTIFY_UPDATE:
3580 return acpi_nfit_update_notify(dev, handle);
3581 case NFIT_NOTIFY_UC_MEMORY_ERROR:
3582 return acpi_nfit_uc_error_notify(dev, handle);
3587 EXPORT_SYMBOL_GPL(__acpi_nfit_notify);
3589 static void acpi_nfit_notify(struct acpi_device *adev, u32 event)
3591 device_lock(&adev->dev);
3592 __acpi_nfit_notify(&adev->dev, adev->handle, event);
3593 device_unlock(&adev->dev);
3596 static const struct acpi_device_id acpi_nfit_ids[] = {
3600 MODULE_DEVICE_TABLE(acpi, acpi_nfit_ids);
3602 static struct acpi_driver acpi_nfit_driver = {
3603 .name = KBUILD_MODNAME,
3604 .ids = acpi_nfit_ids,
3606 .add = acpi_nfit_add,
3607 .remove = acpi_nfit_remove,
3608 .notify = acpi_nfit_notify,
3612 static __init int nfit_init(void)
3616 BUILD_BUG_ON(sizeof(struct acpi_table_nfit) != 40);
3617 BUILD_BUG_ON(sizeof(struct acpi_nfit_system_address) != 56);
3618 BUILD_BUG_ON(sizeof(struct acpi_nfit_memory_map) != 48);
3619 BUILD_BUG_ON(sizeof(struct acpi_nfit_interleave) != 20);
3620 BUILD_BUG_ON(sizeof(struct acpi_nfit_smbios) != 9);
3621 BUILD_BUG_ON(sizeof(struct acpi_nfit_control_region) != 80);
3622 BUILD_BUG_ON(sizeof(struct acpi_nfit_data_region) != 40);
3623 BUILD_BUG_ON(sizeof(struct acpi_nfit_capabilities) != 16);
3625 guid_parse(UUID_VOLATILE_MEMORY, &nfit_uuid[NFIT_SPA_VOLATILE]);
3626 guid_parse(UUID_PERSISTENT_MEMORY, &nfit_uuid[NFIT_SPA_PM]);
3627 guid_parse(UUID_CONTROL_REGION, &nfit_uuid[NFIT_SPA_DCR]);
3628 guid_parse(UUID_DATA_REGION, &nfit_uuid[NFIT_SPA_BDW]);
3629 guid_parse(UUID_VOLATILE_VIRTUAL_DISK, &nfit_uuid[NFIT_SPA_VDISK]);
3630 guid_parse(UUID_VOLATILE_VIRTUAL_CD, &nfit_uuid[NFIT_SPA_VCD]);
3631 guid_parse(UUID_PERSISTENT_VIRTUAL_DISK, &nfit_uuid[NFIT_SPA_PDISK]);
3632 guid_parse(UUID_PERSISTENT_VIRTUAL_CD, &nfit_uuid[NFIT_SPA_PCD]);
3633 guid_parse(UUID_NFIT_BUS, &nfit_uuid[NFIT_DEV_BUS]);
3634 guid_parse(UUID_NFIT_DIMM, &nfit_uuid[NFIT_DEV_DIMM]);
3635 guid_parse(UUID_NFIT_DIMM_N_HPE1, &nfit_uuid[NFIT_DEV_DIMM_N_HPE1]);
3636 guid_parse(UUID_NFIT_DIMM_N_HPE2, &nfit_uuid[NFIT_DEV_DIMM_N_HPE2]);
3637 guid_parse(UUID_NFIT_DIMM_N_MSFT, &nfit_uuid[NFIT_DEV_DIMM_N_MSFT]);
3638 guid_parse(UUID_NFIT_DIMM_N_HYPERV, &nfit_uuid[NFIT_DEV_DIMM_N_HYPERV]);
3640 nfit_wq = create_singlethread_workqueue("nfit");
3644 nfit_mce_register();
3645 ret = acpi_bus_register_driver(&acpi_nfit_driver);
3647 nfit_mce_unregister();
3648 destroy_workqueue(nfit_wq);
3655 static __exit void nfit_exit(void)
3657 nfit_mce_unregister();
3658 acpi_bus_unregister_driver(&acpi_nfit_driver);
3659 destroy_workqueue(nfit_wq);
3660 WARN_ON(!list_empty(&acpi_descs));
3663 module_init(nfit_init);
3664 module_exit(nfit_exit);
3665 MODULE_LICENSE("GPL v2");
3666 MODULE_AUTHOR("Intel Corporation");