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_commit; 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 bool drm_dp_tunnel_pr_optimization_supported(const struct drm_dp_tunnel *tunnel); 57 int drm_dp_tunnel_alloc_bw(struct drm_dp_tunnel *tunnel, int bw); 58 int drm_dp_tunnel_get_allocated_bw(struct drm_dp_tunnel *tunnel); 59 int drm_dp_tunnel_update_state(struct drm_dp_tunnel *tunnel); 60 61 void drm_dp_tunnel_set_io_error(struct drm_dp_tunnel *tunnel); 62 63 int drm_dp_tunnel_handle_irq(struct drm_dp_tunnel_mgr *mgr, 64 struct drm_dp_aux *aux); 65 66 bool drm_dp_tunnel_128b132b_supported(const struct drm_dp_tunnel *tunnel); 67 bool drm_dp_tunnel_128b132b_lane0_mapping_supported(const struct drm_dp_tunnel *tunnel); 68 u8 drm_dp_tunnel_128b132b_dprx_rates(const struct drm_dp_tunnel *tunnel); 69 int drm_dp_tunnel_max_dprx_rate(const struct drm_dp_tunnel *tunnel); 70 int drm_dp_tunnel_max_dprx_lane_count(const struct drm_dp_tunnel *tunnel); 71 int drm_dp_tunnel_available_bw(const struct drm_dp_tunnel *tunnel); 72 73 const char *drm_dp_tunnel_name(const struct drm_dp_tunnel *tunnel); 74 75 struct drm_dp_tunnel_state * 76 drm_dp_tunnel_atomic_get_state(struct drm_atomic_commit *state, 77 struct drm_dp_tunnel *tunnel); 78 79 struct drm_dp_tunnel_state * 80 drm_dp_tunnel_atomic_get_old_state(struct drm_atomic_commit *state, 81 const struct drm_dp_tunnel *tunnel); 82 83 struct drm_dp_tunnel_state * 84 drm_dp_tunnel_atomic_get_new_state(struct drm_atomic_commit *state, 85 const struct drm_dp_tunnel *tunnel); 86 87 int drm_dp_tunnel_atomic_set_stream_bw(struct drm_atomic_commit *state, 88 struct drm_dp_tunnel *tunnel, 89 u8 stream_id, int bw); 90 int drm_dp_tunnel_atomic_get_group_streams_in_state(struct drm_atomic_commit *state, 91 const struct drm_dp_tunnel *tunnel, 92 u32 *stream_mask); 93 94 int drm_dp_tunnel_atomic_check_stream_bws(struct drm_atomic_commit *state, 95 u32 *failed_stream_mask); 96 97 int drm_dp_tunnel_atomic_get_required_bw(const struct drm_dp_tunnel_state *tunnel_state); 98 99 struct drm_dp_tunnel_mgr * 100 drm_dp_tunnel_mgr_create(struct drm_device *dev, int max_group_count); 101 void drm_dp_tunnel_mgr_destroy(struct drm_dp_tunnel_mgr *mgr); 102 103 #else 104 105 static inline struct drm_dp_tunnel * 106 drm_dp_tunnel_get(struct drm_dp_tunnel *tunnel, struct ref_tracker **tracker) 107 { 108 return NULL; 109 } 110 111 static inline void 112 drm_dp_tunnel_put(struct drm_dp_tunnel *tunnel, struct ref_tracker **tracker) {} 113 114 static inline void drm_dp_tunnel_ref_get(struct drm_dp_tunnel *tunnel, 115 struct drm_dp_tunnel_ref *tunnel_ref) {} 116 117 static inline void drm_dp_tunnel_ref_put(struct drm_dp_tunnel_ref *tunnel_ref) {} 118 119 static inline struct drm_dp_tunnel * 120 drm_dp_tunnel_detect(struct drm_dp_tunnel_mgr *mgr, 121 struct drm_dp_aux *aux) 122 { 123 return ERR_PTR(-EOPNOTSUPP); 124 } 125 126 static inline int 127 drm_dp_tunnel_destroy(struct drm_dp_tunnel *tunnel) 128 { 129 return 0; 130 } 131 132 static inline int drm_dp_tunnel_enable_bw_alloc(struct drm_dp_tunnel *tunnel) 133 { 134 return -EOPNOTSUPP; 135 } 136 137 static inline int drm_dp_tunnel_disable_bw_alloc(struct drm_dp_tunnel *tunnel) 138 { 139 return -EOPNOTSUPP; 140 } 141 142 static inline bool drm_dp_tunnel_bw_alloc_is_enabled(const struct drm_dp_tunnel *tunnel) 143 { 144 return false; 145 } 146 147 static inline bool drm_dp_tunnel_pr_optimization_supported(const struct drm_dp_tunnel *tunnel) 148 { 149 return false; 150 } 151 152 static inline int 153 drm_dp_tunnel_alloc_bw(struct drm_dp_tunnel *tunnel, int bw) 154 { 155 return -EOPNOTSUPP; 156 } 157 158 static inline int 159 drm_dp_tunnel_get_allocated_bw(struct drm_dp_tunnel *tunnel) 160 { 161 return -1; 162 } 163 164 static inline int 165 drm_dp_tunnel_update_state(struct drm_dp_tunnel *tunnel) 166 { 167 return -EOPNOTSUPP; 168 } 169 170 static inline void drm_dp_tunnel_set_io_error(struct drm_dp_tunnel *tunnel) {} 171 172 static inline int 173 drm_dp_tunnel_handle_irq(struct drm_dp_tunnel_mgr *mgr, 174 struct drm_dp_aux *aux) 175 { 176 return -EOPNOTSUPP; 177 } 178 179 static inline bool 180 drm_dp_tunnel_128b132b_supported(const struct drm_dp_tunnel *tunnel) 181 { 182 return false; 183 } 184 185 static inline bool 186 drm_dp_tunnel_128b132b_lane0_mapping_supported(const struct drm_dp_tunnel *tunnel) 187 { 188 return false; 189 } 190 191 static inline u8 192 drm_dp_tunnel_128b132b_dprx_rates(const struct drm_dp_tunnel *tunnel) 193 { 194 return 0; 195 } 196 197 static inline int 198 drm_dp_tunnel_max_dprx_rate(const struct drm_dp_tunnel *tunnel) 199 { 200 return 0; 201 } 202 203 static inline int 204 drm_dp_tunnel_max_dprx_lane_count(const struct drm_dp_tunnel *tunnel) 205 { 206 return 0; 207 } 208 209 static inline int 210 drm_dp_tunnel_available_bw(const struct drm_dp_tunnel *tunnel) 211 { 212 return -1; 213 } 214 215 static inline const char * 216 drm_dp_tunnel_name(const struct drm_dp_tunnel *tunnel) 217 { 218 return NULL; 219 } 220 221 static inline struct drm_dp_tunnel_state * 222 drm_dp_tunnel_atomic_get_state(struct drm_atomic_commit *state, 223 struct drm_dp_tunnel *tunnel) 224 { 225 return ERR_PTR(-EOPNOTSUPP); 226 } 227 228 static inline struct drm_dp_tunnel_state * 229 drm_dp_tunnel_atomic_get_new_state(struct drm_atomic_commit *state, 230 const struct drm_dp_tunnel *tunnel) 231 { 232 return ERR_PTR(-EOPNOTSUPP); 233 } 234 235 static inline int 236 drm_dp_tunnel_atomic_set_stream_bw(struct drm_atomic_commit *state, 237 struct drm_dp_tunnel *tunnel, 238 u8 stream_id, int bw) 239 { 240 return -EOPNOTSUPP; 241 } 242 243 static inline int 244 drm_dp_tunnel_atomic_get_group_streams_in_state(struct drm_atomic_commit *state, 245 const struct drm_dp_tunnel *tunnel, 246 u32 *stream_mask) 247 { 248 return -EOPNOTSUPP; 249 } 250 251 static inline int 252 drm_dp_tunnel_atomic_check_stream_bws(struct drm_atomic_commit *state, 253 u32 *failed_stream_mask) 254 { 255 return -EOPNOTSUPP; 256 } 257 258 static inline int 259 drm_dp_tunnel_atomic_get_required_bw(const struct drm_dp_tunnel_state *tunnel_state) 260 { 261 return 0; 262 } 263 264 static inline struct drm_dp_tunnel_mgr * 265 drm_dp_tunnel_mgr_create(struct drm_device *dev, int max_group_count) 266 { 267 return ERR_PTR(-EOPNOTSUPP); 268 } 269 270 static inline 271 void drm_dp_tunnel_mgr_destroy(struct drm_dp_tunnel_mgr *mgr) {} 272 273 #endif /* CONFIG_DRM_DISPLAY_DP_TUNNEL */ 274 275 #endif /* __DRM_DP_TUNNEL_H__ */ 276