Huang Ying | d334a49 | 2010-05-18 14:35:20 +0800 | [diff] [blame] | 1 | /* |
| 2 | * APEI Generic Hardware Error Source support |
| 3 | * |
| 4 | * Generic Hardware Error Source provides a way to report platform |
| 5 | * hardware errors (such as that from chipset). It works in so called |
| 6 | * "Firmware First" mode, that is, hardware errors are reported to |
| 7 | * firmware firstly, then reported to Linux by firmware. This way, |
| 8 | * some non-standard hardware error registers or non-standard hardware |
| 9 | * link can be checked by firmware to produce more hardware error |
| 10 | * information for Linux. |
| 11 | * |
| 12 | * For more information about Generic Hardware Error Source, please |
| 13 | * refer to ACPI Specification version 4.0, section 17.3.2.6 |
| 14 | * |
Huang Ying | 67eb2e9 | 2011-07-13 13:14:25 +0800 | [diff] [blame] | 15 | * Copyright 2010,2011 Intel Corp. |
Huang Ying | d334a49 | 2010-05-18 14:35:20 +0800 | [diff] [blame] | 16 | * Author: Huang Ying <ying.huang@intel.com> |
| 17 | * |
| 18 | * This program is free software; you can redistribute it and/or |
| 19 | * modify it under the terms of the GNU General Public License version |
| 20 | * 2 as published by the Free Software Foundation; |
| 21 | * |
| 22 | * This program is distributed in the hope that it will be useful, |
| 23 | * but WITHOUT ANY WARRANTY; without even the implied warranty of |
| 24 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
| 25 | * GNU General Public License for more details. |
| 26 | * |
| 27 | * You should have received a copy of the GNU General Public License |
| 28 | * along with this program; if not, write to the Free Software |
| 29 | * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA |
| 30 | */ |
| 31 | |
| 32 | #include <linux/kernel.h> |
| 33 | #include <linux/module.h> |
| 34 | #include <linux/init.h> |
| 35 | #include <linux/acpi.h> |
| 36 | #include <linux/io.h> |
| 37 | #include <linux/interrupt.h> |
Huang Ying | 81e88fd | 2011-01-12 14:44:55 +0800 | [diff] [blame] | 38 | #include <linux/timer.h> |
Huang Ying | d334a49 | 2010-05-18 14:35:20 +0800 | [diff] [blame] | 39 | #include <linux/cper.h> |
| 40 | #include <linux/kdebug.h> |
Huang Ying | 7ad6e94 | 2010-08-02 15:48:24 +0800 | [diff] [blame] | 41 | #include <linux/platform_device.h> |
| 42 | #include <linux/mutex.h> |
Huang Ying | 32c361f | 2010-12-07 10:22:31 +0800 | [diff] [blame] | 43 | #include <linux/ratelimit.h> |
Huang Ying | 81e88fd | 2011-01-12 14:44:55 +0800 | [diff] [blame] | 44 | #include <linux/vmalloc.h> |
Huang Ying | 67eb2e9 | 2011-07-13 13:14:25 +0800 | [diff] [blame] | 45 | #include <linux/irq_work.h> |
| 46 | #include <linux/llist.h> |
| 47 | #include <linux/genalloc.h> |
Huang Ying | a654e5e | 2011-12-08 11:25:41 +0800 | [diff] [blame] | 48 | #include <linux/pci.h> |
| 49 | #include <linux/aer.h> |
Tomasz Nowicki | 44a69f6 | 2014-07-22 11:20:12 +0200 | [diff] [blame] | 50 | #include <linux/nmi.h> |
Mauro Carvalho Chehab | 40e0641 | 2013-02-15 05:41:22 -0300 | [diff] [blame] | 51 | |
| 52 | #include <acpi/ghes.h> |
Tomasz Nowicki | 9dae3d0 | 2014-07-22 11:20:11 +0200 | [diff] [blame] | 53 | #include <acpi/apei.h> |
Huang Ying | 81e88fd | 2011-01-12 14:44:55 +0800 | [diff] [blame] | 54 | #include <asm/tlbflush.h> |
Huang Ying | d334a49 | 2010-05-18 14:35:20 +0800 | [diff] [blame] | 55 | |
| 56 | #include "apei-internal.h" |
| 57 | |
| 58 | #define GHES_PFX "GHES: " |
| 59 | |
| 60 | #define GHES_ESTATUS_MAX_SIZE 65536 |
Huang Ying | 67eb2e9 | 2011-07-13 13:14:25 +0800 | [diff] [blame] | 61 | #define GHES_ESOURCE_PREALLOC_MAX_SIZE 65536 |
| 62 | |
| 63 | #define GHES_ESTATUS_POOL_MIN_ALLOC_ORDER 3 |
| 64 | |
Huang Ying | 152cef4 | 2011-07-13 13:14:26 +0800 | [diff] [blame] | 65 | /* This is just an estimation for memory pool allocation */ |
| 66 | #define GHES_ESTATUS_CACHE_AVG_SIZE 512 |
| 67 | |
| 68 | #define GHES_ESTATUS_CACHES_SIZE 4 |
| 69 | |
Len Brown | 70cb6e1 | 2011-08-02 18:00:21 -0400 | [diff] [blame] | 70 | #define GHES_ESTATUS_IN_CACHE_MAX_NSEC 10000000000ULL |
Huang Ying | 152cef4 | 2011-07-13 13:14:26 +0800 | [diff] [blame] | 71 | /* Prevent too many caches are allocated because of RCU */ |
| 72 | #define GHES_ESTATUS_CACHE_ALLOCED_MAX (GHES_ESTATUS_CACHES_SIZE * 3 / 2) |
| 73 | |
| 74 | #define GHES_ESTATUS_CACHE_LEN(estatus_len) \ |
| 75 | (sizeof(struct ghes_estatus_cache) + (estatus_len)) |
| 76 | #define GHES_ESTATUS_FROM_CACHE(estatus_cache) \ |
Lv Zheng | 0a00fd5 | 2014-06-03 16:32:53 +0800 | [diff] [blame] | 77 | ((struct acpi_hest_generic_status *) \ |
Huang Ying | 152cef4 | 2011-07-13 13:14:26 +0800 | [diff] [blame] | 78 | ((struct ghes_estatus_cache *)(estatus_cache) + 1)) |
| 79 | |
Huang Ying | 67eb2e9 | 2011-07-13 13:14:25 +0800 | [diff] [blame] | 80 | #define GHES_ESTATUS_NODE_LEN(estatus_len) \ |
| 81 | (sizeof(struct ghes_estatus_node) + (estatus_len)) |
Chen, Gong | 88f074f | 2013-10-18 14:28:59 -0700 | [diff] [blame] | 82 | #define GHES_ESTATUS_FROM_NODE(estatus_node) \ |
Lv Zheng | 0a00fd5 | 2014-06-03 16:32:53 +0800 | [diff] [blame] | 83 | ((struct acpi_hest_generic_status *) \ |
Huang Ying | 67eb2e9 | 2011-07-13 13:14:25 +0800 | [diff] [blame] | 84 | ((struct ghes_estatus_node *)(estatus_node) + 1)) |
Huang Ying | d334a49 | 2010-05-18 14:35:20 +0800 | [diff] [blame] | 85 | |
Rusty Russell | 90ab5ee | 2012-01-13 09:32:20 +1030 | [diff] [blame] | 86 | bool ghes_disable; |
Huang Ying | b6a9501 | 2011-07-13 13:14:19 +0800 | [diff] [blame] | 87 | module_param_named(disable, ghes_disable, bool, 0); |
| 88 | |
Huang Ying | d334a49 | 2010-05-18 14:35:20 +0800 | [diff] [blame] | 89 | /* |
Huang Ying | 81e88fd | 2011-01-12 14:44:55 +0800 | [diff] [blame] | 90 | * All error sources notified with SCI shares one notifier function, |
| 91 | * so they need to be linked and checked one by one. This is applied |
| 92 | * to NMI too. |
Huang Ying | d334a49 | 2010-05-18 14:35:20 +0800 | [diff] [blame] | 93 | * |
Huang Ying | 81e88fd | 2011-01-12 14:44:55 +0800 | [diff] [blame] | 94 | * RCU is used for these lists, so ghes_list_mutex is only used for |
| 95 | * list changing, not for traversing. |
Huang Ying | d334a49 | 2010-05-18 14:35:20 +0800 | [diff] [blame] | 96 | */ |
| 97 | static LIST_HEAD(ghes_sci); |
Huang Ying | 7ad6e94 | 2010-08-02 15:48:24 +0800 | [diff] [blame] | 98 | static DEFINE_MUTEX(ghes_list_mutex); |
Huang Ying | d334a49 | 2010-05-18 14:35:20 +0800 | [diff] [blame] | 99 | |
Huang Ying | 81e88fd | 2011-01-12 14:44:55 +0800 | [diff] [blame] | 100 | /* |
Huang Ying | 81e88fd | 2011-01-12 14:44:55 +0800 | [diff] [blame] | 101 | * Because the memory area used to transfer hardware error information |
| 102 | * from BIOS to Linux can be determined only in NMI, IRQ or timer |
| 103 | * handler, but general ioremap can not be used in atomic context, so |
| 104 | * a special version of atomic ioremap is implemented for that. |
| 105 | */ |
| 106 | |
| 107 | /* |
Tomasz Nowicki | 594c725 | 2014-07-22 11:20:13 +0200 | [diff] [blame] | 108 | * Two virtual pages are used, one for IRQ/PROCESS context, the other for |
| 109 | * NMI context (optionally). |
Huang Ying | 81e88fd | 2011-01-12 14:44:55 +0800 | [diff] [blame] | 110 | */ |
Tomasz Nowicki | 594c725 | 2014-07-22 11:20:13 +0200 | [diff] [blame] | 111 | #ifdef CONFIG_HAVE_ACPI_APEI_NMI |
| 112 | #define GHES_IOREMAP_PAGES 2 |
| 113 | #else |
| 114 | #define GHES_IOREMAP_PAGES 1 |
| 115 | #endif |
| 116 | #define GHES_IOREMAP_IRQ_PAGE(base) (base) |
| 117 | #define GHES_IOREMAP_NMI_PAGE(base) ((base) + PAGE_SIZE) |
Huang Ying | 81e88fd | 2011-01-12 14:44:55 +0800 | [diff] [blame] | 118 | |
| 119 | /* virtual memory area for atomic ioremap */ |
| 120 | static struct vm_struct *ghes_ioremap_area; |
| 121 | /* |
| 122 | * These 2 spinlock is used to prevent atomic ioremap virtual memory |
| 123 | * area from being mapped simultaneously. |
| 124 | */ |
| 125 | static DEFINE_RAW_SPINLOCK(ghes_ioremap_lock_nmi); |
| 126 | static DEFINE_SPINLOCK(ghes_ioremap_lock_irq); |
| 127 | |
Huang Ying | 67eb2e9 | 2011-07-13 13:14:25 +0800 | [diff] [blame] | 128 | static struct gen_pool *ghes_estatus_pool; |
| 129 | static unsigned long ghes_estatus_pool_size_request; |
Huang Ying | 67eb2e9 | 2011-07-13 13:14:25 +0800 | [diff] [blame] | 130 | |
Borislav Petkov | 8f7c31f | 2014-09-29 13:33:17 +0200 | [diff] [blame] | 131 | static struct ghes_estatus_cache *ghes_estatus_caches[GHES_ESTATUS_CACHES_SIZE]; |
Huang Ying | 152cef4 | 2011-07-13 13:14:26 +0800 | [diff] [blame] | 132 | static atomic_t ghes_estatus_cache_alloced; |
| 133 | |
Huang Ying | 81e88fd | 2011-01-12 14:44:55 +0800 | [diff] [blame] | 134 | static int ghes_ioremap_init(void) |
| 135 | { |
| 136 | ghes_ioremap_area = __get_vm_area(PAGE_SIZE * GHES_IOREMAP_PAGES, |
| 137 | VM_IOREMAP, VMALLOC_START, VMALLOC_END); |
| 138 | if (!ghes_ioremap_area) { |
| 139 | pr_err(GHES_PFX "Failed to allocate virtual memory area for atomic ioremap.\n"); |
| 140 | return -ENOMEM; |
| 141 | } |
| 142 | |
| 143 | return 0; |
| 144 | } |
| 145 | |
| 146 | static void ghes_ioremap_exit(void) |
| 147 | { |
| 148 | free_vm_area(ghes_ioremap_area); |
| 149 | } |
| 150 | |
| 151 | static void __iomem *ghes_ioremap_pfn_nmi(u64 pfn) |
| 152 | { |
| 153 | unsigned long vaddr; |
| 154 | |
| 155 | vaddr = (unsigned long)GHES_IOREMAP_NMI_PAGE(ghes_ioremap_area->addr); |
| 156 | ioremap_page_range(vaddr, vaddr + PAGE_SIZE, |
| 157 | pfn << PAGE_SHIFT, PAGE_KERNEL); |
| 158 | |
| 159 | return (void __iomem *)vaddr; |
| 160 | } |
| 161 | |
| 162 | static void __iomem *ghes_ioremap_pfn_irq(u64 pfn) |
| 163 | { |
| 164 | unsigned long vaddr; |
| 165 | |
| 166 | vaddr = (unsigned long)GHES_IOREMAP_IRQ_PAGE(ghes_ioremap_area->addr); |
| 167 | ioremap_page_range(vaddr, vaddr + PAGE_SIZE, |
| 168 | pfn << PAGE_SHIFT, PAGE_KERNEL); |
| 169 | |
| 170 | return (void __iomem *)vaddr; |
| 171 | } |
| 172 | |
| 173 | static void ghes_iounmap_nmi(void __iomem *vaddr_ptr) |
| 174 | { |
| 175 | unsigned long vaddr = (unsigned long __force)vaddr_ptr; |
| 176 | void *base = ghes_ioremap_area->addr; |
| 177 | |
| 178 | BUG_ON(vaddr != (unsigned long)GHES_IOREMAP_NMI_PAGE(base)); |
| 179 | unmap_kernel_range_noflush(vaddr, PAGE_SIZE); |
Tomasz Nowicki | 594c725 | 2014-07-22 11:20:13 +0200 | [diff] [blame] | 180 | arch_apei_flush_tlb_one(vaddr); |
Huang Ying | 81e88fd | 2011-01-12 14:44:55 +0800 | [diff] [blame] | 181 | } |
| 182 | |
| 183 | static void ghes_iounmap_irq(void __iomem *vaddr_ptr) |
| 184 | { |
| 185 | unsigned long vaddr = (unsigned long __force)vaddr_ptr; |
| 186 | void *base = ghes_ioremap_area->addr; |
| 187 | |
| 188 | BUG_ON(vaddr != (unsigned long)GHES_IOREMAP_IRQ_PAGE(base)); |
| 189 | unmap_kernel_range_noflush(vaddr, PAGE_SIZE); |
Tomasz Nowicki | 594c725 | 2014-07-22 11:20:13 +0200 | [diff] [blame] | 190 | arch_apei_flush_tlb_one(vaddr); |
Huang Ying | 81e88fd | 2011-01-12 14:44:55 +0800 | [diff] [blame] | 191 | } |
| 192 | |
Huang Ying | 67eb2e9 | 2011-07-13 13:14:25 +0800 | [diff] [blame] | 193 | static int ghes_estatus_pool_init(void) |
| 194 | { |
| 195 | ghes_estatus_pool = gen_pool_create(GHES_ESTATUS_POOL_MIN_ALLOC_ORDER, -1); |
| 196 | if (!ghes_estatus_pool) |
| 197 | return -ENOMEM; |
| 198 | return 0; |
| 199 | } |
| 200 | |
| 201 | static void ghes_estatus_pool_free_chunk_page(struct gen_pool *pool, |
| 202 | struct gen_pool_chunk *chunk, |
| 203 | void *data) |
| 204 | { |
| 205 | free_page(chunk->start_addr); |
| 206 | } |
| 207 | |
| 208 | static void ghes_estatus_pool_exit(void) |
| 209 | { |
| 210 | gen_pool_for_each_chunk(ghes_estatus_pool, |
| 211 | ghes_estatus_pool_free_chunk_page, NULL); |
| 212 | gen_pool_destroy(ghes_estatus_pool); |
| 213 | } |
| 214 | |
| 215 | static int ghes_estatus_pool_expand(unsigned long len) |
| 216 | { |
| 217 | unsigned long i, pages, size, addr; |
| 218 | int ret; |
| 219 | |
| 220 | ghes_estatus_pool_size_request += PAGE_ALIGN(len); |
| 221 | size = gen_pool_size(ghes_estatus_pool); |
| 222 | if (size >= ghes_estatus_pool_size_request) |
| 223 | return 0; |
| 224 | pages = (ghes_estatus_pool_size_request - size) / PAGE_SIZE; |
| 225 | for (i = 0; i < pages; i++) { |
| 226 | addr = __get_free_page(GFP_KERNEL); |
| 227 | if (!addr) |
| 228 | return -ENOMEM; |
| 229 | ret = gen_pool_add(ghes_estatus_pool, addr, PAGE_SIZE, -1); |
| 230 | if (ret) |
| 231 | return ret; |
| 232 | } |
| 233 | |
| 234 | return 0; |
| 235 | } |
| 236 | |
Huang Ying | d334a49 | 2010-05-18 14:35:20 +0800 | [diff] [blame] | 237 | static struct ghes *ghes_new(struct acpi_hest_generic *generic) |
| 238 | { |
| 239 | struct ghes *ghes; |
| 240 | unsigned int error_block_length; |
| 241 | int rc; |
| 242 | |
| 243 | ghes = kzalloc(sizeof(*ghes), GFP_KERNEL); |
| 244 | if (!ghes) |
| 245 | return ERR_PTR(-ENOMEM); |
| 246 | ghes->generic = generic; |
Huang Ying | 34ddeb0 | 2012-06-12 11:20:19 +0800 | [diff] [blame] | 247 | rc = apei_map_generic_address(&generic->error_status_address); |
Huang Ying | d334a49 | 2010-05-18 14:35:20 +0800 | [diff] [blame] | 248 | if (rc) |
| 249 | goto err_free; |
| 250 | error_block_length = generic->error_block_length; |
| 251 | if (error_block_length > GHES_ESTATUS_MAX_SIZE) { |
| 252 | pr_warning(FW_WARN GHES_PFX |
| 253 | "Error status block length is too long: %u for " |
| 254 | "generic hardware error source: %d.\n", |
| 255 | error_block_length, generic->header.source_id); |
| 256 | error_block_length = GHES_ESTATUS_MAX_SIZE; |
| 257 | } |
| 258 | ghes->estatus = kmalloc(error_block_length, GFP_KERNEL); |
| 259 | if (!ghes->estatus) { |
| 260 | rc = -ENOMEM; |
| 261 | goto err_unmap; |
| 262 | } |
| 263 | |
| 264 | return ghes; |
| 265 | |
| 266 | err_unmap: |
Huang Ying | 34ddeb0 | 2012-06-12 11:20:19 +0800 | [diff] [blame] | 267 | apei_unmap_generic_address(&generic->error_status_address); |
Huang Ying | d334a49 | 2010-05-18 14:35:20 +0800 | [diff] [blame] | 268 | err_free: |
| 269 | kfree(ghes); |
| 270 | return ERR_PTR(rc); |
| 271 | } |
| 272 | |
| 273 | static void ghes_fini(struct ghes *ghes) |
| 274 | { |
| 275 | kfree(ghes->estatus); |
Huang Ying | 34ddeb0 | 2012-06-12 11:20:19 +0800 | [diff] [blame] | 276 | apei_unmap_generic_address(&ghes->generic->error_status_address); |
Huang Ying | d334a49 | 2010-05-18 14:35:20 +0800 | [diff] [blame] | 277 | } |
| 278 | |
Huang Ying | d334a49 | 2010-05-18 14:35:20 +0800 | [diff] [blame] | 279 | static inline int ghes_severity(int severity) |
| 280 | { |
| 281 | switch (severity) { |
Huang Ying | ad4ecef | 2010-08-02 15:48:23 +0800 | [diff] [blame] | 282 | case CPER_SEV_INFORMATIONAL: |
| 283 | return GHES_SEV_NO; |
| 284 | case CPER_SEV_CORRECTED: |
| 285 | return GHES_SEV_CORRECTED; |
| 286 | case CPER_SEV_RECOVERABLE: |
| 287 | return GHES_SEV_RECOVERABLE; |
| 288 | case CPER_SEV_FATAL: |
| 289 | return GHES_SEV_PANIC; |
Huang Ying | d334a49 | 2010-05-18 14:35:20 +0800 | [diff] [blame] | 290 | default: |
Lucas De Marchi | 25985ed | 2011-03-30 22:57:33 -0300 | [diff] [blame] | 291 | /* Unknown, go panic */ |
Huang Ying | ad4ecef | 2010-08-02 15:48:23 +0800 | [diff] [blame] | 292 | return GHES_SEV_PANIC; |
Huang Ying | d334a49 | 2010-05-18 14:35:20 +0800 | [diff] [blame] | 293 | } |
| 294 | } |
| 295 | |
Huang Ying | 81e88fd | 2011-01-12 14:44:55 +0800 | [diff] [blame] | 296 | static void ghes_copy_tofrom_phys(void *buffer, u64 paddr, u32 len, |
| 297 | int from_phys) |
Huang Ying | d334a49 | 2010-05-18 14:35:20 +0800 | [diff] [blame] | 298 | { |
Huang Ying | 81e88fd | 2011-01-12 14:44:55 +0800 | [diff] [blame] | 299 | void __iomem *vaddr; |
| 300 | unsigned long flags = 0; |
| 301 | int in_nmi = in_nmi(); |
| 302 | u64 offset; |
| 303 | u32 trunk; |
Huang Ying | d334a49 | 2010-05-18 14:35:20 +0800 | [diff] [blame] | 304 | |
Huang Ying | 81e88fd | 2011-01-12 14:44:55 +0800 | [diff] [blame] | 305 | while (len > 0) { |
| 306 | offset = paddr - (paddr & PAGE_MASK); |
| 307 | if (in_nmi) { |
| 308 | raw_spin_lock(&ghes_ioremap_lock_nmi); |
| 309 | vaddr = ghes_ioremap_pfn_nmi(paddr >> PAGE_SHIFT); |
| 310 | } else { |
| 311 | spin_lock_irqsave(&ghes_ioremap_lock_irq, flags); |
| 312 | vaddr = ghes_ioremap_pfn_irq(paddr >> PAGE_SHIFT); |
| 313 | } |
| 314 | trunk = PAGE_SIZE - offset; |
| 315 | trunk = min(trunk, len); |
| 316 | if (from_phys) |
| 317 | memcpy_fromio(buffer, vaddr + offset, trunk); |
| 318 | else |
| 319 | memcpy_toio(vaddr + offset, buffer, trunk); |
| 320 | len -= trunk; |
| 321 | paddr += trunk; |
| 322 | buffer += trunk; |
| 323 | if (in_nmi) { |
| 324 | ghes_iounmap_nmi(vaddr); |
| 325 | raw_spin_unlock(&ghes_ioremap_lock_nmi); |
| 326 | } else { |
| 327 | ghes_iounmap_irq(vaddr); |
| 328 | spin_unlock_irqrestore(&ghes_ioremap_lock_irq, flags); |
| 329 | } |
| 330 | } |
Huang Ying | d334a49 | 2010-05-18 14:35:20 +0800 | [diff] [blame] | 331 | } |
| 332 | |
| 333 | static int ghes_read_estatus(struct ghes *ghes, int silent) |
| 334 | { |
| 335 | struct acpi_hest_generic *g = ghes->generic; |
| 336 | u64 buf_paddr; |
| 337 | u32 len; |
| 338 | int rc; |
| 339 | |
Myron Stowe | 700130b | 2011-11-07 16:23:41 -0700 | [diff] [blame] | 340 | rc = apei_read(&buf_paddr, &g->error_status_address); |
Huang Ying | d334a49 | 2010-05-18 14:35:20 +0800 | [diff] [blame] | 341 | if (rc) { |
| 342 | if (!silent && printk_ratelimit()) |
| 343 | pr_warning(FW_WARN GHES_PFX |
| 344 | "Failed to read error status block address for hardware error source: %d.\n", |
| 345 | g->header.source_id); |
| 346 | return -EIO; |
| 347 | } |
| 348 | if (!buf_paddr) |
| 349 | return -ENOENT; |
| 350 | |
Huang Ying | 81e88fd | 2011-01-12 14:44:55 +0800 | [diff] [blame] | 351 | ghes_copy_tofrom_phys(ghes->estatus, buf_paddr, |
| 352 | sizeof(*ghes->estatus), 1); |
Huang Ying | d334a49 | 2010-05-18 14:35:20 +0800 | [diff] [blame] | 353 | if (!ghes->estatus->block_status) |
| 354 | return -ENOENT; |
| 355 | |
| 356 | ghes->buffer_paddr = buf_paddr; |
| 357 | ghes->flags |= GHES_TO_CLEAR; |
| 358 | |
| 359 | rc = -EIO; |
Chen, Gong | 88f074f | 2013-10-18 14:28:59 -0700 | [diff] [blame] | 360 | len = cper_estatus_len(ghes->estatus); |
Huang Ying | d334a49 | 2010-05-18 14:35:20 +0800 | [diff] [blame] | 361 | if (len < sizeof(*ghes->estatus)) |
| 362 | goto err_read_block; |
| 363 | if (len > ghes->generic->error_block_length) |
| 364 | goto err_read_block; |
Chen, Gong | 88f074f | 2013-10-18 14:28:59 -0700 | [diff] [blame] | 365 | if (cper_estatus_check_header(ghes->estatus)) |
Huang Ying | d334a49 | 2010-05-18 14:35:20 +0800 | [diff] [blame] | 366 | goto err_read_block; |
Huang Ying | 81e88fd | 2011-01-12 14:44:55 +0800 | [diff] [blame] | 367 | ghes_copy_tofrom_phys(ghes->estatus + 1, |
| 368 | buf_paddr + sizeof(*ghes->estatus), |
| 369 | len - sizeof(*ghes->estatus), 1); |
Chen, Gong | 88f074f | 2013-10-18 14:28:59 -0700 | [diff] [blame] | 370 | if (cper_estatus_check(ghes->estatus)) |
Huang Ying | d334a49 | 2010-05-18 14:35:20 +0800 | [diff] [blame] | 371 | goto err_read_block; |
| 372 | rc = 0; |
| 373 | |
| 374 | err_read_block: |
Huang Ying | 81e88fd | 2011-01-12 14:44:55 +0800 | [diff] [blame] | 375 | if (rc && !silent && printk_ratelimit()) |
Huang Ying | d334a49 | 2010-05-18 14:35:20 +0800 | [diff] [blame] | 376 | pr_warning(FW_WARN GHES_PFX |
| 377 | "Failed to read error status block!\n"); |
| 378 | return rc; |
| 379 | } |
| 380 | |
| 381 | static void ghes_clear_estatus(struct ghes *ghes) |
| 382 | { |
| 383 | ghes->estatus->block_status = 0; |
| 384 | if (!(ghes->flags & GHES_TO_CLEAR)) |
| 385 | return; |
| 386 | ghes_copy_tofrom_phys(ghes->estatus, ghes->buffer_paddr, |
| 387 | sizeof(ghes->estatus->block_status), 0); |
| 388 | ghes->flags &= ~GHES_TO_CLEAR; |
| 389 | } |
| 390 | |
Lv Zheng | 0a00fd5 | 2014-06-03 16:32:53 +0800 | [diff] [blame] | 391 | static void ghes_handle_memory_failure(struct acpi_hest_generic_data *gdata, int sev) |
Naveen N. Rao | cf870c7 | 2013-07-10 14:57:01 +0530 | [diff] [blame] | 392 | { |
| 393 | #ifdef CONFIG_ACPI_APEI_MEMORY_FAILURE |
| 394 | unsigned long pfn; |
Chen, Gong | ca104ed | 2013-11-25 02:15:01 -0500 | [diff] [blame] | 395 | int flags = -1; |
Naveen N. Rao | cf870c7 | 2013-07-10 14:57:01 +0530 | [diff] [blame] | 396 | int sec_sev = ghes_severity(gdata->error_severity); |
| 397 | struct cper_sec_mem_err *mem_err; |
| 398 | mem_err = (struct cper_sec_mem_err *)(gdata + 1); |
| 399 | |
Chen, Gong | ca104ed | 2013-11-25 02:15:01 -0500 | [diff] [blame] | 400 | if (!(mem_err->validation_bits & CPER_MEM_VALID_PA)) |
| 401 | return; |
| 402 | |
| 403 | pfn = mem_err->physical_addr >> PAGE_SHIFT; |
| 404 | if (!pfn_valid(pfn)) { |
| 405 | pr_warn_ratelimited(FW_WARN GHES_PFX |
| 406 | "Invalid address in generic error data: %#llx\n", |
| 407 | mem_err->physical_addr); |
| 408 | return; |
| 409 | } |
| 410 | |
| 411 | /* iff following two events can be handled properly by now */ |
Naveen N. Rao | cf870c7 | 2013-07-10 14:57:01 +0530 | [diff] [blame] | 412 | if (sec_sev == GHES_SEV_CORRECTED && |
Chen, Gong | ca104ed | 2013-11-25 02:15:01 -0500 | [diff] [blame] | 413 | (gdata->flags & CPER_SEC_ERROR_THRESHOLD_EXCEEDED)) |
| 414 | flags = MF_SOFT_OFFLINE; |
| 415 | if (sev == GHES_SEV_RECOVERABLE && sec_sev == GHES_SEV_RECOVERABLE) |
| 416 | flags = 0; |
| 417 | |
| 418 | if (flags != -1) |
| 419 | memory_failure_queue(pfn, 0, flags); |
Naveen N. Rao | cf870c7 | 2013-07-10 14:57:01 +0530 | [diff] [blame] | 420 | #endif |
| 421 | } |
| 422 | |
Mauro Carvalho Chehab | 2148054 | 2013-02-15 06:10:39 -0300 | [diff] [blame] | 423 | static void ghes_do_proc(struct ghes *ghes, |
Lv Zheng | 0a00fd5 | 2014-06-03 16:32:53 +0800 | [diff] [blame] | 424 | const struct acpi_hest_generic_status *estatus) |
Huang Ying | d334a49 | 2010-05-18 14:35:20 +0800 | [diff] [blame] | 425 | { |
Huang Ying | ba61ca4 | 2011-07-13 13:14:28 +0800 | [diff] [blame] | 426 | int sev, sec_sev; |
Lv Zheng | 0a00fd5 | 2014-06-03 16:32:53 +0800 | [diff] [blame] | 427 | struct acpi_hest_generic_data *gdata; |
Huang Ying | d334a49 | 2010-05-18 14:35:20 +0800 | [diff] [blame] | 428 | |
Huang Ying | 67eb2e9 | 2011-07-13 13:14:25 +0800 | [diff] [blame] | 429 | sev = ghes_severity(estatus->error_severity); |
| 430 | apei_estatus_for_each_section(estatus, gdata) { |
Huang Ying | ba61ca4 | 2011-07-13 13:14:28 +0800 | [diff] [blame] | 431 | sec_sev = ghes_severity(gdata->error_severity); |
Huang Ying | d334a49 | 2010-05-18 14:35:20 +0800 | [diff] [blame] | 432 | if (!uuid_le_cmp(*(uuid_le *)gdata->section_type, |
| 433 | CPER_SEC_PLATFORM_MEM)) { |
Huang Ying | ba61ca4 | 2011-07-13 13:14:28 +0800 | [diff] [blame] | 434 | struct cper_sec_mem_err *mem_err; |
| 435 | mem_err = (struct cper_sec_mem_err *)(gdata+1); |
Mauro Carvalho Chehab | 2148054 | 2013-02-15 06:10:39 -0300 | [diff] [blame] | 436 | ghes_edac_report_mem_error(ghes, sev, mem_err); |
| 437 | |
Tomasz Nowicki | 9dae3d0 | 2014-07-22 11:20:11 +0200 | [diff] [blame] | 438 | arch_apei_report_mem_error(sev, mem_err); |
Naveen N. Rao | cf870c7 | 2013-07-10 14:57:01 +0530 | [diff] [blame] | 439 | ghes_handle_memory_failure(gdata, sev); |
Huang Ying | ba61ca4 | 2011-07-13 13:14:28 +0800 | [diff] [blame] | 440 | } |
Huang Ying | a654e5e | 2011-12-08 11:25:41 +0800 | [diff] [blame] | 441 | #ifdef CONFIG_ACPI_APEI_PCIEAER |
| 442 | else if (!uuid_le_cmp(*(uuid_le *)gdata->section_type, |
| 443 | CPER_SEC_PCIE)) { |
| 444 | struct cper_sec_pcie *pcie_err; |
| 445 | pcie_err = (struct cper_sec_pcie *)(gdata+1); |
| 446 | if (sev == GHES_SEV_RECOVERABLE && |
| 447 | sec_sev == GHES_SEV_RECOVERABLE && |
| 448 | pcie_err->validation_bits & CPER_PCIE_VALID_DEVICE_ID && |
| 449 | pcie_err->validation_bits & CPER_PCIE_VALID_AER_INFO) { |
| 450 | unsigned int devfn; |
| 451 | int aer_severity; |
Betty Dall | 0ba98ec | 2013-06-06 12:10:50 -0600 | [diff] [blame] | 452 | |
Huang Ying | a654e5e | 2011-12-08 11:25:41 +0800 | [diff] [blame] | 453 | devfn = PCI_DEVFN(pcie_err->device_id.device, |
| 454 | pcie_err->device_id.function); |
| 455 | aer_severity = cper_severity_to_aer(sev); |
Betty Dall | 0ba98ec | 2013-06-06 12:10:50 -0600 | [diff] [blame] | 456 | |
| 457 | /* |
| 458 | * If firmware reset the component to contain |
| 459 | * the error, we must reinitialize it before |
| 460 | * use, so treat it as a fatal AER error. |
| 461 | */ |
| 462 | if (gdata->flags & CPER_SEC_RESET) |
| 463 | aer_severity = AER_FATAL; |
| 464 | |
Huang Ying | a654e5e | 2011-12-08 11:25:41 +0800 | [diff] [blame] | 465 | aer_recover_queue(pcie_err->device_id.segment, |
| 466 | pcie_err->device_id.bus, |
Lance Ortiz | 37448ad | 2013-05-30 08:25:12 -0600 | [diff] [blame] | 467 | devfn, aer_severity, |
| 468 | (struct aer_capability_regs *) |
| 469 | pcie_err->aer_info); |
Huang Ying | a654e5e | 2011-12-08 11:25:41 +0800 | [diff] [blame] | 470 | } |
| 471 | |
| 472 | } |
| 473 | #endif |
Huang Ying | d334a49 | 2010-05-18 14:35:20 +0800 | [diff] [blame] | 474 | } |
Huang Ying | 32c361f | 2010-12-07 10:22:31 +0800 | [diff] [blame] | 475 | } |
Huang Ying | d334a49 | 2010-05-18 14:35:20 +0800 | [diff] [blame] | 476 | |
Huang Ying | 67eb2e9 | 2011-07-13 13:14:25 +0800 | [diff] [blame] | 477 | static void __ghes_print_estatus(const char *pfx, |
| 478 | const struct acpi_hest_generic *generic, |
Lv Zheng | 0a00fd5 | 2014-06-03 16:32:53 +0800 | [diff] [blame] | 479 | const struct acpi_hest_generic_status *estatus) |
Huang Ying | 32c361f | 2010-12-07 10:22:31 +0800 | [diff] [blame] | 480 | { |
Huang Ying | 5ba82ab | 2011-12-08 11:25:44 +0800 | [diff] [blame] | 481 | static atomic_t seqno; |
| 482 | unsigned int curr_seqno; |
| 483 | char pfx_seq[64]; |
| 484 | |
Huang Ying | 32c361f | 2010-12-07 10:22:31 +0800 | [diff] [blame] | 485 | if (pfx == NULL) { |
Huang Ying | 67eb2e9 | 2011-07-13 13:14:25 +0800 | [diff] [blame] | 486 | if (ghes_severity(estatus->error_severity) <= |
Huang Ying | 32c361f | 2010-12-07 10:22:31 +0800 | [diff] [blame] | 487 | GHES_SEV_CORRECTED) |
Huang Ying | 5ba82ab | 2011-12-08 11:25:44 +0800 | [diff] [blame] | 488 | pfx = KERN_WARNING; |
Huang Ying | 32c361f | 2010-12-07 10:22:31 +0800 | [diff] [blame] | 489 | else |
Huang Ying | 5ba82ab | 2011-12-08 11:25:44 +0800 | [diff] [blame] | 490 | pfx = KERN_ERR; |
Huang Ying | 32c361f | 2010-12-07 10:22:31 +0800 | [diff] [blame] | 491 | } |
Huang Ying | 5ba82ab | 2011-12-08 11:25:44 +0800 | [diff] [blame] | 492 | curr_seqno = atomic_inc_return(&seqno); |
| 493 | snprintf(pfx_seq, sizeof(pfx_seq), "%s{%u}" HW_ERR, pfx, curr_seqno); |
Huang Ying | 5588340 | 2011-07-13 13:14:15 +0800 | [diff] [blame] | 494 | printk("%s""Hardware error from APEI Generic Hardware Error Source: %d\n", |
Huang Ying | 5ba82ab | 2011-12-08 11:25:44 +0800 | [diff] [blame] | 495 | pfx_seq, generic->header.source_id); |
Chen, Gong | 88f074f | 2013-10-18 14:28:59 -0700 | [diff] [blame] | 496 | cper_estatus_print(pfx_seq, estatus); |
Huang Ying | 5588340 | 2011-07-13 13:14:15 +0800 | [diff] [blame] | 497 | } |
| 498 | |
Huang Ying | 152cef4 | 2011-07-13 13:14:26 +0800 | [diff] [blame] | 499 | static int ghes_print_estatus(const char *pfx, |
| 500 | const struct acpi_hest_generic *generic, |
Lv Zheng | 0a00fd5 | 2014-06-03 16:32:53 +0800 | [diff] [blame] | 501 | const struct acpi_hest_generic_status *estatus) |
Huang Ying | 5588340 | 2011-07-13 13:14:15 +0800 | [diff] [blame] | 502 | { |
| 503 | /* Not more than 2 messages every 5 seconds */ |
Huang Ying | 67eb2e9 | 2011-07-13 13:14:25 +0800 | [diff] [blame] | 504 | static DEFINE_RATELIMIT_STATE(ratelimit_corrected, 5*HZ, 2); |
| 505 | static DEFINE_RATELIMIT_STATE(ratelimit_uncorrected, 5*HZ, 2); |
| 506 | struct ratelimit_state *ratelimit; |
Huang Ying | 5588340 | 2011-07-13 13:14:15 +0800 | [diff] [blame] | 507 | |
Huang Ying | 67eb2e9 | 2011-07-13 13:14:25 +0800 | [diff] [blame] | 508 | if (ghes_severity(estatus->error_severity) <= GHES_SEV_CORRECTED) |
| 509 | ratelimit = &ratelimit_corrected; |
| 510 | else |
| 511 | ratelimit = &ratelimit_uncorrected; |
Huang Ying | 152cef4 | 2011-07-13 13:14:26 +0800 | [diff] [blame] | 512 | if (__ratelimit(ratelimit)) { |
Huang Ying | 67eb2e9 | 2011-07-13 13:14:25 +0800 | [diff] [blame] | 513 | __ghes_print_estatus(pfx, generic, estatus); |
Huang Ying | 152cef4 | 2011-07-13 13:14:26 +0800 | [diff] [blame] | 514 | return 1; |
| 515 | } |
| 516 | return 0; |
| 517 | } |
| 518 | |
| 519 | /* |
| 520 | * GHES error status reporting throttle, to report more kinds of |
| 521 | * errors, instead of just most frequently occurred errors. |
| 522 | */ |
Lv Zheng | 0a00fd5 | 2014-06-03 16:32:53 +0800 | [diff] [blame] | 523 | static int ghes_estatus_cached(struct acpi_hest_generic_status *estatus) |
Huang Ying | 152cef4 | 2011-07-13 13:14:26 +0800 | [diff] [blame] | 524 | { |
| 525 | u32 len; |
| 526 | int i, cached = 0; |
| 527 | unsigned long long now; |
| 528 | struct ghes_estatus_cache *cache; |
Lv Zheng | 0a00fd5 | 2014-06-03 16:32:53 +0800 | [diff] [blame] | 529 | struct acpi_hest_generic_status *cache_estatus; |
Huang Ying | 152cef4 | 2011-07-13 13:14:26 +0800 | [diff] [blame] | 530 | |
Chen, Gong | 88f074f | 2013-10-18 14:28:59 -0700 | [diff] [blame] | 531 | len = cper_estatus_len(estatus); |
Huang Ying | 152cef4 | 2011-07-13 13:14:26 +0800 | [diff] [blame] | 532 | rcu_read_lock(); |
| 533 | for (i = 0; i < GHES_ESTATUS_CACHES_SIZE; i++) { |
| 534 | cache = rcu_dereference(ghes_estatus_caches[i]); |
| 535 | if (cache == NULL) |
| 536 | continue; |
| 537 | if (len != cache->estatus_len) |
| 538 | continue; |
| 539 | cache_estatus = GHES_ESTATUS_FROM_CACHE(cache); |
| 540 | if (memcmp(estatus, cache_estatus, len)) |
| 541 | continue; |
| 542 | atomic_inc(&cache->count); |
| 543 | now = sched_clock(); |
| 544 | if (now - cache->time_in < GHES_ESTATUS_IN_CACHE_MAX_NSEC) |
| 545 | cached = 1; |
| 546 | break; |
| 547 | } |
| 548 | rcu_read_unlock(); |
| 549 | return cached; |
| 550 | } |
| 551 | |
| 552 | static struct ghes_estatus_cache *ghes_estatus_cache_alloc( |
| 553 | struct acpi_hest_generic *generic, |
Lv Zheng | 0a00fd5 | 2014-06-03 16:32:53 +0800 | [diff] [blame] | 554 | struct acpi_hest_generic_status *estatus) |
Huang Ying | 152cef4 | 2011-07-13 13:14:26 +0800 | [diff] [blame] | 555 | { |
| 556 | int alloced; |
| 557 | u32 len, cache_len; |
| 558 | struct ghes_estatus_cache *cache; |
Lv Zheng | 0a00fd5 | 2014-06-03 16:32:53 +0800 | [diff] [blame] | 559 | struct acpi_hest_generic_status *cache_estatus; |
Huang Ying | 152cef4 | 2011-07-13 13:14:26 +0800 | [diff] [blame] | 560 | |
| 561 | alloced = atomic_add_return(1, &ghes_estatus_cache_alloced); |
| 562 | if (alloced > GHES_ESTATUS_CACHE_ALLOCED_MAX) { |
| 563 | atomic_dec(&ghes_estatus_cache_alloced); |
| 564 | return NULL; |
| 565 | } |
Chen, Gong | 88f074f | 2013-10-18 14:28:59 -0700 | [diff] [blame] | 566 | len = cper_estatus_len(estatus); |
Huang Ying | 152cef4 | 2011-07-13 13:14:26 +0800 | [diff] [blame] | 567 | cache_len = GHES_ESTATUS_CACHE_LEN(len); |
| 568 | cache = (void *)gen_pool_alloc(ghes_estatus_pool, cache_len); |
| 569 | if (!cache) { |
| 570 | atomic_dec(&ghes_estatus_cache_alloced); |
| 571 | return NULL; |
| 572 | } |
| 573 | cache_estatus = GHES_ESTATUS_FROM_CACHE(cache); |
| 574 | memcpy(cache_estatus, estatus, len); |
| 575 | cache->estatus_len = len; |
| 576 | atomic_set(&cache->count, 0); |
| 577 | cache->generic = generic; |
| 578 | cache->time_in = sched_clock(); |
| 579 | return cache; |
| 580 | } |
| 581 | |
| 582 | static void ghes_estatus_cache_free(struct ghes_estatus_cache *cache) |
| 583 | { |
| 584 | u32 len; |
| 585 | |
Chen, Gong | 88f074f | 2013-10-18 14:28:59 -0700 | [diff] [blame] | 586 | len = cper_estatus_len(GHES_ESTATUS_FROM_CACHE(cache)); |
Huang Ying | 152cef4 | 2011-07-13 13:14:26 +0800 | [diff] [blame] | 587 | len = GHES_ESTATUS_CACHE_LEN(len); |
| 588 | gen_pool_free(ghes_estatus_pool, (unsigned long)cache, len); |
| 589 | atomic_dec(&ghes_estatus_cache_alloced); |
| 590 | } |
| 591 | |
| 592 | static void ghes_estatus_cache_rcu_free(struct rcu_head *head) |
| 593 | { |
| 594 | struct ghes_estatus_cache *cache; |
| 595 | |
| 596 | cache = container_of(head, struct ghes_estatus_cache, rcu); |
| 597 | ghes_estatus_cache_free(cache); |
| 598 | } |
| 599 | |
| 600 | static void ghes_estatus_cache_add( |
| 601 | struct acpi_hest_generic *generic, |
Lv Zheng | 0a00fd5 | 2014-06-03 16:32:53 +0800 | [diff] [blame] | 602 | struct acpi_hest_generic_status *estatus) |
Huang Ying | 152cef4 | 2011-07-13 13:14:26 +0800 | [diff] [blame] | 603 | { |
| 604 | int i, slot = -1, count; |
| 605 | unsigned long long now, duration, period, max_period = 0; |
| 606 | struct ghes_estatus_cache *cache, *slot_cache = NULL, *new_cache; |
| 607 | |
| 608 | new_cache = ghes_estatus_cache_alloc(generic, estatus); |
| 609 | if (new_cache == NULL) |
| 610 | return; |
| 611 | rcu_read_lock(); |
| 612 | now = sched_clock(); |
| 613 | for (i = 0; i < GHES_ESTATUS_CACHES_SIZE; i++) { |
| 614 | cache = rcu_dereference(ghes_estatus_caches[i]); |
| 615 | if (cache == NULL) { |
| 616 | slot = i; |
| 617 | slot_cache = NULL; |
| 618 | break; |
| 619 | } |
| 620 | duration = now - cache->time_in; |
| 621 | if (duration >= GHES_ESTATUS_IN_CACHE_MAX_NSEC) { |
| 622 | slot = i; |
| 623 | slot_cache = cache; |
| 624 | break; |
| 625 | } |
| 626 | count = atomic_read(&cache->count); |
Len Brown | 70cb6e1 | 2011-08-02 18:00:21 -0400 | [diff] [blame] | 627 | period = duration; |
| 628 | do_div(period, (count + 1)); |
Huang Ying | 152cef4 | 2011-07-13 13:14:26 +0800 | [diff] [blame] | 629 | if (period > max_period) { |
| 630 | max_period = period; |
| 631 | slot = i; |
| 632 | slot_cache = cache; |
| 633 | } |
| 634 | } |
| 635 | /* new_cache must be put into array after its contents are written */ |
| 636 | smp_wmb(); |
| 637 | if (slot != -1 && cmpxchg(ghes_estatus_caches + slot, |
| 638 | slot_cache, new_cache) == slot_cache) { |
| 639 | if (slot_cache) |
| 640 | call_rcu(&slot_cache->rcu, ghes_estatus_cache_rcu_free); |
| 641 | } else |
| 642 | ghes_estatus_cache_free(new_cache); |
| 643 | rcu_read_unlock(); |
Huang Ying | d334a49 | 2010-05-18 14:35:20 +0800 | [diff] [blame] | 644 | } |
| 645 | |
| 646 | static int ghes_proc(struct ghes *ghes) |
| 647 | { |
| 648 | int rc; |
| 649 | |
| 650 | rc = ghes_read_estatus(ghes, 0); |
| 651 | if (rc) |
| 652 | goto out; |
Huang Ying | 152cef4 | 2011-07-13 13:14:26 +0800 | [diff] [blame] | 653 | if (!ghes_estatus_cached(ghes->estatus)) { |
| 654 | if (ghes_print_estatus(NULL, ghes->generic, ghes->estatus)) |
| 655 | ghes_estatus_cache_add(ghes->generic, ghes->estatus); |
| 656 | } |
Mauro Carvalho Chehab | 2148054 | 2013-02-15 06:10:39 -0300 | [diff] [blame] | 657 | ghes_do_proc(ghes, ghes->estatus); |
Huang Ying | d334a49 | 2010-05-18 14:35:20 +0800 | [diff] [blame] | 658 | out: |
| 659 | ghes_clear_estatus(ghes); |
| 660 | return 0; |
| 661 | } |
| 662 | |
Huang Ying | 81e88fd | 2011-01-12 14:44:55 +0800 | [diff] [blame] | 663 | static void ghes_add_timer(struct ghes *ghes) |
| 664 | { |
| 665 | struct acpi_hest_generic *g = ghes->generic; |
| 666 | unsigned long expire; |
| 667 | |
| 668 | if (!g->notify.poll_interval) { |
| 669 | pr_warning(FW_WARN GHES_PFX "Poll interval is 0 for generic hardware error source: %d, disabled.\n", |
| 670 | g->header.source_id); |
| 671 | return; |
| 672 | } |
| 673 | expire = jiffies + msecs_to_jiffies(g->notify.poll_interval); |
| 674 | ghes->timer.expires = round_jiffies_relative(expire); |
| 675 | add_timer(&ghes->timer); |
| 676 | } |
| 677 | |
| 678 | static void ghes_poll_func(unsigned long data) |
| 679 | { |
| 680 | struct ghes *ghes = (void *)data; |
| 681 | |
| 682 | ghes_proc(ghes); |
| 683 | if (!(ghes->flags & GHES_EXITING)) |
| 684 | ghes_add_timer(ghes); |
| 685 | } |
| 686 | |
| 687 | static irqreturn_t ghes_irq_func(int irq, void *data) |
| 688 | { |
| 689 | struct ghes *ghes = data; |
| 690 | int rc; |
| 691 | |
| 692 | rc = ghes_proc(ghes); |
| 693 | if (rc) |
| 694 | return IRQ_NONE; |
| 695 | |
| 696 | return IRQ_HANDLED; |
| 697 | } |
| 698 | |
Huang Ying | d334a49 | 2010-05-18 14:35:20 +0800 | [diff] [blame] | 699 | static int ghes_notify_sci(struct notifier_block *this, |
| 700 | unsigned long event, void *data) |
| 701 | { |
| 702 | struct ghes *ghes; |
| 703 | int ret = NOTIFY_DONE; |
| 704 | |
| 705 | rcu_read_lock(); |
| 706 | list_for_each_entry_rcu(ghes, &ghes_sci, list) { |
| 707 | if (!ghes_proc(ghes)) |
| 708 | ret = NOTIFY_OK; |
| 709 | } |
| 710 | rcu_read_unlock(); |
| 711 | |
| 712 | return ret; |
| 713 | } |
| 714 | |
Tomasz Nowicki | 44a69f6 | 2014-07-22 11:20:12 +0200 | [diff] [blame] | 715 | static struct notifier_block ghes_notifier_sci = { |
| 716 | .notifier_call = ghes_notify_sci, |
| 717 | }; |
| 718 | |
| 719 | #ifdef CONFIG_HAVE_ACPI_APEI_NMI |
| 720 | /* |
| 721 | * printk is not safe in NMI context. So in NMI handler, we allocate |
| 722 | * required memory from lock-less memory allocator |
| 723 | * (ghes_estatus_pool), save estatus into it, put them into lock-less |
| 724 | * list (ghes_estatus_llist), then delay printk into IRQ context via |
| 725 | * irq_work (ghes_proc_irq_work). ghes_estatus_size_request record |
| 726 | * required pool size by all NMI error source. |
| 727 | */ |
| 728 | static struct llist_head ghes_estatus_llist; |
| 729 | static struct irq_work ghes_proc_irq_work; |
| 730 | |
| 731 | /* |
| 732 | * NMI may be triggered on any CPU, so ghes_nmi_lock is used for |
| 733 | * mutual exclusion. |
| 734 | */ |
| 735 | static DEFINE_RAW_SPINLOCK(ghes_nmi_lock); |
| 736 | |
| 737 | static LIST_HEAD(ghes_nmi); |
| 738 | |
| 739 | static int ghes_panic_timeout __read_mostly = 30; |
| 740 | |
Huang Ying | 46d12f0 | 2011-12-08 11:25:45 +0800 | [diff] [blame] | 741 | static void ghes_proc_in_irq(struct irq_work *irq_work) |
| 742 | { |
| 743 | struct llist_node *llnode, *next; |
| 744 | struct ghes_estatus_node *estatus_node; |
| 745 | struct acpi_hest_generic *generic; |
Lv Zheng | 0a00fd5 | 2014-06-03 16:32:53 +0800 | [diff] [blame] | 746 | struct acpi_hest_generic_status *estatus; |
Huang Ying | 46d12f0 | 2011-12-08 11:25:45 +0800 | [diff] [blame] | 747 | u32 len, node_len; |
| 748 | |
| 749 | llnode = llist_del_all(&ghes_estatus_llist); |
| 750 | /* |
| 751 | * Because the time order of estatus in list is reversed, |
| 752 | * revert it back to proper order. |
| 753 | */ |
Chen, Gong | 8d21d4c | 2014-07-28 02:50:59 -0400 | [diff] [blame] | 754 | llnode = llist_reverse_order(llnode); |
Huang Ying | 67eb2e9 | 2011-07-13 13:14:25 +0800 | [diff] [blame] | 755 | while (llnode) { |
| 756 | next = llnode->next; |
| 757 | estatus_node = llist_entry(llnode, struct ghes_estatus_node, |
| 758 | llnode); |
| 759 | estatus = GHES_ESTATUS_FROM_NODE(estatus_node); |
Chen, Gong | 88f074f | 2013-10-18 14:28:59 -0700 | [diff] [blame] | 760 | len = cper_estatus_len(estatus); |
Huang Ying | 67eb2e9 | 2011-07-13 13:14:25 +0800 | [diff] [blame] | 761 | node_len = GHES_ESTATUS_NODE_LEN(len); |
Mauro Carvalho Chehab | 2148054 | 2013-02-15 06:10:39 -0300 | [diff] [blame] | 762 | ghes_do_proc(estatus_node->ghes, estatus); |
Huang Ying | 152cef4 | 2011-07-13 13:14:26 +0800 | [diff] [blame] | 763 | if (!ghes_estatus_cached(estatus)) { |
| 764 | generic = estatus_node->generic; |
| 765 | if (ghes_print_estatus(NULL, generic, estatus)) |
| 766 | ghes_estatus_cache_add(generic, estatus); |
| 767 | } |
Huang Ying | 67eb2e9 | 2011-07-13 13:14:25 +0800 | [diff] [blame] | 768 | gen_pool_free(ghes_estatus_pool, (unsigned long)estatus_node, |
| 769 | node_len); |
| 770 | llnode = next; |
| 771 | } |
| 772 | } |
| 773 | |
Huang Ying | 46d12f0 | 2011-12-08 11:25:45 +0800 | [diff] [blame] | 774 | static void ghes_print_queued_estatus(void) |
| 775 | { |
| 776 | struct llist_node *llnode; |
| 777 | struct ghes_estatus_node *estatus_node; |
| 778 | struct acpi_hest_generic *generic; |
Lv Zheng | 0a00fd5 | 2014-06-03 16:32:53 +0800 | [diff] [blame] | 779 | struct acpi_hest_generic_status *estatus; |
Huang Ying | 46d12f0 | 2011-12-08 11:25:45 +0800 | [diff] [blame] | 780 | u32 len, node_len; |
| 781 | |
| 782 | llnode = llist_del_all(&ghes_estatus_llist); |
| 783 | /* |
| 784 | * Because the time order of estatus in list is reversed, |
| 785 | * revert it back to proper order. |
| 786 | */ |
Chen, Gong | 8d21d4c | 2014-07-28 02:50:59 -0400 | [diff] [blame] | 787 | llnode = llist_reverse_order(llnode); |
Huang Ying | 46d12f0 | 2011-12-08 11:25:45 +0800 | [diff] [blame] | 788 | while (llnode) { |
| 789 | estatus_node = llist_entry(llnode, struct ghes_estatus_node, |
| 790 | llnode); |
| 791 | estatus = GHES_ESTATUS_FROM_NODE(estatus_node); |
Chen, Gong | 88f074f | 2013-10-18 14:28:59 -0700 | [diff] [blame] | 792 | len = cper_estatus_len(estatus); |
Huang Ying | 46d12f0 | 2011-12-08 11:25:45 +0800 | [diff] [blame] | 793 | node_len = GHES_ESTATUS_NODE_LEN(len); |
| 794 | generic = estatus_node->generic; |
| 795 | ghes_print_estatus(NULL, generic, estatus); |
| 796 | llnode = llnode->next; |
| 797 | } |
| 798 | } |
| 799 | |
Don Zickus | 9c48f1c | 2011-09-30 15:06:21 -0400 | [diff] [blame] | 800 | static int ghes_notify_nmi(unsigned int cmd, struct pt_regs *regs) |
Huang Ying | 81e88fd | 2011-01-12 14:44:55 +0800 | [diff] [blame] | 801 | { |
| 802 | struct ghes *ghes, *ghes_global = NULL; |
| 803 | int sev, sev_global = -1; |
Don Zickus | 9c48f1c | 2011-09-30 15:06:21 -0400 | [diff] [blame] | 804 | int ret = NMI_DONE; |
Huang Ying | 81e88fd | 2011-01-12 14:44:55 +0800 | [diff] [blame] | 805 | |
| 806 | raw_spin_lock(&ghes_nmi_lock); |
| 807 | list_for_each_entry_rcu(ghes, &ghes_nmi, list) { |
| 808 | if (ghes_read_estatus(ghes, 1)) { |
| 809 | ghes_clear_estatus(ghes); |
| 810 | continue; |
| 811 | } |
| 812 | sev = ghes_severity(ghes->estatus->error_severity); |
| 813 | if (sev > sev_global) { |
| 814 | sev_global = sev; |
| 815 | ghes_global = ghes; |
| 816 | } |
Don Zickus | 9c48f1c | 2011-09-30 15:06:21 -0400 | [diff] [blame] | 817 | ret = NMI_HANDLED; |
Huang Ying | 81e88fd | 2011-01-12 14:44:55 +0800 | [diff] [blame] | 818 | } |
| 819 | |
Don Zickus | 9c48f1c | 2011-09-30 15:06:21 -0400 | [diff] [blame] | 820 | if (ret == NMI_DONE) |
Huang Ying | 81e88fd | 2011-01-12 14:44:55 +0800 | [diff] [blame] | 821 | goto out; |
| 822 | |
| 823 | if (sev_global >= GHES_SEV_PANIC) { |
| 824 | oops_begin(); |
Huang Ying | 46d12f0 | 2011-12-08 11:25:45 +0800 | [diff] [blame] | 825 | ghes_print_queued_estatus(); |
Huang Ying | 5ba82ab | 2011-12-08 11:25:44 +0800 | [diff] [blame] | 826 | __ghes_print_estatus(KERN_EMERG, ghes_global->generic, |
Huang Ying | 67eb2e9 | 2011-07-13 13:14:25 +0800 | [diff] [blame] | 827 | ghes_global->estatus); |
Huang Ying | 81e88fd | 2011-01-12 14:44:55 +0800 | [diff] [blame] | 828 | /* reboot to log the error! */ |
| 829 | if (panic_timeout == 0) |
| 830 | panic_timeout = ghes_panic_timeout; |
| 831 | panic("Fatal hardware error!"); |
| 832 | } |
| 833 | |
| 834 | list_for_each_entry_rcu(ghes, &ghes_nmi, list) { |
Huang Ying | 67eb2e9 | 2011-07-13 13:14:25 +0800 | [diff] [blame] | 835 | #ifdef CONFIG_ARCH_HAVE_NMI_SAFE_CMPXCHG |
| 836 | u32 len, node_len; |
| 837 | struct ghes_estatus_node *estatus_node; |
Lv Zheng | 0a00fd5 | 2014-06-03 16:32:53 +0800 | [diff] [blame] | 838 | struct acpi_hest_generic_status *estatus; |
Huang Ying | 67eb2e9 | 2011-07-13 13:14:25 +0800 | [diff] [blame] | 839 | #endif |
Huang Ying | 81e88fd | 2011-01-12 14:44:55 +0800 | [diff] [blame] | 840 | if (!(ghes->flags & GHES_TO_CLEAR)) |
| 841 | continue; |
Huang Ying | 67eb2e9 | 2011-07-13 13:14:25 +0800 | [diff] [blame] | 842 | #ifdef CONFIG_ARCH_HAVE_NMI_SAFE_CMPXCHG |
Huang Ying | 152cef4 | 2011-07-13 13:14:26 +0800 | [diff] [blame] | 843 | if (ghes_estatus_cached(ghes->estatus)) |
| 844 | goto next; |
Huang Ying | 67eb2e9 | 2011-07-13 13:14:25 +0800 | [diff] [blame] | 845 | /* Save estatus for further processing in IRQ context */ |
Chen, Gong | 88f074f | 2013-10-18 14:28:59 -0700 | [diff] [blame] | 846 | len = cper_estatus_len(ghes->estatus); |
Huang Ying | 67eb2e9 | 2011-07-13 13:14:25 +0800 | [diff] [blame] | 847 | node_len = GHES_ESTATUS_NODE_LEN(len); |
| 848 | estatus_node = (void *)gen_pool_alloc(ghes_estatus_pool, |
| 849 | node_len); |
| 850 | if (estatus_node) { |
Mauro Carvalho Chehab | 2148054 | 2013-02-15 06:10:39 -0300 | [diff] [blame] | 851 | estatus_node->ghes = ghes; |
Huang Ying | 67eb2e9 | 2011-07-13 13:14:25 +0800 | [diff] [blame] | 852 | estatus_node->generic = ghes->generic; |
| 853 | estatus = GHES_ESTATUS_FROM_NODE(estatus_node); |
| 854 | memcpy(estatus, ghes->estatus, len); |
| 855 | llist_add(&estatus_node->llnode, &ghes_estatus_llist); |
| 856 | } |
Huang Ying | 152cef4 | 2011-07-13 13:14:26 +0800 | [diff] [blame] | 857 | next: |
Huang Ying | 67eb2e9 | 2011-07-13 13:14:25 +0800 | [diff] [blame] | 858 | #endif |
Huang Ying | 81e88fd | 2011-01-12 14:44:55 +0800 | [diff] [blame] | 859 | ghes_clear_estatus(ghes); |
| 860 | } |
Huang Ying | 67eb2e9 | 2011-07-13 13:14:25 +0800 | [diff] [blame] | 861 | #ifdef CONFIG_ARCH_HAVE_NMI_SAFE_CMPXCHG |
| 862 | irq_work_queue(&ghes_proc_irq_work); |
| 863 | #endif |
Huang Ying | 81e88fd | 2011-01-12 14:44:55 +0800 | [diff] [blame] | 864 | |
| 865 | out: |
| 866 | raw_spin_unlock(&ghes_nmi_lock); |
| 867 | return ret; |
| 868 | } |
| 869 | |
Huang Ying | 67eb2e9 | 2011-07-13 13:14:25 +0800 | [diff] [blame] | 870 | static unsigned long ghes_esource_prealloc_size( |
| 871 | const struct acpi_hest_generic *generic) |
| 872 | { |
| 873 | unsigned long block_length, prealloc_records, prealloc_size; |
| 874 | |
| 875 | block_length = min_t(unsigned long, generic->error_block_length, |
| 876 | GHES_ESTATUS_MAX_SIZE); |
| 877 | prealloc_records = max_t(unsigned long, |
| 878 | generic->records_to_preallocate, 1); |
| 879 | prealloc_size = min_t(unsigned long, block_length * prealloc_records, |
| 880 | GHES_ESOURCE_PREALLOC_MAX_SIZE); |
| 881 | |
| 882 | return prealloc_size; |
| 883 | } |
| 884 | |
Tomasz Nowicki | 44a69f6 | 2014-07-22 11:20:12 +0200 | [diff] [blame] | 885 | static void ghes_estatus_pool_shrink(unsigned long len) |
| 886 | { |
| 887 | ghes_estatus_pool_size_request -= PAGE_ALIGN(len); |
| 888 | } |
| 889 | |
| 890 | static void ghes_nmi_add(struct ghes *ghes) |
| 891 | { |
| 892 | unsigned long len; |
| 893 | |
| 894 | len = ghes_esource_prealloc_size(ghes->generic); |
| 895 | ghes_estatus_pool_expand(len); |
| 896 | mutex_lock(&ghes_list_mutex); |
| 897 | if (list_empty(&ghes_nmi)) |
| 898 | register_nmi_handler(NMI_LOCAL, ghes_notify_nmi, 0, "ghes"); |
| 899 | list_add_rcu(&ghes->list, &ghes_nmi); |
| 900 | mutex_unlock(&ghes_list_mutex); |
| 901 | } |
| 902 | |
| 903 | static void ghes_nmi_remove(struct ghes *ghes) |
| 904 | { |
| 905 | unsigned long len; |
| 906 | |
| 907 | mutex_lock(&ghes_list_mutex); |
| 908 | list_del_rcu(&ghes->list); |
| 909 | if (list_empty(&ghes_nmi)) |
| 910 | unregister_nmi_handler(NMI_LOCAL, "ghes"); |
| 911 | mutex_unlock(&ghes_list_mutex); |
| 912 | /* |
| 913 | * To synchronize with NMI handler, ghes can only be |
| 914 | * freed after NMI handler finishes. |
| 915 | */ |
| 916 | synchronize_rcu(); |
| 917 | len = ghes_esource_prealloc_size(ghes->generic); |
| 918 | ghes_estatus_pool_shrink(len); |
| 919 | } |
| 920 | |
| 921 | static void ghes_nmi_init_cxt(void) |
| 922 | { |
| 923 | init_irq_work(&ghes_proc_irq_work, ghes_proc_in_irq); |
| 924 | } |
| 925 | #else /* CONFIG_HAVE_ACPI_APEI_NMI */ |
| 926 | static inline void ghes_nmi_add(struct ghes *ghes) |
| 927 | { |
| 928 | pr_err(GHES_PFX "ID: %d, trying to add NMI notification which is not supported!\n", |
| 929 | ghes->generic->header.source_id); |
| 930 | BUG(); |
| 931 | } |
| 932 | |
| 933 | static inline void ghes_nmi_remove(struct ghes *ghes) |
| 934 | { |
| 935 | pr_err(GHES_PFX "ID: %d, trying to remove NMI notification which is not supported!\n", |
| 936 | ghes->generic->header.source_id); |
| 937 | BUG(); |
| 938 | } |
| 939 | |
| 940 | static inline void ghes_nmi_init_cxt(void) |
| 941 | { |
| 942 | } |
| 943 | #endif /* CONFIG_HAVE_ACPI_APEI_NMI */ |
| 944 | |
Bill Pemberton | da095fd | 2012-11-19 13:22:46 -0500 | [diff] [blame] | 945 | static int ghes_probe(struct platform_device *ghes_dev) |
Huang Ying | d334a49 | 2010-05-18 14:35:20 +0800 | [diff] [blame] | 946 | { |
| 947 | struct acpi_hest_generic *generic; |
| 948 | struct ghes *ghes = NULL; |
Tomasz Nowicki | 44a69f6 | 2014-07-22 11:20:12 +0200 | [diff] [blame] | 949 | |
Huang Ying | 7ad6e94 | 2010-08-02 15:48:24 +0800 | [diff] [blame] | 950 | int rc = -EINVAL; |
Huang Ying | d334a49 | 2010-05-18 14:35:20 +0800 | [diff] [blame] | 951 | |
Jin Dongming | 1dd6b20 | 2010-09-29 19:53:53 +0800 | [diff] [blame] | 952 | generic = *(struct acpi_hest_generic **)ghes_dev->dev.platform_data; |
Huang Ying | d334a49 | 2010-05-18 14:35:20 +0800 | [diff] [blame] | 953 | if (!generic->enabled) |
Huang Ying | 7ad6e94 | 2010-08-02 15:48:24 +0800 | [diff] [blame] | 954 | return -ENODEV; |
Huang Ying | d334a49 | 2010-05-18 14:35:20 +0800 | [diff] [blame] | 955 | |
Huang Ying | 81e88fd | 2011-01-12 14:44:55 +0800 | [diff] [blame] | 956 | switch (generic->notify.type) { |
| 957 | case ACPI_HEST_NOTIFY_POLLED: |
| 958 | case ACPI_HEST_NOTIFY_EXTERNAL: |
| 959 | case ACPI_HEST_NOTIFY_SCI: |
Tomasz Nowicki | 44a69f6 | 2014-07-22 11:20:12 +0200 | [diff] [blame] | 960 | break; |
Huang Ying | 81e88fd | 2011-01-12 14:44:55 +0800 | [diff] [blame] | 961 | case ACPI_HEST_NOTIFY_NMI: |
Tomasz Nowicki | 44a69f6 | 2014-07-22 11:20:12 +0200 | [diff] [blame] | 962 | if (!IS_ENABLED(CONFIG_HAVE_ACPI_APEI_NMI)) { |
| 963 | pr_warn(GHES_PFX "Generic hardware error source: %d notified via NMI interrupt is not supported!\n", |
| 964 | generic->header.source_id); |
| 965 | goto err; |
| 966 | } |
Huang Ying | 81e88fd | 2011-01-12 14:44:55 +0800 | [diff] [blame] | 967 | break; |
| 968 | case ACPI_HEST_NOTIFY_LOCAL: |
| 969 | pr_warning(GHES_PFX "Generic hardware error source: %d notified via local interrupt is not supported!\n", |
Huang Ying | d334a49 | 2010-05-18 14:35:20 +0800 | [diff] [blame] | 970 | generic->header.source_id); |
| 971 | goto err; |
Huang Ying | 81e88fd | 2011-01-12 14:44:55 +0800 | [diff] [blame] | 972 | default: |
| 973 | pr_warning(FW_WARN GHES_PFX "Unknown notification type: %u for generic hardware error source: %d\n", |
| 974 | generic->notify.type, generic->header.source_id); |
| 975 | goto err; |
Huang Ying | d334a49 | 2010-05-18 14:35:20 +0800 | [diff] [blame] | 976 | } |
Huang Ying | 81e88fd | 2011-01-12 14:44:55 +0800 | [diff] [blame] | 977 | |
| 978 | rc = -EIO; |
| 979 | if (generic->error_block_length < |
Lv Zheng | 0a00fd5 | 2014-06-03 16:32:53 +0800 | [diff] [blame] | 980 | sizeof(struct acpi_hest_generic_status)) { |
Huang Ying | 81e88fd | 2011-01-12 14:44:55 +0800 | [diff] [blame] | 981 | pr_warning(FW_BUG GHES_PFX "Invalid error block length: %u for generic hardware error source: %d\n", |
| 982 | generic->error_block_length, |
Huang Ying | d334a49 | 2010-05-18 14:35:20 +0800 | [diff] [blame] | 983 | generic->header.source_id); |
| 984 | goto err; |
| 985 | } |
| 986 | ghes = ghes_new(generic); |
| 987 | if (IS_ERR(ghes)) { |
| 988 | rc = PTR_ERR(ghes); |
| 989 | ghes = NULL; |
| 990 | goto err; |
| 991 | } |
Mauro Carvalho Chehab | 2148054 | 2013-02-15 06:10:39 -0300 | [diff] [blame] | 992 | |
| 993 | rc = ghes_edac_register(ghes, &ghes_dev->dev); |
| 994 | if (rc < 0) |
| 995 | goto err; |
| 996 | |
Huang Ying | 81e88fd | 2011-01-12 14:44:55 +0800 | [diff] [blame] | 997 | switch (generic->notify.type) { |
| 998 | case ACPI_HEST_NOTIFY_POLLED: |
| 999 | ghes->timer.function = ghes_poll_func; |
| 1000 | ghes->timer.data = (unsigned long)ghes; |
| 1001 | init_timer_deferrable(&ghes->timer); |
| 1002 | ghes_add_timer(ghes); |
| 1003 | break; |
| 1004 | case ACPI_HEST_NOTIFY_EXTERNAL: |
| 1005 | /* External interrupt vector is GSI */ |
Wei Yongjun | a98d4f6 | 2013-06-03 02:08:39 +0000 | [diff] [blame] | 1006 | rc = acpi_gsi_to_irq(generic->notify.vector, &ghes->irq); |
| 1007 | if (rc) { |
Huang Ying | 81e88fd | 2011-01-12 14:44:55 +0800 | [diff] [blame] | 1008 | pr_err(GHES_PFX "Failed to map GSI to IRQ for generic hardware error source: %d\n", |
| 1009 | generic->header.source_id); |
Mauro Carvalho Chehab | 2148054 | 2013-02-15 06:10:39 -0300 | [diff] [blame] | 1010 | goto err_edac_unreg; |
Huang Ying | 81e88fd | 2011-01-12 14:44:55 +0800 | [diff] [blame] | 1011 | } |
Wei Yongjun | a98d4f6 | 2013-06-03 02:08:39 +0000 | [diff] [blame] | 1012 | rc = request_irq(ghes->irq, ghes_irq_func, 0, "GHES IRQ", ghes); |
| 1013 | if (rc) { |
Huang Ying | 81e88fd | 2011-01-12 14:44:55 +0800 | [diff] [blame] | 1014 | pr_err(GHES_PFX "Failed to register IRQ for generic hardware error source: %d\n", |
| 1015 | generic->header.source_id); |
Mauro Carvalho Chehab | 2148054 | 2013-02-15 06:10:39 -0300 | [diff] [blame] | 1016 | goto err_edac_unreg; |
Huang Ying | 81e88fd | 2011-01-12 14:44:55 +0800 | [diff] [blame] | 1017 | } |
| 1018 | break; |
| 1019 | case ACPI_HEST_NOTIFY_SCI: |
Huang Ying | 7ad6e94 | 2010-08-02 15:48:24 +0800 | [diff] [blame] | 1020 | mutex_lock(&ghes_list_mutex); |
Huang Ying | d334a49 | 2010-05-18 14:35:20 +0800 | [diff] [blame] | 1021 | if (list_empty(&ghes_sci)) |
| 1022 | register_acpi_hed_notifier(&ghes_notifier_sci); |
| 1023 | list_add_rcu(&ghes->list, &ghes_sci); |
Huang Ying | 7ad6e94 | 2010-08-02 15:48:24 +0800 | [diff] [blame] | 1024 | mutex_unlock(&ghes_list_mutex); |
Huang Ying | 81e88fd | 2011-01-12 14:44:55 +0800 | [diff] [blame] | 1025 | break; |
| 1026 | case ACPI_HEST_NOTIFY_NMI: |
Tomasz Nowicki | 44a69f6 | 2014-07-22 11:20:12 +0200 | [diff] [blame] | 1027 | ghes_nmi_add(ghes); |
Huang Ying | 81e88fd | 2011-01-12 14:44:55 +0800 | [diff] [blame] | 1028 | break; |
| 1029 | default: |
| 1030 | BUG(); |
Huang Ying | d334a49 | 2010-05-18 14:35:20 +0800 | [diff] [blame] | 1031 | } |
Huang Ying | 7ad6e94 | 2010-08-02 15:48:24 +0800 | [diff] [blame] | 1032 | platform_set_drvdata(ghes_dev, ghes); |
Huang Ying | d334a49 | 2010-05-18 14:35:20 +0800 | [diff] [blame] | 1033 | |
| 1034 | return 0; |
Mauro Carvalho Chehab | 2148054 | 2013-02-15 06:10:39 -0300 | [diff] [blame] | 1035 | err_edac_unreg: |
| 1036 | ghes_edac_unregister(ghes); |
Huang Ying | d334a49 | 2010-05-18 14:35:20 +0800 | [diff] [blame] | 1037 | err: |
Huang Ying | 7ad6e94 | 2010-08-02 15:48:24 +0800 | [diff] [blame] | 1038 | if (ghes) { |
Huang Ying | d334a49 | 2010-05-18 14:35:20 +0800 | [diff] [blame] | 1039 | ghes_fini(ghes); |
| 1040 | kfree(ghes); |
| 1041 | } |
Huang Ying | 7ad6e94 | 2010-08-02 15:48:24 +0800 | [diff] [blame] | 1042 | return rc; |
Huang Ying | d334a49 | 2010-05-18 14:35:20 +0800 | [diff] [blame] | 1043 | } |
| 1044 | |
Bill Pemberton | b59bc2f | 2012-11-21 23:13:09 +0100 | [diff] [blame] | 1045 | static int ghes_remove(struct platform_device *ghes_dev) |
Huang Ying | 7ad6e94 | 2010-08-02 15:48:24 +0800 | [diff] [blame] | 1046 | { |
| 1047 | struct ghes *ghes; |
| 1048 | struct acpi_hest_generic *generic; |
| 1049 | |
| 1050 | ghes = platform_get_drvdata(ghes_dev); |
| 1051 | generic = ghes->generic; |
| 1052 | |
Huang Ying | 81e88fd | 2011-01-12 14:44:55 +0800 | [diff] [blame] | 1053 | ghes->flags |= GHES_EXITING; |
Huang Ying | 7ad6e94 | 2010-08-02 15:48:24 +0800 | [diff] [blame] | 1054 | switch (generic->notify.type) { |
Huang Ying | 81e88fd | 2011-01-12 14:44:55 +0800 | [diff] [blame] | 1055 | case ACPI_HEST_NOTIFY_POLLED: |
| 1056 | del_timer_sync(&ghes->timer); |
| 1057 | break; |
| 1058 | case ACPI_HEST_NOTIFY_EXTERNAL: |
| 1059 | free_irq(ghes->irq, ghes); |
| 1060 | break; |
Huang Ying | 7ad6e94 | 2010-08-02 15:48:24 +0800 | [diff] [blame] | 1061 | case ACPI_HEST_NOTIFY_SCI: |
| 1062 | mutex_lock(&ghes_list_mutex); |
| 1063 | list_del_rcu(&ghes->list); |
| 1064 | if (list_empty(&ghes_sci)) |
| 1065 | unregister_acpi_hed_notifier(&ghes_notifier_sci); |
| 1066 | mutex_unlock(&ghes_list_mutex); |
| 1067 | break; |
Huang Ying | 81e88fd | 2011-01-12 14:44:55 +0800 | [diff] [blame] | 1068 | case ACPI_HEST_NOTIFY_NMI: |
Tomasz Nowicki | 44a69f6 | 2014-07-22 11:20:12 +0200 | [diff] [blame] | 1069 | ghes_nmi_remove(ghes); |
Huang Ying | 81e88fd | 2011-01-12 14:44:55 +0800 | [diff] [blame] | 1070 | break; |
Huang Ying | 7ad6e94 | 2010-08-02 15:48:24 +0800 | [diff] [blame] | 1071 | default: |
| 1072 | BUG(); |
| 1073 | break; |
| 1074 | } |
| 1075 | |
Huang Ying | 7ad6e94 | 2010-08-02 15:48:24 +0800 | [diff] [blame] | 1076 | ghes_fini(ghes); |
Mauro Carvalho Chehab | 2148054 | 2013-02-15 06:10:39 -0300 | [diff] [blame] | 1077 | |
| 1078 | ghes_edac_unregister(ghes); |
| 1079 | |
Huang Ying | 7ad6e94 | 2010-08-02 15:48:24 +0800 | [diff] [blame] | 1080 | kfree(ghes); |
| 1081 | |
| 1082 | platform_set_drvdata(ghes_dev, NULL); |
| 1083 | |
| 1084 | return 0; |
| 1085 | } |
| 1086 | |
| 1087 | static struct platform_driver ghes_platform_driver = { |
| 1088 | .driver = { |
| 1089 | .name = "GHES", |
Huang Ying | 7ad6e94 | 2010-08-02 15:48:24 +0800 | [diff] [blame] | 1090 | }, |
| 1091 | .probe = ghes_probe, |
| 1092 | .remove = ghes_remove, |
| 1093 | }; |
| 1094 | |
Huang Ying | d334a49 | 2010-05-18 14:35:20 +0800 | [diff] [blame] | 1095 | static int __init ghes_init(void) |
| 1096 | { |
Huang Ying | 81e88fd | 2011-01-12 14:44:55 +0800 | [diff] [blame] | 1097 | int rc; |
| 1098 | |
Huang Ying | d334a49 | 2010-05-18 14:35:20 +0800 | [diff] [blame] | 1099 | if (acpi_disabled) |
| 1100 | return -ENODEV; |
| 1101 | |
| 1102 | if (hest_disable) { |
| 1103 | pr_info(GHES_PFX "HEST is not enabled!\n"); |
| 1104 | return -EINVAL; |
| 1105 | } |
| 1106 | |
Huang Ying | b6a9501 | 2011-07-13 13:14:19 +0800 | [diff] [blame] | 1107 | if (ghes_disable) { |
| 1108 | pr_info(GHES_PFX "GHES is not enabled!\n"); |
| 1109 | return -EINVAL; |
| 1110 | } |
| 1111 | |
Tomasz Nowicki | 44a69f6 | 2014-07-22 11:20:12 +0200 | [diff] [blame] | 1112 | ghes_nmi_init_cxt(); |
Huang Ying | 67eb2e9 | 2011-07-13 13:14:25 +0800 | [diff] [blame] | 1113 | |
Huang Ying | 81e88fd | 2011-01-12 14:44:55 +0800 | [diff] [blame] | 1114 | rc = ghes_ioremap_init(); |
| 1115 | if (rc) |
| 1116 | goto err; |
| 1117 | |
Huang Ying | 67eb2e9 | 2011-07-13 13:14:25 +0800 | [diff] [blame] | 1118 | rc = ghes_estatus_pool_init(); |
Huang Ying | 81e88fd | 2011-01-12 14:44:55 +0800 | [diff] [blame] | 1119 | if (rc) |
| 1120 | goto err_ioremap_exit; |
| 1121 | |
Huang Ying | 152cef4 | 2011-07-13 13:14:26 +0800 | [diff] [blame] | 1122 | rc = ghes_estatus_pool_expand(GHES_ESTATUS_CACHE_AVG_SIZE * |
| 1123 | GHES_ESTATUS_CACHE_ALLOCED_MAX); |
| 1124 | if (rc) |
| 1125 | goto err_pool_exit; |
| 1126 | |
Huang Ying | 67eb2e9 | 2011-07-13 13:14:25 +0800 | [diff] [blame] | 1127 | rc = platform_driver_register(&ghes_platform_driver); |
| 1128 | if (rc) |
| 1129 | goto err_pool_exit; |
| 1130 | |
Huang Ying | 9fb0bfe | 2011-07-13 13:14:21 +0800 | [diff] [blame] | 1131 | rc = apei_osc_setup(); |
| 1132 | if (rc == 0 && osc_sb_apei_support_acked) |
| 1133 | pr_info(GHES_PFX "APEI firmware first mode is enabled by APEI bit and WHEA _OSC.\n"); |
| 1134 | else if (rc == 0 && !osc_sb_apei_support_acked) |
| 1135 | pr_info(GHES_PFX "APEI firmware first mode is enabled by WHEA _OSC.\n"); |
| 1136 | else if (rc && osc_sb_apei_support_acked) |
| 1137 | pr_info(GHES_PFX "APEI firmware first mode is enabled by APEI bit.\n"); |
| 1138 | else |
| 1139 | pr_info(GHES_PFX "Failed to enable APEI firmware first mode.\n"); |
| 1140 | |
Huang Ying | 81e88fd | 2011-01-12 14:44:55 +0800 | [diff] [blame] | 1141 | return 0; |
Huang Ying | 67eb2e9 | 2011-07-13 13:14:25 +0800 | [diff] [blame] | 1142 | err_pool_exit: |
| 1143 | ghes_estatus_pool_exit(); |
Huang Ying | 81e88fd | 2011-01-12 14:44:55 +0800 | [diff] [blame] | 1144 | err_ioremap_exit: |
| 1145 | ghes_ioremap_exit(); |
| 1146 | err: |
| 1147 | return rc; |
Huang Ying | d334a49 | 2010-05-18 14:35:20 +0800 | [diff] [blame] | 1148 | } |
| 1149 | |
| 1150 | static void __exit ghes_exit(void) |
| 1151 | { |
Huang Ying | 7ad6e94 | 2010-08-02 15:48:24 +0800 | [diff] [blame] | 1152 | platform_driver_unregister(&ghes_platform_driver); |
Huang Ying | 67eb2e9 | 2011-07-13 13:14:25 +0800 | [diff] [blame] | 1153 | ghes_estatus_pool_exit(); |
Huang Ying | 81e88fd | 2011-01-12 14:44:55 +0800 | [diff] [blame] | 1154 | ghes_ioremap_exit(); |
Huang Ying | d334a49 | 2010-05-18 14:35:20 +0800 | [diff] [blame] | 1155 | } |
| 1156 | |
| 1157 | module_init(ghes_init); |
| 1158 | module_exit(ghes_exit); |
| 1159 | |
| 1160 | MODULE_AUTHOR("Huang Ying"); |
| 1161 | MODULE_DESCRIPTION("APEI Generic Hardware Error Source support"); |
| 1162 | MODULE_LICENSE("GPL"); |
Huang Ying | 7ad6e94 | 2010-08-02 15:48:24 +0800 | [diff] [blame] | 1163 | MODULE_ALIAS("platform:GHES"); |