1 // SPDX-License-Identifier: MIT
3 * Copyright 2022 Advanced Micro Devices, Inc.
5 * Permission is hereby granted, free of charge, to any person obtaining a
6 * copy of this software and associated documentation files (the "Software"),
7 * to deal in the Software without restriction, including without limitation
8 * the rights to use, copy, modify, merge, publish, distribute, sublicense,
9 * and/or sell copies of the Software, and to permit persons to whom the
10 * Software is furnished to do so, subject to the following conditions:
12 * The above copyright notice and this permission notice shall be included in
13 * all copies or substantial portions of the Software.
15 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16 * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17 * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
18 * THE COPYRIGHT HOLDER(S) OR AUTHOR(S) BE LIABLE FOR ANY CLAIM, DAMAGES OR
19 * OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE,
20 * ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR
21 * OTHER DEALINGS IN THE SOFTWARE.
27 #include <drm/drm_atomic_helper.h>
28 #include <drm/drm_blend.h>
29 #include "drm/drm_framebuffer.h"
30 #include <drm/drm_gem_atomic_helper.h>
31 #include <drm/drm_plane_helper.h>
32 #include <drm/drm_gem_framebuffer_helper.h>
33 #include <drm/drm_fourcc.h>
36 #include "dal_asic_id.h"
37 #include "amdgpu_display.h"
38 #include "amdgpu_dm_trace.h"
39 #include "amdgpu_dm_plane.h"
40 #include "gc/gc_11_0_0_offset.h"
41 #include "gc/gc_11_0_0_sh_mask.h"
44 * TODO: these are currently initialized to rgb formats only.
45 * For future use cases we should either initialize them dynamically based on
46 * plane capabilities, or initialize this array to all formats, so internal drm
47 * check will succeed, and let DC implement proper check
49 static const uint32_t rgb_formats[] = {
53 DRM_FORMAT_XRGB2101010,
54 DRM_FORMAT_XBGR2101010,
55 DRM_FORMAT_ARGB2101010,
56 DRM_FORMAT_ABGR2101010,
57 DRM_FORMAT_XRGB16161616,
58 DRM_FORMAT_XBGR16161616,
59 DRM_FORMAT_ARGB16161616,
60 DRM_FORMAT_ABGR16161616,
66 static const uint32_t overlay_formats[] = {
78 static const uint32_t video_formats[] = {
84 static const u32 cursor_formats[] = {
88 enum dm_micro_swizzle {
95 const struct drm_format_info *amdgpu_dm_plane_get_format_info(const struct drm_mode_fb_cmd2 *cmd)
97 return amdgpu_lookup_format_info(cmd->pixel_format, cmd->modifier[0]);
100 void amdgpu_dm_plane_fill_blending_from_plane_state(const struct drm_plane_state *plane_state,
101 bool *per_pixel_alpha, bool *pre_multiplied_alpha,
102 bool *global_alpha, int *global_alpha_value)
104 *per_pixel_alpha = false;
105 *pre_multiplied_alpha = true;
106 *global_alpha = false;
107 *global_alpha_value = 0xff;
110 if (plane_state->pixel_blend_mode == DRM_MODE_BLEND_PREMULTI ||
111 plane_state->pixel_blend_mode == DRM_MODE_BLEND_COVERAGE) {
112 static const uint32_t alpha_formats[] = {
116 DRM_FORMAT_ARGB2101010,
117 DRM_FORMAT_ABGR2101010,
118 DRM_FORMAT_ARGB16161616,
119 DRM_FORMAT_ABGR16161616,
120 DRM_FORMAT_ARGB16161616F,
122 uint32_t format = plane_state->fb->format->format;
125 for (i = 0; i < ARRAY_SIZE(alpha_formats); ++i) {
126 if (format == alpha_formats[i]) {
127 *per_pixel_alpha = true;
132 if (*per_pixel_alpha && plane_state->pixel_blend_mode == DRM_MODE_BLEND_COVERAGE)
133 *pre_multiplied_alpha = false;
136 if (plane_state->alpha < 0xffff) {
137 *global_alpha = true;
138 *global_alpha_value = plane_state->alpha >> 8;
142 static void amdgpu_dm_plane_add_modifier(uint64_t **mods, uint64_t *size, uint64_t *cap, uint64_t mod)
147 if (*cap - *size < 1) {
148 uint64_t new_cap = *cap * 2;
149 uint64_t *new_mods = kmalloc(new_cap * sizeof(uint64_t), GFP_KERNEL);
157 memcpy(new_mods, *mods, sizeof(uint64_t) * *size);
163 (*mods)[*size] = mod;
167 static bool amdgpu_dm_plane_modifier_has_dcc(uint64_t modifier)
169 return IS_AMD_FMT_MOD(modifier) && AMD_FMT_MOD_GET(DCC, modifier);
172 static unsigned int amdgpu_dm_plane_modifier_gfx9_swizzle_mode(uint64_t modifier)
174 if (modifier == DRM_FORMAT_MOD_LINEAR)
177 return AMD_FMT_MOD_GET(TILE, modifier);
180 static void amdgpu_dm_plane_fill_gfx8_tiling_info_from_flags(struct dc_tiling_info *tiling_info,
181 uint64_t tiling_flags)
183 /* Fill GFX8 params */
184 if (AMDGPU_TILING_GET(tiling_flags, ARRAY_MODE) == DC_ARRAY_2D_TILED_THIN1) {
185 unsigned int bankw, bankh, mtaspect, tile_split, num_banks;
187 bankw = AMDGPU_TILING_GET(tiling_flags, BANK_WIDTH);
188 bankh = AMDGPU_TILING_GET(tiling_flags, BANK_HEIGHT);
189 mtaspect = AMDGPU_TILING_GET(tiling_flags, MACRO_TILE_ASPECT);
190 tile_split = AMDGPU_TILING_GET(tiling_flags, TILE_SPLIT);
191 num_banks = AMDGPU_TILING_GET(tiling_flags, NUM_BANKS);
193 tiling_info->gfxversion = DcGfxVersion8;
194 /* XXX fix me for VI */
195 tiling_info->gfx8.num_banks = num_banks;
196 tiling_info->gfx8.array_mode =
197 DC_ARRAY_2D_TILED_THIN1;
198 tiling_info->gfx8.tile_split = tile_split;
199 tiling_info->gfx8.bank_width = bankw;
200 tiling_info->gfx8.bank_height = bankh;
201 tiling_info->gfx8.tile_aspect = mtaspect;
202 tiling_info->gfx8.tile_mode =
203 DC_ADDR_SURF_MICRO_TILING_DISPLAY;
204 } else if (AMDGPU_TILING_GET(tiling_flags, ARRAY_MODE)
205 == DC_ARRAY_1D_TILED_THIN1) {
206 tiling_info->gfx8.array_mode = DC_ARRAY_1D_TILED_THIN1;
209 tiling_info->gfx8.pipe_config =
210 AMDGPU_TILING_GET(tiling_flags, PIPE_CONFIG);
213 static void amdgpu_dm_plane_fill_gfx9_tiling_info_from_device(const struct amdgpu_device *adev,
214 struct dc_tiling_info *tiling_info)
216 /* Fill GFX9 params */
217 tiling_info->gfx9.num_pipes =
218 adev->gfx.config.gb_addr_config_fields.num_pipes;
219 tiling_info->gfx9.num_banks =
220 adev->gfx.config.gb_addr_config_fields.num_banks;
221 tiling_info->gfx9.pipe_interleave =
222 adev->gfx.config.gb_addr_config_fields.pipe_interleave_size;
223 tiling_info->gfx9.num_shader_engines =
224 adev->gfx.config.gb_addr_config_fields.num_se;
225 tiling_info->gfx9.max_compressed_frags =
226 adev->gfx.config.gb_addr_config_fields.max_compress_frags;
227 tiling_info->gfx9.num_rb_per_se =
228 adev->gfx.config.gb_addr_config_fields.num_rb_per_se;
229 tiling_info->gfx9.shaderEnable = 1;
230 if (amdgpu_ip_version(adev, GC_HWIP, 0) >= IP_VERSION(10, 3, 0))
231 tiling_info->gfx9.num_pkrs = adev->gfx.config.gb_addr_config_fields.num_pkrs;
234 static void amdgpu_dm_plane_fill_gfx9_tiling_info_from_modifier(const struct amdgpu_device *adev,
235 struct dc_tiling_info *tiling_info,
238 unsigned int mod_bank_xor_bits = AMD_FMT_MOD_GET(BANK_XOR_BITS, modifier);
239 unsigned int mod_pipe_xor_bits = AMD_FMT_MOD_GET(PIPE_XOR_BITS, modifier);
240 unsigned int pkrs_log2 = AMD_FMT_MOD_GET(PACKERS, modifier);
241 unsigned int pipes_log2;
243 pipes_log2 = min(5u, mod_pipe_xor_bits);
245 amdgpu_dm_plane_fill_gfx9_tiling_info_from_device(adev, tiling_info);
247 if (!IS_AMD_FMT_MOD(modifier))
250 tiling_info->gfx9.num_pipes = 1u << pipes_log2;
251 tiling_info->gfx9.num_shader_engines = 1u << (mod_pipe_xor_bits - pipes_log2);
253 if (adev->family >= AMDGPU_FAMILY_NV) {
254 tiling_info->gfx9.num_pkrs = 1u << pkrs_log2;
256 tiling_info->gfx9.num_banks = 1u << mod_bank_xor_bits;
258 /* for DCC we know it isn't rb aligned, so rb_per_se doesn't matter. */
262 static int amdgpu_dm_plane_validate_dcc(struct amdgpu_device *adev,
263 const enum surface_pixel_format format,
264 const enum dc_rotation_angle rotation,
265 const struct dc_tiling_info *tiling_info,
266 const struct dc_plane_dcc_param *dcc,
267 const struct dc_plane_address *address,
268 const struct plane_size *plane_size)
270 struct dc *dc = adev->dm.dc;
271 struct dc_dcc_surface_param input;
272 struct dc_surface_dcc_cap output;
274 memset(&input, 0, sizeof(input));
275 memset(&output, 0, sizeof(output));
280 if (format >= SURFACE_PIXEL_FORMAT_VIDEO_BEGIN ||
281 !dc->cap_funcs.get_dcc_compression_cap)
284 input.format = format;
285 input.surface_size.width = plane_size->surface_size.width;
286 input.surface_size.height = plane_size->surface_size.height;
287 input.swizzle_mode = tiling_info->gfx9.swizzle;
289 if (rotation == ROTATION_ANGLE_0 || rotation == ROTATION_ANGLE_180)
290 input.scan = SCAN_DIRECTION_HORIZONTAL;
291 else if (rotation == ROTATION_ANGLE_90 || rotation == ROTATION_ANGLE_270)
292 input.scan = SCAN_DIRECTION_VERTICAL;
294 if (!dc->cap_funcs.get_dcc_compression_cap(dc, &input, &output))
300 if (dcc->independent_64b_blks == 0 &&
301 output.grph.rgb.independent_64b_blks != 0)
307 static int amdgpu_dm_plane_fill_gfx9_plane_attributes_from_modifiers(struct amdgpu_device *adev,
308 const struct amdgpu_framebuffer *afb,
309 const enum surface_pixel_format format,
310 const enum dc_rotation_angle rotation,
311 const struct plane_size *plane_size,
312 struct dc_tiling_info *tiling_info,
313 struct dc_plane_dcc_param *dcc,
314 struct dc_plane_address *address)
316 const uint64_t modifier = afb->base.modifier;
319 amdgpu_dm_plane_fill_gfx9_tiling_info_from_modifier(adev, tiling_info, modifier);
320 tiling_info->gfx9.swizzle = amdgpu_dm_plane_modifier_gfx9_swizzle_mode(modifier);
321 tiling_info->gfxversion = DcGfxVersion9;
323 if (amdgpu_dm_plane_modifier_has_dcc(modifier)) {
324 uint64_t dcc_address = afb->address + afb->base.offsets[1];
325 bool independent_64b_blks = AMD_FMT_MOD_GET(DCC_INDEPENDENT_64B, modifier);
326 bool independent_128b_blks = AMD_FMT_MOD_GET(DCC_INDEPENDENT_128B, modifier);
329 dcc->meta_pitch = afb->base.pitches[1];
330 dcc->independent_64b_blks = independent_64b_blks;
331 if (AMD_FMT_MOD_GET(TILE_VERSION, modifier) >= AMD_FMT_MOD_TILE_VER_GFX10_RBPLUS) {
332 if (independent_64b_blks && independent_128b_blks)
333 dcc->dcc_ind_blk = hubp_ind_block_64b_no_128bcl;
334 else if (independent_128b_blks)
335 dcc->dcc_ind_blk = hubp_ind_block_128b;
336 else if (independent_64b_blks && !independent_128b_blks)
337 dcc->dcc_ind_blk = hubp_ind_block_64b;
339 dcc->dcc_ind_blk = hubp_ind_block_unconstrained;
341 if (independent_64b_blks)
342 dcc->dcc_ind_blk = hubp_ind_block_64b;
344 dcc->dcc_ind_blk = hubp_ind_block_unconstrained;
347 address->grph.meta_addr.low_part = lower_32_bits(dcc_address);
348 address->grph.meta_addr.high_part = upper_32_bits(dcc_address);
351 ret = amdgpu_dm_plane_validate_dcc(adev, format, rotation, tiling_info, dcc, address, plane_size);
353 drm_dbg_kms(adev_to_drm(adev), "amdgpu_dm_plane_validate_dcc: returned error: %d\n", ret);
358 static int amdgpu_dm_plane_fill_gfx12_plane_attributes_from_modifiers(struct amdgpu_device *adev,
359 const struct amdgpu_framebuffer *afb,
360 const enum surface_pixel_format format,
361 const enum dc_rotation_angle rotation,
362 const struct plane_size *plane_size,
363 struct dc_tiling_info *tiling_info,
364 struct dc_plane_dcc_param *dcc,
365 struct dc_plane_address *address)
367 const uint64_t modifier = afb->base.modifier;
370 /* TODO: Most of this function shouldn't be needed on GFX12. */
371 amdgpu_dm_plane_fill_gfx9_tiling_info_from_device(adev, tiling_info);
373 tiling_info->gfx9.swizzle = amdgpu_dm_plane_modifier_gfx9_swizzle_mode(modifier);
374 tiling_info->gfxversion = DcGfxAddr3;
376 if (amdgpu_dm_plane_modifier_has_dcc(modifier)) {
377 int max_compressed_block = AMD_FMT_MOD_GET(DCC_MAX_COMPRESSED_BLOCK, modifier);
380 dcc->independent_64b_blks = max_compressed_block == 0;
382 if (max_compressed_block == 0)
383 dcc->dcc_ind_blk = hubp_ind_block_64b;
384 else if (max_compressed_block == 1)
385 dcc->dcc_ind_blk = hubp_ind_block_128b;
387 dcc->dcc_ind_blk = hubp_ind_block_unconstrained;
390 /* TODO: This seems wrong because there is no DCC plane on GFX12. */
391 ret = amdgpu_dm_plane_validate_dcc(adev, format, rotation, tiling_info, dcc, address, plane_size);
393 drm_dbg_kms(adev_to_drm(adev), "amdgpu_dm_plane_validate_dcc: returned error: %d\n", ret);
398 static void amdgpu_dm_plane_add_gfx10_1_modifiers(const struct amdgpu_device *adev,
403 int pipe_xor_bits = ilog2(adev->gfx.config.gb_addr_config_fields.num_pipes);
405 amdgpu_dm_plane_add_modifier(mods, size, capacity, AMD_FMT_MOD |
406 AMD_FMT_MOD_SET(TILE, AMD_FMT_MOD_TILE_GFX9_64K_R_X) |
407 AMD_FMT_MOD_SET(TILE_VERSION, AMD_FMT_MOD_TILE_VER_GFX10) |
408 AMD_FMT_MOD_SET(PIPE_XOR_BITS, pipe_xor_bits) |
409 AMD_FMT_MOD_SET(DCC, 1) |
410 AMD_FMT_MOD_SET(DCC_CONSTANT_ENCODE, 1) |
411 AMD_FMT_MOD_SET(DCC_INDEPENDENT_64B, 1) |
412 AMD_FMT_MOD_SET(DCC_MAX_COMPRESSED_BLOCK, AMD_FMT_MOD_DCC_BLOCK_64B));
414 amdgpu_dm_plane_add_modifier(mods, size, capacity, AMD_FMT_MOD |
415 AMD_FMT_MOD_SET(TILE, AMD_FMT_MOD_TILE_GFX9_64K_R_X) |
416 AMD_FMT_MOD_SET(TILE_VERSION, AMD_FMT_MOD_TILE_VER_GFX10) |
417 AMD_FMT_MOD_SET(PIPE_XOR_BITS, pipe_xor_bits) |
418 AMD_FMT_MOD_SET(DCC, 1) |
419 AMD_FMT_MOD_SET(DCC_RETILE, 1) |
420 AMD_FMT_MOD_SET(DCC_CONSTANT_ENCODE, 1) |
421 AMD_FMT_MOD_SET(DCC_INDEPENDENT_64B, 1) |
422 AMD_FMT_MOD_SET(DCC_MAX_COMPRESSED_BLOCK, AMD_FMT_MOD_DCC_BLOCK_64B));
424 amdgpu_dm_plane_add_modifier(mods, size, capacity, AMD_FMT_MOD |
425 AMD_FMT_MOD_SET(TILE, AMD_FMT_MOD_TILE_GFX9_64K_R_X) |
426 AMD_FMT_MOD_SET(TILE_VERSION, AMD_FMT_MOD_TILE_VER_GFX10) |
427 AMD_FMT_MOD_SET(PIPE_XOR_BITS, pipe_xor_bits));
429 amdgpu_dm_plane_add_modifier(mods, size, capacity, AMD_FMT_MOD |
430 AMD_FMT_MOD_SET(TILE, AMD_FMT_MOD_TILE_GFX9_64K_S_X) |
431 AMD_FMT_MOD_SET(TILE_VERSION, AMD_FMT_MOD_TILE_VER_GFX10) |
432 AMD_FMT_MOD_SET(PIPE_XOR_BITS, pipe_xor_bits));
435 /* Only supported for 64bpp, will be filtered in amdgpu_dm_plane_format_mod_supported */
436 amdgpu_dm_plane_add_modifier(mods, size, capacity, AMD_FMT_MOD |
437 AMD_FMT_MOD_SET(TILE, AMD_FMT_MOD_TILE_GFX9_64K_D) |
438 AMD_FMT_MOD_SET(TILE_VERSION, AMD_FMT_MOD_TILE_VER_GFX9));
440 amdgpu_dm_plane_add_modifier(mods, size, capacity, AMD_FMT_MOD |
441 AMD_FMT_MOD_SET(TILE, AMD_FMT_MOD_TILE_GFX9_64K_S) |
442 AMD_FMT_MOD_SET(TILE_VERSION, AMD_FMT_MOD_TILE_VER_GFX9));
445 static void amdgpu_dm_plane_add_gfx9_modifiers(const struct amdgpu_device *adev,
450 int pipes = ilog2(adev->gfx.config.gb_addr_config_fields.num_pipes);
451 int pipe_xor_bits = min(8, pipes +
452 ilog2(adev->gfx.config.gb_addr_config_fields.num_se));
453 int bank_xor_bits = min(8 - pipe_xor_bits,
454 ilog2(adev->gfx.config.gb_addr_config_fields.num_banks));
455 int rb = ilog2(adev->gfx.config.gb_addr_config_fields.num_se) +
456 ilog2(adev->gfx.config.gb_addr_config_fields.num_rb_per_se);
459 if (adev->family == AMDGPU_FAMILY_RV) {
460 /* Raven2 and later */
461 bool has_constant_encode = adev->asic_type > CHIP_RAVEN || adev->external_rev_id >= 0x81;
464 * No _D DCC swizzles yet because we only allow 32bpp, which
465 * doesn't support _D on DCN
468 if (has_constant_encode) {
469 amdgpu_dm_plane_add_modifier(mods, size, capacity, AMD_FMT_MOD |
470 AMD_FMT_MOD_SET(TILE, AMD_FMT_MOD_TILE_GFX9_64K_S_X) |
471 AMD_FMT_MOD_SET(TILE_VERSION, AMD_FMT_MOD_TILE_VER_GFX9) |
472 AMD_FMT_MOD_SET(PIPE_XOR_BITS, pipe_xor_bits) |
473 AMD_FMT_MOD_SET(BANK_XOR_BITS, bank_xor_bits) |
474 AMD_FMT_MOD_SET(DCC, 1) |
475 AMD_FMT_MOD_SET(DCC_INDEPENDENT_64B, 1) |
476 AMD_FMT_MOD_SET(DCC_MAX_COMPRESSED_BLOCK, AMD_FMT_MOD_DCC_BLOCK_64B) |
477 AMD_FMT_MOD_SET(DCC_CONSTANT_ENCODE, 1));
480 amdgpu_dm_plane_add_modifier(mods, size, capacity, AMD_FMT_MOD |
481 AMD_FMT_MOD_SET(TILE, AMD_FMT_MOD_TILE_GFX9_64K_S_X) |
482 AMD_FMT_MOD_SET(TILE_VERSION, AMD_FMT_MOD_TILE_VER_GFX9) |
483 AMD_FMT_MOD_SET(PIPE_XOR_BITS, pipe_xor_bits) |
484 AMD_FMT_MOD_SET(BANK_XOR_BITS, bank_xor_bits) |
485 AMD_FMT_MOD_SET(DCC, 1) |
486 AMD_FMT_MOD_SET(DCC_INDEPENDENT_64B, 1) |
487 AMD_FMT_MOD_SET(DCC_MAX_COMPRESSED_BLOCK, AMD_FMT_MOD_DCC_BLOCK_64B) |
488 AMD_FMT_MOD_SET(DCC_CONSTANT_ENCODE, 0));
490 if (has_constant_encode) {
491 amdgpu_dm_plane_add_modifier(mods, size, capacity, AMD_FMT_MOD |
492 AMD_FMT_MOD_SET(TILE, AMD_FMT_MOD_TILE_GFX9_64K_S_X) |
493 AMD_FMT_MOD_SET(TILE_VERSION, AMD_FMT_MOD_TILE_VER_GFX9) |
494 AMD_FMT_MOD_SET(PIPE_XOR_BITS, pipe_xor_bits) |
495 AMD_FMT_MOD_SET(BANK_XOR_BITS, bank_xor_bits) |
496 AMD_FMT_MOD_SET(DCC, 1) |
497 AMD_FMT_MOD_SET(DCC_RETILE, 1) |
498 AMD_FMT_MOD_SET(DCC_INDEPENDENT_64B, 1) |
499 AMD_FMT_MOD_SET(DCC_MAX_COMPRESSED_BLOCK, AMD_FMT_MOD_DCC_BLOCK_64B) |
500 AMD_FMT_MOD_SET(DCC_CONSTANT_ENCODE, 1) |
501 AMD_FMT_MOD_SET(RB, rb) |
502 AMD_FMT_MOD_SET(PIPE, pipes));
505 amdgpu_dm_plane_add_modifier(mods, size, capacity, AMD_FMT_MOD |
506 AMD_FMT_MOD_SET(TILE, AMD_FMT_MOD_TILE_GFX9_64K_S_X) |
507 AMD_FMT_MOD_SET(TILE_VERSION, AMD_FMT_MOD_TILE_VER_GFX9) |
508 AMD_FMT_MOD_SET(PIPE_XOR_BITS, pipe_xor_bits) |
509 AMD_FMT_MOD_SET(BANK_XOR_BITS, bank_xor_bits) |
510 AMD_FMT_MOD_SET(DCC, 1) |
511 AMD_FMT_MOD_SET(DCC_RETILE, 1) |
512 AMD_FMT_MOD_SET(DCC_INDEPENDENT_64B, 1) |
513 AMD_FMT_MOD_SET(DCC_MAX_COMPRESSED_BLOCK, AMD_FMT_MOD_DCC_BLOCK_64B) |
514 AMD_FMT_MOD_SET(DCC_CONSTANT_ENCODE, 0) |
515 AMD_FMT_MOD_SET(RB, rb) |
516 AMD_FMT_MOD_SET(PIPE, pipes));
520 * Only supported for 64bpp on Raven, will be filtered on format in
521 * amdgpu_dm_plane_format_mod_supported.
523 amdgpu_dm_plane_add_modifier(mods, size, capacity, AMD_FMT_MOD |
524 AMD_FMT_MOD_SET(TILE, AMD_FMT_MOD_TILE_GFX9_64K_D_X) |
525 AMD_FMT_MOD_SET(TILE_VERSION, AMD_FMT_MOD_TILE_VER_GFX9) |
526 AMD_FMT_MOD_SET(PIPE_XOR_BITS, pipe_xor_bits) |
527 AMD_FMT_MOD_SET(BANK_XOR_BITS, bank_xor_bits));
529 if (adev->family == AMDGPU_FAMILY_RV) {
530 amdgpu_dm_plane_add_modifier(mods, size, capacity, AMD_FMT_MOD |
531 AMD_FMT_MOD_SET(TILE, AMD_FMT_MOD_TILE_GFX9_64K_S_X) |
532 AMD_FMT_MOD_SET(TILE_VERSION, AMD_FMT_MOD_TILE_VER_GFX9) |
533 AMD_FMT_MOD_SET(PIPE_XOR_BITS, pipe_xor_bits) |
534 AMD_FMT_MOD_SET(BANK_XOR_BITS, bank_xor_bits));
538 * Only supported for 64bpp on Raven, will be filtered on format in
539 * amdgpu_dm_plane_format_mod_supported.
541 amdgpu_dm_plane_add_modifier(mods, size, capacity, AMD_FMT_MOD |
542 AMD_FMT_MOD_SET(TILE, AMD_FMT_MOD_TILE_GFX9_64K_D) |
543 AMD_FMT_MOD_SET(TILE_VERSION, AMD_FMT_MOD_TILE_VER_GFX9));
545 if (adev->family == AMDGPU_FAMILY_RV) {
546 amdgpu_dm_plane_add_modifier(mods, size, capacity, AMD_FMT_MOD |
547 AMD_FMT_MOD_SET(TILE, AMD_FMT_MOD_TILE_GFX9_64K_S) |
548 AMD_FMT_MOD_SET(TILE_VERSION, AMD_FMT_MOD_TILE_VER_GFX9));
552 static void amdgpu_dm_plane_add_gfx10_3_modifiers(const struct amdgpu_device *adev,
557 int pipe_xor_bits = ilog2(adev->gfx.config.gb_addr_config_fields.num_pipes);
558 int pkrs = ilog2(adev->gfx.config.gb_addr_config_fields.num_pkrs);
560 amdgpu_dm_plane_add_modifier(mods, size, capacity, AMD_FMT_MOD |
561 AMD_FMT_MOD_SET(TILE, AMD_FMT_MOD_TILE_GFX9_64K_R_X) |
562 AMD_FMT_MOD_SET(TILE_VERSION, AMD_FMT_MOD_TILE_VER_GFX10_RBPLUS) |
563 AMD_FMT_MOD_SET(PIPE_XOR_BITS, pipe_xor_bits) |
564 AMD_FMT_MOD_SET(PACKERS, pkrs) |
565 AMD_FMT_MOD_SET(DCC, 1) |
566 AMD_FMT_MOD_SET(DCC_CONSTANT_ENCODE, 1) |
567 AMD_FMT_MOD_SET(DCC_INDEPENDENT_64B, 1) |
568 AMD_FMT_MOD_SET(DCC_INDEPENDENT_128B, 1) |
569 AMD_FMT_MOD_SET(DCC_MAX_COMPRESSED_BLOCK, AMD_FMT_MOD_DCC_BLOCK_64B));
571 amdgpu_dm_plane_add_modifier(mods, size, capacity, AMD_FMT_MOD |
572 AMD_FMT_MOD_SET(TILE, AMD_FMT_MOD_TILE_GFX9_64K_R_X) |
573 AMD_FMT_MOD_SET(TILE_VERSION, AMD_FMT_MOD_TILE_VER_GFX10_RBPLUS) |
574 AMD_FMT_MOD_SET(PIPE_XOR_BITS, pipe_xor_bits) |
575 AMD_FMT_MOD_SET(PACKERS, pkrs) |
576 AMD_FMT_MOD_SET(DCC, 1) |
577 AMD_FMT_MOD_SET(DCC_CONSTANT_ENCODE, 1) |
578 AMD_FMT_MOD_SET(DCC_INDEPENDENT_128B, 1) |
579 AMD_FMT_MOD_SET(DCC_MAX_COMPRESSED_BLOCK, AMD_FMT_MOD_DCC_BLOCK_128B));
581 amdgpu_dm_plane_add_modifier(mods, size, capacity, AMD_FMT_MOD |
582 AMD_FMT_MOD_SET(TILE, AMD_FMT_MOD_TILE_GFX9_64K_R_X) |
583 AMD_FMT_MOD_SET(TILE_VERSION, AMD_FMT_MOD_TILE_VER_GFX10_RBPLUS) |
584 AMD_FMT_MOD_SET(PIPE_XOR_BITS, pipe_xor_bits) |
585 AMD_FMT_MOD_SET(PACKERS, pkrs) |
586 AMD_FMT_MOD_SET(DCC, 1) |
587 AMD_FMT_MOD_SET(DCC_RETILE, 1) |
588 AMD_FMT_MOD_SET(DCC_CONSTANT_ENCODE, 1) |
589 AMD_FMT_MOD_SET(DCC_INDEPENDENT_64B, 1) |
590 AMD_FMT_MOD_SET(DCC_INDEPENDENT_128B, 1) |
591 AMD_FMT_MOD_SET(DCC_MAX_COMPRESSED_BLOCK, AMD_FMT_MOD_DCC_BLOCK_64B));
593 amdgpu_dm_plane_add_modifier(mods, size, capacity, AMD_FMT_MOD |
594 AMD_FMT_MOD_SET(TILE, AMD_FMT_MOD_TILE_GFX9_64K_R_X) |
595 AMD_FMT_MOD_SET(TILE_VERSION, AMD_FMT_MOD_TILE_VER_GFX10_RBPLUS) |
596 AMD_FMT_MOD_SET(PIPE_XOR_BITS, pipe_xor_bits) |
597 AMD_FMT_MOD_SET(PACKERS, pkrs) |
598 AMD_FMT_MOD_SET(DCC, 1) |
599 AMD_FMT_MOD_SET(DCC_RETILE, 1) |
600 AMD_FMT_MOD_SET(DCC_CONSTANT_ENCODE, 1) |
601 AMD_FMT_MOD_SET(DCC_INDEPENDENT_128B, 1) |
602 AMD_FMT_MOD_SET(DCC_MAX_COMPRESSED_BLOCK, AMD_FMT_MOD_DCC_BLOCK_128B));
604 amdgpu_dm_plane_add_modifier(mods, size, capacity, AMD_FMT_MOD |
605 AMD_FMT_MOD_SET(TILE, AMD_FMT_MOD_TILE_GFX9_64K_R_X) |
606 AMD_FMT_MOD_SET(TILE_VERSION, AMD_FMT_MOD_TILE_VER_GFX10_RBPLUS) |
607 AMD_FMT_MOD_SET(PIPE_XOR_BITS, pipe_xor_bits) |
608 AMD_FMT_MOD_SET(PACKERS, pkrs));
610 amdgpu_dm_plane_add_modifier(mods, size, capacity, AMD_FMT_MOD |
611 AMD_FMT_MOD_SET(TILE, AMD_FMT_MOD_TILE_GFX9_64K_S_X) |
612 AMD_FMT_MOD_SET(TILE_VERSION, AMD_FMT_MOD_TILE_VER_GFX10_RBPLUS) |
613 AMD_FMT_MOD_SET(PIPE_XOR_BITS, pipe_xor_bits) |
614 AMD_FMT_MOD_SET(PACKERS, pkrs));
616 /* Only supported for 64bpp, will be filtered in amdgpu_dm_plane_format_mod_supported */
617 amdgpu_dm_plane_add_modifier(mods, size, capacity, AMD_FMT_MOD |
618 AMD_FMT_MOD_SET(TILE, AMD_FMT_MOD_TILE_GFX9_64K_D) |
619 AMD_FMT_MOD_SET(TILE_VERSION, AMD_FMT_MOD_TILE_VER_GFX9));
621 amdgpu_dm_plane_add_modifier(mods, size, capacity, AMD_FMT_MOD |
622 AMD_FMT_MOD_SET(TILE, AMD_FMT_MOD_TILE_GFX9_64K_S) |
623 AMD_FMT_MOD_SET(TILE_VERSION, AMD_FMT_MOD_TILE_VER_GFX9));
626 static void amdgpu_dm_plane_add_gfx11_modifiers(struct amdgpu_device *adev,
627 uint64_t **mods, uint64_t *size, uint64_t *capacity)
630 int pipe_xor_bits = 0;
635 unsigned int swizzle_r_x;
636 uint64_t modifier_r_x;
637 uint64_t modifier_dcc_best;
638 uint64_t modifier_dcc_4k;
640 /* TODO: GFX11 IP HW init hasnt finish and we get zero if we read from
641 * adev->gfx.config.gb_addr_config_fields.num_{pkrs,pipes}
643 gb_addr_config = RREG32_SOC15(GC, 0, regGB_ADDR_CONFIG);
644 ASSERT(gb_addr_config != 0);
646 num_pkrs = 1 << REG_GET_FIELD(gb_addr_config, GB_ADDR_CONFIG, NUM_PKRS);
647 pkrs = ilog2(num_pkrs);
648 num_pipes = 1 << REG_GET_FIELD(gb_addr_config, GB_ADDR_CONFIG, NUM_PIPES);
649 pipe_xor_bits = ilog2(num_pipes);
651 for (i = 0; i < 2; i++) {
652 /* Insert the best one first. */
653 /* R_X swizzle modes are the best for rendering and DCC requires them. */
655 swizzle_r_x = !i ? AMD_FMT_MOD_TILE_GFX11_256K_R_X : AMD_FMT_MOD_TILE_GFX9_64K_R_X;
657 swizzle_r_x = !i ? AMD_FMT_MOD_TILE_GFX9_64K_R_X : AMD_FMT_MOD_TILE_GFX11_256K_R_X;
659 modifier_r_x = AMD_FMT_MOD |
660 AMD_FMT_MOD_SET(TILE_VERSION, AMD_FMT_MOD_TILE_VER_GFX11) |
661 AMD_FMT_MOD_SET(PIPE_XOR_BITS, pipe_xor_bits) |
662 AMD_FMT_MOD_SET(TILE, swizzle_r_x) |
663 AMD_FMT_MOD_SET(PACKERS, pkrs);
665 /* DCC_CONSTANT_ENCODE is not set because it can't vary with gfx11 (it's implied to be 1). */
666 modifier_dcc_best = modifier_r_x | AMD_FMT_MOD_SET(DCC, 1) |
667 AMD_FMT_MOD_SET(DCC_INDEPENDENT_64B, 0) |
668 AMD_FMT_MOD_SET(DCC_INDEPENDENT_128B, 1) |
669 AMD_FMT_MOD_SET(DCC_MAX_COMPRESSED_BLOCK, AMD_FMT_MOD_DCC_BLOCK_128B);
671 /* DCC settings for 4K and greater resolutions. (required by display hw) */
672 modifier_dcc_4k = modifier_r_x | AMD_FMT_MOD_SET(DCC, 1) |
673 AMD_FMT_MOD_SET(DCC_INDEPENDENT_64B, 1) |
674 AMD_FMT_MOD_SET(DCC_INDEPENDENT_128B, 1) |
675 AMD_FMT_MOD_SET(DCC_MAX_COMPRESSED_BLOCK, AMD_FMT_MOD_DCC_BLOCK_64B);
677 amdgpu_dm_plane_add_modifier(mods, size, capacity, modifier_dcc_best);
678 amdgpu_dm_plane_add_modifier(mods, size, capacity, modifier_dcc_4k);
680 amdgpu_dm_plane_add_modifier(mods, size, capacity, modifier_dcc_best | AMD_FMT_MOD_SET(DCC_RETILE, 1));
681 amdgpu_dm_plane_add_modifier(mods, size, capacity, modifier_dcc_4k | AMD_FMT_MOD_SET(DCC_RETILE, 1));
683 amdgpu_dm_plane_add_modifier(mods, size, capacity, modifier_r_x);
686 amdgpu_dm_plane_add_modifier(mods, size, capacity, AMD_FMT_MOD |
687 AMD_FMT_MOD_SET(TILE_VERSION, AMD_FMT_MOD_TILE_VER_GFX11) |
688 AMD_FMT_MOD_SET(TILE, AMD_FMT_MOD_TILE_GFX9_64K_D));
691 static void amdgpu_dm_plane_add_gfx12_modifiers(struct amdgpu_device *adev,
692 uint64_t **mods, uint64_t *size, uint64_t *capacity)
694 uint64_t ver = AMD_FMT_MOD | AMD_FMT_MOD_SET(TILE_VERSION, AMD_FMT_MOD_TILE_VER_GFX12);
695 uint64_t mod_256k = ver | AMD_FMT_MOD_SET(TILE, AMD_FMT_MOD_TILE_GFX12_256K_2D);
696 uint64_t mod_64k = ver | AMD_FMT_MOD_SET(TILE, AMD_FMT_MOD_TILE_GFX12_64K_2D);
697 uint64_t mod_4k = ver | AMD_FMT_MOD_SET(TILE, AMD_FMT_MOD_TILE_GFX12_4K_2D);
698 uint64_t mod_256b = ver | AMD_FMT_MOD_SET(TILE, AMD_FMT_MOD_TILE_GFX12_256B_2D);
699 uint64_t dcc = ver | AMD_FMT_MOD_SET(DCC, 1);
700 uint8_t max_comp_block[] = {1, 0};
701 uint64_t max_comp_block_mod[ARRAY_SIZE(max_comp_block)] = {0};
702 uint8_t i = 0, j = 0;
703 uint64_t gfx12_modifiers[] = {mod_256k, mod_64k, mod_4k, mod_256b, DRM_FORMAT_MOD_LINEAR};
705 for (i = 0; i < ARRAY_SIZE(max_comp_block); i++)
706 max_comp_block_mod[i] = AMD_FMT_MOD_SET(DCC_MAX_COMPRESSED_BLOCK, max_comp_block[i]);
708 /* With DCC: Best choice should be kept first. Hence, add all 256k modifiers of different
709 * max compressed blocks first and then move on to the next smaller sized layouts.
710 * Do not add the linear modifier here, and hence the condition of size-1 for the loop
712 for (j = 0; j < ARRAY_SIZE(gfx12_modifiers) - 1; j++)
713 for (i = 0; i < ARRAY_SIZE(max_comp_block); i++)
714 amdgpu_dm_plane_add_modifier(mods, size, capacity,
715 ver | dcc | max_comp_block_mod[i] | gfx12_modifiers[j]);
717 /* Without DCC. Add all modifiers including linear at the end */
718 for (i = 0; i < ARRAY_SIZE(gfx12_modifiers); i++)
719 amdgpu_dm_plane_add_modifier(mods, size, capacity, gfx12_modifiers[i]);
723 static int amdgpu_dm_plane_get_plane_modifiers(struct amdgpu_device *adev, unsigned int plane_type, uint64_t **mods)
725 uint64_t size = 0, capacity = 128;
728 /* We have not hooked up any pre-GFX9 modifiers. */
729 if (adev->family < AMDGPU_FAMILY_AI)
732 *mods = kmalloc(capacity * sizeof(uint64_t), GFP_KERNEL);
734 if (plane_type == DRM_PLANE_TYPE_CURSOR) {
735 amdgpu_dm_plane_add_modifier(mods, &size, &capacity, DRM_FORMAT_MOD_LINEAR);
736 amdgpu_dm_plane_add_modifier(mods, &size, &capacity, DRM_FORMAT_MOD_INVALID);
737 return *mods ? 0 : -ENOMEM;
740 switch (adev->family) {
741 case AMDGPU_FAMILY_AI:
742 case AMDGPU_FAMILY_RV:
743 amdgpu_dm_plane_add_gfx9_modifiers(adev, mods, &size, &capacity);
745 case AMDGPU_FAMILY_NV:
746 case AMDGPU_FAMILY_VGH:
747 case AMDGPU_FAMILY_YC:
748 case AMDGPU_FAMILY_GC_10_3_6:
749 case AMDGPU_FAMILY_GC_10_3_7:
750 if (amdgpu_ip_version(adev, GC_HWIP, 0) >= IP_VERSION(10, 3, 0))
751 amdgpu_dm_plane_add_gfx10_3_modifiers(adev, mods, &size, &capacity);
753 amdgpu_dm_plane_add_gfx10_1_modifiers(adev, mods, &size, &capacity);
755 case AMDGPU_FAMILY_GC_11_0_0:
756 case AMDGPU_FAMILY_GC_11_0_1:
757 case AMDGPU_FAMILY_GC_11_5_0:
758 amdgpu_dm_plane_add_gfx11_modifiers(adev, mods, &size, &capacity);
760 case AMDGPU_FAMILY_GC_12_0_0:
761 amdgpu_dm_plane_add_gfx12_modifiers(adev, mods, &size, &capacity);
765 amdgpu_dm_plane_add_modifier(mods, &size, &capacity, DRM_FORMAT_MOD_LINEAR);
767 /* INVALID marks the end of the list. */
768 amdgpu_dm_plane_add_modifier(mods, &size, &capacity, DRM_FORMAT_MOD_INVALID);
776 static int amdgpu_dm_plane_get_plane_formats(const struct drm_plane *plane,
777 const struct dc_plane_cap *plane_cap,
778 uint32_t *formats, int max_formats)
780 int i, num_formats = 0;
783 * TODO: Query support for each group of formats directly from
784 * DC plane caps. This will require adding more formats to the
788 if (plane->type == DRM_PLANE_TYPE_PRIMARY ||
789 (plane_cap && plane_cap->type == DC_PLANE_TYPE_DCN_UNIVERSAL && plane->type != DRM_PLANE_TYPE_CURSOR)) {
790 for (i = 0; i < ARRAY_SIZE(rgb_formats); ++i) {
791 if (num_formats >= max_formats)
794 formats[num_formats++] = rgb_formats[i];
797 if (plane_cap && plane_cap->pixel_format_support.nv12)
798 formats[num_formats++] = DRM_FORMAT_NV12;
799 if (plane_cap && plane_cap->pixel_format_support.p010)
800 formats[num_formats++] = DRM_FORMAT_P010;
801 if (plane_cap && plane_cap->pixel_format_support.fp16) {
802 formats[num_formats++] = DRM_FORMAT_XRGB16161616F;
803 formats[num_formats++] = DRM_FORMAT_ARGB16161616F;
804 formats[num_formats++] = DRM_FORMAT_XBGR16161616F;
805 formats[num_formats++] = DRM_FORMAT_ABGR16161616F;
808 switch (plane->type) {
809 case DRM_PLANE_TYPE_OVERLAY:
810 for (i = 0; i < ARRAY_SIZE(overlay_formats); ++i) {
811 if (num_formats >= max_formats)
814 formats[num_formats++] = overlay_formats[i];
818 case DRM_PLANE_TYPE_CURSOR:
819 for (i = 0; i < ARRAY_SIZE(cursor_formats); ++i) {
820 if (num_formats >= max_formats)
823 formats[num_formats++] = cursor_formats[i];
835 int amdgpu_dm_plane_fill_plane_buffer_attributes(struct amdgpu_device *adev,
836 const struct amdgpu_framebuffer *afb,
837 const enum surface_pixel_format format,
838 const enum dc_rotation_angle rotation,
839 const uint64_t tiling_flags,
840 struct dc_tiling_info *tiling_info,
841 struct plane_size *plane_size,
842 struct dc_plane_dcc_param *dcc,
843 struct dc_plane_address *address,
846 const struct drm_framebuffer *fb = &afb->base;
849 memset(tiling_info, 0, sizeof(*tiling_info));
850 memset(plane_size, 0, sizeof(*plane_size));
851 memset(dcc, 0, sizeof(*dcc));
852 memset(address, 0, sizeof(*address));
854 address->tmz_surface = tmz_surface;
856 if (format < SURFACE_PIXEL_FORMAT_VIDEO_BEGIN) {
857 uint64_t addr = afb->address + fb->offsets[0];
859 plane_size->surface_size.x = 0;
860 plane_size->surface_size.y = 0;
861 plane_size->surface_size.width = fb->width;
862 plane_size->surface_size.height = fb->height;
863 plane_size->surface_pitch =
864 fb->pitches[0] / fb->format->cpp[0];
866 address->type = PLN_ADDR_TYPE_GRAPHICS;
867 address->grph.addr.low_part = lower_32_bits(addr);
868 address->grph.addr.high_part = upper_32_bits(addr);
869 } else if (format < SURFACE_PIXEL_FORMAT_INVALID) {
870 uint64_t luma_addr = afb->address + fb->offsets[0];
871 uint64_t chroma_addr = afb->address + fb->offsets[1];
873 plane_size->surface_size.x = 0;
874 plane_size->surface_size.y = 0;
875 plane_size->surface_size.width = fb->width;
876 plane_size->surface_size.height = fb->height;
877 plane_size->surface_pitch =
878 fb->pitches[0] / fb->format->cpp[0];
880 plane_size->chroma_size.x = 0;
881 plane_size->chroma_size.y = 0;
882 /* TODO: set these based on surface format */
883 plane_size->chroma_size.width = fb->width / 2;
884 plane_size->chroma_size.height = fb->height / 2;
886 plane_size->chroma_pitch =
887 fb->pitches[1] / fb->format->cpp[1];
889 address->type = PLN_ADDR_TYPE_VIDEO_PROGRESSIVE;
890 address->video_progressive.luma_addr.low_part =
891 lower_32_bits(luma_addr);
892 address->video_progressive.luma_addr.high_part =
893 upper_32_bits(luma_addr);
894 address->video_progressive.chroma_addr.low_part =
895 lower_32_bits(chroma_addr);
896 address->video_progressive.chroma_addr.high_part =
897 upper_32_bits(chroma_addr);
900 if (adev->family >= AMDGPU_FAMILY_GC_12_0_0) {
901 ret = amdgpu_dm_plane_fill_gfx12_plane_attributes_from_modifiers(adev, afb, format,
902 rotation, plane_size,
907 } else if (adev->family >= AMDGPU_FAMILY_AI) {
908 ret = amdgpu_dm_plane_fill_gfx9_plane_attributes_from_modifiers(adev, afb, format,
909 rotation, plane_size,
915 amdgpu_dm_plane_fill_gfx8_tiling_info_from_flags(tiling_info, tiling_flags);
921 static int amdgpu_dm_plane_helper_prepare_fb(struct drm_plane *plane,
922 struct drm_plane_state *new_state)
924 struct amdgpu_framebuffer *afb;
925 struct drm_gem_object *obj;
926 struct amdgpu_device *adev;
927 struct amdgpu_bo *rbo;
928 struct dm_plane_state *dm_plane_state_new, *dm_plane_state_old;
932 if (!new_state->fb) {
933 DRM_DEBUG_KMS("No FB bound\n");
937 afb = to_amdgpu_framebuffer(new_state->fb);
938 obj = drm_gem_fb_get_obj(new_state->fb, 0);
940 DRM_ERROR("Failed to get obj from framebuffer\n");
944 rbo = gem_to_amdgpu_bo(obj);
945 adev = amdgpu_ttm_adev(rbo->tbo.bdev);
946 r = amdgpu_bo_reserve(rbo, true);
948 dev_err(adev->dev, "fail to reserve bo (%d)\n", r);
952 r = dma_resv_reserve_fences(rbo->tbo.base.resv, 1);
954 dev_err(adev->dev, "reserving fence slot failed (%d)\n", r);
958 if (plane->type != DRM_PLANE_TYPE_CURSOR)
959 domain = amdgpu_display_supported_domains(adev, rbo->flags);
961 domain = AMDGPU_GEM_DOMAIN_VRAM;
963 rbo->flags |= AMDGPU_GEM_CREATE_VRAM_CONTIGUOUS;
964 r = amdgpu_bo_pin(rbo, domain);
965 if (unlikely(r != 0)) {
966 if (r != -ERESTARTSYS)
967 DRM_ERROR("Failed to pin framebuffer with error %d\n", r);
971 r = amdgpu_ttm_alloc_gart(&rbo->tbo);
972 if (unlikely(r != 0)) {
973 DRM_ERROR("%p bind failed\n", rbo);
977 r = drm_gem_plane_helper_prepare_fb(plane, new_state);
978 if (unlikely(r != 0))
981 amdgpu_bo_unreserve(rbo);
983 afb->address = amdgpu_bo_gpu_offset(rbo);
988 * We don't do surface updates on planes that have been newly created,
989 * but we also don't have the afb->address during atomic check.
991 * Fill in buffer attributes depending on the address here, but only on
992 * newly created planes since they're not being used by DC yet and this
993 * won't modify global state.
995 dm_plane_state_old = to_dm_plane_state(plane->state);
996 dm_plane_state_new = to_dm_plane_state(new_state);
998 if (dm_plane_state_new->dc_state &&
999 dm_plane_state_old->dc_state != dm_plane_state_new->dc_state) {
1000 struct dc_plane_state *plane_state =
1001 dm_plane_state_new->dc_state;
1003 amdgpu_dm_plane_fill_plane_buffer_attributes(
1004 adev, afb, plane_state->format, plane_state->rotation,
1006 &plane_state->tiling_info, &plane_state->plane_size,
1007 &plane_state->dcc, &plane_state->address,
1014 amdgpu_bo_unpin(rbo);
1017 amdgpu_bo_unreserve(rbo);
1021 static void amdgpu_dm_plane_helper_cleanup_fb(struct drm_plane *plane,
1022 struct drm_plane_state *old_state)
1024 struct amdgpu_bo *rbo;
1030 rbo = gem_to_amdgpu_bo(old_state->fb->obj[0]);
1031 r = amdgpu_bo_reserve(rbo, false);
1033 DRM_ERROR("failed to reserve rbo before unpin\n");
1037 amdgpu_bo_unpin(rbo);
1038 amdgpu_bo_unreserve(rbo);
1039 amdgpu_bo_unref(&rbo);
1042 static void amdgpu_dm_plane_get_min_max_dc_plane_scaling(struct drm_device *dev,
1043 struct drm_framebuffer *fb,
1044 int *min_downscale, int *max_upscale)
1046 struct amdgpu_device *adev = drm_to_adev(dev);
1047 struct dc *dc = adev->dm.dc;
1048 /* Caps for all supported planes are the same on DCE and DCN 1 - 3 */
1049 struct dc_plane_cap *plane_cap = &dc->caps.planes[0];
1051 switch (fb->format->format) {
1052 case DRM_FORMAT_P010:
1053 case DRM_FORMAT_NV12:
1054 case DRM_FORMAT_NV21:
1055 *max_upscale = plane_cap->max_upscale_factor.nv12;
1056 *min_downscale = plane_cap->max_downscale_factor.nv12;
1059 case DRM_FORMAT_XRGB16161616F:
1060 case DRM_FORMAT_ARGB16161616F:
1061 case DRM_FORMAT_XBGR16161616F:
1062 case DRM_FORMAT_ABGR16161616F:
1063 *max_upscale = plane_cap->max_upscale_factor.fp16;
1064 *min_downscale = plane_cap->max_downscale_factor.fp16;
1068 *max_upscale = plane_cap->max_upscale_factor.argb8888;
1069 *min_downscale = plane_cap->max_downscale_factor.argb8888;
1074 * A factor of 1 in the plane_cap means to not allow scaling, ie. use a
1075 * scaling factor of 1.0 == 1000 units.
1077 if (*max_upscale == 1)
1078 *max_upscale = 1000;
1080 if (*min_downscale == 1)
1081 *min_downscale = 1000;
1084 int amdgpu_dm_plane_helper_check_state(struct drm_plane_state *state,
1085 struct drm_crtc_state *new_crtc_state)
1087 struct drm_framebuffer *fb = state->fb;
1088 int min_downscale, max_upscale;
1090 int max_scale = INT_MAX;
1092 /* Plane enabled? Validate viewport and get scaling factors from plane caps. */
1093 if (fb && state->crtc) {
1094 /* Validate viewport to cover the case when only the position changes */
1095 if (state->plane->type != DRM_PLANE_TYPE_CURSOR) {
1096 int viewport_width = state->crtc_w;
1097 int viewport_height = state->crtc_h;
1099 if (state->crtc_x < 0)
1100 viewport_width += state->crtc_x;
1101 else if (state->crtc_x + state->crtc_w > new_crtc_state->mode.crtc_hdisplay)
1102 viewport_width = new_crtc_state->mode.crtc_hdisplay - state->crtc_x;
1104 if (state->crtc_y < 0)
1105 viewport_height += state->crtc_y;
1106 else if (state->crtc_y + state->crtc_h > new_crtc_state->mode.crtc_vdisplay)
1107 viewport_height = new_crtc_state->mode.crtc_vdisplay - state->crtc_y;
1109 if (viewport_width < 0 || viewport_height < 0) {
1110 DRM_DEBUG_ATOMIC("Plane completely outside of screen\n");
1112 } else if (viewport_width < MIN_VIEWPORT_SIZE*2) { /* x2 for width is because of pipe-split. */
1113 DRM_DEBUG_ATOMIC("Viewport width %d smaller than %d\n", viewport_width, MIN_VIEWPORT_SIZE*2);
1115 } else if (viewport_height < MIN_VIEWPORT_SIZE) {
1116 DRM_DEBUG_ATOMIC("Viewport height %d smaller than %d\n", viewport_height, MIN_VIEWPORT_SIZE);
1122 /* Get min/max allowed scaling factors from plane caps. */
1123 amdgpu_dm_plane_get_min_max_dc_plane_scaling(state->crtc->dev, fb,
1124 &min_downscale, &max_upscale);
1126 * Convert to drm convention: 16.16 fixed point, instead of dc's
1127 * 1.0 == 1000. Also drm scaling is src/dst instead of dc's
1128 * dst/src, so min_scale = 1.0 / max_upscale, etc.
1130 min_scale = (1000 << 16) / max_upscale;
1131 max_scale = (1000 << 16) / min_downscale;
1134 return drm_atomic_helper_check_plane_state(
1135 state, new_crtc_state, min_scale, max_scale, true, true);
1138 int amdgpu_dm_plane_fill_dc_scaling_info(struct amdgpu_device *adev,
1139 const struct drm_plane_state *state,
1140 struct dc_scaling_info *scaling_info)
1142 int scale_w, scale_h, min_downscale, max_upscale;
1144 memset(scaling_info, 0, sizeof(*scaling_info));
1146 /* Source is fixed 16.16 but we ignore mantissa for now... */
1147 scaling_info->src_rect.x = state->src_x >> 16;
1148 scaling_info->src_rect.y = state->src_y >> 16;
1151 * For reasons we don't (yet) fully understand a non-zero
1152 * src_y coordinate into an NV12 buffer can cause a
1153 * system hang on DCN1x.
1154 * To avoid hangs (and maybe be overly cautious)
1155 * let's reject both non-zero src_x and src_y.
1157 * We currently know of only one use-case to reproduce a
1158 * scenario with non-zero src_x and src_y for NV12, which
1159 * is to gesture the YouTube Android app into full screen
1162 if (((amdgpu_ip_version(adev, DCE_HWIP, 0) == IP_VERSION(1, 0, 0)) ||
1163 (amdgpu_ip_version(adev, DCE_HWIP, 0) == IP_VERSION(1, 0, 1))) &&
1164 (state->fb && state->fb->format->format == DRM_FORMAT_NV12 &&
1165 (scaling_info->src_rect.x != 0 || scaling_info->src_rect.y != 0)))
1168 scaling_info->src_rect.width = state->src_w >> 16;
1169 if (scaling_info->src_rect.width == 0)
1172 scaling_info->src_rect.height = state->src_h >> 16;
1173 if (scaling_info->src_rect.height == 0)
1176 scaling_info->dst_rect.x = state->crtc_x;
1177 scaling_info->dst_rect.y = state->crtc_y;
1179 if (state->crtc_w == 0)
1182 scaling_info->dst_rect.width = state->crtc_w;
1184 if (state->crtc_h == 0)
1187 scaling_info->dst_rect.height = state->crtc_h;
1189 /* DRM doesn't specify clipping on destination output. */
1190 scaling_info->clip_rect = scaling_info->dst_rect;
1192 /* Validate scaling per-format with DC plane caps */
1193 if (state->plane && state->plane->dev && state->fb) {
1194 amdgpu_dm_plane_get_min_max_dc_plane_scaling(state->plane->dev, state->fb,
1195 &min_downscale, &max_upscale);
1197 min_downscale = 250;
1198 max_upscale = 16000;
1201 scale_w = scaling_info->dst_rect.width * 1000 /
1202 scaling_info->src_rect.width;
1204 if (scale_w < min_downscale || scale_w > max_upscale)
1207 scale_h = scaling_info->dst_rect.height * 1000 /
1208 scaling_info->src_rect.height;
1210 if (scale_h < min_downscale || scale_h > max_upscale)
1214 * The "scaling_quality" can be ignored for now, quality = 0 has DC
1215 * assume reasonable defaults based on the format.
1221 static int amdgpu_dm_plane_atomic_check(struct drm_plane *plane,
1222 struct drm_atomic_state *state)
1224 struct drm_plane_state *new_plane_state = drm_atomic_get_new_plane_state(state,
1226 struct amdgpu_device *adev = drm_to_adev(plane->dev);
1227 struct dc *dc = adev->dm.dc;
1228 struct dm_plane_state *dm_plane_state;
1229 struct dc_scaling_info scaling_info;
1230 struct drm_crtc_state *new_crtc_state;
1233 trace_amdgpu_dm_plane_atomic_check(new_plane_state);
1235 dm_plane_state = to_dm_plane_state(new_plane_state);
1237 if (!dm_plane_state->dc_state)
1241 drm_atomic_get_new_crtc_state(state,
1242 new_plane_state->crtc);
1243 if (!new_crtc_state)
1246 ret = amdgpu_dm_plane_helper_check_state(new_plane_state, new_crtc_state);
1250 ret = amdgpu_dm_plane_fill_dc_scaling_info(adev, new_plane_state, &scaling_info);
1254 if (dc_validate_plane(dc, dm_plane_state->dc_state) == DC_OK)
1260 static int amdgpu_dm_plane_atomic_async_check(struct drm_plane *plane,
1261 struct drm_atomic_state *state)
1263 struct drm_crtc_state *new_crtc_state;
1264 struct drm_plane_state *new_plane_state;
1265 struct dm_crtc_state *dm_new_crtc_state;
1267 /* Only support async updates on cursor planes. */
1268 if (plane->type != DRM_PLANE_TYPE_CURSOR)
1271 new_plane_state = drm_atomic_get_new_plane_state(state, plane);
1272 new_crtc_state = drm_atomic_get_new_crtc_state(state, new_plane_state->crtc);
1273 dm_new_crtc_state = to_dm_crtc_state(new_crtc_state);
1274 /* Reject overlay cursors for now*/
1275 if (dm_new_crtc_state->cursor_mode == DM_CURSOR_OVERLAY_MODE)
1281 int amdgpu_dm_plane_get_cursor_position(struct drm_plane *plane, struct drm_crtc *crtc,
1282 struct dc_cursor_position *position)
1284 struct amdgpu_crtc *amdgpu_crtc = to_amdgpu_crtc(crtc);
1285 struct amdgpu_device *adev = drm_to_adev(plane->dev);
1287 int xorigin = 0, yorigin = 0;
1289 if (!crtc || !plane->state->fb)
1292 if ((plane->state->crtc_w > amdgpu_crtc->max_cursor_width) ||
1293 (plane->state->crtc_h > amdgpu_crtc->max_cursor_height)) {
1294 DRM_ERROR("%s: bad cursor width or height %d x %d\n",
1296 plane->state->crtc_w,
1297 plane->state->crtc_h);
1301 x = plane->state->crtc_x;
1302 y = plane->state->crtc_y;
1304 if (x <= -amdgpu_crtc->max_cursor_width ||
1305 y <= -amdgpu_crtc->max_cursor_height)
1309 xorigin = min(-x, amdgpu_crtc->max_cursor_width - 1);
1313 yorigin = min(-y, amdgpu_crtc->max_cursor_height - 1);
1316 position->enable = true;
1319 position->x_hotspot = xorigin;
1320 position->y_hotspot = yorigin;
1322 if (amdgpu_ip_version(adev, DCE_HWIP, 0) < IP_VERSION(4, 0, 1))
1323 position->translate_by_source = true;
1328 void amdgpu_dm_plane_handle_cursor_update(struct drm_plane *plane,
1329 struct drm_plane_state *old_plane_state)
1331 struct amdgpu_device *adev = drm_to_adev(plane->dev);
1332 struct amdgpu_framebuffer *afb = to_amdgpu_framebuffer(plane->state->fb);
1333 struct drm_crtc *crtc = afb ? plane->state->crtc : old_plane_state->crtc;
1334 struct dm_crtc_state *crtc_state = crtc ? to_dm_crtc_state(crtc->state) : NULL;
1335 struct amdgpu_crtc *amdgpu_crtc = to_amdgpu_crtc(crtc);
1336 uint64_t address = afb ? afb->address : 0;
1337 struct dc_cursor_position position = {0};
1338 struct dc_cursor_attributes attributes;
1341 if (!plane->state->fb && !old_plane_state->fb)
1344 drm_dbg_atomic(plane->dev, "crtc_id=%d with size %d to %d\n",
1345 amdgpu_crtc->crtc_id, plane->state->crtc_w,
1346 plane->state->crtc_h);
1348 ret = amdgpu_dm_plane_get_cursor_position(plane, crtc, &position);
1352 if (!position.enable) {
1353 /* turn off cursor */
1354 if (crtc_state && crtc_state->stream) {
1355 mutex_lock(&adev->dm.dc_lock);
1356 dc_stream_program_cursor_position(crtc_state->stream,
1358 mutex_unlock(&adev->dm.dc_lock);
1363 amdgpu_crtc->cursor_width = plane->state->crtc_w;
1364 amdgpu_crtc->cursor_height = plane->state->crtc_h;
1366 memset(&attributes, 0, sizeof(attributes));
1367 attributes.address.high_part = upper_32_bits(address);
1368 attributes.address.low_part = lower_32_bits(address);
1369 attributes.width = plane->state->crtc_w;
1370 attributes.height = plane->state->crtc_h;
1371 attributes.color_format = CURSOR_MODE_COLOR_PRE_MULTIPLIED_ALPHA;
1372 attributes.rotation_angle = 0;
1373 attributes.attribute_flags.value = 0;
1375 /* Enable cursor degamma ROM on DCN3+ for implicit sRGB degamma in DRM
1376 * legacy gamma setup.
1378 if (crtc_state->cm_is_degamma_srgb &&
1379 adev->dm.dc->caps.color.dpp.gamma_corr)
1380 attributes.attribute_flags.bits.ENABLE_CURSOR_DEGAMMA = 1;
1383 attributes.pitch = afb->base.pitches[0] / afb->base.format->cpp[0];
1385 if (crtc_state->stream) {
1386 mutex_lock(&adev->dm.dc_lock);
1387 if (!dc_stream_program_cursor_attributes(crtc_state->stream,
1389 DRM_ERROR("DC failed to set cursor attributes\n");
1391 if (!dc_stream_program_cursor_position(crtc_state->stream,
1393 DRM_ERROR("DC failed to set cursor position\n");
1394 mutex_unlock(&adev->dm.dc_lock);
1398 static void amdgpu_dm_plane_atomic_async_update(struct drm_plane *plane,
1399 struct drm_atomic_state *state)
1401 struct drm_plane_state *new_state = drm_atomic_get_new_plane_state(state,
1403 struct drm_plane_state *old_state =
1404 drm_atomic_get_old_plane_state(state, plane);
1406 trace_amdgpu_dm_atomic_update_cursor(new_state);
1408 swap(plane->state->fb, new_state->fb);
1410 plane->state->src_x = new_state->src_x;
1411 plane->state->src_y = new_state->src_y;
1412 plane->state->src_w = new_state->src_w;
1413 plane->state->src_h = new_state->src_h;
1414 plane->state->crtc_x = new_state->crtc_x;
1415 plane->state->crtc_y = new_state->crtc_y;
1416 plane->state->crtc_w = new_state->crtc_w;
1417 plane->state->crtc_h = new_state->crtc_h;
1419 amdgpu_dm_plane_handle_cursor_update(plane, old_state);
1422 static void amdgpu_dm_plane_panic_flush(struct drm_plane *plane)
1424 struct dm_plane_state *dm_plane_state = to_dm_plane_state(plane->state);
1425 struct drm_framebuffer *fb = plane->state->fb;
1426 struct dc_plane_state *dc_plane_state;
1428 if (!dm_plane_state || !dm_plane_state->dc_state)
1431 dc_plane_state = dm_plane_state->dc_state;
1433 dc_plane_force_update_for_panic(dc_plane_state, fb->modifier ? true : false);
1436 static const struct drm_plane_helper_funcs dm_plane_helper_funcs = {
1437 .prepare_fb = amdgpu_dm_plane_helper_prepare_fb,
1438 .cleanup_fb = amdgpu_dm_plane_helper_cleanup_fb,
1439 .atomic_check = amdgpu_dm_plane_atomic_check,
1440 .atomic_async_check = amdgpu_dm_plane_atomic_async_check,
1441 .atomic_async_update = amdgpu_dm_plane_atomic_async_update
1444 static const struct drm_plane_helper_funcs dm_primary_plane_helper_funcs = {
1445 .prepare_fb = amdgpu_dm_plane_helper_prepare_fb,
1446 .cleanup_fb = amdgpu_dm_plane_helper_cleanup_fb,
1447 .atomic_check = amdgpu_dm_plane_atomic_check,
1448 .atomic_async_check = amdgpu_dm_plane_atomic_async_check,
1449 .atomic_async_update = amdgpu_dm_plane_atomic_async_update,
1450 .get_scanout_buffer = amdgpu_display_get_scanout_buffer,
1451 .panic_flush = amdgpu_dm_plane_panic_flush,
1454 static void amdgpu_dm_plane_drm_plane_reset(struct drm_plane *plane)
1456 struct dm_plane_state *amdgpu_state = NULL;
1459 plane->funcs->atomic_destroy_state(plane, plane->state);
1461 amdgpu_state = kzalloc(sizeof(*amdgpu_state), GFP_KERNEL);
1462 WARN_ON(amdgpu_state == NULL);
1467 __drm_atomic_helper_plane_reset(plane, &amdgpu_state->base);
1468 amdgpu_state->degamma_tf = AMDGPU_TRANSFER_FUNCTION_DEFAULT;
1469 amdgpu_state->hdr_mult = AMDGPU_HDR_MULT_DEFAULT;
1470 amdgpu_state->shaper_tf = AMDGPU_TRANSFER_FUNCTION_DEFAULT;
1471 amdgpu_state->blend_tf = AMDGPU_TRANSFER_FUNCTION_DEFAULT;
1474 static struct drm_plane_state *amdgpu_dm_plane_drm_plane_duplicate_state(struct drm_plane *plane)
1476 struct dm_plane_state *dm_plane_state, *old_dm_plane_state;
1478 old_dm_plane_state = to_dm_plane_state(plane->state);
1479 dm_plane_state = kzalloc(sizeof(*dm_plane_state), GFP_KERNEL);
1480 if (!dm_plane_state)
1483 __drm_atomic_helper_plane_duplicate_state(plane, &dm_plane_state->base);
1485 if (old_dm_plane_state->dc_state) {
1486 dm_plane_state->dc_state = old_dm_plane_state->dc_state;
1487 dc_plane_state_retain(dm_plane_state->dc_state);
1490 if (old_dm_plane_state->degamma_lut)
1491 dm_plane_state->degamma_lut =
1492 drm_property_blob_get(old_dm_plane_state->degamma_lut);
1493 if (old_dm_plane_state->ctm)
1494 dm_plane_state->ctm =
1495 drm_property_blob_get(old_dm_plane_state->ctm);
1496 if (old_dm_plane_state->shaper_lut)
1497 dm_plane_state->shaper_lut =
1498 drm_property_blob_get(old_dm_plane_state->shaper_lut);
1499 if (old_dm_plane_state->lut3d)
1500 dm_plane_state->lut3d =
1501 drm_property_blob_get(old_dm_plane_state->lut3d);
1502 if (old_dm_plane_state->blend_lut)
1503 dm_plane_state->blend_lut =
1504 drm_property_blob_get(old_dm_plane_state->blend_lut);
1506 dm_plane_state->degamma_tf = old_dm_plane_state->degamma_tf;
1507 dm_plane_state->hdr_mult = old_dm_plane_state->hdr_mult;
1508 dm_plane_state->shaper_tf = old_dm_plane_state->shaper_tf;
1509 dm_plane_state->blend_tf = old_dm_plane_state->blend_tf;
1511 return &dm_plane_state->base;
1514 static bool amdgpu_dm_plane_format_mod_supported(struct drm_plane *plane,
1518 struct amdgpu_device *adev = drm_to_adev(plane->dev);
1519 const struct drm_format_info *info = drm_format_info(format);
1526 * We always have to allow these modifiers:
1527 * 1. Core DRM checks for LINEAR support if userspace does not provide modifiers.
1528 * 2. Not passing any modifiers is the same as explicitly passing INVALID.
1530 if (modifier == DRM_FORMAT_MOD_LINEAR ||
1531 modifier == DRM_FORMAT_MOD_INVALID) {
1535 /* Check that the modifier is on the list of the plane's supported modifiers. */
1536 for (i = 0; i < plane->modifier_count; i++) {
1537 if (modifier == plane->modifiers[i])
1540 if (i == plane->modifier_count)
1543 /* GFX12 doesn't have these limitations. */
1544 if (AMD_FMT_MOD_GET(TILE_VERSION, modifier) <= AMD_FMT_MOD_TILE_VER_GFX11) {
1545 enum dm_micro_swizzle microtile = amdgpu_dm_plane_modifier_gfx9_swizzle_mode(modifier) & 3;
1548 * For D swizzle the canonical modifier depends on the bpp, so check
1551 if (AMD_FMT_MOD_GET(TILE_VERSION, modifier) == AMD_FMT_MOD_TILE_VER_GFX9 &&
1552 adev->family >= AMDGPU_FAMILY_NV) {
1553 if (microtile == MICRO_SWIZZLE_D && info->cpp[0] == 4)
1557 if (adev->family >= AMDGPU_FAMILY_RV && microtile == MICRO_SWIZZLE_D &&
1561 if (amdgpu_dm_plane_modifier_has_dcc(modifier)) {
1562 /* Per radeonsi comments 16/64 bpp are more complicated. */
1563 if (info->cpp[0] != 4)
1565 /* We support multi-planar formats, but not when combined with
1566 * additional DCC metadata planes.
1568 if (info->num_planes > 1)
1576 static void amdgpu_dm_plane_drm_plane_destroy_state(struct drm_plane *plane,
1577 struct drm_plane_state *state)
1579 struct dm_plane_state *dm_plane_state = to_dm_plane_state(state);
1581 if (dm_plane_state->degamma_lut)
1582 drm_property_blob_put(dm_plane_state->degamma_lut);
1583 if (dm_plane_state->ctm)
1584 drm_property_blob_put(dm_plane_state->ctm);
1585 if (dm_plane_state->lut3d)
1586 drm_property_blob_put(dm_plane_state->lut3d);
1587 if (dm_plane_state->shaper_lut)
1588 drm_property_blob_put(dm_plane_state->shaper_lut);
1589 if (dm_plane_state->blend_lut)
1590 drm_property_blob_put(dm_plane_state->blend_lut);
1592 if (dm_plane_state->dc_state)
1593 dc_plane_state_release(dm_plane_state->dc_state);
1595 drm_atomic_helper_plane_destroy_state(plane, state);
1598 #ifdef AMD_PRIVATE_COLOR
1600 dm_atomic_plane_attach_color_mgmt_properties(struct amdgpu_display_manager *dm,
1601 struct drm_plane *plane)
1603 struct amdgpu_mode_info mode_info = dm->adev->mode_info;
1604 struct dpp_color_caps dpp_color_caps = dm->dc->caps.color.dpp;
1606 /* Check HW color pipeline capabilities on DPP block (pre-blending)
1607 * before exposing related properties.
1609 if (dpp_color_caps.dgam_ram || dpp_color_caps.gamma_corr) {
1610 drm_object_attach_property(&plane->base,
1611 mode_info.plane_degamma_lut_property,
1613 drm_object_attach_property(&plane->base,
1614 mode_info.plane_degamma_lut_size_property,
1615 MAX_COLOR_LUT_ENTRIES);
1616 drm_object_attach_property(&plane->base,
1617 dm->adev->mode_info.plane_degamma_tf_property,
1618 AMDGPU_TRANSFER_FUNCTION_DEFAULT);
1620 /* HDR MULT is always available */
1621 drm_object_attach_property(&plane->base,
1622 dm->adev->mode_info.plane_hdr_mult_property,
1623 AMDGPU_HDR_MULT_DEFAULT);
1625 /* Only enable plane CTM if both DPP and MPC gamut remap is available. */
1626 if (dm->dc->caps.color.mpc.gamut_remap)
1627 drm_object_attach_property(&plane->base,
1628 dm->adev->mode_info.plane_ctm_property, 0);
1630 if (dpp_color_caps.hw_3d_lut) {
1631 drm_object_attach_property(&plane->base,
1632 mode_info.plane_shaper_lut_property, 0);
1633 drm_object_attach_property(&plane->base,
1634 mode_info.plane_shaper_lut_size_property,
1635 MAX_COLOR_LUT_ENTRIES);
1636 drm_object_attach_property(&plane->base,
1637 mode_info.plane_shaper_tf_property,
1638 AMDGPU_TRANSFER_FUNCTION_DEFAULT);
1639 drm_object_attach_property(&plane->base,
1640 mode_info.plane_lut3d_property, 0);
1641 drm_object_attach_property(&plane->base,
1642 mode_info.plane_lut3d_size_property,
1643 MAX_COLOR_3DLUT_SIZE);
1646 if (dpp_color_caps.ogam_ram) {
1647 drm_object_attach_property(&plane->base,
1648 mode_info.plane_blend_lut_property, 0);
1649 drm_object_attach_property(&plane->base,
1650 mode_info.plane_blend_lut_size_property,
1651 MAX_COLOR_LUT_ENTRIES);
1652 drm_object_attach_property(&plane->base,
1653 mode_info.plane_blend_tf_property,
1654 AMDGPU_TRANSFER_FUNCTION_DEFAULT);
1659 dm_atomic_plane_set_property(struct drm_plane *plane,
1660 struct drm_plane_state *state,
1661 struct drm_property *property,
1664 struct dm_plane_state *dm_plane_state = to_dm_plane_state(state);
1665 struct amdgpu_device *adev = drm_to_adev(plane->dev);
1666 bool replaced = false;
1669 if (property == adev->mode_info.plane_degamma_lut_property) {
1670 ret = drm_property_replace_blob_from_id(plane->dev,
1671 &dm_plane_state->degamma_lut,
1673 sizeof(struct drm_color_lut),
1675 dm_plane_state->base.color_mgmt_changed |= replaced;
1677 } else if (property == adev->mode_info.plane_degamma_tf_property) {
1678 if (dm_plane_state->degamma_tf != val) {
1679 dm_plane_state->degamma_tf = val;
1680 dm_plane_state->base.color_mgmt_changed = 1;
1682 } else if (property == adev->mode_info.plane_hdr_mult_property) {
1683 if (dm_plane_state->hdr_mult != val) {
1684 dm_plane_state->hdr_mult = val;
1685 dm_plane_state->base.color_mgmt_changed = 1;
1687 } else if (property == adev->mode_info.plane_ctm_property) {
1688 ret = drm_property_replace_blob_from_id(plane->dev,
1689 &dm_plane_state->ctm,
1691 sizeof(struct drm_color_ctm_3x4), -1,
1693 dm_plane_state->base.color_mgmt_changed |= replaced;
1695 } else if (property == adev->mode_info.plane_shaper_lut_property) {
1696 ret = drm_property_replace_blob_from_id(plane->dev,
1697 &dm_plane_state->shaper_lut,
1699 sizeof(struct drm_color_lut),
1701 dm_plane_state->base.color_mgmt_changed |= replaced;
1703 } else if (property == adev->mode_info.plane_shaper_tf_property) {
1704 if (dm_plane_state->shaper_tf != val) {
1705 dm_plane_state->shaper_tf = val;
1706 dm_plane_state->base.color_mgmt_changed = 1;
1708 } else if (property == adev->mode_info.plane_lut3d_property) {
1709 ret = drm_property_replace_blob_from_id(plane->dev,
1710 &dm_plane_state->lut3d,
1712 sizeof(struct drm_color_lut),
1714 dm_plane_state->base.color_mgmt_changed |= replaced;
1716 } else if (property == adev->mode_info.plane_blend_lut_property) {
1717 ret = drm_property_replace_blob_from_id(plane->dev,
1718 &dm_plane_state->blend_lut,
1720 sizeof(struct drm_color_lut),
1722 dm_plane_state->base.color_mgmt_changed |= replaced;
1724 } else if (property == adev->mode_info.plane_blend_tf_property) {
1725 if (dm_plane_state->blend_tf != val) {
1726 dm_plane_state->blend_tf = val;
1727 dm_plane_state->base.color_mgmt_changed = 1;
1730 drm_dbg_atomic(plane->dev,
1731 "[PLANE:%d:%s] unknown property [PROP:%d:%s]]\n",
1732 plane->base.id, plane->name,
1733 property->base.id, property->name);
1741 dm_atomic_plane_get_property(struct drm_plane *plane,
1742 const struct drm_plane_state *state,
1743 struct drm_property *property,
1746 struct dm_plane_state *dm_plane_state = to_dm_plane_state(state);
1747 struct amdgpu_device *adev = drm_to_adev(plane->dev);
1749 if (property == adev->mode_info.plane_degamma_lut_property) {
1750 *val = (dm_plane_state->degamma_lut) ?
1751 dm_plane_state->degamma_lut->base.id : 0;
1752 } else if (property == adev->mode_info.plane_degamma_tf_property) {
1753 *val = dm_plane_state->degamma_tf;
1754 } else if (property == adev->mode_info.plane_hdr_mult_property) {
1755 *val = dm_plane_state->hdr_mult;
1756 } else if (property == adev->mode_info.plane_ctm_property) {
1757 *val = (dm_plane_state->ctm) ?
1758 dm_plane_state->ctm->base.id : 0;
1759 } else if (property == adev->mode_info.plane_shaper_lut_property) {
1760 *val = (dm_plane_state->shaper_lut) ?
1761 dm_plane_state->shaper_lut->base.id : 0;
1762 } else if (property == adev->mode_info.plane_shaper_tf_property) {
1763 *val = dm_plane_state->shaper_tf;
1764 } else if (property == adev->mode_info.plane_lut3d_property) {
1765 *val = (dm_plane_state->lut3d) ?
1766 dm_plane_state->lut3d->base.id : 0;
1767 } else if (property == adev->mode_info.plane_blend_lut_property) {
1768 *val = (dm_plane_state->blend_lut) ?
1769 dm_plane_state->blend_lut->base.id : 0;
1770 } else if (property == adev->mode_info.plane_blend_tf_property) {
1771 *val = dm_plane_state->blend_tf;
1781 static const struct drm_plane_funcs dm_plane_funcs = {
1782 .update_plane = drm_atomic_helper_update_plane,
1783 .disable_plane = drm_atomic_helper_disable_plane,
1784 .destroy = drm_plane_helper_destroy,
1785 .reset = amdgpu_dm_plane_drm_plane_reset,
1786 .atomic_duplicate_state = amdgpu_dm_plane_drm_plane_duplicate_state,
1787 .atomic_destroy_state = amdgpu_dm_plane_drm_plane_destroy_state,
1788 .format_mod_supported = amdgpu_dm_plane_format_mod_supported,
1789 #ifdef AMD_PRIVATE_COLOR
1790 .atomic_set_property = dm_atomic_plane_set_property,
1791 .atomic_get_property = dm_atomic_plane_get_property,
1795 int amdgpu_dm_plane_init(struct amdgpu_display_manager *dm,
1796 struct drm_plane *plane,
1797 unsigned long possible_crtcs,
1798 const struct dc_plane_cap *plane_cap)
1800 uint32_t formats[32];
1803 unsigned int supported_rotations;
1804 uint64_t *modifiers = NULL;
1805 unsigned int primary_zpos = dm->dc->caps.max_slave_planes;
1807 num_formats = amdgpu_dm_plane_get_plane_formats(plane, plane_cap, formats,
1808 ARRAY_SIZE(formats));
1810 res = amdgpu_dm_plane_get_plane_modifiers(dm->adev, plane->type, &modifiers);
1814 if (modifiers == NULL)
1815 adev_to_drm(dm->adev)->mode_config.fb_modifiers_not_supported = true;
1817 res = drm_universal_plane_init(adev_to_drm(dm->adev), plane, possible_crtcs,
1818 &dm_plane_funcs, formats, num_formats,
1819 modifiers, plane->type, NULL);
1824 if (plane->type == DRM_PLANE_TYPE_OVERLAY &&
1825 plane_cap && plane_cap->per_pixel_alpha) {
1826 unsigned int blend_caps = BIT(DRM_MODE_BLEND_PIXEL_NONE) |
1827 BIT(DRM_MODE_BLEND_PREMULTI) |
1828 BIT(DRM_MODE_BLEND_COVERAGE);
1830 drm_plane_create_alpha_property(plane);
1831 drm_plane_create_blend_mode_property(plane, blend_caps);
1834 if (plane->type == DRM_PLANE_TYPE_PRIMARY) {
1836 * Allow OVERLAY planes to be used as underlays by assigning an
1837 * immutable zpos = # of OVERLAY planes to the PRIMARY plane.
1839 drm_plane_create_zpos_immutable_property(plane, primary_zpos);
1840 } else if (plane->type == DRM_PLANE_TYPE_OVERLAY) {
1842 * OVERLAY planes can be below or above the PRIMARY, but cannot
1843 * be above the CURSOR plane.
1845 unsigned int zpos = primary_zpos + 1 + drm_plane_index(plane);
1847 drm_plane_create_zpos_property(plane, zpos, 0, 254);
1848 } else if (plane->type == DRM_PLANE_TYPE_CURSOR) {
1849 drm_plane_create_zpos_immutable_property(plane, 255);
1852 if (plane->type == DRM_PLANE_TYPE_PRIMARY &&
1854 (plane_cap->pixel_format_support.nv12 ||
1855 plane_cap->pixel_format_support.p010)) {
1856 /* This only affects YUV formats. */
1857 drm_plane_create_color_properties(
1859 BIT(DRM_COLOR_YCBCR_BT601) |
1860 BIT(DRM_COLOR_YCBCR_BT709) |
1861 BIT(DRM_COLOR_YCBCR_BT2020),
1862 BIT(DRM_COLOR_YCBCR_LIMITED_RANGE) |
1863 BIT(DRM_COLOR_YCBCR_FULL_RANGE),
1864 DRM_COLOR_YCBCR_BT709, DRM_COLOR_YCBCR_LIMITED_RANGE);
1867 supported_rotations =
1868 DRM_MODE_ROTATE_0 | DRM_MODE_ROTATE_90 |
1869 DRM_MODE_ROTATE_180 | DRM_MODE_ROTATE_270;
1871 if (dm->adev->asic_type >= CHIP_BONAIRE &&
1872 plane->type != DRM_PLANE_TYPE_CURSOR)
1873 drm_plane_create_rotation_property(plane, DRM_MODE_ROTATE_0,
1874 supported_rotations);
1876 if (amdgpu_ip_version(dm->adev, DCE_HWIP, 0) > IP_VERSION(3, 0, 1) &&
1877 plane->type != DRM_PLANE_TYPE_CURSOR)
1878 drm_plane_enable_fb_damage_clips(plane);
1880 if (plane->type == DRM_PLANE_TYPE_PRIMARY)
1881 drm_plane_helper_add(plane, &dm_primary_plane_helper_funcs);
1883 drm_plane_helper_add(plane, &dm_plane_helper_funcs);
1885 #ifdef AMD_PRIVATE_COLOR
1886 dm_atomic_plane_attach_color_mgmt_properties(dm, plane);
1888 /* Create (reset) the plane state */
1889 if (plane->funcs->reset)
1890 plane->funcs->reset(plane);
1895 bool amdgpu_dm_plane_is_video_format(uint32_t format)
1899 for (i = 0; i < ARRAY_SIZE(video_formats); i++)
1900 if (format == video_formats[i])