]>
Commit | Line | Data |
---|---|---|
4562236b HW |
1 | /* |
2 | * Copyright 2012-15 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 | #include "dm_services.h" | |
27 | #include "dc.h" | |
28 | #include "core_types.h" | |
29 | #include "resource.h" | |
ab2541b6 AC |
30 | #include "ipp.h" |
31 | #include "timing_generator.h" | |
4562236b | 32 | |
4562236b HW |
33 | /******************************************************************************* |
34 | * Private functions | |
35 | ******************************************************************************/ | |
96313f1b JZ |
36 | #define TMDS_MAX_PIXEL_CLOCK_IN_KHZ_UPMOST 297000 |
37 | static void update_stream_signal(struct dc_stream_state *stream) | |
38 | { | |
39 | if (stream->output_signal == SIGNAL_TYPE_NONE) { | |
40 | struct dc_sink *dc_sink = stream->sink; | |
41 | ||
42 | if (dc_sink->sink_signal == SIGNAL_TYPE_NONE) | |
43 | stream->signal = stream->sink->link->connector_signal; | |
44 | else | |
45 | stream->signal = dc_sink->sink_signal; | |
46 | } else { | |
47 | stream->signal = stream->output_signal; | |
48 | } | |
49 | ||
50 | if (dc_is_dvi_signal(stream->signal)) { | |
51 | if (stream->timing.pix_clk_khz > TMDS_MAX_PIXEL_CLOCK_IN_KHZ_UPMOST && | |
52 | stream->sink->sink_signal != SIGNAL_TYPE_DVI_SINGLE_LINK) | |
53 | stream->signal = SIGNAL_TYPE_DVI_DUAL_LINK; | |
54 | else | |
55 | stream->signal = SIGNAL_TYPE_DVI_SINGLE_LINK; | |
56 | } | |
57 | } | |
4562236b | 58 | |
db6c3bdc | 59 | static void construct(struct dc_stream_state *stream, |
b73a22d3 | 60 | struct dc_sink *dc_sink_data) |
4562236b HW |
61 | { |
62 | uint32_t i = 0; | |
63 | ||
b73a22d3 | 64 | stream->sink = dc_sink_data; |
4562236b | 65 | stream->ctx = stream->sink->ctx; |
4562236b HW |
66 | |
67 | dc_sink_retain(dc_sink_data); | |
68 | ||
69 | /* Copy audio modes */ | |
70 | /* TODO - Remove this translation */ | |
71 | for (i = 0; i < (dc_sink_data->edid_caps.audio_mode_count); i++) | |
72 | { | |
4fa086b9 LSL |
73 | stream->audio_info.modes[i].channel_count = dc_sink_data->edid_caps.audio_modes[i].channel_count; |
74 | stream->audio_info.modes[i].format_code = dc_sink_data->edid_caps.audio_modes[i].format_code; | |
75 | stream->audio_info.modes[i].sample_rates.all = dc_sink_data->edid_caps.audio_modes[i].sample_rate; | |
76 | stream->audio_info.modes[i].sample_size = dc_sink_data->edid_caps.audio_modes[i].sample_size; | |
4562236b | 77 | } |
4fa086b9 LSL |
78 | stream->audio_info.mode_count = dc_sink_data->edid_caps.audio_mode_count; |
79 | stream->audio_info.audio_latency = dc_sink_data->edid_caps.audio_latency; | |
80 | stream->audio_info.video_latency = dc_sink_data->edid_caps.video_latency; | |
4562236b | 81 | memmove( |
4fa086b9 | 82 | stream->audio_info.display_name, |
4562236b HW |
83 | dc_sink_data->edid_caps.display_name, |
84 | AUDIO_INFO_DISPLAY_NAME_SIZE_IN_CHARS); | |
4fa086b9 LSL |
85 | stream->audio_info.manufacture_id = dc_sink_data->edid_caps.manufacturer_id; |
86 | stream->audio_info.product_id = dc_sink_data->edid_caps.product_id; | |
87 | stream->audio_info.flags.all = dc_sink_data->edid_caps.speaker_flags; | |
4562236b | 88 | |
8c895313 | 89 | if (dc_sink_data->dc_container_id != NULL) { |
90 | struct dc_container_id *dc_container_id = dc_sink_data->dc_container_id; | |
91 | ||
4fa086b9 LSL |
92 | stream->audio_info.port_id[0] = dc_container_id->portId[0]; |
93 | stream->audio_info.port_id[1] = dc_container_id->portId[1]; | |
8c895313 | 94 | } else { |
95 | /* TODO - WindowDM has implemented, | |
96 | other DMs need Unhardcode port_id */ | |
4fa086b9 LSL |
97 | stream->audio_info.port_id[0] = 0x5558859e; |
98 | stream->audio_info.port_id[1] = 0xd989449; | |
8c895313 | 99 | } |
4562236b HW |
100 | |
101 | /* EDID CAP translation for HDMI 2.0 */ | |
4fa086b9 | 102 | stream->timing.flags.LTE_340MCSC_SCRAMBLE = dc_sink_data->edid_caps.lte_340mcsc_scramble; |
4562236b | 103 | |
d0778ebf | 104 | stream->status.link = stream->sink->link; |
96313f1b JZ |
105 | |
106 | update_stream_signal(stream); | |
4562236b HW |
107 | } |
108 | ||
0971c40e | 109 | static void destruct(struct dc_stream_state *stream) |
4562236b | 110 | { |
b73a22d3 | 111 | dc_sink_release(stream->sink); |
4fa086b9 | 112 | if (stream->out_transfer_func != NULL) { |
90e508ba | 113 | dc_transfer_func_release( |
4fa086b9 LSL |
114 | stream->out_transfer_func); |
115 | stream->out_transfer_func = NULL; | |
80bd2096 | 116 | } |
4562236b HW |
117 | } |
118 | ||
0971c40e | 119 | void dc_stream_retain(struct dc_stream_state *stream) |
4562236b | 120 | { |
bfe0feb1 DA |
121 | kref_get(&stream->refcount); |
122 | } | |
123 | ||
124 | static void dc_stream_free(struct kref *kref) | |
125 | { | |
126 | struct dc_stream_state *stream = container_of(kref, struct dc_stream_state, refcount); | |
127 | ||
128 | destruct(stream); | |
129 | kfree(stream); | |
4562236b HW |
130 | } |
131 | ||
0971c40e | 132 | void dc_stream_release(struct dc_stream_state *stream) |
4562236b | 133 | { |
a989ab08 | 134 | if (stream != NULL) { |
bfe0feb1 | 135 | kref_put(&stream->refcount, dc_stream_free); |
4562236b HW |
136 | } |
137 | } | |
138 | ||
0971c40e | 139 | struct dc_stream_state *dc_create_stream_for_sink( |
b73a22d3 | 140 | struct dc_sink *sink) |
4562236b | 141 | { |
0971c40e | 142 | struct dc_stream_state *stream; |
4562236b HW |
143 | |
144 | if (sink == NULL) | |
db6c3bdc | 145 | return NULL; |
4562236b | 146 | |
2004f45e | 147 | stream = kzalloc(sizeof(struct dc_stream_state), GFP_KERNEL); |
db6c3bdc DA |
148 | if (stream == NULL) |
149 | return NULL; | |
4562236b | 150 | |
db6c3bdc | 151 | construct(stream, sink); |
4562236b | 152 | |
bfe0feb1 | 153 | kref_init(&stream->refcount); |
4562236b | 154 | |
a989ab08 | 155 | return stream; |
4562236b | 156 | } |
ab2541b6 | 157 | |
e12cfcb1 | 158 | struct dc_stream_status *dc_stream_get_status( |
0971c40e | 159 | struct dc_stream_state *stream) |
ab2541b6 AC |
160 | { |
161 | uint8_t i; | |
fb3466a4 | 162 | struct dc *dc = stream->ctx->dc; |
ab2541b6 | 163 | |
608ac7bb JZ |
164 | for (i = 0; i < dc->current_state->stream_count; i++) { |
165 | if (stream == dc->current_state->streams[i]) | |
166 | return &dc->current_state->stream_status[i]; | |
e2c7bb12 | 167 | } |
ab2541b6 AC |
168 | |
169 | return NULL; | |
170 | } | |
171 | ||
172 | /** | |
173 | * Update the cursor attributes and set cursor surface address | |
174 | */ | |
175 | bool dc_stream_set_cursor_attributes( | |
067c878a | 176 | struct dc_stream_state *stream, |
ab2541b6 AC |
177 | const struct dc_cursor_attributes *attributes) |
178 | { | |
179 | int i; | |
fb3466a4 | 180 | struct dc *core_dc; |
ab2541b6 | 181 | struct resource_context *res_ctx; |
ab2541b6 | 182 | |
4fa086b9 | 183 | if (NULL == stream) { |
ab2541b6 | 184 | dm_error("DC: dc_stream is NULL!\n"); |
bf5563ed | 185 | return false; |
ab2541b6 AC |
186 | } |
187 | if (NULL == attributes) { | |
188 | dm_error("DC: attributes is NULL!\n"); | |
bf5563ed | 189 | return false; |
ab2541b6 AC |
190 | } |
191 | ||
067c878a | 192 | if (attributes->address.quad_part == 0) { |
b0f8d4e9 | 193 | dm_output_to_console("DC: Cursor address is 0!\n"); |
067c878a YS |
194 | return false; |
195 | } | |
196 | ||
fb3466a4 | 197 | core_dc = stream->ctx->dc; |
608ac7bb | 198 | res_ctx = &core_dc->current_state->res_ctx; |
ab2541b6 AC |
199 | |
200 | for (i = 0; i < MAX_PIPES; i++) { | |
201 | struct pipe_ctx *pipe_ctx = &res_ctx->pipe_ctx[i]; | |
202 | ||
00b06d2d S |
203 | if (pipe_ctx->stream != stream || (!pipe_ctx->plane_res.xfm && |
204 | !pipe_ctx->plane_res.dpp) || !pipe_ctx->plane_res.ipp) | |
beb16b6a | 205 | continue; |
3be5262e | 206 | if (pipe_ctx->top_pipe && pipe_ctx->plane_state != pipe_ctx->top_pipe->plane_state) |
beb16b6a | 207 | continue; |
ab2541b6 | 208 | |
b87d78d6 YHL |
209 | |
210 | if (pipe_ctx->plane_res.ipp->funcs->ipp_cursor_set_attributes != NULL) | |
211 | pipe_ctx->plane_res.ipp->funcs->ipp_cursor_set_attributes( | |
212 | pipe_ctx->plane_res.ipp, attributes); | |
213 | ||
39a4e660 YHL |
214 | if (pipe_ctx->plane_res.hubp != NULL && |
215 | pipe_ctx->plane_res.hubp->funcs->set_cursor_attributes != NULL) | |
8feabd03 YHL |
216 | pipe_ctx->plane_res.hubp->funcs->set_cursor_attributes( |
217 | pipe_ctx->plane_res.hubp, attributes); | |
218 | ||
39a4e660 YHL |
219 | if (pipe_ctx->plane_res.mi != NULL && |
220 | pipe_ctx->plane_res.mi->funcs->set_cursor_attributes != NULL) | |
b87d78d6 YHL |
221 | pipe_ctx->plane_res.mi->funcs->set_cursor_attributes( |
222 | pipe_ctx->plane_res.mi, attributes); | |
223 | ||
8feabd03 | 224 | |
d94585a0 YHL |
225 | if (pipe_ctx->plane_res.xfm != NULL && |
226 | pipe_ctx->plane_res.xfm->funcs->set_cursor_attributes != NULL) | |
b87d78d6 YHL |
227 | pipe_ctx->plane_res.xfm->funcs->set_cursor_attributes( |
228 | pipe_ctx->plane_res.xfm, attributes); | |
d94585a0 YHL |
229 | |
230 | if (pipe_ctx->plane_res.dpp != NULL && | |
231 | pipe_ctx->plane_res.dpp->funcs->set_cursor_attributes != NULL) | |
232 | pipe_ctx->plane_res.dpp->funcs->set_cursor_attributes( | |
233 | pipe_ctx->plane_res.dpp, attributes); | |
ab2541b6 AC |
234 | } |
235 | ||
067c878a YS |
236 | stream->cursor_attributes = *attributes; |
237 | ||
beb16b6a | 238 | return true; |
ab2541b6 AC |
239 | } |
240 | ||
241 | bool dc_stream_set_cursor_position( | |
0971c40e | 242 | struct dc_stream_state *stream, |
beb16b6a | 243 | const struct dc_cursor_position *position) |
ab2541b6 AC |
244 | { |
245 | int i; | |
fb3466a4 | 246 | struct dc *core_dc; |
ab2541b6 | 247 | struct resource_context *res_ctx; |
ab2541b6 | 248 | |
4fa086b9 | 249 | if (NULL == stream) { |
ab2541b6 AC |
250 | dm_error("DC: dc_stream is NULL!\n"); |
251 | return false; | |
252 | } | |
253 | ||
254 | if (NULL == position) { | |
255 | dm_error("DC: cursor position is NULL!\n"); | |
256 | return false; | |
257 | } | |
258 | ||
fb3466a4 | 259 | core_dc = stream->ctx->dc; |
608ac7bb | 260 | res_ctx = &core_dc->current_state->res_ctx; |
ab2541b6 AC |
261 | |
262 | for (i = 0; i < MAX_PIPES; i++) { | |
263 | struct pipe_ctx *pipe_ctx = &res_ctx->pipe_ctx[i]; | |
86a66c4e | 264 | struct input_pixel_processor *ipp = pipe_ctx->plane_res.ipp; |
39a4e660 | 265 | struct mem_input *mi = pipe_ctx->plane_res.mi; |
8feabd03 | 266 | struct hubp *hubp = pipe_ctx->plane_res.hubp; |
d94585a0 | 267 | struct dpp *dpp = pipe_ctx->plane_res.dpp; |
beb16b6a DL |
268 | struct dc_cursor_position pos_cpy = *position; |
269 | struct dc_cursor_mi_param param = { | |
4fa086b9 | 270 | .pixel_clk_khz = stream->timing.pix_clk_khz, |
a2b8659d | 271 | .ref_clk_khz = core_dc->res_pool->ref_clock_inKhz, |
6702a9ac HW |
272 | .viewport_x_start = pipe_ctx->plane_res.scl_data.viewport.x, |
273 | .viewport_width = pipe_ctx->plane_res.scl_data.viewport.width, | |
274 | .h_scale_ratio = pipe_ctx->plane_res.scl_data.ratios.horz | |
beb16b6a DL |
275 | }; |
276 | ||
277 | if (pipe_ctx->stream != stream || | |
8feabd03 | 278 | (!pipe_ctx->plane_res.mi && !pipe_ctx->plane_res.hubp) || |
b87d78d6 | 279 | !pipe_ctx->plane_state || |
00b06d2d S |
280 | (!pipe_ctx->plane_res.xfm && !pipe_ctx->plane_res.dpp) || |
281 | !pipe_ctx->plane_res.ipp) | |
beb16b6a | 282 | continue; |
ab2541b6 | 283 | |
3be5262e | 284 | if (pipe_ctx->plane_state->address.type |
cf4cde2b YS |
285 | == PLN_ADDR_TYPE_VIDEO_PROGRESSIVE) |
286 | pos_cpy.enable = false; | |
287 | ||
3be5262e | 288 | if (pipe_ctx->top_pipe && pipe_ctx->plane_state != pipe_ctx->top_pipe->plane_state) |
beb16b6a DL |
289 | pos_cpy.enable = false; |
290 | ||
b87d78d6 | 291 | |
82e97810 | 292 | if (ipp != NULL && ipp->funcs->ipp_cursor_set_position != NULL) |
b87d78d6 YHL |
293 | ipp->funcs->ipp_cursor_set_position(ipp, &pos_cpy, ¶m); |
294 | ||
39a4e660 YHL |
295 | if (mi != NULL && mi->funcs->set_cursor_position != NULL) |
296 | mi->funcs->set_cursor_position(mi, &pos_cpy, ¶m); | |
297 | ||
b3fb2b4e HW |
298 | if (!hubp) |
299 | continue; | |
8feabd03 | 300 | |
b3fb2b4e HW |
301 | if (hubp->funcs->set_cursor_position != NULL) |
302 | hubp->funcs->set_cursor_position(hubp, &pos_cpy, ¶m); | |
b87d78d6 | 303 | |
d94585a0 YHL |
304 | if (dpp != NULL && dpp->funcs->set_cursor_position != NULL) |
305 | dpp->funcs->set_cursor_position(dpp, &pos_cpy, ¶m, hubp->curs_attr.width); | |
306 | ||
ab2541b6 AC |
307 | } |
308 | ||
beb16b6a | 309 | return true; |
ab2541b6 AC |
310 | } |
311 | ||
0971c40e | 312 | uint32_t dc_stream_get_vblank_counter(const struct dc_stream_state *stream) |
ab2541b6 AC |
313 | { |
314 | uint8_t i; | |
fb3466a4 | 315 | struct dc *core_dc = stream->ctx->dc; |
ab2541b6 | 316 | struct resource_context *res_ctx = |
608ac7bb | 317 | &core_dc->current_state->res_ctx; |
ab2541b6 AC |
318 | |
319 | for (i = 0; i < MAX_PIPES; i++) { | |
6b670fa9 | 320 | struct timing_generator *tg = res_ctx->pipe_ctx[i].stream_res.tg; |
ab2541b6 AC |
321 | |
322 | if (res_ctx->pipe_ctx[i].stream != stream) | |
323 | continue; | |
324 | ||
325 | return tg->funcs->get_frame_count(tg); | |
326 | } | |
327 | ||
328 | return 0; | |
329 | } | |
330 | ||
0971c40e | 331 | bool dc_stream_get_scanoutpos(const struct dc_stream_state *stream, |
81c50963 ST |
332 | uint32_t *v_blank_start, |
333 | uint32_t *v_blank_end, | |
334 | uint32_t *h_position, | |
335 | uint32_t *v_position) | |
ab2541b6 AC |
336 | { |
337 | uint8_t i; | |
81c50963 | 338 | bool ret = false; |
fb3466a4 | 339 | struct dc *core_dc = stream->ctx->dc; |
ab2541b6 | 340 | struct resource_context *res_ctx = |
608ac7bb | 341 | &core_dc->current_state->res_ctx; |
ab2541b6 AC |
342 | |
343 | for (i = 0; i < MAX_PIPES; i++) { | |
6b670fa9 | 344 | struct timing_generator *tg = res_ctx->pipe_ctx[i].stream_res.tg; |
ab2541b6 AC |
345 | |
346 | if (res_ctx->pipe_ctx[i].stream != stream) | |
347 | continue; | |
348 | ||
81c50963 ST |
349 | tg->funcs->get_scanoutpos(tg, |
350 | v_blank_start, | |
351 | v_blank_end, | |
352 | h_position, | |
353 | v_position); | |
354 | ||
355 | ret = true; | |
356 | break; | |
ab2541b6 AC |
357 | } |
358 | ||
81c50963 | 359 | return ret; |
ab2541b6 AC |
360 | } |
361 | ||
362 | ||
363 | void dc_stream_log( | |
0971c40e | 364 | const struct dc_stream_state *stream, |
ab2541b6 AC |
365 | struct dal_logger *dm_logger, |
366 | enum dc_log_type log_type) | |
367 | { | |
ab2541b6 AC |
368 | |
369 | dm_logger_write(dm_logger, | |
370 | log_type, | |
4b679bc3 | 371 | "core_stream 0x%x: src: %d, %d, %d, %d; dst: %d, %d, %d, %d, colorSpace:%d\n", |
4fa086b9 LSL |
372 | stream, |
373 | stream->src.x, | |
374 | stream->src.y, | |
375 | stream->src.width, | |
376 | stream->src.height, | |
377 | stream->dst.x, | |
378 | stream->dst.y, | |
379 | stream->dst.width, | |
380 | stream->dst.height, | |
381 | stream->output_color_space); | |
ab2541b6 AC |
382 | dm_logger_write(dm_logger, |
383 | log_type, | |
4b679bc3 | 384 | "\tpix_clk_khz: %d, h_total: %d, v_total: %d, pixelencoder:%d, displaycolorDepth:%d\n", |
4fa086b9 LSL |
385 | stream->timing.pix_clk_khz, |
386 | stream->timing.h_total, | |
387 | stream->timing.v_total, | |
388 | stream->timing.pixel_encoding, | |
389 | stream->timing.display_color_depth); | |
ab2541b6 AC |
390 | dm_logger_write(dm_logger, |
391 | log_type, | |
392 | "\tsink name: %s, serial: %d\n", | |
4fa086b9 LSL |
393 | stream->sink->edid_caps.display_name, |
394 | stream->sink->edid_caps.serial_number); | |
ab2541b6 AC |
395 | dm_logger_write(dm_logger, |
396 | log_type, | |
397 | "\tlink: %d\n", | |
4fa086b9 | 398 | stream->sink->link->link_index); |
ab2541b6 | 399 | } |