Dan Williams | b94d523 | 2015-05-19 22:54:31 -0400 | [diff] [blame] | 1 | /* |
| 2 | * Copyright(c) 2013-2015 Intel Corporation. All rights reserved. |
| 3 | * |
| 4 | * This program is free software; you can redistribute it and/or modify |
| 5 | * it under the terms of version 2 of the GNU General Public License as |
| 6 | * published by the Free Software Foundation. |
| 7 | * |
| 8 | * This program is distributed in the hope that it will be useful, but |
| 9 | * WITHOUT ANY WARRANTY; without even the implied warranty of |
| 10 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU |
| 11 | * General Public License for more details. |
| 12 | */ |
| 13 | #include <linux/list_sort.h> |
| 14 | #include <linux/libnvdimm.h> |
| 15 | #include <linux/module.h> |
Ross Zwisler | 047fc8a | 2015-06-25 04:21:02 -0400 | [diff] [blame] | 16 | #include <linux/mutex.h> |
Dan Williams | 62232e45 | 2015-06-08 14:27:06 -0400 | [diff] [blame] | 17 | #include <linux/ndctl.h> |
Vishal Verma | 37b137f | 2016-07-23 21:51:42 -0700 | [diff] [blame] | 18 | #include <linux/sysfs.h> |
Vishal Verma | 0caeef6 | 2015-12-24 19:21:43 -0700 | [diff] [blame] | 19 | #include <linux/delay.h> |
Dan Williams | b94d523 | 2015-05-19 22:54:31 -0400 | [diff] [blame] | 20 | #include <linux/list.h> |
| 21 | #include <linux/acpi.h> |
Dan Williams | eaf9615 | 2015-05-01 13:11:27 -0400 | [diff] [blame] | 22 | #include <linux/sort.h> |
Ross Zwisler | c2ad295 | 2015-07-10 11:06:13 -0600 | [diff] [blame] | 23 | #include <linux/pmem.h> |
Ross Zwisler | 047fc8a | 2015-06-25 04:21:02 -0400 | [diff] [blame] | 24 | #include <linux/io.h> |
Dan Williams | 1cf03c0 | 2016-02-17 13:01:23 -0800 | [diff] [blame] | 25 | #include <linux/nd.h> |
Dan Williams | 96601ad | 2015-08-24 18:29:38 -0400 | [diff] [blame] | 26 | #include <asm/cacheflush.h> |
Dan Williams | b94d523 | 2015-05-19 22:54:31 -0400 | [diff] [blame] | 27 | #include "nfit.h" |
| 28 | |
Ross Zwisler | 047fc8a | 2015-06-25 04:21:02 -0400 | [diff] [blame] | 29 | /* |
| 30 | * For readq() and writeq() on 32-bit builds, the hi-lo, lo-hi order is |
| 31 | * irrelevant. |
| 32 | */ |
Christoph Hellwig | 2f8e2c8 | 2015-08-28 09:27:14 +0200 | [diff] [blame] | 33 | #include <linux/io-64-nonatomic-hi-lo.h> |
Ross Zwisler | 047fc8a | 2015-06-25 04:21:02 -0400 | [diff] [blame] | 34 | |
Dan Williams | 4d88a97 | 2015-05-31 14:41:48 -0400 | [diff] [blame] | 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"); |
| 38 | |
Dan Williams | 1cf03c0 | 2016-02-17 13:01:23 -0800 | [diff] [blame] | 39 | static unsigned int scrub_timeout = NFIT_ARS_TIMEOUT; |
| 40 | module_param(scrub_timeout, uint, S_IRUGO|S_IWUSR); |
| 41 | MODULE_PARM_DESC(scrub_timeout, "Initial scrub timeout in seconds"); |
| 42 | |
| 43 | /* after three payloads of overflow, it's dead jim */ |
| 44 | static unsigned int scrub_overflow_abort = 3; |
| 45 | module_param(scrub_overflow_abort, uint, S_IRUGO|S_IWUSR); |
| 46 | MODULE_PARM_DESC(scrub_overflow_abort, |
| 47 | "Number of times we overflow ARS results before abort"); |
| 48 | |
Dan Williams | 8755409 | 2016-04-28 18:01:20 -0700 | [diff] [blame] | 49 | static bool disable_vendor_specific; |
| 50 | module_param(disable_vendor_specific, bool, S_IRUGO); |
| 51 | MODULE_PARM_DESC(disable_vendor_specific, |
Linda Knippers | f2668fa | 2017-03-07 16:35:14 -0500 | [diff] [blame] | 52 | "Limit commands to the publicly specified set"); |
Dan Williams | 8755409 | 2016-04-28 18:01:20 -0700 | [diff] [blame] | 53 | |
Linda Knippers | 095ab4b | 2017-03-07 16:35:12 -0500 | [diff] [blame] | 54 | static unsigned long override_dsm_mask; |
| 55 | module_param(override_dsm_mask, ulong, S_IRUGO); |
| 56 | MODULE_PARM_DESC(override_dsm_mask, "Bitmask of allowed NVDIMM DSM functions"); |
| 57 | |
Linda Knippers | ba650cf | 2017-03-07 16:35:13 -0500 | [diff] [blame] | 58 | static int default_dsm_family = -1; |
| 59 | module_param(default_dsm_family, int, S_IRUGO); |
| 60 | MODULE_PARM_DESC(default_dsm_family, |
| 61 | "Try this DSM type first when identifying NVDIMM family"); |
| 62 | |
Vishal Verma | 6839a6d | 2016-07-23 21:51:21 -0700 | [diff] [blame] | 63 | LIST_HEAD(acpi_descs); |
| 64 | DEFINE_MUTEX(acpi_desc_lock); |
| 65 | |
Dan Williams | 7ae0fa43 | 2016-02-19 12:16:34 -0800 | [diff] [blame] | 66 | static struct workqueue_struct *nfit_wq; |
| 67 | |
Vishal Verma | 2098516 | 2015-10-27 16:58:27 -0600 | [diff] [blame] | 68 | struct nfit_table_prev { |
| 69 | struct list_head spas; |
| 70 | struct list_head memdevs; |
| 71 | struct list_head dcrs; |
| 72 | struct list_head bdws; |
| 73 | struct list_head idts; |
| 74 | struct list_head flushes; |
| 75 | }; |
| 76 | |
Dan Williams | b94d523 | 2015-05-19 22:54:31 -0400 | [diff] [blame] | 77 | static u8 nfit_uuid[NFIT_UUID_MAX][16]; |
| 78 | |
Dan Williams | 6bc7561 | 2015-06-17 17:23:32 -0400 | [diff] [blame] | 79 | const u8 *to_nfit_uuid(enum nfit_uuids id) |
Dan Williams | b94d523 | 2015-05-19 22:54:31 -0400 | [diff] [blame] | 80 | { |
| 81 | return nfit_uuid[id]; |
| 82 | } |
Dan Williams | 6bc7561 | 2015-06-17 17:23:32 -0400 | [diff] [blame] | 83 | EXPORT_SYMBOL(to_nfit_uuid); |
Dan Williams | b94d523 | 2015-05-19 22:54:31 -0400 | [diff] [blame] | 84 | |
Dan Williams | 62232e45 | 2015-06-08 14:27:06 -0400 | [diff] [blame] | 85 | static struct acpi_nfit_desc *to_acpi_nfit_desc( |
| 86 | struct nvdimm_bus_descriptor *nd_desc) |
| 87 | { |
| 88 | return container_of(nd_desc, struct acpi_nfit_desc, nd_desc); |
| 89 | } |
| 90 | |
| 91 | static struct acpi_device *to_acpi_dev(struct acpi_nfit_desc *acpi_desc) |
| 92 | { |
| 93 | struct nvdimm_bus_descriptor *nd_desc = &acpi_desc->nd_desc; |
| 94 | |
| 95 | /* |
| 96 | * If provider == 'ACPI.NFIT' we can assume 'dev' is a struct |
| 97 | * acpi_device. |
| 98 | */ |
| 99 | if (!nd_desc->provider_name |
| 100 | || strcmp(nd_desc->provider_name, "ACPI.NFIT") != 0) |
| 101 | return NULL; |
| 102 | |
| 103 | return to_acpi_device(acpi_desc->dev); |
| 104 | } |
| 105 | |
Dan Williams | d6eb270 | 2016-12-06 15:06:55 -0800 | [diff] [blame] | 106 | static int xlat_bus_status(void *buf, unsigned int cmd, u32 status) |
Dan Williams | aef2533 | 2016-02-12 17:01:11 -0800 | [diff] [blame] | 107 | { |
Dan Williams | d4f3236 | 2016-03-03 16:08:54 -0800 | [diff] [blame] | 108 | struct nd_cmd_clear_error *clear_err; |
Dan Williams | aef2533 | 2016-02-12 17:01:11 -0800 | [diff] [blame] | 109 | struct nd_cmd_ars_status *ars_status; |
Dan Williams | aef2533 | 2016-02-12 17:01:11 -0800 | [diff] [blame] | 110 | u16 flags; |
| 111 | |
| 112 | switch (cmd) { |
| 113 | case ND_CMD_ARS_CAP: |
Dan Williams | 11294d6 | 2016-09-21 09:21:26 -0700 | [diff] [blame] | 114 | if ((status & 0xffff) == NFIT_ARS_CAP_NONE) |
Dan Williams | aef2533 | 2016-02-12 17:01:11 -0800 | [diff] [blame] | 115 | return -ENOTTY; |
| 116 | |
| 117 | /* Command failed */ |
Dan Williams | 11294d6 | 2016-09-21 09:21:26 -0700 | [diff] [blame] | 118 | if (status & 0xffff) |
Dan Williams | aef2533 | 2016-02-12 17:01:11 -0800 | [diff] [blame] | 119 | return -EIO; |
| 120 | |
| 121 | /* No supported scan types for this range */ |
| 122 | flags = ND_ARS_PERSISTENT | ND_ARS_VOLATILE; |
Dan Williams | 11294d6 | 2016-09-21 09:21:26 -0700 | [diff] [blame] | 123 | if ((status >> 16 & flags) == 0) |
Dan Williams | aef2533 | 2016-02-12 17:01:11 -0800 | [diff] [blame] | 124 | return -ENOTTY; |
Vishal Verma | 9a901f5 | 2016-12-05 17:00:37 -0700 | [diff] [blame] | 125 | return 0; |
Dan Williams | aef2533 | 2016-02-12 17:01:11 -0800 | [diff] [blame] | 126 | case ND_CMD_ARS_START: |
Dan Williams | aef2533 | 2016-02-12 17:01:11 -0800 | [diff] [blame] | 127 | /* ARS is in progress */ |
Dan Williams | 11294d6 | 2016-09-21 09:21:26 -0700 | [diff] [blame] | 128 | if ((status & 0xffff) == NFIT_ARS_START_BUSY) |
Dan Williams | aef2533 | 2016-02-12 17:01:11 -0800 | [diff] [blame] | 129 | return -EBUSY; |
| 130 | |
| 131 | /* Command failed */ |
Dan Williams | 11294d6 | 2016-09-21 09:21:26 -0700 | [diff] [blame] | 132 | if (status & 0xffff) |
Dan Williams | aef2533 | 2016-02-12 17:01:11 -0800 | [diff] [blame] | 133 | return -EIO; |
Vishal Verma | 9a901f5 | 2016-12-05 17:00:37 -0700 | [diff] [blame] | 134 | return 0; |
Dan Williams | aef2533 | 2016-02-12 17:01:11 -0800 | [diff] [blame] | 135 | case ND_CMD_ARS_STATUS: |
| 136 | ars_status = buf; |
| 137 | /* Command failed */ |
Dan Williams | 11294d6 | 2016-09-21 09:21:26 -0700 | [diff] [blame] | 138 | if (status & 0xffff) |
Dan Williams | aef2533 | 2016-02-12 17:01:11 -0800 | [diff] [blame] | 139 | return -EIO; |
| 140 | /* Check extended status (Upper two bytes) */ |
Dan Williams | 11294d6 | 2016-09-21 09:21:26 -0700 | [diff] [blame] | 141 | if (status == NFIT_ARS_STATUS_DONE) |
Dan Williams | aef2533 | 2016-02-12 17:01:11 -0800 | [diff] [blame] | 142 | return 0; |
| 143 | |
| 144 | /* ARS is in progress */ |
Dan Williams | 11294d6 | 2016-09-21 09:21:26 -0700 | [diff] [blame] | 145 | if (status == NFIT_ARS_STATUS_BUSY) |
Dan Williams | aef2533 | 2016-02-12 17:01:11 -0800 | [diff] [blame] | 146 | return -EBUSY; |
| 147 | |
| 148 | /* No ARS performed for the current boot */ |
Dan Williams | 11294d6 | 2016-09-21 09:21:26 -0700 | [diff] [blame] | 149 | if (status == NFIT_ARS_STATUS_NONE) |
Dan Williams | aef2533 | 2016-02-12 17:01:11 -0800 | [diff] [blame] | 150 | return -EAGAIN; |
| 151 | |
| 152 | /* |
| 153 | * ARS interrupted, either we overflowed or some other |
| 154 | * agent wants the scan to stop. If we didn't overflow |
| 155 | * then just continue with the returned results. |
| 156 | */ |
Dan Williams | 11294d6 | 2016-09-21 09:21:26 -0700 | [diff] [blame] | 157 | if (status == NFIT_ARS_STATUS_INTR) { |
Dan Williams | 82aa37c | 2016-12-06 12:45:24 -0800 | [diff] [blame] | 158 | if (ars_status->out_length >= 40 && (ars_status->flags |
| 159 | & NFIT_ARS_F_OVERFLOW)) |
Dan Williams | aef2533 | 2016-02-12 17:01:11 -0800 | [diff] [blame] | 160 | return -ENOSPC; |
| 161 | return 0; |
| 162 | } |
| 163 | |
| 164 | /* Unknown status */ |
Dan Williams | 11294d6 | 2016-09-21 09:21:26 -0700 | [diff] [blame] | 165 | if (status >> 16) |
Dan Williams | aef2533 | 2016-02-12 17:01:11 -0800 | [diff] [blame] | 166 | return -EIO; |
Vishal Verma | 9a901f5 | 2016-12-05 17:00:37 -0700 | [diff] [blame] | 167 | return 0; |
Dan Williams | d4f3236 | 2016-03-03 16:08:54 -0800 | [diff] [blame] | 168 | case ND_CMD_CLEAR_ERROR: |
| 169 | clear_err = buf; |
Dan Williams | 11294d6 | 2016-09-21 09:21:26 -0700 | [diff] [blame] | 170 | if (status & 0xffff) |
Dan Williams | d4f3236 | 2016-03-03 16:08:54 -0800 | [diff] [blame] | 171 | return -EIO; |
| 172 | if (!clear_err->cleared) |
| 173 | return -EIO; |
| 174 | if (clear_err->length > clear_err->cleared) |
| 175 | return clear_err->cleared; |
Vishal Verma | 9a901f5 | 2016-12-05 17:00:37 -0700 | [diff] [blame] | 176 | return 0; |
Dan Williams | aef2533 | 2016-02-12 17:01:11 -0800 | [diff] [blame] | 177 | default: |
| 178 | break; |
| 179 | } |
| 180 | |
Dan Williams | 11294d6 | 2016-09-21 09:21:26 -0700 | [diff] [blame] | 181 | /* all other non-zero status results in an error */ |
| 182 | if (status) |
| 183 | return -EIO; |
Dan Williams | aef2533 | 2016-02-12 17:01:11 -0800 | [diff] [blame] | 184 | return 0; |
| 185 | } |
| 186 | |
Dan Williams | d6eb270 | 2016-12-06 15:06:55 -0800 | [diff] [blame] | 187 | static int xlat_status(struct nvdimm *nvdimm, void *buf, unsigned int cmd, |
| 188 | u32 status) |
| 189 | { |
| 190 | if (!nvdimm) |
| 191 | return xlat_bus_status(buf, cmd, status); |
| 192 | if (status) |
| 193 | return -EIO; |
| 194 | return 0; |
| 195 | } |
| 196 | |
Dan Williams | a7de92d | 2016-12-05 13:43:25 -0800 | [diff] [blame] | 197 | int acpi_nfit_ctl(struct nvdimm_bus_descriptor *nd_desc, struct nvdimm *nvdimm, |
| 198 | unsigned int cmd, void *buf, unsigned int buf_len, int *cmd_rc) |
Dan Williams | b94d523 | 2015-05-19 22:54:31 -0400 | [diff] [blame] | 199 | { |
Dan Williams | 62232e45 | 2015-06-08 14:27:06 -0400 | [diff] [blame] | 200 | struct acpi_nfit_desc *acpi_desc = to_acpi_nfit_desc(nd_desc); |
Dan Williams | 62232e45 | 2015-06-08 14:27:06 -0400 | [diff] [blame] | 201 | union acpi_object in_obj, in_buf, *out_obj; |
Dan Williams | 31eca76 | 2016-04-28 16:23:43 -0700 | [diff] [blame] | 202 | const struct nd_cmd_desc *desc = NULL; |
Dan Williams | 62232e45 | 2015-06-08 14:27:06 -0400 | [diff] [blame] | 203 | struct device *dev = acpi_desc->dev; |
Dan Williams | 31eca76 | 2016-04-28 16:23:43 -0700 | [diff] [blame] | 204 | struct nd_cmd_pkg *call_pkg = NULL; |
Dan Williams | 62232e45 | 2015-06-08 14:27:06 -0400 | [diff] [blame] | 205 | const char *cmd_name, *dimm_name; |
Dan Williams | 31eca76 | 2016-04-28 16:23:43 -0700 | [diff] [blame] | 206 | unsigned long cmd_mask, dsm_mask; |
Dan Williams | 11294d6 | 2016-09-21 09:21:26 -0700 | [diff] [blame] | 207 | u32 offset, fw_status = 0; |
Dan Williams | 62232e45 | 2015-06-08 14:27:06 -0400 | [diff] [blame] | 208 | acpi_handle handle; |
Dan Williams | 31eca76 | 2016-04-28 16:23:43 -0700 | [diff] [blame] | 209 | unsigned int func; |
Dan Williams | 62232e45 | 2015-06-08 14:27:06 -0400 | [diff] [blame] | 210 | const u8 *uuid; |
Dan Williams | 62232e45 | 2015-06-08 14:27:06 -0400 | [diff] [blame] | 211 | int rc, i; |
| 212 | |
Dan Williams | 31eca76 | 2016-04-28 16:23:43 -0700 | [diff] [blame] | 213 | func = cmd; |
| 214 | if (cmd == ND_CMD_CALL) { |
| 215 | call_pkg = buf; |
| 216 | func = call_pkg->nd_command; |
| 217 | } |
| 218 | |
Dan Williams | 62232e45 | 2015-06-08 14:27:06 -0400 | [diff] [blame] | 219 | if (nvdimm) { |
| 220 | struct nfit_mem *nfit_mem = nvdimm_provider_data(nvdimm); |
| 221 | struct acpi_device *adev = nfit_mem->adev; |
| 222 | |
| 223 | if (!adev) |
| 224 | return -ENOTTY; |
Dan Williams | 31eca76 | 2016-04-28 16:23:43 -0700 | [diff] [blame] | 225 | if (call_pkg && nfit_mem->family != call_pkg->nd_family) |
| 226 | return -ENOTTY; |
| 227 | |
Ross Zwisler | 047fc8a | 2015-06-25 04:21:02 -0400 | [diff] [blame] | 228 | dimm_name = nvdimm_name(nvdimm); |
Dan Williams | 62232e45 | 2015-06-08 14:27:06 -0400 | [diff] [blame] | 229 | cmd_name = nvdimm_cmd_name(cmd); |
Dan Williams | e3654ec | 2016-04-28 16:17:07 -0700 | [diff] [blame] | 230 | cmd_mask = nvdimm_cmd_mask(nvdimm); |
Dan Williams | 62232e45 | 2015-06-08 14:27:06 -0400 | [diff] [blame] | 231 | dsm_mask = nfit_mem->dsm_mask; |
| 232 | desc = nd_cmd_dimm_desc(cmd); |
Dan Williams | 31eca76 | 2016-04-28 16:23:43 -0700 | [diff] [blame] | 233 | uuid = to_nfit_uuid(nfit_mem->family); |
Dan Williams | 62232e45 | 2015-06-08 14:27:06 -0400 | [diff] [blame] | 234 | handle = adev->handle; |
| 235 | } else { |
| 236 | struct acpi_device *adev = to_acpi_dev(acpi_desc); |
| 237 | |
| 238 | cmd_name = nvdimm_bus_cmd_name(cmd); |
Dan Williams | e3654ec | 2016-04-28 16:17:07 -0700 | [diff] [blame] | 239 | cmd_mask = nd_desc->cmd_mask; |
Dan Williams | 31eca76 | 2016-04-28 16:23:43 -0700 | [diff] [blame] | 240 | dsm_mask = cmd_mask; |
Dan Williams | 62232e45 | 2015-06-08 14:27:06 -0400 | [diff] [blame] | 241 | desc = nd_cmd_bus_desc(cmd); |
| 242 | uuid = to_nfit_uuid(NFIT_DEV_BUS); |
| 243 | handle = adev->handle; |
| 244 | dimm_name = "bus"; |
| 245 | } |
| 246 | |
| 247 | if (!desc || (cmd && (desc->out_num + desc->in_num == 0))) |
| 248 | return -ENOTTY; |
| 249 | |
Dan Williams | 31eca76 | 2016-04-28 16:23:43 -0700 | [diff] [blame] | 250 | if (!test_bit(cmd, &cmd_mask) || !test_bit(func, &dsm_mask)) |
Dan Williams | 62232e45 | 2015-06-08 14:27:06 -0400 | [diff] [blame] | 251 | return -ENOTTY; |
| 252 | |
| 253 | in_obj.type = ACPI_TYPE_PACKAGE; |
| 254 | in_obj.package.count = 1; |
| 255 | in_obj.package.elements = &in_buf; |
| 256 | in_buf.type = ACPI_TYPE_BUFFER; |
| 257 | in_buf.buffer.pointer = buf; |
| 258 | in_buf.buffer.length = 0; |
| 259 | |
| 260 | /* libnvdimm has already validated the input envelope */ |
| 261 | for (i = 0; i < desc->in_num; i++) |
| 262 | in_buf.buffer.length += nd_cmd_in_size(nvdimm, cmd, desc, |
| 263 | i, buf); |
| 264 | |
Dan Williams | 31eca76 | 2016-04-28 16:23:43 -0700 | [diff] [blame] | 265 | if (call_pkg) { |
| 266 | /* skip over package wrapper */ |
| 267 | in_buf.buffer.pointer = (void *) &call_pkg->nd_payload; |
| 268 | in_buf.buffer.length = call_pkg->nd_size_in; |
Dan Williams | 62232e45 | 2015-06-08 14:27:06 -0400 | [diff] [blame] | 269 | } |
| 270 | |
Dan Williams | 31eca76 | 2016-04-28 16:23:43 -0700 | [diff] [blame] | 271 | if (IS_ENABLED(CONFIG_ACPI_NFIT_DEBUG)) { |
| 272 | dev_dbg(dev, "%s:%s cmd: %d: func: %d input length: %d\n", |
| 273 | __func__, dimm_name, cmd, func, |
| 274 | in_buf.buffer.length); |
| 275 | print_hex_dump_debug("nvdimm in ", DUMP_PREFIX_OFFSET, 4, 4, |
| 276 | in_buf.buffer.pointer, |
| 277 | min_t(u32, 256, in_buf.buffer.length), true); |
| 278 | } |
| 279 | |
| 280 | out_obj = acpi_evaluate_dsm(handle, uuid, 1, func, &in_obj); |
Dan Williams | 62232e45 | 2015-06-08 14:27:06 -0400 | [diff] [blame] | 281 | if (!out_obj) { |
| 282 | dev_dbg(dev, "%s:%s _DSM failed cmd: %s\n", __func__, dimm_name, |
| 283 | cmd_name); |
| 284 | return -EINVAL; |
| 285 | } |
| 286 | |
Dan Williams | 31eca76 | 2016-04-28 16:23:43 -0700 | [diff] [blame] | 287 | if (call_pkg) { |
| 288 | call_pkg->nd_fw_size = out_obj->buffer.length; |
| 289 | memcpy(call_pkg->nd_payload + call_pkg->nd_size_in, |
| 290 | out_obj->buffer.pointer, |
| 291 | min(call_pkg->nd_fw_size, call_pkg->nd_size_out)); |
| 292 | |
| 293 | ACPI_FREE(out_obj); |
| 294 | /* |
| 295 | * Need to support FW function w/o known size in advance. |
| 296 | * Caller can determine required size based upon nd_fw_size. |
| 297 | * If we return an error (like elsewhere) then caller wouldn't |
| 298 | * be able to rely upon data returned to make calculation. |
| 299 | */ |
| 300 | return 0; |
| 301 | } |
| 302 | |
Dan Williams | 62232e45 | 2015-06-08 14:27:06 -0400 | [diff] [blame] | 303 | if (out_obj->package.type != ACPI_TYPE_BUFFER) { |
| 304 | dev_dbg(dev, "%s:%s unexpected output object type cmd: %s type: %d\n", |
| 305 | __func__, dimm_name, cmd_name, out_obj->type); |
| 306 | rc = -EINVAL; |
| 307 | goto out; |
| 308 | } |
| 309 | |
| 310 | if (IS_ENABLED(CONFIG_ACPI_NFIT_DEBUG)) { |
| 311 | dev_dbg(dev, "%s:%s cmd: %s output length: %d\n", __func__, |
| 312 | dimm_name, cmd_name, out_obj->buffer.length); |
| 313 | print_hex_dump_debug(cmd_name, DUMP_PREFIX_OFFSET, 4, |
| 314 | 4, out_obj->buffer.pointer, min_t(u32, 128, |
| 315 | out_obj->buffer.length), true); |
| 316 | } |
| 317 | |
| 318 | for (i = 0, offset = 0; i < desc->out_num; i++) { |
| 319 | u32 out_size = nd_cmd_out_size(nvdimm, cmd, desc, i, buf, |
Dan Williams | efda1b5d | 2016-12-06 09:10:12 -0800 | [diff] [blame] | 320 | (u32 *) out_obj->buffer.pointer, |
| 321 | out_obj->buffer.length - offset); |
Dan Williams | 62232e45 | 2015-06-08 14:27:06 -0400 | [diff] [blame] | 322 | |
| 323 | if (offset + out_size > out_obj->buffer.length) { |
| 324 | dev_dbg(dev, "%s:%s output object underflow cmd: %s field: %d\n", |
| 325 | __func__, dimm_name, cmd_name, i); |
| 326 | break; |
| 327 | } |
| 328 | |
| 329 | if (in_buf.buffer.length + offset + out_size > buf_len) { |
| 330 | dev_dbg(dev, "%s:%s output overrun cmd: %s field: %d\n", |
| 331 | __func__, dimm_name, cmd_name, i); |
| 332 | rc = -ENXIO; |
| 333 | goto out; |
| 334 | } |
| 335 | memcpy(buf + in_buf.buffer.length + offset, |
| 336 | out_obj->buffer.pointer + offset, out_size); |
| 337 | offset += out_size; |
| 338 | } |
Dan Williams | 11294d6 | 2016-09-21 09:21:26 -0700 | [diff] [blame] | 339 | |
| 340 | /* |
| 341 | * Set fw_status for all the commands with a known format to be |
| 342 | * later interpreted by xlat_status(). |
| 343 | */ |
| 344 | if (i >= 1 && ((cmd >= ND_CMD_ARS_CAP && cmd <= ND_CMD_CLEAR_ERROR) |
| 345 | || (cmd >= ND_CMD_SMART && cmd <= ND_CMD_VENDOR))) |
| 346 | fw_status = *(u32 *) out_obj->buffer.pointer; |
| 347 | |
Dan Williams | 62232e45 | 2015-06-08 14:27:06 -0400 | [diff] [blame] | 348 | if (offset + in_buf.buffer.length < buf_len) { |
| 349 | if (i >= 1) { |
| 350 | /* |
| 351 | * status valid, return the number of bytes left |
| 352 | * unfilled in the output buffer |
| 353 | */ |
| 354 | rc = buf_len - offset - in_buf.buffer.length; |
Dan Williams | aef2533 | 2016-02-12 17:01:11 -0800 | [diff] [blame] | 355 | if (cmd_rc) |
Dan Williams | d6eb270 | 2016-12-06 15:06:55 -0800 | [diff] [blame] | 356 | *cmd_rc = xlat_status(nvdimm, buf, cmd, |
| 357 | fw_status); |
Dan Williams | 62232e45 | 2015-06-08 14:27:06 -0400 | [diff] [blame] | 358 | } else { |
| 359 | dev_err(dev, "%s:%s underrun cmd: %s buf_len: %d out_len: %d\n", |
| 360 | __func__, dimm_name, cmd_name, buf_len, |
| 361 | offset); |
| 362 | rc = -ENXIO; |
| 363 | } |
Dan Williams | 2eea658 | 2016-05-02 09:11:53 -0700 | [diff] [blame] | 364 | } else { |
Dan Williams | 62232e45 | 2015-06-08 14:27:06 -0400 | [diff] [blame] | 365 | rc = 0; |
Dan Williams | 2eea658 | 2016-05-02 09:11:53 -0700 | [diff] [blame] | 366 | if (cmd_rc) |
Dan Williams | d6eb270 | 2016-12-06 15:06:55 -0800 | [diff] [blame] | 367 | *cmd_rc = xlat_status(nvdimm, buf, cmd, fw_status); |
Dan Williams | 2eea658 | 2016-05-02 09:11:53 -0700 | [diff] [blame] | 368 | } |
Dan Williams | 62232e45 | 2015-06-08 14:27:06 -0400 | [diff] [blame] | 369 | |
| 370 | out: |
| 371 | ACPI_FREE(out_obj); |
| 372 | |
| 373 | return rc; |
Dan Williams | b94d523 | 2015-05-19 22:54:31 -0400 | [diff] [blame] | 374 | } |
Dan Williams | a7de92d | 2016-12-05 13:43:25 -0800 | [diff] [blame] | 375 | EXPORT_SYMBOL_GPL(acpi_nfit_ctl); |
Dan Williams | b94d523 | 2015-05-19 22:54:31 -0400 | [diff] [blame] | 376 | |
| 377 | static const char *spa_type_name(u16 type) |
| 378 | { |
| 379 | static const char *to_name[] = { |
| 380 | [NFIT_SPA_VOLATILE] = "volatile", |
| 381 | [NFIT_SPA_PM] = "pmem", |
| 382 | [NFIT_SPA_DCR] = "dimm-control-region", |
| 383 | [NFIT_SPA_BDW] = "block-data-window", |
| 384 | [NFIT_SPA_VDISK] = "volatile-disk", |
| 385 | [NFIT_SPA_VCD] = "volatile-cd", |
| 386 | [NFIT_SPA_PDISK] = "persistent-disk", |
| 387 | [NFIT_SPA_PCD] = "persistent-cd", |
| 388 | |
| 389 | }; |
| 390 | |
| 391 | if (type > NFIT_SPA_PCD) |
| 392 | return "unknown"; |
| 393 | |
| 394 | return to_name[type]; |
| 395 | } |
| 396 | |
Vishal Verma | 6839a6d | 2016-07-23 21:51:21 -0700 | [diff] [blame] | 397 | int nfit_spa_type(struct acpi_nfit_system_address *spa) |
Dan Williams | b94d523 | 2015-05-19 22:54:31 -0400 | [diff] [blame] | 398 | { |
| 399 | int i; |
| 400 | |
| 401 | for (i = 0; i < NFIT_UUID_MAX; i++) |
| 402 | if (memcmp(to_nfit_uuid(i), spa->range_guid, 16) == 0) |
| 403 | return i; |
| 404 | return -1; |
| 405 | } |
| 406 | |
| 407 | static bool add_spa(struct acpi_nfit_desc *acpi_desc, |
Vishal Verma | 2098516 | 2015-10-27 16:58:27 -0600 | [diff] [blame] | 408 | struct nfit_table_prev *prev, |
Dan Williams | b94d523 | 2015-05-19 22:54:31 -0400 | [diff] [blame] | 409 | struct acpi_nfit_system_address *spa) |
| 410 | { |
| 411 | struct device *dev = acpi_desc->dev; |
Vishal Verma | 2098516 | 2015-10-27 16:58:27 -0600 | [diff] [blame] | 412 | struct nfit_spa *nfit_spa; |
Dan Williams | b94d523 | 2015-05-19 22:54:31 -0400 | [diff] [blame] | 413 | |
Dan Williams | 3193204 | 2016-07-14 17:22:48 -0700 | [diff] [blame] | 414 | if (spa->header.length != sizeof(*spa)) |
| 415 | return false; |
| 416 | |
Vishal Verma | 2098516 | 2015-10-27 16:58:27 -0600 | [diff] [blame] | 417 | list_for_each_entry(nfit_spa, &prev->spas, list) { |
Dan Williams | 3193204 | 2016-07-14 17:22:48 -0700 | [diff] [blame] | 418 | if (memcmp(nfit_spa->spa, spa, sizeof(*spa)) == 0) { |
Vishal Verma | 2098516 | 2015-10-27 16:58:27 -0600 | [diff] [blame] | 419 | list_move_tail(&nfit_spa->list, &acpi_desc->spas); |
| 420 | return true; |
| 421 | } |
| 422 | } |
| 423 | |
Dan Williams | 3193204 | 2016-07-14 17:22:48 -0700 | [diff] [blame] | 424 | nfit_spa = devm_kzalloc(dev, sizeof(*nfit_spa) + sizeof(*spa), |
| 425 | GFP_KERNEL); |
Dan Williams | b94d523 | 2015-05-19 22:54:31 -0400 | [diff] [blame] | 426 | if (!nfit_spa) |
| 427 | return false; |
| 428 | INIT_LIST_HEAD(&nfit_spa->list); |
Dan Williams | 3193204 | 2016-07-14 17:22:48 -0700 | [diff] [blame] | 429 | memcpy(nfit_spa->spa, spa, sizeof(*spa)); |
Dan Williams | b94d523 | 2015-05-19 22:54:31 -0400 | [diff] [blame] | 430 | list_add_tail(&nfit_spa->list, &acpi_desc->spas); |
| 431 | dev_dbg(dev, "%s: spa index: %d type: %s\n", __func__, |
| 432 | spa->range_index, |
| 433 | spa_type_name(nfit_spa_type(spa))); |
| 434 | return true; |
| 435 | } |
| 436 | |
| 437 | static bool add_memdev(struct acpi_nfit_desc *acpi_desc, |
Vishal Verma | 2098516 | 2015-10-27 16:58:27 -0600 | [diff] [blame] | 438 | struct nfit_table_prev *prev, |
Dan Williams | b94d523 | 2015-05-19 22:54:31 -0400 | [diff] [blame] | 439 | struct acpi_nfit_memory_map *memdev) |
| 440 | { |
| 441 | struct device *dev = acpi_desc->dev; |
Vishal Verma | 2098516 | 2015-10-27 16:58:27 -0600 | [diff] [blame] | 442 | struct nfit_memdev *nfit_memdev; |
Dan Williams | b94d523 | 2015-05-19 22:54:31 -0400 | [diff] [blame] | 443 | |
Dan Williams | 3193204 | 2016-07-14 17:22:48 -0700 | [diff] [blame] | 444 | if (memdev->header.length != sizeof(*memdev)) |
| 445 | return false; |
| 446 | |
Vishal Verma | 2098516 | 2015-10-27 16:58:27 -0600 | [diff] [blame] | 447 | list_for_each_entry(nfit_memdev, &prev->memdevs, list) |
Dan Williams | 3193204 | 2016-07-14 17:22:48 -0700 | [diff] [blame] | 448 | if (memcmp(nfit_memdev->memdev, memdev, sizeof(*memdev)) == 0) { |
Vishal Verma | 2098516 | 2015-10-27 16:58:27 -0600 | [diff] [blame] | 449 | list_move_tail(&nfit_memdev->list, &acpi_desc->memdevs); |
| 450 | return true; |
| 451 | } |
| 452 | |
Dan Williams | 3193204 | 2016-07-14 17:22:48 -0700 | [diff] [blame] | 453 | nfit_memdev = devm_kzalloc(dev, sizeof(*nfit_memdev) + sizeof(*memdev), |
| 454 | GFP_KERNEL); |
Dan Williams | b94d523 | 2015-05-19 22:54:31 -0400 | [diff] [blame] | 455 | if (!nfit_memdev) |
| 456 | return false; |
| 457 | INIT_LIST_HEAD(&nfit_memdev->list); |
Dan Williams | 3193204 | 2016-07-14 17:22:48 -0700 | [diff] [blame] | 458 | memcpy(nfit_memdev->memdev, memdev, sizeof(*memdev)); |
Dan Williams | b94d523 | 2015-05-19 22:54:31 -0400 | [diff] [blame] | 459 | list_add_tail(&nfit_memdev->list, &acpi_desc->memdevs); |
| 460 | dev_dbg(dev, "%s: memdev handle: %#x spa: %d dcr: %d\n", |
| 461 | __func__, memdev->device_handle, memdev->range_index, |
| 462 | memdev->region_index); |
| 463 | return true; |
| 464 | } |
| 465 | |
Dan Williams | 3193204 | 2016-07-14 17:22:48 -0700 | [diff] [blame] | 466 | /* |
| 467 | * An implementation may provide a truncated control region if no block windows |
| 468 | * are defined. |
| 469 | */ |
| 470 | static size_t sizeof_dcr(struct acpi_nfit_control_region *dcr) |
| 471 | { |
| 472 | if (dcr->header.length < offsetof(struct acpi_nfit_control_region, |
| 473 | window_size)) |
| 474 | return 0; |
| 475 | if (dcr->windows) |
| 476 | return sizeof(*dcr); |
| 477 | return offsetof(struct acpi_nfit_control_region, window_size); |
| 478 | } |
| 479 | |
Dan Williams | b94d523 | 2015-05-19 22:54:31 -0400 | [diff] [blame] | 480 | static bool add_dcr(struct acpi_nfit_desc *acpi_desc, |
Vishal Verma | 2098516 | 2015-10-27 16:58:27 -0600 | [diff] [blame] | 481 | struct nfit_table_prev *prev, |
Dan Williams | b94d523 | 2015-05-19 22:54:31 -0400 | [diff] [blame] | 482 | struct acpi_nfit_control_region *dcr) |
| 483 | { |
| 484 | struct device *dev = acpi_desc->dev; |
Vishal Verma | 2098516 | 2015-10-27 16:58:27 -0600 | [diff] [blame] | 485 | struct nfit_dcr *nfit_dcr; |
Dan Williams | b94d523 | 2015-05-19 22:54:31 -0400 | [diff] [blame] | 486 | |
Dan Williams | 3193204 | 2016-07-14 17:22:48 -0700 | [diff] [blame] | 487 | if (!sizeof_dcr(dcr)) |
| 488 | return false; |
| 489 | |
Vishal Verma | 2098516 | 2015-10-27 16:58:27 -0600 | [diff] [blame] | 490 | list_for_each_entry(nfit_dcr, &prev->dcrs, list) |
Dan Williams | 3193204 | 2016-07-14 17:22:48 -0700 | [diff] [blame] | 491 | if (memcmp(nfit_dcr->dcr, dcr, sizeof_dcr(dcr)) == 0) { |
Vishal Verma | 2098516 | 2015-10-27 16:58:27 -0600 | [diff] [blame] | 492 | list_move_tail(&nfit_dcr->list, &acpi_desc->dcrs); |
| 493 | return true; |
| 494 | } |
| 495 | |
Dan Williams | 3193204 | 2016-07-14 17:22:48 -0700 | [diff] [blame] | 496 | nfit_dcr = devm_kzalloc(dev, sizeof(*nfit_dcr) + sizeof(*dcr), |
| 497 | GFP_KERNEL); |
Dan Williams | b94d523 | 2015-05-19 22:54:31 -0400 | [diff] [blame] | 498 | if (!nfit_dcr) |
| 499 | return false; |
| 500 | INIT_LIST_HEAD(&nfit_dcr->list); |
Dan Williams | 3193204 | 2016-07-14 17:22:48 -0700 | [diff] [blame] | 501 | memcpy(nfit_dcr->dcr, dcr, sizeof_dcr(dcr)); |
Dan Williams | b94d523 | 2015-05-19 22:54:31 -0400 | [diff] [blame] | 502 | list_add_tail(&nfit_dcr->list, &acpi_desc->dcrs); |
| 503 | dev_dbg(dev, "%s: dcr index: %d windows: %d\n", __func__, |
| 504 | dcr->region_index, dcr->windows); |
| 505 | return true; |
| 506 | } |
| 507 | |
| 508 | static bool add_bdw(struct acpi_nfit_desc *acpi_desc, |
Vishal Verma | 2098516 | 2015-10-27 16:58:27 -0600 | [diff] [blame] | 509 | struct nfit_table_prev *prev, |
Dan Williams | b94d523 | 2015-05-19 22:54:31 -0400 | [diff] [blame] | 510 | struct acpi_nfit_data_region *bdw) |
| 511 | { |
| 512 | struct device *dev = acpi_desc->dev; |
Vishal Verma | 2098516 | 2015-10-27 16:58:27 -0600 | [diff] [blame] | 513 | struct nfit_bdw *nfit_bdw; |
Dan Williams | b94d523 | 2015-05-19 22:54:31 -0400 | [diff] [blame] | 514 | |
Dan Williams | 3193204 | 2016-07-14 17:22:48 -0700 | [diff] [blame] | 515 | if (bdw->header.length != sizeof(*bdw)) |
| 516 | return false; |
Vishal Verma | 2098516 | 2015-10-27 16:58:27 -0600 | [diff] [blame] | 517 | list_for_each_entry(nfit_bdw, &prev->bdws, list) |
Dan Williams | 3193204 | 2016-07-14 17:22:48 -0700 | [diff] [blame] | 518 | if (memcmp(nfit_bdw->bdw, bdw, sizeof(*bdw)) == 0) { |
Vishal Verma | 2098516 | 2015-10-27 16:58:27 -0600 | [diff] [blame] | 519 | list_move_tail(&nfit_bdw->list, &acpi_desc->bdws); |
| 520 | return true; |
| 521 | } |
| 522 | |
Dan Williams | 3193204 | 2016-07-14 17:22:48 -0700 | [diff] [blame] | 523 | nfit_bdw = devm_kzalloc(dev, sizeof(*nfit_bdw) + sizeof(*bdw), |
| 524 | GFP_KERNEL); |
Dan Williams | b94d523 | 2015-05-19 22:54:31 -0400 | [diff] [blame] | 525 | if (!nfit_bdw) |
| 526 | return false; |
| 527 | INIT_LIST_HEAD(&nfit_bdw->list); |
Dan Williams | 3193204 | 2016-07-14 17:22:48 -0700 | [diff] [blame] | 528 | memcpy(nfit_bdw->bdw, bdw, sizeof(*bdw)); |
Dan Williams | b94d523 | 2015-05-19 22:54:31 -0400 | [diff] [blame] | 529 | list_add_tail(&nfit_bdw->list, &acpi_desc->bdws); |
| 530 | dev_dbg(dev, "%s: bdw dcr: %d windows: %d\n", __func__, |
| 531 | bdw->region_index, bdw->windows); |
| 532 | return true; |
| 533 | } |
| 534 | |
Dan Williams | 3193204 | 2016-07-14 17:22:48 -0700 | [diff] [blame] | 535 | static size_t sizeof_idt(struct acpi_nfit_interleave *idt) |
| 536 | { |
| 537 | if (idt->header.length < sizeof(*idt)) |
| 538 | return 0; |
| 539 | return sizeof(*idt) + sizeof(u32) * (idt->line_count - 1); |
| 540 | } |
| 541 | |
Ross Zwisler | 047fc8a | 2015-06-25 04:21:02 -0400 | [diff] [blame] | 542 | static bool add_idt(struct acpi_nfit_desc *acpi_desc, |
Vishal Verma | 2098516 | 2015-10-27 16:58:27 -0600 | [diff] [blame] | 543 | struct nfit_table_prev *prev, |
Ross Zwisler | 047fc8a | 2015-06-25 04:21:02 -0400 | [diff] [blame] | 544 | struct acpi_nfit_interleave *idt) |
| 545 | { |
| 546 | struct device *dev = acpi_desc->dev; |
Vishal Verma | 2098516 | 2015-10-27 16:58:27 -0600 | [diff] [blame] | 547 | struct nfit_idt *nfit_idt; |
Ross Zwisler | 047fc8a | 2015-06-25 04:21:02 -0400 | [diff] [blame] | 548 | |
Dan Williams | 3193204 | 2016-07-14 17:22:48 -0700 | [diff] [blame] | 549 | if (!sizeof_idt(idt)) |
| 550 | return false; |
| 551 | |
| 552 | list_for_each_entry(nfit_idt, &prev->idts, list) { |
| 553 | if (sizeof_idt(nfit_idt->idt) != sizeof_idt(idt)) |
| 554 | continue; |
| 555 | |
| 556 | if (memcmp(nfit_idt->idt, idt, sizeof_idt(idt)) == 0) { |
Vishal Verma | 2098516 | 2015-10-27 16:58:27 -0600 | [diff] [blame] | 557 | list_move_tail(&nfit_idt->list, &acpi_desc->idts); |
| 558 | return true; |
| 559 | } |
Dan Williams | 3193204 | 2016-07-14 17:22:48 -0700 | [diff] [blame] | 560 | } |
Vishal Verma | 2098516 | 2015-10-27 16:58:27 -0600 | [diff] [blame] | 561 | |
Dan Williams | 3193204 | 2016-07-14 17:22:48 -0700 | [diff] [blame] | 562 | nfit_idt = devm_kzalloc(dev, sizeof(*nfit_idt) + sizeof_idt(idt), |
| 563 | GFP_KERNEL); |
Ross Zwisler | 047fc8a | 2015-06-25 04:21:02 -0400 | [diff] [blame] | 564 | if (!nfit_idt) |
| 565 | return false; |
| 566 | INIT_LIST_HEAD(&nfit_idt->list); |
Dan Williams | 3193204 | 2016-07-14 17:22:48 -0700 | [diff] [blame] | 567 | memcpy(nfit_idt->idt, idt, sizeof_idt(idt)); |
Ross Zwisler | 047fc8a | 2015-06-25 04:21:02 -0400 | [diff] [blame] | 568 | list_add_tail(&nfit_idt->list, &acpi_desc->idts); |
| 569 | dev_dbg(dev, "%s: idt index: %d num_lines: %d\n", __func__, |
| 570 | idt->interleave_index, idt->line_count); |
| 571 | return true; |
| 572 | } |
| 573 | |
Dan Williams | 3193204 | 2016-07-14 17:22:48 -0700 | [diff] [blame] | 574 | static size_t sizeof_flush(struct acpi_nfit_flush_address *flush) |
| 575 | { |
| 576 | if (flush->header.length < sizeof(*flush)) |
| 577 | return 0; |
| 578 | return sizeof(*flush) + sizeof(u64) * (flush->hint_count - 1); |
| 579 | } |
| 580 | |
Ross Zwisler | c2ad295 | 2015-07-10 11:06:13 -0600 | [diff] [blame] | 581 | static bool add_flush(struct acpi_nfit_desc *acpi_desc, |
Vishal Verma | 2098516 | 2015-10-27 16:58:27 -0600 | [diff] [blame] | 582 | struct nfit_table_prev *prev, |
Ross Zwisler | c2ad295 | 2015-07-10 11:06:13 -0600 | [diff] [blame] | 583 | struct acpi_nfit_flush_address *flush) |
| 584 | { |
| 585 | struct device *dev = acpi_desc->dev; |
Vishal Verma | 2098516 | 2015-10-27 16:58:27 -0600 | [diff] [blame] | 586 | struct nfit_flush *nfit_flush; |
Ross Zwisler | c2ad295 | 2015-07-10 11:06:13 -0600 | [diff] [blame] | 587 | |
Dan Williams | 3193204 | 2016-07-14 17:22:48 -0700 | [diff] [blame] | 588 | if (!sizeof_flush(flush)) |
| 589 | return false; |
| 590 | |
| 591 | list_for_each_entry(nfit_flush, &prev->flushes, list) { |
| 592 | if (sizeof_flush(nfit_flush->flush) != sizeof_flush(flush)) |
| 593 | continue; |
| 594 | |
| 595 | if (memcmp(nfit_flush->flush, flush, |
| 596 | sizeof_flush(flush)) == 0) { |
Vishal Verma | 2098516 | 2015-10-27 16:58:27 -0600 | [diff] [blame] | 597 | list_move_tail(&nfit_flush->list, &acpi_desc->flushes); |
| 598 | return true; |
| 599 | } |
Dan Williams | 3193204 | 2016-07-14 17:22:48 -0700 | [diff] [blame] | 600 | } |
Vishal Verma | 2098516 | 2015-10-27 16:58:27 -0600 | [diff] [blame] | 601 | |
Dan Williams | 3193204 | 2016-07-14 17:22:48 -0700 | [diff] [blame] | 602 | nfit_flush = devm_kzalloc(dev, sizeof(*nfit_flush) |
| 603 | + sizeof_flush(flush), GFP_KERNEL); |
Ross Zwisler | c2ad295 | 2015-07-10 11:06:13 -0600 | [diff] [blame] | 604 | if (!nfit_flush) |
| 605 | return false; |
| 606 | INIT_LIST_HEAD(&nfit_flush->list); |
Dan Williams | 3193204 | 2016-07-14 17:22:48 -0700 | [diff] [blame] | 607 | memcpy(nfit_flush->flush, flush, sizeof_flush(flush)); |
Ross Zwisler | c2ad295 | 2015-07-10 11:06:13 -0600 | [diff] [blame] | 608 | list_add_tail(&nfit_flush->list, &acpi_desc->flushes); |
| 609 | dev_dbg(dev, "%s: nfit_flush handle: %d hint_count: %d\n", __func__, |
| 610 | flush->device_handle, flush->hint_count); |
| 611 | return true; |
| 612 | } |
| 613 | |
Vishal Verma | 2098516 | 2015-10-27 16:58:27 -0600 | [diff] [blame] | 614 | static void *add_table(struct acpi_nfit_desc *acpi_desc, |
| 615 | struct nfit_table_prev *prev, void *table, const void *end) |
Dan Williams | b94d523 | 2015-05-19 22:54:31 -0400 | [diff] [blame] | 616 | { |
| 617 | struct device *dev = acpi_desc->dev; |
| 618 | struct acpi_nfit_header *hdr; |
| 619 | void *err = ERR_PTR(-ENOMEM); |
| 620 | |
| 621 | if (table >= end) |
| 622 | return NULL; |
| 623 | |
| 624 | hdr = table; |
Vishal Verma | 564d501 | 2015-10-27 16:58:26 -0600 | [diff] [blame] | 625 | if (!hdr->length) { |
| 626 | dev_warn(dev, "found a zero length table '%d' parsing nfit\n", |
| 627 | hdr->type); |
| 628 | return NULL; |
| 629 | } |
| 630 | |
Dan Williams | b94d523 | 2015-05-19 22:54:31 -0400 | [diff] [blame] | 631 | switch (hdr->type) { |
| 632 | case ACPI_NFIT_TYPE_SYSTEM_ADDRESS: |
Vishal Verma | 2098516 | 2015-10-27 16:58:27 -0600 | [diff] [blame] | 633 | if (!add_spa(acpi_desc, prev, table)) |
Dan Williams | b94d523 | 2015-05-19 22:54:31 -0400 | [diff] [blame] | 634 | return err; |
| 635 | break; |
| 636 | case ACPI_NFIT_TYPE_MEMORY_MAP: |
Vishal Verma | 2098516 | 2015-10-27 16:58:27 -0600 | [diff] [blame] | 637 | if (!add_memdev(acpi_desc, prev, table)) |
Dan Williams | b94d523 | 2015-05-19 22:54:31 -0400 | [diff] [blame] | 638 | return err; |
| 639 | break; |
| 640 | case ACPI_NFIT_TYPE_CONTROL_REGION: |
Vishal Verma | 2098516 | 2015-10-27 16:58:27 -0600 | [diff] [blame] | 641 | if (!add_dcr(acpi_desc, prev, table)) |
Dan Williams | b94d523 | 2015-05-19 22:54:31 -0400 | [diff] [blame] | 642 | return err; |
| 643 | break; |
| 644 | case ACPI_NFIT_TYPE_DATA_REGION: |
Vishal Verma | 2098516 | 2015-10-27 16:58:27 -0600 | [diff] [blame] | 645 | if (!add_bdw(acpi_desc, prev, table)) |
Dan Williams | b94d523 | 2015-05-19 22:54:31 -0400 | [diff] [blame] | 646 | return err; |
| 647 | break; |
Dan Williams | b94d523 | 2015-05-19 22:54:31 -0400 | [diff] [blame] | 648 | case ACPI_NFIT_TYPE_INTERLEAVE: |
Vishal Verma | 2098516 | 2015-10-27 16:58:27 -0600 | [diff] [blame] | 649 | if (!add_idt(acpi_desc, prev, table)) |
Ross Zwisler | 047fc8a | 2015-06-25 04:21:02 -0400 | [diff] [blame] | 650 | return err; |
Dan Williams | b94d523 | 2015-05-19 22:54:31 -0400 | [diff] [blame] | 651 | break; |
| 652 | case ACPI_NFIT_TYPE_FLUSH_ADDRESS: |
Vishal Verma | 2098516 | 2015-10-27 16:58:27 -0600 | [diff] [blame] | 653 | if (!add_flush(acpi_desc, prev, table)) |
Ross Zwisler | c2ad295 | 2015-07-10 11:06:13 -0600 | [diff] [blame] | 654 | return err; |
Dan Williams | b94d523 | 2015-05-19 22:54:31 -0400 | [diff] [blame] | 655 | break; |
| 656 | case ACPI_NFIT_TYPE_SMBIOS: |
| 657 | dev_dbg(dev, "%s: smbios\n", __func__); |
| 658 | break; |
| 659 | default: |
| 660 | dev_err(dev, "unknown table '%d' parsing nfit\n", hdr->type); |
| 661 | break; |
| 662 | } |
| 663 | |
| 664 | return table + hdr->length; |
| 665 | } |
| 666 | |
| 667 | static void nfit_mem_find_spa_bdw(struct acpi_nfit_desc *acpi_desc, |
| 668 | struct nfit_mem *nfit_mem) |
| 669 | { |
| 670 | u32 device_handle = __to_nfit_memdev(nfit_mem)->device_handle; |
| 671 | u16 dcr = nfit_mem->dcr->region_index; |
| 672 | struct nfit_spa *nfit_spa; |
| 673 | |
| 674 | list_for_each_entry(nfit_spa, &acpi_desc->spas, list) { |
| 675 | u16 range_index = nfit_spa->spa->range_index; |
| 676 | int type = nfit_spa_type(nfit_spa->spa); |
| 677 | struct nfit_memdev *nfit_memdev; |
| 678 | |
| 679 | if (type != NFIT_SPA_BDW) |
| 680 | continue; |
| 681 | |
| 682 | list_for_each_entry(nfit_memdev, &acpi_desc->memdevs, list) { |
| 683 | if (nfit_memdev->memdev->range_index != range_index) |
| 684 | continue; |
| 685 | if (nfit_memdev->memdev->device_handle != device_handle) |
| 686 | continue; |
| 687 | if (nfit_memdev->memdev->region_index != dcr) |
| 688 | continue; |
| 689 | |
| 690 | nfit_mem->spa_bdw = nfit_spa->spa; |
| 691 | return; |
| 692 | } |
| 693 | } |
| 694 | |
| 695 | dev_dbg(acpi_desc->dev, "SPA-BDW not found for SPA-DCR %d\n", |
| 696 | nfit_mem->spa_dcr->range_index); |
| 697 | nfit_mem->bdw = NULL; |
| 698 | } |
| 699 | |
Dan Williams | 6697b2c | 2016-02-04 16:51:00 -0800 | [diff] [blame] | 700 | static void nfit_mem_init_bdw(struct acpi_nfit_desc *acpi_desc, |
Dan Williams | b94d523 | 2015-05-19 22:54:31 -0400 | [diff] [blame] | 701 | struct nfit_mem *nfit_mem, struct acpi_nfit_system_address *spa) |
| 702 | { |
| 703 | u16 dcr = __to_nfit_memdev(nfit_mem)->region_index; |
Ross Zwisler | 047fc8a | 2015-06-25 04:21:02 -0400 | [diff] [blame] | 704 | struct nfit_memdev *nfit_memdev; |
Dan Williams | b94d523 | 2015-05-19 22:54:31 -0400 | [diff] [blame] | 705 | struct nfit_bdw *nfit_bdw; |
Ross Zwisler | 047fc8a | 2015-06-25 04:21:02 -0400 | [diff] [blame] | 706 | struct nfit_idt *nfit_idt; |
| 707 | u16 idt_idx, range_index; |
Dan Williams | b94d523 | 2015-05-19 22:54:31 -0400 | [diff] [blame] | 708 | |
Dan Williams | b94d523 | 2015-05-19 22:54:31 -0400 | [diff] [blame] | 709 | list_for_each_entry(nfit_bdw, &acpi_desc->bdws, list) { |
| 710 | if (nfit_bdw->bdw->region_index != dcr) |
| 711 | continue; |
| 712 | nfit_mem->bdw = nfit_bdw->bdw; |
| 713 | break; |
| 714 | } |
| 715 | |
| 716 | if (!nfit_mem->bdw) |
Dan Williams | 6697b2c | 2016-02-04 16:51:00 -0800 | [diff] [blame] | 717 | return; |
Dan Williams | b94d523 | 2015-05-19 22:54:31 -0400 | [diff] [blame] | 718 | |
| 719 | nfit_mem_find_spa_bdw(acpi_desc, nfit_mem); |
Ross Zwisler | 047fc8a | 2015-06-25 04:21:02 -0400 | [diff] [blame] | 720 | |
| 721 | if (!nfit_mem->spa_bdw) |
Dan Williams | 6697b2c | 2016-02-04 16:51:00 -0800 | [diff] [blame] | 722 | return; |
Ross Zwisler | 047fc8a | 2015-06-25 04:21:02 -0400 | [diff] [blame] | 723 | |
| 724 | range_index = nfit_mem->spa_bdw->range_index; |
| 725 | list_for_each_entry(nfit_memdev, &acpi_desc->memdevs, list) { |
| 726 | if (nfit_memdev->memdev->range_index != range_index || |
| 727 | nfit_memdev->memdev->region_index != dcr) |
| 728 | continue; |
| 729 | nfit_mem->memdev_bdw = nfit_memdev->memdev; |
| 730 | idt_idx = nfit_memdev->memdev->interleave_index; |
| 731 | list_for_each_entry(nfit_idt, &acpi_desc->idts, list) { |
| 732 | if (nfit_idt->idt->interleave_index != idt_idx) |
| 733 | continue; |
| 734 | nfit_mem->idt_bdw = nfit_idt->idt; |
| 735 | break; |
| 736 | } |
| 737 | break; |
| 738 | } |
Dan Williams | b94d523 | 2015-05-19 22:54:31 -0400 | [diff] [blame] | 739 | } |
| 740 | |
Dan Williams | 1499934 | 2017-04-13 19:46:36 -0700 | [diff] [blame^] | 741 | static int __nfit_mem_init(struct acpi_nfit_desc *acpi_desc, |
Dan Williams | b94d523 | 2015-05-19 22:54:31 -0400 | [diff] [blame] | 742 | struct acpi_nfit_system_address *spa) |
| 743 | { |
| 744 | struct nfit_mem *nfit_mem, *found; |
| 745 | struct nfit_memdev *nfit_memdev; |
Dan Williams | 1499934 | 2017-04-13 19:46:36 -0700 | [diff] [blame^] | 746 | int type = spa ? nfit_spa_type(spa) : 0; |
Dan Williams | b94d523 | 2015-05-19 22:54:31 -0400 | [diff] [blame] | 747 | |
| 748 | switch (type) { |
| 749 | case NFIT_SPA_DCR: |
| 750 | case NFIT_SPA_PM: |
| 751 | break; |
| 752 | default: |
Dan Williams | 1499934 | 2017-04-13 19:46:36 -0700 | [diff] [blame^] | 753 | if (spa) |
| 754 | return 0; |
Dan Williams | b94d523 | 2015-05-19 22:54:31 -0400 | [diff] [blame] | 755 | } |
| 756 | |
Dan Williams | 1499934 | 2017-04-13 19:46:36 -0700 | [diff] [blame^] | 757 | /* |
| 758 | * This loop runs in two modes, when a dimm is mapped the loop |
| 759 | * adds memdev associations to an existing dimm, or creates a |
| 760 | * dimm. In the unmapped dimm case this loop sweeps for memdev |
| 761 | * instances with an invalid / zero range_index and adds those |
| 762 | * dimms without spa associations. |
| 763 | */ |
Dan Williams | b94d523 | 2015-05-19 22:54:31 -0400 | [diff] [blame] | 764 | list_for_each_entry(nfit_memdev, &acpi_desc->memdevs, list) { |
Dan Williams | ad9ac5e | 2016-05-26 11:38:08 -0700 | [diff] [blame] | 765 | struct nfit_flush *nfit_flush; |
Dan Williams | 6697b2c | 2016-02-04 16:51:00 -0800 | [diff] [blame] | 766 | struct nfit_dcr *nfit_dcr; |
| 767 | u32 device_handle; |
| 768 | u16 dcr; |
Dan Williams | b94d523 | 2015-05-19 22:54:31 -0400 | [diff] [blame] | 769 | |
Dan Williams | 1499934 | 2017-04-13 19:46:36 -0700 | [diff] [blame^] | 770 | if (spa && nfit_memdev->memdev->range_index != spa->range_index) |
| 771 | continue; |
| 772 | if (!spa && nfit_memdev->memdev->range_index) |
Dan Williams | b94d523 | 2015-05-19 22:54:31 -0400 | [diff] [blame] | 773 | continue; |
| 774 | found = NULL; |
| 775 | dcr = nfit_memdev->memdev->region_index; |
Dan Williams | 6697b2c | 2016-02-04 16:51:00 -0800 | [diff] [blame] | 776 | device_handle = nfit_memdev->memdev->device_handle; |
Dan Williams | b94d523 | 2015-05-19 22:54:31 -0400 | [diff] [blame] | 777 | list_for_each_entry(nfit_mem, &acpi_desc->dimms, list) |
Dan Williams | 6697b2c | 2016-02-04 16:51:00 -0800 | [diff] [blame] | 778 | if (__to_nfit_memdev(nfit_mem)->device_handle |
| 779 | == device_handle) { |
Dan Williams | b94d523 | 2015-05-19 22:54:31 -0400 | [diff] [blame] | 780 | found = nfit_mem; |
| 781 | break; |
| 782 | } |
| 783 | |
| 784 | if (found) |
| 785 | nfit_mem = found; |
| 786 | else { |
| 787 | nfit_mem = devm_kzalloc(acpi_desc->dev, |
| 788 | sizeof(*nfit_mem), GFP_KERNEL); |
| 789 | if (!nfit_mem) |
| 790 | return -ENOMEM; |
| 791 | INIT_LIST_HEAD(&nfit_mem->list); |
Dan Williams | 8cc6ddf | 2016-04-05 15:26:50 -0700 | [diff] [blame] | 792 | nfit_mem->acpi_desc = acpi_desc; |
Dan Williams | 6697b2c | 2016-02-04 16:51:00 -0800 | [diff] [blame] | 793 | list_add(&nfit_mem->list, &acpi_desc->dimms); |
| 794 | } |
| 795 | |
| 796 | list_for_each_entry(nfit_dcr, &acpi_desc->dcrs, list) { |
| 797 | if (nfit_dcr->dcr->region_index != dcr) |
| 798 | continue; |
| 799 | /* |
| 800 | * Record the control region for the dimm. For |
| 801 | * the ACPI 6.1 case, where there are separate |
| 802 | * control regions for the pmem vs blk |
| 803 | * interfaces, be sure to record the extended |
| 804 | * blk details. |
| 805 | */ |
| 806 | if (!nfit_mem->dcr) |
| 807 | nfit_mem->dcr = nfit_dcr->dcr; |
| 808 | else if (nfit_mem->dcr->windows == 0 |
| 809 | && nfit_dcr->dcr->windows) |
| 810 | nfit_mem->dcr = nfit_dcr->dcr; |
| 811 | break; |
| 812 | } |
| 813 | |
Dan Williams | ad9ac5e | 2016-05-26 11:38:08 -0700 | [diff] [blame] | 814 | list_for_each_entry(nfit_flush, &acpi_desc->flushes, list) { |
Dan Williams | e5ae3b2 | 2016-06-07 17:00:04 -0700 | [diff] [blame] | 815 | struct acpi_nfit_flush_address *flush; |
| 816 | u16 i; |
| 817 | |
Dan Williams | ad9ac5e | 2016-05-26 11:38:08 -0700 | [diff] [blame] | 818 | if (nfit_flush->flush->device_handle != device_handle) |
| 819 | continue; |
| 820 | nfit_mem->nfit_flush = nfit_flush; |
Dan Williams | e5ae3b2 | 2016-06-07 17:00:04 -0700 | [diff] [blame] | 821 | flush = nfit_flush->flush; |
| 822 | nfit_mem->flush_wpq = devm_kzalloc(acpi_desc->dev, |
| 823 | flush->hint_count |
| 824 | * sizeof(struct resource), GFP_KERNEL); |
| 825 | if (!nfit_mem->flush_wpq) |
| 826 | return -ENOMEM; |
| 827 | for (i = 0; i < flush->hint_count; i++) { |
| 828 | struct resource *res = &nfit_mem->flush_wpq[i]; |
| 829 | |
| 830 | res->start = flush->hint_address[i]; |
| 831 | res->end = res->start + 8 - 1; |
| 832 | } |
Dan Williams | ad9ac5e | 2016-05-26 11:38:08 -0700 | [diff] [blame] | 833 | break; |
| 834 | } |
| 835 | |
Dan Williams | 6697b2c | 2016-02-04 16:51:00 -0800 | [diff] [blame] | 836 | if (dcr && !nfit_mem->dcr) { |
| 837 | dev_err(acpi_desc->dev, "SPA %d missing DCR %d\n", |
| 838 | spa->range_index, dcr); |
| 839 | return -ENODEV; |
Dan Williams | b94d523 | 2015-05-19 22:54:31 -0400 | [diff] [blame] | 840 | } |
| 841 | |
| 842 | if (type == NFIT_SPA_DCR) { |
Ross Zwisler | 047fc8a | 2015-06-25 04:21:02 -0400 | [diff] [blame] | 843 | struct nfit_idt *nfit_idt; |
| 844 | u16 idt_idx; |
| 845 | |
Dan Williams | b94d523 | 2015-05-19 22:54:31 -0400 | [diff] [blame] | 846 | /* multiple dimms may share a SPA when interleaved */ |
| 847 | nfit_mem->spa_dcr = spa; |
| 848 | nfit_mem->memdev_dcr = nfit_memdev->memdev; |
Ross Zwisler | 047fc8a | 2015-06-25 04:21:02 -0400 | [diff] [blame] | 849 | idt_idx = nfit_memdev->memdev->interleave_index; |
| 850 | list_for_each_entry(nfit_idt, &acpi_desc->idts, list) { |
| 851 | if (nfit_idt->idt->interleave_index != idt_idx) |
| 852 | continue; |
| 853 | nfit_mem->idt_dcr = nfit_idt->idt; |
| 854 | break; |
| 855 | } |
Dan Williams | 6697b2c | 2016-02-04 16:51:00 -0800 | [diff] [blame] | 856 | nfit_mem_init_bdw(acpi_desc, nfit_mem, spa); |
Dan Williams | 1499934 | 2017-04-13 19:46:36 -0700 | [diff] [blame^] | 857 | } else if (type == NFIT_SPA_PM) { |
Dan Williams | b94d523 | 2015-05-19 22:54:31 -0400 | [diff] [blame] | 858 | /* |
| 859 | * A single dimm may belong to multiple SPA-PM |
| 860 | * ranges, record at least one in addition to |
| 861 | * any SPA-DCR range. |
| 862 | */ |
| 863 | nfit_mem->memdev_pmem = nfit_memdev->memdev; |
Dan Williams | 1499934 | 2017-04-13 19:46:36 -0700 | [diff] [blame^] | 864 | } else |
| 865 | nfit_mem->memdev_dcr = nfit_memdev->memdev; |
Dan Williams | b94d523 | 2015-05-19 22:54:31 -0400 | [diff] [blame] | 866 | } |
| 867 | |
| 868 | return 0; |
| 869 | } |
| 870 | |
| 871 | static int nfit_mem_cmp(void *priv, struct list_head *_a, struct list_head *_b) |
| 872 | { |
| 873 | struct nfit_mem *a = container_of(_a, typeof(*a), list); |
| 874 | struct nfit_mem *b = container_of(_b, typeof(*b), list); |
| 875 | u32 handleA, handleB; |
| 876 | |
| 877 | handleA = __to_nfit_memdev(a)->device_handle; |
| 878 | handleB = __to_nfit_memdev(b)->device_handle; |
| 879 | if (handleA < handleB) |
| 880 | return -1; |
| 881 | else if (handleA > handleB) |
| 882 | return 1; |
| 883 | return 0; |
| 884 | } |
| 885 | |
| 886 | static int nfit_mem_init(struct acpi_nfit_desc *acpi_desc) |
| 887 | { |
| 888 | struct nfit_spa *nfit_spa; |
Dan Williams | 1499934 | 2017-04-13 19:46:36 -0700 | [diff] [blame^] | 889 | int rc; |
| 890 | |
Dan Williams | b94d523 | 2015-05-19 22:54:31 -0400 | [diff] [blame] | 891 | |
| 892 | /* |
| 893 | * For each SPA-DCR or SPA-PMEM address range find its |
| 894 | * corresponding MEMDEV(s). From each MEMDEV find the |
| 895 | * corresponding DCR. Then, if we're operating on a SPA-DCR, |
| 896 | * try to find a SPA-BDW and a corresponding BDW that references |
| 897 | * the DCR. Throw it all into an nfit_mem object. Note, that |
| 898 | * BDWs are optional. |
| 899 | */ |
| 900 | list_for_each_entry(nfit_spa, &acpi_desc->spas, list) { |
Dan Williams | 1499934 | 2017-04-13 19:46:36 -0700 | [diff] [blame^] | 901 | rc = __nfit_mem_init(acpi_desc, nfit_spa->spa); |
Dan Williams | b94d523 | 2015-05-19 22:54:31 -0400 | [diff] [blame] | 902 | if (rc) |
| 903 | return rc; |
| 904 | } |
| 905 | |
Dan Williams | 1499934 | 2017-04-13 19:46:36 -0700 | [diff] [blame^] | 906 | /* |
| 907 | * If a DIMM has failed to be mapped into SPA there will be no |
| 908 | * SPA entries above. Find and register all the unmapped DIMMs |
| 909 | * for reporting and recovery purposes. |
| 910 | */ |
| 911 | rc = __nfit_mem_init(acpi_desc, NULL); |
| 912 | if (rc) |
| 913 | return rc; |
| 914 | |
Dan Williams | b94d523 | 2015-05-19 22:54:31 -0400 | [diff] [blame] | 915 | list_sort(NULL, &acpi_desc->dimms, nfit_mem_cmp); |
| 916 | |
| 917 | return 0; |
| 918 | } |
| 919 | |
Dan Williams | 45def22 | 2015-04-26 19:26:48 -0400 | [diff] [blame] | 920 | static ssize_t revision_show(struct device *dev, |
| 921 | struct device_attribute *attr, char *buf) |
| 922 | { |
| 923 | struct nvdimm_bus *nvdimm_bus = to_nvdimm_bus(dev); |
| 924 | struct nvdimm_bus_descriptor *nd_desc = to_nd_desc(nvdimm_bus); |
| 925 | struct acpi_nfit_desc *acpi_desc = to_acpi_desc(nd_desc); |
| 926 | |
Linda Knippers | 6b577c9 | 2015-11-20 19:05:49 -0500 | [diff] [blame] | 927 | return sprintf(buf, "%d\n", acpi_desc->acpi_header.revision); |
Dan Williams | 45def22 | 2015-04-26 19:26:48 -0400 | [diff] [blame] | 928 | } |
| 929 | static DEVICE_ATTR_RO(revision); |
| 930 | |
Vishal Verma | 9ffd635 | 2016-09-30 17:19:29 -0600 | [diff] [blame] | 931 | static ssize_t hw_error_scrub_show(struct device *dev, |
| 932 | struct device_attribute *attr, char *buf) |
| 933 | { |
| 934 | struct nvdimm_bus *nvdimm_bus = to_nvdimm_bus(dev); |
| 935 | struct nvdimm_bus_descriptor *nd_desc = to_nd_desc(nvdimm_bus); |
| 936 | struct acpi_nfit_desc *acpi_desc = to_acpi_desc(nd_desc); |
| 937 | |
| 938 | return sprintf(buf, "%d\n", acpi_desc->scrub_mode); |
| 939 | } |
| 940 | |
| 941 | /* |
| 942 | * The 'hw_error_scrub' attribute can have the following values written to it: |
| 943 | * '0': Switch to the default mode where an exception will only insert |
| 944 | * the address of the memory error into the poison and badblocks lists. |
| 945 | * '1': Enable a full scrub to happen if an exception for a memory error is |
| 946 | * received. |
| 947 | */ |
| 948 | static ssize_t hw_error_scrub_store(struct device *dev, |
| 949 | struct device_attribute *attr, const char *buf, size_t size) |
| 950 | { |
| 951 | struct nvdimm_bus_descriptor *nd_desc; |
| 952 | ssize_t rc; |
| 953 | long val; |
| 954 | |
| 955 | rc = kstrtol(buf, 0, &val); |
| 956 | if (rc) |
| 957 | return rc; |
| 958 | |
| 959 | device_lock(dev); |
| 960 | nd_desc = dev_get_drvdata(dev); |
| 961 | if (nd_desc) { |
| 962 | struct acpi_nfit_desc *acpi_desc = to_acpi_desc(nd_desc); |
| 963 | |
| 964 | switch (val) { |
| 965 | case HW_ERROR_SCRUB_ON: |
| 966 | acpi_desc->scrub_mode = HW_ERROR_SCRUB_ON; |
| 967 | break; |
| 968 | case HW_ERROR_SCRUB_OFF: |
| 969 | acpi_desc->scrub_mode = HW_ERROR_SCRUB_OFF; |
| 970 | break; |
| 971 | default: |
| 972 | rc = -EINVAL; |
| 973 | break; |
| 974 | } |
| 975 | } |
| 976 | device_unlock(dev); |
| 977 | if (rc) |
| 978 | return rc; |
| 979 | return size; |
| 980 | } |
| 981 | static DEVICE_ATTR_RW(hw_error_scrub); |
| 982 | |
Vishal Verma | 37b137f | 2016-07-23 21:51:42 -0700 | [diff] [blame] | 983 | /* |
| 984 | * This shows the number of full Address Range Scrubs that have been |
| 985 | * completed since driver load time. Userspace can wait on this using |
| 986 | * select/poll etc. A '+' at the end indicates an ARS is in progress |
| 987 | */ |
| 988 | static ssize_t scrub_show(struct device *dev, |
| 989 | struct device_attribute *attr, char *buf) |
| 990 | { |
| 991 | struct nvdimm_bus_descriptor *nd_desc; |
| 992 | ssize_t rc = -ENXIO; |
| 993 | |
| 994 | device_lock(dev); |
| 995 | nd_desc = dev_get_drvdata(dev); |
| 996 | if (nd_desc) { |
| 997 | struct acpi_nfit_desc *acpi_desc = to_acpi_desc(nd_desc); |
| 998 | |
| 999 | rc = sprintf(buf, "%d%s", acpi_desc->scrub_count, |
| 1000 | (work_busy(&acpi_desc->work)) ? "+\n" : "\n"); |
| 1001 | } |
| 1002 | device_unlock(dev); |
| 1003 | return rc; |
| 1004 | } |
| 1005 | |
Vishal Verma | 37b137f | 2016-07-23 21:51:42 -0700 | [diff] [blame] | 1006 | static ssize_t scrub_store(struct device *dev, |
| 1007 | struct device_attribute *attr, const char *buf, size_t size) |
| 1008 | { |
| 1009 | struct nvdimm_bus_descriptor *nd_desc; |
| 1010 | ssize_t rc; |
| 1011 | long val; |
| 1012 | |
| 1013 | rc = kstrtol(buf, 0, &val); |
| 1014 | if (rc) |
| 1015 | return rc; |
| 1016 | if (val != 1) |
| 1017 | return -EINVAL; |
| 1018 | |
| 1019 | device_lock(dev); |
| 1020 | nd_desc = dev_get_drvdata(dev); |
| 1021 | if (nd_desc) { |
| 1022 | struct acpi_nfit_desc *acpi_desc = to_acpi_desc(nd_desc); |
| 1023 | |
| 1024 | rc = acpi_nfit_ars_rescan(acpi_desc); |
| 1025 | } |
| 1026 | device_unlock(dev); |
| 1027 | if (rc) |
| 1028 | return rc; |
| 1029 | return size; |
| 1030 | } |
| 1031 | static DEVICE_ATTR_RW(scrub); |
| 1032 | |
| 1033 | static bool ars_supported(struct nvdimm_bus *nvdimm_bus) |
| 1034 | { |
| 1035 | struct nvdimm_bus_descriptor *nd_desc = to_nd_desc(nvdimm_bus); |
| 1036 | const unsigned long mask = 1 << ND_CMD_ARS_CAP | 1 << ND_CMD_ARS_START |
| 1037 | | 1 << ND_CMD_ARS_STATUS; |
| 1038 | |
| 1039 | return (nd_desc->cmd_mask & mask) == mask; |
| 1040 | } |
| 1041 | |
| 1042 | static umode_t nfit_visible(struct kobject *kobj, struct attribute *a, int n) |
| 1043 | { |
| 1044 | struct device *dev = container_of(kobj, struct device, kobj); |
| 1045 | struct nvdimm_bus *nvdimm_bus = to_nvdimm_bus(dev); |
| 1046 | |
| 1047 | if (a == &dev_attr_scrub.attr && !ars_supported(nvdimm_bus)) |
| 1048 | return 0; |
| 1049 | return a->mode; |
| 1050 | } |
| 1051 | |
Dan Williams | 45def22 | 2015-04-26 19:26:48 -0400 | [diff] [blame] | 1052 | static struct attribute *acpi_nfit_attributes[] = { |
| 1053 | &dev_attr_revision.attr, |
Vishal Verma | 37b137f | 2016-07-23 21:51:42 -0700 | [diff] [blame] | 1054 | &dev_attr_scrub.attr, |
Vishal Verma | 9ffd635 | 2016-09-30 17:19:29 -0600 | [diff] [blame] | 1055 | &dev_attr_hw_error_scrub.attr, |
Dan Williams | 45def22 | 2015-04-26 19:26:48 -0400 | [diff] [blame] | 1056 | NULL, |
| 1057 | }; |
| 1058 | |
| 1059 | static struct attribute_group acpi_nfit_attribute_group = { |
| 1060 | .name = "nfit", |
| 1061 | .attrs = acpi_nfit_attributes, |
Vishal Verma | 37b137f | 2016-07-23 21:51:42 -0700 | [diff] [blame] | 1062 | .is_visible = nfit_visible, |
Dan Williams | 45def22 | 2015-04-26 19:26:48 -0400 | [diff] [blame] | 1063 | }; |
| 1064 | |
Dan Williams | a61fe6f | 2016-02-19 12:29:32 -0800 | [diff] [blame] | 1065 | static const struct attribute_group *acpi_nfit_attribute_groups[] = { |
Dan Williams | 45def22 | 2015-04-26 19:26:48 -0400 | [diff] [blame] | 1066 | &nvdimm_bus_attribute_group, |
| 1067 | &acpi_nfit_attribute_group, |
| 1068 | NULL, |
| 1069 | }; |
| 1070 | |
Dan Williams | e6dfb2d | 2015-04-25 03:56:17 -0400 | [diff] [blame] | 1071 | static struct acpi_nfit_memory_map *to_nfit_memdev(struct device *dev) |
| 1072 | { |
| 1073 | struct nvdimm *nvdimm = to_nvdimm(dev); |
| 1074 | struct nfit_mem *nfit_mem = nvdimm_provider_data(nvdimm); |
| 1075 | |
| 1076 | return __to_nfit_memdev(nfit_mem); |
| 1077 | } |
| 1078 | |
| 1079 | static struct acpi_nfit_control_region *to_nfit_dcr(struct device *dev) |
| 1080 | { |
| 1081 | struct nvdimm *nvdimm = to_nvdimm(dev); |
| 1082 | struct nfit_mem *nfit_mem = nvdimm_provider_data(nvdimm); |
| 1083 | |
| 1084 | return nfit_mem->dcr; |
| 1085 | } |
| 1086 | |
| 1087 | static ssize_t handle_show(struct device *dev, |
| 1088 | struct device_attribute *attr, char *buf) |
| 1089 | { |
| 1090 | struct acpi_nfit_memory_map *memdev = to_nfit_memdev(dev); |
| 1091 | |
| 1092 | return sprintf(buf, "%#x\n", memdev->device_handle); |
| 1093 | } |
| 1094 | static DEVICE_ATTR_RO(handle); |
| 1095 | |
| 1096 | static ssize_t phys_id_show(struct device *dev, |
| 1097 | struct device_attribute *attr, char *buf) |
| 1098 | { |
| 1099 | struct acpi_nfit_memory_map *memdev = to_nfit_memdev(dev); |
| 1100 | |
| 1101 | return sprintf(buf, "%#x\n", memdev->physical_id); |
| 1102 | } |
| 1103 | static DEVICE_ATTR_RO(phys_id); |
| 1104 | |
| 1105 | static ssize_t vendor_show(struct device *dev, |
| 1106 | struct device_attribute *attr, char *buf) |
| 1107 | { |
| 1108 | struct acpi_nfit_control_region *dcr = to_nfit_dcr(dev); |
| 1109 | |
Toshi Kani | 5ad9a7f | 2016-04-25 15:34:58 -0600 | [diff] [blame] | 1110 | return sprintf(buf, "0x%04x\n", be16_to_cpu(dcr->vendor_id)); |
Dan Williams | e6dfb2d | 2015-04-25 03:56:17 -0400 | [diff] [blame] | 1111 | } |
| 1112 | static DEVICE_ATTR_RO(vendor); |
| 1113 | |
| 1114 | static ssize_t rev_id_show(struct device *dev, |
| 1115 | struct device_attribute *attr, char *buf) |
| 1116 | { |
| 1117 | struct acpi_nfit_control_region *dcr = to_nfit_dcr(dev); |
| 1118 | |
Toshi Kani | 5ad9a7f | 2016-04-25 15:34:58 -0600 | [diff] [blame] | 1119 | return sprintf(buf, "0x%04x\n", be16_to_cpu(dcr->revision_id)); |
Dan Williams | e6dfb2d | 2015-04-25 03:56:17 -0400 | [diff] [blame] | 1120 | } |
| 1121 | static DEVICE_ATTR_RO(rev_id); |
| 1122 | |
| 1123 | static ssize_t device_show(struct device *dev, |
| 1124 | struct device_attribute *attr, char *buf) |
| 1125 | { |
| 1126 | struct acpi_nfit_control_region *dcr = to_nfit_dcr(dev); |
| 1127 | |
Toshi Kani | 5ad9a7f | 2016-04-25 15:34:58 -0600 | [diff] [blame] | 1128 | return sprintf(buf, "0x%04x\n", be16_to_cpu(dcr->device_id)); |
Dan Williams | e6dfb2d | 2015-04-25 03:56:17 -0400 | [diff] [blame] | 1129 | } |
| 1130 | static DEVICE_ATTR_RO(device); |
| 1131 | |
Dan Williams | 6ca7208 | 2016-04-29 10:33:23 -0700 | [diff] [blame] | 1132 | static ssize_t subsystem_vendor_show(struct device *dev, |
| 1133 | struct device_attribute *attr, char *buf) |
| 1134 | { |
| 1135 | struct acpi_nfit_control_region *dcr = to_nfit_dcr(dev); |
| 1136 | |
| 1137 | return sprintf(buf, "0x%04x\n", be16_to_cpu(dcr->subsystem_vendor_id)); |
| 1138 | } |
| 1139 | static DEVICE_ATTR_RO(subsystem_vendor); |
| 1140 | |
| 1141 | static ssize_t subsystem_rev_id_show(struct device *dev, |
| 1142 | struct device_attribute *attr, char *buf) |
| 1143 | { |
| 1144 | struct acpi_nfit_control_region *dcr = to_nfit_dcr(dev); |
| 1145 | |
| 1146 | return sprintf(buf, "0x%04x\n", |
| 1147 | be16_to_cpu(dcr->subsystem_revision_id)); |
| 1148 | } |
| 1149 | static DEVICE_ATTR_RO(subsystem_rev_id); |
| 1150 | |
| 1151 | static ssize_t subsystem_device_show(struct device *dev, |
| 1152 | struct device_attribute *attr, char *buf) |
| 1153 | { |
| 1154 | struct acpi_nfit_control_region *dcr = to_nfit_dcr(dev); |
| 1155 | |
| 1156 | return sprintf(buf, "0x%04x\n", be16_to_cpu(dcr->subsystem_device_id)); |
| 1157 | } |
| 1158 | static DEVICE_ATTR_RO(subsystem_device); |
| 1159 | |
Dan Williams | 8cc6ddf | 2016-04-05 15:26:50 -0700 | [diff] [blame] | 1160 | static int num_nvdimm_formats(struct nvdimm *nvdimm) |
| 1161 | { |
| 1162 | struct nfit_mem *nfit_mem = nvdimm_provider_data(nvdimm); |
| 1163 | int formats = 0; |
| 1164 | |
| 1165 | if (nfit_mem->memdev_pmem) |
| 1166 | formats++; |
| 1167 | if (nfit_mem->memdev_bdw) |
| 1168 | formats++; |
| 1169 | return formats; |
| 1170 | } |
| 1171 | |
Dan Williams | e6dfb2d | 2015-04-25 03:56:17 -0400 | [diff] [blame] | 1172 | static ssize_t format_show(struct device *dev, |
| 1173 | struct device_attribute *attr, char *buf) |
| 1174 | { |
| 1175 | struct acpi_nfit_control_region *dcr = to_nfit_dcr(dev); |
| 1176 | |
Dan Williams | 1bcbf42 | 2016-06-29 11:19:32 -0700 | [diff] [blame] | 1177 | return sprintf(buf, "0x%04x\n", le16_to_cpu(dcr->code)); |
Dan Williams | e6dfb2d | 2015-04-25 03:56:17 -0400 | [diff] [blame] | 1178 | } |
| 1179 | static DEVICE_ATTR_RO(format); |
| 1180 | |
Dan Williams | 8cc6ddf | 2016-04-05 15:26:50 -0700 | [diff] [blame] | 1181 | static ssize_t format1_show(struct device *dev, |
| 1182 | struct device_attribute *attr, char *buf) |
| 1183 | { |
| 1184 | u32 handle; |
| 1185 | ssize_t rc = -ENXIO; |
| 1186 | struct nfit_mem *nfit_mem; |
| 1187 | struct nfit_memdev *nfit_memdev; |
| 1188 | struct acpi_nfit_desc *acpi_desc; |
| 1189 | struct nvdimm *nvdimm = to_nvdimm(dev); |
| 1190 | struct acpi_nfit_control_region *dcr = to_nfit_dcr(dev); |
| 1191 | |
| 1192 | nfit_mem = nvdimm_provider_data(nvdimm); |
| 1193 | acpi_desc = nfit_mem->acpi_desc; |
| 1194 | handle = to_nfit_memdev(dev)->device_handle; |
| 1195 | |
| 1196 | /* assumes DIMMs have at most 2 published interface codes */ |
| 1197 | mutex_lock(&acpi_desc->init_mutex); |
| 1198 | list_for_each_entry(nfit_memdev, &acpi_desc->memdevs, list) { |
| 1199 | struct acpi_nfit_memory_map *memdev = nfit_memdev->memdev; |
| 1200 | struct nfit_dcr *nfit_dcr; |
| 1201 | |
| 1202 | if (memdev->device_handle != handle) |
| 1203 | continue; |
| 1204 | |
| 1205 | list_for_each_entry(nfit_dcr, &acpi_desc->dcrs, list) { |
| 1206 | if (nfit_dcr->dcr->region_index != memdev->region_index) |
| 1207 | continue; |
| 1208 | if (nfit_dcr->dcr->code == dcr->code) |
| 1209 | continue; |
Dan Williams | 1bcbf42 | 2016-06-29 11:19:32 -0700 | [diff] [blame] | 1210 | rc = sprintf(buf, "0x%04x\n", |
| 1211 | le16_to_cpu(nfit_dcr->dcr->code)); |
Dan Williams | 8cc6ddf | 2016-04-05 15:26:50 -0700 | [diff] [blame] | 1212 | break; |
| 1213 | } |
| 1214 | if (rc != ENXIO) |
| 1215 | break; |
| 1216 | } |
| 1217 | mutex_unlock(&acpi_desc->init_mutex); |
| 1218 | return rc; |
| 1219 | } |
| 1220 | static DEVICE_ATTR_RO(format1); |
| 1221 | |
| 1222 | static ssize_t formats_show(struct device *dev, |
| 1223 | struct device_attribute *attr, char *buf) |
| 1224 | { |
| 1225 | struct nvdimm *nvdimm = to_nvdimm(dev); |
| 1226 | |
| 1227 | return sprintf(buf, "%d\n", num_nvdimm_formats(nvdimm)); |
| 1228 | } |
| 1229 | static DEVICE_ATTR_RO(formats); |
| 1230 | |
Dan Williams | e6dfb2d | 2015-04-25 03:56:17 -0400 | [diff] [blame] | 1231 | static ssize_t serial_show(struct device *dev, |
| 1232 | struct device_attribute *attr, char *buf) |
| 1233 | { |
| 1234 | struct acpi_nfit_control_region *dcr = to_nfit_dcr(dev); |
| 1235 | |
Toshi Kani | 5ad9a7f | 2016-04-25 15:34:58 -0600 | [diff] [blame] | 1236 | return sprintf(buf, "0x%08x\n", be32_to_cpu(dcr->serial_number)); |
Dan Williams | e6dfb2d | 2015-04-25 03:56:17 -0400 | [diff] [blame] | 1237 | } |
| 1238 | static DEVICE_ATTR_RO(serial); |
| 1239 | |
Dan Williams | a94e3fb | 2016-04-28 18:18:05 -0700 | [diff] [blame] | 1240 | static ssize_t family_show(struct device *dev, |
| 1241 | struct device_attribute *attr, char *buf) |
| 1242 | { |
| 1243 | struct nvdimm *nvdimm = to_nvdimm(dev); |
| 1244 | struct nfit_mem *nfit_mem = nvdimm_provider_data(nvdimm); |
| 1245 | |
| 1246 | if (nfit_mem->family < 0) |
| 1247 | return -ENXIO; |
| 1248 | return sprintf(buf, "%d\n", nfit_mem->family); |
| 1249 | } |
| 1250 | static DEVICE_ATTR_RO(family); |
| 1251 | |
| 1252 | static ssize_t dsm_mask_show(struct device *dev, |
| 1253 | struct device_attribute *attr, char *buf) |
| 1254 | { |
| 1255 | struct nvdimm *nvdimm = to_nvdimm(dev); |
| 1256 | struct nfit_mem *nfit_mem = nvdimm_provider_data(nvdimm); |
| 1257 | |
| 1258 | if (nfit_mem->family < 0) |
| 1259 | return -ENXIO; |
| 1260 | return sprintf(buf, "%#lx\n", nfit_mem->dsm_mask); |
| 1261 | } |
| 1262 | static DEVICE_ATTR_RO(dsm_mask); |
| 1263 | |
Dan Williams | 5813882 | 2015-06-23 20:08:34 -0400 | [diff] [blame] | 1264 | static ssize_t flags_show(struct device *dev, |
| 1265 | struct device_attribute *attr, char *buf) |
| 1266 | { |
| 1267 | u16 flags = to_nfit_memdev(dev)->flags; |
| 1268 | |
Dan Williams | ffab938 | 2017-04-13 15:05:30 -0700 | [diff] [blame] | 1269 | return sprintf(buf, "%s%s%s%s%s%s%s\n", |
Toshi Kani | 402bae5 | 2015-08-26 10:20:23 -0600 | [diff] [blame] | 1270 | flags & ACPI_NFIT_MEM_SAVE_FAILED ? "save_fail " : "", |
| 1271 | flags & ACPI_NFIT_MEM_RESTORE_FAILED ? "restore_fail " : "", |
| 1272 | flags & ACPI_NFIT_MEM_FLUSH_FAILED ? "flush_fail " : "", |
Bob Moore | ca321d1 | 2015-10-19 10:24:52 +0800 | [diff] [blame] | 1273 | flags & ACPI_NFIT_MEM_NOT_ARMED ? "not_armed " : "", |
Dan Williams | ffab938 | 2017-04-13 15:05:30 -0700 | [diff] [blame] | 1274 | flags & ACPI_NFIT_MEM_HEALTH_OBSERVED ? "smart_event " : "", |
| 1275 | flags & ACPI_NFIT_MEM_MAP_FAILED ? "map_fail " : "", |
| 1276 | flags & ACPI_NFIT_MEM_HEALTH_ENABLED ? "smart_notify " : ""); |
Dan Williams | 5813882 | 2015-06-23 20:08:34 -0400 | [diff] [blame] | 1277 | } |
| 1278 | static DEVICE_ATTR_RO(flags); |
| 1279 | |
Toshi Kani | 38a879b | 2016-04-25 15:34:59 -0600 | [diff] [blame] | 1280 | static ssize_t id_show(struct device *dev, |
| 1281 | struct device_attribute *attr, char *buf) |
| 1282 | { |
| 1283 | struct acpi_nfit_control_region *dcr = to_nfit_dcr(dev); |
| 1284 | |
| 1285 | if (dcr->valid_fields & ACPI_NFIT_CONTROL_MFG_INFO_VALID) |
| 1286 | return sprintf(buf, "%04x-%02x-%04x-%08x\n", |
| 1287 | be16_to_cpu(dcr->vendor_id), |
| 1288 | dcr->manufacturing_location, |
| 1289 | be16_to_cpu(dcr->manufacturing_date), |
| 1290 | be32_to_cpu(dcr->serial_number)); |
| 1291 | else |
| 1292 | return sprintf(buf, "%04x-%08x\n", |
| 1293 | be16_to_cpu(dcr->vendor_id), |
| 1294 | be32_to_cpu(dcr->serial_number)); |
| 1295 | } |
| 1296 | static DEVICE_ATTR_RO(id); |
| 1297 | |
Dan Williams | e6dfb2d | 2015-04-25 03:56:17 -0400 | [diff] [blame] | 1298 | static struct attribute *acpi_nfit_dimm_attributes[] = { |
| 1299 | &dev_attr_handle.attr, |
| 1300 | &dev_attr_phys_id.attr, |
| 1301 | &dev_attr_vendor.attr, |
| 1302 | &dev_attr_device.attr, |
Dan Williams | 6ca7208 | 2016-04-29 10:33:23 -0700 | [diff] [blame] | 1303 | &dev_attr_rev_id.attr, |
| 1304 | &dev_attr_subsystem_vendor.attr, |
| 1305 | &dev_attr_subsystem_device.attr, |
| 1306 | &dev_attr_subsystem_rev_id.attr, |
Dan Williams | e6dfb2d | 2015-04-25 03:56:17 -0400 | [diff] [blame] | 1307 | &dev_attr_format.attr, |
Dan Williams | 8cc6ddf | 2016-04-05 15:26:50 -0700 | [diff] [blame] | 1308 | &dev_attr_formats.attr, |
| 1309 | &dev_attr_format1.attr, |
Dan Williams | e6dfb2d | 2015-04-25 03:56:17 -0400 | [diff] [blame] | 1310 | &dev_attr_serial.attr, |
Dan Williams | 5813882 | 2015-06-23 20:08:34 -0400 | [diff] [blame] | 1311 | &dev_attr_flags.attr, |
Toshi Kani | 38a879b | 2016-04-25 15:34:59 -0600 | [diff] [blame] | 1312 | &dev_attr_id.attr, |
Dan Williams | a94e3fb | 2016-04-28 18:18:05 -0700 | [diff] [blame] | 1313 | &dev_attr_family.attr, |
| 1314 | &dev_attr_dsm_mask.attr, |
Dan Williams | e6dfb2d | 2015-04-25 03:56:17 -0400 | [diff] [blame] | 1315 | NULL, |
| 1316 | }; |
| 1317 | |
| 1318 | static umode_t acpi_nfit_dimm_attr_visible(struct kobject *kobj, |
| 1319 | struct attribute *a, int n) |
| 1320 | { |
| 1321 | struct device *dev = container_of(kobj, struct device, kobj); |
Dan Williams | 8cc6ddf | 2016-04-05 15:26:50 -0700 | [diff] [blame] | 1322 | struct nvdimm *nvdimm = to_nvdimm(dev); |
Dan Williams | e6dfb2d | 2015-04-25 03:56:17 -0400 | [diff] [blame] | 1323 | |
Dan Williams | 1499934 | 2017-04-13 19:46:36 -0700 | [diff] [blame^] | 1324 | if (!to_nfit_dcr(dev)) { |
| 1325 | /* Without a dcr only the memdev attributes can be surfaced */ |
| 1326 | if (a == &dev_attr_handle.attr || a == &dev_attr_phys_id.attr |
| 1327 | || a == &dev_attr_flags.attr |
| 1328 | || a == &dev_attr_family.attr |
| 1329 | || a == &dev_attr_dsm_mask.attr) |
| 1330 | return a->mode; |
Dan Williams | e6dfb2d | 2015-04-25 03:56:17 -0400 | [diff] [blame] | 1331 | return 0; |
Dan Williams | 1499934 | 2017-04-13 19:46:36 -0700 | [diff] [blame^] | 1332 | } |
| 1333 | |
Dan Williams | 8cc6ddf | 2016-04-05 15:26:50 -0700 | [diff] [blame] | 1334 | if (a == &dev_attr_format1.attr && num_nvdimm_formats(nvdimm) <= 1) |
| 1335 | return 0; |
| 1336 | return a->mode; |
Dan Williams | e6dfb2d | 2015-04-25 03:56:17 -0400 | [diff] [blame] | 1337 | } |
| 1338 | |
| 1339 | static struct attribute_group acpi_nfit_dimm_attribute_group = { |
| 1340 | .name = "nfit", |
| 1341 | .attrs = acpi_nfit_dimm_attributes, |
| 1342 | .is_visible = acpi_nfit_dimm_attr_visible, |
| 1343 | }; |
| 1344 | |
| 1345 | static const struct attribute_group *acpi_nfit_dimm_attribute_groups[] = { |
Dan Williams | 62232e45 | 2015-06-08 14:27:06 -0400 | [diff] [blame] | 1346 | &nvdimm_attribute_group, |
Dan Williams | 4d88a97 | 2015-05-31 14:41:48 -0400 | [diff] [blame] | 1347 | &nd_device_attribute_group, |
Dan Williams | e6dfb2d | 2015-04-25 03:56:17 -0400 | [diff] [blame] | 1348 | &acpi_nfit_dimm_attribute_group, |
| 1349 | NULL, |
| 1350 | }; |
| 1351 | |
| 1352 | static struct nvdimm *acpi_nfit_dimm_by_handle(struct acpi_nfit_desc *acpi_desc, |
| 1353 | u32 device_handle) |
| 1354 | { |
| 1355 | struct nfit_mem *nfit_mem; |
| 1356 | |
| 1357 | list_for_each_entry(nfit_mem, &acpi_desc->dimms, list) |
| 1358 | if (__to_nfit_memdev(nfit_mem)->device_handle == device_handle) |
| 1359 | return nfit_mem->nvdimm; |
| 1360 | |
| 1361 | return NULL; |
| 1362 | } |
| 1363 | |
Dan Williams | 231bf11 | 2016-08-22 19:23:25 -0700 | [diff] [blame] | 1364 | void __acpi_nvdimm_notify(struct device *dev, u32 event) |
Dan Williams | ba9c8dd | 2016-08-22 19:28:37 -0700 | [diff] [blame] | 1365 | { |
| 1366 | struct nfit_mem *nfit_mem; |
| 1367 | struct acpi_nfit_desc *acpi_desc; |
| 1368 | |
| 1369 | dev_dbg(dev->parent, "%s: %s: event: %d\n", dev_name(dev), __func__, |
| 1370 | event); |
| 1371 | |
| 1372 | if (event != NFIT_NOTIFY_DIMM_HEALTH) { |
| 1373 | dev_dbg(dev->parent, "%s: unknown event: %d\n", dev_name(dev), |
| 1374 | event); |
| 1375 | return; |
| 1376 | } |
| 1377 | |
| 1378 | acpi_desc = dev_get_drvdata(dev->parent); |
| 1379 | if (!acpi_desc) |
| 1380 | return; |
| 1381 | |
| 1382 | /* |
| 1383 | * If we successfully retrieved acpi_desc, then we know nfit_mem data |
| 1384 | * is still valid. |
| 1385 | */ |
| 1386 | nfit_mem = dev_get_drvdata(dev); |
| 1387 | if (nfit_mem && nfit_mem->flags_attr) |
| 1388 | sysfs_notify_dirent(nfit_mem->flags_attr); |
| 1389 | } |
Dan Williams | 231bf11 | 2016-08-22 19:23:25 -0700 | [diff] [blame] | 1390 | EXPORT_SYMBOL_GPL(__acpi_nvdimm_notify); |
Dan Williams | ba9c8dd | 2016-08-22 19:28:37 -0700 | [diff] [blame] | 1391 | |
| 1392 | static void acpi_nvdimm_notify(acpi_handle handle, u32 event, void *data) |
| 1393 | { |
| 1394 | struct acpi_device *adev = data; |
| 1395 | struct device *dev = &adev->dev; |
| 1396 | |
| 1397 | device_lock(dev->parent); |
| 1398 | __acpi_nvdimm_notify(dev, event); |
| 1399 | device_unlock(dev->parent); |
| 1400 | } |
| 1401 | |
Dan Williams | 62232e45 | 2015-06-08 14:27:06 -0400 | [diff] [blame] | 1402 | static int acpi_nfit_add_dimm(struct acpi_nfit_desc *acpi_desc, |
| 1403 | struct nfit_mem *nfit_mem, u32 device_handle) |
| 1404 | { |
| 1405 | struct acpi_device *adev, *adev_dimm; |
| 1406 | struct device *dev = acpi_desc->dev; |
Dan Williams | 31eca76 | 2016-04-28 16:23:43 -0700 | [diff] [blame] | 1407 | unsigned long dsm_mask; |
| 1408 | const u8 *uuid; |
Linda Knippers | 60e95f4 | 2015-07-22 16:17:22 -0400 | [diff] [blame] | 1409 | int i; |
Linda Knippers | ba650cf | 2017-03-07 16:35:13 -0500 | [diff] [blame] | 1410 | int family = -1; |
Dan Williams | 62232e45 | 2015-06-08 14:27:06 -0400 | [diff] [blame] | 1411 | |
Dan Williams | e3654ec | 2016-04-28 16:17:07 -0700 | [diff] [blame] | 1412 | /* nfit test assumes 1:1 relationship between commands and dsms */ |
| 1413 | nfit_mem->dsm_mask = acpi_desc->dimm_cmd_force_en; |
Dan Williams | 31eca76 | 2016-04-28 16:23:43 -0700 | [diff] [blame] | 1414 | nfit_mem->family = NVDIMM_FAMILY_INTEL; |
Dan Williams | 62232e45 | 2015-06-08 14:27:06 -0400 | [diff] [blame] | 1415 | adev = to_acpi_dev(acpi_desc); |
| 1416 | if (!adev) |
| 1417 | return 0; |
| 1418 | |
| 1419 | adev_dimm = acpi_find_child_device(adev, device_handle, false); |
| 1420 | nfit_mem->adev = adev_dimm; |
| 1421 | if (!adev_dimm) { |
| 1422 | dev_err(dev, "no ACPI.NFIT device with _ADR %#x, disabling...\n", |
| 1423 | device_handle); |
Dan Williams | 4d88a97 | 2015-05-31 14:41:48 -0400 | [diff] [blame] | 1424 | return force_enable_dimms ? 0 : -ENODEV; |
Dan Williams | 62232e45 | 2015-06-08 14:27:06 -0400 | [diff] [blame] | 1425 | } |
| 1426 | |
Dan Williams | ba9c8dd | 2016-08-22 19:28:37 -0700 | [diff] [blame] | 1427 | if (ACPI_FAILURE(acpi_install_notify_handler(adev_dimm->handle, |
| 1428 | ACPI_DEVICE_NOTIFY, acpi_nvdimm_notify, adev_dimm))) { |
| 1429 | dev_err(dev, "%s: notification registration failed\n", |
| 1430 | dev_name(&adev_dimm->dev)); |
| 1431 | return -ENXIO; |
| 1432 | } |
| 1433 | |
Dan Williams | 31eca76 | 2016-04-28 16:23:43 -0700 | [diff] [blame] | 1434 | /* |
stuart hayes | e02fb72 | 2016-05-26 11:38:41 -0500 | [diff] [blame] | 1435 | * Until standardization materializes we need to consider 4 |
Dan Williams | a722559 | 2016-07-19 12:32:39 -0700 | [diff] [blame] | 1436 | * different command sets. Note, that checking for function0 (bit0) |
| 1437 | * tells us if any commands are reachable through this uuid. |
Dan Williams | 31eca76 | 2016-04-28 16:23:43 -0700 | [diff] [blame] | 1438 | */ |
stuart hayes | e02fb72 | 2016-05-26 11:38:41 -0500 | [diff] [blame] | 1439 | for (i = NVDIMM_FAMILY_INTEL; i <= NVDIMM_FAMILY_MSFT; i++) |
Dan Williams | a722559 | 2016-07-19 12:32:39 -0700 | [diff] [blame] | 1440 | if (acpi_check_dsm(adev_dimm->handle, to_nfit_uuid(i), 1, 1)) |
Linda Knippers | ba650cf | 2017-03-07 16:35:13 -0500 | [diff] [blame] | 1441 | if (family < 0 || i == default_dsm_family) |
| 1442 | family = i; |
Dan Williams | 31eca76 | 2016-04-28 16:23:43 -0700 | [diff] [blame] | 1443 | |
| 1444 | /* limit the supported commands to those that are publicly documented */ |
Linda Knippers | ba650cf | 2017-03-07 16:35:13 -0500 | [diff] [blame] | 1445 | nfit_mem->family = family; |
Linda Knippers | 095ab4b | 2017-03-07 16:35:12 -0500 | [diff] [blame] | 1446 | if (override_dsm_mask && !disable_vendor_specific) |
| 1447 | dsm_mask = override_dsm_mask; |
| 1448 | else if (nfit_mem->family == NVDIMM_FAMILY_INTEL) { |
Dan Williams | 31eca76 | 2016-04-28 16:23:43 -0700 | [diff] [blame] | 1449 | dsm_mask = 0x3fe; |
Dan Williams | 8755409 | 2016-04-28 18:01:20 -0700 | [diff] [blame] | 1450 | if (disable_vendor_specific) |
| 1451 | dsm_mask &= ~(1 << ND_CMD_VENDOR); |
stuart hayes | e02fb72 | 2016-05-26 11:38:41 -0500 | [diff] [blame] | 1452 | } else if (nfit_mem->family == NVDIMM_FAMILY_HPE1) { |
Dan Williams | 31eca76 | 2016-04-28 16:23:43 -0700 | [diff] [blame] | 1453 | dsm_mask = 0x1c3c76; |
stuart hayes | e02fb72 | 2016-05-26 11:38:41 -0500 | [diff] [blame] | 1454 | } else if (nfit_mem->family == NVDIMM_FAMILY_HPE2) { |
Dan Williams | 31eca76 | 2016-04-28 16:23:43 -0700 | [diff] [blame] | 1455 | dsm_mask = 0x1fe; |
Dan Williams | 8755409 | 2016-04-28 18:01:20 -0700 | [diff] [blame] | 1456 | if (disable_vendor_specific) |
| 1457 | dsm_mask &= ~(1 << 8); |
stuart hayes | e02fb72 | 2016-05-26 11:38:41 -0500 | [diff] [blame] | 1458 | } else if (nfit_mem->family == NVDIMM_FAMILY_MSFT) { |
| 1459 | dsm_mask = 0xffffffff; |
Dan Williams | 8755409 | 2016-04-28 18:01:20 -0700 | [diff] [blame] | 1460 | } else { |
Dan Williams | a722559 | 2016-07-19 12:32:39 -0700 | [diff] [blame] | 1461 | dev_dbg(dev, "unknown dimm command family\n"); |
Dan Williams | 31eca76 | 2016-04-28 16:23:43 -0700 | [diff] [blame] | 1462 | nfit_mem->family = -1; |
Dan Williams | a722559 | 2016-07-19 12:32:39 -0700 | [diff] [blame] | 1463 | /* DSMs are optional, continue loading the driver... */ |
| 1464 | return 0; |
Dan Williams | 31eca76 | 2016-04-28 16:23:43 -0700 | [diff] [blame] | 1465 | } |
| 1466 | |
| 1467 | uuid = to_nfit_uuid(nfit_mem->family); |
| 1468 | for_each_set_bit(i, &dsm_mask, BITS_PER_LONG) |
Dan Williams | 62232e45 | 2015-06-08 14:27:06 -0400 | [diff] [blame] | 1469 | if (acpi_check_dsm(adev_dimm->handle, uuid, 1, 1ULL << i)) |
| 1470 | set_bit(i, &nfit_mem->dsm_mask); |
| 1471 | |
Linda Knippers | 60e95f4 | 2015-07-22 16:17:22 -0400 | [diff] [blame] | 1472 | return 0; |
Dan Williams | 62232e45 | 2015-06-08 14:27:06 -0400 | [diff] [blame] | 1473 | } |
| 1474 | |
Dan Williams | ba9c8dd | 2016-08-22 19:28:37 -0700 | [diff] [blame] | 1475 | static void shutdown_dimm_notify(void *data) |
| 1476 | { |
| 1477 | struct acpi_nfit_desc *acpi_desc = data; |
| 1478 | struct nfit_mem *nfit_mem; |
| 1479 | |
| 1480 | mutex_lock(&acpi_desc->init_mutex); |
| 1481 | /* |
| 1482 | * Clear out the nfit_mem->flags_attr and shut down dimm event |
| 1483 | * notifications. |
| 1484 | */ |
| 1485 | list_for_each_entry(nfit_mem, &acpi_desc->dimms, list) { |
Dan Williams | 231bf11 | 2016-08-22 19:23:25 -0700 | [diff] [blame] | 1486 | struct acpi_device *adev_dimm = nfit_mem->adev; |
| 1487 | |
Dan Williams | ba9c8dd | 2016-08-22 19:28:37 -0700 | [diff] [blame] | 1488 | if (nfit_mem->flags_attr) { |
| 1489 | sysfs_put(nfit_mem->flags_attr); |
| 1490 | nfit_mem->flags_attr = NULL; |
| 1491 | } |
Dan Williams | 231bf11 | 2016-08-22 19:23:25 -0700 | [diff] [blame] | 1492 | if (adev_dimm) |
| 1493 | acpi_remove_notify_handler(adev_dimm->handle, |
| 1494 | ACPI_DEVICE_NOTIFY, acpi_nvdimm_notify); |
Dan Williams | ba9c8dd | 2016-08-22 19:28:37 -0700 | [diff] [blame] | 1495 | } |
| 1496 | mutex_unlock(&acpi_desc->init_mutex); |
| 1497 | } |
| 1498 | |
Dan Williams | e6dfb2d | 2015-04-25 03:56:17 -0400 | [diff] [blame] | 1499 | static int acpi_nfit_register_dimms(struct acpi_nfit_desc *acpi_desc) |
| 1500 | { |
| 1501 | struct nfit_mem *nfit_mem; |
Dan Williams | ba9c8dd | 2016-08-22 19:28:37 -0700 | [diff] [blame] | 1502 | int dimm_count = 0, rc; |
| 1503 | struct nvdimm *nvdimm; |
Dan Williams | e6dfb2d | 2015-04-25 03:56:17 -0400 | [diff] [blame] | 1504 | |
| 1505 | list_for_each_entry(nfit_mem, &acpi_desc->dimms, list) { |
Dan Williams | e5ae3b2 | 2016-06-07 17:00:04 -0700 | [diff] [blame] | 1506 | struct acpi_nfit_flush_address *flush; |
Dan Williams | 31eca76 | 2016-04-28 16:23:43 -0700 | [diff] [blame] | 1507 | unsigned long flags = 0, cmd_mask; |
Dan Williams | e6dfb2d | 2015-04-25 03:56:17 -0400 | [diff] [blame] | 1508 | u32 device_handle; |
Dan Williams | 5813882 | 2015-06-23 20:08:34 -0400 | [diff] [blame] | 1509 | u16 mem_flags; |
Dan Williams | e6dfb2d | 2015-04-25 03:56:17 -0400 | [diff] [blame] | 1510 | |
| 1511 | device_handle = __to_nfit_memdev(nfit_mem)->device_handle; |
| 1512 | nvdimm = acpi_nfit_dimm_by_handle(acpi_desc, device_handle); |
| 1513 | if (nvdimm) { |
Vishal Verma | 2098516 | 2015-10-27 16:58:27 -0600 | [diff] [blame] | 1514 | dimm_count++; |
Dan Williams | e6dfb2d | 2015-04-25 03:56:17 -0400 | [diff] [blame] | 1515 | continue; |
| 1516 | } |
| 1517 | |
| 1518 | if (nfit_mem->bdw && nfit_mem->memdev_pmem) |
| 1519 | flags |= NDD_ALIASING; |
| 1520 | |
Dan Williams | 5813882 | 2015-06-23 20:08:34 -0400 | [diff] [blame] | 1521 | mem_flags = __to_nfit_memdev(nfit_mem)->flags; |
Bob Moore | ca321d1 | 2015-10-19 10:24:52 +0800 | [diff] [blame] | 1522 | if (mem_flags & ACPI_NFIT_MEM_NOT_ARMED) |
Dan Williams | 5813882 | 2015-06-23 20:08:34 -0400 | [diff] [blame] | 1523 | flags |= NDD_UNARMED; |
| 1524 | |
Dan Williams | 62232e45 | 2015-06-08 14:27:06 -0400 | [diff] [blame] | 1525 | rc = acpi_nfit_add_dimm(acpi_desc, nfit_mem, device_handle); |
| 1526 | if (rc) |
| 1527 | continue; |
| 1528 | |
Dan Williams | e3654ec | 2016-04-28 16:17:07 -0700 | [diff] [blame] | 1529 | /* |
Dan Williams | 31eca76 | 2016-04-28 16:23:43 -0700 | [diff] [blame] | 1530 | * TODO: provide translation for non-NVDIMM_FAMILY_INTEL |
| 1531 | * devices (i.e. from nd_cmd to acpi_dsm) to standardize the |
| 1532 | * userspace interface. |
Dan Williams | e3654ec | 2016-04-28 16:17:07 -0700 | [diff] [blame] | 1533 | */ |
Dan Williams | 31eca76 | 2016-04-28 16:23:43 -0700 | [diff] [blame] | 1534 | cmd_mask = 1UL << ND_CMD_CALL; |
| 1535 | if (nfit_mem->family == NVDIMM_FAMILY_INTEL) |
| 1536 | cmd_mask |= nfit_mem->dsm_mask; |
| 1537 | |
Dan Williams | e5ae3b2 | 2016-06-07 17:00:04 -0700 | [diff] [blame] | 1538 | flush = nfit_mem->nfit_flush ? nfit_mem->nfit_flush->flush |
| 1539 | : NULL; |
Dan Williams | e6dfb2d | 2015-04-25 03:56:17 -0400 | [diff] [blame] | 1540 | nvdimm = nvdimm_create(acpi_desc->nvdimm_bus, nfit_mem, |
Dan Williams | 62232e45 | 2015-06-08 14:27:06 -0400 | [diff] [blame] | 1541 | acpi_nfit_dimm_attribute_groups, |
Dan Williams | e5ae3b2 | 2016-06-07 17:00:04 -0700 | [diff] [blame] | 1542 | flags, cmd_mask, flush ? flush->hint_count : 0, |
| 1543 | nfit_mem->flush_wpq); |
Dan Williams | e6dfb2d | 2015-04-25 03:56:17 -0400 | [diff] [blame] | 1544 | if (!nvdimm) |
| 1545 | return -ENOMEM; |
| 1546 | |
| 1547 | nfit_mem->nvdimm = nvdimm; |
Dan Williams | 4d88a97 | 2015-05-31 14:41:48 -0400 | [diff] [blame] | 1548 | dimm_count++; |
Dan Williams | 5813882 | 2015-06-23 20:08:34 -0400 | [diff] [blame] | 1549 | |
| 1550 | if ((mem_flags & ACPI_NFIT_MEM_FAILED_MASK) == 0) |
| 1551 | continue; |
| 1552 | |
Dan Williams | 1499934 | 2017-04-13 19:46:36 -0700 | [diff] [blame^] | 1553 | dev_info(acpi_desc->dev, "%s flags:%s%s%s%s%s\n", |
Dan Williams | 5813882 | 2015-06-23 20:08:34 -0400 | [diff] [blame] | 1554 | nvdimm_name(nvdimm), |
Toshi Kani | 402bae5 | 2015-08-26 10:20:23 -0600 | [diff] [blame] | 1555 | mem_flags & ACPI_NFIT_MEM_SAVE_FAILED ? " save_fail" : "", |
| 1556 | mem_flags & ACPI_NFIT_MEM_RESTORE_FAILED ? " restore_fail":"", |
| 1557 | mem_flags & ACPI_NFIT_MEM_FLUSH_FAILED ? " flush_fail" : "", |
Dan Williams | 1499934 | 2017-04-13 19:46:36 -0700 | [diff] [blame^] | 1558 | mem_flags & ACPI_NFIT_MEM_NOT_ARMED ? " not_armed" : "", |
| 1559 | mem_flags & ACPI_NFIT_MEM_MAP_FAILED ? " map_fail" : ""); |
Dan Williams | 5813882 | 2015-06-23 20:08:34 -0400 | [diff] [blame] | 1560 | |
Dan Williams | e6dfb2d | 2015-04-25 03:56:17 -0400 | [diff] [blame] | 1561 | } |
| 1562 | |
Dan Williams | ba9c8dd | 2016-08-22 19:28:37 -0700 | [diff] [blame] | 1563 | rc = nvdimm_bus_check_dimm_count(acpi_desc->nvdimm_bus, dimm_count); |
| 1564 | if (rc) |
| 1565 | return rc; |
| 1566 | |
| 1567 | /* |
| 1568 | * Now that dimms are successfully registered, and async registration |
| 1569 | * is flushed, attempt to enable event notification. |
| 1570 | */ |
| 1571 | list_for_each_entry(nfit_mem, &acpi_desc->dimms, list) { |
| 1572 | struct kernfs_node *nfit_kernfs; |
| 1573 | |
| 1574 | nvdimm = nfit_mem->nvdimm; |
| 1575 | nfit_kernfs = sysfs_get_dirent(nvdimm_kobj(nvdimm)->sd, "nfit"); |
| 1576 | if (nfit_kernfs) |
| 1577 | nfit_mem->flags_attr = sysfs_get_dirent(nfit_kernfs, |
| 1578 | "flags"); |
| 1579 | sysfs_put(nfit_kernfs); |
| 1580 | if (!nfit_mem->flags_attr) |
| 1581 | dev_warn(acpi_desc->dev, "%s: notifications disabled\n", |
| 1582 | nvdimm_name(nvdimm)); |
| 1583 | } |
| 1584 | |
| 1585 | return devm_add_action_or_reset(acpi_desc->dev, shutdown_dimm_notify, |
| 1586 | acpi_desc); |
Dan Williams | e6dfb2d | 2015-04-25 03:56:17 -0400 | [diff] [blame] | 1587 | } |
| 1588 | |
Dan Williams | 62232e45 | 2015-06-08 14:27:06 -0400 | [diff] [blame] | 1589 | static void acpi_nfit_init_dsms(struct acpi_nfit_desc *acpi_desc) |
| 1590 | { |
| 1591 | struct nvdimm_bus_descriptor *nd_desc = &acpi_desc->nd_desc; |
| 1592 | const u8 *uuid = to_nfit_uuid(NFIT_DEV_BUS); |
| 1593 | struct acpi_device *adev; |
| 1594 | int i; |
| 1595 | |
Dan Williams | e3654ec | 2016-04-28 16:17:07 -0700 | [diff] [blame] | 1596 | nd_desc->cmd_mask = acpi_desc->bus_cmd_force_en; |
Dan Williams | 62232e45 | 2015-06-08 14:27:06 -0400 | [diff] [blame] | 1597 | adev = to_acpi_dev(acpi_desc); |
| 1598 | if (!adev) |
| 1599 | return; |
| 1600 | |
Dan Williams | d4f3236 | 2016-03-03 16:08:54 -0800 | [diff] [blame] | 1601 | for (i = ND_CMD_ARS_CAP; i <= ND_CMD_CLEAR_ERROR; i++) |
Dan Williams | 62232e45 | 2015-06-08 14:27:06 -0400 | [diff] [blame] | 1602 | if (acpi_check_dsm(adev->handle, uuid, 1, 1ULL << i)) |
Dan Williams | e3654ec | 2016-04-28 16:17:07 -0700 | [diff] [blame] | 1603 | set_bit(i, &nd_desc->cmd_mask); |
Dan Williams | 62232e45 | 2015-06-08 14:27:06 -0400 | [diff] [blame] | 1604 | } |
| 1605 | |
Dan Williams | 1f7df6f | 2015-06-09 20:13:14 -0400 | [diff] [blame] | 1606 | static ssize_t range_index_show(struct device *dev, |
| 1607 | struct device_attribute *attr, char *buf) |
| 1608 | { |
| 1609 | struct nd_region *nd_region = to_nd_region(dev); |
| 1610 | struct nfit_spa *nfit_spa = nd_region_provider_data(nd_region); |
| 1611 | |
| 1612 | return sprintf(buf, "%d\n", nfit_spa->spa->range_index); |
| 1613 | } |
| 1614 | static DEVICE_ATTR_RO(range_index); |
| 1615 | |
| 1616 | static struct attribute *acpi_nfit_region_attributes[] = { |
| 1617 | &dev_attr_range_index.attr, |
| 1618 | NULL, |
| 1619 | }; |
| 1620 | |
| 1621 | static struct attribute_group acpi_nfit_region_attribute_group = { |
| 1622 | .name = "nfit", |
| 1623 | .attrs = acpi_nfit_region_attributes, |
| 1624 | }; |
| 1625 | |
| 1626 | static const struct attribute_group *acpi_nfit_region_attribute_groups[] = { |
| 1627 | &nd_region_attribute_group, |
| 1628 | &nd_mapping_attribute_group, |
Dan Williams | 3d88002 | 2015-05-31 15:02:11 -0400 | [diff] [blame] | 1629 | &nd_device_attribute_group, |
Toshi Kani | 74ae66c | 2015-06-19 12:18:34 -0600 | [diff] [blame] | 1630 | &nd_numa_attribute_group, |
Dan Williams | 1f7df6f | 2015-06-09 20:13:14 -0400 | [diff] [blame] | 1631 | &acpi_nfit_region_attribute_group, |
| 1632 | NULL, |
| 1633 | }; |
| 1634 | |
Dan Williams | eaf9615 | 2015-05-01 13:11:27 -0400 | [diff] [blame] | 1635 | /* enough info to uniquely specify an interleave set */ |
| 1636 | struct nfit_set_info { |
| 1637 | struct nfit_set_info_map { |
| 1638 | u64 region_offset; |
| 1639 | u32 serial_number; |
| 1640 | u32 pad; |
| 1641 | } mapping[0]; |
| 1642 | }; |
| 1643 | |
| 1644 | static size_t sizeof_nfit_set_info(int num_mappings) |
| 1645 | { |
| 1646 | return sizeof(struct nfit_set_info) |
| 1647 | + num_mappings * sizeof(struct nfit_set_info_map); |
| 1648 | } |
| 1649 | |
Dan Williams | 86ef58a | 2017-02-28 18:32:48 -0800 | [diff] [blame] | 1650 | static int cmp_map_compat(const void *m0, const void *m1) |
Dan Williams | eaf9615 | 2015-05-01 13:11:27 -0400 | [diff] [blame] | 1651 | { |
| 1652 | const struct nfit_set_info_map *map0 = m0; |
| 1653 | const struct nfit_set_info_map *map1 = m1; |
| 1654 | |
| 1655 | return memcmp(&map0->region_offset, &map1->region_offset, |
| 1656 | sizeof(u64)); |
| 1657 | } |
| 1658 | |
Dan Williams | 86ef58a | 2017-02-28 18:32:48 -0800 | [diff] [blame] | 1659 | static int cmp_map(const void *m0, const void *m1) |
| 1660 | { |
| 1661 | const struct nfit_set_info_map *map0 = m0; |
| 1662 | const struct nfit_set_info_map *map1 = m1; |
| 1663 | |
Dan Williams | b03b99a | 2017-03-27 21:53:38 -0700 | [diff] [blame] | 1664 | if (map0->region_offset < map1->region_offset) |
| 1665 | return -1; |
| 1666 | else if (map0->region_offset > map1->region_offset) |
| 1667 | return 1; |
| 1668 | return 0; |
Dan Williams | 86ef58a | 2017-02-28 18:32:48 -0800 | [diff] [blame] | 1669 | } |
| 1670 | |
Dan Williams | eaf9615 | 2015-05-01 13:11:27 -0400 | [diff] [blame] | 1671 | /* Retrieve the nth entry referencing this spa */ |
| 1672 | static struct acpi_nfit_memory_map *memdev_from_spa( |
| 1673 | struct acpi_nfit_desc *acpi_desc, u16 range_index, int n) |
| 1674 | { |
| 1675 | struct nfit_memdev *nfit_memdev; |
| 1676 | |
| 1677 | list_for_each_entry(nfit_memdev, &acpi_desc->memdevs, list) |
| 1678 | if (nfit_memdev->memdev->range_index == range_index) |
| 1679 | if (n-- == 0) |
| 1680 | return nfit_memdev->memdev; |
| 1681 | return NULL; |
| 1682 | } |
| 1683 | |
| 1684 | static int acpi_nfit_init_interleave_set(struct acpi_nfit_desc *acpi_desc, |
| 1685 | struct nd_region_desc *ndr_desc, |
| 1686 | struct acpi_nfit_system_address *spa) |
| 1687 | { |
| 1688 | int i, spa_type = nfit_spa_type(spa); |
| 1689 | struct device *dev = acpi_desc->dev; |
| 1690 | struct nd_interleave_set *nd_set; |
| 1691 | u16 nr = ndr_desc->num_mappings; |
| 1692 | struct nfit_set_info *info; |
| 1693 | |
| 1694 | if (spa_type == NFIT_SPA_PM || spa_type == NFIT_SPA_VOLATILE) |
| 1695 | /* pass */; |
| 1696 | else |
| 1697 | return 0; |
| 1698 | |
| 1699 | nd_set = devm_kzalloc(dev, sizeof(*nd_set), GFP_KERNEL); |
| 1700 | if (!nd_set) |
| 1701 | return -ENOMEM; |
| 1702 | |
| 1703 | info = devm_kzalloc(dev, sizeof_nfit_set_info(nr), GFP_KERNEL); |
| 1704 | if (!info) |
| 1705 | return -ENOMEM; |
| 1706 | for (i = 0; i < nr; i++) { |
Dan Williams | 44c462e | 2016-09-19 16:38:50 -0700 | [diff] [blame] | 1707 | struct nd_mapping_desc *mapping = &ndr_desc->mapping[i]; |
Dan Williams | eaf9615 | 2015-05-01 13:11:27 -0400 | [diff] [blame] | 1708 | struct nfit_set_info_map *map = &info->mapping[i]; |
Dan Williams | 44c462e | 2016-09-19 16:38:50 -0700 | [diff] [blame] | 1709 | struct nvdimm *nvdimm = mapping->nvdimm; |
Dan Williams | eaf9615 | 2015-05-01 13:11:27 -0400 | [diff] [blame] | 1710 | struct nfit_mem *nfit_mem = nvdimm_provider_data(nvdimm); |
| 1711 | struct acpi_nfit_memory_map *memdev = memdev_from_spa(acpi_desc, |
| 1712 | spa->range_index, i); |
| 1713 | |
| 1714 | if (!memdev || !nfit_mem->dcr) { |
| 1715 | dev_err(dev, "%s: failed to find DCR\n", __func__); |
| 1716 | return -ENODEV; |
| 1717 | } |
| 1718 | |
| 1719 | map->region_offset = memdev->region_offset; |
| 1720 | map->serial_number = nfit_mem->dcr->serial_number; |
| 1721 | } |
| 1722 | |
| 1723 | sort(&info->mapping[0], nr, sizeof(struct nfit_set_info_map), |
| 1724 | cmp_map, NULL); |
| 1725 | nd_set->cookie = nd_fletcher64(info, sizeof_nfit_set_info(nr), 0); |
Dan Williams | 86ef58a | 2017-02-28 18:32:48 -0800 | [diff] [blame] | 1726 | |
| 1727 | /* support namespaces created with the wrong sort order */ |
| 1728 | sort(&info->mapping[0], nr, sizeof(struct nfit_set_info_map), |
| 1729 | cmp_map_compat, NULL); |
| 1730 | nd_set->altcookie = nd_fletcher64(info, sizeof_nfit_set_info(nr), 0); |
| 1731 | |
Dan Williams | eaf9615 | 2015-05-01 13:11:27 -0400 | [diff] [blame] | 1732 | ndr_desc->nd_set = nd_set; |
| 1733 | devm_kfree(dev, info); |
| 1734 | |
| 1735 | return 0; |
| 1736 | } |
| 1737 | |
Ross Zwisler | 047fc8a | 2015-06-25 04:21:02 -0400 | [diff] [blame] | 1738 | static u64 to_interleave_offset(u64 offset, struct nfit_blk_mmio *mmio) |
| 1739 | { |
| 1740 | struct acpi_nfit_interleave *idt = mmio->idt; |
| 1741 | u32 sub_line_offset, line_index, line_offset; |
| 1742 | u64 line_no, table_skip_count, table_offset; |
| 1743 | |
| 1744 | line_no = div_u64_rem(offset, mmio->line_size, &sub_line_offset); |
| 1745 | table_skip_count = div_u64_rem(line_no, mmio->num_lines, &line_index); |
| 1746 | line_offset = idt->line_offset[line_index] |
| 1747 | * mmio->line_size; |
| 1748 | table_offset = table_skip_count * mmio->table_size; |
| 1749 | |
| 1750 | return mmio->base_offset + line_offset + table_offset + sub_line_offset; |
| 1751 | } |
| 1752 | |
Ross Zwisler | de4a196 | 2015-08-20 16:27:38 -0600 | [diff] [blame] | 1753 | static u32 read_blk_stat(struct nfit_blk *nfit_blk, unsigned int bw) |
Ross Zwisler | 047fc8a | 2015-06-25 04:21:02 -0400 | [diff] [blame] | 1754 | { |
| 1755 | struct nfit_blk_mmio *mmio = &nfit_blk->mmio[DCR]; |
| 1756 | u64 offset = nfit_blk->stat_offset + mmio->size * bw; |
Ross Zwisler | 68202c9 | 2016-07-29 14:59:12 -0600 | [diff] [blame] | 1757 | const u32 STATUS_MASK = 0x80000037; |
Ross Zwisler | 047fc8a | 2015-06-25 04:21:02 -0400 | [diff] [blame] | 1758 | |
| 1759 | if (mmio->num_lines) |
| 1760 | offset = to_interleave_offset(offset, mmio); |
| 1761 | |
Ross Zwisler | 68202c9 | 2016-07-29 14:59:12 -0600 | [diff] [blame] | 1762 | return readl(mmio->addr.base + offset) & STATUS_MASK; |
Ross Zwisler | 047fc8a | 2015-06-25 04:21:02 -0400 | [diff] [blame] | 1763 | } |
| 1764 | |
| 1765 | static void write_blk_ctl(struct nfit_blk *nfit_blk, unsigned int bw, |
| 1766 | resource_size_t dpa, unsigned int len, unsigned int write) |
| 1767 | { |
| 1768 | u64 cmd, offset; |
| 1769 | struct nfit_blk_mmio *mmio = &nfit_blk->mmio[DCR]; |
| 1770 | |
| 1771 | enum { |
| 1772 | BCW_OFFSET_MASK = (1ULL << 48)-1, |
| 1773 | BCW_LEN_SHIFT = 48, |
| 1774 | BCW_LEN_MASK = (1ULL << 8) - 1, |
| 1775 | BCW_CMD_SHIFT = 56, |
| 1776 | }; |
| 1777 | |
| 1778 | cmd = (dpa >> L1_CACHE_SHIFT) & BCW_OFFSET_MASK; |
| 1779 | len = len >> L1_CACHE_SHIFT; |
| 1780 | cmd |= ((u64) len & BCW_LEN_MASK) << BCW_LEN_SHIFT; |
| 1781 | cmd |= ((u64) write) << BCW_CMD_SHIFT; |
| 1782 | |
| 1783 | offset = nfit_blk->cmd_offset + mmio->size * bw; |
| 1784 | if (mmio->num_lines) |
| 1785 | offset = to_interleave_offset(offset, mmio); |
| 1786 | |
Ross Zwisler | 67a3e8f | 2015-08-27 13:14:20 -0600 | [diff] [blame] | 1787 | writeq(cmd, mmio->addr.base + offset); |
Dan Williams | f284a4f | 2016-07-07 19:44:50 -0700 | [diff] [blame] | 1788 | nvdimm_flush(nfit_blk->nd_region); |
Ross Zwisler | f0f2c07 | 2015-07-10 11:06:14 -0600 | [diff] [blame] | 1789 | |
Dan Williams | aef2533 | 2016-02-12 17:01:11 -0800 | [diff] [blame] | 1790 | if (nfit_blk->dimm_flags & NFIT_BLK_DCR_LATCH) |
Ross Zwisler | 67a3e8f | 2015-08-27 13:14:20 -0600 | [diff] [blame] | 1791 | readq(mmio->addr.base + offset); |
Ross Zwisler | 047fc8a | 2015-06-25 04:21:02 -0400 | [diff] [blame] | 1792 | } |
| 1793 | |
| 1794 | static int acpi_nfit_blk_single_io(struct nfit_blk *nfit_blk, |
| 1795 | resource_size_t dpa, void *iobuf, size_t len, int rw, |
| 1796 | unsigned int lane) |
| 1797 | { |
| 1798 | struct nfit_blk_mmio *mmio = &nfit_blk->mmio[BDW]; |
| 1799 | unsigned int copied = 0; |
| 1800 | u64 base_offset; |
| 1801 | int rc; |
| 1802 | |
| 1803 | base_offset = nfit_blk->bdw_offset + dpa % L1_CACHE_BYTES |
| 1804 | + lane * mmio->size; |
Ross Zwisler | 047fc8a | 2015-06-25 04:21:02 -0400 | [diff] [blame] | 1805 | write_blk_ctl(nfit_blk, lane, dpa, len, rw); |
| 1806 | while (len) { |
| 1807 | unsigned int c; |
| 1808 | u64 offset; |
| 1809 | |
| 1810 | if (mmio->num_lines) { |
| 1811 | u32 line_offset; |
| 1812 | |
| 1813 | offset = to_interleave_offset(base_offset + copied, |
| 1814 | mmio); |
| 1815 | div_u64_rem(offset, mmio->line_size, &line_offset); |
| 1816 | c = min_t(size_t, len, mmio->line_size - line_offset); |
| 1817 | } else { |
| 1818 | offset = base_offset + nfit_blk->bdw_offset; |
| 1819 | c = len; |
| 1820 | } |
| 1821 | |
| 1822 | if (rw) |
Ross Zwisler | 67a3e8f | 2015-08-27 13:14:20 -0600 | [diff] [blame] | 1823 | memcpy_to_pmem(mmio->addr.aperture + offset, |
Ross Zwisler | c2ad295 | 2015-07-10 11:06:13 -0600 | [diff] [blame] | 1824 | iobuf + copied, c); |
Ross Zwisler | 67a3e8f | 2015-08-27 13:14:20 -0600 | [diff] [blame] | 1825 | else { |
Dan Williams | aef2533 | 2016-02-12 17:01:11 -0800 | [diff] [blame] | 1826 | if (nfit_blk->dimm_flags & NFIT_BLK_READ_FLUSH) |
Ross Zwisler | 67a3e8f | 2015-08-27 13:14:20 -0600 | [diff] [blame] | 1827 | mmio_flush_range((void __force *) |
| 1828 | mmio->addr.aperture + offset, c); |
| 1829 | |
Ross Zwisler | c2ad295 | 2015-07-10 11:06:13 -0600 | [diff] [blame] | 1830 | memcpy_from_pmem(iobuf + copied, |
Ross Zwisler | 67a3e8f | 2015-08-27 13:14:20 -0600 | [diff] [blame] | 1831 | mmio->addr.aperture + offset, c); |
| 1832 | } |
Ross Zwisler | 047fc8a | 2015-06-25 04:21:02 -0400 | [diff] [blame] | 1833 | |
| 1834 | copied += c; |
| 1835 | len -= c; |
| 1836 | } |
Ross Zwisler | c2ad295 | 2015-07-10 11:06:13 -0600 | [diff] [blame] | 1837 | |
| 1838 | if (rw) |
Dan Williams | f284a4f | 2016-07-07 19:44:50 -0700 | [diff] [blame] | 1839 | nvdimm_flush(nfit_blk->nd_region); |
Ross Zwisler | c2ad295 | 2015-07-10 11:06:13 -0600 | [diff] [blame] | 1840 | |
Ross Zwisler | 047fc8a | 2015-06-25 04:21:02 -0400 | [diff] [blame] | 1841 | rc = read_blk_stat(nfit_blk, lane) ? -EIO : 0; |
| 1842 | return rc; |
| 1843 | } |
| 1844 | |
| 1845 | static int acpi_nfit_blk_region_do_io(struct nd_blk_region *ndbr, |
| 1846 | resource_size_t dpa, void *iobuf, u64 len, int rw) |
| 1847 | { |
| 1848 | struct nfit_blk *nfit_blk = nd_blk_region_provider_data(ndbr); |
| 1849 | struct nfit_blk_mmio *mmio = &nfit_blk->mmio[BDW]; |
| 1850 | struct nd_region *nd_region = nfit_blk->nd_region; |
| 1851 | unsigned int lane, copied = 0; |
| 1852 | int rc = 0; |
| 1853 | |
| 1854 | lane = nd_region_acquire_lane(nd_region); |
| 1855 | while (len) { |
| 1856 | u64 c = min(len, mmio->size); |
| 1857 | |
| 1858 | rc = acpi_nfit_blk_single_io(nfit_blk, dpa + copied, |
| 1859 | iobuf + copied, c, rw, lane); |
| 1860 | if (rc) |
| 1861 | break; |
| 1862 | |
| 1863 | copied += c; |
| 1864 | len -= c; |
| 1865 | } |
| 1866 | nd_region_release_lane(nd_region, lane); |
| 1867 | |
| 1868 | return rc; |
| 1869 | } |
| 1870 | |
Ross Zwisler | 047fc8a | 2015-06-25 04:21:02 -0400 | [diff] [blame] | 1871 | static int nfit_blk_init_interleave(struct nfit_blk_mmio *mmio, |
| 1872 | struct acpi_nfit_interleave *idt, u16 interleave_ways) |
| 1873 | { |
| 1874 | if (idt) { |
| 1875 | mmio->num_lines = idt->line_count; |
| 1876 | mmio->line_size = idt->line_size; |
| 1877 | if (interleave_ways == 0) |
| 1878 | return -ENXIO; |
| 1879 | mmio->table_size = mmio->num_lines * interleave_ways |
| 1880 | * mmio->line_size; |
| 1881 | } |
| 1882 | |
| 1883 | return 0; |
| 1884 | } |
| 1885 | |
Ross Zwisler | f0f2c07 | 2015-07-10 11:06:14 -0600 | [diff] [blame] | 1886 | static int acpi_nfit_blk_get_flags(struct nvdimm_bus_descriptor *nd_desc, |
| 1887 | struct nvdimm *nvdimm, struct nfit_blk *nfit_blk) |
| 1888 | { |
| 1889 | struct nd_cmd_dimm_flags flags; |
| 1890 | int rc; |
| 1891 | |
| 1892 | memset(&flags, 0, sizeof(flags)); |
| 1893 | rc = nd_desc->ndctl(nd_desc, nvdimm, ND_CMD_DIMM_FLAGS, &flags, |
Dan Williams | aef2533 | 2016-02-12 17:01:11 -0800 | [diff] [blame] | 1894 | sizeof(flags), NULL); |
Ross Zwisler | f0f2c07 | 2015-07-10 11:06:14 -0600 | [diff] [blame] | 1895 | |
| 1896 | if (rc >= 0 && flags.status == 0) |
| 1897 | nfit_blk->dimm_flags = flags.flags; |
| 1898 | else if (rc == -ENOTTY) { |
| 1899 | /* fall back to a conservative default */ |
Dan Williams | aef2533 | 2016-02-12 17:01:11 -0800 | [diff] [blame] | 1900 | nfit_blk->dimm_flags = NFIT_BLK_DCR_LATCH | NFIT_BLK_READ_FLUSH; |
Ross Zwisler | f0f2c07 | 2015-07-10 11:06:14 -0600 | [diff] [blame] | 1901 | rc = 0; |
| 1902 | } else |
| 1903 | rc = -ENXIO; |
| 1904 | |
| 1905 | return rc; |
| 1906 | } |
| 1907 | |
Ross Zwisler | 047fc8a | 2015-06-25 04:21:02 -0400 | [diff] [blame] | 1908 | static int acpi_nfit_blk_region_enable(struct nvdimm_bus *nvdimm_bus, |
| 1909 | struct device *dev) |
| 1910 | { |
| 1911 | struct nvdimm_bus_descriptor *nd_desc = to_nd_desc(nvdimm_bus); |
Ross Zwisler | 047fc8a | 2015-06-25 04:21:02 -0400 | [diff] [blame] | 1912 | struct nd_blk_region *ndbr = to_nd_blk_region(dev); |
| 1913 | struct nfit_blk_mmio *mmio; |
| 1914 | struct nfit_blk *nfit_blk; |
| 1915 | struct nfit_mem *nfit_mem; |
| 1916 | struct nvdimm *nvdimm; |
| 1917 | int rc; |
| 1918 | |
| 1919 | nvdimm = nd_blk_region_to_dimm(ndbr); |
| 1920 | nfit_mem = nvdimm_provider_data(nvdimm); |
| 1921 | if (!nfit_mem || !nfit_mem->dcr || !nfit_mem->bdw) { |
| 1922 | dev_dbg(dev, "%s: missing%s%s%s\n", __func__, |
| 1923 | nfit_mem ? "" : " nfit_mem", |
Dan Williams | 193ccca | 2015-06-30 16:09:39 -0400 | [diff] [blame] | 1924 | (nfit_mem && nfit_mem->dcr) ? "" : " dcr", |
| 1925 | (nfit_mem && nfit_mem->bdw) ? "" : " bdw"); |
Ross Zwisler | 047fc8a | 2015-06-25 04:21:02 -0400 | [diff] [blame] | 1926 | return -ENXIO; |
| 1927 | } |
| 1928 | |
| 1929 | nfit_blk = devm_kzalloc(dev, sizeof(*nfit_blk), GFP_KERNEL); |
| 1930 | if (!nfit_blk) |
| 1931 | return -ENOMEM; |
| 1932 | nd_blk_region_set_provider_data(ndbr, nfit_blk); |
| 1933 | nfit_blk->nd_region = to_nd_region(dev); |
| 1934 | |
| 1935 | /* map block aperture memory */ |
| 1936 | nfit_blk->bdw_offset = nfit_mem->bdw->offset; |
| 1937 | mmio = &nfit_blk->mmio[BDW]; |
Dan Williams | 29b9aa0 | 2016-06-06 17:42:38 -0700 | [diff] [blame] | 1938 | mmio->addr.base = devm_nvdimm_memremap(dev, nfit_mem->spa_bdw->address, |
| 1939 | nfit_mem->spa_bdw->length, ARCH_MEMREMAP_PMEM); |
Ross Zwisler | 67a3e8f | 2015-08-27 13:14:20 -0600 | [diff] [blame] | 1940 | if (!mmio->addr.base) { |
Ross Zwisler | 047fc8a | 2015-06-25 04:21:02 -0400 | [diff] [blame] | 1941 | dev_dbg(dev, "%s: %s failed to map bdw\n", __func__, |
| 1942 | nvdimm_name(nvdimm)); |
| 1943 | return -ENOMEM; |
| 1944 | } |
| 1945 | mmio->size = nfit_mem->bdw->size; |
| 1946 | mmio->base_offset = nfit_mem->memdev_bdw->region_offset; |
| 1947 | mmio->idt = nfit_mem->idt_bdw; |
| 1948 | mmio->spa = nfit_mem->spa_bdw; |
| 1949 | rc = nfit_blk_init_interleave(mmio, nfit_mem->idt_bdw, |
| 1950 | nfit_mem->memdev_bdw->interleave_ways); |
| 1951 | if (rc) { |
| 1952 | dev_dbg(dev, "%s: %s failed to init bdw interleave\n", |
| 1953 | __func__, nvdimm_name(nvdimm)); |
| 1954 | return rc; |
| 1955 | } |
| 1956 | |
| 1957 | /* map block control memory */ |
| 1958 | nfit_blk->cmd_offset = nfit_mem->dcr->command_offset; |
| 1959 | nfit_blk->stat_offset = nfit_mem->dcr->status_offset; |
| 1960 | mmio = &nfit_blk->mmio[DCR]; |
Dan Williams | 29b9aa0 | 2016-06-06 17:42:38 -0700 | [diff] [blame] | 1961 | mmio->addr.base = devm_nvdimm_ioremap(dev, nfit_mem->spa_dcr->address, |
| 1962 | nfit_mem->spa_dcr->length); |
Ross Zwisler | 67a3e8f | 2015-08-27 13:14:20 -0600 | [diff] [blame] | 1963 | if (!mmio->addr.base) { |
Ross Zwisler | 047fc8a | 2015-06-25 04:21:02 -0400 | [diff] [blame] | 1964 | dev_dbg(dev, "%s: %s failed to map dcr\n", __func__, |
| 1965 | nvdimm_name(nvdimm)); |
| 1966 | return -ENOMEM; |
| 1967 | } |
| 1968 | mmio->size = nfit_mem->dcr->window_size; |
| 1969 | mmio->base_offset = nfit_mem->memdev_dcr->region_offset; |
| 1970 | mmio->idt = nfit_mem->idt_dcr; |
| 1971 | mmio->spa = nfit_mem->spa_dcr; |
| 1972 | rc = nfit_blk_init_interleave(mmio, nfit_mem->idt_dcr, |
| 1973 | nfit_mem->memdev_dcr->interleave_ways); |
| 1974 | if (rc) { |
| 1975 | dev_dbg(dev, "%s: %s failed to init dcr interleave\n", |
| 1976 | __func__, nvdimm_name(nvdimm)); |
| 1977 | return rc; |
| 1978 | } |
| 1979 | |
Ross Zwisler | f0f2c07 | 2015-07-10 11:06:14 -0600 | [diff] [blame] | 1980 | rc = acpi_nfit_blk_get_flags(nd_desc, nvdimm, nfit_blk); |
| 1981 | if (rc < 0) { |
| 1982 | dev_dbg(dev, "%s: %s failed get DIMM flags\n", |
| 1983 | __func__, nvdimm_name(nvdimm)); |
| 1984 | return rc; |
| 1985 | } |
| 1986 | |
Dan Williams | f284a4f | 2016-07-07 19:44:50 -0700 | [diff] [blame] | 1987 | if (nvdimm_has_flush(nfit_blk->nd_region) < 0) |
Ross Zwisler | c2ad295 | 2015-07-10 11:06:13 -0600 | [diff] [blame] | 1988 | dev_warn(dev, "unable to guarantee persistence of writes\n"); |
| 1989 | |
Ross Zwisler | 047fc8a | 2015-06-25 04:21:02 -0400 | [diff] [blame] | 1990 | if (mmio->line_size == 0) |
| 1991 | return 0; |
| 1992 | |
| 1993 | if ((u32) nfit_blk->cmd_offset % mmio->line_size |
| 1994 | + 8 > mmio->line_size) { |
| 1995 | dev_dbg(dev, "cmd_offset crosses interleave boundary\n"); |
| 1996 | return -ENXIO; |
| 1997 | } else if ((u32) nfit_blk->stat_offset % mmio->line_size |
| 1998 | + 8 > mmio->line_size) { |
| 1999 | dev_dbg(dev, "stat_offset crosses interleave boundary\n"); |
| 2000 | return -ENXIO; |
| 2001 | } |
| 2002 | |
| 2003 | return 0; |
| 2004 | } |
| 2005 | |
Dan Williams | aef2533 | 2016-02-12 17:01:11 -0800 | [diff] [blame] | 2006 | static int ars_get_cap(struct acpi_nfit_desc *acpi_desc, |
Dan Williams | 1cf03c0 | 2016-02-17 13:01:23 -0800 | [diff] [blame] | 2007 | struct nd_cmd_ars_cap *cmd, struct nfit_spa *nfit_spa) |
Vishal Verma | 0caeef6 | 2015-12-24 19:21:43 -0700 | [diff] [blame] | 2008 | { |
Dan Williams | aef2533 | 2016-02-12 17:01:11 -0800 | [diff] [blame] | 2009 | struct nvdimm_bus_descriptor *nd_desc = &acpi_desc->nd_desc; |
Dan Williams | 1cf03c0 | 2016-02-17 13:01:23 -0800 | [diff] [blame] | 2010 | struct acpi_nfit_system_address *spa = nfit_spa->spa; |
Dan Williams | aef2533 | 2016-02-12 17:01:11 -0800 | [diff] [blame] | 2011 | int cmd_rc, rc; |
| 2012 | |
Dan Williams | 1cf03c0 | 2016-02-17 13:01:23 -0800 | [diff] [blame] | 2013 | cmd->address = spa->address; |
| 2014 | cmd->length = spa->length; |
Dan Williams | aef2533 | 2016-02-12 17:01:11 -0800 | [diff] [blame] | 2015 | rc = nd_desc->ndctl(nd_desc, NULL, ND_CMD_ARS_CAP, cmd, |
| 2016 | sizeof(*cmd), &cmd_rc); |
| 2017 | if (rc < 0) |
| 2018 | return rc; |
Dan Williams | 1cf03c0 | 2016-02-17 13:01:23 -0800 | [diff] [blame] | 2019 | return cmd_rc; |
Vishal Verma | 0caeef6 | 2015-12-24 19:21:43 -0700 | [diff] [blame] | 2020 | } |
| 2021 | |
Dan Williams | 1cf03c0 | 2016-02-17 13:01:23 -0800 | [diff] [blame] | 2022 | static int ars_start(struct acpi_nfit_desc *acpi_desc, struct nfit_spa *nfit_spa) |
Vishal Verma | 0caeef6 | 2015-12-24 19:21:43 -0700 | [diff] [blame] | 2023 | { |
| 2024 | int rc; |
Dan Williams | 1cf03c0 | 2016-02-17 13:01:23 -0800 | [diff] [blame] | 2025 | int cmd_rc; |
| 2026 | struct nd_cmd_ars_start ars_start; |
| 2027 | struct acpi_nfit_system_address *spa = nfit_spa->spa; |
| 2028 | struct nvdimm_bus_descriptor *nd_desc = &acpi_desc->nd_desc; |
Vishal Verma | 0caeef6 | 2015-12-24 19:21:43 -0700 | [diff] [blame] | 2029 | |
Dan Williams | 1cf03c0 | 2016-02-17 13:01:23 -0800 | [diff] [blame] | 2030 | memset(&ars_start, 0, sizeof(ars_start)); |
| 2031 | ars_start.address = spa->address; |
| 2032 | ars_start.length = spa->length; |
| 2033 | if (nfit_spa_type(spa) == NFIT_SPA_PM) |
| 2034 | ars_start.type = ND_ARS_PERSISTENT; |
| 2035 | else if (nfit_spa_type(spa) == NFIT_SPA_VOLATILE) |
| 2036 | ars_start.type = ND_ARS_VOLATILE; |
| 2037 | else |
| 2038 | return -ENOTTY; |
Vishal Verma | 0caeef6 | 2015-12-24 19:21:43 -0700 | [diff] [blame] | 2039 | |
Dan Williams | 1cf03c0 | 2016-02-17 13:01:23 -0800 | [diff] [blame] | 2040 | rc = nd_desc->ndctl(nd_desc, NULL, ND_CMD_ARS_START, &ars_start, |
| 2041 | sizeof(ars_start), &cmd_rc); |
Dan Williams | aef2533 | 2016-02-12 17:01:11 -0800 | [diff] [blame] | 2042 | |
Dan Williams | 1cf03c0 | 2016-02-17 13:01:23 -0800 | [diff] [blame] | 2043 | if (rc < 0) |
| 2044 | return rc; |
| 2045 | return cmd_rc; |
Vishal Verma | 0caeef6 | 2015-12-24 19:21:43 -0700 | [diff] [blame] | 2046 | } |
| 2047 | |
Dan Williams | 1cf03c0 | 2016-02-17 13:01:23 -0800 | [diff] [blame] | 2048 | static int ars_continue(struct acpi_nfit_desc *acpi_desc) |
Vishal Verma | 0caeef6 | 2015-12-24 19:21:43 -0700 | [diff] [blame] | 2049 | { |
Dan Williams | aef2533 | 2016-02-12 17:01:11 -0800 | [diff] [blame] | 2050 | int rc, cmd_rc; |
Dan Williams | 1cf03c0 | 2016-02-17 13:01:23 -0800 | [diff] [blame] | 2051 | struct nd_cmd_ars_start ars_start; |
| 2052 | struct nvdimm_bus_descriptor *nd_desc = &acpi_desc->nd_desc; |
| 2053 | struct nd_cmd_ars_status *ars_status = acpi_desc->ars_status; |
Vishal Verma | 0caeef6 | 2015-12-24 19:21:43 -0700 | [diff] [blame] | 2054 | |
Dan Williams | 1cf03c0 | 2016-02-17 13:01:23 -0800 | [diff] [blame] | 2055 | memset(&ars_start, 0, sizeof(ars_start)); |
| 2056 | ars_start.address = ars_status->restart_address; |
| 2057 | ars_start.length = ars_status->restart_length; |
| 2058 | ars_start.type = ars_status->type; |
| 2059 | rc = nd_desc->ndctl(nd_desc, NULL, ND_CMD_ARS_START, &ars_start, |
| 2060 | sizeof(ars_start), &cmd_rc); |
| 2061 | if (rc < 0) |
| 2062 | return rc; |
| 2063 | return cmd_rc; |
| 2064 | } |
Dan Williams | aef2533 | 2016-02-12 17:01:11 -0800 | [diff] [blame] | 2065 | |
Dan Williams | 1cf03c0 | 2016-02-17 13:01:23 -0800 | [diff] [blame] | 2066 | static int ars_get_status(struct acpi_nfit_desc *acpi_desc) |
| 2067 | { |
| 2068 | struct nvdimm_bus_descriptor *nd_desc = &acpi_desc->nd_desc; |
| 2069 | struct nd_cmd_ars_status *ars_status = acpi_desc->ars_status; |
| 2070 | int rc, cmd_rc; |
Dan Williams | aef2533 | 2016-02-12 17:01:11 -0800 | [diff] [blame] | 2071 | |
Dan Williams | 1cf03c0 | 2016-02-17 13:01:23 -0800 | [diff] [blame] | 2072 | rc = nd_desc->ndctl(nd_desc, NULL, ND_CMD_ARS_STATUS, ars_status, |
| 2073 | acpi_desc->ars_status_size, &cmd_rc); |
| 2074 | if (rc < 0) |
| 2075 | return rc; |
| 2076 | return cmd_rc; |
Vishal Verma | 0caeef6 | 2015-12-24 19:21:43 -0700 | [diff] [blame] | 2077 | } |
| 2078 | |
Dan Williams | 82aa37c | 2016-12-06 12:45:24 -0800 | [diff] [blame] | 2079 | static int ars_status_process_records(struct acpi_nfit_desc *acpi_desc, |
Dan Williams | 1cf03c0 | 2016-02-17 13:01:23 -0800 | [diff] [blame] | 2080 | struct nd_cmd_ars_status *ars_status) |
Vishal Verma | 0caeef6 | 2015-12-24 19:21:43 -0700 | [diff] [blame] | 2081 | { |
Dan Williams | 82aa37c | 2016-12-06 12:45:24 -0800 | [diff] [blame] | 2082 | struct nvdimm_bus *nvdimm_bus = acpi_desc->nvdimm_bus; |
Vishal Verma | 0caeef6 | 2015-12-24 19:21:43 -0700 | [diff] [blame] | 2083 | int rc; |
| 2084 | u32 i; |
| 2085 | |
Dan Williams | 82aa37c | 2016-12-06 12:45:24 -0800 | [diff] [blame] | 2086 | /* |
| 2087 | * First record starts at 44 byte offset from the start of the |
| 2088 | * payload. |
| 2089 | */ |
| 2090 | if (ars_status->out_length < 44) |
| 2091 | return 0; |
Vishal Verma | 0caeef6 | 2015-12-24 19:21:43 -0700 | [diff] [blame] | 2092 | for (i = 0; i < ars_status->num_records; i++) { |
Dan Williams | 82aa37c | 2016-12-06 12:45:24 -0800 | [diff] [blame] | 2093 | /* only process full records */ |
| 2094 | if (ars_status->out_length |
| 2095 | < 44 + sizeof(struct nd_ars_record) * (i + 1)) |
| 2096 | break; |
Vishal Verma | 0caeef6 | 2015-12-24 19:21:43 -0700 | [diff] [blame] | 2097 | rc = nvdimm_bus_add_poison(nvdimm_bus, |
| 2098 | ars_status->records[i].err_address, |
| 2099 | ars_status->records[i].length); |
| 2100 | if (rc) |
| 2101 | return rc; |
| 2102 | } |
Dan Williams | 82aa37c | 2016-12-06 12:45:24 -0800 | [diff] [blame] | 2103 | if (i < ars_status->num_records) |
| 2104 | dev_warn(acpi_desc->dev, "detected truncated ars results\n"); |
Vishal Verma | 0caeef6 | 2015-12-24 19:21:43 -0700 | [diff] [blame] | 2105 | |
| 2106 | return 0; |
| 2107 | } |
| 2108 | |
Toshi Kani | af1996e | 2016-03-09 12:47:06 -0700 | [diff] [blame] | 2109 | static void acpi_nfit_remove_resource(void *data) |
| 2110 | { |
| 2111 | struct resource *res = data; |
| 2112 | |
| 2113 | remove_resource(res); |
| 2114 | } |
| 2115 | |
| 2116 | static int acpi_nfit_insert_resource(struct acpi_nfit_desc *acpi_desc, |
| 2117 | struct nd_region_desc *ndr_desc) |
| 2118 | { |
| 2119 | struct resource *res, *nd_res = ndr_desc->res; |
| 2120 | int is_pmem, ret; |
| 2121 | |
| 2122 | /* No operation if the region is already registered as PMEM */ |
| 2123 | is_pmem = region_intersects(nd_res->start, resource_size(nd_res), |
| 2124 | IORESOURCE_MEM, IORES_DESC_PERSISTENT_MEMORY); |
| 2125 | if (is_pmem == REGION_INTERSECTS) |
| 2126 | return 0; |
| 2127 | |
| 2128 | res = devm_kzalloc(acpi_desc->dev, sizeof(*res), GFP_KERNEL); |
| 2129 | if (!res) |
| 2130 | return -ENOMEM; |
| 2131 | |
| 2132 | res->name = "Persistent Memory"; |
| 2133 | res->start = nd_res->start; |
| 2134 | res->end = nd_res->end; |
| 2135 | res->flags = IORESOURCE_MEM; |
| 2136 | res->desc = IORES_DESC_PERSISTENT_MEMORY; |
| 2137 | |
| 2138 | ret = insert_resource(&iomem_resource, res); |
| 2139 | if (ret) |
| 2140 | return ret; |
| 2141 | |
Sajjan, Vikas C | d932dd2 | 2016-07-04 10:02:51 +0530 | [diff] [blame] | 2142 | ret = devm_add_action_or_reset(acpi_desc->dev, |
| 2143 | acpi_nfit_remove_resource, |
| 2144 | res); |
| 2145 | if (ret) |
Toshi Kani | af1996e | 2016-03-09 12:47:06 -0700 | [diff] [blame] | 2146 | return ret; |
Toshi Kani | af1996e | 2016-03-09 12:47:06 -0700 | [diff] [blame] | 2147 | |
| 2148 | return 0; |
| 2149 | } |
| 2150 | |
Dan Williams | 1f7df6f | 2015-06-09 20:13:14 -0400 | [diff] [blame] | 2151 | static int acpi_nfit_init_mapping(struct acpi_nfit_desc *acpi_desc, |
Dan Williams | 44c462e | 2016-09-19 16:38:50 -0700 | [diff] [blame] | 2152 | struct nd_mapping_desc *mapping, struct nd_region_desc *ndr_desc, |
Dan Williams | 1f7df6f | 2015-06-09 20:13:14 -0400 | [diff] [blame] | 2153 | struct acpi_nfit_memory_map *memdev, |
Dan Williams | 1cf03c0 | 2016-02-17 13:01:23 -0800 | [diff] [blame] | 2154 | struct nfit_spa *nfit_spa) |
Dan Williams | 1f7df6f | 2015-06-09 20:13:14 -0400 | [diff] [blame] | 2155 | { |
| 2156 | struct nvdimm *nvdimm = acpi_nfit_dimm_by_handle(acpi_desc, |
| 2157 | memdev->device_handle); |
Dan Williams | 1cf03c0 | 2016-02-17 13:01:23 -0800 | [diff] [blame] | 2158 | struct acpi_nfit_system_address *spa = nfit_spa->spa; |
Ross Zwisler | 047fc8a | 2015-06-25 04:21:02 -0400 | [diff] [blame] | 2159 | struct nd_blk_region_desc *ndbr_desc; |
Dan Williams | 1f7df6f | 2015-06-09 20:13:14 -0400 | [diff] [blame] | 2160 | struct nfit_mem *nfit_mem; |
| 2161 | int blk_valid = 0; |
| 2162 | |
| 2163 | if (!nvdimm) { |
| 2164 | dev_err(acpi_desc->dev, "spa%d dimm: %#x not found\n", |
| 2165 | spa->range_index, memdev->device_handle); |
| 2166 | return -ENODEV; |
| 2167 | } |
| 2168 | |
Dan Williams | 44c462e | 2016-09-19 16:38:50 -0700 | [diff] [blame] | 2169 | mapping->nvdimm = nvdimm; |
Dan Williams | 1f7df6f | 2015-06-09 20:13:14 -0400 | [diff] [blame] | 2170 | switch (nfit_spa_type(spa)) { |
| 2171 | case NFIT_SPA_PM: |
| 2172 | case NFIT_SPA_VOLATILE: |
Dan Williams | 44c462e | 2016-09-19 16:38:50 -0700 | [diff] [blame] | 2173 | mapping->start = memdev->address; |
| 2174 | mapping->size = memdev->region_size; |
Dan Williams | 1f7df6f | 2015-06-09 20:13:14 -0400 | [diff] [blame] | 2175 | break; |
| 2176 | case NFIT_SPA_DCR: |
| 2177 | nfit_mem = nvdimm_provider_data(nvdimm); |
| 2178 | if (!nfit_mem || !nfit_mem->bdw) { |
| 2179 | dev_dbg(acpi_desc->dev, "spa%d %s missing bdw\n", |
| 2180 | spa->range_index, nvdimm_name(nvdimm)); |
| 2181 | } else { |
Dan Williams | 44c462e | 2016-09-19 16:38:50 -0700 | [diff] [blame] | 2182 | mapping->size = nfit_mem->bdw->capacity; |
| 2183 | mapping->start = nfit_mem->bdw->start_address; |
Vishal Verma | 5212e11 | 2015-06-25 04:20:32 -0400 | [diff] [blame] | 2184 | ndr_desc->num_lanes = nfit_mem->bdw->windows; |
Dan Williams | 1f7df6f | 2015-06-09 20:13:14 -0400 | [diff] [blame] | 2185 | blk_valid = 1; |
| 2186 | } |
| 2187 | |
Dan Williams | 44c462e | 2016-09-19 16:38:50 -0700 | [diff] [blame] | 2188 | ndr_desc->mapping = mapping; |
Dan Williams | 1f7df6f | 2015-06-09 20:13:14 -0400 | [diff] [blame] | 2189 | ndr_desc->num_mappings = blk_valid; |
Ross Zwisler | 047fc8a | 2015-06-25 04:21:02 -0400 | [diff] [blame] | 2190 | ndbr_desc = to_blk_region_desc(ndr_desc); |
| 2191 | ndbr_desc->enable = acpi_nfit_blk_region_enable; |
Dan Williams | 6bc7561 | 2015-06-17 17:23:32 -0400 | [diff] [blame] | 2192 | ndbr_desc->do_io = acpi_desc->blk_do_io; |
Dan Williams | 1cf03c0 | 2016-02-17 13:01:23 -0800 | [diff] [blame] | 2193 | nfit_spa->nd_region = nvdimm_blk_region_create(acpi_desc->nvdimm_bus, |
| 2194 | ndr_desc); |
| 2195 | if (!nfit_spa->nd_region) |
Dan Williams | 1f7df6f | 2015-06-09 20:13:14 -0400 | [diff] [blame] | 2196 | return -ENOMEM; |
| 2197 | break; |
| 2198 | } |
| 2199 | |
| 2200 | return 0; |
| 2201 | } |
| 2202 | |
Lee, Chun-Yi | c2f32ac | 2016-07-15 12:05:35 +0800 | [diff] [blame] | 2203 | static bool nfit_spa_is_virtual(struct acpi_nfit_system_address *spa) |
| 2204 | { |
| 2205 | return (nfit_spa_type(spa) == NFIT_SPA_VDISK || |
| 2206 | nfit_spa_type(spa) == NFIT_SPA_VCD || |
| 2207 | nfit_spa_type(spa) == NFIT_SPA_PDISK || |
| 2208 | nfit_spa_type(spa) == NFIT_SPA_PCD); |
| 2209 | } |
| 2210 | |
Dan Williams | 1f7df6f | 2015-06-09 20:13:14 -0400 | [diff] [blame] | 2211 | static int acpi_nfit_register_region(struct acpi_nfit_desc *acpi_desc, |
| 2212 | struct nfit_spa *nfit_spa) |
| 2213 | { |
Dan Williams | 44c462e | 2016-09-19 16:38:50 -0700 | [diff] [blame] | 2214 | static struct nd_mapping_desc mappings[ND_MAX_MAPPINGS]; |
Dan Williams | 1f7df6f | 2015-06-09 20:13:14 -0400 | [diff] [blame] | 2215 | struct acpi_nfit_system_address *spa = nfit_spa->spa; |
Ross Zwisler | 047fc8a | 2015-06-25 04:21:02 -0400 | [diff] [blame] | 2216 | struct nd_blk_region_desc ndbr_desc; |
| 2217 | struct nd_region_desc *ndr_desc; |
Dan Williams | 1f7df6f | 2015-06-09 20:13:14 -0400 | [diff] [blame] | 2218 | struct nfit_memdev *nfit_memdev; |
Dan Williams | 1f7df6f | 2015-06-09 20:13:14 -0400 | [diff] [blame] | 2219 | struct nvdimm_bus *nvdimm_bus; |
| 2220 | struct resource res; |
Dan Williams | eaf9615 | 2015-05-01 13:11:27 -0400 | [diff] [blame] | 2221 | int count = 0, rc; |
Dan Williams | 1f7df6f | 2015-06-09 20:13:14 -0400 | [diff] [blame] | 2222 | |
Dan Williams | 1cf03c0 | 2016-02-17 13:01:23 -0800 | [diff] [blame] | 2223 | if (nfit_spa->nd_region) |
Vishal Verma | 2098516 | 2015-10-27 16:58:27 -0600 | [diff] [blame] | 2224 | return 0; |
| 2225 | |
Lee, Chun-Yi | c2f32ac | 2016-07-15 12:05:35 +0800 | [diff] [blame] | 2226 | if (spa->range_index == 0 && !nfit_spa_is_virtual(spa)) { |
Dan Williams | 1f7df6f | 2015-06-09 20:13:14 -0400 | [diff] [blame] | 2227 | dev_dbg(acpi_desc->dev, "%s: detected invalid spa index\n", |
| 2228 | __func__); |
| 2229 | return 0; |
| 2230 | } |
| 2231 | |
| 2232 | memset(&res, 0, sizeof(res)); |
Dan Williams | 44c462e | 2016-09-19 16:38:50 -0700 | [diff] [blame] | 2233 | memset(&mappings, 0, sizeof(mappings)); |
Ross Zwisler | 047fc8a | 2015-06-25 04:21:02 -0400 | [diff] [blame] | 2234 | memset(&ndbr_desc, 0, sizeof(ndbr_desc)); |
Dan Williams | 1f7df6f | 2015-06-09 20:13:14 -0400 | [diff] [blame] | 2235 | res.start = spa->address; |
| 2236 | res.end = res.start + spa->length - 1; |
Ross Zwisler | 047fc8a | 2015-06-25 04:21:02 -0400 | [diff] [blame] | 2237 | ndr_desc = &ndbr_desc.ndr_desc; |
| 2238 | ndr_desc->res = &res; |
| 2239 | ndr_desc->provider_data = nfit_spa; |
| 2240 | ndr_desc->attr_groups = acpi_nfit_region_attribute_groups; |
Toshi Kani | 41d7a6d | 2015-06-19 12:18:33 -0600 | [diff] [blame] | 2241 | if (spa->flags & ACPI_NFIT_PROXIMITY_VALID) |
| 2242 | ndr_desc->numa_node = acpi_map_pxm_to_online_node( |
| 2243 | spa->proximity_domain); |
| 2244 | else |
| 2245 | ndr_desc->numa_node = NUMA_NO_NODE; |
| 2246 | |
Dan Williams | 1f7df6f | 2015-06-09 20:13:14 -0400 | [diff] [blame] | 2247 | list_for_each_entry(nfit_memdev, &acpi_desc->memdevs, list) { |
| 2248 | struct acpi_nfit_memory_map *memdev = nfit_memdev->memdev; |
Dan Williams | 44c462e | 2016-09-19 16:38:50 -0700 | [diff] [blame] | 2249 | struct nd_mapping_desc *mapping; |
Dan Williams | 1f7df6f | 2015-06-09 20:13:14 -0400 | [diff] [blame] | 2250 | |
| 2251 | if (memdev->range_index != spa->range_index) |
| 2252 | continue; |
| 2253 | if (count >= ND_MAX_MAPPINGS) { |
| 2254 | dev_err(acpi_desc->dev, "spa%d exceeds max mappings %d\n", |
| 2255 | spa->range_index, ND_MAX_MAPPINGS); |
| 2256 | return -ENXIO; |
| 2257 | } |
Dan Williams | 44c462e | 2016-09-19 16:38:50 -0700 | [diff] [blame] | 2258 | mapping = &mappings[count++]; |
| 2259 | rc = acpi_nfit_init_mapping(acpi_desc, mapping, ndr_desc, |
Dan Williams | 1cf03c0 | 2016-02-17 13:01:23 -0800 | [diff] [blame] | 2260 | memdev, nfit_spa); |
Dan Williams | 1f7df6f | 2015-06-09 20:13:14 -0400 | [diff] [blame] | 2261 | if (rc) |
Dan Williams | 1cf03c0 | 2016-02-17 13:01:23 -0800 | [diff] [blame] | 2262 | goto out; |
Dan Williams | 1f7df6f | 2015-06-09 20:13:14 -0400 | [diff] [blame] | 2263 | } |
| 2264 | |
Dan Williams | 44c462e | 2016-09-19 16:38:50 -0700 | [diff] [blame] | 2265 | ndr_desc->mapping = mappings; |
Ross Zwisler | 047fc8a | 2015-06-25 04:21:02 -0400 | [diff] [blame] | 2266 | ndr_desc->num_mappings = count; |
| 2267 | rc = acpi_nfit_init_interleave_set(acpi_desc, ndr_desc, spa); |
Dan Williams | eaf9615 | 2015-05-01 13:11:27 -0400 | [diff] [blame] | 2268 | if (rc) |
Dan Williams | 1cf03c0 | 2016-02-17 13:01:23 -0800 | [diff] [blame] | 2269 | goto out; |
Dan Williams | eaf9615 | 2015-05-01 13:11:27 -0400 | [diff] [blame] | 2270 | |
Dan Williams | 1f7df6f | 2015-06-09 20:13:14 -0400 | [diff] [blame] | 2271 | nvdimm_bus = acpi_desc->nvdimm_bus; |
| 2272 | if (nfit_spa_type(spa) == NFIT_SPA_PM) { |
Toshi Kani | af1996e | 2016-03-09 12:47:06 -0700 | [diff] [blame] | 2273 | rc = acpi_nfit_insert_resource(acpi_desc, ndr_desc); |
Dan Williams | 4890116 | 2016-03-09 17:15:43 -0800 | [diff] [blame] | 2274 | if (rc) { |
Toshi Kani | af1996e | 2016-03-09 12:47:06 -0700 | [diff] [blame] | 2275 | dev_warn(acpi_desc->dev, |
| 2276 | "failed to insert pmem resource to iomem: %d\n", |
| 2277 | rc); |
Dan Williams | 4890116 | 2016-03-09 17:15:43 -0800 | [diff] [blame] | 2278 | goto out; |
Vishal Verma | 0caeef6 | 2015-12-24 19:21:43 -0700 | [diff] [blame] | 2279 | } |
Dan Williams | 4890116 | 2016-03-09 17:15:43 -0800 | [diff] [blame] | 2280 | |
Dan Williams | 1cf03c0 | 2016-02-17 13:01:23 -0800 | [diff] [blame] | 2281 | nfit_spa->nd_region = nvdimm_pmem_region_create(nvdimm_bus, |
| 2282 | ndr_desc); |
| 2283 | if (!nfit_spa->nd_region) |
| 2284 | rc = -ENOMEM; |
Dan Williams | 1f7df6f | 2015-06-09 20:13:14 -0400 | [diff] [blame] | 2285 | } else if (nfit_spa_type(spa) == NFIT_SPA_VOLATILE) { |
Dan Williams | 1cf03c0 | 2016-02-17 13:01:23 -0800 | [diff] [blame] | 2286 | nfit_spa->nd_region = nvdimm_volatile_region_create(nvdimm_bus, |
| 2287 | ndr_desc); |
| 2288 | if (!nfit_spa->nd_region) |
| 2289 | rc = -ENOMEM; |
Lee, Chun-Yi | c2f32ac | 2016-07-15 12:05:35 +0800 | [diff] [blame] | 2290 | } else if (nfit_spa_is_virtual(spa)) { |
| 2291 | nfit_spa->nd_region = nvdimm_pmem_region_create(nvdimm_bus, |
| 2292 | ndr_desc); |
| 2293 | if (!nfit_spa->nd_region) |
| 2294 | rc = -ENOMEM; |
Dan Williams | 1f7df6f | 2015-06-09 20:13:14 -0400 | [diff] [blame] | 2295 | } |
Vishal Verma | 2098516 | 2015-10-27 16:58:27 -0600 | [diff] [blame] | 2296 | |
Dan Williams | 1cf03c0 | 2016-02-17 13:01:23 -0800 | [diff] [blame] | 2297 | out: |
| 2298 | if (rc) |
| 2299 | dev_err(acpi_desc->dev, "failed to register spa range %d\n", |
| 2300 | nfit_spa->spa->range_index); |
| 2301 | return rc; |
| 2302 | } |
| 2303 | |
| 2304 | static int ars_status_alloc(struct acpi_nfit_desc *acpi_desc, |
| 2305 | u32 max_ars) |
| 2306 | { |
| 2307 | struct device *dev = acpi_desc->dev; |
| 2308 | struct nd_cmd_ars_status *ars_status; |
| 2309 | |
| 2310 | if (acpi_desc->ars_status && acpi_desc->ars_status_size >= max_ars) { |
| 2311 | memset(acpi_desc->ars_status, 0, acpi_desc->ars_status_size); |
| 2312 | return 0; |
| 2313 | } |
| 2314 | |
| 2315 | if (acpi_desc->ars_status) |
| 2316 | devm_kfree(dev, acpi_desc->ars_status); |
| 2317 | acpi_desc->ars_status = NULL; |
| 2318 | ars_status = devm_kzalloc(dev, max_ars, GFP_KERNEL); |
| 2319 | if (!ars_status) |
| 2320 | return -ENOMEM; |
| 2321 | acpi_desc->ars_status = ars_status; |
| 2322 | acpi_desc->ars_status_size = max_ars; |
Dan Williams | 1f7df6f | 2015-06-09 20:13:14 -0400 | [diff] [blame] | 2323 | return 0; |
| 2324 | } |
| 2325 | |
Dan Williams | 1cf03c0 | 2016-02-17 13:01:23 -0800 | [diff] [blame] | 2326 | static int acpi_nfit_query_poison(struct acpi_nfit_desc *acpi_desc, |
| 2327 | struct nfit_spa *nfit_spa) |
| 2328 | { |
| 2329 | struct acpi_nfit_system_address *spa = nfit_spa->spa; |
| 2330 | int rc; |
| 2331 | |
| 2332 | if (!nfit_spa->max_ars) { |
| 2333 | struct nd_cmd_ars_cap ars_cap; |
| 2334 | |
| 2335 | memset(&ars_cap, 0, sizeof(ars_cap)); |
| 2336 | rc = ars_get_cap(acpi_desc, &ars_cap, nfit_spa); |
| 2337 | if (rc < 0) |
| 2338 | return rc; |
| 2339 | nfit_spa->max_ars = ars_cap.max_ars_out; |
| 2340 | nfit_spa->clear_err_unit = ars_cap.clear_err_unit; |
| 2341 | /* check that the supported scrub types match the spa type */ |
| 2342 | if (nfit_spa_type(spa) == NFIT_SPA_VOLATILE && |
| 2343 | ((ars_cap.status >> 16) & ND_ARS_VOLATILE) == 0) |
| 2344 | return -ENOTTY; |
| 2345 | else if (nfit_spa_type(spa) == NFIT_SPA_PM && |
| 2346 | ((ars_cap.status >> 16) & ND_ARS_PERSISTENT) == 0) |
| 2347 | return -ENOTTY; |
| 2348 | } |
| 2349 | |
| 2350 | if (ars_status_alloc(acpi_desc, nfit_spa->max_ars)) |
| 2351 | return -ENOMEM; |
| 2352 | |
| 2353 | rc = ars_get_status(acpi_desc); |
| 2354 | if (rc < 0 && rc != -ENOSPC) |
| 2355 | return rc; |
| 2356 | |
Dan Williams | 82aa37c | 2016-12-06 12:45:24 -0800 | [diff] [blame] | 2357 | if (ars_status_process_records(acpi_desc, acpi_desc->ars_status)) |
Dan Williams | 1cf03c0 | 2016-02-17 13:01:23 -0800 | [diff] [blame] | 2358 | return -ENOMEM; |
| 2359 | |
| 2360 | return 0; |
| 2361 | } |
| 2362 | |
| 2363 | static void acpi_nfit_async_scrub(struct acpi_nfit_desc *acpi_desc, |
| 2364 | struct nfit_spa *nfit_spa) |
| 2365 | { |
| 2366 | struct acpi_nfit_system_address *spa = nfit_spa->spa; |
| 2367 | unsigned int overflow_retry = scrub_overflow_abort; |
| 2368 | u64 init_ars_start = 0, init_ars_len = 0; |
| 2369 | struct device *dev = acpi_desc->dev; |
| 2370 | unsigned int tmo = scrub_timeout; |
| 2371 | int rc; |
| 2372 | |
Vishal Verma | 37b137f | 2016-07-23 21:51:42 -0700 | [diff] [blame] | 2373 | if (!nfit_spa->ars_required || !nfit_spa->nd_region) |
Dan Williams | 1cf03c0 | 2016-02-17 13:01:23 -0800 | [diff] [blame] | 2374 | return; |
| 2375 | |
| 2376 | rc = ars_start(acpi_desc, nfit_spa); |
| 2377 | /* |
| 2378 | * If we timed out the initial scan we'll still be busy here, |
| 2379 | * and will wait another timeout before giving up permanently. |
| 2380 | */ |
| 2381 | if (rc < 0 && rc != -EBUSY) |
| 2382 | return; |
| 2383 | |
| 2384 | do { |
| 2385 | u64 ars_start, ars_len; |
| 2386 | |
| 2387 | if (acpi_desc->cancel) |
| 2388 | break; |
| 2389 | rc = acpi_nfit_query_poison(acpi_desc, nfit_spa); |
| 2390 | if (rc == -ENOTTY) |
| 2391 | break; |
| 2392 | if (rc == -EBUSY && !tmo) { |
| 2393 | dev_warn(dev, "range %d ars timeout, aborting\n", |
| 2394 | spa->range_index); |
| 2395 | break; |
| 2396 | } |
| 2397 | |
| 2398 | if (rc == -EBUSY) { |
| 2399 | /* |
| 2400 | * Note, entries may be appended to the list |
| 2401 | * while the lock is dropped, but the workqueue |
| 2402 | * being active prevents entries being deleted / |
| 2403 | * freed. |
| 2404 | */ |
| 2405 | mutex_unlock(&acpi_desc->init_mutex); |
| 2406 | ssleep(1); |
| 2407 | tmo--; |
| 2408 | mutex_lock(&acpi_desc->init_mutex); |
| 2409 | continue; |
| 2410 | } |
| 2411 | |
| 2412 | /* we got some results, but there are more pending... */ |
| 2413 | if (rc == -ENOSPC && overflow_retry--) { |
| 2414 | if (!init_ars_len) { |
| 2415 | init_ars_len = acpi_desc->ars_status->length; |
| 2416 | init_ars_start = acpi_desc->ars_status->address; |
| 2417 | } |
| 2418 | rc = ars_continue(acpi_desc); |
| 2419 | } |
| 2420 | |
| 2421 | if (rc < 0) { |
| 2422 | dev_warn(dev, "range %d ars continuation failed\n", |
| 2423 | spa->range_index); |
| 2424 | break; |
| 2425 | } |
| 2426 | |
| 2427 | if (init_ars_len) { |
| 2428 | ars_start = init_ars_start; |
| 2429 | ars_len = init_ars_len; |
| 2430 | } else { |
| 2431 | ars_start = acpi_desc->ars_status->address; |
| 2432 | ars_len = acpi_desc->ars_status->length; |
| 2433 | } |
| 2434 | dev_dbg(dev, "spa range: %d ars from %#llx + %#llx complete\n", |
| 2435 | spa->range_index, ars_start, ars_len); |
| 2436 | /* notify the region about new poison entries */ |
| 2437 | nvdimm_region_notify(nfit_spa->nd_region, |
| 2438 | NVDIMM_REVALIDATE_POISON); |
| 2439 | break; |
| 2440 | } while (1); |
| 2441 | } |
| 2442 | |
| 2443 | static void acpi_nfit_scrub(struct work_struct *work) |
| 2444 | { |
| 2445 | struct device *dev; |
| 2446 | u64 init_scrub_length = 0; |
| 2447 | struct nfit_spa *nfit_spa; |
| 2448 | u64 init_scrub_address = 0; |
| 2449 | bool init_ars_done = false; |
| 2450 | struct acpi_nfit_desc *acpi_desc; |
| 2451 | unsigned int tmo = scrub_timeout; |
| 2452 | unsigned int overflow_retry = scrub_overflow_abort; |
| 2453 | |
| 2454 | acpi_desc = container_of(work, typeof(*acpi_desc), work); |
| 2455 | dev = acpi_desc->dev; |
| 2456 | |
| 2457 | /* |
| 2458 | * We scrub in 2 phases. The first phase waits for any platform |
| 2459 | * firmware initiated scrubs to complete and then we go search for the |
| 2460 | * affected spa regions to mark them scanned. In the second phase we |
| 2461 | * initiate a directed scrub for every range that was not scrubbed in |
Vishal Verma | 37b137f | 2016-07-23 21:51:42 -0700 | [diff] [blame] | 2462 | * phase 1. If we're called for a 'rescan', we harmlessly pass through |
| 2463 | * the first phase, but really only care about running phase 2, where |
| 2464 | * regions can be notified of new poison. |
Dan Williams | 1cf03c0 | 2016-02-17 13:01:23 -0800 | [diff] [blame] | 2465 | */ |
| 2466 | |
| 2467 | /* process platform firmware initiated scrubs */ |
| 2468 | retry: |
| 2469 | mutex_lock(&acpi_desc->init_mutex); |
| 2470 | list_for_each_entry(nfit_spa, &acpi_desc->spas, list) { |
| 2471 | struct nd_cmd_ars_status *ars_status; |
| 2472 | struct acpi_nfit_system_address *spa; |
| 2473 | u64 ars_start, ars_len; |
| 2474 | int rc; |
| 2475 | |
| 2476 | if (acpi_desc->cancel) |
| 2477 | break; |
| 2478 | |
| 2479 | if (nfit_spa->nd_region) |
| 2480 | continue; |
| 2481 | |
| 2482 | if (init_ars_done) { |
| 2483 | /* |
| 2484 | * No need to re-query, we're now just |
| 2485 | * reconciling all the ranges covered by the |
| 2486 | * initial scrub |
| 2487 | */ |
| 2488 | rc = 0; |
| 2489 | } else |
| 2490 | rc = acpi_nfit_query_poison(acpi_desc, nfit_spa); |
| 2491 | |
| 2492 | if (rc == -ENOTTY) { |
| 2493 | /* no ars capability, just register spa and move on */ |
| 2494 | acpi_nfit_register_region(acpi_desc, nfit_spa); |
| 2495 | continue; |
| 2496 | } |
| 2497 | |
| 2498 | if (rc == -EBUSY && !tmo) { |
| 2499 | /* fallthrough to directed scrub in phase 2 */ |
| 2500 | dev_warn(dev, "timeout awaiting ars results, continuing...\n"); |
| 2501 | break; |
| 2502 | } else if (rc == -EBUSY) { |
| 2503 | mutex_unlock(&acpi_desc->init_mutex); |
| 2504 | ssleep(1); |
| 2505 | tmo--; |
| 2506 | goto retry; |
| 2507 | } |
| 2508 | |
| 2509 | /* we got some results, but there are more pending... */ |
| 2510 | if (rc == -ENOSPC && overflow_retry--) { |
| 2511 | ars_status = acpi_desc->ars_status; |
| 2512 | /* |
| 2513 | * Record the original scrub range, so that we |
| 2514 | * can recall all the ranges impacted by the |
| 2515 | * initial scrub. |
| 2516 | */ |
| 2517 | if (!init_scrub_length) { |
| 2518 | init_scrub_length = ars_status->length; |
| 2519 | init_scrub_address = ars_status->address; |
| 2520 | } |
| 2521 | rc = ars_continue(acpi_desc); |
| 2522 | if (rc == 0) { |
| 2523 | mutex_unlock(&acpi_desc->init_mutex); |
| 2524 | goto retry; |
| 2525 | } |
| 2526 | } |
| 2527 | |
| 2528 | if (rc < 0) { |
| 2529 | /* |
| 2530 | * Initial scrub failed, we'll give it one more |
| 2531 | * try below... |
| 2532 | */ |
| 2533 | break; |
| 2534 | } |
| 2535 | |
| 2536 | /* We got some final results, record completed ranges */ |
| 2537 | ars_status = acpi_desc->ars_status; |
| 2538 | if (init_scrub_length) { |
| 2539 | ars_start = init_scrub_address; |
| 2540 | ars_len = ars_start + init_scrub_length; |
| 2541 | } else { |
| 2542 | ars_start = ars_status->address; |
| 2543 | ars_len = ars_status->length; |
| 2544 | } |
| 2545 | spa = nfit_spa->spa; |
| 2546 | |
| 2547 | if (!init_ars_done) { |
| 2548 | init_ars_done = true; |
| 2549 | dev_dbg(dev, "init scrub %#llx + %#llx complete\n", |
| 2550 | ars_start, ars_len); |
| 2551 | } |
| 2552 | if (ars_start <= spa->address && ars_start + ars_len |
| 2553 | >= spa->address + spa->length) |
| 2554 | acpi_nfit_register_region(acpi_desc, nfit_spa); |
| 2555 | } |
| 2556 | |
| 2557 | /* |
| 2558 | * For all the ranges not covered by an initial scrub we still |
| 2559 | * want to see if there are errors, but it's ok to discover them |
| 2560 | * asynchronously. |
| 2561 | */ |
| 2562 | list_for_each_entry(nfit_spa, &acpi_desc->spas, list) { |
| 2563 | /* |
| 2564 | * Flag all the ranges that still need scrubbing, but |
| 2565 | * register them now to make data available. |
| 2566 | */ |
Vishal Verma | 37b137f | 2016-07-23 21:51:42 -0700 | [diff] [blame] | 2567 | if (!nfit_spa->nd_region) { |
| 2568 | nfit_spa->ars_required = 1; |
Dan Williams | 1cf03c0 | 2016-02-17 13:01:23 -0800 | [diff] [blame] | 2569 | acpi_nfit_register_region(acpi_desc, nfit_spa); |
Vishal Verma | 37b137f | 2016-07-23 21:51:42 -0700 | [diff] [blame] | 2570 | } |
Dan Williams | 1cf03c0 | 2016-02-17 13:01:23 -0800 | [diff] [blame] | 2571 | } |
| 2572 | |
| 2573 | list_for_each_entry(nfit_spa, &acpi_desc->spas, list) |
| 2574 | acpi_nfit_async_scrub(acpi_desc, nfit_spa); |
Vishal Verma | 37b137f | 2016-07-23 21:51:42 -0700 | [diff] [blame] | 2575 | acpi_desc->scrub_count++; |
| 2576 | if (acpi_desc->scrub_count_state) |
| 2577 | sysfs_notify_dirent(acpi_desc->scrub_count_state); |
Dan Williams | 1cf03c0 | 2016-02-17 13:01:23 -0800 | [diff] [blame] | 2578 | mutex_unlock(&acpi_desc->init_mutex); |
| 2579 | } |
| 2580 | |
Dan Williams | 1f7df6f | 2015-06-09 20:13:14 -0400 | [diff] [blame] | 2581 | static int acpi_nfit_register_regions(struct acpi_nfit_desc *acpi_desc) |
| 2582 | { |
| 2583 | struct nfit_spa *nfit_spa; |
Dan Williams | 1cf03c0 | 2016-02-17 13:01:23 -0800 | [diff] [blame] | 2584 | int rc; |
Dan Williams | 1f7df6f | 2015-06-09 20:13:14 -0400 | [diff] [blame] | 2585 | |
Dan Williams | 1cf03c0 | 2016-02-17 13:01:23 -0800 | [diff] [blame] | 2586 | list_for_each_entry(nfit_spa, &acpi_desc->spas, list) |
| 2587 | if (nfit_spa_type(nfit_spa->spa) == NFIT_SPA_DCR) { |
| 2588 | /* BLK regions don't need to wait for ars results */ |
| 2589 | rc = acpi_nfit_register_region(acpi_desc, nfit_spa); |
| 2590 | if (rc) |
| 2591 | return rc; |
| 2592 | } |
Dan Williams | 1f7df6f | 2015-06-09 20:13:14 -0400 | [diff] [blame] | 2593 | |
Dan Williams | 1cf03c0 | 2016-02-17 13:01:23 -0800 | [diff] [blame] | 2594 | queue_work(nfit_wq, &acpi_desc->work); |
Dan Williams | 1f7df6f | 2015-06-09 20:13:14 -0400 | [diff] [blame] | 2595 | return 0; |
| 2596 | } |
| 2597 | |
Vishal Verma | 2098516 | 2015-10-27 16:58:27 -0600 | [diff] [blame] | 2598 | static int acpi_nfit_check_deletions(struct acpi_nfit_desc *acpi_desc, |
| 2599 | struct nfit_table_prev *prev) |
| 2600 | { |
| 2601 | struct device *dev = acpi_desc->dev; |
| 2602 | |
| 2603 | if (!list_empty(&prev->spas) || |
| 2604 | !list_empty(&prev->memdevs) || |
| 2605 | !list_empty(&prev->dcrs) || |
| 2606 | !list_empty(&prev->bdws) || |
| 2607 | !list_empty(&prev->idts) || |
| 2608 | !list_empty(&prev->flushes)) { |
| 2609 | dev_err(dev, "new nfit deletes entries (unsupported)\n"); |
| 2610 | return -ENXIO; |
| 2611 | } |
| 2612 | return 0; |
| 2613 | } |
| 2614 | |
Vishal Verma | 37b137f | 2016-07-23 21:51:42 -0700 | [diff] [blame] | 2615 | static int acpi_nfit_desc_init_scrub_attr(struct acpi_nfit_desc *acpi_desc) |
| 2616 | { |
| 2617 | struct device *dev = acpi_desc->dev; |
| 2618 | struct kernfs_node *nfit; |
| 2619 | struct device *bus_dev; |
| 2620 | |
| 2621 | if (!ars_supported(acpi_desc->nvdimm_bus)) |
| 2622 | return 0; |
| 2623 | |
| 2624 | bus_dev = to_nvdimm_bus_dev(acpi_desc->nvdimm_bus); |
| 2625 | nfit = sysfs_get_dirent(bus_dev->kobj.sd, "nfit"); |
| 2626 | if (!nfit) { |
| 2627 | dev_err(dev, "sysfs_get_dirent 'nfit' failed\n"); |
| 2628 | return -ENODEV; |
| 2629 | } |
| 2630 | acpi_desc->scrub_count_state = sysfs_get_dirent(nfit, "scrub"); |
| 2631 | sysfs_put(nfit); |
| 2632 | if (!acpi_desc->scrub_count_state) { |
| 2633 | dev_err(dev, "sysfs_get_dirent 'scrub' failed\n"); |
| 2634 | return -ENODEV; |
| 2635 | } |
| 2636 | |
| 2637 | return 0; |
| 2638 | } |
| 2639 | |
Dan Williams | 58cd71b | 2016-07-21 18:05:36 -0700 | [diff] [blame] | 2640 | static void acpi_nfit_destruct(void *data) |
| 2641 | { |
| 2642 | struct acpi_nfit_desc *acpi_desc = data; |
Vishal Verma | 37b137f | 2016-07-23 21:51:42 -0700 | [diff] [blame] | 2643 | struct device *bus_dev = to_nvdimm_bus_dev(acpi_desc->nvdimm_bus); |
Dan Williams | 58cd71b | 2016-07-21 18:05:36 -0700 | [diff] [blame] | 2644 | |
Vishal Verma | 6839a6d | 2016-07-23 21:51:21 -0700 | [diff] [blame] | 2645 | /* |
| 2646 | * Destruct under acpi_desc_lock so that nfit_handle_mce does not |
| 2647 | * race teardown |
| 2648 | */ |
| 2649 | mutex_lock(&acpi_desc_lock); |
Dan Williams | 58cd71b | 2016-07-21 18:05:36 -0700 | [diff] [blame] | 2650 | acpi_desc->cancel = 1; |
Vishal Verma | 37b137f | 2016-07-23 21:51:42 -0700 | [diff] [blame] | 2651 | /* |
| 2652 | * Bounce the nvdimm bus lock to make sure any in-flight |
| 2653 | * acpi_nfit_ars_rescan() submissions have had a chance to |
| 2654 | * either submit or see ->cancel set. |
| 2655 | */ |
| 2656 | device_lock(bus_dev); |
| 2657 | device_unlock(bus_dev); |
| 2658 | |
Dan Williams | 58cd71b | 2016-07-21 18:05:36 -0700 | [diff] [blame] | 2659 | flush_workqueue(nfit_wq); |
Vishal Verma | 37b137f | 2016-07-23 21:51:42 -0700 | [diff] [blame] | 2660 | if (acpi_desc->scrub_count_state) |
| 2661 | sysfs_put(acpi_desc->scrub_count_state); |
Dan Williams | 58cd71b | 2016-07-21 18:05:36 -0700 | [diff] [blame] | 2662 | nvdimm_bus_unregister(acpi_desc->nvdimm_bus); |
| 2663 | acpi_desc->nvdimm_bus = NULL; |
Vishal Verma | 6839a6d | 2016-07-23 21:51:21 -0700 | [diff] [blame] | 2664 | list_del(&acpi_desc->list); |
| 2665 | mutex_unlock(&acpi_desc_lock); |
Dan Williams | 58cd71b | 2016-07-21 18:05:36 -0700 | [diff] [blame] | 2666 | } |
| 2667 | |
Dan Williams | e7a11b4 | 2016-07-14 16:19:55 -0700 | [diff] [blame] | 2668 | int acpi_nfit_init(struct acpi_nfit_desc *acpi_desc, void *data, acpi_size sz) |
Dan Williams | b94d523 | 2015-05-19 22:54:31 -0400 | [diff] [blame] | 2669 | { |
| 2670 | struct device *dev = acpi_desc->dev; |
Vishal Verma | 2098516 | 2015-10-27 16:58:27 -0600 | [diff] [blame] | 2671 | struct nfit_table_prev prev; |
Dan Williams | b94d523 | 2015-05-19 22:54:31 -0400 | [diff] [blame] | 2672 | const void *end; |
Dan Williams | 1f7df6f | 2015-06-09 20:13:14 -0400 | [diff] [blame] | 2673 | int rc; |
Dan Williams | b94d523 | 2015-05-19 22:54:31 -0400 | [diff] [blame] | 2674 | |
Dan Williams | 58cd71b | 2016-07-21 18:05:36 -0700 | [diff] [blame] | 2675 | if (!acpi_desc->nvdimm_bus) { |
Vishal Verma | 37b137f | 2016-07-23 21:51:42 -0700 | [diff] [blame] | 2676 | acpi_nfit_init_dsms(acpi_desc); |
| 2677 | |
Dan Williams | 58cd71b | 2016-07-21 18:05:36 -0700 | [diff] [blame] | 2678 | acpi_desc->nvdimm_bus = nvdimm_bus_register(dev, |
| 2679 | &acpi_desc->nd_desc); |
| 2680 | if (!acpi_desc->nvdimm_bus) |
| 2681 | return -ENOMEM; |
Vishal Verma | 37b137f | 2016-07-23 21:51:42 -0700 | [diff] [blame] | 2682 | |
Dan Williams | 58cd71b | 2016-07-21 18:05:36 -0700 | [diff] [blame] | 2683 | rc = devm_add_action_or_reset(dev, acpi_nfit_destruct, |
| 2684 | acpi_desc); |
| 2685 | if (rc) |
| 2686 | return rc; |
Vishal Verma | 37b137f | 2016-07-23 21:51:42 -0700 | [diff] [blame] | 2687 | |
| 2688 | rc = acpi_nfit_desc_init_scrub_attr(acpi_desc); |
| 2689 | if (rc) |
| 2690 | return rc; |
Vishal Verma | 6839a6d | 2016-07-23 21:51:21 -0700 | [diff] [blame] | 2691 | |
| 2692 | /* register this acpi_desc for mce notifications */ |
| 2693 | mutex_lock(&acpi_desc_lock); |
| 2694 | list_add_tail(&acpi_desc->list, &acpi_descs); |
| 2695 | mutex_unlock(&acpi_desc_lock); |
Dan Williams | 58cd71b | 2016-07-21 18:05:36 -0700 | [diff] [blame] | 2696 | } |
| 2697 | |
Vishal Verma | 2098516 | 2015-10-27 16:58:27 -0600 | [diff] [blame] | 2698 | mutex_lock(&acpi_desc->init_mutex); |
| 2699 | |
| 2700 | INIT_LIST_HEAD(&prev.spas); |
| 2701 | INIT_LIST_HEAD(&prev.memdevs); |
| 2702 | INIT_LIST_HEAD(&prev.dcrs); |
| 2703 | INIT_LIST_HEAD(&prev.bdws); |
| 2704 | INIT_LIST_HEAD(&prev.idts); |
| 2705 | INIT_LIST_HEAD(&prev.flushes); |
| 2706 | |
| 2707 | list_cut_position(&prev.spas, &acpi_desc->spas, |
| 2708 | acpi_desc->spas.prev); |
| 2709 | list_cut_position(&prev.memdevs, &acpi_desc->memdevs, |
| 2710 | acpi_desc->memdevs.prev); |
| 2711 | list_cut_position(&prev.dcrs, &acpi_desc->dcrs, |
| 2712 | acpi_desc->dcrs.prev); |
| 2713 | list_cut_position(&prev.bdws, &acpi_desc->bdws, |
| 2714 | acpi_desc->bdws.prev); |
| 2715 | list_cut_position(&prev.idts, &acpi_desc->idts, |
| 2716 | acpi_desc->idts.prev); |
| 2717 | list_cut_position(&prev.flushes, &acpi_desc->flushes, |
| 2718 | acpi_desc->flushes.prev); |
| 2719 | |
Vishal Verma | 2098516 | 2015-10-27 16:58:27 -0600 | [diff] [blame] | 2720 | end = data + sz; |
Vishal Verma | 2098516 | 2015-10-27 16:58:27 -0600 | [diff] [blame] | 2721 | while (!IS_ERR_OR_NULL(data)) |
| 2722 | data = add_table(acpi_desc, &prev, data, end); |
| 2723 | |
| 2724 | if (IS_ERR(data)) { |
| 2725 | dev_dbg(dev, "%s: nfit table parsing error: %ld\n", __func__, |
| 2726 | PTR_ERR(data)); |
| 2727 | rc = PTR_ERR(data); |
| 2728 | goto out_unlock; |
| 2729 | } |
| 2730 | |
| 2731 | rc = acpi_nfit_check_deletions(acpi_desc, &prev); |
| 2732 | if (rc) |
| 2733 | goto out_unlock; |
| 2734 | |
Dan Williams | 81ed4e3 | 2016-06-10 18:20:53 -0700 | [diff] [blame] | 2735 | rc = nfit_mem_init(acpi_desc); |
| 2736 | if (rc) |
Vishal Verma | 2098516 | 2015-10-27 16:58:27 -0600 | [diff] [blame] | 2737 | goto out_unlock; |
Vishal Verma | 2098516 | 2015-10-27 16:58:27 -0600 | [diff] [blame] | 2738 | |
| 2739 | rc = acpi_nfit_register_dimms(acpi_desc); |
| 2740 | if (rc) |
| 2741 | goto out_unlock; |
| 2742 | |
| 2743 | rc = acpi_nfit_register_regions(acpi_desc); |
| 2744 | |
| 2745 | out_unlock: |
| 2746 | mutex_unlock(&acpi_desc->init_mutex); |
| 2747 | return rc; |
| 2748 | } |
| 2749 | EXPORT_SYMBOL_GPL(acpi_nfit_init); |
| 2750 | |
Dan Williams | 7ae0fa43 | 2016-02-19 12:16:34 -0800 | [diff] [blame] | 2751 | struct acpi_nfit_flush_work { |
| 2752 | struct work_struct work; |
| 2753 | struct completion cmp; |
| 2754 | }; |
| 2755 | |
| 2756 | static void flush_probe(struct work_struct *work) |
| 2757 | { |
| 2758 | struct acpi_nfit_flush_work *flush; |
| 2759 | |
| 2760 | flush = container_of(work, typeof(*flush), work); |
| 2761 | complete(&flush->cmp); |
| 2762 | } |
| 2763 | |
| 2764 | static int acpi_nfit_flush_probe(struct nvdimm_bus_descriptor *nd_desc) |
| 2765 | { |
| 2766 | struct acpi_nfit_desc *acpi_desc = to_acpi_nfit_desc(nd_desc); |
| 2767 | struct device *dev = acpi_desc->dev; |
| 2768 | struct acpi_nfit_flush_work flush; |
Dan Williams | e471486 | 2017-02-02 10:31:00 -0800 | [diff] [blame] | 2769 | int rc; |
Dan Williams | 7ae0fa43 | 2016-02-19 12:16:34 -0800 | [diff] [blame] | 2770 | |
| 2771 | /* bounce the device lock to flush acpi_nfit_add / acpi_nfit_notify */ |
| 2772 | device_lock(dev); |
| 2773 | device_unlock(dev); |
| 2774 | |
| 2775 | /* |
| 2776 | * Scrub work could take 10s of seconds, userspace may give up so we |
| 2777 | * need to be interruptible while waiting. |
| 2778 | */ |
| 2779 | INIT_WORK_ONSTACK(&flush.work, flush_probe); |
| 2780 | COMPLETION_INITIALIZER_ONSTACK(flush.cmp); |
| 2781 | queue_work(nfit_wq, &flush.work); |
Dan Williams | e471486 | 2017-02-02 10:31:00 -0800 | [diff] [blame] | 2782 | |
| 2783 | rc = wait_for_completion_interruptible(&flush.cmp); |
| 2784 | cancel_work_sync(&flush.work); |
| 2785 | return rc; |
Dan Williams | 7ae0fa43 | 2016-02-19 12:16:34 -0800 | [diff] [blame] | 2786 | } |
| 2787 | |
Dan Williams | 87bf572 | 2016-02-22 21:50:31 -0800 | [diff] [blame] | 2788 | static int acpi_nfit_clear_to_send(struct nvdimm_bus_descriptor *nd_desc, |
| 2789 | struct nvdimm *nvdimm, unsigned int cmd) |
| 2790 | { |
| 2791 | struct acpi_nfit_desc *acpi_desc = to_acpi_nfit_desc(nd_desc); |
| 2792 | |
| 2793 | if (nvdimm) |
| 2794 | return 0; |
| 2795 | if (cmd != ND_CMD_ARS_START) |
| 2796 | return 0; |
| 2797 | |
| 2798 | /* |
| 2799 | * The kernel and userspace may race to initiate a scrub, but |
| 2800 | * the scrub thread is prepared to lose that initial race. It |
| 2801 | * just needs guarantees that any ars it initiates are not |
| 2802 | * interrupted by any intervening start reqeusts from userspace. |
| 2803 | */ |
| 2804 | if (work_busy(&acpi_desc->work)) |
| 2805 | return -EBUSY; |
| 2806 | |
| 2807 | return 0; |
| 2808 | } |
| 2809 | |
Vishal Verma | 6839a6d | 2016-07-23 21:51:21 -0700 | [diff] [blame] | 2810 | int acpi_nfit_ars_rescan(struct acpi_nfit_desc *acpi_desc) |
Vishal Verma | 37b137f | 2016-07-23 21:51:42 -0700 | [diff] [blame] | 2811 | { |
| 2812 | struct device *dev = acpi_desc->dev; |
| 2813 | struct nfit_spa *nfit_spa; |
| 2814 | |
| 2815 | if (work_busy(&acpi_desc->work)) |
| 2816 | return -EBUSY; |
| 2817 | |
| 2818 | if (acpi_desc->cancel) |
| 2819 | return 0; |
| 2820 | |
| 2821 | mutex_lock(&acpi_desc->init_mutex); |
| 2822 | list_for_each_entry(nfit_spa, &acpi_desc->spas, list) { |
| 2823 | struct acpi_nfit_system_address *spa = nfit_spa->spa; |
| 2824 | |
| 2825 | if (nfit_spa_type(spa) != NFIT_SPA_PM) |
| 2826 | continue; |
| 2827 | |
| 2828 | nfit_spa->ars_required = 1; |
| 2829 | } |
| 2830 | queue_work(nfit_wq, &acpi_desc->work); |
| 2831 | dev_dbg(dev, "%s: ars_scan triggered\n", __func__); |
| 2832 | mutex_unlock(&acpi_desc->init_mutex); |
| 2833 | |
| 2834 | return 0; |
| 2835 | } |
| 2836 | |
Dan Williams | a61fe6f | 2016-02-19 12:29:32 -0800 | [diff] [blame] | 2837 | void acpi_nfit_desc_init(struct acpi_nfit_desc *acpi_desc, struct device *dev) |
Vishal Verma | 2098516 | 2015-10-27 16:58:27 -0600 | [diff] [blame] | 2838 | { |
| 2839 | struct nvdimm_bus_descriptor *nd_desc; |
Vishal Verma | 2098516 | 2015-10-27 16:58:27 -0600 | [diff] [blame] | 2840 | |
| 2841 | dev_set_drvdata(dev, acpi_desc); |
| 2842 | acpi_desc->dev = dev; |
| 2843 | acpi_desc->blk_do_io = acpi_nfit_blk_region_do_io; |
| 2844 | nd_desc = &acpi_desc->nd_desc; |
| 2845 | nd_desc->provider_name = "ACPI.NFIT"; |
Dan Williams | bc9775d | 2016-07-21 20:03:19 -0700 | [diff] [blame] | 2846 | nd_desc->module = THIS_MODULE; |
Vishal Verma | 2098516 | 2015-10-27 16:58:27 -0600 | [diff] [blame] | 2847 | nd_desc->ndctl = acpi_nfit_ctl; |
Dan Williams | 7ae0fa43 | 2016-02-19 12:16:34 -0800 | [diff] [blame] | 2848 | nd_desc->flush_probe = acpi_nfit_flush_probe; |
Dan Williams | 87bf572 | 2016-02-22 21:50:31 -0800 | [diff] [blame] | 2849 | nd_desc->clear_to_send = acpi_nfit_clear_to_send; |
Vishal Verma | 2098516 | 2015-10-27 16:58:27 -0600 | [diff] [blame] | 2850 | nd_desc->attr_groups = acpi_nfit_attribute_groups; |
| 2851 | |
Dan Williams | b94d523 | 2015-05-19 22:54:31 -0400 | [diff] [blame] | 2852 | INIT_LIST_HEAD(&acpi_desc->spas); |
| 2853 | INIT_LIST_HEAD(&acpi_desc->dcrs); |
| 2854 | INIT_LIST_HEAD(&acpi_desc->bdws); |
Ross Zwisler | 047fc8a | 2015-06-25 04:21:02 -0400 | [diff] [blame] | 2855 | INIT_LIST_HEAD(&acpi_desc->idts); |
Ross Zwisler | c2ad295 | 2015-07-10 11:06:13 -0600 | [diff] [blame] | 2856 | INIT_LIST_HEAD(&acpi_desc->flushes); |
Dan Williams | b94d523 | 2015-05-19 22:54:31 -0400 | [diff] [blame] | 2857 | INIT_LIST_HEAD(&acpi_desc->memdevs); |
| 2858 | INIT_LIST_HEAD(&acpi_desc->dimms); |
Vishal Verma | 6839a6d | 2016-07-23 21:51:21 -0700 | [diff] [blame] | 2859 | INIT_LIST_HEAD(&acpi_desc->list); |
Vishal Verma | 2098516 | 2015-10-27 16:58:27 -0600 | [diff] [blame] | 2860 | mutex_init(&acpi_desc->init_mutex); |
Dan Williams | 1cf03c0 | 2016-02-17 13:01:23 -0800 | [diff] [blame] | 2861 | INIT_WORK(&acpi_desc->work, acpi_nfit_scrub); |
Dan Williams | b94d523 | 2015-05-19 22:54:31 -0400 | [diff] [blame] | 2862 | } |
Dan Williams | a61fe6f | 2016-02-19 12:29:32 -0800 | [diff] [blame] | 2863 | EXPORT_SYMBOL_GPL(acpi_nfit_desc_init); |
Dan Williams | b94d523 | 2015-05-19 22:54:31 -0400 | [diff] [blame] | 2864 | |
Dan Williams | 3c87f37 | 2017-04-03 13:52:14 -0700 | [diff] [blame] | 2865 | static void acpi_nfit_put_table(void *table) |
| 2866 | { |
| 2867 | acpi_put_table(table); |
| 2868 | } |
| 2869 | |
Dan Williams | b94d523 | 2015-05-19 22:54:31 -0400 | [diff] [blame] | 2870 | static int acpi_nfit_add(struct acpi_device *adev) |
| 2871 | { |
Vishal Verma | 2098516 | 2015-10-27 16:58:27 -0600 | [diff] [blame] | 2872 | struct acpi_buffer buf = { ACPI_ALLOCATE_BUFFER, NULL }; |
Dan Williams | b94d523 | 2015-05-19 22:54:31 -0400 | [diff] [blame] | 2873 | struct acpi_nfit_desc *acpi_desc; |
| 2874 | struct device *dev = &adev->dev; |
| 2875 | struct acpi_table_header *tbl; |
| 2876 | acpi_status status = AE_OK; |
| 2877 | acpi_size sz; |
Dan Williams | 3193204 | 2016-07-14 17:22:48 -0700 | [diff] [blame] | 2878 | int rc = 0; |
Dan Williams | b94d523 | 2015-05-19 22:54:31 -0400 | [diff] [blame] | 2879 | |
Lv Zheng | 6b11d1d | 2016-12-14 15:04:39 +0800 | [diff] [blame] | 2880 | status = acpi_get_table(ACPI_SIG_NFIT, 0, &tbl); |
Dan Williams | b94d523 | 2015-05-19 22:54:31 -0400 | [diff] [blame] | 2881 | if (ACPI_FAILURE(status)) { |
Vishal Verma | 2098516 | 2015-10-27 16:58:27 -0600 | [diff] [blame] | 2882 | /* This is ok, we could have an nvdimm hotplugged later */ |
| 2883 | dev_dbg(dev, "failed to find NFIT at startup\n"); |
| 2884 | return 0; |
Dan Williams | b94d523 | 2015-05-19 22:54:31 -0400 | [diff] [blame] | 2885 | } |
Dan Williams | 3c87f37 | 2017-04-03 13:52:14 -0700 | [diff] [blame] | 2886 | |
| 2887 | rc = devm_add_action_or_reset(dev, acpi_nfit_put_table, tbl); |
| 2888 | if (rc) |
| 2889 | return rc; |
Lv Zheng | 6b11d1d | 2016-12-14 15:04:39 +0800 | [diff] [blame] | 2890 | sz = tbl->length; |
Dan Williams | b94d523 | 2015-05-19 22:54:31 -0400 | [diff] [blame] | 2891 | |
Dan Williams | a61fe6f | 2016-02-19 12:29:32 -0800 | [diff] [blame] | 2892 | acpi_desc = devm_kzalloc(dev, sizeof(*acpi_desc), GFP_KERNEL); |
| 2893 | if (!acpi_desc) |
| 2894 | return -ENOMEM; |
| 2895 | acpi_nfit_desc_init(acpi_desc, &adev->dev); |
Dan Williams | b94d523 | 2015-05-19 22:54:31 -0400 | [diff] [blame] | 2896 | |
Dan Williams | e7a11b4 | 2016-07-14 16:19:55 -0700 | [diff] [blame] | 2897 | /* Save the acpi header for exporting the revision via sysfs */ |
Linda Knippers | 6b577c9 | 2015-11-20 19:05:49 -0500 | [diff] [blame] | 2898 | acpi_desc->acpi_header = *tbl; |
Dan Williams | b94d523 | 2015-05-19 22:54:31 -0400 | [diff] [blame] | 2899 | |
Vishal Verma | 2098516 | 2015-10-27 16:58:27 -0600 | [diff] [blame] | 2900 | /* Evaluate _FIT and override with that if present */ |
| 2901 | status = acpi_evaluate_object(adev->handle, "_FIT", NULL, &buf); |
| 2902 | if (ACPI_SUCCESS(status) && buf.length > 0) { |
Dan Williams | e7a11b4 | 2016-07-14 16:19:55 -0700 | [diff] [blame] | 2903 | union acpi_object *obj = buf.pointer; |
| 2904 | |
| 2905 | if (obj->type == ACPI_TYPE_BUFFER) |
| 2906 | rc = acpi_nfit_init(acpi_desc, obj->buffer.pointer, |
| 2907 | obj->buffer.length); |
| 2908 | else |
Linda Knippers | 6b577c9 | 2015-11-20 19:05:49 -0500 | [diff] [blame] | 2909 | dev_dbg(dev, "%s invalid type %d, ignoring _FIT\n", |
| 2910 | __func__, (int) obj->type); |
Dan Williams | 3193204 | 2016-07-14 17:22:48 -0700 | [diff] [blame] | 2911 | kfree(buf.pointer); |
| 2912 | } else |
Dan Williams | e7a11b4 | 2016-07-14 16:19:55 -0700 | [diff] [blame] | 2913 | /* skip over the lead-in header table */ |
| 2914 | rc = acpi_nfit_init(acpi_desc, (void *) tbl |
| 2915 | + sizeof(struct acpi_table_nfit), |
| 2916 | sz - sizeof(struct acpi_table_nfit)); |
Dan Williams | e7a11b4 | 2016-07-14 16:19:55 -0700 | [diff] [blame] | 2917 | return rc; |
Dan Williams | b94d523 | 2015-05-19 22:54:31 -0400 | [diff] [blame] | 2918 | } |
| 2919 | |
| 2920 | static int acpi_nfit_remove(struct acpi_device *adev) |
| 2921 | { |
Dan Williams | 58cd71b | 2016-07-21 18:05:36 -0700 | [diff] [blame] | 2922 | /* see acpi_nfit_destruct */ |
Dan Williams | b94d523 | 2015-05-19 22:54:31 -0400 | [diff] [blame] | 2923 | return 0; |
| 2924 | } |
| 2925 | |
Dan Williams | c14a868 | 2016-08-18 22:15:04 -0700 | [diff] [blame] | 2926 | void __acpi_nfit_notify(struct device *dev, acpi_handle handle, u32 event) |
Vishal Verma | 2098516 | 2015-10-27 16:58:27 -0600 | [diff] [blame] | 2927 | { |
Dan Williams | c14a868 | 2016-08-18 22:15:04 -0700 | [diff] [blame] | 2928 | struct acpi_nfit_desc *acpi_desc = dev_get_drvdata(dev); |
Vishal Verma | 2098516 | 2015-10-27 16:58:27 -0600 | [diff] [blame] | 2929 | struct acpi_buffer buf = { ACPI_ALLOCATE_BUFFER, NULL }; |
Dan Williams | e7a11b4 | 2016-07-14 16:19:55 -0700 | [diff] [blame] | 2930 | union acpi_object *obj; |
Vishal Verma | 2098516 | 2015-10-27 16:58:27 -0600 | [diff] [blame] | 2931 | acpi_status status; |
| 2932 | int ret; |
| 2933 | |
| 2934 | dev_dbg(dev, "%s: event: %d\n", __func__, event); |
| 2935 | |
Vishal Verma | c09f121 | 2016-08-19 14:40:58 -0600 | [diff] [blame] | 2936 | if (event != NFIT_NOTIFY_UPDATE) |
| 2937 | return; |
| 2938 | |
Vishal Verma | 2098516 | 2015-10-27 16:58:27 -0600 | [diff] [blame] | 2939 | if (!dev->driver) { |
| 2940 | /* dev->driver may be null if we're being removed */ |
| 2941 | dev_dbg(dev, "%s: no driver found for dev\n", __func__); |
Dan Williams | c14a868 | 2016-08-18 22:15:04 -0700 | [diff] [blame] | 2942 | return; |
Vishal Verma | 2098516 | 2015-10-27 16:58:27 -0600 | [diff] [blame] | 2943 | } |
| 2944 | |
| 2945 | if (!acpi_desc) { |
Dan Williams | a61fe6f | 2016-02-19 12:29:32 -0800 | [diff] [blame] | 2946 | acpi_desc = devm_kzalloc(dev, sizeof(*acpi_desc), GFP_KERNEL); |
| 2947 | if (!acpi_desc) |
Dan Williams | c14a868 | 2016-08-18 22:15:04 -0700 | [diff] [blame] | 2948 | return; |
| 2949 | acpi_nfit_desc_init(acpi_desc, dev); |
Dan Williams | 7ae0fa43 | 2016-02-19 12:16:34 -0800 | [diff] [blame] | 2950 | } else { |
| 2951 | /* |
| 2952 | * Finish previous registration before considering new |
| 2953 | * regions. |
| 2954 | */ |
| 2955 | flush_workqueue(nfit_wq); |
Vishal Verma | 2098516 | 2015-10-27 16:58:27 -0600 | [diff] [blame] | 2956 | } |
| 2957 | |
| 2958 | /* Evaluate _FIT */ |
Dan Williams | c14a868 | 2016-08-18 22:15:04 -0700 | [diff] [blame] | 2959 | status = acpi_evaluate_object(handle, "_FIT", NULL, &buf); |
Vishal Verma | 2098516 | 2015-10-27 16:58:27 -0600 | [diff] [blame] | 2960 | if (ACPI_FAILURE(status)) { |
| 2961 | dev_err(dev, "failed to evaluate _FIT\n"); |
Dan Williams | c14a868 | 2016-08-18 22:15:04 -0700 | [diff] [blame] | 2962 | return; |
Vishal Verma | 2098516 | 2015-10-27 16:58:27 -0600 | [diff] [blame] | 2963 | } |
| 2964 | |
Linda Knippers | 6b577c9 | 2015-11-20 19:05:49 -0500 | [diff] [blame] | 2965 | obj = buf.pointer; |
| 2966 | if (obj->type == ACPI_TYPE_BUFFER) { |
Dan Williams | e7a11b4 | 2016-07-14 16:19:55 -0700 | [diff] [blame] | 2967 | ret = acpi_nfit_init(acpi_desc, obj->buffer.pointer, |
| 2968 | obj->buffer.length); |
Dan Williams | 3193204 | 2016-07-14 17:22:48 -0700 | [diff] [blame] | 2969 | if (ret) |
Linda Knippers | 6b577c9 | 2015-11-20 19:05:49 -0500 | [diff] [blame] | 2970 | dev_err(dev, "failed to merge updated NFIT\n"); |
Dan Williams | 3193204 | 2016-07-14 17:22:48 -0700 | [diff] [blame] | 2971 | } else |
Linda Knippers | 6b577c9 | 2015-11-20 19:05:49 -0500 | [diff] [blame] | 2972 | dev_err(dev, "Invalid _FIT\n"); |
Vishal Verma | 2098516 | 2015-10-27 16:58:27 -0600 | [diff] [blame] | 2973 | kfree(buf.pointer); |
Dan Williams | c14a868 | 2016-08-18 22:15:04 -0700 | [diff] [blame] | 2974 | } |
| 2975 | EXPORT_SYMBOL_GPL(__acpi_nfit_notify); |
Vishal Verma | 2098516 | 2015-10-27 16:58:27 -0600 | [diff] [blame] | 2976 | |
Dan Williams | c14a868 | 2016-08-18 22:15:04 -0700 | [diff] [blame] | 2977 | static void acpi_nfit_notify(struct acpi_device *adev, u32 event) |
| 2978 | { |
| 2979 | device_lock(&adev->dev); |
| 2980 | __acpi_nfit_notify(&adev->dev, adev->handle, event); |
| 2981 | device_unlock(&adev->dev); |
Vishal Verma | 2098516 | 2015-10-27 16:58:27 -0600 | [diff] [blame] | 2982 | } |
| 2983 | |
Dan Williams | b94d523 | 2015-05-19 22:54:31 -0400 | [diff] [blame] | 2984 | static const struct acpi_device_id acpi_nfit_ids[] = { |
| 2985 | { "ACPI0012", 0 }, |
| 2986 | { "", 0 }, |
| 2987 | }; |
| 2988 | MODULE_DEVICE_TABLE(acpi, acpi_nfit_ids); |
| 2989 | |
| 2990 | static struct acpi_driver acpi_nfit_driver = { |
| 2991 | .name = KBUILD_MODNAME, |
| 2992 | .ids = acpi_nfit_ids, |
| 2993 | .ops = { |
| 2994 | .add = acpi_nfit_add, |
| 2995 | .remove = acpi_nfit_remove, |
Vishal Verma | 2098516 | 2015-10-27 16:58:27 -0600 | [diff] [blame] | 2996 | .notify = acpi_nfit_notify, |
Dan Williams | b94d523 | 2015-05-19 22:54:31 -0400 | [diff] [blame] | 2997 | }, |
| 2998 | }; |
| 2999 | |
| 3000 | static __init int nfit_init(void) |
| 3001 | { |
| 3002 | BUILD_BUG_ON(sizeof(struct acpi_table_nfit) != 40); |
| 3003 | BUILD_BUG_ON(sizeof(struct acpi_nfit_system_address) != 56); |
| 3004 | BUILD_BUG_ON(sizeof(struct acpi_nfit_memory_map) != 48); |
| 3005 | BUILD_BUG_ON(sizeof(struct acpi_nfit_interleave) != 20); |
| 3006 | BUILD_BUG_ON(sizeof(struct acpi_nfit_smbios) != 9); |
| 3007 | BUILD_BUG_ON(sizeof(struct acpi_nfit_control_region) != 80); |
| 3008 | BUILD_BUG_ON(sizeof(struct acpi_nfit_data_region) != 40); |
| 3009 | |
| 3010 | acpi_str_to_uuid(UUID_VOLATILE_MEMORY, nfit_uuid[NFIT_SPA_VOLATILE]); |
| 3011 | acpi_str_to_uuid(UUID_PERSISTENT_MEMORY, nfit_uuid[NFIT_SPA_PM]); |
| 3012 | acpi_str_to_uuid(UUID_CONTROL_REGION, nfit_uuid[NFIT_SPA_DCR]); |
| 3013 | acpi_str_to_uuid(UUID_DATA_REGION, nfit_uuid[NFIT_SPA_BDW]); |
| 3014 | acpi_str_to_uuid(UUID_VOLATILE_VIRTUAL_DISK, nfit_uuid[NFIT_SPA_VDISK]); |
| 3015 | acpi_str_to_uuid(UUID_VOLATILE_VIRTUAL_CD, nfit_uuid[NFIT_SPA_VCD]); |
| 3016 | acpi_str_to_uuid(UUID_PERSISTENT_VIRTUAL_DISK, nfit_uuid[NFIT_SPA_PDISK]); |
| 3017 | acpi_str_to_uuid(UUID_PERSISTENT_VIRTUAL_CD, nfit_uuid[NFIT_SPA_PCD]); |
| 3018 | acpi_str_to_uuid(UUID_NFIT_BUS, nfit_uuid[NFIT_DEV_BUS]); |
| 3019 | acpi_str_to_uuid(UUID_NFIT_DIMM, nfit_uuid[NFIT_DEV_DIMM]); |
Dan Williams | 31eca76 | 2016-04-28 16:23:43 -0700 | [diff] [blame] | 3020 | acpi_str_to_uuid(UUID_NFIT_DIMM_N_HPE1, nfit_uuid[NFIT_DEV_DIMM_N_HPE1]); |
| 3021 | acpi_str_to_uuid(UUID_NFIT_DIMM_N_HPE2, nfit_uuid[NFIT_DEV_DIMM_N_HPE2]); |
stuart hayes | e02fb72 | 2016-05-26 11:38:41 -0500 | [diff] [blame] | 3022 | acpi_str_to_uuid(UUID_NFIT_DIMM_N_MSFT, nfit_uuid[NFIT_DEV_DIMM_N_MSFT]); |
Dan Williams | b94d523 | 2015-05-19 22:54:31 -0400 | [diff] [blame] | 3023 | |
Dan Williams | 7ae0fa43 | 2016-02-19 12:16:34 -0800 | [diff] [blame] | 3024 | nfit_wq = create_singlethread_workqueue("nfit"); |
| 3025 | if (!nfit_wq) |
| 3026 | return -ENOMEM; |
| 3027 | |
Vishal Verma | 6839a6d | 2016-07-23 21:51:21 -0700 | [diff] [blame] | 3028 | nfit_mce_register(); |
| 3029 | |
Dan Williams | b94d523 | 2015-05-19 22:54:31 -0400 | [diff] [blame] | 3030 | return acpi_bus_register_driver(&acpi_nfit_driver); |
| 3031 | } |
| 3032 | |
| 3033 | static __exit void nfit_exit(void) |
| 3034 | { |
Vishal Verma | 6839a6d | 2016-07-23 21:51:21 -0700 | [diff] [blame] | 3035 | nfit_mce_unregister(); |
Dan Williams | b94d523 | 2015-05-19 22:54:31 -0400 | [diff] [blame] | 3036 | acpi_bus_unregister_driver(&acpi_nfit_driver); |
Dan Williams | 7ae0fa43 | 2016-02-19 12:16:34 -0800 | [diff] [blame] | 3037 | destroy_workqueue(nfit_wq); |
Vishal Verma | 6839a6d | 2016-07-23 21:51:21 -0700 | [diff] [blame] | 3038 | WARN_ON(!list_empty(&acpi_descs)); |
Dan Williams | b94d523 | 2015-05-19 22:54:31 -0400 | [diff] [blame] | 3039 | } |
| 3040 | |
| 3041 | module_init(nfit_init); |
| 3042 | module_exit(nfit_exit); |
| 3043 | MODULE_LICENSE("GPL v2"); |
| 3044 | MODULE_AUTHOR("Intel Corporation"); |