Huang Ying | a08f82d | 2010-05-18 14:35:21 +0800 | [diff] [blame] | 1 | /* |
| 2 | * APEI Error Record Serialization Table support |
| 3 | * |
| 4 | * ERST is a way provided by APEI to save and retrieve hardware error |
Lucas De Marchi | 58f87ed | 2010-09-07 12:49:45 -0400 | [diff] [blame] | 5 | * information to and from a persistent store. |
Huang Ying | a08f82d | 2010-05-18 14:35:21 +0800 | [diff] [blame] | 6 | * |
| 7 | * For more information about ERST, please refer to ACPI Specification |
| 8 | * version 4.0, section 17.4. |
| 9 | * |
| 10 | * Copyright 2010 Intel Corp. |
| 11 | * Author: Huang Ying <ying.huang@intel.com> |
| 12 | * |
| 13 | * This program is free software; you can redistribute it and/or |
| 14 | * modify it under the terms of the GNU General Public License version |
| 15 | * 2 as published by the Free Software Foundation. |
| 16 | * |
| 17 | * This program is distributed in the hope that it will be useful, |
| 18 | * but WITHOUT ANY WARRANTY; without even the implied warranty of |
| 19 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
| 20 | * GNU General Public License for more details. |
Huang Ying | a08f82d | 2010-05-18 14:35:21 +0800 | [diff] [blame] | 21 | */ |
| 22 | |
| 23 | #include <linux/kernel.h> |
| 24 | #include <linux/module.h> |
| 25 | #include <linux/init.h> |
| 26 | #include <linux/delay.h> |
| 27 | #include <linux/io.h> |
| 28 | #include <linux/acpi.h> |
| 29 | #include <linux/uaccess.h> |
| 30 | #include <linux/cper.h> |
| 31 | #include <linux/nmi.h> |
Thomas Gleixner | 0a7992c | 2010-08-11 14:17:29 -0700 | [diff] [blame] | 32 | #include <linux/hardirq.h> |
Tony Luck | 0bb77c4 | 2011-01-03 14:22:11 -0800 | [diff] [blame] | 33 | #include <linux/pstore.h> |
Stephen Rothwell | d647230 | 2015-06-02 19:01:38 +1000 | [diff] [blame] | 34 | #include <linux/vmalloc.h> |
Tetsuo Handa | 1d5cfdb | 2016-01-22 15:11:02 -0800 | [diff] [blame] | 35 | #include <linux/mm.h> /* kvfree() */ |
Huang Ying | a08f82d | 2010-05-18 14:35:21 +0800 | [diff] [blame] | 36 | #include <acpi/apei.h> |
| 37 | |
| 38 | #include "apei-internal.h" |
| 39 | |
Borislav Petkov | cb82a2e | 2013-07-29 15:51:35 +0200 | [diff] [blame] | 40 | #undef pr_fmt |
| 41 | #define pr_fmt(fmt) "ERST: " fmt |
Huang Ying | a08f82d | 2010-05-18 14:35:21 +0800 | [diff] [blame] | 42 | |
| 43 | /* ERST command status */ |
| 44 | #define ERST_STATUS_SUCCESS 0x0 |
| 45 | #define ERST_STATUS_NOT_ENOUGH_SPACE 0x1 |
| 46 | #define ERST_STATUS_HARDWARE_NOT_AVAILABLE 0x2 |
| 47 | #define ERST_STATUS_FAILED 0x3 |
| 48 | #define ERST_STATUS_RECORD_STORE_EMPTY 0x4 |
| 49 | #define ERST_STATUS_RECORD_NOT_FOUND 0x5 |
| 50 | |
| 51 | #define ERST_TAB_ENTRY(tab) \ |
| 52 | ((struct acpi_whea_header *)((char *)(tab) + \ |
| 53 | sizeof(struct acpi_table_erst))) |
| 54 | |
| 55 | #define SPIN_UNIT 100 /* 100ns */ |
Stefan Weil | e8a8b25 | 2011-01-02 15:12:42 +0100 | [diff] [blame] | 56 | /* Firmware should respond within 1 milliseconds */ |
Huang Ying | a08f82d | 2010-05-18 14:35:21 +0800 | [diff] [blame] | 57 | #define FIRMWARE_TIMEOUT (1 * NSEC_PER_MSEC) |
| 58 | #define FIRMWARE_MAX_STALL 50 /* 50us */ |
| 59 | |
| 60 | int erst_disable; |
| 61 | EXPORT_SYMBOL_GPL(erst_disable); |
| 62 | |
| 63 | static struct acpi_table_erst *erst_tab; |
| 64 | |
| 65 | /* ERST Error Log Address Range atrributes */ |
| 66 | #define ERST_RANGE_RESERVED 0x0001 |
| 67 | #define ERST_RANGE_NVRAM 0x0002 |
| 68 | #define ERST_RANGE_SLOW 0x0004 |
| 69 | |
| 70 | /* |
| 71 | * ERST Error Log Address Range, used as buffer for reading/writing |
| 72 | * error records. |
| 73 | */ |
| 74 | static struct erst_erange { |
| 75 | u64 base; |
| 76 | u64 size; |
| 77 | void __iomem *vaddr; |
| 78 | u32 attr; |
| 79 | } erst_erange; |
| 80 | |
| 81 | /* |
| 82 | * Prevent ERST interpreter to run simultaneously, because the |
| 83 | * corresponding firmware implementation may not work properly when |
| 84 | * invoked simultaneously. |
| 85 | * |
| 86 | * It is used to provide exclusive accessing for ERST Error Log |
| 87 | * Address Range too. |
| 88 | */ |
Huang Ying | 3b38bb5 | 2010-12-02 10:40:53 +0800 | [diff] [blame] | 89 | static DEFINE_RAW_SPINLOCK(erst_lock); |
Huang Ying | a08f82d | 2010-05-18 14:35:21 +0800 | [diff] [blame] | 90 | |
| 91 | static inline int erst_errno(int command_status) |
| 92 | { |
| 93 | switch (command_status) { |
| 94 | case ERST_STATUS_SUCCESS: |
| 95 | return 0; |
| 96 | case ERST_STATUS_HARDWARE_NOT_AVAILABLE: |
| 97 | return -ENODEV; |
| 98 | case ERST_STATUS_NOT_ENOUGH_SPACE: |
| 99 | return -ENOSPC; |
| 100 | case ERST_STATUS_RECORD_STORE_EMPTY: |
| 101 | case ERST_STATUS_RECORD_NOT_FOUND: |
| 102 | return -ENOENT; |
| 103 | default: |
| 104 | return -EINVAL; |
| 105 | } |
| 106 | } |
| 107 | |
| 108 | static int erst_timedout(u64 *t, u64 spin_unit) |
| 109 | { |
| 110 | if ((s64)*t < spin_unit) { |
Borislav Petkov | cb82a2e | 2013-07-29 15:51:35 +0200 | [diff] [blame] | 111 | pr_warn(FW_WARN "Firmware does not respond in time.\n"); |
Huang Ying | a08f82d | 2010-05-18 14:35:21 +0800 | [diff] [blame] | 112 | return 1; |
| 113 | } |
| 114 | *t -= spin_unit; |
| 115 | ndelay(spin_unit); |
| 116 | touch_nmi_watchdog(); |
| 117 | return 0; |
| 118 | } |
| 119 | |
| 120 | static int erst_exec_load_var1(struct apei_exec_context *ctx, |
| 121 | struct acpi_whea_header *entry) |
| 122 | { |
| 123 | return __apei_exec_read_register(entry, &ctx->var1); |
| 124 | } |
| 125 | |
| 126 | static int erst_exec_load_var2(struct apei_exec_context *ctx, |
| 127 | struct acpi_whea_header *entry) |
| 128 | { |
| 129 | return __apei_exec_read_register(entry, &ctx->var2); |
| 130 | } |
| 131 | |
| 132 | static int erst_exec_store_var1(struct apei_exec_context *ctx, |
| 133 | struct acpi_whea_header *entry) |
| 134 | { |
| 135 | return __apei_exec_write_register(entry, ctx->var1); |
| 136 | } |
| 137 | |
| 138 | static int erst_exec_add(struct apei_exec_context *ctx, |
| 139 | struct acpi_whea_header *entry) |
| 140 | { |
| 141 | ctx->var1 += ctx->var2; |
| 142 | return 0; |
| 143 | } |
| 144 | |
| 145 | static int erst_exec_subtract(struct apei_exec_context *ctx, |
| 146 | struct acpi_whea_header *entry) |
| 147 | { |
| 148 | ctx->var1 -= ctx->var2; |
| 149 | return 0; |
| 150 | } |
| 151 | |
| 152 | static int erst_exec_add_value(struct apei_exec_context *ctx, |
| 153 | struct acpi_whea_header *entry) |
| 154 | { |
| 155 | int rc; |
| 156 | u64 val; |
| 157 | |
| 158 | rc = __apei_exec_read_register(entry, &val); |
| 159 | if (rc) |
| 160 | return rc; |
| 161 | val += ctx->value; |
| 162 | rc = __apei_exec_write_register(entry, val); |
| 163 | return rc; |
| 164 | } |
| 165 | |
| 166 | static int erst_exec_subtract_value(struct apei_exec_context *ctx, |
| 167 | struct acpi_whea_header *entry) |
| 168 | { |
| 169 | int rc; |
| 170 | u64 val; |
| 171 | |
| 172 | rc = __apei_exec_read_register(entry, &val); |
| 173 | if (rc) |
| 174 | return rc; |
| 175 | val -= ctx->value; |
| 176 | rc = __apei_exec_write_register(entry, val); |
| 177 | return rc; |
| 178 | } |
| 179 | |
| 180 | static int erst_exec_stall(struct apei_exec_context *ctx, |
| 181 | struct acpi_whea_header *entry) |
| 182 | { |
| 183 | u64 stall_time; |
| 184 | |
| 185 | if (ctx->value > FIRMWARE_MAX_STALL) { |
| 186 | if (!in_nmi()) |
Borislav Petkov | cb82a2e | 2013-07-29 15:51:35 +0200 | [diff] [blame] | 187 | pr_warn(FW_WARN |
| 188 | "Too long stall time for stall instruction: 0x%llx.\n", |
Huang Ying | a08f82d | 2010-05-18 14:35:21 +0800 | [diff] [blame] | 189 | ctx->value); |
| 190 | stall_time = FIRMWARE_MAX_STALL; |
| 191 | } else |
| 192 | stall_time = ctx->value; |
| 193 | udelay(stall_time); |
| 194 | return 0; |
| 195 | } |
| 196 | |
| 197 | static int erst_exec_stall_while_true(struct apei_exec_context *ctx, |
| 198 | struct acpi_whea_header *entry) |
| 199 | { |
| 200 | int rc; |
| 201 | u64 val; |
| 202 | u64 timeout = FIRMWARE_TIMEOUT; |
| 203 | u64 stall_time; |
| 204 | |
| 205 | if (ctx->var1 > FIRMWARE_MAX_STALL) { |
| 206 | if (!in_nmi()) |
Borislav Petkov | cb82a2e | 2013-07-29 15:51:35 +0200 | [diff] [blame] | 207 | pr_warn(FW_WARN |
| 208 | "Too long stall time for stall while true instruction: 0x%llx.\n", |
Huang Ying | a08f82d | 2010-05-18 14:35:21 +0800 | [diff] [blame] | 209 | ctx->var1); |
| 210 | stall_time = FIRMWARE_MAX_STALL; |
| 211 | } else |
| 212 | stall_time = ctx->var1; |
| 213 | |
| 214 | for (;;) { |
| 215 | rc = __apei_exec_read_register(entry, &val); |
| 216 | if (rc) |
| 217 | return rc; |
| 218 | if (val != ctx->value) |
| 219 | break; |
| 220 | if (erst_timedout(&timeout, stall_time * NSEC_PER_USEC)) |
| 221 | return -EIO; |
| 222 | } |
| 223 | return 0; |
| 224 | } |
| 225 | |
| 226 | static int erst_exec_skip_next_instruction_if_true( |
| 227 | struct apei_exec_context *ctx, |
| 228 | struct acpi_whea_header *entry) |
| 229 | { |
| 230 | int rc; |
| 231 | u64 val; |
| 232 | |
| 233 | rc = __apei_exec_read_register(entry, &val); |
| 234 | if (rc) |
| 235 | return rc; |
| 236 | if (val == ctx->value) { |
| 237 | ctx->ip += 2; |
| 238 | return APEI_EXEC_SET_IP; |
| 239 | } |
| 240 | |
| 241 | return 0; |
| 242 | } |
| 243 | |
| 244 | static int erst_exec_goto(struct apei_exec_context *ctx, |
| 245 | struct acpi_whea_header *entry) |
| 246 | { |
| 247 | ctx->ip = ctx->value; |
| 248 | return APEI_EXEC_SET_IP; |
| 249 | } |
| 250 | |
| 251 | static int erst_exec_set_src_address_base(struct apei_exec_context *ctx, |
| 252 | struct acpi_whea_header *entry) |
| 253 | { |
| 254 | return __apei_exec_read_register(entry, &ctx->src_base); |
| 255 | } |
| 256 | |
| 257 | static int erst_exec_set_dst_address_base(struct apei_exec_context *ctx, |
| 258 | struct acpi_whea_header *entry) |
| 259 | { |
| 260 | return __apei_exec_read_register(entry, &ctx->dst_base); |
| 261 | } |
| 262 | |
| 263 | static int erst_exec_move_data(struct apei_exec_context *ctx, |
| 264 | struct acpi_whea_header *entry) |
| 265 | { |
| 266 | int rc; |
| 267 | u64 offset; |
Huang Ying | 0bbba38 | 2010-09-29 19:53:55 +0800 | [diff] [blame] | 268 | void *src, *dst; |
| 269 | |
| 270 | /* ioremap does not work in interrupt context */ |
| 271 | if (in_interrupt()) { |
Borislav Petkov | cb82a2e | 2013-07-29 15:51:35 +0200 | [diff] [blame] | 272 | pr_warn("MOVE_DATA can not be used in interrupt context.\n"); |
Huang Ying | 0bbba38 | 2010-09-29 19:53:55 +0800 | [diff] [blame] | 273 | return -EBUSY; |
| 274 | } |
Huang Ying | a08f82d | 2010-05-18 14:35:21 +0800 | [diff] [blame] | 275 | |
| 276 | rc = __apei_exec_read_register(entry, &offset); |
| 277 | if (rc) |
| 278 | return rc; |
Huang Ying | 0bbba38 | 2010-09-29 19:53:55 +0800 | [diff] [blame] | 279 | |
| 280 | src = ioremap(ctx->src_base + offset, ctx->var2); |
| 281 | if (!src) |
| 282 | return -ENOMEM; |
| 283 | dst = ioremap(ctx->dst_base + offset, ctx->var2); |
Wei Yongjun | 08b326d | 2013-07-02 09:02:32 +0800 | [diff] [blame] | 284 | if (!dst) { |
| 285 | iounmap(src); |
Huang Ying | 0bbba38 | 2010-09-29 19:53:55 +0800 | [diff] [blame] | 286 | return -ENOMEM; |
Wei Yongjun | 08b326d | 2013-07-02 09:02:32 +0800 | [diff] [blame] | 287 | } |
Huang Ying | 0bbba38 | 2010-09-29 19:53:55 +0800 | [diff] [blame] | 288 | |
| 289 | memmove(dst, src, ctx->var2); |
| 290 | |
| 291 | iounmap(src); |
| 292 | iounmap(dst); |
Huang Ying | a08f82d | 2010-05-18 14:35:21 +0800 | [diff] [blame] | 293 | |
| 294 | return 0; |
| 295 | } |
| 296 | |
| 297 | static struct apei_exec_ins_type erst_ins_type[] = { |
| 298 | [ACPI_ERST_READ_REGISTER] = { |
| 299 | .flags = APEI_EXEC_INS_ACCESS_REGISTER, |
| 300 | .run = apei_exec_read_register, |
| 301 | }, |
| 302 | [ACPI_ERST_READ_REGISTER_VALUE] = { |
| 303 | .flags = APEI_EXEC_INS_ACCESS_REGISTER, |
| 304 | .run = apei_exec_read_register_value, |
| 305 | }, |
| 306 | [ACPI_ERST_WRITE_REGISTER] = { |
| 307 | .flags = APEI_EXEC_INS_ACCESS_REGISTER, |
| 308 | .run = apei_exec_write_register, |
| 309 | }, |
| 310 | [ACPI_ERST_WRITE_REGISTER_VALUE] = { |
| 311 | .flags = APEI_EXEC_INS_ACCESS_REGISTER, |
| 312 | .run = apei_exec_write_register_value, |
| 313 | }, |
| 314 | [ACPI_ERST_NOOP] = { |
| 315 | .flags = 0, |
| 316 | .run = apei_exec_noop, |
| 317 | }, |
| 318 | [ACPI_ERST_LOAD_VAR1] = { |
| 319 | .flags = APEI_EXEC_INS_ACCESS_REGISTER, |
| 320 | .run = erst_exec_load_var1, |
| 321 | }, |
| 322 | [ACPI_ERST_LOAD_VAR2] = { |
| 323 | .flags = APEI_EXEC_INS_ACCESS_REGISTER, |
| 324 | .run = erst_exec_load_var2, |
| 325 | }, |
| 326 | [ACPI_ERST_STORE_VAR1] = { |
| 327 | .flags = APEI_EXEC_INS_ACCESS_REGISTER, |
| 328 | .run = erst_exec_store_var1, |
| 329 | }, |
| 330 | [ACPI_ERST_ADD] = { |
| 331 | .flags = 0, |
| 332 | .run = erst_exec_add, |
| 333 | }, |
| 334 | [ACPI_ERST_SUBTRACT] = { |
| 335 | .flags = 0, |
| 336 | .run = erst_exec_subtract, |
| 337 | }, |
| 338 | [ACPI_ERST_ADD_VALUE] = { |
| 339 | .flags = APEI_EXEC_INS_ACCESS_REGISTER, |
| 340 | .run = erst_exec_add_value, |
| 341 | }, |
| 342 | [ACPI_ERST_SUBTRACT_VALUE] = { |
| 343 | .flags = APEI_EXEC_INS_ACCESS_REGISTER, |
| 344 | .run = erst_exec_subtract_value, |
| 345 | }, |
| 346 | [ACPI_ERST_STALL] = { |
| 347 | .flags = 0, |
| 348 | .run = erst_exec_stall, |
| 349 | }, |
| 350 | [ACPI_ERST_STALL_WHILE_TRUE] = { |
| 351 | .flags = APEI_EXEC_INS_ACCESS_REGISTER, |
| 352 | .run = erst_exec_stall_while_true, |
| 353 | }, |
| 354 | [ACPI_ERST_SKIP_NEXT_IF_TRUE] = { |
| 355 | .flags = APEI_EXEC_INS_ACCESS_REGISTER, |
| 356 | .run = erst_exec_skip_next_instruction_if_true, |
| 357 | }, |
| 358 | [ACPI_ERST_GOTO] = { |
| 359 | .flags = 0, |
| 360 | .run = erst_exec_goto, |
| 361 | }, |
| 362 | [ACPI_ERST_SET_SRC_ADDRESS_BASE] = { |
| 363 | .flags = APEI_EXEC_INS_ACCESS_REGISTER, |
| 364 | .run = erst_exec_set_src_address_base, |
| 365 | }, |
| 366 | [ACPI_ERST_SET_DST_ADDRESS_BASE] = { |
| 367 | .flags = APEI_EXEC_INS_ACCESS_REGISTER, |
| 368 | .run = erst_exec_set_dst_address_base, |
| 369 | }, |
| 370 | [ACPI_ERST_MOVE_DATA] = { |
| 371 | .flags = APEI_EXEC_INS_ACCESS_REGISTER, |
| 372 | .run = erst_exec_move_data, |
| 373 | }, |
| 374 | }; |
| 375 | |
| 376 | static inline void erst_exec_ctx_init(struct apei_exec_context *ctx) |
| 377 | { |
| 378 | apei_exec_ctx_init(ctx, erst_ins_type, ARRAY_SIZE(erst_ins_type), |
| 379 | ERST_TAB_ENTRY(erst_tab), erst_tab->entries); |
| 380 | } |
| 381 | |
| 382 | static int erst_get_erange(struct erst_erange *range) |
| 383 | { |
| 384 | struct apei_exec_context ctx; |
| 385 | int rc; |
| 386 | |
| 387 | erst_exec_ctx_init(&ctx); |
| 388 | rc = apei_exec_run(&ctx, ACPI_ERST_GET_ERROR_RANGE); |
| 389 | if (rc) |
| 390 | return rc; |
| 391 | range->base = apei_exec_ctx_get_output(&ctx); |
| 392 | rc = apei_exec_run(&ctx, ACPI_ERST_GET_ERROR_LENGTH); |
| 393 | if (rc) |
| 394 | return rc; |
| 395 | range->size = apei_exec_ctx_get_output(&ctx); |
| 396 | rc = apei_exec_run(&ctx, ACPI_ERST_GET_ERROR_ATTRIBUTES); |
| 397 | if (rc) |
| 398 | return rc; |
| 399 | range->attr = apei_exec_ctx_get_output(&ctx); |
| 400 | |
| 401 | return 0; |
| 402 | } |
| 403 | |
| 404 | static ssize_t __erst_get_record_count(void) |
| 405 | { |
| 406 | struct apei_exec_context ctx; |
| 407 | int rc; |
| 408 | |
| 409 | erst_exec_ctx_init(&ctx); |
| 410 | rc = apei_exec_run(&ctx, ACPI_ERST_GET_RECORD_COUNT); |
| 411 | if (rc) |
| 412 | return rc; |
| 413 | return apei_exec_ctx_get_output(&ctx); |
| 414 | } |
| 415 | |
| 416 | ssize_t erst_get_record_count(void) |
| 417 | { |
| 418 | ssize_t count; |
| 419 | unsigned long flags; |
| 420 | |
| 421 | if (erst_disable) |
| 422 | return -ENODEV; |
| 423 | |
Huang Ying | 3b38bb5 | 2010-12-02 10:40:53 +0800 | [diff] [blame] | 424 | raw_spin_lock_irqsave(&erst_lock, flags); |
Huang Ying | a08f82d | 2010-05-18 14:35:21 +0800 | [diff] [blame] | 425 | count = __erst_get_record_count(); |
Huang Ying | 3b38bb5 | 2010-12-02 10:40:53 +0800 | [diff] [blame] | 426 | raw_spin_unlock_irqrestore(&erst_lock, flags); |
Huang Ying | a08f82d | 2010-05-18 14:35:21 +0800 | [diff] [blame] | 427 | |
| 428 | return count; |
| 429 | } |
| 430 | EXPORT_SYMBOL_GPL(erst_get_record_count); |
| 431 | |
Huang Ying | 885b976 | 2011-02-21 13:54:41 +0800 | [diff] [blame] | 432 | #define ERST_RECORD_ID_CACHE_SIZE_MIN 16 |
| 433 | #define ERST_RECORD_ID_CACHE_SIZE_MAX 1024 |
| 434 | |
| 435 | struct erst_record_id_cache { |
| 436 | struct mutex lock; |
| 437 | u64 *entries; |
| 438 | int len; |
| 439 | int size; |
| 440 | int refcount; |
| 441 | }; |
| 442 | |
| 443 | static struct erst_record_id_cache erst_record_id_cache = { |
| 444 | .lock = __MUTEX_INITIALIZER(erst_record_id_cache.lock), |
| 445 | .refcount = 0, |
| 446 | }; |
| 447 | |
Huang Ying | a08f82d | 2010-05-18 14:35:21 +0800 | [diff] [blame] | 448 | static int __erst_get_next_record_id(u64 *record_id) |
| 449 | { |
| 450 | struct apei_exec_context ctx; |
| 451 | int rc; |
| 452 | |
| 453 | erst_exec_ctx_init(&ctx); |
| 454 | rc = apei_exec_run(&ctx, ACPI_ERST_GET_RECORD_ID); |
| 455 | if (rc) |
| 456 | return rc; |
| 457 | *record_id = apei_exec_ctx_get_output(&ctx); |
| 458 | |
| 459 | return 0; |
| 460 | } |
| 461 | |
Huang Ying | 885b976 | 2011-02-21 13:54:41 +0800 | [diff] [blame] | 462 | int erst_get_record_id_begin(int *pos) |
| 463 | { |
| 464 | int rc; |
| 465 | |
| 466 | if (erst_disable) |
| 467 | return -ENODEV; |
| 468 | |
| 469 | rc = mutex_lock_interruptible(&erst_record_id_cache.lock); |
| 470 | if (rc) |
| 471 | return rc; |
| 472 | erst_record_id_cache.refcount++; |
| 473 | mutex_unlock(&erst_record_id_cache.lock); |
| 474 | |
| 475 | *pos = 0; |
| 476 | |
| 477 | return 0; |
| 478 | } |
| 479 | EXPORT_SYMBOL_GPL(erst_get_record_id_begin); |
| 480 | |
| 481 | /* erst_record_id_cache.lock must be held by caller */ |
| 482 | static int __erst_record_id_cache_add_one(void) |
| 483 | { |
| 484 | u64 id, prev_id, first_id; |
| 485 | int i, rc; |
| 486 | u64 *entries; |
| 487 | unsigned long flags; |
| 488 | |
| 489 | id = prev_id = first_id = APEI_ERST_INVALID_RECORD_ID; |
| 490 | retry: |
| 491 | raw_spin_lock_irqsave(&erst_lock, flags); |
| 492 | rc = __erst_get_next_record_id(&id); |
| 493 | raw_spin_unlock_irqrestore(&erst_lock, flags); |
| 494 | if (rc == -ENOENT) |
| 495 | return 0; |
| 496 | if (rc) |
| 497 | return rc; |
| 498 | if (id == APEI_ERST_INVALID_RECORD_ID) |
| 499 | return 0; |
| 500 | /* can not skip current ID, or loop back to first ID */ |
| 501 | if (id == prev_id || id == first_id) |
| 502 | return 0; |
| 503 | if (first_id == APEI_ERST_INVALID_RECORD_ID) |
| 504 | first_id = id; |
| 505 | prev_id = id; |
| 506 | |
| 507 | entries = erst_record_id_cache.entries; |
| 508 | for (i = 0; i < erst_record_id_cache.len; i++) { |
| 509 | if (entries[i] == id) |
| 510 | break; |
| 511 | } |
| 512 | /* record id already in cache, try next */ |
| 513 | if (i < erst_record_id_cache.len) |
| 514 | goto retry; |
| 515 | if (erst_record_id_cache.len >= erst_record_id_cache.size) { |
| 516 | int new_size, alloc_size; |
| 517 | u64 *new_entries; |
| 518 | |
| 519 | new_size = erst_record_id_cache.size * 2; |
| 520 | new_size = clamp_val(new_size, ERST_RECORD_ID_CACHE_SIZE_MIN, |
| 521 | ERST_RECORD_ID_CACHE_SIZE_MAX); |
| 522 | if (new_size <= erst_record_id_cache.size) { |
| 523 | if (printk_ratelimit()) |
Borislav Petkov | cb82a2e | 2013-07-29 15:51:35 +0200 | [diff] [blame] | 524 | pr_warn(FW_WARN "too many record IDs!\n"); |
Huang Ying | 885b976 | 2011-02-21 13:54:41 +0800 | [diff] [blame] | 525 | return 0; |
| 526 | } |
| 527 | alloc_size = new_size * sizeof(entries[0]); |
| 528 | if (alloc_size < PAGE_SIZE) |
| 529 | new_entries = kmalloc(alloc_size, GFP_KERNEL); |
| 530 | else |
| 531 | new_entries = vmalloc(alloc_size); |
| 532 | if (!new_entries) |
| 533 | return -ENOMEM; |
| 534 | memcpy(new_entries, entries, |
| 535 | erst_record_id_cache.len * sizeof(entries[0])); |
Tetsuo Handa | 1d5cfdb | 2016-01-22 15:11:02 -0800 | [diff] [blame] | 536 | kvfree(entries); |
Huang Ying | 885b976 | 2011-02-21 13:54:41 +0800 | [diff] [blame] | 537 | erst_record_id_cache.entries = entries = new_entries; |
| 538 | erst_record_id_cache.size = new_size; |
| 539 | } |
| 540 | entries[i] = id; |
| 541 | erst_record_id_cache.len++; |
| 542 | |
| 543 | return 1; |
| 544 | } |
| 545 | |
Huang Ying | a08f82d | 2010-05-18 14:35:21 +0800 | [diff] [blame] | 546 | /* |
| 547 | * Get the record ID of an existing error record on the persistent |
| 548 | * storage. If there is no error record on the persistent storage, the |
| 549 | * returned record_id is APEI_ERST_INVALID_RECORD_ID. |
| 550 | */ |
Huang Ying | 885b976 | 2011-02-21 13:54:41 +0800 | [diff] [blame] | 551 | int erst_get_record_id_next(int *pos, u64 *record_id) |
Huang Ying | a08f82d | 2010-05-18 14:35:21 +0800 | [diff] [blame] | 552 | { |
Huang Ying | 885b976 | 2011-02-21 13:54:41 +0800 | [diff] [blame] | 553 | int rc = 0; |
| 554 | u64 *entries; |
Huang Ying | a08f82d | 2010-05-18 14:35:21 +0800 | [diff] [blame] | 555 | |
| 556 | if (erst_disable) |
| 557 | return -ENODEV; |
| 558 | |
Huang Ying | 885b976 | 2011-02-21 13:54:41 +0800 | [diff] [blame] | 559 | /* must be enclosed by erst_get_record_id_begin/end */ |
| 560 | BUG_ON(!erst_record_id_cache.refcount); |
| 561 | BUG_ON(*pos < 0 || *pos > erst_record_id_cache.len); |
| 562 | |
| 563 | mutex_lock(&erst_record_id_cache.lock); |
| 564 | entries = erst_record_id_cache.entries; |
| 565 | for (; *pos < erst_record_id_cache.len; (*pos)++) |
| 566 | if (entries[*pos] != APEI_ERST_INVALID_RECORD_ID) |
| 567 | break; |
| 568 | /* found next record id in cache */ |
| 569 | if (*pos < erst_record_id_cache.len) { |
| 570 | *record_id = entries[*pos]; |
| 571 | (*pos)++; |
| 572 | goto out_unlock; |
| 573 | } |
| 574 | |
| 575 | /* Try to add one more record ID to cache */ |
| 576 | rc = __erst_record_id_cache_add_one(); |
| 577 | if (rc < 0) |
| 578 | goto out_unlock; |
| 579 | /* successfully add one new ID */ |
| 580 | if (rc == 1) { |
| 581 | *record_id = erst_record_id_cache.entries[*pos]; |
| 582 | (*pos)++; |
| 583 | rc = 0; |
| 584 | } else { |
| 585 | *pos = -1; |
| 586 | *record_id = APEI_ERST_INVALID_RECORD_ID; |
| 587 | } |
| 588 | out_unlock: |
| 589 | mutex_unlock(&erst_record_id_cache.lock); |
Huang Ying | a08f82d | 2010-05-18 14:35:21 +0800 | [diff] [blame] | 590 | |
| 591 | return rc; |
| 592 | } |
Huang Ying | 885b976 | 2011-02-21 13:54:41 +0800 | [diff] [blame] | 593 | EXPORT_SYMBOL_GPL(erst_get_record_id_next); |
| 594 | |
| 595 | /* erst_record_id_cache.lock must be held by caller */ |
| 596 | static void __erst_record_id_cache_compact(void) |
| 597 | { |
| 598 | int i, wpos = 0; |
| 599 | u64 *entries; |
| 600 | |
| 601 | if (erst_record_id_cache.refcount) |
| 602 | return; |
| 603 | |
| 604 | entries = erst_record_id_cache.entries; |
| 605 | for (i = 0; i < erst_record_id_cache.len; i++) { |
| 606 | if (entries[i] == APEI_ERST_INVALID_RECORD_ID) |
| 607 | continue; |
| 608 | if (wpos != i) |
Chen, Gong | d3ab3ed | 2013-12-18 01:30:49 -0500 | [diff] [blame] | 609 | entries[wpos] = entries[i]; |
Huang Ying | 885b976 | 2011-02-21 13:54:41 +0800 | [diff] [blame] | 610 | wpos++; |
| 611 | } |
| 612 | erst_record_id_cache.len = wpos; |
| 613 | } |
| 614 | |
| 615 | void erst_get_record_id_end(void) |
| 616 | { |
| 617 | /* |
| 618 | * erst_disable != 0 should be detected by invoker via the |
| 619 | * return value of erst_get_record_id_begin/next, so this |
| 620 | * function should not be called for erst_disable != 0. |
| 621 | */ |
| 622 | BUG_ON(erst_disable); |
| 623 | |
| 624 | mutex_lock(&erst_record_id_cache.lock); |
| 625 | erst_record_id_cache.refcount--; |
| 626 | BUG_ON(erst_record_id_cache.refcount < 0); |
| 627 | __erst_record_id_cache_compact(); |
| 628 | mutex_unlock(&erst_record_id_cache.lock); |
| 629 | } |
| 630 | EXPORT_SYMBOL_GPL(erst_get_record_id_end); |
Huang Ying | a08f82d | 2010-05-18 14:35:21 +0800 | [diff] [blame] | 631 | |
| 632 | static int __erst_write_to_storage(u64 offset) |
| 633 | { |
| 634 | struct apei_exec_context ctx; |
| 635 | u64 timeout = FIRMWARE_TIMEOUT; |
| 636 | u64 val; |
| 637 | int rc; |
| 638 | |
| 639 | erst_exec_ctx_init(&ctx); |
Huang Ying | 392913d | 2011-07-13 13:14:17 +0800 | [diff] [blame] | 640 | rc = apei_exec_run_optional(&ctx, ACPI_ERST_BEGIN_WRITE); |
Huang Ying | a08f82d | 2010-05-18 14:35:21 +0800 | [diff] [blame] | 641 | if (rc) |
| 642 | return rc; |
| 643 | apei_exec_ctx_set_input(&ctx, offset); |
| 644 | rc = apei_exec_run(&ctx, ACPI_ERST_SET_RECORD_OFFSET); |
| 645 | if (rc) |
| 646 | return rc; |
| 647 | rc = apei_exec_run(&ctx, ACPI_ERST_EXECUTE_OPERATION); |
| 648 | if (rc) |
| 649 | return rc; |
| 650 | for (;;) { |
| 651 | rc = apei_exec_run(&ctx, ACPI_ERST_CHECK_BUSY_STATUS); |
| 652 | if (rc) |
| 653 | return rc; |
| 654 | val = apei_exec_ctx_get_output(&ctx); |
| 655 | if (!val) |
| 656 | break; |
| 657 | if (erst_timedout(&timeout, SPIN_UNIT)) |
| 658 | return -EIO; |
| 659 | } |
| 660 | rc = apei_exec_run(&ctx, ACPI_ERST_GET_COMMAND_STATUS); |
| 661 | if (rc) |
| 662 | return rc; |
| 663 | val = apei_exec_ctx_get_output(&ctx); |
Huang Ying | 392913d | 2011-07-13 13:14:17 +0800 | [diff] [blame] | 664 | rc = apei_exec_run_optional(&ctx, ACPI_ERST_END); |
Huang Ying | a08f82d | 2010-05-18 14:35:21 +0800 | [diff] [blame] | 665 | if (rc) |
| 666 | return rc; |
| 667 | |
| 668 | return erst_errno(val); |
| 669 | } |
| 670 | |
| 671 | static int __erst_read_from_storage(u64 record_id, u64 offset) |
| 672 | { |
| 673 | struct apei_exec_context ctx; |
| 674 | u64 timeout = FIRMWARE_TIMEOUT; |
| 675 | u64 val; |
| 676 | int rc; |
| 677 | |
| 678 | erst_exec_ctx_init(&ctx); |
Huang Ying | 392913d | 2011-07-13 13:14:17 +0800 | [diff] [blame] | 679 | rc = apei_exec_run_optional(&ctx, ACPI_ERST_BEGIN_READ); |
Huang Ying | a08f82d | 2010-05-18 14:35:21 +0800 | [diff] [blame] | 680 | if (rc) |
| 681 | return rc; |
| 682 | apei_exec_ctx_set_input(&ctx, offset); |
| 683 | rc = apei_exec_run(&ctx, ACPI_ERST_SET_RECORD_OFFSET); |
| 684 | if (rc) |
| 685 | return rc; |
| 686 | apei_exec_ctx_set_input(&ctx, record_id); |
| 687 | rc = apei_exec_run(&ctx, ACPI_ERST_SET_RECORD_ID); |
| 688 | if (rc) |
| 689 | return rc; |
| 690 | rc = apei_exec_run(&ctx, ACPI_ERST_EXECUTE_OPERATION); |
| 691 | if (rc) |
| 692 | return rc; |
| 693 | for (;;) { |
| 694 | rc = apei_exec_run(&ctx, ACPI_ERST_CHECK_BUSY_STATUS); |
| 695 | if (rc) |
| 696 | return rc; |
| 697 | val = apei_exec_ctx_get_output(&ctx); |
| 698 | if (!val) |
| 699 | break; |
| 700 | if (erst_timedout(&timeout, SPIN_UNIT)) |
| 701 | return -EIO; |
| 702 | }; |
| 703 | rc = apei_exec_run(&ctx, ACPI_ERST_GET_COMMAND_STATUS); |
| 704 | if (rc) |
| 705 | return rc; |
| 706 | val = apei_exec_ctx_get_output(&ctx); |
Huang Ying | 392913d | 2011-07-13 13:14:17 +0800 | [diff] [blame] | 707 | rc = apei_exec_run_optional(&ctx, ACPI_ERST_END); |
Huang Ying | a08f82d | 2010-05-18 14:35:21 +0800 | [diff] [blame] | 708 | if (rc) |
| 709 | return rc; |
| 710 | |
| 711 | return erst_errno(val); |
| 712 | } |
| 713 | |
| 714 | static int __erst_clear_from_storage(u64 record_id) |
| 715 | { |
| 716 | struct apei_exec_context ctx; |
| 717 | u64 timeout = FIRMWARE_TIMEOUT; |
| 718 | u64 val; |
| 719 | int rc; |
| 720 | |
| 721 | erst_exec_ctx_init(&ctx); |
Huang Ying | 392913d | 2011-07-13 13:14:17 +0800 | [diff] [blame] | 722 | rc = apei_exec_run_optional(&ctx, ACPI_ERST_BEGIN_CLEAR); |
Huang Ying | a08f82d | 2010-05-18 14:35:21 +0800 | [diff] [blame] | 723 | if (rc) |
| 724 | return rc; |
| 725 | apei_exec_ctx_set_input(&ctx, record_id); |
| 726 | rc = apei_exec_run(&ctx, ACPI_ERST_SET_RECORD_ID); |
| 727 | if (rc) |
| 728 | return rc; |
| 729 | rc = apei_exec_run(&ctx, ACPI_ERST_EXECUTE_OPERATION); |
| 730 | if (rc) |
| 731 | return rc; |
| 732 | for (;;) { |
| 733 | rc = apei_exec_run(&ctx, ACPI_ERST_CHECK_BUSY_STATUS); |
| 734 | if (rc) |
| 735 | return rc; |
| 736 | val = apei_exec_ctx_get_output(&ctx); |
| 737 | if (!val) |
| 738 | break; |
| 739 | if (erst_timedout(&timeout, SPIN_UNIT)) |
| 740 | return -EIO; |
| 741 | } |
| 742 | rc = apei_exec_run(&ctx, ACPI_ERST_GET_COMMAND_STATUS); |
| 743 | if (rc) |
| 744 | return rc; |
| 745 | val = apei_exec_ctx_get_output(&ctx); |
Huang Ying | 392913d | 2011-07-13 13:14:17 +0800 | [diff] [blame] | 746 | rc = apei_exec_run_optional(&ctx, ACPI_ERST_END); |
Huang Ying | a08f82d | 2010-05-18 14:35:21 +0800 | [diff] [blame] | 747 | if (rc) |
| 748 | return rc; |
| 749 | |
| 750 | return erst_errno(val); |
| 751 | } |
| 752 | |
| 753 | /* NVRAM ERST Error Log Address Range is not supported yet */ |
| 754 | static void pr_unimpl_nvram(void) |
| 755 | { |
| 756 | if (printk_ratelimit()) |
Borislav Petkov | cb82a2e | 2013-07-29 15:51:35 +0200 | [diff] [blame] | 757 | pr_warn("NVRAM ERST Log Address Range not implemented yet.\n"); |
Huang Ying | a08f82d | 2010-05-18 14:35:21 +0800 | [diff] [blame] | 758 | } |
| 759 | |
| 760 | static int __erst_write_to_nvram(const struct cper_record_header *record) |
| 761 | { |
| 762 | /* do not print message, because printk is not safe for NMI */ |
| 763 | return -ENOSYS; |
| 764 | } |
| 765 | |
| 766 | static int __erst_read_to_erange_from_nvram(u64 record_id, u64 *offset) |
| 767 | { |
| 768 | pr_unimpl_nvram(); |
| 769 | return -ENOSYS; |
| 770 | } |
| 771 | |
| 772 | static int __erst_clear_from_nvram(u64 record_id) |
| 773 | { |
| 774 | pr_unimpl_nvram(); |
| 775 | return -ENOSYS; |
| 776 | } |
| 777 | |
| 778 | int erst_write(const struct cper_record_header *record) |
| 779 | { |
| 780 | int rc; |
| 781 | unsigned long flags; |
| 782 | struct cper_record_header *rcd_erange; |
| 783 | |
| 784 | if (erst_disable) |
| 785 | return -ENODEV; |
| 786 | |
| 787 | if (memcmp(record->signature, CPER_SIG_RECORD, CPER_SIG_SIZE)) |
| 788 | return -EINVAL; |
| 789 | |
| 790 | if (erst_erange.attr & ERST_RANGE_NVRAM) { |
Huang Ying | 3b38bb5 | 2010-12-02 10:40:53 +0800 | [diff] [blame] | 791 | if (!raw_spin_trylock_irqsave(&erst_lock, flags)) |
Huang Ying | a08f82d | 2010-05-18 14:35:21 +0800 | [diff] [blame] | 792 | return -EBUSY; |
| 793 | rc = __erst_write_to_nvram(record); |
Huang Ying | 3b38bb5 | 2010-12-02 10:40:53 +0800 | [diff] [blame] | 794 | raw_spin_unlock_irqrestore(&erst_lock, flags); |
Huang Ying | a08f82d | 2010-05-18 14:35:21 +0800 | [diff] [blame] | 795 | return rc; |
| 796 | } |
| 797 | |
| 798 | if (record->record_length > erst_erange.size) |
| 799 | return -EINVAL; |
| 800 | |
Huang Ying | 3b38bb5 | 2010-12-02 10:40:53 +0800 | [diff] [blame] | 801 | if (!raw_spin_trylock_irqsave(&erst_lock, flags)) |
Huang Ying | a08f82d | 2010-05-18 14:35:21 +0800 | [diff] [blame] | 802 | return -EBUSY; |
| 803 | memcpy(erst_erange.vaddr, record, record->record_length); |
| 804 | rcd_erange = erst_erange.vaddr; |
| 805 | /* signature for serialization system */ |
| 806 | memcpy(&rcd_erange->persistence_information, "ER", 2); |
| 807 | |
| 808 | rc = __erst_write_to_storage(0); |
Huang Ying | 3b38bb5 | 2010-12-02 10:40:53 +0800 | [diff] [blame] | 809 | raw_spin_unlock_irqrestore(&erst_lock, flags); |
Huang Ying | a08f82d | 2010-05-18 14:35:21 +0800 | [diff] [blame] | 810 | |
| 811 | return rc; |
| 812 | } |
| 813 | EXPORT_SYMBOL_GPL(erst_write); |
| 814 | |
| 815 | static int __erst_read_to_erange(u64 record_id, u64 *offset) |
| 816 | { |
| 817 | int rc; |
| 818 | |
| 819 | if (erst_erange.attr & ERST_RANGE_NVRAM) |
| 820 | return __erst_read_to_erange_from_nvram( |
| 821 | record_id, offset); |
| 822 | |
| 823 | rc = __erst_read_from_storage(record_id, 0); |
| 824 | if (rc) |
| 825 | return rc; |
| 826 | *offset = 0; |
| 827 | |
| 828 | return 0; |
| 829 | } |
| 830 | |
| 831 | static ssize_t __erst_read(u64 record_id, struct cper_record_header *record, |
| 832 | size_t buflen) |
| 833 | { |
| 834 | int rc; |
| 835 | u64 offset, len = 0; |
| 836 | struct cper_record_header *rcd_tmp; |
| 837 | |
| 838 | rc = __erst_read_to_erange(record_id, &offset); |
| 839 | if (rc) |
| 840 | return rc; |
| 841 | rcd_tmp = erst_erange.vaddr + offset; |
| 842 | len = rcd_tmp->record_length; |
| 843 | if (len <= buflen) |
| 844 | memcpy(record, rcd_tmp, len); |
| 845 | |
| 846 | return len; |
| 847 | } |
| 848 | |
| 849 | /* |
| 850 | * If return value > buflen, the buffer size is not big enough, |
| 851 | * else if return value < 0, something goes wrong, |
| 852 | * else everything is OK, and return value is record length |
| 853 | */ |
| 854 | ssize_t erst_read(u64 record_id, struct cper_record_header *record, |
| 855 | size_t buflen) |
| 856 | { |
| 857 | ssize_t len; |
| 858 | unsigned long flags; |
| 859 | |
| 860 | if (erst_disable) |
| 861 | return -ENODEV; |
| 862 | |
Huang Ying | 3b38bb5 | 2010-12-02 10:40:53 +0800 | [diff] [blame] | 863 | raw_spin_lock_irqsave(&erst_lock, flags); |
Huang Ying | a08f82d | 2010-05-18 14:35:21 +0800 | [diff] [blame] | 864 | len = __erst_read(record_id, record, buflen); |
Huang Ying | 3b38bb5 | 2010-12-02 10:40:53 +0800 | [diff] [blame] | 865 | raw_spin_unlock_irqrestore(&erst_lock, flags); |
Huang Ying | a08f82d | 2010-05-18 14:35:21 +0800 | [diff] [blame] | 866 | return len; |
| 867 | } |
| 868 | EXPORT_SYMBOL_GPL(erst_read); |
| 869 | |
Huang Ying | a08f82d | 2010-05-18 14:35:21 +0800 | [diff] [blame] | 870 | int erst_clear(u64 record_id) |
| 871 | { |
Huang Ying | 885b976 | 2011-02-21 13:54:41 +0800 | [diff] [blame] | 872 | int rc, i; |
Huang Ying | a08f82d | 2010-05-18 14:35:21 +0800 | [diff] [blame] | 873 | unsigned long flags; |
Huang Ying | 885b976 | 2011-02-21 13:54:41 +0800 | [diff] [blame] | 874 | u64 *entries; |
Huang Ying | a08f82d | 2010-05-18 14:35:21 +0800 | [diff] [blame] | 875 | |
| 876 | if (erst_disable) |
| 877 | return -ENODEV; |
| 878 | |
Huang Ying | 885b976 | 2011-02-21 13:54:41 +0800 | [diff] [blame] | 879 | rc = mutex_lock_interruptible(&erst_record_id_cache.lock); |
| 880 | if (rc) |
| 881 | return rc; |
Huang Ying | 3b38bb5 | 2010-12-02 10:40:53 +0800 | [diff] [blame] | 882 | raw_spin_lock_irqsave(&erst_lock, flags); |
Huang Ying | a08f82d | 2010-05-18 14:35:21 +0800 | [diff] [blame] | 883 | if (erst_erange.attr & ERST_RANGE_NVRAM) |
| 884 | rc = __erst_clear_from_nvram(record_id); |
| 885 | else |
| 886 | rc = __erst_clear_from_storage(record_id); |
Huang Ying | 3b38bb5 | 2010-12-02 10:40:53 +0800 | [diff] [blame] | 887 | raw_spin_unlock_irqrestore(&erst_lock, flags); |
Huang Ying | 885b976 | 2011-02-21 13:54:41 +0800 | [diff] [blame] | 888 | if (rc) |
| 889 | goto out; |
| 890 | entries = erst_record_id_cache.entries; |
| 891 | for (i = 0; i < erst_record_id_cache.len; i++) { |
| 892 | if (entries[i] == record_id) |
| 893 | entries[i] = APEI_ERST_INVALID_RECORD_ID; |
| 894 | } |
| 895 | __erst_record_id_cache_compact(); |
| 896 | out: |
| 897 | mutex_unlock(&erst_record_id_cache.lock); |
Huang Ying | a08f82d | 2010-05-18 14:35:21 +0800 | [diff] [blame] | 898 | return rc; |
| 899 | } |
| 900 | EXPORT_SYMBOL_GPL(erst_clear); |
| 901 | |
| 902 | static int __init setup_erst_disable(char *str) |
| 903 | { |
| 904 | erst_disable = 1; |
| 905 | return 0; |
| 906 | } |
| 907 | |
| 908 | __setup("erst_disable", setup_erst_disable); |
| 909 | |
| 910 | static int erst_check_table(struct acpi_table_erst *erst_tab) |
| 911 | { |
Huang Ying | 3a78f96 | 2010-09-29 19:53:51 +0800 | [diff] [blame] | 912 | if ((erst_tab->header_length != |
| 913 | (sizeof(struct acpi_table_erst) - sizeof(erst_tab->header))) |
Jiang Liu | 7ed28f2 | 2012-03-07 22:15:06 +0800 | [diff] [blame] | 914 | && (erst_tab->header_length != sizeof(struct acpi_table_erst))) |
Huang Ying | a08f82d | 2010-05-18 14:35:21 +0800 | [diff] [blame] | 915 | return -EINVAL; |
| 916 | if (erst_tab->header.length < sizeof(struct acpi_table_erst)) |
| 917 | return -EINVAL; |
| 918 | if (erst_tab->entries != |
| 919 | (erst_tab->header.length - sizeof(struct acpi_table_erst)) / |
| 920 | sizeof(struct acpi_erst_entry)) |
| 921 | return -EINVAL; |
| 922 | |
| 923 | return 0; |
| 924 | } |
| 925 | |
Chen Gong | 06cf91b | 2011-05-16 11:00:27 -0700 | [diff] [blame] | 926 | static int erst_open_pstore(struct pstore_info *psi); |
| 927 | static int erst_close_pstore(struct pstore_info *psi); |
Kees Cook | 125cc42 | 2017-03-03 22:09:18 -0800 | [diff] [blame] | 928 | static ssize_t erst_reader(struct pstore_record *record); |
Kees Cook | 76cc958 | 2017-03-03 23:28:53 -0800 | [diff] [blame] | 929 | static int erst_writer(struct pstore_record *record); |
Kees Cook | a61072a | 2017-03-04 23:31:19 -0800 | [diff] [blame] | 930 | static int erst_clearer(struct pstore_record *record); |
Tony Luck | 0bb77c4 | 2011-01-03 14:22:11 -0800 | [diff] [blame] | 931 | |
| 932 | static struct pstore_info erst_info = { |
| 933 | .owner = THIS_MODULE, |
| 934 | .name = "erst", |
Namhyung Kim | c950fd6 | 2016-07-28 00:08:25 +0900 | [diff] [blame] | 935 | .flags = PSTORE_FLAGS_DMESG, |
Chen Gong | 06cf91b | 2011-05-16 11:00:27 -0700 | [diff] [blame] | 936 | .open = erst_open_pstore, |
| 937 | .close = erst_close_pstore, |
Tony Luck | 0bb77c4 | 2011-01-03 14:22:11 -0800 | [diff] [blame] | 938 | .read = erst_reader, |
| 939 | .write = erst_writer, |
Matthew Garrett | 638c1fd | 2011-07-21 16:57:52 -0400 | [diff] [blame] | 940 | .erase = erst_clearer |
Tony Luck | 0bb77c4 | 2011-01-03 14:22:11 -0800 | [diff] [blame] | 941 | }; |
| 942 | |
| 943 | #define CPER_CREATOR_PSTORE \ |
| 944 | UUID_LE(0x75a574e3, 0x5052, 0x4b29, 0x8a, 0x8e, 0xbe, 0x2c, \ |
| 945 | 0x64, 0x90, 0xb8, 0x9d) |
| 946 | #define CPER_SECTION_TYPE_DMESG \ |
| 947 | UUID_LE(0xc197e04e, 0xd545, 0x4a70, 0x9c, 0x17, 0xa5, 0x54, \ |
| 948 | 0x94, 0x19, 0xeb, 0x12) |
Aruna Balakrishnaiah | 901037b | 2013-08-16 13:57:26 -0700 | [diff] [blame] | 949 | #define CPER_SECTION_TYPE_DMESG_Z \ |
| 950 | UUID_LE(0x4f118707, 0x04dd, 0x4055, 0xb5, 0xdd, 0x95, 0x6d, \ |
| 951 | 0x34, 0xdd, 0xfa, 0xc6) |
Tony Luck | 0bb77c4 | 2011-01-03 14:22:11 -0800 | [diff] [blame] | 952 | #define CPER_SECTION_TYPE_MCE \ |
| 953 | UUID_LE(0xfe08ffbe, 0x95e4, 0x4be7, 0xbc, 0x73, 0x40, 0x96, \ |
| 954 | 0x04, 0x4a, 0x38, 0xfc) |
| 955 | |
| 956 | struct cper_pstore_record { |
| 957 | struct cper_record_header hdr; |
| 958 | struct cper_section_descriptor sec_hdr; |
| 959 | char data[]; |
| 960 | } __packed; |
| 961 | |
Chen Gong | 06cf91b | 2011-05-16 11:00:27 -0700 | [diff] [blame] | 962 | static int reader_pos; |
| 963 | |
| 964 | static int erst_open_pstore(struct pstore_info *psi) |
| 965 | { |
| 966 | int rc; |
| 967 | |
| 968 | if (erst_disable) |
| 969 | return -ENODEV; |
| 970 | |
| 971 | rc = erst_get_record_id_begin(&reader_pos); |
| 972 | |
| 973 | return rc; |
| 974 | } |
| 975 | |
| 976 | static int erst_close_pstore(struct pstore_info *psi) |
| 977 | { |
| 978 | erst_get_record_id_end(); |
| 979 | |
| 980 | return 0; |
| 981 | } |
| 982 | |
Kees Cook | 125cc42 | 2017-03-03 22:09:18 -0800 | [diff] [blame] | 983 | static ssize_t erst_reader(struct pstore_record *record) |
Tony Luck | 0bb77c4 | 2011-01-03 14:22:11 -0800 | [diff] [blame] | 984 | { |
| 985 | int rc; |
Chen Gong | 06cf91b | 2011-05-16 11:00:27 -0700 | [diff] [blame] | 986 | ssize_t len = 0; |
Tony Luck | 0bb77c4 | 2011-01-03 14:22:11 -0800 | [diff] [blame] | 987 | u64 record_id; |
Kees Cook | f6f8285 | 2011-11-17 12:58:07 -0800 | [diff] [blame] | 988 | struct cper_pstore_record *rcd; |
| 989 | size_t rcd_len = sizeof(*rcd) + erst_info.bufsize; |
Tony Luck | 0bb77c4 | 2011-01-03 14:22:11 -0800 | [diff] [blame] | 990 | |
| 991 | if (erst_disable) |
| 992 | return -ENODEV; |
| 993 | |
Kees Cook | f6f8285 | 2011-11-17 12:58:07 -0800 | [diff] [blame] | 994 | rcd = kmalloc(rcd_len, GFP_KERNEL); |
| 995 | if (!rcd) { |
| 996 | rc = -ENOMEM; |
| 997 | goto out; |
| 998 | } |
Tony Luck | 0bb77c4 | 2011-01-03 14:22:11 -0800 | [diff] [blame] | 999 | skip: |
Chen Gong | 06cf91b | 2011-05-16 11:00:27 -0700 | [diff] [blame] | 1000 | rc = erst_get_record_id_next(&reader_pos, &record_id); |
| 1001 | if (rc) |
| 1002 | goto out; |
| 1003 | |
Tony Luck | 0bb77c4 | 2011-01-03 14:22:11 -0800 | [diff] [blame] | 1004 | /* no more record */ |
| 1005 | if (record_id == APEI_ERST_INVALID_RECORD_ID) { |
Kees Cook | f6f8285 | 2011-11-17 12:58:07 -0800 | [diff] [blame] | 1006 | rc = -EINVAL; |
Chen Gong | 06cf91b | 2011-05-16 11:00:27 -0700 | [diff] [blame] | 1007 | goto out; |
Tony Luck | 0bb77c4 | 2011-01-03 14:22:11 -0800 | [diff] [blame] | 1008 | } |
| 1009 | |
Kees Cook | f6f8285 | 2011-11-17 12:58:07 -0800 | [diff] [blame] | 1010 | len = erst_read(record_id, &rcd->hdr, rcd_len); |
Chen Gong | f5ec25d | 2011-05-16 11:01:39 -0700 | [diff] [blame] | 1011 | /* The record may be cleared by others, try read next record */ |
| 1012 | if (len == -ENOENT) |
| 1013 | goto skip; |
Kees Cook | f6f8285 | 2011-11-17 12:58:07 -0800 | [diff] [blame] | 1014 | else if (len < sizeof(*rcd)) { |
| 1015 | rc = -EIO; |
Chen Gong | f5ec25d | 2011-05-16 11:01:39 -0700 | [diff] [blame] | 1016 | goto out; |
| 1017 | } |
Tony Luck | 0bb77c4 | 2011-01-03 14:22:11 -0800 | [diff] [blame] | 1018 | if (uuid_le_cmp(rcd->hdr.creator_id, CPER_CREATOR_PSTORE) != 0) |
| 1019 | goto skip; |
Tony Luck | 0bb77c4 | 2011-01-03 14:22:11 -0800 | [diff] [blame] | 1020 | |
Kees Cook | 125cc42 | 2017-03-03 22:09:18 -0800 | [diff] [blame] | 1021 | record->buf = kmalloc(len, GFP_KERNEL); |
| 1022 | if (record->buf == NULL) { |
Kees Cook | f6f8285 | 2011-11-17 12:58:07 -0800 | [diff] [blame] | 1023 | rc = -ENOMEM; |
| 1024 | goto out; |
| 1025 | } |
Kees Cook | 125cc42 | 2017-03-03 22:09:18 -0800 | [diff] [blame] | 1026 | memcpy(record->buf, rcd->data, len - sizeof(*rcd)); |
| 1027 | record->id = record_id; |
| 1028 | record->compressed = false; |
| 1029 | record->ecc_notice_size = 0; |
Tony Luck | 0bb77c4 | 2011-01-03 14:22:11 -0800 | [diff] [blame] | 1030 | if (uuid_le_cmp(rcd->sec_hdr.section_type, |
Aruna Balakrishnaiah | 901037b | 2013-08-16 13:57:26 -0700 | [diff] [blame] | 1031 | CPER_SECTION_TYPE_DMESG_Z) == 0) { |
Kees Cook | 125cc42 | 2017-03-03 22:09:18 -0800 | [diff] [blame] | 1032 | record->type = PSTORE_TYPE_DMESG; |
| 1033 | record->compressed = true; |
Aruna Balakrishnaiah | 901037b | 2013-08-16 13:57:26 -0700 | [diff] [blame] | 1034 | } else if (uuid_le_cmp(rcd->sec_hdr.section_type, |
Tony Luck | 0bb77c4 | 2011-01-03 14:22:11 -0800 | [diff] [blame] | 1035 | CPER_SECTION_TYPE_DMESG) == 0) |
Kees Cook | 125cc42 | 2017-03-03 22:09:18 -0800 | [diff] [blame] | 1036 | record->type = PSTORE_TYPE_DMESG; |
Tony Luck | 0bb77c4 | 2011-01-03 14:22:11 -0800 | [diff] [blame] | 1037 | else if (uuid_le_cmp(rcd->sec_hdr.section_type, |
| 1038 | CPER_SECTION_TYPE_MCE) == 0) |
Kees Cook | 125cc42 | 2017-03-03 22:09:18 -0800 | [diff] [blame] | 1039 | record->type = PSTORE_TYPE_MCE; |
Tony Luck | 0bb77c4 | 2011-01-03 14:22:11 -0800 | [diff] [blame] | 1040 | else |
Kees Cook | 125cc42 | 2017-03-03 22:09:18 -0800 | [diff] [blame] | 1041 | record->type = PSTORE_TYPE_UNKNOWN; |
Tony Luck | 0bb77c4 | 2011-01-03 14:22:11 -0800 | [diff] [blame] | 1042 | |
| 1043 | if (rcd->hdr.validation_bits & CPER_VALID_TIMESTAMP) |
Kees Cook | 125cc42 | 2017-03-03 22:09:18 -0800 | [diff] [blame] | 1044 | record->time.tv_sec = rcd->hdr.timestamp; |
Tony Luck | 0bb77c4 | 2011-01-03 14:22:11 -0800 | [diff] [blame] | 1045 | else |
Kees Cook | 125cc42 | 2017-03-03 22:09:18 -0800 | [diff] [blame] | 1046 | record->time.tv_sec = 0; |
| 1047 | record->time.tv_nsec = 0; |
Tony Luck | 0bb77c4 | 2011-01-03 14:22:11 -0800 | [diff] [blame] | 1048 | |
Chen Gong | 06cf91b | 2011-05-16 11:00:27 -0700 | [diff] [blame] | 1049 | out: |
Kees Cook | f6f8285 | 2011-11-17 12:58:07 -0800 | [diff] [blame] | 1050 | kfree(rcd); |
Chen Gong | 06cf91b | 2011-05-16 11:00:27 -0700 | [diff] [blame] | 1051 | return (rc < 0) ? rc : (len - sizeof(*rcd)); |
Tony Luck | 0bb77c4 | 2011-01-03 14:22:11 -0800 | [diff] [blame] | 1052 | } |
| 1053 | |
Kees Cook | 76cc958 | 2017-03-03 23:28:53 -0800 | [diff] [blame] | 1054 | static int erst_writer(struct pstore_record *record) |
Tony Luck | 0bb77c4 | 2011-01-03 14:22:11 -0800 | [diff] [blame] | 1055 | { |
| 1056 | struct cper_pstore_record *rcd = (struct cper_pstore_record *) |
| 1057 | (erst_info.buf - sizeof(*rcd)); |
Chen Gong | b238b8f | 2011-10-12 09:17:24 -0700 | [diff] [blame] | 1058 | int ret; |
Tony Luck | 0bb77c4 | 2011-01-03 14:22:11 -0800 | [diff] [blame] | 1059 | |
| 1060 | memset(rcd, 0, sizeof(*rcd)); |
| 1061 | memcpy(rcd->hdr.signature, CPER_SIG_RECORD, CPER_SIG_SIZE); |
| 1062 | rcd->hdr.revision = CPER_RECORD_REV; |
| 1063 | rcd->hdr.signature_end = CPER_SIG_END; |
| 1064 | rcd->hdr.section_count = 1; |
| 1065 | rcd->hdr.error_severity = CPER_SEV_FATAL; |
| 1066 | /* timestamp valid. platform_id, partition_id are invalid */ |
| 1067 | rcd->hdr.validation_bits = CPER_VALID_TIMESTAMP; |
| 1068 | rcd->hdr.timestamp = get_seconds(); |
Kees Cook | 76cc958 | 2017-03-03 23:28:53 -0800 | [diff] [blame] | 1069 | rcd->hdr.record_length = sizeof(*rcd) + record->size; |
Tony Luck | 0bb77c4 | 2011-01-03 14:22:11 -0800 | [diff] [blame] | 1070 | rcd->hdr.creator_id = CPER_CREATOR_PSTORE; |
| 1071 | rcd->hdr.notification_type = CPER_NOTIFY_MCE; |
| 1072 | rcd->hdr.record_id = cper_next_record_id(); |
| 1073 | rcd->hdr.flags = CPER_HW_ERROR_FLAGS_PREVERR; |
| 1074 | |
| 1075 | rcd->sec_hdr.section_offset = sizeof(*rcd); |
Kees Cook | 76cc958 | 2017-03-03 23:28:53 -0800 | [diff] [blame] | 1076 | rcd->sec_hdr.section_length = record->size; |
Tony Luck | 0bb77c4 | 2011-01-03 14:22:11 -0800 | [diff] [blame] | 1077 | rcd->sec_hdr.revision = CPER_SEC_REV; |
| 1078 | /* fru_id and fru_text is invalid */ |
| 1079 | rcd->sec_hdr.validation_bits = 0; |
| 1080 | rcd->sec_hdr.flags = CPER_SEC_PRIMARY; |
Kees Cook | 76cc958 | 2017-03-03 23:28:53 -0800 | [diff] [blame] | 1081 | switch (record->type) { |
Tony Luck | 0bb77c4 | 2011-01-03 14:22:11 -0800 | [diff] [blame] | 1082 | case PSTORE_TYPE_DMESG: |
Kees Cook | 76cc958 | 2017-03-03 23:28:53 -0800 | [diff] [blame] | 1083 | if (record->compressed) |
Aruna Balakrishnaiah | 901037b | 2013-08-16 13:57:26 -0700 | [diff] [blame] | 1084 | rcd->sec_hdr.section_type = CPER_SECTION_TYPE_DMESG_Z; |
| 1085 | else |
| 1086 | rcd->sec_hdr.section_type = CPER_SECTION_TYPE_DMESG; |
Tony Luck | 0bb77c4 | 2011-01-03 14:22:11 -0800 | [diff] [blame] | 1087 | break; |
| 1088 | case PSTORE_TYPE_MCE: |
| 1089 | rcd->sec_hdr.section_type = CPER_SECTION_TYPE_MCE; |
| 1090 | break; |
| 1091 | default: |
| 1092 | return -EINVAL; |
| 1093 | } |
| 1094 | rcd->sec_hdr.section_severity = CPER_SEV_FATAL; |
| 1095 | |
Chen Gong | b238b8f | 2011-10-12 09:17:24 -0700 | [diff] [blame] | 1096 | ret = erst_write(&rcd->hdr); |
Kees Cook | 76cc958 | 2017-03-03 23:28:53 -0800 | [diff] [blame] | 1097 | record->id = rcd->hdr.record_id; |
Tony Luck | 0bb77c4 | 2011-01-03 14:22:11 -0800 | [diff] [blame] | 1098 | |
Chen Gong | b238b8f | 2011-10-12 09:17:24 -0700 | [diff] [blame] | 1099 | return ret; |
Tony Luck | 0bb77c4 | 2011-01-03 14:22:11 -0800 | [diff] [blame] | 1100 | } |
| 1101 | |
Kees Cook | a61072a | 2017-03-04 23:31:19 -0800 | [diff] [blame] | 1102 | static int erst_clearer(struct pstore_record *record) |
Matthew Garrett | 638c1fd | 2011-07-21 16:57:52 -0400 | [diff] [blame] | 1103 | { |
Kees Cook | a61072a | 2017-03-04 23:31:19 -0800 | [diff] [blame] | 1104 | return erst_clear(record->id); |
Matthew Garrett | 638c1fd | 2011-07-21 16:57:52 -0400 | [diff] [blame] | 1105 | } |
| 1106 | |
Huang Ying | a08f82d | 2010-05-18 14:35:21 +0800 | [diff] [blame] | 1107 | static int __init erst_init(void) |
| 1108 | { |
| 1109 | int rc = 0; |
| 1110 | acpi_status status; |
| 1111 | struct apei_exec_context ctx; |
| 1112 | struct apei_resources erst_resources; |
| 1113 | struct resource *r; |
Tony Luck | 0bb77c4 | 2011-01-03 14:22:11 -0800 | [diff] [blame] | 1114 | char *buf; |
Huang Ying | a08f82d | 2010-05-18 14:35:21 +0800 | [diff] [blame] | 1115 | |
| 1116 | if (acpi_disabled) |
| 1117 | goto err; |
| 1118 | |
| 1119 | if (erst_disable) { |
Borislav Petkov | cb82a2e | 2013-07-29 15:51:35 +0200 | [diff] [blame] | 1120 | pr_info( |
Huang Ying | a08f82d | 2010-05-18 14:35:21 +0800 | [diff] [blame] | 1121 | "Error Record Serialization Table (ERST) support is disabled.\n"); |
| 1122 | goto err; |
| 1123 | } |
| 1124 | |
| 1125 | status = acpi_get_table(ACPI_SIG_ERST, 0, |
| 1126 | (struct acpi_table_header **)&erst_tab); |
Huang Ying | ad68615 | 2011-12-08 11:25:43 +0800 | [diff] [blame] | 1127 | if (status == AE_NOT_FOUND) |
Huang Ying | a08f82d | 2010-05-18 14:35:21 +0800 | [diff] [blame] | 1128 | goto err; |
Huang Ying | ad68615 | 2011-12-08 11:25:43 +0800 | [diff] [blame] | 1129 | else if (ACPI_FAILURE(status)) { |
Huang Ying | a08f82d | 2010-05-18 14:35:21 +0800 | [diff] [blame] | 1130 | const char *msg = acpi_format_exception(status); |
Borislav Petkov | cb82a2e | 2013-07-29 15:51:35 +0200 | [diff] [blame] | 1131 | pr_err("Failed to get table, %s\n", msg); |
Huang Ying | a08f82d | 2010-05-18 14:35:21 +0800 | [diff] [blame] | 1132 | rc = -EINVAL; |
| 1133 | goto err; |
| 1134 | } |
| 1135 | |
| 1136 | rc = erst_check_table(erst_tab); |
| 1137 | if (rc) { |
Borislav Petkov | cb82a2e | 2013-07-29 15:51:35 +0200 | [diff] [blame] | 1138 | pr_err(FW_BUG "ERST table is invalid.\n"); |
Huang Ying | a08f82d | 2010-05-18 14:35:21 +0800 | [diff] [blame] | 1139 | goto err; |
| 1140 | } |
| 1141 | |
| 1142 | apei_resources_init(&erst_resources); |
| 1143 | erst_exec_ctx_init(&ctx); |
| 1144 | rc = apei_exec_collect_resources(&ctx, &erst_resources); |
| 1145 | if (rc) |
| 1146 | goto err_fini; |
| 1147 | rc = apei_resources_request(&erst_resources, "APEI ERST"); |
| 1148 | if (rc) |
| 1149 | goto err_fini; |
| 1150 | rc = apei_exec_pre_map_gars(&ctx); |
| 1151 | if (rc) |
| 1152 | goto err_release; |
| 1153 | rc = erst_get_erange(&erst_erange); |
| 1154 | if (rc) { |
| 1155 | if (rc == -ENODEV) |
Borislav Petkov | cb82a2e | 2013-07-29 15:51:35 +0200 | [diff] [blame] | 1156 | pr_info( |
Huang Ying | a08f82d | 2010-05-18 14:35:21 +0800 | [diff] [blame] | 1157 | "The corresponding hardware device or firmware implementation " |
| 1158 | "is not available.\n"); |
| 1159 | else |
Borislav Petkov | cb82a2e | 2013-07-29 15:51:35 +0200 | [diff] [blame] | 1160 | pr_err("Failed to get Error Log Address Range.\n"); |
Huang Ying | a08f82d | 2010-05-18 14:35:21 +0800 | [diff] [blame] | 1161 | goto err_unmap_reg; |
| 1162 | } |
| 1163 | |
| 1164 | r = request_mem_region(erst_erange.base, erst_erange.size, "APEI ERST"); |
| 1165 | if (!r) { |
Borislav Petkov | cb82a2e | 2013-07-29 15:51:35 +0200 | [diff] [blame] | 1166 | pr_err("Can not request [mem %#010llx-%#010llx] for ERST.\n", |
| 1167 | (unsigned long long)erst_erange.base, |
| 1168 | (unsigned long long)erst_erange.base + erst_erange.size - 1); |
Huang Ying | a08f82d | 2010-05-18 14:35:21 +0800 | [diff] [blame] | 1169 | rc = -EIO; |
| 1170 | goto err_unmap_reg; |
| 1171 | } |
| 1172 | rc = -ENOMEM; |
| 1173 | erst_erange.vaddr = ioremap_cache(erst_erange.base, |
| 1174 | erst_erange.size); |
| 1175 | if (!erst_erange.vaddr) |
| 1176 | goto err_release_erange; |
| 1177 | |
Borislav Petkov | cb82a2e | 2013-07-29 15:51:35 +0200 | [diff] [blame] | 1178 | pr_info( |
Lenny Szubowicz | 74fd6c6 | 2013-06-28 16:14:10 -0400 | [diff] [blame] | 1179 | "Error Record Serialization Table (ERST) support is initialized.\n"); |
| 1180 | |
Tony Luck | 0bb77c4 | 2011-01-03 14:22:11 -0800 | [diff] [blame] | 1181 | buf = kmalloc(erst_erange.size, GFP_KERNEL); |
Don Zickus | abd4d55 | 2011-08-12 10:54:51 -0700 | [diff] [blame] | 1182 | spin_lock_init(&erst_info.buf_lock); |
Tony Luck | 0bb77c4 | 2011-01-03 14:22:11 -0800 | [diff] [blame] | 1183 | if (buf) { |
| 1184 | erst_info.buf = buf + sizeof(struct cper_pstore_record); |
| 1185 | erst_info.bufsize = erst_erange.size - |
| 1186 | sizeof(struct cper_pstore_record); |
Lenny Szubowicz | 74fd6c6 | 2013-06-28 16:14:10 -0400 | [diff] [blame] | 1187 | rc = pstore_register(&erst_info); |
| 1188 | if (rc) { |
| 1189 | if (rc != -EPERM) |
Borislav Petkov | cb82a2e | 2013-07-29 15:51:35 +0200 | [diff] [blame] | 1190 | pr_info( |
| 1191 | "Could not register with persistent store.\n"); |
Lenny Szubowicz | 74fd6c6 | 2013-06-28 16:14:10 -0400 | [diff] [blame] | 1192 | erst_info.buf = NULL; |
| 1193 | erst_info.bufsize = 0; |
Tony Luck | 0bb77c4 | 2011-01-03 14:22:11 -0800 | [diff] [blame] | 1194 | kfree(buf); |
| 1195 | } |
Lenny Szubowicz | 74fd6c6 | 2013-06-28 16:14:10 -0400 | [diff] [blame] | 1196 | } else |
Borislav Petkov | cb82a2e | 2013-07-29 15:51:35 +0200 | [diff] [blame] | 1197 | pr_err( |
| 1198 | "Failed to allocate %lld bytes for persistent store error log.\n", |
Lenny Szubowicz | 74fd6c6 | 2013-06-28 16:14:10 -0400 | [diff] [blame] | 1199 | erst_erange.size); |
Huang Ying | a08f82d | 2010-05-18 14:35:21 +0800 | [diff] [blame] | 1200 | |
Josh Hunt | 3a03d12 | 2016-03-08 10:52:12 -0500 | [diff] [blame] | 1201 | /* Cleanup ERST Resources */ |
| 1202 | apei_resources_fini(&erst_resources); |
| 1203 | |
Huang Ying | a08f82d | 2010-05-18 14:35:21 +0800 | [diff] [blame] | 1204 | return 0; |
| 1205 | |
| 1206 | err_release_erange: |
| 1207 | release_mem_region(erst_erange.base, erst_erange.size); |
| 1208 | err_unmap_reg: |
| 1209 | apei_exec_post_unmap_gars(&ctx); |
| 1210 | err_release: |
| 1211 | apei_resources_release(&erst_resources); |
| 1212 | err_fini: |
| 1213 | apei_resources_fini(&erst_resources); |
| 1214 | err: |
| 1215 | erst_disable = 1; |
| 1216 | return rc; |
| 1217 | } |
| 1218 | |
| 1219 | device_initcall(erst_init); |