xref: /linux/include/drm/display/drm_dp_tunnel.h (revision 7255fcc80d4b525cc10cfaaf7f485830d4ed2000)
1 /* SPDX-License-Identifier: MIT */
2 /*
3  * Copyright © 2023 Intel Corporation
4  */
5 
6 #ifndef __DRM_DP_TUNNEL_H__
7 #define __DRM_DP_TUNNEL_H__
8 
9 #include <linux/err.h>
10 #include <linux/errno.h>
11 #include <linux/types.h>
12 
13 struct drm_dp_aux;
14 
15 struct drm_device;
16 
17 struct drm_atomic_state;
18 struct drm_dp_tunnel_mgr;
19 struct drm_dp_tunnel_state;
20 
21 struct ref_tracker;
22 
23 struct drm_dp_tunnel_ref {
24 	struct drm_dp_tunnel *tunnel;
25 	struct ref_tracker *tracker;
26 };
27 
28 #ifdef CONFIG_DRM_DISPLAY_DP_TUNNEL
29 
30 struct drm_dp_tunnel *
31 drm_dp_tunnel_get(struct drm_dp_tunnel *tunnel, struct ref_tracker **tracker);
32 
33 void
34 drm_dp_tunnel_put(struct drm_dp_tunnel *tunnel, struct ref_tracker **tracker);
35 
36 static inline void drm_dp_tunnel_ref_get(struct drm_dp_tunnel *tunnel,
37 					 struct drm_dp_tunnel_ref *tunnel_ref)
38 {
39 	tunnel_ref->tunnel = drm_dp_tunnel_get(tunnel, &tunnel_ref->tracker);
40 }
41 
42 static inline void drm_dp_tunnel_ref_put(struct drm_dp_tunnel_ref *tunnel_ref)
43 {
44 	drm_dp_tunnel_put(tunnel_ref->tunnel, &tunnel_ref->tracker);
45 	tunnel_ref->tunnel = NULL;
46 }
47 
48 struct drm_dp_tunnel *
49 drm_dp_tunnel_detect(struct drm_dp_tunnel_mgr *mgr,
50 		     struct drm_dp_aux *aux);
51 int drm_dp_tunnel_destroy(struct drm_dp_tunnel *tunnel);
52 
53 int drm_dp_tunnel_enable_bw_alloc(struct drm_dp_tunnel *tunnel);
54 int drm_dp_tunnel_disable_bw_alloc(struct drm_dp_tunnel *tunnel);
55 bool drm_dp_tunnel_bw_alloc_is_enabled(const struct drm_dp_tunnel *tunnel);
56 int drm_dp_tunnel_alloc_bw(struct drm_dp_tunnel *tunnel, int bw);
57 int drm_dp_tunnel_get_allocated_bw(struct drm_dp_tunnel *tunnel);
58 int drm_dp_tunnel_update_state(struct drm_dp_tunnel *tunnel);
59 
60 void drm_dp_tunnel_set_io_error(struct drm_dp_tunnel *tunnel);
61 
62 int drm_dp_tunnel_handle_irq(struct drm_dp_tunnel_mgr *mgr,
63 			     struct drm_dp_aux *aux);
64 
65 int drm_dp_tunnel_max_dprx_rate(const struct drm_dp_tunnel *tunnel);
66 int drm_dp_tunnel_max_dprx_lane_count(const struct drm_dp_tunnel *tunnel);
67 int drm_dp_tunnel_available_bw(const struct drm_dp_tunnel *tunnel);
68 
69 const char *drm_dp_tunnel_name(const struct drm_dp_tunnel *tunnel);
70 
71 struct drm_dp_tunnel_state *
72 drm_dp_tunnel_atomic_get_state(struct drm_atomic_state *state,
73 			       struct drm_dp_tunnel *tunnel);
74 
75 struct drm_dp_tunnel_state *
76 drm_dp_tunnel_atomic_get_old_state(struct drm_atomic_state *state,
77 				   const struct drm_dp_tunnel *tunnel);
78 
79 struct drm_dp_tunnel_state *
80 drm_dp_tunnel_atomic_get_new_state(struct drm_atomic_state *state,
81 				   const struct drm_dp_tunnel *tunnel);
82 
83 int drm_dp_tunnel_atomic_set_stream_bw(struct drm_atomic_state *state,
84 				       struct drm_dp_tunnel *tunnel,
85 				       u8 stream_id, int bw);
86 int drm_dp_tunnel_atomic_get_group_streams_in_state(struct drm_atomic_state *state,
87 						    const struct drm_dp_tunnel *tunnel,
88 						    u32 *stream_mask);
89 
90 int drm_dp_tunnel_atomic_check_stream_bws(struct drm_atomic_state *state,
91 					  u32 *failed_stream_mask);
92 
93 int drm_dp_tunnel_atomic_get_required_bw(const struct drm_dp_tunnel_state *tunnel_state);
94 
95 struct drm_dp_tunnel_mgr *
96 drm_dp_tunnel_mgr_create(struct drm_device *dev, int max_group_count);
97 void drm_dp_tunnel_mgr_destroy(struct drm_dp_tunnel_mgr *mgr);
98 
99 #else
100 
101 static inline struct drm_dp_tunnel *
102 drm_dp_tunnel_get(struct drm_dp_tunnel *tunnel, struct ref_tracker **tracker)
103 {
104 	return NULL;
105 }
106 
107 static inline void
108 drm_dp_tunnel_put(struct drm_dp_tunnel *tunnel, struct ref_tracker **tracker) {}
109 
110 static inline void drm_dp_tunnel_ref_get(struct drm_dp_tunnel *tunnel,
111 					 struct drm_dp_tunnel_ref *tunnel_ref) {}
112 
113 static inline void drm_dp_tunnel_ref_put(struct drm_dp_tunnel_ref *tunnel_ref) {}
114 
115 static inline struct drm_dp_tunnel *
116 drm_dp_tunnel_detect(struct drm_dp_tunnel_mgr *mgr,
117 		     struct drm_dp_aux *aux)
118 {
119 	return ERR_PTR(-EOPNOTSUPP);
120 }
121 
122 static inline int
123 drm_dp_tunnel_destroy(struct drm_dp_tunnel *tunnel)
124 {
125 	return 0;
126 }
127 
128 static inline int drm_dp_tunnel_enable_bw_alloc(struct drm_dp_tunnel *tunnel)
129 {
130 	return -EOPNOTSUPP;
131 }
132 
133 static inline int drm_dp_tunnel_disable_bw_alloc(struct drm_dp_tunnel *tunnel)
134 {
135 	return -EOPNOTSUPP;
136 }
137 
138 static inline bool drm_dp_tunnel_bw_alloc_is_enabled(const struct drm_dp_tunnel *tunnel)
139 {
140 	return false;
141 }
142 
143 static inline int
144 drm_dp_tunnel_alloc_bw(struct drm_dp_tunnel *tunnel, int bw)
145 {
146 	return -EOPNOTSUPP;
147 }
148 
149 static inline int
150 drm_dp_tunnel_get_allocated_bw(struct drm_dp_tunnel *tunnel)
151 {
152 	return -1;
153 }
154 
155 static inline int
156 drm_dp_tunnel_update_state(struct drm_dp_tunnel *tunnel)
157 {
158 	return -EOPNOTSUPP;
159 }
160 
161 static inline void drm_dp_tunnel_set_io_error(struct drm_dp_tunnel *tunnel) {}
162 
163 static inline int
164 drm_dp_tunnel_handle_irq(struct drm_dp_tunnel_mgr *mgr,
165 			 struct drm_dp_aux *aux)
166 {
167 	return -EOPNOTSUPP;
168 }
169 
170 static inline int
171 drm_dp_tunnel_max_dprx_rate(const struct drm_dp_tunnel *tunnel)
172 {
173 	return 0;
174 }
175 
176 static inline int
177 drm_dp_tunnel_max_dprx_lane_count(const struct drm_dp_tunnel *tunnel)
178 {
179 	return 0;
180 }
181 
182 static inline int
183 drm_dp_tunnel_available_bw(const struct drm_dp_tunnel *tunnel)
184 {
185 	return -1;
186 }
187 
188 static inline const char *
189 drm_dp_tunnel_name(const struct drm_dp_tunnel *tunnel)
190 {
191 	return NULL;
192 }
193 
194 static inline struct drm_dp_tunnel_state *
195 drm_dp_tunnel_atomic_get_state(struct drm_atomic_state *state,
196 			       struct drm_dp_tunnel *tunnel)
197 {
198 	return ERR_PTR(-EOPNOTSUPP);
199 }
200 
201 static inline struct drm_dp_tunnel_state *
202 drm_dp_tunnel_atomic_get_new_state(struct drm_atomic_state *state,
203 				   const struct drm_dp_tunnel *tunnel)
204 {
205 	return ERR_PTR(-EOPNOTSUPP);
206 }
207 
208 static inline int
209 drm_dp_tunnel_atomic_set_stream_bw(struct drm_atomic_state *state,
210 				   struct drm_dp_tunnel *tunnel,
211 				   u8 stream_id, int bw)
212 {
213 	return -EOPNOTSUPP;
214 }
215 
216 static inline int
217 drm_dp_tunnel_atomic_get_group_streams_in_state(struct drm_atomic_state *state,
218 						const struct drm_dp_tunnel *tunnel,
219 						u32 *stream_mask)
220 {
221 	return -EOPNOTSUPP;
222 }
223 
224 static inline int
225 drm_dp_tunnel_atomic_check_stream_bws(struct drm_atomic_state *state,
226 				      u32 *failed_stream_mask)
227 {
228 	return -EOPNOTSUPP;
229 }
230 
231 static inline int
232 drm_dp_tunnel_atomic_get_required_bw(const struct drm_dp_tunnel_state *tunnel_state)
233 {
234 	return 0;
235 }
236 
237 static inline struct drm_dp_tunnel_mgr *
238 drm_dp_tunnel_mgr_create(struct drm_device *dev, int max_group_count)
239 {
240 	return ERR_PTR(-EOPNOTSUPP);
241 }
242 
243 static inline
244 void drm_dp_tunnel_mgr_destroy(struct drm_dp_tunnel_mgr *mgr) {}
245 
246 #endif /* CONFIG_DRM_DISPLAY_DP_TUNNEL */
247 
248 #endif /* __DRM_DP_TUNNEL_H__ */
249