xref: /linux/drivers/gpu/drm/amd/amdkfd/kfd_int_process_v9.c (revision 4b132aacb0768ac1e652cf517097ea6f237214b9)
1 // SPDX-License-Identifier: GPL-2.0 OR MIT
2 /*
3  * Copyright 2016-2022 Advanced Micro Devices, Inc.
4  *
5  * Permission is hereby granted, free of charge, to any person obtaining a
6  * copy of this software and associated documentation files (the "Software"),
7  * to deal in the Software without restriction, including without limitation
8  * the rights to use, copy, modify, merge, publish, distribute, sublicense,
9  * and/or sell copies of the Software, and to permit persons to whom the
10  * Software is furnished to do so, subject to the following conditions:
11  *
12  * The above copyright notice and this permission notice shall be included in
13  * all copies or substantial portions of the Software.
14  *
15  * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16  * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17  * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.  IN NO EVENT SHALL
18  * THE COPYRIGHT HOLDER(S) OR AUTHOR(S) BE LIABLE FOR ANY CLAIM, DAMAGES OR
19  * OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE,
20  * ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR
21  * OTHER DEALINGS IN THE SOFTWARE.
22  */
23 
24 #include "kfd_priv.h"
25 #include "kfd_events.h"
26 #include "kfd_debug.h"
27 #include "soc15_int.h"
28 #include "kfd_device_queue_manager.h"
29 #include "kfd_smi_events.h"
30 #include "amdgpu_ras.h"
31 
32 /*
33  * GFX9 SQ Interrupts
34  *
35  * There are 3 encoding types of interrupts sourced from SQ sent as a 44-bit
36  * packet to the Interrupt Handler:
37  * Auto - Generated by the SQG (various cmd overflows, timestamps etc)
38  * Wave - Generated by S_SENDMSG through a shader program
39  * Error - HW generated errors (Illegal instructions, Memviols, EDC etc)
40  *
41  * The 44-bit packet is mapped as {context_id1[7:0],context_id0[31:0]} plus
42  * 4-bits for VMID (SOC15_VMID_FROM_IH_ENTRY) as such:
43  *
44  * - context_id0[27:26]
45  * Encoding type (0 = Auto, 1 = Wave, 2 = Error)
46  *
47  * - context_id0[13]
48  * PRIV bit indicates that Wave S_SEND or error occurred within trap
49  *
50  * - {context_id1[7:0],context_id0[31:28],context_id0[11:0]}
51  * 24-bit data with the following layout per encoding type:
52  * Auto - only context_id0[8:0] is used, which reports various interrupts
53  * generated by SQG.  The rest is 0.
54  * Wave - user data sent from m0 via S_SENDMSG
55  * Error - Error type (context_id1[7:4]), Error Details (rest of bits)
56  *
57  * The other context_id bits show coordinates (SE/SH/CU/SIMD/WAVE) for wave
58  * S_SENDMSG and Errors.  These are 0 for Auto.
59  */
60 
61 enum SQ_INTERRUPT_WORD_ENCODING {
62 	SQ_INTERRUPT_WORD_ENCODING_AUTO = 0x0,
63 	SQ_INTERRUPT_WORD_ENCODING_INST,
64 	SQ_INTERRUPT_WORD_ENCODING_ERROR,
65 };
66 
67 enum SQ_INTERRUPT_ERROR_TYPE {
68 	SQ_INTERRUPT_ERROR_TYPE_EDC_FUE = 0x0,
69 	SQ_INTERRUPT_ERROR_TYPE_ILLEGAL_INST,
70 	SQ_INTERRUPT_ERROR_TYPE_MEMVIOL,
71 	SQ_INTERRUPT_ERROR_TYPE_EDC_FED,
72 };
73 
74 /* SQ_INTERRUPT_WORD_AUTO_CTXID */
75 #define SQ_INTERRUPT_WORD_AUTO_CTXID__THREAD_TRACE__SHIFT 0
76 #define SQ_INTERRUPT_WORD_AUTO_CTXID__WLT__SHIFT 1
77 #define SQ_INTERRUPT_WORD_AUTO_CTXID__THREAD_TRACE_BUF_FULL__SHIFT 2
78 #define SQ_INTERRUPT_WORD_AUTO_CTXID__REG_TIMESTAMP__SHIFT 3
79 #define SQ_INTERRUPT_WORD_AUTO_CTXID__CMD_TIMESTAMP__SHIFT 4
80 #define SQ_INTERRUPT_WORD_AUTO_CTXID__HOST_CMD_OVERFLOW__SHIFT 5
81 #define SQ_INTERRUPT_WORD_AUTO_CTXID__HOST_REG_OVERFLOW__SHIFT 6
82 #define SQ_INTERRUPT_WORD_AUTO_CTXID__IMMED_OVERFLOW__SHIFT 7
83 #define SQ_INTERRUPT_WORD_AUTO_CTXID__THREAD_TRACE_UTC_ERROR__SHIFT 8
84 #define SQ_INTERRUPT_WORD_AUTO_CTXID__SE_ID__SHIFT 24
85 #define SQ_INTERRUPT_WORD_AUTO_CTXID__ENCODING__SHIFT 26
86 
87 #define SQ_INTERRUPT_WORD_AUTO_CTXID__THREAD_TRACE_MASK 0x00000001
88 #define SQ_INTERRUPT_WORD_AUTO_CTXID__WLT_MASK 0x00000002
89 #define SQ_INTERRUPT_WORD_AUTO_CTXID__THREAD_TRACE_BUF_FULL_MASK 0x00000004
90 #define SQ_INTERRUPT_WORD_AUTO_CTXID__REG_TIMESTAMP_MASK 0x00000008
91 #define SQ_INTERRUPT_WORD_AUTO_CTXID__CMD_TIMESTAMP_MASK 0x00000010
92 #define SQ_INTERRUPT_WORD_AUTO_CTXID__HOST_CMD_OVERFLOW_MASK 0x00000020
93 #define SQ_INTERRUPT_WORD_AUTO_CTXID__HOST_REG_OVERFLOW_MASK 0x00000040
94 #define SQ_INTERRUPT_WORD_AUTO_CTXID__IMMED_OVERFLOW_MASK 0x00000080
95 #define SQ_INTERRUPT_WORD_AUTO_CTXID__THREAD_TRACE_UTC_ERROR_MASK 0x00000100
96 #define SQ_INTERRUPT_WORD_AUTO_CTXID__SE_ID_MASK 0x03000000
97 #define SQ_INTERRUPT_WORD_AUTO_CTXID__ENCODING_MASK 0x0c000000
98 
99 /* SQ_INTERRUPT_WORD_WAVE_CTXID */
100 #define SQ_INTERRUPT_WORD_WAVE_CTXID__DATA__SHIFT 0
101 #define SQ_INTERRUPT_WORD_WAVE_CTXID__SH_ID__SHIFT 12
102 #define SQ_INTERRUPT_WORD_WAVE_CTXID__PRIV__SHIFT 13
103 #define SQ_INTERRUPT_WORD_WAVE_CTXID__WAVE_ID__SHIFT 14
104 #define SQ_INTERRUPT_WORD_WAVE_CTXID__SIMD_ID__SHIFT 18
105 #define SQ_INTERRUPT_WORD_WAVE_CTXID__CU_ID__SHIFT 20
106 #define SQ_INTERRUPT_WORD_WAVE_CTXID__SE_ID__SHIFT 24
107 #define SQ_INTERRUPT_WORD_WAVE_CTXID__ENCODING__SHIFT 26
108 
109 #define SQ_INTERRUPT_WORD_WAVE_CTXID__DATA_MASK 0x00000fff
110 #define SQ_INTERRUPT_WORD_WAVE_CTXID__SH_ID_MASK 0x00001000
111 #define SQ_INTERRUPT_WORD_WAVE_CTXID__PRIV_MASK 0x00002000
112 #define SQ_INTERRUPT_WORD_WAVE_CTXID__WAVE_ID_MASK 0x0003c000
113 #define SQ_INTERRUPT_WORD_WAVE_CTXID__SIMD_ID_MASK 0x000c0000
114 #define SQ_INTERRUPT_WORD_WAVE_CTXID__CU_ID_MASK 0x00f00000
115 #define SQ_INTERRUPT_WORD_WAVE_CTXID__SE_ID_MASK 0x03000000
116 #define SQ_INTERRUPT_WORD_WAVE_CTXID__ENCODING_MASK 0x0c000000
117 
118 /* GFX9 SQ interrupt 24-bit data from context_id<0,1> */
119 #define KFD_CONTEXT_ID_GET_SQ_INT_DATA(ctx0, ctx1)                             \
120 	((ctx0 & 0xfff) | ((ctx0 >> 16) & 0xf000) | ((ctx1 << 16) & 0xff0000))
121 
122 #define KFD_SQ_INT_DATA__ERR_TYPE_MASK 0xF00000
123 #define KFD_SQ_INT_DATA__ERR_TYPE__SHIFT 20
124 
125 /*
126  * The debugger will send user data(m0) with PRIV=1 to indicate it requires
127  * notification from the KFD with the following queue id (DOORBELL_ID) and
128  * trap code (TRAP_CODE).
129  */
130 #define KFD_INT_DATA_DEBUG_DOORBELL_MASK	0x0003ff
131 #define KFD_INT_DATA_DEBUG_TRAP_CODE_SHIFT	10
132 #define KFD_INT_DATA_DEBUG_TRAP_CODE_MASK	0x07fc00
133 #define KFD_DEBUG_DOORBELL_ID(sq_int_data)	((sq_int_data) &	\
134 				KFD_INT_DATA_DEBUG_DOORBELL_MASK)
135 #define KFD_DEBUG_TRAP_CODE(sq_int_data)	(((sq_int_data) &	\
136 				KFD_INT_DATA_DEBUG_TRAP_CODE_MASK)	\
137 				>> KFD_INT_DATA_DEBUG_TRAP_CODE_SHIFT)
138 #define KFD_DEBUG_CP_BAD_OP_ECODE_MASK		0x3fffc00
139 #define KFD_DEBUG_CP_BAD_OP_ECODE_SHIFT		10
140 #define KFD_DEBUG_CP_BAD_OP_ECODE(ctxid0)	(((ctxid0) &		\
141 				KFD_DEBUG_CP_BAD_OP_ECODE_MASK)		\
142 				>> KFD_DEBUG_CP_BAD_OP_ECODE_SHIFT)
143 
144 static void event_interrupt_poison_consumption_v9(struct kfd_node *dev,
145 				uint16_t pasid, uint16_t client_id)
146 {
147 	enum amdgpu_ras_block block = 0;
148 	uint32_t reset = 0;
149 	struct kfd_process *p = kfd_lookup_process_by_pasid(pasid);
150 	enum ras_event_type type = RAS_EVENT_TYPE_POISON_CONSUMPTION;
151 	u64 event_id;
152 	int old_poison, ret;
153 
154 	if (!p)
155 		return;
156 
157 	/* all queues of a process will be unmapped in one time */
158 	old_poison = atomic_cmpxchg(&p->poison, 0, 1);
159 	kfd_unref_process(p);
160 	if (old_poison)
161 		return;
162 
163 	switch (client_id) {
164 	case SOC15_IH_CLIENTID_SE0SH:
165 	case SOC15_IH_CLIENTID_SE1SH:
166 	case SOC15_IH_CLIENTID_SE2SH:
167 	case SOC15_IH_CLIENTID_SE3SH:
168 	case SOC15_IH_CLIENTID_UTCL2:
169 		block = AMDGPU_RAS_BLOCK__GFX;
170 		if (amdgpu_ip_version(dev->adev, GC_HWIP, 0) == IP_VERSION(9, 4, 3) ||
171 			amdgpu_ip_version(dev->adev, GC_HWIP, 0) == IP_VERSION(9, 4, 4))
172 			reset = AMDGPU_RAS_GPU_RESET_MODE1_RESET;
173 		else
174 			reset = AMDGPU_RAS_GPU_RESET_MODE2_RESET;
175 		break;
176 	case SOC15_IH_CLIENTID_VMC:
177 	case SOC15_IH_CLIENTID_VMC1:
178 		block = AMDGPU_RAS_BLOCK__MMHUB;
179 		reset = AMDGPU_RAS_GPU_RESET_MODE1_RESET;
180 		break;
181 	case SOC15_IH_CLIENTID_SDMA0:
182 	case SOC15_IH_CLIENTID_SDMA1:
183 	case SOC15_IH_CLIENTID_SDMA2:
184 	case SOC15_IH_CLIENTID_SDMA3:
185 	case SOC15_IH_CLIENTID_SDMA4:
186 		block = AMDGPU_RAS_BLOCK__SDMA;
187 		if (amdgpu_ip_version(dev->adev, GC_HWIP, 0) == IP_VERSION(9, 4, 3) ||
188 			amdgpu_ip_version(dev->adev, GC_HWIP, 0) == IP_VERSION(9, 4, 4))
189 			reset = AMDGPU_RAS_GPU_RESET_MODE1_RESET;
190 		else
191 			reset = AMDGPU_RAS_GPU_RESET_MODE2_RESET;
192 		break;
193 	default:
194 		dev_warn(dev->adev->dev,
195 			 "client %d does not support poison consumption\n", client_id);
196 		return;
197 	}
198 
199 	ret = amdgpu_ras_mark_ras_event(dev->adev, type);
200 	if (ret)
201 		return;
202 
203 	kfd_signal_poison_consumed_event(dev, pasid);
204 
205 	event_id = amdgpu_ras_acquire_event_id(dev->adev, type);
206 
207 	RAS_EVENT_LOG(dev->adev, event_id,
208 		      "poison is consumed by client %d, kick off gpu reset flow\n", client_id);
209 
210 	amdgpu_amdkfd_ras_pasid_poison_consumption_handler(dev->adev,
211 		block, pasid, NULL, NULL, reset);
212 }
213 
214 static bool context_id_expected(struct kfd_dev *dev)
215 {
216 	switch (KFD_GC_VERSION(dev)) {
217 	case IP_VERSION(9, 0, 1):
218 		return dev->mec_fw_version >= 0x817a;
219 	case IP_VERSION(9, 1, 0):
220 	case IP_VERSION(9, 2, 1):
221 	case IP_VERSION(9, 2, 2):
222 	case IP_VERSION(9, 3, 0):
223 	case IP_VERSION(9, 4, 0):
224 		return dev->mec_fw_version >= 0x17a;
225 	default:
226 		/* Other GFXv9 and later GPUs always sent valid context IDs
227 		 * on legitimate events
228 		 */
229 		return KFD_GC_VERSION(dev) >= IP_VERSION(9, 4, 1);
230 	}
231 }
232 
233 static bool event_interrupt_isr_v9(struct kfd_node *dev,
234 					const uint32_t *ih_ring_entry,
235 					uint32_t *patched_ihre,
236 					bool *patched_flag)
237 {
238 	uint16_t source_id, client_id, pasid, vmid;
239 	const uint32_t *data = ih_ring_entry;
240 
241 	source_id = SOC15_SOURCE_ID_FROM_IH_ENTRY(ih_ring_entry);
242 	client_id = SOC15_CLIENT_ID_FROM_IH_ENTRY(ih_ring_entry);
243 
244 	/* Only handle interrupts from KFD VMIDs */
245 	vmid = SOC15_VMID_FROM_IH_ENTRY(ih_ring_entry);
246 	if (!KFD_IRQ_IS_FENCE(client_id, source_id) &&
247 	   (vmid < dev->vm_info.first_vmid_kfd ||
248 	    vmid > dev->vm_info.last_vmid_kfd))
249 		return false;
250 
251 	pasid = SOC15_PASID_FROM_IH_ENTRY(ih_ring_entry);
252 
253 	/* Only handle clients we care about */
254 	if (client_id != SOC15_IH_CLIENTID_GRBM_CP &&
255 	    client_id != SOC15_IH_CLIENTID_SDMA0 &&
256 	    client_id != SOC15_IH_CLIENTID_SDMA1 &&
257 	    client_id != SOC15_IH_CLIENTID_SDMA2 &&
258 	    client_id != SOC15_IH_CLIENTID_SDMA3 &&
259 	    client_id != SOC15_IH_CLIENTID_SDMA4 &&
260 	    client_id != SOC15_IH_CLIENTID_SDMA5 &&
261 	    client_id != SOC15_IH_CLIENTID_SDMA6 &&
262 	    client_id != SOC15_IH_CLIENTID_SDMA7 &&
263 	    client_id != SOC15_IH_CLIENTID_VMC &&
264 	    client_id != SOC15_IH_CLIENTID_VMC1 &&
265 	    client_id != SOC15_IH_CLIENTID_UTCL2 &&
266 	    client_id != SOC15_IH_CLIENTID_SE0SH &&
267 	    client_id != SOC15_IH_CLIENTID_SE1SH &&
268 	    client_id != SOC15_IH_CLIENTID_SE2SH &&
269 	    client_id != SOC15_IH_CLIENTID_SE3SH &&
270 	    !KFD_IRQ_IS_FENCE(client_id, source_id))
271 		return false;
272 
273 	/* This is a known issue for gfx9. Under non HWS, pasid is not set
274 	 * in the interrupt payload, so we need to find out the pasid on our
275 	 * own.
276 	 */
277 	if (!pasid && dev->dqm->sched_policy == KFD_SCHED_POLICY_NO_HWS) {
278 		const uint32_t pasid_mask = 0xffff;
279 
280 		*patched_flag = true;
281 		memcpy(patched_ihre, ih_ring_entry,
282 				dev->kfd->device_info.ih_ring_entry_size);
283 
284 		pasid = dev->dqm->vmid_pasid[vmid];
285 
286 		/* Patch the pasid field */
287 		patched_ihre[3] = cpu_to_le32((le32_to_cpu(patched_ihre[3])
288 					& ~pasid_mask) | pasid);
289 	}
290 
291 	pr_debug("client id 0x%x, source id %d, vmid %d, pasid 0x%x. raw data:\n",
292 		 client_id, source_id, vmid, pasid);
293 	pr_debug("%8X, %8X, %8X, %8X, %8X, %8X, %8X, %8X.\n",
294 		 data[0], data[1], data[2], data[3],
295 		 data[4], data[5], data[6], data[7]);
296 
297 	/* If there is no valid PASID, it's likely a bug */
298 	if (WARN_ONCE(pasid == 0, "Bug: No PASID in KFD interrupt"))
299 		return false;
300 
301 	/* Workaround CP firmware sending bogus signals with 0 context_id.
302 	 * Those can be safely ignored on hardware and firmware versions that
303 	 * include a valid context_id on legitimate signals. This avoids the
304 	 * slow path in kfd_signal_event_interrupt that scans all event slots
305 	 * for signaled events.
306 	 */
307 	if (source_id == SOC15_INTSRC_CP_END_OF_PIPE) {
308 		uint32_t context_id =
309 			SOC15_CONTEXT_ID0_FROM_IH_ENTRY(ih_ring_entry);
310 
311 		if (context_id == 0 && context_id_expected(dev->kfd))
312 			return false;
313 	}
314 
315 	/* Interrupt types we care about: various signals and faults.
316 	 * They will be forwarded to a work queue (see below).
317 	 */
318 	return source_id == SOC15_INTSRC_CP_END_OF_PIPE ||
319 		source_id == SOC15_INTSRC_SDMA_TRAP ||
320 		source_id == SOC15_INTSRC_SDMA_ECC ||
321 		source_id == SOC15_INTSRC_SQ_INTERRUPT_MSG ||
322 		source_id == SOC15_INTSRC_CP_BAD_OPCODE ||
323 		KFD_IRQ_IS_FENCE(client_id, source_id) ||
324 		((client_id == SOC15_IH_CLIENTID_VMC ||
325 		client_id == SOC15_IH_CLIENTID_VMC1 ||
326 		client_id == SOC15_IH_CLIENTID_UTCL2) &&
327 		!amdgpu_no_queue_eviction_on_vm_fault);
328 }
329 
330 static void event_interrupt_wq_v9(struct kfd_node *dev,
331 					const uint32_t *ih_ring_entry)
332 {
333 	uint16_t source_id, client_id, pasid, vmid;
334 	uint32_t context_id0, context_id1;
335 	uint32_t sq_intr_err, sq_int_data, encoding;
336 
337 	source_id = SOC15_SOURCE_ID_FROM_IH_ENTRY(ih_ring_entry);
338 	client_id = SOC15_CLIENT_ID_FROM_IH_ENTRY(ih_ring_entry);
339 	pasid = SOC15_PASID_FROM_IH_ENTRY(ih_ring_entry);
340 	vmid = SOC15_VMID_FROM_IH_ENTRY(ih_ring_entry);
341 	context_id0 = SOC15_CONTEXT_ID0_FROM_IH_ENTRY(ih_ring_entry);
342 	context_id1 = SOC15_CONTEXT_ID1_FROM_IH_ENTRY(ih_ring_entry);
343 
344 	if (client_id == SOC15_IH_CLIENTID_GRBM_CP ||
345 	    client_id == SOC15_IH_CLIENTID_SE0SH ||
346 	    client_id == SOC15_IH_CLIENTID_SE1SH ||
347 	    client_id == SOC15_IH_CLIENTID_SE2SH ||
348 	    client_id == SOC15_IH_CLIENTID_SE3SH) {
349 		if (source_id == SOC15_INTSRC_CP_END_OF_PIPE)
350 			kfd_signal_event_interrupt(pasid, context_id0, 32);
351 		else if (source_id == SOC15_INTSRC_SQ_INTERRUPT_MSG) {
352 			sq_int_data = KFD_CONTEXT_ID_GET_SQ_INT_DATA(context_id0, context_id1);
353 			encoding = REG_GET_FIELD(context_id0, SQ_INTERRUPT_WORD_WAVE_CTXID, ENCODING);
354 			switch (encoding) {
355 			case SQ_INTERRUPT_WORD_ENCODING_AUTO:
356 				pr_debug_ratelimited(
357 					"sq_intr: auto, se %d, ttrace %d, wlt %d, ttrac_buf_full %d, reg_tms %d, cmd_tms %d, host_cmd_ovf %d, host_reg_ovf %d, immed_ovf %d, ttrace_utc_err %d\n",
358 					REG_GET_FIELD(context_id0, SQ_INTERRUPT_WORD_AUTO_CTXID, SE_ID),
359 					REG_GET_FIELD(context_id0, SQ_INTERRUPT_WORD_AUTO_CTXID, THREAD_TRACE),
360 					REG_GET_FIELD(context_id0, SQ_INTERRUPT_WORD_AUTO_CTXID, WLT),
361 					REG_GET_FIELD(context_id0, SQ_INTERRUPT_WORD_AUTO_CTXID, THREAD_TRACE_BUF_FULL),
362 					REG_GET_FIELD(context_id0, SQ_INTERRUPT_WORD_AUTO_CTXID, REG_TIMESTAMP),
363 					REG_GET_FIELD(context_id0, SQ_INTERRUPT_WORD_AUTO_CTXID, CMD_TIMESTAMP),
364 					REG_GET_FIELD(context_id0, SQ_INTERRUPT_WORD_AUTO_CTXID, HOST_CMD_OVERFLOW),
365 					REG_GET_FIELD(context_id0, SQ_INTERRUPT_WORD_AUTO_CTXID, HOST_REG_OVERFLOW),
366 					REG_GET_FIELD(context_id0, SQ_INTERRUPT_WORD_AUTO_CTXID, IMMED_OVERFLOW),
367 					REG_GET_FIELD(context_id0, SQ_INTERRUPT_WORD_AUTO_CTXID, THREAD_TRACE_UTC_ERROR));
368 				break;
369 			case SQ_INTERRUPT_WORD_ENCODING_INST:
370 				pr_debug_ratelimited("sq_intr: inst, se %d, data 0x%x, sh %d, priv %d, wave_id %d, simd_id %d, cu_id %d, intr_data 0x%x\n",
371 					REG_GET_FIELD(context_id0, SQ_INTERRUPT_WORD_WAVE_CTXID, SE_ID),
372 					REG_GET_FIELD(context_id0, SQ_INTERRUPT_WORD_WAVE_CTXID, DATA),
373 					REG_GET_FIELD(context_id0, SQ_INTERRUPT_WORD_WAVE_CTXID, SH_ID),
374 					REG_GET_FIELD(context_id0, SQ_INTERRUPT_WORD_WAVE_CTXID, PRIV),
375 					REG_GET_FIELD(context_id0, SQ_INTERRUPT_WORD_WAVE_CTXID, WAVE_ID),
376 					REG_GET_FIELD(context_id0, SQ_INTERRUPT_WORD_WAVE_CTXID, SIMD_ID),
377 					REG_GET_FIELD(context_id0, SQ_INTERRUPT_WORD_WAVE_CTXID, CU_ID),
378 					sq_int_data);
379 				if (context_id0 & SQ_INTERRUPT_WORD_WAVE_CTXID__PRIV_MASK) {
380 					if (kfd_set_dbg_ev_from_interrupt(dev, pasid,
381 							KFD_DEBUG_DOORBELL_ID(sq_int_data),
382 							KFD_DEBUG_TRAP_CODE(sq_int_data),
383 							NULL, 0))
384 						return;
385 				}
386 				break;
387 			case SQ_INTERRUPT_WORD_ENCODING_ERROR:
388 				sq_intr_err = REG_GET_FIELD(sq_int_data, KFD_SQ_INT_DATA, ERR_TYPE);
389 				pr_warn_ratelimited("sq_intr: error, se %d, data 0x%x, sh %d, priv %d, wave_id %d, simd_id %d, cu_id %d, err_type %d\n",
390 					REG_GET_FIELD(context_id0, SQ_INTERRUPT_WORD_WAVE_CTXID, SE_ID),
391 					REG_GET_FIELD(context_id0, SQ_INTERRUPT_WORD_WAVE_CTXID, DATA),
392 					REG_GET_FIELD(context_id0, SQ_INTERRUPT_WORD_WAVE_CTXID, SH_ID),
393 					REG_GET_FIELD(context_id0, SQ_INTERRUPT_WORD_WAVE_CTXID, PRIV),
394 					REG_GET_FIELD(context_id0, SQ_INTERRUPT_WORD_WAVE_CTXID, WAVE_ID),
395 					REG_GET_FIELD(context_id0, SQ_INTERRUPT_WORD_WAVE_CTXID, SIMD_ID),
396 					REG_GET_FIELD(context_id0, SQ_INTERRUPT_WORD_WAVE_CTXID, CU_ID),
397 					sq_intr_err);
398 				if (sq_intr_err != SQ_INTERRUPT_ERROR_TYPE_ILLEGAL_INST &&
399 					sq_intr_err != SQ_INTERRUPT_ERROR_TYPE_MEMVIOL) {
400 					event_interrupt_poison_consumption_v9(dev, pasid, client_id);
401 					return;
402 				}
403 				break;
404 			default:
405 				break;
406 			}
407 			kfd_signal_event_interrupt(pasid, sq_int_data, 24);
408 		} else if (source_id == SOC15_INTSRC_CP_BAD_OPCODE &&
409 			   KFD_DBG_EC_TYPE_IS_PACKET(KFD_DEBUG_CP_BAD_OP_ECODE(context_id0))) {
410 			kfd_set_dbg_ev_from_interrupt(dev, pasid,
411 				KFD_DEBUG_DOORBELL_ID(context_id0),
412 				KFD_EC_MASK(KFD_DEBUG_CP_BAD_OP_ECODE(context_id0)),
413 				NULL, 0);
414 		}
415 	} else if (client_id == SOC15_IH_CLIENTID_SDMA0 ||
416 		   client_id == SOC15_IH_CLIENTID_SDMA1 ||
417 		   client_id == SOC15_IH_CLIENTID_SDMA2 ||
418 		   client_id == SOC15_IH_CLIENTID_SDMA3 ||
419 		   client_id == SOC15_IH_CLIENTID_SDMA4 ||
420 		   client_id == SOC15_IH_CLIENTID_SDMA5 ||
421 		   client_id == SOC15_IH_CLIENTID_SDMA6 ||
422 		   client_id == SOC15_IH_CLIENTID_SDMA7) {
423 		if (source_id == SOC15_INTSRC_SDMA_TRAP) {
424 			kfd_signal_event_interrupt(pasid, context_id0 & 0xfffffff, 28);
425 		} else if (source_id == SOC15_INTSRC_SDMA_ECC) {
426 			event_interrupt_poison_consumption_v9(dev, pasid, client_id);
427 			return;
428 		}
429 	} else if (client_id == SOC15_IH_CLIENTID_VMC ||
430 		   client_id == SOC15_IH_CLIENTID_VMC1 ||
431 		   client_id == SOC15_IH_CLIENTID_UTCL2) {
432 		struct kfd_vm_fault_info info = {0};
433 		uint16_t ring_id = SOC15_RING_ID_FROM_IH_ENTRY(ih_ring_entry);
434 		uint32_t node_id = SOC15_NODEID_FROM_IH_ENTRY(ih_ring_entry);
435 		uint32_t vmid_type = SOC15_VMID_TYPE_FROM_IH_ENTRY(ih_ring_entry);
436 		int hub_inst = 0;
437 		struct kfd_hsa_memory_exception_data exception_data;
438 
439 		/* gfxhub */
440 		if (!vmid_type && dev->adev->gfx.funcs->ih_node_to_logical_xcc) {
441 			hub_inst = dev->adev->gfx.funcs->ih_node_to_logical_xcc(dev->adev,
442 				node_id);
443 			if (hub_inst < 0)
444 				hub_inst = 0;
445 		}
446 
447 		/* mmhub */
448 		if (vmid_type && client_id == SOC15_IH_CLIENTID_VMC)
449 			hub_inst = node_id / 4;
450 
451 		if (amdgpu_amdkfd_ras_query_utcl2_poison_status(dev->adev,
452 					hub_inst, vmid_type)) {
453 			event_interrupt_poison_consumption_v9(dev, pasid, client_id);
454 			return;
455 		}
456 
457 		info.vmid = vmid;
458 		info.mc_id = client_id;
459 		info.page_addr = ih_ring_entry[4] |
460 			(uint64_t)(ih_ring_entry[5] & 0xf) << 32;
461 		info.prot_valid = ring_id & 0x08;
462 		info.prot_read  = ring_id & 0x10;
463 		info.prot_write = ring_id & 0x20;
464 
465 		memset(&exception_data, 0, sizeof(exception_data));
466 		exception_data.gpu_id = dev->id;
467 		exception_data.va = (info.page_addr) << PAGE_SHIFT;
468 		exception_data.failure.NotPresent = info.prot_valid ? 1 : 0;
469 		exception_data.failure.NoExecute = info.prot_exec ? 1 : 0;
470 		exception_data.failure.ReadOnly = info.prot_write ? 1 : 0;
471 		exception_data.failure.imprecise = 0;
472 
473 		kfd_set_dbg_ev_from_interrupt(dev,
474 						pasid,
475 						-1,
476 						KFD_EC_MASK(EC_DEVICE_MEMORY_VIOLATION),
477 						&exception_data,
478 						sizeof(exception_data));
479 		kfd_smi_event_update_vmfault(dev, pasid);
480 	} else if (KFD_IRQ_IS_FENCE(client_id, source_id)) {
481 		kfd_process_close_interrupt_drain(pasid);
482 	}
483 }
484 
485 static bool event_interrupt_isr_v9_4_3(struct kfd_node *node,
486 				const uint32_t *ih_ring_entry,
487 				uint32_t *patched_ihre,
488 				bool *patched_flag)
489 {
490 	uint16_t node_id, vmid;
491 
492 	/*
493 	 * For GFX 9.4.3, process the interrupt if:
494 	 * - NodeID field in IH entry matches the corresponding bit
495 	 *   set in interrupt_bitmap Bits 0-15.
496 	 *   OR
497 	 * - If partition mode is CPX and interrupt came from
498 	 *   Node_id 0,4,8,12, then check if the Bit (16 + client id)
499 	 *   is set in interrupt bitmap Bits 16-31.
500 	 */
501 	node_id = SOC15_NODEID_FROM_IH_ENTRY(ih_ring_entry);
502 	vmid = SOC15_VMID_FROM_IH_ENTRY(ih_ring_entry);
503 	if (kfd_irq_is_from_node(node, node_id, vmid))
504 		return event_interrupt_isr_v9(node, ih_ring_entry,
505 					patched_ihre, patched_flag);
506 	return false;
507 }
508 
509 const struct kfd_event_interrupt_class event_interrupt_class_v9 = {
510 	.interrupt_isr = event_interrupt_isr_v9,
511 	.interrupt_wq = event_interrupt_wq_v9,
512 };
513 
514 const struct kfd_event_interrupt_class event_interrupt_class_v9_4_3 = {
515 	.interrupt_isr = event_interrupt_isr_v9_4_3,
516 	.interrupt_wq = event_interrupt_wq_v9,
517 };
518