Lines Matching +full:force +full:- +full:m1

1 // SPDX-License-Identifier: GPL-2.0-only
3 * Copyright(c) 2013-2015 Intel Corporation. All rights reserved.
24 * For readq() and writeq() on 32-bit builds, the hi-lo, lo-hi order is
27 #include <linux/io-64-nonatomic-hi-lo.h>
42 static int default_dsm_family = -1;
53 MODULE_PARM_DESC(force_labels, "Opt-in to labels despite missing methods");
91 struct nvdimm_bus_descriptor *nd_desc = &acpi_desc->nd_desc; in to_acpi_dev()
97 if (!nd_desc->provider_name in to_acpi_dev()
98 || strcmp(nd_desc->provider_name, "ACPI.NFIT") != 0) in to_acpi_dev()
101 return to_acpi_device(acpi_desc->dev); in to_acpi_dev()
113 return -ENOTTY; in xlat_bus_status()
117 return -EIO; in xlat_bus_status()
122 return -ENOTTY; in xlat_bus_status()
127 return -EBUSY; in xlat_bus_status()
131 return -EIO; in xlat_bus_status()
137 return -EIO; in xlat_bus_status()
144 return -EBUSY; in xlat_bus_status()
148 return -EAGAIN; in xlat_bus_status()
156 if (ars_status->out_length >= 40 && (ars_status->flags in xlat_bus_status()
158 return -ENOSPC; in xlat_bus_status()
164 return -EIO; in xlat_bus_status()
169 return -EIO; in xlat_bus_status()
170 if (!clear_err->cleared) in xlat_bus_status()
171 return -EIO; in xlat_bus_status()
172 if (clear_err->length > clear_err->cleared) in xlat_bus_status()
173 return clear_err->cleared; in xlat_bus_status()
179 /* all other non-zero status results in an error */ in xlat_bus_status()
181 return -EIO; in xlat_bus_status()
198 if (test_bit(NFIT_MEM_LSR, &nfit_mem->flags)) in xlat_nvdimm_status()
202 return -EACCES; in xlat_nvdimm_status()
205 if (test_bit(NFIT_MEM_LSR, &nfit_mem->flags) in xlat_nvdimm_status()
207 return -EACCES; in xlat_nvdimm_status()
210 if (test_bit(NFIT_MEM_LSW, &nfit_mem->flags) in xlat_nvdimm_status()
212 return -EACCES; in xlat_nvdimm_status()
218 /* all other non-zero status results in an error */ in xlat_nvdimm_status()
220 return -EIO; in xlat_nvdimm_status()
240 if (pkg->type != ACPI_TYPE_PACKAGE) { in pkg_to_buf()
242 pkg->type); in pkg_to_buf()
246 for (i = 0; i < pkg->package.count; i++) { in pkg_to_buf()
247 union acpi_object *obj = &pkg->package.elements[i]; in pkg_to_buf()
249 if (obj->type == ACPI_TYPE_INTEGER) in pkg_to_buf()
251 else if (obj->type == ACPI_TYPE_BUFFER) in pkg_to_buf()
252 size += obj->buffer.length; in pkg_to_buf()
255 obj->type); in pkg_to_buf()
265 buf->type = ACPI_TYPE_BUFFER; in pkg_to_buf()
266 buf->buffer.length = size; in pkg_to_buf()
267 buf->buffer.pointer = dst; in pkg_to_buf()
268 for (i = 0; i < pkg->package.count; i++) { in pkg_to_buf()
269 union acpi_object *obj = &pkg->package.elements[i]; in pkg_to_buf()
271 if (obj->type == ACPI_TYPE_INTEGER) { in pkg_to_buf()
272 memcpy(dst, &obj->integer.value, 4); in pkg_to_buf()
274 } else if (obj->type == ACPI_TYPE_BUFFER) { in pkg_to_buf()
275 memcpy(dst, obj->buffer.pointer, obj->buffer.length); in pkg_to_buf()
276 dst += obj->buffer.length; in pkg_to_buf()
289 if (integer->type != ACPI_TYPE_INTEGER) { in int_to_buf()
291 integer->type); in int_to_buf()
300 buf->type = ACPI_TYPE_BUFFER; in int_to_buf()
301 buf->buffer.length = 4; in int_to_buf()
302 buf->buffer.pointer = dst; in int_to_buf()
303 memcpy(dst, &integer->integer.value, 4); in int_to_buf()
399 if (nfit_mem && nfit_mem->family == NVDIMM_FAMILY_INTEL in payload_dumpable()
412 if (nfit_mem && nfit_mem->family != call_pkg->nd_family) in cmd_to_func()
413 return -ENOTTY; in cmd_to_func()
415 for (i = 0; i < ARRAY_SIZE(call_pkg->nd_reserved2); i++) in cmd_to_func()
416 if (call_pkg->nd_reserved2[i]) in cmd_to_func()
417 return -EINVAL; in cmd_to_func()
418 *family = call_pkg->nd_family; in cmd_to_func()
419 return call_pkg->nd_command; in cmd_to_func()
427 if (nfit_mem->family == NVDIMM_FAMILY_INTEL) in cmd_to_func()
431 * Force function number validation to fail since 0 is never in cmd_to_func()
444 struct device *dev = acpi_desc->dev; in acpi_nfit_ctl()
455 *cmd_rc = -EINVAL; in acpi_nfit_ctl()
459 return -EINVAL; in acpi_nfit_ctl()
469 struct acpi_device *adev = nfit_mem->adev; in acpi_nfit_ctl()
472 return -ENOTTY; in acpi_nfit_ctl()
477 dsm_mask = nfit_mem->dsm_mask; in acpi_nfit_ctl()
479 guid = to_nfit_uuid(nfit_mem->family); in acpi_nfit_ctl()
480 handle = adev->handle; in acpi_nfit_ctl()
485 cmd_mask = nd_desc->cmd_mask; in acpi_nfit_ctl()
486 if (cmd == ND_CMD_CALL && call_pkg->nd_family) { in acpi_nfit_ctl()
487 family = call_pkg->nd_family; in acpi_nfit_ctl()
489 !test_bit(family, &nd_desc->bus_family_mask)) in acpi_nfit_ctl()
490 return -EINVAL; in acpi_nfit_ctl()
493 dsm_mask = acpi_desc->family_dsm_mask[family]; in acpi_nfit_ctl()
496 dsm_mask = acpi_desc->bus_dsm_mask; in acpi_nfit_ctl()
500 handle = adev->handle; in acpi_nfit_ctl()
504 if (!desc || (cmd && (desc->out_num + desc->in_num == 0))) in acpi_nfit_ctl()
505 return -ENOTTY; in acpi_nfit_ctl()
513 return -ENOTTY; in acpi_nfit_ctl()
515 return -ENOTTY; in acpi_nfit_ctl()
525 for (i = 0; i < desc->in_num; i++) in acpi_nfit_ctl()
531 in_buf.buffer.pointer = (void *) &call_pkg->nd_payload; in acpi_nfit_ctl()
532 in_buf.buffer.length = call_pkg->nd_size_in; in acpi_nfit_ctl()
544 && test_bit(NFIT_MEM_LSR, &nfit_mem->flags)) in acpi_nfit_ctl()
547 && test_bit(NFIT_MEM_LSR, &nfit_mem->flags)) { in acpi_nfit_ctl()
550 out_obj = acpi_label_read(handle, p->in_offset, p->in_length); in acpi_nfit_ctl()
552 && test_bit(NFIT_MEM_LSW, &nfit_mem->flags)) { in acpi_nfit_ctl()
555 out_obj = acpi_label_write(handle, p->in_offset, p->in_length, in acpi_nfit_ctl()
556 p->in_buf); in acpi_nfit_ctl()
561 revid = nfit_dsm_revid(nfit_mem->family, func); in acpi_nfit_ctl()
569 return -EINVAL; in acpi_nfit_ctl()
572 if (out_obj->type != ACPI_TYPE_BUFFER) { in acpi_nfit_ctl()
574 dimm_name, cmd_name, out_obj->type); in acpi_nfit_ctl()
575 rc = -EINVAL; in acpi_nfit_ctl()
580 cmd_name, out_obj->buffer.length); in acpi_nfit_ctl()
582 out_obj->buffer.pointer, in acpi_nfit_ctl()
583 min_t(u32, 128, out_obj->buffer.length), true); in acpi_nfit_ctl()
586 call_pkg->nd_fw_size = out_obj->buffer.length; in acpi_nfit_ctl()
587 memcpy(call_pkg->nd_payload + call_pkg->nd_size_in, in acpi_nfit_ctl()
588 out_obj->buffer.pointer, in acpi_nfit_ctl()
589 min(call_pkg->nd_fw_size, call_pkg->nd_size_out)); in acpi_nfit_ctl()
603 for (i = 0, offset = 0; i < desc->out_num; i++) { in acpi_nfit_ctl()
605 (u32 *) out_obj->buffer.pointer, in acpi_nfit_ctl()
606 out_obj->buffer.length - offset); in acpi_nfit_ctl()
608 if (offset + out_size > out_obj->buffer.length) { in acpi_nfit_ctl()
617 rc = -ENXIO; in acpi_nfit_ctl()
621 out_obj->buffer.pointer + offset, out_size); in acpi_nfit_ctl()
633 fw_status = *(u32 *) out_obj->buffer.pointer; in acpi_nfit_ctl()
641 rc = buf_len - offset - in_buf.buffer.length; in acpi_nfit_ctl()
649 rc = -ENXIO; in acpi_nfit_ctl()
669 [NFIT_SPA_DCR] = "dimm-control-region", in spa_type_name()
670 [NFIT_SPA_BDW] = "block-data-window", in spa_type_name()
671 [NFIT_SPA_VDISK] = "volatile-disk", in spa_type_name()
672 [NFIT_SPA_VCD] = "volatile-cd", in spa_type_name()
673 [NFIT_SPA_PDISK] = "persistent-disk", in spa_type_name()
674 [NFIT_SPA_PCD] = "persistent-cd", in spa_type_name()
689 import_guid(&guid, spa->range_guid); in nfit_spa_type()
693 return -1; in nfit_spa_type()
698 if (spa->flags & ACPI_NFIT_LOCATION_COOKIE_VALID) in sizeof_spa()
700 return sizeof(*spa) - 8; in sizeof_spa()
707 struct device *dev = acpi_desc->dev; in add_spa()
710 if (spa->header.length != sizeof_spa(spa)) in add_spa()
713 list_for_each_entry(nfit_spa, &prev->spas, list) { in add_spa()
714 if (memcmp(nfit_spa->spa, spa, sizeof_spa(spa)) == 0) { in add_spa()
715 list_move_tail(&nfit_spa->list, &acpi_desc->spas); in add_spa()
724 INIT_LIST_HEAD(&nfit_spa->list); in add_spa()
725 memcpy(nfit_spa->spa, spa, sizeof_spa(spa)); in add_spa()
726 list_add_tail(&nfit_spa->list, &acpi_desc->spas); in add_spa()
728 spa->range_index, in add_spa()
737 struct device *dev = acpi_desc->dev; in add_memdev()
740 if (memdev->header.length != sizeof(*memdev)) in add_memdev()
743 list_for_each_entry(nfit_memdev, &prev->memdevs, list) in add_memdev()
744 if (memcmp(nfit_memdev->memdev, memdev, sizeof(*memdev)) == 0) { in add_memdev()
745 list_move_tail(&nfit_memdev->list, &acpi_desc->memdevs); in add_memdev()
753 INIT_LIST_HEAD(&nfit_memdev->list); in add_memdev()
754 memcpy(nfit_memdev->memdev, memdev, sizeof(*memdev)); in add_memdev()
755 list_add_tail(&nfit_memdev->list, &acpi_desc->memdevs); in add_memdev()
757 memdev->device_handle, memdev->range_index, in add_memdev()
758 memdev->region_index, memdev->flags); in add_memdev()
771 mutex_lock(&acpi_desc->init_mutex); in nfit_get_smbios_id()
772 list_for_each_entry(nfit_mem, &acpi_desc->dimms, list) { in nfit_get_smbios_id()
774 if (memdev->device_handle == device_handle) { in nfit_get_smbios_id()
775 *flags = memdev->flags; in nfit_get_smbios_id()
776 physical_id = memdev->physical_id; in nfit_get_smbios_id()
777 mutex_unlock(&acpi_desc->init_mutex); in nfit_get_smbios_id()
782 mutex_unlock(&acpi_desc->init_mutex); in nfit_get_smbios_id()
786 return -ENODEV; in nfit_get_smbios_id()
796 if (dcr->header.length < offsetof(struct acpi_nfit_control_region, in sizeof_dcr()
799 if (dcr->windows) in sizeof_dcr()
808 struct device *dev = acpi_desc->dev; in add_dcr()
814 list_for_each_entry(nfit_dcr, &prev->dcrs, list) in add_dcr()
815 if (memcmp(nfit_dcr->dcr, dcr, sizeof_dcr(dcr)) == 0) { in add_dcr()
816 list_move_tail(&nfit_dcr->list, &acpi_desc->dcrs); in add_dcr()
824 INIT_LIST_HEAD(&nfit_dcr->list); in add_dcr()
825 memcpy(nfit_dcr->dcr, dcr, sizeof_dcr(dcr)); in add_dcr()
826 list_add_tail(&nfit_dcr->list, &acpi_desc->dcrs); in add_dcr()
828 dcr->region_index, dcr->windows); in add_dcr()
836 struct device *dev = acpi_desc->dev; in add_bdw()
839 if (bdw->header.length != sizeof(*bdw)) in add_bdw()
841 list_for_each_entry(nfit_bdw, &prev->bdws, list) in add_bdw()
842 if (memcmp(nfit_bdw->bdw, bdw, sizeof(*bdw)) == 0) { in add_bdw()
843 list_move_tail(&nfit_bdw->list, &acpi_desc->bdws); in add_bdw()
851 INIT_LIST_HEAD(&nfit_bdw->list); in add_bdw()
852 memcpy(nfit_bdw->bdw, bdw, sizeof(*bdw)); in add_bdw()
853 list_add_tail(&nfit_bdw->list, &acpi_desc->bdws); in add_bdw()
855 bdw->region_index, bdw->windows); in add_bdw()
861 if (idt->header.length < sizeof(*idt)) in sizeof_idt()
863 return sizeof(*idt) + sizeof(u32) * idt->line_count; in sizeof_idt()
870 struct device *dev = acpi_desc->dev; in add_idt()
876 list_for_each_entry(nfit_idt, &prev->idts, list) { in add_idt()
877 if (sizeof_idt(nfit_idt->idt) != sizeof_idt(idt)) in add_idt()
880 if (memcmp(nfit_idt->idt, idt, sizeof_idt(idt)) == 0) { in add_idt()
881 list_move_tail(&nfit_idt->list, &acpi_desc->idts); in add_idt()
890 INIT_LIST_HEAD(&nfit_idt->list); in add_idt()
891 memcpy(nfit_idt->idt, idt, sizeof_idt(idt)); in add_idt()
892 list_add_tail(&nfit_idt->list, &acpi_desc->idts); in add_idt()
894 idt->interleave_index, idt->line_count); in add_idt()
900 if (flush->header.length < sizeof(*flush)) in sizeof_flush()
902 return struct_size(flush, hint_address, flush->hint_count); in sizeof_flush()
909 struct device *dev = acpi_desc->dev; in add_flush()
915 list_for_each_entry(nfit_flush, &prev->flushes, list) { in add_flush()
916 if (sizeof_flush(nfit_flush->flush) != sizeof_flush(flush)) in add_flush()
919 if (memcmp(nfit_flush->flush, flush, in add_flush()
921 list_move_tail(&nfit_flush->list, &acpi_desc->flushes); in add_flush()
930 INIT_LIST_HEAD(&nfit_flush->list); in add_flush()
931 memcpy(nfit_flush->flush, flush, sizeof_flush(flush)); in add_flush()
932 list_add_tail(&nfit_flush->list, &acpi_desc->flushes); in add_flush()
934 flush->device_handle, flush->hint_count); in add_flush()
941 struct device *dev = acpi_desc->dev; in add_platform_cap()
944 mask = (1 << (pcap->highest_capability + 1)) - 1; in add_platform_cap()
945 acpi_desc->platform_cap = pcap->capabilities & mask; in add_platform_cap()
946 dev_dbg(dev, "cap: %#x\n", acpi_desc->platform_cap); in add_platform_cap()
953 struct device *dev = acpi_desc->dev; in add_table()
955 void *err = ERR_PTR(-ENOMEM); in add_table()
961 if (!hdr->length) { in add_table()
963 hdr->type); in add_table()
967 switch (hdr->type) { in add_table()
1000 dev_err(dev, "unknown table '%d' parsing nfit\n", hdr->type); in add_table()
1004 return table + hdr->length; in add_table()
1030 list_for_each_entry(nfit_memdev, &acpi_desc->memdevs, list) { in __nfit_mem_init()
1036 if (spa && nfit_memdev->memdev->range_index != spa->range_index) in __nfit_mem_init()
1038 if (!spa && nfit_memdev->memdev->range_index) in __nfit_mem_init()
1041 dcr = nfit_memdev->memdev->region_index; in __nfit_mem_init()
1042 device_handle = nfit_memdev->memdev->device_handle; in __nfit_mem_init()
1043 list_for_each_entry(nfit_mem, &acpi_desc->dimms, list) in __nfit_mem_init()
1044 if (__to_nfit_memdev(nfit_mem)->device_handle in __nfit_mem_init()
1053 nfit_mem = devm_kzalloc(acpi_desc->dev, in __nfit_mem_init()
1056 return -ENOMEM; in __nfit_mem_init()
1057 INIT_LIST_HEAD(&nfit_mem->list); in __nfit_mem_init()
1058 nfit_mem->acpi_desc = acpi_desc; in __nfit_mem_init()
1059 list_add(&nfit_mem->list, &acpi_desc->dimms); in __nfit_mem_init()
1062 list_for_each_entry(nfit_dcr, &acpi_desc->dcrs, list) { in __nfit_mem_init()
1063 if (nfit_dcr->dcr->region_index != dcr) in __nfit_mem_init()
1072 if (!nfit_mem->dcr) in __nfit_mem_init()
1073 nfit_mem->dcr = nfit_dcr->dcr; in __nfit_mem_init()
1074 else if (nfit_mem->dcr->windows == 0 in __nfit_mem_init()
1075 && nfit_dcr->dcr->windows) in __nfit_mem_init()
1076 nfit_mem->dcr = nfit_dcr->dcr; in __nfit_mem_init()
1080 list_for_each_entry(nfit_flush, &acpi_desc->flushes, list) { in __nfit_mem_init()
1084 if (nfit_flush->flush->device_handle != device_handle) in __nfit_mem_init()
1086 nfit_mem->nfit_flush = nfit_flush; in __nfit_mem_init()
1087 flush = nfit_flush->flush; in __nfit_mem_init()
1088 nfit_mem->flush_wpq = devm_kcalloc(acpi_desc->dev, in __nfit_mem_init()
1089 flush->hint_count, in __nfit_mem_init()
1092 if (!nfit_mem->flush_wpq) in __nfit_mem_init()
1093 return -ENOMEM; in __nfit_mem_init()
1094 for (i = 0; i < flush->hint_count; i++) { in __nfit_mem_init()
1095 struct resource *res = &nfit_mem->flush_wpq[i]; in __nfit_mem_init()
1097 res->start = flush->hint_address[i]; in __nfit_mem_init()
1098 res->end = res->start + 8 - 1; in __nfit_mem_init()
1103 if (dcr && !nfit_mem->dcr) { in __nfit_mem_init()
1104 dev_err(acpi_desc->dev, "SPA %d missing DCR %d\n", in __nfit_mem_init()
1105 spa->range_index, dcr); in __nfit_mem_init()
1106 return -ENODEV; in __nfit_mem_init()
1114 nfit_mem->spa_dcr = spa; in __nfit_mem_init()
1115 nfit_mem->memdev_dcr = nfit_memdev->memdev; in __nfit_mem_init()
1116 idt_idx = nfit_memdev->memdev->interleave_index; in __nfit_mem_init()
1117 list_for_each_entry(nfit_idt, &acpi_desc->idts, list) { in __nfit_mem_init()
1118 if (nfit_idt->idt->interleave_index != idt_idx) in __nfit_mem_init()
1120 nfit_mem->idt_dcr = nfit_idt->idt; in __nfit_mem_init()
1125 * A single dimm may belong to multiple SPA-PM in __nfit_mem_init()
1127 * any SPA-DCR range. in __nfit_mem_init()
1129 nfit_mem->memdev_pmem = nfit_memdev->memdev; in __nfit_mem_init()
1131 nfit_mem->memdev_dcr = nfit_memdev->memdev; in __nfit_mem_init()
1144 handleA = __to_nfit_memdev(a)->device_handle; in nfit_mem_cmp()
1145 handleB = __to_nfit_memdev(b)->device_handle; in nfit_mem_cmp()
1147 return -1; in nfit_mem_cmp()
1160 * For each SPA-DCR or SPA-PMEM address range find its in nfit_mem_init()
1162 * corresponding DCR. Then, if we're operating on a SPA-DCR, in nfit_mem_init()
1163 * try to find a SPA-BDW and a corresponding BDW that references in nfit_mem_init()
1167 list_for_each_entry(nfit_spa, &acpi_desc->spas, list) { in nfit_mem_init()
1168 rc = __nfit_mem_init(acpi_desc, nfit_spa->spa); in nfit_mem_init()
1182 list_sort(NULL, &acpi_desc->dimms, nfit_mem_cmp); in nfit_mem_init()
1194 return sysfs_emit(buf, "%#lx\n", acpi_desc->bus_dsm_mask); in bus_dsm_mask_show()
1206 return sysfs_emit(buf, "%d\n", acpi_desc->acpi_header.revision); in revision_show()
1217 return sysfs_emit(buf, "%d\n", acpi_desc->scrub_mode); in hw_error_scrub_show()
1245 acpi_desc->scrub_mode = HW_ERROR_SCRUB_ON; in hw_error_scrub_store()
1248 acpi_desc->scrub_mode = HW_ERROR_SCRUB_OFF; in hw_error_scrub_store()
1251 rc = -EINVAL; in hw_error_scrub_store()
1272 ssize_t rc = -ENXIO; in scrub_show()
1283 mutex_lock(&acpi_desc->init_mutex); in scrub_show()
1284 busy = test_bit(ARS_BUSY, &acpi_desc->scrub_flags) in scrub_show()
1285 && !test_bit(ARS_CANCEL, &acpi_desc->scrub_flags); in scrub_show()
1286 rc = sysfs_emit(buf, "%d%s", acpi_desc->scrub_count, busy ? "+\n" : "\n"); in scrub_show()
1289 &acpi_desc->scrub_flags)) { in scrub_show()
1290 acpi_desc->scrub_tmo = 1; in scrub_show()
1291 mod_delayed_work(nfit_wq, &acpi_desc->dwork, HZ); in scrub_show()
1294 mutex_unlock(&acpi_desc->init_mutex); in scrub_show()
1310 return -EINVAL; in scrub_store()
1332 return (nd_desc->cmd_mask & mask) == mask; in ars_supported()
1341 return ars_supported(nvdimm_bus) ? a->mode : 0; in nfit_visible()
1344 return intel_fwa_supported(nvdimm_bus) ? a->mode : 0; in nfit_visible()
1346 return a->mode; in nfit_visible()
1382 return nfit_mem->dcr; in to_nfit_dcr()
1390 return sysfs_emit(buf, "%#x\n", memdev->device_handle); in handle_show()
1399 return sysfs_emit(buf, "%#x\n", memdev->physical_id); in phys_id_show()
1408 return sysfs_emit(buf, "0x%04x\n", be16_to_cpu(dcr->vendor_id)); in vendor_show()
1417 return sysfs_emit(buf, "0x%04x\n", be16_to_cpu(dcr->revision_id)); in rev_id_show()
1426 return sysfs_emit(buf, "0x%04x\n", be16_to_cpu(dcr->device_id)); in device_show()
1435 return sysfs_emit(buf, "0x%04x\n", be16_to_cpu(dcr->subsystem_vendor_id)); in subsystem_vendor_show()
1445 be16_to_cpu(dcr->subsystem_revision_id)); in subsystem_rev_id_show()
1454 return sysfs_emit(buf, "0x%04x\n", be16_to_cpu(dcr->subsystem_device_id)); in subsystem_device_show()
1463 if (nfit_mem->memdev_pmem) in num_nvdimm_formats()
1473 return sysfs_emit(buf, "0x%04x\n", le16_to_cpu(dcr->code)); in format_show()
1481 ssize_t rc = -ENXIO; in format1_show()
1489 acpi_desc = nfit_mem->acpi_desc; in format1_show()
1490 handle = to_nfit_memdev(dev)->device_handle; in format1_show()
1493 mutex_lock(&acpi_desc->init_mutex); in format1_show()
1494 list_for_each_entry(nfit_memdev, &acpi_desc->memdevs, list) { in format1_show()
1495 struct acpi_nfit_memory_map *memdev = nfit_memdev->memdev; in format1_show()
1498 if (memdev->device_handle != handle) in format1_show()
1501 list_for_each_entry(nfit_dcr, &acpi_desc->dcrs, list) { in format1_show()
1502 if (nfit_dcr->dcr->region_index != memdev->region_index) in format1_show()
1504 if (nfit_dcr->dcr->code == dcr->code) in format1_show()
1507 le16_to_cpu(nfit_dcr->dcr->code)); in format1_show()
1510 if (rc != -ENXIO) in format1_show()
1513 mutex_unlock(&acpi_desc->init_mutex); in format1_show()
1532 return sysfs_emit(buf, "0x%08x\n", be32_to_cpu(dcr->serial_number)); in serial_show()
1542 if (nfit_mem->family < 0) in family_show()
1543 return -ENXIO; in family_show()
1544 return sysfs_emit(buf, "%d\n", nfit_mem->family); in family_show()
1554 if (nfit_mem->family < 0) in dsm_mask_show()
1555 return -ENXIO; in dsm_mask_show()
1556 return sysfs_emit(buf, "%#lx\n", nfit_mem->dsm_mask); in dsm_mask_show()
1565 u16 flags = __to_nfit_memdev(nfit_mem)->flags; in flags_show()
1567 if (test_bit(NFIT_MEM_DIRTY, &nfit_mem->flags)) in flags_show()
1587 return sysfs_emit(buf, "%s\n", nfit_mem->id); in id_show()
1597 return sysfs_emit(buf, "%d\n", nfit_mem->dirty_shutdown); in dirty_shutdown_show()
1635 return a->mode; in acpi_nfit_dimm_attr_visible()
1642 if (!test_bit(NFIT_MEM_DIRTY_COUNT, &nfit_mem->flags) in acpi_nfit_dimm_attr_visible()
1646 return a->mode; in acpi_nfit_dimm_attr_visible()
1665 list_for_each_entry(nfit_mem, &acpi_desc->dimms, list) in acpi_nfit_dimm_by_handle()
1666 if (__to_nfit_memdev(nfit_mem)->device_handle == device_handle) in acpi_nfit_dimm_by_handle()
1667 return nfit_mem->nvdimm; in acpi_nfit_dimm_by_handle()
1677 dev_dbg(dev->parent, "%s: event: %d\n", dev_name(dev), in __acpi_nvdimm_notify()
1681 dev_dbg(dev->parent, "%s: unknown event: %d\n", dev_name(dev), in __acpi_nvdimm_notify()
1686 acpi_desc = dev_get_drvdata(dev->parent); in __acpi_nvdimm_notify()
1695 if (nfit_mem && nfit_mem->flags_attr) in __acpi_nvdimm_notify()
1696 sysfs_notify_dirent(nfit_mem->flags_attr); in __acpi_nvdimm_notify()
1703 struct device *dev = &adev->dev; in acpi_nvdimm_notify()
1705 device_lock(dev->parent); in acpi_nvdimm_notify()
1707 device_unlock(dev->parent); in acpi_nvdimm_notify()
1715 status = acpi_get_handle(adev->handle, method, &handle); in acpi_nvdimm_has_method()
1724 struct device *dev = &nfit_mem->adev->dev; in nfit_intel_shutdown_status()
1736 const guid_t *guid = to_nfit_uuid(nfit_mem->family); in nfit_intel_shutdown_status()
1737 u8 revid = nfit_dsm_revid(nfit_mem->family, func); in nfit_intel_shutdown_status()
1738 struct acpi_device *adev = nfit_mem->adev; in nfit_intel_shutdown_status()
1739 acpi_handle handle = adev->handle; in nfit_intel_shutdown_status()
1742 if ((nfit_mem->dsm_mask & (1 << func)) == 0) in nfit_intel_shutdown_status()
1746 if (!out_obj || out_obj->buffer.length < sizeof(smart)) { in nfit_intel_shutdown_status()
1747 dev_dbg(dev->parent, "%s: failed to retrieve initial health\n", in nfit_intel_shutdown_status()
1752 memcpy(&smart, out_obj->buffer.pointer, sizeof(smart)); in nfit_intel_shutdown_status()
1757 set_bit(NFIT_MEM_DIRTY, &nfit_mem->flags); in nfit_intel_shutdown_status()
1761 set_bit(NFIT_MEM_DIRTY_COUNT, &nfit_mem->flags); in nfit_intel_shutdown_status()
1762 nfit_mem->dirty_shutdown = smart.shutdown_count; in nfit_intel_shutdown_status()
1770 * dirty-shutdown status and/or a dirty-shutdown count, cache in populate_shutdown_status()
1773 if (nfit_mem->family == NVDIMM_FAMILY_INTEL) in populate_shutdown_status()
1780 struct nvdimm_bus_descriptor *nd_desc = &acpi_desc->nd_desc; in acpi_nfit_add_dimm()
1782 struct device *dev = acpi_desc->dev; in acpi_nfit_add_dimm()
1786 int family = -1; in acpi_nfit_add_dimm()
1787 struct acpi_nfit_control_region *dcr = nfit_mem->dcr; in acpi_nfit_add_dimm()
1790 nfit_mem->dsm_mask = acpi_desc->dimm_cmd_force_en; in acpi_nfit_add_dimm()
1791 nfit_mem->family = NVDIMM_FAMILY_INTEL; in acpi_nfit_add_dimm()
1792 set_bit(NVDIMM_FAMILY_INTEL, &nd_desc->dimm_family_mask); in acpi_nfit_add_dimm()
1794 if (dcr->valid_fields & ACPI_NFIT_CONTROL_MFG_INFO_VALID) in acpi_nfit_add_dimm()
1795 sprintf(nfit_mem->id, "%04x-%02x-%04x-%08x", in acpi_nfit_add_dimm()
1796 be16_to_cpu(dcr->vendor_id), in acpi_nfit_add_dimm()
1797 dcr->manufacturing_location, in acpi_nfit_add_dimm()
1798 be16_to_cpu(dcr->manufacturing_date), in acpi_nfit_add_dimm()
1799 be32_to_cpu(dcr->serial_number)); in acpi_nfit_add_dimm()
1801 sprintf(nfit_mem->id, "%04x-%08x", in acpi_nfit_add_dimm()
1802 be16_to_cpu(dcr->vendor_id), in acpi_nfit_add_dimm()
1803 be32_to_cpu(dcr->serial_number)); in acpi_nfit_add_dimm()
1813 nfit_mem->adev = adev_dimm; in acpi_nfit_add_dimm()
1817 return force_enable_dimms ? 0 : -ENODEV; in acpi_nfit_add_dimm()
1820 if (ACPI_FAILURE(acpi_install_notify_handler(adev_dimm->handle, in acpi_nfit_add_dimm()
1823 dev_name(&adev_dimm->dev)); in acpi_nfit_add_dimm()
1824 return -ENXIO; in acpi_nfit_add_dimm()
1830 dev_set_drvdata(&adev_dimm->dev, nfit_mem); in acpi_nfit_add_dimm()
1845 clear_bit(NVDIMM_FAMILY_INTEL, &nd_desc->dimm_family_mask); in acpi_nfit_add_dimm()
1847 if (acpi_check_dsm(adev_dimm->handle, to_nfit_uuid(i), 1, 1)) { in acpi_nfit_add_dimm()
1848 set_bit(i, &nd_desc->dimm_family_mask); in acpi_nfit_add_dimm()
1854 nfit_mem->family = family; in acpi_nfit_add_dimm()
1857 else if (nfit_mem->family == NVDIMM_FAMILY_INTEL) { in acpi_nfit_add_dimm()
1861 } else if (nfit_mem->family == NVDIMM_FAMILY_HPE1) { in acpi_nfit_add_dimm()
1863 } else if (nfit_mem->family == NVDIMM_FAMILY_HPE2) { in acpi_nfit_add_dimm()
1867 } else if (nfit_mem->family == NVDIMM_FAMILY_MSFT) { in acpi_nfit_add_dimm()
1869 } else if (nfit_mem->family == NVDIMM_FAMILY_HYPERV) { in acpi_nfit_add_dimm()
1873 nfit_mem->family = -1; in acpi_nfit_add_dimm()
1885 guid = to_nfit_uuid(nfit_mem->family); in acpi_nfit_add_dimm()
1887 if (acpi_check_dsm(adev_dimm->handle, guid, in acpi_nfit_add_dimm()
1888 nfit_dsm_revid(nfit_mem->family, i), in acpi_nfit_add_dimm()
1890 set_bit(i, &nfit_mem->dsm_mask); in acpi_nfit_add_dimm()
1904 dev_dbg(dev, "%s: has _LSR\n", dev_name(&adev_dimm->dev)); in acpi_nfit_add_dimm()
1905 set_bit(NFIT_MEM_LSR, &nfit_mem->flags); in acpi_nfit_add_dimm()
1908 if (test_bit(NFIT_MEM_LSR, &nfit_mem->flags) in acpi_nfit_add_dimm()
1910 dev_dbg(dev, "%s: has _LSW\n", dev_name(&adev_dimm->dev)); in acpi_nfit_add_dimm()
1911 set_bit(NFIT_MEM_LSW, &nfit_mem->flags); in acpi_nfit_add_dimm()
1915 * Quirk read-only label configurations to preserve in acpi_nfit_add_dimm()
1916 * access to label-less namespaces by default. in acpi_nfit_add_dimm()
1918 if (!test_bit(NFIT_MEM_LSW, &nfit_mem->flags) in acpi_nfit_add_dimm()
1921 dev_name(&adev_dimm->dev)); in acpi_nfit_add_dimm()
1922 clear_bit(NFIT_MEM_LSR, &nfit_mem->flags); in acpi_nfit_add_dimm()
1924 dev_dbg(dev, "%s: Force enable labels\n", in acpi_nfit_add_dimm()
1925 dev_name(&adev_dimm->dev)); in acpi_nfit_add_dimm()
1938 mutex_lock(&acpi_desc->init_mutex); in shutdown_dimm_notify()
1940 * Clear out the nfit_mem->flags_attr and shut down dimm event in shutdown_dimm_notify()
1943 list_for_each_entry(nfit_mem, &acpi_desc->dimms, list) { in shutdown_dimm_notify()
1944 struct acpi_device *adev_dimm = nfit_mem->adev; in shutdown_dimm_notify()
1946 if (nfit_mem->flags_attr) { in shutdown_dimm_notify()
1947 sysfs_put(nfit_mem->flags_attr); in shutdown_dimm_notify()
1948 nfit_mem->flags_attr = NULL; in shutdown_dimm_notify()
1951 acpi_remove_notify_handler(adev_dimm->handle, in shutdown_dimm_notify()
1953 dev_set_drvdata(&adev_dimm->dev, NULL); in shutdown_dimm_notify()
1956 mutex_unlock(&acpi_desc->init_mutex); in shutdown_dimm_notify()
1973 struct acpi_nfit_desc *acpi_desc = nfit_mem->acpi_desc; in acpi_nfit_get_fw_ops()
1974 struct nvdimm_bus_descriptor *nd_desc = &acpi_desc->nd_desc; in acpi_nfit_get_fw_ops()
1976 if (!nd_desc->fw_ops) in acpi_nfit_get_fw_ops()
1979 if (nfit_mem->family != NVDIMM_FAMILY_INTEL) in acpi_nfit_get_fw_ops()
1982 mask = nfit_mem->dsm_mask & NVDIMM_INTEL_FW_ACTIVATE_CMDMASK; in acpi_nfit_get_fw_ops()
1995 list_for_each_entry(nfit_mem, &acpi_desc->dimms, list) { in acpi_nfit_register_dimms()
2002 device_handle = __to_nfit_memdev(nfit_mem)->device_handle; in acpi_nfit_register_dimms()
2010 list_for_each_entry(nfit_memdev, &acpi_desc->memdevs, list) { in acpi_nfit_register_dimms()
2014 if (dimm_memdev->device_handle in acpi_nfit_register_dimms()
2015 != nfit_memdev->memdev->device_handle) in acpi_nfit_register_dimms()
2017 dimm_memdev->flags |= nfit_memdev->memdev->flags; in acpi_nfit_register_dimms()
2020 mem_flags = __to_nfit_memdev(nfit_mem)->flags; in acpi_nfit_register_dimms()
2029 * TODO: provide translation for non-NVDIMM_FAMILY_INTEL in acpi_nfit_register_dimms()
2034 if (nfit_mem->family == NVDIMM_FAMILY_INTEL) { in acpi_nfit_register_dimms()
2040 cmd_mask |= nfit_mem->dsm_mask & NVDIMM_STANDARD_CMDMASK; in acpi_nfit_register_dimms()
2043 if (test_bit(NFIT_MEM_LSR, &nfit_mem->flags)) { in acpi_nfit_register_dimms()
2047 if (test_bit(NFIT_MEM_LSW, &nfit_mem->flags)) in acpi_nfit_register_dimms()
2050 flush = nfit_mem->nfit_flush ? nfit_mem->nfit_flush->flush in acpi_nfit_register_dimms()
2052 nvdimm = __nvdimm_create(acpi_desc->nvdimm_bus, nfit_mem, in acpi_nfit_register_dimms()
2054 flags, cmd_mask, flush ? flush->hint_count : 0, in acpi_nfit_register_dimms()
2055 nfit_mem->flush_wpq, &nfit_mem->id[0], in acpi_nfit_register_dimms()
2056 acpi_nfit_get_security_ops(nfit_mem->family), in acpi_nfit_register_dimms()
2059 return -ENOMEM; in acpi_nfit_register_dimms()
2061 nfit_mem->nvdimm = nvdimm; in acpi_nfit_register_dimms()
2067 dev_err(acpi_desc->dev, "Error found in NVDIMM %s flags:%s%s%s%s%s\n", in acpi_nfit_register_dimms()
2077 rc = nvdimm_bus_check_dimm_count(acpi_desc->nvdimm_bus, dimm_count); in acpi_nfit_register_dimms()
2085 list_for_each_entry(nfit_mem, &acpi_desc->dimms, list) { in acpi_nfit_register_dimms()
2088 nvdimm = nfit_mem->nvdimm; in acpi_nfit_register_dimms()
2092 nfit_kernfs = sysfs_get_dirent(nvdimm_kobj(nvdimm)->sd, "nfit"); in acpi_nfit_register_dimms()
2094 nfit_mem->flags_attr = sysfs_get_dirent(nfit_kernfs, in acpi_nfit_register_dimms()
2097 if (!nfit_mem->flags_attr) in acpi_nfit_register_dimms()
2098 dev_warn(acpi_desc->dev, "%s: notifications disabled\n", in acpi_nfit_register_dimms()
2102 return devm_add_action_or_reset(acpi_desc->dev, shutdown_dimm_notify, in acpi_nfit_register_dimms()
2119 struct nvdimm_bus_descriptor *nd_desc = &acpi_desc->nd_desc; in acpi_nfit_init_dsms()
2125 set_bit(ND_CMD_CALL, &nd_desc->cmd_mask); in acpi_nfit_init_dsms()
2126 set_bit(NVDIMM_BUS_FAMILY_NFIT, &nd_desc->bus_family_mask); in acpi_nfit_init_dsms()
2129 if (acpi_desc->bus_cmd_force_en) { in acpi_nfit_init_dsms()
2130 nd_desc->cmd_mask = acpi_desc->bus_cmd_force_en; in acpi_nfit_init_dsms()
2131 mask = &nd_desc->bus_family_mask; in acpi_nfit_init_dsms()
2132 if (acpi_desc->family_dsm_mask[NVDIMM_BUS_FAMILY_INTEL]) { in acpi_nfit_init_dsms()
2134 nd_desc->fw_ops = intel_bus_fw_ops; in acpi_nfit_init_dsms()
2143 if (acpi_check_dsm(adev->handle, guid, 1, 1ULL << i)) in acpi_nfit_init_dsms()
2144 set_bit(i, &nd_desc->cmd_mask); in acpi_nfit_init_dsms()
2156 if (acpi_check_dsm(adev->handle, guid, 1, 1ULL << i)) in acpi_nfit_init_dsms()
2157 set_bit(i, &acpi_desc->bus_dsm_mask); in acpi_nfit_init_dsms()
2162 mask = &acpi_desc->family_dsm_mask[NVDIMM_BUS_FAMILY_INTEL]; in acpi_nfit_init_dsms()
2164 if (acpi_check_dsm(adev->handle, guid, 1, 1ULL << i)) in acpi_nfit_init_dsms()
2168 set_bit(NVDIMM_BUS_FAMILY_INTEL, &nd_desc->bus_family_mask); in acpi_nfit_init_dsms()
2169 nd_desc->fw_ops = intel_bus_fw_ops; in acpi_nfit_init_dsms()
2179 return sysfs_emit(buf, "%d\n", nfit_spa->spa->range_index); in range_index_show()
2214 static int cmp_map_compat(const void *m0, const void *m1) in cmp_map_compat() argument
2217 const struct nfit_set_info *map1 = m1; in cmp_map_compat()
2219 return memcmp(&map0->region_offset, &map1->region_offset, in cmp_map_compat()
2223 static int cmp_map(const void *m0, const void *m1) in cmp_map() argument
2226 const struct nfit_set_info *map1 = m1; in cmp_map()
2228 if (map0->region_offset < map1->region_offset) in cmp_map()
2229 return -1; in cmp_map()
2230 else if (map0->region_offset > map1->region_offset) in cmp_map()
2235 static int cmp_map2(const void *m0, const void *m1) in cmp_map2() argument
2238 const struct nfit_set_info2 *map1 = m1; in cmp_map2()
2240 if (map0->region_offset < map1->region_offset) in cmp_map2()
2241 return -1; in cmp_map2()
2242 else if (map0->region_offset > map1->region_offset) in cmp_map2()
2253 list_for_each_entry(nfit_memdev, &acpi_desc->memdevs, list) in memdev_from_spa()
2254 if (nfit_memdev->memdev->range_index == range_index) in memdev_from_spa()
2255 if (n-- == 0) in memdev_from_spa()
2256 return nfit_memdev->memdev; in memdev_from_spa()
2264 u16 nr = ndr_desc->num_mappings; in acpi_nfit_init_interleave_set()
2269 struct device *dev = acpi_desc->dev; in acpi_nfit_init_interleave_set()
2274 return -ENOMEM; in acpi_nfit_init_interleave_set()
2278 return -ENOMEM; in acpi_nfit_init_interleave_set()
2279 import_guid(&nd_set->type_guid, spa->range_guid); in acpi_nfit_init_interleave_set()
2282 struct nd_mapping_desc *mapping = &ndr_desc->mapping[i]; in acpi_nfit_init_interleave_set()
2283 struct nvdimm *nvdimm = mapping->nvdimm; in acpi_nfit_init_interleave_set()
2288 memdev_from_spa(acpi_desc, spa->range_index, i); in acpi_nfit_init_interleave_set()
2289 struct acpi_nfit_control_region *dcr = nfit_mem->dcr; in acpi_nfit_init_interleave_set()
2291 if (!memdev || !nfit_mem->dcr) { in acpi_nfit_init_interleave_set()
2293 return -ENODEV; in acpi_nfit_init_interleave_set()
2296 map->region_offset = memdev->region_offset; in acpi_nfit_init_interleave_set()
2297 map->serial_number = dcr->serial_number; in acpi_nfit_init_interleave_set()
2299 map2->region_offset = memdev->region_offset; in acpi_nfit_init_interleave_set()
2300 map2->serial_number = dcr->serial_number; in acpi_nfit_init_interleave_set()
2301 map2->vendor_id = dcr->vendor_id; in acpi_nfit_init_interleave_set()
2302 map2->manufacturing_date = dcr->manufacturing_date; in acpi_nfit_init_interleave_set()
2303 map2->manufacturing_location = dcr->manufacturing_location; in acpi_nfit_init_interleave_set()
2308 nd_set->cookie1 = nd_fletcher64(info, sizeof(*info) * nr, 0); in acpi_nfit_init_interleave_set()
2312 nd_set->cookie2 = nd_fletcher64(info2, sizeof(*info2) * nr, 0); in acpi_nfit_init_interleave_set()
2316 nd_set->altcookie = nd_fletcher64(info, sizeof(*info) * nr, 0); in acpi_nfit_init_interleave_set()
2324 struct nd_mapping_desc *mapping = &ndr_desc->mapping[j]; in acpi_nfit_init_interleave_set()
2325 struct nvdimm *nvdimm = mapping->nvdimm; in acpi_nfit_init_interleave_set()
2327 struct acpi_nfit_control_region *dcr = nfit_mem->dcr; in acpi_nfit_init_interleave_set()
2329 if (map2->serial_number == dcr->serial_number && in acpi_nfit_init_interleave_set()
2330 map2->vendor_id == dcr->vendor_id && in acpi_nfit_init_interleave_set()
2331 map2->manufacturing_date == dcr->manufacturing_date && in acpi_nfit_init_interleave_set()
2332 map2->manufacturing_location in acpi_nfit_init_interleave_set()
2333 == dcr->manufacturing_location) { in acpi_nfit_init_interleave_set()
2334 mapping->position = i; in acpi_nfit_init_interleave_set()
2340 ndr_desc->nd_set = nd_set; in acpi_nfit_init_interleave_set()
2348 struct nvdimm_bus_descriptor *nd_desc = &acpi_desc->nd_desc; in ars_get_cap()
2349 struct acpi_nfit_system_address *spa = nfit_spa->spa; in ars_get_cap()
2352 cmd->address = spa->address; in ars_get_cap()
2353 cmd->length = spa->length; in ars_get_cap()
2354 rc = nd_desc->ndctl(nd_desc, NULL, ND_CMD_ARS_CAP, cmd, in ars_get_cap()
2367 struct acpi_nfit_system_address *spa = nfit_spa->spa; in ars_start()
2368 struct nvdimm_bus_descriptor *nd_desc = &acpi_desc->nd_desc; in ars_start()
2371 ars_start.address = spa->address; in ars_start()
2372 ars_start.length = spa->length; in ars_start()
2380 return -ENOTTY; in ars_start()
2382 rc = nd_desc->ndctl(nd_desc, NULL, ND_CMD_ARS_START, &ars_start, in ars_start()
2389 set_bit(ARS_VALID, &acpi_desc->scrub_flags); in ars_start()
2397 struct nvdimm_bus_descriptor *nd_desc = &acpi_desc->nd_desc; in ars_continue()
2398 struct nd_cmd_ars_status *ars_status = acpi_desc->ars_status; in ars_continue()
2401 .address = ars_status->restart_address, in ars_continue()
2402 .length = ars_status->restart_length, in ars_continue()
2403 .type = ars_status->type, in ars_continue()
2405 rc = nd_desc->ndctl(nd_desc, NULL, ND_CMD_ARS_START, &ars_start, in ars_continue()
2414 struct nvdimm_bus_descriptor *nd_desc = &acpi_desc->nd_desc; in ars_get_status()
2415 struct nd_cmd_ars_status *ars_status = acpi_desc->ars_status; in ars_get_status()
2418 rc = nd_desc->ndctl(nd_desc, NULL, ND_CMD_ARS_STATUS, ars_status, in ars_get_status()
2419 acpi_desc->max_ars, &cmd_rc); in ars_get_status()
2428 struct nd_cmd_ars_status *ars_status = acpi_desc->ars_status; in ars_complete()
2429 struct acpi_nfit_system_address *spa = nfit_spa->spa; in ars_complete()
2430 struct nd_region *nd_region = nfit_spa->nd_region; in ars_complete()
2433 lockdep_assert_held(&acpi_desc->init_mutex); in ars_complete()
2439 if (acpi_desc->scrub_spa != nfit_spa) in ars_complete()
2442 if ((ars_status->address >= spa->address && ars_status->address in ars_complete()
2443 < spa->address + spa->length) in ars_complete()
2444 || (ars_status->address < spa->address)) { in ars_complete()
2453 if (ars_status->address + ars_status->length in ars_complete()
2454 >= spa->address + spa->length) in ars_complete()
2461 acpi_desc->scrub_spa = NULL; in ars_complete()
2466 dev = acpi_desc->dev; in ars_complete()
2467 dev_dbg(dev, "ARS: range %d complete\n", spa->range_index); in ars_complete()
2472 struct nvdimm_bus *nvdimm_bus = acpi_desc->nvdimm_bus; in ars_status_process_records()
2473 struct nd_cmd_ars_status *ars_status = acpi_desc->ars_status; in ars_status_process_records()
2481 if (ars_status->out_length < 44) in ars_status_process_records()
2486 * after a start-ARS event. in ars_status_process_records()
2488 if (!test_and_clear_bit(ARS_VALID, &acpi_desc->scrub_flags)) { in ars_status_process_records()
2489 dev_dbg(acpi_desc->dev, "skip %d stale records\n", in ars_status_process_records()
2490 ars_status->num_records); in ars_status_process_records()
2494 for (i = 0; i < ars_status->num_records; i++) { in ars_status_process_records()
2496 if (ars_status->out_length in ars_status_process_records()
2500 ars_status->records[i].err_address, in ars_status_process_records()
2501 ars_status->records[i].length); in ars_status_process_records()
2505 if (i < ars_status->num_records) in ars_status_process_records()
2506 dev_warn(acpi_desc->dev, "detected truncated ars results\n"); in ars_status_process_records()
2521 struct resource *res, *nd_res = ndr_desc->res; in acpi_nfit_insert_resource()
2525 is_pmem = region_intersects(nd_res->start, resource_size(nd_res), in acpi_nfit_insert_resource()
2530 res = devm_kzalloc(acpi_desc->dev, sizeof(*res), GFP_KERNEL); in acpi_nfit_insert_resource()
2532 return -ENOMEM; in acpi_nfit_insert_resource()
2534 res->name = "Persistent Memory"; in acpi_nfit_insert_resource()
2535 res->start = nd_res->start; in acpi_nfit_insert_resource()
2536 res->end = nd_res->end; in acpi_nfit_insert_resource()
2537 res->flags = IORESOURCE_MEM; in acpi_nfit_insert_resource()
2538 res->desc = IORES_DESC_PERSISTENT_MEMORY; in acpi_nfit_insert_resource()
2544 ret = devm_add_action_or_reset(acpi_desc->dev, in acpi_nfit_insert_resource()
2559 memdev->device_handle); in acpi_nfit_init_mapping()
2560 struct acpi_nfit_system_address *spa = nfit_spa->spa; in acpi_nfit_init_mapping()
2563 dev_err(acpi_desc->dev, "spa%d dimm: %#x not found\n", in acpi_nfit_init_mapping()
2564 spa->range_index, memdev->device_handle); in acpi_nfit_init_mapping()
2565 return -ENODEV; in acpi_nfit_init_mapping()
2568 mapping->nvdimm = nvdimm; in acpi_nfit_init_mapping()
2572 mapping->start = memdev->address; in acpi_nfit_init_mapping()
2573 mapping->size = memdev->region_size; in acpi_nfit_init_mapping()
2599 struct acpi_nfit_system_address *spa = nfit_spa->spa; in acpi_nfit_register_region()
2606 if (nfit_spa->nd_region) in acpi_nfit_register_region()
2609 if (spa->range_index == 0 && !nfit_spa_is_virtual(spa)) { in acpi_nfit_register_region()
2610 dev_dbg(acpi_desc->dev, "detected invalid spa index\n"); in acpi_nfit_register_region()
2617 res.start = spa->address; in acpi_nfit_register_region()
2618 res.end = res.start + spa->length - 1; in acpi_nfit_register_region()
2620 ndr_desc->res = &res; in acpi_nfit_register_region()
2621 ndr_desc->provider_data = nfit_spa; in acpi_nfit_register_region()
2622 ndr_desc->attr_groups = acpi_nfit_region_attribute_groups; in acpi_nfit_register_region()
2623 if (spa->flags & ACPI_NFIT_PROXIMITY_VALID) { in acpi_nfit_register_region()
2624 ndr_desc->numa_node = pxm_to_online_node(spa->proximity_domain); in acpi_nfit_register_region()
2625 ndr_desc->target_node = pxm_to_node(spa->proximity_domain); in acpi_nfit_register_region()
2627 ndr_desc->numa_node = NUMA_NO_NODE; in acpi_nfit_register_region()
2628 ndr_desc->target_node = NUMA_NO_NODE; in acpi_nfit_register_region()
2632 if (ndr_desc->numa_node == NUMA_NO_NODE) { in acpi_nfit_register_region()
2633 ndr_desc->numa_node = memory_add_physaddr_to_nid(spa->address); in acpi_nfit_register_region()
2634 dev_info(acpi_desc->dev, "changing numa node from %d to %d for nfit region [%pa-%pa]", in acpi_nfit_register_region()
2635 NUMA_NO_NODE, ndr_desc->numa_node, &res.start, &res.end); in acpi_nfit_register_region()
2637 if (ndr_desc->target_node == NUMA_NO_NODE) { in acpi_nfit_register_region()
2638 ndr_desc->target_node = phys_to_target_node(spa->address); in acpi_nfit_register_region()
2639 dev_info(acpi_desc->dev, "changing target node from %d to %d for nfit region [%pa-%pa]", in acpi_nfit_register_region()
2640 NUMA_NO_NODE, ndr_desc->numa_node, &res.start, &res.end); in acpi_nfit_register_region()
2648 if (acpi_desc->platform_cap & ACPI_NFIT_CAPABILITY_CACHE_FLUSH) in acpi_nfit_register_region()
2649 set_bit(ND_REGION_PERSIST_CACHE, &ndr_desc->flags); in acpi_nfit_register_region()
2650 else if (acpi_desc->platform_cap & ACPI_NFIT_CAPABILITY_MEM_FLUSH) in acpi_nfit_register_region()
2651 set_bit(ND_REGION_PERSIST_MEMCTRL, &ndr_desc->flags); in acpi_nfit_register_region()
2653 list_for_each_entry(nfit_memdev, &acpi_desc->memdevs, list) { in acpi_nfit_register_region()
2654 struct acpi_nfit_memory_map *memdev = nfit_memdev->memdev; in acpi_nfit_register_region()
2657 /* range index 0 == unmapped in SPA or invalid-SPA */ in acpi_nfit_register_region()
2658 if (memdev->range_index == 0 || spa->range_index == 0) in acpi_nfit_register_region()
2660 if (memdev->range_index != spa->range_index) in acpi_nfit_register_region()
2663 dev_err(acpi_desc->dev, "spa%d exceeds max mappings %d\n", in acpi_nfit_register_region()
2664 spa->range_index, ND_MAX_MAPPINGS); in acpi_nfit_register_region()
2665 return -ENXIO; in acpi_nfit_register_region()
2674 ndr_desc->mapping = mappings; in acpi_nfit_register_region()
2675 ndr_desc->num_mappings = count; in acpi_nfit_register_region()
2680 nvdimm_bus = acpi_desc->nvdimm_bus; in acpi_nfit_register_region()
2684 dev_warn(acpi_desc->dev, in acpi_nfit_register_region()
2690 nfit_spa->nd_region = nvdimm_pmem_region_create(nvdimm_bus, in acpi_nfit_register_region()
2692 if (!nfit_spa->nd_region) in acpi_nfit_register_region()
2693 rc = -ENOMEM; in acpi_nfit_register_region()
2695 nfit_spa->nd_region = nvdimm_volatile_region_create(nvdimm_bus, in acpi_nfit_register_region()
2697 if (!nfit_spa->nd_region) in acpi_nfit_register_region()
2698 rc = -ENOMEM; in acpi_nfit_register_region()
2700 nfit_spa->nd_region = nvdimm_pmem_region_create(nvdimm_bus, in acpi_nfit_register_region()
2702 if (!nfit_spa->nd_region) in acpi_nfit_register_region()
2703 rc = -ENOMEM; in acpi_nfit_register_region()
2708 dev_err(acpi_desc->dev, "failed to register spa range %d\n", in acpi_nfit_register_region()
2709 nfit_spa->spa->range_index); in acpi_nfit_register_region()
2715 struct device *dev = acpi_desc->dev; in ars_status_alloc()
2718 if (acpi_desc->ars_status) { in ars_status_alloc()
2719 memset(acpi_desc->ars_status, 0, acpi_desc->max_ars); in ars_status_alloc()
2723 ars_status = devm_kzalloc(dev, acpi_desc->max_ars, GFP_KERNEL); in ars_status_alloc()
2725 return -ENOMEM; in ars_status_alloc()
2726 acpi_desc->ars_status = ars_status; in ars_status_alloc()
2735 return -ENOMEM; in acpi_nfit_query_poison()
2739 if (rc < 0 && rc != -ENOSPC) in acpi_nfit_query_poison()
2743 dev_err(acpi_desc->dev, "Failed to process ARS records\n"); in acpi_nfit_query_poison()
2753 if (test_bit(ARS_FAILED, &nfit_spa->ars_state)) in ars_register()
2756 set_bit(ARS_REQ_SHORT, &nfit_spa->ars_state); in ars_register()
2758 set_bit(ARS_REQ_LONG, &nfit_spa->ars_state); in ars_register()
2762 case -ENOSPC: in ars_register()
2763 case -EAGAIN: in ars_register()
2766 if (rc == -EBUSY) in ars_register()
2769 set_bit(ARS_FAILED, &nfit_spa->ars_state); in ars_register()
2772 clear_bit(ARS_REQ_SHORT, &nfit_spa->ars_state); in ars_register()
2776 acpi_desc->scrub_spa = nfit_spa; in ars_register()
2783 acpi_desc->scrub_spa = NULL; in ars_register()
2785 case -EBUSY: in ars_register()
2786 case -ENOMEM: in ars_register()
2794 set_bit(ARS_FAILED, &nfit_spa->ars_state); in ars_register()
2805 list_for_each_entry(nfit_spa, &acpi_desc->spas, list) { in ars_complete_all()
2806 if (test_bit(ARS_FAILED, &nfit_spa->ars_state)) in ars_complete_all()
2815 unsigned int tmo = acpi_desc->scrub_tmo; in __acpi_nfit_scrub()
2816 struct device *dev = acpi_desc->dev; in __acpi_nfit_scrub()
2819 lockdep_assert_held(&acpi_desc->init_mutex); in __acpi_nfit_scrub()
2821 if (test_bit(ARS_CANCEL, &acpi_desc->scrub_flags)) in __acpi_nfit_scrub()
2824 if (query_rc == -EBUSY) { in __acpi_nfit_scrub()
2828 if (query_rc == -ENOSPC) { in __acpi_nfit_scrub()
2833 if (query_rc && query_rc != -EAGAIN) { in __acpi_nfit_scrub()
2836 addr = acpi_desc->ars_status->address; in __acpi_nfit_scrub()
2837 end = addr + acpi_desc->ars_status->length; in __acpi_nfit_scrub()
2838 dev_dbg(dev, "ARS: %llx-%llx failed (%d)\n", addr, end, in __acpi_nfit_scrub()
2843 list_for_each_entry(nfit_spa, &acpi_desc->spas, list) { in __acpi_nfit_scrub()
2847 if (test_bit(ARS_FAILED, &nfit_spa->ars_state)) in __acpi_nfit_scrub()
2851 if (test_bit(ARS_REQ_SHORT, &nfit_spa->ars_state)) in __acpi_nfit_scrub()
2853 else if (test_bit(ARS_REQ_LONG, &nfit_spa->ars_state)) in __acpi_nfit_scrub()
2859 dev = nd_region_dev(nfit_spa->nd_region); in __acpi_nfit_scrub()
2861 nfit_spa->spa->range_index, in __acpi_nfit_scrub()
2868 if (rc == -EBUSY) in __acpi_nfit_scrub()
2871 dev_WARN_ONCE(dev, acpi_desc->scrub_spa, in __acpi_nfit_scrub()
2873 acpi_desc->scrub_spa->spa->range_index); in __acpi_nfit_scrub()
2874 clear_bit(req_type, &nfit_spa->ars_state); in __acpi_nfit_scrub()
2875 acpi_desc->scrub_spa = nfit_spa; in __acpi_nfit_scrub()
2880 list_move_tail(&nfit_spa->list, &acpi_desc->spas); in __acpi_nfit_scrub()
2885 nfit_spa->spa->range_index, rc); in __acpi_nfit_scrub()
2886 set_bit(ARS_FAILED, &nfit_spa->ars_state); in __acpi_nfit_scrub()
2893 lockdep_assert_held(&acpi_desc->init_mutex); in __sched_ars()
2895 set_bit(ARS_BUSY, &acpi_desc->scrub_flags); in __sched_ars()
2898 acpi_desc->scrub_tmo = tmo; in __sched_ars()
2899 queue_delayed_work(nfit_wq, &acpi_desc->dwork, tmo * HZ); in __sched_ars()
2909 lockdep_assert_held(&acpi_desc->init_mutex); in notify_ars_done()
2911 clear_bit(ARS_BUSY, &acpi_desc->scrub_flags); in notify_ars_done()
2912 acpi_desc->scrub_count++; in notify_ars_done()
2913 if (acpi_desc->scrub_count_state) in notify_ars_done()
2914 sysfs_notify_dirent(acpi_desc->scrub_count_state); in notify_ars_done()
2924 mutex_lock(&acpi_desc->init_mutex); in acpi_nfit_scrub()
2931 memset(acpi_desc->ars_status, 0, acpi_desc->max_ars); in acpi_nfit_scrub()
2932 clear_bit(ARS_POLL, &acpi_desc->scrub_flags); in acpi_nfit_scrub()
2933 mutex_unlock(&acpi_desc->init_mutex); in acpi_nfit_scrub()
2939 int type = nfit_spa_type(nfit_spa->spa); in acpi_nfit_init_ars()
2943 set_bit(ARS_FAILED, &nfit_spa->ars_state); in acpi_nfit_init_ars()
2956 nfit_spa->max_ars = ars_cap.max_ars_out; in acpi_nfit_init_ars()
2957 nfit_spa->clear_err_unit = ars_cap.clear_err_unit; in acpi_nfit_init_ars()
2958 acpi_desc->max_ars = max(nfit_spa->max_ars, acpi_desc->max_ars); in acpi_nfit_init_ars()
2959 clear_bit(ARS_FAILED, &nfit_spa->ars_state); in acpi_nfit_init_ars()
2967 set_bit(ARS_VALID, &acpi_desc->scrub_flags); in acpi_nfit_register_regions()
2968 list_for_each_entry(nfit_spa, &acpi_desc->spas, list) { in acpi_nfit_register_regions()
2969 switch (nfit_spa_type(nfit_spa->spa)) { in acpi_nfit_register_regions()
2977 list_for_each_entry(nfit_spa, &acpi_desc->spas, list) { in acpi_nfit_register_regions()
2978 switch (nfit_spa_type(nfit_spa->spa)) { in acpi_nfit_register_regions()
2990 if (!test_bit(ARS_FAILED, &nfit_spa->ars_state)) in acpi_nfit_register_regions()
3020 struct device *dev = acpi_desc->dev; in acpi_nfit_check_deletions()
3022 if (!list_empty(&prev->spas) || in acpi_nfit_check_deletions()
3023 !list_empty(&prev->memdevs) || in acpi_nfit_check_deletions()
3024 !list_empty(&prev->dcrs) || in acpi_nfit_check_deletions()
3025 !list_empty(&prev->bdws) || in acpi_nfit_check_deletions()
3026 !list_empty(&prev->idts) || in acpi_nfit_check_deletions()
3027 !list_empty(&prev->flushes)) { in acpi_nfit_check_deletions()
3029 return -ENXIO; in acpi_nfit_check_deletions()
3036 struct device *dev = acpi_desc->dev; in acpi_nfit_desc_init_scrub_attr()
3040 if (!ars_supported(acpi_desc->nvdimm_bus)) in acpi_nfit_desc_init_scrub_attr()
3043 bus_dev = to_nvdimm_bus_dev(acpi_desc->nvdimm_bus); in acpi_nfit_desc_init_scrub_attr()
3044 nfit = sysfs_get_dirent(bus_dev->kobj.sd, "nfit"); in acpi_nfit_desc_init_scrub_attr()
3047 return -ENODEV; in acpi_nfit_desc_init_scrub_attr()
3049 acpi_desc->scrub_count_state = sysfs_get_dirent(nfit, "scrub"); in acpi_nfit_desc_init_scrub_attr()
3051 if (!acpi_desc->scrub_count_state) { in acpi_nfit_desc_init_scrub_attr()
3053 return -ENODEV; in acpi_nfit_desc_init_scrub_attr()
3063 nvdimm_bus_unregister(acpi_desc->nvdimm_bus); in acpi_nfit_unregister()
3068 struct device *dev = acpi_desc->dev; in acpi_nfit_init()
3073 if (!acpi_desc->nvdimm_bus) { in acpi_nfit_init()
3076 acpi_desc->nvdimm_bus = nvdimm_bus_register(dev, in acpi_nfit_init()
3077 &acpi_desc->nd_desc); in acpi_nfit_init()
3078 if (!acpi_desc->nvdimm_bus) in acpi_nfit_init()
3079 return -ENOMEM; in acpi_nfit_init()
3092 list_add_tail(&acpi_desc->list, &acpi_descs); in acpi_nfit_init()
3096 mutex_lock(&acpi_desc->init_mutex); in acpi_nfit_init()
3105 list_cut_position(&prev.spas, &acpi_desc->spas, in acpi_nfit_init()
3106 acpi_desc->spas.prev); in acpi_nfit_init()
3107 list_cut_position(&prev.memdevs, &acpi_desc->memdevs, in acpi_nfit_init()
3108 acpi_desc->memdevs.prev); in acpi_nfit_init()
3109 list_cut_position(&prev.dcrs, &acpi_desc->dcrs, in acpi_nfit_init()
3110 acpi_desc->dcrs.prev); in acpi_nfit_init()
3111 list_cut_position(&prev.bdws, &acpi_desc->bdws, in acpi_nfit_init()
3112 acpi_desc->bdws.prev); in acpi_nfit_init()
3113 list_cut_position(&prev.idts, &acpi_desc->idts, in acpi_nfit_init()
3114 acpi_desc->idts.prev); in acpi_nfit_init()
3115 list_cut_position(&prev.flushes, &acpi_desc->flushes, in acpi_nfit_init()
3116 acpi_desc->flushes.prev); in acpi_nfit_init()
3143 mutex_unlock(&acpi_desc->init_mutex); in acpi_nfit_init()
3151 struct device *dev = acpi_desc->dev; in acpi_nfit_flush_probe()
3158 mutex_lock(&acpi_desc->init_mutex); in acpi_nfit_flush_probe()
3159 mutex_unlock(&acpi_desc->init_mutex); in acpi_nfit_flush_probe()
3180 if (work_busy(&acpi_desc->dwork.work)) in __acpi_nfit_clear_to_send()
3181 return -EBUSY; in __acpi_nfit_clear_to_send()
3197 call_pkg->nd_family == NVDIMM_FAMILY_INTEL) { in acpi_nfit_clear_to_send()
3198 func = call_pkg->nd_command; in acpi_nfit_clear_to_send()
3201 return -EOPNOTSUPP; in acpi_nfit_clear_to_send()
3204 /* block all non-nfit bus commands */ in acpi_nfit_clear_to_send()
3206 call_pkg->nd_family != NVDIMM_BUS_FAMILY_NFIT) in acpi_nfit_clear_to_send()
3207 return -EOPNOTSUPP; in acpi_nfit_clear_to_send()
3215 struct device *dev = acpi_desc->dev; in acpi_nfit_ars_rescan()
3219 mutex_lock(&acpi_desc->init_mutex); in acpi_nfit_ars_rescan()
3220 if (test_bit(ARS_CANCEL, &acpi_desc->scrub_flags)) { in acpi_nfit_ars_rescan()
3221 mutex_unlock(&acpi_desc->init_mutex); in acpi_nfit_ars_rescan()
3225 list_for_each_entry(nfit_spa, &acpi_desc->spas, list) { in acpi_nfit_ars_rescan()
3226 int type = nfit_spa_type(nfit_spa->spa); in acpi_nfit_ars_rescan()
3230 if (test_bit(ARS_FAILED, &nfit_spa->ars_state)) in acpi_nfit_ars_rescan()
3233 if (test_and_set_bit(req_type, &nfit_spa->ars_state)) in acpi_nfit_ars_rescan()
3242 mutex_unlock(&acpi_desc->init_mutex); in acpi_nfit_ars_rescan()
3247 return -EBUSY; in acpi_nfit_ars_rescan()
3248 return -ENOTTY; in acpi_nfit_ars_rescan()
3256 acpi_desc->dev = dev; in acpi_nfit_desc_init()
3257 nd_desc = &acpi_desc->nd_desc; in acpi_nfit_desc_init()
3258 nd_desc->provider_name = "ACPI.NFIT"; in acpi_nfit_desc_init()
3259 nd_desc->module = THIS_MODULE; in acpi_nfit_desc_init()
3260 nd_desc->ndctl = acpi_nfit_ctl; in acpi_nfit_desc_init()
3261 nd_desc->flush_probe = acpi_nfit_flush_probe; in acpi_nfit_desc_init()
3262 nd_desc->clear_to_send = acpi_nfit_clear_to_send; in acpi_nfit_desc_init()
3263 nd_desc->attr_groups = acpi_nfit_attribute_groups; in acpi_nfit_desc_init()
3265 INIT_LIST_HEAD(&acpi_desc->spas); in acpi_nfit_desc_init()
3266 INIT_LIST_HEAD(&acpi_desc->dcrs); in acpi_nfit_desc_init()
3267 INIT_LIST_HEAD(&acpi_desc->bdws); in acpi_nfit_desc_init()
3268 INIT_LIST_HEAD(&acpi_desc->idts); in acpi_nfit_desc_init()
3269 INIT_LIST_HEAD(&acpi_desc->flushes); in acpi_nfit_desc_init()
3270 INIT_LIST_HEAD(&acpi_desc->memdevs); in acpi_nfit_desc_init()
3271 INIT_LIST_HEAD(&acpi_desc->dimms); in acpi_nfit_desc_init()
3272 INIT_LIST_HEAD(&acpi_desc->list); in acpi_nfit_desc_init()
3273 mutex_init(&acpi_desc->init_mutex); in acpi_nfit_desc_init()
3274 acpi_desc->scrub_tmo = 1; in acpi_nfit_desc_init()
3275 INIT_DELAYED_WORK(&acpi_desc->dwork, acpi_nfit_scrub); in acpi_nfit_desc_init()
3288 device_lock(&adev->dev); in acpi_nfit_notify()
3289 __acpi_nfit_notify(&adev->dev, handle, event); in acpi_nfit_notify()
3290 device_unlock(&adev->dev); in acpi_nfit_notify()
3304 struct device *bus_dev = to_nvdimm_bus_dev(acpi_desc->nvdimm_bus); in acpi_nfit_shutdown()
3311 list_del(&acpi_desc->list); in acpi_nfit_shutdown()
3314 mutex_lock(&acpi_desc->init_mutex); in acpi_nfit_shutdown()
3315 set_bit(ARS_CANCEL, &acpi_desc->scrub_flags); in acpi_nfit_shutdown()
3316 mutex_unlock(&acpi_desc->init_mutex); in acpi_nfit_shutdown()
3317 cancel_delayed_work_sync(&acpi_desc->dwork); in acpi_nfit_shutdown()
3320 * Bounce the nvdimm bus lock to make sure any in-flight in acpi_nfit_shutdown()
3322 * either submit or see ->cancel set. in acpi_nfit_shutdown()
3335 struct device *dev = &adev->dev; in acpi_nfit_add()
3354 * NVDIMMs through NFIT at boot time and re-enumeration at in acpi_nfit_add()
3367 sz = tbl->length; in acpi_nfit_add()
3371 return -ENOMEM; in acpi_nfit_add()
3372 acpi_nfit_desc_init(acpi_desc, &adev->dev); in acpi_nfit_add()
3375 acpi_desc->acpi_header = *tbl; in acpi_nfit_add()
3378 status = acpi_evaluate_object(adev->handle, "_FIT", NULL, &buf); in acpi_nfit_add()
3382 if (obj->type == ACPI_TYPE_BUFFER) in acpi_nfit_add()
3383 rc = acpi_nfit_init(acpi_desc, obj->buffer.pointer, in acpi_nfit_add()
3384 obj->buffer.length); in acpi_nfit_add()
3387 (int) obj->type); in acpi_nfit_add()
3390 /* skip over the lead-in header table */ in acpi_nfit_add()
3393 sz - sizeof(struct acpi_table_nfit)); in acpi_nfit_add()
3409 if (!dev->driver) { in acpi_nfit_update_notify()
3410 /* dev->driver may be null if we're being removed */ in acpi_nfit_update_notify()
3436 if (obj->type == ACPI_TYPE_BUFFER) { in acpi_nfit_update_notify()
3437 ret = acpi_nfit_init(acpi_desc, obj->buffer.pointer, in acpi_nfit_update_notify()
3438 obj->buffer.length); in acpi_nfit_update_notify()
3450 if (acpi_desc->scrub_mode == HW_ERROR_SCRUB_ON) in acpi_nfit_uc_error_notify()
3516 return -ENOMEM; in nfit_init()