xref: /openbmc/linux/drivers/gpu/drm/amd/display/dc/dc_stream.h (revision 530e7a660fb795452357b36cce26b839a9a187a9)
1 /*
2  * Copyright 2012-14 Advanced Micro Devices, Inc.
3  *
4  * Permission is hereby granted, free of charge, to any person obtaining a
5  * copy of this software and associated documentation files (the "Software"),
6  * to deal in the Software without restriction, including without limitation
7  * the rights to use, copy, modify, merge, publish, distribute, sublicense,
8  * and/or sell copies of the Software, and to permit persons to whom the
9  * Software is furnished to do so, subject to the following conditions:
10  *
11  * The above copyright notice and this permission notice shall be included in
12  * all copies or substantial portions of the Software.
13  *
14  * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
15  * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
16  * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.  IN NO EVENT SHALL
17  * THE COPYRIGHT HOLDER(S) OR AUTHOR(S) BE LIABLE FOR ANY CLAIM, DAMAGES OR
18  * OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE,
19  * ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR
20  * OTHER DEALINGS IN THE SOFTWARE.
21  *
22  * Authors: AMD
23  *
24  */
25 
26 #ifndef DC_STREAM_H_
27 #define DC_STREAM_H_
28 
29 #include "dc_types.h"
30 #include "grph_object_defs.h"
31 
32 /*******************************************************************************
33  * Stream Interfaces
34  ******************************************************************************/
35 
36 struct dc_stream_status {
37 	int primary_otg_inst;
38 	int stream_enc_inst;
39 	int plane_count;
40 	struct dc_plane_state *plane_states[MAX_SURFACE_NUM];
41 
42 	/*
43 	 * link this stream passes through
44 	 */
45 	struct dc_link *link;
46 };
47 
48 struct dc_stream_state {
49 	struct dc_sink *sink;
50 	struct dc_crtc_timing timing;
51 	struct dc_crtc_timing_adjust timing_adjust;
52 	struct vrr_params vrr_params;
53 
54 	struct rect src; /* composition area */
55 	struct rect dst; /* stream addressable area */
56 
57 	struct audio_info audio_info;
58 
59 	struct freesync_context freesync_ctx;
60 
61 	struct dc_info_packet hdr_static_metadata;
62 	PHYSICAL_ADDRESS_LOC dmdata_address;
63 	bool   use_dynamic_meta;
64 
65 	struct dc_transfer_func *out_transfer_func;
66 	struct colorspace_transform gamut_remap_matrix;
67 	struct dc_csc_transform csc_color_matrix;
68 
69 	enum dc_color_space output_color_space;
70 	enum dc_dither_option dither_option;
71 
72 	enum view_3d_format view_format;
73 
74 	bool ignore_msa_timing_param;
75 
76 	unsigned long long periodic_fn_vsync_delta;
77 
78 	/* TODO: custom INFO packets */
79 	/* TODO: ABM info (DMCU) */
80 	/* PSR info */
81 	unsigned char psr_version;
82 	/* TODO: CEA VIC */
83 
84 	/* DMCU info */
85 	unsigned int abm_level;
86 	unsigned int bl_pwm_level;
87 
88 	/* from core_stream struct */
89 	struct dc_context *ctx;
90 
91 	/* used by DCP and FMT */
92 	struct bit_depth_reduction_params bit_depth_params;
93 	struct clamping_and_pixel_encoding_params clamping;
94 
95 	int phy_pix_clk;
96 	enum signal_type signal;
97 	bool dpms_off;
98 
99 	struct dc_stream_status status;
100 
101 	struct dc_cursor_attributes cursor_attributes;
102 	struct dc_cursor_position cursor_position;
103 
104 	/* from stream struct */
105 	struct kref refcount;
106 
107 	struct crtc_trigger_info triggered_crtc_reset;
108 
109 	/* Computed state bits */
110 	bool mode_changed : 1;
111 
112 };
113 
114 struct dc_stream_update {
115 	struct rect src;
116 	struct rect dst;
117 	struct dc_transfer_func *out_transfer_func;
118 	struct dc_info_packet *hdr_static_metadata;
119 	unsigned int *abm_level;
120 
121 	unsigned long long *periodic_fn_vsync_delta;
122 };
123 
124 bool dc_is_stream_unchanged(
125 	struct dc_stream_state *old_stream, struct dc_stream_state *stream);
126 bool dc_is_stream_scaling_unchanged(
127 	struct dc_stream_state *old_stream, struct dc_stream_state *stream);
128 
129 /*
130  * Set up surface attributes and associate to a stream
131  * The surfaces parameter is an absolute set of all surface active for the stream.
132  * If no surfaces are provided, the stream will be blanked; no memory read.
133  * Any flip related attribute changes must be done through this interface.
134  *
135  * After this call:
136  *   Surfaces attributes are programmed and configured to be composed into stream.
137  *   This does not trigger a flip.  No surface address is programmed.
138  */
139 
140 void dc_commit_updates_for_stream(struct dc *dc,
141 		struct dc_surface_update *srf_updates,
142 		int surface_count,
143 		struct dc_stream_state *stream,
144 		struct dc_stream_update *stream_update,
145 		struct dc_plane_state **plane_states,
146 		struct dc_state *state);
147 /*
148  * Log the current stream state.
149  */
150 void dc_stream_log(
151 	const struct dc_stream_state *stream,
152 	struct dal_logger *dc_logger,
153 	enum dc_log_type log_type);
154 
155 uint8_t dc_get_current_stream_count(struct dc *dc);
156 struct dc_stream_state *dc_get_stream_at_index(struct dc *dc, uint8_t i);
157 
158 /*
159  * Return the current frame counter.
160  */
161 uint32_t dc_stream_get_vblank_counter(const struct dc_stream_state *stream);
162 
163 /* TODO: Return parsed values rather than direct register read
164  * This has a dependency on the caller (amdgpu_display_get_crtc_scanoutpos)
165  * being refactored properly to be dce-specific
166  */
167 bool dc_stream_get_scanoutpos(const struct dc_stream_state *stream,
168 				  uint32_t *v_blank_start,
169 				  uint32_t *v_blank_end,
170 				  uint32_t *h_position,
171 				  uint32_t *v_position);
172 
173 enum dc_status dc_add_stream_to_ctx(
174 			struct dc *dc,
175 		struct dc_state *new_ctx,
176 		struct dc_stream_state *stream);
177 
178 enum dc_status dc_remove_stream_from_ctx(
179 		struct dc *dc,
180 			struct dc_state *new_ctx,
181 			struct dc_stream_state *stream);
182 
183 
184 bool dc_add_plane_to_context(
185 		const struct dc *dc,
186 		struct dc_stream_state *stream,
187 		struct dc_plane_state *plane_state,
188 		struct dc_state *context);
189 
190 bool dc_remove_plane_from_context(
191 		const struct dc *dc,
192 		struct dc_stream_state *stream,
193 		struct dc_plane_state *plane_state,
194 		struct dc_state *context);
195 
196 bool dc_rem_all_planes_for_stream(
197 		const struct dc *dc,
198 		struct dc_stream_state *stream,
199 		struct dc_state *context);
200 
201 bool dc_add_all_planes_for_stream(
202 		const struct dc *dc,
203 		struct dc_stream_state *stream,
204 		struct dc_plane_state * const *plane_states,
205 		int plane_count,
206 		struct dc_state *context);
207 
208 enum dc_status dc_validate_stream(struct dc *dc, struct dc_stream_state *stream);
209 
210 /*
211  * Set up streams and links associated to drive sinks
212  * The streams parameter is an absolute set of all active streams.
213  *
214  * After this call:
215  *   Phy, Encoder, Timing Generator are programmed and enabled.
216  *   New streams are enabled with blank stream; no memory read.
217  */
218 /*
219  * Enable stereo when commit_streams is not required,
220  * for example, frame alternate.
221  */
222 bool dc_enable_stereo(
223 	struct dc *dc,
224 	struct dc_state *context,
225 	struct dc_stream_state *streams[],
226 	uint8_t stream_count);
227 
228 
229 enum surface_update_type dc_check_update_surfaces_for_stream(
230 		struct dc *dc,
231 		struct dc_surface_update *updates,
232 		int surface_count,
233 		struct dc_stream_update *stream_update,
234 		const struct dc_stream_status *stream_status);
235 
236 /**
237  * Create a new default stream for the requested sink
238  */
239 struct dc_stream_state *dc_create_stream_for_sink(struct dc_sink *dc_sink);
240 
241 void update_stream_signal(struct dc_stream_state *stream);
242 
243 void dc_stream_retain(struct dc_stream_state *dc_stream);
244 void dc_stream_release(struct dc_stream_state *dc_stream);
245 
246 struct dc_stream_status *dc_stream_get_status(
247 	struct dc_stream_state *dc_stream);
248 
249 /*******************************************************************************
250  * Cursor interfaces - To manages the cursor within a stream
251  ******************************************************************************/
252 /* TODO: Deprecated once we switch to dc_set_cursor_position */
253 bool dc_stream_set_cursor_attributes(
254 	struct dc_stream_state *stream,
255 	const struct dc_cursor_attributes *attributes);
256 
257 bool dc_stream_set_cursor_position(
258 	struct dc_stream_state *stream,
259 	const struct dc_cursor_position *position);
260 
261 bool dc_stream_adjust_vmin_vmax(struct dc *dc,
262 				struct dc_stream_state **stream,
263 				int num_streams,
264 				int vmin,
265 				int vmax);
266 
267 bool dc_stream_get_crtc_position(struct dc *dc,
268 				 struct dc_stream_state **stream,
269 				 int num_streams,
270 				 unsigned int *v_pos,
271 				 unsigned int *nom_v_pos);
272 
273 bool dc_stream_configure_crc(struct dc *dc,
274 			     struct dc_stream_state *stream,
275 			     bool enable,
276 			     bool continuous);
277 
278 bool dc_stream_get_crc(struct dc *dc,
279 		       struct dc_stream_state *stream,
280 		       uint32_t *r_cr,
281 		       uint32_t *g_y,
282 		       uint32_t *b_cb);
283 
284 void dc_stream_set_static_screen_events(struct dc *dc,
285 					struct dc_stream_state **stream,
286 					int num_streams,
287 					const struct dc_static_screen_events *events);
288 
289 void dc_stream_set_dither_option(struct dc_stream_state *stream,
290 				 enum dc_dither_option option);
291 
292 
293 bool dc_stream_adjust_vmin_vmax(struct dc *dc,
294 				struct dc_stream_state **stream,
295 				int num_streams,
296 				int vmin,
297 				int vmax);
298 
299 bool dc_stream_get_crtc_position(struct dc *dc,
300 				 struct dc_stream_state **stream,
301 				 int num_streams,
302 				 unsigned int *v_pos,
303 				 unsigned int *nom_v_pos);
304 
305 #endif /* DC_STREAM_H_ */
306