1 // SPDX-License-Identifier: MIT
3 * Copyright © 2021-2022 Intel Corporation
6 #include <linux/types.h>
8 #include <drm/drm_print.h>
10 #include "gt/intel_engine_regs.h"
11 #include "gt/intel_gt.h"
12 #include "gt/intel_gt_mcr.h"
13 #include "gt/intel_gt_regs.h"
14 #include "gt/intel_lrc.h"
15 #include "guc_capture_fwif.h"
16 #include "intel_guc_capture.h"
17 #include "intel_guc_fwif.h"
18 #include "intel_guc_print.h"
20 #include "i915_gpu_error.h"
22 #include "i915_memcpy.h"
26 * Define all device tables of GuC error capture register lists
27 * NOTE: For engine-registers, GuC only needs the register offsets
28 * from the engine-mmio-base
30 #define COMMON_BASE_GLOBAL \
31 { FORCEWAKE_MT, 0, 0, "FORCEWAKE" }
33 #define COMMON_GEN8BASE_GLOBAL \
34 { ERROR_GEN6, 0, 0, "ERROR_GEN6" }, \
35 { DONE_REG, 0, 0, "DONE_REG" }, \
36 { HSW_GTT_CACHE_EN, 0, 0, "HSW_GTT_CACHE_EN" }
39 { GEN8_FAULT_TLB_DATA0, 0, 0, "GEN8_FAULT_TLB_DATA0" }, \
40 { GEN8_FAULT_TLB_DATA1, 0, 0, "GEN8_FAULT_TLB_DATA1" }
42 #define COMMON_GEN12BASE_GLOBAL \
43 { GEN12_FAULT_TLB_DATA0, 0, 0, "GEN12_FAULT_TLB_DATA0" }, \
44 { GEN12_FAULT_TLB_DATA1, 0, 0, "GEN12_FAULT_TLB_DATA1" }, \
45 { GEN12_AUX_ERR_DBG, 0, 0, "AUX_ERR_DBG" }, \
46 { GEN12_GAM_DONE, 0, 0, "GAM_DONE" }, \
47 { GEN12_RING_FAULT_REG, 0, 0, "FAULT_REG" }
49 #define COMMON_BASE_ENGINE_INSTANCE \
50 { RING_PSMI_CTL(0), 0, 0, "RC PSMI" }, \
51 { RING_ESR(0), 0, 0, "ESR" }, \
52 { RING_DMA_FADD(0), 0, 0, "RING_DMA_FADD_LDW" }, \
53 { RING_DMA_FADD_UDW(0), 0, 0, "RING_DMA_FADD_UDW" }, \
54 { RING_IPEIR(0), 0, 0, "IPEIR" }, \
55 { RING_IPEHR(0), 0, 0, "IPEHR" }, \
56 { RING_INSTPS(0), 0, 0, "INSTPS" }, \
57 { RING_BBADDR(0), 0, 0, "RING_BBADDR_LOW32" }, \
58 { RING_BBADDR_UDW(0), 0, 0, "RING_BBADDR_UP32" }, \
59 { RING_BBSTATE(0), 0, 0, "BB_STATE" }, \
60 { CCID(0), 0, 0, "CCID" }, \
61 { RING_ACTHD(0), 0, 0, "ACTHD_LDW" }, \
62 { RING_ACTHD_UDW(0), 0, 0, "ACTHD_UDW" }, \
63 { RING_INSTPM(0), 0, 0, "INSTPM" }, \
64 { RING_INSTDONE(0), 0, 0, "INSTDONE" }, \
65 { RING_NOPID(0), 0, 0, "RING_NOPID" }, \
66 { RING_START(0), 0, 0, "START" }, \
67 { RING_HEAD(0), 0, 0, "HEAD" }, \
68 { RING_TAIL(0), 0, 0, "TAIL" }, \
69 { RING_CTL(0), 0, 0, "CTL" }, \
70 { RING_MI_MODE(0), 0, 0, "MODE" }, \
71 { RING_CONTEXT_CONTROL(0), 0, 0, "RING_CONTEXT_CONTROL" }, \
72 { RING_HWS_PGA(0), 0, 0, "HWS" }, \
73 { RING_MODE_GEN7(0), 0, 0, "GFX_MODE" }, \
74 { GEN8_RING_PDP_LDW(0, 0), 0, 0, "PDP0_LDW" }, \
75 { GEN8_RING_PDP_UDW(0, 0), 0, 0, "PDP0_UDW" }, \
76 { GEN8_RING_PDP_LDW(0, 1), 0, 0, "PDP1_LDW" }, \
77 { GEN8_RING_PDP_UDW(0, 1), 0, 0, "PDP1_UDW" }, \
78 { GEN8_RING_PDP_LDW(0, 2), 0, 0, "PDP2_LDW" }, \
79 { GEN8_RING_PDP_UDW(0, 2), 0, 0, "PDP2_UDW" }, \
80 { GEN8_RING_PDP_LDW(0, 3), 0, 0, "PDP3_LDW" }, \
81 { GEN8_RING_PDP_UDW(0, 3), 0, 0, "PDP3_UDW" }
83 #define COMMON_BASE_HAS_EU \
86 #define COMMON_BASE_RENDER \
87 { GEN7_SC_INSTDONE, 0, 0, "GEN7_SC_INSTDONE" }
89 #define COMMON_GEN12BASE_RENDER \
90 { GEN12_SC_INSTDONE_EXTRA, 0, 0, "GEN12_SC_INSTDONE_EXTRA" }, \
91 { GEN12_SC_INSTDONE_EXTRA2, 0, 0, "GEN12_SC_INSTDONE_EXTRA2" }
93 #define COMMON_GEN12BASE_VEC \
94 { GEN12_SFC_DONE(0), 0, 0, "SFC_DONE[0]" }, \
95 { GEN12_SFC_DONE(1), 0, 0, "SFC_DONE[1]" }, \
96 { GEN12_SFC_DONE(2), 0, 0, "SFC_DONE[2]" }, \
97 { GEN12_SFC_DONE(3), 0, 0, "SFC_DONE[3]" }
100 static const struct __guc_mmio_reg_descr xe_lp_global_regs[] = {
102 COMMON_GEN8BASE_GLOBAL,
103 COMMON_GEN12BASE_GLOBAL,
106 /* XE_LP Render / Compute Per-Class */
107 static const struct __guc_mmio_reg_descr xe_lp_rc_class_regs[] = {
110 COMMON_GEN12BASE_RENDER,
113 /* GEN8+ Render / Compute Per-Engine-Instance */
114 static const struct __guc_mmio_reg_descr gen8_rc_inst_regs[] = {
115 COMMON_BASE_ENGINE_INSTANCE,
118 /* GEN8+ Media Decode/Encode Per-Engine-Instance */
119 static const struct __guc_mmio_reg_descr gen8_vd_inst_regs[] = {
120 COMMON_BASE_ENGINE_INSTANCE,
123 /* XE_LP Video Enhancement Per-Class */
124 static const struct __guc_mmio_reg_descr xe_lp_vec_class_regs[] = {
125 COMMON_GEN12BASE_VEC,
128 /* GEN8+ Video Enhancement Per-Engine-Instance */
129 static const struct __guc_mmio_reg_descr gen8_vec_inst_regs[] = {
130 COMMON_BASE_ENGINE_INSTANCE,
133 /* GEN8+ Blitter Per-Engine-Instance */
134 static const struct __guc_mmio_reg_descr gen8_blt_inst_regs[] = {
135 COMMON_BASE_ENGINE_INSTANCE,
138 /* XE_LP - GSC Per-Engine-Instance */
139 static const struct __guc_mmio_reg_descr xe_lp_gsc_inst_regs[] = {
140 COMMON_BASE_ENGINE_INSTANCE,
144 static const struct __guc_mmio_reg_descr gen8_global_regs[] = {
146 COMMON_GEN8BASE_GLOBAL,
150 static const struct __guc_mmio_reg_descr gen8_rc_class_regs[] = {
156 * Empty list to prevent warnings about unknown class/instance types
157 * as not all class/instanace types have entries on all platforms.
159 static const struct __guc_mmio_reg_descr empty_regs_list[] = {
162 #define TO_GCAP_DEF_OWNER(x) (GUC_CAPTURE_LIST_INDEX_##x)
163 #define TO_GCAP_DEF_TYPE(x) (GUC_CAPTURE_LIST_TYPE_##x)
164 #define MAKE_REGLIST(regslist, regsowner, regstype, class) \
167 ARRAY_SIZE(regslist), \
168 TO_GCAP_DEF_OWNER(regsowner), \
169 TO_GCAP_DEF_TYPE(regstype), \
175 static const struct __guc_mmio_reg_descr_group gen8_lists[] = {
176 MAKE_REGLIST(gen8_global_regs, PF, GLOBAL, 0),
177 MAKE_REGLIST(gen8_rc_class_regs, PF, ENGINE_CLASS, GUC_CAPTURE_LIST_CLASS_RENDER_COMPUTE),
178 MAKE_REGLIST(gen8_rc_inst_regs, PF, ENGINE_INSTANCE, GUC_CAPTURE_LIST_CLASS_RENDER_COMPUTE),
179 MAKE_REGLIST(empty_regs_list, PF, ENGINE_CLASS, GUC_CAPTURE_LIST_CLASS_VIDEO),
180 MAKE_REGLIST(gen8_vd_inst_regs, PF, ENGINE_INSTANCE, GUC_CAPTURE_LIST_CLASS_VIDEO),
181 MAKE_REGLIST(empty_regs_list, PF, ENGINE_CLASS, GUC_CAPTURE_LIST_CLASS_VIDEOENHANCE),
182 MAKE_REGLIST(gen8_vec_inst_regs, PF, ENGINE_INSTANCE, GUC_CAPTURE_LIST_CLASS_VIDEOENHANCE),
183 MAKE_REGLIST(empty_regs_list, PF, ENGINE_CLASS, GUC_CAPTURE_LIST_CLASS_BLITTER),
184 MAKE_REGLIST(gen8_blt_inst_regs, PF, ENGINE_INSTANCE, GUC_CAPTURE_LIST_CLASS_BLITTER),
185 MAKE_REGLIST(empty_regs_list, PF, ENGINE_CLASS, GUC_CAPTURE_LIST_CLASS_GSC_OTHER),
186 MAKE_REGLIST(empty_regs_list, PF, ENGINE_INSTANCE, GUC_CAPTURE_LIST_CLASS_GSC_OTHER),
190 static const struct __guc_mmio_reg_descr_group xe_lp_lists[] = {
191 MAKE_REGLIST(xe_lp_global_regs, PF, GLOBAL, 0),
192 MAKE_REGLIST(xe_lp_rc_class_regs, PF, ENGINE_CLASS, GUC_CAPTURE_LIST_CLASS_RENDER_COMPUTE),
193 MAKE_REGLIST(gen8_rc_inst_regs, PF, ENGINE_INSTANCE, GUC_CAPTURE_LIST_CLASS_RENDER_COMPUTE),
194 MAKE_REGLIST(empty_regs_list, PF, ENGINE_CLASS, GUC_CAPTURE_LIST_CLASS_VIDEO),
195 MAKE_REGLIST(gen8_vd_inst_regs, PF, ENGINE_INSTANCE, GUC_CAPTURE_LIST_CLASS_VIDEO),
196 MAKE_REGLIST(xe_lp_vec_class_regs, PF, ENGINE_CLASS, GUC_CAPTURE_LIST_CLASS_VIDEOENHANCE),
197 MAKE_REGLIST(gen8_vec_inst_regs, PF, ENGINE_INSTANCE, GUC_CAPTURE_LIST_CLASS_VIDEOENHANCE),
198 MAKE_REGLIST(empty_regs_list, PF, ENGINE_CLASS, GUC_CAPTURE_LIST_CLASS_BLITTER),
199 MAKE_REGLIST(gen8_blt_inst_regs, PF, ENGINE_INSTANCE, GUC_CAPTURE_LIST_CLASS_BLITTER),
200 MAKE_REGLIST(empty_regs_list, PF, ENGINE_CLASS, GUC_CAPTURE_LIST_CLASS_GSC_OTHER),
201 MAKE_REGLIST(xe_lp_gsc_inst_regs, PF, ENGINE_INSTANCE, GUC_CAPTURE_LIST_CLASS_GSC_OTHER),
205 static const struct __guc_mmio_reg_descr_group *
206 guc_capture_get_one_list(const struct __guc_mmio_reg_descr_group *reglists,
207 u32 owner, u32 type, u32 id)
214 for (i = 0; reglists[i].list; ++i) {
215 if (reglists[i].owner == owner && reglists[i].type == type &&
216 (reglists[i].engine == id || reglists[i].type == GUC_CAPTURE_LIST_TYPE_GLOBAL))
223 static struct __guc_mmio_reg_descr_group *
224 guc_capture_get_one_ext_list(struct __guc_mmio_reg_descr_group *reglists,
225 u32 owner, u32 type, u32 id)
232 for (i = 0; reglists[i].extlist; ++i) {
233 if (reglists[i].owner == owner && reglists[i].type == type &&
234 (reglists[i].engine == id || reglists[i].type == GUC_CAPTURE_LIST_TYPE_GLOBAL))
241 static void guc_capture_free_extlists(struct __guc_mmio_reg_descr_group *reglists)
248 while (reglists[i].extlist)
249 kfree(reglists[i++].extlist);
252 struct __ext_steer_reg {
257 static const struct __ext_steer_reg gen8_extregs[] = {
258 {"GEN8_SAMPLER_INSTDONE", GEN8_SAMPLER_INSTDONE},
259 {"GEN8_ROW_INSTDONE", GEN8_ROW_INSTDONE}
262 static const struct __ext_steer_reg xehpg_extregs[] = {
263 {"XEHPG_INSTDONE_GEOM_SVG", XEHPG_INSTDONE_GEOM_SVG}
266 static void __fill_ext_reg(struct __guc_mmio_reg_descr *ext,
267 const struct __ext_steer_reg *extlist,
268 int slice_id, int subslice_id)
270 ext->reg = _MMIO(i915_mmio_reg_offset(extlist->reg));
271 ext->flags = FIELD_PREP(GUC_REGSET_STEERING_GROUP, slice_id);
272 ext->flags |= FIELD_PREP(GUC_REGSET_STEERING_INSTANCE, subslice_id);
273 ext->regname = extlist->name;
277 __alloc_ext_regs(struct __guc_mmio_reg_descr_group *newlist,
278 const struct __guc_mmio_reg_descr_group *rootlist, int num_regs)
280 struct __guc_mmio_reg_descr *list;
282 list = kcalloc(num_regs, sizeof(struct __guc_mmio_reg_descr), GFP_KERNEL);
286 newlist->extlist = list;
287 newlist->num_regs = num_regs;
288 newlist->owner = rootlist->owner;
289 newlist->engine = rootlist->engine;
290 newlist->type = rootlist->type;
296 guc_capture_alloc_steered_lists(struct intel_guc *guc,
297 const struct __guc_mmio_reg_descr_group *lists)
299 struct intel_gt *gt = guc_to_gt(guc);
300 int slice, subslice, iter, i, num_steer_regs, num_tot_regs = 0;
301 const struct __guc_mmio_reg_descr_group *list;
302 struct __guc_mmio_reg_descr_group *extlists;
303 struct __guc_mmio_reg_descr *extarray;
304 struct sseu_dev_info *sseu;
305 bool has_xehpg_extregs;
307 /* steered registers currently only exist for the render-class */
308 list = guc_capture_get_one_list(lists, GUC_CAPTURE_LIST_INDEX_PF,
309 GUC_CAPTURE_LIST_TYPE_ENGINE_CLASS,
310 GUC_CAPTURE_LIST_CLASS_RENDER_COMPUTE);
311 /* skip if extlists was previously allocated */
312 if (!list || guc->capture->extlists)
315 has_xehpg_extregs = GRAPHICS_VER_FULL(gt->i915) >= IP_VER(12, 55);
317 num_steer_regs = ARRAY_SIZE(gen8_extregs);
318 if (has_xehpg_extregs)
319 num_steer_regs += ARRAY_SIZE(xehpg_extregs);
321 sseu = >->info.sseu;
322 for_each_ss_steering(iter, gt, slice, subslice)
323 num_tot_regs += num_steer_regs;
328 /* allocate an extra for an end marker */
329 extlists = kcalloc(2, sizeof(struct __guc_mmio_reg_descr_group), GFP_KERNEL);
333 if (__alloc_ext_regs(&extlists[0], list, num_tot_regs)) {
338 extarray = extlists[0].extlist;
339 for_each_ss_steering(iter, gt, slice, subslice) {
340 for (i = 0; i < ARRAY_SIZE(gen8_extregs); ++i) {
341 __fill_ext_reg(extarray, &gen8_extregs[i], slice, subslice);
345 if (has_xehpg_extregs) {
346 for (i = 0; i < ARRAY_SIZE(xehpg_extregs); ++i) {
347 __fill_ext_reg(extarray, &xehpg_extregs[i], slice, subslice);
353 guc_dbg(guc, "capture found %d ext-regs.\n", num_tot_regs);
354 guc->capture->extlists = extlists;
357 static const struct __guc_mmio_reg_descr_group *
358 guc_capture_get_device_reglist(struct intel_guc *guc)
360 struct drm_i915_private *i915 = guc_to_gt(guc)->i915;
361 const struct __guc_mmio_reg_descr_group *lists;
363 if (GRAPHICS_VER(i915) >= 12)
369 * For certain engine classes, there are slice and subslice
370 * level registers requiring steering. We allocate and populate
371 * these at init time based on hw config add it as an extension
372 * list at the end of the pre-populated render list.
374 guc_capture_alloc_steered_lists(guc, lists);
380 __stringify_type(u32 type)
383 case GUC_CAPTURE_LIST_TYPE_GLOBAL:
385 case GUC_CAPTURE_LIST_TYPE_ENGINE_CLASS:
387 case GUC_CAPTURE_LIST_TYPE_ENGINE_INSTANCE:
397 __stringify_engclass(u32 class)
400 case GUC_CAPTURE_LIST_CLASS_RENDER_COMPUTE:
401 return "Render/Compute";
402 case GUC_CAPTURE_LIST_CLASS_VIDEO:
404 case GUC_CAPTURE_LIST_CLASS_VIDEOENHANCE:
405 return "VideoEnhance";
406 case GUC_CAPTURE_LIST_CLASS_BLITTER:
408 case GUC_CAPTURE_LIST_CLASS_GSC_OTHER:
418 guc_capture_list_init(struct intel_guc *guc, u32 owner, u32 type, u32 classid,
419 struct guc_mmio_reg *ptr, u16 num_entries)
422 const struct __guc_mmio_reg_descr_group *reglists = guc->capture->reglists;
423 struct __guc_mmio_reg_descr_group *extlists = guc->capture->extlists;
424 const struct __guc_mmio_reg_descr_group *match;
425 struct __guc_mmio_reg_descr_group *matchext;
430 match = guc_capture_get_one_list(reglists, owner, type, classid);
434 for (i = 0; i < num_entries && i < match->num_regs; ++i) {
435 ptr[i].offset = match->list[i].reg.reg;
436 ptr[i].value = 0xDEADF00D;
437 ptr[i].flags = match->list[i].flags;
438 ptr[i].mask = match->list[i].mask;
441 matchext = guc_capture_get_one_ext_list(extlists, owner, type, classid);
443 for (i = match->num_regs, j = 0; i < num_entries &&
444 i < (match->num_regs + matchext->num_regs) &&
445 j < matchext->num_regs; ++i, ++j) {
446 ptr[i].offset = matchext->extlist[j].reg.reg;
447 ptr[i].value = 0xDEADF00D;
448 ptr[i].flags = matchext->extlist[j].flags;
449 ptr[i].mask = matchext->extlist[j].mask;
453 guc_dbg(guc, "Got short capture reglist init: %d out %d.\n", i, num_entries);
459 guc_cap_list_num_regs(struct intel_guc_state_capture *gc, u32 owner, u32 type, u32 classid)
461 const struct __guc_mmio_reg_descr_group *match;
462 struct __guc_mmio_reg_descr_group *matchext;
465 match = guc_capture_get_one_list(gc->reglists, owner, type, classid);
469 num_regs = match->num_regs;
471 matchext = guc_capture_get_one_ext_list(gc->extlists, owner, type, classid);
473 num_regs += matchext->num_regs;
479 guc_capture_getlistsize(struct intel_guc *guc, u32 owner, u32 type, u32 classid,
480 size_t *size, bool is_purpose_est)
482 struct intel_guc_state_capture *gc = guc->capture;
483 struct __guc_capture_ads_cache *cache = &gc->ads_cache[owner][type][classid];
487 guc_warn(guc, "No capture reglist for this device\n");
491 if (cache->is_valid) {
493 return cache->status;
496 if (!is_purpose_est && owner == GUC_CAPTURE_LIST_INDEX_PF &&
497 !guc_capture_get_one_list(gc->reglists, owner, type, classid)) {
498 if (type == GUC_CAPTURE_LIST_TYPE_GLOBAL)
499 guc_warn(guc, "Missing capture reglist: global!\n");
501 guc_warn(guc, "Missing capture reglist: %s(%u):%s(%u)!\n",
502 __stringify_type(type), type,
503 __stringify_engclass(classid), classid);
507 num_regs = guc_cap_list_num_regs(gc, owner, type, classid);
508 /* intentional empty lists can exist depending on hw config */
513 *size = PAGE_ALIGN((sizeof(struct guc_debug_capture_list)) +
514 (num_regs * sizeof(struct guc_mmio_reg)));
520 intel_guc_capture_getlistsize(struct intel_guc *guc, u32 owner, u32 type, u32 classid,
523 return guc_capture_getlistsize(guc, owner, type, classid, size, false);
526 static void guc_capture_create_prealloc_nodes(struct intel_guc *guc);
529 intel_guc_capture_getlist(struct intel_guc *guc, u32 owner, u32 type, u32 classid,
532 struct intel_guc_state_capture *gc = guc->capture;
533 struct __guc_capture_ads_cache *cache = &gc->ads_cache[owner][type][classid];
534 struct guc_debug_capture_list *listnode;
542 if (cache->is_valid) {
543 *outptr = cache->ptr;
544 return cache->status;
548 * ADS population of input registers is a good
549 * time to pre-allocate cachelist output nodes
551 guc_capture_create_prealloc_nodes(guc);
553 ret = intel_guc_capture_getlistsize(guc, owner, type, classid, &size);
555 cache->is_valid = true;
562 caplist = kzalloc(size, GFP_KERNEL);
564 guc_dbg(guc, "Failed to alloc cached register capture list");
568 /* populate capture list header */
570 num_regs = guc_cap_list_num_regs(guc->capture, owner, type, classid);
571 listnode = (struct guc_debug_capture_list *)tmp;
572 listnode->header.info = FIELD_PREP(GUC_CAPTURELISTHDR_NUMDESCR, (u32)num_regs);
574 /* populate list of register descriptor */
575 tmp += sizeof(struct guc_debug_capture_list);
576 guc_capture_list_init(guc, owner, type, classid, (struct guc_mmio_reg *)tmp, num_regs);
578 /* cache this list */
579 cache->is_valid = true;
580 cache->ptr = caplist;
590 intel_guc_capture_getnullheader(struct intel_guc *guc,
591 void **outptr, size_t *size)
593 struct intel_guc_state_capture *gc = guc->capture;
594 int tmp = sizeof(u32) * 4;
597 if (gc->ads_null_cache) {
598 *outptr = gc->ads_null_cache;
603 null_header = kzalloc(tmp, GFP_KERNEL);
605 guc_dbg(guc, "Failed to alloc cached register capture null list");
609 gc->ads_null_cache = null_header;
610 *outptr = null_header;
617 guc_capture_output_min_size_est(struct intel_guc *guc)
619 struct intel_gt *gt = guc_to_gt(guc);
620 struct intel_engine_cs *engine;
621 enum intel_engine_id id;
622 int worst_min_size = 0;
629 * If every single engine-instance suffered a failure in quick succession but
630 * were all unrelated, then a burst of multiple error-capture events would dump
631 * registers for every one engine instance, one at a time. In this case, GuC
632 * would even dump the global-registers repeatedly.
634 * For each engine instance, there would be 1 x guc_state_capture_group_t output
635 * followed by 3 x guc_state_capture_t lists. The latter is how the register
636 * dumps are split across different register types (where the '3' are global vs class
639 for_each_engine(engine, gt, id) {
640 worst_min_size += sizeof(struct guc_state_capture_group_header_t) +
641 (3 * sizeof(struct guc_state_capture_header_t));
643 if (!guc_capture_getlistsize(guc, 0, GUC_CAPTURE_LIST_TYPE_GLOBAL, 0, &tmp, true))
644 worst_min_size += tmp;
646 if (!guc_capture_getlistsize(guc, 0, GUC_CAPTURE_LIST_TYPE_ENGINE_CLASS,
647 engine->class, &tmp, true)) {
648 worst_min_size += tmp;
650 if (!guc_capture_getlistsize(guc, 0, GUC_CAPTURE_LIST_TYPE_ENGINE_INSTANCE,
651 engine->class, &tmp, true)) {
652 worst_min_size += tmp;
656 return worst_min_size;
660 * Add on a 3x multiplier to allow for multiple back-to-back captures occurring
661 * before the i915 can read the data out and process it
663 #define GUC_CAPTURE_OVERBUFFER_MULTIPLIER 3
665 static void check_guc_capture_size(struct intel_guc *guc)
667 int min_size = guc_capture_output_min_size_est(guc);
668 int spare_size = min_size * GUC_CAPTURE_OVERBUFFER_MULTIPLIER;
669 u32 buffer_size = intel_guc_log_section_size_capture(&guc->log);
672 * NOTE: min_size is much smaller than the capture region allocation (DG2: <80K vs 1MB)
673 * Additionally, its based on space needed to fit all engines getting reset at once
674 * within the same G2H handler task slot. This is very unlikely. However, if GuC really
675 * does run out of space for whatever reason, we will see an separate warning message
676 * when processing the G2H event capture-notification, search for:
677 * INTEL_GUC_STATE_CAPTURE_EVENT_STATUS_NOSPACE.
680 guc_warn(guc, "Failed to calculate error state capture buffer minimum size: %d!\n",
682 else if (min_size > buffer_size)
683 guc_warn(guc, "Error state capture buffer maybe small: %d < %d\n",
684 buffer_size, min_size);
685 else if (spare_size > buffer_size)
686 guc_dbg(guc, "Error state capture buffer lacks spare size: %d < %d (min = %d)\n",
687 buffer_size, spare_size, min_size);
691 * KMD Init time flows:
692 * --------------------
693 * --> alloc A: GuC input capture regs lists (registered to GuC via ADS).
694 * intel_guc_ads acquires the register lists by calling
695 * intel_guc_capture_list_size and intel_guc_capture_list_get 'n' times,
696 * where n = 1 for global-reg-list +
697 * num_engine_classes for class-reg-list +
698 * num_engine_classes for instance-reg-list
699 * (since all instances of the same engine-class type
700 * have an identical engine-instance register-list).
701 * ADS module also calls separately for PF vs VF.
703 * --> alloc B: GuC output capture buf (registered via guc_init_params(log_param))
704 * Size = #define CAPTURE_BUFFER_SIZE (warns if on too-small)
705 * Note2: 'x 3' to hold multiple capture groups
707 * GUC Runtime notify capture:
708 * --------------------------
709 * --> G2H STATE_CAPTURE_NOTIFICATION
710 * L--> intel_guc_capture_process
711 * L--> Loop through B (head..tail) and for each engine instance's
712 * err-state-captured register-list we find, we alloc 'C':
713 * --> alloc C: A capture-output-node structure that includes misc capture info along
714 * with 3 register list dumps (global, engine-class and engine-instance)
715 * This node is created from a pre-allocated list of blank nodes in
716 * guc->capture->cachelist and populated with the error-capture
717 * data from GuC and then it's added into guc->capture->outlist linked
718 * list. This list is used for matchup and printout by i915_gpu_coredump
719 * and err_print_gt, (when user invokes the error capture sysfs).
721 * GUC --> notify context reset:
722 * -----------------------------
723 * --> G2H CONTEXT RESET
724 * L--> guc_handle_context_reset --> i915_capture_error_state
725 * L--> i915_gpu_coredump(..IS_GUC_CAPTURE) --> gt_record_engines
726 * --> capture_engine(..IS_GUC_CAPTURE)
727 * L--> intel_guc_capture_get_matching_node is where
728 * detach C from internal linked list and add it into
729 * intel_engine_coredump struct (if the context and
730 * engine of the event notification matches a node
733 * User Sysfs / Debugfs
734 * --------------------
735 * --> i915_gpu_coredump_copy_to_buffer->
736 * L--> err_print_to_sgl --> err_print_gt
737 * L--> error_print_guc_captures
738 * L--> intel_guc_capture_print_node prints the
739 * register lists values of the attached node
740 * on the error-engine-dump being reported.
741 * L--> i915_reset_error_state ... -->__i915_gpu_coredump_free
742 * L--> ... cleanup_gt -->
743 * L--> intel_guc_capture_free_node returns the
744 * capture-output-node back to the internal
745 * cachelist for reuse.
749 static int guc_capture_buf_cnt(struct __guc_capture_bufstate *buf)
751 if (buf->wr >= buf->rd)
752 return (buf->wr - buf->rd);
753 return (buf->size - buf->rd) + buf->wr;
756 static int guc_capture_buf_cnt_to_end(struct __guc_capture_bufstate *buf)
758 if (buf->rd > buf->wr)
759 return (buf->size - buf->rd);
760 return (buf->wr - buf->rd);
764 * GuC's error-capture output is a ring buffer populated in a byte-stream fashion:
766 * The GuC Log buffer region for error-capture is managed like a ring buffer.
767 * The GuC firmware dumps error capture logs into this ring in a byte-stream flow.
768 * Additionally, as per the current and foreseeable future, all packed error-
769 * capture output structures are dword aligned.
771 * That said, if the GuC firmware is in the midst of writing a structure that is larger
772 * than one dword but the tail end of the err-capture buffer-region has lesser space left,
773 * we would need to extract that structure one dword at a time straddled across the end,
774 * onto the start of the ring.
776 * Below function, guc_capture_log_remove_dw is a helper for that. All callers of this
777 * function would typically do a straight-up memcpy from the ring contents and will only
778 * call this helper if their structure-extraction is straddling across the end of the
779 * ring. GuC firmware does not add any padding. The reason for the no-padding is to ease
780 * scalability for future expansion of output data types without requiring a redesign
781 * of the flow controls.
784 guc_capture_log_remove_dw(struct intel_guc *guc, struct __guc_capture_bufstate *buf,
791 if (!guc_capture_buf_cnt(buf))
795 avail = guc_capture_buf_cnt_to_end(buf);
796 if (avail >= sizeof(u32)) {
797 src_data = (u32 *)(buf->data + buf->rd);
803 guc_dbg(guc, "Register capture log not dword aligned, skipping.\n");
811 guc_capture_data_extracted(struct __guc_capture_bufstate *b,
812 int size, void *dest)
814 if (guc_capture_buf_cnt_to_end(b) >= size) {
815 memcpy(dest, (b->data + b->rd), size);
823 guc_capture_log_get_group_hdr(struct intel_guc *guc, struct __guc_capture_bufstate *buf,
824 struct guc_state_capture_group_header_t *ghdr)
827 int fullsize = sizeof(struct guc_state_capture_group_header_t);
829 if (fullsize > guc_capture_buf_cnt(buf))
832 if (guc_capture_data_extracted(buf, fullsize, (void *)ghdr))
835 read += guc_capture_log_remove_dw(guc, buf, &ghdr->owner);
836 read += guc_capture_log_remove_dw(guc, buf, &ghdr->info);
837 if (read != fullsize)
844 guc_capture_log_get_data_hdr(struct intel_guc *guc, struct __guc_capture_bufstate *buf,
845 struct guc_state_capture_header_t *hdr)
848 int fullsize = sizeof(struct guc_state_capture_header_t);
850 if (fullsize > guc_capture_buf_cnt(buf))
853 if (guc_capture_data_extracted(buf, fullsize, (void *)hdr))
856 read += guc_capture_log_remove_dw(guc, buf, &hdr->owner);
857 read += guc_capture_log_remove_dw(guc, buf, &hdr->info);
858 read += guc_capture_log_remove_dw(guc, buf, &hdr->lrca);
859 read += guc_capture_log_remove_dw(guc, buf, &hdr->guc_id);
860 read += guc_capture_log_remove_dw(guc, buf, &hdr->num_mmios);
861 if (read != fullsize)
868 guc_capture_log_get_register(struct intel_guc *guc, struct __guc_capture_bufstate *buf,
869 struct guc_mmio_reg *reg)
872 int fullsize = sizeof(struct guc_mmio_reg);
874 if (fullsize > guc_capture_buf_cnt(buf))
877 if (guc_capture_data_extracted(buf, fullsize, (void *)reg))
880 read += guc_capture_log_remove_dw(guc, buf, ®->offset);
881 read += guc_capture_log_remove_dw(guc, buf, ®->value);
882 read += guc_capture_log_remove_dw(guc, buf, ®->flags);
883 read += guc_capture_log_remove_dw(guc, buf, ®->mask);
884 if (read != fullsize)
891 guc_capture_delete_one_node(struct intel_guc *guc, struct __guc_capture_parsed_output *node)
895 for (i = 0; i < GUC_CAPTURE_LIST_TYPE_MAX; ++i)
896 kfree(node->reginfo[i].regs);
897 list_del(&node->link);
902 guc_capture_delete_prealloc_nodes(struct intel_guc *guc)
904 struct __guc_capture_parsed_output *n, *ntmp;
907 * NOTE: At the end of driver operation, we must assume that we
908 * have prealloc nodes in both the cachelist as well as outlist
909 * if unclaimed error capture events occurred prior to shutdown.
911 list_for_each_entry_safe(n, ntmp, &guc->capture->outlist, link)
912 guc_capture_delete_one_node(guc, n);
914 list_for_each_entry_safe(n, ntmp, &guc->capture->cachelist, link)
915 guc_capture_delete_one_node(guc, n);
919 guc_capture_add_node_to_list(struct __guc_capture_parsed_output *node,
920 struct list_head *list)
922 list_add_tail(&node->link, list);
926 guc_capture_add_node_to_outlist(struct intel_guc_state_capture *gc,
927 struct __guc_capture_parsed_output *node)
929 guc_capture_add_node_to_list(node, &gc->outlist);
933 guc_capture_add_node_to_cachelist(struct intel_guc_state_capture *gc,
934 struct __guc_capture_parsed_output *node)
936 guc_capture_add_node_to_list(node, &gc->cachelist);
940 guc_capture_init_node(struct intel_guc *guc, struct __guc_capture_parsed_output *node)
942 struct guc_mmio_reg *tmp[GUC_CAPTURE_LIST_TYPE_MAX];
945 for (i = 0; i < GUC_CAPTURE_LIST_TYPE_MAX; ++i) {
946 tmp[i] = node->reginfo[i].regs;
947 memset(tmp[i], 0, sizeof(struct guc_mmio_reg) *
948 guc->capture->max_mmio_per_node);
950 memset(node, 0, sizeof(*node));
951 for (i = 0; i < GUC_CAPTURE_LIST_TYPE_MAX; ++i)
952 node->reginfo[i].regs = tmp[i];
954 INIT_LIST_HEAD(&node->link);
957 static struct __guc_capture_parsed_output *
958 guc_capture_get_prealloc_node(struct intel_guc *guc)
960 struct __guc_capture_parsed_output *found = NULL;
962 if (!list_empty(&guc->capture->cachelist)) {
963 struct __guc_capture_parsed_output *n, *ntmp;
965 /* get first avail node from the cache list */
966 list_for_each_entry_safe(n, ntmp, &guc->capture->cachelist, link) {
972 struct __guc_capture_parsed_output *n, *ntmp;
974 /* traverse down and steal back the oldest node already allocated */
975 list_for_each_entry_safe(n, ntmp, &guc->capture->outlist, link) {
979 list_del(&found->link);
982 guc_capture_init_node(guc, found);
987 static struct __guc_capture_parsed_output *
988 guc_capture_alloc_one_node(struct intel_guc *guc)
990 struct __guc_capture_parsed_output *new;
993 new = kzalloc(sizeof(*new), GFP_KERNEL);
997 for (i = 0; i < GUC_CAPTURE_LIST_TYPE_MAX; ++i) {
998 new->reginfo[i].regs = kcalloc(guc->capture->max_mmio_per_node,
999 sizeof(struct guc_mmio_reg), GFP_KERNEL);
1000 if (!new->reginfo[i].regs) {
1002 kfree(new->reginfo[--i].regs);
1007 guc_capture_init_node(guc, new);
1012 static struct __guc_capture_parsed_output *
1013 guc_capture_clone_node(struct intel_guc *guc, struct __guc_capture_parsed_output *original,
1014 u32 keep_reglist_mask)
1016 struct __guc_capture_parsed_output *new;
1019 new = guc_capture_get_prealloc_node(guc);
1025 new->is_partial = original->is_partial;
1027 /* copy reg-lists that we want to clone */
1028 for (i = 0; i < GUC_CAPTURE_LIST_TYPE_MAX; ++i) {
1029 if (keep_reglist_mask & BIT(i)) {
1030 GEM_BUG_ON(original->reginfo[i].num_regs >
1031 guc->capture->max_mmio_per_node);
1033 memcpy(new->reginfo[i].regs, original->reginfo[i].regs,
1034 original->reginfo[i].num_regs * sizeof(struct guc_mmio_reg));
1036 new->reginfo[i].num_regs = original->reginfo[i].num_regs;
1037 new->reginfo[i].vfid = original->reginfo[i].vfid;
1039 if (i == GUC_CAPTURE_LIST_TYPE_ENGINE_CLASS) {
1040 new->eng_class = original->eng_class;
1041 } else if (i == GUC_CAPTURE_LIST_TYPE_ENGINE_INSTANCE) {
1042 new->eng_inst = original->eng_inst;
1043 new->guc_id = original->guc_id;
1044 new->lrca = original->lrca;
1053 __guc_capture_create_prealloc_nodes(struct intel_guc *guc)
1055 struct __guc_capture_parsed_output *node = NULL;
1058 for (i = 0; i < PREALLOC_NODES_MAX_COUNT; ++i) {
1059 node = guc_capture_alloc_one_node(guc);
1061 guc_warn(guc, "Register capture pre-alloc-cache failure\n");
1062 /* dont free the priors, use what we got and cleanup at shutdown */
1065 guc_capture_add_node_to_cachelist(guc->capture, node);
1070 guc_get_max_reglist_count(struct intel_guc *guc)
1072 int i, j, k, tmp, maxregcount = 0;
1074 for (i = 0; i < GUC_CAPTURE_LIST_INDEX_MAX; ++i) {
1075 for (j = 0; j < GUC_CAPTURE_LIST_TYPE_MAX; ++j) {
1076 for (k = 0; k < GUC_MAX_ENGINE_CLASSES; ++k) {
1077 if (j == GUC_CAPTURE_LIST_TYPE_GLOBAL && k > 0)
1080 tmp = guc_cap_list_num_regs(guc->capture, i, j, k);
1081 if (tmp > maxregcount)
1087 maxregcount = PREALLOC_NODES_DEFAULT_NUMREGS;
1093 guc_capture_create_prealloc_nodes(struct intel_guc *guc)
1095 /* skip if we've already done the pre-alloc */
1096 if (guc->capture->max_mmio_per_node)
1099 guc->capture->max_mmio_per_node = guc_get_max_reglist_count(guc);
1100 __guc_capture_create_prealloc_nodes(guc);
1104 guc_capture_extract_reglists(struct intel_guc *guc, struct __guc_capture_bufstate *buf)
1106 struct guc_state_capture_group_header_t ghdr = {0};
1107 struct guc_state_capture_header_t hdr = {0};
1108 struct __guc_capture_parsed_output *node = NULL;
1109 struct guc_mmio_reg *regs = NULL;
1110 int i, numlists, numregs, ret = 0;
1111 enum guc_capture_type datatype;
1112 struct guc_mmio_reg tmp;
1113 bool is_partial = false;
1115 i = guc_capture_buf_cnt(buf);
1118 if (i % sizeof(u32)) {
1119 guc_warn(guc, "Got mis-aligned register capture entries\n");
1124 /* first get the capture group header */
1125 if (guc_capture_log_get_group_hdr(guc, buf, &ghdr)) {
1130 * we would typically expect a layout as below where n would be expected to be
1131 * anywhere between 3 to n where n > 3 if we are seeing multiple dependent engine
1132 * instances being reset together.
1133 * ____________________________________________
1135 * | ________________________________________ |
1136 * | | Capture Group Header: | |
1137 * | | - num_captures = 5 | |
1138 * | |______________________________________| |
1139 * | ________________________________________ |
1141 * | | Hdr: GLOBAL, numregs=a | |
1142 * | | ____________________________________ | |
1143 * | | | Reglist | | |
1144 * | | | - reg1, reg2, ... rega | | |
1145 * | | |__________________________________| | |
1146 * | |______________________________________| |
1147 * | ________________________________________ |
1149 * | | Hdr: CLASS=RENDER/COMPUTE, numregs=b| |
1150 * | | ____________________________________ | |
1151 * | | | Reglist | | |
1152 * | | | - reg1, reg2, ... regb | | |
1153 * | | |__________________________________| | |
1154 * | |______________________________________| |
1155 * | ________________________________________ |
1157 * | | Hdr: INSTANCE=RCS, numregs=c | |
1158 * | | ____________________________________ | |
1159 * | | | Reglist | | |
1160 * | | | - reg1, reg2, ... regc | | |
1161 * | | |__________________________________| | |
1162 * | |______________________________________| |
1163 * | ________________________________________ |
1165 * | | Hdr: CLASS=RENDER/COMPUTE, numregs=d| |
1166 * | | ____________________________________ | |
1167 * | | | Reglist | | |
1168 * | | | - reg1, reg2, ... regd | | |
1169 * | | |__________________________________| | |
1170 * | |______________________________________| |
1171 * | ________________________________________ |
1173 * | | Hdr: INSTANCE=CCS0, numregs=e | |
1174 * | | ____________________________________ | |
1175 * | | | Reglist | | |
1176 * | | | - reg1, reg2, ... rege | | |
1177 * | | |__________________________________| | |
1178 * | |______________________________________| |
1179 * |__________________________________________|
1181 is_partial = FIELD_GET(CAP_GRP_HDR_CAPTURE_TYPE, ghdr.info);
1182 numlists = FIELD_GET(CAP_GRP_HDR_NUM_CAPTURES, ghdr.info);
1184 while (numlists--) {
1185 if (guc_capture_log_get_data_hdr(guc, buf, &hdr)) {
1190 datatype = FIELD_GET(CAP_HDR_CAPTURE_TYPE, hdr.info);
1191 if (datatype > GUC_CAPTURE_LIST_TYPE_ENGINE_INSTANCE) {
1192 /* unknown capture type - skip over to next capture set */
1193 numregs = FIELD_GET(CAP_HDR_NUM_MMIOS, hdr.num_mmios);
1195 if (guc_capture_log_get_register(guc, buf, &tmp)) {
1203 * Based on the current capture type and what we have so far,
1204 * decide if we should add the current node into the internal
1205 * linked list for match-up when i915_gpu_coredump calls later
1206 * (and alloc a blank node for the next set of reglists)
1207 * or continue with the same node or clone the current node
1208 * but only retain the global or class registers (such as the
1209 * case of dependent engine resets).
1211 if (datatype == GUC_CAPTURE_LIST_TYPE_GLOBAL) {
1212 guc_capture_add_node_to_outlist(guc->capture, node);
1214 } else if (datatype == GUC_CAPTURE_LIST_TYPE_ENGINE_CLASS &&
1215 node->reginfo[GUC_CAPTURE_LIST_TYPE_ENGINE_CLASS].num_regs) {
1216 /* Add to list, clone node and duplicate global list */
1217 guc_capture_add_node_to_outlist(guc->capture, node);
1218 node = guc_capture_clone_node(guc, node,
1219 GCAP_PARSED_REGLIST_INDEX_GLOBAL);
1220 } else if (datatype == GUC_CAPTURE_LIST_TYPE_ENGINE_INSTANCE &&
1221 node->reginfo[GUC_CAPTURE_LIST_TYPE_ENGINE_INSTANCE].num_regs) {
1222 /* Add to list, clone node and duplicate global + class lists */
1223 guc_capture_add_node_to_outlist(guc->capture, node);
1224 node = guc_capture_clone_node(guc, node,
1225 (GCAP_PARSED_REGLIST_INDEX_GLOBAL |
1226 GCAP_PARSED_REGLIST_INDEX_ENGCLASS));
1231 node = guc_capture_get_prealloc_node(guc);
1236 if (datatype != GUC_CAPTURE_LIST_TYPE_GLOBAL)
1237 guc_dbg(guc, "Register capture missing global dump: %08x!\n",
1240 node->is_partial = is_partial;
1241 node->reginfo[datatype].vfid = FIELD_GET(CAP_HDR_CAPTURE_VFID, hdr.owner);
1243 case GUC_CAPTURE_LIST_TYPE_ENGINE_INSTANCE:
1244 node->eng_class = FIELD_GET(CAP_HDR_ENGINE_CLASS, hdr.info);
1245 node->eng_inst = FIELD_GET(CAP_HDR_ENGINE_INSTANCE, hdr.info);
1246 node->lrca = hdr.lrca;
1247 node->guc_id = hdr.guc_id;
1249 case GUC_CAPTURE_LIST_TYPE_ENGINE_CLASS:
1250 node->eng_class = FIELD_GET(CAP_HDR_ENGINE_CLASS, hdr.info);
1256 numregs = FIELD_GET(CAP_HDR_NUM_MMIOS, hdr.num_mmios);
1257 if (numregs > guc->capture->max_mmio_per_node) {
1258 guc_dbg(guc, "Register capture list extraction clipped by prealloc!\n");
1259 numregs = guc->capture->max_mmio_per_node;
1261 node->reginfo[datatype].num_regs = numregs;
1262 regs = node->reginfo[datatype].regs;
1265 if (guc_capture_log_get_register(guc, buf, ®s[i++])) {
1274 /* If we have data, add to linked list for match-up when i915_gpu_coredump calls */
1275 for (i = GUC_CAPTURE_LIST_TYPE_GLOBAL; i < GUC_CAPTURE_LIST_TYPE_MAX; ++i) {
1276 if (node->reginfo[i].regs) {
1277 guc_capture_add_node_to_outlist(guc->capture, node);
1282 if (node) /* else return it back to cache list */
1283 guc_capture_add_node_to_cachelist(guc->capture, node);
1288 static int __guc_capture_flushlog_complete(struct intel_guc *guc)
1291 INTEL_GUC_ACTION_LOG_BUFFER_FILE_FLUSH_COMPLETE,
1292 GUC_CAPTURE_LOG_BUFFER
1295 return intel_guc_send_nb(guc, action, ARRAY_SIZE(action), 0);
1299 static void __guc_capture_process_output(struct intel_guc *guc)
1301 unsigned int buffer_size, read_offset, write_offset, full_count;
1302 struct intel_uc *uc = container_of(guc, typeof(*uc), guc);
1303 struct guc_log_buffer_state log_buf_state_local;
1304 struct guc_log_buffer_state *log_buf_state;
1305 struct __guc_capture_bufstate buf;
1306 void *src_data = NULL;
1310 log_buf_state = guc->log.buf_addr +
1311 (sizeof(struct guc_log_buffer_state) * GUC_CAPTURE_LOG_BUFFER);
1312 src_data = guc->log.buf_addr +
1313 intel_guc_get_log_buffer_offset(&guc->log, GUC_CAPTURE_LOG_BUFFER);
1316 * Make a copy of the state structure, inside GuC log buffer
1317 * (which is uncached mapped), on the stack to avoid reading
1318 * from it multiple times.
1320 memcpy(&log_buf_state_local, log_buf_state, sizeof(struct guc_log_buffer_state));
1321 buffer_size = intel_guc_get_log_buffer_size(&guc->log, GUC_CAPTURE_LOG_BUFFER);
1322 read_offset = log_buf_state_local.read_ptr;
1323 write_offset = log_buf_state_local.sampled_write_ptr;
1324 full_count = log_buf_state_local.buffer_full_cnt;
1326 /* Bookkeeping stuff */
1327 guc->log.stats[GUC_CAPTURE_LOG_BUFFER].flush += log_buf_state_local.flush_to_file;
1328 new_overflow = intel_guc_check_log_buf_overflow(&guc->log, GUC_CAPTURE_LOG_BUFFER,
1331 /* Now copy the actual logs. */
1332 if (unlikely(new_overflow)) {
1333 /* copy the whole buffer in case of overflow */
1335 write_offset = buffer_size;
1336 } else if (unlikely((read_offset > buffer_size) ||
1337 (write_offset > buffer_size))) {
1338 guc_err(guc, "Register capture buffer in invalid state: read = 0x%X, size = 0x%X!\n",
1339 read_offset, buffer_size);
1340 /* copy whole buffer as offsets are unreliable */
1342 write_offset = buffer_size;
1345 buf.size = buffer_size;
1346 buf.rd = read_offset;
1347 buf.wr = write_offset;
1348 buf.data = src_data;
1350 if (!uc->reset_in_progress) {
1352 ret = guc_capture_extract_reglists(guc, &buf);
1356 /* Update the state of log buffer err-cap state */
1357 log_buf_state->read_ptr = write_offset;
1358 log_buf_state->flush_to_file = 0;
1359 __guc_capture_flushlog_complete(guc);
1362 #if IS_ENABLED(CONFIG_DRM_I915_CAPTURE_ERROR)
1365 guc_capture_reg_to_str(const struct intel_guc *guc, u32 owner, u32 type,
1366 u32 class, u32 id, u32 offset, u32 *is_ext)
1368 const struct __guc_mmio_reg_descr_group *reglists = guc->capture->reglists;
1369 struct __guc_mmio_reg_descr_group *extlists = guc->capture->extlists;
1370 const struct __guc_mmio_reg_descr_group *match;
1371 struct __guc_mmio_reg_descr_group *matchext;
1378 match = guc_capture_get_one_list(reglists, owner, type, id);
1382 for (j = 0; j < match->num_regs; ++j) {
1383 if (offset == match->list[j].reg.reg)
1384 return match->list[j].regname;
1387 matchext = guc_capture_get_one_ext_list(extlists, owner, type, id);
1390 for (j = 0; j < matchext->num_regs; ++j) {
1391 if (offset == matchext->extlist[j].reg.reg) {
1393 return matchext->extlist[j].regname;
1401 #define GCAP_PRINT_INTEL_ENG_INFO(ebuf, eng) \
1403 i915_error_printf(ebuf, " i915-Eng-Name: %s command stream\n", \
1405 i915_error_printf(ebuf, " i915-Eng-Inst-Class: 0x%02x\n", (eng)->class); \
1406 i915_error_printf(ebuf, " i915-Eng-Inst-Id: 0x%02x\n", (eng)->instance); \
1407 i915_error_printf(ebuf, " i915-Eng-LogicalMask: 0x%08x\n", \
1408 (eng)->logical_mask); \
1411 #define GCAP_PRINT_GUC_INST_INFO(ebuf, node) \
1413 i915_error_printf(ebuf, " GuC-Engine-Inst-Id: 0x%08x\n", \
1414 (node)->eng_inst); \
1415 i915_error_printf(ebuf, " GuC-Context-Id: 0x%08x\n", (node)->guc_id); \
1416 i915_error_printf(ebuf, " LRCA: 0x%08x\n", (node)->lrca); \
1419 int intel_guc_capture_print_engine_node(struct drm_i915_error_state_buf *ebuf,
1420 const struct intel_engine_coredump *ee)
1422 const char *grptype[GUC_STATE_CAPTURE_GROUP_TYPE_MAX] = {
1426 const char *datatype[GUC_CAPTURE_LIST_TYPE_MAX] = {
1431 struct intel_guc_state_capture *cap;
1432 struct __guc_capture_parsed_output *node;
1433 struct intel_engine_cs *eng;
1434 struct guc_mmio_reg *regs;
1435 struct intel_guc *guc;
1442 cap = ee->guc_capture;
1443 if (!cap || !ee->engine)
1446 guc = &ee->engine->gt->uc.guc;
1448 i915_error_printf(ebuf, "global --- GuC Error Capture on %s command stream:\n",
1451 node = ee->guc_capture_node;
1453 i915_error_printf(ebuf, " No matching ee-node\n");
1457 i915_error_printf(ebuf, "Coverage: %s\n", grptype[node->is_partial]);
1459 for (i = GUC_CAPTURE_LIST_TYPE_GLOBAL; i < GUC_CAPTURE_LIST_TYPE_MAX; ++i) {
1460 i915_error_printf(ebuf, " RegListType: %s\n",
1461 datatype[i % GUC_CAPTURE_LIST_TYPE_MAX]);
1462 i915_error_printf(ebuf, " Owner-Id: %d\n", node->reginfo[i].vfid);
1465 case GUC_CAPTURE_LIST_TYPE_GLOBAL:
1468 case GUC_CAPTURE_LIST_TYPE_ENGINE_CLASS:
1469 i915_error_printf(ebuf, " GuC-Eng-Class: %d\n", node->eng_class);
1470 i915_error_printf(ebuf, " i915-Eng-Class: %d\n",
1471 guc_class_to_engine_class(node->eng_class));
1473 case GUC_CAPTURE_LIST_TYPE_ENGINE_INSTANCE:
1474 eng = intel_guc_lookup_engine(guc, node->eng_class, node->eng_inst);
1476 GCAP_PRINT_INTEL_ENG_INFO(ebuf, eng);
1478 i915_error_printf(ebuf, " i915-Eng-Lookup Fail!\n");
1479 GCAP_PRINT_GUC_INST_INFO(ebuf, node);
1483 numregs = node->reginfo[i].num_regs;
1484 i915_error_printf(ebuf, " NumRegs: %d\n", numregs);
1487 regs = node->reginfo[i].regs;
1488 str = guc_capture_reg_to_str(guc, GUC_CAPTURE_LIST_INDEX_PF, i,
1489 node->eng_class, 0, regs[j].offset, &is_ext);
1491 i915_error_printf(ebuf, " REG-0x%08x", regs[j].offset);
1493 i915_error_printf(ebuf, " %s", str);
1495 i915_error_printf(ebuf, "[%ld][%ld]",
1496 FIELD_GET(GUC_REGSET_STEERING_GROUP, regs[j].flags),
1497 FIELD_GET(GUC_REGSET_STEERING_INSTANCE, regs[j].flags));
1498 i915_error_printf(ebuf, ": 0x%08x\n", regs[j].value);
1505 #endif //CONFIG_DRM_I915_CAPTURE_ERROR
1507 static void guc_capture_find_ecode(struct intel_engine_coredump *ee)
1509 struct gcap_reg_list_info *reginfo;
1510 struct guc_mmio_reg *regs;
1511 i915_reg_t reg_ipehr = RING_IPEHR(0);
1512 i915_reg_t reg_instdone = RING_INSTDONE(0);
1515 if (!ee->guc_capture_node)
1518 reginfo = ee->guc_capture_node->reginfo + GUC_CAPTURE_LIST_TYPE_ENGINE_INSTANCE;
1519 regs = reginfo->regs;
1520 for (i = 0; i < reginfo->num_regs; i++) {
1521 if (regs[i].offset == reg_ipehr.reg)
1522 ee->ipehr = regs[i].value;
1523 else if (regs[i].offset == reg_instdone.reg)
1524 ee->instdone.instdone = regs[i].value;
1528 void intel_guc_capture_free_node(struct intel_engine_coredump *ee)
1530 if (!ee || !ee->guc_capture_node)
1533 guc_capture_add_node_to_cachelist(ee->guc_capture, ee->guc_capture_node);
1534 ee->guc_capture = NULL;
1535 ee->guc_capture_node = NULL;
1538 bool intel_guc_capture_is_matching_engine(struct intel_gt *gt,
1539 struct intel_context *ce,
1540 struct intel_engine_cs *engine)
1542 struct __guc_capture_parsed_output *n;
1543 struct intel_guc *guc;
1545 if (!gt || !ce || !engine)
1553 * Look for a matching GuC reported error capture node from
1554 * the internal output link-list based on lrca, guc-id and engine
1557 list_for_each_entry(n, &guc->capture->outlist, link) {
1558 if (n->eng_inst == GUC_ID_TO_ENGINE_INSTANCE(engine->guc_id) &&
1559 n->eng_class == GUC_ID_TO_ENGINE_CLASS(engine->guc_id) &&
1560 n->guc_id == ce->guc_id.id &&
1561 (n->lrca & CTX_GTT_ADDRESS_MASK) == (ce->lrc.lrca & CTX_GTT_ADDRESS_MASK))
1568 void intel_guc_capture_get_matching_node(struct intel_gt *gt,
1569 struct intel_engine_coredump *ee,
1570 struct intel_context *ce)
1572 struct __guc_capture_parsed_output *n, *ntmp;
1573 struct intel_guc *guc;
1575 if (!gt || !ee || !ce)
1582 GEM_BUG_ON(ee->guc_capture_node);
1585 * Look for a matching GuC reported error capture node from
1586 * the internal output link-list based on lrca, guc-id and engine
1589 list_for_each_entry_safe(n, ntmp, &guc->capture->outlist, link) {
1590 if (n->eng_inst == GUC_ID_TO_ENGINE_INSTANCE(ee->engine->guc_id) &&
1591 n->eng_class == GUC_ID_TO_ENGINE_CLASS(ee->engine->guc_id) &&
1592 n->guc_id == ce->guc_id.id &&
1593 (n->lrca & CTX_GTT_ADDRESS_MASK) == (ce->lrc.lrca & CTX_GTT_ADDRESS_MASK)) {
1595 ee->guc_capture_node = n;
1596 ee->guc_capture = guc->capture;
1597 guc_capture_find_ecode(ee);
1602 guc_warn(guc, "No register capture node found for 0x%04X / 0x%08X\n",
1603 ce->guc_id.id, ce->lrc.lrca);
1606 void intel_guc_capture_process(struct intel_guc *guc)
1609 __guc_capture_process_output(guc);
1613 guc_capture_free_ads_cache(struct intel_guc_state_capture *gc)
1616 struct __guc_capture_ads_cache *cache;
1618 for (i = 0; i < GUC_CAPTURE_LIST_INDEX_MAX; ++i) {
1619 for (j = 0; j < GUC_CAPTURE_LIST_TYPE_MAX; ++j) {
1620 for (k = 0; k < GUC_MAX_ENGINE_CLASSES; ++k) {
1621 cache = &gc->ads_cache[i][j][k];
1622 if (cache->is_valid)
1627 kfree(gc->ads_null_cache);
1630 void intel_guc_capture_destroy(struct intel_guc *guc)
1635 guc_capture_free_ads_cache(guc->capture);
1637 guc_capture_delete_prealloc_nodes(guc);
1639 guc_capture_free_extlists(guc->capture->extlists);
1640 kfree(guc->capture->extlists);
1642 kfree(guc->capture);
1643 guc->capture = NULL;
1646 int intel_guc_capture_init(struct intel_guc *guc)
1648 guc->capture = kzalloc(sizeof(*guc->capture), GFP_KERNEL);
1652 guc->capture->reglists = guc_capture_get_device_reglist(guc);
1654 INIT_LIST_HEAD(&guc->capture->outlist);
1655 INIT_LIST_HEAD(&guc->capture->cachelist);
1657 check_guc_capture_size(guc);