From: Badal Nilawar <badal.nilawar@intel.com>
To: intel-xe@lists.freedesktop.org
Cc: anshuman.gupta@intel.com, rodrigo.vivi@intel.com,
daniele.ceraolospurio@intel.com, raag.jadav@intel.com,
riana.tauro@intel.com, mallesh.koujalagi@intel.com,
aravind.iddamsetty@intel.com, michal.wajdeczko@intel.com,
himal.prasad.ghimiray@intel.com, arvind.yadav@intel.com
Subject: [PATCH v2 04/11] drm/xe/cper: APIs to prepare and log CPER record
Date: Tue, 25 Aug 2026 23:29:21 +0530 [thread overview]
Message-ID: <20260825175916.1103841-17-badal.nilawar@intel.com> (raw)
In-Reply-To: <20260825175916.1103841-13-badal.nilawar@intel.com>
Add APIs to initialize Intel-specific CPER metadata, build a
non-standard CPER record, and emit it via the xe_error_cper tracepoint.
Signed-off-by: Badal Nilawar <badal.nilawar@intel.com>
Assisted-by: Copilot:claude-sonnet-4.6
---
drivers/gpu/drm/xe/Makefile | 5 +-
drivers/gpu/drm/xe/regs/xe_regs.h | 2 +
drivers/gpu/drm/xe/xe_cper.c | 184 ++++++++++++++++++++++++++++++
drivers/gpu/drm/xe/xe_cper.h | 34 ++++++
4 files changed, 224 insertions(+), 1 deletion(-)
create mode 100644 drivers/gpu/drm/xe/xe_cper.c
create mode 100644 drivers/gpu/drm/xe/xe_cper.h
diff --git a/drivers/gpu/drm/xe/Makefile b/drivers/gpu/drm/xe/Makefile
index 3ed60697f3f3..c7d13bb090a6 100644
--- a/drivers/gpu/drm/xe/Makefile
+++ b/drivers/gpu/drm/xe/Makefile
@@ -136,7 +136,6 @@ xe-y += xe_bb.o \
xe_tlb_inval_job.o \
xe_trace.o \
xe_trace_bo.o \
- xe_trace_cper.o \
xe_trace_guc.o \
xe_trace_lrc.o \
xe_ttm_stolen_mgr.o \
@@ -165,6 +164,10 @@ xe-$(CONFIG_HWMON) += xe_hwmon.o
xe-$(CONFIG_PERF_EVENTS) += xe_pmu.o
xe-$(CONFIG_CONFIGFS_FS) += xe_configfs.o
+xe-$(CONFIG_UEFI_CPER_X86) += \
+ xe_cper.o \
+ xe_trace_cper.o
+
# graphics virtualization (SR-IOV) support
xe-y += \
xe_gt_sriov_vf.o \
diff --git a/drivers/gpu/drm/xe/regs/xe_regs.h b/drivers/gpu/drm/xe/regs/xe_regs.h
index ef4746b7b5d3..580c3dad858a 100644
--- a/drivers/gpu/drm/xe/regs/xe_regs.h
+++ b/drivers/gpu/drm/xe/regs/xe_regs.h
@@ -30,6 +30,8 @@
#define XEHP_MTCFG_ADDR XE_REG(0x101800)
#define TILE_COUNT REG_GENMASK(15, 8)
+#define CRI_FRU_ID XE_REG(0x102008)
+
#define GGC XE_REG(0x108040)
#define GMS_MASK REG_GENMASK(15, 8)
#define GGMS_MASK REG_GENMASK(7, 6)
diff --git a/drivers/gpu/drm/xe/xe_cper.c b/drivers/gpu/drm/xe/xe_cper.c
new file mode 100644
index 000000000000..371537052de3
--- /dev/null
+++ b/drivers/gpu/drm/xe/xe_cper.c
@@ -0,0 +1,184 @@
+// SPDX-License-Identifier: MIT
+/*
+ * Copyright © 2026 Intel Corporation
+ */
+
+#include <linux/cper.h>
+#include <linux/ktime.h>
+#include <linux/module.h>
+#include <linux/pci.h>
+#include <linux/slab.h>
+#include <linux/string.h>
+
+#include <drm/drm_print.h>
+
+#include "regs/xe_regs.h"
+#include "xe_cper.h"
+#include "xe_cper_types.h"
+#include "xe_device.h"
+#include "xe_device_types.h"
+#include "xe_mmio.h"
+#include "xe_ras_types.h"
+#include "xe_trace_cper.h"
+
+static const struct xe_platform_id_entry xe_platform_ids[] = {
+ /* 0x674C platform/8086:674c */
+ { 0x674C, GUID_INIT(0x9046afe5, 0x9041, 0x5124,
+ 0x86, 0x14, 0x92, 0x55, 0x0d, 0x9e, 0x9d, 0xa6) },
+};
+
+static const guid_t *lookup_platform_id(const struct pci_dev *pdev)
+{
+ int i;
+
+ for (i = 0; i < ARRAY_SIZE(xe_platform_ids); i++)
+ if (xe_platform_ids[i].device_id == pdev->device)
+ return &xe_platform_ids[i].platform_id;
+ return NULL;
+}
+
+static guid_t read_fru_id(struct xe_device *xe)
+{
+ struct xe_mmio *mmio = xe_root_tile_mmio(xe);
+ guid_t guid = GUID_INIT(0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0);
+ u64 val;
+
+ val = xe_mmio_read64_2x32(mmio, CRI_FRU_ID);
+
+ memcpy(&guid, &val, sizeof(val));
+
+ return guid;
+}
+
+static void fill_fw_id(struct xe_device *xe, struct xe_cper_sec_intel_err_hdr *ihdr)
+{
+ /* TODO: populate ihdr->fw_id from firmware version queries */
+}
+
+/**
+ * xe_cper_init_intel_err_hdr - Populate an Intel CPER section header
+ * @xe: xe device instance
+ * @location: 12-byte error classification blob (cast from the source
+ * error class struct); pass %NULL if not applicable
+ * @first_timestamp: timestamp of the first occurrence; pass 0 if not available
+ * @sig_id: signal identifier for the error; pass %U32_MAX if not applicable
+ * @error_count: number of times this error has occurred
+ * @ihdr: Intel section header to populate
+ *
+ * Fills in @ihdr with the provided error metadata and sets the corresponding
+ * valid bits.
+ */
+void xe_cper_init_intel_err_hdr(struct xe_device *xe, const u8 location[12],
+ u64 first_timestamp, u32 sig_id,
+ u32 error_count, struct xe_cper_sec_intel_err_hdr *ihdr)
+{
+ if (location) {
+ memcpy(&ihdr->error_class, location, sizeof(ihdr->error_class));
+ ihdr->valid_bits.location = 1;
+ }
+
+ if (first_timestamp) {
+ ihdr->first_timestamp = first_timestamp;
+ ihdr->valid_bits.first_timestamp = 1;
+ }
+
+ if (sig_id != U32_MAX) {
+ ihdr->sig_id = sig_id;
+ ihdr->valid_bits.sig_id = 1;
+ }
+
+ ihdr->error_count = error_count;
+
+ strscpy(ihdr->pci_bdf, pci_name(to_pci_dev(xe->drm.dev)), sizeof(ihdr->pci_bdf));
+ ihdr->valid_bits.pci_bdf = 1;
+
+#ifdef MODULE
+ strscpy(ihdr->drv_version, THIS_MODULE->srcversion, sizeof(ihdr->drv_version));
+ ihdr->valid_bits.drv_version = 1;
+#else
+ ihdr->valid_bits.drv_version = 0;
+#endif
+
+ fill_fw_id(xe, ihdr);
+}
+
+/**
+ * xe_cper_record_emit - Build and emit a CPER record for an Intel GPU error
+ * @xe: xe device instance
+ * @notification_type: CPER notification type (INTEL_CPER_NOTIFY_*)
+ * @severity: CPER error severity (CPER_SEV_*)
+ * @ihdr: Intel-specific section header, fully populated by
+ * xe_cper_init_intel_err_hdr()
+ * @einfo: optional xe_cper_sec_intel_error_info payload; may be %NULL
+ * @einfo_size: byte size of @einfo, including any event_queue data
+ *
+ * The platform_id is resolved automatically from xe_platform_ids[] using
+ * the PCI device ID. If no entry matches, the field is left zeroed and
+ * the record is still emitted.
+ */
+void xe_cper_record_emit(struct xe_device *xe, u8 severity,
+ guid_t *notification_type,
+ struct xe_cper_sec_intel_err_hdr *ihdr,
+ const void *einfo, u32 einfo_len)
+{
+ struct pci_dev *pdev = to_pci_dev(xe->drm.dev);
+ const guid_t *platform_id = lookup_platform_id(pdev);
+ u32 total_len = sizeof(struct xe_cper_nonstd_record) + einfo_len;
+ struct cper_section_descriptor *sdesc;
+ struct cper_record_header *rhdr;
+ struct xe_cper_nonstd_record *rec;
+
+ rec = kzalloc(total_len, GFP_KERNEL);
+ if (!rec)
+ return;
+
+ rhdr = &rec->record_hdr;
+ sdesc = &rec->section_desc;
+
+ /* Assemble the CPER record header (UEFI Appendix N.2.1) */
+ memcpy(rhdr->signature, CPER_SIG_RECORD, CPER_SIG_SIZE);
+ rhdr->revision = CPER_RECORD_REV;
+ rhdr->signature_end = CPER_SIG_END;
+ rhdr->section_count = 1;
+ rhdr->error_severity = severity;
+ rhdr->validation_bits = CPER_VALID_TIMESTAMP;
+ rhdr->record_length = total_len;
+ rhdr->timestamp = ktime_get_real_seconds();
+ if (platform_id) {
+ rhdr->platform_id = *platform_id;
+ rhdr->validation_bits |= CPER_VALID_PLATFORM_ID;
+ }
+ rhdr->creator_id = INTEL_CPER_CREATOR_XEKMD;
+ rhdr->notification_type = *notification_type;
+ rhdr->record_id = cper_next_record_id();
+ rhdr->flags = 0;
+
+ /* Assemble the section descriptor (UEFI Appendix N.2.2) */
+ sdesc->section_offset = sizeof(struct cper_record_header) +
+ sizeof(struct cper_section_descriptor);
+ sdesc->section_length = sizeof(struct xe_cper_sec_intel_err_hdr) + einfo_len;
+ sdesc->revision = CPER_RECORD_REV;
+ /*
+ * Set validation_bits using CPER_SEC_VALID_FRU_ID / CPER_SEC_VALID_FRU_TEXT
+ * when the corresponding fields are populated.
+ */
+ sdesc->validation_bits = 0;
+ sdesc->reserved = 0;
+ sdesc->flags = 0;
+ sdesc->section_type = INTEL_CPER_SECTION_ACCEL_GENERIC;
+ sdesc->fru_id = read_fru_id(xe);
+ sdesc->validation_bits |= CPER_SEC_VALID_FRU_ID;
+ sdesc->section_severity = severity;
+
+ /* Copy the Intel-specific section header (updated with BDF/version) */
+ rec->intel_hdr = *ihdr;
+
+ /* Append optional variable-length error info */
+ if (einfo && einfo_len)
+ memcpy((u8 *)rec + sizeof(*rec), einfo, einfo_len);
+
+ trace_xe_error_cper(xe, &rhdr->platform_id, &sdesc->fru_id, severity,
+ &rec->intel_hdr, total_len, (u8 *)rec);
+
+ kfree(rec);
+}
diff --git a/drivers/gpu/drm/xe/xe_cper.h b/drivers/gpu/drm/xe/xe_cper.h
new file mode 100644
index 000000000000..4d852a487b65
--- /dev/null
+++ b/drivers/gpu/drm/xe/xe_cper.h
@@ -0,0 +1,34 @@
+/* SPDX-License-Identifier: MIT */
+/*
+ * Copyright © 2026 Intel Corporation
+ */
+
+#ifndef _XE_CPER_H_
+#define _XE_CPER_H_
+
+#include <linux/types.h>
+#include <linux/uuid.h>
+
+struct xe_cper_sec_intel_err_hdr;
+struct xe_device;
+
+#if IS_REACHABLE(CONFIG_UEFI_CPER_X86)
+void xe_cper_record_emit(struct xe_device *xe, u8 severity,
+ guid_t *notification_type,
+ struct xe_cper_sec_intel_err_hdr *ihdr,
+ const void *einfo, u32 einfo_size);
+
+void xe_cper_init_intel_err_hdr(struct xe_device *xe, const u8 location[12],
+ u64 first_timestamp, u32 sig_id, u32 error_count,
+ struct xe_cper_sec_intel_err_hdr *ihdr);
+#else
+static inline void xe_cper_record_emit(struct xe_device *xe, u8 severity,
+ guid_t *notification_type,
+ struct xe_cper_sec_intel_err_hdr *ihdr,
+ const void *einfo, u32 einfo_size) {}
+
+static inline void xe_cper_init_intel_err_hdr(struct xe_device *xe, const u8 location[12],
+ u64 first_timestamp, u32 sig_id, u32 error_count,
+ struct xe_cper_sec_intel_err_hdr *ihdr) {}
+#endif
+#endif /* _XE_CPER_H_ */
--
2.54.0
next prev parent reply other threads:[~2026-08-25 17:42 UTC|newest]
Thread overview: 35+ messages / expand[flat|nested] mbox.gz Atom feed top
2026-08-25 17:59 [PATCH v2 00/11] Add CPER logging support for CRI Badal Nilawar
2026-08-25 17:59 ` [PATCH v2 01/11] drm/xe/xe_ras: Add support to retrieve info queue data " Badal Nilawar
2026-08-25 17:53 ` sashiko-bot
2026-08-26 0:54 ` Rodrigo Vivi
2026-08-25 20:48 ` Michal Wajdeczko
2026-08-25 17:59 ` [PATCH v2 02/11] drm/xe/xe_ras: Refactor get_counter() to return response structure Badal Nilawar
2026-08-25 17:59 ` [PATCH v2 03/11] drm/xe/cper: Add CPER structures and trace event Badal Nilawar
2026-08-25 17:51 ` sashiko-bot
2026-08-28 15:23 ` Rodrigo Vivi
2026-08-25 17:59 ` Badal Nilawar [this message]
2026-08-25 18:02 ` [PATCH v2 04/11] drm/xe/cper: APIs to prepare and log CPER record sashiko-bot
2026-08-26 0:59 ` Rodrigo Vivi
2026-08-25 17:59 ` [PATCH v2 05/11] drm/xe/cper: Prepare Intel CPER error info from info queue Badal Nilawar
2026-08-25 17:54 ` sashiko-bot
2026-08-25 17:59 ` [PATCH v2 06/11] drm/xe/cper: Log CPER records for aggregate counter retrival Badal Nilawar
2026-08-25 17:55 ` sashiko-bot
2026-08-26 1:01 ` Rodrigo Vivi
2026-08-25 17:59 ` [PATCH v2 07/11] drm/xe/cper: Allow hardware error CPER reporting from xe_log Badal Nilawar
2026-08-25 17:54 ` sashiko-bot
2026-08-27 21:27 ` Michal Wajdeczko
2026-08-25 17:59 ` [PATCH v2 08/11] drm/xe/ras: Report device memory errors using SIGID Badal Nilawar
2026-08-25 17:58 ` sashiko-bot
2026-08-27 20:25 ` Michal Wajdeczko
2026-08-25 17:59 ` [PATCH v2 09/11] drm/xe/ras: Report core compute " Badal Nilawar
2026-08-25 17:55 ` sashiko-bot
2026-08-25 17:59 ` [PATCH v2 10/11] drm/xe/ras: Report soc internal " Badal Nilawar
2026-08-28 15:20 ` Rodrigo Vivi
2026-08-25 17:59 ` [PATCH v2 11/11] drm/xe/ras: Report correctable " Badal Nilawar
2026-08-25 18:03 ` sashiko-bot
2026-08-25 18:29 ` ✗ CI.checkpatch: warning for Add CPER logging support for CRI (rev2) Patchwork
2026-08-25 18:31 ` ✓ CI.KUnit: success " Patchwork
2026-08-25 19:25 ` ✓ Xe.CI.BAT: " Patchwork
2026-08-25 22:06 ` ✗ Xe.CI.FULL: failure " Patchwork
2026-08-26 19:50 ` [PATCH v2 00/11] Add CPER logging support for CRI Matt Roper
2026-08-27 20:12 ` Rodrigo Vivi
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=20260825175916.1103841-17-badal.nilawar@intel.com \
--to=badal.nilawar@intel.com \
--cc=anshuman.gupta@intel.com \
--cc=aravind.iddamsetty@intel.com \
--cc=arvind.yadav@intel.com \
--cc=daniele.ceraolospurio@intel.com \
--cc=himal.prasad.ghimiray@intel.com \
--cc=intel-xe@lists.freedesktop.org \
--cc=mallesh.koujalagi@intel.com \
--cc=michal.wajdeczko@intel.com \
--cc=raag.jadav@intel.com \
--cc=riana.tauro@intel.com \
--cc=rodrigo.vivi@intel.com \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.