2 * Copyright 2012-13 Advanced Micro Devices, Inc.
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:
11 * The above copyright notice and this permission notice shall be included in
12 * all copies or substantial portions of the Software.
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.
26 #include <linux/types.h>
27 #include <linux/version.h>
30 #include <drm/drm_atomic_helper.h>
31 #include <drm/drm_fb_helper.h>
32 #include <drm/drm_atomic.h>
33 #include <drm/drm_edid.h>
36 #include "amdgpu_pm.h"
37 #include "dm_services_types.h"
39 // We need to #undef FRAME_SIZE and DEPRECATED because they conflict
40 // with ptrace-abi.h's #define's of them.
46 #include "amdgpu_dm_types.h"
47 #include "amdgpu_dm_mst_types.h"
49 #include "modules/inc/mod_freesync.h"
51 struct dm_connector_state
{
52 struct drm_connector_state base
;
54 enum amdgpu_rmx_type scaling
;
55 uint8_t underscan_vborder
;
56 uint8_t underscan_hborder
;
57 bool underscan_enable
;
60 #define to_dm_connector_state(x)\
61 container_of((x), struct dm_connector_state, base)
64 void amdgpu_dm_encoder_destroy(struct drm_encoder
*encoder
)
66 drm_encoder_cleanup(encoder
);
70 static const struct drm_encoder_funcs amdgpu_dm_encoder_funcs
= {
71 .destroy
= amdgpu_dm_encoder_destroy
,
74 static void dm_set_cursor(
75 struct amdgpu_crtc
*amdgpu_crtc
,
80 struct dc_cursor_attributes attributes
;
81 struct dc_cursor_position position
;
82 struct drm_crtc
*crtc
= &amdgpu_crtc
->base
;
84 int xorigin
= 0, yorigin
= 0;
86 amdgpu_crtc
->cursor_width
= width
;
87 amdgpu_crtc
->cursor_height
= height
;
89 attributes
.address
.high_part
= upper_32_bits(gpu_addr
);
90 attributes
.address
.low_part
= lower_32_bits(gpu_addr
);
91 attributes
.width
= width
;
92 attributes
.height
= height
;
95 attributes
.color_format
= CURSOR_MODE_COLOR_PRE_MULTIPLIED_ALPHA
;
96 attributes
.rotation_angle
= 0;
97 attributes
.attribute_flags
.value
= 0;
99 x
= amdgpu_crtc
->cursor_x
;
100 y
= amdgpu_crtc
->cursor_y
;
102 /* avivo cursor are offset into the total surface */
103 x
+= crtc
->primary
->state
->src_x
>> 16;
104 y
+= crtc
->primary
->state
->src_y
>> 16;
107 xorigin
= min(-x
, amdgpu_crtc
->max_cursor_width
- 1);
111 yorigin
= min(-y
, amdgpu_crtc
->max_cursor_height
- 1);
115 position
.enable
= true;
119 position
.hot_spot_enable
= true;
120 position
.x_hotspot
= xorigin
;
121 position
.y_hotspot
= yorigin
;
123 if (!dc_stream_set_cursor_attributes(
126 DRM_ERROR("DC failed to set cursor attributes\n");
129 if (!dc_stream_set_cursor_position(
132 DRM_ERROR("DC failed to set cursor position\n");
136 static int dm_crtc_unpin_cursor_bo_old(
137 struct amdgpu_crtc
*amdgpu_crtc
)
139 struct amdgpu_bo
*robj
;
142 if (NULL
!= amdgpu_crtc
&& NULL
!= amdgpu_crtc
->cursor_bo
) {
143 robj
= gem_to_amdgpu_bo(amdgpu_crtc
->cursor_bo
);
145 ret
= amdgpu_bo_reserve(robj
, false);
147 if (likely(ret
== 0)) {
148 ret
= amdgpu_bo_unpin(robj
);
150 if (unlikely(ret
!= 0)) {
152 "%s: unpin failed (ret=%d), bo %p\n",
155 amdgpu_crtc
->cursor_bo
);
158 amdgpu_bo_unreserve(robj
);
161 "%s: reserve failed (ret=%d), bo %p\n",
164 amdgpu_crtc
->cursor_bo
);
167 drm_gem_object_unreference_unlocked(amdgpu_crtc
->cursor_bo
);
168 amdgpu_crtc
->cursor_bo
= NULL
;
174 static int dm_crtc_pin_cursor_bo_new(
175 struct drm_crtc
*crtc
,
176 struct drm_file
*file_priv
,
178 struct amdgpu_bo
**ret_obj
)
180 struct amdgpu_crtc
*amdgpu_crtc
;
181 struct amdgpu_bo
*robj
;
182 struct drm_gem_object
*obj
;
186 struct drm_device
*dev
= crtc
->dev
;
187 struct amdgpu_device
*adev
= dev
->dev_private
;
190 amdgpu_crtc
= to_amdgpu_crtc(crtc
);
192 obj
= drm_gem_object_lookup(file_priv
, handle
);
196 "Cannot find cursor object %x for crtc %d\n",
198 amdgpu_crtc
->crtc_id
);
201 robj
= gem_to_amdgpu_bo(obj
);
203 ret
= amdgpu_bo_reserve(robj
, false);
205 if (unlikely(ret
!= 0)) {
206 drm_gem_object_unreference_unlocked(obj
);
207 DRM_ERROR("dm_crtc_pin_cursor_bo_new ret %x, handle %x\n",
212 ret
= amdgpu_bo_pin_restricted(robj
, AMDGPU_GEM_DOMAIN_VRAM
, 0,
213 adev
->mc
.visible_vram_size
,
217 amdgpu_crtc
->cursor_addr
= gpu_addr
;
220 amdgpu_bo_unreserve(robj
);
222 drm_gem_object_unreference_unlocked(obj
);
230 static int dm_crtc_cursor_set(
231 struct drm_crtc
*crtc
,
232 struct drm_file
*file_priv
,
237 struct amdgpu_bo
*new_cursor_bo
;
238 struct dc_cursor_position position
;
242 struct amdgpu_crtc
*amdgpu_crtc
= to_amdgpu_crtc(crtc
);
245 new_cursor_bo
= NULL
;
248 "%s: crtc_id=%d with handle %d and size %d to %d, bo_object %p\n",
250 amdgpu_crtc
->crtc_id
,
254 amdgpu_crtc
->cursor_bo
);
257 /* turn off cursor */
258 position
.enable
= false;
261 position
.hot_spot_enable
= false;
263 if (amdgpu_crtc
->stream
) {
264 /*set cursor visible false*/
265 dc_stream_set_cursor_position(
269 /*unpin old cursor buffer and update cache*/
270 ret
= dm_crtc_unpin_cursor_bo_old(amdgpu_crtc
);
275 if ((width
> amdgpu_crtc
->max_cursor_width
) ||
276 (height
> amdgpu_crtc
->max_cursor_height
)) {
278 "%s: bad cursor width or height %d x %d\n",
284 /*try to pin new cursor bo*/
285 ret
= dm_crtc_pin_cursor_bo_new(crtc
, file_priv
, handle
, &new_cursor_bo
);
286 /*if map not successful then return an error*/
290 /*program new cursor bo to hardware*/
291 dm_set_cursor(amdgpu_crtc
, amdgpu_crtc
->cursor_addr
, width
, height
);
293 /*un map old, not used anymore cursor bo ,
294 * return memory and mapping back */
295 dm_crtc_unpin_cursor_bo_old(amdgpu_crtc
);
297 /*assign new cursor bo to our internal cache*/
298 amdgpu_crtc
->cursor_bo
= &new_cursor_bo
->gem_base
;
305 static int dm_crtc_cursor_move(struct drm_crtc
*crtc
,
308 struct amdgpu_crtc
*amdgpu_crtc
= to_amdgpu_crtc(crtc
);
309 int xorigin
= 0, yorigin
= 0;
310 struct dc_cursor_position position
;
312 amdgpu_crtc
->cursor_x
= x
;
313 amdgpu_crtc
->cursor_y
= y
;
315 /* avivo cursor are offset into the total surface */
316 x
+= crtc
->primary
->state
->src_x
>> 16;
317 y
+= crtc
->primary
->state
->src_y
>> 16;
320 * TODO: for cursor debugging unguard the following
324 "%s: x %d y %d c->x %d c->y %d\n",
333 xorigin
= min(-x
, amdgpu_crtc
->max_cursor_width
- 1);
337 yorigin
= min(-y
, amdgpu_crtc
->max_cursor_height
- 1);
341 position
.enable
= true;
345 position
.hot_spot_enable
= true;
346 position
.x_hotspot
= xorigin
;
347 position
.y_hotspot
= yorigin
;
349 if (amdgpu_crtc
->stream
) {
350 if (!dc_stream_set_cursor_position(
353 DRM_ERROR("DC failed to set cursor position\n");
361 static void dm_crtc_cursor_reset(struct drm_crtc
*crtc
)
363 struct amdgpu_crtc
*amdgpu_crtc
= to_amdgpu_crtc(crtc
);
366 "%s: with cursor_bo %p\n",
368 amdgpu_crtc
->cursor_bo
);
370 if (amdgpu_crtc
->cursor_bo
&& amdgpu_crtc
->stream
) {
373 amdgpu_crtc
->cursor_addr
,
374 amdgpu_crtc
->cursor_width
,
375 amdgpu_crtc
->cursor_height
);
378 static bool fill_rects_from_plane_state(
379 const struct drm_plane_state
*state
,
380 struct dc_surface
*surface
)
382 surface
->src_rect
.x
= state
->src_x
>> 16;
383 surface
->src_rect
.y
= state
->src_y
>> 16;
384 /*we ignore for now mantissa and do not to deal with floating pixels :(*/
385 surface
->src_rect
.width
= state
->src_w
>> 16;
387 if (surface
->src_rect
.width
== 0)
390 surface
->src_rect
.height
= state
->src_h
>> 16;
391 if (surface
->src_rect
.height
== 0)
394 surface
->dst_rect
.x
= state
->crtc_x
;
395 surface
->dst_rect
.y
= state
->crtc_y
;
397 if (state
->crtc_w
== 0)
400 surface
->dst_rect
.width
= state
->crtc_w
;
402 if (state
->crtc_h
== 0)
405 surface
->dst_rect
.height
= state
->crtc_h
;
407 surface
->clip_rect
= surface
->dst_rect
;
409 switch (state
->rotation
& DRM_MODE_ROTATE_MASK
) {
410 case DRM_MODE_ROTATE_0
:
411 surface
->rotation
= ROTATION_ANGLE_0
;
413 case DRM_MODE_ROTATE_90
:
414 surface
->rotation
= ROTATION_ANGLE_90
;
416 case DRM_MODE_ROTATE_180
:
417 surface
->rotation
= ROTATION_ANGLE_180
;
419 case DRM_MODE_ROTATE_270
:
420 surface
->rotation
= ROTATION_ANGLE_270
;
423 surface
->rotation
= ROTATION_ANGLE_0
;
429 static bool get_fb_info(
430 const struct amdgpu_framebuffer
*amdgpu_fb
,
431 uint64_t *tiling_flags
,
432 uint64_t *fb_location
)
434 struct amdgpu_bo
*rbo
= gem_to_amdgpu_bo(amdgpu_fb
->obj
);
435 int r
= amdgpu_bo_reserve(rbo
, false);
436 if (unlikely(r
!= 0)){
437 DRM_ERROR("Unable to reserve buffer\n");
442 *fb_location
= amdgpu_bo_gpu_offset(rbo
);
445 amdgpu_bo_get_tiling_flags(rbo
, tiling_flags
);
447 amdgpu_bo_unreserve(rbo
);
451 static void fill_plane_attributes_from_fb(
452 struct amdgpu_device
*adev
,
453 struct dc_surface
*surface
,
454 const struct amdgpu_framebuffer
*amdgpu_fb
, bool addReq
)
456 uint64_t tiling_flags
;
457 uint64_t fb_location
= 0;
458 const struct drm_framebuffer
*fb
= &amdgpu_fb
->base
;
459 struct drm_format_name_buf format_name
;
464 addReq
== true ? &fb_location
:NULL
);
466 surface
->address
.type
= PLN_ADDR_TYPE_GRAPHICS
;
467 surface
->address
.grph
.addr
.low_part
= lower_32_bits(fb_location
);
468 surface
->address
.grph
.addr
.high_part
= upper_32_bits(fb_location
);
470 switch (fb
->format
->format
) {
472 surface
->format
= SURFACE_PIXEL_FORMAT_GRPH_PALETA_256_COLORS
;
474 case DRM_FORMAT_RGB565
:
475 surface
->format
= SURFACE_PIXEL_FORMAT_GRPH_RGB565
;
477 case DRM_FORMAT_XRGB8888
:
478 case DRM_FORMAT_ARGB8888
:
479 surface
->format
= SURFACE_PIXEL_FORMAT_GRPH_ARGB8888
;
481 case DRM_FORMAT_XRGB2101010
:
482 case DRM_FORMAT_ARGB2101010
:
483 surface
->format
= SURFACE_PIXEL_FORMAT_GRPH_ARGB2101010
;
485 case DRM_FORMAT_XBGR2101010
:
486 case DRM_FORMAT_ABGR2101010
:
487 surface
->format
= SURFACE_PIXEL_FORMAT_GRPH_ABGR2101010
;
490 DRM_ERROR("Unsupported screen format %s\n",
491 drm_get_format_name(fb
->format
->format
, &format_name
));
495 memset(&surface
->tiling_info
, 0, sizeof(surface
->tiling_info
));
497 /* Fill GFX8 params */
498 if (AMDGPU_TILING_GET(tiling_flags
, ARRAY_MODE
) == DC_ARRAY_2D_TILED_THIN1
)
500 unsigned bankw
, bankh
, mtaspect
, tile_split
, num_banks
;
502 bankw
= AMDGPU_TILING_GET(tiling_flags
, BANK_WIDTH
);
503 bankh
= AMDGPU_TILING_GET(tiling_flags
, BANK_HEIGHT
);
504 mtaspect
= AMDGPU_TILING_GET(tiling_flags
, MACRO_TILE_ASPECT
);
505 tile_split
= AMDGPU_TILING_GET(tiling_flags
, TILE_SPLIT
);
506 num_banks
= AMDGPU_TILING_GET(tiling_flags
, NUM_BANKS
);
508 /* XXX fix me for VI */
509 surface
->tiling_info
.gfx8
.num_banks
= num_banks
;
510 surface
->tiling_info
.gfx8
.array_mode
=
511 DC_ARRAY_2D_TILED_THIN1
;
512 surface
->tiling_info
.gfx8
.tile_split
= tile_split
;
513 surface
->tiling_info
.gfx8
.bank_width
= bankw
;
514 surface
->tiling_info
.gfx8
.bank_height
= bankh
;
515 surface
->tiling_info
.gfx8
.tile_aspect
= mtaspect
;
516 surface
->tiling_info
.gfx8
.tile_mode
=
517 DC_ADDR_SURF_MICRO_TILING_DISPLAY
;
518 } else if (AMDGPU_TILING_GET(tiling_flags
, ARRAY_MODE
)
519 == DC_ARRAY_1D_TILED_THIN1
) {
520 surface
->tiling_info
.gfx8
.array_mode
= DC_ARRAY_1D_TILED_THIN1
;
523 surface
->tiling_info
.gfx8
.pipe_config
=
524 AMDGPU_TILING_GET(tiling_flags
, PIPE_CONFIG
);
526 surface
->plane_size
.grph
.surface_size
.x
= 0;
527 surface
->plane_size
.grph
.surface_size
.y
= 0;
528 surface
->plane_size
.grph
.surface_size
.width
= fb
->width
;
529 surface
->plane_size
.grph
.surface_size
.height
= fb
->height
;
530 surface
->plane_size
.grph
.surface_pitch
=
531 fb
->pitches
[0] / fb
->format
->cpp
[0];
533 surface
->visible
= true;
534 surface
->scaling_quality
.h_taps_c
= 0;
535 surface
->scaling_quality
.v_taps_c
= 0;
537 /* TODO: unhardcode */
538 surface
->color_space
= COLOR_SPACE_SRGB
;
539 /* is this needed? is surface zeroed at allocation? */
540 surface
->scaling_quality
.h_taps
= 0;
541 surface
->scaling_quality
.v_taps
= 0;
542 surface
->stereo_format
= PLANE_STEREO_FORMAT_NONE
;
546 #define NUM_OF_RAW_GAMMA_RAMP_RGB_256 256
548 static void fill_gamma_from_crtc(
549 const struct drm_crtc
*crtc
,
550 struct dc_surface
*dc_surface
)
553 struct dc_gamma
*gamma
;
554 struct drm_crtc_state
*state
= crtc
->state
;
555 struct drm_color_lut
*lut
= (struct drm_color_lut
*) state
->gamma_lut
->data
;
557 gamma
= dc_create_gamma();
562 for (i
= 0; i
< NUM_OF_RAW_GAMMA_RAMP_RGB_256
; i
++) {
563 gamma
->red
[i
] = lut
[i
].red
;
564 gamma
->green
[i
] = lut
[i
].green
;
565 gamma
->blue
[i
] = lut
[i
].blue
;
568 dc_surface
->gamma_correction
= gamma
;
571 static void fill_plane_attributes(
572 struct amdgpu_device
*adev
,
573 struct dc_surface
*surface
,
574 struct drm_plane_state
*state
, bool addrReq
)
576 const struct amdgpu_framebuffer
*amdgpu_fb
=
577 to_amdgpu_framebuffer(state
->fb
);
578 const struct drm_crtc
*crtc
= state
->crtc
;
579 struct dc_transfer_func
*input_tf
;
581 fill_rects_from_plane_state(state
, surface
);
582 fill_plane_attributes_from_fb(
583 crtc
->dev
->dev_private
,
588 input_tf
= dc_create_transfer_func();
590 if (input_tf
== NULL
)
593 input_tf
->type
= TF_TYPE_PREDEFINED
;
594 input_tf
->tf
= TRANSFER_FUNCTION_SRGB
;
596 surface
->in_transfer_func
= input_tf
;
598 /* In case of gamma set, update gamma value */
599 if (state
->crtc
->state
->gamma_lut
) {
600 fill_gamma_from_crtc(crtc
, surface
);
604 /*****************************************************************************/
606 struct amdgpu_connector
*aconnector_from_drm_crtc_id(
607 const struct drm_crtc
*crtc
)
609 struct drm_device
*dev
= crtc
->dev
;
610 struct drm_connector
*connector
;
611 struct amdgpu_crtc
*acrtc
= to_amdgpu_crtc(crtc
);
612 struct amdgpu_connector
*aconnector
;
614 list_for_each_entry(connector
,
615 &dev
->mode_config
.connector_list
, head
) {
617 aconnector
= to_amdgpu_connector(connector
);
619 if (aconnector
->base
.state
->crtc
!= &acrtc
->base
)
622 /* Found the connector */
626 /* If we get here, not found. */
630 static void update_stream_scaling_settings(
631 const struct drm_display_mode
*mode
,
632 const struct dm_connector_state
*dm_state
,
633 const struct dc_stream
*stream
)
635 struct amdgpu_device
*adev
= dm_state
->base
.crtc
->dev
->dev_private
;
636 enum amdgpu_rmx_type rmx_type
;
638 struct rect src
= { 0 }; /* viewport in composition space*/
639 struct rect dst
= { 0 }; /* stream addressable area */
641 /* Full screen scaling by default */
642 src
.width
= mode
->hdisplay
;
643 src
.height
= mode
->vdisplay
;
644 dst
.width
= stream
->timing
.h_addressable
;
645 dst
.height
= stream
->timing
.v_addressable
;
647 rmx_type
= dm_state
->scaling
;
648 if (rmx_type
== RMX_ASPECT
|| rmx_type
== RMX_OFF
) {
649 if (src
.width
* dst
.height
<
650 src
.height
* dst
.width
) {
651 /* height needs less upscaling/more downscaling */
652 dst
.width
= src
.width
*
653 dst
.height
/ src
.height
;
655 /* width needs less upscaling/more downscaling */
656 dst
.height
= src
.height
*
657 dst
.width
/ src
.width
;
659 } else if (rmx_type
== RMX_CENTER
) {
663 dst
.x
= (stream
->timing
.h_addressable
- dst
.width
) / 2;
664 dst
.y
= (stream
->timing
.v_addressable
- dst
.height
) / 2;
666 if (dm_state
->underscan_enable
) {
667 dst
.x
+= dm_state
->underscan_hborder
/ 2;
668 dst
.y
+= dm_state
->underscan_vborder
/ 2;
669 dst
.width
-= dm_state
->underscan_hborder
;
670 dst
.height
-= dm_state
->underscan_vborder
;
673 adev
->dm
.dc
->stream_funcs
.stream_update_scaling(adev
->dm
.dc
, stream
, &src
, &dst
);
675 DRM_DEBUG_KMS("Destination Rectangle x:%d y:%d width:%d height:%d\n",
676 dst
.x
, dst
.y
, dst
.width
, dst
.height
);
680 static void dm_dc_surface_commit(
682 struct drm_crtc
*crtc
)
684 struct dc_surface
*dc_surface
;
685 const struct dc_surface
*dc_surfaces
[1];
686 const struct amdgpu_crtc
*acrtc
= to_amdgpu_crtc(crtc
);
687 const struct dc_stream
*dc_stream
= acrtc
->stream
;
691 "%s: Failed to obtain stream on crtc (%d)!\n",
697 dc_surface
= dc_create_surface(dc
);
701 "%s: Failed to create a surface!\n",
706 /* Surface programming */
707 fill_plane_attributes(
708 crtc
->dev
->dev_private
,
710 crtc
->primary
->state
,
713 dc_surfaces
[0] = dc_surface
;
715 if (false == dc_commit_surfaces_to_stream(
721 "%s: Failed to attach surface!\n",
725 dc_surface_release(dc_surface
);
730 static enum dc_color_depth
convert_color_depth_from_display_info(
731 const struct drm_connector
*connector
)
733 uint32_t bpc
= connector
->display_info
.bpc
;
735 /* Limited color depth to 8bit
736 * TODO: Still need to handle deep color*/
742 /* Temporary Work around, DRM don't parse color depth for
743 * EDID revision before 1.4
744 * TODO: Fix edid parsing
746 return COLOR_DEPTH_888
;
748 return COLOR_DEPTH_666
;
750 return COLOR_DEPTH_888
;
752 return COLOR_DEPTH_101010
;
754 return COLOR_DEPTH_121212
;
756 return COLOR_DEPTH_141414
;
758 return COLOR_DEPTH_161616
;
760 return COLOR_DEPTH_UNDEFINED
;
764 static enum dc_aspect_ratio
get_aspect_ratio(
765 const struct drm_display_mode
*mode_in
)
767 int32_t width
= mode_in
->crtc_hdisplay
* 9;
768 int32_t height
= mode_in
->crtc_vdisplay
* 16;
769 if ((width
- height
) < 10 && (width
- height
) > -10)
770 return ASPECT_RATIO_16_9
;
772 return ASPECT_RATIO_4_3
;
775 static enum dc_color_space
get_output_color_space(
776 const struct dc_crtc_timing
*dc_crtc_timing
)
778 enum dc_color_space color_space
= COLOR_SPACE_SRGB
;
780 switch (dc_crtc_timing
->pixel_encoding
) {
781 case PIXEL_ENCODING_YCBCR422
:
782 case PIXEL_ENCODING_YCBCR444
:
783 case PIXEL_ENCODING_YCBCR420
:
786 * 27030khz is the separation point between HDTV and SDTV
787 * according to HDMI spec, we use YCbCr709 and YCbCr601
790 if (dc_crtc_timing
->pix_clk_khz
> 27030) {
791 if (dc_crtc_timing
->flags
.Y_ONLY
)
793 COLOR_SPACE_YCBCR709_LIMITED
;
795 color_space
= COLOR_SPACE_YCBCR709
;
797 if (dc_crtc_timing
->flags
.Y_ONLY
)
799 COLOR_SPACE_YCBCR601_LIMITED
;
801 color_space
= COLOR_SPACE_YCBCR601
;
806 case PIXEL_ENCODING_RGB
:
807 color_space
= COLOR_SPACE_SRGB
;
818 /*****************************************************************************/
820 static void fill_stream_properties_from_drm_display_mode(
821 struct dc_stream
*stream
,
822 const struct drm_display_mode
*mode_in
,
823 const struct drm_connector
*connector
)
825 struct dc_crtc_timing
*timing_out
= &stream
->timing
;
826 memset(timing_out
, 0, sizeof(struct dc_crtc_timing
));
828 timing_out
->h_border_left
= 0;
829 timing_out
->h_border_right
= 0;
830 timing_out
->v_border_top
= 0;
831 timing_out
->v_border_bottom
= 0;
832 /* TODO: un-hardcode */
834 if ((connector
->display_info
.color_formats
& DRM_COLOR_FORMAT_YCRCB444
)
835 && stream
->sink
->sink_signal
== SIGNAL_TYPE_HDMI_TYPE_A
)
836 timing_out
->pixel_encoding
= PIXEL_ENCODING_YCBCR444
;
838 timing_out
->pixel_encoding
= PIXEL_ENCODING_RGB
;
840 timing_out
->timing_3d_format
= TIMING_3D_FORMAT_NONE
;
841 timing_out
->display_color_depth
= convert_color_depth_from_display_info(
843 timing_out
->scan_type
= SCANNING_TYPE_NODATA
;
844 timing_out
->hdmi_vic
= 0;
845 timing_out
->vic
= drm_match_cea_mode(mode_in
);
847 timing_out
->h_addressable
= mode_in
->crtc_hdisplay
;
848 timing_out
->h_total
= mode_in
->crtc_htotal
;
849 timing_out
->h_sync_width
=
850 mode_in
->crtc_hsync_end
- mode_in
->crtc_hsync_start
;
851 timing_out
->h_front_porch
=
852 mode_in
->crtc_hsync_start
- mode_in
->crtc_hdisplay
;
853 timing_out
->v_total
= mode_in
->crtc_vtotal
;
854 timing_out
->v_addressable
= mode_in
->crtc_vdisplay
;
855 timing_out
->v_front_porch
=
856 mode_in
->crtc_vsync_start
- mode_in
->crtc_vdisplay
;
857 timing_out
->v_sync_width
=
858 mode_in
->crtc_vsync_end
- mode_in
->crtc_vsync_start
;
859 timing_out
->pix_clk_khz
= mode_in
->crtc_clock
;
860 timing_out
->aspect_ratio
= get_aspect_ratio(mode_in
);
861 if (mode_in
->flags
& DRM_MODE_FLAG_PHSYNC
)
862 timing_out
->flags
.HSYNC_POSITIVE_POLARITY
= 1;
863 if (mode_in
->flags
& DRM_MODE_FLAG_PVSYNC
)
864 timing_out
->flags
.VSYNC_POSITIVE_POLARITY
= 1;
866 stream
->output_color_space
= get_output_color_space(timing_out
);
869 struct dc_transfer_func
*tf
= dc_create_transfer_func();
870 tf
->type
= TF_TYPE_PREDEFINED
;
871 tf
->tf
= TRANSFER_FUNCTION_SRGB
;
872 stream
->out_transfer_func
= tf
;
876 static void fill_audio_info(
877 struct audio_info
*audio_info
,
878 const struct drm_connector
*drm_connector
,
879 const struct dc_sink
*dc_sink
)
882 int cea_revision
= 0;
883 const struct dc_edid_caps
*edid_caps
= &dc_sink
->edid_caps
;
885 audio_info
->manufacture_id
= edid_caps
->manufacturer_id
;
886 audio_info
->product_id
= edid_caps
->product_id
;
888 cea_revision
= drm_connector
->display_info
.cea_rev
;
890 while (i
< AUDIO_INFO_DISPLAY_NAME_SIZE_IN_CHARS
&&
891 edid_caps
->display_name
[i
]) {
892 audio_info
->display_name
[i
] = edid_caps
->display_name
[i
];
896 if(cea_revision
>= 3) {
897 audio_info
->mode_count
= edid_caps
->audio_mode_count
;
899 for (i
= 0; i
< audio_info
->mode_count
; ++i
) {
900 audio_info
->modes
[i
].format_code
=
901 (enum audio_format_code
)
902 (edid_caps
->audio_modes
[i
].format_code
);
903 audio_info
->modes
[i
].channel_count
=
904 edid_caps
->audio_modes
[i
].channel_count
;
905 audio_info
->modes
[i
].sample_rates
.all
=
906 edid_caps
->audio_modes
[i
].sample_rate
;
907 audio_info
->modes
[i
].sample_size
=
908 edid_caps
->audio_modes
[i
].sample_size
;
912 audio_info
->flags
.all
= edid_caps
->speaker_flags
;
914 /* TODO: We only check for the progressive mode, check for interlace mode too */
915 if(drm_connector
->latency_present
[0]) {
916 audio_info
->video_latency
= drm_connector
->video_latency
[0];
917 audio_info
->audio_latency
= drm_connector
->audio_latency
[0];
920 /* TODO: For DP, video and audio latency should be calculated from DPCD caps */
924 static void copy_crtc_timing_for_drm_display_mode(
925 const struct drm_display_mode
*src_mode
,
926 struct drm_display_mode
*dst_mode
)
928 dst_mode
->crtc_hdisplay
= src_mode
->crtc_hdisplay
;
929 dst_mode
->crtc_vdisplay
= src_mode
->crtc_vdisplay
;
930 dst_mode
->crtc_clock
= src_mode
->crtc_clock
;
931 dst_mode
->crtc_hblank_start
= src_mode
->crtc_hblank_start
;
932 dst_mode
->crtc_hblank_end
= src_mode
->crtc_hblank_end
;
933 dst_mode
->crtc_hsync_start
= src_mode
->crtc_hsync_start
;
934 dst_mode
->crtc_hsync_end
= src_mode
->crtc_hsync_end
;
935 dst_mode
->crtc_htotal
= src_mode
->crtc_htotal
;
936 dst_mode
->crtc_hskew
= src_mode
->crtc_hskew
;
937 dst_mode
->crtc_vblank_start
= src_mode
->crtc_vblank_start
;;
938 dst_mode
->crtc_vblank_end
= src_mode
->crtc_vblank_end
;;
939 dst_mode
->crtc_vsync_start
= src_mode
->crtc_vsync_start
;;
940 dst_mode
->crtc_vsync_end
= src_mode
->crtc_vsync_end
;;
941 dst_mode
->crtc_vtotal
= src_mode
->crtc_vtotal
;;
944 static void decide_crtc_timing_for_drm_display_mode(
945 struct drm_display_mode
*drm_mode
,
946 const struct drm_display_mode
*native_mode
,
950 copy_crtc_timing_for_drm_display_mode(native_mode
, drm_mode
);
951 } else if (native_mode
->clock
== drm_mode
->clock
&&
952 native_mode
->htotal
== drm_mode
->htotal
&&
953 native_mode
->vtotal
== drm_mode
->vtotal
) {
954 copy_crtc_timing_for_drm_display_mode(native_mode
, drm_mode
);
956 /* no scaling nor amdgpu inserted, no need to patch */
960 static struct dc_stream
*create_stream_for_sink(
961 const struct amdgpu_connector
*aconnector
,
962 const struct drm_display_mode
*drm_mode
,
963 const struct dm_connector_state
*dm_state
)
965 struct drm_display_mode
*preferred_mode
= NULL
;
966 const struct drm_connector
*drm_connector
;
967 struct dc_stream
*stream
= NULL
;
968 struct drm_display_mode mode
= *drm_mode
;
969 bool native_mode_found
= false;
971 if (NULL
== aconnector
) {
972 DRM_ERROR("aconnector is NULL!\n");
973 goto drm_connector_null
;
976 if (NULL
== dm_state
) {
977 DRM_ERROR("dm_state is NULL!\n");
981 drm_connector
= &aconnector
->base
;
982 stream
= dc_create_stream_for_sink(aconnector
->dc_sink
);
984 if (NULL
== stream
) {
985 DRM_ERROR("Failed to create stream for sink!\n");
986 goto stream_create_fail
;
989 list_for_each_entry(preferred_mode
, &aconnector
->base
.modes
, head
) {
990 /* Search for preferred mode */
991 if (preferred_mode
->type
& DRM_MODE_TYPE_PREFERRED
) {
992 native_mode_found
= true;
996 if (!native_mode_found
)
997 preferred_mode
= list_first_entry_or_null(
998 &aconnector
->base
.modes
,
999 struct drm_display_mode
,
1002 if (NULL
== preferred_mode
) {
1003 /* This may not be an error, the use case is when we we have no
1004 * usermode calls to reset and set mode upon hotplug. In this
1005 * case, we call set mode ourselves to restore the previous mode
1006 * and the modelist may not be filled in in time.
1008 DRM_INFO("No preferred mode found\n");
1010 decide_crtc_timing_for_drm_display_mode(
1011 &mode
, preferred_mode
,
1012 dm_state
->scaling
!= RMX_OFF
);
1015 fill_stream_properties_from_drm_display_mode(stream
,
1016 &mode
, &aconnector
->base
);
1017 update_stream_scaling_settings(&mode
, dm_state
, stream
);
1020 &stream
->audio_info
,
1022 aconnector
->dc_sink
);
1030 void amdgpu_dm_crtc_destroy(struct drm_crtc
*crtc
)
1032 drm_crtc_cleanup(crtc
);
1036 /* Implemented only the options currently availible for the driver */
1037 static const struct drm_crtc_funcs amdgpu_dm_crtc_funcs
= {
1038 .reset
= drm_atomic_helper_crtc_reset
,
1039 .cursor_set
= dm_crtc_cursor_set
,
1040 .cursor_move
= dm_crtc_cursor_move
,
1041 .destroy
= amdgpu_dm_crtc_destroy
,
1042 .gamma_set
= drm_atomic_helper_legacy_gamma_set
,
1043 .set_config
= drm_atomic_helper_set_config
,
1044 .page_flip
= drm_atomic_helper_page_flip
,
1045 .atomic_duplicate_state
= drm_atomic_helper_crtc_duplicate_state
,
1046 .atomic_destroy_state
= drm_atomic_helper_crtc_destroy_state
,
1049 static enum drm_connector_status
1050 amdgpu_dm_connector_detect(struct drm_connector
*connector
, bool force
)
1053 struct amdgpu_connector
*aconnector
= to_amdgpu_connector(connector
);
1056 * 1. This interface is NOT called in context of HPD irq.
1057 * 2. This interface *is called* in context of user-mode ioctl. Which
1058 * makes it a bad place for *any* MST-related activit. */
1060 if (aconnector
->base
.force
== DRM_FORCE_UNSPECIFIED
)
1061 connected
= (aconnector
->dc_sink
!= NULL
);
1063 connected
= (aconnector
->base
.force
== DRM_FORCE_ON
);
1065 return (connected
? connector_status_connected
:
1066 connector_status_disconnected
);
1069 int amdgpu_dm_connector_atomic_set_property(
1070 struct drm_connector
*connector
,
1071 struct drm_connector_state
*connector_state
,
1072 struct drm_property
*property
,
1075 struct drm_device
*dev
= connector
->dev
;
1076 struct amdgpu_device
*adev
= dev
->dev_private
;
1077 struct dm_connector_state
*dm_old_state
=
1078 to_dm_connector_state(connector
->state
);
1079 struct dm_connector_state
*dm_new_state
=
1080 to_dm_connector_state(connector_state
);
1082 struct drm_crtc_state
*new_crtc_state
;
1083 struct drm_crtc
*crtc
;
1087 if (property
== dev
->mode_config
.scaling_mode_property
) {
1088 enum amdgpu_rmx_type rmx_type
;
1091 case DRM_MODE_SCALE_CENTER
:
1092 rmx_type
= RMX_CENTER
;
1094 case DRM_MODE_SCALE_ASPECT
:
1095 rmx_type
= RMX_ASPECT
;
1097 case DRM_MODE_SCALE_FULLSCREEN
:
1098 rmx_type
= RMX_FULL
;
1100 case DRM_MODE_SCALE_NONE
:
1106 if (dm_old_state
->scaling
== rmx_type
)
1109 dm_new_state
->scaling
= rmx_type
;
1111 } else if (property
== adev
->mode_info
.underscan_hborder_property
) {
1112 dm_new_state
->underscan_hborder
= val
;
1114 } else if (property
== adev
->mode_info
.underscan_vborder_property
) {
1115 dm_new_state
->underscan_vborder
= val
;
1117 } else if (property
== adev
->mode_info
.underscan_property
) {
1118 dm_new_state
->underscan_enable
= val
;
1122 for_each_crtc_in_state(
1123 connector_state
->state
,
1128 if (crtc
== connector_state
->crtc
) {
1129 struct drm_plane_state
*plane_state
;
1132 * Bit of magic done here. We need to ensure
1133 * that planes get update after mode is set.
1134 * So, we need to add primary plane to state,
1135 * and this way atomic_update would be called
1139 drm_atomic_get_plane_state(
1140 connector_state
->state
,
1151 void amdgpu_dm_connector_destroy(struct drm_connector
*connector
)
1153 struct amdgpu_connector
*aconnector
= to_amdgpu_connector(connector
);
1154 const struct dc_link
*link
= aconnector
->dc_link
;
1155 struct amdgpu_device
*adev
= connector
->dev
->dev_private
;
1156 struct amdgpu_display_manager
*dm
= &adev
->dm
;
1157 #if defined(CONFIG_BACKLIGHT_CLASS_DEVICE) ||\
1158 defined(CONFIG_BACKLIGHT_CLASS_DEVICE_MODULE)
1160 if (link
->connector_signal
& (SIGNAL_TYPE_EDP
| SIGNAL_TYPE_LVDS
)) {
1161 amdgpu_dm_register_backlight_device(dm
);
1163 if (dm
->backlight_dev
) {
1164 backlight_device_unregister(dm
->backlight_dev
);
1165 dm
->backlight_dev
= NULL
;
1170 drm_connector_unregister(connector
);
1171 drm_connector_cleanup(connector
);
1175 void amdgpu_dm_connector_funcs_reset(struct drm_connector
*connector
)
1177 struct dm_connector_state
*state
=
1178 to_dm_connector_state(connector
->state
);
1182 state
= kzalloc(sizeof(*state
), GFP_KERNEL
);
1185 state
->scaling
= RMX_OFF
;
1186 state
->underscan_enable
= false;
1187 state
->underscan_hborder
= 0;
1188 state
->underscan_vborder
= 0;
1190 connector
->state
= &state
->base
;
1191 connector
->state
->connector
= connector
;
1195 struct drm_connector_state
*amdgpu_dm_connector_atomic_duplicate_state(
1196 struct drm_connector
*connector
)
1198 struct dm_connector_state
*state
=
1199 to_dm_connector_state(connector
->state
);
1201 struct dm_connector_state
*new_state
=
1202 kmemdup(state
, sizeof(*state
), GFP_KERNEL
);
1205 __drm_atomic_helper_connector_duplicate_state(connector
,
1207 return &new_state
->base
;
1213 static const struct drm_connector_funcs amdgpu_dm_connector_funcs
= {
1214 .reset
= amdgpu_dm_connector_funcs_reset
,
1215 .detect
= amdgpu_dm_connector_detect
,
1216 .fill_modes
= drm_helper_probe_single_connector_modes
,
1217 .destroy
= amdgpu_dm_connector_destroy
,
1218 .atomic_duplicate_state
= amdgpu_dm_connector_atomic_duplicate_state
,
1219 .atomic_destroy_state
= drm_atomic_helper_connector_destroy_state
,
1220 .atomic_set_property
= amdgpu_dm_connector_atomic_set_property
1223 static struct drm_encoder
*best_encoder(struct drm_connector
*connector
)
1225 int enc_id
= connector
->encoder_ids
[0];
1226 struct drm_mode_object
*obj
;
1227 struct drm_encoder
*encoder
;
1229 DRM_DEBUG_KMS("Finding the best encoder\n");
1231 /* pick the encoder ids */
1233 obj
= drm_mode_object_find(connector
->dev
, enc_id
, DRM_MODE_OBJECT_ENCODER
);
1235 DRM_ERROR("Couldn't find a matching encoder for our connector\n");
1238 encoder
= obj_to_encoder(obj
);
1241 DRM_ERROR("No encoder id\n");
1245 static int get_modes(struct drm_connector
*connector
)
1247 return amdgpu_dm_connector_get_modes(connector
);
1250 static void create_eml_sink(struct amdgpu_connector
*aconnector
)
1252 struct dc_sink_init_data init_params
= {
1253 .link
= aconnector
->dc_link
,
1254 .sink_signal
= SIGNAL_TYPE_VIRTUAL
1256 struct edid
*edid
= (struct edid
*) aconnector
->base
.edid_blob_ptr
->data
;
1258 if (!aconnector
->base
.edid_blob_ptr
||
1259 !aconnector
->base
.edid_blob_ptr
->data
) {
1260 DRM_ERROR("No EDID firmware found on connector: %s ,forcing to OFF!\n",
1261 aconnector
->base
.name
);
1263 aconnector
->base
.force
= DRM_FORCE_OFF
;
1264 aconnector
->base
.override_edid
= false;
1268 aconnector
->edid
= edid
;
1270 aconnector
->dc_em_sink
= dc_link_add_remote_sink(
1271 aconnector
->dc_link
,
1273 (edid
->extensions
+ 1) * EDID_LENGTH
,
1276 if (aconnector
->base
.force
1278 aconnector
->dc_sink
= aconnector
->dc_link
->local_sink
?
1279 aconnector
->dc_link
->local_sink
:
1280 aconnector
->dc_em_sink
;
1283 static void handle_edid_mgmt(struct amdgpu_connector
*aconnector
)
1285 struct dc_link
*link
= (struct dc_link
*)aconnector
->dc_link
;
1287 /* In case of headless boot with force on for DP managed connector
1288 * Those settings have to be != 0 to get initial modeset
1290 if (link
->connector_signal
== SIGNAL_TYPE_DISPLAY_PORT
) {
1291 link
->verified_link_cap
.lane_count
= LANE_COUNT_FOUR
;
1292 link
->verified_link_cap
.link_rate
= LINK_RATE_HIGH2
;
1296 aconnector
->base
.override_edid
= true;
1297 create_eml_sink(aconnector
);
1300 int amdgpu_dm_connector_mode_valid(
1301 struct drm_connector
*connector
,
1302 struct drm_display_mode
*mode
)
1304 int result
= MODE_ERROR
;
1305 const struct dc_sink
*dc_sink
;
1306 struct amdgpu_device
*adev
= connector
->dev
->dev_private
;
1307 struct dc_validation_set val_set
= { 0 };
1308 /* TODO: Unhardcode stream count */
1309 struct dc_stream
*stream
;
1310 struct amdgpu_connector
*aconnector
= to_amdgpu_connector(connector
);
1312 if ((mode
->flags
& DRM_MODE_FLAG_INTERLACE
) ||
1313 (mode
->flags
& DRM_MODE_FLAG_DBLSCAN
))
1316 /* Only run this the first time mode_valid is called to initilialize
1319 if (aconnector
->base
.force
!= DRM_FORCE_UNSPECIFIED
&&
1320 !aconnector
->dc_em_sink
)
1321 handle_edid_mgmt(aconnector
);
1323 dc_sink
= to_amdgpu_connector(connector
)->dc_sink
;
1325 if (NULL
== dc_sink
) {
1326 DRM_ERROR("dc_sink is NULL!\n");
1330 stream
= dc_create_stream_for_sink(dc_sink
);
1331 if (NULL
== stream
) {
1332 DRM_ERROR("Failed to create stream for sink!\n");
1333 goto stream_create_fail
;
1336 drm_mode_set_crtcinfo(mode
, 0);
1337 fill_stream_properties_from_drm_display_mode(stream
, mode
, connector
);
1339 val_set
.stream
= stream
;
1340 val_set
.surface_count
= 0;
1341 stream
->src
.width
= mode
->hdisplay
;
1342 stream
->src
.height
= mode
->vdisplay
;
1343 stream
->dst
= stream
->src
;
1345 if (dc_validate_resources(adev
->dm
.dc
, &val_set
, 1))
1348 dc_stream_release(stream
);
1352 /* TODO: error handling*/
1356 static const struct drm_connector_helper_funcs
1357 amdgpu_dm_connector_helper_funcs
= {
1359 * If hotplug a second bigger display in FB Con mode, bigger resolution
1360 * modes will be filtered by drm_mode_validate_size(), and those modes
1361 * is missing after user start lightdm. So we need to renew modes list.
1362 * in get_modes call back, not just return the modes count
1364 .get_modes
= get_modes
,
1365 .mode_valid
= amdgpu_dm_connector_mode_valid
,
1366 .best_encoder
= best_encoder
1369 static void dm_crtc_helper_disable(struct drm_crtc
*crtc
)
1373 static int dm_crtc_helper_atomic_check(
1374 struct drm_crtc
*crtc
,
1375 struct drm_crtc_state
*state
)
1380 static bool dm_crtc_helper_mode_fixup(
1381 struct drm_crtc
*crtc
,
1382 const struct drm_display_mode
*mode
,
1383 struct drm_display_mode
*adjusted_mode
)
1388 static const struct drm_crtc_helper_funcs amdgpu_dm_crtc_helper_funcs
= {
1389 .disable
= dm_crtc_helper_disable
,
1390 .atomic_check
= dm_crtc_helper_atomic_check
,
1391 .mode_fixup
= dm_crtc_helper_mode_fixup
1394 static void dm_encoder_helper_disable(struct drm_encoder
*encoder
)
1399 static int dm_encoder_helper_atomic_check(
1400 struct drm_encoder
*encoder
,
1401 struct drm_crtc_state
*crtc_state
,
1402 struct drm_connector_state
*conn_state
)
1407 const struct drm_encoder_helper_funcs amdgpu_dm_encoder_helper_funcs
= {
1408 .disable
= dm_encoder_helper_disable
,
1409 .atomic_check
= dm_encoder_helper_atomic_check
1412 static const struct drm_plane_funcs dm_plane_funcs
= {
1413 .reset
= drm_atomic_helper_plane_reset
,
1414 .atomic_duplicate_state
= drm_atomic_helper_plane_duplicate_state
,
1415 .atomic_destroy_state
= drm_atomic_helper_plane_destroy_state
1418 static void clear_unrelated_fields(struct drm_plane_state
*state
)
1422 state
->state
= NULL
;
1423 state
->fence
= NULL
;
1426 static bool page_flip_needed(
1427 const struct drm_plane_state
*new_state
,
1428 const struct drm_plane_state
*old_state
,
1429 struct drm_pending_vblank_event
*event
,
1430 bool commit_surface_required
)
1432 struct drm_plane_state old_state_tmp
;
1433 struct drm_plane_state new_state_tmp
;
1435 struct amdgpu_framebuffer
*amdgpu_fb_old
;
1436 struct amdgpu_framebuffer
*amdgpu_fb_new
;
1437 struct amdgpu_crtc
*acrtc_new
;
1439 uint64_t old_tiling_flags
;
1440 uint64_t new_tiling_flags
;
1442 bool page_flip_required
;
1456 old_state_tmp
= *old_state
;
1457 new_state_tmp
= *new_state
;
1462 amdgpu_fb_old
= to_amdgpu_framebuffer(old_state
->fb
);
1463 amdgpu_fb_new
= to_amdgpu_framebuffer(new_state
->fb
);
1465 if (!get_fb_info(amdgpu_fb_old
, &old_tiling_flags
, NULL
))
1468 if (!get_fb_info(amdgpu_fb_new
, &new_tiling_flags
, NULL
))
1471 if (commit_surface_required
== true &&
1472 old_tiling_flags
!= new_tiling_flags
)
1475 clear_unrelated_fields(&old_state_tmp
);
1476 clear_unrelated_fields(&new_state_tmp
);
1478 page_flip_required
= memcmp(&old_state_tmp
,
1480 sizeof(old_state_tmp
)) == 0 ? true:false;
1481 if (new_state
->crtc
&& page_flip_required
== false) {
1482 acrtc_new
= to_amdgpu_crtc(new_state
->crtc
);
1483 if (acrtc_new
->flip_flags
& DRM_MODE_PAGE_FLIP_ASYNC
)
1484 page_flip_required
= true;
1486 return page_flip_required
;
1489 static int dm_plane_helper_prepare_fb(
1490 struct drm_plane
*plane
,
1491 struct drm_plane_state
*new_state
)
1493 struct amdgpu_framebuffer
*afb
;
1494 struct drm_gem_object
*obj
;
1495 struct amdgpu_bo
*rbo
;
1498 if (!new_state
->fb
) {
1499 DRM_DEBUG_KMS("No FB bound\n");
1503 afb
= to_amdgpu_framebuffer(new_state
->fb
);
1506 rbo
= gem_to_amdgpu_bo(obj
);
1507 r
= amdgpu_bo_reserve(rbo
, false);
1508 if (unlikely(r
!= 0))
1511 r
= amdgpu_bo_pin(rbo
, AMDGPU_GEM_DOMAIN_VRAM
, NULL
);
1513 amdgpu_bo_unreserve(rbo
);
1515 if (unlikely(r
!= 0)) {
1516 DRM_ERROR("Failed to pin framebuffer\n");
1523 static void dm_plane_helper_cleanup_fb(
1524 struct drm_plane
*plane
,
1525 struct drm_plane_state
*old_state
)
1527 struct amdgpu_bo
*rbo
;
1528 struct amdgpu_framebuffer
*afb
;
1534 afb
= to_amdgpu_framebuffer(old_state
->fb
);
1535 rbo
= gem_to_amdgpu_bo(afb
->obj
);
1536 r
= amdgpu_bo_reserve(rbo
, false);
1538 DRM_ERROR("failed to reserve rbo before unpin\n");
1541 amdgpu_bo_unpin(rbo
);
1542 amdgpu_bo_unreserve(rbo
);
1546 int dm_create_validation_set_for_connector(struct drm_connector
*connector
,
1547 struct drm_display_mode
*mode
, struct dc_validation_set
*val_set
)
1549 int result
= MODE_ERROR
;
1550 const struct dc_sink
*dc_sink
=
1551 to_amdgpu_connector(connector
)->dc_sink
;
1552 /* TODO: Unhardcode stream count */
1553 struct dc_stream
*stream
;
1555 if ((mode
->flags
& DRM_MODE_FLAG_INTERLACE
) ||
1556 (mode
->flags
& DRM_MODE_FLAG_DBLSCAN
))
1559 if (NULL
== dc_sink
) {
1560 DRM_ERROR("dc_sink is NULL!\n");
1564 stream
= dc_create_stream_for_sink(dc_sink
);
1566 if (NULL
== stream
) {
1567 DRM_ERROR("Failed to create stream for sink!\n");
1571 drm_mode_set_crtcinfo(mode
, 0);
1573 fill_stream_properties_from_drm_display_mode(stream
, mode
, connector
);
1575 val_set
->stream
= stream
;
1577 stream
->src
.width
= mode
->hdisplay
;
1578 stream
->src
.height
= mode
->vdisplay
;
1579 stream
->dst
= stream
->src
;
1584 static const struct drm_plane_helper_funcs dm_plane_helper_funcs
= {
1585 .prepare_fb
= dm_plane_helper_prepare_fb
,
1586 .cleanup_fb
= dm_plane_helper_cleanup_fb
,
1590 * TODO: these are currently initialized to rgb formats only.
1591 * For future use cases we should either initialize them dynamically based on
1592 * plane capabilities, or initialize this array to all formats, so internal drm
1593 * check will succeed, and let DC to implement proper check
1595 static uint32_t rgb_formats
[] = {
1596 DRM_FORMAT_XRGB4444
,
1597 DRM_FORMAT_ARGB4444
,
1598 DRM_FORMAT_RGBA4444
,
1599 DRM_FORMAT_ARGB1555
,
1602 DRM_FORMAT_XRGB8888
,
1603 DRM_FORMAT_ARGB8888
,
1604 DRM_FORMAT_RGBA8888
,
1605 DRM_FORMAT_XRGB2101010
,
1606 DRM_FORMAT_XBGR2101010
,
1607 DRM_FORMAT_ARGB2101010
,
1608 DRM_FORMAT_ABGR2101010
,
1611 int amdgpu_dm_crtc_init(struct amdgpu_display_manager
*dm
,
1612 struct amdgpu_crtc
*acrtc
,
1613 uint32_t crtc_index
)
1617 struct drm_plane
*primary_plane
=
1618 kzalloc(sizeof(*primary_plane
), GFP_KERNEL
);
1623 primary_plane
->format_default
= true;
1625 res
= drm_universal_plane_init(
1631 ARRAY_SIZE(rgb_formats
),
1633 DRM_PLANE_TYPE_PRIMARY
, NULL
);
1635 primary_plane
->crtc
= &acrtc
->base
;
1637 drm_plane_helper_add(primary_plane
, &dm_plane_helper_funcs
);
1639 res
= drm_crtc_init_with_planes(
1644 &amdgpu_dm_crtc_funcs
, NULL
);
1649 drm_crtc_helper_add(&acrtc
->base
, &amdgpu_dm_crtc_helper_funcs
);
1651 acrtc
->max_cursor_width
= 128;
1652 acrtc
->max_cursor_height
= 128;
1654 acrtc
->crtc_id
= crtc_index
;
1655 acrtc
->base
.enabled
= false;
1657 dm
->adev
->mode_info
.crtcs
[crtc_index
] = acrtc
;
1658 drm_mode_crtc_set_gamma_size(&acrtc
->base
, 256);
1662 kfree(primary_plane
);
1664 acrtc
->crtc_id
= -1;
1668 static int to_drm_connector_type(enum signal_type st
)
1671 case SIGNAL_TYPE_HDMI_TYPE_A
:
1672 return DRM_MODE_CONNECTOR_HDMIA
;
1673 case SIGNAL_TYPE_EDP
:
1674 return DRM_MODE_CONNECTOR_eDP
;
1675 case SIGNAL_TYPE_RGB
:
1676 return DRM_MODE_CONNECTOR_VGA
;
1677 case SIGNAL_TYPE_DISPLAY_PORT
:
1678 case SIGNAL_TYPE_DISPLAY_PORT_MST
:
1679 return DRM_MODE_CONNECTOR_DisplayPort
;
1680 case SIGNAL_TYPE_DVI_DUAL_LINK
:
1681 case SIGNAL_TYPE_DVI_SINGLE_LINK
:
1682 return DRM_MODE_CONNECTOR_DVID
;
1683 case SIGNAL_TYPE_VIRTUAL
:
1684 return DRM_MODE_CONNECTOR_VIRTUAL
;
1687 return DRM_MODE_CONNECTOR_Unknown
;
1691 static void amdgpu_dm_get_native_mode(struct drm_connector
*connector
)
1693 const struct drm_connector_helper_funcs
*helper
=
1694 connector
->helper_private
;
1695 struct drm_encoder
*encoder
;
1696 struct amdgpu_encoder
*amdgpu_encoder
;
1698 encoder
= helper
->best_encoder(connector
);
1700 if (encoder
== NULL
)
1703 amdgpu_encoder
= to_amdgpu_encoder(encoder
);
1705 amdgpu_encoder
->native_mode
.clock
= 0;
1707 if (!list_empty(&connector
->probed_modes
)) {
1708 struct drm_display_mode
*preferred_mode
= NULL
;
1709 list_for_each_entry(preferred_mode
,
1710 &connector
->probed_modes
,
1712 if (preferred_mode
->type
& DRM_MODE_TYPE_PREFERRED
) {
1713 amdgpu_encoder
->native_mode
= *preferred_mode
;
1721 static struct drm_display_mode
*amdgpu_dm_create_common_mode(
1722 struct drm_encoder
*encoder
, char *name
,
1723 int hdisplay
, int vdisplay
)
1725 struct drm_device
*dev
= encoder
->dev
;
1726 struct amdgpu_encoder
*amdgpu_encoder
= to_amdgpu_encoder(encoder
);
1727 struct drm_display_mode
*mode
= NULL
;
1728 struct drm_display_mode
*native_mode
= &amdgpu_encoder
->native_mode
;
1730 mode
= drm_mode_duplicate(dev
, native_mode
);
1735 mode
->hdisplay
= hdisplay
;
1736 mode
->vdisplay
= vdisplay
;
1737 mode
->type
&= ~DRM_MODE_TYPE_PREFERRED
;
1738 strncpy(mode
->name
, name
, DRM_DISPLAY_MODE_LEN
);
1744 static void amdgpu_dm_connector_add_common_modes(struct drm_encoder
*encoder
,
1745 struct drm_connector
*connector
)
1747 struct amdgpu_encoder
*amdgpu_encoder
= to_amdgpu_encoder(encoder
);
1748 struct drm_display_mode
*mode
= NULL
;
1749 struct drm_display_mode
*native_mode
= &amdgpu_encoder
->native_mode
;
1750 struct amdgpu_connector
*amdgpu_connector
=
1751 to_amdgpu_connector(connector
);
1755 char name
[DRM_DISPLAY_MODE_LEN
];
1759 { "640x480", 640, 480},
1760 { "800x600", 800, 600},
1761 { "1024x768", 1024, 768},
1762 { "1280x720", 1280, 720},
1763 { "1280x800", 1280, 800},
1764 {"1280x1024", 1280, 1024},
1765 { "1440x900", 1440, 900},
1766 {"1680x1050", 1680, 1050},
1767 {"1600x1200", 1600, 1200},
1768 {"1920x1080", 1920, 1080},
1769 {"1920x1200", 1920, 1200}
1772 n
= sizeof(common_modes
) / sizeof(common_modes
[0]);
1774 for (i
= 0; i
< n
; i
++) {
1775 struct drm_display_mode
*curmode
= NULL
;
1776 bool mode_existed
= false;
1778 if (common_modes
[i
].w
> native_mode
->hdisplay
||
1779 common_modes
[i
].h
> native_mode
->vdisplay
||
1780 (common_modes
[i
].w
== native_mode
->hdisplay
&&
1781 common_modes
[i
].h
== native_mode
->vdisplay
))
1784 list_for_each_entry(curmode
, &connector
->probed_modes
, head
) {
1785 if (common_modes
[i
].w
== curmode
->hdisplay
&&
1786 common_modes
[i
].h
== curmode
->vdisplay
) {
1787 mode_existed
= true;
1795 mode
= amdgpu_dm_create_common_mode(encoder
,
1796 common_modes
[i
].name
, common_modes
[i
].w
,
1798 drm_mode_probed_add(connector
, mode
);
1799 amdgpu_connector
->num_modes
++;
1803 static void amdgpu_dm_connector_ddc_get_modes(
1804 struct drm_connector
*connector
,
1807 struct amdgpu_connector
*amdgpu_connector
=
1808 to_amdgpu_connector(connector
);
1811 /* empty probed_modes */
1812 INIT_LIST_HEAD(&connector
->probed_modes
);
1813 amdgpu_connector
->num_modes
=
1814 drm_add_edid_modes(connector
, edid
);
1816 drm_edid_to_eld(connector
, edid
);
1818 amdgpu_dm_get_native_mode(connector
);
1820 amdgpu_connector
->num_modes
= 0;
1823 int amdgpu_dm_connector_get_modes(struct drm_connector
*connector
)
1825 const struct drm_connector_helper_funcs
*helper
=
1826 connector
->helper_private
;
1827 struct amdgpu_connector
*amdgpu_connector
=
1828 to_amdgpu_connector(connector
);
1829 struct drm_encoder
*encoder
;
1830 struct edid
*edid
= amdgpu_connector
->edid
;
1832 encoder
= helper
->best_encoder(connector
);
1834 amdgpu_dm_connector_ddc_get_modes(connector
, edid
);
1835 amdgpu_dm_connector_add_common_modes(encoder
, connector
);
1836 return amdgpu_connector
->num_modes
;
1839 void amdgpu_dm_connector_init_helper(
1840 struct amdgpu_display_manager
*dm
,
1841 struct amdgpu_connector
*aconnector
,
1843 const struct dc_link
*link
,
1846 struct amdgpu_device
*adev
= dm
->ddev
->dev_private
;
1848 aconnector
->connector_id
= link_index
;
1849 aconnector
->dc_link
= link
;
1850 aconnector
->base
.interlace_allowed
= true;
1851 aconnector
->base
.doublescan_allowed
= true;
1852 aconnector
->base
.dpms
= DRM_MODE_DPMS_OFF
;
1853 aconnector
->hpd
.hpd
= AMDGPU_HPD_NONE
; /* not used */
1855 mutex_init(&aconnector
->hpd_lock
);
1857 /*configure suport HPD hot plug connector_>polled default value is 0
1858 * which means HPD hot plug not supported*/
1859 switch (connector_type
) {
1860 case DRM_MODE_CONNECTOR_HDMIA
:
1861 aconnector
->base
.polled
= DRM_CONNECTOR_POLL_HPD
;
1863 case DRM_MODE_CONNECTOR_DisplayPort
:
1864 aconnector
->base
.polled
= DRM_CONNECTOR_POLL_HPD
;
1866 case DRM_MODE_CONNECTOR_DVID
:
1867 aconnector
->base
.polled
= DRM_CONNECTOR_POLL_HPD
;
1873 drm_object_attach_property(&aconnector
->base
.base
,
1874 dm
->ddev
->mode_config
.scaling_mode_property
,
1875 DRM_MODE_SCALE_NONE
);
1877 drm_object_attach_property(&aconnector
->base
.base
,
1878 adev
->mode_info
.underscan_property
,
1880 drm_object_attach_property(&aconnector
->base
.base
,
1881 adev
->mode_info
.underscan_hborder_property
,
1883 drm_object_attach_property(&aconnector
->base
.base
,
1884 adev
->mode_info
.underscan_vborder_property
,
1889 int amdgpu_dm_i2c_xfer(struct i2c_adapter
*i2c_adap
,
1890 struct i2c_msg
*msgs
, int num
)
1892 struct amdgpu_i2c_adapter
*i2c
= i2c_get_adapdata(i2c_adap
);
1893 struct i2c_command cmd
;
1897 cmd
.payloads
= kzalloc(num
* sizeof(struct i2c_payload
), GFP_KERNEL
);
1902 cmd
.number_of_payloads
= num
;
1903 cmd
.engine
= I2C_COMMAND_ENGINE_DEFAULT
;
1906 for (i
= 0; i
< num
; i
++) {
1907 cmd
.payloads
[i
].write
= (msgs
[i
].flags
& I2C_M_RD
);
1908 cmd
.payloads
[i
].address
= msgs
[i
].addr
;
1909 cmd
.payloads
[i
].length
= msgs
[i
].len
;
1910 cmd
.payloads
[i
].data
= msgs
[i
].buf
;
1913 if (dc_submit_i2c(i2c
->dm
->dc
, i2c
->link_index
, &cmd
))
1916 kfree(cmd
.payloads
);
1921 u32
amdgpu_dm_i2c_func(struct i2c_adapter
*adap
)
1923 return I2C_FUNC_I2C
| I2C_FUNC_SMBUS_EMUL
;
1926 static const struct i2c_algorithm amdgpu_dm_i2c_algo
= {
1927 .master_xfer
= amdgpu_dm_i2c_xfer
,
1928 .functionality
= amdgpu_dm_i2c_func
,
1931 struct amdgpu_i2c_adapter
*create_i2c(unsigned int link_index
, struct amdgpu_display_manager
*dm
, int *res
)
1933 struct amdgpu_i2c_adapter
*i2c
;
1935 i2c
= kzalloc(sizeof (struct amdgpu_i2c_adapter
), GFP_KERNEL
);
1937 i2c
->base
.owner
= THIS_MODULE
;
1938 i2c
->base
.class = I2C_CLASS_DDC
;
1939 i2c
->base
.dev
.parent
= &dm
->adev
->pdev
->dev
;
1940 i2c
->base
.algo
= &amdgpu_dm_i2c_algo
;
1941 snprintf(i2c
->base
.name
, sizeof (i2c
->base
.name
), "AMDGPU DM i2c hw bus %d", link_index
);
1942 i2c
->link_index
= link_index
;
1943 i2c_set_adapdata(&i2c
->base
, i2c
);
1948 /* Note: this function assumes that dc_link_detect() was called for the
1949 * dc_link which will be represented by this aconnector. */
1950 int amdgpu_dm_connector_init(
1951 struct amdgpu_display_manager
*dm
,
1952 struct amdgpu_connector
*aconnector
,
1953 uint32_t link_index
,
1954 struct amdgpu_encoder
*aencoder
)
1958 struct dc
*dc
= dm
->dc
;
1959 const struct dc_link
*link
= dc_get_link_at_index(dc
, link_index
);
1960 struct amdgpu_i2c_adapter
*i2c
;
1962 DRM_DEBUG_KMS("%s()\n", __func__
);
1964 i2c
= create_i2c(link
->link_index
, dm
, &res
);
1965 aconnector
->i2c
= i2c
;
1966 res
= i2c_add_adapter(&i2c
->base
);
1969 DRM_ERROR("Failed to register hw i2c %d\n", link
->link_index
);
1973 connector_type
= to_drm_connector_type(link
->connector_signal
);
1975 res
= drm_connector_init(
1978 &amdgpu_dm_connector_funcs
,
1982 DRM_ERROR("connector_init failed\n");
1983 aconnector
->connector_id
= -1;
1987 drm_connector_helper_add(
1989 &amdgpu_dm_connector_helper_funcs
);
1991 amdgpu_dm_connector_init_helper(
1998 drm_mode_connector_attach_encoder(
1999 &aconnector
->base
, &aencoder
->base
);
2001 drm_connector_register(&aconnector
->base
);
2003 if (connector_type
== DRM_MODE_CONNECTOR_DisplayPort
2004 || connector_type
== DRM_MODE_CONNECTOR_eDP
)
2005 amdgpu_dm_initialize_mst_connector(dm
, aconnector
);
2007 #if defined(CONFIG_BACKLIGHT_CLASS_DEVICE) ||\
2008 defined(CONFIG_BACKLIGHT_CLASS_DEVICE_MODULE)
2010 /* NOTE: this currently will create backlight device even if a panel
2011 * is not connected to the eDP/LVDS connector.
2013 * This is less than ideal but we don't have sink information at this
2014 * stage since detection happens after. We can't do detection earlier
2015 * since MST detection needs connectors to be created first.
2017 if (link
->connector_signal
& (SIGNAL_TYPE_EDP
| SIGNAL_TYPE_LVDS
)) {
2018 /* Event if registration failed, we should continue with
2019 * DM initialization because not having a backlight control
2020 * is better then a black screen. */
2021 amdgpu_dm_register_backlight_device(dm
);
2023 if (dm
->backlight_dev
)
2024 dm
->backlight_link
= link
;
2031 aconnector
->i2c
= NULL
;
2036 int amdgpu_dm_get_encoder_crtc_mask(struct amdgpu_device
*adev
)
2038 switch (adev
->mode_info
.num_crtc
) {
2055 int amdgpu_dm_encoder_init(
2056 struct drm_device
*dev
,
2057 struct amdgpu_encoder
*aencoder
,
2058 uint32_t link_index
)
2060 struct amdgpu_device
*adev
= dev
->dev_private
;
2062 int res
= drm_encoder_init(dev
,
2064 &amdgpu_dm_encoder_funcs
,
2065 DRM_MODE_ENCODER_TMDS
,
2068 aencoder
->base
.possible_crtcs
= amdgpu_dm_get_encoder_crtc_mask(adev
);
2071 aencoder
->encoder_id
= link_index
;
2073 aencoder
->encoder_id
= -1;
2075 drm_encoder_helper_add(&aencoder
->base
, &amdgpu_dm_encoder_helper_funcs
);
2080 enum dm_commit_action
{
2081 DM_COMMIT_ACTION_NOTHING
,
2082 DM_COMMIT_ACTION_RESET
,
2083 DM_COMMIT_ACTION_DPMS_ON
,
2084 DM_COMMIT_ACTION_DPMS_OFF
,
2085 DM_COMMIT_ACTION_SET
2088 static enum dm_commit_action
get_dm_commit_action(struct drm_crtc_state
*state
)
2090 /* mode changed means either actually mode changed or enabled changed */
2091 /* active changed means dpms changed */
2093 DRM_DEBUG_KMS("crtc_state_flags: enable:%d, active:%d, planes_changed:%d, mode_changed:%d,active_changed:%d,connectors_changed:%d\n",
2096 state
->planes_changed
,
2097 state
->mode_changed
,
2098 state
->active_changed
,
2099 state
->connectors_changed
);
2101 if (state
->mode_changed
) {
2102 /* if it is got disabled - call reset mode */
2104 return DM_COMMIT_ACTION_RESET
;
2107 return DM_COMMIT_ACTION_SET
;
2109 return DM_COMMIT_ACTION_RESET
;
2111 /* ! mode_changed */
2113 /* if it is remain disable - skip it */
2115 return DM_COMMIT_ACTION_NOTHING
;
2117 if (state
->active
&& state
->connectors_changed
)
2118 return DM_COMMIT_ACTION_SET
;
2120 if (state
->active_changed
) {
2121 if (state
->active
) {
2122 return DM_COMMIT_ACTION_DPMS_ON
;
2124 return DM_COMMIT_ACTION_DPMS_OFF
;
2127 /* ! active_changed */
2128 return DM_COMMIT_ACTION_NOTHING
;
2134 typedef bool (*predicate
)(struct amdgpu_crtc
*acrtc
);
2136 static void wait_while_pflip_status(struct amdgpu_device
*adev
,
2137 struct amdgpu_crtc
*acrtc
, predicate f
) {
2143 if (count
== 1000) {
2144 DRM_ERROR("%s - crtc:%d[%p], pflip_stat:%d, probable hang!\n",
2145 __func__
, acrtc
->crtc_id
,
2147 acrtc
->pflip_status
);
2149 /* we do not expect to hit this case except on Polaris with PHY PLL
2150 * 1. DP to HDMI passive dongle connected
2151 * 2. unplug (headless)
2153 * 3a. on plug in, DP will try verify link by training, and training
2154 * would disable PHY PLL which HDMI rely on to drive TG
2155 * 3b. this will cause flip interrupt cannot be generated, and we
2156 * exit when timeout expired. however we do not have code to clean
2157 * up flip, flip clean up will happen when the address is written
2158 * with the restore mode change
2165 DRM_DEBUG_DRIVER("%s - Finished waiting for:%d msec, crtc:%d[%p], pflip_stat:%d \n",
2170 acrtc
->pflip_status
);
2173 static bool pflip_in_progress_predicate(struct amdgpu_crtc
*acrtc
)
2175 return acrtc
->pflip_status
!= AMDGPU_FLIP_NONE
;
2178 static void manage_dm_interrupts(
2179 struct amdgpu_device
*adev
,
2180 struct amdgpu_crtc
*acrtc
,
2184 * this is not correct translation but will work as soon as VBLANK
2185 * constant is the same as PFLIP
2188 amdgpu_crtc_idx_to_irq_type(
2193 drm_crtc_vblank_on(&acrtc
->base
);
2196 &adev
->pageflip_irq
,
2199 wait_while_pflip_status(adev
, acrtc
,
2200 pflip_in_progress_predicate
);
2204 &adev
->pageflip_irq
,
2206 drm_crtc_vblank_off(&acrtc
->base
);
2211 static bool pflip_pending_predicate(struct amdgpu_crtc
*acrtc
)
2213 return acrtc
->pflip_status
== AMDGPU_FLIP_PENDING
;
2216 static bool is_scaling_state_different(
2217 const struct dm_connector_state
*dm_state
,
2218 const struct dm_connector_state
*old_dm_state
)
2220 if (dm_state
->scaling
!= old_dm_state
->scaling
)
2222 if (!dm_state
->underscan_enable
&& old_dm_state
->underscan_enable
) {
2223 if (old_dm_state
->underscan_hborder
!= 0 && old_dm_state
->underscan_vborder
!= 0)
2225 } else if (dm_state
->underscan_enable
&& !old_dm_state
->underscan_enable
) {
2226 if (dm_state
->underscan_hborder
!= 0 && dm_state
->underscan_vborder
!= 0)
2228 } else if (dm_state
->underscan_hborder
!= old_dm_state
->underscan_hborder
2229 || dm_state
->underscan_vborder
!= old_dm_state
->underscan_vborder
)
2234 static void remove_stream(struct amdgpu_device
*adev
, struct amdgpu_crtc
*acrtc
)
2237 * we evade vblanks and pflips on crtc that
2240 manage_dm_interrupts(adev
, acrtc
, false);
2242 /* this is the update mode case */
2243 if (adev
->dm
.freesync_module
)
2244 mod_freesync_remove_stream(adev
->dm
.freesync_module
,
2247 dc_stream_release(acrtc
->stream
);
2248 acrtc
->stream
= NULL
;
2249 acrtc
->otg_inst
= -1;
2250 acrtc
->enabled
= false;
2253 int amdgpu_dm_atomic_commit(
2254 struct drm_device
*dev
,
2255 struct drm_atomic_state
*state
,
2258 struct amdgpu_device
*adev
= dev
->dev_private
;
2259 struct amdgpu_display_manager
*dm
= &adev
->dm
;
2260 struct drm_plane
*plane
;
2261 struct drm_plane_state
*new_plane_state
;
2262 struct drm_plane_state
*old_plane_state
;
2265 uint32_t commit_streams_count
= 0;
2266 uint32_t new_crtcs_count
= 0;
2267 uint32_t flip_crtcs_count
= 0;
2268 struct drm_crtc
*crtc
;
2269 struct drm_crtc_state
*old_crtc_state
;
2270 const struct dc_stream
*commit_streams
[MAX_STREAMS
];
2271 struct amdgpu_crtc
*new_crtcs
[MAX_STREAMS
];
2272 const struct dc_stream
*new_stream
;
2273 struct drm_crtc
*flip_crtcs
[MAX_STREAMS
];
2274 struct amdgpu_flip_work
*work
[MAX_STREAMS
] = {0};
2275 struct amdgpu_bo
*new_abo
[MAX_STREAMS
] = {0};
2277 /* In this step all new fb would be pinned */
2280 * TODO: Revisit when we support true asynchronous commit.
2281 * Right now we receive async commit only from pageflip, in which case
2282 * we should not pin/unpin the fb here, it should be done in
2283 * amdgpu_crtc_flip and from the vblank irq handler.
2286 ret
= drm_atomic_helper_prepare_planes(dev
, state
);
2291 /* Page flip if needed */
2292 for_each_plane_in_state(state
, plane
, new_plane_state
, i
) {
2293 struct drm_plane_state
*old_plane_state
= plane
->state
;
2294 struct drm_crtc
*crtc
= new_plane_state
->crtc
;
2295 struct amdgpu_crtc
*acrtc
= to_amdgpu_crtc(crtc
);
2296 struct drm_framebuffer
*fb
= new_plane_state
->fb
;
2297 struct drm_crtc_state
*crtc_state
;
2302 crtc_state
= drm_atomic_get_crtc_state(state
, crtc
);
2304 if (!crtc_state
->planes_changed
|| !crtc_state
->active
)
2307 if (page_flip_needed(
2312 ret
= amdgpu_crtc_prepare_flip(crtc
,
2316 drm_crtc_vblank_count(crtc
),
2317 &work
[flip_crtcs_count
],
2318 &new_abo
[flip_crtcs_count
]);
2321 /* According to atomic_commit hook API, EINVAL is not allowed */
2322 if (unlikely(ret
== -EINVAL
))
2325 DRM_ERROR("Atomic commit: Flip for crtc id %d: [%p], "
2326 "failed, errno = %d\n",
2330 /* cleanup all flip configurations which
2331 * succeeded in this commit
2333 for (i
= 0; i
< flip_crtcs_count
; i
++)
2334 amdgpu_crtc_cleanup_flip_ctx(
2341 flip_crtcs
[flip_crtcs_count
] = crtc
;
2347 * This is the point of no return - everything below never fails except
2348 * when the hw goes bonghits. Which means we can commit the new state on
2349 * the software side now.
2352 drm_atomic_helper_swap_state(state
, true);
2355 * From this point state become old state really. New state is
2356 * initialized to appropriate objects and could be accessed from there
2360 * there is no fences usage yet in state. We can skip the following line
2361 * wait_for_fences(dev, state);
2364 drm_atomic_helper_update_legacy_modeset_state(dev
, state
);
2366 /* update changed items */
2367 for_each_crtc_in_state(state
, crtc
, old_crtc_state
, i
) {
2368 struct amdgpu_crtc
*acrtc
;
2369 struct amdgpu_connector
*aconnector
= NULL
;
2370 enum dm_commit_action action
;
2371 struct drm_crtc_state
*new_state
= crtc
->state
;
2373 acrtc
= to_amdgpu_crtc(crtc
);
2376 amdgpu_dm_find_first_crct_matching_connector(
2381 /* handles headless hotplug case, updating new_state and
2382 * aconnector as needed
2385 action
= get_dm_commit_action(new_state
);
2388 case DM_COMMIT_ACTION_DPMS_ON
:
2389 case DM_COMMIT_ACTION_SET
: {
2390 struct dm_connector_state
*dm_state
= NULL
;
2394 dm_state
= to_dm_connector_state(aconnector
->base
.state
);
2396 new_stream
= create_stream_for_sink(
2401 DRM_INFO("Atomic commit: SET crtc id %d: [%p]\n", acrtc
->crtc_id
, acrtc
);
2405 * this could happen because of issues with
2406 * userspace notifications delivery.
2407 * In this case userspace tries to set mode on
2408 * display which is disconnect in fact.
2409 * dc_sink in NULL in this case on aconnector.
2410 * We expect reset mode will come soon.
2412 * This can also happen when unplug is done
2413 * during resume sequence ended
2415 * In this case, we want to pretend we still
2416 * have a sink to keep the pipe running so that
2417 * hw state is consistent with the sw state
2419 DRM_DEBUG_KMS("%s: Failed to create new stream for crtc %d\n",
2420 __func__
, acrtc
->base
.base
.id
);
2425 remove_stream(adev
, acrtc
);
2428 * this loop saves set mode crtcs
2429 * we needed to enable vblanks once all
2430 * resources acquired in dc after dc_commit_streams
2432 new_crtcs
[new_crtcs_count
] = acrtc
;
2435 acrtc
->stream
= new_stream
;
2436 acrtc
->enabled
= true;
2437 acrtc
->hw_mode
= crtc
->state
->mode
;
2438 crtc
->hwmode
= crtc
->state
->mode
;
2443 case DM_COMMIT_ACTION_NOTHING
: {
2444 struct dm_connector_state
*dm_state
= NULL
;
2449 dm_state
= to_dm_connector_state(aconnector
->base
.state
);
2451 /* Scaling update */
2452 update_stream_scaling_settings(&crtc
->state
->mode
,
2453 dm_state
, acrtc
->stream
);
2457 case DM_COMMIT_ACTION_DPMS_OFF
:
2458 case DM_COMMIT_ACTION_RESET
:
2459 DRM_INFO("Atomic commit: RESET. crtc id %d:[%p]\n", acrtc
->crtc_id
, acrtc
);
2460 /* i.e. reset mode */
2462 remove_stream(adev
, acrtc
);
2465 } /* for_each_crtc_in_state() */
2467 list_for_each_entry(crtc
, &dev
->mode_config
.crtc_list
, head
) {
2469 struct amdgpu_crtc
*acrtc
= to_amdgpu_crtc(crtc
);
2471 if (acrtc
->stream
) {
2472 commit_streams
[commit_streams_count
] = acrtc
->stream
;
2473 ++commit_streams_count
;
2478 * Add streams after required streams from new and replaced streams
2479 * are removed from freesync module
2481 if (adev
->dm
.freesync_module
) {
2482 for (i
= 0; i
< new_crtcs_count
; i
++) {
2483 struct amdgpu_connector
*aconnector
= NULL
;
2484 new_stream
= new_crtcs
[i
]->stream
;
2486 amdgpu_dm_find_first_crct_matching_connector(
2488 &new_crtcs
[i
]->base
,
2492 "Atomic commit: Failed to find connector for acrtc id:%d "
2493 "skipping freesync init\n",
2494 new_crtcs
[i
]->crtc_id
);
2498 mod_freesync_add_stream(adev
->dm
.freesync_module
,
2499 new_stream
, &aconnector
->caps
);
2503 /* DC is optimized not to do anything if 'streams' didn't change. */
2504 dc_commit_streams(dm
->dc
, commit_streams
, commit_streams_count
);
2506 list_for_each_entry(crtc
, &dev
->mode_config
.crtc_list
, head
) {
2507 struct amdgpu_crtc
*acrtc
= to_amdgpu_crtc(crtc
);
2509 if (acrtc
->stream
!= NULL
)
2511 dc_stream_get_status(acrtc
->stream
)->primary_otg_inst
;
2514 /* update planes when needed */
2515 for_each_plane_in_state(state
, plane
, old_plane_state
, i
) {
2516 struct drm_plane_state
*plane_state
= plane
->state
;
2517 struct drm_crtc
*crtc
= plane_state
->crtc
;
2518 struct amdgpu_crtc
*acrtc
= to_amdgpu_crtc(crtc
);
2519 struct drm_framebuffer
*fb
= plane_state
->fb
;
2520 struct drm_connector
*connector
;
2521 struct dm_connector_state
*dm_state
= NULL
;
2522 enum dm_commit_action action
;
2524 if (!fb
|| !crtc
|| !crtc
->state
->active
)
2527 action
= get_dm_commit_action(crtc
->state
);
2529 /* Surfaces are created under two scenarios:
2530 * 1. This commit is not a page flip.
2531 * 2. This commit is a page flip, and streams are created.
2533 if (!page_flip_needed(
2536 crtc
->state
->event
, true) ||
2537 action
== DM_COMMIT_ACTION_DPMS_ON
||
2538 action
== DM_COMMIT_ACTION_SET
) {
2539 list_for_each_entry(connector
,
2540 &dev
->mode_config
.connector_list
, head
) {
2541 if (connector
->state
->crtc
== crtc
) {
2542 dm_state
= to_dm_connector_state(
2549 * This situation happens in the following case:
2550 * we are about to get set mode for connector who's only
2551 * possible crtc (in encoder crtc mask) is used by
2552 * another connector, that is why it will try to
2553 * re-assing crtcs in order to make configuration
2554 * supported. For our implementation we need to make all
2555 * encoders support all crtcs, then this issue will
2556 * never arise again. But to guard code from this issue
2559 * Also it should be needed when used with actual
2560 * drm_atomic_commit ioctl in future
2566 * if flip is pending (ie, still waiting for fence to return
2567 * before address is submitted) here, we cannot commit_surface
2568 * as commit_surface will pre-maturely write out the future
2569 * address. wait until flip is submitted before proceeding.
2571 wait_while_pflip_status(adev
, acrtc
, pflip_pending_predicate
);
2573 dm_dc_surface_commit(dm
->dc
, crtc
);
2577 for (i
= 0; i
< new_crtcs_count
; i
++) {
2579 * loop to enable interrupts on newly arrived crtc
2581 struct amdgpu_crtc
*acrtc
= new_crtcs
[i
];
2583 if (adev
->dm
.freesync_module
)
2584 mod_freesync_notify_mode_change(
2585 adev
->dm
.freesync_module
, &acrtc
->stream
, 1);
2587 manage_dm_interrupts(adev
, acrtc
, true);
2588 dm_crtc_cursor_reset(&acrtc
->base
);
2592 /* Do actual flip */
2593 flip_crtcs_count
= 0;
2594 for_each_plane_in_state(state
, plane
, old_plane_state
, i
) {
2595 struct drm_plane_state
*plane_state
= plane
->state
;
2596 struct drm_crtc
*crtc
= plane_state
->crtc
;
2597 struct amdgpu_crtc
*acrtc
= to_amdgpu_crtc(crtc
);
2598 struct drm_framebuffer
*fb
= plane_state
->fb
;
2600 if (!fb
|| !crtc
|| !crtc
->state
->planes_changed
||
2601 !crtc
->state
->active
)
2604 if (page_flip_needed(
2609 amdgpu_crtc_submit_flip(
2612 work
[flip_crtcs_count
],
2615 /*clean up the flags for next usage*/
2616 acrtc
->flip_flags
= 0;
2620 /* In this state all old framebuffers would be unpinned */
2622 /* TODO: Revisit when we support true asynchronous commit.*/
2624 drm_atomic_helper_cleanup_planes(dev
, state
);
2626 drm_atomic_state_put(state
);
2631 * This functions handle all cases when set mode does not come upon hotplug.
2632 * This include when the same display is unplugged then plugged back into the
2633 * same port and when we are running without usermode desktop manager supprot
2635 void dm_restore_drm_connector_state(struct drm_device
*dev
, struct drm_connector
*connector
)
2637 struct drm_crtc
*crtc
;
2638 struct amdgpu_device
*adev
= dev
->dev_private
;
2639 struct dc
*dc
= adev
->dm
.dc
;
2640 struct amdgpu_connector
*aconnector
= to_amdgpu_connector(connector
);
2641 struct amdgpu_crtc
*disconnected_acrtc
;
2642 const struct dc_sink
*sink
;
2643 const struct dc_stream
*commit_streams
[MAX_STREAMS
];
2644 const struct dc_stream
*current_stream
;
2645 uint32_t commit_streams_count
= 0;
2647 if (!aconnector
->dc_sink
|| !connector
->state
|| !connector
->encoder
)
2650 disconnected_acrtc
= to_amdgpu_crtc(connector
->encoder
->crtc
);
2652 if (!disconnected_acrtc
|| !disconnected_acrtc
->stream
)
2655 sink
= disconnected_acrtc
->stream
->sink
;
2658 * If the previous sink is not released and different from the current,
2659 * we deduce we are in a state where we can not rely on usermode call
2660 * to turn on the display, so we do it here
2662 if (sink
!= aconnector
->dc_sink
) {
2663 struct dm_connector_state
*dm_state
=
2664 to_dm_connector_state(aconnector
->base
.state
);
2666 struct dc_stream
*new_stream
=
2667 create_stream_for_sink(
2669 &disconnected_acrtc
->base
.state
->mode
,
2672 DRM_INFO("Headless hotplug, restoring connector state\n");
2674 * we evade vblanks and pflips on crtc that
2677 manage_dm_interrupts(adev
, disconnected_acrtc
, false);
2678 /* this is the update mode case */
2680 current_stream
= disconnected_acrtc
->stream
;
2682 disconnected_acrtc
->stream
= new_stream
;
2683 disconnected_acrtc
->enabled
= true;
2684 disconnected_acrtc
->hw_mode
= disconnected_acrtc
->base
.state
->mode
;
2686 commit_streams_count
= 0;
2688 list_for_each_entry(crtc
, &dev
->mode_config
.crtc_list
, head
) {
2689 struct amdgpu_crtc
*acrtc
= to_amdgpu_crtc(crtc
);
2691 if (acrtc
->stream
) {
2692 commit_streams
[commit_streams_count
] = acrtc
->stream
;
2693 ++commit_streams_count
;
2697 /* DC is optimized not to do anything if 'streams' didn't change. */
2698 if (!dc_commit_streams(dc
, commit_streams
,
2699 commit_streams_count
)) {
2700 DRM_INFO("Failed to restore connector state!\n");
2701 dc_stream_release(disconnected_acrtc
->stream
);
2702 disconnected_acrtc
->stream
= current_stream
;
2703 manage_dm_interrupts(adev
, disconnected_acrtc
, true);
2707 if (adev
->dm
.freesync_module
) {
2708 mod_freesync_remove_stream(adev
->dm
.freesync_module
,
2711 mod_freesync_add_stream(adev
->dm
.freesync_module
,
2712 new_stream
, &aconnector
->caps
);
2715 list_for_each_entry(crtc
, &dev
->mode_config
.crtc_list
, head
) {
2716 struct amdgpu_crtc
*acrtc
= to_amdgpu_crtc(crtc
);
2718 if (acrtc
->stream
!= NULL
) {
2720 dc_stream_get_status(acrtc
->stream
)->primary_otg_inst
;
2724 dc_stream_release(current_stream
);
2726 dm_dc_surface_commit(dc
, &disconnected_acrtc
->base
);
2728 manage_dm_interrupts(adev
, disconnected_acrtc
, true);
2729 dm_crtc_cursor_reset(&disconnected_acrtc
->base
);
2734 static uint32_t add_val_sets_surface(
2735 struct dc_validation_set
*val_sets
,
2737 const struct dc_stream
*stream
,
2738 const struct dc_surface
*surface
)
2742 while (i
< set_count
) {
2743 if (val_sets
[i
].stream
== stream
)
2748 val_sets
[i
].surfaces
[val_sets
[i
].surface_count
] = surface
;
2749 val_sets
[i
].surface_count
++;
2751 return val_sets
[i
].surface_count
;
2754 static uint32_t update_in_val_sets_stream(
2755 struct dc_validation_set
*val_sets
,
2756 struct drm_crtc
**crtcs
,
2758 const struct dc_stream
*old_stream
,
2759 const struct dc_stream
*new_stream
,
2760 struct drm_crtc
*crtc
)
2764 while (i
< set_count
) {
2765 if (val_sets
[i
].stream
== old_stream
)
2770 val_sets
[i
].stream
= new_stream
;
2773 if (i
== set_count
) {
2774 /* nothing found. add new one to the end */
2775 return set_count
+ 1;
2781 static uint32_t remove_from_val_sets(
2782 struct dc_validation_set
*val_sets
,
2784 const struct dc_stream
*stream
)
2788 for (i
= 0; i
< set_count
; i
++)
2789 if (val_sets
[i
].stream
== stream
)
2792 if (i
== set_count
) {
2799 for (; i
< set_count
; i
++) {
2800 val_sets
[i
] = val_sets
[i
+ 1];
2806 int amdgpu_dm_atomic_check(struct drm_device
*dev
,
2807 struct drm_atomic_state
*state
)
2809 struct drm_crtc
*crtc
;
2810 struct drm_crtc_state
*crtc_state
;
2811 struct drm_plane
*plane
;
2812 struct drm_plane_state
*plane_state
;
2816 int new_stream_count
;
2817 struct dc_validation_set set
[MAX_STREAMS
] = {{ 0 }};
2818 struct dc_stream
*new_streams
[MAX_STREAMS
] = { 0 };
2819 struct drm_crtc
*crtc_set
[MAX_STREAMS
] = { 0 };
2820 struct amdgpu_device
*adev
= dev
->dev_private
;
2821 struct dc
*dc
= adev
->dm
.dc
;
2822 bool need_to_validate
= false;
2824 ret
= drm_atomic_helper_check(dev
, state
);
2827 DRM_ERROR("Atomic state validation failed with error :%d !\n",
2834 /* copy existing configuration */
2835 new_stream_count
= 0;
2837 list_for_each_entry(crtc
, &dev
->mode_config
.crtc_list
, head
) {
2839 struct amdgpu_crtc
*acrtc
= to_amdgpu_crtc(crtc
);
2841 if (acrtc
->stream
) {
2842 set
[set_count
].stream
= acrtc
->stream
;
2843 crtc_set
[set_count
] = crtc
;
2848 /* update changed items */
2849 for_each_crtc_in_state(state
, crtc
, crtc_state
, i
) {
2850 struct amdgpu_crtc
*acrtc
= NULL
;
2851 struct amdgpu_connector
*aconnector
= NULL
;
2852 enum dm_commit_action action
;
2854 acrtc
= to_amdgpu_crtc(crtc
);
2856 aconnector
= amdgpu_dm_find_first_crct_matching_connector(state
, crtc
, true);
2858 action
= get_dm_commit_action(crtc_state
);
2861 case DM_COMMIT_ACTION_DPMS_ON
:
2862 case DM_COMMIT_ACTION_SET
: {
2863 struct dc_stream
*new_stream
= NULL
;
2864 struct drm_connector_state
*conn_state
= NULL
;
2865 struct dm_connector_state
*dm_state
= NULL
;
2868 conn_state
= drm_atomic_get_connector_state(state
, &aconnector
->base
);
2869 if (IS_ERR(conn_state
))
2871 dm_state
= to_dm_connector_state(conn_state
);
2874 new_stream
= create_stream_for_sink(aconnector
, &crtc_state
->mode
, dm_state
);
2877 * we can have no stream on ACTION_SET if a display
2878 * was disconnected during S3, in this case it not and
2879 * error, the OS will be updated after detection, and
2880 * do the right thing on next atomic commit
2883 DRM_DEBUG_KMS("%s: Failed to create new stream for crtc %d\n",
2884 __func__
, acrtc
->base
.base
.id
);
2888 new_streams
[new_stream_count
] = new_stream
;
2889 set_count
= update_in_val_sets_stream(
2898 need_to_validate
= true;
2902 case DM_COMMIT_ACTION_NOTHING
: {
2903 const struct drm_connector
*drm_connector
= NULL
;
2904 struct drm_connector_state
*conn_state
= NULL
;
2905 struct dm_connector_state
*dm_state
= NULL
;
2906 struct dm_connector_state
*old_dm_state
= NULL
;
2907 struct dc_stream
*new_stream
;
2912 for_each_connector_in_state(
2913 state
, drm_connector
, conn_state
, j
) {
2914 if (&aconnector
->base
== drm_connector
)
2918 old_dm_state
= to_dm_connector_state(drm_connector
->state
);
2919 dm_state
= to_dm_connector_state(conn_state
);
2921 /* Support underscan adjustment*/
2922 if (!is_scaling_state_different(dm_state
, old_dm_state
))
2925 new_stream
= create_stream_for_sink(aconnector
, &crtc_state
->mode
, dm_state
);
2928 DRM_ERROR("%s: Failed to create new stream for crtc %d\n",
2929 __func__
, acrtc
->base
.base
.id
);
2933 new_streams
[new_stream_count
] = new_stream
;
2934 set_count
= update_in_val_sets_stream(
2943 need_to_validate
= true;
2947 case DM_COMMIT_ACTION_DPMS_OFF
:
2948 case DM_COMMIT_ACTION_RESET
:
2949 /* i.e. reset mode */
2950 if (acrtc
->stream
) {
2951 set_count
= remove_from_val_sets(
2960 * TODO revisit when removing commit action
2961 * and looking at atomic flags directly
2964 /* commit needs planes right now (for gamma, eg.) */
2965 /* TODO rework commit to chack crtc for gamma change */
2966 ret
= drm_atomic_add_affected_planes(state
, crtc
);
2971 for (i
= 0; i
< set_count
; i
++) {
2972 for_each_plane_in_state(state
, plane
, plane_state
, j
) {
2973 struct drm_plane_state
*old_plane_state
= plane
->state
;
2974 struct drm_crtc
*crtc
= plane_state
->crtc
;
2975 struct drm_framebuffer
*fb
= plane_state
->fb
;
2976 struct drm_connector
*connector
;
2977 struct dm_connector_state
*dm_state
= NULL
;
2978 enum dm_commit_action action
;
2979 struct drm_crtc_state
*crtc_state
;
2982 if (!fb
|| !crtc
|| crtc_set
[i
] != crtc
||
2983 !crtc
->state
->planes_changed
|| !crtc
->state
->active
)
2986 action
= get_dm_commit_action(crtc
->state
);
2988 /* Surfaces are created under two scenarios:
2989 * 1. This commit is not a page flip.
2990 * 2. This commit is a page flip, and streams are created.
2992 crtc_state
= drm_atomic_get_crtc_state(state
, crtc
);
2993 if (!page_flip_needed(plane_state
, old_plane_state
,
2994 crtc_state
->event
, true) ||
2995 action
== DM_COMMIT_ACTION_DPMS_ON
||
2996 action
== DM_COMMIT_ACTION_SET
) {
2997 struct dc_surface
*surface
;
2999 list_for_each_entry(connector
,
3000 &dev
->mode_config
.connector_list
, head
) {
3001 if (connector
->state
->crtc
== crtc
) {
3002 dm_state
= to_dm_connector_state(
3009 * This situation happens in the following case:
3010 * we are about to get set mode for connector who's only
3011 * possible crtc (in encoder crtc mask) is used by
3012 * another connector, that is why it will try to
3013 * re-assing crtcs in order to make configuration
3014 * supported. For our implementation we need to make all
3015 * encoders support all crtcs, then this issue will
3016 * never arise again. But to guard code from this issue
3019 * Also it should be needed when used with actual
3020 * drm_atomic_commit ioctl in future
3025 surface
= dc_create_surface(dc
);
3026 fill_plane_attributes(
3027 crtc
->dev
->dev_private
,
3032 add_val_sets_surface(
3038 need_to_validate
= true;
3043 if (need_to_validate
== false || set_count
== 0 ||
3044 dc_validate_resources(dc
, set
, set_count
))
3047 for (i
= 0; i
< set_count
; i
++) {
3048 for (j
= 0; j
< set
[i
].surface_count
; j
++) {
3049 dc_surface_release(set
[i
].surfaces
[j
]);
3052 for (i
= 0; i
< new_stream_count
; i
++)
3053 dc_stream_release(new_streams
[i
]);
3056 DRM_ERROR("Atomic check failed.\n");
3061 static bool is_dp_capable_without_timing_msa(
3063 struct amdgpu_connector
*amdgpu_connector
)
3066 bool capable
= false;
3067 if (amdgpu_connector
->dc_link
&&
3068 dc_read_dpcd(dc
, amdgpu_connector
->dc_link
->link_index
,
3069 DP_DOWN_STREAM_PORT_COUNT
,
3070 &dpcd_data
, sizeof(dpcd_data
)) )
3071 capable
= (dpcd_data
& DP_MSA_TIMING_PAR_IGNORED
) ? true:false;
3075 void amdgpu_dm_add_sink_to_freesync_module(
3076 struct drm_connector
*connector
,
3080 uint64_t val_capable
;
3081 bool edid_check_required
;
3082 struct detailed_timing
*timing
;
3083 struct detailed_non_pixel
*data
;
3084 struct detailed_data_monitor_range
*range
;
3085 struct amdgpu_connector
*amdgpu_connector
=
3086 to_amdgpu_connector(connector
);
3088 struct drm_device
*dev
= connector
->dev
;
3089 struct amdgpu_device
*adev
= dev
->dev_private
;
3090 edid_check_required
= false;
3091 if (!amdgpu_connector
->dc_sink
) {
3092 DRM_ERROR("dc_sink NULL, could not add free_sync module.\n");
3095 if (!adev
->dm
.freesync_module
)
3098 * if edid non zero restrict freesync only for dp and edp
3101 if (amdgpu_connector
->dc_sink
->sink_signal
== SIGNAL_TYPE_DISPLAY_PORT
3102 || amdgpu_connector
->dc_sink
->sink_signal
== SIGNAL_TYPE_EDP
) {
3103 edid_check_required
= is_dp_capable_without_timing_msa(
3109 if (edid_check_required
== true && (edid
->version
> 1 ||
3110 (edid
->version
== 1 && edid
->revision
> 1))) {
3111 for (i
= 0; i
< 4; i
++) {
3113 timing
= &edid
->detailed_timings
[i
];
3114 data
= &timing
->data
.other_data
;
3115 range
= &data
->data
.range
;
3117 * Check if monitor has continuous frequency mode
3119 if (data
->type
!= EDID_DETAIL_MONITOR_RANGE
)
3122 * Check for flag range limits only. If flag == 1 then
3123 * no additional timing information provided.
3124 * Default GTF, GTF Secondary curve and CVT are not
3127 if (range
->flags
!= 1)
3130 amdgpu_connector
->min_vfreq
= range
->min_vfreq
;
3131 amdgpu_connector
->max_vfreq
= range
->max_vfreq
;
3132 amdgpu_connector
->pixel_clock_mhz
=
3133 range
->pixel_clock_mhz
* 10;
3137 if (amdgpu_connector
->max_vfreq
-
3138 amdgpu_connector
->min_vfreq
> 10) {
3139 amdgpu_connector
->caps
.supported
= true;
3140 amdgpu_connector
->caps
.min_refresh_in_micro_hz
=
3141 amdgpu_connector
->min_vfreq
* 1000000;
3142 amdgpu_connector
->caps
.max_refresh_in_micro_hz
=
3143 amdgpu_connector
->max_vfreq
* 1000000;
3149 * TODO figure out how to notify user-mode or DRM of freesync caps
3150 * once we figure out how to deal with freesync in an upstreamable
3156 void amdgpu_dm_remove_sink_from_freesync_module(
3157 struct drm_connector
*connector
)
3160 * TODO fill in once we figure out how to deal with freesync in
3161 * an upstreamable fashion