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