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/stackdepot.h>
13#include <linux/wait.h>
14#include <linux/xarray.h>
15
16#include "abi/guc_communication_ctb_abi.h"
17
18struct xe_bo;
19
20/**
21 * struct guc_ctb_info - GuC command transport buffer (CTB) info
22 */
23struct guc_ctb_info {
24 /** @size: size of CTB commands (DW) */
25 u32 size;
26 /** @resv_space: reserved space of CTB commands (DW) */
27 u32 resv_space;
28 /** @head: head of CTB commands (DW) */
29 u32 head;
30 /** @tail: tail of CTB commands (DW) */
31 u32 tail;
32 /** @space: space in CTB commands (DW) */
33 u32 space;
34 /** @broken: channel broken */
35 bool broken;
36};
37
38/**
39 * struct guc_ctb - GuC command transport buffer (CTB)
40 */
41struct guc_ctb {
42 /** @desc: dma buffer map for CTB descriptor */
43 struct iosys_map desc;
44 /** @cmds: dma buffer map for CTB commands */
45 struct iosys_map cmds;
46 /** @info: CTB info */
47 struct guc_ctb_info info;
48};
49
50/**
51 * struct guc_ctb_snapshot - GuC command transport buffer (CTB) snapshot
52 */
53struct guc_ctb_snapshot {
54 /** @desc: snapshot of the CTB descriptor */
55 struct guc_ct_buffer_desc desc;
56 /** @info: snapshot of the CTB info */
57 struct guc_ctb_info info;
58};
59
60/**
61 * struct xe_guc_ct_snapshot - GuC command transport (CT) snapshot
62 */
63struct xe_guc_ct_snapshot {
64 /** @ct_enabled: CT enabled info at capture time. */
65 bool ct_enabled;
66 /** @g2h_outstanding: G2H outstanding info at the capture time */
67 u32 g2h_outstanding;
68 /** @g2h: G2H CTB snapshot */
69 struct guc_ctb_snapshot g2h;
70 /** @h2g: H2G CTB snapshot */
71 struct guc_ctb_snapshot h2g;
72 /** @ctb_size: size of the snapshot of the CTB */
73 size_t ctb_size;
74 /** @ctb: snapshot of the entire CTB */
75 u32 *ctb;
76};
77
78/**
79 * enum xe_guc_ct_state - CT state
80 * @XE_GUC_CT_STATE_NOT_INITIALIZED: CT not initialized, messages not expected in this state
81 * @XE_GUC_CT_STATE_DISABLED: CT disabled, messages not expected in this state
82 * @XE_GUC_CT_STATE_STOPPED: CT stopped, drop messages without errors
83 * @XE_GUC_CT_STATE_ENABLED: CT enabled, messages sent / received in this state
84 */
85enum xe_guc_ct_state {
86 XE_GUC_CT_STATE_NOT_INITIALIZED = 0,
87 XE_GUC_CT_STATE_DISABLED,
88 XE_GUC_CT_STATE_STOPPED,
89 XE_GUC_CT_STATE_ENABLED,
90};
91
92#if IS_ENABLED(CONFIG_DRM_XE_DEBUG)
93/** struct xe_dead_ct - Information for debugging a dead CT */
94struct xe_dead_ct {
95 /** @lock: protects memory allocation/free operations, and @reason updates */
96 spinlock_t lock;
97 /** @reason: bit mask of CT_DEAD_* reason codes */
98 unsigned int reason;
99 /** @reported: for preventing multiple dumps per error sequence */
100 bool reported;
101 /** @worker: worker thread to get out of interrupt context before dumping */
102 struct work_struct worker;
103 /** snapshot_ct: copy of CT state and CTB content at point of error */
104 struct xe_guc_ct_snapshot *snapshot_ct;
105 /** snapshot_log: copy of GuC log at point of error */
106 struct xe_guc_log_snapshot *snapshot_log;
107};
108
109/** struct xe_fast_req_fence - Used to track FAST_REQ messages by fence to match error responses */
110struct xe_fast_req_fence {
111 /** @fence: sequence number sent in H2G and return in G2H error */
112 u16 fence;
113 /** @action: H2G action code */
114 u16 action;
115#if IS_ENABLED(CONFIG_DRM_XE_DEBUG_GUC)
116 /** @stack: call stack from when the H2G was sent */
117 depot_stack_handle_t stack;
118#endif
119};
120#endif
121
122/**
123 * struct xe_guc_ct - GuC command transport (CT) layer
124 *
125 * Includes a pair of CT buffers for bi-directional communication and tracking
126 * for the H2G and G2H requests sent and received through the buffers.
127 */
128struct xe_guc_ct {
129 /** @bo: Xe BO for CT */
130 struct xe_bo *bo;
131 /** @lock: protects everything in CT layer */
132 struct mutex lock;
133 /** @fast_lock: protects G2H channel and credits */
134 spinlock_t fast_lock;
135 /** @ctbs: buffers for sending and receiving commands */
136 struct {
137 /** @ctbs.send: Host to GuC (H2G, send) channel */
138 struct guc_ctb h2g;
139 /** @ctbs.recv: GuC to Host (G2H, receive) channel */
140 struct guc_ctb g2h;
141 } ctbs;
142 /** @g2h_outstanding: number of outstanding G2H */
143 u32 g2h_outstanding;
144 /** @g2h_worker: worker to process G2H messages */
145 struct work_struct g2h_worker;
146 /** @safe_mode_worker: worker to check G2H messages with IRQ disabled */
147 struct delayed_work safe_mode_worker;
148 /** @state: CT state */
149 enum xe_guc_ct_state state;
150 /** @fence_seqno: G2H fence seqno - 16 bits used by CT */
151 u32 fence_seqno;
152 /** @fence_lookup: G2H fence lookup */
153 struct xarray fence_lookup;
154 /** @wq: wait queue used for reliable CT sends and freeing G2H credits */
155 wait_queue_head_t wq;
156 /** @g2h_fence_wq: wait queue used for G2H fencing */
157 wait_queue_head_t g2h_fence_wq;
158 /** @g2h_wq: used to process G2H */
159 struct workqueue_struct *g2h_wq;
160 /** @msg: Message buffer */
161 u32 msg[GUC_CTB_MSG_MAX_LEN];
162 /** @fast_msg: Message buffer */
163 u32 fast_msg[GUC_CTB_MSG_MAX_LEN];
164
165#if IS_ENABLED(CONFIG_DRM_XE_DEBUG)
166 /** @dead: information for debugging dead CTs */
167 struct xe_dead_ct dead;
168 /** @fast_req: history of FAST_REQ messages for matching with G2H error responses */
169 struct xe_fast_req_fence fast_req[SZ_32];
170#endif
171};
172
173#endif
174

source code of linux/drivers/gpu/drm/xe/xe_guc_ct_types.h