xref: /linux/drivers/gpu/drm/xe/xe_guc_capture.c (revision ecb6336463911d6eb684998754f8701d0f437f18)
19c8c7a7eSZhanjun Dong // SPDX-License-Identifier: MIT
29c8c7a7eSZhanjun Dong /*
39c8c7a7eSZhanjun Dong  * Copyright © 2021-2024 Intel Corporation
49c8c7a7eSZhanjun Dong  */
59c8c7a7eSZhanjun Dong 
69c8c7a7eSZhanjun Dong #include <linux/types.h>
79c8c7a7eSZhanjun Dong 
89c8c7a7eSZhanjun Dong #include <drm/drm_managed.h>
99c8c7a7eSZhanjun Dong #include <drm/drm_print.h>
109c8c7a7eSZhanjun Dong 
119c8c7a7eSZhanjun Dong #include "abi/guc_actions_abi.h"
129c8c7a7eSZhanjun Dong #include "abi/guc_capture_abi.h"
138bfc4963SZhanjun Dong #include "abi/guc_log_abi.h"
149c8c7a7eSZhanjun Dong #include "regs/xe_engine_regs.h"
159c8c7a7eSZhanjun Dong #include "regs/xe_gt_regs.h"
169c8c7a7eSZhanjun Dong #include "regs/xe_guc_regs.h"
179c8c7a7eSZhanjun Dong #include "regs/xe_regs.h"
189c8c7a7eSZhanjun Dong 
199c8c7a7eSZhanjun Dong #include "xe_bo.h"
209c8c7a7eSZhanjun Dong #include "xe_device.h"
219c8c7a7eSZhanjun Dong #include "xe_exec_queue_types.h"
229c8c7a7eSZhanjun Dong #include "xe_gt.h"
239c8c7a7eSZhanjun Dong #include "xe_gt_mcr.h"
249c8c7a7eSZhanjun Dong #include "xe_gt_printk.h"
259c8c7a7eSZhanjun Dong #include "xe_guc.h"
2684d15f42SZhanjun Dong #include "xe_guc_ads.h"
279c8c7a7eSZhanjun Dong #include "xe_guc_capture.h"
289c8c7a7eSZhanjun Dong #include "xe_guc_capture_types.h"
299c8c7a7eSZhanjun Dong #include "xe_guc_ct.h"
30*ecb63364SZhanjun Dong #include "xe_guc_exec_queue_types.h"
319c8c7a7eSZhanjun Dong #include "xe_guc_log.h"
32*ecb63364SZhanjun Dong #include "xe_guc_submit_types.h"
339c8c7a7eSZhanjun Dong #include "xe_guc_submit.h"
349c8c7a7eSZhanjun Dong #include "xe_hw_engine_types.h"
35*ecb63364SZhanjun Dong #include "xe_hw_engine.h"
36*ecb63364SZhanjun Dong #include "xe_lrc.h"
379c8c7a7eSZhanjun Dong #include "xe_macros.h"
389c8c7a7eSZhanjun Dong #include "xe_map.h"
39*ecb63364SZhanjun Dong #include "xe_mmio.h"
40*ecb63364SZhanjun Dong #include "xe_sched_job.h"
419c8c7a7eSZhanjun Dong 
429c8c7a7eSZhanjun Dong /*
438bfc4963SZhanjun Dong  * struct __guc_capture_bufstate
448bfc4963SZhanjun Dong  *
458bfc4963SZhanjun Dong  * Book-keeping structure used to track read and write pointers
468bfc4963SZhanjun Dong  * as we extract error capture data from the GuC-log-buffer's
478bfc4963SZhanjun Dong  * error-capture region as a stream of dwords.
488bfc4963SZhanjun Dong  */
498bfc4963SZhanjun Dong struct __guc_capture_bufstate {
508bfc4963SZhanjun Dong 	u32 size;
518bfc4963SZhanjun Dong 	u32 data_offset;
528bfc4963SZhanjun Dong 	u32 rd;
538bfc4963SZhanjun Dong 	u32 wr;
548bfc4963SZhanjun Dong };
558bfc4963SZhanjun Dong 
568bfc4963SZhanjun Dong /*
578bfc4963SZhanjun Dong  * struct __guc_capture_parsed_output - extracted error capture node
588bfc4963SZhanjun Dong  *
598bfc4963SZhanjun Dong  * A single unit of extracted error-capture output data grouped together
608bfc4963SZhanjun Dong  * at an engine-instance level. We keep these nodes in a linked list.
618bfc4963SZhanjun Dong  * See cachelist and outlist below.
628bfc4963SZhanjun Dong  */
638bfc4963SZhanjun Dong struct __guc_capture_parsed_output {
648bfc4963SZhanjun Dong 	/*
658bfc4963SZhanjun Dong 	 * A single set of 3 capture lists: a global-list
668bfc4963SZhanjun Dong 	 * an engine-class-list and an engine-instance list.
678bfc4963SZhanjun Dong 	 * outlist in __guc_capture_parsed_output will keep
688bfc4963SZhanjun Dong 	 * a linked list of these nodes that will eventually
698bfc4963SZhanjun Dong 	 * be detached from outlist and attached into to
708bfc4963SZhanjun Dong 	 * xe_codedump in response to a context reset
718bfc4963SZhanjun Dong 	 */
728bfc4963SZhanjun Dong 	struct list_head link;
738bfc4963SZhanjun Dong 	bool is_partial;
748bfc4963SZhanjun Dong 	u32 eng_class;
758bfc4963SZhanjun Dong 	u32 eng_inst;
768bfc4963SZhanjun Dong 	u32 guc_id;
778bfc4963SZhanjun Dong 	u32 lrca;
78*ecb63364SZhanjun Dong 	u32 type;
79*ecb63364SZhanjun Dong 	bool locked;
80*ecb63364SZhanjun Dong 	enum xe_hw_engine_snapshot_source_id source;
818bfc4963SZhanjun Dong 	struct gcap_reg_list_info {
828bfc4963SZhanjun Dong 		u32 vfid;
838bfc4963SZhanjun Dong 		u32 num_regs;
848bfc4963SZhanjun Dong 		struct guc_mmio_reg *regs;
858bfc4963SZhanjun Dong 	} reginfo[GUC_STATE_CAPTURE_TYPE_MAX];
868bfc4963SZhanjun Dong #define GCAP_PARSED_REGLIST_INDEX_GLOBAL   BIT(GUC_STATE_CAPTURE_TYPE_GLOBAL)
878bfc4963SZhanjun Dong #define GCAP_PARSED_REGLIST_INDEX_ENGCLASS BIT(GUC_STATE_CAPTURE_TYPE_ENGINE_CLASS)
888bfc4963SZhanjun Dong };
898bfc4963SZhanjun Dong 
908bfc4963SZhanjun Dong /*
919c8c7a7eSZhanjun Dong  * Define all device tables of GuC error capture register lists
929c8c7a7eSZhanjun Dong  * NOTE:
939c8c7a7eSZhanjun Dong  *     For engine-registers, GuC only needs the register offsets
949c8c7a7eSZhanjun Dong  *     from the engine-mmio-base
959c8c7a7eSZhanjun Dong  *
969c8c7a7eSZhanjun Dong  *     64 bit registers need 2 entries for low 32 bit register and high 32 bit
979c8c7a7eSZhanjun Dong  *     register, for example:
989c8c7a7eSZhanjun Dong  *       Register           data_type       flags   mask    Register name
999c8c7a7eSZhanjun Dong  *     { XXX_REG_LO(0),  REG_64BIT_LOW_DW,    0,      0,      NULL},
1009c8c7a7eSZhanjun Dong  *     { XXX_REG_HI(0),  REG_64BIT_HI_DW,,    0,      0,      "XXX_REG"},
1019c8c7a7eSZhanjun Dong  *     1. data_type: Indicate is hi/low 32 bit for a 64 bit register
1029c8c7a7eSZhanjun Dong  *                   A 64 bit register define requires 2 consecutive entries,
1039c8c7a7eSZhanjun Dong  *                   with low dword first and hi dword the second.
1049c8c7a7eSZhanjun Dong  *     2. Register name: null for incompleted define
1059c8c7a7eSZhanjun Dong  */
1069c8c7a7eSZhanjun Dong #define COMMON_XELP_BASE_GLOBAL \
1079c8c7a7eSZhanjun Dong 	{ FORCEWAKE_GT,			REG_32BIT,	0,	0,	"FORCEWAKE_GT"}
1089c8c7a7eSZhanjun Dong 
1099c8c7a7eSZhanjun Dong #define COMMON_BASE_ENGINE_INSTANCE \
1109c8c7a7eSZhanjun Dong 	{ RING_HWSTAM(0),		REG_32BIT,	0,	0,	"HWSTAM"}, \
1119c8c7a7eSZhanjun Dong 	{ RING_HWS_PGA(0),		REG_32BIT,	0,	0,	"RING_HWS_PGA"}, \
1129c8c7a7eSZhanjun Dong 	{ RING_HEAD(0),			REG_32BIT,	0,	0,	"RING_HEAD"}, \
1139c8c7a7eSZhanjun Dong 	{ RING_TAIL(0),			REG_32BIT,	0,	0,	"RING_TAIL"}, \
1149c8c7a7eSZhanjun Dong 	{ RING_CTL(0),			REG_32BIT,	0,	0,	"RING_CTL"}, \
1159c8c7a7eSZhanjun Dong 	{ RING_MI_MODE(0),		REG_32BIT,	0,	0,	"RING_MI_MODE"}, \
1169c8c7a7eSZhanjun Dong 	{ RING_MODE(0),			REG_32BIT,	0,	0,	"RING_MODE"}, \
1179c8c7a7eSZhanjun Dong 	{ RING_ESR(0),			REG_32BIT,	0,	0,	"RING_ESR"}, \
1189c8c7a7eSZhanjun Dong 	{ RING_EMR(0),			REG_32BIT,	0,	0,	"RING_EMR"}, \
1199c8c7a7eSZhanjun Dong 	{ RING_EIR(0),			REG_32BIT,	0,	0,	"RING_EIR"}, \
1209c8c7a7eSZhanjun Dong 	{ RING_IMR(0),			REG_32BIT,	0,	0,	"RING_IMR"}, \
1219c8c7a7eSZhanjun Dong 	{ RING_IPEHR(0),		REG_32BIT,	0,	0,	"IPEHR"}, \
1229c8c7a7eSZhanjun Dong 	{ RING_INSTDONE(0),		REG_32BIT,	0,	0,	"RING_INSTDONE"}, \
1239c8c7a7eSZhanjun Dong 	{ INDIRECT_RING_STATE(0),	REG_32BIT,	0,	0,	"INDIRECT_RING_STATE"}, \
1249c8c7a7eSZhanjun Dong 	{ RING_ACTHD(0),		REG_64BIT_LOW_DW, 0,	0,	NULL}, \
1259c8c7a7eSZhanjun Dong 	{ RING_ACTHD_UDW(0),		REG_64BIT_HI_DW, 0,	0,	"ACTHD"}, \
1269c8c7a7eSZhanjun Dong 	{ RING_BBADDR(0),		REG_64BIT_LOW_DW, 0,	0,	NULL}, \
1279c8c7a7eSZhanjun Dong 	{ RING_BBADDR_UDW(0),		REG_64BIT_HI_DW, 0,	0,	"RING_BBADDR"}, \
1289c8c7a7eSZhanjun Dong 	{ RING_START(0),		REG_64BIT_LOW_DW, 0,	0,	NULL}, \
1299c8c7a7eSZhanjun Dong 	{ RING_START_UDW(0),		REG_64BIT_HI_DW, 0,	0,	"RING_START"}, \
1309c8c7a7eSZhanjun Dong 	{ RING_DMA_FADD(0),		REG_64BIT_LOW_DW, 0,	0,	NULL}, \
1319c8c7a7eSZhanjun Dong 	{ RING_DMA_FADD_UDW(0),		REG_64BIT_HI_DW, 0,	0,	"RING_DMA_FADD"}, \
1329c8c7a7eSZhanjun Dong 	{ RING_EXECLIST_STATUS_LO(0),	REG_64BIT_LOW_DW, 0,	0,	NULL}, \
1339c8c7a7eSZhanjun Dong 	{ RING_EXECLIST_STATUS_HI(0),	REG_64BIT_HI_DW, 0,	0,	"RING_EXECLIST_STATUS"}, \
1349c8c7a7eSZhanjun Dong 	{ RING_EXECLIST_SQ_CONTENTS_LO(0), REG_64BIT_LOW_DW, 0,	0,	NULL}, \
1359c8c7a7eSZhanjun Dong 	{ RING_EXECLIST_SQ_CONTENTS_HI(0), REG_64BIT_HI_DW, 0,	0,	"RING_EXECLIST_SQ_CONTENTS"}
1369c8c7a7eSZhanjun Dong 
1379c8c7a7eSZhanjun Dong #define COMMON_XELP_RC_CLASS \
1389c8c7a7eSZhanjun Dong 	{ RCU_MODE,			REG_32BIT,	0,	0,	"RCU_MODE"}
1399c8c7a7eSZhanjun Dong 
1409c8c7a7eSZhanjun Dong #define COMMON_XELP_RC_CLASS_INSTDONE \
1419c8c7a7eSZhanjun Dong 	{ SC_INSTDONE,			REG_32BIT,	0,	0,	"SC_INSTDONE"}, \
1429c8c7a7eSZhanjun Dong 	{ SC_INSTDONE_EXTRA,		REG_32BIT,	0,	0,	"SC_INSTDONE_EXTRA"}, \
1439c8c7a7eSZhanjun Dong 	{ SC_INSTDONE_EXTRA2,		REG_32BIT,	0,	0,	"SC_INSTDONE_EXTRA2"}
1449c8c7a7eSZhanjun Dong 
1459c8c7a7eSZhanjun Dong #define XELP_VEC_CLASS_REGS \
1469c8c7a7eSZhanjun Dong 	{ SFC_DONE(0),			0,	0,	0,	"SFC_DONE[0]"}, \
1479c8c7a7eSZhanjun Dong 	{ SFC_DONE(1),			0,	0,	0,	"SFC_DONE[1]"}, \
1489c8c7a7eSZhanjun Dong 	{ SFC_DONE(2),			0,	0,	0,	"SFC_DONE[2]"}, \
1499c8c7a7eSZhanjun Dong 	{ SFC_DONE(3),			0,	0,	0,	"SFC_DONE[3]"}
1509c8c7a7eSZhanjun Dong 
1519c8c7a7eSZhanjun Dong /* XE_LP Global */
1529c8c7a7eSZhanjun Dong static const struct __guc_mmio_reg_descr xe_lp_global_regs[] = {
1539c8c7a7eSZhanjun Dong 	COMMON_XELP_BASE_GLOBAL,
1549c8c7a7eSZhanjun Dong };
1559c8c7a7eSZhanjun Dong 
1569c8c7a7eSZhanjun Dong /* Render / Compute Per-Engine-Instance */
1579c8c7a7eSZhanjun Dong static const struct __guc_mmio_reg_descr xe_rc_inst_regs[] = {
1589c8c7a7eSZhanjun Dong 	COMMON_BASE_ENGINE_INSTANCE,
1599c8c7a7eSZhanjun Dong };
1609c8c7a7eSZhanjun Dong 
1619c8c7a7eSZhanjun Dong /* Render / Compute Engine-Class */
1629c8c7a7eSZhanjun Dong static const struct __guc_mmio_reg_descr xe_rc_class_regs[] = {
1639c8c7a7eSZhanjun Dong 	COMMON_XELP_RC_CLASS,
1649c8c7a7eSZhanjun Dong 	COMMON_XELP_RC_CLASS_INSTDONE,
1659c8c7a7eSZhanjun Dong };
1669c8c7a7eSZhanjun Dong 
1679c8c7a7eSZhanjun Dong /* Render / Compute Engine-Class for xehpg */
1689c8c7a7eSZhanjun Dong static const struct __guc_mmio_reg_descr xe_hpg_rc_class_regs[] = {
1699c8c7a7eSZhanjun Dong 	COMMON_XELP_RC_CLASS,
1709c8c7a7eSZhanjun Dong };
1719c8c7a7eSZhanjun Dong 
1729c8c7a7eSZhanjun Dong /* Media Decode/Encode Per-Engine-Instance */
1739c8c7a7eSZhanjun Dong static const struct __guc_mmio_reg_descr xe_vd_inst_regs[] = {
1749c8c7a7eSZhanjun Dong 	COMMON_BASE_ENGINE_INSTANCE,
1759c8c7a7eSZhanjun Dong };
1769c8c7a7eSZhanjun Dong 
1779c8c7a7eSZhanjun Dong /* Video Enhancement Engine-Class */
1789c8c7a7eSZhanjun Dong static const struct __guc_mmio_reg_descr xe_vec_class_regs[] = {
1799c8c7a7eSZhanjun Dong 	XELP_VEC_CLASS_REGS,
1809c8c7a7eSZhanjun Dong };
1819c8c7a7eSZhanjun Dong 
1829c8c7a7eSZhanjun Dong /* Video Enhancement Per-Engine-Instance */
1839c8c7a7eSZhanjun Dong static const struct __guc_mmio_reg_descr xe_vec_inst_regs[] = {
1849c8c7a7eSZhanjun Dong 	COMMON_BASE_ENGINE_INSTANCE,
1859c8c7a7eSZhanjun Dong };
1869c8c7a7eSZhanjun Dong 
1879c8c7a7eSZhanjun Dong /* Blitter Per-Engine-Instance */
1889c8c7a7eSZhanjun Dong static const struct __guc_mmio_reg_descr xe_blt_inst_regs[] = {
1899c8c7a7eSZhanjun Dong 	COMMON_BASE_ENGINE_INSTANCE,
1909c8c7a7eSZhanjun Dong };
1919c8c7a7eSZhanjun Dong 
1929c8c7a7eSZhanjun Dong /* XE_LP - GSC Per-Engine-Instance */
1939c8c7a7eSZhanjun Dong static const struct __guc_mmio_reg_descr xe_lp_gsc_inst_regs[] = {
1949c8c7a7eSZhanjun Dong 	COMMON_BASE_ENGINE_INSTANCE,
1959c8c7a7eSZhanjun Dong };
1969c8c7a7eSZhanjun Dong 
1979c8c7a7eSZhanjun Dong /*
1989c8c7a7eSZhanjun Dong  * Empty list to prevent warnings about unknown class/instance types
1999c8c7a7eSZhanjun Dong  * as not all class/instance types have entries on all platforms.
2009c8c7a7eSZhanjun Dong  */
2019c8c7a7eSZhanjun Dong static const struct __guc_mmio_reg_descr empty_regs_list[] = {
2029c8c7a7eSZhanjun Dong };
2039c8c7a7eSZhanjun Dong 
2049c8c7a7eSZhanjun Dong #define TO_GCAP_DEF_OWNER(x) (GUC_CAPTURE_LIST_INDEX_##x)
2059c8c7a7eSZhanjun Dong #define TO_GCAP_DEF_TYPE(x) (GUC_STATE_CAPTURE_TYPE_##x)
2069c8c7a7eSZhanjun Dong #define MAKE_REGLIST(regslist, regsowner, regstype, class) \
2079c8c7a7eSZhanjun Dong 	{ \
2089c8c7a7eSZhanjun Dong 		regslist, \
2099c8c7a7eSZhanjun Dong 		ARRAY_SIZE(regslist), \
2109c8c7a7eSZhanjun Dong 		TO_GCAP_DEF_OWNER(regsowner), \
2119c8c7a7eSZhanjun Dong 		TO_GCAP_DEF_TYPE(regstype), \
2129c8c7a7eSZhanjun Dong 		class \
2139c8c7a7eSZhanjun Dong 	}
2149c8c7a7eSZhanjun Dong 
2159c8c7a7eSZhanjun Dong /* List of lists for legacy graphic product version < 1255 */
2169c8c7a7eSZhanjun Dong static const struct __guc_mmio_reg_descr_group xe_lp_lists[] = {
2179c8c7a7eSZhanjun Dong 	MAKE_REGLIST(xe_lp_global_regs, PF, GLOBAL, 0),
2189c8c7a7eSZhanjun Dong 	MAKE_REGLIST(xe_rc_class_regs, PF, ENGINE_CLASS, GUC_CAPTURE_LIST_CLASS_RENDER_COMPUTE),
2199c8c7a7eSZhanjun Dong 	MAKE_REGLIST(xe_rc_inst_regs, PF, ENGINE_INSTANCE, GUC_CAPTURE_LIST_CLASS_RENDER_COMPUTE),
2209c8c7a7eSZhanjun Dong 	MAKE_REGLIST(empty_regs_list, PF, ENGINE_CLASS, GUC_CAPTURE_LIST_CLASS_VIDEO),
2219c8c7a7eSZhanjun Dong 	MAKE_REGLIST(xe_vd_inst_regs, PF, ENGINE_INSTANCE, GUC_CAPTURE_LIST_CLASS_VIDEO),
2229c8c7a7eSZhanjun Dong 	MAKE_REGLIST(xe_vec_class_regs, PF, ENGINE_CLASS, GUC_CAPTURE_LIST_CLASS_VIDEOENHANCE),
2239c8c7a7eSZhanjun Dong 	MAKE_REGLIST(xe_vec_inst_regs, PF, ENGINE_INSTANCE, GUC_CAPTURE_LIST_CLASS_VIDEOENHANCE),
2249c8c7a7eSZhanjun Dong 	MAKE_REGLIST(empty_regs_list, PF, ENGINE_CLASS, GUC_CAPTURE_LIST_CLASS_BLITTER),
2259c8c7a7eSZhanjun Dong 	MAKE_REGLIST(xe_blt_inst_regs, PF, ENGINE_INSTANCE, GUC_CAPTURE_LIST_CLASS_BLITTER),
2269c8c7a7eSZhanjun Dong 	MAKE_REGLIST(empty_regs_list, PF, ENGINE_CLASS, GUC_CAPTURE_LIST_CLASS_GSC_OTHER),
2279c8c7a7eSZhanjun Dong 	MAKE_REGLIST(xe_lp_gsc_inst_regs, PF, ENGINE_INSTANCE, GUC_CAPTURE_LIST_CLASS_GSC_OTHER),
2289c8c7a7eSZhanjun Dong 	{}
2299c8c7a7eSZhanjun Dong };
2309c8c7a7eSZhanjun Dong 
2319c8c7a7eSZhanjun Dong  /* List of lists for graphic product version >= 1255 */
2329c8c7a7eSZhanjun Dong static const struct __guc_mmio_reg_descr_group xe_hpg_lists[] = {
2339c8c7a7eSZhanjun Dong 	MAKE_REGLIST(xe_lp_global_regs, PF, GLOBAL, 0),
2349c8c7a7eSZhanjun Dong 	MAKE_REGLIST(xe_hpg_rc_class_regs, PF, ENGINE_CLASS, GUC_CAPTURE_LIST_CLASS_RENDER_COMPUTE),
2359c8c7a7eSZhanjun Dong 	MAKE_REGLIST(xe_rc_inst_regs, PF, ENGINE_INSTANCE, GUC_CAPTURE_LIST_CLASS_RENDER_COMPUTE),
2369c8c7a7eSZhanjun Dong 	MAKE_REGLIST(empty_regs_list, PF, ENGINE_CLASS, GUC_CAPTURE_LIST_CLASS_VIDEO),
2379c8c7a7eSZhanjun Dong 	MAKE_REGLIST(xe_vd_inst_regs, PF, ENGINE_INSTANCE, GUC_CAPTURE_LIST_CLASS_VIDEO),
2389c8c7a7eSZhanjun Dong 	MAKE_REGLIST(xe_vec_class_regs, PF, ENGINE_CLASS, GUC_CAPTURE_LIST_CLASS_VIDEOENHANCE),
2399c8c7a7eSZhanjun Dong 	MAKE_REGLIST(xe_vec_inst_regs, PF, ENGINE_INSTANCE, GUC_CAPTURE_LIST_CLASS_VIDEOENHANCE),
2409c8c7a7eSZhanjun Dong 	MAKE_REGLIST(empty_regs_list, PF, ENGINE_CLASS, GUC_CAPTURE_LIST_CLASS_BLITTER),
2419c8c7a7eSZhanjun Dong 	MAKE_REGLIST(xe_blt_inst_regs, PF, ENGINE_INSTANCE, GUC_CAPTURE_LIST_CLASS_BLITTER),
2429c8c7a7eSZhanjun Dong 	MAKE_REGLIST(empty_regs_list, PF, ENGINE_CLASS, GUC_CAPTURE_LIST_CLASS_GSC_OTHER),
2439c8c7a7eSZhanjun Dong 	MAKE_REGLIST(xe_lp_gsc_inst_regs, PF, ENGINE_INSTANCE, GUC_CAPTURE_LIST_CLASS_GSC_OTHER),
2449c8c7a7eSZhanjun Dong 	{}
2459c8c7a7eSZhanjun Dong };
2469c8c7a7eSZhanjun Dong 
2479c8c7a7eSZhanjun Dong static const char * const capture_list_type_names[] = {
2489c8c7a7eSZhanjun Dong 	"Global",
2499c8c7a7eSZhanjun Dong 	"Class",
2509c8c7a7eSZhanjun Dong 	"Instance",
2519c8c7a7eSZhanjun Dong };
2529c8c7a7eSZhanjun Dong 
2539c8c7a7eSZhanjun Dong static const char * const capture_engine_class_names[] = {
2549c8c7a7eSZhanjun Dong 	"Render/Compute",
2559c8c7a7eSZhanjun Dong 	"Video",
2569c8c7a7eSZhanjun Dong 	"VideoEnhance",
2579c8c7a7eSZhanjun Dong 	"Blitter",
2589c8c7a7eSZhanjun Dong 	"GSC-Other",
2599c8c7a7eSZhanjun Dong };
2609c8c7a7eSZhanjun Dong 
2619c8c7a7eSZhanjun Dong struct __guc_capture_ads_cache {
2629c8c7a7eSZhanjun Dong 	bool is_valid;
2639c8c7a7eSZhanjun Dong 	void *ptr;
2649c8c7a7eSZhanjun Dong 	size_t size;
2659c8c7a7eSZhanjun Dong 	int status;
2669c8c7a7eSZhanjun Dong };
2679c8c7a7eSZhanjun Dong 
2689c8c7a7eSZhanjun Dong struct xe_guc_state_capture {
2699c8c7a7eSZhanjun Dong 	const struct __guc_mmio_reg_descr_group *reglists;
270b170d696SZhanjun Dong 	/**
271b170d696SZhanjun Dong 	 * NOTE: steered registers have multiple instances depending on the HW configuration
272b170d696SZhanjun Dong 	 * (slices or dual-sub-slices) and thus depends on HW fuses discovered
273b170d696SZhanjun Dong 	 */
274b170d696SZhanjun Dong 	struct __guc_mmio_reg_descr_group *extlists;
2759c8c7a7eSZhanjun Dong 	struct __guc_capture_ads_cache ads_cache[GUC_CAPTURE_LIST_INDEX_MAX]
2769c8c7a7eSZhanjun Dong 						[GUC_STATE_CAPTURE_TYPE_MAX]
2779c8c7a7eSZhanjun Dong 						[GUC_CAPTURE_LIST_CLASS_MAX];
2789c8c7a7eSZhanjun Dong 	void *ads_null_cache;
2798bfc4963SZhanjun Dong 	struct list_head cachelist;
2808bfc4963SZhanjun Dong #define PREALLOC_NODES_MAX_COUNT (3 * GUC_MAX_ENGINE_CLASSES * GUC_MAX_INSTANCES_PER_CLASS)
2818bfc4963SZhanjun Dong #define PREALLOC_NODES_DEFAULT_NUMREGS 64
2828bfc4963SZhanjun Dong 
2838bfc4963SZhanjun Dong 	int max_mmio_per_node;
2848bfc4963SZhanjun Dong 	struct list_head outlist;
2859c8c7a7eSZhanjun Dong };
2869c8c7a7eSZhanjun Dong 
287*ecb63364SZhanjun Dong static void
288*ecb63364SZhanjun Dong guc_capture_remove_stale_matches_from_list(struct xe_guc_state_capture *gc,
289*ecb63364SZhanjun Dong 					   struct __guc_capture_parsed_output *node);
290*ecb63364SZhanjun Dong 
2919c8c7a7eSZhanjun Dong static const struct __guc_mmio_reg_descr_group *
2929c8c7a7eSZhanjun Dong guc_capture_get_device_reglist(struct xe_device *xe)
2939c8c7a7eSZhanjun Dong {
2949c8c7a7eSZhanjun Dong 	if (GRAPHICS_VERx100(xe) >= 1255)
2959c8c7a7eSZhanjun Dong 		return xe_hpg_lists;
2969c8c7a7eSZhanjun Dong 	else
2979c8c7a7eSZhanjun Dong 		return xe_lp_lists;
2989c8c7a7eSZhanjun Dong }
2999c8c7a7eSZhanjun Dong 
3009c8c7a7eSZhanjun Dong static const struct __guc_mmio_reg_descr_group *
3019c8c7a7eSZhanjun Dong guc_capture_get_one_list(const struct __guc_mmio_reg_descr_group *reglists,
3029c8c7a7eSZhanjun Dong 			 u32 owner, u32 type, enum guc_capture_list_class_type capture_class)
3039c8c7a7eSZhanjun Dong {
3049c8c7a7eSZhanjun Dong 	int i;
3059c8c7a7eSZhanjun Dong 
3069c8c7a7eSZhanjun Dong 	if (!reglists)
3079c8c7a7eSZhanjun Dong 		return NULL;
3089c8c7a7eSZhanjun Dong 
3099c8c7a7eSZhanjun Dong 	for (i = 0; reglists[i].list; ++i) {
3109c8c7a7eSZhanjun Dong 		if (reglists[i].owner == owner && reglists[i].type == type &&
3119c8c7a7eSZhanjun Dong 		    (reglists[i].engine == capture_class ||
3129c8c7a7eSZhanjun Dong 		     reglists[i].type == GUC_STATE_CAPTURE_TYPE_GLOBAL))
3139c8c7a7eSZhanjun Dong 			return &reglists[i];
3149c8c7a7eSZhanjun Dong 	}
3159c8c7a7eSZhanjun Dong 
3169c8c7a7eSZhanjun Dong 	return NULL;
3179c8c7a7eSZhanjun Dong }
3189c8c7a7eSZhanjun Dong 
319*ecb63364SZhanjun Dong const struct __guc_mmio_reg_descr_group *
320*ecb63364SZhanjun Dong xe_guc_capture_get_reg_desc_list(struct xe_gt *gt, u32 owner, u32 type,
321*ecb63364SZhanjun Dong 				 enum guc_capture_list_class_type capture_class, bool is_ext)
322*ecb63364SZhanjun Dong {
323*ecb63364SZhanjun Dong 	const struct __guc_mmio_reg_descr_group *reglists;
324*ecb63364SZhanjun Dong 
325*ecb63364SZhanjun Dong 	if (is_ext) {
326*ecb63364SZhanjun Dong 		struct xe_guc *guc = &gt->uc.guc;
327*ecb63364SZhanjun Dong 
328*ecb63364SZhanjun Dong 		reglists = guc->capture->extlists;
329*ecb63364SZhanjun Dong 	} else {
330*ecb63364SZhanjun Dong 		reglists = guc_capture_get_device_reglist(gt_to_xe(gt));
331*ecb63364SZhanjun Dong 	}
332*ecb63364SZhanjun Dong 	return guc_capture_get_one_list(reglists, owner, type, capture_class);
333*ecb63364SZhanjun Dong }
334*ecb63364SZhanjun Dong 
335b170d696SZhanjun Dong struct __ext_steer_reg {
336b170d696SZhanjun Dong 	const char *name;
337b170d696SZhanjun Dong 	struct xe_reg_mcr reg;
338b170d696SZhanjun Dong };
339b170d696SZhanjun Dong 
340b170d696SZhanjun Dong static const struct __ext_steer_reg xe_extregs[] = {
341b170d696SZhanjun Dong 	{"SAMPLER_INSTDONE",		SAMPLER_INSTDONE},
342b170d696SZhanjun Dong 	{"ROW_INSTDONE",		ROW_INSTDONE}
343b170d696SZhanjun Dong };
344b170d696SZhanjun Dong 
345b170d696SZhanjun Dong static const struct __ext_steer_reg xehpg_extregs[] = {
346b170d696SZhanjun Dong 	{"SC_INSTDONE",			XEHPG_SC_INSTDONE},
347b170d696SZhanjun Dong 	{"SC_INSTDONE_EXTRA",		XEHPG_SC_INSTDONE_EXTRA},
348b170d696SZhanjun Dong 	{"SC_INSTDONE_EXTRA2",		XEHPG_SC_INSTDONE_EXTRA2},
349b170d696SZhanjun Dong 	{"INSTDONE_GEOM_SVGUNIT",	XEHPG_INSTDONE_GEOM_SVGUNIT}
350b170d696SZhanjun Dong };
351b170d696SZhanjun Dong 
352b170d696SZhanjun Dong static void __fill_ext_reg(struct __guc_mmio_reg_descr *ext,
353b170d696SZhanjun Dong 			   const struct __ext_steer_reg *extlist,
354b170d696SZhanjun Dong 			   int slice_id, int subslice_id)
355b170d696SZhanjun Dong {
356b170d696SZhanjun Dong 	if (!ext || !extlist)
357b170d696SZhanjun Dong 		return;
358b170d696SZhanjun Dong 
359b170d696SZhanjun Dong 	ext->reg = XE_REG(extlist->reg.__reg.addr);
360b170d696SZhanjun Dong 	ext->flags = FIELD_PREP(GUC_REGSET_STEERING_NEEDED, 1);
361b170d696SZhanjun Dong 	ext->flags = FIELD_PREP(GUC_REGSET_STEERING_GROUP, slice_id);
362b170d696SZhanjun Dong 	ext->flags |= FIELD_PREP(GUC_REGSET_STEERING_INSTANCE, subslice_id);
363b170d696SZhanjun Dong 	ext->regname = extlist->name;
364b170d696SZhanjun Dong }
365b170d696SZhanjun Dong 
366b170d696SZhanjun Dong static int
367b170d696SZhanjun Dong __alloc_ext_regs(struct drm_device *drm, struct __guc_mmio_reg_descr_group *newlist,
368b170d696SZhanjun Dong 		 const struct __guc_mmio_reg_descr_group *rootlist, int num_regs)
369b170d696SZhanjun Dong {
370b170d696SZhanjun Dong 	struct __guc_mmio_reg_descr *list;
371b170d696SZhanjun Dong 
372b170d696SZhanjun Dong 	list = drmm_kzalloc(drm, num_regs * sizeof(struct __guc_mmio_reg_descr), GFP_KERNEL);
373b170d696SZhanjun Dong 	if (!list)
374b170d696SZhanjun Dong 		return -ENOMEM;
375b170d696SZhanjun Dong 
376b170d696SZhanjun Dong 	newlist->list = list;
377b170d696SZhanjun Dong 	newlist->num_regs = num_regs;
378b170d696SZhanjun Dong 	newlist->owner = rootlist->owner;
379b170d696SZhanjun Dong 	newlist->engine = rootlist->engine;
380b170d696SZhanjun Dong 	newlist->type = rootlist->type;
381b170d696SZhanjun Dong 
382b170d696SZhanjun Dong 	return 0;
383b170d696SZhanjun Dong }
384b170d696SZhanjun Dong 
385b170d696SZhanjun Dong static int guc_capture_get_steer_reg_num(struct xe_device *xe)
386b170d696SZhanjun Dong {
387b170d696SZhanjun Dong 	int num = ARRAY_SIZE(xe_extregs);
388b170d696SZhanjun Dong 
389b170d696SZhanjun Dong 	if (GRAPHICS_VERx100(xe) >= 1255)
390b170d696SZhanjun Dong 		num += ARRAY_SIZE(xehpg_extregs);
391b170d696SZhanjun Dong 
392b170d696SZhanjun Dong 	return num;
393b170d696SZhanjun Dong }
394b170d696SZhanjun Dong 
395b170d696SZhanjun Dong static void guc_capture_alloc_steered_lists(struct xe_guc *guc)
396b170d696SZhanjun Dong {
397b170d696SZhanjun Dong 	struct xe_gt *gt = guc_to_gt(guc);
398b170d696SZhanjun Dong 	u16 slice, subslice;
399b170d696SZhanjun Dong 	int iter, i, total = 0;
400b170d696SZhanjun Dong 	const struct __guc_mmio_reg_descr_group *lists = guc->capture->reglists;
401b170d696SZhanjun Dong 	const struct __guc_mmio_reg_descr_group *list;
402b170d696SZhanjun Dong 	struct __guc_mmio_reg_descr_group *extlists;
403b170d696SZhanjun Dong 	struct __guc_mmio_reg_descr *extarray;
404b170d696SZhanjun Dong 	bool has_xehpg_extregs = GRAPHICS_VERx100(gt_to_xe(gt)) >= 1255;
405b170d696SZhanjun Dong 	struct drm_device *drm = &gt_to_xe(gt)->drm;
406b170d696SZhanjun Dong 	bool has_rcs_ccs = false;
407b170d696SZhanjun Dong 	struct xe_hw_engine *hwe;
408b170d696SZhanjun Dong 	enum xe_hw_engine_id id;
409b170d696SZhanjun Dong 
410b170d696SZhanjun Dong 	/*
411b170d696SZhanjun Dong 	 * If GT has no rcs/ccs, no need to alloc steered list.
412b170d696SZhanjun Dong 	 * Currently, only rcs/ccs has steering register, if in the future,
413b170d696SZhanjun Dong 	 * other engine types has steering register, this condition check need
414b170d696SZhanjun Dong 	 * to be extended
415b170d696SZhanjun Dong 	 */
416b170d696SZhanjun Dong 	for_each_hw_engine(hwe, gt, id) {
417b170d696SZhanjun Dong 		if (xe_engine_class_to_guc_capture_class(hwe->class) ==
418b170d696SZhanjun Dong 		    GUC_CAPTURE_LIST_CLASS_RENDER_COMPUTE) {
419b170d696SZhanjun Dong 			has_rcs_ccs = true;
420b170d696SZhanjun Dong 			break;
421b170d696SZhanjun Dong 		}
422b170d696SZhanjun Dong 	}
423b170d696SZhanjun Dong 
424b170d696SZhanjun Dong 	if (!has_rcs_ccs)
425b170d696SZhanjun Dong 		return;
426b170d696SZhanjun Dong 
427b170d696SZhanjun Dong 	/* steered registers currently only exist for the render-class */
428b170d696SZhanjun Dong 	list = guc_capture_get_one_list(lists, GUC_CAPTURE_LIST_INDEX_PF,
429b170d696SZhanjun Dong 					GUC_STATE_CAPTURE_TYPE_ENGINE_CLASS,
430b170d696SZhanjun Dong 					GUC_CAPTURE_LIST_CLASS_RENDER_COMPUTE);
431b170d696SZhanjun Dong 	/*
432b170d696SZhanjun Dong 	 * Skip if this platform has no engine class registers or if extlists
433b170d696SZhanjun Dong 	 * was previously allocated
434b170d696SZhanjun Dong 	 */
435b170d696SZhanjun Dong 	if (!list || guc->capture->extlists)
436b170d696SZhanjun Dong 		return;
437b170d696SZhanjun Dong 
438b170d696SZhanjun Dong 	total = bitmap_weight(gt->fuse_topo.g_dss_mask, sizeof(gt->fuse_topo.g_dss_mask) * 8) *
439b170d696SZhanjun Dong 		guc_capture_get_steer_reg_num(guc_to_xe(guc));
440b170d696SZhanjun Dong 
441b170d696SZhanjun Dong 	if (!total)
442b170d696SZhanjun Dong 		return;
443b170d696SZhanjun Dong 
444b170d696SZhanjun Dong 	/* allocate an extra for an end marker */
445b170d696SZhanjun Dong 	extlists = drmm_kzalloc(drm, 2 * sizeof(struct __guc_mmio_reg_descr_group), GFP_KERNEL);
446b170d696SZhanjun Dong 	if (!extlists)
447b170d696SZhanjun Dong 		return;
448b170d696SZhanjun Dong 
449b170d696SZhanjun Dong 	if (__alloc_ext_regs(drm, &extlists[0], list, total)) {
450b170d696SZhanjun Dong 		drmm_kfree(drm, extlists);
451b170d696SZhanjun Dong 		return;
452b170d696SZhanjun Dong 	}
453b170d696SZhanjun Dong 
454b170d696SZhanjun Dong 	/* For steering registers, the list is generated at run-time */
455b170d696SZhanjun Dong 	extarray = (struct __guc_mmio_reg_descr *)extlists[0].list;
456b170d696SZhanjun Dong 	for_each_dss_steering(iter, gt, slice, subslice) {
457b170d696SZhanjun Dong 		for (i = 0; i < ARRAY_SIZE(xe_extregs); ++i) {
458b170d696SZhanjun Dong 			__fill_ext_reg(extarray, &xe_extregs[i], slice, subslice);
459b170d696SZhanjun Dong 			++extarray;
460b170d696SZhanjun Dong 		}
461b170d696SZhanjun Dong 
462b170d696SZhanjun Dong 		if (has_xehpg_extregs)
463b170d696SZhanjun Dong 			for (i = 0; i < ARRAY_SIZE(xehpg_extregs); ++i) {
464b170d696SZhanjun Dong 				__fill_ext_reg(extarray, &xehpg_extregs[i], slice, subslice);
465b170d696SZhanjun Dong 				++extarray;
466b170d696SZhanjun Dong 			}
467b170d696SZhanjun Dong 	}
468b170d696SZhanjun Dong 
469b170d696SZhanjun Dong 	extlists[0].num_regs = total;
470b170d696SZhanjun Dong 
471b170d696SZhanjun Dong 	xe_gt_dbg(guc_to_gt(guc), "capture found %d ext-regs.\n", total);
472b170d696SZhanjun Dong 	guc->capture->extlists = extlists;
473b170d696SZhanjun Dong }
474b170d696SZhanjun Dong 
4759c8c7a7eSZhanjun Dong static int
4769c8c7a7eSZhanjun Dong guc_capture_list_init(struct xe_guc *guc, u32 owner, u32 type,
4779c8c7a7eSZhanjun Dong 		      enum guc_capture_list_class_type capture_class, struct guc_mmio_reg *ptr,
4789c8c7a7eSZhanjun Dong 		      u16 num_entries)
4799c8c7a7eSZhanjun Dong {
480b170d696SZhanjun Dong 	u32 ptr_idx = 0, list_idx = 0;
4819c8c7a7eSZhanjun Dong 	const struct __guc_mmio_reg_descr_group *reglists = guc->capture->reglists;
482b170d696SZhanjun Dong 	struct __guc_mmio_reg_descr_group *extlists = guc->capture->extlists;
4839c8c7a7eSZhanjun Dong 	const struct __guc_mmio_reg_descr_group *match;
484b170d696SZhanjun Dong 	u32 list_num;
4859c8c7a7eSZhanjun Dong 
4869c8c7a7eSZhanjun Dong 	if (!reglists)
4879c8c7a7eSZhanjun Dong 		return -ENODEV;
4889c8c7a7eSZhanjun Dong 
4899c8c7a7eSZhanjun Dong 	match = guc_capture_get_one_list(reglists, owner, type, capture_class);
4909c8c7a7eSZhanjun Dong 	if (!match)
4919c8c7a7eSZhanjun Dong 		return -ENODATA;
4929c8c7a7eSZhanjun Dong 
493b170d696SZhanjun Dong 	list_num = match->num_regs;
494b170d696SZhanjun Dong 	for (list_idx = 0; ptr_idx < num_entries && list_idx < list_num; ++list_idx, ++ptr_idx) {
495b170d696SZhanjun Dong 		ptr[ptr_idx].offset = match->list[list_idx].reg.addr;
496b170d696SZhanjun Dong 		ptr[ptr_idx].value = 0xDEADF00D;
497b170d696SZhanjun Dong 		ptr[ptr_idx].flags = match->list[list_idx].flags;
498b170d696SZhanjun Dong 		ptr[ptr_idx].mask = match->list[list_idx].mask;
4999c8c7a7eSZhanjun Dong 	}
5009c8c7a7eSZhanjun Dong 
501b170d696SZhanjun Dong 	match = guc_capture_get_one_list(extlists, owner, type, capture_class);
502b170d696SZhanjun Dong 	if (match)
503b170d696SZhanjun Dong 		for (ptr_idx = list_num, list_idx = 0;
504b170d696SZhanjun Dong 		     ptr_idx < num_entries && list_idx < match->num_regs;
505b170d696SZhanjun Dong 		     ++ptr_idx, ++list_idx) {
506b170d696SZhanjun Dong 			ptr[ptr_idx].offset = match->list[list_idx].reg.addr;
507b170d696SZhanjun Dong 			ptr[ptr_idx].value = 0xDEADF00D;
508b170d696SZhanjun Dong 			ptr[ptr_idx].flags = match->list[list_idx].flags;
509b170d696SZhanjun Dong 			ptr[ptr_idx].mask = match->list[list_idx].mask;
510b170d696SZhanjun Dong 		}
511b170d696SZhanjun Dong 
512b170d696SZhanjun Dong 	if (ptr_idx < num_entries)
513b170d696SZhanjun Dong 		xe_gt_dbg(guc_to_gt(guc), "Got short capture reglist init: %d out-of %d.\n",
514b170d696SZhanjun Dong 			  ptr_idx, num_entries);
5159c8c7a7eSZhanjun Dong 
5169c8c7a7eSZhanjun Dong 	return 0;
5179c8c7a7eSZhanjun Dong }
5189c8c7a7eSZhanjun Dong 
5199c8c7a7eSZhanjun Dong static int
5209c8c7a7eSZhanjun Dong guc_cap_list_num_regs(struct xe_guc *guc, u32 owner, u32 type,
5219c8c7a7eSZhanjun Dong 		      enum guc_capture_list_class_type capture_class)
5229c8c7a7eSZhanjun Dong {
5239c8c7a7eSZhanjun Dong 	const struct __guc_mmio_reg_descr_group *match;
524b170d696SZhanjun Dong 	int num_regs = 0;
5259c8c7a7eSZhanjun Dong 
5269c8c7a7eSZhanjun Dong 	match = guc_capture_get_one_list(guc->capture->reglists, owner, type, capture_class);
527b170d696SZhanjun Dong 	if (match)
528b170d696SZhanjun Dong 		num_regs = match->num_regs;
5299c8c7a7eSZhanjun Dong 
530b170d696SZhanjun Dong 	match = guc_capture_get_one_list(guc->capture->extlists, owner, type, capture_class);
531b170d696SZhanjun Dong 	if (match)
532b170d696SZhanjun Dong 		num_regs += match->num_regs;
533b170d696SZhanjun Dong 	else
5348bfc4963SZhanjun Dong 		/*
5358bfc4963SZhanjun Dong 		 * If a caller wants the full register dump size but we have
5368bfc4963SZhanjun Dong 		 * not yet got the hw-config, which is before max_mmio_per_node
5378bfc4963SZhanjun Dong 		 * is initialized, then provide a worst-case number for
5388bfc4963SZhanjun Dong 		 * extlists based on max dss fuse bits, but only ever for
5398bfc4963SZhanjun Dong 		 * render/compute
5408bfc4963SZhanjun Dong 		 */
5418bfc4963SZhanjun Dong 		if (owner == GUC_CAPTURE_LIST_INDEX_PF &&
5428bfc4963SZhanjun Dong 		    type == GUC_STATE_CAPTURE_TYPE_ENGINE_CLASS &&
5438bfc4963SZhanjun Dong 		    capture_class == GUC_CAPTURE_LIST_CLASS_RENDER_COMPUTE &&
5448bfc4963SZhanjun Dong 		    !guc->capture->max_mmio_per_node)
545b170d696SZhanjun Dong 			num_regs += guc_capture_get_steer_reg_num(guc_to_xe(guc)) *
546b170d696SZhanjun Dong 				    XE_MAX_DSS_FUSE_BITS;
547b170d696SZhanjun Dong 
548b170d696SZhanjun Dong 	return num_regs;
5499c8c7a7eSZhanjun Dong }
5509c8c7a7eSZhanjun Dong 
5519c8c7a7eSZhanjun Dong static int
5529c8c7a7eSZhanjun Dong guc_capture_getlistsize(struct xe_guc *guc, u32 owner, u32 type,
5539c8c7a7eSZhanjun Dong 			enum guc_capture_list_class_type capture_class,
5549c8c7a7eSZhanjun Dong 			size_t *size, bool is_purpose_est)
5559c8c7a7eSZhanjun Dong {
5569c8c7a7eSZhanjun Dong 	struct xe_guc_state_capture *gc = guc->capture;
5579c8c7a7eSZhanjun Dong 	struct xe_gt *gt = guc_to_gt(guc);
5589c8c7a7eSZhanjun Dong 	struct __guc_capture_ads_cache *cache;
5599c8c7a7eSZhanjun Dong 	int num_regs;
5609c8c7a7eSZhanjun Dong 
5619c8c7a7eSZhanjun Dong 	xe_gt_assert(gt, type < GUC_STATE_CAPTURE_TYPE_MAX);
5629c8c7a7eSZhanjun Dong 	xe_gt_assert(gt, capture_class < GUC_CAPTURE_LIST_CLASS_MAX);
5639c8c7a7eSZhanjun Dong 
5649c8c7a7eSZhanjun Dong 	cache = &gc->ads_cache[owner][type][capture_class];
5659c8c7a7eSZhanjun Dong 	if (!gc->reglists) {
5669c8c7a7eSZhanjun Dong 		xe_gt_warn(gt, "No capture reglist for this device\n");
5679c8c7a7eSZhanjun Dong 		return -ENODEV;
5689c8c7a7eSZhanjun Dong 	}
5699c8c7a7eSZhanjun Dong 
5709c8c7a7eSZhanjun Dong 	if (cache->is_valid) {
5719c8c7a7eSZhanjun Dong 		*size = cache->size;
5729c8c7a7eSZhanjun Dong 		return cache->status;
5739c8c7a7eSZhanjun Dong 	}
5749c8c7a7eSZhanjun Dong 
5759c8c7a7eSZhanjun Dong 	if (!is_purpose_est && owner == GUC_CAPTURE_LIST_INDEX_PF &&
5769c8c7a7eSZhanjun Dong 	    !guc_capture_get_one_list(gc->reglists, owner, type, capture_class)) {
5779c8c7a7eSZhanjun Dong 		if (type == GUC_STATE_CAPTURE_TYPE_GLOBAL)
5789c8c7a7eSZhanjun Dong 			xe_gt_warn(gt, "Missing capture reglist: global!\n");
5799c8c7a7eSZhanjun Dong 		else
5809c8c7a7eSZhanjun Dong 			xe_gt_warn(gt, "Missing capture reglist: %s(%u):%s(%u)!\n",
5819c8c7a7eSZhanjun Dong 				   capture_list_type_names[type], type,
5829c8c7a7eSZhanjun Dong 				   capture_engine_class_names[capture_class], capture_class);
5839c8c7a7eSZhanjun Dong 		return -ENODEV;
5849c8c7a7eSZhanjun Dong 	}
5859c8c7a7eSZhanjun Dong 
5869c8c7a7eSZhanjun Dong 	num_regs = guc_cap_list_num_regs(guc, owner, type, capture_class);
5879c8c7a7eSZhanjun Dong 	/* intentional empty lists can exist depending on hw config */
5889c8c7a7eSZhanjun Dong 	if (!num_regs)
5899c8c7a7eSZhanjun Dong 		return -ENODATA;
5909c8c7a7eSZhanjun Dong 
5919c8c7a7eSZhanjun Dong 	if (size)
5929c8c7a7eSZhanjun Dong 		*size = PAGE_ALIGN((sizeof(struct guc_debug_capture_list)) +
5939c8c7a7eSZhanjun Dong 				   (num_regs * sizeof(struct guc_mmio_reg)));
5949c8c7a7eSZhanjun Dong 
5959c8c7a7eSZhanjun Dong 	return 0;
5969c8c7a7eSZhanjun Dong }
5979c8c7a7eSZhanjun Dong 
5989c8c7a7eSZhanjun Dong /**
5999c8c7a7eSZhanjun Dong  * xe_guc_capture_getlistsize - Get list size for owner/type/class combination
6009c8c7a7eSZhanjun Dong  * @guc: The GuC object
6019c8c7a7eSZhanjun Dong  * @owner: PF/VF owner
6029c8c7a7eSZhanjun Dong  * @type: GuC capture register type
6039c8c7a7eSZhanjun Dong  * @capture_class: GuC capture engine class id
6049c8c7a7eSZhanjun Dong  * @size: Point to the size
6059c8c7a7eSZhanjun Dong  *
6069c8c7a7eSZhanjun Dong  * This function will get the list for the owner/type/class combination, and
6079c8c7a7eSZhanjun Dong  * return the page aligned list size.
6089c8c7a7eSZhanjun Dong  *
6099c8c7a7eSZhanjun Dong  * Returns: 0 on success or a negative error code on failure.
6109c8c7a7eSZhanjun Dong  */
6119c8c7a7eSZhanjun Dong int
6129c8c7a7eSZhanjun Dong xe_guc_capture_getlistsize(struct xe_guc *guc, u32 owner, u32 type,
6139c8c7a7eSZhanjun Dong 			   enum guc_capture_list_class_type capture_class, size_t *size)
6149c8c7a7eSZhanjun Dong {
6159c8c7a7eSZhanjun Dong 	return guc_capture_getlistsize(guc, owner, type, capture_class, size, false);
6169c8c7a7eSZhanjun Dong }
6179c8c7a7eSZhanjun Dong 
6189c8c7a7eSZhanjun Dong /**
6199c8c7a7eSZhanjun Dong  * xe_guc_capture_getlist - Get register capture list for owner/type/class
6209c8c7a7eSZhanjun Dong  * combination
6219c8c7a7eSZhanjun Dong  * @guc:	The GuC object
6229c8c7a7eSZhanjun Dong  * @owner:	PF/VF owner
6239c8c7a7eSZhanjun Dong  * @type:	GuC capture register type
6249c8c7a7eSZhanjun Dong  * @capture_class:	GuC capture engine class id
6259c8c7a7eSZhanjun Dong  * @outptr:	Point to cached register capture list
6269c8c7a7eSZhanjun Dong  *
6279c8c7a7eSZhanjun Dong  * This function will get the register capture list for the owner/type/class
6289c8c7a7eSZhanjun Dong  * combination.
6299c8c7a7eSZhanjun Dong  *
6309c8c7a7eSZhanjun Dong  * Returns: 0 on success or a negative error code on failure.
6319c8c7a7eSZhanjun Dong  */
6329c8c7a7eSZhanjun Dong int
6339c8c7a7eSZhanjun Dong xe_guc_capture_getlist(struct xe_guc *guc, u32 owner, u32 type,
6349c8c7a7eSZhanjun Dong 		       enum guc_capture_list_class_type capture_class, void **outptr)
6359c8c7a7eSZhanjun Dong {
6369c8c7a7eSZhanjun Dong 	struct xe_guc_state_capture *gc = guc->capture;
6379c8c7a7eSZhanjun Dong 	struct __guc_capture_ads_cache *cache = &gc->ads_cache[owner][type][capture_class];
6389c8c7a7eSZhanjun Dong 	struct guc_debug_capture_list *listnode;
6399c8c7a7eSZhanjun Dong 	int ret, num_regs;
6409c8c7a7eSZhanjun Dong 	u8 *caplist, *tmp;
6419c8c7a7eSZhanjun Dong 	size_t size = 0;
6429c8c7a7eSZhanjun Dong 
6439c8c7a7eSZhanjun Dong 	if (!gc->reglists)
6449c8c7a7eSZhanjun Dong 		return -ENODEV;
6459c8c7a7eSZhanjun Dong 
6469c8c7a7eSZhanjun Dong 	if (cache->is_valid) {
6479c8c7a7eSZhanjun Dong 		*outptr = cache->ptr;
6489c8c7a7eSZhanjun Dong 		return cache->status;
6499c8c7a7eSZhanjun Dong 	}
6509c8c7a7eSZhanjun Dong 
6519c8c7a7eSZhanjun Dong 	ret = xe_guc_capture_getlistsize(guc, owner, type, capture_class, &size);
6529c8c7a7eSZhanjun Dong 	if (ret) {
6539c8c7a7eSZhanjun Dong 		cache->is_valid = true;
6549c8c7a7eSZhanjun Dong 		cache->ptr = NULL;
6559c8c7a7eSZhanjun Dong 		cache->size = 0;
6569c8c7a7eSZhanjun Dong 		cache->status = ret;
6579c8c7a7eSZhanjun Dong 		return ret;
6589c8c7a7eSZhanjun Dong 	}
6599c8c7a7eSZhanjun Dong 
6609c8c7a7eSZhanjun Dong 	caplist = drmm_kzalloc(guc_to_drm(guc), size, GFP_KERNEL);
6619c8c7a7eSZhanjun Dong 	if (!caplist)
6629c8c7a7eSZhanjun Dong 		return -ENOMEM;
6639c8c7a7eSZhanjun Dong 
6649c8c7a7eSZhanjun Dong 	/* populate capture list header */
6659c8c7a7eSZhanjun Dong 	tmp = caplist;
6669c8c7a7eSZhanjun Dong 	num_regs = guc_cap_list_num_regs(guc, owner, type, capture_class);
6679c8c7a7eSZhanjun Dong 	listnode = (struct guc_debug_capture_list *)tmp;
6689c8c7a7eSZhanjun Dong 	listnode->header.info = FIELD_PREP(GUC_CAPTURELISTHDR_NUMDESCR, (u32)num_regs);
6699c8c7a7eSZhanjun Dong 
6709c8c7a7eSZhanjun Dong 	/* populate list of register descriptor */
6719c8c7a7eSZhanjun Dong 	tmp += sizeof(struct guc_debug_capture_list);
6729c8c7a7eSZhanjun Dong 	guc_capture_list_init(guc, owner, type, capture_class,
6739c8c7a7eSZhanjun Dong 			      (struct guc_mmio_reg *)tmp, num_regs);
6749c8c7a7eSZhanjun Dong 
6759c8c7a7eSZhanjun Dong 	/* cache this list */
6769c8c7a7eSZhanjun Dong 	cache->is_valid = true;
6779c8c7a7eSZhanjun Dong 	cache->ptr = caplist;
6789c8c7a7eSZhanjun Dong 	cache->size = size;
6799c8c7a7eSZhanjun Dong 	cache->status = 0;
6809c8c7a7eSZhanjun Dong 
6819c8c7a7eSZhanjun Dong 	*outptr = caplist;
6829c8c7a7eSZhanjun Dong 
6839c8c7a7eSZhanjun Dong 	return 0;
6849c8c7a7eSZhanjun Dong }
6859c8c7a7eSZhanjun Dong 
6869c8c7a7eSZhanjun Dong /**
6879c8c7a7eSZhanjun Dong  * xe_guc_capture_getnullheader - Get a null list for register capture
6889c8c7a7eSZhanjun Dong  * @guc:	The GuC object
6899c8c7a7eSZhanjun Dong  * @outptr:	Point to cached register capture list
6909c8c7a7eSZhanjun Dong  * @size:	Point to the size
6919c8c7a7eSZhanjun Dong  *
6929c8c7a7eSZhanjun Dong  * This function will alloc for a null list for register capture.
6939c8c7a7eSZhanjun Dong  *
6949c8c7a7eSZhanjun Dong  * Returns: 0 on success or a negative error code on failure.
6959c8c7a7eSZhanjun Dong  */
6969c8c7a7eSZhanjun Dong int
6979c8c7a7eSZhanjun Dong xe_guc_capture_getnullheader(struct xe_guc *guc, void **outptr, size_t *size)
6989c8c7a7eSZhanjun Dong {
6999c8c7a7eSZhanjun Dong 	struct xe_guc_state_capture *gc = guc->capture;
7009c8c7a7eSZhanjun Dong 	int tmp = sizeof(u32) * 4;
7019c8c7a7eSZhanjun Dong 	void *null_header;
7029c8c7a7eSZhanjun Dong 
7039c8c7a7eSZhanjun Dong 	if (gc->ads_null_cache) {
7049c8c7a7eSZhanjun Dong 		*outptr = gc->ads_null_cache;
7059c8c7a7eSZhanjun Dong 		*size = tmp;
7069c8c7a7eSZhanjun Dong 		return 0;
7079c8c7a7eSZhanjun Dong 	}
7089c8c7a7eSZhanjun Dong 
7099c8c7a7eSZhanjun Dong 	null_header = drmm_kzalloc(guc_to_drm(guc), tmp, GFP_KERNEL);
7109c8c7a7eSZhanjun Dong 	if (!null_header)
7119c8c7a7eSZhanjun Dong 		return -ENOMEM;
7129c8c7a7eSZhanjun Dong 
7139c8c7a7eSZhanjun Dong 	gc->ads_null_cache = null_header;
7149c8c7a7eSZhanjun Dong 	*outptr = null_header;
7159c8c7a7eSZhanjun Dong 	*size = tmp;
7169c8c7a7eSZhanjun Dong 
7179c8c7a7eSZhanjun Dong 	return 0;
7189c8c7a7eSZhanjun Dong }
7199c8c7a7eSZhanjun Dong 
7209c8c7a7eSZhanjun Dong /**
7219c8c7a7eSZhanjun Dong  * xe_guc_capture_ads_input_worst_size - Calculate the worst size for GuC register capture
7229c8c7a7eSZhanjun Dong  * @guc: point to xe_guc structure
7239c8c7a7eSZhanjun Dong  *
7249c8c7a7eSZhanjun Dong  * Calculate the worst size for GuC register capture by including all possible engines classes.
7259c8c7a7eSZhanjun Dong  *
7269c8c7a7eSZhanjun Dong  * Returns: Calculated size
7279c8c7a7eSZhanjun Dong  */
7289c8c7a7eSZhanjun Dong size_t xe_guc_capture_ads_input_worst_size(struct xe_guc *guc)
7299c8c7a7eSZhanjun Dong {
7309c8c7a7eSZhanjun Dong 	size_t total_size, class_size, instance_size, global_size;
7319c8c7a7eSZhanjun Dong 	int i, j;
7329c8c7a7eSZhanjun Dong 
7339c8c7a7eSZhanjun Dong 	/*
7349c8c7a7eSZhanjun Dong 	 * This function calculates the worst case register lists size by
7359c8c7a7eSZhanjun Dong 	 * including all possible engines classes. It is called during the
7369c8c7a7eSZhanjun Dong 	 * first of a two-phase GuC (and ADS-population) initialization
7379c8c7a7eSZhanjun Dong 	 * sequence, that is, during the pre-hwconfig phase before we have
7389c8c7a7eSZhanjun Dong 	 * the exact engine fusing info.
7399c8c7a7eSZhanjun Dong 	 */
7409c8c7a7eSZhanjun Dong 	total_size = PAGE_SIZE;	/* Pad a page in front for empty lists */
7419c8c7a7eSZhanjun Dong 	for (i = 0; i < GUC_CAPTURE_LIST_INDEX_MAX; i++) {
7429c8c7a7eSZhanjun Dong 		for (j = 0; j < GUC_CAPTURE_LIST_CLASS_MAX; j++) {
7439c8c7a7eSZhanjun Dong 			if (xe_guc_capture_getlistsize(guc, i,
7449c8c7a7eSZhanjun Dong 						       GUC_STATE_CAPTURE_TYPE_ENGINE_CLASS,
7459c8c7a7eSZhanjun Dong 						       j, &class_size) < 0)
7469c8c7a7eSZhanjun Dong 				class_size = 0;
7479c8c7a7eSZhanjun Dong 			if (xe_guc_capture_getlistsize(guc, i,
7489c8c7a7eSZhanjun Dong 						       GUC_STATE_CAPTURE_TYPE_ENGINE_INSTANCE,
7499c8c7a7eSZhanjun Dong 						       j, &instance_size) < 0)
7509c8c7a7eSZhanjun Dong 				instance_size = 0;
7519c8c7a7eSZhanjun Dong 			total_size += class_size + instance_size;
7529c8c7a7eSZhanjun Dong 		}
7539c8c7a7eSZhanjun Dong 		if (xe_guc_capture_getlistsize(guc, i,
7549c8c7a7eSZhanjun Dong 					       GUC_STATE_CAPTURE_TYPE_GLOBAL,
7559c8c7a7eSZhanjun Dong 					       0, &global_size) < 0)
7569c8c7a7eSZhanjun Dong 			global_size = 0;
7579c8c7a7eSZhanjun Dong 		total_size += global_size;
7589c8c7a7eSZhanjun Dong 	}
7599c8c7a7eSZhanjun Dong 
7609c8c7a7eSZhanjun Dong 	return PAGE_ALIGN(total_size);
7619c8c7a7eSZhanjun Dong }
7629c8c7a7eSZhanjun Dong 
76384d15f42SZhanjun Dong static int guc_capture_output_size_est(struct xe_guc *guc)
76484d15f42SZhanjun Dong {
76584d15f42SZhanjun Dong 	struct xe_gt *gt = guc_to_gt(guc);
76684d15f42SZhanjun Dong 	struct xe_hw_engine *hwe;
76784d15f42SZhanjun Dong 	enum xe_hw_engine_id id;
76884d15f42SZhanjun Dong 
76984d15f42SZhanjun Dong 	int capture_size = 0;
77084d15f42SZhanjun Dong 	size_t tmp = 0;
77184d15f42SZhanjun Dong 
77284d15f42SZhanjun Dong 	if (!guc->capture)
77384d15f42SZhanjun Dong 		return -ENODEV;
77484d15f42SZhanjun Dong 
77584d15f42SZhanjun Dong 	/*
77684d15f42SZhanjun Dong 	 * If every single engine-instance suffered a failure in quick succession but
77784d15f42SZhanjun Dong 	 * were all unrelated, then a burst of multiple error-capture events would dump
77884d15f42SZhanjun Dong 	 * registers for every one engine instance, one at a time. In this case, GuC
77984d15f42SZhanjun Dong 	 * would even dump the global-registers repeatedly.
78084d15f42SZhanjun Dong 	 *
78184d15f42SZhanjun Dong 	 * For each engine instance, there would be 1 x guc_state_capture_group_t output
78284d15f42SZhanjun Dong 	 * followed by 3 x guc_state_capture_t lists. The latter is how the register
78384d15f42SZhanjun Dong 	 * dumps are split across different register types (where the '3' are global vs class
78484d15f42SZhanjun Dong 	 * vs instance).
78584d15f42SZhanjun Dong 	 */
78684d15f42SZhanjun Dong 	for_each_hw_engine(hwe, gt, id) {
78784d15f42SZhanjun Dong 		enum guc_capture_list_class_type capture_class;
78884d15f42SZhanjun Dong 
78984d15f42SZhanjun Dong 		capture_class = xe_engine_class_to_guc_capture_class(hwe->class);
79084d15f42SZhanjun Dong 		capture_size += sizeof(struct guc_state_capture_group_header_t) +
79184d15f42SZhanjun Dong 					 (3 * sizeof(struct guc_state_capture_header_t));
79284d15f42SZhanjun Dong 
79384d15f42SZhanjun Dong 		if (!guc_capture_getlistsize(guc, 0, GUC_STATE_CAPTURE_TYPE_GLOBAL,
79484d15f42SZhanjun Dong 					     0, &tmp, true))
79584d15f42SZhanjun Dong 			capture_size += tmp;
79684d15f42SZhanjun Dong 		if (!guc_capture_getlistsize(guc, 0, GUC_STATE_CAPTURE_TYPE_ENGINE_CLASS,
79784d15f42SZhanjun Dong 					     capture_class, &tmp, true))
79884d15f42SZhanjun Dong 			capture_size += tmp;
79984d15f42SZhanjun Dong 		if (!guc_capture_getlistsize(guc, 0, GUC_STATE_CAPTURE_TYPE_ENGINE_INSTANCE,
80084d15f42SZhanjun Dong 					     capture_class, &tmp, true))
80184d15f42SZhanjun Dong 			capture_size += tmp;
80284d15f42SZhanjun Dong 	}
80384d15f42SZhanjun Dong 
80484d15f42SZhanjun Dong 	return capture_size;
80584d15f42SZhanjun Dong }
80684d15f42SZhanjun Dong 
80784d15f42SZhanjun Dong /*
80884d15f42SZhanjun Dong  * Add on a 3x multiplier to allow for multiple back-to-back captures occurring
80984d15f42SZhanjun Dong  * before the Xe can read the data out and process it
81084d15f42SZhanjun Dong  */
81184d15f42SZhanjun Dong #define GUC_CAPTURE_OVERBUFFER_MULTIPLIER 3
81284d15f42SZhanjun Dong 
81384d15f42SZhanjun Dong static void check_guc_capture_size(struct xe_guc *guc)
81484d15f42SZhanjun Dong {
81584d15f42SZhanjun Dong 	int capture_size = guc_capture_output_size_est(guc);
81684d15f42SZhanjun Dong 	int spare_size = capture_size * GUC_CAPTURE_OVERBUFFER_MULTIPLIER;
81784d15f42SZhanjun Dong 	u32 buffer_size = xe_guc_log_section_size_capture(&guc->log);
81884d15f42SZhanjun Dong 
81984d15f42SZhanjun Dong 	/*
82084d15f42SZhanjun Dong 	 * NOTE: capture_size is much smaller than the capture region
82184d15f42SZhanjun Dong 	 * allocation (DG2: <80K vs 1MB).
82284d15f42SZhanjun Dong 	 * Additionally, its based on space needed to fit all engines getting
82384d15f42SZhanjun Dong 	 * reset at once within the same G2H handler task slot. This is very
82484d15f42SZhanjun Dong 	 * unlikely. However, if GuC really does run out of space for whatever
82584d15f42SZhanjun Dong 	 * reason, we will see an separate warning message when processing the
82684d15f42SZhanjun Dong 	 * G2H event capture-notification, search for:
82784d15f42SZhanjun Dong 	 * xe_guc_STATE_CAPTURE_EVENT_STATUS_NOSPACE.
82884d15f42SZhanjun Dong 	 */
82984d15f42SZhanjun Dong 	if (capture_size < 0)
83084d15f42SZhanjun Dong 		xe_gt_dbg(guc_to_gt(guc),
83184d15f42SZhanjun Dong 			  "Failed to calculate error state capture buffer minimum size: %d!\n",
83284d15f42SZhanjun Dong 			  capture_size);
83384d15f42SZhanjun Dong 	if (capture_size > buffer_size)
83484d15f42SZhanjun Dong 		xe_gt_dbg(guc_to_gt(guc), "Error state capture buffer maybe small: %d < %d\n",
83584d15f42SZhanjun Dong 			  buffer_size, capture_size);
83684d15f42SZhanjun Dong 	else if (spare_size > buffer_size)
83784d15f42SZhanjun Dong 		xe_gt_dbg(guc_to_gt(guc),
83884d15f42SZhanjun Dong 			  "Error state capture buffer lacks spare size: %d < %d (min = %d)\n",
83984d15f42SZhanjun Dong 			  buffer_size, spare_size, capture_size);
84084d15f42SZhanjun Dong }
84184d15f42SZhanjun Dong 
8428bfc4963SZhanjun Dong static void
8438bfc4963SZhanjun Dong guc_capture_add_node_to_list(struct __guc_capture_parsed_output *node,
8448bfc4963SZhanjun Dong 			     struct list_head *list)
8458bfc4963SZhanjun Dong {
846*ecb63364SZhanjun Dong 	list_add(&node->link, list);
8478bfc4963SZhanjun Dong }
8488bfc4963SZhanjun Dong 
8498bfc4963SZhanjun Dong static void
8508bfc4963SZhanjun Dong guc_capture_add_node_to_outlist(struct xe_guc_state_capture *gc,
8518bfc4963SZhanjun Dong 				struct __guc_capture_parsed_output *node)
8528bfc4963SZhanjun Dong {
853*ecb63364SZhanjun Dong 	guc_capture_remove_stale_matches_from_list(gc, node);
8548bfc4963SZhanjun Dong 	guc_capture_add_node_to_list(node, &gc->outlist);
8558bfc4963SZhanjun Dong }
8568bfc4963SZhanjun Dong 
8578bfc4963SZhanjun Dong static void
8588bfc4963SZhanjun Dong guc_capture_add_node_to_cachelist(struct xe_guc_state_capture *gc,
8598bfc4963SZhanjun Dong 				  struct __guc_capture_parsed_output *node)
8608bfc4963SZhanjun Dong {
8618bfc4963SZhanjun Dong 	guc_capture_add_node_to_list(node, &gc->cachelist);
8628bfc4963SZhanjun Dong }
8638bfc4963SZhanjun Dong 
8648bfc4963SZhanjun Dong static void
865*ecb63364SZhanjun Dong guc_capture_free_outlist_node(struct xe_guc_state_capture *gc,
866*ecb63364SZhanjun Dong 			      struct __guc_capture_parsed_output *n)
867*ecb63364SZhanjun Dong {
868*ecb63364SZhanjun Dong 	if (n) {
869*ecb63364SZhanjun Dong 		n->locked = 0;
870*ecb63364SZhanjun Dong 		list_del(&n->link);
871*ecb63364SZhanjun Dong 		/* put node back to cache list */
872*ecb63364SZhanjun Dong 		guc_capture_add_node_to_cachelist(gc, n);
873*ecb63364SZhanjun Dong 	}
874*ecb63364SZhanjun Dong }
875*ecb63364SZhanjun Dong 
876*ecb63364SZhanjun Dong static void
877*ecb63364SZhanjun Dong guc_capture_remove_stale_matches_from_list(struct xe_guc_state_capture *gc,
878*ecb63364SZhanjun Dong 					   struct __guc_capture_parsed_output *node)
879*ecb63364SZhanjun Dong {
880*ecb63364SZhanjun Dong 	struct __guc_capture_parsed_output *n, *ntmp;
881*ecb63364SZhanjun Dong 	int guc_id = node->guc_id;
882*ecb63364SZhanjun Dong 
883*ecb63364SZhanjun Dong 	list_for_each_entry_safe(n, ntmp, &gc->outlist, link) {
884*ecb63364SZhanjun Dong 		if (n != node && !n->locked && n->guc_id == guc_id)
885*ecb63364SZhanjun Dong 			guc_capture_free_outlist_node(gc, n);
886*ecb63364SZhanjun Dong 	}
887*ecb63364SZhanjun Dong }
888*ecb63364SZhanjun Dong 
889*ecb63364SZhanjun Dong static void
8908bfc4963SZhanjun Dong guc_capture_init_node(struct xe_guc *guc, struct __guc_capture_parsed_output *node)
8918bfc4963SZhanjun Dong {
8928bfc4963SZhanjun Dong 	struct guc_mmio_reg *tmp[GUC_STATE_CAPTURE_TYPE_MAX];
8938bfc4963SZhanjun Dong 	int i;
8948bfc4963SZhanjun Dong 
8958bfc4963SZhanjun Dong 	for (i = 0; i < GUC_STATE_CAPTURE_TYPE_MAX; ++i) {
8968bfc4963SZhanjun Dong 		tmp[i] = node->reginfo[i].regs;
8978bfc4963SZhanjun Dong 		memset(tmp[i], 0, sizeof(struct guc_mmio_reg) *
8988bfc4963SZhanjun Dong 		       guc->capture->max_mmio_per_node);
8998bfc4963SZhanjun Dong 	}
9008bfc4963SZhanjun Dong 	memset(node, 0, sizeof(*node));
9018bfc4963SZhanjun Dong 	for (i = 0; i < GUC_STATE_CAPTURE_TYPE_MAX; ++i)
9028bfc4963SZhanjun Dong 		node->reginfo[i].regs = tmp[i];
9038bfc4963SZhanjun Dong 
9048bfc4963SZhanjun Dong 	INIT_LIST_HEAD(&node->link);
9058bfc4963SZhanjun Dong }
9068bfc4963SZhanjun Dong 
9078bfc4963SZhanjun Dong /**
9088bfc4963SZhanjun Dong  * DOC: Init, G2H-event and reporting flows for GuC-error-capture
9098bfc4963SZhanjun Dong  *
9108bfc4963SZhanjun Dong  * KMD Init time flows:
9118bfc4963SZhanjun Dong  * --------------------
9128bfc4963SZhanjun Dong  *     --> alloc A: GuC input capture regs lists (registered to GuC via ADS).
9138bfc4963SZhanjun Dong  *                  xe_guc_ads acquires the register lists by calling
9148bfc4963SZhanjun Dong  *                  xe_guc_capture_getlistsize and xe_guc_capture_getlist 'n' times,
9158bfc4963SZhanjun Dong  *                  where n = 1 for global-reg-list +
9168bfc4963SZhanjun Dong  *                            num_engine_classes for class-reg-list +
9178bfc4963SZhanjun Dong  *                            num_engine_classes for instance-reg-list
9188bfc4963SZhanjun Dong  *                               (since all instances of the same engine-class type
9198bfc4963SZhanjun Dong  *                                have an identical engine-instance register-list).
9208bfc4963SZhanjun Dong  *                  ADS module also calls separately for PF vs VF.
9218bfc4963SZhanjun Dong  *
9228bfc4963SZhanjun Dong  *     --> alloc B: GuC output capture buf (registered via guc_init_params(log_param))
9238bfc4963SZhanjun Dong  *                  Size = #define CAPTURE_BUFFER_SIZE (warns if on too-small)
9248bfc4963SZhanjun Dong  *                  Note2: 'x 3' to hold multiple capture groups
9258bfc4963SZhanjun Dong  *
9268bfc4963SZhanjun Dong  * GUC Runtime notify capture:
9278bfc4963SZhanjun Dong  * --------------------------
9288bfc4963SZhanjun Dong  *     --> G2H STATE_CAPTURE_NOTIFICATION
9298bfc4963SZhanjun Dong  *                   L--> xe_guc_capture_process
9308bfc4963SZhanjun Dong  *                           L--> Loop through B (head..tail) and for each engine instance's
9318bfc4963SZhanjun Dong  *                                err-state-captured register-list we find, we alloc 'C':
9328bfc4963SZhanjun Dong  *      --> alloc C: A capture-output-node structure that includes misc capture info along
9338bfc4963SZhanjun Dong  *                   with 3 register list dumps (global, engine-class and engine-instance)
9348bfc4963SZhanjun Dong  *                   This node is created from a pre-allocated list of blank nodes in
9358bfc4963SZhanjun Dong  *                   guc->capture->cachelist and populated with the error-capture
9368bfc4963SZhanjun Dong  *                   data from GuC and then it's added into guc->capture->outlist linked
9378bfc4963SZhanjun Dong  *                   list. This list is used for matchup and printout by xe_devcoredump_read
9388bfc4963SZhanjun Dong  *                   and xe_hw_engine_snapshot_print, (when user invokes the devcoredump sysfs).
9398bfc4963SZhanjun Dong  *
9408bfc4963SZhanjun Dong  * GUC --> notify context reset:
9418bfc4963SZhanjun Dong  * -----------------------------
9428bfc4963SZhanjun Dong  *     --> guc_exec_queue_timedout_job
9438bfc4963SZhanjun Dong  *                   L--> xe_devcoredump
9448bfc4963SZhanjun Dong  *                          L--> devcoredump_snapshot
9458bfc4963SZhanjun Dong  *                               --> xe_hw_engine_snapshot_capture
9468bfc4963SZhanjun Dong  *
9478bfc4963SZhanjun Dong  * User Sysfs / Debugfs
9488bfc4963SZhanjun Dong  * --------------------
9498bfc4963SZhanjun Dong  *      --> xe_devcoredump_read->
9508bfc4963SZhanjun Dong  *             L--> xxx_snapshot_print
9518bfc4963SZhanjun Dong  *                    L--> xe_hw_engine_snapshot_print
9528bfc4963SZhanjun Dong  *                         Print register lists values saved at
9538bfc4963SZhanjun Dong  *                         guc->capture->outlist
9548bfc4963SZhanjun Dong  *
9558bfc4963SZhanjun Dong  */
9568bfc4963SZhanjun Dong 
9578bfc4963SZhanjun Dong static int guc_capture_buf_cnt(struct __guc_capture_bufstate *buf)
9588bfc4963SZhanjun Dong {
9598bfc4963SZhanjun Dong 	if (buf->wr >= buf->rd)
9608bfc4963SZhanjun Dong 		return (buf->wr - buf->rd);
9618bfc4963SZhanjun Dong 	return (buf->size - buf->rd) + buf->wr;
9628bfc4963SZhanjun Dong }
9638bfc4963SZhanjun Dong 
9648bfc4963SZhanjun Dong static int guc_capture_buf_cnt_to_end(struct __guc_capture_bufstate *buf)
9658bfc4963SZhanjun Dong {
9668bfc4963SZhanjun Dong 	if (buf->rd > buf->wr)
9678bfc4963SZhanjun Dong 		return (buf->size - buf->rd);
9688bfc4963SZhanjun Dong 	return (buf->wr - buf->rd);
9698bfc4963SZhanjun Dong }
9708bfc4963SZhanjun Dong 
9718bfc4963SZhanjun Dong /*
9728bfc4963SZhanjun Dong  * GuC's error-capture output is a ring buffer populated in a byte-stream fashion:
9738bfc4963SZhanjun Dong  *
9748bfc4963SZhanjun Dong  * The GuC Log buffer region for error-capture is managed like a ring buffer.
9758bfc4963SZhanjun Dong  * The GuC firmware dumps error capture logs into this ring in a byte-stream flow.
9768bfc4963SZhanjun Dong  * Additionally, as per the current and foreseeable future, all packed error-
9778bfc4963SZhanjun Dong  * capture output structures are dword aligned.
9788bfc4963SZhanjun Dong  *
9798bfc4963SZhanjun Dong  * That said, if the GuC firmware is in the midst of writing a structure that is larger
9808bfc4963SZhanjun Dong  * than one dword but the tail end of the err-capture buffer-region has lesser space left,
9818bfc4963SZhanjun Dong  * we would need to extract that structure one dword at a time straddled across the end,
9828bfc4963SZhanjun Dong  * onto the start of the ring.
9838bfc4963SZhanjun Dong  *
9848bfc4963SZhanjun Dong  * Below function, guc_capture_log_remove_bytes is a helper for that. All callers of this
9858bfc4963SZhanjun Dong  * function would typically do a straight-up memcpy from the ring contents and will only
9868bfc4963SZhanjun Dong  * call this helper if their structure-extraction is straddling across the end of the
9878bfc4963SZhanjun Dong  * ring. GuC firmware does not add any padding. The reason for the no-padding is to ease
9888bfc4963SZhanjun Dong  * scalability for future expansion of output data types without requiring a redesign
9898bfc4963SZhanjun Dong  * of the flow controls.
9908bfc4963SZhanjun Dong  */
9918bfc4963SZhanjun Dong static int
9928bfc4963SZhanjun Dong guc_capture_log_remove_bytes(struct xe_guc *guc, struct __guc_capture_bufstate *buf,
9938bfc4963SZhanjun Dong 			     void *out, int bytes_needed)
9948bfc4963SZhanjun Dong {
9958bfc4963SZhanjun Dong #define GUC_CAPTURE_LOG_BUF_COPY_RETRY_MAX	3
9968bfc4963SZhanjun Dong 
9978bfc4963SZhanjun Dong 	int fill_size = 0, tries = GUC_CAPTURE_LOG_BUF_COPY_RETRY_MAX;
9988bfc4963SZhanjun Dong 	int copy_size, avail;
9998bfc4963SZhanjun Dong 
10008bfc4963SZhanjun Dong 	xe_assert(guc_to_xe(guc), bytes_needed % sizeof(u32) == 0);
10018bfc4963SZhanjun Dong 
10028bfc4963SZhanjun Dong 	if (bytes_needed > guc_capture_buf_cnt(buf))
10038bfc4963SZhanjun Dong 		return -1;
10048bfc4963SZhanjun Dong 
10058bfc4963SZhanjun Dong 	while (bytes_needed > 0 && tries--) {
10068bfc4963SZhanjun Dong 		int misaligned;
10078bfc4963SZhanjun Dong 
10088bfc4963SZhanjun Dong 		avail = guc_capture_buf_cnt_to_end(buf);
10098bfc4963SZhanjun Dong 		misaligned = avail % sizeof(u32);
10108bfc4963SZhanjun Dong 		/* wrap if at end */
10118bfc4963SZhanjun Dong 		if (!avail) {
10128bfc4963SZhanjun Dong 			/* output stream clipped */
10138bfc4963SZhanjun Dong 			if (!buf->rd)
10148bfc4963SZhanjun Dong 				return fill_size;
10158bfc4963SZhanjun Dong 			buf->rd = 0;
10168bfc4963SZhanjun Dong 			continue;
10178bfc4963SZhanjun Dong 		}
10188bfc4963SZhanjun Dong 
10198bfc4963SZhanjun Dong 		/* Only copy to u32 aligned data */
10208bfc4963SZhanjun Dong 		copy_size = avail < bytes_needed ? avail - misaligned : bytes_needed;
10218bfc4963SZhanjun Dong 		xe_map_memcpy_from(guc_to_xe(guc), out + fill_size, &guc->log.bo->vmap,
10228bfc4963SZhanjun Dong 				   buf->data_offset + buf->rd, copy_size);
10238bfc4963SZhanjun Dong 		buf->rd += copy_size;
10248bfc4963SZhanjun Dong 		fill_size += copy_size;
10258bfc4963SZhanjun Dong 		bytes_needed -= copy_size;
10268bfc4963SZhanjun Dong 
10278bfc4963SZhanjun Dong 		if (misaligned)
10288bfc4963SZhanjun Dong 			xe_gt_warn(guc_to_gt(guc),
10298bfc4963SZhanjun Dong 				   "Bytes extraction not dword aligned, clipping.\n");
10308bfc4963SZhanjun Dong 	}
10318bfc4963SZhanjun Dong 
10328bfc4963SZhanjun Dong 	return fill_size;
10338bfc4963SZhanjun Dong }
10348bfc4963SZhanjun Dong 
10358bfc4963SZhanjun Dong static int
10368bfc4963SZhanjun Dong guc_capture_log_get_group_hdr(struct xe_guc *guc, struct __guc_capture_bufstate *buf,
10378bfc4963SZhanjun Dong 			      struct guc_state_capture_group_header_t *ghdr)
10388bfc4963SZhanjun Dong {
10398bfc4963SZhanjun Dong 	int fullsize = sizeof(struct guc_state_capture_group_header_t);
10408bfc4963SZhanjun Dong 
10418bfc4963SZhanjun Dong 	if (guc_capture_log_remove_bytes(guc, buf, ghdr, fullsize) != fullsize)
10428bfc4963SZhanjun Dong 		return -1;
10438bfc4963SZhanjun Dong 	return 0;
10448bfc4963SZhanjun Dong }
10458bfc4963SZhanjun Dong 
10468bfc4963SZhanjun Dong static int
10478bfc4963SZhanjun Dong guc_capture_log_get_data_hdr(struct xe_guc *guc, struct __guc_capture_bufstate *buf,
10488bfc4963SZhanjun Dong 			     struct guc_state_capture_header_t *hdr)
10498bfc4963SZhanjun Dong {
10508bfc4963SZhanjun Dong 	int fullsize = sizeof(struct guc_state_capture_header_t);
10518bfc4963SZhanjun Dong 
10528bfc4963SZhanjun Dong 	if (guc_capture_log_remove_bytes(guc, buf, hdr, fullsize) != fullsize)
10538bfc4963SZhanjun Dong 		return -1;
10548bfc4963SZhanjun Dong 	return 0;
10558bfc4963SZhanjun Dong }
10568bfc4963SZhanjun Dong 
10578bfc4963SZhanjun Dong static int
10588bfc4963SZhanjun Dong guc_capture_log_get_register(struct xe_guc *guc, struct __guc_capture_bufstate *buf,
10598bfc4963SZhanjun Dong 			     struct guc_mmio_reg *reg)
10608bfc4963SZhanjun Dong {
10618bfc4963SZhanjun Dong 	int fullsize = sizeof(struct guc_mmio_reg);
10628bfc4963SZhanjun Dong 
10638bfc4963SZhanjun Dong 	if (guc_capture_log_remove_bytes(guc, buf, reg, fullsize) != fullsize)
10648bfc4963SZhanjun Dong 		return -1;
10658bfc4963SZhanjun Dong 	return 0;
10668bfc4963SZhanjun Dong }
10678bfc4963SZhanjun Dong 
10688bfc4963SZhanjun Dong static struct __guc_capture_parsed_output *
10698bfc4963SZhanjun Dong guc_capture_get_prealloc_node(struct xe_guc *guc)
10708bfc4963SZhanjun Dong {
10718bfc4963SZhanjun Dong 	struct __guc_capture_parsed_output *found = NULL;
10728bfc4963SZhanjun Dong 
10738bfc4963SZhanjun Dong 	if (!list_empty(&guc->capture->cachelist)) {
10748bfc4963SZhanjun Dong 		struct __guc_capture_parsed_output *n, *ntmp;
10758bfc4963SZhanjun Dong 
10768bfc4963SZhanjun Dong 		/* get first avail node from the cache list */
10778bfc4963SZhanjun Dong 		list_for_each_entry_safe(n, ntmp, &guc->capture->cachelist, link) {
10788bfc4963SZhanjun Dong 			found = n;
10798bfc4963SZhanjun Dong 			break;
10808bfc4963SZhanjun Dong 		}
10818bfc4963SZhanjun Dong 	} else {
10828bfc4963SZhanjun Dong 		struct __guc_capture_parsed_output *n, *ntmp;
10838bfc4963SZhanjun Dong 
1084*ecb63364SZhanjun Dong 		/*
1085*ecb63364SZhanjun Dong 		 * traverse reversed and steal back the oldest node already
1086*ecb63364SZhanjun Dong 		 * allocated
1087*ecb63364SZhanjun Dong 		 */
1088*ecb63364SZhanjun Dong 		list_for_each_entry_safe_reverse(n, ntmp, &guc->capture->outlist, link) {
1089*ecb63364SZhanjun Dong 			if (!n->locked)
10908bfc4963SZhanjun Dong 				found = n;
10918bfc4963SZhanjun Dong 		}
10928bfc4963SZhanjun Dong 	}
10938bfc4963SZhanjun Dong 	if (found) {
10948bfc4963SZhanjun Dong 		list_del(&found->link);
10958bfc4963SZhanjun Dong 		guc_capture_init_node(guc, found);
10968bfc4963SZhanjun Dong 	}
10978bfc4963SZhanjun Dong 
10988bfc4963SZhanjun Dong 	return found;
10998bfc4963SZhanjun Dong }
11008bfc4963SZhanjun Dong 
11018bfc4963SZhanjun Dong static struct __guc_capture_parsed_output *
11028bfc4963SZhanjun Dong guc_capture_clone_node(struct xe_guc *guc, struct __guc_capture_parsed_output *original,
11038bfc4963SZhanjun Dong 		       u32 keep_reglist_mask)
11048bfc4963SZhanjun Dong {
11058bfc4963SZhanjun Dong 	struct __guc_capture_parsed_output *new;
11068bfc4963SZhanjun Dong 	int i;
11078bfc4963SZhanjun Dong 
11088bfc4963SZhanjun Dong 	new = guc_capture_get_prealloc_node(guc);
11098bfc4963SZhanjun Dong 	if (!new)
11108bfc4963SZhanjun Dong 		return NULL;
11118bfc4963SZhanjun Dong 	if (!original)
11128bfc4963SZhanjun Dong 		return new;
11138bfc4963SZhanjun Dong 
11148bfc4963SZhanjun Dong 	new->is_partial = original->is_partial;
11158bfc4963SZhanjun Dong 
11168bfc4963SZhanjun Dong 	/* copy reg-lists that we want to clone */
11178bfc4963SZhanjun Dong 	for (i = 0; i < GUC_STATE_CAPTURE_TYPE_MAX; ++i) {
11188bfc4963SZhanjun Dong 		if (keep_reglist_mask & BIT(i)) {
11198bfc4963SZhanjun Dong 			XE_WARN_ON(original->reginfo[i].num_regs  >
11208bfc4963SZhanjun Dong 				   guc->capture->max_mmio_per_node);
11218bfc4963SZhanjun Dong 
11228bfc4963SZhanjun Dong 			memcpy(new->reginfo[i].regs, original->reginfo[i].regs,
11238bfc4963SZhanjun Dong 			       original->reginfo[i].num_regs * sizeof(struct guc_mmio_reg));
11248bfc4963SZhanjun Dong 
11258bfc4963SZhanjun Dong 			new->reginfo[i].num_regs = original->reginfo[i].num_regs;
11268bfc4963SZhanjun Dong 			new->reginfo[i].vfid  = original->reginfo[i].vfid;
11278bfc4963SZhanjun Dong 
11288bfc4963SZhanjun Dong 			if (i == GUC_STATE_CAPTURE_TYPE_ENGINE_CLASS) {
11298bfc4963SZhanjun Dong 				new->eng_class = original->eng_class;
11308bfc4963SZhanjun Dong 			} else if (i == GUC_STATE_CAPTURE_TYPE_ENGINE_INSTANCE) {
11318bfc4963SZhanjun Dong 				new->eng_inst = original->eng_inst;
11328bfc4963SZhanjun Dong 				new->guc_id = original->guc_id;
11338bfc4963SZhanjun Dong 				new->lrca = original->lrca;
11348bfc4963SZhanjun Dong 			}
11358bfc4963SZhanjun Dong 		}
11368bfc4963SZhanjun Dong 	}
11378bfc4963SZhanjun Dong 
11388bfc4963SZhanjun Dong 	return new;
11398bfc4963SZhanjun Dong }
11408bfc4963SZhanjun Dong 
11418bfc4963SZhanjun Dong static int
11428bfc4963SZhanjun Dong guc_capture_extract_reglists(struct xe_guc *guc, struct __guc_capture_bufstate *buf)
11438bfc4963SZhanjun Dong {
11448bfc4963SZhanjun Dong 	struct xe_gt *gt = guc_to_gt(guc);
11458bfc4963SZhanjun Dong 	struct guc_state_capture_group_header_t ghdr = {0};
11468bfc4963SZhanjun Dong 	struct guc_state_capture_header_t hdr = {0};
11478bfc4963SZhanjun Dong 	struct __guc_capture_parsed_output *node = NULL;
11488bfc4963SZhanjun Dong 	struct guc_mmio_reg *regs = NULL;
11498bfc4963SZhanjun Dong 	int i, numlists, numregs, ret = 0;
11508bfc4963SZhanjun Dong 	enum guc_state_capture_type datatype;
11518bfc4963SZhanjun Dong 	struct guc_mmio_reg tmp;
11528bfc4963SZhanjun Dong 	bool is_partial = false;
11538bfc4963SZhanjun Dong 
11548bfc4963SZhanjun Dong 	i = guc_capture_buf_cnt(buf);
11558bfc4963SZhanjun Dong 	if (!i)
11568bfc4963SZhanjun Dong 		return -ENODATA;
11578bfc4963SZhanjun Dong 
11588bfc4963SZhanjun Dong 	if (i % sizeof(u32)) {
11598bfc4963SZhanjun Dong 		xe_gt_warn(gt, "Got mis-aligned register capture entries\n");
11608bfc4963SZhanjun Dong 		ret = -EIO;
11618bfc4963SZhanjun Dong 		goto bailout;
11628bfc4963SZhanjun Dong 	}
11638bfc4963SZhanjun Dong 
11648bfc4963SZhanjun Dong 	/* first get the capture group header */
11658bfc4963SZhanjun Dong 	if (guc_capture_log_get_group_hdr(guc, buf, &ghdr)) {
11668bfc4963SZhanjun Dong 		ret = -EIO;
11678bfc4963SZhanjun Dong 		goto bailout;
11688bfc4963SZhanjun Dong 	}
11698bfc4963SZhanjun Dong 	/*
11708bfc4963SZhanjun Dong 	 * we would typically expect a layout as below where n would be expected to be
11718bfc4963SZhanjun Dong 	 * anywhere between 3 to n where n > 3 if we are seeing multiple dependent engine
11728bfc4963SZhanjun Dong 	 * instances being reset together.
11738bfc4963SZhanjun Dong 	 * ____________________________________________
11748bfc4963SZhanjun Dong 	 * | Capture Group                            |
11758bfc4963SZhanjun Dong 	 * | ________________________________________ |
11768bfc4963SZhanjun Dong 	 * | | Capture Group Header:                | |
11778bfc4963SZhanjun Dong 	 * | |  - num_captures = 5                  | |
11788bfc4963SZhanjun Dong 	 * | |______________________________________| |
11798bfc4963SZhanjun Dong 	 * | ________________________________________ |
11808bfc4963SZhanjun Dong 	 * | | Capture1:                            | |
11818bfc4963SZhanjun Dong 	 * | |  Hdr: GLOBAL, numregs=a              | |
11828bfc4963SZhanjun Dong 	 * | | ____________________________________ | |
11838bfc4963SZhanjun Dong 	 * | | | Reglist                          | | |
11848bfc4963SZhanjun Dong 	 * | | | - reg1, reg2, ... rega           | | |
11858bfc4963SZhanjun Dong 	 * | | |__________________________________| | |
11868bfc4963SZhanjun Dong 	 * | |______________________________________| |
11878bfc4963SZhanjun Dong 	 * | ________________________________________ |
11888bfc4963SZhanjun Dong 	 * | | Capture2:                            | |
11898bfc4963SZhanjun Dong 	 * | |  Hdr: CLASS=RENDER/COMPUTE, numregs=b| |
11908bfc4963SZhanjun Dong 	 * | | ____________________________________ | |
11918bfc4963SZhanjun Dong 	 * | | | Reglist                          | | |
11928bfc4963SZhanjun Dong 	 * | | | - reg1, reg2, ... regb           | | |
11938bfc4963SZhanjun Dong 	 * | | |__________________________________| | |
11948bfc4963SZhanjun Dong 	 * | |______________________________________| |
11958bfc4963SZhanjun Dong 	 * | ________________________________________ |
11968bfc4963SZhanjun Dong 	 * | | Capture3:                            | |
11978bfc4963SZhanjun Dong 	 * | |  Hdr: INSTANCE=RCS, numregs=c        | |
11988bfc4963SZhanjun Dong 	 * | | ____________________________________ | |
11998bfc4963SZhanjun Dong 	 * | | | Reglist                          | | |
12008bfc4963SZhanjun Dong 	 * | | | - reg1, reg2, ... regc           | | |
12018bfc4963SZhanjun Dong 	 * | | |__________________________________| | |
12028bfc4963SZhanjun Dong 	 * | |______________________________________| |
12038bfc4963SZhanjun Dong 	 * | ________________________________________ |
12048bfc4963SZhanjun Dong 	 * | | Capture4:                            | |
12058bfc4963SZhanjun Dong 	 * | |  Hdr: CLASS=RENDER/COMPUTE, numregs=d| |
12068bfc4963SZhanjun Dong 	 * | | ____________________________________ | |
12078bfc4963SZhanjun Dong 	 * | | | Reglist                          | | |
12088bfc4963SZhanjun Dong 	 * | | | - reg1, reg2, ... regd           | | |
12098bfc4963SZhanjun Dong 	 * | | |__________________________________| | |
12108bfc4963SZhanjun Dong 	 * | |______________________________________| |
12118bfc4963SZhanjun Dong 	 * | ________________________________________ |
12128bfc4963SZhanjun Dong 	 * | | Capture5:                            | |
12138bfc4963SZhanjun Dong 	 * | |  Hdr: INSTANCE=CCS0, numregs=e       | |
12148bfc4963SZhanjun Dong 	 * | | ____________________________________ | |
12158bfc4963SZhanjun Dong 	 * | | | Reglist                          | | |
12168bfc4963SZhanjun Dong 	 * | | | - reg1, reg2, ... rege           | | |
12178bfc4963SZhanjun Dong 	 * | | |__________________________________| | |
12188bfc4963SZhanjun Dong 	 * | |______________________________________| |
12198bfc4963SZhanjun Dong 	 * |__________________________________________|
12208bfc4963SZhanjun Dong 	 */
12218bfc4963SZhanjun Dong 	is_partial = FIELD_GET(GUC_STATE_CAPTURE_GROUP_HEADER_CAPTURE_GROUP_TYPE, ghdr.info);
12228bfc4963SZhanjun Dong 	numlists = FIELD_GET(GUC_STATE_CAPTURE_GROUP_HEADER_NUM_CAPTURES, ghdr.info);
12238bfc4963SZhanjun Dong 
12248bfc4963SZhanjun Dong 	while (numlists--) {
12258bfc4963SZhanjun Dong 		if (guc_capture_log_get_data_hdr(guc, buf, &hdr)) {
12268bfc4963SZhanjun Dong 			ret = -EIO;
12278bfc4963SZhanjun Dong 			break;
12288bfc4963SZhanjun Dong 		}
12298bfc4963SZhanjun Dong 
12308bfc4963SZhanjun Dong 		datatype = FIELD_GET(GUC_STATE_CAPTURE_HEADER_CAPTURE_TYPE, hdr.info);
12318bfc4963SZhanjun Dong 		if (datatype > GUC_STATE_CAPTURE_TYPE_ENGINE_INSTANCE) {
12328bfc4963SZhanjun Dong 			/* unknown capture type - skip over to next capture set */
12338bfc4963SZhanjun Dong 			numregs = FIELD_GET(GUC_STATE_CAPTURE_HEADER_NUM_MMIO_ENTRIES,
12348bfc4963SZhanjun Dong 					    hdr.num_mmio_entries);
12358bfc4963SZhanjun Dong 			while (numregs--) {
12368bfc4963SZhanjun Dong 				if (guc_capture_log_get_register(guc, buf, &tmp)) {
12378bfc4963SZhanjun Dong 					ret = -EIO;
12388bfc4963SZhanjun Dong 					break;
12398bfc4963SZhanjun Dong 				}
12408bfc4963SZhanjun Dong 			}
12418bfc4963SZhanjun Dong 			continue;
12428bfc4963SZhanjun Dong 		} else if (node) {
12438bfc4963SZhanjun Dong 			/*
12448bfc4963SZhanjun Dong 			 * Based on the current capture type and what we have so far,
12458bfc4963SZhanjun Dong 			 * decide if we should add the current node into the internal
12468bfc4963SZhanjun Dong 			 * linked list for match-up when xe_devcoredump calls later
12478bfc4963SZhanjun Dong 			 * (and alloc a blank node for the next set of reglists)
12488bfc4963SZhanjun Dong 			 * or continue with the same node or clone the current node
12498bfc4963SZhanjun Dong 			 * but only retain the global or class registers (such as the
12508bfc4963SZhanjun Dong 			 * case of dependent engine resets).
12518bfc4963SZhanjun Dong 			 */
12528bfc4963SZhanjun Dong 			if (datatype == GUC_STATE_CAPTURE_TYPE_GLOBAL) {
12538bfc4963SZhanjun Dong 				guc_capture_add_node_to_outlist(guc->capture, node);
12548bfc4963SZhanjun Dong 				node = NULL;
12558bfc4963SZhanjun Dong 			} else if (datatype == GUC_STATE_CAPTURE_TYPE_ENGINE_CLASS &&
12568bfc4963SZhanjun Dong 				   node->reginfo[GUC_STATE_CAPTURE_TYPE_ENGINE_CLASS].num_regs) {
12578bfc4963SZhanjun Dong 				/* Add to list, clone node and duplicate global list */
12588bfc4963SZhanjun Dong 				guc_capture_add_node_to_outlist(guc->capture, node);
12598bfc4963SZhanjun Dong 				node = guc_capture_clone_node(guc, node,
12608bfc4963SZhanjun Dong 							      GCAP_PARSED_REGLIST_INDEX_GLOBAL);
12618bfc4963SZhanjun Dong 			} else if (datatype == GUC_STATE_CAPTURE_TYPE_ENGINE_INSTANCE &&
12628bfc4963SZhanjun Dong 				   node->reginfo[GUC_STATE_CAPTURE_TYPE_ENGINE_INSTANCE].num_regs) {
12638bfc4963SZhanjun Dong 				/* Add to list, clone node and duplicate global + class lists */
12648bfc4963SZhanjun Dong 				guc_capture_add_node_to_outlist(guc->capture, node);
12658bfc4963SZhanjun Dong 				node = guc_capture_clone_node(guc, node,
12668bfc4963SZhanjun Dong 							      (GCAP_PARSED_REGLIST_INDEX_GLOBAL |
12678bfc4963SZhanjun Dong 							      GCAP_PARSED_REGLIST_INDEX_ENGCLASS));
12688bfc4963SZhanjun Dong 			}
12698bfc4963SZhanjun Dong 		}
12708bfc4963SZhanjun Dong 
12718bfc4963SZhanjun Dong 		if (!node) {
12728bfc4963SZhanjun Dong 			node = guc_capture_get_prealloc_node(guc);
12738bfc4963SZhanjun Dong 			if (!node) {
12748bfc4963SZhanjun Dong 				ret = -ENOMEM;
12758bfc4963SZhanjun Dong 				break;
12768bfc4963SZhanjun Dong 			}
12778bfc4963SZhanjun Dong 			if (datatype != GUC_STATE_CAPTURE_TYPE_GLOBAL)
12788bfc4963SZhanjun Dong 				xe_gt_dbg(gt, "Register capture missing global dump: %08x!\n",
12798bfc4963SZhanjun Dong 					  datatype);
12808bfc4963SZhanjun Dong 		}
12818bfc4963SZhanjun Dong 		node->is_partial = is_partial;
12828bfc4963SZhanjun Dong 		node->reginfo[datatype].vfid = FIELD_GET(GUC_STATE_CAPTURE_HEADER_VFID, hdr.owner);
1283*ecb63364SZhanjun Dong 		node->source = XE_ENGINE_CAPTURE_SOURCE_GUC;
1284*ecb63364SZhanjun Dong 		node->type = datatype;
12858bfc4963SZhanjun Dong 
12868bfc4963SZhanjun Dong 		switch (datatype) {
12878bfc4963SZhanjun Dong 		case GUC_STATE_CAPTURE_TYPE_ENGINE_INSTANCE:
12888bfc4963SZhanjun Dong 			node->eng_class = FIELD_GET(GUC_STATE_CAPTURE_HEADER_ENGINE_CLASS,
12898bfc4963SZhanjun Dong 						    hdr.info);
12908bfc4963SZhanjun Dong 			node->eng_inst = FIELD_GET(GUC_STATE_CAPTURE_HEADER_ENGINE_INSTANCE,
12918bfc4963SZhanjun Dong 						   hdr.info);
12928bfc4963SZhanjun Dong 			node->lrca = hdr.lrca;
12938bfc4963SZhanjun Dong 			node->guc_id = hdr.guc_id;
12948bfc4963SZhanjun Dong 			break;
12958bfc4963SZhanjun Dong 		case GUC_STATE_CAPTURE_TYPE_ENGINE_CLASS:
12968bfc4963SZhanjun Dong 			node->eng_class = FIELD_GET(GUC_STATE_CAPTURE_HEADER_ENGINE_CLASS,
12978bfc4963SZhanjun Dong 						    hdr.info);
12988bfc4963SZhanjun Dong 			break;
12998bfc4963SZhanjun Dong 		default:
13008bfc4963SZhanjun Dong 			break;
13018bfc4963SZhanjun Dong 		}
13028bfc4963SZhanjun Dong 
13038bfc4963SZhanjun Dong 		numregs = FIELD_GET(GUC_STATE_CAPTURE_HEADER_NUM_MMIO_ENTRIES,
13048bfc4963SZhanjun Dong 				    hdr.num_mmio_entries);
13058bfc4963SZhanjun Dong 		if (numregs > guc->capture->max_mmio_per_node) {
13068bfc4963SZhanjun Dong 			xe_gt_dbg(gt, "Register capture list extraction clipped by prealloc!\n");
13078bfc4963SZhanjun Dong 			numregs = guc->capture->max_mmio_per_node;
13088bfc4963SZhanjun Dong 		}
13098bfc4963SZhanjun Dong 		node->reginfo[datatype].num_regs = numregs;
13108bfc4963SZhanjun Dong 		regs = node->reginfo[datatype].regs;
13118bfc4963SZhanjun Dong 		i = 0;
13128bfc4963SZhanjun Dong 		while (numregs--) {
13138bfc4963SZhanjun Dong 			if (guc_capture_log_get_register(guc, buf, &regs[i++])) {
13148bfc4963SZhanjun Dong 				ret = -EIO;
13158bfc4963SZhanjun Dong 				break;
13168bfc4963SZhanjun Dong 			}
13178bfc4963SZhanjun Dong 		}
13188bfc4963SZhanjun Dong 	}
13198bfc4963SZhanjun Dong 
13208bfc4963SZhanjun Dong bailout:
13218bfc4963SZhanjun Dong 	if (node) {
13228bfc4963SZhanjun Dong 		/* If we have data, add to linked list for match-up when xe_devcoredump calls */
13238bfc4963SZhanjun Dong 		for (i = GUC_STATE_CAPTURE_TYPE_GLOBAL; i < GUC_STATE_CAPTURE_TYPE_MAX; ++i) {
13248bfc4963SZhanjun Dong 			if (node->reginfo[i].regs) {
13258bfc4963SZhanjun Dong 				guc_capture_add_node_to_outlist(guc->capture, node);
13268bfc4963SZhanjun Dong 				node = NULL;
13278bfc4963SZhanjun Dong 				break;
13288bfc4963SZhanjun Dong 			}
13298bfc4963SZhanjun Dong 		}
13308bfc4963SZhanjun Dong 		if (node) /* else return it back to cache list */
13318bfc4963SZhanjun Dong 			guc_capture_add_node_to_cachelist(guc->capture, node);
13328bfc4963SZhanjun Dong 	}
13338bfc4963SZhanjun Dong 	return ret;
13348bfc4963SZhanjun Dong }
13358bfc4963SZhanjun Dong 
13368bfc4963SZhanjun Dong static int __guc_capture_flushlog_complete(struct xe_guc *guc)
13378bfc4963SZhanjun Dong {
13388bfc4963SZhanjun Dong 	u32 action[] = {
13398bfc4963SZhanjun Dong 		XE_GUC_ACTION_LOG_BUFFER_FILE_FLUSH_COMPLETE,
13408bfc4963SZhanjun Dong 		GUC_LOG_BUFFER_CAPTURE
13418bfc4963SZhanjun Dong 	};
13428bfc4963SZhanjun Dong 
13438bfc4963SZhanjun Dong 	return xe_guc_ct_send_g2h_handler(&guc->ct, action, ARRAY_SIZE(action));
13448bfc4963SZhanjun Dong }
13458bfc4963SZhanjun Dong 
13468bfc4963SZhanjun Dong static void __guc_capture_process_output(struct xe_guc *guc)
13478bfc4963SZhanjun Dong {
13488bfc4963SZhanjun Dong 	unsigned int buffer_size, read_offset, write_offset, full_count;
13498bfc4963SZhanjun Dong 	struct xe_uc *uc = container_of(guc, typeof(*uc), guc);
13508bfc4963SZhanjun Dong 	struct guc_log_buffer_state log_buf_state_local;
13518bfc4963SZhanjun Dong 	struct __guc_capture_bufstate buf;
13528bfc4963SZhanjun Dong 	bool new_overflow;
13538bfc4963SZhanjun Dong 	int ret, tmp;
13548bfc4963SZhanjun Dong 	u32 log_buf_state_offset;
13558bfc4963SZhanjun Dong 	u32 src_data_offset;
13568bfc4963SZhanjun Dong 
13578bfc4963SZhanjun Dong 	log_buf_state_offset = sizeof(struct guc_log_buffer_state) * GUC_LOG_BUFFER_CAPTURE;
13588bfc4963SZhanjun Dong 	src_data_offset = xe_guc_get_log_buffer_offset(&guc->log, GUC_LOG_BUFFER_CAPTURE);
13598bfc4963SZhanjun Dong 
13608bfc4963SZhanjun Dong 	/*
13618bfc4963SZhanjun Dong 	 * Make a copy of the state structure, inside GuC log buffer
13628bfc4963SZhanjun Dong 	 * (which is uncached mapped), on the stack to avoid reading
13638bfc4963SZhanjun Dong 	 * from it multiple times.
13648bfc4963SZhanjun Dong 	 */
13658bfc4963SZhanjun Dong 	xe_map_memcpy_from(guc_to_xe(guc), &log_buf_state_local, &guc->log.bo->vmap,
13668bfc4963SZhanjun Dong 			   log_buf_state_offset, sizeof(struct guc_log_buffer_state));
13678bfc4963SZhanjun Dong 
13688bfc4963SZhanjun Dong 	buffer_size = xe_guc_get_log_buffer_size(&guc->log, GUC_LOG_BUFFER_CAPTURE);
13698bfc4963SZhanjun Dong 	read_offset = log_buf_state_local.read_ptr;
13708bfc4963SZhanjun Dong 	write_offset = log_buf_state_local.sampled_write_ptr;
13718bfc4963SZhanjun Dong 	full_count = FIELD_GET(GUC_LOG_BUFFER_STATE_BUFFER_FULL_CNT, log_buf_state_local.flags);
13728bfc4963SZhanjun Dong 
13738bfc4963SZhanjun Dong 	/* Bookkeeping stuff */
13748bfc4963SZhanjun Dong 	tmp = FIELD_GET(GUC_LOG_BUFFER_STATE_FLUSH_TO_FILE, log_buf_state_local.flags);
13758bfc4963SZhanjun Dong 	guc->log.stats[GUC_LOG_BUFFER_CAPTURE].flush += tmp;
13768bfc4963SZhanjun Dong 	new_overflow = xe_guc_check_log_buf_overflow(&guc->log, GUC_LOG_BUFFER_CAPTURE,
13778bfc4963SZhanjun Dong 						     full_count);
13788bfc4963SZhanjun Dong 
13798bfc4963SZhanjun Dong 	/* Now copy the actual logs. */
13808bfc4963SZhanjun Dong 	if (unlikely(new_overflow)) {
13818bfc4963SZhanjun Dong 		/* copy the whole buffer in case of overflow */
13828bfc4963SZhanjun Dong 		read_offset = 0;
13838bfc4963SZhanjun Dong 		write_offset = buffer_size;
13848bfc4963SZhanjun Dong 	} else if (unlikely((read_offset > buffer_size) ||
13858bfc4963SZhanjun Dong 			(write_offset > buffer_size))) {
13868bfc4963SZhanjun Dong 		xe_gt_err(guc_to_gt(guc),
13878bfc4963SZhanjun Dong 			  "Register capture buffer in invalid state: read = 0x%X, size = 0x%X!\n",
13888bfc4963SZhanjun Dong 			  read_offset, buffer_size);
13898bfc4963SZhanjun Dong 		/* copy whole buffer as offsets are unreliable */
13908bfc4963SZhanjun Dong 		read_offset = 0;
13918bfc4963SZhanjun Dong 		write_offset = buffer_size;
13928bfc4963SZhanjun Dong 	}
13938bfc4963SZhanjun Dong 
13948bfc4963SZhanjun Dong 	buf.size = buffer_size;
13958bfc4963SZhanjun Dong 	buf.rd = read_offset;
13968bfc4963SZhanjun Dong 	buf.wr = write_offset;
13978bfc4963SZhanjun Dong 	buf.data_offset = src_data_offset;
13988bfc4963SZhanjun Dong 
13998bfc4963SZhanjun Dong 	if (!xe_guc_read_stopped(guc)) {
14008bfc4963SZhanjun Dong 		do {
14018bfc4963SZhanjun Dong 			ret = guc_capture_extract_reglists(guc, &buf);
14028bfc4963SZhanjun Dong 			if (ret && ret != -ENODATA)
14038bfc4963SZhanjun Dong 				xe_gt_dbg(guc_to_gt(guc), "Capture extraction failed:%d\n", ret);
14048bfc4963SZhanjun Dong 		} while (ret >= 0);
14058bfc4963SZhanjun Dong 	}
14068bfc4963SZhanjun Dong 
14078bfc4963SZhanjun Dong 	/* Update the state of log buffer err-cap state */
14088bfc4963SZhanjun Dong 	xe_map_wr(guc_to_xe(guc), &guc->log.bo->vmap,
14098bfc4963SZhanjun Dong 		  log_buf_state_offset + offsetof(struct guc_log_buffer_state, read_ptr), u32,
14108bfc4963SZhanjun Dong 		  write_offset);
14118bfc4963SZhanjun Dong 
14128bfc4963SZhanjun Dong 	/*
14138bfc4963SZhanjun Dong 	 * Clear the flush_to_file from local first, the local was loaded by above
14148bfc4963SZhanjun Dong 	 * xe_map_memcpy_from, then write out the "updated local" through
14158bfc4963SZhanjun Dong 	 * xe_map_wr()
14168bfc4963SZhanjun Dong 	 */
14178bfc4963SZhanjun Dong 	log_buf_state_local.flags &= ~GUC_LOG_BUFFER_STATE_FLUSH_TO_FILE;
14188bfc4963SZhanjun Dong 	xe_map_wr(guc_to_xe(guc), &guc->log.bo->vmap,
14198bfc4963SZhanjun Dong 		  log_buf_state_offset + offsetof(struct guc_log_buffer_state, flags), u32,
14208bfc4963SZhanjun Dong 		  log_buf_state_local.flags);
14218bfc4963SZhanjun Dong 	__guc_capture_flushlog_complete(guc);
14228bfc4963SZhanjun Dong }
14238bfc4963SZhanjun Dong 
14248bfc4963SZhanjun Dong /*
14258bfc4963SZhanjun Dong  * xe_guc_capture_process - Process GuC register captured data
14268bfc4963SZhanjun Dong  * @guc: The GuC object
14278bfc4963SZhanjun Dong  *
14288bfc4963SZhanjun Dong  * When GuC captured data is ready, GuC will send message
14298bfc4963SZhanjun Dong  * XE_GUC_ACTION_STATE_CAPTURE_NOTIFICATION to host, this function will be
14308bfc4963SZhanjun Dong  * called to process the data comes with the message.
14318bfc4963SZhanjun Dong  *
14328bfc4963SZhanjun Dong  * Returns: None
14338bfc4963SZhanjun Dong  */
14348bfc4963SZhanjun Dong void xe_guc_capture_process(struct xe_guc *guc)
14358bfc4963SZhanjun Dong {
14368bfc4963SZhanjun Dong 	if (guc->capture)
14378bfc4963SZhanjun Dong 		__guc_capture_process_output(guc);
14388bfc4963SZhanjun Dong }
14398bfc4963SZhanjun Dong 
14408bfc4963SZhanjun Dong static struct __guc_capture_parsed_output *
14418bfc4963SZhanjun Dong guc_capture_alloc_one_node(struct xe_guc *guc)
14428bfc4963SZhanjun Dong {
14438bfc4963SZhanjun Dong 	struct drm_device *drm = guc_to_drm(guc);
14448bfc4963SZhanjun Dong 	struct __guc_capture_parsed_output *new;
14458bfc4963SZhanjun Dong 	int i;
14468bfc4963SZhanjun Dong 
14478bfc4963SZhanjun Dong 	new = drmm_kzalloc(drm, sizeof(*new), GFP_KERNEL);
14488bfc4963SZhanjun Dong 	if (!new)
14498bfc4963SZhanjun Dong 		return NULL;
14508bfc4963SZhanjun Dong 
14518bfc4963SZhanjun Dong 	for (i = 0; i < GUC_STATE_CAPTURE_TYPE_MAX; ++i) {
14528bfc4963SZhanjun Dong 		new->reginfo[i].regs = drmm_kzalloc(drm, guc->capture->max_mmio_per_node *
14538bfc4963SZhanjun Dong 						    sizeof(struct guc_mmio_reg), GFP_KERNEL);
14548bfc4963SZhanjun Dong 		if (!new->reginfo[i].regs) {
14558bfc4963SZhanjun Dong 			while (i)
14568bfc4963SZhanjun Dong 				drmm_kfree(drm, new->reginfo[--i].regs);
14578bfc4963SZhanjun Dong 			drmm_kfree(drm, new);
14588bfc4963SZhanjun Dong 			return NULL;
14598bfc4963SZhanjun Dong 		}
14608bfc4963SZhanjun Dong 	}
14618bfc4963SZhanjun Dong 	guc_capture_init_node(guc, new);
14628bfc4963SZhanjun Dong 
14638bfc4963SZhanjun Dong 	return new;
14648bfc4963SZhanjun Dong }
14658bfc4963SZhanjun Dong 
14668bfc4963SZhanjun Dong static void
14678bfc4963SZhanjun Dong __guc_capture_create_prealloc_nodes(struct xe_guc *guc)
14688bfc4963SZhanjun Dong {
14698bfc4963SZhanjun Dong 	struct __guc_capture_parsed_output *node = NULL;
14708bfc4963SZhanjun Dong 	int i;
14718bfc4963SZhanjun Dong 
14728bfc4963SZhanjun Dong 	for (i = 0; i < PREALLOC_NODES_MAX_COUNT; ++i) {
14738bfc4963SZhanjun Dong 		node = guc_capture_alloc_one_node(guc);
14748bfc4963SZhanjun Dong 		if (!node) {
14758bfc4963SZhanjun Dong 			xe_gt_warn(guc_to_gt(guc), "Register capture pre-alloc-cache failure\n");
14768bfc4963SZhanjun Dong 			/* dont free the priors, use what we got and cleanup at shutdown */
14778bfc4963SZhanjun Dong 			return;
14788bfc4963SZhanjun Dong 		}
14798bfc4963SZhanjun Dong 		guc_capture_add_node_to_cachelist(guc->capture, node);
14808bfc4963SZhanjun Dong 	}
14818bfc4963SZhanjun Dong }
14828bfc4963SZhanjun Dong 
14838bfc4963SZhanjun Dong static int
14848bfc4963SZhanjun Dong guc_get_max_reglist_count(struct xe_guc *guc)
14858bfc4963SZhanjun Dong {
14868bfc4963SZhanjun Dong 	int i, j, k, tmp, maxregcount = 0;
14878bfc4963SZhanjun Dong 
14888bfc4963SZhanjun Dong 	for (i = 0; i < GUC_CAPTURE_LIST_INDEX_MAX; ++i) {
14898bfc4963SZhanjun Dong 		for (j = 0; j < GUC_STATE_CAPTURE_TYPE_MAX; ++j) {
14908bfc4963SZhanjun Dong 			for (k = 0; k < GUC_CAPTURE_LIST_CLASS_MAX; ++k) {
14918bfc4963SZhanjun Dong 				const struct __guc_mmio_reg_descr_group *match;
14928bfc4963SZhanjun Dong 
14938bfc4963SZhanjun Dong 				if (j == GUC_STATE_CAPTURE_TYPE_GLOBAL && k > 0)
14948bfc4963SZhanjun Dong 					continue;
14958bfc4963SZhanjun Dong 
14968bfc4963SZhanjun Dong 				tmp = 0;
14978bfc4963SZhanjun Dong 				match = guc_capture_get_one_list(guc->capture->reglists, i, j, k);
14988bfc4963SZhanjun Dong 				if (match)
14998bfc4963SZhanjun Dong 					tmp = match->num_regs;
15008bfc4963SZhanjun Dong 
15018bfc4963SZhanjun Dong 				match = guc_capture_get_one_list(guc->capture->extlists, i, j, k);
15028bfc4963SZhanjun Dong 				if (match)
15038bfc4963SZhanjun Dong 					tmp += match->num_regs;
15048bfc4963SZhanjun Dong 
15058bfc4963SZhanjun Dong 				if (tmp > maxregcount)
15068bfc4963SZhanjun Dong 					maxregcount = tmp;
15078bfc4963SZhanjun Dong 			}
15088bfc4963SZhanjun Dong 		}
15098bfc4963SZhanjun Dong 	}
15108bfc4963SZhanjun Dong 	if (!maxregcount)
15118bfc4963SZhanjun Dong 		maxregcount = PREALLOC_NODES_DEFAULT_NUMREGS;
15128bfc4963SZhanjun Dong 
15138bfc4963SZhanjun Dong 	return maxregcount;
15148bfc4963SZhanjun Dong }
15158bfc4963SZhanjun Dong 
15168bfc4963SZhanjun Dong static void
15178bfc4963SZhanjun Dong guc_capture_create_prealloc_nodes(struct xe_guc *guc)
15188bfc4963SZhanjun Dong {
15198bfc4963SZhanjun Dong 	/* skip if we've already done the pre-alloc */
15208bfc4963SZhanjun Dong 	if (guc->capture->max_mmio_per_node)
15218bfc4963SZhanjun Dong 		return;
15228bfc4963SZhanjun Dong 
15238bfc4963SZhanjun Dong 	guc->capture->max_mmio_per_node = guc_get_max_reglist_count(guc);
15248bfc4963SZhanjun Dong 	__guc_capture_create_prealloc_nodes(guc);
15258bfc4963SZhanjun Dong }
15268bfc4963SZhanjun Dong 
1527*ecb63364SZhanjun Dong static struct guc_mmio_reg *
1528*ecb63364SZhanjun Dong guc_capture_find_reg(struct gcap_reg_list_info *reginfo, u32 addr, u32 flags)
1529*ecb63364SZhanjun Dong {
1530*ecb63364SZhanjun Dong 	int i;
1531*ecb63364SZhanjun Dong 
1532*ecb63364SZhanjun Dong 	if (reginfo && reginfo->num_regs > 0) {
1533*ecb63364SZhanjun Dong 		struct guc_mmio_reg *regs = reginfo->regs;
1534*ecb63364SZhanjun Dong 
1535*ecb63364SZhanjun Dong 		if (regs)
1536*ecb63364SZhanjun Dong 			for (i = 0; i < reginfo->num_regs; i++)
1537*ecb63364SZhanjun Dong 				if (regs[i].offset == addr && regs[i].flags == flags)
1538*ecb63364SZhanjun Dong 					return &regs[i];
1539*ecb63364SZhanjun Dong 	}
1540*ecb63364SZhanjun Dong 
1541*ecb63364SZhanjun Dong 	return NULL;
1542*ecb63364SZhanjun Dong }
1543*ecb63364SZhanjun Dong 
1544*ecb63364SZhanjun Dong static void
1545*ecb63364SZhanjun Dong snapshot_print_by_list_order(struct xe_hw_engine_snapshot *snapshot, struct drm_printer *p,
1546*ecb63364SZhanjun Dong 			     u32 type, const struct __guc_mmio_reg_descr_group *list)
1547*ecb63364SZhanjun Dong {
1548*ecb63364SZhanjun Dong 	struct xe_gt *gt = snapshot->hwe->gt;
1549*ecb63364SZhanjun Dong 	struct xe_device *xe = gt_to_xe(gt);
1550*ecb63364SZhanjun Dong 	struct xe_guc *guc = &gt->uc.guc;
1551*ecb63364SZhanjun Dong 	struct xe_devcoredump *devcoredump = &xe->devcoredump;
1552*ecb63364SZhanjun Dong 	struct xe_devcoredump_snapshot *devcore_snapshot = &devcoredump->snapshot;
1553*ecb63364SZhanjun Dong 	struct gcap_reg_list_info *reginfo = NULL;
1554*ecb63364SZhanjun Dong 	u32 last_value, i;
1555*ecb63364SZhanjun Dong 	bool is_ext;
1556*ecb63364SZhanjun Dong 
1557*ecb63364SZhanjun Dong 	if (!list || list->num_regs == 0)
1558*ecb63364SZhanjun Dong 		return;
1559*ecb63364SZhanjun Dong 	XE_WARN_ON(!devcore_snapshot->matched_node);
1560*ecb63364SZhanjun Dong 
1561*ecb63364SZhanjun Dong 	is_ext = list == guc->capture->extlists;
1562*ecb63364SZhanjun Dong 	reginfo = &devcore_snapshot->matched_node->reginfo[type];
1563*ecb63364SZhanjun Dong 
1564*ecb63364SZhanjun Dong 	/*
1565*ecb63364SZhanjun Dong 	 * loop through descriptor first and find the register in the node
1566*ecb63364SZhanjun Dong 	 * this is more scalable for developer maintenance as it will ensure
1567*ecb63364SZhanjun Dong 	 * the printout matched the ordering of the static descriptor
1568*ecb63364SZhanjun Dong 	 * table-of-lists
1569*ecb63364SZhanjun Dong 	 */
1570*ecb63364SZhanjun Dong 	for (i = 0; i < list->num_regs; i++) {
1571*ecb63364SZhanjun Dong 		const struct __guc_mmio_reg_descr *reg_desc = &list->list[i];
1572*ecb63364SZhanjun Dong 		struct guc_mmio_reg *reg;
1573*ecb63364SZhanjun Dong 		u32 value;
1574*ecb63364SZhanjun Dong 
1575*ecb63364SZhanjun Dong 		reg = guc_capture_find_reg(reginfo, reg_desc->reg.addr, reg_desc->flags);
1576*ecb63364SZhanjun Dong 		if (!reg)
1577*ecb63364SZhanjun Dong 			continue;
1578*ecb63364SZhanjun Dong 
1579*ecb63364SZhanjun Dong 		value = reg->value;
1580*ecb63364SZhanjun Dong 		if (reg_desc->data_type == REG_64BIT_LOW_DW) {
1581*ecb63364SZhanjun Dong 			last_value = value;
1582*ecb63364SZhanjun Dong 			/* Low 32 bit dword saved, continue for high 32 bit */
1583*ecb63364SZhanjun Dong 			continue;
1584*ecb63364SZhanjun Dong 		} else if (reg_desc->data_type == REG_64BIT_HI_DW) {
1585*ecb63364SZhanjun Dong 			u64 value_qw = ((u64)value << 32) | last_value;
1586*ecb63364SZhanjun Dong 
1587*ecb63364SZhanjun Dong 			drm_printf(p, "\t%s: 0x%016llx\n", reg_desc->regname, value_qw);
1588*ecb63364SZhanjun Dong 			continue;
1589*ecb63364SZhanjun Dong 		}
1590*ecb63364SZhanjun Dong 
1591*ecb63364SZhanjun Dong 		if (is_ext) {
1592*ecb63364SZhanjun Dong 			int dss, group, instance;
1593*ecb63364SZhanjun Dong 
1594*ecb63364SZhanjun Dong 			group = FIELD_GET(GUC_REGSET_STEERING_GROUP, reg_desc->flags);
1595*ecb63364SZhanjun Dong 			instance = FIELD_GET(GUC_REGSET_STEERING_INSTANCE, reg_desc->flags);
1596*ecb63364SZhanjun Dong 			dss = xe_gt_mcr_steering_info_to_dss_id(gt, group, instance);
1597*ecb63364SZhanjun Dong 
1598*ecb63364SZhanjun Dong 			drm_printf(p, "\t%s[%u]: 0x%08x\n", reg_desc->regname, dss, value);
1599*ecb63364SZhanjun Dong 		} else {
1600*ecb63364SZhanjun Dong 			drm_printf(p, "\t%s: 0x%08x\n", reg_desc->regname, value);
1601*ecb63364SZhanjun Dong 		}
1602*ecb63364SZhanjun Dong 	}
1603*ecb63364SZhanjun Dong }
1604*ecb63364SZhanjun Dong 
1605*ecb63364SZhanjun Dong /**
1606*ecb63364SZhanjun Dong  * xe_engine_snapshot_print - Print out a given Xe HW Engine snapshot.
1607*ecb63364SZhanjun Dong  * @snapshot: Xe HW Engine snapshot object.
1608*ecb63364SZhanjun Dong  * @p: drm_printer where it will be printed out.
1609*ecb63364SZhanjun Dong  *
1610*ecb63364SZhanjun Dong  * This function prints out a given Xe HW Engine snapshot object.
1611*ecb63364SZhanjun Dong  */
1612*ecb63364SZhanjun Dong void xe_engine_guc_capture_print(struct xe_hw_engine_snapshot *snapshot, struct drm_printer *p)
1613*ecb63364SZhanjun Dong {
1614*ecb63364SZhanjun Dong 	const char *grptype[GUC_STATE_CAPTURE_GROUP_TYPE_MAX] = {
1615*ecb63364SZhanjun Dong 		"full-capture",
1616*ecb63364SZhanjun Dong 		"partial-capture"
1617*ecb63364SZhanjun Dong 	};
1618*ecb63364SZhanjun Dong 	int type;
1619*ecb63364SZhanjun Dong 	const struct __guc_mmio_reg_descr_group *list;
1620*ecb63364SZhanjun Dong 	enum guc_capture_list_class_type capture_class;
1621*ecb63364SZhanjun Dong 
1622*ecb63364SZhanjun Dong 	struct xe_gt *gt;
1623*ecb63364SZhanjun Dong 	struct xe_device *xe;
1624*ecb63364SZhanjun Dong 	struct xe_devcoredump *devcoredump;
1625*ecb63364SZhanjun Dong 	struct xe_devcoredump_snapshot *devcore_snapshot;
1626*ecb63364SZhanjun Dong 
1627*ecb63364SZhanjun Dong 	if (!snapshot)
1628*ecb63364SZhanjun Dong 		return;
1629*ecb63364SZhanjun Dong 
1630*ecb63364SZhanjun Dong 	gt = snapshot->hwe->gt;
1631*ecb63364SZhanjun Dong 	xe = gt_to_xe(gt);
1632*ecb63364SZhanjun Dong 	devcoredump = &xe->devcoredump;
1633*ecb63364SZhanjun Dong 	devcore_snapshot = &devcoredump->snapshot;
1634*ecb63364SZhanjun Dong 
1635*ecb63364SZhanjun Dong 	if (!devcore_snapshot->matched_node)
1636*ecb63364SZhanjun Dong 		return;
1637*ecb63364SZhanjun Dong 
1638*ecb63364SZhanjun Dong 	xe_gt_assert(gt, snapshot->source <= XE_ENGINE_CAPTURE_SOURCE_GUC);
1639*ecb63364SZhanjun Dong 	xe_gt_assert(gt, snapshot->hwe);
1640*ecb63364SZhanjun Dong 
1641*ecb63364SZhanjun Dong 	capture_class = xe_engine_class_to_guc_capture_class(snapshot->hwe->class);
1642*ecb63364SZhanjun Dong 
1643*ecb63364SZhanjun Dong 	drm_printf(p, "%s (physical), logical instance=%d\n",
1644*ecb63364SZhanjun Dong 		   snapshot->name ? snapshot->name : "",
1645*ecb63364SZhanjun Dong 		   snapshot->logical_instance);
1646*ecb63364SZhanjun Dong 	drm_printf(p, "\tCapture_source: %s\n",
1647*ecb63364SZhanjun Dong 		   snapshot->source == XE_ENGINE_CAPTURE_SOURCE_GUC ? "GuC" : "Manual");
1648*ecb63364SZhanjun Dong 	drm_printf(p, "\tCoverage: %s\n", grptype[devcore_snapshot->matched_node->is_partial]);
1649*ecb63364SZhanjun Dong 	drm_printf(p, "\tForcewake: domain 0x%x, ref %d\n",
1650*ecb63364SZhanjun Dong 		   snapshot->forcewake.domain, snapshot->forcewake.ref);
1651*ecb63364SZhanjun Dong 
1652*ecb63364SZhanjun Dong 	for (type = GUC_STATE_CAPTURE_TYPE_GLOBAL; type < GUC_STATE_CAPTURE_TYPE_MAX; type++) {
1653*ecb63364SZhanjun Dong 		list = xe_guc_capture_get_reg_desc_list(gt, GUC_CAPTURE_LIST_INDEX_PF, type,
1654*ecb63364SZhanjun Dong 							capture_class, false);
1655*ecb63364SZhanjun Dong 		snapshot_print_by_list_order(snapshot, p, type, list);
1656*ecb63364SZhanjun Dong 	}
1657*ecb63364SZhanjun Dong 
1658*ecb63364SZhanjun Dong 	if (capture_class == GUC_CAPTURE_LIST_CLASS_RENDER_COMPUTE) {
1659*ecb63364SZhanjun Dong 		list = xe_guc_capture_get_reg_desc_list(gt, GUC_CAPTURE_LIST_INDEX_PF,
1660*ecb63364SZhanjun Dong 							GUC_STATE_CAPTURE_TYPE_ENGINE_CLASS,
1661*ecb63364SZhanjun Dong 							capture_class, true);
1662*ecb63364SZhanjun Dong 		snapshot_print_by_list_order(snapshot, p, GUC_STATE_CAPTURE_TYPE_ENGINE_CLASS,
1663*ecb63364SZhanjun Dong 					     list);
1664*ecb63364SZhanjun Dong 	}
1665*ecb63364SZhanjun Dong 
1666*ecb63364SZhanjun Dong 	drm_puts(p, "\n");
1667*ecb63364SZhanjun Dong }
1668*ecb63364SZhanjun Dong 
1669*ecb63364SZhanjun Dong /**
1670*ecb63364SZhanjun Dong  * xe_guc_capture_get_matching_and_lock - Matching GuC capture for the job.
1671*ecb63364SZhanjun Dong  * @job: The job object.
1672*ecb63364SZhanjun Dong  *
1673*ecb63364SZhanjun Dong  * Search within the capture outlist for the job, could be used for check if
1674*ecb63364SZhanjun Dong  * GuC capture is ready for the job.
1675*ecb63364SZhanjun Dong  * If found, the locked boolean of the node will be flagged.
1676*ecb63364SZhanjun Dong  *
1677*ecb63364SZhanjun Dong  * Returns: found guc-capture node ptr else NULL
1678*ecb63364SZhanjun Dong  */
1679*ecb63364SZhanjun Dong struct __guc_capture_parsed_output *
1680*ecb63364SZhanjun Dong xe_guc_capture_get_matching_and_lock(struct xe_sched_job *job)
1681*ecb63364SZhanjun Dong {
1682*ecb63364SZhanjun Dong 	struct xe_hw_engine *hwe;
1683*ecb63364SZhanjun Dong 	enum xe_hw_engine_id id;
1684*ecb63364SZhanjun Dong 	struct xe_exec_queue *q;
1685*ecb63364SZhanjun Dong 	struct xe_device *xe;
1686*ecb63364SZhanjun Dong 	u16 guc_class = GUC_LAST_ENGINE_CLASS + 1;
1687*ecb63364SZhanjun Dong 	struct xe_devcoredump_snapshot *ss;
1688*ecb63364SZhanjun Dong 
1689*ecb63364SZhanjun Dong 	if (!job)
1690*ecb63364SZhanjun Dong 		return NULL;
1691*ecb63364SZhanjun Dong 
1692*ecb63364SZhanjun Dong 	q = job->q;
1693*ecb63364SZhanjun Dong 	if (!q || !q->gt)
1694*ecb63364SZhanjun Dong 		return NULL;
1695*ecb63364SZhanjun Dong 
1696*ecb63364SZhanjun Dong 	xe = gt_to_xe(q->gt);
1697*ecb63364SZhanjun Dong 	if (xe->wedged.mode >= 2 || !xe_device_uc_enabled(xe))
1698*ecb63364SZhanjun Dong 		return NULL;
1699*ecb63364SZhanjun Dong 
1700*ecb63364SZhanjun Dong 	ss = &xe->devcoredump.snapshot;
1701*ecb63364SZhanjun Dong 	if (ss->matched_node && ss->matched_node->source == XE_ENGINE_CAPTURE_SOURCE_GUC)
1702*ecb63364SZhanjun Dong 		return ss->matched_node;
1703*ecb63364SZhanjun Dong 
1704*ecb63364SZhanjun Dong 	/* Find hwe for the job */
1705*ecb63364SZhanjun Dong 	for_each_hw_engine(hwe, q->gt, id) {
1706*ecb63364SZhanjun Dong 		if (hwe != q->hwe)
1707*ecb63364SZhanjun Dong 			continue;
1708*ecb63364SZhanjun Dong 		guc_class = xe_engine_class_to_guc_class(hwe->class);
1709*ecb63364SZhanjun Dong 		break;
1710*ecb63364SZhanjun Dong 	}
1711*ecb63364SZhanjun Dong 
1712*ecb63364SZhanjun Dong 	if (guc_class <= GUC_LAST_ENGINE_CLASS) {
1713*ecb63364SZhanjun Dong 		struct __guc_capture_parsed_output *n, *ntmp;
1714*ecb63364SZhanjun Dong 		struct xe_guc *guc =  &q->gt->uc.guc;
1715*ecb63364SZhanjun Dong 		u16 guc_id = q->guc->id;
1716*ecb63364SZhanjun Dong 		u32 lrca = xe_lrc_ggtt_addr(q->lrc[0]);
1717*ecb63364SZhanjun Dong 
1718*ecb63364SZhanjun Dong 		/*
1719*ecb63364SZhanjun Dong 		 * Look for a matching GuC reported error capture node from
1720*ecb63364SZhanjun Dong 		 * the internal output link-list based on engine, guc id and
1721*ecb63364SZhanjun Dong 		 * lrca info.
1722*ecb63364SZhanjun Dong 		 */
1723*ecb63364SZhanjun Dong 		list_for_each_entry_safe(n, ntmp, &guc->capture->outlist, link) {
1724*ecb63364SZhanjun Dong 			if (n->eng_class == guc_class && n->eng_inst == hwe->instance &&
1725*ecb63364SZhanjun Dong 			    n->guc_id == guc_id && n->lrca == lrca &&
1726*ecb63364SZhanjun Dong 			    n->source == XE_ENGINE_CAPTURE_SOURCE_GUC) {
1727*ecb63364SZhanjun Dong 				n->locked = 1;
1728*ecb63364SZhanjun Dong 				return n;
1729*ecb63364SZhanjun Dong 			}
1730*ecb63364SZhanjun Dong 		}
1731*ecb63364SZhanjun Dong 	}
1732*ecb63364SZhanjun Dong 	return NULL;
1733*ecb63364SZhanjun Dong }
1734*ecb63364SZhanjun Dong 
1735*ecb63364SZhanjun Dong /**
1736*ecb63364SZhanjun Dong  * xe_engine_snapshot_capture_for_job - Take snapshot of associated engine
1737*ecb63364SZhanjun Dong  * @job: The job object
1738*ecb63364SZhanjun Dong  *
1739*ecb63364SZhanjun Dong  * Take snapshot of associated HW Engine
1740*ecb63364SZhanjun Dong  *
1741*ecb63364SZhanjun Dong  * Returns: None.
1742*ecb63364SZhanjun Dong  */
1743*ecb63364SZhanjun Dong void
1744*ecb63364SZhanjun Dong xe_engine_snapshot_capture_for_job(struct xe_sched_job *job)
1745*ecb63364SZhanjun Dong {
1746*ecb63364SZhanjun Dong 	struct xe_exec_queue *q = job->q;
1747*ecb63364SZhanjun Dong 	struct xe_device *xe = gt_to_xe(q->gt);
1748*ecb63364SZhanjun Dong 	struct xe_devcoredump *coredump = &xe->devcoredump;
1749*ecb63364SZhanjun Dong 	struct xe_hw_engine *hwe;
1750*ecb63364SZhanjun Dong 	enum xe_hw_engine_id id;
1751*ecb63364SZhanjun Dong 	u32 adj_logical_mask = q->logical_mask;
1752*ecb63364SZhanjun Dong 
1753*ecb63364SZhanjun Dong 	for_each_hw_engine(hwe, q->gt, id) {
1754*ecb63364SZhanjun Dong 		if (hwe->class != q->hwe->class ||
1755*ecb63364SZhanjun Dong 		    !(BIT(hwe->logical_instance) & adj_logical_mask)) {
1756*ecb63364SZhanjun Dong 			coredump->snapshot.hwe[id] = NULL;
1757*ecb63364SZhanjun Dong 			continue;
1758*ecb63364SZhanjun Dong 		}
1759*ecb63364SZhanjun Dong 
1760*ecb63364SZhanjun Dong 		if (!coredump->snapshot.hwe[id])
1761*ecb63364SZhanjun Dong 			coredump->snapshot.hwe[id] = xe_hw_engine_snapshot_capture(hwe, job);
1762*ecb63364SZhanjun Dong 
1763*ecb63364SZhanjun Dong 		break;
1764*ecb63364SZhanjun Dong 	}
1765*ecb63364SZhanjun Dong }
1766*ecb63364SZhanjun Dong 
1767*ecb63364SZhanjun Dong /*
1768*ecb63364SZhanjun Dong  * xe_guc_capture_put_matched_nodes - Cleanup macthed nodes
1769*ecb63364SZhanjun Dong  * @guc: The GuC object
1770*ecb63364SZhanjun Dong  *
1771*ecb63364SZhanjun Dong  * Free matched node and all nodes with the equal guc_id from
1772*ecb63364SZhanjun Dong  * GuC captured outlist
1773*ecb63364SZhanjun Dong  */
1774*ecb63364SZhanjun Dong void xe_guc_capture_put_matched_nodes(struct xe_guc *guc)
1775*ecb63364SZhanjun Dong {
1776*ecb63364SZhanjun Dong 	struct xe_device *xe = guc_to_xe(guc);
1777*ecb63364SZhanjun Dong 	struct xe_devcoredump *devcoredump = &xe->devcoredump;
1778*ecb63364SZhanjun Dong 	struct __guc_capture_parsed_output *n = devcoredump->snapshot.matched_node;
1779*ecb63364SZhanjun Dong 
1780*ecb63364SZhanjun Dong 	if (n) {
1781*ecb63364SZhanjun Dong 		guc_capture_remove_stale_matches_from_list(guc->capture, n);
1782*ecb63364SZhanjun Dong 		guc_capture_free_outlist_node(guc->capture, n);
1783*ecb63364SZhanjun Dong 		devcoredump->snapshot.matched_node = NULL;
1784*ecb63364SZhanjun Dong 	}
1785*ecb63364SZhanjun Dong }
1786*ecb63364SZhanjun Dong 
1787b170d696SZhanjun Dong /*
1788b170d696SZhanjun Dong  * xe_guc_capture_steered_list_init - Init steering register list
1789b170d696SZhanjun Dong  * @guc: The GuC object
1790b170d696SZhanjun Dong  *
17918bfc4963SZhanjun Dong  * Init steering register list for GuC register capture, create pre-alloc node
1792b170d696SZhanjun Dong  */
1793b170d696SZhanjun Dong void xe_guc_capture_steered_list_init(struct xe_guc *guc)
1794b170d696SZhanjun Dong {
1795b170d696SZhanjun Dong 	/*
1796b170d696SZhanjun Dong 	 * For certain engine classes, there are slice and subslice
1797b170d696SZhanjun Dong 	 * level registers requiring steering. We allocate and populate
1798b170d696SZhanjun Dong 	 * these based on hw config and add it as an extension list at
1799b170d696SZhanjun Dong 	 * the end of the pre-populated render list.
1800b170d696SZhanjun Dong 	 */
1801b170d696SZhanjun Dong 	guc_capture_alloc_steered_lists(guc);
180284d15f42SZhanjun Dong 	check_guc_capture_size(guc);
18038bfc4963SZhanjun Dong 	guc_capture_create_prealloc_nodes(guc);
1804b170d696SZhanjun Dong }
1805b170d696SZhanjun Dong 
180684d15f42SZhanjun Dong /*
18079c8c7a7eSZhanjun Dong  * xe_guc_capture_init - Init for GuC register capture
18089c8c7a7eSZhanjun Dong  * @guc: The GuC object
18099c8c7a7eSZhanjun Dong  *
18109c8c7a7eSZhanjun Dong  * Init for GuC register capture, alloc memory for capture data structure.
18119c8c7a7eSZhanjun Dong  *
18129c8c7a7eSZhanjun Dong  * Returns: 0 if success.
1813b170d696SZhanjun Dong  *	    -ENOMEM if out of memory
18149c8c7a7eSZhanjun Dong  */
18159c8c7a7eSZhanjun Dong int xe_guc_capture_init(struct xe_guc *guc)
18169c8c7a7eSZhanjun Dong {
18179c8c7a7eSZhanjun Dong 	guc->capture = drmm_kzalloc(guc_to_drm(guc), sizeof(*guc->capture), GFP_KERNEL);
18189c8c7a7eSZhanjun Dong 	if (!guc->capture)
18199c8c7a7eSZhanjun Dong 		return -ENOMEM;
18209c8c7a7eSZhanjun Dong 
18219c8c7a7eSZhanjun Dong 	guc->capture->reglists = guc_capture_get_device_reglist(guc_to_xe(guc));
18228bfc4963SZhanjun Dong 
18238bfc4963SZhanjun Dong 	INIT_LIST_HEAD(&guc->capture->outlist);
18248bfc4963SZhanjun Dong 	INIT_LIST_HEAD(&guc->capture->cachelist);
18258bfc4963SZhanjun Dong 
18269c8c7a7eSZhanjun Dong 	return 0;
18279c8c7a7eSZhanjun Dong }
1828