1 /*	$NetBSD: intel_guc_ct.h,v 1.2 2021/12/18 23:45:31 riastradh Exp $	*/
2 
3 /* SPDX-License-Identifier: MIT */
4 /*
5  * Copyright © 2016-2019 Intel Corporation
6  */
7 
8 #ifndef _INTEL_GUC_CT_H_
9 #define _INTEL_GUC_CT_H_
10 
11 #include <linux/spinlock.h>
12 #include <linux/workqueue.h>
13 
14 #include "intel_guc_fwif.h"
15 
16 struct i915_vma;
17 struct intel_guc;
18 
19 /**
20  * DOC: Command Transport (CT).
21  *
22  * Buffer based command transport is a replacement for MMIO based mechanism.
23  * It can be used to perform both host-2-guc and guc-to-host communication.
24  */
25 
26 /** Represents single command transport buffer.
27  *
28  * A single command transport buffer consists of two parts, the header
29  * record (command transport buffer descriptor) and the actual buffer which
30  * holds the commands.
31  *
32  * @desc: pointer to the buffer descriptor
33  * @cmds: pointer to the commands buffer
34  */
35 struct intel_guc_ct_buffer {
36 	struct guc_ct_buffer_desc *desc;
37 	u32 *cmds;
38 };
39 
40 
41 /** Top-level structure for Command Transport related data
42  *
43  * Includes a pair of CT buffers for bi-directional communication and tracking
44  * for the H2G and G2H requests sent and received through the buffers.
45  */
46 struct intel_guc_ct {
47 	struct i915_vma *vma;
48 	bool enabled;
49 
50 	/* buffers for sending(0) and receiving(1) commands */
51 	struct intel_guc_ct_buffer ctbs[2];
52 
53 	struct {
54 		u32 next_fence; /* fence to be used with next request to send */
55 
56 		spinlock_t lock; /* protects pending requests list */
57 		struct list_head pending; /* requests waiting for response */
58 
59 		struct list_head incoming; /* incoming requests */
60 		struct work_struct worker; /* handler for incoming requests */
61 	} requests;
62 };
63 
64 void intel_guc_ct_init_early(struct intel_guc_ct *ct);
65 int intel_guc_ct_init(struct intel_guc_ct *ct);
66 void intel_guc_ct_fini(struct intel_guc_ct *ct);
67 int intel_guc_ct_enable(struct intel_guc_ct *ct);
68 void intel_guc_ct_disable(struct intel_guc_ct *ct);
69 
intel_guc_ct_enabled(struct intel_guc_ct * ct)70 static inline bool intel_guc_ct_enabled(struct intel_guc_ct *ct)
71 {
72 	return ct->enabled;
73 }
74 
75 int intel_guc_ct_send(struct intel_guc_ct *ct, const u32 *action, u32 len,
76 		      u32 *response_buf, u32 response_buf_size);
77 void intel_guc_ct_event_handler(struct intel_guc_ct *ct);
78 
79 #endif /* _INTEL_GUC_CT_H_ */
80