xref: /linux/drivers/gpu/drm/xe/xe_guc_ct.h (revision 5f2b6c5f6b692c696a232d12c43b8e41c0d393b9)
1 /* SPDX-License-Identifier: MIT */
2 /*
3  * Copyright © 2022 Intel Corporation
4  */
5 
6 #ifndef _XE_GUC_CT_H_
7 #define _XE_GUC_CT_H_
8 
9 #include "xe_guc_ct_types.h"
10 
11 struct drm_printer;
12 struct xe_device;
13 
14 int xe_guc_ct_init(struct xe_guc_ct *ct);
15 int xe_guc_ct_enable(struct xe_guc_ct *ct);
16 void xe_guc_ct_disable(struct xe_guc_ct *ct);
17 void xe_guc_ct_stop(struct xe_guc_ct *ct);
18 void xe_guc_ct_fast_path(struct xe_guc_ct *ct);
19 
20 struct xe_guc_ct_snapshot *xe_guc_ct_snapshot_capture(struct xe_guc_ct *ct);
21 void xe_guc_ct_snapshot_print(struct xe_guc_ct_snapshot *snapshot, struct drm_printer *p);
22 void xe_guc_ct_snapshot_free(struct xe_guc_ct_snapshot *snapshot);
23 void xe_guc_ct_print(struct xe_guc_ct *ct, struct drm_printer *p, bool want_ctb);
24 
xe_guc_ct_initialized(struct xe_guc_ct * ct)25 static inline bool xe_guc_ct_initialized(struct xe_guc_ct *ct)
26 {
27 	return ct->state != XE_GUC_CT_STATE_NOT_INITIALIZED;
28 }
29 
xe_guc_ct_enabled(struct xe_guc_ct * ct)30 static inline bool xe_guc_ct_enabled(struct xe_guc_ct *ct)
31 {
32 	return ct->state == XE_GUC_CT_STATE_ENABLED;
33 }
34 
xe_guc_ct_irq_handler(struct xe_guc_ct * ct)35 static inline void xe_guc_ct_irq_handler(struct xe_guc_ct *ct)
36 {
37 	if (!xe_guc_ct_enabled(ct))
38 		return;
39 
40 	wake_up_all(&ct->wq);
41 	queue_work(ct->g2h_wq, &ct->g2h_worker);
42 	xe_guc_ct_fast_path(ct);
43 }
44 
45 /* Basic CT send / receives */
46 int xe_guc_ct_send(struct xe_guc_ct *ct, const u32 *action, u32 len,
47 		   u32 g2h_len, u32 num_g2h);
48 int xe_guc_ct_send_locked(struct xe_guc_ct *ct, const u32 *action, u32 len,
49 			  u32 g2h_len, u32 num_g2h);
50 int xe_guc_ct_send_recv(struct xe_guc_ct *ct, const u32 *action, u32 len,
51 			u32 *response_buffer);
52 static inline int
xe_guc_ct_send_block(struct xe_guc_ct * ct,const u32 * action,u32 len)53 xe_guc_ct_send_block(struct xe_guc_ct *ct, const u32 *action, u32 len)
54 {
55 	return xe_guc_ct_send_recv(ct, action, len, NULL);
56 }
57 
58 /* This is only version of the send CT you can call from a G2H handler */
59 int xe_guc_ct_send_g2h_handler(struct xe_guc_ct *ct, const u32 *action,
60 			       u32 len);
61 
62 /* Can't fail because a GT reset is in progress */
63 int xe_guc_ct_send_recv_no_fail(struct xe_guc_ct *ct, const u32 *action,
64 				u32 len, u32 *response_buffer);
65 static inline int
xe_guc_ct_send_block_no_fail(struct xe_guc_ct * ct,const u32 * action,u32 len)66 xe_guc_ct_send_block_no_fail(struct xe_guc_ct *ct, const u32 *action, u32 len)
67 {
68 	return xe_guc_ct_send_recv_no_fail(ct, action, len, NULL);
69 }
70 
71 long xe_guc_ct_queue_proc_time_jiffies(struct xe_guc_ct *ct);
72 
73 #endif
74