Merge tag 'rtc-6.9' of git://git.kernel.org/pub/scm/linux/kernel/git/abelloni/linux
[linux-block.git] / drivers / gpu / drm / xe / xe_guc_ct_types.h
1 /* SPDX-License-Identifier: MIT */
2 /*
3  * Copyright © 2022 Intel Corporation
4  */
5
6 #ifndef _XE_GUC_CT_TYPES_H_
7 #define _XE_GUC_CT_TYPES_H_
8
9 #include <linux/interrupt.h>
10 #include <linux/iosys-map.h>
11 #include <linux/spinlock_types.h>
12 #include <linux/wait.h>
13 #include <linux/xarray.h>
14
15 #include "abi/guc_communication_ctb_abi.h"
16
17 struct xe_bo;
18
19 /**
20  * struct guc_ctb_info - GuC command transport buffer (CTB) info
21  */
22 struct guc_ctb_info {
23         /** @size: size of CTB commands (DW) */
24         u32 size;
25         /** @resv_space: reserved space of CTB commands (DW) */
26         u32 resv_space;
27         /** @head: head of CTB commands (DW) */
28         u32 head;
29         /** @tail: tail of CTB commands (DW) */
30         u32 tail;
31         /** @space: space in CTB commands (DW) */
32         u32 space;
33         /** @broken: channel broken */
34         bool broken;
35 };
36
37 /**
38  * struct guc_ctb - GuC command transport buffer (CTB)
39  */
40 struct guc_ctb {
41         /** @desc: dma buffer map for CTB descriptor */
42         struct iosys_map desc;
43         /** @cmds: dma buffer map for CTB commands */
44         struct iosys_map cmds;
45         /** @info: CTB info */
46         struct guc_ctb_info info;
47 };
48
49 /**
50  * struct guc_ctb_snapshot - GuC command transport buffer (CTB) snapshot
51  */
52 struct guc_ctb_snapshot {
53         /** @desc: snapshot of the CTB descriptor */
54         struct guc_ct_buffer_desc desc;
55         /** @cmds: snapshot of the CTB commands */
56         u32 *cmds;
57         /** @info: snapshot of the CTB info */
58         struct guc_ctb_info info;
59 };
60
61 /**
62  * struct xe_guc_ct_snapshot - GuC command transport (CT) snapshot
63  */
64 struct xe_guc_ct_snapshot {
65         /** @ct_enabled: CT enabled info at capture time. */
66         bool ct_enabled;
67         /** @g2h_outstanding: G2H outstanding info at the capture time */
68         u32 g2h_outstanding;
69         /** @g2h: G2H CTB snapshot */
70         struct guc_ctb_snapshot g2h;
71         /** @h2g: H2G CTB snapshot */
72         struct guc_ctb_snapshot h2g;
73 };
74
75 /**
76  * enum xe_guc_ct_state - CT state
77  * @XE_GUC_CT_STATE_NOT_INITIALIZED: CT not initialized, messages not expected in this state
78  * @XE_GUC_CT_STATE_DISABLED: CT disabled, messages not expected in this state
79  * @XE_GUC_CT_STATE_STOPPED: CT stopped, drop messages without errors
80  * @XE_GUC_CT_STATE_ENABLED: CT enabled, messages sent / received in this state
81  */
82 enum xe_guc_ct_state {
83         XE_GUC_CT_STATE_NOT_INITIALIZED = 0,
84         XE_GUC_CT_STATE_DISABLED,
85         XE_GUC_CT_STATE_STOPPED,
86         XE_GUC_CT_STATE_ENABLED,
87 };
88
89 /**
90  * struct xe_guc_ct - GuC command transport (CT) layer
91  *
92  * Includes a pair of CT buffers for bi-directional communication and tracking
93  * for the H2G and G2H requests sent and received through the buffers.
94  */
95 struct xe_guc_ct {
96         /** @bo: XE BO for CT */
97         struct xe_bo *bo;
98         /** @lock: protects everything in CT layer */
99         struct mutex lock;
100         /** @fast_lock: protects G2H channel and credits */
101         spinlock_t fast_lock;
102         /** @ctbs: buffers for sending and receiving commands */
103         struct {
104                 /** @ctbs.send: Host to GuC (H2G, send) channel */
105                 struct guc_ctb h2g;
106                 /** @ctbs.recv: GuC to Host (G2H, receive) channel */
107                 struct guc_ctb g2h;
108         } ctbs;
109         /** @g2h_outstanding: number of outstanding G2H */
110         u32 g2h_outstanding;
111         /** @g2h_worker: worker to process G2H messages */
112         struct work_struct g2h_worker;
113         /** @state: CT state */
114         enum xe_guc_ct_state state;
115         /** @fence_seqno: G2H fence seqno - 16 bits used by CT */
116         u32 fence_seqno;
117         /** @fence_lookup: G2H fence lookup */
118         struct xarray fence_lookup;
119         /** @wq: wait queue used for reliable CT sends and freeing G2H credits */
120         wait_queue_head_t wq;
121         /** @g2h_fence_wq: wait queue used for G2H fencing */
122         wait_queue_head_t g2h_fence_wq;
123         /** @msg: Message buffer */
124         u32 msg[GUC_CTB_MSG_MAX_LEN];
125         /** @fast_msg: Message buffer */
126         u32 fast_msg[GUC_CTB_MSG_MAX_LEN];
127 };
128
129 #endif