Orange Pi5 kernel

Deprecated Linux kernel 5.10.110 for OrangePi 5/5B/5+ boards

3 Commits   0 Branches   0 Tags
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300    1) // SPDX-License-Identifier: GPL-2.0-only
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300    2) /*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300    3)  * APEI Generic Hardware Error Source support
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300    4)  *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300    5)  * Generic Hardware Error Source provides a way to report platform
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300    6)  * hardware errors (such as that from chipset). It works in so called
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300    7)  * "Firmware First" mode, that is, hardware errors are reported to
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300    8)  * firmware firstly, then reported to Linux by firmware. This way,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300    9)  * some non-standard hardware error registers or non-standard hardware
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   10)  * link can be checked by firmware to produce more hardware error
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   11)  * information for Linux.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   12)  *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   13)  * For more information about Generic Hardware Error Source, please
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   14)  * refer to ACPI Specification version 4.0, section 17.3.2.6
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   15)  *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   16)  * Copyright 2010,2011 Intel Corp.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   17)  *   Author: Huang Ying <ying.huang@intel.com>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   18)  */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   19) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   20) #include <linux/arm_sdei.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   21) #include <linux/kernel.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   22) #include <linux/moduleparam.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   23) #include <linux/init.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   24) #include <linux/acpi.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   25) #include <linux/io.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   26) #include <linux/interrupt.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   27) #include <linux/timer.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   28) #include <linux/cper.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   29) #include <linux/platform_device.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   30) #include <linux/mutex.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   31) #include <linux/ratelimit.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   32) #include <linux/vmalloc.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   33) #include <linux/irq_work.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   34) #include <linux/llist.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   35) #include <linux/genalloc.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   36) #include <linux/pci.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   37) #include <linux/pfn.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   38) #include <linux/aer.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   39) #include <linux/nmi.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   40) #include <linux/sched/clock.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   41) #include <linux/uuid.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   42) #include <linux/ras.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   43) #include <linux/task_work.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   44) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   45) #include <acpi/actbl1.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   46) #include <acpi/ghes.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   47) #include <acpi/apei.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   48) #include <asm/fixmap.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   49) #include <asm/tlbflush.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   50) #include <ras/ras_event.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   51) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   52) #include "apei-internal.h"
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   53) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   54) #define GHES_PFX	"GHES: "
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   55) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   56) #define GHES_ESTATUS_MAX_SIZE		65536
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   57) #define GHES_ESOURCE_PREALLOC_MAX_SIZE	65536
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   58) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   59) #define GHES_ESTATUS_POOL_MIN_ALLOC_ORDER 3
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   60) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   61) /* This is just an estimation for memory pool allocation */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   62) #define GHES_ESTATUS_CACHE_AVG_SIZE	512
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   63) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   64) #define GHES_ESTATUS_CACHES_SIZE	4
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   65) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   66) #define GHES_ESTATUS_IN_CACHE_MAX_NSEC	10000000000ULL
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   67) /* Prevent too many caches are allocated because of RCU */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   68) #define GHES_ESTATUS_CACHE_ALLOCED_MAX	(GHES_ESTATUS_CACHES_SIZE * 3 / 2)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   69) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   70) #define GHES_ESTATUS_CACHE_LEN(estatus_len)			\
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   71) 	(sizeof(struct ghes_estatus_cache) + (estatus_len))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   72) #define GHES_ESTATUS_FROM_CACHE(estatus_cache)			\
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   73) 	((struct acpi_hest_generic_status *)				\
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   74) 	 ((struct ghes_estatus_cache *)(estatus_cache) + 1))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   75) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   76) #define GHES_ESTATUS_NODE_LEN(estatus_len)			\
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   77) 	(sizeof(struct ghes_estatus_node) + (estatus_len))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   78) #define GHES_ESTATUS_FROM_NODE(estatus_node)			\
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   79) 	((struct acpi_hest_generic_status *)				\
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   80) 	 ((struct ghes_estatus_node *)(estatus_node) + 1))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   81) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   82) #define GHES_VENDOR_ENTRY_LEN(gdata_len)                               \
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   83) 	(sizeof(struct ghes_vendor_record_entry) + (gdata_len))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   84) #define GHES_GDATA_FROM_VENDOR_ENTRY(vendor_entry)                     \
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   85) 	((struct acpi_hest_generic_data *)                              \
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   86) 	((struct ghes_vendor_record_entry *)(vendor_entry) + 1))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   87) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   88) /*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   89)  *  NMI-like notifications vary by architecture, before the compiler can prune
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   90)  *  unused static functions it needs a value for these enums.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   91)  */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   92) #ifndef CONFIG_ARM_SDE_INTERFACE
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   93) #define FIX_APEI_GHES_SDEI_NORMAL	__end_of_fixed_addresses
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   94) #define FIX_APEI_GHES_SDEI_CRITICAL	__end_of_fixed_addresses
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   95) #endif
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   96) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   97) static inline bool is_hest_type_generic_v2(struct ghes *ghes)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   98) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   99) 	return ghes->generic->header.type == ACPI_HEST_TYPE_GENERIC_ERROR_V2;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  100) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  101) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  102) /*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  103)  * This driver isn't really modular, however for the time being,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  104)  * continuing to use module_param is the easiest way to remain
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  105)  * compatible with existing boot arg use cases.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  106)  */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  107) bool ghes_disable;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  108) module_param_named(disable, ghes_disable, bool, 0);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  109) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  110) /*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  111)  * All error sources notified with HED (Hardware Error Device) share a
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  112)  * single notifier callback, so they need to be linked and checked one
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  113)  * by one. This holds true for NMI too.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  114)  *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  115)  * RCU is used for these lists, so ghes_list_mutex is only used for
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  116)  * list changing, not for traversing.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  117)  */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  118) static LIST_HEAD(ghes_hed);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  119) static DEFINE_MUTEX(ghes_list_mutex);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  120) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  121) /*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  122)  * Because the memory area used to transfer hardware error information
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  123)  * from BIOS to Linux can be determined only in NMI, IRQ or timer
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  124)  * handler, but general ioremap can not be used in atomic context, so
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  125)  * the fixmap is used instead.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  126)  *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  127)  * This spinlock is used to prevent the fixmap entry from being used
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  128)  * simultaneously.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  129)  */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  130) static DEFINE_SPINLOCK(ghes_notify_lock_irq);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  131) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  132) struct ghes_vendor_record_entry {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  133) 	struct work_struct work;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  134) 	int error_severity;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  135) 	char vendor_record[];
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  136) };
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  137) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  138) static struct gen_pool *ghes_estatus_pool;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  139) static unsigned long ghes_estatus_pool_size_request;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  140) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  141) static struct ghes_estatus_cache *ghes_estatus_caches[GHES_ESTATUS_CACHES_SIZE];
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  142) static atomic_t ghes_estatus_cache_alloced;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  143) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  144) static int ghes_panic_timeout __read_mostly = 30;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  145) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  146) static void __iomem *ghes_map(u64 pfn, enum fixed_addresses fixmap_idx)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  147) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  148) 	phys_addr_t paddr;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  149) 	pgprot_t prot;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  150) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  151) 	paddr = PFN_PHYS(pfn);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  152) 	prot = arch_apei_get_mem_attribute(paddr);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  153) 	__set_fixmap(fixmap_idx, paddr, prot);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  154) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  155) 	return (void __iomem *) __fix_to_virt(fixmap_idx);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  156) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  157) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  158) static void ghes_unmap(void __iomem *vaddr, enum fixed_addresses fixmap_idx)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  159) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  160) 	int _idx = virt_to_fix((unsigned long)vaddr);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  161) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  162) 	WARN_ON_ONCE(fixmap_idx != _idx);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  163) 	clear_fixmap(fixmap_idx);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  164) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  165) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  166) int ghes_estatus_pool_init(int num_ghes)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  167) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  168) 	unsigned long addr, len;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  169) 	int rc;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  170) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  171) 	ghes_estatus_pool = gen_pool_create(GHES_ESTATUS_POOL_MIN_ALLOC_ORDER, -1);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  172) 	if (!ghes_estatus_pool)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  173) 		return -ENOMEM;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  174) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  175) 	len = GHES_ESTATUS_CACHE_AVG_SIZE * GHES_ESTATUS_CACHE_ALLOCED_MAX;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  176) 	len += (num_ghes * GHES_ESOURCE_PREALLOC_MAX_SIZE);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  177) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  178) 	ghes_estatus_pool_size_request = PAGE_ALIGN(len);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  179) 	addr = (unsigned long)vmalloc(PAGE_ALIGN(len));
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  180) 	if (!addr)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  181) 		goto err_pool_alloc;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  182) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  183) 	rc = gen_pool_add(ghes_estatus_pool, addr, PAGE_ALIGN(len), -1);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  184) 	if (rc)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  185) 		goto err_pool_add;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  186) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  187) 	return 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  188) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  189) err_pool_add:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  190) 	vfree((void *)addr);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  191) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  192) err_pool_alloc:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  193) 	gen_pool_destroy(ghes_estatus_pool);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  194) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  195) 	return -ENOMEM;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  196) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  197) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  198) static int map_gen_v2(struct ghes *ghes)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  199) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  200) 	return apei_map_generic_address(&ghes->generic_v2->read_ack_register);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  201) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  202) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  203) static void unmap_gen_v2(struct ghes *ghes)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  204) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  205) 	apei_unmap_generic_address(&ghes->generic_v2->read_ack_register);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  206) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  207) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  208) static void ghes_ack_error(struct acpi_hest_generic_v2 *gv2)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  209) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  210) 	int rc;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  211) 	u64 val = 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  212) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  213) 	rc = apei_read(&val, &gv2->read_ack_register);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  214) 	if (rc)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  215) 		return;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  216) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  217) 	val &= gv2->read_ack_preserve << gv2->read_ack_register.bit_offset;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  218) 	val |= gv2->read_ack_write    << gv2->read_ack_register.bit_offset;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  219) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  220) 	apei_write(val, &gv2->read_ack_register);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  221) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  222) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  223) static struct ghes *ghes_new(struct acpi_hest_generic *generic)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  224) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  225) 	struct ghes *ghes;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  226) 	unsigned int error_block_length;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  227) 	int rc;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  228) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  229) 	ghes = kzalloc(sizeof(*ghes), GFP_KERNEL);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  230) 	if (!ghes)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  231) 		return ERR_PTR(-ENOMEM);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  232) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  233) 	ghes->generic = generic;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  234) 	if (is_hest_type_generic_v2(ghes)) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  235) 		rc = map_gen_v2(ghes);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  236) 		if (rc)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  237) 			goto err_free;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  238) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  239) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  240) 	rc = apei_map_generic_address(&generic->error_status_address);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  241) 	if (rc)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  242) 		goto err_unmap_read_ack_addr;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  243) 	error_block_length = generic->error_block_length;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  244) 	if (error_block_length > GHES_ESTATUS_MAX_SIZE) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  245) 		pr_warn(FW_WARN GHES_PFX
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  246) 			"Error status block length is too long: %u for "
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  247) 			"generic hardware error source: %d.\n",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  248) 			error_block_length, generic->header.source_id);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  249) 		error_block_length = GHES_ESTATUS_MAX_SIZE;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  250) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  251) 	ghes->estatus = kmalloc(error_block_length, GFP_KERNEL);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  252) 	if (!ghes->estatus) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  253) 		rc = -ENOMEM;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  254) 		goto err_unmap_status_addr;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  255) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  256) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  257) 	return ghes;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  258) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  259) err_unmap_status_addr:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  260) 	apei_unmap_generic_address(&generic->error_status_address);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  261) err_unmap_read_ack_addr:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  262) 	if (is_hest_type_generic_v2(ghes))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  263) 		unmap_gen_v2(ghes);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  264) err_free:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  265) 	kfree(ghes);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  266) 	return ERR_PTR(rc);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  267) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  268) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  269) static void ghes_fini(struct ghes *ghes)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  270) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  271) 	kfree(ghes->estatus);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  272) 	apei_unmap_generic_address(&ghes->generic->error_status_address);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  273) 	if (is_hest_type_generic_v2(ghes))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  274) 		unmap_gen_v2(ghes);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  275) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  276) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  277) static inline int ghes_severity(int severity)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  278) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  279) 	switch (severity) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  280) 	case CPER_SEV_INFORMATIONAL:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  281) 		return GHES_SEV_NO;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  282) 	case CPER_SEV_CORRECTED:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  283) 		return GHES_SEV_CORRECTED;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  284) 	case CPER_SEV_RECOVERABLE:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  285) 		return GHES_SEV_RECOVERABLE;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  286) 	case CPER_SEV_FATAL:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  287) 		return GHES_SEV_PANIC;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  288) 	default:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  289) 		/* Unknown, go panic */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  290) 		return GHES_SEV_PANIC;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  291) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  292) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  293) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  294) static void ghes_copy_tofrom_phys(void *buffer, u64 paddr, u32 len,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  295) 				  int from_phys,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  296) 				  enum fixed_addresses fixmap_idx)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  297) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  298) 	void __iomem *vaddr;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  299) 	u64 offset;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  300) 	u32 trunk;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  301) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  302) 	while (len > 0) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  303) 		offset = paddr - (paddr & PAGE_MASK);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  304) 		vaddr = ghes_map(PHYS_PFN(paddr), fixmap_idx);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  305) 		trunk = PAGE_SIZE - offset;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  306) 		trunk = min(trunk, len);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  307) 		if (from_phys)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  308) 			memcpy_fromio(buffer, vaddr + offset, trunk);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  309) 		else
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  310) 			memcpy_toio(vaddr + offset, buffer, trunk);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  311) 		len -= trunk;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  312) 		paddr += trunk;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  313) 		buffer += trunk;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  314) 		ghes_unmap(vaddr, fixmap_idx);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  315) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  316) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  317) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  318) /* Check the top-level record header has an appropriate size. */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  319) static int __ghes_check_estatus(struct ghes *ghes,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  320) 				struct acpi_hest_generic_status *estatus)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  321) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  322) 	u32 len = cper_estatus_len(estatus);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  323) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  324) 	if (len < sizeof(*estatus)) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  325) 		pr_warn_ratelimited(FW_WARN GHES_PFX "Truncated error status block!\n");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  326) 		return -EIO;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  327) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  328) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  329) 	if (len > ghes->generic->error_block_length) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  330) 		pr_warn_ratelimited(FW_WARN GHES_PFX "Invalid error status block length!\n");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  331) 		return -EIO;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  332) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  333) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  334) 	if (cper_estatus_check_header(estatus)) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  335) 		pr_warn_ratelimited(FW_WARN GHES_PFX "Invalid CPER header!\n");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  336) 		return -EIO;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  337) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  338) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  339) 	return 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  340) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  341) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  342) /* Read the CPER block, returning its address, and header in estatus. */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  343) static int __ghes_peek_estatus(struct ghes *ghes,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  344) 			       struct acpi_hest_generic_status *estatus,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  345) 			       u64 *buf_paddr, enum fixed_addresses fixmap_idx)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  346) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  347) 	struct acpi_hest_generic *g = ghes->generic;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  348) 	int rc;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  349) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  350) 	rc = apei_read(buf_paddr, &g->error_status_address);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  351) 	if (rc) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  352) 		*buf_paddr = 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  353) 		pr_warn_ratelimited(FW_WARN GHES_PFX
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  354) "Failed to read error status block address for hardware error source: %d.\n",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  355) 				   g->header.source_id);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  356) 		return -EIO;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  357) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  358) 	if (!*buf_paddr)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  359) 		return -ENOENT;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  360) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  361) 	ghes_copy_tofrom_phys(estatus, *buf_paddr, sizeof(*estatus), 1,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  362) 			      fixmap_idx);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  363) 	if (!estatus->block_status) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  364) 		*buf_paddr = 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  365) 		return -ENOENT;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  366) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  367) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  368) 	return 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  369) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  370) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  371) static int __ghes_read_estatus(struct acpi_hest_generic_status *estatus,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  372) 			       u64 buf_paddr, enum fixed_addresses fixmap_idx,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  373) 			       size_t buf_len)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  374) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  375) 	ghes_copy_tofrom_phys(estatus, buf_paddr, buf_len, 1, fixmap_idx);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  376) 	if (cper_estatus_check(estatus)) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  377) 		pr_warn_ratelimited(FW_WARN GHES_PFX
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  378) 				    "Failed to read error status block!\n");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  379) 		return -EIO;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  380) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  381) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  382) 	return 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  383) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  384) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  385) static int ghes_read_estatus(struct ghes *ghes,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  386) 			     struct acpi_hest_generic_status *estatus,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  387) 			     u64 *buf_paddr, enum fixed_addresses fixmap_idx)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  388) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  389) 	int rc;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  390) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  391) 	rc = __ghes_peek_estatus(ghes, estatus, buf_paddr, fixmap_idx);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  392) 	if (rc)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  393) 		return rc;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  394) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  395) 	rc = __ghes_check_estatus(ghes, estatus);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  396) 	if (rc)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  397) 		return rc;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  398) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  399) 	return __ghes_read_estatus(estatus, *buf_paddr, fixmap_idx,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  400) 				   cper_estatus_len(estatus));
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  401) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  402) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  403) static void ghes_clear_estatus(struct ghes *ghes,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  404) 			       struct acpi_hest_generic_status *estatus,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  405) 			       u64 buf_paddr, enum fixed_addresses fixmap_idx)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  406) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  407) 	estatus->block_status = 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  408) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  409) 	if (!buf_paddr)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  410) 		return;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  411) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  412) 	ghes_copy_tofrom_phys(estatus, buf_paddr,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  413) 			      sizeof(estatus->block_status), 0,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  414) 			      fixmap_idx);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  415) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  416) 	/*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  417) 	 * GHESv2 type HEST entries introduce support for error acknowledgment,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  418) 	 * so only acknowledge the error if this support is present.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  419) 	 */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  420) 	if (is_hest_type_generic_v2(ghes))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  421) 		ghes_ack_error(ghes->generic_v2);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  422) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  423) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  424) /*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  425)  * Called as task_work before returning to user-space.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  426)  * Ensure any queued work has been done before we return to the context that
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  427)  * triggered the notification.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  428)  */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  429) static void ghes_kick_task_work(struct callback_head *head)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  430) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  431) 	struct acpi_hest_generic_status *estatus;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  432) 	struct ghes_estatus_node *estatus_node;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  433) 	u32 node_len;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  434) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  435) 	estatus_node = container_of(head, struct ghes_estatus_node, task_work);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  436) 	if (IS_ENABLED(CONFIG_ACPI_APEI_MEMORY_FAILURE))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  437) 		memory_failure_queue_kick(estatus_node->task_work_cpu);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  438) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  439) 	estatus = GHES_ESTATUS_FROM_NODE(estatus_node);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  440) 	node_len = GHES_ESTATUS_NODE_LEN(cper_estatus_len(estatus));
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  441) 	gen_pool_free(ghes_estatus_pool, (unsigned long)estatus_node, node_len);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  442) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  443) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  444) static bool ghes_do_memory_failure(u64 physical_addr, int flags)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  445) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  446) 	unsigned long pfn;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  447) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  448) 	if (!IS_ENABLED(CONFIG_ACPI_APEI_MEMORY_FAILURE))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  449) 		return false;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  450) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  451) 	pfn = PHYS_PFN(physical_addr);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  452) 	if (!pfn_valid(pfn)) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  453) 		pr_warn_ratelimited(FW_WARN GHES_PFX
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  454) 		"Invalid address in generic error data: %#llx\n",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  455) 		physical_addr);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  456) 		return false;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  457) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  458) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  459) 	memory_failure_queue(pfn, flags);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  460) 	return true;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  461) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  462) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  463) static bool ghes_handle_memory_failure(struct acpi_hest_generic_data *gdata,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  464) 				       int sev)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  465) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  466) 	int flags = -1;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  467) 	int sec_sev = ghes_severity(gdata->error_severity);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  468) 	struct cper_sec_mem_err *mem_err = acpi_hest_get_payload(gdata);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  469) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  470) 	if (!(mem_err->validation_bits & CPER_MEM_VALID_PA))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  471) 		return false;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  472) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  473) 	/* iff following two events can be handled properly by now */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  474) 	if (sec_sev == GHES_SEV_CORRECTED &&
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  475) 	    (gdata->flags & CPER_SEC_ERROR_THRESHOLD_EXCEEDED))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  476) 		flags = MF_SOFT_OFFLINE;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  477) 	if (sev == GHES_SEV_RECOVERABLE && sec_sev == GHES_SEV_RECOVERABLE)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  478) 		flags = 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  479) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  480) 	if (flags != -1)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  481) 		return ghes_do_memory_failure(mem_err->physical_addr, flags);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  482) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  483) 	return false;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  484) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  485) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  486) static bool ghes_handle_arm_hw_error(struct acpi_hest_generic_data *gdata, int sev)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  487) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  488) 	struct cper_sec_proc_arm *err = acpi_hest_get_payload(gdata);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  489) 	bool queued = false;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  490) 	int sec_sev, i;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  491) 	char *p;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  492) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  493) 	log_arm_hw_error(err);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  494) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  495) 	sec_sev = ghes_severity(gdata->error_severity);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  496) 	if (sev != GHES_SEV_RECOVERABLE || sec_sev != GHES_SEV_RECOVERABLE)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  497) 		return false;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  498) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  499) 	p = (char *)(err + 1);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  500) 	for (i = 0; i < err->err_info_num; i++) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  501) 		struct cper_arm_err_info *err_info = (struct cper_arm_err_info *)p;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  502) 		bool is_cache = (err_info->type == CPER_ARM_CACHE_ERROR);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  503) 		bool has_pa = (err_info->validation_bits & CPER_ARM_INFO_VALID_PHYSICAL_ADDR);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  504) 		const char *error_type = "unknown error";
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  505) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  506) 		/*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  507) 		 * The field (err_info->error_info & BIT(26)) is fixed to set to
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  508) 		 * 1 in some old firmware of HiSilicon Kunpeng920. We assume that
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  509) 		 * firmware won't mix corrected errors in an uncorrected section,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  510) 		 * and don't filter out 'corrected' error here.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  511) 		 */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  512) 		if (is_cache && has_pa) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  513) 			queued = ghes_do_memory_failure(err_info->physical_fault_addr, 0);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  514) 			p += err_info->length;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  515) 			continue;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  516) 		}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  517) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  518) 		if (err_info->type < ARRAY_SIZE(cper_proc_error_type_strs))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  519) 			error_type = cper_proc_error_type_strs[err_info->type];
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  520) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  521) 		pr_warn_ratelimited(FW_WARN GHES_PFX
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  522) 				    "Unhandled processor error type: %s\n",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  523) 				    error_type);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  524) 		p += err_info->length;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  525) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  526) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  527) 	return queued;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  528) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  529) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  530) /*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  531)  * PCIe AER errors need to be sent to the AER driver for reporting and
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  532)  * recovery. The GHES severities map to the following AER severities and
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  533)  * require the following handling:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  534)  *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  535)  * GHES_SEV_CORRECTABLE -> AER_CORRECTABLE
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  536)  *     These need to be reported by the AER driver but no recovery is
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  537)  *     necessary.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  538)  * GHES_SEV_RECOVERABLE -> AER_NONFATAL
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  539)  * GHES_SEV_RECOVERABLE && CPER_SEC_RESET -> AER_FATAL
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  540)  *     These both need to be reported and recovered from by the AER driver.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  541)  * GHES_SEV_PANIC does not make it to this handling since the kernel must
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  542)  *     panic.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  543)  */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  544) static void ghes_handle_aer(struct acpi_hest_generic_data *gdata)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  545) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  546) #ifdef CONFIG_ACPI_APEI_PCIEAER
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  547) 	struct cper_sec_pcie *pcie_err = acpi_hest_get_payload(gdata);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  548) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  549) 	if (pcie_err->validation_bits & CPER_PCIE_VALID_DEVICE_ID &&
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  550) 	    pcie_err->validation_bits & CPER_PCIE_VALID_AER_INFO) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  551) 		unsigned int devfn;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  552) 		int aer_severity;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  553) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  554) 		devfn = PCI_DEVFN(pcie_err->device_id.device,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  555) 				  pcie_err->device_id.function);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  556) 		aer_severity = cper_severity_to_aer(gdata->error_severity);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  557) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  558) 		/*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  559) 		 * If firmware reset the component to contain
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  560) 		 * the error, we must reinitialize it before
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  561) 		 * use, so treat it as a fatal AER error.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  562) 		 */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  563) 		if (gdata->flags & CPER_SEC_RESET)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  564) 			aer_severity = AER_FATAL;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  565) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  566) 		aer_recover_queue(pcie_err->device_id.segment,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  567) 				  pcie_err->device_id.bus,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  568) 				  devfn, aer_severity,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  569) 				  (struct aer_capability_regs *)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  570) 				  pcie_err->aer_info);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  571) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  572) #endif
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  573) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  574) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  575) static BLOCKING_NOTIFIER_HEAD(vendor_record_notify_list);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  576) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  577) int ghes_register_vendor_record_notifier(struct notifier_block *nb)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  578) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  579) 	return blocking_notifier_chain_register(&vendor_record_notify_list, nb);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  580) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  581) EXPORT_SYMBOL_GPL(ghes_register_vendor_record_notifier);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  582) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  583) void ghes_unregister_vendor_record_notifier(struct notifier_block *nb)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  584) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  585) 	blocking_notifier_chain_unregister(&vendor_record_notify_list, nb);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  586) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  587) EXPORT_SYMBOL_GPL(ghes_unregister_vendor_record_notifier);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  588) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  589) static void ghes_vendor_record_work_func(struct work_struct *work)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  590) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  591) 	struct ghes_vendor_record_entry *entry;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  592) 	struct acpi_hest_generic_data *gdata;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  593) 	u32 len;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  594) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  595) 	entry = container_of(work, struct ghes_vendor_record_entry, work);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  596) 	gdata = GHES_GDATA_FROM_VENDOR_ENTRY(entry);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  597) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  598) 	blocking_notifier_call_chain(&vendor_record_notify_list,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  599) 				     entry->error_severity, gdata);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  600) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  601) 	len = GHES_VENDOR_ENTRY_LEN(acpi_hest_get_record_size(gdata));
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  602) 	gen_pool_free(ghes_estatus_pool, (unsigned long)entry, len);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  603) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  604) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  605) static void ghes_defer_non_standard_event(struct acpi_hest_generic_data *gdata,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  606) 					  int sev)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  607) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  608) 	struct acpi_hest_generic_data *copied_gdata;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  609) 	struct ghes_vendor_record_entry *entry;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  610) 	u32 len;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  611) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  612) 	len = GHES_VENDOR_ENTRY_LEN(acpi_hest_get_record_size(gdata));
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  613) 	entry = (void *)gen_pool_alloc(ghes_estatus_pool, len);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  614) 	if (!entry)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  615) 		return;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  616) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  617) 	copied_gdata = GHES_GDATA_FROM_VENDOR_ENTRY(entry);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  618) 	memcpy(copied_gdata, gdata, acpi_hest_get_record_size(gdata));
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  619) 	entry->error_severity = sev;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  620) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  621) 	INIT_WORK(&entry->work, ghes_vendor_record_work_func);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  622) 	schedule_work(&entry->work);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  623) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  624) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  625) static bool ghes_do_proc(struct ghes *ghes,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  626) 			 const struct acpi_hest_generic_status *estatus)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  627) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  628) 	int sev, sec_sev;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  629) 	struct acpi_hest_generic_data *gdata;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  630) 	guid_t *sec_type;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  631) 	const guid_t *fru_id = &guid_null;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  632) 	char *fru_text = "";
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  633) 	bool queued = false;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  634) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  635) 	sev = ghes_severity(estatus->error_severity);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  636) 	apei_estatus_for_each_section(estatus, gdata) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  637) 		sec_type = (guid_t *)gdata->section_type;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  638) 		sec_sev = ghes_severity(gdata->error_severity);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  639) 		if (gdata->validation_bits & CPER_SEC_VALID_FRU_ID)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  640) 			fru_id = (guid_t *)gdata->fru_id;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  641) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  642) 		if (gdata->validation_bits & CPER_SEC_VALID_FRU_TEXT)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  643) 			fru_text = gdata->fru_text;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  644) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  645) 		if (guid_equal(sec_type, &CPER_SEC_PLATFORM_MEM)) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  646) 			struct cper_sec_mem_err *mem_err = acpi_hest_get_payload(gdata);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  647) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  648) 			ghes_edac_report_mem_error(sev, mem_err);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  649) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  650) 			arch_apei_report_mem_error(sev, mem_err);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  651) 			queued = ghes_handle_memory_failure(gdata, sev);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  652) 		}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  653) 		else if (guid_equal(sec_type, &CPER_SEC_PCIE)) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  654) 			ghes_handle_aer(gdata);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  655) 		}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  656) 		else if (guid_equal(sec_type, &CPER_SEC_PROC_ARM)) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  657) 			queued = ghes_handle_arm_hw_error(gdata, sev);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  658) 		} else {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  659) 			void *err = acpi_hest_get_payload(gdata);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  660) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  661) 			ghes_defer_non_standard_event(gdata, sev);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  662) 			log_non_standard_event(sec_type, fru_id, fru_text,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  663) 					       sec_sev, err,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  664) 					       gdata->error_data_length);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  665) 		}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  666) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  667) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  668) 	return queued;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  669) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  670) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  671) static void __ghes_print_estatus(const char *pfx,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  672) 				 const struct acpi_hest_generic *generic,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  673) 				 const struct acpi_hest_generic_status *estatus)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  674) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  675) 	static atomic_t seqno;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  676) 	unsigned int curr_seqno;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  677) 	char pfx_seq[64];
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  678) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  679) 	if (pfx == NULL) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  680) 		if (ghes_severity(estatus->error_severity) <=
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  681) 		    GHES_SEV_CORRECTED)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  682) 			pfx = KERN_WARNING;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  683) 		else
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  684) 			pfx = KERN_ERR;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  685) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  686) 	curr_seqno = atomic_inc_return(&seqno);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  687) 	snprintf(pfx_seq, sizeof(pfx_seq), "%s{%u}" HW_ERR, pfx, curr_seqno);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  688) 	printk("%s""Hardware error from APEI Generic Hardware Error Source: %d\n",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  689) 	       pfx_seq, generic->header.source_id);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  690) 	cper_estatus_print(pfx_seq, estatus);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  691) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  692) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  693) static int ghes_print_estatus(const char *pfx,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  694) 			      const struct acpi_hest_generic *generic,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  695) 			      const struct acpi_hest_generic_status *estatus)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  696) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  697) 	/* Not more than 2 messages every 5 seconds */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  698) 	static DEFINE_RATELIMIT_STATE(ratelimit_corrected, 5*HZ, 2);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  699) 	static DEFINE_RATELIMIT_STATE(ratelimit_uncorrected, 5*HZ, 2);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  700) 	struct ratelimit_state *ratelimit;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  701) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  702) 	if (ghes_severity(estatus->error_severity) <= GHES_SEV_CORRECTED)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  703) 		ratelimit = &ratelimit_corrected;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  704) 	else
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  705) 		ratelimit = &ratelimit_uncorrected;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  706) 	if (__ratelimit(ratelimit)) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  707) 		__ghes_print_estatus(pfx, generic, estatus);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  708) 		return 1;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  709) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  710) 	return 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  711) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  712) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  713) /*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  714)  * GHES error status reporting throttle, to report more kinds of
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  715)  * errors, instead of just most frequently occurred errors.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  716)  */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  717) static int ghes_estatus_cached(struct acpi_hest_generic_status *estatus)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  718) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  719) 	u32 len;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  720) 	int i, cached = 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  721) 	unsigned long long now;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  722) 	struct ghes_estatus_cache *cache;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  723) 	struct acpi_hest_generic_status *cache_estatus;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  724) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  725) 	len = cper_estatus_len(estatus);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  726) 	rcu_read_lock();
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  727) 	for (i = 0; i < GHES_ESTATUS_CACHES_SIZE; i++) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  728) 		cache = rcu_dereference(ghes_estatus_caches[i]);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  729) 		if (cache == NULL)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  730) 			continue;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  731) 		if (len != cache->estatus_len)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  732) 			continue;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  733) 		cache_estatus = GHES_ESTATUS_FROM_CACHE(cache);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  734) 		if (memcmp(estatus, cache_estatus, len))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  735) 			continue;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  736) 		atomic_inc(&cache->count);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  737) 		now = sched_clock();
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  738) 		if (now - cache->time_in < GHES_ESTATUS_IN_CACHE_MAX_NSEC)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  739) 			cached = 1;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  740) 		break;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  741) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  742) 	rcu_read_unlock();
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  743) 	return cached;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  744) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  745) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  746) static struct ghes_estatus_cache *ghes_estatus_cache_alloc(
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  747) 	struct acpi_hest_generic *generic,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  748) 	struct acpi_hest_generic_status *estatus)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  749) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  750) 	int alloced;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  751) 	u32 len, cache_len;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  752) 	struct ghes_estatus_cache *cache;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  753) 	struct acpi_hest_generic_status *cache_estatus;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  754) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  755) 	alloced = atomic_add_return(1, &ghes_estatus_cache_alloced);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  756) 	if (alloced > GHES_ESTATUS_CACHE_ALLOCED_MAX) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  757) 		atomic_dec(&ghes_estatus_cache_alloced);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  758) 		return NULL;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  759) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  760) 	len = cper_estatus_len(estatus);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  761) 	cache_len = GHES_ESTATUS_CACHE_LEN(len);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  762) 	cache = (void *)gen_pool_alloc(ghes_estatus_pool, cache_len);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  763) 	if (!cache) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  764) 		atomic_dec(&ghes_estatus_cache_alloced);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  765) 		return NULL;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  766) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  767) 	cache_estatus = GHES_ESTATUS_FROM_CACHE(cache);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  768) 	memcpy(cache_estatus, estatus, len);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  769) 	cache->estatus_len = len;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  770) 	atomic_set(&cache->count, 0);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  771) 	cache->generic = generic;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  772) 	cache->time_in = sched_clock();
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  773) 	return cache;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  774) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  775) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  776) static void ghes_estatus_cache_free(struct ghes_estatus_cache *cache)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  777) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  778) 	u32 len;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  779) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  780) 	len = cper_estatus_len(GHES_ESTATUS_FROM_CACHE(cache));
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  781) 	len = GHES_ESTATUS_CACHE_LEN(len);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  782) 	gen_pool_free(ghes_estatus_pool, (unsigned long)cache, len);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  783) 	atomic_dec(&ghes_estatus_cache_alloced);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  784) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  785) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  786) static void ghes_estatus_cache_rcu_free(struct rcu_head *head)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  787) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  788) 	struct ghes_estatus_cache *cache;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  789) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  790) 	cache = container_of(head, struct ghes_estatus_cache, rcu);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  791) 	ghes_estatus_cache_free(cache);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  792) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  793) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  794) static void ghes_estatus_cache_add(
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  795) 	struct acpi_hest_generic *generic,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  796) 	struct acpi_hest_generic_status *estatus)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  797) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  798) 	int i, slot = -1, count;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  799) 	unsigned long long now, duration, period, max_period = 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  800) 	struct ghes_estatus_cache *cache, *slot_cache = NULL, *new_cache;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  801) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  802) 	new_cache = ghes_estatus_cache_alloc(generic, estatus);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  803) 	if (new_cache == NULL)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  804) 		return;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  805) 	rcu_read_lock();
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  806) 	now = sched_clock();
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  807) 	for (i = 0; i < GHES_ESTATUS_CACHES_SIZE; i++) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  808) 		cache = rcu_dereference(ghes_estatus_caches[i]);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  809) 		if (cache == NULL) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  810) 			slot = i;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  811) 			slot_cache = NULL;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  812) 			break;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  813) 		}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  814) 		duration = now - cache->time_in;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  815) 		if (duration >= GHES_ESTATUS_IN_CACHE_MAX_NSEC) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  816) 			slot = i;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  817) 			slot_cache = cache;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  818) 			break;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  819) 		}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  820) 		count = atomic_read(&cache->count);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  821) 		period = duration;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  822) 		do_div(period, (count + 1));
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  823) 		if (period > max_period) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  824) 			max_period = period;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  825) 			slot = i;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  826) 			slot_cache = cache;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  827) 		}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  828) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  829) 	/* new_cache must be put into array after its contents are written */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  830) 	smp_wmb();
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  831) 	if (slot != -1 && cmpxchg(ghes_estatus_caches + slot,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  832) 				  slot_cache, new_cache) == slot_cache) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  833) 		if (slot_cache)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  834) 			call_rcu(&slot_cache->rcu, ghes_estatus_cache_rcu_free);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  835) 	} else
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  836) 		ghes_estatus_cache_free(new_cache);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  837) 	rcu_read_unlock();
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  838) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  839) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  840) static void __ghes_panic(struct ghes *ghes,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  841) 			 struct acpi_hest_generic_status *estatus,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  842) 			 u64 buf_paddr, enum fixed_addresses fixmap_idx)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  843) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  844) 	__ghes_print_estatus(KERN_EMERG, ghes->generic, estatus);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  845) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  846) 	ghes_clear_estatus(ghes, estatus, buf_paddr, fixmap_idx);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  847) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  848) 	/* reboot to log the error! */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  849) 	if (!panic_timeout)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  850) 		panic_timeout = ghes_panic_timeout;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  851) 	panic("Fatal hardware error!");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  852) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  853) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  854) static int ghes_proc(struct ghes *ghes)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  855) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  856) 	struct acpi_hest_generic_status *estatus = ghes->estatus;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  857) 	u64 buf_paddr;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  858) 	int rc;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  859) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  860) 	rc = ghes_read_estatus(ghes, estatus, &buf_paddr, FIX_APEI_GHES_IRQ);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  861) 	if (rc)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  862) 		goto out;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  863) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  864) 	if (ghes_severity(estatus->error_severity) >= GHES_SEV_PANIC)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  865) 		__ghes_panic(ghes, estatus, buf_paddr, FIX_APEI_GHES_IRQ);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  866) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  867) 	if (!ghes_estatus_cached(estatus)) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  868) 		if (ghes_print_estatus(NULL, ghes->generic, estatus))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  869) 			ghes_estatus_cache_add(ghes->generic, estatus);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  870) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  871) 	ghes_do_proc(ghes, estatus);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  872) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  873) out:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  874) 	ghes_clear_estatus(ghes, estatus, buf_paddr, FIX_APEI_GHES_IRQ);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  875) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  876) 	return rc;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  877) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  878) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  879) static void ghes_add_timer(struct ghes *ghes)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  880) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  881) 	struct acpi_hest_generic *g = ghes->generic;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  882) 	unsigned long expire;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  883) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  884) 	if (!g->notify.poll_interval) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  885) 		pr_warn(FW_WARN GHES_PFX "Poll interval is 0 for generic hardware error source: %d, disabled.\n",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  886) 			g->header.source_id);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  887) 		return;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  888) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  889) 	expire = jiffies + msecs_to_jiffies(g->notify.poll_interval);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  890) 	ghes->timer.expires = round_jiffies_relative(expire);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  891) 	add_timer(&ghes->timer);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  892) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  893) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  894) static void ghes_poll_func(struct timer_list *t)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  895) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  896) 	struct ghes *ghes = from_timer(ghes, t, timer);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  897) 	unsigned long flags;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  898) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  899) 	spin_lock_irqsave(&ghes_notify_lock_irq, flags);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  900) 	ghes_proc(ghes);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  901) 	spin_unlock_irqrestore(&ghes_notify_lock_irq, flags);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  902) 	if (!(ghes->flags & GHES_EXITING))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  903) 		ghes_add_timer(ghes);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  904) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  905) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  906) static irqreturn_t ghes_irq_func(int irq, void *data)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  907) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  908) 	struct ghes *ghes = data;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  909) 	unsigned long flags;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  910) 	int rc;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  911) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  912) 	spin_lock_irqsave(&ghes_notify_lock_irq, flags);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  913) 	rc = ghes_proc(ghes);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  914) 	spin_unlock_irqrestore(&ghes_notify_lock_irq, flags);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  915) 	if (rc)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  916) 		return IRQ_NONE;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  917) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  918) 	return IRQ_HANDLED;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  919) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  920) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  921) static int ghes_notify_hed(struct notifier_block *this, unsigned long event,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  922) 			   void *data)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  923) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  924) 	struct ghes *ghes;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  925) 	unsigned long flags;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  926) 	int ret = NOTIFY_DONE;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  927) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  928) 	spin_lock_irqsave(&ghes_notify_lock_irq, flags);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  929) 	rcu_read_lock();
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  930) 	list_for_each_entry_rcu(ghes, &ghes_hed, list) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  931) 		if (!ghes_proc(ghes))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  932) 			ret = NOTIFY_OK;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  933) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  934) 	rcu_read_unlock();
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  935) 	spin_unlock_irqrestore(&ghes_notify_lock_irq, flags);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  936) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  937) 	return ret;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  938) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  939) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  940) static struct notifier_block ghes_notifier_hed = {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  941) 	.notifier_call = ghes_notify_hed,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  942) };
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  943) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  944) /*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  945)  * Handlers for CPER records may not be NMI safe. For example,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  946)  * memory_failure_queue() takes spinlocks and calls schedule_work_on().
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  947)  * In any NMI-like handler, memory from ghes_estatus_pool is used to save
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  948)  * estatus, and added to the ghes_estatus_llist. irq_work_queue() causes
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  949)  * ghes_proc_in_irq() to run in IRQ context where each estatus in
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  950)  * ghes_estatus_llist is processed.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  951)  *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  952)  * Memory from the ghes_estatus_pool is also used with the ghes_estatus_cache
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  953)  * to suppress frequent messages.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  954)  */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  955) static struct llist_head ghes_estatus_llist;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  956) static struct irq_work ghes_proc_irq_work;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  957) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  958) static void ghes_proc_in_irq(struct irq_work *irq_work)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  959) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  960) 	struct llist_node *llnode, *next;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  961) 	struct ghes_estatus_node *estatus_node;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  962) 	struct acpi_hest_generic *generic;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  963) 	struct acpi_hest_generic_status *estatus;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  964) 	bool task_work_pending;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  965) 	u32 len, node_len;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  966) 	int ret;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  967) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  968) 	llnode = llist_del_all(&ghes_estatus_llist);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  969) 	/*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  970) 	 * Because the time order of estatus in list is reversed,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  971) 	 * revert it back to proper order.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  972) 	 */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  973) 	llnode = llist_reverse_order(llnode);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  974) 	while (llnode) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  975) 		next = llnode->next;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  976) 		estatus_node = llist_entry(llnode, struct ghes_estatus_node,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  977) 					   llnode);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  978) 		estatus = GHES_ESTATUS_FROM_NODE(estatus_node);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  979) 		len = cper_estatus_len(estatus);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  980) 		node_len = GHES_ESTATUS_NODE_LEN(len);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  981) 		task_work_pending = ghes_do_proc(estatus_node->ghes, estatus);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  982) 		if (!ghes_estatus_cached(estatus)) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  983) 			generic = estatus_node->generic;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  984) 			if (ghes_print_estatus(NULL, generic, estatus))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  985) 				ghes_estatus_cache_add(generic, estatus);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  986) 		}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  987) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  988) 		if (task_work_pending && current->mm != &init_mm) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  989) 			estatus_node->task_work.func = ghes_kick_task_work;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  990) 			estatus_node->task_work_cpu = smp_processor_id();
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  991) 			ret = task_work_add(current, &estatus_node->task_work,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  992) 					    TWA_RESUME);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  993) 			if (ret)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  994) 				estatus_node->task_work.func = NULL;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  995) 		}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  996) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  997) 		if (!estatus_node->task_work.func)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  998) 			gen_pool_free(ghes_estatus_pool,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  999) 				      (unsigned long)estatus_node, node_len);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1000) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1001) 		llnode = next;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1002) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1003) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1004) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1005) static void ghes_print_queued_estatus(void)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1006) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1007) 	struct llist_node *llnode;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1008) 	struct ghes_estatus_node *estatus_node;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1009) 	struct acpi_hest_generic *generic;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1010) 	struct acpi_hest_generic_status *estatus;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1011) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1012) 	llnode = llist_del_all(&ghes_estatus_llist);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1013) 	/*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1014) 	 * Because the time order of estatus in list is reversed,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1015) 	 * revert it back to proper order.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1016) 	 */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1017) 	llnode = llist_reverse_order(llnode);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1018) 	while (llnode) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1019) 		estatus_node = llist_entry(llnode, struct ghes_estatus_node,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1020) 					   llnode);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1021) 		estatus = GHES_ESTATUS_FROM_NODE(estatus_node);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1022) 		generic = estatus_node->generic;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1023) 		ghes_print_estatus(NULL, generic, estatus);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1024) 		llnode = llnode->next;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1025) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1026) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1027) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1028) static int ghes_in_nmi_queue_one_entry(struct ghes *ghes,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1029) 				       enum fixed_addresses fixmap_idx)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1030) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1031) 	struct acpi_hest_generic_status *estatus, tmp_header;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1032) 	struct ghes_estatus_node *estatus_node;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1033) 	u32 len, node_len;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1034) 	u64 buf_paddr;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1035) 	int sev, rc;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1036) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1037) 	if (!IS_ENABLED(CONFIG_ARCH_HAVE_NMI_SAFE_CMPXCHG))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1038) 		return -EOPNOTSUPP;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1039) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1040) 	rc = __ghes_peek_estatus(ghes, &tmp_header, &buf_paddr, fixmap_idx);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1041) 	if (rc) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1042) 		ghes_clear_estatus(ghes, &tmp_header, buf_paddr, fixmap_idx);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1043) 		return rc;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1044) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1045) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1046) 	rc = __ghes_check_estatus(ghes, &tmp_header);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1047) 	if (rc) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1048) 		ghes_clear_estatus(ghes, &tmp_header, buf_paddr, fixmap_idx);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1049) 		return rc;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1050) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1051) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1052) 	len = cper_estatus_len(&tmp_header);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1053) 	node_len = GHES_ESTATUS_NODE_LEN(len);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1054) 	estatus_node = (void *)gen_pool_alloc(ghes_estatus_pool, node_len);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1055) 	if (!estatus_node)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1056) 		return -ENOMEM;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1057) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1058) 	estatus_node->ghes = ghes;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1059) 	estatus_node->generic = ghes->generic;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1060) 	estatus_node->task_work.func = NULL;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1061) 	estatus = GHES_ESTATUS_FROM_NODE(estatus_node);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1062) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1063) 	if (__ghes_read_estatus(estatus, buf_paddr, fixmap_idx, len)) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1064) 		ghes_clear_estatus(ghes, estatus, buf_paddr, fixmap_idx);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1065) 		rc = -ENOENT;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1066) 		goto no_work;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1067) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1068) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1069) 	sev = ghes_severity(estatus->error_severity);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1070) 	if (sev >= GHES_SEV_PANIC) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1071) 		ghes_print_queued_estatus();
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1072) 		__ghes_panic(ghes, estatus, buf_paddr, fixmap_idx);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1073) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1074) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1075) 	ghes_clear_estatus(ghes, &tmp_header, buf_paddr, fixmap_idx);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1076) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1077) 	/* This error has been reported before, don't process it again. */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1078) 	if (ghes_estatus_cached(estatus))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1079) 		goto no_work;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1080) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1081) 	llist_add(&estatus_node->llnode, &ghes_estatus_llist);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1082) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1083) 	return rc;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1084) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1085) no_work:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1086) 	gen_pool_free(ghes_estatus_pool, (unsigned long)estatus_node,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1087) 		      node_len);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1088) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1089) 	return rc;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1090) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1091) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1092) static int ghes_in_nmi_spool_from_list(struct list_head *rcu_list,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1093) 				       enum fixed_addresses fixmap_idx)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1094) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1095) 	int ret = -ENOENT;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1096) 	struct ghes *ghes;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1097) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1098) 	rcu_read_lock();
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1099) 	list_for_each_entry_rcu(ghes, rcu_list, list) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1100) 		if (!ghes_in_nmi_queue_one_entry(ghes, fixmap_idx))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1101) 			ret = 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1102) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1103) 	rcu_read_unlock();
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1104) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1105) 	if (IS_ENABLED(CONFIG_ARCH_HAVE_NMI_SAFE_CMPXCHG) && !ret)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1106) 		irq_work_queue(&ghes_proc_irq_work);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1107) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1108) 	return ret;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1109) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1110) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1111) #ifdef CONFIG_ACPI_APEI_SEA
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1112) static LIST_HEAD(ghes_sea);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1113) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1114) /*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1115)  * Return 0 only if one of the SEA error sources successfully reported an error
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1116)  * record sent from the firmware.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1117)  */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1118) int ghes_notify_sea(void)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1119) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1120) 	static DEFINE_RAW_SPINLOCK(ghes_notify_lock_sea);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1121) 	int rv;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1122) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1123) 	raw_spin_lock(&ghes_notify_lock_sea);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1124) 	rv = ghes_in_nmi_spool_from_list(&ghes_sea, FIX_APEI_GHES_SEA);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1125) 	raw_spin_unlock(&ghes_notify_lock_sea);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1126) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1127) 	return rv;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1128) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1129) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1130) static void ghes_sea_add(struct ghes *ghes)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1131) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1132) 	mutex_lock(&ghes_list_mutex);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1133) 	list_add_rcu(&ghes->list, &ghes_sea);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1134) 	mutex_unlock(&ghes_list_mutex);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1135) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1136) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1137) static void ghes_sea_remove(struct ghes *ghes)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1138) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1139) 	mutex_lock(&ghes_list_mutex);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1140) 	list_del_rcu(&ghes->list);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1141) 	mutex_unlock(&ghes_list_mutex);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1142) 	synchronize_rcu();
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1143) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1144) #else /* CONFIG_ACPI_APEI_SEA */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1145) static inline void ghes_sea_add(struct ghes *ghes) { }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1146) static inline void ghes_sea_remove(struct ghes *ghes) { }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1147) #endif /* CONFIG_ACPI_APEI_SEA */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1148) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1149) #ifdef CONFIG_HAVE_ACPI_APEI_NMI
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1150) /*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1151)  * NMI may be triggered on any CPU, so ghes_in_nmi is used for
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1152)  * having only one concurrent reader.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1153)  */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1154) static atomic_t ghes_in_nmi = ATOMIC_INIT(0);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1155) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1156) static LIST_HEAD(ghes_nmi);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1157) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1158) static int ghes_notify_nmi(unsigned int cmd, struct pt_regs *regs)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1159) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1160) 	static DEFINE_RAW_SPINLOCK(ghes_notify_lock_nmi);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1161) 	int ret = NMI_DONE;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1162) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1163) 	if (!atomic_add_unless(&ghes_in_nmi, 1, 1))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1164) 		return ret;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1165) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1166) 	raw_spin_lock(&ghes_notify_lock_nmi);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1167) 	if (!ghes_in_nmi_spool_from_list(&ghes_nmi, FIX_APEI_GHES_NMI))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1168) 		ret = NMI_HANDLED;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1169) 	raw_spin_unlock(&ghes_notify_lock_nmi);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1170) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1171) 	atomic_dec(&ghes_in_nmi);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1172) 	return ret;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1173) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1174) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1175) static void ghes_nmi_add(struct ghes *ghes)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1176) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1177) 	mutex_lock(&ghes_list_mutex);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1178) 	if (list_empty(&ghes_nmi))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1179) 		register_nmi_handler(NMI_LOCAL, ghes_notify_nmi, 0, "ghes");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1180) 	list_add_rcu(&ghes->list, &ghes_nmi);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1181) 	mutex_unlock(&ghes_list_mutex);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1182) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1183) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1184) static void ghes_nmi_remove(struct ghes *ghes)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1185) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1186) 	mutex_lock(&ghes_list_mutex);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1187) 	list_del_rcu(&ghes->list);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1188) 	if (list_empty(&ghes_nmi))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1189) 		unregister_nmi_handler(NMI_LOCAL, "ghes");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1190) 	mutex_unlock(&ghes_list_mutex);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1191) 	/*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1192) 	 * To synchronize with NMI handler, ghes can only be
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1193) 	 * freed after NMI handler finishes.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1194) 	 */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1195) 	synchronize_rcu();
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1196) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1197) #else /* CONFIG_HAVE_ACPI_APEI_NMI */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1198) static inline void ghes_nmi_add(struct ghes *ghes) { }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1199) static inline void ghes_nmi_remove(struct ghes *ghes) { }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1200) #endif /* CONFIG_HAVE_ACPI_APEI_NMI */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1201) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1202) static void ghes_nmi_init_cxt(void)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1203) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1204) 	init_irq_work(&ghes_proc_irq_work, ghes_proc_in_irq);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1205) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1206) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1207) static int __ghes_sdei_callback(struct ghes *ghes,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1208) 				enum fixed_addresses fixmap_idx)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1209) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1210) 	if (!ghes_in_nmi_queue_one_entry(ghes, fixmap_idx)) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1211) 		irq_work_queue(&ghes_proc_irq_work);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1212) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1213) 		return 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1214) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1215) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1216) 	return -ENOENT;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1217) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1218) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1219) static int ghes_sdei_normal_callback(u32 event_num, struct pt_regs *regs,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1220) 				      void *arg)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1221) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1222) 	static DEFINE_RAW_SPINLOCK(ghes_notify_lock_sdei_normal);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1223) 	struct ghes *ghes = arg;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1224) 	int err;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1225) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1226) 	raw_spin_lock(&ghes_notify_lock_sdei_normal);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1227) 	err = __ghes_sdei_callback(ghes, FIX_APEI_GHES_SDEI_NORMAL);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1228) 	raw_spin_unlock(&ghes_notify_lock_sdei_normal);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1229) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1230) 	return err;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1231) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1232) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1233) static int ghes_sdei_critical_callback(u32 event_num, struct pt_regs *regs,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1234) 				       void *arg)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1235) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1236) 	static DEFINE_RAW_SPINLOCK(ghes_notify_lock_sdei_critical);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1237) 	struct ghes *ghes = arg;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1238) 	int err;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1239) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1240) 	raw_spin_lock(&ghes_notify_lock_sdei_critical);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1241) 	err = __ghes_sdei_callback(ghes, FIX_APEI_GHES_SDEI_CRITICAL);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1242) 	raw_spin_unlock(&ghes_notify_lock_sdei_critical);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1243) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1244) 	return err;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1245) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1246) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1247) static int apei_sdei_register_ghes(struct ghes *ghes)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1248) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1249) 	if (!IS_ENABLED(CONFIG_ARM_SDE_INTERFACE))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1250) 		return -EOPNOTSUPP;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1251) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1252) 	return sdei_register_ghes(ghes, ghes_sdei_normal_callback,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1253) 				 ghes_sdei_critical_callback);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1254) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1255) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1256) static int apei_sdei_unregister_ghes(struct ghes *ghes)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1257) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1258) 	if (!IS_ENABLED(CONFIG_ARM_SDE_INTERFACE))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1259) 		return -EOPNOTSUPP;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1260) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1261) 	return sdei_unregister_ghes(ghes);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1262) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1263) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1264) static int ghes_probe(struct platform_device *ghes_dev)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1265) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1266) 	struct acpi_hest_generic *generic;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1267) 	struct ghes *ghes = NULL;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1268) 	unsigned long flags;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1269) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1270) 	int rc = -EINVAL;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1271) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1272) 	generic = *(struct acpi_hest_generic **)ghes_dev->dev.platform_data;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1273) 	if (!generic->enabled)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1274) 		return -ENODEV;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1275) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1276) 	switch (generic->notify.type) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1277) 	case ACPI_HEST_NOTIFY_POLLED:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1278) 	case ACPI_HEST_NOTIFY_EXTERNAL:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1279) 	case ACPI_HEST_NOTIFY_SCI:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1280) 	case ACPI_HEST_NOTIFY_GSIV:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1281) 	case ACPI_HEST_NOTIFY_GPIO:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1282) 		break;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1283) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1284) 	case ACPI_HEST_NOTIFY_SEA:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1285) 		if (!IS_ENABLED(CONFIG_ACPI_APEI_SEA)) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1286) 			pr_warn(GHES_PFX "Generic hardware error source: %d notified via SEA is not supported\n",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1287) 				generic->header.source_id);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1288) 			rc = -ENOTSUPP;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1289) 			goto err;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1290) 		}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1291) 		break;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1292) 	case ACPI_HEST_NOTIFY_NMI:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1293) 		if (!IS_ENABLED(CONFIG_HAVE_ACPI_APEI_NMI)) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1294) 			pr_warn(GHES_PFX "Generic hardware error source: %d notified via NMI interrupt is not supported!\n",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1295) 				generic->header.source_id);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1296) 			goto err;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1297) 		}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1298) 		break;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1299) 	case ACPI_HEST_NOTIFY_SOFTWARE_DELEGATED:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1300) 		if (!IS_ENABLED(CONFIG_ARM_SDE_INTERFACE)) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1301) 			pr_warn(GHES_PFX "Generic hardware error source: %d notified via SDE Interface is not supported!\n",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1302) 				generic->header.source_id);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1303) 			goto err;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1304) 		}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1305) 		break;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1306) 	case ACPI_HEST_NOTIFY_LOCAL:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1307) 		pr_warn(GHES_PFX "Generic hardware error source: %d notified via local interrupt is not supported!\n",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1308) 			generic->header.source_id);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1309) 		goto err;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1310) 	default:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1311) 		pr_warn(FW_WARN GHES_PFX "Unknown notification type: %u for generic hardware error source: %d\n",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1312) 			generic->notify.type, generic->header.source_id);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1313) 		goto err;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1314) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1315) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1316) 	rc = -EIO;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1317) 	if (generic->error_block_length <
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1318) 	    sizeof(struct acpi_hest_generic_status)) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1319) 		pr_warn(FW_BUG GHES_PFX "Invalid error block length: %u for generic hardware error source: %d\n",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1320) 			generic->error_block_length, generic->header.source_id);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1321) 		goto err;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1322) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1323) 	ghes = ghes_new(generic);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1324) 	if (IS_ERR(ghes)) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1325) 		rc = PTR_ERR(ghes);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1326) 		ghes = NULL;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1327) 		goto err;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1328) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1329) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1330) 	switch (generic->notify.type) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1331) 	case ACPI_HEST_NOTIFY_POLLED:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1332) 		timer_setup(&ghes->timer, ghes_poll_func, 0);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1333) 		ghes_add_timer(ghes);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1334) 		break;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1335) 	case ACPI_HEST_NOTIFY_EXTERNAL:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1336) 		/* External interrupt vector is GSI */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1337) 		rc = acpi_gsi_to_irq(generic->notify.vector, &ghes->irq);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1338) 		if (rc) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1339) 			pr_err(GHES_PFX "Failed to map GSI to IRQ for generic hardware error source: %d\n",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1340) 			       generic->header.source_id);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1341) 			goto err;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1342) 		}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1343) 		rc = request_irq(ghes->irq, ghes_irq_func, IRQF_SHARED,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1344) 				 "GHES IRQ", ghes);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1345) 		if (rc) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1346) 			pr_err(GHES_PFX "Failed to register IRQ for generic hardware error source: %d\n",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1347) 			       generic->header.source_id);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1348) 			goto err;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1349) 		}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1350) 		break;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1351) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1352) 	case ACPI_HEST_NOTIFY_SCI:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1353) 	case ACPI_HEST_NOTIFY_GSIV:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1354) 	case ACPI_HEST_NOTIFY_GPIO:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1355) 		mutex_lock(&ghes_list_mutex);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1356) 		if (list_empty(&ghes_hed))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1357) 			register_acpi_hed_notifier(&ghes_notifier_hed);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1358) 		list_add_rcu(&ghes->list, &ghes_hed);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1359) 		mutex_unlock(&ghes_list_mutex);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1360) 		break;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1361) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1362) 	case ACPI_HEST_NOTIFY_SEA:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1363) 		ghes_sea_add(ghes);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1364) 		break;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1365) 	case ACPI_HEST_NOTIFY_NMI:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1366) 		ghes_nmi_add(ghes);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1367) 		break;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1368) 	case ACPI_HEST_NOTIFY_SOFTWARE_DELEGATED:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1369) 		rc = apei_sdei_register_ghes(ghes);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1370) 		if (rc)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1371) 			goto err;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1372) 		break;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1373) 	default:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1374) 		BUG();
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1375) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1376) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1377) 	platform_set_drvdata(ghes_dev, ghes);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1378) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1379) 	ghes_edac_register(ghes, &ghes_dev->dev);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1380) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1381) 	/* Handle any pending errors right away */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1382) 	spin_lock_irqsave(&ghes_notify_lock_irq, flags);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1383) 	ghes_proc(ghes);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1384) 	spin_unlock_irqrestore(&ghes_notify_lock_irq, flags);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1385) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1386) 	return 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1387) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1388) err:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1389) 	if (ghes) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1390) 		ghes_fini(ghes);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1391) 		kfree(ghes);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1392) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1393) 	return rc;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1394) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1395) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1396) static int ghes_remove(struct platform_device *ghes_dev)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1397) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1398) 	int rc;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1399) 	struct ghes *ghes;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1400) 	struct acpi_hest_generic *generic;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1401) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1402) 	ghes = platform_get_drvdata(ghes_dev);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1403) 	generic = ghes->generic;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1404) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1405) 	ghes->flags |= GHES_EXITING;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1406) 	switch (generic->notify.type) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1407) 	case ACPI_HEST_NOTIFY_POLLED:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1408) 		del_timer_sync(&ghes->timer);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1409) 		break;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1410) 	case ACPI_HEST_NOTIFY_EXTERNAL:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1411) 		free_irq(ghes->irq, ghes);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1412) 		break;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1413) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1414) 	case ACPI_HEST_NOTIFY_SCI:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1415) 	case ACPI_HEST_NOTIFY_GSIV:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1416) 	case ACPI_HEST_NOTIFY_GPIO:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1417) 		mutex_lock(&ghes_list_mutex);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1418) 		list_del_rcu(&ghes->list);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1419) 		if (list_empty(&ghes_hed))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1420) 			unregister_acpi_hed_notifier(&ghes_notifier_hed);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1421) 		mutex_unlock(&ghes_list_mutex);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1422) 		synchronize_rcu();
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1423) 		break;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1424) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1425) 	case ACPI_HEST_NOTIFY_SEA:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1426) 		ghes_sea_remove(ghes);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1427) 		break;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1428) 	case ACPI_HEST_NOTIFY_NMI:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1429) 		ghes_nmi_remove(ghes);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1430) 		break;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1431) 	case ACPI_HEST_NOTIFY_SOFTWARE_DELEGATED:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1432) 		rc = apei_sdei_unregister_ghes(ghes);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1433) 		if (rc)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1434) 			return rc;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1435) 		break;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1436) 	default:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1437) 		BUG();
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1438) 		break;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1439) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1440) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1441) 	ghes_fini(ghes);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1442) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1443) 	ghes_edac_unregister(ghes);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1444) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1445) 	kfree(ghes);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1446) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1447) 	platform_set_drvdata(ghes_dev, NULL);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1448) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1449) 	return 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1450) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1451) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1452) static struct platform_driver ghes_platform_driver = {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1453) 	.driver		= {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1454) 		.name	= "GHES",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1455) 	},
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1456) 	.probe		= ghes_probe,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1457) 	.remove		= ghes_remove,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1458) };
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1459) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1460) static int __init ghes_init(void)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1461) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1462) 	int rc;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1463) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1464) 	if (acpi_disabled)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1465) 		return -ENODEV;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1466) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1467) 	switch (hest_disable) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1468) 	case HEST_NOT_FOUND:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1469) 		return -ENODEV;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1470) 	case HEST_DISABLED:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1471) 		pr_info(GHES_PFX "HEST is not enabled!\n");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1472) 		return -EINVAL;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1473) 	default:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1474) 		break;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1475) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1476) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1477) 	if (ghes_disable) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1478) 		pr_info(GHES_PFX "GHES is not enabled!\n");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1479) 		return -EINVAL;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1480) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1481) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1482) 	ghes_nmi_init_cxt();
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1483) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1484) 	rc = platform_driver_register(&ghes_platform_driver);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1485) 	if (rc)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1486) 		goto err;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1487) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1488) 	rc = apei_osc_setup();
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1489) 	if (rc == 0 && osc_sb_apei_support_acked)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1490) 		pr_info(GHES_PFX "APEI firmware first mode is enabled by APEI bit and WHEA _OSC.\n");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1491) 	else if (rc == 0 && !osc_sb_apei_support_acked)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1492) 		pr_info(GHES_PFX "APEI firmware first mode is enabled by WHEA _OSC.\n");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1493) 	else if (rc && osc_sb_apei_support_acked)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1494) 		pr_info(GHES_PFX "APEI firmware first mode is enabled by APEI bit.\n");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1495) 	else
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1496) 		pr_info(GHES_PFX "Failed to enable APEI firmware first mode.\n");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1497) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1498) 	return 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1499) err:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1500) 	return rc;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1501) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1502) device_initcall(ghes_init);