xref: /linux/drivers/gpu/drm/xe/xe_guc_ct.h (revision 1fd1dc41724319406b0aff221a352a400b0ddfc5)
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_noalloc(struct xe_guc_ct *ct);
15 int xe_guc_ct_init(struct xe_guc_ct *ct);
16 int xe_guc_ct_init_post_hwconfig(struct xe_guc_ct *ct);
17 int xe_guc_ct_enable(struct xe_guc_ct *ct);
18 int xe_guc_ct_restart(struct xe_guc_ct *ct);
19 void xe_guc_ct_disable(struct xe_guc_ct *ct);
20 void xe_guc_ct_runtime_resume(struct xe_guc_ct *ct);
21 void xe_guc_ct_runtime_suspend(struct xe_guc_ct *ct);
22 void xe_guc_ct_stop(struct xe_guc_ct *ct);
23 void xe_guc_ct_flush_and_stop(struct xe_guc_ct *ct);
24 void xe_guc_ct_fast_path(struct xe_guc_ct *ct);
25 
26 struct xe_guc_ct_snapshot *xe_guc_ct_snapshot_capture(struct xe_guc_ct *ct);
27 void xe_guc_ct_snapshot_print(struct xe_guc_ct_snapshot *snapshot, struct drm_printer *p);
28 void xe_guc_ct_snapshot_free(struct xe_guc_ct_snapshot *snapshot);
29 void xe_guc_ct_print(struct xe_guc_ct *ct, struct drm_printer *p, bool want_ctb);
30 
31 static inline bool xe_guc_ct_initialized(struct xe_guc_ct *ct)
32 {
33 	/* READ_ONCE pairs with WRITE_ONCE in guc_ct_change_state. */
34 	return READ_ONCE(ct->state) != XE_GUC_CT_STATE_NOT_INITIALIZED;
35 }
36 
37 static inline bool xe_guc_ct_enabled(struct xe_guc_ct *ct)
38 {
39 	/* READ_ONCE pairs with WRITE_ONCE in guc_ct_change_state. */
40 	return READ_ONCE(ct->state) == XE_GUC_CT_STATE_ENABLED;
41 }
42 
43 static inline void xe_guc_ct_irq_handler(struct xe_guc_ct *ct)
44 {
45 	if (!xe_guc_ct_enabled(ct))
46 		return;
47 
48 	wake_up_all(&ct->wq);
49 	queue_work(ct->g2h_wq, &ct->g2h_worker);
50 	xe_guc_ct_fast_path(ct);
51 }
52 
53 /* Basic CT send / receives */
54 int xe_guc_ct_send(struct xe_guc_ct *ct, const u32 *action, u32 len,
55 		   u32 g2h_len, u32 num_g2h);
56 int xe_guc_ct_send_locked(struct xe_guc_ct *ct, const u32 *action, u32 len,
57 			  u32 g2h_len, u32 num_g2h);
58 int xe_guc_ct_send_recv(struct xe_guc_ct *ct, const u32 *action, u32 len,
59 			u32 *response_buffer);
60 static inline int
61 xe_guc_ct_send_block(struct xe_guc_ct *ct, const u32 *action, u32 len)
62 {
63 	return xe_guc_ct_send_recv(ct, action, len, NULL);
64 }
65 
66 /* This is only version of the send CT you can call from a G2H handler */
67 int xe_guc_ct_send_g2h_handler(struct xe_guc_ct *ct, const u32 *action,
68 			       u32 len);
69 
70 /* Can't fail because a GT reset is in progress */
71 int xe_guc_ct_send_recv_no_fail(struct xe_guc_ct *ct, const u32 *action,
72 				u32 len, u32 *response_buffer);
73 static inline int
74 xe_guc_ct_send_block_no_fail(struct xe_guc_ct *ct, const u32 *action, u32 len)
75 {
76 	return xe_guc_ct_send_recv_no_fail(ct, action, len, NULL);
77 }
78 
79 long xe_guc_ct_queue_proc_time_jiffies(struct xe_guc_ct *ct);
80 
81 /**
82  * xe_guc_ct_wake_waiters() - GuC CT wake up waiters
83  * @ct: GuC CT object
84  */
85 static inline void xe_guc_ct_wake_waiters(struct xe_guc_ct *ct)
86 {
87 	wake_up_all(&ct->wq);
88 }
89 
90 #endif
91