Add a firmware-first CPER provider that reuses the shared GHES helpers, wire it into the RAS Kconfig/Makefile and document it in the admin guide.
Update MAINTAINERS now that the driver exists. Signed-off-by: Ahmed Tiba <[email protected]> --- Documentation/admin-guide/RAS/main.rst | 15 ++ MAINTAINERS | 1 + drivers/Makefile | 1 + drivers/acpi/Kconfig | 5 + drivers/acpi/acpi_extlog.c | 7 +- drivers/acpi/apei/Kconfig | 1 + drivers/acpi/apei/Makefile | 1 - drivers/acpi/apei/ghes.c | 9 +- drivers/acpi/apei/ghes_cper.c | 46 +++-- drivers/pci/pcie/aer.c | 4 +- drivers/ras/Kconfig | 13 ++ drivers/ras/Makefile | 1 + drivers/ras/cper-esource.c | 356 +++++++++++++++++++++++++++++++++ include/acpi/ghes_cper.h | 23 ++- include/cxl/event.h | 2 +- 15 files changed, 456 insertions(+), 29 deletions(-) diff --git a/Documentation/admin-guide/RAS/main.rst b/Documentation/admin-guide/RAS/main.rst index c1040e5a5b35..b75c27f1e3c1 100644 --- a/Documentation/admin-guide/RAS/main.rst +++ b/Documentation/admin-guide/RAS/main.rst @@ -205,6 +205,21 @@ Architecture (MCA)\ [#f3]_. .. [#f3] For more details about the Machine Check Architecture (MCA), please read Documentation/arch/x86/x86_64/machinecheck.rst at the Kernel tree. +Firmware-first CPER providers +----------------------------- + +Some systems expose Common Platform Error Record (CPER) data through +platform firmware, with the error source described in DeviceTree. +Enable ``CONFIG_RAS_CPER_ESOURCE`` to support those providers. The +current in-tree binding is +``Documentation/devicetree/bindings/firmware/arm,ras-cper.yaml``. + +The DeviceTree node describes the firmware-owned status buffer and ack +buffer used to exchange CPER data with the OS. The driver reuses the +shared GHES CPER handling helpers, so parsing, logging, notifier +delivery, and memory failure handling follow the same paths as ACPI +GHES whether the error source is described by ACPI or DeviceTree. + EDAC - Error Detection And Correction ************************************* diff --git a/MAINTAINERS b/MAINTAINERS index 8be23ad6d2c0..7426c0406ace 100644 --- a/MAINTAINERS +++ b/MAINTAINERS @@ -23405,6 +23405,7 @@ RAS ERROR STATUS M: Ahmed Tiba <[email protected]> S: Maintained F: Documentation/devicetree/bindings/firmware/arm,ras-cper.yaml +F: drivers/ras/cper-esource.c RAS INFRASTRUCTURE M: Tony Luck <[email protected]> diff --git a/drivers/Makefile b/drivers/Makefile index 27a664cb45ea..1a62b5aa718c 100644 --- a/drivers/Makefile +++ b/drivers/Makefile @@ -32,6 +32,7 @@ obj-y += char/ipmi/ obj-$(CONFIG_ACPI) += acpi/ obj-$(CONFIG_GHES_CPER_HELPERS) += acpi/apei/ghes_cper.o +obj-$(CONFIG_GHES_CPER_PCIEAER_HELPERS) += acpi/apei/ghes_helpers.o # PnP must come after ACPI since it will eventually need to check if acpi # was used and do nothing if so diff --git a/drivers/acpi/Kconfig b/drivers/acpi/Kconfig index 3cec674cf788..1687b819bdff 100644 --- a/drivers/acpi/Kconfig +++ b/drivers/acpi/Kconfig @@ -8,8 +8,13 @@ config ARCH_SUPPORTS_ACPI config GHES_CPER_HELPERS bool + select GENERIC_ALLOCATOR select UEFI_CPER +config GHES_CPER_PCIEAER_HELPERS + bool + depends on PCIEAER + menuconfig ACPI bool "ACPI (Advanced Configuration and Power Interface) Support" depends on ARCH_SUPPORTS_ACPI diff --git a/drivers/acpi/acpi_extlog.c b/drivers/acpi/acpi_extlog.c index bf5f7b1a9aea..27c32f7b1f08 100644 --- a/drivers/acpi/acpi_extlog.c +++ b/drivers/acpi/acpi_extlog.c @@ -235,9 +235,10 @@ static int extlog_print(struct notifier_block *nb, unsigned long val, struct cxl_cper_sec_prot_err *prot_err = acpi_hest_get_payload(gdata); - cxl_cper_post_prot_err(prot_err, - gdata->error_severity, - gdata->error_data_length); + if (IS_ENABLED(CONFIG_ACPI_APEI_PCIEAER)) + cxl_cper_post_prot_err(prot_err, + gdata->error_severity, + gdata->error_data_length); } else if (guid_equal(sec_type, &CPER_SEC_PCIE)) { struct cper_sec_pcie *pcie_err = acpi_hest_get_payload(gdata); diff --git a/drivers/acpi/apei/Kconfig b/drivers/acpi/apei/Kconfig index ddb62638eb02..3a858b10f14c 100644 --- a/drivers/acpi/apei/Kconfig +++ b/drivers/acpi/apei/Kconfig @@ -38,6 +38,7 @@ config ACPI_APEI_GHES config ACPI_APEI_PCIEAER bool "APEI PCIe AER logging/recovering support" depends on ACPI_APEI && PCIEAER + select GHES_CPER_PCIEAER_HELPERS help PCIe AER errors may be reported via APEI firmware first mode. Turn on this option to enable the corresponding support. diff --git a/drivers/acpi/apei/Makefile b/drivers/acpi/apei/Makefile index 66588d6be56f..378863dfec77 100644 --- a/drivers/acpi/apei/Makefile +++ b/drivers/acpi/apei/Makefile @@ -5,7 +5,6 @@ obj-$(CONFIG_ACPI_APEI_GHES) += ghes.o ifeq ($(CONFIG_COMPILE_TEST)_$(CONFIG_CC_IS_CLANG)_$(call clang-min-version, 180000),y_y_) KASAN_SANITIZE_ghes.o := n endif -obj-$(CONFIG_ACPI_APEI_PCIEAER) += ghes_helpers.o obj-$(CONFIG_ACPI_APEI_EINJ) += einj.o einj-y := einj-core.o einj-$(CONFIG_ACPI_APEI_EINJ_CXL) += einj-cxl.o diff --git a/drivers/acpi/apei/ghes.c b/drivers/acpi/apei/ghes.c index 3a3a864ac5f6..6833edd819de 100644 --- a/drivers/acpi/apei/ghes.c +++ b/drivers/acpi/apei/ghes.c @@ -114,8 +114,15 @@ static DEFINE_SPINLOCK(ghes_notify_lock_irq); static void ghes_do_proc(struct ghes *ghes, const struct acpi_hest_generic_status *estatus) { + unsigned int recovery = 0; + + if (IS_ENABLED(CONFIG_ACPI_APEI_MEMORY_FAILURE)) + recovery |= GHES_CPER_RECOVER_MEMORY; + if (IS_ENABLED(CONFIG_ACPI_APEI_PCIEAER)) + recovery |= GHES_CPER_RECOVER_PCIE; + ghes_cper_handle_status(ghes->dev, ghes->generic, - estatus, is_hest_sync_notify(ghes)); + estatus, is_hest_sync_notify(ghes), recovery); } static void __ghes_panic(struct ghes *ghes, diff --git a/drivers/acpi/apei/ghes_cper.c b/drivers/acpi/apei/ghes_cper.c index bceac27ac274..330150f43f5e 100644 --- a/drivers/acpi/apei/ghes_cper.c +++ b/drivers/acpi/apei/ghes_cper.c @@ -42,8 +42,10 @@ #include <acpi/acpi_io.h> #include <acpi/ghes_cper.h> +#ifdef CONFIG_ACPI_APEI #include <asm/fixmap.h> #include <asm/tlbflush.h> +#endif #include "apei-internal.h" @@ -169,12 +171,12 @@ static void memory_failure_cb(struct callback_head *twork) gen_pool_free(ghes_estatus_pool, (unsigned long)twcb, sizeof(*twcb)); } -static bool ghes_do_memory_failure(u64 physical_addr, int flags) +static bool ghes_do_memory_failure(u64 physical_addr, int flags, bool recover) { struct ghes_task_work *twcb; unsigned long pfn; - if (!IS_ENABLED(CONFIG_ACPI_APEI_MEMORY_FAILURE)) + if (!IS_ENABLED(CONFIG_MEMORY_FAILURE) || !recover) return false; pfn = PHYS_PFN(physical_addr); @@ -196,7 +198,7 @@ static bool ghes_do_memory_failure(u64 physical_addr, int flags) } bool ghes_handle_memory_failure(struct acpi_hest_generic_data *gdata, - int sev, bool sync) + int sev, bool sync, bool recover) { int flags = -1; int sec_sev = ghes_severity(gdata->error_severity); @@ -213,13 +215,14 @@ bool ghes_handle_memory_failure(struct acpi_hest_generic_data *gdata, flags = sync ? MF_ACTION_REQUIRED : 0; if (flags != -1) - return ghes_do_memory_failure(mem_err->physical_addr, flags); + return ghes_do_memory_failure(mem_err->physical_addr, flags, + recover); return false; } bool ghes_handle_arm_hw_error(struct acpi_hest_generic_data *gdata, - int sev, bool sync) + int sev, bool sync, bool recover) { struct cper_sec_proc_arm *err = acpi_hest_get_payload(gdata); int flags = sync ? MF_ACTION_REQUIRED : 0; @@ -270,7 +273,8 @@ bool ghes_handle_arm_hw_error(struct acpi_hest_generic_data *gdata, * and don't filter out 'corrected' error here. */ if (is_cache && has_pa) { - queued |= ghes_do_memory_failure(err_info->physical_fault_addr, flags); + queued |= ghes_do_memory_failure(err_info->physical_fault_addr, + flags, recover); p += err_info->length; continue; } @@ -304,11 +308,14 @@ bool ghes_handle_arm_hw_error(struct acpi_hest_generic_data *gdata, * GHES_SEV_PANIC does not make it to this handling since the kernel must * panic. */ -void ghes_handle_aer(struct acpi_hest_generic_data *gdata) +void ghes_handle_aer(struct acpi_hest_generic_data *gdata, bool recover) { -#ifdef CONFIG_ACPI_APEI_PCIEAER +#ifdef CONFIG_GHES_CPER_PCIEAER_HELPERS struct cper_sec_pcie *pcie_err = acpi_hest_get_payload(gdata); + if (!recover) + return; + if (gdata->error_data_length < sizeof(*pcie_err)) return; @@ -403,7 +410,7 @@ static u32 ghes_mem_err_min_len(u64 validation_bits) void ghes_cper_handle_status(struct device *dev, const struct acpi_hest_generic *generic, const struct acpi_hest_generic_status *estatus, - bool sync) + bool sync, unsigned int recovery) { int sev, sec_sev; struct acpi_hest_generic_data *gdata; @@ -451,16 +458,23 @@ void ghes_cper_handle_status(struct device *dev, atomic_notifier_call_chain(&ghes_report_chain, sev, mem_err); arch_apei_report_mem_error(sev, mem_err); - queued |= ghes_handle_memory_failure(gdata, sev, sync); + queued |= ghes_handle_memory_failure(gdata, sev, sync, + recovery & GHES_CPER_RECOVER_MEMORY); } else if (guid_equal(sec_type, &CPER_SEC_PCIE)) { - ghes_handle_aer(gdata); + ghes_handle_aer(gdata, + recovery & GHES_CPER_RECOVER_PCIE); } else if (guid_equal(sec_type, &CPER_SEC_PROC_ARM)) { - queued |= ghes_handle_arm_hw_error(gdata, sev, sync); + queued |= ghes_handle_arm_hw_error(gdata, sev, sync, + recovery & GHES_CPER_RECOVER_MEMORY); } else if (guid_equal(sec_type, &CPER_SEC_CXL_PROT_ERR)) { - struct cxl_cper_sec_prot_err *prot_err = acpi_hest_get_payload(gdata); + if (recovery & GHES_CPER_RECOVER_PCIE) { + struct cxl_cper_sec_prot_err *prot_err; - cxl_cper_post_prot_err(prot_err, gdata->error_severity, - gdata->error_data_length); + prot_err = acpi_hest_get_payload(gdata); + cxl_cper_post_prot_err(prot_err, + gdata->error_severity, + gdata->error_data_length); + } } else if (guid_equal(sec_type, &CPER_SEC_CXL_GEN_MEDIA_GUID)) { struct cxl_cper_event_rec *rec = acpi_hest_get_payload(gdata); @@ -868,7 +882,7 @@ struct work_struct *cxl_cper_prot_err_work; void cxl_cper_post_prot_err(struct cxl_cper_sec_prot_err *prot_err, int severity, u32 len) { -#ifdef CONFIG_ACPI_APEI_PCIEAER +#ifdef CONFIG_GHES_CPER_PCIEAER_HELPERS struct cxl_cper_prot_err_work_data wd; if (cxl_cper_sec_prot_err_valid(prot_err, len)) diff --git a/drivers/pci/pcie/aer.c b/drivers/pci/pcie/aer.c index 8708ca3257bb..ee41fd43e5fc 100644 --- a/drivers/pci/pcie/aer.c +++ b/drivers/pci/pcie/aer.c @@ -1014,7 +1014,7 @@ void aer_print_error(struct aer_err_info *info, int i) } } -#ifdef CONFIG_ACPI_APEI_PCIEAER +#ifdef CONFIG_GHES_CPER_PCIEAER_HELPERS int cper_severity_to_aer(int cper_severity) { switch (cper_severity) { @@ -1343,7 +1343,7 @@ static void handle_error_source(struct pci_dev *dev, struct aer_err_info *info) pci_aer_handle_error(dev, info); } -#ifdef CONFIG_ACPI_APEI_PCIEAER +#ifdef CONFIG_GHES_CPER_PCIEAER_HELPERS #define AER_RECOVER_RING_SIZE 16 diff --git a/drivers/ras/Kconfig b/drivers/ras/Kconfig index 070e17639faa..f416b71ea80a 100644 --- a/drivers/ras/Kconfig +++ b/drivers/ras/Kconfig @@ -56,6 +56,19 @@ config RAS_CEC_DEBUG source "drivers/ras/amd/atl/Kconfig" +config RAS_CPER_ESOURCE + bool "Firmware-first CPER error source block provider" + select GHES_CPER_HELPERS + select GHES_CPER_PCIEAER_HELPERS if PCIEAER + depends on OF_RESERVED_MEM && !CPU_BIG_ENDIAN + help + Enable support for firmware-first Common Platform Error Record + (CPER) error source block providers. The current in-tree user is + described by the arm,ras-cper DeviceTree binding. The driver + reuses the existing GHES CPER helpers so the error processing + matches the ACPI code paths, but it can be built even when ACPI is + disabled. + config RAS_FMPM tristate "FRU Memory Poison Manager" default m diff --git a/drivers/ras/Makefile b/drivers/ras/Makefile index 11f95d59d397..0de069557f31 100644 --- a/drivers/ras/Makefile +++ b/drivers/ras/Makefile @@ -2,6 +2,7 @@ obj-$(CONFIG_RAS) += ras.o obj-$(CONFIG_DEBUG_FS) += debugfs.o obj-$(CONFIG_RAS_CEC) += cec.o +obj-$(CONFIG_RAS_CPER_ESOURCE) += cper-esource.o obj-$(CONFIG_RAS_FMPM) += amd/fmpm.o obj-y += amd/atl/ diff --git a/drivers/ras/cper-esource.c b/drivers/ras/cper-esource.c new file mode 100644 index 000000000000..221b5f97e335 --- /dev/null +++ b/drivers/ras/cper-esource.c @@ -0,0 +1,356 @@ +// SPDX-License-Identifier: GPL-2.0-only +/* + * Firmware-first CPER error source provider. + * + * This driver shares the GHES CPER helpers so we keep the reporting and + * notifier behaviour identical to ACPI GHES. + * + * Copyright (C) 2026 ARM Ltd. + * Author: Ahmed Tiba <[email protected]> + */ + +#include <linux/bitops.h> +#include <linux/cper.h> +#include <linux/device-id/of.h> +#include <linux/idr.h> +#include <linux/interrupt.h> +#include <linux/io.h> +#include <linux/module.h> +#include <linux/mutex.h> +#include <linux/of_address.h> +#include <linux/of_reserved_mem.h> +#include <linux/panic.h> +#include <linux/platform_device.h> +#include <linux/slab.h> + +#include <acpi/ghes.h> +#include <acpi/ghes_cper.h> + +static DEFINE_IDA(cper_esource_source_ids); +static DEFINE_MUTEX(cper_esource_pool_lock); +static bool cper_esource_pool_ready; + +struct cper_esource_ack { + void __iomem *addr; + bool present; +}; + +struct cper_esource { + struct device *dev; + void __iomem *status; + size_t status_len; + + struct cper_esource_ack ack; + + struct acpi_hest_generic generic; + struct acpi_hest_generic_status *estatus; + + int irq; +}; + +static void __iomem *cper_esource_map_region(struct device *dev, + unsigned int index, size_t *size, + resource_size_t *start) +{ + resource_size_t resource_len; + struct resource res; + void __iomem *addr; + + if (of_reserved_mem_region_to_resource(dev->of_node, index, &res)) + return ERR_PTR(dev_err_probe(dev, -EINVAL, + "unable to resolve memory-region %u\n", + index)); + + resource_len = resource_size(&res); + if (!resource_len) + return ERR_PTR(dev_err_probe(dev, -EINVAL, + "memory-region %u has zero length\n", + index)); + if (resource_len > SIZE_MAX) + return ERR_PTR(dev_err_probe(dev, -EOVERFLOW, + "memory-region %u is too large\n", + index)); + + *size = resource_len; + if (start) + *start = res.start; + + addr = devm_ioremap(dev, res.start, *size); + if (!addr) + return ERR_PTR(dev_err_probe(dev, -ENOMEM, + "failed to map memory-region %u\n", + index)); + + return addr; +} + +static void cper_esource_release_source_id(void *data) +{ + struct cper_esource *ctx = data; + + ida_free(&cper_esource_source_ids, ctx->generic.header.source_id); +} + +static int cper_esource_init_pool(void) +{ + struct device_node *np; + unsigned int count = 0; + int rc = 0; + + mutex_lock(&cper_esource_pool_lock); + if (cper_esource_pool_ready) + goto out_unlock; + + for_each_compatible_node(np, NULL, "arm,ras-cper") + if (of_device_is_available(np)) + count++; + + rc = ghes_estatus_pool_init(count ?: 1); + if (!rc) + cper_esource_pool_ready = true; + +out_unlock: + mutex_unlock(&cper_esource_pool_lock); + return rc; +} + +static size_t cper_esource_estatus_len(struct acpi_hest_generic_status *estatus) +{ + if (estatus->raw_data_length) + return (size_t)estatus->raw_data_offset + + (size_t)estatus->raw_data_length; + else + return sizeof(*estatus) + (size_t)estatus->data_length; +} + +static int cper_esource_get_estatus_len(struct cper_esource *ctx, size_t *len) +{ + if (!ctx->estatus->block_status) + return -ENOENT; + + if (ctx->estatus->data_length > + ctx->status_len - sizeof(*ctx->estatus)) + return -EINVAL; + + if (cper_estatus_check_header(ctx->estatus)) + return -EINVAL; + + if (ctx->estatus->raw_data_length && + (ctx->estatus->raw_data_offset > ctx->status_len || + ctx->estatus->raw_data_length > + ctx->status_len - ctx->estatus->raw_data_offset)) + return -EINVAL; + + *len = cper_esource_estatus_len(ctx->estatus); + if (*len < sizeof(*ctx->estatus) || *len > ctx->status_len) + return -EINVAL; + + return 0; +} + +static void cper_esource_ack(struct cper_esource *ctx) +{ + u32 val; + + if (!ctx->ack.present) + return; + + val = readl(ctx->ack.addr); + writel(val | BIT(0), ctx->ack.addr); +} + +static void cper_esource_clear_status(struct cper_esource *ctx) +{ + ctx->estatus->block_status = 0; + writel(0, ctx->status); +} + +static void cper_esource_fatal(struct cper_esource *ctx) +{ + __ghes_print_estatus(KERN_EMERG, &ctx->generic, ctx->estatus); + add_taint(TAINT_MACHINE_CHECK, LOCKDEP_STILL_OK); + cper_esource_clear_status(ctx); + cper_esource_ack(ctx); + panic("GHES: fatal firmware-first CPER record from %s\n", + dev_name(ctx->dev)); +} + +static irqreturn_t cper_esource_process(struct cper_esource *ctx) +{ + unsigned int recovery = 0; + size_t estatus_len, snapshot_len; + int rc; + int sev; + + if (!readl(ctx->status)) + return IRQ_NONE; + + memcpy_fromio(ctx->estatus, ctx->status, sizeof(*ctx->estatus)); + + rc = cper_esource_get_estatus_len(ctx, &estatus_len); + if (rc == -ENOENT) + return IRQ_NONE; + if (rc) + goto invalid; + + memcpy_fromio(ctx->estatus, ctx->status, estatus_len); + rc = cper_esource_get_estatus_len(ctx, &snapshot_len); + if (rc || snapshot_len != estatus_len) + goto invalid; + if (cper_estatus_check(ctx->estatus)) + goto invalid; + + sev = ghes_severity(ctx->estatus->error_severity); + if (sev >= GHES_SEV_PANIC) + cper_esource_fatal(ctx); + + if (!ghes_estatus_cached(ctx->estatus) && + ghes_print_estatus(NULL, &ctx->generic, ctx->estatus)) + ghes_estatus_cache_add(&ctx->generic, ctx->estatus); + + if (IS_ENABLED(CONFIG_MEMORY_FAILURE)) + recovery |= GHES_CPER_RECOVER_MEMORY; + if (IS_ENABLED(CONFIG_PCIEAER)) + recovery |= GHES_CPER_RECOVER_PCIE; + + ghes_cper_handle_status(ctx->dev, &ctx->generic, ctx->estatus, false, + recovery); + cper_esource_clear_status(ctx); + cper_esource_ack(ctx); + + return IRQ_HANDLED; + +invalid: + dev_warn_ratelimited(ctx->dev, FW_WARN GHES_PFX + "Invalid error status block\n"); + cper_esource_clear_status(ctx); + cper_esource_ack(ctx); + return IRQ_HANDLED; +} + +static irqreturn_t cper_esource_irq(int irq, void *data) +{ + struct cper_esource *ctx = data; + + return cper_esource_process(ctx); +} + +static int cper_esource_init_ack(struct cper_esource *ctx) +{ + struct device *dev = ctx->dev; + resource_size_t start; + size_t size; + + ctx->ack.addr = cper_esource_map_region(dev, 1, &size, &start); + if (IS_ERR(ctx->ack.addr)) + return PTR_ERR(ctx->ack.addr); + + if (size < sizeof(u32)) + return dev_err_probe(dev, -EINVAL, + "ack resource is smaller than 4 bytes\n"); + if (!IS_ALIGNED(start, sizeof(u32))) + return dev_err_probe(dev, -EINVAL, + "ack resource is not naturally aligned\n"); + + ctx->ack.present = true; + return 0; +} + +static int cper_esource_probe(struct platform_device *pdev) +{ + struct device *dev = &pdev->dev; + struct cper_esource *ctx; + resource_size_t status_start; + size_t size; + int source_id; + int rc; + + ctx = devm_kzalloc(dev, sizeof(*ctx), GFP_KERNEL); + if (!ctx) + return -ENOMEM; + + ctx->dev = dev; + + ctx->status = cper_esource_map_region(dev, 0, &size, &status_start); + if (IS_ERR(ctx->status)) + return PTR_ERR(ctx->status); + + if (!IS_ALIGNED(status_start, sizeof(ctx->estatus->block_status))) + return dev_err_probe(dev, -EINVAL, + "status resource is not naturally aligned\n"); + + ctx->status_len = min_t(size_t, size, GHES_ESTATUS_MAX_SIZE); + if (size > ctx->status_len) + dev_warn(dev, "using the first %zu bytes of the status region\n", + ctx->status_len); + if (ctx->status_len < sizeof(*ctx->estatus)) + return dev_err_probe(dev, -EINVAL, + "status region is smaller than a CPER header\n"); + + rc = cper_esource_init_ack(ctx); + if (rc) + return rc; + + rc = cper_esource_init_pool(); + if (rc) + return rc; + + ctx->estatus = devm_kzalloc(dev, ctx->status_len, GFP_KERNEL); + if (!ctx->estatus) + return -ENOMEM; + + /* Keep source_id 0 unused so a zeroed header is never treated as valid. */ + source_id = ida_alloc_min(&cper_esource_source_ids, 1, GFP_KERNEL); + if (source_id < 0) + return source_id; + if (source_id > U16_MAX) { + ida_free(&cper_esource_source_ids, source_id); + return -ENOSPC; + } + + ctx->generic.header.type = ACPI_HEST_TYPE_GENERIC_ERROR; + ctx->generic.header.source_id = source_id; + + rc = devm_add_action_or_reset(dev, cper_esource_release_source_id, + ctx); + if (rc) + return rc; + + ctx->generic.notify.type = ACPI_HEST_NOTIFY_EXTERNAL; + ctx->generic.error_block_length = ctx->status_len; + + ctx->irq = platform_get_irq(pdev, 0); + if (ctx->irq < 0) + return ctx->irq; + + rc = devm_request_irq(dev, ctx->irq, cper_esource_irq, 0, + dev_name(dev), ctx); + if (rc) + return dev_err_probe(dev, rc, "failed to request interrupt\n"); + + disable_irq(ctx->irq); + cper_esource_process(ctx); + enable_irq(ctx->irq); + + return 0; +} + +static const struct of_device_id cper_esource_of_match[] = { + { .compatible = "arm,ras-cper" }, + { /* sentinel */ } +}; +MODULE_DEVICE_TABLE(of, cper_esource_of_match); + +static struct platform_driver cper_esource_driver = { + .driver = { + .name = "cper-esource", + .of_match_table = cper_esource_of_match, + }, + .probe = cper_esource_probe, +}; + +module_platform_driver(cper_esource_driver); + +MODULE_AUTHOR("Ahmed Tiba <[email protected]>"); +MODULE_DESCRIPTION("Firmware-first CPER provider"); +MODULE_LICENSE("GPL"); diff --git a/include/acpi/ghes_cper.h b/include/acpi/ghes_cper.h index eb07ec98cc94..8183652257a4 100644 --- a/include/acpi/ghes_cper.h +++ b/include/acpi/ghes_cper.h @@ -16,14 +16,18 @@ #ifndef ACPI_APEI_GHES_CPER_H #define ACPI_APEI_GHES_CPER_H +#include <linux/bits.h> #include <linux/device.h> #include <linux/notifier.h> #include <linux/workqueue.h> #include <acpi/ghes.h> -#include <asm/fixmap.h> #include <cxl/event.h> +#ifdef CONFIG_ACPI_APEI +#include <asm/fixmap.h> +#endif + #define GHES_PFX "GHES: " #define GHES_ESTATUS_MAX_SIZE 65536 @@ -40,6 +44,11 @@ /* Prevent too many caches are allocated because of RCU */ #define GHES_ESTATUS_CACHE_ALLOCED_MAX (GHES_ESTATUS_CACHES_SIZE * 3 / 2) +enum ghes_cper_recovery { + GHES_CPER_RECOVER_MEMORY = BIT(0), + GHES_CPER_RECOVER_PCIE = BIT(1), +}; + #define GHES_ESTATUS_CACHE_LEN(estatus_len) \ (sizeof(struct ghes_estatus_cache) + (estatus_len)) #define GHES_ESTATUS_FROM_CACHE(estatus_cache) \ @@ -108,14 +117,18 @@ void ghes_clear_estatus(struct ghes *ghes, int ghes_estatus_cached(struct acpi_hest_generic_status *estatus); void ghes_estatus_cache_add(struct acpi_hest_generic *generic, struct acpi_hest_generic_status *estatus); +int ghes_register_vendor_record_notifier(struct notifier_block *nb); +void ghes_unregister_vendor_record_notifier(struct notifier_block *nb); +int devm_ghes_register_vendor_record_notifier(struct device *dev, + struct notifier_block *nb); void ghes_defer_non_standard_event(struct acpi_hest_generic_data *gdata, int sev); int ghes_severity(int severity); bool ghes_handle_memory_failure(struct acpi_hest_generic_data *gdata, - int sev, bool sync); + int sev, bool sync, bool recover); bool ghes_handle_arm_hw_error(struct acpi_hest_generic_data *gdata, - int sev, bool sync); -void ghes_handle_aer(struct acpi_hest_generic_data *gdata); + int sev, bool sync, bool recover); +void ghes_handle_aer(struct acpi_hest_generic_data *gdata, bool recover); void ghes_log_hwerr(int sev, guid_t *sec_type); void __ghes_print_estatus(const char *pfx, const struct acpi_hest_generic *generic, @@ -126,7 +139,7 @@ int ghes_print_estatus(const char *pfx, void ghes_cper_handle_status(struct device *dev, const struct acpi_hest_generic *generic, const struct acpi_hest_generic_status *estatus, - bool sync); + bool sync, unsigned int recovery); void cxl_cper_post_prot_err(struct cxl_cper_sec_prot_err *prot_err, int severity, u32 len); void cxl_cper_register_prot_err_work(struct work_struct *work); diff --git a/include/cxl/event.h b/include/cxl/event.h index 91fb76d052b5..75d5e3013901 100644 --- a/include/cxl/event.h +++ b/include/cxl/event.h @@ -311,7 +311,7 @@ static inline int cxl_cper_prot_err_kfifo_get(struct cxl_cper_prot_err_work_data } #endif -#ifdef CONFIG_ACPI_APEI_PCIEAER +#ifdef CONFIG_GHES_CPER_PCIEAER_HELPERS int cxl_cper_sec_prot_err_valid(struct cxl_cper_sec_prot_err *prot_err, u32 len); int cxl_cper_setup_prot_err_work_data(struct cxl_cper_prot_err_work_data *wd, struct cxl_cper_sec_prot_err *prot_err, -- 2.43.0
