Skip to contentSkip to conversation

DC Patches July 20th, 2026

PATCH In review Fangzhi Zuo 3 participants 52 messages Jul 23 – Sep 17

Subsystems (4)
lore
Share & tools
lore
#0 lore raw

cover DC Patches July 20th, 2026

This DC patchset brings improvements in multiple areas. In summary, we have:
* Expand KUnit test
* dm refactor ongoing
* Fix apple 5k tiled monitor light up
* Fix frl dsc upstream mistake
* dcn42 fixes

Alex Deucher (1):
drm/amd/display: check if dml21_add_phantom_plane() is successful

Alex Hung (16):
drm/amd/display: share common DM KUnit helpers drm/amd/display: move scaling helper to connector drm/amd/display: move stutter quirk to quirks file drm/amd/display: move watermarks table to pp_smu drm/amd/display: move GPU mem helpers to services drm/amd/display: add FreeSync/VRR module drm/amd/display: add cursor module
drm/amd/display: add KUnit tests for audio component get_eld drm/amd/display: add KUnit tests for audio commit path drm/amd/display: Add KUnit test for native backlight registration drm/amd/display: Add color transfer-function tests drm/amd/display: Add atomic transfer-function tests drm/amd/display: Add CRTC and plane degamma tests drm/amd/display: Add legacy plane LUT tests drm/amd/display: Add truncated colorop tests drm/amd/display: Add colorop LUT programming tests

Alexander Chechik (2):
drm/amd/display: enforce UCLK pstate support in mode_support drm/amd/display: plumb PMO per-plane pstate methods into mode_support

Bhawanpreet Lakha (13):
drm/amd/display: Add KUnit tests for link_lock and psp SRM helpers drm/amd/display: Add KUnit tests for HDCP display helpers drm/amd/display: Add KUnit tests for event_callback drm/amd/display: Add KUnit tests for event_property_validate drm/amd/display: Add KUnit tests for watchdog and cpirq events drm/amd/display: Add KUnit tests for hdcp_destroy drm/amd/display: Add KUnit tests for enable_assr drm/amd/display: Add KUnit tests for update_config drm/amd/display: Add KUnit tests for hdcp_create_workqueue drm/amd/display: Add KUnit tests for srm_data_write and srm_data_read drm/amd/display: Add KUnit tests for HDCP DDC link adapters drm/amd/display: Add initialized-branch test for psp_set_srm drm/amd/display: Add deeper event_property_update tests

Charlene Liu (2):
drm/amd/display: revert "convert dcn42 GPIO translation to lookup
tables"
drm/amd/display: change dcc_rate from 1 to 2 for log use only

Clay King (1):
drm/amd/display: adjust floating point format for gamut remap when
needed

Dillon Varone (1):
drm/amd/display: Port DCN4+ MCIF ARB programming to new format

Fangzhi Zuo (2):
drm/amd/display: Prune per-tile Timing from Apple Studio Display
Primary Tile
drm/amd/display: dispatch compressed FRL cap check inside
dml1_frl_cap_chk_inter

George Zhang (1):
drm/amd/display: Fix divide-by-zero in calculate_mcache_setting on
zero viewport

Huang, Leon (1):
drm/amd/display: Add get replay residency function

Justin Chen (1):
drm/amd/display: add DalForceMaxDisplayClock debug option to DML2

Matthew Stewart (2):
drm/amd/display: Fixes for dcn42b_soc_bb.h drm/amd/display: Fix rounding errors in CalculatePrefetchSchedule

Nicholas Carbones (2):
drm/amd/display: Correct vblank_end calc for fams cmd packet drm/amd/display: Reintroduce "convert dcn42 GPIO translation to lookup
tables"

Ray Wu (1):
drm/amd/display: Add AV mute wait frames to dce110_set_avmute

Relja Vojvodic (1):
drm/amd/display: Fix force FRL rate debug setting

Santhosh, Ashwin (1):
drm/amd/display: Promote DC to 3.2.391

Tomasz Siemek (1):
drm/amd/display: Use current mpc pipe in set output transfer func

 .../gpu/drm/amd/display/amdgpu_dm/Makefile    |    4 +-
 .../gpu/drm/amd/display/amdgpu_dm/amdgpu_dm.c |  981 +-------
 .../gpu/drm/amd/display/amdgpu_dm/amdgpu_dm.h |   37 +-
 .../amd/display/amdgpu_dm/amdgpu_dm_audio.c   |    1 +
 .../amd/display/amdgpu_dm/amdgpu_dm_color.c   |   36 +-
 .../amd/display/amdgpu_dm/amdgpu_dm_color.h   |   14 +
 .../display/amdgpu_dm/amdgpu_dm_connector.c   |  100 +
 .../amd/display/amdgpu_dm/amdgpu_dm_cursor.c  |  443 ++++
 .../amd/display/amdgpu_dm/amdgpu_dm_cursor.h  |   52 +
 .../display/amdgpu_dm/amdgpu_dm_freesync.c    |  362 +++
 .../display/amdgpu_dm/amdgpu_dm_freesync.h    |   65 +
 .../amd/display/amdgpu_dm/amdgpu_dm_hdcp.c    |   99 +-
 .../amd/display/amdgpu_dm/amdgpu_dm_hdcp.h    |   37 +
 .../amd/display/amdgpu_dm/amdgpu_dm_pp_smu.c  |   52 +
 .../amd/display/amdgpu_dm/amdgpu_dm_pp_smu.h  |    3 +
 .../amd/display/amdgpu_dm/amdgpu_dm_quirks.c  |   32 +
 .../display/amdgpu_dm/amdgpu_dm_services.c    |   53 +
 .../drm/amd/display/amdgpu_dm/tests/Makefile  |    2 +
 .../amdgpu_dm/tests/amdgpu_dm_audio_test.c    |  651 ++++++
 .../tests/amdgpu_dm_backlight_test.c          |   61 +-
 .../amdgpu_dm/tests/amdgpu_dm_color_test.c    |  602 +++++
 .../tests/amdgpu_dm_connector_test.c          |  209 ++
 .../amdgpu_dm/tests/amdgpu_dm_crtc_test.c     |   30 +-
 .../amdgpu_dm/tests/amdgpu_dm_cursor_test.c   |  268 +++
 .../amdgpu_dm/tests/amdgpu_dm_freesync_test.c |  453 ++++
 .../amdgpu_dm/tests/amdgpu_dm_hdcp_test.c     | 2063 ++++++++++++++++-
 .../amdgpu_dm/tests/amdgpu_dm_irq_test.c      |   32 +-
 .../amdgpu_dm/tests/amdgpu_dm_kunit_helpers.c |   39 +-
 .../tests/amdgpu_dm_kunit_test_helpers.h      |    4 +
 .../amdgpu_dm/tests/amdgpu_dm_pp_smu_test.c   |   20 +
 .../amdgpu_dm/tests/amdgpu_dm_psr_test.c      |   15 +-
 .../amdgpu_dm/tests/amdgpu_dm_quirks_test.c   |   65 +
 .../display/amdgpu_dm/tests/amdgpu_dm_test.c  |  937 --------
 .../drm/amd/display/dc/basics/conversion.c    |   61 +-
 .../drm/amd/display/dc/basics/conversion.h    |   12 +-
 .../drm/amd/display/dc/core/dc_hw_sequencer.c |    4 +-
 .../drm/amd/display/dc/core/dc_link_exports.c |    7 +
 .../gpu/drm/amd/display/dc/core/dc_stream.c   |    4 +-
 drivers/gpu/drm/amd/display/dc/dc.h           |   11 +-
 .../drm/amd/display/dc/dce/dce_transform.c    |    4 +-
 .../drm/amd/display/dc/dml/dml1_frl_cap_chk.c |   10 +-
 .../dml2_0/dml21/dml21_translation_helper.c   |    8 +-
 .../amd/display/dc/dml2_0/dml21/dml21_utils.c |   15 +-
 .../dc/dml2_0/dml21/dml21_wrapper_fpu.c       |    5 +
 .../dml21/inc/bounding_boxes/dcn42b_soc_bb.h  |    4 +-
 .../dml21/src/dml2_core/dml2_core_dcn4.c      |    4 +
 .../src/dml2_core/dml2_core_dcn4_calcs.c      |   67 +-
 .../src/dml2_core/dml2_core_shared_types.h    |    1 +
 .../dml21/src/dml2_pmo/dml2_pmo_dcn42.c       |   32 +-
 .../dml21/src/dml2_pmo/dml2_pmo_dcn4_fams2.c  |    2 +-
 .../amd/display/dc/dpp/dcn10/dcn10_dpp_cm.c   |    8 +-
 .../amd/display/dc/dpp/dcn20/dcn20_dpp_cm.c   |    8 +-
 .../amd/display/dc/dpp/dcn30/dcn30_dpp_cm.c   |    8 +-
 .../amd/display/dc/dwb/dcn30/dcn30_dwb_cm.c   |    3 +-
 .../dc/gpio/dcn42/hw_translate_dcn42.c.orig   |  206 ++
 .../amd/display/dc/hwss/dce110/dce110_hwseq.c |   21 +-
 .../display/dc/link/protocols/link_hdmi_frl.c |    2 +-
 .../gpu/drm/amd/display/dc/mmhubbub/Makefile  |   10 +
 .../dc/mmhubbub/dcn32/dcn32_mmhubbub.c        |    4 +-
 .../dc/mmhubbub/dcn32/dcn32_mmhubbub.h        |    5 +
 .../dc/mmhubbub/dcn401/dcn401_mmhubbub.c      |  135 ++
 .../dc/mmhubbub/dcn401/dcn401_mmhubbub.h      |   40 +
 .../dc/mmhubbub/dcn42/dcn42_mmhubbub.h        |    1 +
 .../drm/amd/display/dc/mpc/dcn30/dcn30_mpc.c  |   44 +-
 .../amd/display/dc/mpc/dcn401/dcn401_mpc.c    |   69 +-
 .../amd/display/dc/mpc/dcn401/dcn401_mpc.h    |    6 +-
 .../dc/resource/dcn30/dcn30_resource.c        |    2 +
 .../dc/resource/dcn301/dcn301_resource.c      |    2 +
 .../dc/resource/dcn302/dcn302_resource.c      |    2 +
 .../dc/resource/dcn303/dcn303_resource.c      |    2 +
 .../dc/resource/dcn31/dcn31_resource.c        |    2 +
 .../dc/resource/dcn314/dcn314_resource.c      |    2 +
 .../dc/resource/dcn315/dcn315_resource.c      |    2 +
 .../dc/resource/dcn316/dcn316_resource.c      |    2 +
 .../dc/resource/dcn32/dcn32_resource.c        |    2 +
 .../dc/resource/dcn321/dcn321_resource.c      |    2 +
 .../dc/resource/dcn35/dcn35_resource.c        |    2 +
 .../dc/resource/dcn351/dcn351_resource.c      |    2 +
 .../dc/resource/dcn36/dcn36_resource.c        |    2 +
 .../dc/resource/dcn401/dcn401_resource.c      |   31 +-
 .../dc/resource/dcn401/dcn401_resource.h      |    4 +
 .../dc/resource/dcn42/dcn42_resource.c        |   30 +-
 .../dc/resource/dcn42b/dcn42b_resource.c      |    2 +
 83 files changed, 6482 insertions(+), 2254 deletions(-)
 create mode 100644 drivers/gpu/drm/amd/display/amdgpu_dm/amdgpu_dm_cursor.c
 create mode 100644 drivers/gpu/drm/amd/display/amdgpu_dm/amdgpu_dm_cursor.h
 create mode 100644 drivers/gpu/drm/amd/display/amdgpu_dm/amdgpu_dm_freesync.c
 create mode 100644 drivers/gpu/drm/amd/display/amdgpu_dm/amdgpu_dm_freesync.h
 create mode 100644 drivers/gpu/drm/amd/display/amdgpu_dm/tests/amdgpu_dm_cursor_test.c
 create mode 100644 drivers/gpu/drm/amd/display/amdgpu_dm/tests/amdgpu_dm_freesync_test.c
 create mode 100644 drivers/gpu/drm/amd/display/dc/gpio/dcn42/hw_translate_dcn42.c.orig
 create mode 100644 drivers/gpu/drm/amd/display/dc/mmhubbub/dcn401/dcn401_mmhubbub.c
 create mode 100644 drivers/gpu/drm/amd/display/dc/mmhubbub/dcn401/dcn401_mmhubbub.h
Signature · 1 line
2.53.0
#1 lore raw

PATCH 1/49 drm/amd/display: share common DM KUnit helpers

From: Alex Hung <[email protected]>

Move fixture setup that was duplicated across several amdgpu_dm KUnit tests into amdgpu_dm_kunit_helpers.c:

- dm_kunit_alloc_dc_with_ctx() allocates a dc and its dc_context.
- dm_kunit_alloc_drm_with_connector_list() allocates a drm_device with an initialized connector list.

Update the irq, psr, crtc and backlight tests to use these helpers.

---
 .../tests/amdgpu_dm_backlight_test.c          |  9 +----
 .../amdgpu_dm/tests/amdgpu_dm_crtc_test.c     | 30 +++-----------
 .../amdgpu_dm/tests/amdgpu_dm_irq_test.c      | 32 ++++-----------
 .../amdgpu_dm/tests/amdgpu_dm_kunit_helpers.c | 39 +++++++++++++++----
 .../tests/amdgpu_dm_kunit_test_helpers.h      |  4 ++
 .../amdgpu_dm/tests/amdgpu_dm_psr_test.c      | 15 ++-----
 6 files changed, 52 insertions(+), 77 deletions(-)
drivers/gpu/drm/amd/display/amdgpu_dm/tests/amdgpu_dm_backlight_test.c +1 -8
index f55f93747df7..618fd5142da0 100644
@@ -56,14 +56,7 @@ static void setup_test_connector(struct kunit *test,
 
 static void setup_test_dm_ddev(struct kunit *test, struct amdgpu_display_manager *dm)
 {
-	struct drm_device *ddev;
-
-	ddev = kunit_kzalloc(test, sizeof(*ddev), GFP_KERNEL);
-	KUNIT_ASSERT_NOT_ERR_OR_NULL(test, ddev);
-
-	INIT_LIST_HEAD(&ddev->mode_config.connector_list);
-	spin_lock_init(&ddev->mode_config.connector_list_lock);
-	dm->ddev = ddev;
+	dm->ddev = dm_kunit_alloc_drm_with_connector_list(test);
 }
 
 /* Tests for dm_find_stream_with_link() */
drivers/gpu/drm/amd/display/amdgpu_dm/tests/amdgpu_dm_crtc_test.c +5 -25
index 0edaf969f16b..ac21bbec92ab 100644
@@ -296,13 +296,9 @@ static void dm_test_crtc_is_headless_null_adev(struct kunit *test)
 static void dm_test_crtc_is_headless_no_connectors(struct kunit *test)
 {
 	struct amdgpu_device *adev = kunit_kzalloc(test, sizeof(*adev), GFP_KERNEL);
-	struct drm_device *dev = kunit_kzalloc(test, sizeof(*dev), GFP_KERNEL);
+	struct drm_device *dev = dm_kunit_alloc_drm_with_connector_list(test);
 
 	KUNIT_ASSERT_NOT_ERR_OR_NULL(test, adev);
-	KUNIT_ASSERT_NOT_ERR_OR_NULL(test, dev);
-
-	INIT_LIST_HEAD(&dev->mode_config.connector_list);
-	spin_lock_init(&dev->mode_config.connector_list_lock);
 	adev->dm.ddev = dev;
 
 	KUNIT_EXPECT_TRUE(test, amdgpu_dm_is_headless(adev));
@@ -315,15 +311,11 @@ static void dm_test_crtc_is_headless_no_connectors(struct kunit *test)
 static void dm_test_crtc_is_headless_writeback_only(struct kunit *test)
 {
 	struct amdgpu_device *adev = kunit_kzalloc(test, sizeof(*adev), GFP_KERNEL);
-	struct drm_device *dev = kunit_kzalloc(test, sizeof(*dev), GFP_KERNEL);
+	struct drm_device *dev = dm_kunit_alloc_drm_with_connector_list(test);
 	struct drm_connector *wb = kunit_kzalloc(test, sizeof(*wb), GFP_KERNEL);
 
 	KUNIT_ASSERT_NOT_ERR_OR_NULL(test, adev);
-	KUNIT_ASSERT_NOT_ERR_OR_NULL(test, dev);
 	KUNIT_ASSERT_NOT_ERR_OR_NULL(test, wb);
-
-	INIT_LIST_HEAD(&dev->mode_config.connector_list);
-	spin_lock_init(&dev->mode_config.connector_list_lock);
 	adev->dm.ddev = dev;
 
 	dm_test_add_connector(dev, wb, DRM_MODE_CONNECTOR_WRITEBACK,
@@ -339,15 +331,11 @@ static void dm_test_crtc_is_headless_writeback_only(struct kunit *test)
 static void dm_test_crtc_is_headless_disconnected_display(struct kunit *test)
 {
 	struct amdgpu_device *adev = kunit_kzalloc(test, sizeof(*adev), GFP_KERNEL);
-	struct drm_device *dev = kunit_kzalloc(test, sizeof(*dev), GFP_KERNEL);
+	struct drm_device *dev = dm_kunit_alloc_drm_with_connector_list(test);
 	struct drm_connector *display = kunit_kzalloc(test, sizeof(*display), GFP_KERNEL);
 
 	KUNIT_ASSERT_NOT_ERR_OR_NULL(test, adev);
-	KUNIT_ASSERT_NOT_ERR_OR_NULL(test, dev);
 	KUNIT_ASSERT_NOT_ERR_OR_NULL(test, display);
-
-	INIT_LIST_HEAD(&dev->mode_config.connector_list);
-	spin_lock_init(&dev->mode_config.connector_list_lock);
 	adev->dm.ddev = dev;
 
 	dm_test_add_connector(dev, display, DRM_MODE_CONNECTOR_HDMIA,
@@ -363,15 +351,11 @@ static void dm_test_crtc_is_headless_disconnected_display(struct kunit *test)
 static void dm_test_crtc_is_headless_connected_display(struct kunit *test)
 {
 	struct amdgpu_device *adev = kunit_kzalloc(test, sizeof(*adev), GFP_KERNEL);
-	struct drm_device *dev = kunit_kzalloc(test, sizeof(*dev), GFP_KERNEL);
+	struct drm_device *dev = dm_kunit_alloc_drm_with_connector_list(test);
 	struct drm_connector *display = kunit_kzalloc(test, sizeof(*display), GFP_KERNEL);
 
 	KUNIT_ASSERT_NOT_ERR_OR_NULL(test, adev);
-	KUNIT_ASSERT_NOT_ERR_OR_NULL(test, dev);
 	KUNIT_ASSERT_NOT_ERR_OR_NULL(test, display);
-
-	INIT_LIST_HEAD(&dev->mode_config.connector_list);
-	spin_lock_init(&dev->mode_config.connector_list_lock);
 	adev->dm.ddev = dev;
 
 	dm_test_add_connector(dev, display, DRM_MODE_CONNECTOR_HDMIA,
@@ -387,17 +371,13 @@ static void dm_test_crtc_is_headless_connected_display(struct kunit *test)
 static void dm_test_crtc_is_headless_mixed_connectors(struct kunit *test)
 {
 	struct amdgpu_device *adev = kunit_kzalloc(test, sizeof(*adev), GFP_KERNEL);
-	struct drm_device *dev = kunit_kzalloc(test, sizeof(*dev), GFP_KERNEL);
+	struct drm_device *dev = dm_kunit_alloc_drm_with_connector_list(test);
 	struct drm_connector *wb = kunit_kzalloc(test, sizeof(*wb), GFP_KERNEL);
 	struct drm_connector *display = kunit_kzalloc(test, sizeof(*display), GFP_KERNEL);
 
 	KUNIT_ASSERT_NOT_ERR_OR_NULL(test, adev);
-	KUNIT_ASSERT_NOT_ERR_OR_NULL(test, dev);
 	KUNIT_ASSERT_NOT_ERR_OR_NULL(test, wb);
 	KUNIT_ASSERT_NOT_ERR_OR_NULL(test, display);
-
-	INIT_LIST_HEAD(&dev->mode_config.connector_list);
-	spin_lock_init(&dev->mode_config.connector_list_lock);
 	adev->dm.ddev = dev;
 
 	dm_test_add_connector(dev, wb, DRM_MODE_CONNECTOR_WRITEBACK,
drivers/gpu/drm/amd/display/amdgpu_dm/tests/amdgpu_dm_irq_test.c +8 -24
index dc7ef0523b8f..28c36217f6a2 100644
@@ -202,22 +202,6 @@ static void dm_test_dmub_notify_callback(struct amdgpu_device *adev,
 	dm_test_dmub_notify_count++;
 }
 
-static struct dc *dm_test_alloc_dc_with_ctx(struct kunit *test)
-{
-	struct dc_context *ctx;
-	struct dc *dc;
-
-	dc = kunit_kzalloc(test, sizeof(*dc), GFP_KERNEL);
-	KUNIT_ASSERT_NOT_ERR_OR_NULL(test, dc);
-	ctx = kunit_kzalloc(test, sizeof(*ctx), GFP_KERNEL);
-	KUNIT_ASSERT_NOT_ERR_OR_NULL(test, ctx);
-
-	dc->ctx = ctx;
-	ctx->dc = dc;
-
-	return dc;
-}
-
 static enum dc_irq_source dm_test_to_dal_irq_source_dce110(
 		struct irq_service *irq_service,
 		uint32_t src_id,
@@ -299,7 +283,7 @@ static struct dc *dm_test_alloc_dc_with_irq_service(struct kunit *test,
 	struct dc *dc;
 	int i;
 
-	dc = dm_test_alloc_dc_with_ctx(test);
+	dc = dm_kunit_alloc_dc_with_ctx(test);
 	res_pool = kunit_kzalloc(test, sizeof(*res_pool), GFP_KERNEL);
 	KUNIT_ASSERT_NOT_ERR_OR_NULL(test, res_pool);
 	irqs = kunit_kzalloc(test, sizeof(*irqs), GFP_KERNEL);
@@ -3283,7 +3267,7 @@ static void dm_test_register_hpd_handlers_dmub_outbox(struct kunit *test)
 
 	adev = dm_kunit_alloc_adev(test);
 	KUNIT_ASSERT_EQ(test, amdgpu_dm_irq_init(adev), 0);
-	dc = dm_test_alloc_dc_with_ctx(test);
+	dc = dm_kunit_alloc_dc_with_ctx(test);
 	adev->dm.dc = dc;
 
 	/* Make dc_is_dmub_outbox_supported() return true. */
@@ -3495,7 +3479,7 @@ static void dm_test_dmub_outbox1_low_irq_empty(struct kunit *test)
 	struct dc *dc;
 
 	adev = dm_kunit_alloc_adev(test);
-	dc = dm_test_alloc_dc_with_ctx(test);
+	dc = dm_kunit_alloc_dc_with_ctx(test);
 	dc_dmub_srv = kunit_kzalloc(test, sizeof(*dc_dmub_srv), GFP_KERNEL);
 	KUNIT_ASSERT_NOT_ERR_OR_NULL(test, dc_dmub_srv);
 	dmub = kunit_kzalloc(test, sizeof(*dmub), GFP_KERNEL);
@@ -3529,7 +3513,7 @@ static struct amdgpu_device *dm_test_alloc_adev_outbox_notify(struct kunit *test
 	struct dc *dc;
 
 	adev = dm_kunit_alloc_adev(test);
-	dc = dm_test_alloc_dc_with_ctx(test);
+	dc = dm_kunit_alloc_dc_with_ctx(test);
 	dc_dmub_srv = kunit_kzalloc(test, sizeof(*dc_dmub_srv), GFP_KERNEL);
 	KUNIT_ASSERT_NOT_ERR_OR_NULL(test, dc_dmub_srv);
 	dmub = kunit_kzalloc(test, sizeof(*dmub), GFP_KERNEL);
@@ -3635,7 +3619,7 @@ static void dm_test_dce110_register_irq_handlers_rejects_uninitialized_sources(s
 	struct dc *dc;
 
 	adev = dm_kunit_alloc_adev(test);
-	dc = dm_test_alloc_dc_with_ctx(test);
+	dc = dm_kunit_alloc_dc_with_ctx(test);
 	adev->dm.dc = dc;
 
 	KUNIT_EXPECT_EQ(test, amdgpu_dm_dce110_register_irq_handlers(adev), -EINVAL);
@@ -3696,7 +3680,7 @@ static void dm_test_dcn10_register_irq_handlers_zero_crtc(struct kunit *test)
 	adev = dm_kunit_alloc_adev(test);
 	KUNIT_ASSERT_EQ(test, kunit_add_action_or_reset(test, dm_test_free_irq_sources,
 							 adev), 0);
-	dc = dm_test_alloc_dc_with_ctx(test);
+	dc = dm_kunit_alloc_dc_with_ctx(test);
 	adev->dm.dc = dc;
 	adev->mode_info.num_hpd = 1;
 	amdgpu_dm_set_irq_funcs(adev);
@@ -3759,7 +3743,7 @@ static void dm_test_register_outbox_irq_handlers_without_dmub(struct kunit *test
 	adev = dm_kunit_alloc_adev(test);
 	KUNIT_ASSERT_EQ(test, kunit_add_action_or_reset(test, dm_test_free_irq_sources,
 							 adev), 0);
-	dc = dm_test_alloc_dc_with_ctx(test);
+	dc = dm_kunit_alloc_dc_with_ctx(test);
 	adev->dm.dc = dc;
 	amdgpu_dm_set_irq_funcs(adev);
 
@@ -3899,7 +3883,7 @@ static void dm_test_handle_vmin_vmax_update(struct kunit *test)
 	KUNIT_ASSERT_NOT_ERR_OR_NULL(test, adev);
 	mutex_init(&adev->dm.dc_lock);
 
-	dc = dm_test_alloc_dc_with_ctx(test);
+	dc = dm_kunit_alloc_dc_with_ctx(test);
 	dc->current_state = kunit_kzalloc(test, sizeof(*dc->current_state),
 					  GFP_KERNEL);
 	KUNIT_ASSERT_NOT_ERR_OR_NULL(test, dc->current_state);
drivers/gpu/drm/amd/display/amdgpu_dm/tests/amdgpu_dm_kunit_helpers.c +31 -8
index 58615cdbe854..75cd4fef3076 100644
@@ -45,23 +45,32 @@ struct dc_link *dm_kunit_alloc_link(struct kunit *test)
 }
 EXPORT_SYMBOL(dm_kunit_alloc_link);
 
-struct dc_link *dm_kunit_alloc_link_with_ctx(struct kunit *test)
+struct dc *dm_kunit_alloc_dc_with_ctx(struct kunit *test)
 {
-	struct dc_link *link;
 	struct dc_context *ctx;
 	struct dc *dc;
 
-	link = dm_kunit_alloc_link(test);
+	dc = kunit_kzalloc(test, sizeof(*dc), GFP_KERNEL);
+	KUNIT_ASSERT_NOT_NULL(test, dc);
 
 	ctx = kunit_kzalloc(test, sizeof(*ctx), GFP_KERNEL);
 	KUNIT_ASSERT_NOT_NULL(test, ctx);
 
-	dc = kunit_kzalloc(test, sizeof(*dc), GFP_KERNEL);
-	KUNIT_ASSERT_NOT_NULL(test, dc);
-
-	link->ctx = ctx;
-	ctx->dc = dc;
 	dc->ctx = ctx;
+	ctx->dc = dc;
+
+	return dc;
+}
+EXPORT_SYMBOL(dm_kunit_alloc_dc_with_ctx);
+
+struct dc_link *dm_kunit_alloc_link_with_ctx(struct kunit *test)
+{
+	struct dc_link *link;
+	struct dc *dc;
+
+	link = dm_kunit_alloc_link(test);
+	dc = dm_kunit_alloc_dc_with_ctx(test);
+	link->ctx = dc->ctx;
 
 	return link;
 }
@@ -138,5 +147,19 @@ struct amdgpu_dm_connector *dm_kunit_alloc_connector(struct kunit *test,
 }
 EXPORT_SYMBOL(dm_kunit_alloc_connector);
 
+struct drm_device *dm_kunit_alloc_drm_with_connector_list(struct kunit *test)
+{
+	struct drm_device *dev;
+
+	dev = kunit_kzalloc(test, sizeof(*dev), GFP_KERNEL);
+	KUNIT_ASSERT_NOT_ERR_OR_NULL(test, dev);
+
+	INIT_LIST_HEAD(&dev->mode_config.connector_list);
+	spin_lock_init(&dev->mode_config.connector_list_lock);
+
+	return dev;
+}
+EXPORT_SYMBOL(dm_kunit_alloc_drm_with_connector_list);
+
 MODULE_LICENSE("Dual MIT/GPL");
 MODULE_DESCRIPTION("KUnit test helpers for amdgpu_dm tests");
drivers/gpu/drm/amd/display/amdgpu_dm/tests/amdgpu_dm_kunit_test_helpers.h +4 -0
index 0f1c48fa2128..49b358681d60 100644
@@ -13,14 +13,18 @@
 struct amdgpu_device;
 struct amdgpu_display_manager;
 struct amdgpu_dm_connector;
+struct dc;
 struct dc_link;
 struct dc_state;
 struct dc_stream_state;
+struct drm_device;
 
 struct amdgpu_device *dm_kunit_alloc_adev(struct kunit *test);
+struct dc *dm_kunit_alloc_dc_with_ctx(struct kunit *test);
 struct dc_link *dm_kunit_alloc_link(struct kunit *test);
 struct dc_link *dm_kunit_alloc_link_with_ctx(struct kunit *test);
 struct amdgpu_display_manager *dm_kunit_alloc_dm(struct kunit *test);
+struct drm_device *dm_kunit_alloc_drm_with_connector_list(struct kunit *test);
 struct dc_stream_state *dm_kunit_alloc_stream(struct kunit *test,
 					      struct dc_link *link);
 void dm_kunit_add_stream_to_state(struct kunit *test, struct dc_state *state,
drivers/gpu/drm/amd/display/amdgpu_dm/tests/amdgpu_dm_psr_test.c +3 -12
index 09bd98e93047..0a484ea7c0e8 100644
@@ -46,19 +46,10 @@ static struct core_power *create_test_power_module(struct kunit *test,
 
 static struct dc_link *alloc_test_psrsu_link(struct kunit *test)
 {
-	struct dc_link *link = dm_kunit_alloc_link(test);
-	struct dc_context *ctx;
-	struct dc *dc;
-
-	ctx = kunit_kzalloc(test, sizeof(*ctx), GFP_KERNEL);
-	KUNIT_ASSERT_NOT_NULL(test, ctx);
-
-	dc = kunit_kzalloc(test, sizeof(*dc), GFP_KERNEL);
-	KUNIT_ASSERT_NOT_NULL(test, dc);
+	struct dc_link *link = dm_kunit_alloc_link_with_ctx(test);
+	struct dc_context *ctx = link->ctx;
+	struct dc *dc = ctx->dc;
 
-	link->ctx = ctx;
-	ctx->dc = dc;
-	dc->ctx = ctx;
 	dc->caps.dmcub_support = true;
 	ctx->dce_version = DCN_VERSION_3_1;
 	link->dpcd_caps.edp_rev = DP_EDP_14;
Signature · 1 line
2.53.0
#2 lore raw

PATCH 2/49 drm/amd/display: Port DCN4+ MCIF ARB programming to new format

In reply to Fangzhi Zuo

From: Dillon Varone <[email protected]>

[WHY&HOW]
DML2.1 now outputs MCIF arbiter programming, but using a new structure. Change DCN401 and DCN42 to use this new format.

---
 .../gpu/drm/amd/display/dc/mmhubbub/Makefile  |  10 ++
 .../dc/mmhubbub/dcn32/dcn32_mmhubbub.c        |   4 +-
 .../dc/mmhubbub/dcn32/dcn32_mmhubbub.h        |   5 +
 .../dc/mmhubbub/dcn401/dcn401_mmhubbub.c      | 135 ++++++++++++++++++
 .../dc/mmhubbub/dcn401/dcn401_mmhubbub.h      |  40 ++++++
 .../dc/mmhubbub/dcn42/dcn42_mmhubbub.h        |   1 +
 .../dc/resource/dcn401/dcn401_resource.c      |  29 ++--
 .../dc/resource/dcn401/dcn401_resource.h      |   4 +
 .../dc/resource/dcn42/dcn42_resource.c        |  28 ++--
 9 files changed, 227 insertions(+), 29 deletions(-)
 create mode 100644 drivers/gpu/drm/amd/display/dc/mmhubbub/dcn401/dcn401_mmhubbub.c
 create mode 100644 drivers/gpu/drm/amd/display/dc/mmhubbub/dcn401/dcn401_mmhubbub.h
drivers/gpu/drm/amd/display/dc/mmhubbub/Makefile +10 -0
index afc376defa0b..dddf5a9eb0b8 100644
@@ -50,6 +50,16 @@ MMHUBBUB_DCN35 = dcn35_mmhubbub.o
 AMD_DAL_MMHUBBUB_DCN35 = $(addprefix $(AMDDALPATH)/dc/mmhubbub/dcn35/,$(MMHUBBUB_DCN35))
 
 AMD_DISPLAY_FILES += $(AMD_DAL_MMHUBBUB_DCN35)
+
+
+###############################################################################
+# DCN401
+###############################################################################
+MMHUBBUB_DCN401 = dcn401_mmhubbub.o
+
+AMD_DAL_MMHUBBUB_DCN401 = $(addprefix $(AMDDALPATH)/dc/mmhubbub/dcn401/,$(MMHUBBUB_DCN401))
+
+AMD_DISPLAY_FILES += $(AMD_DAL_MMHUBBUB_DCN401)
 endif
 
 ###############################################################################
drivers/gpu/drm/amd/display/dc/mmhubbub/dcn32/dcn32_mmhubbub.c +2 -2
index 6b6f80a3bfd5..5ce787632fe9 100644
@@ -73,7 +73,7 @@
  *    the bufmgr status can show the progress of write back, can be used for debug purpose
  */
 
-static void mmhubbub32_warmup_mcif(struct mcif_wb *mcif_wb,
+void mmhubbub32_warmup_mcif(struct mcif_wb *mcif_wb,
 		struct mcif_warmup_params *params)
 {
 	struct dcn30_mmhubbub *mcif_wb30 = TO_DCN30_MMHUBBUB(mcif_wb);
@@ -100,7 +100,7 @@ static void mmhubbub32_warmup_mcif(struct mcif_wb *mcif_wb,
 	REG_UPDATE(MMHUBBUB_WARMUP_CONTROL_STATUS, MMHUBBUB_WARMUP_EN, false);
 }
 
-static void mmhubbub32_config_mcif_buf(struct mcif_wb *mcif_wb,
+void mmhubbub32_config_mcif_buf(struct mcif_wb *mcif_wb,
 		struct mcif_buf_params *params,
 		unsigned int dest_height)
 {
drivers/gpu/drm/amd/display/dc/mmhubbub/dcn32/dcn32_mmhubbub.h +5 -0
index ef15b4f1f6b9..682f3bba6d50 100644
@@ -200,6 +200,11 @@
 	SF(MMHUBBUB_WARMUP_CONTROL_STATUS, MMHUBBUB_WARMUP_SW_INT_ACK, mask_sh),\
 	SF(MMHUBBUB_WARMUP_CONTROL_STATUS, MMHUBBUB_WARMUP_INC_ADDR, mask_sh)
 
+void mmhubbub32_warmup_mcif(struct mcif_wb *mcif_wb,
+		struct mcif_warmup_params *params);
+void mmhubbub32_config_mcif_buf(struct mcif_wb *mcif_wb,
+		struct mcif_buf_params *params,
+		unsigned int dest_height);
 
 void dcn32_mmhubbub_construct(struct dcn30_mmhubbub *mcif_wb30,
 	struct dc_context *ctx,
drivers/gpu/drm/amd/display/dc/mmhubbub/dcn401/dcn401_mmhubbub.c new file +135 -0

135 lines not on this page · raw message

drivers/gpu/drm/amd/display/dc/mmhubbub/dcn401/dcn401_mmhubbub.h new file +40 -0
new file mode 100644
index 000000000000..fbc69a210fa7
@@ -0,0 +1,40 @@
+/* SPDX-License-Identifier: MIT */
+/* Copyright 2026 Advanced Micro Devices, Inc. */
+
+
+#ifndef __DCN401_MMHUBBUB_H
+#define __DCN401_MMHUBBUB_H
+
+#include "mcif_wb.h"
+#include "dcn32/dcn32_mmhubbub.h"
+#include "dcn35/dcn35_mmhubbub.h"
+
+#define MCIF_WB_REG_VARIABLE_LIST_DCN4_01  \
+	MCIF_WB_REG_VARIABLE_LIST_DCN3_5;
+
+#define MCIF_WB_COMMON_MASK_SH_LIST_DCN4_01(mask_sh)                            \
+	MCIF_WB_COMMON_MASK_SH_LIST_DCN3_5(mask_sh),                            \
+    SF(MCIF_WB_NB_PSTATE_LATENCY_WATERMARK, NB_PSTATE_CHANGE_WATERMARK_TYPE, mask_sh)
+
+#define MCIF_WB_REG_FIELD_LIST_DCN4_01(type)          \
+	struct {                                     \
+		MCIF_WB_REG_FIELD_LIST_DCN3_5(type); \
+		type NB_PSTATE_CHANGE_WATERMARK_TYPE;          \
+	}
+
+struct dcn401_mmhubbub_mask {
+	MCIF_WB_REG_FIELD_LIST_DCN4_01(uint32_t);
+};
+
+struct dcn401_mmhubbub_shift {
+	MCIF_WB_REG_FIELD_LIST_DCN4_01(uint8_t);
+};
+
+void dcn401_mmhubbub_construct(struct dcn30_mmhubbub *mcif_wb30,
+		struct dc_context *ctx,
+		const struct dcn35_mmhubbub_registers *mcif_wb_regs,
+		const struct dcn401_mmhubbub_shift *mcif_wb_shift,
+		const struct dcn401_mmhubbub_mask *mcif_wb_mask,
+		int inst);
+
+#endif // __DCN401_MMHUBBUB_H
drivers/gpu/drm/amd/display/dc/mmhubbub/dcn42/dcn42_mmhubbub.h +1 -0
index 0dd1f0d2eb88..0001903a04ec 100644
@@ -8,6 +8,7 @@
 #include "mcif_wb.h"
 #include "dcn32/dcn32_mmhubbub.h"
 #include "dcn35/dcn35_mmhubbub.h"
+#include "dcn401/dcn401_mmhubbub.h"
 
 void dcn42_mmhubbub_set_fgcg(struct dcn30_mmhubbub *mcif_wb30, bool enabled);
 #endif // __DCN42_MMHUBBUB_H
drivers/gpu/drm/amd/display/dc/resource/dcn401/dcn401_resource.c +15 -14
index e3ee792fb2e8..f7ba0509e6bd 100644
@@ -16,6 +16,7 @@
 #include "dcn30/dcn30_resource.h"
 #include "dcn32/dcn32_resource.h"
 #include "dcn321/dcn321_resource.h"
+#include "dcn35/dcn35_resource.h"
 
 #include "dcn10/dcn10_ipp.h"
 #include "dcn401/dcn401_hubbub.h"
@@ -58,7 +59,7 @@
 #include "dcn31/dcn31_panel_cntl.h"
 
 #include "dcn30/dcn30_dwb.h"
-#include "dcn32/dcn32_mmhubbub.h"
+#include "dcn401/dcn401_mmhubbub.h"
 
 #include "dcn/dcn_4_1_0_offset.h"
 #include "dcn/dcn_4_1_0_sh_mask.h"
@@ -435,17 +436,17 @@ static const struct dcn30_dwbc_mask dwbc401_mask = {
 };
 
 
-#define mcif_wb_regs_dcn3_init(id)\
-	MCIF_WB_COMMON_REG_LIST_DCN32_RI(id)
+#define mcif_wb_regs_dcn401_init(id) \
+	MCIF_WB_COMMON_REG_LIST_DCN4_01_RI(id)
 
-static struct dcn30_mmhubbub_registers mcif_wb30_regs[1];
+static struct dcn35_mmhubbub_registers mcif_wb401_regs[1];
 
-static const struct dcn30_mmhubbub_shift mcif_wb30_shift = {
-	MCIF_WB_COMMON_MASK_SH_LIST_DCN32(__SHIFT)
+static const struct dcn401_mmhubbub_shift mcif_wb401_shift = {
+	MCIF_WB_COMMON_MASK_SH_LIST_DCN4_01(__SHIFT)
 };
 
-static const struct dcn30_mmhubbub_mask mcif_wb30_mask = {
-	MCIF_WB_COMMON_MASK_SH_LIST_DCN32(_MASK)
+static const struct dcn401_mmhubbub_mask mcif_wb401_mask = {
+	MCIF_WB_COMMON_MASK_SH_LIST_DCN4_01(_MASK)
 };
 
 #define dsc_regs_init(id)\
@@ -1704,13 +1705,13 @@ static bool dcn401_mmhubbub_create(struct dc_context *ctx, struct resource_pool
 		}
 
 #undef REG_STRUCT
-#define REG_STRUCT mcif_wb30_regs
-		mcif_wb_regs_dcn3_init(0);
+#define REG_STRUCT mcif_wb401_regs
+		mcif_wb_regs_dcn401_init(0);
 
-		dcn32_mmhubbub_construct(mcif_wb30, ctx,
-				&mcif_wb30_regs[i],
-				&mcif_wb30_shift,
-				&mcif_wb30_mask,
+		dcn401_mmhubbub_construct(mcif_wb30, ctx,
+				&mcif_wb401_regs[i],
+				&mcif_wb401_shift,
+				&mcif_wb401_mask,
 				i);
 
 		pool->mcif_wb[i] = &mcif_wb30->base;
drivers/gpu/drm/amd/display/dc/resource/dcn401/dcn401_resource.h +4 -0
index ce96fe1ddb7c..42a0986d6fe2 100644
@@ -7,6 +7,7 @@
 
 #include "core_types.h"
 #include "dcn32/dcn32_resource.h"
+#include "dcn35/dcn35_resource.h"
 #include "dcn401/dcn401_hubp.h"
 
 #define TO_DCN401_RES_POOL(pool)\
@@ -660,4 +661,7 @@ int dcn401_get_power_profile(const struct dc_state *context);
 	SR(SYMCLKC_CLOCK_ENABLE),\
 	SR(SYMCLKD_CLOCK_ENABLE)
 
+#define MCIF_WB_COMMON_REG_LIST_DCN4_01_RI(inst)  \
+	MCIF_WB_COMMON_REG_LIST_DCN3_5_RI(inst)
+
 #endif /* _DCN401_RESOURCE_H_ */
drivers/gpu/drm/amd/display/dc/resource/dcn42/dcn42_resource.c +15 -13
index 547a0b816539..67673a9e5155 100644
@@ -400,16 +400,18 @@ static const struct dcn30_dwbc_shift dwbc401_shift = {
 static const struct dcn30_dwbc_mask dwbc401_mask = {
 	DWBC_COMMON_MASK_SH_LIST_DCN30(_MASK)};
 
-#define mcif_wb_regs_dcn3_init(id) \
-	MCIF_WB_COMMON_REG_LIST_DCN3_5_RI(id)
+#define mcif_wb_regs_dcn401_init(id) \
+	MCIF_WB_COMMON_REG_LIST_DCN4_01_RI(id)
 
-static struct dcn35_mmhubbub_registers mcif_wb35_regs[1];
+static struct dcn35_mmhubbub_registers mcif_wb401_regs[1];
 
-static const struct dcn35_mmhubbub_shift mcif_wb35_shift = {
-	MCIF_WB_COMMON_MASK_SH_LIST_DCN3_5(__SHIFT)};
+static const struct dcn401_mmhubbub_shift mcif_wb401_shift = {
+	MCIF_WB_COMMON_MASK_SH_LIST_DCN4_01(__SHIFT)
+};
 
-static const struct dcn35_mmhubbub_mask mcif_wb35_mask = {
-	MCIF_WB_COMMON_MASK_SH_LIST_DCN3_5(_MASK)};
+static const struct dcn401_mmhubbub_mask mcif_wb401_mask = {
+	MCIF_WB_COMMON_MASK_SH_LIST_DCN4_01(_MASK)
+};
 
 #define dsc_regs_init(id) \
 	DSC_REG_LIST_DCN401_RI(id)
@@ -1768,13 +1770,13 @@ static bool dcn42_mmhubbub_create(struct dc_context *ctx, struct resource_pool *
 		}
 
 #undef REG_STRUCT
-#define REG_STRUCT mcif_wb35_regs
-		mcif_wb_regs_dcn3_init(0);
+#define REG_STRUCT mcif_wb401_regs
+		mcif_wb_regs_dcn401_init(0);
 
-		dcn35_mmhubbub_construct(mcif_wb30, ctx,
-					&mcif_wb35_regs[i],
-					&mcif_wb35_shift,
-					&mcif_wb35_mask,
+		dcn401_mmhubbub_construct(mcif_wb30, ctx,
+					&mcif_wb401_regs[i],
+					&mcif_wb401_shift,
+					&mcif_wb401_mask,
 					i);
 
 		dcn42_mmhubbub_init(mcif_wb30, ctx);
Signature · 1 line
2.53.0
#3 lore raw

PATCH 3/49 drm/amd/display: Fix force FRL rate debug setting

In reply to Fangzhi Zuo

From: Relja Vojvodic <[email protected]>

[Why & How]
- force FRL rate debug bit was not correctly forcing requested FRL rate

---
 drivers/gpu/drm/amd/display/dc/core/dc_stream.c               | 4 +++-
 drivers/gpu/drm/amd/display/dc/link/protocols/link_hdmi_frl.c | 2 +-
 2 files changed, 4 insertions(+), 2 deletions(-)
drivers/gpu/drm/amd/display/dc/core/dc_stream.c +3 -1
index 25f904eccb10..cdcf140bc1bb 100644
@@ -100,7 +100,9 @@ void update_stream_signal(struct dc_stream_state *stream, struct dc_sink *sink)
 
 		if (stream->link->frl_flags.force_frl_always ||
 				stream->link->frl_flags.force_frl_max
-				|| stream->link->frl_flags.force_frl_dsc)
+				|| stream->link->frl_flags.force_frl_dsc
+				|| (stream->link->frl_flags.force_frl_rate != 0 &&
+					stream->link->frl_flags.force_frl_rate != 0xF))
 			stream->signal = SIGNAL_TYPE_HDMI_FRL;
 	}
 }
drivers/gpu/drm/amd/display/dc/link/protocols/link_hdmi_frl.c +1 -1
index c35074177a36..2afdfc113675 100644
@@ -1090,7 +1090,7 @@ void hdmi_frl_decide_link_settings(struct dc_stream_state *stream,
 		&stream->link->frl_verified_link_cap);
 
 	if (stream->link->frl_flags.force_frl_rate != 0 &&
-		stream->link->frl_flags.force_frl_rate < stream->link->frl_verified_link_cap.frl_link_rate) {
+		stream->link->frl_flags.force_frl_rate <= stream->link->frl_verified_link_cap.frl_link_rate) {
 		switch (stream->link->frl_flags.force_frl_rate) {
 		case HDMI_FRL_LINK_RATE_3GBPS:
 			temp_settings.frl_link_rate = HDMI_FRL_LINK_RATE_3GBPS;
Signature · 1 line
2.53.0
#4 lore raw

PATCH 4/49 drm/amd/display: Add KUnit tests for link_lock and psp SRM helpers

In reply to Fangzhi Zuo

From: Bhawanpreet Lakha <[email protected]>

Cover link_lock() across all links (lock then unlock) and the max_link == 0 no-op path, checking each per-link mutex ends in the expected state.

Also cover the psp_get_srm() and psp_set_srm() guard paths when the HDCP TA context is uninitialized: psp_get_srm() returns NULL and psp_set_srm() returns -EINVAL, both leaving their output parameters untouched. The post-guard paths invoke real PSP firmware and are not unit-testable in UML.

---
 .../amd/display/amdgpu_dm/amdgpu_dm_hdcp.c    |  12 +-
 .../amd/display/amdgpu_dm/amdgpu_dm_hdcp.h    |   4 +
 .../amdgpu_dm/tests/amdgpu_dm_hdcp_test.c     | 127 ++++++++++++++++++
 3 files changed, 140 insertions(+), 3 deletions(-)
drivers/gpu/drm/amd/display/amdgpu_dm/amdgpu_dm_hdcp.c +9 -3
index 0dee603ecfaa..3b5e0e64adde 100644
@@ -106,7 +106,8 @@ static bool lp_atomic_write_poll_read_aux(
 	return dm_atomic_write_poll_read_aux(link, write, poll, read, poll_timeout_us, poll_mask_msb);
 }
 
-static uint8_t *psp_get_srm(struct psp_context *psp, uint32_t *srm_version, uint32_t *srm_size)
+STATIC_IFN_KUNIT
+uint8_t *psp_get_srm(struct psp_context *psp, uint32_t *srm_version, uint32_t *srm_size)
 {
 	struct ta_hdcp_shared_memory *hdcp_cmd;
 
@@ -129,8 +130,10 @@ static uint8_t *psp_get_srm(struct psp_context *psp, uint32_t *srm_version, uint
 
 	return hdcp_cmd->out_msg.hdcp_get_srm.srm_buf;
 }
+EXPORT_IF_KUNIT(psp_get_srm);
 
-static int psp_set_srm(struct psp_context *psp,
+STATIC_IFN_KUNIT
+int psp_set_srm(struct psp_context *psp,
 		       u8 *srm, uint32_t srm_size, uint32_t *srm_version)
 {
 	struct ta_hdcp_shared_memory *hdcp_cmd;
@@ -157,6 +160,7 @@ static int psp_set_srm(struct psp_context *psp,
 	*srm_version = hdcp_cmd->out_msg.hdcp_set_srm.srm_version;
 	return 0;
 }
+EXPORT_IF_KUNIT(psp_set_srm);
 
 STATIC_IFN_KUNIT
 void process_output(struct hdcp_workqueue *hdcp_work)
@@ -245,7 +249,8 @@ void hdcp_get_link_display_adjustments(
 }
 EXPORT_IF_KUNIT(hdcp_get_link_display_adjustments);
 
-static void link_lock(struct hdcp_workqueue *work, bool lock)
+STATIC_IFN_KUNIT
+void link_lock(struct hdcp_workqueue *work, bool lock)
 {
 	int i = 0;
 
@@ -256,6 +261,7 @@ static void link_lock(struct hdcp_workqueue *work, bool lock)
 			mutex_unlock(&work[i].mutex);
 	}
 }
+EXPORT_IF_KUNIT(link_lock);
 
 STATIC_IFN_KUNIT
 void hdcp_update_display_encryption_control(struct hdcp_workqueue *hdcp_work,
drivers/gpu/drm/amd/display/amdgpu_dm/amdgpu_dm_hdcp.h +4 -0
index a82a20b80518..fb66f48d7297 100644
@@ -44,6 +44,7 @@ struct mod_hdcp_link;
 struct mod_hdcp_display;
 struct cp_psp;
 struct amdgpu_device;
+struct psp_context;
 
 struct hdcp_workqueue {
 	struct work_struct cpirq_work;
@@ -113,6 +114,9 @@ void hdcp_update_display_encryption_control(struct hdcp_workqueue *hdcp_work,
 					    unsigned int conn_index,
 					    bool enable_encryption);
 void event_property_update(struct work_struct *work);
+void link_lock(struct hdcp_workqueue *work, bool lock);
+uint8_t *psp_get_srm(struct psp_context *psp, uint32_t *srm_version, uint32_t *srm_size);
+int psp_set_srm(struct psp_context *psp, u8 *srm, uint32_t srm_size, uint32_t *srm_version);
 #endif
 
 #endif /* AMDGPU_DM_AMDGPU_DM_HDCP_H_ */
drivers/gpu/drm/amd/display/amdgpu_dm/tests/amdgpu_dm_hdcp_test.c +127 -0

145 lines not on this page · raw message

Signature · 1 line
2.53.0
#5 lore raw

PATCH 5/49 drm/amd/display: Add KUnit tests for HDCP display helpers

In reply to Fangzhi Zuo

From: Bhawanpreet Lakha <[email protected]>

Cover the HDCP display lifecycle helpers:
- hdcp_update_display() registers the connector and, on the disable path, resets the per-link encryption status to HDCP_OFF.
- hdcp_remove_display() reverts an ENABLED connector back to DESIRED and clears the per-link entry, including the NULL connector-state path.
- hdcp_reset_display() clears the encryption status and the connector for every link.

---
 .../amd/display/amdgpu_dm/amdgpu_dm_hdcp.c    |   6 +-
 .../amd/display/amdgpu_dm/amdgpu_dm_hdcp.h    |   2 +
 .../amdgpu_dm/tests/amdgpu_dm_hdcp_test.c     | 207 ++++++++++++++++++
 3 files changed, 214 insertions(+), 1 deletion(-)
drivers/gpu/drm/amd/display/amdgpu_dm/amdgpu_dm_hdcp.c +5 -1
index 3b5e0e64adde..f786c0a85425 100644
@@ -317,8 +317,10 @@ void hdcp_update_display(struct hdcp_workqueue *hdcp_work,
 
 	process_output(hdcp_w);
 }
+EXPORT_IF_KUNIT(hdcp_update_display);
 
-static void hdcp_remove_display(struct hdcp_workqueue *hdcp_work,
+STATIC_IFN_KUNIT
+void hdcp_remove_display(struct hdcp_workqueue *hdcp_work,
 				unsigned int link_index,
 			 struct amdgpu_dm_connector *aconnector)
 {
@@ -348,6 +350,7 @@ static void hdcp_remove_display(struct hdcp_workqueue *hdcp_work,
 	}
 	process_output(hdcp_w);
 }
+EXPORT_IF_KUNIT(hdcp_remove_display);
 
 void hdcp_reset_display(struct hdcp_workqueue *hdcp_work, unsigned int link_index)
 {
@@ -371,6 +374,7 @@ void hdcp_reset_display(struct hdcp_workqueue *hdcp_work, unsigned int link_inde
 
 	process_output(hdcp_w);
 }
+EXPORT_IF_KUNIT(hdcp_reset_display);
 
 void hdcp_handle_cpirq(struct hdcp_workqueue *hdcp_work, unsigned int link_index)
 {
drivers/gpu/drm/amd/display/amdgpu_dm/amdgpu_dm_hdcp.h +2 -0
index fb66f48d7297..69a50e081c56 100644
@@ -115,6 +115,8 @@ void hdcp_update_display_encryption_control(struct hdcp_workqueue *hdcp_work,
 					    bool enable_encryption);
 void event_property_update(struct work_struct *work);
 void link_lock(struct hdcp_workqueue *work, bool lock);
+void hdcp_remove_display(struct hdcp_workqueue *hdcp_work, unsigned int link_index,
+			 struct amdgpu_dm_connector *aconnector);
 uint8_t *psp_get_srm(struct psp_context *psp, uint32_t *srm_version, uint32_t *srm_size);
 int psp_set_srm(struct psp_context *psp, u8 *srm, uint32_t srm_size, uint32_t *srm_version);
 #endif
drivers/gpu/drm/amd/display/amdgpu_dm/tests/amdgpu_dm_hdcp_test.c +207 -0

225 lines not on this page · raw message

Signature · 1 line
2.53.0
#6 lore raw

PATCH 6/49 drm/amd/display: Add KUnit tests for event_callback

In reply to Fangzhi Zuo

From: Bhawanpreet Lakha <[email protected]>

Verify event_callback() cancels a pending callback_dwork and then runs process_output(), which re-arms property_validate_dwork, and that the work-queue mutex is released on return.

---
 .../amd/display/amdgpu_dm/amdgpu_dm_hdcp.c    |  4 +-
 .../amd/display/amdgpu_dm/amdgpu_dm_hdcp.h    |  1 +
 .../amdgpu_dm/tests/amdgpu_dm_hdcp_test.c     | 78 +++++++++++++++++++
 3 files changed, 82 insertions(+), 1 deletion(-)
drivers/gpu/drm/amd/display/amdgpu_dm/amdgpu_dm_hdcp.c +3 -1
index f786c0a85425..34f70e517dc6 100644
@@ -384,7 +384,8 @@ void hdcp_handle_cpirq(struct hdcp_workqueue *hdcp_work, unsigned int link_index
 }
 EXPORT_IF_KUNIT(hdcp_handle_cpirq);
 
-static void event_callback(struct work_struct *work)
+STATIC_IFN_KUNIT
+void event_callback(struct work_struct *work)
 {
 	struct hdcp_workqueue *hdcp_work;
 
@@ -400,6 +401,7 @@ static void event_callback(struct work_struct *work)
 
 	process_output(hdcp_work);
 }
+EXPORT_IF_KUNIT(event_callback);
 
 STATIC_IFN_KUNIT
 void event_property_update(struct work_struct *work)
drivers/gpu/drm/amd/display/amdgpu_dm/amdgpu_dm_hdcp.h +1 -0
index 69a50e081c56..4b8ba743f9d8 100644
@@ -114,6 +114,7 @@ void hdcp_update_display_encryption_control(struct hdcp_workqueue *hdcp_work,
 					    unsigned int conn_index,
 					    bool enable_encryption);
 void event_property_update(struct work_struct *work);
+void event_callback(struct work_struct *work);
 void link_lock(struct hdcp_workqueue *work, bool lock);
 void hdcp_remove_display(struct hdcp_workqueue *hdcp_work, unsigned int link_index,
 			 struct amdgpu_dm_connector *aconnector);
drivers/gpu/drm/amd/display/amdgpu_dm/tests/amdgpu_dm_hdcp_test.c +78 -0

90 lines not on this page · raw message

Signature · 1 line
2.53.0
#7 lore raw

PATCH 7/49 drm/amd/display: Add KUnit tests for event_property_validate

In reply to Fangzhi Zuo

From: Bhawanpreet Lakha <[email protected]>

Cover the per-connector scan in event_property_validate(): NULL, disconnected and NULL-state connectors are skipped; a changed encryption status updates the cached value and schedules property_update_work; and an unchanged status leaves it untouched.

---
 .../amd/display/amdgpu_dm/amdgpu_dm_hdcp.c    |   4 +-
 .../amd/display/amdgpu_dm/amdgpu_dm_hdcp.h    |   1 +
 .../amdgpu_dm/tests/amdgpu_dm_hdcp_test.c     | 178 ++++++++++++++++++
 3 files changed, 182 insertions(+), 1 deletion(-)
drivers/gpu/drm/amd/display/amdgpu_dm/amdgpu_dm_hdcp.c +3 -1
index 34f70e517dc6..622d9c275c3a 100644
@@ -465,7 +465,8 @@ void event_property_update(struct work_struct *work)
 }
 EXPORT_IF_KUNIT(event_property_update);
 
-static void event_property_validate(struct work_struct *work)
+STATIC_IFN_KUNIT
+void event_property_validate(struct work_struct *work)
 {
 	struct hdcp_workqueue *hdcp_work =
 		container_of(to_delayed_work(work), struct hdcp_workqueue, property_validate_dwork);
@@ -514,6 +515,7 @@ static void event_property_validate(struct work_struct *work)
 		}
 	}
 }
+EXPORT_IF_KUNIT(event_property_validate);
 
 static void event_watchdog_timer(struct work_struct *work)
 {
drivers/gpu/drm/amd/display/amdgpu_dm/amdgpu_dm_hdcp.h +1 -0
index 4b8ba743f9d8..57c534efbc71 100644
@@ -114,6 +114,7 @@ void hdcp_update_display_encryption_control(struct hdcp_workqueue *hdcp_work,
 					    unsigned int conn_index,
 					    bool enable_encryption);
 void event_property_update(struct work_struct *work);
+void event_property_validate(struct work_struct *work);
 void event_callback(struct work_struct *work);
 void link_lock(struct hdcp_workqueue *work, bool lock);
 void hdcp_remove_display(struct hdcp_workqueue *hdcp_work, unsigned int link_index,
drivers/gpu/drm/amd/display/amdgpu_dm/tests/amdgpu_dm_hdcp_test.c +178 -0

190 lines not on this page · raw message

Signature · 1 line
2.53.0
#8 lore raw

PATCH 8/49 drm/amd/display: Add KUnit tests for watchdog and cpirq events

In reply to Fangzhi Zuo

From: Bhawanpreet Lakha <[email protected]>

Verify event_watchdog_timer() cancels its pending watchdog_dwork and runs process_output(), and that event_cpirq() runs process_output() without arming the callback or watchdog timers. Both release the work-queue mutex on return.

---
 .../amd/display/amdgpu_dm/amdgpu_dm_hdcp.c    |   8 +-
 .../amd/display/amdgpu_dm/amdgpu_dm_hdcp.h    |   2 +
 .../amdgpu_dm/tests/amdgpu_dm_hdcp_test.c     | 132 ++++++++++++++++++
 3 files changed, 140 insertions(+), 2 deletions(-)
drivers/gpu/drm/amd/display/amdgpu_dm/amdgpu_dm_hdcp.c +6 -2
index 622d9c275c3a..896668c92888 100644
@@ -517,7 +517,8 @@ void event_property_validate(struct work_struct *work)
 }
 EXPORT_IF_KUNIT(event_property_validate);
 
-static void event_watchdog_timer(struct work_struct *work)
+STATIC_IFN_KUNIT
+void event_watchdog_timer(struct work_struct *work)
 {
 	struct hdcp_workqueue *hdcp_work;
 
@@ -535,8 +536,10 @@ static void event_watchdog_timer(struct work_struct *work)
 
 	process_output(hdcp_work);
 }
+EXPORT_IF_KUNIT(event_watchdog_timer);
 
-static void event_cpirq(struct work_struct *work)
+STATIC_IFN_KUNIT
+void event_cpirq(struct work_struct *work)
 {
 	struct hdcp_workqueue *hdcp_work;
 
@@ -548,6 +551,7 @@ static void event_cpirq(struct work_struct *work)
 
 	process_output(hdcp_work);
 }
+EXPORT_IF_KUNIT(event_cpirq);
 
 void hdcp_destroy(struct kobject *kobj, struct hdcp_workqueue *hdcp_work)
 {
drivers/gpu/drm/amd/display/amdgpu_dm/amdgpu_dm_hdcp.h +2 -0
index 57c534efbc71..a2b08bec58b5 100644
@@ -116,6 +116,8 @@ void hdcp_update_display_encryption_control(struct hdcp_workqueue *hdcp_work,
 void event_property_update(struct work_struct *work);
 void event_property_validate(struct work_struct *work);
 void event_callback(struct work_struct *work);
+void event_watchdog_timer(struct work_struct *work);
+void event_cpirq(struct work_struct *work);
 void link_lock(struct hdcp_workqueue *work, bool lock);
 void hdcp_remove_display(struct hdcp_workqueue *hdcp_work, unsigned int link_index,
 			 struct amdgpu_dm_connector *aconnector);
drivers/gpu/drm/amd/display/amdgpu_dm/tests/amdgpu_dm_hdcp_test.c +132 -0

144 lines not on this page · raw message

Signature · 1 line
2.53.0
#9 lore raw

PATCH 9/49 drm/amd/display: Add KUnit tests for hdcp_destroy

In reply to Fangzhi Zuo

From: Bhawanpreet Lakha <[email protected]>

Verify hdcp_destroy() cancels each link's delayed works, removes the SRM sysfs file and frees the workqueue and SRM buffers. Cover both a populated work-queue and the zero-link / NULL-SRM path.

---
 .../amd/display/amdgpu_dm/amdgpu_dm_hdcp.c    |   1 +
 .../amdgpu_dm/tests/amdgpu_dm_hdcp_test.c     | 122 ++++++++++++++++++
 2 files changed, 123 insertions(+)
drivers/gpu/drm/amd/display/amdgpu_dm/amdgpu_dm_hdcp.c +1 -0
index 896668c92888..e704b6b7fc0b 100644
@@ -568,6 +568,7 @@ void hdcp_destroy(struct kobject *kobj, struct hdcp_workqueue *hdcp_work)
 	kfree(hdcp_work->srm_temp);
 	kfree(hdcp_work);
 }
+EXPORT_IF_KUNIT(hdcp_destroy);
 
 static bool enable_assr(void *handle, struct dc_link *link)
 {
drivers/gpu/drm/amd/display/amdgpu_dm/tests/amdgpu_dm_hdcp_test.c +122 -0

140 lines not on this page · raw message

Signature · 1 line
2.53.0
#10 lore raw

PATCH 10/49 drm/amd/display: Add AV mute wait frames to dce110_set_avmute

In reply to Fangzhi Zuo

From: Ray Wu <[email protected]>

Port the three-frame wait logic from dcn30_set_avmute to dce110_set_avmute so that older DCN versions (1.0, 2.0) also wait for GCP packets to be sent out before proceeding.

This ensures HDMI sinks properly process the mute state, preventing garbled display after link re-establishment.

---
 .../amd/display/dc/hwss/dce110/dce110_hwseq.c | 21 ++++++++++++++++++-
 1 file changed, 20 insertions(+), 1 deletion(-)
drivers/gpu/drm/amd/display/dc/hwss/dce110/dce110_hwseq.c +20 -1
index 262982ca5ad9..f91ce2b4b1bf 100644
@@ -1336,8 +1336,27 @@ void dce110_blank_stream(struct pipe_ctx *pipe_ctx)
 
 void dce110_set_avmute(struct pipe_ctx *pipe_ctx, bool enable)
 {
-	if (pipe_ctx != NULL && pipe_ctx->stream_res.stream_enc != NULL)
+	if (pipe_ctx == NULL || pipe_ctx->stream_res.stream_enc == NULL)
+		return;
+
+	if (dc_is_hdmi_signal(pipe_ctx->stream->signal)) {
 		pipe_ctx->stream_res.stream_enc->funcs->set_avmute(pipe_ctx->stream_res.stream_enc, enable);
+
+		/* Wait for three frames to make sure AV mute is sent out.
+		 * Some HDMI sinks need additional GCP packets to properly
+		 * process the mute state, especially after link re-establishment
+		 * with HDMI 2.0 scrambling enabled.
+		 */
+		if (enable && pipe_ctx->stream_res.tg->funcs->is_tg_enabled(pipe_ctx->stream_res.tg)) {
+			int i;
+
+			pipe_ctx->stream_res.tg->funcs->wait_for_state(pipe_ctx->stream_res.tg, CRTC_STATE_VACTIVE);
+			for (i = 0; i < 3; i++) {
+				pipe_ctx->stream_res.tg->funcs->wait_for_state(pipe_ctx->stream_res.tg, CRTC_STATE_VBLANK);
+				pipe_ctx->stream_res.tg->funcs->wait_for_state(pipe_ctx->stream_res.tg, CRTC_STATE_VACTIVE);
+			}
+		}
+	}
 }
 
 enum audio_dto_source translate_to_dto_source(enum controller_id crtc_id)
Signature · 1 line
2.53.0
#11 lore raw

PATCH 11/49 drm/amd/display: revert "convert dcn42 GPIO translation to lookup tables"

In reply to Fangzhi Zuo

From: Charlene Liu <[email protected]>

[why]
This reverts commit b536028ffbce3c3f026ba7c9b42b8f66cfb186e9.

---
 .../dc/gpio/dcn42/hw_translate_dcn42.c        | 193 +++++++++++-------
 .../dc/gpio/dcn42/hw_translate_dcn42.c.orig   | 153 ++++++++++++++
 2 files changed, 276 insertions(+), 70 deletions(-)
 create mode 100644 drivers/gpu/drm/amd/display/dc/gpio/dcn42/hw_translate_dcn42.c.orig
drivers/gpu/drm/amd/display/dc/gpio/dcn42/hw_translate_dcn42.c +123 -70
index 7b2c4cd42450..e7e1d9979876 100644
@@ -39,76 +39,62 @@
  * end *********************/
 
 
-static const struct gpio_id_offset_entry gpio_offsets[] = {
-	/* HPD */
-	GPIO_ENTRY(HPD0_DC_HPD_INT_STATUS, GPIO_ID_HPD, GPIO_HPD_1),
-	GPIO_ENTRY(HPD1_DC_HPD_INT_STATUS, GPIO_ID_HPD, GPIO_HPD_2),
-	GPIO_ENTRY(HPD2_DC_HPD_INT_STATUS, GPIO_ID_HPD, GPIO_HPD_3),
-	GPIO_ENTRY(HPD3_DC_HPD_INT_STATUS, GPIO_ID_HPD, GPIO_HPD_4),
-	GPIO_ENTRY(HPD4_DC_HPD_INT_STATUS, GPIO_ID_HPD, GPIO_HPD_5),
-};
-
-
-/* DDC */
-static const struct gpio_ddc_offset_entry ddc_offset_map[] = {
-	{ REG(DC_GPIO_DDC1_A), GPIO_DDC_LINE_DDC1 },
-	{ REG(DC_GPIO_DDC2_A), GPIO_DDC_LINE_DDC2 },
-	{ REG(DC_GPIO_DDC3_A), GPIO_DDC_LINE_DDC3 },
-	{ REG(DC_GPIO_DDC4_A), GPIO_DDC_LINE_DDC4 },
-	{ REG(DC_GPIO_DDC5_A), GPIO_DDC_LINE_DDC5 },
-	{ REG(DC_GPIO_DDCVGA_A), GPIO_DDC_LINE_DDC_VGA },
-};
-
-
-static const struct gpio_pin_entry gpio_pins[] = {
-	/* DDC */
-	GPIO_PIN_ENTRY(GPIO_ID_DDC_DATA, GPIO_DDC_LINE_DDC1,
-		DC_GPIO_DDC1_A, DC_GPIO_DDC1_A__DC_GPIO_DDC1DATA_A_MASK),
-	GPIO_PIN_ENTRY(GPIO_ID_DDC_DATA, GPIO_DDC_LINE_DDC2,
-		DC_GPIO_DDC2_A, DC_GPIO_DDC1_A__DC_GPIO_DDC1DATA_A_MASK),
-	GPIO_PIN_ENTRY(GPIO_ID_DDC_DATA, GPIO_DDC_LINE_DDC3,
-		DC_GPIO_DDC3_A, DC_GPIO_DDC1_A__DC_GPIO_DDC1DATA_A_MASK),
-	GPIO_PIN_ENTRY(GPIO_ID_DDC_DATA, GPIO_DDC_LINE_DDC4,
-		DC_GPIO_DDC4_A, DC_GPIO_DDC1_A__DC_GPIO_DDC1DATA_A_MASK),
-	GPIO_PIN_ENTRY(GPIO_ID_DDC_DATA, GPIO_DDC_LINE_DDC5,
-		DC_GPIO_DDC5_A, DC_GPIO_DDC1_A__DC_GPIO_DDC1DATA_A_MASK),
-	GPIO_PIN_ENTRY(GPIO_ID_DDC_DATA, GPIO_DDC_LINE_DDC_VGA,
-		DC_GPIO_DDCVGA_A, DC_GPIO_DDC1_A__DC_GPIO_DDC1DATA_A_MASK),
-	GPIO_PIN_ENTRY(GPIO_ID_DDC_CLOCK, GPIO_DDC_LINE_DDC1,
-		DC_GPIO_DDC1_A, DC_GPIO_DDC1_A__DC_GPIO_DDC1CLK_A_MASK),
-	GPIO_PIN_ENTRY(GPIO_ID_DDC_CLOCK, GPIO_DDC_LINE_DDC2,
-		DC_GPIO_DDC2_A, DC_GPIO_DDC1_A__DC_GPIO_DDC1CLK_A_MASK),
-	GPIO_PIN_ENTRY(GPIO_ID_DDC_CLOCK, GPIO_DDC_LINE_DDC3,
-		DC_GPIO_DDC3_A, DC_GPIO_DDC1_A__DC_GPIO_DDC1CLK_A_MASK),
-	GPIO_PIN_ENTRY(GPIO_ID_DDC_CLOCK, GPIO_DDC_LINE_DDC4,
-		DC_GPIO_DDC4_A, DC_GPIO_DDC1_A__DC_GPIO_DDC1CLK_A_MASK),
-	GPIO_PIN_ENTRY(GPIO_ID_DDC_CLOCK, GPIO_DDC_LINE_DDC5,
-		DC_GPIO_DDC5_A, DC_GPIO_DDC1_A__DC_GPIO_DDC1CLK_A_MASK),
-	GPIO_PIN_ENTRY(GPIO_ID_DDC_CLOCK, GPIO_DDC_LINE_DDC_VGA,
-		DC_GPIO_DDCVGA_A, DC_GPIO_DDC1_A__DC_GPIO_DDC1CLK_A_MASK),
-};
-
-
 static bool offset_to_id(
 	uint32_t offset,
 	uint32_t mask,
 	enum gpio_id *id,
 	uint32_t *en)
 {
-	if (dal_hw_translate_gpio_ddc_offset_to_id(
-			ddc_offset_map,
-			ARRAY_SIZE(ddc_offset_map),
-			offset, en))
+	(void)mask;
+	switch (offset) {
+	/* HPD */
+	case REG(HPD0_DC_HPD_INT_STATUS):
+		*id = GPIO_ID_HPD;
+		*en = GPIO_HPD_1;
 		return true;
-
-	if (dal_hw_translate_gpio_offset_to_id(
-			gpio_offsets,
-			ARRAY_SIZE(gpio_offsets),
-			offset, mask, id, en))
+	case REG(HPD1_DC_HPD_INT_STATUS):
+		*id = GPIO_ID_HPD;
+		*en = GPIO_HPD_2;
 		return true;
-
-	ASSERT_CRITICAL(false);
-	return false;
+	case REG(HPD2_DC_HPD_INT_STATUS):
+		*id = GPIO_ID_HPD;
+		*en = GPIO_HPD_3;
+		return true;
+	case REG(HPD3_DC_HPD_INT_STATUS):
+		*id = GPIO_ID_HPD;
+		*en = GPIO_HPD_4;
+		return true;
+	case REG(HPD4_DC_HPD_INT_STATUS):
+		*id = GPIO_ID_HPD;
+		*en = GPIO_HPD_5;
+		return true;
+	/* DDC */
+	/* we don't care about the GPIO_ID for DDC
+	 * in DdcHandle it will use GPIO_ID_DDC_DATA/GPIO_ID_DDC_CLOCK
+	 * directly in the create method
+	 */
+	case REG(DC_GPIO_DDC1_A):
+		*en = GPIO_DDC_LINE_DDC1;
+		return true;
+	case REG(DC_GPIO_DDC2_A):
+		*en = GPIO_DDC_LINE_DDC2;
+		return true;
+	case REG(DC_GPIO_DDC3_A):
+		*en = GPIO_DDC_LINE_DDC3;
+		return true;
+	case REG(DC_GPIO_DDC4_A):
+		*en = GPIO_DDC_LINE_DDC4;
+		return true;
+	case REG(DC_GPIO_DDC5_A):
+		*en = GPIO_DDC_LINE_DDC5;
+		return true;
+	case REG(DC_GPIO_DDCVGA_A):
+		*en = GPIO_DDC_LINE_DDC_VGA;
+		return true;
+	default:
+		ASSERT_CRITICAL(false);
+		return false;
+	}
 }
 
 
@@ -117,14 +103,81 @@ static bool id_to_offset(
 	uint32_t en,
 	struct gpio_pin_info *info)
 {
-	if (dal_hw_translate_id_to_offset(
-			gpio_pins,
-			ARRAY_SIZE(gpio_pins),
-			id, en, info))
-		return true;
-
-	ASSERT_CRITICAL(false);
-	return false;
+	bool result = true;
+
+	switch (id) {
+	case GPIO_ID_DDC_DATA:
+		info->mask = DC_GPIO_DDC1_A__DC_GPIO_DDC1DATA_A_MASK;
+		switch (en) {
+		case GPIO_DDC_LINE_DDC1:
+			info->offset = REG(DC_GPIO_DDC1_A);
+		break;
+		case GPIO_DDC_LINE_DDC2:
+			info->offset = REG(DC_GPIO_DDC2_A);
+		break;
+		case GPIO_DDC_LINE_DDC3:
+			info->offset = REG(DC_GPIO_DDC3_A);
+		break;
+		case GPIO_DDC_LINE_DDC4:
+			info->offset = REG(DC_GPIO_DDC4_A);
+		break;
+		case GPIO_DDC_LINE_DDC5:
+			info->offset = REG(DC_GPIO_DDC5_A);
+		break;
+		case GPIO_DDC_LINE_DDC_VGA:
+			info->offset = REG(DC_GPIO_DDCVGA_A);
+		break;
+		case GPIO_DDC_LINE_I2C_PAD:
+		default:
+			ASSERT_CRITICAL(false);
+			result = false;
+		}
+	break;
+	case GPIO_ID_DDC_CLOCK:
+		info->mask = DC_GPIO_DDC1_A__DC_GPIO_DDC1CLK_A_MASK;
+		switch (en) {
+		case GPIO_DDC_LINE_DDC1:
+			info->offset = REG(DC_GPIO_DDC1_A);
+		break;
+		case GPIO_DDC_LINE_DDC2:
+			info->offset = REG(DC_GPIO_DDC2_A);
+		break;
+		case GPIO_DDC_LINE_DDC3:
+			info->offset = REG(DC_GPIO_DDC3_A);
+		break;
+		case GPIO_DDC_LINE_DDC4:
+			info->offset = REG(DC_GPIO_DDC4_A);
+		break;
+		case GPIO_DDC_LINE_DDC5:
+			info->offset = REG(DC_GPIO_DDC5_A);
+		break;
+		case GPIO_DDC_LINE_DDC_VGA:
+			info->offset = REG(DC_GPIO_DDCVGA_A);
+		break;
+		case GPIO_DDC_LINE_I2C_PAD:
+		default:
+			ASSERT_CRITICAL(false);
+			result = false;
+		}
+	break;
+	case GPIO_ID_SYNC:
+	case GPIO_ID_VIP_PAD:
+	default:
+		ASSERT_CRITICAL(false);
+		result = false;
+	}
+
+	if (result) {
+		info->offset_y = info->offset + 2;
+		info->offset_en = info->offset + 1;
+		info->offset_mask = info->offset - 1;
+
+		info->mask_y = info->mask;
+		info->mask_en = info->mask;
+		info->mask_mask = info->mask;
+	}
+
+	return result;
 }
 
 
drivers/gpu/drm/amd/display/dc/gpio/dcn42/hw_translate_dcn42.c.orig new file +153 -0

153 lines not on this page · raw message

Signature · 1 line
2.53.0
#12 lore raw

PATCH 12/49 drm/amd/display: move scaling helper to connector

In reply to Fangzhi Zuo

From: Alex Hung <[email protected]>

[WHAT]
amdgpu_dm_update_stream_scaling_settings() computes the stream src/dst rectangles for a connector's scaling mode. It is already declared in amdgpu_dm_connector.h and consumed by create_stream_for_sink(), so move its definition out of the oversized amdgpu_dm.c into amdgpu_dm_connector.c where it belongs.

Relocate its KUnit tests from the amdgpu_dm suite to the amdgpu_dm_connector suite accordingly. No functional change.

---
 .../gpu/drm/amd/display/amdgpu_dm/amdgpu_dm.c |  57 -----
 .../display/amdgpu_dm/amdgpu_dm_connector.c   |  57 +++++
 .../tests/amdgpu_dm_connector_test.c          | 209 ++++++++++++++++++
 .../display/amdgpu_dm/tests/amdgpu_dm_test.c  | 208 -----------------
 4 files changed, 266 insertions(+), 265 deletions(-)
drivers/gpu/drm/amd/display/amdgpu_dm/amdgpu_dm.c +0 -57
index 111cdd66fe93..e6452237ba70 100644
@@ -3405,63 +3405,6 @@ static void fill_dc_dirty_rects(struct drm_plane *plane,
 			   &flip_addrs->dirty_rect_count, true);
 }
 
-void amdgpu_dm_update_stream_scaling_settings(struct drm_device *dev,
-					   const struct drm_display_mode *mode,
-					   const struct dm_connector_state *dm_state,
-					   struct dc_stream_state *stream)
-{
-	enum amdgpu_rmx_type rmx_type;
-
-	struct rect src = { 0 }; /* viewport in composition space*/
-	struct rect dst = { 0 }; /* stream addressable area */
-
-	/* no mode. nothing to be done */
-	if (!mode)
-		return;
-
-	/* Full screen scaling by default */
-	src.width = mode->hdisplay;
-	src.height = mode->vdisplay;
-	dst.width = stream->timing.h_addressable;
-	dst.height = stream->timing.v_addressable;
-
-	if (dm_state) {
-		rmx_type = dm_state->scaling;
-		if (rmx_type == RMX_ASPECT || rmx_type == RMX_OFF) {
-			if (src.width * dst.height <
-					src.height * dst.width) {
-				/* height needs less upscaling/more downscaling */
-				dst.width = src.width *
-						dst.height / src.height;
-			} else {
-				/* width needs less upscaling/more downscaling */
-				dst.height = src.height *
-						dst.width / src.width;
-			}
-		} else if (rmx_type == RMX_CENTER) {
-			dst = src;
-		}
-
-		dst.x = (stream->timing.h_addressable - dst.width) / 2;
-		dst.y = (stream->timing.v_addressable - dst.height) / 2;
-
-		if (dm_state->underscan_enable) {
-			dst.x += dm_state->underscan_hborder / 2;
-			dst.y += dm_state->underscan_vborder / 2;
-			dst.width -= dm_state->underscan_hborder;
-			dst.height -= dm_state->underscan_vborder;
-		}
-	}
-
-	stream->src = src;
-	stream->dst = dst;
-
-	drm_dbg_kms(dev, "Destination Rectangle x:%d  y:%d  width:%d  height:%d\n",
-		    dst.x, dst.y, dst.width, dst.height);
-
-}
-EXPORT_IF_KUNIT(amdgpu_dm_update_stream_scaling_settings);
-
 static int dm_update_mst_vcpi_slots_for_dsc(struct drm_atomic_commit *state,
 					    struct dc_state *dc_state,
 					    struct dsc_mst_fairness_vars *vars)
drivers/gpu/drm/amd/display/amdgpu_dm/amdgpu_dm_connector.c +57 -0

63 lines not on this page · raw message

drivers/gpu/drm/amd/display/amdgpu_dm/tests/amdgpu_dm_connector_test.c +209 -0

227 lines not on this page · raw message

drivers/gpu/drm/amd/display/amdgpu_dm/tests/amdgpu_dm_test.c +0 -208

220 lines not on this page · raw message

Signature · 1 line
2.53.0
#13 lore raw

PATCH 13/49 drm/amd/display: move stutter quirk to quirks file

In reply to Fangzhi Zuo

From: Alex Hung <[email protected]>

[WHAT]
dm_should_disable_stutter() and its amdgpu_stutter_quirk PCI match table are self-contained quirk logic. Move them out of amdgpu_dm.c into amdgpu_dm_quirks.c alongside the existing DMI quirk handling.

The helper is called from amdgpu_dm_init(), so it becomes a plain exported function instead of STATIC_IFN_KUNIT, and its declaration moves from the KUnit-only block to a regular prototype in amdgpu_dm.h. Relocate its KUnit tests from the amdgpu_dm suite to the amdgpu_dm_quirks suite. No functional change.

---
 .../gpu/drm/amd/display/amdgpu_dm/amdgpu_dm.c | 33 ----------
 .../gpu/drm/amd/display/amdgpu_dm/amdgpu_dm.h |  4 +-
 .../amd/display/amdgpu_dm/amdgpu_dm_quirks.c  | 32 +++++++++
 .../amdgpu_dm/tests/amdgpu_dm_quirks_test.c   | 65 +++++++++++++++++++
 .../display/amdgpu_dm/tests/amdgpu_dm_test.c  | 64 ------------------
 5 files changed, 99 insertions(+), 99 deletions(-)
drivers/gpu/drm/amd/display/amdgpu_dm/amdgpu_dm.c +0 -33
index e6452237ba70..c6b9cd1ce489 100644
@@ -410,39 +410,6 @@ static void mmhub_read_system_context(struct amdgpu_device *adev, struct dc_phy_
 
 }
 
-struct amdgpu_stutter_quirk {
-	u16 chip_vendor;
-	u16 chip_device;
-	u16 subsys_vendor;
-	u16 subsys_device;
-	u8 revision;
-};
-
-static const struct amdgpu_stutter_quirk amdgpu_stutter_quirk_list[] = {
-	/* https://bugzilla.kernel.org/show_bug.cgi?id=214417 */
-	{ 0x1002, 0x15dd, 0x1002, 0x15dd, 0xc8 },
-	{ 0, 0, 0, 0, 0 },
-};
-
-STATIC_IFN_KUNIT bool dm_should_disable_stutter(struct pci_dev *pdev)
-{
-	const struct amdgpu_stutter_quirk *p = amdgpu_stutter_quirk_list;
-
-	while (p && p->chip_device != 0) {
-		if (pdev->vendor == p->chip_vendor &&
-		    pdev->device == p->chip_device &&
-		    pdev->subsystem_vendor == p->subsys_vendor &&
-		    pdev->subsystem_device == p->subsys_device &&
-		    pdev->revision == p->revision) {
-			return true;
-		}
-		++p;
-	}
-	return false;
-}
-EXPORT_IF_KUNIT(dm_should_disable_stutter);
-
-
 void*
 dm_allocate_gpu_mem(
 		struct amdgpu_device *adev,
drivers/gpu/drm/amd/display/amdgpu_dm/amdgpu_dm.h +2 -2
index 03189f44efd4..617328497203 100644
@@ -1134,6 +1134,8 @@ bool amdgpu_dm_is_headless(struct amdgpu_device *adev);
 bool amdgpu_dm_crtc_complete_writeback(struct amdgpu_crtc *acrtc);
 
 void retrieve_dmi_info(struct amdgpu_display_manager *dm);
+struct pci_dev;
+bool dm_should_disable_stutter(struct pci_dev *pdev);
 
 void amdgpu_dm_emulated_link_detect(struct dc_link *link);
 void amdgpu_dm_apply_delay_after_dpcd_poweroff(struct amdgpu_device *adev,
@@ -1178,8 +1180,6 @@ bool is_dc_timing_adjust_needed(struct dm_crtc_state *old_state,
 				struct dm_crtc_state *new_state);
 void set_multisync_trigger_params(struct dc_stream_state *stream);
 void set_master_stream(struct dc_stream_state *stream_set[], int stream_count);
-struct pci_dev;
-bool dm_should_disable_stutter(struct pci_dev *pdev);
 void reset_freesync_config_for_crtc(struct dm_crtc_state *new_crtc_state);
 void get_freesync_config_for_crtc(struct dm_crtc_state *new_crtc_state,
 				  struct dm_connector_state *new_con_state);
drivers/gpu/drm/amd/display/amdgpu_dm/amdgpu_dm_quirks.c +32 -0
index 0a7602ed70b2..259966703cef 100644
@@ -178,3 +178,35 @@ void retrieve_dmi_info(struct amdgpu_display_manager *dm)
 	}
 }
 EXPORT_IF_KUNIT(retrieve_dmi_info);
+
+struct amdgpu_stutter_quirk {
+	u16 chip_vendor;
+	u16 chip_device;
+	u16 subsys_vendor;
+	u16 subsys_device;
+	u8 revision;
+};
+
+static const struct amdgpu_stutter_quirk amdgpu_stutter_quirk_list[] = {
+	/* https://bugzilla.kernel.org/show_bug.cgi?id=214417 */
+	{ 0x1002, 0x15dd, 0x1002, 0x15dd, 0xc8 },
+	{ 0, 0, 0, 0, 0 },
+};
+
+bool dm_should_disable_stutter(struct pci_dev *pdev)
+{
+	const struct amdgpu_stutter_quirk *p = amdgpu_stutter_quirk_list;
+
+	while (p && p->chip_device != 0) {
+		if (pdev->vendor == p->chip_vendor &&
+		    pdev->device == p->chip_device &&
+		    pdev->subsystem_vendor == p->subsys_vendor &&
+		    pdev->subsystem_device == p->subsys_device &&
+		    pdev->revision == p->revision) {
+			return true;
+		}
+		++p;
+	}
+	return false;
+}
+EXPORT_IF_KUNIT(dm_should_disable_stutter);
drivers/gpu/drm/amd/display/amdgpu_dm/tests/amdgpu_dm_quirks_test.c +65 -0

82 lines not on this page · raw message

drivers/gpu/drm/amd/display/amdgpu_dm/tests/amdgpu_dm_test.c +0 -64

76 lines not on this page · raw message

Signature · 1 line
2.53.0
#14 lore raw

PATCH 14/49 drm/amd/display: move watermarks table to pp_smu

In reply to Fangzhi Zuo

From: Alex Hung <[email protected]>

[WHAT]
amdgpu_dm_smu_write_watermarks_table() pushes fixed dcn watermark clock settings to the SMU on Navi1x. It belongs with the other dc-pplib bridge code, so move it out of amdgpu_dm.c into amdgpu_dm_pp_smu.c.

It is called from dm_resume(), so it becomes a plain exported function declared in amdgpu_dm_pp_smu.h (now included by amdgpu_dm.c) instead of STATIC_IFN_KUNIT in amdgpu_dm.h. Relocate its KUnit test from the amdgpu_dm suite to the amdgpu_dm_pp_smu suite. No functional change.

---
 .../gpu/drm/amd/display/amdgpu_dm/amdgpu_dm.c | 53 +------------------
 .../gpu/drm/amd/display/amdgpu_dm/amdgpu_dm.h |  1 -
 .../amd/display/amdgpu_dm/amdgpu_dm_pp_smu.c  | 52 ++++++++++++++++++
 .../amd/display/amdgpu_dm/amdgpu_dm_pp_smu.h  |  3 ++
 .../amdgpu_dm/tests/amdgpu_dm_pp_smu_test.c   | 20 +++++++
 .../display/amdgpu_dm/tests/amdgpu_dm_test.c  | 16 ------
 6 files changed, 76 insertions(+), 69 deletions(-)
drivers/gpu/drm/amd/display/amdgpu_dm/amdgpu_dm.c +1 -52
index c6b9cd1ce489..d49f0cd3b113 100644
@@ -70,6 +70,7 @@
 #include "amdgpu_dm_audio.h"
 #include "amdgpu_dm_dmub.h"
 #include "amdgpu_dm_connector.h"
+#include "amdgpu_dm_pp_smu.h"
 
 #include "ivsrcid/ivsrcid_vislands30.h"
 
@@ -1372,58 +1373,6 @@ static void s3_handle_mst(struct drm_device *dev, bool suspend)
 	drm_connector_list_iter_end(&iter);
 }
 
-STATIC_IFN_KUNIT int amdgpu_dm_smu_write_watermarks_table(struct amdgpu_device *adev)
-{
-	int ret = 0;
-
-	/* This interface is for dGPU Navi1x.Linux dc-pplib interface depends
-	 * on window driver dc implementation.
-	 * For Navi1x, clock settings of dcn watermarks are fixed. the settings
-	 * should be passed to smu during boot up and resume from s3.
-	 * boot up: dc calculate dcn watermark clock settings within dc_create,
-	 * dcn20_resource_construct
-	 * then call pplib functions below to pass the settings to smu:
-	 * smu_set_watermarks_for_clock_ranges
-	 * smu_set_watermarks_table
-	 * navi10_set_watermarks_table
-	 * smu_write_watermarks_table
-	 *
-	 * For Renoir, clock settings of dcn watermark are also fixed values.
-	 * dc has implemented different flow for window driver:
-	 * dc_hardware_init / dc_set_power_state
-	 * dcn10_init_hw
-	 * notify_wm_ranges
-	 * set_wm_ranges
-	 * -- Linux
-	 * smu_set_watermarks_for_clock_ranges
-	 * renoir_set_watermarks_table
-	 * smu_write_watermarks_table
-	 *
-	 * For Linux,
-	 * dc_hardware_init -> amdgpu_dm_init
-	 * dc_set_power_state --> dm_resume
-	 *
-	 * therefore, this function apply to navi10/12/14 but not Renoir
-	 * *
-	 */
-	switch (amdgpu_ip_version(adev, DCE_HWIP, 0)) {
-	case IP_VERSION(2, 0, 2):
-	case IP_VERSION(2, 0, 0):
-		break;
-	default:
-		return 0;
-	}
-
-	ret = amdgpu_dpm_write_watermarks_table(adev);
-	if (ret) {
-		drm_err(adev_to_drm(adev), "Failed to update WMTABLE!\n");
-		return ret;
-	}
-
-	return 0;
-}
-EXPORT_IF_KUNIT(amdgpu_dm_smu_write_watermarks_table);
-
 static int dm_oem_i2c_hw_init(struct amdgpu_device *adev)
 {
 	struct amdgpu_display_manager *dm = &adev->dm;
drivers/gpu/drm/amd/display/amdgpu_dm/amdgpu_dm.h +0 -1
index 617328497203..70220997cde9 100644
@@ -1157,7 +1157,6 @@ int dm_crtc_get_scanoutpos(struct amdgpu_device *adev, int crtc,
 struct dm_atomic_state *dm_atomic_get_new_state(struct drm_atomic_commit *state);
 void dm_atomic_destroy_state(struct drm_private_obj *obj,
 			     struct drm_private_state *state);
-int amdgpu_dm_smu_write_watermarks_table(struct amdgpu_device *adev);
 bool dm_should_update_native_cursor(struct drm_atomic_commit *state,
 				    struct drm_crtc *old_plane_crtc,
 				    struct drm_crtc *new_plane_crtc,
drivers/gpu/drm/amd/display/amdgpu_dm/amdgpu_dm_pp_smu.c +52 -0

55 lines not on this page · raw message

drivers/gpu/drm/amd/display/amdgpu_dm/amdgpu_dm_pp_smu.h +3 -0
index f918eb71f0d1..1d153d0e2f03 100644
@@ -11,6 +11,9 @@
 struct amd_pp_display_configuration;
 struct pp_smu_wm_range_sets;
 struct dm_pp_wm_sets_with_clock_ranges_soc15;
+struct amdgpu_device;
+
+int amdgpu_dm_smu_write_watermarks_table(struct amdgpu_device *adev);
 
 #if IS_ENABLED(CONFIG_DRM_AMD_DC_KUNIT_TEST)
 void build_pm_display_cfg(struct amd_pp_display_configuration *pm_display_cfg,
drivers/gpu/drm/amd/display/amdgpu_dm/tests/amdgpu_dm_pp_smu_test.c +20 -0
index 8d1d26bfcc16..fbd07af60230 100644
@@ -16,6 +16,7 @@
 #include "amdgpu_mode.h"
 #include "amdgpu_dm.h"
 #include "amdgpu_dm_pp_smu.h"
+#include "amdgpu_dm_kunit_test_helpers.h"
 
 /* ---- Stub DPM layer ---- */
 
@@ -2321,6 +2322,23 @@ static void dm_test_nv_get_uclk_dpm_states_fail(struct kunit *test)
 			(int)PP_SMU_RESULT_FAIL);
 }
 
+/* Tests for amdgpu_dm_smu_write_watermarks_table() */
+
+/**
+ * dm_test_smu_write_watermarks_table_default - Test watermarks table skips non-Navi1x IP versions
+ * @test: The KUnit test context
+ */
+static void dm_test_smu_write_watermarks_table_default(struct kunit *test)
+{
+	struct amdgpu_device *adev = dm_kunit_alloc_adev(test);
+
+	/*
+	 * A zeroed adev reports DCE IP version 0, which is not one of the
+	 * Navi1x versions handled by the switch, so the function returns early.
+	 */
+	KUNIT_EXPECT_EQ(test, amdgpu_dm_smu_write_watermarks_table(adev), 0);
+}
+
 static struct kunit_case dm_pp_smu_test_cases[] = {
 	/* get_default_clock_levels */
 	KUNIT_CASE(dm_test_default_clock_levels_display),
@@ -2440,6 +2458,8 @@ static struct kunit_case dm_pp_smu_test_cases[] = {
 	KUNIT_CASE(dm_test_nv_get_uclk_dpm_states_ok),
 	KUNIT_CASE(dm_test_nv_get_uclk_dpm_states_unsupported),
 	KUNIT_CASE(dm_test_nv_get_uclk_dpm_states_fail),
+	/* amdgpu_dm_smu_write_watermarks_table */
+	KUNIT_CASE(dm_test_smu_write_watermarks_table_default),
 	{}
 };
 
drivers/gpu/drm/amd/display/amdgpu_dm/tests/amdgpu_dm_test.c +0 -16
index 72d5a4012a3c..49a1d2ae5588 100644
@@ -316,21 +316,6 @@ static void dm_test_atomic_destroy_state_no_context(struct kunit *test)
 	dm_atomic_destroy_state(NULL, &dm_state->base);
 }
 
-/**
- * dm_test_smu_write_watermarks_table_default - Test watermarks table skips non-Navi1x IP versions
- * @test: The KUnit test context
- */
-static void dm_test_smu_write_watermarks_table_default(struct kunit *test)
-{
-	struct amdgpu_device *adev = dm_kunit_alloc_adev(test);
-
-	/*
-	 * A zeroed adev reports DCE IP version 0, which is not one of the
-	 * Navi1x versions handled by the switch, so the function returns early.
-	 */
-	KUNIT_EXPECT_EQ(test, amdgpu_dm_smu_write_watermarks_table(adev), 0);
-}
-
 /* Tests for dm_plane_layer_index_cmp() */
 
 /**
@@ -1801,7 +1786,6 @@ static struct kunit_case amdgpu_dm_tests[] = {
 	KUNIT_CASE(dm_test_should_update_native_cursor_disable_native),
 	KUNIT_CASE(dm_test_should_update_native_cursor_enable_overlay),
 	KUNIT_CASE(dm_test_atomic_destroy_state_no_context),
-	KUNIT_CASE(dm_test_smu_write_watermarks_table_default),
 	/* dm_plane_layer_index_cmp */
 	KUNIT_CASE(dm_test_plane_layer_index_cmp_equal),
 	KUNIT_CASE(dm_test_plane_layer_index_cmp_descending),
Signature · 1 line
2.53.0
#15 lore raw

PATCH 15/49 drm/amd/display: move GPU mem helpers to services

In reply to Fangzhi Zuo

From: Alex Hung <[email protected]>

[WHAT]
dm_allocate_gpu_mem() and dm_free_gpu_mem() are generic DM service helpers that wrap amdgpu_bo_create_kernel()/amdgpu_bo_free_kernel() and track allocations on adev->dm.da_list. Move them out of amdgpu_dm.c into amdgpu_dm_services.c alongside the other dm_* service callbacks.

Both are already public and declared in amdgpu_dm.h; their callers in amdgpu_dm_dmub.c and amdgpu_dm_helpers.c are unaffected. No functional change.

---
 .../gpu/drm/amd/display/amdgpu_dm/amdgpu_dm.c | 53 -------------------
 .../display/amdgpu_dm/amdgpu_dm_services.c    | 53 +++++++++++++++++++
 2 files changed, 53 insertions(+), 53 deletions(-)
drivers/gpu/drm/amd/display/amdgpu_dm/amdgpu_dm.c +0 -53
index d49f0cd3b113..dfc16f5e415a 100644
@@ -411,59 +411,6 @@ static void mmhub_read_system_context(struct amdgpu_device *adev, struct dc_phy_
 
 }
 
-void*
-dm_allocate_gpu_mem(
-		struct amdgpu_device *adev,
-		enum dc_gpu_mem_alloc_type type,
-		size_t size,
-		long long *addr)
-{
-	struct dal_allocation *da;
-	u32 domain = (type == DC_MEM_ALLOC_TYPE_GART) ?
-		AMDGPU_GEM_DOMAIN_GTT : AMDGPU_GEM_DOMAIN_VRAM;
-	int ret;
-
-	da = kzalloc_obj(struct dal_allocation);
-	if (!da)
-		return NULL;
-
-	ret = amdgpu_bo_create_kernel(adev, size, PAGE_SIZE,
-				      domain, &da->bo,
-				      &da->gpu_addr, &da->cpu_ptr);
-
-	*addr = da->gpu_addr;
-
-	if (ret) {
-		kfree(da);
-		return NULL;
-	}
-
-	/* add da to list in dm */
-	list_add(&da->list, &adev->dm.da_list);
-
-	return da->cpu_ptr;
-}
-
-void
-dm_free_gpu_mem(
-		struct amdgpu_device *adev,
-		enum dc_gpu_mem_alloc_type type,
-		void *pvMem)
-{
-	struct dal_allocation *da;
-
-	/* walk the da list in DM */
-	list_for_each_entry(da, &adev->dm.da_list, list) {
-		if (pvMem == da->cpu_ptr) {
-			amdgpu_bo_free_kernel(&da->bo, &da->gpu_addr, &da->cpu_ptr);
-			list_del(&da->list);
-			kfree(da);
-			break;
-		}
-	}
-
-}
-
 static int amdgpu_dm_init_power_module(struct amdgpu_display_manager *dm)
 {
 	struct mod_power_init_params init_data[MAX_NUM_EDP];
drivers/gpu/drm/amd/display/amdgpu_dm/amdgpu_dm_services.c +53 -0

56 lines not on this page · raw message

Signature · 1 line
2.53.0
#16 lore raw

PATCH 16/49 drm/amd/display: add FreeSync/VRR module

In reply to Fangzhi Zuo

From: Alex Hung <[email protected]>

[WHAT]
Group the FreeSync/VRR helpers from amdgpu_dm.c into a dedicated amdgpu_dm_freesync.c and amdgpu_dm_freesync.h. The moved functions are:

is_dc_timing_adjust_needed, is_timing_unchanged_for_freesync, set_freesync_fixed_config, reset_freesync_config_for_crtc, get_freesync_config_for_crtc, update_freesync_state_on_stream, update_stream_irq_parameters, amdgpu_dm_handle_vrr_transition.

The FreeSync/VRR helpers exposed by amdgpu_dm_freesync.h are called from amdgpu_dm.c, so give the seven that lacked a namespace prefix the standard amdgpu_dm_ prefix:

Relocate the corresponding KUnit tests into amdgpu_dm_freesync_test.c.

No functional change.

---
 .../gpu/drm/amd/display/amdgpu_dm/Makefile    |   3 +-
 .../gpu/drm/amd/display/amdgpu_dm/amdgpu_dm.c | 349 +-------------
 .../gpu/drm/amd/display/amdgpu_dm/amdgpu_dm.h |   8 -
 .../display/amdgpu_dm/amdgpu_dm_freesync.c    | 362 ++++++++++++++
 .../display/amdgpu_dm/amdgpu_dm_freesync.h    |  65 +++
 .../drm/amd/display/amdgpu_dm/tests/Makefile  |   1 +
 .../amdgpu_dm/tests/amdgpu_dm_freesync_test.c | 453 ++++++++++++++++++
 .../display/amdgpu_dm/tests/amdgpu_dm_test.c  | 417 ----------------
 8 files changed, 894 insertions(+), 764 deletions(-)
 create mode 100644 drivers/gpu/drm/amd/display/amdgpu_dm/amdgpu_dm_freesync.c
 create mode 100644 drivers/gpu/drm/amd/display/amdgpu_dm/amdgpu_dm_freesync.h
 create mode 100644 drivers/gpu/drm/amd/display/amdgpu_dm/tests/amdgpu_dm_freesync_test.c
drivers/gpu/drm/amd/display/amdgpu_dm/Makefile +2 -1
index d83878e35b61..5cb8c143e72f 100644
@@ -45,7 +45,8 @@ AMDGPUDM = \
 	amdgpu_dm_backlight.o \
 	amdgpu_dm_audio.o \
 	amdgpu_dm_dmub.o \
-	amdgpu_dm_connector.o
+	amdgpu_dm_connector.o \
+	amdgpu_dm_freesync.o
 
 ifdef CONFIG_DRM_AMD_DC_FP
 AMDGPUDM += dc_fpu.o
drivers/gpu/drm/amd/display/amdgpu_dm/amdgpu_dm.c +11 -338

445 lines not on this page · raw message

drivers/gpu/drm/amd/display/amdgpu_dm/amdgpu_dm.h +0 -8
index 70220997cde9..1ef92a28e3e9 100644
@@ -1172,16 +1172,8 @@ void dm_get_plane_scale(struct drm_plane_state *plane_state,
 			int *out_plane_scale_w, int *out_plane_scale_h);
 bool is_scaling_state_different(const struct dm_connector_state *dm_state,
 				const struct dm_connector_state *old_dm_state);
-bool is_timing_unchanged_for_freesync(struct drm_crtc_state *old_crtc_state,
-				      struct drm_crtc_state *new_crtc_state);
-void set_freesync_fixed_config(struct dm_crtc_state *dm_new_crtc_state);
-bool is_dc_timing_adjust_needed(struct dm_crtc_state *old_state,
-				struct dm_crtc_state *new_state);
 void set_multisync_trigger_params(struct dc_stream_state *stream);
 void set_master_stream(struct dc_stream_state *stream_set[], int stream_count);
-void reset_freesync_config_for_crtc(struct dm_crtc_state *new_crtc_state);
-void get_freesync_config_for_crtc(struct dm_crtc_state *new_crtc_state,
-				  struct dm_connector_state *new_con_state);
 void dm_enable_per_frame_crtc_master_sync(struct dc_state *context);
 struct hdcp_workqueue;
 bool is_content_protection_different(struct drm_crtc_state *new_crtc_state,
drivers/gpu/drm/amd/display/amdgpu_dm/amdgpu_dm_freesync.c new file +362 -0

362 lines not on this page · raw message

drivers/gpu/drm/amd/display/amdgpu_dm/amdgpu_dm_freesync.h new file +65 -0

65 lines not on this page · raw message

drivers/gpu/drm/amd/display/amdgpu_dm/tests/Makefile +1 -0
index 1592e8dae1a9..e58ffc4dcd84 100644
@@ -29,6 +29,7 @@ obj-$(CONFIG_DRM_AMD_DC_KUNIT_TEST) += amdgpu_dm_plane_test.o
 obj-$(CONFIG_DRM_AMD_DC_KUNIT_TEST) += amdgpu_dm_mst_types_test.o
 obj-$(CONFIG_DRM_AMD_DC_KUNIT_TEST) += amdgpu_dm_pp_smu_test.o
 obj-$(CONFIG_DRM_AMD_DC_KUNIT_TEST) += amdgpu_dm_test.o
+obj-$(CONFIG_DRM_AMD_DC_KUNIT_TEST) += amdgpu_dm_freesync_test.o
 obj-$(CONFIG_DRM_AMD_DC_KUNIT_TEST) += amdgpu_dm_crtc_test.o
 obj-$(CONFIG_DRM_AMD_DC_KUNIT_TEST) += amdgpu_dm_services_test.o
 obj-$(CONFIG_DRM_AMD_DC_KUNIT_TEST) += amdgpu_dm_helpers_test.o
drivers/gpu/drm/amd/display/amdgpu_dm/tests/amdgpu_dm_freesync_test.c new file +453 -0

453 lines not on this page · raw message

drivers/gpu/drm/amd/display/amdgpu_dm/tests/amdgpu_dm_test.c +0 -417

441 lines not on this page · raw message

Signature · 1 line
2.53.0
#17 lore raw

PATCH 17/49 drm/amd/display: add cursor module

In reply to Fangzhi Zuo

From: Alex Hung <[email protected]>

[WHAT]
Group the cursor policy and validation helpers from amdgpu_dm.c into a dedicated amdgpu_dm_cursor.c and amdgpu_dm_cursor.h. The moved functions are:

dm_check_cursor_fb, dm_check_native_cursor_state, dm_should_update_native_cursor, dm_get_oriented_plane_size, dm_get_plane_scale, dm_plane_color_pipeline_active, dm_crtc_get_cursor_mode.

The cursor helpers exposed by amdgpu_dm_cursor.h are called from amdgpu_dm.c, so give the three that lacked a namespace prefix the standard amdgpu_dm_ prefix: amdgpu_dm_check_native_cursor_state, amdgpu_dm_should_update_native_cursor and amdgpu_dm_crtc_get_cursor_mode.

The descending-zpos plane iterator shared by these functions and amdgpu_dm_atomic_check (the for_each_oldnew_plane_in_descending_zpos macro and its __get_next_zpos helper) moves to amdgpu_dm.h, with the helper renamed amdgpu_dm_get_next_zpos and made non-static.

Relocate the corresponding KUnit tests into amdgpu_dm_cursor_test.c.

No functional change.

---
 .../gpu/drm/amd/display/amdgpu_dm/Makefile    |   3 +-
 .../gpu/drm/amd/display/amdgpu_dm/amdgpu_dm.c | 436 +----------------
 .../gpu/drm/amd/display/amdgpu_dm/amdgpu_dm.h |  24 +-
 .../amd/display/amdgpu_dm/amdgpu_dm_cursor.c  | 443 ++++++++++++++++++
 .../amd/display/amdgpu_dm/amdgpu_dm_cursor.h  |  52 ++
 .../drm/amd/display/amdgpu_dm/tests/Makefile  |   1 +
 .../amdgpu_dm/tests/amdgpu_dm_cursor_test.c   | 268 +++++++++++
 .../display/amdgpu_dm/tests/amdgpu_dm_test.c  | 232 ---------
 8 files changed, 796 insertions(+), 663 deletions(-)
 create mode 100644 drivers/gpu/drm/amd/display/amdgpu_dm/amdgpu_dm_cursor.c
 create mode 100644 drivers/gpu/drm/amd/display/amdgpu_dm/amdgpu_dm_cursor.h
 create mode 100644 drivers/gpu/drm/amd/display/amdgpu_dm/tests/amdgpu_dm_cursor_test.c
drivers/gpu/drm/amd/display/amdgpu_dm/Makefile +2 -1
index 5cb8c143e72f..d1faf2d8370f 100644
@@ -46,7 +46,8 @@ AMDGPUDM = \
 	amdgpu_dm_audio.o \
 	amdgpu_dm_dmub.o \
 	amdgpu_dm_connector.o \
-	amdgpu_dm_freesync.o
+	amdgpu_dm_freesync.o \
+	amdgpu_dm_cursor.o
 
 ifdef CONFIG_DRM_AMD_DC_FP
 AMDGPUDM += dc_fpu.o
drivers/gpu/drm/amd/display/amdgpu_dm/amdgpu_dm.c +14 -422

498 lines not on this page · raw message

drivers/gpu/drm/amd/display/amdgpu_dm/amdgpu_dm.h +16 -8
index 1ef92a28e3e9..1ddf5bc88a03 100644
@@ -1141,6 +1141,22 @@ void amdgpu_dm_emulated_link_detect(struct dc_link *link);
 void amdgpu_dm_apply_delay_after_dpcd_poweroff(struct amdgpu_device *adev,
 											   struct dc_sink *sink);
 
+struct __drm_planes_state *amdgpu_dm_get_next_zpos(struct drm_atomic_commit *state,
+						   struct __drm_planes_state *prev);
+
+/*
+ * Use the uniqueness of the plane's (zpos, drm obj ID) combination to iterate
+ * by descending zpos, as read from the new plane state. This is the same
+ * ordering as defined by drm_atomic_normalize_zpos().
+ */
+#define for_each_oldnew_plane_in_descending_zpos(__state, plane, old_plane_state, new_plane_state) \
+	for (struct __drm_planes_state *__i = amdgpu_dm_get_next_zpos((__state), NULL); \
+	     __i != NULL; __i = amdgpu_dm_get_next_zpos((__state), __i))		\
+		for_each_if(((plane) = __i->ptr,				\
+			     (void)(plane) /* Only to avoid unused-but-set-variable warning */, \
+			     (old_plane_state) = __i->old_state,		\
+			     (new_plane_state) = __i->new_state, 1))
+
 #if IS_ENABLED(CONFIG_DRM_AMD_DC_KUNIT_TEST)
 struct amdgpu_ip_block;
 bool dm_is_idle(struct amdgpu_ip_block *ip_block);
@@ -1157,19 +1173,11 @@ int dm_crtc_get_scanoutpos(struct amdgpu_device *adev, int crtc,
 struct dm_atomic_state *dm_atomic_get_new_state(struct drm_atomic_commit *state);
 void dm_atomic_destroy_state(struct drm_private_obj *obj,
 			     struct drm_private_state *state);
-bool dm_should_update_native_cursor(struct drm_atomic_commit *state,
-				    struct drm_crtc *old_plane_crtc,
-				    struct drm_crtc *new_plane_crtc,
-				    bool enable);
 int dm_plane_layer_index_cmp(const void *a, const void *b);
 int fill_plane_color_attributes(const struct drm_plane_state *plane_state,
 				const enum surface_pixel_format format,
 				enum dc_color_space *color_space);
 bool modereset_required(struct drm_crtc_state *crtc_state);
-void dm_get_oriented_plane_size(struct drm_plane_state *plane_state,
-				int *src_w, int *src_h);
-void dm_get_plane_scale(struct drm_plane_state *plane_state,
-			int *out_plane_scale_w, int *out_plane_scale_h);
 bool is_scaling_state_different(const struct dm_connector_state *dm_state,
 				const struct dm_connector_state *old_dm_state);
 void set_multisync_trigger_params(struct dc_stream_state *stream);
drivers/gpu/drm/amd/display/amdgpu_dm/amdgpu_dm_cursor.c new file +443 -0

443 lines not on this page · raw message

drivers/gpu/drm/amd/display/amdgpu_dm/amdgpu_dm_cursor.h new file +52 -0

52 lines not on this page · raw message

drivers/gpu/drm/amd/display/amdgpu_dm/tests/Makefile +1 -0
index e58ffc4dcd84..3a51fccc2a5e 100644
@@ -30,6 +30,7 @@ obj-$(CONFIG_DRM_AMD_DC_KUNIT_TEST) += amdgpu_dm_mst_types_test.o
 obj-$(CONFIG_DRM_AMD_DC_KUNIT_TEST) += amdgpu_dm_pp_smu_test.o
 obj-$(CONFIG_DRM_AMD_DC_KUNIT_TEST) += amdgpu_dm_test.o
 obj-$(CONFIG_DRM_AMD_DC_KUNIT_TEST) += amdgpu_dm_freesync_test.o
+obj-$(CONFIG_DRM_AMD_DC_KUNIT_TEST) += amdgpu_dm_cursor_test.o
 obj-$(CONFIG_DRM_AMD_DC_KUNIT_TEST) += amdgpu_dm_crtc_test.o
 obj-$(CONFIG_DRM_AMD_DC_KUNIT_TEST) += amdgpu_dm_services_test.o
 obj-$(CONFIG_DRM_AMD_DC_KUNIT_TEST) += amdgpu_dm_helpers_test.o
drivers/gpu/drm/amd/display/amdgpu_dm/tests/amdgpu_dm_cursor_test.c new file +268 -0

268 lines not on this page · raw message

drivers/gpu/drm/amd/display/amdgpu_dm/tests/amdgpu_dm_test.c +0 -232

256 lines not on this page · raw message

Signature · 1 line
2.53.0
#18 lore raw

Re: [PATCH 17/49] drm/amd/display: add cursor module

Quoted 18 lines · Central European Summer Time Fangzhi Zuo

From: Alex Hung <[email protected]>

[WHAT]
Group the cursor policy and validation helpers from amdgpu_dm.c into a dedicated amdgpu_dm_cursor.c and amdgpu_dm_cursor.h. The moved functions are:

dm_check_cursor_fb, dm_check_native_cursor_state, dm_should_update_native_cursor, dm_get_oriented_plane_size, dm_get_plane_scale, dm_plane_color_pipeline_active, dm_crtc_get_cursor_mode.

The cursor helpers exposed by amdgpu_dm_cursor.h are called from amdgpu_dm.c, so give the three that lacked a namespace prefix the standard amdgpu_dm_ prefix: amdgpu_dm_check_native_cursor_state, amdgpu_dm_should_update_native_cursor and amdgpu_dm_crtc_get_cursor_mode.

Quoted 8 lines

The descending-zpos plane iterator shared by these functions and amdgpu_dm_atomic_check (the for_each_oldnew_plane_in_descending_zpos macro and its __get_next_zpos helper) moves to amdgpu_dm.h, with the helper renamed amdgpu_dm_get_next_zpos and made non-static.

Relocate the corresponding KUnit tests into amdgpu_dm_cursor_test.c.

No functional change.

Hi,

This commit regresses a recent bug fix from commit "Set native cursor mode for disabled CRTCs". The amdgpu_dm_crtc_get_cursor_mode() function that was added to amdgpu_dm_cursor.c is not the same as was removed from amdgpu_dm.c

I've submitted a fix here:
https://lists.freedesktop.org/archives/amd-gfx/2026-August/149759.html
Please review.

Thanks & best regards,
Timur

Quoted 49 lines
---
 .../gpu/drm/amd/display/amdgpu_dm/Makefile    |   3 +-
 .../gpu/drm/amd/display/amdgpu_dm/amdgpu_dm.c | 436 +----------------
 .../gpu/drm/amd/display/amdgpu_dm/amdgpu_dm.h |  24 +-
 .../amd/display/amdgpu_dm/amdgpu_dm_cursor.c  | 443 ++++++++++++++++++
 .../amd/display/amdgpu_dm/amdgpu_dm_cursor.h  |  52 ++
 .../drm/amd/display/amdgpu_dm/tests/Makefile  |   1 +
 .../amdgpu_dm/tests/amdgpu_dm_cursor_test.c   | 268 +++++++++++
 .../display/amdgpu_dm/tests/amdgpu_dm_test.c  | 232 ---------
 8 files changed, 796 insertions(+), 663 deletions(-)
 create mode 100644 drivers/gpu/drm/amd/display/amdgpu_dm/amdgpu_dm_cursor.c

create mode 100644 drivers/gpu/drm/amd/display/amdgpu_dm/amdgpu_dm_cursor.h create mode 100644 drivers/gpu/drm/amd/display/amdgpu_dm/tests/amdgpu_dm_cursor_test.c

(quoted diff) +0 -0

b/drivers/gpu/drm/amd/display/amdgpu_dm/Makefile index 5cb8c143e72f..d1faf2d8370f 100644

drivers/gpu/drm/amd/display/amdgpu_dm/Makefile +2 -1
@@ -46,7 +46,8 @@ AMDGPUDM = \
 	amdgpu_dm_audio.o \
 	amdgpu_dm_dmub.o \
 	amdgpu_dm_connector.o \
-	amdgpu_dm_freesync.o
+	amdgpu_dm_freesync.o \
+	amdgpu_dm_cursor.o
 
 ifdef CONFIG_DRM_AMD_DC_FP
 AMDGPUDM += dc_fpu.o
(quoted diff) +0 -0

b/drivers/gpu/drm/amd/display/amdgpu_dm/amdgpu_dm.c index c36eb8a1d2d1..217ec822e93e 100644

drivers/gpu/drm/amd/display/amdgpu_dm/amdgpu_dm.c +1 -0
@@ -72,6 +72,7 @@
 #include "amdgpu_dm_connector.h"
 #include "amdgpu_dm_pp_smu.h"
 #include "amdgpu_dm_freesync.h"
+#include "amdgpu_dm_cursor.h"
 
 #include "ivsrcid/ivsrcid_vislands30.h"
 

drivers/gpu/drm/amd/display/amdgpu_dm/amdgpu_dm.c static bool should_reset_plane(struct · line 5764

Quoted 5 lines
drivers/gpu/drm/amd/display/amdgpu_dm/amdgpu_dm.c +0 -2
@@ -5760,133 +5761,6 @@ static bool should_reset_plane(struct
 drm_atomic_commit *state, return false;
 }
 
-static int dm_check_cursor_fb(struct amdgpu_crtc *new_acrtc,
-			      struct drm_plane_state 

*new_plane_state,

drivers/gpu/drm/amd/display/amdgpu_dm/amdgpu_dm.c static bool should_reset_plane(struct drm_atomic_commit *state,

Quoted 10 lines
drivers/gpu/drm/amd/display/amdgpu_dm/amdgpu_dm.c +0 -10
-			      struct drm_framebuffer *fb)
-{
-	struct amdgpu_device *adev = drm_to_adev(new_acrtc->base.dev);
-	struct amdgpu_framebuffer *afb = to_amdgpu_framebuffer(fb);
-	unsigned int pitch;
-	bool linear;
-
-	if (fb->width > new_acrtc->max_cursor_width ||
-	    fb->height > new_acrtc->max_cursor_height) {
-		drm_dbg_atomic(adev_to_drm(adev), "Bad cursor FB size 

%dx%d\n",

drivers/gpu/drm/amd/display/amdgpu_dm/amdgpu_dm.c static bool should_reset_plane(struct drm_atomic_commit *state,

Quoted 7 lines
drivers/gpu/drm/amd/display/amdgpu_dm/amdgpu_dm.c +0 -7
-				 new_plane_state->fb->width,
-				 new_plane_state->fb->height);
-		return -EINVAL;
-	}
-	if (new_plane_state->src_w != fb->width << 16 ||
-	    new_plane_state->src_h != fb->height << 16) {
-		drm_dbg_atomic(adev_to_drm(adev), "Cropping not 

supported for cursor

drivers/gpu/drm/amd/display/amdgpu_dm/amdgpu_dm.c static bool should_reset_plane(struct drm_atomic_commit *state,

Quoted 8 lines
drivers/gpu/drm/amd/display/amdgpu_dm/amdgpu_dm.c +0 -7
 plane\n"); -		return -EINVAL;
-	}
-
-	/* Pitch in pixels */
-	pitch = fb->pitches[0] / fb->format->cpp[0];
-
-	if (fb->width != pitch) {
-		drm_dbg_atomic(adev_to_drm(adev), "Cursor FB width %d 

doesn't match pitch

drivers/gpu/drm/amd/display/amdgpu_dm/amdgpu_dm.c static bool should_reset_plane(struct drm_atomic_commit *state,

Quoted 12 lines
drivers/gpu/drm/amd/display/amdgpu_dm/amdgpu_dm.c +0 -11
 %d", -				 fb->width, pitch);
-		return -EINVAL;
-	}
-
-	switch (pitch) {
-	case 64:
-	case 128:
-	case 256:
-		/* FB pitch is supported by cursor plane */
-		break;
-	default:
-		drm_dbg_atomic(adev_to_drm(adev), "Bad cursor FB pitch 

%d px\n", pitch);

drivers/gpu/drm/amd/display/amdgpu_dm/amdgpu_dm.c static bool should_reset_plane(struct drm_atomic_commit *state,

Quoted 9 lines
drivers/gpu/drm/amd/display/amdgpu_dm/amdgpu_dm.c +0 -9
-		return -EINVAL;
-	}
-
-	/* Core DRM takes care of checking FB modifiers, so we only need to
-	 * check tiling flags when the FB doesn't have a modifier.
-	 */
-	if (!(fb->flags & DRM_MODE_FB_MODIFIERS)) {
-		if (adev->family == AMDGPU_FAMILY_GC_12_0_0) {
-			linear = AMDGPU_TILING_GET(afb->tiling_flags, 

GFX12_SWIZZLE_MODE) == 0;

drivers/gpu/drm/amd/display/amdgpu_dm/amdgpu_dm.c static bool should_reset_plane(struct · line 5812

Quoted 2 lines
drivers/gpu/drm/amd/display/amdgpu_dm/amdgpu_dm.c +0 -2
-		} else if (adev->family >= AMDGPU_FAMILY_AI) {
-			linear = AMDGPU_TILING_GET(afb->tiling_flags, 

SWIZZLE_MODE) == 0;

drivers/gpu/drm/amd/display/amdgpu_dm/amdgpu_dm.c static bool should_reset_plane(struct · line 5814

Quoted 2 lines
drivers/gpu/drm/amd/display/amdgpu_dm/amdgpu_dm.c +0 -2
-		} else {
-			linear = AMDGPU_TILING_GET(afb->tiling_flags, 

ARRAY_MODE) !=

Quoted 1 line

DC_ARRAY_2D_TILED_THIN1 && -

AMDGPU_TILING_GET(afb->tiling_flags,

drivers/gpu/drm/amd/display/amdgpu_dm/amdgpu_dm.c static bool should_reset_plane(struct drm_atomic_commit *state,

Quoted 5 lines

ARRAY_MODE) != DC_ARRAY_1D_TILED_THIN1 && - AMDGPU_TILING_GET(afb->tiling_flags, MICRO_TILE_MODE) == 0;

drivers/gpu/drm/amd/display/amdgpu_dm/amdgpu_dm.c +0 -3
-		}
-		if (!linear) {
-			drm_dbg_atomic(adev_to_drm(adev), "Cursor FB 

not linear");

drivers/gpu/drm/amd/display/amdgpu_dm/amdgpu_dm.c static bool should_reset_plane(struct drm_atomic_commit *state,

Quoted 12 lines
drivers/gpu/drm/amd/display/amdgpu_dm/amdgpu_dm.c +0 -12
-			return -EINVAL;
-		}
-	}
-
-	return 0;
-}
-
-/*
- * Helper function for checking the cursor in native mode
- */
-static int dm_check_native_cursor_state(struct drm_crtc *new_plane_crtc,
-					struct drm_plane 

*plane,

drivers/gpu/drm/amd/display/amdgpu_dm/amdgpu_dm.c

Quoted 1 line
drivers/gpu/drm/amd/display/amdgpu_dm/amdgpu_dm.c +0 -1
-					struct drm_plane_state 

*new_plane_state,

Quoted 4 lines
drivers/gpu/drm/amd/display/amdgpu_dm/amdgpu_dm.c +0 -4
-					bool enable)
-{
-
-	struct amdgpu_crtc *new_acrtc;

drivers/gpu/drm/amd/display/amdgpu_dm/amdgpu_dm.c static bool should_reset_plane(struct drm_atomic_commit *state,

Quoted 10 lines
drivers/gpu/drm/amd/display/amdgpu_dm/amdgpu_dm.c +0 -10
-	int ret;
-
-	if (!enable || !new_plane_crtc ||
-	    drm_atomic_plane_disabling(plane->state, new_plane_state))
-		return 0;
-
-	new_acrtc = to_amdgpu_crtc(new_plane_crtc);
-
-	if (new_plane_state->src_x != 0 || new_plane_state->src_y != 0) {
-		drm_dbg_atomic(new_plane_crtc->dev, "Cropping not 

supported for cursor

drivers/gpu/drm/amd/display/amdgpu_dm/amdgpu_dm.c static bool should_reset_plane(struct drm_atomic_commit *state, · line 5856

Quoted 6 lines

plane\n"); - return -EINVAL;

drivers/gpu/drm/amd/display/amdgpu_dm/amdgpu_dm.c +0 -5
-	}
-
-	if (new_plane_state->fb) {
-		ret = dm_check_cursor_fb(new_acrtc, new_plane_state,
-						

new_plane_state->fb);

Quoted 9 lines
drivers/gpu/drm/amd/display/amdgpu_dm/amdgpu_dm.c +0 -8
-		if (ret)
-			return ret;
-	}
-
-	return 0;
-}
-
-STATIC_IFN_KUNIT bool dm_should_update_native_cursor(struct

drm_atomic_commit *state, -

struct drm_crtc *old_plane_crtc,

drivers/gpu/drm/amd/display/amdgpu_dm/amdgpu_dm.c

Quoted 1 line
drivers/gpu/drm/amd/display/amdgpu_dm/amdgpu_dm.c +0 -1
-						     struct 

drm_crtc *new_plane_crtc,

drivers/gpu/drm/amd/display/amdgpu_dm/amdgpu_dm.c

Quoted 1 line
drivers/gpu/drm/amd/display/amdgpu_dm/amdgpu_dm.c +0 -1
-						     bool 

enable)

drivers/gpu/drm/amd/display/amdgpu_dm/amdgpu_dm.c static bool should_reset_plane(struct drm_atomic_commit *state,

Quoted 13 lines
drivers/gpu/drm/amd/display/amdgpu_dm/amdgpu_dm.c +0 -13
-{
-	struct drm_crtc_state *old_crtc_state, *new_crtc_state;
-	struct dm_crtc_state *dm_old_crtc_state, *dm_new_crtc_state;
-
-	if (!enable) {
-		if (old_plane_crtc == NULL)
-			return true;
-
-		old_crtc_state = drm_atomic_get_old_crtc_state(
-			state, old_plane_crtc);
-		dm_old_crtc_state = to_dm_crtc_state(old_crtc_state);
-
-		return dm_old_crtc_state->cursor_mode == 

DM_CURSOR_NATIVE_MODE;

drivers/gpu/drm/amd/display/amdgpu_dm/amdgpu_dm.c static bool should_reset_plane(struct drm_atomic_commit *state,

Quoted 9 lines
drivers/gpu/drm/amd/display/amdgpu_dm/amdgpu_dm.c +0 -9
-	} else {
-		if (new_plane_crtc == NULL)
-			return true;
-
-		new_crtc_state = drm_atomic_get_new_crtc_state(
-			state, new_plane_crtc);
-		dm_new_crtc_state = to_dm_crtc_state(new_crtc_state);
-
-		return dm_new_crtc_state->cursor_mode == 

DM_CURSOR_NATIVE_MODE;

drivers/gpu/drm/amd/display/amdgpu_dm/amdgpu_dm.c static int dm_update_plane_state(struct dc *dc, · line 5915

Quoted 13 lines
drivers/gpu/drm/amd/display/amdgpu_dm/amdgpu_dm.c +0 -6
-	}
-}
-EXPORT_IF_KUNIT(dm_should_update_native_cursor);
-
 static int dm_update_plane_state(struct dc *dc,
 				 struct drm_atomic_commit *state,
 				 struct drm_plane *plane,
@@ -5911,14 +5785,14 @@ static int dm_update_plane_state(struct dc *dc,
 	dm_new_plane_state = to_dm_plane_state(new_plane_state);
 	dm_old_plane_state = to_dm_plane_state(old_plane_state);
 
-	update_native_cursor = dm_should_update_native_cursor(state,
-							      

old_plane_crtc,

drivers/gpu/drm/amd/display/amdgpu_dm/amdgpu_dm.c static int dm_update_plane_state(struct dc *dc, · line 5916

Quoted 1 line
drivers/gpu/drm/amd/display/amdgpu_dm/amdgpu_dm.c +0 -1
-							      

new_plane_crtc,

drivers/gpu/drm/amd/display/amdgpu_dm/amdgpu_dm.c static int dm_update_plane_state(struct dc *dc, · line 5917

Quoted 1 line
drivers/gpu/drm/amd/display/amdgpu_dm/amdgpu_dm.c +0 -1
-							      

enable);

drivers/gpu/drm/amd/display/amdgpu_dm/amdgpu_dm.c static int dm_update_plane_state(struct dc *dc, · line 5789

Quoted 2 lines
drivers/gpu/drm/amd/display/amdgpu_dm/amdgpu_dm.c +2 -0
+	update_native_cursor = amdgpu_dm_should_update_native_cursor(state,
+								

old_plane_crtc,

drivers/gpu/drm/amd/display/amdgpu_dm/amdgpu_dm.c static int dm_update_plane_state(struct dc *dc, · line 5790

Quoted 1 line
drivers/gpu/drm/amd/display/amdgpu_dm/amdgpu_dm.c +1 -0
+								

new_plane_crtc,

drivers/gpu/drm/amd/display/amdgpu_dm/amdgpu_dm.c static int dm_update_plane_state(struct dc *dc, · line 5791

Quoted 1 line
drivers/gpu/drm/amd/display/amdgpu_dm/amdgpu_dm.c +1 -0
+								
     enable);

drivers/gpu/drm/amd/display/amdgpu_dm/amdgpu_dm.c static int dm_update_plane_state(struct dc *dc, · line 5792

Quoted 2 lines
drivers/gpu/drm/amd/display/amdgpu_dm/amdgpu_dm.c +0 -0
 	if (plane->type == DRM_PLANE_TYPE_CURSOR && update_native_cursor) 

{

drivers/gpu/drm/amd/display/amdgpu_dm/amdgpu_dm.c static int dm_update_plane_state(struct dc *dc, · line 5919

Quoted 1 line
drivers/gpu/drm/amd/display/amdgpu_dm/amdgpu_dm.c +0 -1
-		ret = dm_check_native_cursor_state(new_plane_crtc, 

plane,

drivers/gpu/drm/amd/display/amdgpu_dm/amdgpu_dm.c static int dm_update_plane_state(struct dc *dc, · line 5920

Quoted 1 line
drivers/gpu/drm/amd/display/amdgpu_dm/amdgpu_dm.c +0 -1
-						    

new_plane_state, enable);

drivers/gpu/drm/amd/display/amdgpu_dm/amdgpu_dm.c static int dm_update_plane_state(struct dc *dc, · line 5793

Quoted 1 line
drivers/gpu/drm/amd/display/amdgpu_dm/amdgpu_dm.c +1 -0
+		ret = 

amdgpu_dm_check_native_cursor_state(new_plane_crtc, plane,

drivers/gpu/drm/amd/display/amdgpu_dm/amdgpu_dm.c static int dm_update_plane_state(struct dc *dc, · line 5794

Quoted 1 line
drivers/gpu/drm/amd/display/amdgpu_dm/amdgpu_dm.c +1 -0
+							  

new_plane_state, enable);

drivers/gpu/drm/amd/display/amdgpu_dm/amdgpu_dm.c static int dm_update_plane_state(struct dc *dc, · line 5923

Quoted 6 lines
drivers/gpu/drm/amd/display/amdgpu_dm/amdgpu_dm.c +0 -0
 		if (ret)
 			return ret;
 
@@ -6048,8 +5922,8 @@ static int dm_update_plane_state(struct dc *dc,
 out:
 	/* If enabling cursor overlay failed, attempt fallback to native 

mode */

drivers/gpu/drm/amd/display/amdgpu_dm/amdgpu_dm.c static int dm_update_plane_state(struct dc *dc, · line 5924

Quoted 1 line
drivers/gpu/drm/amd/display/amdgpu_dm/amdgpu_dm.c +0 -0
 	if (enable && ret == -EINVAL && plane->type == 

DRM_PLANE_TYPE_CURSOR) {

drivers/gpu/drm/amd/display/amdgpu_dm/amdgpu_dm.c static int dm_update_plane_state(struct dc *dc, · line 6051

Quoted 1 line
drivers/gpu/drm/amd/display/amdgpu_dm/amdgpu_dm.c +0 -1
-		ret = dm_check_native_cursor_state(new_plane_crtc, 

plane,

drivers/gpu/drm/amd/display/amdgpu_dm/amdgpu_dm.c static int dm_update_plane_state(struct dc *dc, · line 6052

Quoted 1 line
drivers/gpu/drm/amd/display/amdgpu_dm/amdgpu_dm.c +0 -1
-						    

new_plane_state, enable);

drivers/gpu/drm/amd/display/amdgpu_dm/amdgpu_dm.c static int dm_update_plane_state(struct dc *dc, · line 5925

Quoted 1 line
drivers/gpu/drm/amd/display/amdgpu_dm/amdgpu_dm.c +1 -0
+		ret = 

amdgpu_dm_check_native_cursor_state(new_plane_crtc, plane,

drivers/gpu/drm/amd/display/amdgpu_dm/amdgpu_dm.c static int dm_update_plane_state(struct dc *dc, · line 5926

Quoted 1 line
drivers/gpu/drm/amd/display/amdgpu_dm/amdgpu_dm.c +1 -0
+							  

new_plane_state, enable);

drivers/gpu/drm/amd/display/amdgpu_dm/amdgpu_dm.c static int dm_update_plane_state(struct dc *dc, · line 5936

Quoted 9 lines
drivers/gpu/drm/amd/display/amdgpu_dm/amdgpu_dm.c +0 -1
 		if (ret)
 			return ret;
 
@@ -6059,37 +5933,6 @@ static int dm_update_plane_state(struct dc *dc,
 	return ret;
 }
 
-STATIC_IFN_KUNIT void dm_get_oriented_plane_size(struct drm_plane_state
 *plane_state, -					 int 

*src_w, int *src_h)

Quoted 14 lines
drivers/gpu/drm/amd/display/amdgpu_dm/amdgpu_dm.c +0 -14
-{
-	switch (plane_state->rotation & DRM_MODE_ROTATE_MASK) {
-	case DRM_MODE_ROTATE_90:
-	case DRM_MODE_ROTATE_270:
-		*src_w = plane_state->src_h >> 16;
-		*src_h = plane_state->src_w >> 16;
-		break;
-	case DRM_MODE_ROTATE_0:
-	case DRM_MODE_ROTATE_180:
-	default:
-		*src_w = plane_state->src_w >> 16;
-		*src_h = plane_state->src_h >> 16;
-		break;
-	}

drivers/gpu/drm/amd/display/amdgpu_dm/amdgpu_dm.c static int dm_update_plane_state(struct dc *dc,

Quoted 10 lines
drivers/gpu/drm/amd/display/amdgpu_dm/amdgpu_dm.c +0 -10
-}
-EXPORT_IF_KUNIT(dm_get_oriented_plane_size);
-
-STATIC_IFN_KUNIT void
-dm_get_plane_scale(struct drm_plane_state *plane_state,
-		   int *out_plane_scale_w, int *out_plane_scale_h)
-{
-	int plane_src_w, plane_src_h;
-
-	dm_get_oriented_plane_size(plane_state, &plane_src_w, 

&plane_src_h);

Quoted 31 lines
drivers/gpu/drm/amd/display/amdgpu_dm/amdgpu_dm.c +0 -1
-	*out_plane_scale_w = plane_src_w ? plane_state->crtc_w * 1000 /

plane_src_w : 0; - *out_plane_scale_h = plane_src_h ? plane_state-
crtc_h *
1000 / plane_src_h : 0; -}

drivers/gpu/drm/amd/display/amdgpu_dm/amdgpu_dm.c +0 -2
-EXPORT_IF_KUNIT(dm_get_plane_scale);
-
 /*
  * The normalized_zpos value cannot be used by this iterator directly. It's

only * calculated for enabled planes, potentially causing normalized_zpos collisions @@ -6097,7 +5940,7 @@ EXPORT_IF_KUNIT(dm_get_plane_scale);
* so that the iterator will not generate the same object twice, or loop
* indefinitely.
*/

drivers/gpu/drm/amd/display/amdgpu_dm/amdgpu_dm.c +1 -3
-static inline struct __drm_planes_state *__get_next_zpos(
+struct __drm_planes_state *amdgpu_dm_get_next_zpos(
 	struct drm_atomic_commit *state,
 	struct __drm_planes_state *prev)
 {
@@ -6135,19 +5978,6 @@ static inline struct __drm_planes_state
 *__get_next_zpos( return &state->planes[highest_i];
 }
 
-/*
- * Use the uniqueness of the plane's (zpos, drm obj ID) combination to

iterate - * by descending zpos, as read from the new plane state. This is the same - * ordering as defined by drm_atomic_normalize_zpos().
- */
-#define for_each_oldnew_plane_in_descending_zpos(__state, plane,
old_plane_state, new_plane_state) \ - for (struct __drm_planes_state *__i =
__get_next_zpos((__state), NULL); \ - __i != NULL; __i =
__get_next_zpos((__state), __i)) \

drivers/gpu/drm/amd/display/amdgpu_dm/amdgpu_dm.c

Quoted 1 line
drivers/gpu/drm/amd/display/amdgpu_dm/amdgpu_dm.c +0 -1
-		for_each_if(((plane) = __i->ptr,			
	\

drivers/gpu/drm/amd/display/amdgpu_dm/amdgpu_dm.c

Quoted 1 line
drivers/gpu/drm/amd/display/amdgpu_dm/amdgpu_dm.c +0 -1
-			     (void)(plane) /* Only to avoid unused-

but-set-variable warning */,

Quoted 1 line

\ - (old_plane_state) = __i->old_state,

\

Quoted 38 lines
drivers/gpu/drm/amd/display/amdgpu_dm/amdgpu_dm.c +0 -2
-			     (new_plane_state) = __i->new_state, 1))
-
 static int add_affected_mst_dsc_crtcs(struct drm_atomic_commit *state,

struct drm_crtc *crtc) {

drivers/gpu/drm/amd/display/amdgpu_dm/amdgpu_dm.c +0 -0
 	struct drm_connector *connector;
@@ -6178,244 +6008,6 @@ static int add_affected_mst_dsc_crtcs(struct

drm_atomic_commit *state, struct dr return drm_dp_mst_add_affected_dsc_crtcs(state, &aconnector->mst_root->mst_mgr); }

-/**
- * DOC: Cursor Modes - Native vs Overlay
- *
- * In native mode, the cursor uses a integrated cursor pipe within each DCN hw - * plane. It does not require a dedicated hw plane to enable, but it is
- * subjected to the same z-order and scaling as the hw plane. It also has format - * restrictions, a RGB cursor in native mode cannot be enabled within a non-RGB - * hw plane.
- *
- * In overlay mode, the cursor uses a separate DCN hw plane, and thus has its - * own scaling and z-pos. It also has no blending restrictions. It lends to a - * cursor behavior more akin to a DRM client's expectations. However, it does - * occupy an extra DCN plane, and therefore will only be used if a DCN plane is - * available.
- */

drivers/gpu/drm/amd/display/amdgpu_dm/amdgpu_dm.c +0 -3
-
-/**
- * dm_plane_color_pipeline_active() - Check if a plane's color pipeline

active. - * @state: DRM atomic state
- * @plane: DRM plane to check
- * @use_old: if true, inspect the old colorop states; otherwise the new ones - *
- * A color pipeline may be selected (color_pipeline != NULL) but still is
- * inactive if every colorop in the chain is bypassed. Only return
- * true when at least one colorop has bypass == false, meaning the cursor
- * would be subjected to the transformation in native mode.
- *
- * Return: true if the pipeline modifies pixels, false otherwise.
- */

drivers/gpu/drm/amd/display/amdgpu_dm/amdgpu_dm.c

Quoted 2 lines
drivers/gpu/drm/amd/display/amdgpu_dm/amdgpu_dm.c +0 -2
-static bool dm_plane_color_pipeline_active(struct drm_atomic_commit *state,
-					   struct drm_plane 

*plane,

drivers/gpu/drm/amd/display/amdgpu_dm/amdgpu_dm.c static int add_affected_mst_dsc_crtcs(struct drm_atomic_commit *state, struct dr

Quoted 7 lines
drivers/gpu/drm/amd/display/amdgpu_dm/amdgpu_dm.c +0 -7
-					   bool use_old)
-{
-	struct drm_colorop *colorop;
-	struct drm_colorop_state *old_colorop_state, *new_colorop_state;
-	int i;
-
-	for_each_oldnew_colorop_in_state(state, colorop, 

old_colorop_state,

Quoted 1 line

new_colorop_state, i) { - struct drm_colorop_state *cstate =

use_old ?

Quoted 29 lines

old_colorop_state : new_colorop_state; -

drivers/gpu/drm/amd/display/amdgpu_dm/amdgpu_dm.c +0 -16
-		if (cstate->colorop->plane != plane)
-			continue;
-		if (!cstate->bypass)
-			return true;
-	}
-	return false;
-}
-
-/**
- * dm_crtc_get_cursor_mode() - Determine the required cursor mode on crtc
- * @adev: amdgpu device
- * @state: DRM atomic state
- * @dm_crtc_state: amdgpu state for the CRTC containing the cursor
- * @cursor_mode: Returns the required cursor mode on dm_crtc_state
- *
- * Get whether the cursor should be enabled in native mode, or overlay

mode, on - * the dm_crtc_state.
- *
- * The cursor should be enabled in overlay mode if there exists an underlying - * plane - on which the cursor may be blended - that is either YUV formatted, - * scaled differently from the cursor, or has a color pipeline active. - *
- * Since zpos info is required, drm_atomic_normalize_zpos must be called before - * calling this function.
- *
- * Return: 0 on success, or an error code if getting the cursor plane state
- * failed.
- */

drivers/gpu/drm/amd/display/amdgpu_dm/amdgpu_dm.c

Quoted 2 lines
drivers/gpu/drm/amd/display/amdgpu_dm/amdgpu_dm.c +0 -2
-static int dm_crtc_get_cursor_mode(struct amdgpu_device *adev,
-				   struct drm_atomic_commit 

*state,

drivers/gpu/drm/amd/display/amdgpu_dm/amdgpu_dm.c

Quoted 1 line
drivers/gpu/drm/amd/display/amdgpu_dm/amdgpu_dm.c +0 -1
-				   struct dm_crtc_state 

*dm_crtc_state,

drivers/gpu/drm/amd/display/amdgpu_dm/amdgpu_dm.c

Quoted 1 line
drivers/gpu/drm/amd/display/amdgpu_dm/amdgpu_dm.c +0 -1
-				   enum amdgpu_dm_cursor_mode 

*cursor_mode)

drivers/gpu/drm/amd/display/amdgpu_dm/amdgpu_dm.c

Quoted 2 lines
drivers/gpu/drm/amd/display/amdgpu_dm/amdgpu_dm.c +0 -2
-{
-	struct drm_plane_state *old_plane_state, *plane_state, 

*cursor_state;

Quoted 20 lines
drivers/gpu/drm/amd/display/amdgpu_dm/amdgpu_dm.c +0 -11
-	struct drm_crtc_state *crtc_state = &dm_crtc_state->base;
-	struct drm_plane *plane;
-	bool consider_mode_change = false;
-	bool entire_crtc_covered = false;
-	bool cursor_changed = false;
-	int underlying_scale_w, underlying_scale_h;
-	int cursor_scale_w, cursor_scale_h;
-	int i;
-
-	/* Overlay cursor not supported on HW before DCN
-	 * DCN401/420 does not have the cursor-on-scaled-plane or

cursor-on-yuv-plane restrictions - * as previous DCN generations, so
enable native mode on DCN401/420 - *

drivers/gpu/drm/amd/display/amdgpu_dm/amdgpu_dm.c +0 -7
-	 * Always set native cursor mode when the CRTC is disabled,
-	 * to make sure it doesn't cause atomic commits to fail when
-	 * they are trying to disable the CRTC.
-	 */
-	if (amdgpu_ip_version(adev, DCE_HWIP, 0) == IP_VERSION(4, 0, 1) ||
-	    amdgpu_ip_version(adev, DCE_HWIP, 0) == IP_VERSION(4, 2, 0) ||
-	    amdgpu_ip_version(adev, DCE_HWIP, 0) == IP_VERSION(4, 2, 1) ||

drivers/gpu/drm/amd/display/amdgpu_dm/amdgpu_dm.c static int add_affected_mst_dsc_crtcs(struct drm_atomic_commit *state, struct dr

Quoted 10 lines
drivers/gpu/drm/amd/display/amdgpu_dm/amdgpu_dm.c +0 -10
-	    !dm_crtc_state->base.enable) {
-		*cursor_mode = DM_CURSOR_NATIVE_MODE;
-		return 0;
-	}
-
-	/* Init cursor_mode to be the same as current */
-	*cursor_mode = dm_crtc_state->cursor_mode;
-
-	/*
-	 * Cursor mode can change if a plane's format changes, scale 

changes, is

drivers/gpu/drm/amd/display/amdgpu_dm/amdgpu_dm.c

Quoted 1 line
drivers/gpu/drm/amd/display/amdgpu_dm/amdgpu_dm.c +0 -1
-	 * enabled/disabled, z-order changes, or color management 

properties

drivers/gpu/drm/amd/display/amdgpu_dm/amdgpu_dm.c

Quoted 2 lines

change. - */

drivers/gpu/drm/amd/display/amdgpu_dm/amdgpu_dm.c +0 -1
-	for_each_oldnew_plane_in_state(state, plane, old_plane_state, 

plane_state,

Quoted 1 line

i) { - int new_scale_w, new_scale_h, old_scale_w,

old_scale_h;

drivers/gpu/drm/amd/display/amdgpu_dm/amdgpu_dm.c static int add_affected_mst_dsc_crtcs(struct drm_atomic_commit *state, struct dr

Quoted 3 lines
drivers/gpu/drm/amd/display/amdgpu_dm/amdgpu_dm.c +0 -3
-
-		/* Only care about planes on this CRTC */
-		if ((drm_plane_mask(plane) & crtc_state->plane_mask) == 

0)

drivers/gpu/drm/amd/display/amdgpu_dm/amdgpu_dm.c static int add_affected_mst_dsc_crtcs(struct drm_atomic_commit *state, struct dr

Quoted 6 lines
drivers/gpu/drm/amd/display/amdgpu_dm/amdgpu_dm.c +0 -6
-			continue;
-
-		if (plane->type == DRM_PLANE_TYPE_CURSOR)
-			cursor_changed = true;
-
-		if (drm_atomic_plane_enabling(old_plane_state, 

plane_state) ||

drivers/gpu/drm/amd/display/amdgpu_dm/amdgpu_dm.c

Quoted 1 line
drivers/gpu/drm/amd/display/amdgpu_dm/amdgpu_dm.c +0 -1
-		    drm_atomic_plane_disabling(old_plane_state, 

plane_state) ||

drivers/gpu/drm/amd/display/amdgpu_dm/amdgpu_dm.c static int add_affected_mst_dsc_crtcs(struct drm_atomic_commit *state, struct dr

Quoted 7 lines
drivers/gpu/drm/amd/display/amdgpu_dm/amdgpu_dm.c +0 -1
-		    old_plane_state->fb->format != plane_state->fb-

format) {

drivers/gpu/drm/amd/display/amdgpu_dm/amdgpu_dm.c +0 -5
-			consider_mode_change = true;
-			break;
-		}
-
-		dm_get_plane_scale(plane_state, &new_scale_w, 

&new_scale_h);

drivers/gpu/drm/amd/display/amdgpu_dm/amdgpu_dm.c

Quoted 1 line
drivers/gpu/drm/amd/display/amdgpu_dm/amdgpu_dm.c +0 -1
-		dm_get_plane_scale(old_plane_state, &old_scale_w, 

&old_scale_h);

drivers/gpu/drm/amd/display/amdgpu_dm/amdgpu_dm.c

Quoted 1 line
drivers/gpu/drm/amd/display/amdgpu_dm/amdgpu_dm.c +0 -1
-		if (new_scale_w != old_scale_w || new_scale_h != 

old_scale_h) {

drivers/gpu/drm/amd/display/amdgpu_dm/amdgpu_dm.c static int add_affected_mst_dsc_crtcs(struct drm_atomic_commit *state, struct dr

Quoted 6 lines
drivers/gpu/drm/amd/display/amdgpu_dm/amdgpu_dm.c +0 -6
-			consider_mode_change = true;
-			break;
-		}
-
-		/*
-		 * A non-cursor plane moving or resizing (without a 

scale change)

drivers/gpu/drm/amd/display/amdgpu_dm/amdgpu_dm.c

Quoted 1 line
drivers/gpu/drm/amd/display/amdgpu_dm/amdgpu_dm.c +0 -1
-		 * changes how much of the CRTC it covers. This can 

create or

drivers/gpu/drm/amd/display/amdgpu_dm/amdgpu_dm.c

Quoted 1 line
drivers/gpu/drm/amd/display/amdgpu_dm/amdgpu_dm.c +0 -1
-		 * remove a hole under the cursor and thus flip the 

required

drivers/gpu/drm/amd/display/amdgpu_dm/amdgpu_dm.c

Quoted 1 line
drivers/gpu/drm/amd/display/amdgpu_dm/amdgpu_dm.c +0 -1
-		 * cursor mode (native vs overlay), so its destination 

rect must

drivers/gpu/drm/amd/display/amdgpu_dm/amdgpu_dm.c static int add_affected_mst_dsc_crtcs(struct drm_atomic_commit *state, struct dr

Quoted 3 lines
drivers/gpu/drm/amd/display/amdgpu_dm/amdgpu_dm.c +0 -3
-		 * be re-evaluated too.
-		 *
-		 * The cursor plane itself is deliberately excluded: 

the cursor

drivers/gpu/drm/amd/display/amdgpu_dm/amdgpu_dm.c

Quoted 1 line
drivers/gpu/drm/amd/display/amdgpu_dm/amdgpu_dm.c +0 -1
-		 * mode depends on the underlying planes' coverage, not 

on the

drivers/gpu/drm/amd/display/amdgpu_dm/amdgpu_dm.c

Quoted 1 line
drivers/gpu/drm/amd/display/amdgpu_dm/amdgpu_dm.c +0 -1
-		 * cursor's position (see the entire_crtc_covered logic 

below).

drivers/gpu/drm/amd/display/amdgpu_dm/amdgpu_dm.c

Quoted 1 line
drivers/gpu/drm/amd/display/amdgpu_dm/amdgpu_dm.c +0 -1
-		 * Triggering on cursor movement would force every 

legacy cursor

drivers/gpu/drm/amd/display/amdgpu_dm/amdgpu_dm.c

Quoted 1 line
drivers/gpu/drm/amd/display/amdgpu_dm/amdgpu_dm.c +0 -1
-		 * update off its fast path, and in a cursor-only commit 

- where

drivers/gpu/drm/amd/display/amdgpu_dm/amdgpu_dm.c

Quoted 1 line
drivers/gpu/drm/amd/display/amdgpu_dm/amdgpu_dm.c +0 -1
-		 * the underlying planes are not part of the state - 

the coverage

drivers/gpu/drm/amd/display/amdgpu_dm/amdgpu_dm.c

Quoted 1 line
drivers/gpu/drm/amd/display/amdgpu_dm/amdgpu_dm.c +0 -1
-		 * loop would see no covering plane and misevaluate the 

mode as

drivers/gpu/drm/amd/display/amdgpu_dm/amdgpu_dm.c static int add_affected_mst_dsc_crtcs(struct drm_atomic_commit *state, struct dr

Quoted 12 lines
drivers/gpu/drm/amd/display/amdgpu_dm/amdgpu_dm.c +0 -12
-		 * overlay, regressing flip-vs-cursor-legacy.
-		 */
-		if (plane->type != DRM_PLANE_TYPE_CURSOR &&
-		    (old_plane_state->crtc_x != plane_state->crtc_x ||
-		     old_plane_state->crtc_y != plane_state->crtc_y ||
-		     old_plane_state->crtc_w != plane_state->crtc_w ||
-		     old_plane_state->crtc_h != plane_state->crtc_h)) {
-			consider_mode_change = true;
-			break;
-		}
-
-		if (dm_plane_color_pipeline_active(state, plane, true) 

!=

drivers/gpu/drm/amd/display/amdgpu_dm/amdgpu_dm.c

Quoted 1 line
drivers/gpu/drm/amd/display/amdgpu_dm/amdgpu_dm.c +0 -1
-		    dm_plane_color_pipeline_active(state, plane, 

false)) {

drivers/gpu/drm/amd/display/amdgpu_dm/amdgpu_dm.c static int add_affected_mst_dsc_crtcs(struct drm_atomic_commit *state, struct dr

Quoted 10 lines
drivers/gpu/drm/amd/display/amdgpu_dm/amdgpu_dm.c +0 -10
-			consider_mode_change = true;
-			break;
-		}
-	}
-
-	if (!consider_mode_change && !crtc_state->zpos_changed)
-		return 0;
-
-	/*
-	 * If no cursor change on this CRTC, and not enabled on this CRTC, 

then

drivers/gpu/drm/amd/display/amdgpu_dm/amdgpu_dm.c

Quoted 1 line
drivers/gpu/drm/amd/display/amdgpu_dm/amdgpu_dm.c +0 -1
-	 * no need to set cursor mode. This avoids needlessly locking the 

cursor

drivers/gpu/drm/amd/display/amdgpu_dm/amdgpu_dm.c static int add_affected_mst_dsc_crtcs(struct drm_atomic_commit *state, struct dr · line 6360

Quoted 10 lines
drivers/gpu/drm/amd/display/amdgpu_dm/amdgpu_dm.c +0 -4
-	 * state.
-	 */
-	if (!cursor_changed &&
-	    !(drm_plane_mask(crtc_state->crtc->cursor) & crtc_state-

plane_mask))
{ - return 0;

drivers/gpu/drm/amd/display/amdgpu_dm/amdgpu_dm.c +0 -4
-	}
-
-	cursor_state = drm_atomic_get_plane_state(state,
-						  

crtc_state->crtc->cursor);

drivers/gpu/drm/amd/display/amdgpu_dm/amdgpu_dm.c static int add_affected_mst_dsc_crtcs(struct drm_atomic_commit *state, struct dr

Quoted 8 lines
drivers/gpu/drm/amd/display/amdgpu_dm/amdgpu_dm.c +0 -8
-	if (IS_ERR(cursor_state))
-		return PTR_ERR(cursor_state);
-
-	/* Cursor is disabled */
-	if (!cursor_state->fb)
-		return 0;
-
-	/* For all planes in descending z-order (all of which are below 

cursor

drivers/gpu/drm/amd/display/amdgpu_dm/amdgpu_dm.c static int add_affected_mst_dsc_crtcs(struct drm_atomic_commit *state, struct dr

Quoted 3 lines
drivers/gpu/drm/amd/display/amdgpu_dm/amdgpu_dm.c +0 -3
-	 * as per zpos definitions), check their scaling and format
-	 */
-	for_each_oldnew_plane_in_descending_zpos(state, plane, 

old_plane_state,

drivers/gpu/drm/amd/display/amdgpu_dm/amdgpu_dm.c

Quoted 3 lines

plane_state) { -

drivers/gpu/drm/amd/display/amdgpu_dm/amdgpu_dm.c +0 -2
-		/* Only care about non-cursor planes on this CRTC */
-		if ((drm_plane_mask(plane) & crtc_state->plane_mask) == 

0 ||

drivers/gpu/drm/amd/display/amdgpu_dm/amdgpu_dm.c static int add_affected_mst_dsc_crtcs(struct drm_atomic_commit *state, struct dr

Quoted 4 lines
drivers/gpu/drm/amd/display/amdgpu_dm/amdgpu_dm.c +0 -4
-		    plane->type == DRM_PLANE_TYPE_CURSOR)
-			continue;
-
-		/* Underlying plane is YUV format - use overlay cursor 

*/

drivers/gpu/drm/amd/display/amdgpu_dm/amdgpu_dm.c static int add_affected_mst_dsc_crtcs(struct drm_atomic_commit *state, struct dr

Quoted 7 lines
drivers/gpu/drm/amd/display/amdgpu_dm/amdgpu_dm.c +0 -1
-		if (amdgpu_dm_plane_is_video_format(plane_state->fb-

format->format)) {

drivers/gpu/drm/amd/display/amdgpu_dm/amdgpu_dm.c +0 -5
-			*cursor_mode = DM_CURSOR_OVERLAY_MODE;
-			return 0;
-		}
-
-		/* Underlying plane has an active color pipeline - 

cursor would be

Quoted 1 line

transformed */ - if (dm_plane_color_pipeline_active(state,

plane, false))

drivers/gpu/drm/amd/display/amdgpu_dm/amdgpu_dm.c static int add_affected_mst_dsc_crtcs(struct drm_atomic_commit *state, struct dr

Quoted 7 lines

{

drivers/gpu/drm/amd/display/amdgpu_dm/amdgpu_dm.c +0 -6
-			*cursor_mode = DM_CURSOR_OVERLAY_MODE;
-			return 0;
-		}
-
-		dm_get_plane_scale(plane_state,
-				   &underlying_scale_w, 

&underlying_scale_h);

drivers/gpu/drm/amd/display/amdgpu_dm/amdgpu_dm.c

Quoted 2 lines
drivers/gpu/drm/amd/display/amdgpu_dm/amdgpu_dm.c +0 -2
-		dm_get_plane_scale(cursor_state,
-				   &cursor_scale_w, 

&cursor_scale_h);

drivers/gpu/drm/amd/display/amdgpu_dm/amdgpu_dm.c

Quoted 2 lines
drivers/gpu/drm/amd/display/amdgpu_dm/amdgpu_dm.c +0 -2
-
-		/* Underlying plane has different scale - use overlay 

cursor */

drivers/gpu/drm/amd/display/amdgpu_dm/amdgpu_dm.c static int add_affected_mst_dsc_crtcs(struct drm_atomic_commit *state, struct dr

Quoted 7 lines
drivers/gpu/drm/amd/display/amdgpu_dm/amdgpu_dm.c +0 -7
-		if (cursor_scale_w != underlying_scale_w &&
-		    cursor_scale_h != underlying_scale_h) {
-			*cursor_mode = DM_CURSOR_OVERLAY_MODE;
-			return 0;
-		}
-
-		/* If this plane covers the whole CRTC, no need to 

check planes

Quoted 1 line

underneath */ - if (plane_state->crtc_x <= 0 &&

plane_state->crtc_y <= 0

Quoted 4 lines

&&

drivers/gpu/drm/amd/display/amdgpu_dm/amdgpu_dm.c +0 -1
-		    plane_state->crtc_x + plane_state->crtc_w >=

crtc_state->mode.hdisplay && - plane_state->crtc_y +
plane_state->crtc_h >= crtc_state->mode.vdisplay) { -

entire_crtc_covered

drivers/gpu/drm/amd/display/amdgpu_dm/amdgpu_dm.c static bool should_reset_plane(struct drm_atomic_commit *state,

Quoted 6 lines

= true;

drivers/gpu/drm/amd/display/amdgpu_dm/amdgpu_dm.c +0 -5
-			break;
-		}
-	}
-
-	/* If planes do not cover the entire CRTC, use overlay mode to 

enable

drivers/gpu/drm/amd/display/amdgpu_dm/amdgpu_dm.c static int add_affected_mst_dsc_crtcs(struct drm_atomic_commit *state, struct dr

Quoted 12 lines
drivers/gpu/drm/amd/display/amdgpu_dm/amdgpu_dm.c +0 -10
-	 * cursor over holes
-	 */
-	if (entire_crtc_covered)
-		*cursor_mode = DM_CURSOR_NATIVE_MODE;
-	else
-		*cursor_mode = DM_CURSOR_OVERLAY_MODE;
-
-	return 0;
-}
-
 static bool amdgpu_dm_crtc_mem_type_changed(struct drm_device *dev,
 					    struct 

drm_atomic_commit *state,

Quoted 1 line

struct

drm_crtc_state *crtc_state)

drivers/gpu/drm/amd/display/amdgpu_dm/amdgpu_dm.c static int amdgpu_dm_atomic_check(struct drm_device · line 6622

Quoted 5 lines
drivers/gpu/drm/amd/display/amdgpu_dm/amdgpu_dm.c +0 -1
@@ -6619,8 +6211,8 @@ static int amdgpu_dm_atomic_check(struct drm_device
 *dev, for_each_new_crtc_in_state(state, crtc, new_crtc_state, i) {
 		dm_new_crtc_state = to_dm_crtc_state(new_crtc_state);
 
-		ret = dm_crtc_get_cursor_mode(adev, state, 

dm_new_crtc_state,

drivers/gpu/drm/amd/display/amdgpu_dm/amdgpu_dm.c static int amdgpu_dm_atomic_check(struct drm_device · line 6623

Quoted 1 line
drivers/gpu/drm/amd/display/amdgpu_dm/amdgpu_dm.c +0 -1
-					      

&dm_new_crtc_state->cursor_mode);

drivers/gpu/drm/amd/display/amdgpu_dm/amdgpu_dm.c static int amdgpu_dm_atomic_check(struct drm_device · line 6214

Quoted 1 line
drivers/gpu/drm/amd/display/amdgpu_dm/amdgpu_dm.c +1 -0
+		ret = amdgpu_dm_crtc_get_cursor_mode(adev, state, 

dm_new_crtc_state,

drivers/gpu/drm/amd/display/amdgpu_dm/amdgpu_dm.c static int amdgpu_dm_atomic_check(struct drm_device · line 6215

Quoted 1 line
drivers/gpu/drm/amd/display/amdgpu_dm/amdgpu_dm.c +1 -0
+						     

&dm_new_crtc_state->cursor_mode);

drivers/gpu/drm/amd/display/amdgpu_dm/amdgpu_dm.c static int amdgpu_dm_atomic_check(struct drm_device · line 6217

Quoted 2 lines
drivers/gpu/drm/amd/display/amdgpu_dm/amdgpu_dm.c +0 -0
 		if (ret) {
 			drm_dbg(dev, "Failed to determine cursor 

mode: %pe\n", ERR_PTR(ret));

drivers/gpu/drm/amd/display/amdgpu_dm/amdgpu_dm.c static int amdgpu_dm_atomic_check(struct drm_device · line 6348

Quoted 5 lines
drivers/gpu/drm/amd/display/amdgpu_dm/amdgpu_dm.c +0 -0
 			goto fail;
@@ -6754,8 +6346,8 @@ static int amdgpu_dm_atomic_check(struct drm_device
 *dev, }
 
 		/* If HW can only do native cursor, check restrictions 

again */

drivers/gpu/drm/amd/display/amdgpu_dm/amdgpu_dm.c static int amdgpu_dm_atomic_check(struct drm_device · line 6757

Quoted 1 line
drivers/gpu/drm/amd/display/amdgpu_dm/amdgpu_dm.c +0 -1
-		ret = dm_crtc_get_cursor_mode(adev, state, 

dm_new_crtc_state,

drivers/gpu/drm/amd/display/amdgpu_dm/amdgpu_dm.c static int amdgpu_dm_atomic_check(struct drm_device · line 6758

Quoted 1 line
drivers/gpu/drm/amd/display/amdgpu_dm/amdgpu_dm.c +0 -1
-					      

&required_cursor_mode);

drivers/gpu/drm/amd/display/amdgpu_dm/amdgpu_dm.c static int amdgpu_dm_atomic_check(struct drm_device · line 6349

Quoted 1 line
drivers/gpu/drm/amd/display/amdgpu_dm/amdgpu_dm.c +1 -0
+		ret = amdgpu_dm_crtc_get_cursor_mode(adev, state, 

dm_new_crtc_state,

drivers/gpu/drm/amd/display/amdgpu_dm/amdgpu_dm.c static int amdgpu_dm_atomic_check(struct drm_device · line 6350

Quoted 1 line
drivers/gpu/drm/amd/display/amdgpu_dm/amdgpu_dm.c +1 -0
+						     

&required_cursor_mode);

drivers/gpu/drm/amd/display/amdgpu_dm/amdgpu_dm.c static int amdgpu_dm_atomic_check(struct drm_device *dev,

Quoted 3 lines
drivers/gpu/drm/amd/display/amdgpu_dm/amdgpu_dm.c +0 -0
 		if (ret) {
 			drm_dbg_driver(crtc->dev,
 				       "[CRTC:%d:%s] Checking 

cursor mode failed\n",

drivers/gpu/drm/amd/display/amdgpu_dm/amdgpu_dm.h void amdgpu_dm_emulated_link_detect(struct dc_link · line 1145

Quoted 11 lines
(quoted diff) +0 -0

b/drivers/gpu/drm/amd/display/amdgpu_dm/amdgpu_dm.h index 1ef92a28e3e9..1ddf5bc88a03 100644

drivers/gpu/drm/amd/display/amdgpu_dm/amdgpu_dm.h +1 -0
@@ -1141,6 +1141,22 @@ void amdgpu_dm_emulated_link_detect(struct dc_link
 *link); void amdgpu_dm_apply_delay_after_dpcd_poweroff(struct amdgpu_device
 *adev, struct dc_sink *sink);
 
+struct __drm_planes_state *amdgpu_dm_get_next_zpos(struct drm_atomic_commit
 *state, +						   struct 

__drm_planes_state *prev);

Quoted 10 lines
drivers/gpu/drm/amd/display/amdgpu_dm/amdgpu_dm.h +3 -0
+
+/*
+ * Use the uniqueness of the plane's (zpos, drm obj ID) combination to

iterate + * by descending zpos, as read from the new plane state. This is the same + * ordering as defined by drm_atomic_normalize_zpos().
+ */
+#define for_each_oldnew_plane_in_descending_zpos(__state, plane,
old_plane_state, new_plane_state) \ + for (struct __drm_planes_state *__i =
amdgpu_dm_get_next_zpos((__state), NULL); \ + __i != NULL; __i =
amdgpu_dm_get_next_zpos((__state), __i)) \ +

for_each_if(((plane) =

drivers/gpu/drm/amd/display/amdgpu_dm/amdgpu_dm.h

Quoted 2 lines

__i->ptr, \

drivers/gpu/drm/amd/display/amdgpu_dm/amdgpu_dm.h +1 -0
+			     (void)(plane) /* Only to avoid unused-

but-set-variable warning */,

Quoted 1 line

\ + (old_plane_state) = __i->old_state,

\

drivers/gpu/drm/amd/display/amdgpu_dm/amdgpu_dm.h int dm_crtc_get_scanoutpos(struct amdgpu_device *adev, int crtc,

Quoted 12 lines
drivers/gpu/drm/amd/display/amdgpu_dm/amdgpu_dm.h +2 -0
+			     (new_plane_state) = __i->new_state, 1))
+
 #if IS_ENABLED(CONFIG_DRM_AMD_DC_KUNIT_TEST)
 struct amdgpu_ip_block;
 bool dm_is_idle(struct amdgpu_ip_block *ip_block);
@@ -1157,19 +1173,11 @@ int dm_crtc_get_scanoutpos(struct amdgpu_device
 *adev, int crtc, struct dm_atomic_state *dm_atomic_get_new_state(struct

drm_atomic_commit *state); void dm_atomic_destroy_state(struct drm_private_obj *obj,

drivers/gpu/drm/amd/display/amdgpu_dm/amdgpu_dm.h +0 -2
 			     struct drm_private_state *state);
-bool dm_should_update_native_cursor(struct drm_atomic_commit *state,
-				    struct drm_crtc 

*old_plane_crtc,

drivers/gpu/drm/amd/display/amdgpu_dm/amdgpu_dm.h

Quoted 1 line
drivers/gpu/drm/amd/display/amdgpu_dm/amdgpu_dm.h +0 -1
-				    struct drm_crtc 

*new_plane_crtc,

drivers/gpu/drm/amd/display/amdgpu_dm/amdgpu_dm.h int dm_crtc_get_scanoutpos(struct amdgpu_device *adev, int crtc,

Quoted 4 lines
drivers/gpu/drm/amd/display/amdgpu_dm/amdgpu_dm.h +0 -1
-				    bool enable);
 int dm_plane_layer_index_cmp(const void *a, const void *b);
 int fill_plane_color_attributes(const struct drm_plane_state *plane_state,
 				const enum surface_pixel_format 

format,

Quoted 1 line

enum dc_color_space

*color_space);

drivers/gpu/drm/amd/display/amdgpu_dm/amdgpu_dm.h int dm_crtc_get_scanoutpos(struct amdgpu_device *adev, int crtc,

Quoted 5 lines

bool modereset_required(struct drm_crtc_state *crtc_state);

drivers/gpu/drm/amd/display/amdgpu_dm/amdgpu_dm.h +0 -4
-void dm_get_oriented_plane_size(struct drm_plane_state *plane_state,
-				int *src_w, int *src_h);
-void dm_get_plane_scale(struct drm_plane_state *plane_state,
-			int *out_plane_scale_w, int 

*out_plane_scale_h);

Quoted 2 lines

bool is_scaling_state_different(const struct dm_connector_state *dm_state,
const struct dm_connector_state

*old_dm_state);

Quoted 43 lines

void set_multisync_trigger_params(struct dc_stream_state *stream);

(quoted diff) +0 -0

b/drivers/gpu/drm/amd/display/amdgpu_dm/amdgpu_dm_cursor.c new file mode 100644
index 000000000000..ab50d58896ab

drivers/gpu/drm/amd/display/amdgpu_dm/amdgpu_dm_cursor.c new file +6 -0
@@ -0,0 +1,443 @@
+// SPDX-License-Identifier: MIT
+/*
+ * Copyright 2026 Advanced Micro Devices, Inc.
+ *
+ * Permission is hereby granted, free of charge, to any person obtaining a
+ * copy of this software and associated documentation files (the

"Software"), + * to deal in the Software without restriction, including without limitation + * the rights to use, copy, modify, merge, publish, distribute, sublicense, + * and/or sell copies of the Software, and to permit persons to whom the + * Software is furnished to do so, subject to the following conditions: + *
+ * The above copyright notice and this permission notice shall be included in + * all copies or substantial portions of the Software.
+ *
+ * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR + * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, + * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL + * THE COPYRIGHT HOLDER(S) OR AUTHOR(S) BE LIABLE FOR ANY CLAIM, DAMAGES OR + * OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, + * ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR + * OTHER DEALINGS IN THE SOFTWARE.
+ *
+ * Authors: AMD
+ *
+ */

drivers/gpu/drm/amd/display/amdgpu_dm/amdgpu_dm_cursor.c new file +10 -0
+
+#include <drm/drm_atomic.h>
+#include <drm/drm_atomic_helper.h>
+#include <drm/drm_blend.h>
+#include <drm/drm_fourcc.h>
+#include <drm/drm_framebuffer.h>
+#include <drm/drm_plane.h>
+#include <drm/drm_colorop.h>
+
+#include "dc.h"

drivers/gpu/drm/amd/display/amdgpu_dm/amdgpu_dm_cursor.c

Quoted 10 lines
drivers/gpu/drm/amd/display/amdgpu_dm/amdgpu_dm_cursor.c new file +10 -0
+#include "dal_asic_id.h"
+#include "amdgpu.h"
+#include "amdgpu_display.h"
+#include "amdgpu_dm.h"
+#include "amdgpu_dm_plane.h"
+#include "amdgpu_dm_cursor.h"
+#include "dm_helpers.h"
+
+static int dm_check_cursor_fb(struct amdgpu_crtc *new_acrtc,
+			      struct drm_plane_state 

*new_plane_state,

drivers/gpu/drm/amd/display/amdgpu_dm/amdgpu_dm_cursor.c

Quoted 10 lines
drivers/gpu/drm/amd/display/amdgpu_dm/amdgpu_dm_cursor.c new file +10 -0
+			      struct drm_framebuffer *fb)
+{
+	struct amdgpu_device *adev = drm_to_adev(new_acrtc->base.dev);
+	struct amdgpu_framebuffer *afb = to_amdgpu_framebuffer(fb);
+	unsigned int pitch;
+	bool linear;
+
+	if (fb->width > new_acrtc->max_cursor_width ||
+	    fb->height > new_acrtc->max_cursor_height) {
+		drm_dbg_atomic(adev_to_drm(adev), "Bad cursor FB size 

%dx%d\n",

drivers/gpu/drm/amd/display/amdgpu_dm/amdgpu_dm_cursor.c

Quoted 7 lines
drivers/gpu/drm/amd/display/amdgpu_dm/amdgpu_dm_cursor.c new file +7 -0
+				 new_plane_state->fb->width,
+				 new_plane_state->fb->height);
+		return -EINVAL;
+	}
+	if (new_plane_state->src_w != fb->width << 16 ||
+	    new_plane_state->src_h != fb->height << 16) {
+		drm_dbg_atomic(adev_to_drm(adev), "Cropping not 

supported for cursor

drivers/gpu/drm/amd/display/amdgpu_dm/amdgpu_dm_cursor.c

Quoted 8 lines

plane\n"); + return -EINVAL;

drivers/gpu/drm/amd/display/amdgpu_dm/amdgpu_dm_cursor.c new file +7 -0
+	}
+
+	/* Pitch in pixels */
+	pitch = fb->pitches[0] / fb->format->cpp[0];
+
+	if (fb->width != pitch) {
+		drm_dbg_atomic(adev_to_drm(adev), "Cursor FB width %d 

doesn't match pitch

drivers/gpu/drm/amd/display/amdgpu_dm/amdgpu_dm_cursor.c

Quoted 12 lines

%d", + fb->width, pitch);

drivers/gpu/drm/amd/display/amdgpu_dm/amdgpu_dm_cursor.c new file +11 -0
+		return -EINVAL;
+	}
+
+	switch (pitch) {
+	case 64:
+	case 128:
+	case 256:
+		/* FB pitch is supported by cursor plane */
+		break;
+	default:
+		drm_dbg_atomic(adev_to_drm(adev), "Bad cursor FB pitch 

%d px\n", pitch);

Quoted 4 lines
drivers/gpu/drm/amd/display/amdgpu_dm/amdgpu_dm_cursor.c new file +4 -0
+		return -EINVAL;
+	}
+
+	/* Core DRM takes care of checking FB modifiers, so we only need to

drivers/gpu/drm/amd/display/amdgpu_dm/amdgpu_dm_cursor.c

Quoted 10 lines
drivers/gpu/drm/amd/display/amdgpu_dm/amdgpu_dm_cursor.c new file +10 -0
+	 * check tiling flags when the FB doesn't have a modifier.
+	 */
+	if (!(fb->flags & DRM_MODE_FB_MODIFIERS)) {
+#if defined(CONFIG_DRM_AMD_DC_DCN6_0) || defined(CONFIG_DRM_AMD_DC_DCN5_0)
+		if (adev->family == AMDGPU_FAMILY_GC_12_0_0
+		    || adev->family == AMDGPU_FAMILY_GC_13_0_1) {
+#else
+		if (adev->family == AMDGPU_FAMILY_GC_12_0_0) {
+#endif
+			linear = AMDGPU_TILING_GET(afb->tiling_flags, 

GFX12_SWIZZLE_MODE) == 0;

drivers/gpu/drm/amd/display/amdgpu_dm/amdgpu_dm_cursor.c

Quoted 2 lines
drivers/gpu/drm/amd/display/amdgpu_dm/amdgpu_dm_cursor.c new file +2 -0
+		} else if (adev->family >= AMDGPU_FAMILY_AI) {
+			linear = AMDGPU_TILING_GET(afb->tiling_flags, 

SWIZZLE_MODE) == 0;

drivers/gpu/drm/amd/display/amdgpu_dm/amdgpu_dm_cursor.c

Quoted 2 lines
drivers/gpu/drm/amd/display/amdgpu_dm/amdgpu_dm_cursor.c new file +2 -0
+		} else {
+			linear = AMDGPU_TILING_GET(afb->tiling_flags, 

ARRAY_MODE) !=

Quoted 1 line

DC_ARRAY_2D_TILED_THIN1 && +

AMDGPU_TILING_GET(afb->tiling_flags,

drivers/gpu/drm/amd/display/amdgpu_dm/amdgpu_dm_cursor.c

Quoted 5 lines

ARRAY_MODE) != DC_ARRAY_1D_TILED_THIN1 && + AMDGPU_TILING_GET(afb->tiling_flags, MICRO_TILE_MODE) == 0;

drivers/gpu/drm/amd/display/amdgpu_dm/amdgpu_dm_cursor.c new file +3 -0
+		}
+		if (!linear) {
+			drm_dbg_atomic(adev_to_drm(adev), "Cursor FB 

not linear");

drivers/gpu/drm/amd/display/amdgpu_dm/amdgpu_dm_cursor.c

Quoted 12 lines
drivers/gpu/drm/amd/display/amdgpu_dm/amdgpu_dm_cursor.c new file +12 -0
+			return -EINVAL;
+		}
+	}
+
+	return 0;
+}
+
+/*
+ * Helper function for checking the cursor in native mode
+ */
+int amdgpu_dm_check_native_cursor_state(struct drm_crtc *new_plane_crtc,
+					struct drm_plane 

*plane,

drivers/gpu/drm/amd/display/amdgpu_dm/amdgpu_dm_cursor.c

Quoted 1 line
drivers/gpu/drm/amd/display/amdgpu_dm/amdgpu_dm_cursor.c new file +1 -0
+					struct drm_plane_state 

*new_plane_state,

Quoted 4 lines
drivers/gpu/drm/amd/display/amdgpu_dm/amdgpu_dm_cursor.c new file +4 -0
+					bool enable)
+{
+
+	struct amdgpu_crtc *new_acrtc;

drivers/gpu/drm/amd/display/amdgpu_dm/amdgpu_dm_cursor.c

Quoted 10 lines
drivers/gpu/drm/amd/display/amdgpu_dm/amdgpu_dm_cursor.c new file +10 -0
+	int ret;
+
+	if (!enable || !new_plane_crtc ||
+	    drm_atomic_plane_disabling(plane->state, new_plane_state))
+		return 0;
+
+	new_acrtc = to_amdgpu_crtc(new_plane_crtc);
+
+	if (new_plane_state->src_x != 0 || new_plane_state->src_y != 0) {
+		drm_dbg_atomic(new_plane_crtc->dev, "Cropping not 

supported for cursor

drivers/gpu/drm/amd/display/amdgpu_dm/amdgpu_dm_cursor.c line 142

Quoted 6 lines

plane\n"); + return -EINVAL;

drivers/gpu/drm/amd/display/amdgpu_dm/amdgpu_dm_cursor.c new file +5 -0
+	}
+
+	if (new_plane_state->fb) {
+		ret = dm_check_cursor_fb(new_acrtc, new_plane_state,
+						

new_plane_state->fb);

drivers/gpu/drm/amd/display/amdgpu_dm/amdgpu_dm_cursor.c

Quoted 9 lines
drivers/gpu/drm/amd/display/amdgpu_dm/amdgpu_dm_cursor.c new file +9 -0
+		if (ret)
+			return ret;
+	}
+
+	return 0;
+}
+
+bool amdgpu_dm_should_update_native_cursor(struct drm_atomic_commit *state,
+					   struct drm_crtc 

*old_plane_crtc,

drivers/gpu/drm/amd/display/amdgpu_dm/amdgpu_dm_cursor.c

Quoted 1 line
drivers/gpu/drm/amd/display/amdgpu_dm/amdgpu_dm_cursor.c new file +1 -0
+					   struct drm_crtc 

*new_plane_crtc,

Quoted 4 lines
drivers/gpu/drm/amd/display/amdgpu_dm/amdgpu_dm_cursor.c new file +4 -0
+					   bool enable)
+{
+	struct drm_crtc_state *old_crtc_state, *new_crtc_state;
+	struct dm_crtc_state *dm_old_crtc_state, *dm_new_crtc_state;

drivers/gpu/drm/amd/display/amdgpu_dm/amdgpu_dm_cursor.c

Quoted 10 lines
drivers/gpu/drm/amd/display/amdgpu_dm/amdgpu_dm_cursor.c new file +10 -0
+
+	if (!enable) {
+		if (old_plane_crtc == NULL)
+			return true;
+
+		old_crtc_state = drm_atomic_get_old_crtc_state(
+			state, old_plane_crtc);
+		dm_old_crtc_state = to_dm_crtc_state(old_crtc_state);
+
+		return dm_old_crtc_state->cursor_mode == 

DM_CURSOR_NATIVE_MODE;

Quoted 14 lines
drivers/gpu/drm/amd/display/amdgpu_dm/amdgpu_dm_cursor.c new file +14 -0
+	}
+
+	if (new_plane_crtc == NULL)
+		return true;
+
+	new_crtc_state = drm_atomic_get_new_crtc_state(
+		state, new_plane_crtc);
+	dm_new_crtc_state = to_dm_crtc_state(new_crtc_state);
+
+	return dm_new_crtc_state->cursor_mode == DM_CURSOR_NATIVE_MODE;
+}
+EXPORT_IF_KUNIT(amdgpu_dm_should_update_native_cursor);
+
+STATIC_IFN_KUNIT void dm_get_oriented_plane_size(struct drm_plane_state
Quoted 1 line

*plane_state, + int

*src_w, int *src_h)

Quoted 14 lines
drivers/gpu/drm/amd/display/amdgpu_dm/amdgpu_dm_cursor.c new file +14 -0
+{
+	switch (plane_state->rotation & DRM_MODE_ROTATE_MASK) {
+	case DRM_MODE_ROTATE_90:
+	case DRM_MODE_ROTATE_270:
+		*src_w = plane_state->src_h >> 16;
+		*src_h = plane_state->src_w >> 16;
+		break;
+	case DRM_MODE_ROTATE_0:
+	case DRM_MODE_ROTATE_180:
+	default:
+		*src_w = plane_state->src_w >> 16;
+		*src_h = plane_state->src_h >> 16;
+		break;
+	}

drivers/gpu/drm/amd/display/amdgpu_dm/amdgpu_dm_cursor.c

Quoted 10 lines
drivers/gpu/drm/amd/display/amdgpu_dm/amdgpu_dm_cursor.c new file +10 -0
+}
+EXPORT_IF_KUNIT(dm_get_oriented_plane_size);
+
+STATIC_IFN_KUNIT void
+dm_get_plane_scale(struct drm_plane_state *plane_state,
+		   int *out_plane_scale_w, int *out_plane_scale_h)
+{
+	int plane_src_w, plane_src_h;
+
+	dm_get_oriented_plane_size(plane_state, &plane_src_w, 

&plane_src_h);

Quoted 35 lines
drivers/gpu/drm/amd/display/amdgpu_dm/amdgpu_dm_cursor.c new file +1 -0
+	*out_plane_scale_w = plane_src_w ? plane_state->crtc_w * 1000 /

plane_src_w : 0; + *out_plane_scale_h = plane_src_h ? plane_state-
crtc_h *
1000 / plane_src_h : 0; +}

drivers/gpu/drm/amd/display/amdgpu_dm/amdgpu_dm_cursor.c new file +6 -0
+EXPORT_IF_KUNIT(dm_get_plane_scale);
+
+/**
+ * DOC: Cursor Modes - Native vs Overlay
+ *
+ * In native mode, the cursor uses a integrated cursor pipe within each DCN

hw + * plane. It does not require a dedicated hw plane to enable, but it is
+ * subjected to the same z-order and scaling as the hw plane. It also has format + * restrictions, a RGB cursor in native mode cannot be enabled within a non-RGB + * hw plane.
+ *
+ * In overlay mode, the cursor uses a separate DCN hw plane, and thus has its + * own scaling and z-pos. It also has no blending restrictions. It lends to a + * cursor behavior more akin to a DRM client's expectations. However, it does + * occupy an extra DCN plane, and therefore will only be used if a DCN plane is + * available.
+ */

drivers/gpu/drm/amd/display/amdgpu_dm/amdgpu_dm_cursor.c new file +3 -0
+
+/**
+ * dm_plane_color_pipeline_active() - Check if a plane's color pipeline

active. + * @state: DRM atomic state
+ * @plane: DRM plane to check
+ * @use_old: if true, inspect the old colorop states; otherwise the new ones + *
+ * A color pipeline may be selected (color_pipeline != NULL) but still is
+ * inactive if every colorop in the chain is bypassed. Only return
+ * true when at least one colorop has bypass == false, meaning the cursor
+ * would be subjected to the transformation in native mode.
+ *
+ * Return: true if the pipeline modifies pixels, false otherwise.
+ */

drivers/gpu/drm/amd/display/amdgpu_dm/amdgpu_dm_cursor.c

Quoted 2 lines
drivers/gpu/drm/amd/display/amdgpu_dm/amdgpu_dm_cursor.c new file +2 -0
+static bool dm_plane_color_pipeline_active(struct drm_atomic_commit *state,
+					   struct drm_plane 

*plane,

Quoted 8 lines
drivers/gpu/drm/amd/display/amdgpu_dm/amdgpu_dm_cursor.c new file +7 -0
+					   bool use_old)
+{
+	struct drm_colorop *colorop;
+	struct drm_colorop_state *old_colorop_state, *new_colorop_state;
+	int i;
+
+	for_each_oldnew_colorop_in_state(state, colorop, old_colorop_state,

new_colorop_state, i) { + struct drm_colorop_state *cstate =

use_old ?

Quoted 29 lines

old_colorop_state : new_colorop_state; +

drivers/gpu/drm/amd/display/amdgpu_dm/amdgpu_dm_cursor.c new file +10 -0
+		if (cstate->colorop->plane != plane)
+			continue;
+		if (!cstate->bypass)
+			return true;
+	}
+	return false;
+}
+
+/**
+ * amdgpu_dm_crtc_get_cursor_mode() - Determine the required cursor mode on

crtc + * @adev: amdgpu device
+ * @state: DRM atomic state
+ * @dm_crtc_state: amdgpu state for the CRTC containing the cursor
+ * @cursor_mode: Returns the required cursor mode on dm_crtc_state
+ *
+ * Get whether the cursor should be enabled in native mode, or overlay mode, on + * the dm_crtc_state.
+ *
+ * The cursor should be enabled in overlay mode if there exists an underlying + * plane - on which the cursor may be blended - that is either YUV formatted, + * scaled differently from the cursor, or has a color pipeline active. + *
+ * Since zpos info is required, drm_atomic_normalize_zpos must be called before + * calling this function.
+ *
+ * Return: 0 on success, or an error code if getting the cursor plane state
+ * failed.
+ */

drivers/gpu/drm/amd/display/amdgpu_dm/amdgpu_dm_cursor.c

Quoted 2 lines
drivers/gpu/drm/amd/display/amdgpu_dm/amdgpu_dm_cursor.c new file +2 -0
+int amdgpu_dm_crtc_get_cursor_mode(struct amdgpu_device *adev,
+				   struct drm_atomic_commit 

*state,

drivers/gpu/drm/amd/display/amdgpu_dm/amdgpu_dm_cursor.c

Quoted 1 line
drivers/gpu/drm/amd/display/amdgpu_dm/amdgpu_dm_cursor.c new file +1 -0
+				   struct dm_crtc_state 

*dm_crtc_state,

drivers/gpu/drm/amd/display/amdgpu_dm/amdgpu_dm_cursor.c

Quoted 1 line
drivers/gpu/drm/amd/display/amdgpu_dm/amdgpu_dm_cursor.c new file +1 -0
+				   enum amdgpu_dm_cursor_mode 

*cursor_mode)

drivers/gpu/drm/amd/display/amdgpu_dm/amdgpu_dm_cursor.c

Quoted 2 lines
drivers/gpu/drm/amd/display/amdgpu_dm/amdgpu_dm_cursor.c new file +2 -0
+{
+	struct drm_plane_state *old_plane_state, *plane_state, 

*cursor_state;

Quoted 20 lines
drivers/gpu/drm/amd/display/amdgpu_dm/amdgpu_dm_cursor.c new file +11 -0
+	struct drm_crtc_state *crtc_state = &dm_crtc_state->base;
+	struct drm_plane *plane;
+	bool consider_mode_change = false;
+	bool entire_crtc_covered = false;
+	bool cursor_changed = false;
+	int underlying_scale_w, underlying_scale_h;
+	int cursor_scale_w, cursor_scale_h;
+	int i;
+
+	/* Overlay cursor not supported on HW before DCN
+	 * DCN401/420 does not have the cursor-on-scaled-plane or

cursor-on-yuv-plane restrictions + * as previous DCN generations, so
enable native mode on DCN401/420 + */

drivers/gpu/drm/amd/display/amdgpu_dm/amdgpu_dm_cursor.c new file +7 -0
+	if (amdgpu_ip_version(adev, DCE_HWIP, 0) == IP_VERSION(4, 0, 1) ||
+	    amdgpu_ip_version(adev, DCE_HWIP, 0) == IP_VERSION(4, 2, 0) ||
+#if defined(CONFIG_DRM_AMD_DC_DCN6_0)
+	    amdgpu_ip_version(adev, DCE_HWIP, 0) == IP_VERSION(4, 2, 1) ||
+	    amdgpu_ip_version(adev, DCE_HWIP, 0) == IP_VERSION(6, 0, 0)) {
+#else
+	    amdgpu_ip_version(adev, DCE_HWIP, 0) == IP_VERSION(4, 2, 1)) {

drivers/gpu/drm/amd/display/amdgpu_dm/amdgpu_dm_cursor.c

Quoted 10 lines
drivers/gpu/drm/amd/display/amdgpu_dm/amdgpu_dm_cursor.c new file +10 -0
+#endif
+		*cursor_mode = DM_CURSOR_NATIVE_MODE;
+		return 0;
+	}
+
+	/* Init cursor_mode to be the same as current */
+	*cursor_mode = dm_crtc_state->cursor_mode;
+
+	/*
+	 * Cursor mode can change if a plane's format changes, scale 

changes, is

drivers/gpu/drm/amd/display/amdgpu_dm/amdgpu_dm_cursor.c

Quoted 1 line
drivers/gpu/drm/amd/display/amdgpu_dm/amdgpu_dm_cursor.c new file +1 -0
+	 * enabled/disabled, z-order changes, or color management 

properties

drivers/gpu/drm/amd/display/amdgpu_dm/amdgpu_dm_cursor.c

Quoted 2 lines

change. + */

drivers/gpu/drm/amd/display/amdgpu_dm/amdgpu_dm_cursor.c new file +1 -0
+	for_each_oldnew_plane_in_state(state, plane, old_plane_state, 

plane_state,

Quoted 1 line

i) { + int new_scale_w, new_scale_h, old_scale_w,

old_scale_h;

drivers/gpu/drm/amd/display/amdgpu_dm/amdgpu_dm_cursor.c

Quoted 3 lines
drivers/gpu/drm/amd/display/amdgpu_dm/amdgpu_dm_cursor.c new file +3 -0
+
+		/* Only care about planes on this CRTC */
+		if ((drm_plane_mask(plane) & crtc_state->plane_mask) == 

0)

drivers/gpu/drm/amd/display/amdgpu_dm/amdgpu_dm_cursor.c

Quoted 6 lines
drivers/gpu/drm/amd/display/amdgpu_dm/amdgpu_dm_cursor.c new file +6 -0
+			continue;
+
+		if (plane->type == DRM_PLANE_TYPE_CURSOR)
+			cursor_changed = true;
+
+		if (drm_atomic_plane_enabling(old_plane_state, 

plane_state) ||

drivers/gpu/drm/amd/display/amdgpu_dm/amdgpu_dm_cursor.c

Quoted 1 line
drivers/gpu/drm/amd/display/amdgpu_dm/amdgpu_dm_cursor.c new file +1 -0
+		    drm_atomic_plane_disabling(old_plane_state, 

plane_state) ||

drivers/gpu/drm/amd/display/amdgpu_dm/amdgpu_dm_cursor.c

Quoted 7 lines
drivers/gpu/drm/amd/display/amdgpu_dm/amdgpu_dm_cursor.c new file +1 -0
+		    old_plane_state->fb->format != plane_state->fb-

format) {

drivers/gpu/drm/amd/display/amdgpu_dm/amdgpu_dm_cursor.c new file +5 -0
+			consider_mode_change = true;
+			break;
+		}
+
+		dm_get_plane_scale(plane_state, &new_scale_w, 

&new_scale_h);

drivers/gpu/drm/amd/display/amdgpu_dm/amdgpu_dm_cursor.c

Quoted 1 line
drivers/gpu/drm/amd/display/amdgpu_dm/amdgpu_dm_cursor.c new file +1 -0
+		dm_get_plane_scale(old_plane_state, &old_scale_w, 

&old_scale_h);

drivers/gpu/drm/amd/display/amdgpu_dm/amdgpu_dm_cursor.c

Quoted 1 line
drivers/gpu/drm/amd/display/amdgpu_dm/amdgpu_dm_cursor.c new file +1 -0
+		if (new_scale_w != old_scale_w || new_scale_h != 

old_scale_h) {

drivers/gpu/drm/amd/display/amdgpu_dm/amdgpu_dm_cursor.c

Quoted 6 lines
drivers/gpu/drm/amd/display/amdgpu_dm/amdgpu_dm_cursor.c new file +6 -0
+			consider_mode_change = true;
+			break;
+		}
+
+		/*
+		 * A non-cursor plane moving or resizing (without a 

scale change)

drivers/gpu/drm/amd/display/amdgpu_dm/amdgpu_dm_cursor.c

Quoted 1 line
drivers/gpu/drm/amd/display/amdgpu_dm/amdgpu_dm_cursor.c new file +1 -0
+		 * changes how much of the CRTC it covers. This can 

create or

drivers/gpu/drm/amd/display/amdgpu_dm/amdgpu_dm_cursor.c

Quoted 1 line
drivers/gpu/drm/amd/display/amdgpu_dm/amdgpu_dm_cursor.c new file +1 -0
+		 * remove a hole under the cursor and thus flip the 

required

drivers/gpu/drm/amd/display/amdgpu_dm/amdgpu_dm_cursor.c

Quoted 1 line
drivers/gpu/drm/amd/display/amdgpu_dm/amdgpu_dm_cursor.c new file +1 -0
+		 * cursor mode (native vs overlay), so its destination 

rect must

drivers/gpu/drm/amd/display/amdgpu_dm/amdgpu_dm_cursor.c

Quoted 3 lines
drivers/gpu/drm/amd/display/amdgpu_dm/amdgpu_dm_cursor.c new file +3 -0
+		 * be re-evaluated too.
+		 *
+		 * The cursor plane itself is deliberately excluded: the 

cursor

drivers/gpu/drm/amd/display/amdgpu_dm/amdgpu_dm_cursor.c

Quoted 1 line
drivers/gpu/drm/amd/display/amdgpu_dm/amdgpu_dm_cursor.c new file +1 -0
+		 * mode depends on the underlying planes' coverage, not 

on the

drivers/gpu/drm/amd/display/amdgpu_dm/amdgpu_dm_cursor.c

Quoted 1 line
drivers/gpu/drm/amd/display/amdgpu_dm/amdgpu_dm_cursor.c new file +1 -0
+		 * cursor's position (see the entire_crtc_covered logic 

below).

drivers/gpu/drm/amd/display/amdgpu_dm/amdgpu_dm_cursor.c

Quoted 1 line
drivers/gpu/drm/amd/display/amdgpu_dm/amdgpu_dm_cursor.c new file +1 -0
+		 * Triggering on cursor movement would force every 

legacy cursor

drivers/gpu/drm/amd/display/amdgpu_dm/amdgpu_dm_cursor.c

Quoted 1 line
drivers/gpu/drm/amd/display/amdgpu_dm/amdgpu_dm_cursor.c new file +1 -0
+		 * update off its fast path, and in a cursor-only commit 

- where

drivers/gpu/drm/amd/display/amdgpu_dm/amdgpu_dm_cursor.c

Quoted 1 line
drivers/gpu/drm/amd/display/amdgpu_dm/amdgpu_dm_cursor.c new file +1 -0
+		 * the underlying planes are not part of the state - the 

coverage

drivers/gpu/drm/amd/display/amdgpu_dm/amdgpu_dm_cursor.c

Quoted 1 line
drivers/gpu/drm/amd/display/amdgpu_dm/amdgpu_dm_cursor.c new file +1 -0
+		 * loop would see no covering plane and misevaluate the 

mode as

drivers/gpu/drm/amd/display/amdgpu_dm/amdgpu_dm_cursor.c

Quoted 12 lines
drivers/gpu/drm/amd/display/amdgpu_dm/amdgpu_dm_cursor.c new file +12 -0
+		 * overlay, regressing flip-vs-cursor-legacy.
+		 */
+		if (plane->type != DRM_PLANE_TYPE_CURSOR &&
+		    (old_plane_state->crtc_x != plane_state->crtc_x ||
+		     old_plane_state->crtc_y != plane_state->crtc_y ||
+		     old_plane_state->crtc_w != plane_state->crtc_w ||
+		     old_plane_state->crtc_h != plane_state->crtc_h)) {
+			consider_mode_change = true;
+			break;
+		}
+
+		if (dm_plane_color_pipeline_active(state, plane, true) !

=

drivers/gpu/drm/amd/display/amdgpu_dm/amdgpu_dm_cursor.c

Quoted 1 line
drivers/gpu/drm/amd/display/amdgpu_dm/amdgpu_dm_cursor.c new file +1 -0
+		    dm_plane_color_pipeline_active(state, plane, false)) 

{

drivers/gpu/drm/amd/display/amdgpu_dm/amdgpu_dm_cursor.c

Quoted 10 lines
drivers/gpu/drm/amd/display/amdgpu_dm/amdgpu_dm_cursor.c new file +10 -0
+			consider_mode_change = true;
+			break;
+		}
+	}
+
+	if (!consider_mode_change && !crtc_state->zpos_changed)
+		return 0;
+
+	/*
+	 * If no cursor change on this CRTC, and not enabled on this CRTC, 

then

drivers/gpu/drm/amd/display/amdgpu_dm/amdgpu_dm_cursor.c

Quoted 1 line
drivers/gpu/drm/amd/display/amdgpu_dm/amdgpu_dm_cursor.c new file +1 -0
+	 * no need to set cursor mode. This avoids needlessly locking the 

cursor

drivers/gpu/drm/amd/display/amdgpu_dm/amdgpu_dm_cursor.c line 386

Quoted 10 lines
drivers/gpu/drm/amd/display/amdgpu_dm/amdgpu_dm_cursor.c new file +4 -0
+	 * state.
+	 */
+	if (!cursor_changed &&
+	    !(drm_plane_mask(crtc_state->crtc->cursor) & crtc_state-

plane_mask))
{ + return 0;

drivers/gpu/drm/amd/display/amdgpu_dm/amdgpu_dm_cursor.c new file +4 -0
+	}
+
+	cursor_state = drm_atomic_get_plane_state(state,
+						  

crtc_state->crtc->cursor);

drivers/gpu/drm/amd/display/amdgpu_dm/amdgpu_dm_cursor.c

Quoted 8 lines
drivers/gpu/drm/amd/display/amdgpu_dm/amdgpu_dm_cursor.c new file +8 -0
+	if (IS_ERR(cursor_state))
+		return PTR_ERR(cursor_state);
+
+	/* Cursor is disabled */
+	if (!cursor_state->fb)
+		return 0;
+
+	/* For all planes in descending z-order (all of which are below 

cursor

drivers/gpu/drm/amd/display/amdgpu_dm/amdgpu_dm_cursor.c

Quoted 3 lines
drivers/gpu/drm/amd/display/amdgpu_dm/amdgpu_dm_cursor.c new file +3 -0
+	 * as per zpos definitions), check their scaling and format
+	 */
+	for_each_oldnew_plane_in_descending_zpos(state, plane, 

old_plane_state,

drivers/gpu/drm/amd/display/amdgpu_dm/amdgpu_dm_cursor.c

Quoted 3 lines

plane_state) { +

drivers/gpu/drm/amd/display/amdgpu_dm/amdgpu_dm_cursor.c new file +2 -0
+		/* Only care about non-cursor planes on this CRTC */
+		if ((drm_plane_mask(plane) & crtc_state->plane_mask) == 

0 ||

drivers/gpu/drm/amd/display/amdgpu_dm/amdgpu_dm_cursor.c

Quoted 4 lines
drivers/gpu/drm/amd/display/amdgpu_dm/amdgpu_dm_cursor.c new file +4 -0
+		    plane->type == DRM_PLANE_TYPE_CURSOR)
+			continue;
+
+		/* Underlying plane is YUV format - use overlay cursor 

*/

drivers/gpu/drm/amd/display/amdgpu_dm/amdgpu_dm_cursor.c

Quoted 7 lines
drivers/gpu/drm/amd/display/amdgpu_dm/amdgpu_dm_cursor.c new file +1 -0
+		if (amdgpu_dm_plane_is_video_format(plane_state->fb-

format->format)) {

drivers/gpu/drm/amd/display/amdgpu_dm/amdgpu_dm_cursor.c new file +5 -0
+			*cursor_mode = DM_CURSOR_OVERLAY_MODE;
+			return 0;
+		}
+
+		/* Underlying plane has an active color pipeline - 

cursor would be

Quoted 1 line

transformed */ + if (dm_plane_color_pipeline_active(state,

plane, false))

drivers/gpu/drm/amd/display/amdgpu_dm/amdgpu_dm_cursor.c

Quoted 7 lines

{

drivers/gpu/drm/amd/display/amdgpu_dm/amdgpu_dm_cursor.c new file +6 -0
+			*cursor_mode = DM_CURSOR_OVERLAY_MODE;
+			return 0;
+		}
+
+		dm_get_plane_scale(plane_state,
+				   &underlying_scale_w, 

&underlying_scale_h);

drivers/gpu/drm/amd/display/amdgpu_dm/amdgpu_dm_cursor.c

Quoted 2 lines
drivers/gpu/drm/amd/display/amdgpu_dm/amdgpu_dm_cursor.c new file +2 -0
+		dm_get_plane_scale(cursor_state,
+				   &cursor_scale_w, 

&cursor_scale_h);

drivers/gpu/drm/amd/display/amdgpu_dm/amdgpu_dm_cursor.c

Quoted 2 lines
drivers/gpu/drm/amd/display/amdgpu_dm/amdgpu_dm_cursor.c new file +2 -0
+
+		/* Underlying plane has different scale - use overlay 

cursor */

drivers/gpu/drm/amd/display/amdgpu_dm/amdgpu_dm_cursor.c

Quoted 7 lines
drivers/gpu/drm/amd/display/amdgpu_dm/amdgpu_dm_cursor.c new file +7 -0
+		if (cursor_scale_w != underlying_scale_w &&
+		    cursor_scale_h != underlying_scale_h) {
+			*cursor_mode = DM_CURSOR_OVERLAY_MODE;
+			return 0;
+		}
+
+		/* If this plane covers the whole CRTC, no need to check 

planes

Quoted 1 line

underneath */ + if (plane_state->crtc_x <= 0 &&

plane_state->crtc_y <= 0

Quoted 4 lines

&&

drivers/gpu/drm/amd/display/amdgpu_dm/amdgpu_dm_cursor.c new file +1 -0
+		    plane_state->crtc_x + plane_state->crtc_w >=

crtc_state->mode.hdisplay && + plane_state->crtc_y +
plane_state->crtc_h >= crtc_state->mode.vdisplay) { +

entire_crtc_covered

drivers/gpu/drm/amd/display/amdgpu_dm/amdgpu_dm_cursor.c

Quoted 6 lines

= true;

drivers/gpu/drm/amd/display/amdgpu_dm/amdgpu_dm_cursor.c new file +5 -0
+			break;
+		}
+	}
+
+	/* If planes do not cover the entire CRTC, use overlay mode to 

enable

Quoted 41 lines
drivers/gpu/drm/amd/display/amdgpu_dm/amdgpu_dm_cursor.c new file +9 -0
+	 * cursor over holes
+	 */
+	if (entire_crtc_covered)
+		*cursor_mode = DM_CURSOR_NATIVE_MODE;
+	else
+		*cursor_mode = DM_CURSOR_OVERLAY_MODE;
+
+	return 0;
+}
(quoted diff) +0 -0

b/drivers/gpu/drm/amd/display/amdgpu_dm/amdgpu_dm_cursor.h new file mode 100644
index 000000000000..5f619e4474aa

drivers/gpu/drm/amd/display/amdgpu_dm/amdgpu_dm_cursor.h new file +6 -0
@@ -0,0 +1,52 @@
+/* SPDX-License-Identifier: MIT */
+/*
+ * Copyright 2026 Advanced Micro Devices, Inc.
+ *
+ * Permission is hereby granted, free of charge, to any person obtaining a
+ * copy of this software and associated documentation files (the

"Software"), + * to deal in the Software without restriction, including without limitation + * the rights to use, copy, modify, merge, publish, distribute, sublicense, + * and/or sell copies of the Software, and to permit persons to whom the + * Software is furnished to do so, subject to the following conditions: + *
+ * The above copyright notice and this permission notice shall be included in + * all copies or substantial portions of the Software.
+ *
+ * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR + * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, + * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL + * THE COPYRIGHT HOLDER(S) OR AUTHOR(S) BE LIABLE FOR ANY CLAIM, DAMAGES OR + * OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, + * ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR + * OTHER DEALINGS IN THE SOFTWARE.
+ *
+ * Authors: AMD
+ *
+ */

drivers/gpu/drm/amd/display/amdgpu_dm/amdgpu_dm_cursor.h

Quoted 6 lines
drivers/gpu/drm/amd/display/amdgpu_dm/amdgpu_dm_cursor.h new file +6 -0
+
+#ifndef __AMDGPU_DM_CURSOR_H__
+#define __AMDGPU_DM_CURSOR_H__
+
+int amdgpu_dm_check_native_cursor_state(struct drm_crtc *new_plane_crtc,
+					struct drm_plane 

*plane,

drivers/gpu/drm/amd/display/amdgpu_dm/amdgpu_dm_cursor.h

Quoted 1 line
drivers/gpu/drm/amd/display/amdgpu_dm/amdgpu_dm_cursor.h new file +1 -0
+					struct drm_plane_state 

*new_plane_state,

drivers/gpu/drm/amd/display/amdgpu_dm/amdgpu_dm_cursor.h

Quoted 4 lines
drivers/gpu/drm/amd/display/amdgpu_dm/amdgpu_dm_cursor.h new file +4 -0
+					bool enable);
+
+bool amdgpu_dm_should_update_native_cursor(struct drm_atomic_commit *state,
+					   struct drm_crtc 

*old_plane_crtc,

drivers/gpu/drm/amd/display/amdgpu_dm/amdgpu_dm_cursor.h

Quoted 1 line
drivers/gpu/drm/amd/display/amdgpu_dm/amdgpu_dm_cursor.h new file +1 -0
+					   struct drm_crtc 

*new_plane_crtc,

drivers/gpu/drm/amd/display/amdgpu_dm/amdgpu_dm_cursor.h

Quoted 4 lines
drivers/gpu/drm/amd/display/amdgpu_dm/amdgpu_dm_cursor.h new file +4 -0
+					   bool enable);
+
+int amdgpu_dm_crtc_get_cursor_mode(struct amdgpu_device *adev,
+				   struct drm_atomic_commit 

*state,

drivers/gpu/drm/amd/display/amdgpu_dm/amdgpu_dm_cursor.h

Quoted 1 line
drivers/gpu/drm/amd/display/amdgpu_dm/amdgpu_dm_cursor.h new file +1 -0
+				   struct dm_crtc_state 

*dm_crtc_state,

drivers/gpu/drm/amd/display/amdgpu_dm/amdgpu_dm_cursor.h

Quoted 1 line
drivers/gpu/drm/amd/display/amdgpu_dm/amdgpu_dm_cursor.h new file +1 -0
+				   enum amdgpu_dm_cursor_mode 

*cursor_mode);

drivers/gpu/drm/amd/display/amdgpu_dm/amdgpu_dm_cursor.h

Quoted 6 lines
drivers/gpu/drm/amd/display/amdgpu_dm/amdgpu_dm_cursor.h new file +6 -0
+
+#if IS_ENABLED(CONFIG_DRM_AMD_DC_KUNIT_TEST)
+void dm_get_oriented_plane_size(struct drm_plane_state *plane_state,
+				int *src_w, int *src_h);
+void dm_get_plane_scale(struct drm_plane_state *plane_state,
+			int *out_plane_scale_w, int 

*out_plane_scale_h);

Quoted 52 lines
drivers/gpu/drm/amd/display/amdgpu_dm/amdgpu_dm_cursor.h new file +3 -0
+#endif /* CONFIG_DRM_AMD_DC_KUNIT_TEST */
+
+#endif /* __AMDGPU_DM_CURSOR_H__ */
(quoted diff) +0 -0

b/drivers/gpu/drm/amd/display/amdgpu_dm/tests/Makefile index e58ffc4dcd84..3a51fccc2a5e 100644

drivers/gpu/drm/amd/display/amdgpu_dm/tests/Makefile +0 -0
@@ -30,6 +30,7 @@ obj-$(CONFIG_DRM_AMD_DC_KUNIT_TEST) +=

amdgpu_dm_mst_types_test.o obj-$(CONFIG_DRM_AMD_DC_KUNIT_TEST) += amdgpu_dm_pp_smu_test.o
obj-$(CONFIG_DRM_AMD_DC_KUNIT_TEST) += amdgpu_dm_test.o obj-$(CONFIG_DRM_AMD_DC_KUNIT_TEST) += amdgpu_dm_freesync_test.o
+obj-$(CONFIG_DRM_AMD_DC_KUNIT_TEST) += amdgpu_dm_cursor_test.o
obj-$(CONFIG_DRM_AMD_DC_KUNIT_TEST) += amdgpu_dm_crtc_test.o obj-$(CONFIG_DRM_AMD_DC_KUNIT_TEST) += amdgpu_dm_services_test.o obj-$(CONFIG_DRM_AMD_DC_KUNIT_TEST) += amdgpu_dm_helpers_test.o
diff --git a/drivers/gpu/drm/amd/display/amdgpu_dm/tests/amdgpu_dm_cursor_test.c b/drivers/gpu/drm/amd/display/amdgpu_dm/tests/amdgpu_dm_cursor_test.c new file mode 100644
index 000000000000..3da76794ece9

drivers/gpu/drm/amd/display/amdgpu_dm/tests/amdgpu_dm_cursor_test.c new file +23 -0
@@ -0,0 +1,268 @@
+// SPDX-License-Identifier: GPL-2.0 OR MIT
+/*
+ * KUnit tests for amdgpu_dm_cursor.c
+ *
+ * Copyright 2026 Advanced Micro Devices, Inc.
+ */
+
+#include <kunit/test.h>
+#include <drm/drm_atomic.h>
+#include <drm/drm_blend.h>
+#include <drm/drm_crtc.h>
+#include <drm/drm_plane.h>
+
+#include "dc.h"
+#include "amdgpu.h"
+#include "amdgpu_mode.h"
+#include "amdgpu_dm.h"
+#include "amdgpu_dm_cursor.h"
+
+/* Tests for amdgpu_dm_should_update_native_cursor() */
+
+/**
+ * dm_test_should_update_native_cursor_without_crtc - Test NULL crtc cases

update native cursor + * @test: The KUnit test context
+ */
+static void dm_test_should_update_native_cursor_without_crtc(struct kunit *test) +{

drivers/gpu/drm/amd/display/amdgpu_dm/tests/amdgpu_dm_cursor_test.c

Quoted 1 line
drivers/gpu/drm/amd/display/amdgpu_dm/tests/amdgpu_dm_cursor_test.c new file +1 -0
+	KUNIT_EXPECT_TRUE(test, amdgpu_dm_should_update_native_cursor(NULL, 

NULL,

Quoted 10 lines

NULL, false)); + KUNIT_EXPECT_TRUE(test,
amdgpu_dm_should_update_native_cursor(NULL, NULL, NULL, true)); +}

drivers/gpu/drm/amd/display/amdgpu_dm/tests/amdgpu_dm_cursor_test.c new file +3 -0
+
+/**
+ * dm_test_should_update_native_cursor_disable_native - Test disable path

reads old crtc cursor mode + * @test: The KUnit test context
+ */
+static void dm_test_should_update_native_cursor_disable_native(struct kunit *test) +{

drivers/gpu/drm/amd/display/amdgpu_dm/tests/amdgpu_dm_cursor_test.c new file +1 -0
+	struct dm_crtc_state *dm_crtc_state;

drivers/gpu/drm/amd/display/amdgpu_dm/tests/amdgpu_dm_cursor_test.c

Quoted 10 lines
drivers/gpu/drm/amd/display/amdgpu_dm/tests/amdgpu_dm_cursor_test.c new file +10 -0
+	struct drm_atomic_commit *state;
+	struct drm_crtc *crtc;
+
+	state = kunit_kzalloc(test, sizeof(*state), GFP_KERNEL);
+	KUNIT_ASSERT_NOT_NULL(test, state);
+
+	crtc = kunit_kzalloc(test, sizeof(*crtc), GFP_KERNEL);
+	KUNIT_ASSERT_NOT_NULL(test, crtc);
+
+	dm_crtc_state = kunit_kzalloc(test, sizeof(*dm_crtc_state), 

GFP_KERNEL);

drivers/gpu/drm/amd/display/amdgpu_dm/tests/amdgpu_dm_cursor_test.c

Quoted 3 lines
drivers/gpu/drm/amd/display/amdgpu_dm/tests/amdgpu_dm_cursor_test.c new file +3 -0
+	KUNIT_ASSERT_NOT_NULL(test, dm_crtc_state);
+
+	state->crtcs = kunit_kzalloc(test, sizeof(*state->crtcs), 

GFP_KERNEL);

drivers/gpu/drm/amd/display/amdgpu_dm/tests/amdgpu_dm_cursor_test.c line 61

Quoted 8 lines
drivers/gpu/drm/amd/display/amdgpu_dm/tests/amdgpu_dm_cursor_test.c new file +8 -0
+	KUNIT_ASSERT_NOT_NULL(test, state->crtcs);
+
+	crtc->index = 0;
+	dm_crtc_state->cursor_mode = DM_CURSOR_NATIVE_MODE;
+	state->crtcs[0].old_state = &dm_crtc_state->base;
+
+	KUNIT_EXPECT_TRUE(test,
+			  

amdgpu_dm_should_update_native_cursor(state, crtc, NULL, false));

Quoted 9 lines
drivers/gpu/drm/amd/display/amdgpu_dm/tests/amdgpu_dm_cursor_test.c new file +4 -0
+}
+
+/**
+ * dm_test_should_update_native_cursor_enable_overlay - Test enable path

reads new crtc cursor mode + * @test: The KUnit test context
+ */
+static void dm_test_should_update_native_cursor_enable_overlay(struct kunit *test) +{

drivers/gpu/drm/amd/display/amdgpu_dm/tests/amdgpu_dm_cursor_test.c new file +1 -0
+	struct dm_crtc_state *dm_crtc_state;

drivers/gpu/drm/amd/display/amdgpu_dm/tests/amdgpu_dm_cursor_test.c

Quoted 10 lines
drivers/gpu/drm/amd/display/amdgpu_dm/tests/amdgpu_dm_cursor_test.c new file +10 -0
+	struct drm_atomic_commit *state;
+	struct drm_crtc *crtc;
+
+	state = kunit_kzalloc(test, sizeof(*state), GFP_KERNEL);
+	KUNIT_ASSERT_NOT_NULL(test, state);
+
+	crtc = kunit_kzalloc(test, sizeof(*crtc), GFP_KERNEL);
+	KUNIT_ASSERT_NOT_NULL(test, crtc);
+
+	dm_crtc_state = kunit_kzalloc(test, sizeof(*dm_crtc_state), 

GFP_KERNEL);

drivers/gpu/drm/amd/display/amdgpu_dm/tests/amdgpu_dm_cursor_test.c

Quoted 3 lines
drivers/gpu/drm/amd/display/amdgpu_dm/tests/amdgpu_dm_cursor_test.c new file +3 -0
+	KUNIT_ASSERT_NOT_NULL(test, dm_crtc_state);
+
+	state->crtcs = kunit_kzalloc(test, sizeof(*state->crtcs), 

GFP_KERNEL);

drivers/gpu/drm/amd/display/amdgpu_dm/tests/amdgpu_dm_cursor_test.c line 91

Quoted 8 lines
drivers/gpu/drm/amd/display/amdgpu_dm/tests/amdgpu_dm_cursor_test.c new file +8 -0
+	KUNIT_ASSERT_NOT_NULL(test, state->crtcs);
+
+	crtc->index = 0;
+	dm_crtc_state->cursor_mode = DM_CURSOR_OVERLAY_MODE;
+	state->crtcs[0].new_state = &dm_crtc_state->base;
+
+	KUNIT_EXPECT_FALSE(test,
+			   

amdgpu_dm_should_update_native_cursor(state, NULL, crtc, true));

Quoted 194 lines
drivers/gpu/drm/amd/display/amdgpu_dm/tests/amdgpu_dm_cursor_test.c new file +26 -0
+}
+
+/* Tests for dm_get_oriented_plane_size() */
+
+/**
+ * dm_test_oriented_plane_size_rotate_0 - Test Oriented plane size rotate 0
+ * @test: The KUnit test context
+ */
+static void dm_test_oriented_plane_size_rotate_0(struct kunit *test)
+{
+	struct drm_plane_state plane_state = { 0 };
+	int src_w = 0;
+	int src_h = 0;
+
+	plane_state.rotation = DRM_MODE_ROTATE_0;
+	plane_state.src_w = 1920 << 16;
+	plane_state.src_h = 1080 << 16;
+
+	dm_get_oriented_plane_size(&plane_state, &src_w, &src_h);
+
+	KUNIT_EXPECT_EQ(test, src_w, 1920);
+	KUNIT_EXPECT_EQ(test, src_h, 1080);
+}
+
+/**
+ * dm_test_oriented_plane_size_rotate_90 - Test Oriented plane size rotate

90 + * @test: The KUnit test context
+ */

drivers/gpu/drm/amd/display/amdgpu_dm/tests/amdgpu_dm_cursor_test.c new file +18 -0
+static void dm_test_oriented_plane_size_rotate_90(struct kunit *test)
+{
+	struct drm_plane_state plane_state = { 0 };
+	int src_w = 0;
+	int src_h = 0;
+
+	plane_state.rotation = DRM_MODE_ROTATE_90;
+	plane_state.src_w = 1920 << 16;
+	plane_state.src_h = 1080 << 16;
+
+	dm_get_oriented_plane_size(&plane_state, &src_w, &src_h);
+
+	KUNIT_EXPECT_EQ(test, src_w, 1080);
+	KUNIT_EXPECT_EQ(test, src_h, 1920);
+}
+
+/**
+ * dm_test_oriented_plane_size_rotate_180 - Test Oriented plane size rotate

180 + * @test: The KUnit test context
+ */

drivers/gpu/drm/amd/display/amdgpu_dm/tests/amdgpu_dm_cursor_test.c new file +18 -0
+static void dm_test_oriented_plane_size_rotate_180(struct kunit *test)
+{
+	struct drm_plane_state plane_state = { 0 };
+	int src_w = 0;
+	int src_h = 0;
+
+	plane_state.rotation = DRM_MODE_ROTATE_180;
+	plane_state.src_w = 1920 << 16;
+	plane_state.src_h = 1080 << 16;
+
+	dm_get_oriented_plane_size(&plane_state, &src_w, &src_h);
+
+	KUNIT_EXPECT_EQ(test, src_w, 1920);
+	KUNIT_EXPECT_EQ(test, src_h, 1080);
+}
+
+/**
+ * dm_test_oriented_plane_size_rotate_270 - Test Oriented plane size rotate

270 + * @test: The KUnit test context
+ */

drivers/gpu/drm/amd/display/amdgpu_dm/tests/amdgpu_dm_cursor_test.c new file +42 -0
+static void dm_test_oriented_plane_size_rotate_270(struct kunit *test)
+{
+	struct drm_plane_state plane_state = { 0 };
+	int src_w = 0;
+	int src_h = 0;
+
+	plane_state.rotation = DRM_MODE_ROTATE_270;
+	plane_state.src_w = 1920 << 16;
+	plane_state.src_h = 1080 << 16;
+
+	dm_get_oriented_plane_size(&plane_state, &src_w, &src_h);
+
+	KUNIT_EXPECT_EQ(test, src_w, 1080);
+	KUNIT_EXPECT_EQ(test, src_h, 1920);
+}
+
+/* Tests for dm_get_plane_scale() */
+
+/**
+ * dm_test_get_plane_scale_identity - Test Get plane scale identity
+ * @test: The KUnit test context
+ */
+static void dm_test_get_plane_scale_identity(struct kunit *test)
+{
+	struct drm_plane_state plane_state = { 0 };
+	int scale_w = 0;
+	int scale_h = 0;
+
+	plane_state.rotation = DRM_MODE_ROTATE_0;
+	plane_state.src_w = 1920 << 16;
+	plane_state.src_h = 1080 << 16;
+	plane_state.crtc_w = 1920;
+	plane_state.crtc_h = 1080;
+
+	dm_get_plane_scale(&plane_state, &scale_w, &scale_h);
+
+	KUNIT_EXPECT_EQ(test, scale_w, 1000);
+	KUNIT_EXPECT_EQ(test, scale_h, 1000);
+}
+
+/**
+ * dm_test_get_plane_scale_rotate_90_identity - Test Get plane scale rotate

90 identity + * @test: The KUnit test context
+ */

drivers/gpu/drm/amd/display/amdgpu_dm/tests/amdgpu_dm_cursor_test.c new file +20 -0
+static void dm_test_get_plane_scale_rotate_90_identity(struct kunit *test)
+{
+	struct drm_plane_state plane_state = { 0 };
+	int scale_w = 0;
+	int scale_h = 0;
+
+	plane_state.rotation = DRM_MODE_ROTATE_90;
+	plane_state.src_w = 1920 << 16;
+	plane_state.src_h = 1080 << 16;
+	plane_state.crtc_w = 1080;
+	plane_state.crtc_h = 1920;
+
+	dm_get_plane_scale(&plane_state, &scale_w, &scale_h);
+
+	KUNIT_EXPECT_EQ(test, scale_w, 1000);
+	KUNIT_EXPECT_EQ(test, scale_h, 1000);
+}
+
+/**
+ * dm_test_get_plane_scale_zero_src_width - Test Get plane scale zero src

width + * @test: The KUnit test context
+ */

drivers/gpu/drm/amd/display/amdgpu_dm/tests/amdgpu_dm_cursor_test.c new file +45 -0
+static void dm_test_get_plane_scale_zero_src_width(struct kunit *test)
+{
+	struct drm_plane_state plane_state = { 0 };
+	int scale_w = 0;
+	int scale_h = 0;
+
+	plane_state.rotation = DRM_MODE_ROTATE_0;
+	plane_state.src_w = 0;
+	plane_state.src_h = 1080 << 16;
+	plane_state.crtc_w = 100;
+	plane_state.crtc_h = 200;
+
+	dm_get_plane_scale(&plane_state, &scale_w, &scale_h);
+
+	KUNIT_EXPECT_EQ(test, scale_w, 0);
+	KUNIT_EXPECT_EQ(test, scale_h, 185);
+}
+
+static struct kunit_case amdgpu_dm_cursor_tests[] = {
+	/* amdgpu_dm_should_update_native_cursor */
+	KUNIT_CASE(dm_test_should_update_native_cursor_without_crtc),
+	KUNIT_CASE(dm_test_should_update_native_cursor_disable_native),
+	KUNIT_CASE(dm_test_should_update_native_cursor_enable_overlay),
+	/* dm_get_oriented_plane_size */
+	KUNIT_CASE(dm_test_oriented_plane_size_rotate_0),
+	KUNIT_CASE(dm_test_oriented_plane_size_rotate_90),
+	KUNIT_CASE(dm_test_oriented_plane_size_rotate_180),
+	KUNIT_CASE(dm_test_oriented_plane_size_rotate_270),
+	/* dm_get_plane_scale */
+	KUNIT_CASE(dm_test_get_plane_scale_identity),
+	KUNIT_CASE(dm_test_get_plane_scale_rotate_90_identity),
+	KUNIT_CASE(dm_test_get_plane_scale_zero_src_width),
+	{}
+};
+
+static struct kunit_suite amdgpu_dm_cursor_test_suite = {
+	.name = "amdgpu_dm_cursor",
+	.test_cases = amdgpu_dm_cursor_tests,
+};
+
+kunit_test_suite(amdgpu_dm_cursor_test_suite);
+
+MODULE_AUTHOR("AMD");
+MODULE_DESCRIPTION("KUnit tests for amdgpu_dm_cursor");
+MODULE_LICENSE("Dual MIT/GPL");
(quoted diff) +0 -0

b/drivers/gpu/drm/amd/display/amdgpu_dm/tests/amdgpu_dm_test.c index 428d24259198..3c10eec9b1e0 100644

drivers/gpu/drm/amd/display/amdgpu_dm/tests/amdgpu_dm_test.c +0 -2
@@ -227,76 +227,6 @@ static void dm_test_atomic_get_new_state_match(struct
 kunit *test) KUNIT_EXPECT_PTR_EQ(test, dm_atomic_get_new_state(state),
 dm_state); }
 
-/**
- * dm_test_should_update_native_cursor_without_crtc - Test NULL crtc cases

update native cursor - * @test: The KUnit test context
- */
-static void dm_test_should_update_native_cursor_without_crtc(struct kunit *test) -{

drivers/gpu/drm/amd/display/amdgpu_dm/tests/amdgpu_dm_test.c

Quoted 1 line
drivers/gpu/drm/amd/display/amdgpu_dm/tests/amdgpu_dm_test.c +0 -1
-	KUNIT_EXPECT_TRUE(test, dm_should_update_native_cursor(NULL, NULL, 

NULL,

Quoted 10 lines

false)); - KUNIT_EXPECT_TRUE(test, dm_should_update_native_cursor(NULL,
NULL, NULL, true)); -}

drivers/gpu/drm/amd/display/amdgpu_dm/tests/amdgpu_dm_test.c +0 -3
-
-/**
- * dm_test_should_update_native_cursor_disable_native - Test disable path

reads old crtc cursor mode - * @test: The KUnit test context
- */
-static void dm_test_should_update_native_cursor_disable_native(struct kunit *test) -{

drivers/gpu/drm/amd/display/amdgpu_dm/tests/amdgpu_dm_test.c +0 -1
-	struct dm_crtc_state *dm_crtc_state;

drivers/gpu/drm/amd/display/amdgpu_dm/tests/amdgpu_dm_test.c static void dm_test_atomic_get_new_state_match(struct kunit *test)

Quoted 10 lines
drivers/gpu/drm/amd/display/amdgpu_dm/tests/amdgpu_dm_test.c +0 -10
-	struct drm_atomic_commit *state;
-	struct drm_crtc *crtc;
-
-	state = kunit_kzalloc(test, sizeof(*state), GFP_KERNEL);
-	KUNIT_ASSERT_NOT_NULL(test, state);
-
-	crtc = kunit_kzalloc(test, sizeof(*crtc), GFP_KERNEL);
-	KUNIT_ASSERT_NOT_NULL(test, crtc);
-
-	dm_crtc_state = kunit_kzalloc(test, sizeof(*dm_crtc_state), 

GFP_KERNEL);

drivers/gpu/drm/amd/display/amdgpu_dm/tests/amdgpu_dm_test.c static void dm_test_atomic_get_new_state_match(struct kunit *test)

Quoted 3 lines
drivers/gpu/drm/amd/display/amdgpu_dm/tests/amdgpu_dm_test.c +0 -3
-	KUNIT_ASSERT_NOT_NULL(test, dm_crtc_state);
-
-	state->crtcs = kunit_kzalloc(test, sizeof(*state->crtcs), 

GFP_KERNEL);

drivers/gpu/drm/amd/display/amdgpu_dm/tests/amdgpu_dm_test.c static void dm_test_atomic_get_new_state_match(struct kunit *test)

Quoted 8 lines
drivers/gpu/drm/amd/display/amdgpu_dm/tests/amdgpu_dm_test.c +0 -8
-	KUNIT_ASSERT_NOT_NULL(test, state->crtcs);
-
-	crtc->index = 0;
-	dm_crtc_state->cursor_mode = DM_CURSOR_NATIVE_MODE;
-	state->crtcs[0].old_state = &dm_crtc_state->base;
-
-	KUNIT_EXPECT_TRUE(test,
-			  dm_should_update_native_cursor(state, 

crtc, NULL, false));

Quoted 9 lines
drivers/gpu/drm/amd/display/amdgpu_dm/tests/amdgpu_dm_test.c +0 -4
-}
-
-/**
- * dm_test_should_update_native_cursor_enable_overlay - Test enable path

reads new crtc cursor mode - * @test: The KUnit test context
- */
-static void dm_test_should_update_native_cursor_enable_overlay(struct kunit *test) -{

drivers/gpu/drm/amd/display/amdgpu_dm/tests/amdgpu_dm_test.c +0 -1
-	struct dm_crtc_state *dm_crtc_state;

drivers/gpu/drm/amd/display/amdgpu_dm/tests/amdgpu_dm_test.c static void dm_test_atomic_get_new_state_match(struct kunit *test)

Quoted 10 lines
drivers/gpu/drm/amd/display/amdgpu_dm/tests/amdgpu_dm_test.c +0 -10
-	struct drm_atomic_commit *state;
-	struct drm_crtc *crtc;
-
-	state = kunit_kzalloc(test, sizeof(*state), GFP_KERNEL);
-	KUNIT_ASSERT_NOT_NULL(test, state);
-
-	crtc = kunit_kzalloc(test, sizeof(*crtc), GFP_KERNEL);
-	KUNIT_ASSERT_NOT_NULL(test, crtc);
-
-	dm_crtc_state = kunit_kzalloc(test, sizeof(*dm_crtc_state), 

GFP_KERNEL);

drivers/gpu/drm/amd/display/amdgpu_dm/tests/amdgpu_dm_test.c static void dm_test_atomic_get_new_state_match(struct kunit *test)

Quoted 3 lines
drivers/gpu/drm/amd/display/amdgpu_dm/tests/amdgpu_dm_test.c +0 -3
-	KUNIT_ASSERT_NOT_NULL(test, dm_crtc_state);
-
-	state->crtcs = kunit_kzalloc(test, sizeof(*state->crtcs), 

GFP_KERNEL);

drivers/gpu/drm/amd/display/amdgpu_dm/tests/amdgpu_dm_test.c static void dm_test_atomic_get_new_state_match(struct kunit *test)

Quoted 8 lines
drivers/gpu/drm/amd/display/amdgpu_dm/tests/amdgpu_dm_test.c +0 -8
-	KUNIT_ASSERT_NOT_NULL(test, state->crtcs);
-
-	crtc->index = 0;
-	dm_crtc_state->cursor_mode = DM_CURSOR_OVERLAY_MODE;
-	state->crtcs[0].new_state = &dm_crtc_state->base;
-
-	KUNIT_EXPECT_FALSE(test,
-			   dm_should_update_native_cursor(state, 

NULL, crtc, true));

Quoted 174 lines
drivers/gpu/drm/amd/display/amdgpu_dm/tests/amdgpu_dm_test.c +0 -2
-}
-
 /**
  * dm_test_atomic_destroy_state_no_context - Test destroying DM atomic

state without a DC context * @test: The KUnit test context

drivers/gpu/drm/amd/display/amdgpu_dm/tests/amdgpu_dm_test.c +0 -0
@@ -599,156 +529,6 @@ static void

dm_test_modereset_not_required_when_inactive_without_modeset(struct KUNIT_EXPECT_FALSE(test, modereset_required(&crtc_state));
}

drivers/gpu/drm/amd/display/amdgpu_dm/tests/amdgpu_dm_test.c +0 -24
-/* Tests for dm_get_oriented_plane_size() */
-
-/**
- * dm_test_oriented_plane_size_rotate_0 - Test Oriented plane size rotate 0
- * @test: The KUnit test context
- */
-static void dm_test_oriented_plane_size_rotate_0(struct kunit *test)
-{
-	struct drm_plane_state plane_state = { 0 };
-	int src_w = 0;
-	int src_h = 0;
-
-	plane_state.rotation = DRM_MODE_ROTATE_0;
-	plane_state.src_w = 1920 << 16;
-	plane_state.src_h = 1080 << 16;
-
-	dm_get_oriented_plane_size(&plane_state, &src_w, &src_h);
-
-	KUNIT_EXPECT_EQ(test, src_w, 1920);
-	KUNIT_EXPECT_EQ(test, src_h, 1080);
-}
-
-/**
- * dm_test_oriented_plane_size_rotate_90 - Test Oriented plane size rotate

90 - * @test: The KUnit test context
- */

drivers/gpu/drm/amd/display/amdgpu_dm/tests/amdgpu_dm_test.c +0 -18
-static void dm_test_oriented_plane_size_rotate_90(struct kunit *test)
-{
-	struct drm_plane_state plane_state = { 0 };
-	int src_w = 0;
-	int src_h = 0;
-
-	plane_state.rotation = DRM_MODE_ROTATE_90;
-	plane_state.src_w = 1920 << 16;
-	plane_state.src_h = 1080 << 16;
-
-	dm_get_oriented_plane_size(&plane_state, &src_w, &src_h);
-
-	KUNIT_EXPECT_EQ(test, src_w, 1080);
-	KUNIT_EXPECT_EQ(test, src_h, 1920);
-}
-
-/**
- * dm_test_oriented_plane_size_rotate_180 - Test Oriented plane size rotate

180 - * @test: The KUnit test context
- */

drivers/gpu/drm/amd/display/amdgpu_dm/tests/amdgpu_dm_test.c +0 -18
-static void dm_test_oriented_plane_size_rotate_180(struct kunit *test)
-{
-	struct drm_plane_state plane_state = { 0 };
-	int src_w = 0;
-	int src_h = 0;
-
-	plane_state.rotation = DRM_MODE_ROTATE_180;
-	plane_state.src_w = 1920 << 16;
-	plane_state.src_h = 1080 << 16;
-
-	dm_get_oriented_plane_size(&plane_state, &src_w, &src_h);
-
-	KUNIT_EXPECT_EQ(test, src_w, 1920);
-	KUNIT_EXPECT_EQ(test, src_h, 1080);
-}
-
-/**
- * dm_test_oriented_plane_size_rotate_270 - Test Oriented plane size rotate

270 - * @test: The KUnit test context
- */

drivers/gpu/drm/amd/display/amdgpu_dm/tests/amdgpu_dm_test.c +0 -42
-static void dm_test_oriented_plane_size_rotate_270(struct kunit *test)
-{
-	struct drm_plane_state plane_state = { 0 };
-	int src_w = 0;
-	int src_h = 0;
-
-	plane_state.rotation = DRM_MODE_ROTATE_270;
-	plane_state.src_w = 1920 << 16;
-	plane_state.src_h = 1080 << 16;
-
-	dm_get_oriented_plane_size(&plane_state, &src_w, &src_h);
-
-	KUNIT_EXPECT_EQ(test, src_w, 1080);
-	KUNIT_EXPECT_EQ(test, src_h, 1920);
-}
-
-/* Tests for dm_get_plane_scale() */
-
-/**
- * dm_test_get_plane_scale_identity - Test Get plane scale identity
- * @test: The KUnit test context
- */
-static void dm_test_get_plane_scale_identity(struct kunit *test)
-{
-	struct drm_plane_state plane_state = { 0 };
-	int scale_w = 0;
-	int scale_h = 0;
-
-	plane_state.rotation = DRM_MODE_ROTATE_0;
-	plane_state.src_w = 1920 << 16;
-	plane_state.src_h = 1080 << 16;
-	plane_state.crtc_w = 1920;
-	plane_state.crtc_h = 1080;
-
-	dm_get_plane_scale(&plane_state, &scale_w, &scale_h);
-
-	KUNIT_EXPECT_EQ(test, scale_w, 1000);
-	KUNIT_EXPECT_EQ(test, scale_h, 1000);
-}
-
-/**
- * dm_test_get_plane_scale_rotate_90_identity - Test Get plane scale rotate

90 identity - * @test: The KUnit test context
- */

drivers/gpu/drm/amd/display/amdgpu_dm/tests/amdgpu_dm_test.c +0 -20
-static void dm_test_get_plane_scale_rotate_90_identity(struct kunit *test)
-{
-	struct drm_plane_state plane_state = { 0 };
-	int scale_w = 0;
-	int scale_h = 0;
-
-	plane_state.rotation = DRM_MODE_ROTATE_90;
-	plane_state.src_w = 1920 << 16;
-	plane_state.src_h = 1080 << 16;
-	plane_state.crtc_w = 1080;
-	plane_state.crtc_h = 1920;
-
-	dm_get_plane_scale(&plane_state, &scale_w, &scale_h);
-
-	KUNIT_EXPECT_EQ(test, scale_w, 1000);
-	KUNIT_EXPECT_EQ(test, scale_h, 1000);
-}
-
-/**
- * dm_test_get_plane_scale_zero_src_width - Test Get plane scale zero src

width - * @test: The KUnit test context
- */

drivers/gpu/drm/amd/display/amdgpu_dm/tests/amdgpu_dm_test.c +0 -21
-static void dm_test_get_plane_scale_zero_src_width(struct kunit *test)
-{
-	struct drm_plane_state plane_state = { 0 };
-	int scale_w = 0;
-	int scale_h = 0;
-
-	plane_state.rotation = DRM_MODE_ROTATE_0;
-	plane_state.src_w = 0;
-	plane_state.src_h = 1080 << 16;
-	plane_state.crtc_w = 100;
-	plane_state.crtc_h = 200;
-
-	dm_get_plane_scale(&plane_state, &scale_w, &scale_h);
-
-	KUNIT_EXPECT_EQ(test, scale_w, 0);
-	KUNIT_EXPECT_EQ(test, scale_h, 185);
-}
-
 /* Tests for is_scaling_state_different() */
 
 /**
@@ -1386,9 +1166,6 @@ static struct kunit_case amdgpu_dm_tests[] = {
 	KUNIT_CASE(dm_test_crtc_get_scanoutpos_no_stream),
 	KUNIT_CASE(dm_test_atomic_get_new_state_empty),
 	KUNIT_CASE(dm_test_atomic_get_new_state_match),
-	KUNIT_CASE(dm_test_should_update_native_cursor_without_crtc),
-	KUNIT_CASE(dm_test_should_update_native_cursor_disable_native),
-	KUNIT_CASE(dm_test_should_update_native_cursor_enable_overlay),
 	KUNIT_CASE(dm_test_atomic_destroy_state_no_context),
 	/* dm_plane_layer_index_cmp */
 	KUNIT_CASE(dm_test_plane_layer_index_cmp_equal),

drivers/gpu/drm/amd/display/amdgpu_dm/tests/amdgpu_dm_test.c static struct kunit_case amdgpu_dm_tests[] = { · line 1185

Quoted 2 lines
drivers/gpu/drm/amd/display/amdgpu_dm/tests/amdgpu_dm_test.c +0 -0
@@ -1407,15 +1184,6 @@ static struct kunit_case amdgpu_dm_tests[] = {
 	KUNIT_CASE(dm_test_modereset_required_when_inactive_and_modeset),
 

KUNIT_CASE(dm_test_modereset_not_required_when_active_and_modeset),

Quoted 1 line

KUNIT_CASE(dm_test_modereset_not_required_when_inactive_without_modeset),

Quoted 12 lines
drivers/gpu/drm/amd/display/amdgpu_dm/tests/amdgpu_dm_test.c +0 -9
-	/* dm_get_oriented_plane_size */
-	KUNIT_CASE(dm_test_oriented_plane_size_rotate_0),
-	KUNIT_CASE(dm_test_oriented_plane_size_rotate_90),
-	KUNIT_CASE(dm_test_oriented_plane_size_rotate_180),
-	KUNIT_CASE(dm_test_oriented_plane_size_rotate_270),
-	/* dm_get_plane_scale */
-	KUNIT_CASE(dm_test_get_plane_scale_identity),
-	KUNIT_CASE(dm_test_get_plane_scale_rotate_90_identity),
-	KUNIT_CASE(dm_test_get_plane_scale_zero_src_width),
 	/* is_scaling_state_different */
 	KUNIT_CASE(dm_test_scaling_state_same),
 	KUNIT_CASE(dm_test_scaling_state_scaling_changed),
#19 lore raw

PATCH 18/49 drm/amd/display: add KUnit tests for audio component get_eld

In reply to Fangzhi Zuo

From: Alex Hung <[email protected]>

[WHAT]
Add KUnit coverage for amdgpu_dm_audio_component_get_eld(), one of the functions reported as untested by gcov.

The tests use the standard DRM KUnit device plus drm_connector_init() to build a real connector list, then invoke the bound audio component get_eld callback. They cover the matching-connector ELD copy path, the writeback-connector skip, and the no-match (disabled) path. A shared connector funcs table and cleanup action back the fixtures.

---
 .../amdgpu_dm/tests/amdgpu_dm_audio_test.c    | 119 ++++++++++++++++++
 1 file changed, 119 insertions(+)
drivers/gpu/drm/amd/display/amdgpu_dm/tests/amdgpu_dm_audio_test.c +119 -0
index 3f0108e9a951..d30b7f644f97 100644
@@ -8,7 +8,12 @@
 #include <kunit/test.h>
 #include <linux/device.h>
 
+#include <drm/drm_atomic_helper.h>
 #include <drm/drm_audio_component.h>
+#include <drm/drm_connector.h>
+#include <drm/drm_eld.h>
+#include <drm/drm_kunit_helpers.h>
+#include <drm/drm_probe_helper.h>
 
 #include "dc.h"
 #include "dc/inc/core_types.h"
@@ -17,6 +22,20 @@
 #include "amdgpu_mode.h"
 #include "amdgpu_dm.h"
 #include "amdgpu_dm_audio.h"
+#include "amdgpu_dm_kunit_test_helpers.h"
+
+static const struct drm_connector_funcs dm_test_audio_connector_funcs = {
+	.reset = drm_atomic_helper_connector_reset,
+	.atomic_duplicate_state = drm_atomic_helper_connector_duplicate_state,
+	.atomic_destroy_state = drm_atomic_helper_connector_destroy_state,
+	.fill_modes = drm_helper_probe_single_connector_modes,
+	.destroy = drm_connector_cleanup,
+};
+
+static void dm_test_audio_connector_cleanup(void *data)
+{
+	drm_connector_cleanup(data);
+}
 
 /* Tests for amdgpu_dm_audio_init() */
 
@@ -569,6 +588,103 @@ static void dm_test_audio_init_pins_zero_count(struct kunit *test)
 
 /* End of tests for amdgpu_dm_audio_init_pins() */
 
+/* Tests for amdgpu_dm_audio_component_get_eld() */
+
+/**
+ * dm_test_audio_component_get_eld_copies_matching_connector - Test ELD lookup
+ * @test: The KUnit test context
+ *
+ * The bound component callback should find the connector whose audio instance
+ * matches the requested port, report it enabled, and copy the connector ELD.
+ */
+static void dm_test_audio_component_get_eld_copies_matching_connector(struct kunit *test)
+{
+	struct amdgpu_device *adev = dm_kunit_alloc_adev(test);
+	struct amdgpu_dm_connector *aconnector;
+	struct drm_connector *wb_connector;
+	struct drm_audio_component *acomp;
+	struct device *kdev;
+	unsigned char buf[DRM_ELD_HEADER_BLOCK_SIZE + 8] = {0};
+	bool enabled = false;
+	int ret;
+
+	kdev = adev->ddev.dev;
+	KUNIT_ASSERT_NOT_NULL(test, kdev);
+	acomp = kunit_kzalloc(test, sizeof(*acomp), GFP_KERNEL);
+	KUNIT_ASSERT_NOT_NULL(test, acomp);
+	wb_connector = kunit_kzalloc(test, sizeof(*wb_connector), GFP_KERNEL);
+	KUNIT_ASSERT_NOT_NULL(test, wb_connector);
+	KUNIT_ASSERT_EQ(test, drm_connector_init(&adev->ddev, wb_connector,
+						 &dm_test_audio_connector_funcs,
+						 DRM_MODE_CONNECTOR_WRITEBACK), 0);
+	KUNIT_ASSERT_EQ(test, kunit_add_action_or_reset(test,
+			 dm_test_audio_connector_cleanup, wb_connector), 0);
+
+	aconnector = kunit_kzalloc(test, sizeof(*aconnector), GFP_KERNEL);
+	KUNIT_ASSERT_NOT_NULL(test, aconnector);
+	KUNIT_ASSERT_EQ(test, drm_connector_init(&adev->ddev, &aconnector->base,
+						 &dm_test_audio_connector_funcs,
+						 DRM_MODE_CONNECTOR_HDMIA), 0);
+	KUNIT_ASSERT_EQ(test, kunit_add_action_or_reset(test,
+			 dm_test_audio_connector_cleanup, &aconnector->base), 0);
+
+	mutex_init(&adev->dm.audio_lock);
+	aconnector->audio_inst = 3;
+	aconnector->base.eld[DRM_ELD_BASELINE_ELD_LEN] = 2;
+	aconnector->base.eld[DRM_ELD_VER] = DRM_ELD_VER_CEA861D;
+	aconnector->base.eld[DRM_ELD_SPEAKER] = DRM_ELD_SPEAKER_FLR;
+	dev_set_drvdata(kdev, &adev->ddev);
+
+	KUNIT_ASSERT_EQ(test, amdgpu_dm_audio_component_bind(kdev, NULL, acomp), 0);
+	ret = acomp->ops->get_eld(kdev, 3, 0, &enabled, buf, sizeof(buf));
+
+	KUNIT_EXPECT_EQ(test, ret, DRM_ELD_HEADER_BLOCK_SIZE + 8);
+	KUNIT_EXPECT_TRUE(test, enabled);
+	KUNIT_EXPECT_EQ(test, memcmp(buf, aconnector->base.eld, ret), 0);
+}
+
+/**
+ * dm_test_audio_component_get_eld_no_match - Test ELD lookup miss
+ * @test: The KUnit test context
+ *
+ * A non-matching connector should leave the audio port disabled and return an
+ * empty ELD size without copying data.
+ */
+static void dm_test_audio_component_get_eld_no_match(struct kunit *test)
+{
+	struct amdgpu_device *adev = dm_kunit_alloc_adev(test);
+	struct amdgpu_dm_connector *aconnector;
+	struct drm_audio_component *acomp;
+	struct device *kdev;
+	unsigned char buf[DRM_ELD_HEADER_BLOCK_SIZE] = {0x5a};
+	bool enabled = true;
+	int ret;
+
+	kdev = adev->ddev.dev;
+	KUNIT_ASSERT_NOT_NULL(test, kdev);
+	acomp = kunit_kzalloc(test, sizeof(*acomp), GFP_KERNEL);
+	KUNIT_ASSERT_NOT_NULL(test, acomp);
+
+	aconnector = kunit_kzalloc(test, sizeof(*aconnector), GFP_KERNEL);
+	KUNIT_ASSERT_NOT_NULL(test, aconnector);
+	KUNIT_ASSERT_EQ(test, drm_connector_init(&adev->ddev, &aconnector->base,
+						 &dm_test_audio_connector_funcs,
+						 DRM_MODE_CONNECTOR_HDMIA), 0);
+	KUNIT_ASSERT_EQ(test, kunit_add_action_or_reset(test,
+			 dm_test_audio_connector_cleanup, &aconnector->base), 0);
+
+	mutex_init(&adev->dm.audio_lock);
+	aconnector->audio_inst = 4;
+	dev_set_drvdata(kdev, &adev->ddev);
+
+	KUNIT_ASSERT_EQ(test, amdgpu_dm_audio_component_bind(kdev, NULL, acomp), 0);
+	ret = acomp->ops->get_eld(kdev, 3, 0, &enabled, buf, sizeof(buf));
+
+	KUNIT_EXPECT_EQ(test, ret, 0);
+	KUNIT_EXPECT_FALSE(test, enabled);
+	KUNIT_EXPECT_EQ(test, buf[0], 0x5a);
+}
+
 static struct kunit_case dm_audio_test_cases[] = {
 	/* amdgpu_dm_audio_init */
 	KUNIT_CASE(dm_test_audio_init_disabled),
@@ -593,6 +709,9 @@ static struct kunit_case dm_audio_test_cases[] = {
 	KUNIT_CASE(dm_test_eld_notify_no_component),
 	KUNIT_CASE(dm_test_eld_notify_null_audio_ops),
 	KUNIT_CASE(dm_test_eld_notify_null_callback),
+	/* amdgpu_dm_audio_component_get_eld */
+	KUNIT_CASE(dm_test_audio_component_get_eld_copies_matching_connector),
+	KUNIT_CASE(dm_test_audio_component_get_eld_no_match),
 	{}
 };
 
Signature · 1 line
2.53.0
#20 lore raw

PATCH 19/49 drm/amd/display: add KUnit tests for audio commit path

In reply to Fangzhi Zuo

From: Alex Hung <[email protected]>

[WHAT]
Add KUnit coverage for amdgpu_dm_commit_audio(), the remaining function reported as untested by gcov.

The tests build hand-rolled drm_atomic_state arrays and back dc_stream_get_status() with a fake dc->current_state to cover the removal and addition ELD notifications along with their guard/skip
paths: writeback connector, detached connector, missing new CRTC state, no modeset, and absent stream status.

---
 .../amd/display/amdgpu_dm/amdgpu_dm_audio.c   |   1 +
 .../amdgpu_dm/tests/amdgpu_dm_audio_test.c    | 532 ++++++++++++++++++
 2 files changed, 533 insertions(+)
drivers/gpu/drm/amd/display/amdgpu_dm/amdgpu_dm_audio.c +1 -0
index 4b10c683df8e..199f339839b2 100644
@@ -321,6 +321,7 @@ void amdgpu_dm_commit_audio(struct drm_device *dev,
 		amdgpu_dm_audio_eld_notify(adev, inst);
 	}
 }
+EXPORT_IF_KUNIT(amdgpu_dm_commit_audio);
 
 #if IS_ENABLED(CONFIG_DRM_AMD_DC_KUNIT_TEST)
 int amdgpu_dm_audio_get_param(void)
drivers/gpu/drm/amd/display/amdgpu_dm/tests/amdgpu_dm_audio_test.c +532 -0

565 lines not on this page · raw message

Signature · 1 line
2.53.0
#21 lore raw

PATCH 20/49 drm/amd/display: Use current mpc pipe in set output transfer func

In reply to Fangzhi Zuo

From: Tomasz Siemek <[email protected]>

[why]
Only the top pipe had the output transfer function programmed.

[how]
Program the current pipe from the MPC chain during fast sequence build.

---
 drivers/gpu/drm/amd/display/dc/core/dc_hw_sequencer.c | 4 ++--
 1 file changed, 2 insertions(+), 2 deletions(-)
drivers/gpu/drm/amd/display/dc/core/dc_hw_sequencer.c +2 -2
index 8b54bab98283..11411fa94665 100644
@@ -1111,7 +1111,7 @@ void hwss_build_fast_sequence(struct dc *dc,
 					(*num_steps)++;
 				}
 			}
-			if (current_mpc_pipe->stream->update_flags.bits.out_tf) {
+			if (hws->funcs.set_output_transfer_func && current_mpc_pipe->stream->update_flags.bits.out_tf) {
 				struct set_output_transfer_func_params *otf_params =
 					&block_sequence[*num_steps].params.set_output_transfer_func_params;
 
@@ -1119,7 +1119,7 @@ void hwss_build_fast_sequence(struct dc *dc,
 				otf_params->xfm = current_mpc_pipe->plane_res.xfm;
 				otf_params->mpc = dc->res_pool->mpc;
 				otf_params->mpcc_id = current_mpc_pipe->plane_res.hubp->inst;
-				otf_params->is_top_pipe = resource_is_pipe_type(pipe_ctx, OPP_HEAD);
+				otf_params->is_top_pipe = resource_is_pipe_type(current_mpc_pipe, OPP_HEAD);
 				otf_params->stream = current_mpc_pipe->stream;
 				block_sequence[*num_steps].func = DPP_SET_OUTPUT_TRANSFER_FUNC;
 				(*num_steps)++;
Signature · 1 line
2.53.0
#22 lore raw

PATCH 21/49 drm/amd/display: Correct vblank_end calc for fams cmd packet

In reply to Fangzhi Zuo

From: Nicholas Carbones <[email protected]>

[Why]
By changing how we populate vblank_nom, constraining vblank size, the vblank_end calculation for the fams command packet gets affected. We add up v_active with a new vblank_nom value for stream pstate's nom_vtotal, which describes the vtotal and nominal refresh rate, and that causes underflow.

[How]
Set nom_vtotal equal to the timing's v_total.

---
 .../display/dc/dml2_0/dml21/src/dml2_pmo/dml2_pmo_dcn4_fams2.c  | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)
drivers/gpu/drm/amd/display/dc/dml2_0/dml21/src/dml2_pmo/dml2_pmo_dcn4_fams2.c +1 -1
index d5f20c85006e..8f481ef9316f 100644
@@ -1710,7 +1710,7 @@ static void build_pstate_meta_per_stream(struct dml2_pmo_instance *pmo,
 	/* common */
 	stream_pstate_meta->valid = true;
 	stream_pstate_meta->otg_vline_time_us = (double)timing->h_total / timing->pixel_clock_khz * 1000.0;
-	stream_pstate_meta->nom_vtotal = stream_descriptor->timing.vblank_nom + stream_descriptor->timing.v_active;
+	stream_pstate_meta->nom_vtotal = stream_descriptor->timing.v_total;
 	stream_pstate_meta->nom_refresh_rate_hz = timing->pixel_clock_khz * 1000.0 /
 			(stream_pstate_meta->nom_vtotal * timing->h_total);
 	stream_pstate_meta->nom_frame_time_us =
Signature · 1 line
2.53.0
#23 lore raw

PATCH 22/49 drm/amd/display: Add KUnit test for native backlight registration

In reply to Fangzhi Zuo

From: Alex Hung <[email protected]>

[WHAT]
Add a KUnit case covering the successful path of amdgpu_dm_register_backlight_device(). The test uses the standard DRM KUnit device helpers to register a native backlight device, verifies the calculated backlight properties and cached brightness, and unregisters the device through KUnit cleanup to avoid leaking a class device across cases.

---
 .../tests/amdgpu_dm_backlight_test.c          | 52 +++++++++++++++++++
 1 file changed, 52 insertions(+)
drivers/gpu/drm/amd/display/amdgpu_dm/tests/amdgpu_dm_backlight_test.c +52 -0
index 618fd5142da0..7ca17f803f9d 100644
@@ -326,6 +326,11 @@ static int dm_test_get_backlight_level_error(const struct dc_link *link)
 	return DC_ERROR_UNEXPECTED;
 }
 
+static void dm_test_unregister_backlight_device(void *data)
+{
+	backlight_device_unregister(data);
+}
+
 static bool dm_test_get_backlight_level_nits(struct dc_link *link,
 					     uint32_t *avg,
 					     uint32_t *peak)
@@ -463,6 +468,52 @@ static void dm_test_register_backlight_device_negative_index(struct kunit *test)
 	KUNIT_EXPECT_NULL(test, adev->dm.backlight_dev[0]);
 }
 
+/**
+ * dm_test_register_backlight_device_success - Test native backlight registration
+ * @test: The KUnit test context
+ *
+ * A native backlight device must be registered with the calculated
+ * properties, and its initial readback must retain the initial brightness.
+ */
+static void dm_test_register_backlight_device_success(struct kunit *test)
+{
+	struct amdgpu_device *adev = dm_kunit_alloc_adev(test);
+	struct amdgpu_dm_connector *aconnector;
+	struct amdgpu_dm_backlight_caps *caps;
+	struct dc_link *link = dm_kunit_alloc_link(test);
+	struct drm_minor *primary;
+	unsigned int max;
+
+	setup_test_link_service(test, link);
+	link->dc->link_srv->edp_get_backlight_level = dm_test_get_backlight_level_error;
+	primary = kunit_kzalloc(test, sizeof(*primary), GFP_KERNEL);
+	KUNIT_ASSERT_NOT_ERR_OR_NULL(test, primary);
+	adev->ddev.primary = primary;
+	adev->dm.backlight_link[0] = link;
+
+	aconnector = dm_kunit_alloc_connector(test, adev, link);
+	aconnector->bl_idx = 0;
+	aconnector->base.kdev = adev->ddev.dev;
+	caps = &adev->dm.backlight_caps[0];
+	caps->min_input_signal = AMDGPU_DM_DEFAULT_MIN_BACKLIGHT;
+	caps->max_input_signal = AMDGPU_DM_DEFAULT_MAX_BACKLIGHT;
+	caps->ac_level = 50;
+	caps->dc_level = 25;
+	max = 0x101 * AMDGPU_DM_DEFAULT_MAX_BACKLIGHT;
+
+	amdgpu_dm_register_backlight_device(aconnector);
+
+	KUNIT_ASSERT_NOT_NULL(test, adev->dm.backlight_dev[0]);
+	KUNIT_EXPECT_EQ(test, adev->dm.backlight_dev[0]->props.max_brightness, max);
+	KUNIT_EXPECT_EQ(test, adev->dm.backlight_dev[0]->props.brightness,
+			DIV_ROUND_CLOSEST(max * caps->ac_level, 100));
+	KUNIT_EXPECT_EQ(test, adev->dm.brightness[0],
+			adev->dm.backlight_dev[0]->props.brightness);
+	KUNIT_ASSERT_EQ(test, kunit_add_action_or_reset(test,
+			dm_test_unregister_backlight_device,
+			adev->dm.backlight_dev[0]), 0);
+}
+
 static struct drm_connector *setup_panel_power_savings_connector(struct kunit *test,
 							 struct device **device_out,
 							 struct dm_connector_state **state_out)
@@ -1861,6 +1912,7 @@ static struct kunit_case dm_backlight_test_cases[] = {
 	KUNIT_CASE(dm_test_backlight_get_brightness_uses_device_index),
 	/* amdgpu_dm_register_backlight_device */
 	KUNIT_CASE(dm_test_register_backlight_device_negative_index),
+	KUNIT_CASE(dm_test_register_backlight_device_success),
 	/* panel_power_savings_show / store */
 	KUNIT_CASE(dm_test_panel_power_savings_show_maps_disable_to_zero),
 	KUNIT_CASE(dm_test_panel_power_savings_show_reports_level),
Signature · 1 line
2.53.0
#24 lore raw

PATCH 23/49 drm/amd/display: Add color transfer-function tests

In reply to Fangzhi Zuo

From: Alex Hung <[email protected]>

[WHY]
The color transfer-function calculation helpers were not covered by the amdgpu_dm_color KUnit suite. They rely on DAL fixed-point math and run under the KUnit UML build without native floating point.

[HOW]
Expose the five static helpers to KUnit and add direct coverage for the legacy, 16-bit, and 32-bit input and output transfer-function paths, including sRGB, linear, and ROM-backed variants.

---
 .../amd/display/amdgpu_dm/amdgpu_dm_color.c   |  36 +++--
 .../amd/display/amdgpu_dm/amdgpu_dm_color.h   |  14 ++
 .../amdgpu_dm/tests/amdgpu_dm_color_test.c    | 147 ++++++++++++++++++
 3 files changed, 184 insertions(+), 13 deletions(-)
drivers/gpu/drm/amd/display/amdgpu_dm/amdgpu_dm_color.c +23 -13
index 658dfc37d4d4..7b68c6846039 100644
@@ -618,9 +618,10 @@ EXPORT_IF_KUNIT(__drm_ctm_3x4_to_dc_matrix);
  * Returns:
  * 0 in case of success, -ENOMEM if fails
  */
-static int __set_legacy_tf(struct dc_transfer_func *func,
-			   const struct drm_color_lut *lut, uint32_t lut_size,
-			   bool has_rom)
+STATIC_IFN_KUNIT int
+__set_legacy_tf(struct dc_transfer_func *func,
+		const struct drm_color_lut *lut, uint32_t lut_size,
+		bool has_rom)
 {
 	struct dc_gamma *gamma = NULL;
 	struct calculate_buffer cal_buffer = {0};
@@ -645,6 +646,7 @@ static int __set_legacy_tf(struct dc_transfer_func *func,
 
 	return res ? 0 : -ENOMEM;
 }
+EXPORT_IF_KUNIT(__set_legacy_tf);
 
 /**
  * __set_output_tf - calculates the output transfer function based on expected input space.
@@ -656,9 +658,10 @@ static int __set_legacy_tf(struct dc_transfer_func *func,
  * Returns:
  * 0 in case of success. -ENOMEM if fails.
  */
-static int __set_output_tf(struct dc_transfer_func *func,
-			   const struct drm_color_lut *lut, uint32_t lut_size,
-			   bool has_rom)
+STATIC_IFN_KUNIT int
+__set_output_tf(struct dc_transfer_func *func,
+		const struct drm_color_lut *lut, uint32_t lut_size,
+		bool has_rom)
 {
 	struct dc_gamma *gamma = NULL;
 	struct calculate_buffer cal_buffer = {0};
@@ -703,6 +706,7 @@ static int __set_output_tf(struct dc_transfer_func *func,
 
 	return res ? 0 : -ENOMEM;
 }
+EXPORT_IF_KUNIT(__set_output_tf);
 
 /**
  * __set_output_tf_32 - calculates the output transfer function based on expected input space.
@@ -714,9 +718,10 @@ static int __set_output_tf(struct dc_transfer_func *func,
  * Returns:
  * 0 in case of success. -ENOMEM if fails.
  */
-static int __set_output_tf_32(struct dc_transfer_func *func,
-			      const struct drm_color_lut32 *lut, uint32_t lut_size,
-			      bool has_rom)
+STATIC_IFN_KUNIT int
+__set_output_tf_32(struct dc_transfer_func *func,
+		   const struct drm_color_lut32 *lut, uint32_t lut_size,
+		   bool has_rom)
 {
 	struct dc_gamma *gamma = NULL;
 	struct calculate_buffer cal_buffer = {0};
@@ -759,6 +764,7 @@ static int __set_output_tf_32(struct dc_transfer_func *func,
 
 	return res ? 0 : -ENOMEM;
 }
+EXPORT_IF_KUNIT(__set_output_tf_32);
 
 STATIC_IFN_KUNIT void __set_tf_bypass(struct dc_transfer_func *tf)
 {
@@ -820,8 +826,9 @@ EXPORT_IF_KUNIT(amdgpu_dm_set_atomic_regamma);
  * Returns:
  * 0 in case of success. -ENOMEM if fails.
  */
-static int __set_input_tf(struct dc_color_caps *caps, struct dc_transfer_func *func,
-			  const struct drm_color_lut *lut, uint32_t lut_size)
+STATIC_IFN_KUNIT int __set_input_tf(struct dc_color_caps *caps,
+				    struct dc_transfer_func *func,
+				    const struct drm_color_lut *lut, uint32_t lut_size)
 {
 	struct dc_gamma *gamma = NULL;
 	bool res;
@@ -844,6 +851,7 @@ static int __set_input_tf(struct dc_color_caps *caps, struct dc_transfer_func *f
 
 	return res ? 0 : -ENOMEM;
 }
+EXPORT_IF_KUNIT(__set_input_tf);
 
 /**
  * __set_input_tf_32 - calculates the input transfer function based on expected
@@ -856,8 +864,9 @@ static int __set_input_tf(struct dc_color_caps *caps, struct dc_transfer_func *f
  * Returns:
  * 0 in case of success. -ENOMEM if fails.
  */
-static int __set_input_tf_32(struct dc_color_caps *caps, struct dc_transfer_func *func,
-			     const struct drm_color_lut32 *lut, uint32_t lut_size)
+STATIC_IFN_KUNIT int __set_input_tf_32(struct dc_color_caps *caps,
+				       struct dc_transfer_func *func,
+				       const struct drm_color_lut32 *lut, uint32_t lut_size)
 {
 	struct dc_gamma *gamma = NULL;
 	bool res;
@@ -880,6 +889,7 @@ static int __set_input_tf_32(struct dc_color_caps *caps, struct dc_transfer_func
 
 	return res ? 0 : -ENOMEM;
 }
+EXPORT_IF_KUNIT(__set_input_tf_32);
 
 STATIC_IFN_KUNIT
 enum dc_transfer_func_predefined
drivers/gpu/drm/amd/display/amdgpu_dm/amdgpu_dm_color.h +14 -0
index cec23a020c3d..3e8a3d3fc855 100644
@@ -64,6 +64,20 @@ void __drm_ctm_to_dc_matrix(const struct drm_color_ctm *ctm,
 			     struct fixed31_32 *matrix);
 void __drm_ctm_3x4_to_dc_matrix(const struct drm_color_ctm_3x4 *ctm,
 				 struct fixed31_32 *matrix);
+int __set_legacy_tf(struct dc_transfer_func *func,
+		    const struct drm_color_lut *lut, uint32_t lut_size,
+		    bool has_rom);
+int __set_output_tf(struct dc_transfer_func *func,
+		    const struct drm_color_lut *lut, uint32_t lut_size,
+		    bool has_rom);
+int __set_output_tf_32(struct dc_transfer_func *func,
+		       const struct drm_color_lut32 *lut, uint32_t lut_size,
+		       bool has_rom);
+struct dc_color_caps;
+int __set_input_tf(struct dc_color_caps *caps, struct dc_transfer_func *func,
+		   const struct drm_color_lut *lut, uint32_t lut_size);
+int __set_input_tf_32(struct dc_color_caps *caps, struct dc_transfer_func *func,
+		      const struct drm_color_lut32 *lut, uint32_t lut_size);
 enum dc_transfer_func_predefined
 amdgpu_tf_to_dc_tf(enum amdgpu_transfer_function tf);
 enum dc_transfer_func_predefined
drivers/gpu/drm/amd/display/amdgpu_dm/tests/amdgpu_dm_color_test.c +147 -0

159 lines not on this page · raw message

Signature · 1 line
2.53.0
#25 lore raw

PATCH 24/49 drm/amd/display: Add atomic transfer-function tests

In reply to Fangzhi Zuo

From: Alex Hung <[email protected]>

[WHY]
The atomic regamma, shaper, and blend helpers were only exercised on their linear bypass paths, leaving the generated transfer-function cases untested.

[HOW]
Add sRGB success-path tests that verify the generated transfer functions and the corresponding plane color-management enable flags.

---
 .../amdgpu_dm/tests/amdgpu_dm_color_test.c    | 41 +++++++++++++++++++
 1 file changed, 41 insertions(+)
drivers/gpu/drm/amd/display/amdgpu_dm/tests/amdgpu_dm_color_test.c +41 -0
index de11a606a88c..4945f5429bc1 100644
@@ -1535,6 +1535,23 @@ static void dm_test_set_atomic_regamma_bypass(struct kunit *test)
 	KUNIT_EXPECT_EQ(test, (int)out_tf->tf, (int)TRANSFER_FUNCTION_LINEAR);
 }
 
+/**
+ * dm_test_set_atomic_regamma_srgb - Non-linear TF enables generated regamma
+ * @test: KUnit test context
+ */
+static void dm_test_set_atomic_regamma_srgb(struct kunit *test)
+{
+	struct dc_transfer_func *out_tf;
+
+	out_tf = kunit_kzalloc(test, sizeof(*out_tf), GFP_KERNEL);
+	KUNIT_ASSERT_NOT_NULL(test, out_tf);
+
+	KUNIT_EXPECT_EQ(test,
+			amdgpu_dm_set_atomic_regamma(out_tf, NULL, 0, true, TRANSFER_FUNCTION_SRGB),
+			0);
+	KUNIT_EXPECT_EQ(test, (int)out_tf->type, (int)TF_TYPE_DISTRIBUTED_POINTS);
+}
+
 /**
  * dm_test_atomic_shaper_lut_bypass - No LUT and linear TF: must take bypass path
  * @test: KUnit test context
@@ -1577,6 +1594,28 @@ static void dm_test_atomic_blend_lut_bypass(struct kunit *test)
 	KUNIT_EXPECT_EQ(test, (int)cm->blend_func.tf, (int)TRANSFER_FUNCTION_LINEAR);
 }
 
+/**
+ * dm_test_atomic_shaper_blend_srgb - Non-linear TFs enable shaper and blend
+ * @test: KUnit test context
+ */
+static void dm_test_atomic_shaper_blend_srgb(struct kunit *test)
+{
+	struct dc_plane_cm *cm;
+
+	cm = kunit_kzalloc(test, sizeof(*cm), GFP_KERNEL);
+	KUNIT_ASSERT_NOT_NULL(test, cm);
+
+	KUNIT_EXPECT_EQ(test,
+			amdgpu_dm_atomic_shaper_lut(NULL, true, TRANSFER_FUNCTION_SRGB, 0, cm),
+			0);
+	KUNIT_EXPECT_TRUE(test, cm->flags.bits.shaper_enable);
+
+	KUNIT_EXPECT_EQ(test,
+			amdgpu_dm_atomic_blend_lut(NULL, false, TRANSFER_FUNCTION_SRGB, 0, cm),
+			0);
+	KUNIT_EXPECT_TRUE(test, cm->flags.bits.blend_enable);
+}
+
 /* ---- Tests for __set_colorop_in_tf_1d_curve ---- */
 
 /**
@@ -2533,10 +2572,12 @@ static struct kunit_case dm_color_test_cases[] = {
 	KUNIT_CASE(dm_test_set_transfer_funcs_with_luts),
 	/* amdgpu_dm_set_atomic_regamma */
 	KUNIT_CASE(dm_test_set_atomic_regamma_bypass),
+	KUNIT_CASE(dm_test_set_atomic_regamma_srgb),
 	/* amdgpu_dm_atomic_shaper_lut */
 	KUNIT_CASE(dm_test_atomic_shaper_lut_bypass),
 	/* amdgpu_dm_atomic_blend_lut */
 	KUNIT_CASE(dm_test_atomic_blend_lut_bypass),
+	KUNIT_CASE(dm_test_atomic_shaper_blend_srgb),
 	/* __set_colorop_in_tf_1d_curve */
 	KUNIT_CASE(dm_test_set_colorop_in_tf_1d_curve_invalid_type),
 	KUNIT_CASE(dm_test_set_colorop_in_tf_1d_curve_unsupported_curve),
Signature · 1 line
2.53.0
#26 lore raw

PATCH 25/49 drm/amd/display: Add CRTC and plane degamma tests

In reply to Fangzhi Zuo

From: Alex Hung <[email protected]>

[WHY]
CRTC degamma classification and its mapping onto the plane input transfer function lacked both success and conflict coverage.

[HOW]
Exercise legacy regamma detection, atomic and plane degamma LUTs, BT.709 video mapping, and rejection of simultaneous degamma stages.

---
 .../amdgpu_dm/tests/amdgpu_dm_color_test.c    | 128 ++++++++++++++++++
 1 file changed, 128 insertions(+)
drivers/gpu/drm/amd/display/amdgpu_dm/tests/amdgpu_dm_color_test.c +128 -0
index 4945f5429bc1..0835177c98d2 100644
@@ -2121,6 +2121,36 @@ static void dm_test_check_crtc_color_mgmt_no_luts(struct kunit *test)
 	KUNIT_EXPECT_FALSE(test, f.crtc_state->cm_is_degamma_srgb);
 }
 
+/**
+ * dm_test_check_crtc_color_mgmt_legacy_regamma - Legacy LUT uses sRGB regamma
+ * @test: KUnit test context
+ */
+static void dm_test_check_crtc_color_mgmt_legacy_regamma(struct kunit *test)
+{
+	struct dm_test_color_update_fixture f = dm_test_color_update_setup(test);
+
+	f.crtc_state->base.gamma_lut = dm_test_make_lut_blob(test, MAX_COLOR_LEGACY_LUT_ENTRIES);
+
+	KUNIT_EXPECT_EQ(test, amdgpu_dm_check_crtc_color_mgmt(f.crtc_state, true), 0);
+	KUNIT_EXPECT_TRUE(test, f.crtc_state->cm_is_degamma_srgb);
+}
+
+/**
+ * dm_test_check_crtc_color_mgmt_degamma - Atomic degamma is mapped to the plane
+ * @test: KUnit test context
+ */
+static void dm_test_check_crtc_color_mgmt_degamma(struct kunit *test)
+{
+	struct dm_test_color_update_fixture f = dm_test_color_update_setup(test);
+
+	f.crtc_state->base.degamma_lut =
+		dm_test_make_lut_blob(test, MAX_COLOR_LUT_ENTRIES);
+
+	KUNIT_EXPECT_EQ(test, amdgpu_dm_check_crtc_color_mgmt(f.crtc_state, true), 0);
+	KUNIT_EXPECT_TRUE(test, f.crtc_state->cm_has_degamma);
+	KUNIT_EXPECT_FALSE(test, f.crtc_state->cm_is_degamma_srgb);
+}
+
 /**
  * dm_test_update_crtc_color_mgmt_no_ctm - No CRTC CTM leaves remap bypassed
  * @test: KUnit test context
@@ -2214,6 +2244,98 @@ static void dm_test_update_plane_color_mgmt_maps_crtc_degamma(struct kunit *test
 			(int)TRANSFER_FUNCTION_SRGB);
 }
 
+/**
+ * dm_test_update_plane_color_mgmt_maps_crtc_degamma_lut - CRTC LUT maps to plane degamma
+ * @test: KUnit test context
+ */
+static void dm_test_update_plane_color_mgmt_maps_crtc_degamma_lut(struct kunit *test)
+{
+	struct dm_test_color_update_fixture f = dm_test_color_update_setup(test);
+	struct drm_plane_state *plane_state = &f.dm_plane_state->base;
+	int ret;
+
+	f.crtc_state->cm_has_degamma = true;
+	f.crtc_state->cm_is_degamma_srgb = true;
+	f.crtc_state->base.degamma_lut =
+		dm_test_make_lut_blob(test, MAX_COLOR_LUT_ENTRIES);
+
+	ret = amdgpu_dm_update_plane_color_mgmt(f.crtc_state, plane_state,
+						f.dc_plane_state);
+	KUNIT_EXPECT_EQ(test, ret, 0);
+	KUNIT_EXPECT_EQ(test, (int)f.dc_plane_state->in_transfer_func.type,
+			(int)TF_TYPE_DISTRIBUTED_POINTS);
+	KUNIT_EXPECT_EQ(test, (int)f.dc_plane_state->in_transfer_func.tf,
+			(int)TRANSFER_FUNCTION_SRGB);
+}
+
+/**
+ * dm_test_update_plane_color_mgmt_maps_bt709_degamma - Video uses BT.709 degamma
+ * @test: KUnit test context
+ */
+static void dm_test_update_plane_color_mgmt_maps_bt709_degamma(struct kunit *test)
+{
+	struct dm_test_color_update_fixture f = dm_test_color_update_setup(test);
+	struct drm_plane_state *plane_state = &f.dm_plane_state->base;
+	int ret;
+
+	f.crtc_state->cm_is_degamma_srgb = true;
+	f.dc_plane_state->format = SURFACE_PIXEL_FORMAT_VIDEO_420_YCbCr;
+
+	ret = amdgpu_dm_update_plane_color_mgmt(f.crtc_state, plane_state,
+						f.dc_plane_state);
+	KUNIT_EXPECT_EQ(test, ret, 0);
+	KUNIT_EXPECT_EQ(test, (int)f.dc_plane_state->in_transfer_func.tf,
+			(int)TRANSFER_FUNCTION_BT709);
+}
+
+/**
+ * dm_test_update_plane_color_mgmt_plane_degamma_lut - Non-linear plane LUT succeeds
+ * @test: KUnit test context
+ */
+static void dm_test_update_plane_color_mgmt_plane_degamma_lut(struct kunit *test)
+{
+	struct dm_test_color_update_fixture f = dm_test_color_update_setup(test);
+	struct drm_plane_state *plane_state = &f.dm_plane_state->base;
+	struct drm_color_lut *lut;
+	int ret;
+
+	f.dm_plane_state->degamma_lut =
+		dm_test_make_lut_blob(test, MAX_COLOR_LUT_ENTRIES);
+	lut = f.dm_plane_state->degamma_lut->data;
+	lut[0].red = MAX_DRM_LUT_VALUE;
+	lut[0].green = MAX_DRM_LUT_VALUE;
+	lut[0].blue = MAX_DRM_LUT_VALUE;
+
+	ret = amdgpu_dm_update_plane_color_mgmt(f.crtc_state, plane_state,
+						f.dc_plane_state);
+	KUNIT_EXPECT_EQ(test, ret, 0);
+	KUNIT_EXPECT_EQ(test, (int)f.dc_plane_state->in_transfer_func.type,
+			(int)TF_TYPE_DISTRIBUTED_POINTS);
+}
+
+/**
+ * dm_test_update_plane_color_mgmt_rejects_dual_degamma - Reject two degamma stages
+ * @test: KUnit test context
+ */
+static void dm_test_update_plane_color_mgmt_rejects_dual_degamma(struct kunit *test)
+{
+	struct dm_test_color_update_fixture f = dm_test_color_update_setup(test);
+	struct drm_plane_state *plane_state = &f.dm_plane_state->base;
+	struct drm_crtc *crtc;
+	int ret;
+
+	crtc = kunit_kzalloc(test, sizeof(*crtc), GFP_KERNEL);
+	KUNIT_ASSERT_NOT_NULL(test, crtc);
+	crtc->dev = &f.adev->ddev;
+	f.crtc_state->base.crtc = crtc;
+	f.crtc_state->cm_has_degamma = true;
+	f.dm_plane_state->degamma_tf = AMDGPU_TRANSFER_FUNCTION_SRGB_EOTF;
+
+	ret = amdgpu_dm_update_plane_color_mgmt(f.crtc_state, plane_state,
+						f.dc_plane_state);
+	KUNIT_EXPECT_EQ(test, ret, -EINVAL);
+}
+
 /**
  * dm_test_update_plane_color_mgmt_uses_color_caps - DC context provides color caps
  * @test: KUnit test context
@@ -2600,11 +2722,17 @@ static struct kunit_case dm_color_test_cases[] = {
 	KUNIT_CASE(dm_test_colorop_degamma_no_match),
 	/* CRTC and plane color management update paths */
 	KUNIT_CASE(dm_test_check_crtc_color_mgmt_no_luts),
+	KUNIT_CASE(dm_test_check_crtc_color_mgmt_legacy_regamma),
+	KUNIT_CASE(dm_test_check_crtc_color_mgmt_degamma),
 	KUNIT_CASE(dm_test_update_crtc_color_mgmt_no_ctm),
 	KUNIT_CASE(dm_test_update_crtc_color_mgmt_ctm),
 	KUNIT_CASE(dm_test_update_plane_color_mgmt_bad_lut3d),
 	KUNIT_CASE(dm_test_update_plane_color_mgmt_fallback_defaults),
 	KUNIT_CASE(dm_test_update_plane_color_mgmt_maps_crtc_degamma),
+	KUNIT_CASE(dm_test_update_plane_color_mgmt_maps_crtc_degamma_lut),
+	KUNIT_CASE(dm_test_update_plane_color_mgmt_maps_bt709_degamma),
+	KUNIT_CASE(dm_test_update_plane_color_mgmt_plane_degamma_lut),
+	KUNIT_CASE(dm_test_update_plane_color_mgmt_rejects_dual_degamma),
 	KUNIT_CASE(dm_test_update_plane_color_mgmt_uses_color_caps),
 	KUNIT_CASE(dm_test_update_plane_color_mgmt_plane_ctm),
 	KUNIT_CASE(dm_test_update_plane_color_mgmt_colorop_bypass_pipeline),
Signature · 1 line
2.53.0
#27 lore raw

PATCH 26/49 drm/amd/display: Add legacy plane LUT tests

In reply to Fangzhi Zuo

From: Alex Hung <[email protected]>

[WHY]
The legacy plane color path did not exercise successful shaper, 3D LUT, and blend LUT programming as a single transaction.

[HOW]
Provide valid legacy LUT blobs and verify that all three plane color-management stages are enabled.

---
 .../amdgpu_dm/tests/amdgpu_dm_color_test.c    | 28 +++++++++++++++++++
 1 file changed, 28 insertions(+)
drivers/gpu/drm/amd/display/amdgpu_dm/tests/amdgpu_dm_color_test.c +28 -0
index 0835177c98d2..025e408a8ae6 100644
@@ -2355,6 +2355,33 @@ static void dm_test_update_plane_color_mgmt_uses_color_caps(struct kunit *test)
 			0);
 }
 
+/**
+ * dm_test_update_plane_color_mgmt_legacy_luts - Legacy shaper and blend LUTs succeed
+ * @test: KUnit test context
+ */
+static void dm_test_update_plane_color_mgmt_legacy_luts(struct kunit *test)
+{
+	const u32 lut3d_entries =
+		MAX_COLOR_3DLUT_SIZE * MAX_COLOR_3DLUT_SIZE * MAX_COLOR_3DLUT_SIZE;
+	struct dm_test_color_update_fixture f = dm_test_color_update_setup(test);
+	struct drm_plane_state *plane_state = &f.dm_plane_state->base;
+	int ret;
+
+	f.adev->dm.dc->caps.color.dpp.hw_3d_lut = true;
+	f.dm_plane_state->shaper_lut =
+		dm_test_make_lut_blob(test, MAX_COLOR_LUT_ENTRIES);
+	f.dm_plane_state->lut3d = dm_test_make_lut_blob(test, lut3d_entries);
+	f.dm_plane_state->blend_lut =
+		dm_test_make_lut_blob(test, MAX_COLOR_LUT_ENTRIES);
+
+	ret = amdgpu_dm_update_plane_color_mgmt(f.crtc_state, plane_state,
+						f.dc_plane_state);
+	KUNIT_EXPECT_EQ(test, ret, 0);
+	KUNIT_EXPECT_TRUE(test, f.dc_plane_state->cm.flags.bits.shaper_enable);
+	KUNIT_EXPECT_TRUE(test, f.dc_plane_state->cm.flags.bits.lut3d_enable);
+	KUNIT_EXPECT_TRUE(test, f.dc_plane_state->cm.flags.bits.blend_enable);
+}
+
 /**
  * dm_test_update_plane_color_mgmt_plane_ctm - Plane CTM maps to gamut remap
  * @test: KUnit test context
@@ -2734,6 +2761,7 @@ static struct kunit_case dm_color_test_cases[] = {
 	KUNIT_CASE(dm_test_update_plane_color_mgmt_plane_degamma_lut),
 	KUNIT_CASE(dm_test_update_plane_color_mgmt_rejects_dual_degamma),
 	KUNIT_CASE(dm_test_update_plane_color_mgmt_uses_color_caps),
+	KUNIT_CASE(dm_test_update_plane_color_mgmt_legacy_luts),
 	KUNIT_CASE(dm_test_update_plane_color_mgmt_plane_ctm),
 	KUNIT_CASE(dm_test_update_plane_color_mgmt_colorop_bypass_pipeline),
 	KUNIT_CASE(dm_test_update_plane_color_mgmt_colorop_missing_multiplier),
Signature · 1 line
2.53.0
#28 lore raw

PATCH 27/49 drm/amd/display: Add truncated colorop tests

In reply to Fangzhi Zuo

From: Alex Hung <[email protected]>

[WHY]
Truncated colorop pipelines that end after the 3x4 matrix had no coverage for their fallback exits.

[HOW]
Exercise every remaining pipeline length with bypassed operations and verify that the plane color stages stay disabled.

---
 .../amdgpu_dm/tests/amdgpu_dm_color_test.c    | 52 +++++++++++++++++++
 1 file changed, 52 insertions(+)
drivers/gpu/drm/amd/display/amdgpu_dm/tests/amdgpu_dm_color_test.c +52 -0
index 025e408a8ae6..11d42ff59dff 100644
@@ -2581,6 +2581,57 @@ static void dm_test_update_plane_color_mgmt_colorop_missing_3x4(struct kunit *te
 	KUNIT_EXPECT_FALSE(test, f.dc_plane_state->cm.flags.bits.blend_enable);
 }
 
+/**
+ * dm_test_update_plane_color_mgmt_colorop_truncated - truncated pipelines fall back
+ * @test: KUnit test context
+ *
+ * Covers each pipeline exit after the 3x4 matrix while all present colorops
+ * remain bypassed, avoiding the floating-point color calculation paths.
+ */
+static void dm_test_update_plane_color_mgmt_colorop_truncated(struct kunit *test)
+{
+	static const enum drm_colorop_type types[] = {
+		DRM_COLOROP_1D_CURVE,
+		DRM_COLOROP_MULTIPLIER,
+		DRM_COLOROP_CTM_3X4,
+		DRM_COLOROP_1D_CURVE,
+		DRM_COLOROP_1D_LUT,
+		DRM_COLOROP_3D_LUT,
+		DRM_COLOROP_1D_CURVE,
+	};
+	static const enum drm_colorop_curve_1d_type curves[] = {
+		DRM_COLOROP_1D_CURVE_SRGB_EOTF,
+		DRM_COLOROP_1D_CURVE_SRGB_EOTF,
+		DRM_COLOROP_1D_CURVE_SRGB_EOTF,
+		DRM_COLOROP_1D_CURVE_SRGB_INV_EOTF,
+		DRM_COLOROP_1D_CURVE_SRGB_EOTF,
+		DRM_COLOROP_1D_CURVE_SRGB_EOTF,
+		DRM_COLOROP_1D_CURVE_SRGB_EOTF,
+	};
+	static const bool bypass[] = {
+		true, true, true, true, true, true, true,
+	};
+	struct dm_test_color_update_fixture f = dm_test_color_update_setup(test);
+	struct dc_plane_state *dc_plane_state = f.dc_plane_state;
+	struct drm_plane_state *plane_state = &f.dm_plane_state->base;
+	struct dm_crtc_state *crtc_state = f.crtc_state;
+	int count, ret;
+
+	f.adev->dm.dc->caps.color.dpp.hw_3d_lut = true;
+
+	for (count = 3; count <= ARRAY_SIZE(types); count++) {
+		f.dm_plane_state->base.color_pipeline =
+			dm_test_colorop_pipeline_setup(test, &f, types, curves, bypass, count);
+		memset(f.dc_plane_state, 0, sizeof(*f.dc_plane_state));
+
+		ret = amdgpu_dm_update_plane_color_mgmt(crtc_state, plane_state, dc_plane_state);
+		KUNIT_EXPECT_EQ_MSG(test, ret, 0, "pipeline length %d should fall back", count);
+		KUNIT_EXPECT_FALSE(test, f.dc_plane_state->cm.flags.bits.shaper_enable);
+		KUNIT_EXPECT_FALSE(test, f.dc_plane_state->cm.flags.bits.lut3d_enable);
+		KUNIT_EXPECT_FALSE(test, f.dc_plane_state->cm.flags.bits.blend_enable);
+	}
+}
+
 /**
  * dm_test_update_plane_color_mgmt_colorop_no_3dlut_hw - no 3D LUT skips 3D ops
  * @test: KUnit test context
@@ -2766,6 +2817,7 @@ static struct kunit_case dm_color_test_cases[] = {
 	KUNIT_CASE(dm_test_update_plane_color_mgmt_colorop_bypass_pipeline),
 	KUNIT_CASE(dm_test_update_plane_color_mgmt_colorop_missing_multiplier),
 	KUNIT_CASE(dm_test_update_plane_color_mgmt_colorop_missing_3x4),
+	KUNIT_CASE(dm_test_update_plane_color_mgmt_colorop_truncated),
 	KUNIT_CASE(dm_test_update_plane_color_mgmt_colorop_no_3dlut_hw),
 	{}
 };
Signature · 1 line
2.53.0
#29 lore raw

PATCH 28/49 drm/amd/display: Add colorop LUT programming tests

In reply to Fangzhi Zuo

From: Alex Hung <[email protected]>

[WHY]
The enabled colorop shaper, 3D LUT, and blend programming paths were uncovered, including the fallback for missing 3D LUT data.

[HOW]
Build complete colorop pipelines with valid LUT blobs, verify each enabled stage, and cover the empty 3D LUT fallback.

---
 .../amdgpu_dm/tests/amdgpu_dm_color_test.c    | 206 ++++++++++++++++++
 1 file changed, 206 insertions(+)
drivers/gpu/drm/amd/display/amdgpu_dm/tests/amdgpu_dm_color_test.c +206 -0
index 11d42ff59dff..8c2f7ab5f8d3 100644
@@ -2676,6 +2676,208 @@ static void dm_test_update_plane_color_mgmt_colorop_no_3dlut_hw(struct kunit *te
 	KUNIT_EXPECT_FALSE(test, f.dc_plane_state->cm.flags.bits.lut3d_enable);
 }
 
+/**
+ * dm_test_update_plane_color_mgmt_colorop_shaper - enabled shaper TF and LUT succeed
+ * @test: KUnit test context
+ */
+static void dm_test_update_plane_color_mgmt_colorop_shaper(struct kunit *test)
+{
+	static const enum drm_colorop_type types[] = {
+		DRM_COLOROP_1D_CURVE,
+		DRM_COLOROP_MULTIPLIER,
+		DRM_COLOROP_CTM_3X4,
+		DRM_COLOROP_1D_CURVE,
+		DRM_COLOROP_1D_LUT,
+		DRM_COLOROP_3D_LUT,
+		DRM_COLOROP_1D_CURVE,
+		DRM_COLOROP_1D_LUT,
+	};
+	static const enum drm_colorop_curve_1d_type curves[] = {
+		DRM_COLOROP_1D_CURVE_SRGB_EOTF,
+		DRM_COLOROP_1D_CURVE_SRGB_EOTF,
+		DRM_COLOROP_1D_CURVE_SRGB_EOTF,
+		DRM_COLOROP_1D_CURVE_SRGB_INV_EOTF,
+		DRM_COLOROP_1D_CURVE_SRGB_EOTF,
+		DRM_COLOROP_1D_CURVE_SRGB_EOTF,
+		DRM_COLOROP_1D_CURVE_SRGB_EOTF,
+		DRM_COLOROP_1D_CURVE_SRGB_EOTF,
+	};
+	static const bool bypass[] = {
+		true, true, true, false, false, true, true, true,
+	};
+	struct dm_test_color_update_fixture f = dm_test_color_update_setup(test);
+	struct drm_colorop_state *shaper_lut_state;
+	struct drm_plane_state *plane_state = &f.dm_plane_state->base;
+	struct drm_property_blob *blob;
+	int ret;
+
+	f.adev->dm.dc->caps.color.dpp.hw_3d_lut = true;
+	f.dm_plane_state->base.color_pipeline =
+		dm_test_colorop_pipeline_setup(test, &f, types, curves, bypass,
+					       ARRAY_SIZE(types));
+	shaper_lut_state = f.state->colorops[4].new_state;
+	blob = kunit_kzalloc(test, sizeof(*blob), GFP_KERNEL);
+	KUNIT_ASSERT_NOT_NULL(test, blob);
+	blob->length = MAX_COLOR_LUT_ENTRIES * sizeof(struct drm_color_lut32);
+	blob->data = kunit_kzalloc(test, blob->length, GFP_KERNEL);
+	KUNIT_ASSERT_NOT_NULL(test, blob->data);
+	shaper_lut_state->data = blob;
+
+	ret = amdgpu_dm_update_plane_color_mgmt(f.crtc_state, plane_state,
+						f.dc_plane_state);
+	KUNIT_EXPECT_EQ(test, ret, 0);
+	KUNIT_EXPECT_TRUE(test, f.dc_plane_state->cm.flags.bits.shaper_enable);
+	KUNIT_EXPECT_EQ(test, (int)f.dc_plane_state->cm.shaper_func.type,
+			(int)TF_TYPE_DISTRIBUTED_POINTS);
+}
+
+/**
+ * dm_test_update_plane_color_mgmt_colorop_3dlut - enabled 3D LUT succeeds
+ * @test: KUnit test context
+ */
+static void dm_test_update_plane_color_mgmt_colorop_3dlut(struct kunit *test)
+{
+	static const enum drm_colorop_type types[] = {
+		DRM_COLOROP_1D_CURVE,
+		DRM_COLOROP_MULTIPLIER,
+		DRM_COLOROP_CTM_3X4,
+		DRM_COLOROP_1D_CURVE,
+		DRM_COLOROP_1D_LUT,
+		DRM_COLOROP_3D_LUT,
+		DRM_COLOROP_1D_CURVE,
+		DRM_COLOROP_1D_LUT,
+	};
+	static const enum drm_colorop_curve_1d_type curves[] = {
+		DRM_COLOROP_1D_CURVE_SRGB_EOTF,
+		DRM_COLOROP_1D_CURVE_SRGB_EOTF,
+		DRM_COLOROP_1D_CURVE_SRGB_EOTF,
+		DRM_COLOROP_1D_CURVE_SRGB_INV_EOTF,
+		DRM_COLOROP_1D_CURVE_SRGB_EOTF,
+		DRM_COLOROP_1D_CURVE_SRGB_EOTF,
+		DRM_COLOROP_1D_CURVE_SRGB_EOTF,
+		DRM_COLOROP_1D_CURVE_SRGB_EOTF,
+	};
+	static const bool bypass[] = {
+		true, true, true, true, true, false, true, true,
+	};
+	struct dm_test_color_update_fixture f = dm_test_color_update_setup(test);
+	struct drm_colorop_state *lut3d_state;
+	struct drm_plane_state *plane_state = &f.dm_plane_state->base;
+	struct drm_property_blob *blob;
+	int ret;
+
+	f.adev->dm.dc->caps.color.dpp.hw_3d_lut = true;
+	f.dm_plane_state->base.color_pipeline =
+		dm_test_colorop_pipeline_setup(test, &f, types, curves, bypass,
+					       ARRAY_SIZE(types));
+	lut3d_state = f.state->colorops[5].new_state;
+	blob = kunit_kzalloc(test, sizeof(*blob), GFP_KERNEL);
+	KUNIT_ASSERT_NOT_NULL(test, blob);
+	blob->length = 5 * sizeof(struct drm_color_lut32);
+	blob->data = kunit_kzalloc(test, blob->length, GFP_KERNEL);
+	KUNIT_ASSERT_NOT_NULL(test, blob->data);
+	lut3d_state->data = blob;
+
+	ret = amdgpu_dm_update_plane_color_mgmt(f.crtc_state, plane_state,
+						f.dc_plane_state);
+	KUNIT_EXPECT_EQ(test, ret, 0);
+	KUNIT_EXPECT_TRUE(test, f.dc_plane_state->cm.flags.bits.lut3d_enable);
+	KUNIT_EXPECT_EQ(test, (int)f.dc_plane_state->cm.shaper_func.type,
+			(int)TF_TYPE_DISTRIBUTED_POINTS);
+	KUNIT_EXPECT_EQ(test, (int)f.dc_plane_state->cm.shaper_func.tf,
+			(int)TRANSFER_FUNCTION_LINEAR);
+}
+
+/**
+ * dm_test_update_plane_color_mgmt_colorop_3dlut_no_data - empty 3D LUT falls back
+ * @test: KUnit test context
+ */
+static void dm_test_update_plane_color_mgmt_colorop_3dlut_no_data(struct kunit *test)
+{
+	static const enum drm_colorop_type types[] = {
+		DRM_COLOROP_1D_CURVE,
+		DRM_COLOROP_MULTIPLIER,
+		DRM_COLOROP_CTM_3X4,
+		DRM_COLOROP_1D_CURVE,
+		DRM_COLOROP_1D_LUT,
+		DRM_COLOROP_3D_LUT,
+		DRM_COLOROP_1D_CURVE,
+		DRM_COLOROP_1D_LUT,
+	};
+	static const enum drm_colorop_curve_1d_type curves[] = {
+		DRM_COLOROP_1D_CURVE_SRGB_EOTF,
+		DRM_COLOROP_1D_CURVE_SRGB_EOTF,
+		DRM_COLOROP_1D_CURVE_SRGB_EOTF,
+		DRM_COLOROP_1D_CURVE_SRGB_INV_EOTF,
+		DRM_COLOROP_1D_CURVE_SRGB_EOTF,
+		DRM_COLOROP_1D_CURVE_SRGB_EOTF,
+		DRM_COLOROP_1D_CURVE_SRGB_EOTF,
+		DRM_COLOROP_1D_CURVE_SRGB_EOTF,
+	};
+	static const bool bypass[] = {
+		true, true, true, true, true, false, true, true,
+	};
+	struct dm_test_color_update_fixture f = dm_test_color_update_setup(test);
+	struct drm_plane_state *plane_state = &f.dm_plane_state->base;
+	int ret;
+
+	f.adev->dm.dc->caps.color.dpp.hw_3d_lut = true;
+	f.dm_plane_state->base.color_pipeline =
+		dm_test_colorop_pipeline_setup(test, &f, types, curves, bypass,
+					       ARRAY_SIZE(types));
+
+	ret = amdgpu_dm_update_plane_color_mgmt(f.crtc_state, plane_state,
+						f.dc_plane_state);
+	KUNIT_EXPECT_EQ(test, ret, 0);
+	KUNIT_EXPECT_FALSE(test, f.dc_plane_state->cm.flags.bits.lut3d_enable);
+}
+
+/**
+ * dm_test_update_plane_color_mgmt_colorop_blend - enabled blend TF and LUT succeed
+ * @test: KUnit test context
+ */
+static void dm_test_update_plane_color_mgmt_colorop_blend(struct kunit *test)
+{
+	static const enum drm_colorop_type types[] = {
+		DRM_COLOROP_1D_CURVE,
+		DRM_COLOROP_MULTIPLIER,
+		DRM_COLOROP_CTM_3X4,
+		DRM_COLOROP_1D_CURVE,
+		DRM_COLOROP_1D_LUT,
+	};
+	static const enum drm_colorop_curve_1d_type curves[] = {
+		DRM_COLOROP_1D_CURVE_SRGB_EOTF,
+		DRM_COLOROP_1D_CURVE_SRGB_EOTF,
+		DRM_COLOROP_1D_CURVE_SRGB_EOTF,
+		DRM_COLOROP_1D_CURVE_SRGB_EOTF,
+		DRM_COLOROP_1D_CURVE_SRGB_EOTF,
+	};
+	static const bool bypass[] = { true, true, true, false, false };
+	struct dm_test_color_update_fixture f = dm_test_color_update_setup(test);
+	struct drm_colorop_state *blend_lut_state;
+	struct drm_plane_state *plane_state = &f.dm_plane_state->base;
+	struct drm_property_blob *blob;
+	int ret;
+
+	f.dm_plane_state->base.color_pipeline =
+		dm_test_colorop_pipeline_setup(test, &f, types, curves, bypass,
+					       ARRAY_SIZE(types));
+	blend_lut_state = f.state->colorops[4].new_state;
+	blob = kunit_kzalloc(test, sizeof(*blob), GFP_KERNEL);
+	KUNIT_ASSERT_NOT_NULL(test, blob);
+	blob->length = MAX_COLOR_LUT_ENTRIES * sizeof(struct drm_color_lut32);
+	blob->data = kunit_kzalloc(test, blob->length, GFP_KERNEL);
+	KUNIT_ASSERT_NOT_NULL(test, blob->data);
+	blend_lut_state->data = blob;
+
+	ret = amdgpu_dm_update_plane_color_mgmt(f.crtc_state, plane_state,
+						f.dc_plane_state);
+	KUNIT_EXPECT_EQ(test, ret, 0);
+	KUNIT_EXPECT_TRUE(test, f.dc_plane_state->cm.flags.bits.blend_enable);
+	KUNIT_EXPECT_EQ(test, (int)f.dc_plane_state->cm.blend_func.type,
+			(int)TF_TYPE_DISTRIBUTED_POINTS);
+}
+
 static struct kunit_case dm_color_test_cases[] = {
 	/* amdgpu_dm_fixpt_from_s3132 */
 	KUNIT_CASE(dm_test_fixpt_from_s3132_zero),
@@ -2819,6 +3021,10 @@ static struct kunit_case dm_color_test_cases[] = {
 	KUNIT_CASE(dm_test_update_plane_color_mgmt_colorop_missing_3x4),
 	KUNIT_CASE(dm_test_update_plane_color_mgmt_colorop_truncated),
 	KUNIT_CASE(dm_test_update_plane_color_mgmt_colorop_no_3dlut_hw),
+	KUNIT_CASE(dm_test_update_plane_color_mgmt_colorop_shaper),
+	KUNIT_CASE(dm_test_update_plane_color_mgmt_colorop_3dlut),
+	KUNIT_CASE(dm_test_update_plane_color_mgmt_colorop_3dlut_no_data),
+	KUNIT_CASE(dm_test_update_plane_color_mgmt_colorop_blend),
 	{}
 };
 
Signature · 1 line
2.53.0
#30 lore raw

PATCH 29/49 drm/amd/display: Add KUnit tests for enable_assr

In reply to Fangzhi Zuo

From: Bhawanpreet Lakha <[email protected]>

Expose enable_assr() for KUnit and cover the "DTM TA not initialized" path and the full command-build path, using the SR-IOV VF early-return to bypass psp_dtm_invoke()'s firmware submit.

---
 .../amd/display/amdgpu_dm/amdgpu_dm_hdcp.c    |   4 +-
 .../amd/display/amdgpu_dm/amdgpu_dm_hdcp.h    |   1 +
 .../amdgpu_dm/tests/amdgpu_dm_hdcp_test.c     | 138 ++++++++++++++++++
 3 files changed, 142 insertions(+), 1 deletion(-)
drivers/gpu/drm/amd/display/amdgpu_dm/amdgpu_dm_hdcp.c +3 -1
index e704b6b7fc0b..7115cc0c7746 100644
@@ -570,7 +570,8 @@ void hdcp_destroy(struct kobject *kobj, struct hdcp_workqueue *hdcp_work)
 }
 EXPORT_IF_KUNIT(hdcp_destroy);
 
-static bool enable_assr(void *handle, struct dc_link *link)
+STATIC_IFN_KUNIT
+bool enable_assr(void *handle, struct dc_link *link)
 {
 	struct hdcp_workqueue *hdcp_work = handle;
 	struct mod_hdcp hdcp = hdcp_work->hdcp;
@@ -603,6 +604,7 @@ static bool enable_assr(void *handle, struct dc_link *link)
 
 	return true;
 }
+EXPORT_IF_KUNIT(enable_assr);
 
 static void update_config(void *handle, struct cp_psp_stream_config *config)
 {
drivers/gpu/drm/amd/display/amdgpu_dm/amdgpu_dm_hdcp.h +1 -0
index a2b08bec58b5..b8ba2888a2ef 100644
@@ -123,6 +123,7 @@ void hdcp_remove_display(struct hdcp_workqueue *hdcp_work, unsigned int link_ind
 			 struct amdgpu_dm_connector *aconnector);
 uint8_t *psp_get_srm(struct psp_context *psp, uint32_t *srm_version, uint32_t *srm_size);
 int psp_set_srm(struct psp_context *psp, u8 *srm, uint32_t srm_size, uint32_t *srm_version);
+bool enable_assr(void *handle, struct dc_link *link);
 #endif
 
 #endif /* AMDGPU_DM_AMDGPU_DM_HDCP_H_ */
drivers/gpu/drm/amd/display/amdgpu_dm/tests/amdgpu_dm_hdcp_test.c +138 -0

156 lines not on this page · raw message

Signature · 1 line
2.53.0
#31 lore raw

PATCH 30/49 drm/amd/display: Add KUnit tests for update_config

In reply to Fangzhi Zuo

From: Bhawanpreet Lakha <[email protected]>

Expose update_config() for KUnit and cover the NULL connector and NULL dc_link early returns, the dpms_off removal path and the active path that builds the display/link state and registers the connector. The active path leaves the DTM TA uninitialized so add_display_to_topology() returns early without touching firmware.

---
 .../amd/display/amdgpu_dm/amdgpu_dm_hdcp.c    |   4 +-
 .../amd/display/amdgpu_dm/amdgpu_dm_hdcp.h    |   1 +
 .../amdgpu_dm/tests/amdgpu_dm_hdcp_test.c     | 144 ++++++++++++++++++
 3 files changed, 148 insertions(+), 1 deletion(-)
drivers/gpu/drm/amd/display/amdgpu_dm/amdgpu_dm_hdcp.c +3 -1
index 7115cc0c7746..560bfa43dc8a 100644
@@ -606,7 +606,8 @@ bool enable_assr(void *handle, struct dc_link *link)
 }
 EXPORT_IF_KUNIT(enable_assr);
 
-static void update_config(void *handle, struct cp_psp_stream_config *config)
+STATIC_IFN_KUNIT
+void update_config(void *handle, struct cp_psp_stream_config *config)
 {
 	struct hdcp_workqueue *hdcp_work = handle;
 	struct amdgpu_dm_connector *aconnector;
@@ -692,6 +693,7 @@ static void update_config(void *handle, struct cp_psp_stream_config *config)
 	hdcp_w->aconnector[conn_index] = aconnector;
 	process_output(hdcp_w);
 }
+EXPORT_IF_KUNIT(update_config);
 
 /**
  * DOC: Add sysfs interface for set/get srm
drivers/gpu/drm/amd/display/amdgpu_dm/amdgpu_dm_hdcp.h +1 -0
index b8ba2888a2ef..30c1e7b1af1a 100644
@@ -124,6 +124,7 @@ void hdcp_remove_display(struct hdcp_workqueue *hdcp_work, unsigned int link_ind
 uint8_t *psp_get_srm(struct psp_context *psp, uint32_t *srm_version, uint32_t *srm_size);
 int psp_set_srm(struct psp_context *psp, u8 *srm, uint32_t srm_size, uint32_t *srm_version);
 bool enable_assr(void *handle, struct dc_link *link);
+void update_config(void *handle, struct cp_psp_stream_config *config);
 #endif
 
 #endif /* AMDGPU_DM_AMDGPU_DM_HDCP_H_ */
drivers/gpu/drm/amd/display/amdgpu_dm/tests/amdgpu_dm_hdcp_test.c +144 -0

156 lines not on this page · raw message

Signature · 1 line
2.53.0
#32 lore raw

PATCH 31/49 drm/amd/display: Add KUnit tests for hdcp_create_workqueue

In reply to Fangzhi Zuo

From: Bhawanpreet Lakha <[email protected]>

Cover the success path of hdcp_create_workqueue(): the workqueue and SRM buffers are allocated, max_link is recorded, the cp_psp callbacks and handle are published and every link's psp handle points at the device psp. Also cover the dtm_v3_supported branch (set for DCN 3.1, clear otherwise) and the init loop running for more than one link, alongside the existing zero-link early-return case.

---
 .../amdgpu_dm/tests/amdgpu_dm_hdcp_test.c     | 103 ++++++++++++++++++
 1 file changed, 103 insertions(+)
drivers/gpu/drm/amd/display/amdgpu_dm/tests/amdgpu_dm_hdcp_test.c +103 -0
index b75fadd4e14e..d95babb73711 100644
@@ -1010,6 +1010,106 @@ static void dm_test_hdcp_create_workqueue_zero_max_links_returns_null(struct kun
 	KUNIT_EXPECT_PTR_EQ(test, work, NULL);
 }
 
+/**
+ * dm_test_hdcp_create_workqueue_initializes_work - success path wires everything up
+ * @test: KUnit test context
+ *
+ * With a single link, hdcp_create_workqueue() must allocate the workqueue and
+ * both SRM buffers, record max_link, publish the cp_psp callbacks and handle,
+ * and point every link's psp handle at the device psp. A non-matching
+ * dce_version must leave dtm_v3_supported clear. hdcp_destroy() is used to
+ * tear the workqueue down (it also removes the SRM sysfs file created on the
+ * device kobject).
+ */
+static void dm_test_hdcp_create_workqueue_initializes_work(struct kunit *test)
+{
+	struct amdgpu_device *adev = dm_kunit_alloc_adev(test);
+	struct cp_psp cp_psp = {0};
+	struct dc *dc = dm_kunit_alloc_dc_with_ctx(test);
+	struct hdcp_workqueue *work;
+
+	/* sysfs_create_bin_file() needs a real device kobject. */
+	adev->dev = adev->ddev.dev;
+	dc->caps.max_links = 1;
+	/* DCE_VERSION_UNKNOWN (0) is not in the DTM v3 list. */
+	dc->ctx->dce_version = DCE_VERSION_UNKNOWN;
+
+	work = hdcp_create_workqueue(adev, &cp_psp, dc);
+
+	KUNIT_ASSERT_NOT_NULL(test, work);
+	KUNIT_EXPECT_EQ(test, work->max_link, 1);
+	KUNIT_EXPECT_NOT_NULL(test, work->srm);
+	KUNIT_EXPECT_NOT_NULL(test, work->srm_temp);
+	KUNIT_EXPECT_PTR_EQ(test, (void *)cp_psp.funcs.update_stream_config,
+			    (void *)update_config);
+	KUNIT_EXPECT_PTR_EQ(test, (void *)cp_psp.funcs.enable_assr,
+			    (void *)enable_assr);
+	KUNIT_EXPECT_PTR_EQ(test, cp_psp.handle, work);
+	KUNIT_EXPECT_PTR_EQ(test, work[0].hdcp.config.psp.handle, &adev->psp);
+	KUNIT_EXPECT_EQ(test, work[0].hdcp.config.psp.caps.dtm_v3_supported, 0);
+
+	hdcp_destroy(&adev->dev->kobj, work);
+}
+
+/**
+ * dm_test_hdcp_create_workqueue_sets_dtm_v3_for_dcn31 - DCN 3.1 enables DTM v3
+ * @test: KUnit test context
+ *
+ * On a DCN 3.1 device, hdcp_create_workqueue() must set the per-link
+ * dtm_v3_supported cap; an unmatched dce_version must leave it clear.
+ */
+static void dm_test_hdcp_create_workqueue_sets_dtm_v3_for_dcn31(struct kunit *test)
+{
+	struct amdgpu_device *adev = dm_kunit_alloc_adev(test);
+	struct cp_psp cp_psp = {0};
+	struct dc *dc = dm_kunit_alloc_dc_with_ctx(test);
+	struct hdcp_workqueue *work;
+
+	adev->dev = adev->ddev.dev;
+	dc->caps.max_links = 1;
+	dc->ctx->dce_version = DCN_VERSION_3_1;
+
+	work = hdcp_create_workqueue(adev, &cp_psp, dc);
+
+	KUNIT_ASSERT_NOT_NULL(test, work);
+	KUNIT_EXPECT_EQ(test, work[0].hdcp.config.psp.caps.dtm_v3_supported, 1);
+
+	hdcp_destroy(&adev->dev->kobj, work);
+}
+
+/**
+ * dm_test_hdcp_create_workqueue_initializes_all_links - loop covers every link
+ * @test: KUnit test context
+ *
+ * With more than one link, hdcp_create_workqueue() must run its init loop for
+ * every entry: each link records max_link, points its psp handle at the device
+ * psp and gets the DTM v3 cap set for a matching dce_version.
+ */
+static void dm_test_hdcp_create_workqueue_initializes_all_links(struct kunit *test)
+{
+	struct amdgpu_device *adev = dm_kunit_alloc_adev(test);
+	struct cp_psp cp_psp = {0};
+	struct dc *dc = dm_kunit_alloc_dc_with_ctx(test);
+	struct hdcp_workqueue *work;
+	int i;
+
+	adev->dev = adev->ddev.dev;
+	dc->caps.max_links = 3;
+	dc->ctx->dce_version = DCN_VERSION_3_1;
+
+	work = hdcp_create_workqueue(adev, &cp_psp, dc);
+
+	KUNIT_ASSERT_NOT_NULL(test, work);
+	KUNIT_EXPECT_EQ(test, work->max_link, 3);
+	for (i = 0; i < 3; i++) {
+		KUNIT_EXPECT_PTR_EQ(test, work[i].hdcp.config.psp.handle,
+				    &adev->psp);
+		KUNIT_EXPECT_EQ(test, work[i].hdcp.config.psp.caps.dtm_v3_supported, 1);
+	}
+
+	hdcp_destroy(&adev->dev->kobj, work);
+}
+
 /* End of tests for hdcp_create_workqueue() */
 
 /* Tests for hdcp_destroy() */
@@ -1765,6 +1865,9 @@ static struct kunit_case dm_hdcp_test_cases[] = {
 	KUNIT_CASE(dm_test_hdcp_update_display_disable_resets_status_and_cancels_validate),
 	/* hdcp_create_workqueue() */
 	KUNIT_CASE(dm_test_hdcp_create_workqueue_zero_max_links_returns_null),
+	KUNIT_CASE(dm_test_hdcp_create_workqueue_initializes_work),
+	KUNIT_CASE(dm_test_hdcp_create_workqueue_sets_dtm_v3_for_dcn31),
+	KUNIT_CASE(dm_test_hdcp_create_workqueue_initializes_all_links),
 	/* hdcp_destroy() */
 	KUNIT_CASE(dm_test_hdcp_destroy_frees_and_removes_sysfs),
 	KUNIT_CASE(dm_test_hdcp_destroy_zero_links_null_srm),
Signature · 1 line
2.53.0
#33 lore raw

PATCH 32/49 drm/amd/display: Add KUnit tests for srm_data_write and srm_data_read

In reply to Fangzhi Zuo

From: Bhawanpreet Lakha <[email protected]>

Expose srm_data_write() and srm_data_read() for KUnit and add tests covering the sysfs SRM write/read paths:

- write stages the buffer into srm_temp and returns count; with the TA uninitialized psp_set_srm() fails so the committed SRM is unchanged
- read returns -EINVAL when psp_get_srm() returns NULL (TA uninitialized)
- read returns 0 for an empty SRM using the SR-IOV VF bypass so psp_hdcp_invoke() is a no-op and psp_get_srm() returns a non-NULL buffer

---
 .../amd/display/amdgpu_dm/amdgpu_dm_hdcp.c    |   6 +-
 .../amd/display/amdgpu_dm/amdgpu_dm_hdcp.h    |   9 ++
 .../amdgpu_dm/tests/amdgpu_dm_hdcp_test.c     | 117 ++++++++++++++++++
 3 files changed, 130 insertions(+), 2 deletions(-)
drivers/gpu/drm/amd/display/amdgpu_dm/amdgpu_dm_hdcp.c +4 -2
index 560bfa43dc8a..9ea0a120af6f 100644
@@ -743,7 +743,7 @@ EXPORT_IF_KUNIT(update_config);
  *	-if we try to "1. SET" a newer version and PSP rejects it. That means the format is
  *	incorrect/corrupted and we should correct our SRM by getting it from PSP
  */
-static ssize_t srm_data_write(struct file *filp, struct kobject *kobj,
+STATIC_IFN_KUNIT ssize_t srm_data_write(struct file *filp, struct kobject *kobj,
 			      const struct bin_attribute *bin_attr, char *buffer,
 			      loff_t pos, size_t count)
 {
@@ -766,8 +766,9 @@ static ssize_t srm_data_write(struct file *filp, struct kobject *kobj,
 
 	return count;
 }
+EXPORT_IF_KUNIT(srm_data_write);
 
-static ssize_t srm_data_read(struct file *filp, struct kobject *kobj,
+STATIC_IFN_KUNIT ssize_t srm_data_read(struct file *filp, struct kobject *kobj,
 			     const struct bin_attribute *bin_attr, char *buffer,
 			     loff_t pos, size_t count)
 {
@@ -803,6 +804,7 @@ static ssize_t srm_data_read(struct file *filp, struct kobject *kobj,
 	link_lock(work, false);
 	return ret;
 }
+EXPORT_IF_KUNIT(srm_data_read);
 
 /* From the hdcp spec (5.Renewability) SRM needs to be stored in a non-volatile memory.
  *
drivers/gpu/drm/amd/display/amdgpu_dm/amdgpu_dm_hdcp.h +9 -0
index 30c1e7b1af1a..e700d019f971 100644
@@ -45,6 +45,9 @@ struct mod_hdcp_display;
 struct cp_psp;
 struct amdgpu_device;
 struct psp_context;
+struct file;
+struct kobject;
+struct bin_attribute;
 
 struct hdcp_workqueue {
 	struct work_struct cpirq_work;
@@ -125,6 +128,12 @@ uint8_t *psp_get_srm(struct psp_context *psp, uint32_t *srm_version, uint32_t *s
 int psp_set_srm(struct psp_context *psp, u8 *srm, uint32_t srm_size, uint32_t *srm_version);
 bool enable_assr(void *handle, struct dc_link *link);
 void update_config(void *handle, struct cp_psp_stream_config *config);
+ssize_t srm_data_write(struct file *filp, struct kobject *kobj,
+		       const struct bin_attribute *bin_attr, char *buffer,
+		       loff_t pos, size_t count);
+ssize_t srm_data_read(struct file *filp, struct kobject *kobj,
+		      const struct bin_attribute *bin_attr, char *buffer,
+		      loff_t pos, size_t count);
 #endif
 
 #endif /* AMDGPU_DM_AMDGPU_DM_HDCP_H_ */
drivers/gpu/drm/amd/display/amdgpu_dm/tests/amdgpu_dm_hdcp_test.c +117 -0

129 lines not on this page · raw message

Signature · 1 line
2.53.0
#34 lore raw

PATCH 33/49 drm/amd/display: Add KUnit tests for HDCP DDC link adapters

In reply to Fangzhi Zuo

From: Bhawanpreet Lakha <[email protected]>

Expose the mod_hdcp DDC adapter callbacks for KUnit and add tests:

lp_write_i2c / lp_read_i2c / lp_write_dpcd / lp_read_dpcd use recording fake i2c and DP aux backends to assert the built payloads (write flag, address, length, buffer, and the read offset-then-data sequence), plus failure when the connector is missing.

lp_atomic_write_poll_read_i2c / lp_atomic_write_poll_read_aux cover the hardware-free early returns (NULL link and a payload too large to convert); the success path submits fused-IO to the DMCUB and is out of reach for a unit test.

---
 .../amd/display/amdgpu_dm/amdgpu_dm_hdcp.c    |  50 +--
 .../amd/display/amdgpu_dm/amdgpu_dm_hdcp.h    |  16 +
 .../amdgpu_dm/tests/amdgpu_dm_hdcp_test.c     | 378 ++++++++++++++++++
 3 files changed, 420 insertions(+), 24 deletions(-)
drivers/gpu/drm/amd/display/amdgpu_dm/amdgpu_dm_hdcp.c +26 -24
index 9ea0a120af6f..c887a70ae74d 100644
@@ -38,8 +38,7 @@
  */
 #define PSP_SRM_VERSION_MAX 0xFFFF
 
-static bool
-lp_write_i2c(void *handle, uint32_t address, const uint8_t *data, uint32_t size)
+STATIC_IFN_KUNIT bool lp_write_i2c(void *handle, uint32_t address, const uint8_t *data, uint32_t size)
 {
 	struct dc_link *link = handle;
 	struct i2c_payload i2c_payloads[] = {{true, address, size, (void *)data} };
@@ -48,9 +47,9 @@ lp_write_i2c(void *handle, uint32_t address, const uint8_t *data, uint32_t size)
 
 	return dm_helpers_submit_i2c(link->ctx, link, &cmd);
 }
+EXPORT_IF_KUNIT(lp_write_i2c);
 
-static bool
-lp_read_i2c(void *handle, uint32_t address, uint8_t offset, uint8_t *data, uint32_t size)
+STATIC_IFN_KUNIT bool lp_read_i2c(void *handle, uint32_t address, uint8_t offset, uint8_t *data, uint32_t size)
 {
 	struct dc_link *link = handle;
 
@@ -61,50 +60,53 @@ lp_read_i2c(void *handle, uint32_t address, uint8_t offset, uint8_t *data, uint3
 
 	return dm_helpers_submit_i2c(link->ctx, link, &cmd);
 }
+EXPORT_IF_KUNIT(lp_read_i2c);
 
-static bool
-lp_write_dpcd(void *handle, uint32_t address, const uint8_t *data, uint32_t size)
+STATIC_IFN_KUNIT bool lp_write_dpcd(void *handle, uint32_t address, const uint8_t *data, uint32_t size)
 {
 	struct dc_link *link = handle;
 
 	return dm_helpers_dp_write_dpcd(link->ctx, link, address, data, size);
 }
+EXPORT_IF_KUNIT(lp_write_dpcd);
 
-static bool
-lp_read_dpcd(void *handle, uint32_t address, uint8_t *data, uint32_t size)
+STATIC_IFN_KUNIT bool lp_read_dpcd(void *handle, uint32_t address, uint8_t *data, uint32_t size)
 {
 	struct dc_link *link = handle;
 
 	return dm_helpers_dp_read_dpcd(link->ctx, link, address, data, size);
 }
-
-static bool lp_atomic_write_poll_read_i2c(
-		void *handle,
-		const struct mod_hdcp_atomic_op_i2c *write,
-		const struct mod_hdcp_atomic_op_i2c *poll,
-		struct mod_hdcp_atomic_op_i2c *read,
-		uint32_t poll_timeout_us,
-		uint8_t poll_mask_msb
+EXPORT_IF_KUNIT(lp_read_dpcd);
+
+STATIC_IFN_KUNIT bool lp_atomic_write_poll_read_i2c(
+						void *handle,
+						const struct mod_hdcp_atomic_op_i2c *write,
+						const struct mod_hdcp_atomic_op_i2c *poll,
+						struct mod_hdcp_atomic_op_i2c *read,
+						uint32_t poll_timeout_us,
+						uint8_t poll_mask_msb
 )
 {
 	struct dc_link *link = handle;
 
 	return dm_atomic_write_poll_read_i2c(link, write, poll, read, poll_timeout_us, poll_mask_msb);
 }
-
-static bool lp_atomic_write_poll_read_aux(
-		void *handle,
-		const struct mod_hdcp_atomic_op_aux *write,
-		const struct mod_hdcp_atomic_op_aux *poll,
-		struct mod_hdcp_atomic_op_aux *read,
-		uint32_t poll_timeout_us,
-		uint8_t poll_mask_msb
+EXPORT_IF_KUNIT(lp_atomic_write_poll_read_i2c);
+
+STATIC_IFN_KUNIT bool lp_atomic_write_poll_read_aux(
+						void *handle,
+						const struct mod_hdcp_atomic_op_aux *write,
+						const struct mod_hdcp_atomic_op_aux *poll,
+						struct mod_hdcp_atomic_op_aux *read,
+						uint32_t poll_timeout_us,
+						uint8_t poll_mask_msb
 )
 {
 	struct dc_link *link = handle;
 
 	return dm_atomic_write_poll_read_aux(link, write, poll, read, poll_timeout_us, poll_mask_msb);
 }
+EXPORT_IF_KUNIT(lp_atomic_write_poll_read_aux);
 
 STATIC_IFN_KUNIT
 uint8_t *psp_get_srm(struct psp_context *psp, uint32_t *srm_version, uint32_t *srm_size)
drivers/gpu/drm/amd/display/amdgpu_dm/amdgpu_dm_hdcp.h +16 -0
index e700d019f971..665fa4839a25 100644
@@ -48,6 +48,8 @@ struct psp_context;
 struct file;
 struct kobject;
 struct bin_attribute;
+struct mod_hdcp_atomic_op_i2c;
+struct mod_hdcp_atomic_op_aux;
 
 struct hdcp_workqueue {
 	struct work_struct cpirq_work;
@@ -134,6 +136,20 @@ ssize_t srm_data_write(struct file *filp, struct kobject *kobj,
 ssize_t srm_data_read(struct file *filp, struct kobject *kobj,
 		      const struct bin_attribute *bin_attr, char *buffer,
 		      loff_t pos, size_t count);
+bool lp_write_i2c(void *handle, uint32_t address, const uint8_t *data, uint32_t size);
+bool lp_read_i2c(void *handle, uint32_t address, uint8_t offset, uint8_t *data, uint32_t size);
+bool lp_write_dpcd(void *handle, uint32_t address, const uint8_t *data, uint32_t size);
+bool lp_read_dpcd(void *handle, uint32_t address, uint8_t *data, uint32_t size);
+bool lp_atomic_write_poll_read_i2c(void *handle,
+				   const struct mod_hdcp_atomic_op_i2c *write,
+				   const struct mod_hdcp_atomic_op_i2c *poll,
+				   struct mod_hdcp_atomic_op_i2c *read,
+				   uint32_t poll_timeout_us, uint8_t poll_mask_msb);
+bool lp_atomic_write_poll_read_aux(void *handle,
+				   const struct mod_hdcp_atomic_op_aux *write,
+				   const struct mod_hdcp_atomic_op_aux *poll,
+				   struct mod_hdcp_atomic_op_aux *read,
+				   uint32_t poll_timeout_us, uint8_t poll_mask_msb);
 #endif
 
 #endif /* AMDGPU_DM_AMDGPU_DM_HDCP_H_ */
drivers/gpu/drm/amd/display/amdgpu_dm/tests/amdgpu_dm_hdcp_test.c +378 -0

396 lines not on this page · raw message

Signature · 1 line
2.53.0
#35 lore raw

PATCH 34/49 drm/amd/display: Add initialized-branch test for psp_set_srm

In reply to Fangzhi Zuo

From: Bhawanpreet Lakha <[email protected]>

Cover the initialized path of psp_set_srm() using the SR-IOV VF bypass so psp_hdcp_invoke() is a no-op. The test asserts the SET_SRM command is staged (cmd_id, srm_buf_size and the copied SRM bytes) and that response validation fails on the zeroed reply, returning -EINVAL without updating srm_version.

---
 .../amdgpu_dm/tests/amdgpu_dm_hdcp_test.c     | 47 +++++++++++++++++++
 1 file changed, 47 insertions(+)
drivers/gpu/drm/amd/display/amdgpu_dm/tests/amdgpu_dm_hdcp_test.c +47 -0
index 838826d274c2..b359ba5d524b 100644
@@ -1349,6 +1349,52 @@ static void dm_test_psp_set_srm_uninitialized_returns_einval(struct kunit *test)
 	KUNIT_EXPECT_EQ(test, srm_version, 0xdead);
 }
 
+/**
+ * dm_test_psp_set_srm_initialized_stages_command - initialized path builds the command
+ * @test: KUnit test context
+ *
+ * With an initialized TA and the SR-IOV VF bypass, psp_hdcp_invoke() is a
+ * no-op, so the shared command buffer keeps the values psp_set_srm() staged.
+ * The function must copy the SRM into the SET_SRM in-message, record its size
+ * and command id, and then fail the response validation (the zeroed reply has
+ * valid_signature == 0), returning -EINVAL without updating srm_version.
+ */
+static void dm_test_psp_set_srm_initialized_stages_command(struct kunit *test)
+{
+	struct amdgpu_device *adev = dm_kunit_alloc_adev(test);
+	struct ta_hdcp_shared_memory *hdcp_cmd;
+	struct psp_context *psp;
+	uint32_t srm_version = 0xdead;
+	u8 srm_buf[4] = {0x1, 0x2, 0x3, 0x4};
+	int ret;
+
+	KUNIT_ASSERT_NOT_NULL(test, adev);
+
+	psp = kunit_kzalloc(test, sizeof(*psp), GFP_KERNEL);
+	KUNIT_ASSERT_NOT_NULL(test, psp);
+	hdcp_cmd = kunit_kzalloc(test, sizeof(*hdcp_cmd), GFP_KERNEL);
+	KUNIT_ASSERT_NOT_NULL(test, hdcp_cmd);
+
+	psp->adev = adev;
+	psp->hdcp_context.context.initialized = true;
+	psp->hdcp_context.context.mem_context.shared_buf = (uint8_t *)hdcp_cmd;
+
+	/* SR-IOV VF makes psp_hdcp_invoke() return early without firmware. */
+	adev->virt.caps |= AMDGPU_SRIOV_CAPS_IS_VF;
+
+	ret = psp_set_srm(psp, srm_buf, sizeof(srm_buf), &srm_version);
+
+	/* Response validation fails (valid_signature == 0 in the zeroed reply). */
+	KUNIT_EXPECT_EQ(test, ret, -EINVAL);
+	KUNIT_EXPECT_EQ(test, srm_version, 0xdead);
+	/* The initialized path must have staged the SET_SRM command. */
+	KUNIT_EXPECT_EQ(test, hdcp_cmd->cmd_id, TA_HDCP_COMMAND__HDCP_SET_SRM);
+	KUNIT_EXPECT_EQ(test, hdcp_cmd->in_msg.hdcp_set_srm.srm_buf_size,
+			(uint32_t)sizeof(srm_buf));
+	KUNIT_EXPECT_MEMEQ(test, hdcp_cmd->in_msg.hdcp_set_srm.srm_buf, srm_buf,
+			   sizeof(srm_buf));
+}
+
 /* End of tests for psp_get_srm() and psp_set_srm() */
 
 /* Tests for srm_data_write() and srm_data_read() */
@@ -2356,6 +2402,7 @@ static struct kunit_case dm_hdcp_test_cases[] = {
 	/* psp_get_srm() / psp_set_srm() */
 	KUNIT_CASE(dm_test_psp_get_srm_uninitialized_returns_null),
 	KUNIT_CASE(dm_test_psp_set_srm_uninitialized_returns_einval),
+	KUNIT_CASE(dm_test_psp_set_srm_initialized_stages_command),
 	/* srm_data_write() / srm_data_read() */
 	KUNIT_CASE(dm_test_srm_data_write_uninitialized_ta_keeps_srm),
 	KUNIT_CASE(dm_test_srm_data_read_uninitialized_ta_returns_einval),
Signature · 1 line
2.53.0
#36 lore raw

PATCH 35/49 drm/amd/display: Add deeper event_property_update tests

In reply to Fangzhi Zuo

From: Bhawanpreet Lakha <[email protected]>

Expand KUnit coverage for event_property_update() beyond the null connector skip. Add cases for the disconnected, missing-state and missing-device skip branches, plus the fully connected path where hdcp_get_content_protection_from_status() maps HDCP_OFF to DESIRED and HDCP1 TYPE0 encryption to ENABLED.

The connected-path tests use dm_kunit_alloc_adev() so the drm_device has an initialised mode_config connection_mutex, and pre-set the connector state to the expected content protection value so drm_hdcp_update_content_protection() takes its no-change early return.

---
 .../amdgpu_dm/tests/amdgpu_dm_hdcp_test.c     | 174 +++++++++++++++++-
 1 file changed, 173 insertions(+), 1 deletion(-)
drivers/gpu/drm/amd/display/amdgpu_dm/tests/amdgpu_dm_hdcp_test.c +173 -1
index b359ba5d524b..cfdcc44581b1 100644
@@ -473,7 +473,8 @@ static void dm_test_process_output_watchdog_stop_and_needed_requeues(struct kuni
  * @test: KUnit test context for managed allocation
  *
  * Allocates a minimal hdcp_workqueue with property_update_work initialised
- * so event_property_update() can resolve container_of() safely.
+ * so event_property_update() can resolve container_of() safely. The mutex is
+ * initialised as well because the connected path takes guard(mutex).
  */
 static struct hdcp_workqueue *alloc_test_workqueue_for_property_update(struct kunit *test)
 {
@@ -482,11 +483,41 @@ static struct hdcp_workqueue *alloc_test_workqueue_for_property_update(struct ku
 	work = kunit_kzalloc(test, sizeof(*work), GFP_KERNEL);
 	KUNIT_ASSERT_NOT_NULL(test, work);
 
+	mutex_init(&work->mutex);
 	INIT_WORK(&work->property_update_work, dummy_work_fn);
 
 	return work;
 }
 
+/**
+ * alloc_update_connector - connector for event_property_update() tests
+ * @test: KUnit test context for managed allocation
+ * @status: drm connector detection status to assign
+ * @conn_state: drm_connector_state to attach (may be NULL)
+ * @dev: drm_device to attach as connector->dev (may be NULL)
+ *
+ * Allocates an amdgpu_dm_connector wired for the traversal in
+ * event_property_update(). The caller supplies the state and device so the
+ * various skip branches (disconnected, no state, no device) and the fully
+ * connected path can all be exercised.
+ */
+static struct amdgpu_dm_connector *alloc_update_connector(struct kunit *test,
+							  enum drm_connector_status status,
+							  struct drm_connector_state *conn_state,
+							  struct drm_device *dev)
+{
+	struct amdgpu_dm_connector *aconnector;
+
+	aconnector = kunit_kzalloc(test, sizeof(*aconnector), GFP_KERNEL);
+	KUNIT_ASSERT_NOT_NULL(test, aconnector);
+
+	aconnector->base.status = status;
+	aconnector->base.state = conn_state;
+	aconnector->base.dev = dev;
+
+	return aconnector;
+}
+
 /**
  * dm_test_event_property_update_skips_null_connector - null connector is ignored
  * @test: KUnit test context
@@ -507,6 +538,142 @@ static void dm_test_event_property_update_skips_null_connector(struct kunit *tes
 	KUNIT_EXPECT_EQ(test, work->encryption_status[0], before);
 }
 
+/**
+ * dm_test_event_property_update_skips_disconnected - disconnected is skipped
+ * @test: KUnit test context
+ *
+ * A connector whose status is not connector_status_connected must be skipped
+ * before any modeset lock is taken, leaving encryption_status untouched.
+ */
+static void dm_test_event_property_update_skips_disconnected(struct kunit *test)
+{
+	struct hdcp_workqueue *work = alloc_test_workqueue_for_property_update(test);
+	struct drm_connector_state *conn_state;
+
+	conn_state = kunit_kzalloc(test, sizeof(*conn_state), GFP_KERNEL);
+	KUNIT_ASSERT_NOT_NULL(test, conn_state);
+
+	work->aconnector[1] = alloc_update_connector(test, connector_status_disconnected,
+						     conn_state, NULL);
+	work->encryption_status[1] = MOD_HDCP_ENCRYPTION_STATUS_HDCP2_TYPE1_ON;
+
+	event_property_update(&work->property_update_work);
+
+	KUNIT_EXPECT_EQ(test, work->encryption_status[1],
+			MOD_HDCP_ENCRYPTION_STATUS_HDCP2_TYPE1_ON);
+}
+
+/**
+ * dm_test_event_property_update_skips_null_state - missing state is skipped
+ * @test: KUnit test context
+ *
+ * A connected connector without a drm_connector_state must be skipped before
+ * the modeset lock, leaving encryption_status unchanged.
+ */
+static void dm_test_event_property_update_skips_null_state(struct kunit *test)
+{
+	struct hdcp_workqueue *work = alloc_test_workqueue_for_property_update(test);
+
+	work->aconnector[2] = alloc_update_connector(test, connector_status_connected,
+						     NULL, NULL);
+	work->encryption_status[2] = MOD_HDCP_ENCRYPTION_STATUS_HDCP2_TYPE1_ON;
+
+	event_property_update(&work->property_update_work);
+
+	KUNIT_EXPECT_EQ(test, work->encryption_status[2],
+			MOD_HDCP_ENCRYPTION_STATUS_HDCP2_TYPE1_ON);
+}
+
+/**
+ * dm_test_event_property_update_skips_null_dev - missing device is skipped
+ * @test: KUnit test context
+ *
+ * A connected connector with state but no drm_device must be skipped before
+ * the modeset lock, leaving encryption_status unchanged.
+ */
+static void dm_test_event_property_update_skips_null_dev(struct kunit *test)
+{
+	struct hdcp_workqueue *work = alloc_test_workqueue_for_property_update(test);
+	struct drm_connector_state *conn_state;
+
+	conn_state = kunit_kzalloc(test, sizeof(*conn_state), GFP_KERNEL);
+	KUNIT_ASSERT_NOT_NULL(test, conn_state);
+
+	work->aconnector[3] = alloc_update_connector(test, connector_status_connected,
+						     conn_state, NULL);
+	work->encryption_status[3] = MOD_HDCP_ENCRYPTION_STATUS_HDCP2_TYPE1_ON;
+
+	event_property_update(&work->property_update_work);
+
+	KUNIT_EXPECT_EQ(test, work->encryption_status[3],
+			MOD_HDCP_ENCRYPTION_STATUS_HDCP2_TYPE1_ON);
+}
+
+/**
+ * dm_test_event_property_update_desired_when_off - HDCP off maps to DESIRED
+ * @test: KUnit test context
+ *
+ * A fully connected display with HDCP_OFF encryption drives the connected
+ * path: the modeset lock is taken, hdcp_get_content_protection_from_status()
+ * reports DRM_MODE_CONTENT_PROTECTION_DESIRED and
+ * drm_hdcp_update_content_protection() is called. The connector state is
+ * pre-set to DESIRED so the value is unchanged (no sysfs event) and the deep
+ * path completes cleanly.
+ */
+static void dm_test_event_property_update_desired_when_off(struct kunit *test)
+{
+	struct amdgpu_device *adev = dm_kunit_alloc_adev(test);
+	struct hdcp_workqueue *work = alloc_test_workqueue_for_property_update(test);
+	struct drm_connector_state *conn_state;
+
+	conn_state = kunit_kzalloc(test, sizeof(*conn_state), GFP_KERNEL);
+	KUNIT_ASSERT_NOT_NULL(test, conn_state);
+	conn_state->content_protection = DRM_MODE_CONTENT_PROTECTION_DESIRED;
+
+	work->aconnector[0] = alloc_update_connector(test, connector_status_connected,
+						     conn_state, &adev->ddev);
+	work->encryption_status[0] = MOD_HDCP_ENCRYPTION_STATUS_HDCP_OFF;
+
+	event_property_update(&work->property_update_work);
+
+	KUNIT_EXPECT_EQ(test, conn_state->content_protection,
+			(unsigned int)DRM_MODE_CONTENT_PROTECTION_DESIRED);
+	KUNIT_EXPECT_EQ(test, work->encryption_status[0],
+			MOD_HDCP_ENCRYPTION_STATUS_HDCP_OFF);
+}
+
+/**
+ * dm_test_event_property_update_enabled_when_encrypted - encrypted maps to ENABLED
+ * @test: KUnit test context
+ *
+ * A fully connected display with TYPE0 content and HDCP1 encryption drives
+ * the connected path where hdcp_get_content_protection_from_status() reports
+ * DRM_MODE_CONTENT_PROTECTION_ENABLED. The connector state is pre-set to
+ * ENABLED so drm_hdcp_update_content_protection() leaves it unchanged.
+ */
+static void dm_test_event_property_update_enabled_when_encrypted(struct kunit *test)
+{
+	struct amdgpu_device *adev = dm_kunit_alloc_adev(test);
+	struct hdcp_workqueue *work = alloc_test_workqueue_for_property_update(test);
+	struct drm_connector_state *conn_state;
+
+	conn_state = kunit_kzalloc(test, sizeof(*conn_state), GFP_KERNEL);
+	KUNIT_ASSERT_NOT_NULL(test, conn_state);
+	conn_state->hdcp_content_type = DRM_MODE_HDCP_CONTENT_TYPE0;
+	conn_state->content_protection = DRM_MODE_CONTENT_PROTECTION_ENABLED;
+
+	work->aconnector[0] = alloc_update_connector(test, connector_status_connected,
+						     conn_state, &adev->ddev);
+	work->encryption_status[0] = MOD_HDCP_ENCRYPTION_STATUS_HDCP1_ON;
+
+	event_property_update(&work->property_update_work);
+
+	KUNIT_EXPECT_EQ(test, conn_state->content_protection,
+			(unsigned int)DRM_MODE_CONTENT_PROTECTION_ENABLED);
+	KUNIT_EXPECT_EQ(test, work->encryption_status[0],
+			MOD_HDCP_ENCRYPTION_STATUS_HDCP1_ON);
+}
+
 /* End of tests for event_property_update() */
 
 /* Tests for event_callback() */
@@ -2367,6 +2534,11 @@ static struct kunit_case dm_hdcp_test_cases[] = {
 	KUNIT_CASE(dm_test_process_output_watchdog_stop_and_needed_requeues),
 	/* event_property_update() */
 	KUNIT_CASE(dm_test_event_property_update_skips_null_connector),
+	KUNIT_CASE(dm_test_event_property_update_skips_disconnected),
+	KUNIT_CASE(dm_test_event_property_update_skips_null_state),
+	KUNIT_CASE(dm_test_event_property_update_skips_null_dev),
+	KUNIT_CASE(dm_test_event_property_update_desired_when_off),
+	KUNIT_CASE(dm_test_event_property_update_enabled_when_encrypted),
 	/* event_callback() */
 	KUNIT_CASE(dm_test_event_callback_cancels_callback_dwork),
 	KUNIT_CASE(dm_test_event_callback_schedules_property_validate),
Signature · 1 line
2.53.0
#37 lore raw

PATCH 36/49 drm/amd/display: adjust floating point format for gamut remap when needed

In reply to Fangzhi Zuo

From: Clay King <[email protected]>

[Why]
The MPCCs different gamut remap matrices allow for S2D13 and S3D12 floating point formats, but only S2D13 is used. There may be cases where more integer bits are required.

[How]
Switch to S3D12 if any entries in the remap matrix cannot fit in S2D13. Otherwise, prefer the extra precision of S2D13. Communicate the max value that hw can support to dm via dc color caps.

---
 .../drm/amd/display/dc/basics/conversion.c    | 61 +++++++++++-----
 .../drm/amd/display/dc/basics/conversion.h    | 12 +++-
 drivers/gpu/drm/amd/display/dc/dc.h           |  1 +
 .../drm/amd/display/dc/dce/dce_transform.c    |  4 +-
 .../amd/display/dc/dpp/dcn10/dcn10_dpp_cm.c   |  8 +--
 .../amd/display/dc/dpp/dcn20/dcn20_dpp_cm.c   |  8 +--
 .../amd/display/dc/dpp/dcn30/dcn30_dpp_cm.c   |  8 +--
 .../amd/display/dc/dwb/dcn30/dcn30_dwb_cm.c   |  3 +-
 .../drm/amd/display/dc/mpc/dcn30/dcn30_mpc.c  | 44 ++++++++----
 .../amd/display/dc/mpc/dcn401/dcn401_mpc.c    | 69 +++++++++++++------
 .../amd/display/dc/mpc/dcn401/dcn401_mpc.h    |  6 +-
 .../dc/resource/dcn30/dcn30_resource.c        |  2 +
 .../dc/resource/dcn301/dcn301_resource.c      |  2 +
 .../dc/resource/dcn302/dcn302_resource.c      |  2 +
 .../dc/resource/dcn303/dcn303_resource.c      |  2 +
 .../dc/resource/dcn31/dcn31_resource.c        |  2 +
 .../dc/resource/dcn314/dcn314_resource.c      |  2 +
 .../dc/resource/dcn315/dcn315_resource.c      |  2 +
 .../dc/resource/dcn316/dcn316_resource.c      |  2 +
 .../dc/resource/dcn32/dcn32_resource.c        |  2 +
 .../dc/resource/dcn321/dcn321_resource.c      |  2 +
 .../dc/resource/dcn35/dcn35_resource.c        |  2 +
 .../dc/resource/dcn351/dcn351_resource.c      |  2 +
 .../dc/resource/dcn36/dcn36_resource.c        |  2 +
 .../dc/resource/dcn401/dcn401_resource.c      |  2 +
 .../dc/resource/dcn42/dcn42_resource.c        |  2 +
 .../dc/resource/dcn42b/dcn42b_resource.c      |  2 +
 27 files changed, 186 insertions(+), 70 deletions(-)
drivers/gpu/drm/amd/display/dc/basics/conversion.c +45 -16
index a1f2350388e2..1c8d4907245a 100644
@@ -26,11 +26,7 @@
 #include "dm_services.h"
 #include "basics/conversion.h"
 
-#define DIVIDER 10000
 
-/* S2D13 value in [-3.00...0.9999] */
-#define S2D13_MIN (-3 * DIVIDER)
-#define S2D13_MAX (3 * DIVIDER)
 
 uint16_t fixed_point_to_int_frac(
 	struct fixed31_32 arg,
@@ -74,28 +70,44 @@ uint16_t fixed_point_to_int_frac(
 	return result;
 }
 /*
- * convert_float_matrix - This converts a double into HW register spec defined format S2D13.
+ * convert_float_matrix - This converts a double into HW register spec defined format S2D13 / S3D12.
  */
 void convert_float_matrix(
 	uint16_t *matrix,
-	struct fixed31_32 *flt,
+	const struct fixed31_32 *flt,
+	enum cm_gamut_coef_format format,
 	uint32_t buffer_size)
 {
-	const struct fixed31_32 min_2_13 =
-		dc_fixpt_from_fraction(S2D13_MIN, DIVIDER);
-	const struct fixed31_32 max_2_13 =
-		dc_fixpt_from_fraction(S2D13_MAX, DIVIDER);
+	struct fixed31_32 min;
+	struct fixed31_32 max;
+	uint8_t num_int_bits;
+	uint8_t num_dec_bits;
 	uint32_t i;
 
+	if (format == CM_GAMUT_REMAP_COEF_FORMAT_S2_13) {
+		min = dc_fixpt_from_fraction(S2D13_MIN, DIVIDER);
+		max = dc_fixpt_from_fraction(S2D13_MAX, DIVIDER);
+		num_int_bits = 2;
+		num_dec_bits = 13;
+	} else if (format == CM_GAMUT_REMAP_COEF_FORMAT_S3_12) {
+		min = dc_fixpt_from_fraction(S3D12_MIN, DIVIDER);
+		max = dc_fixpt_from_fraction(S3D12_MAX, DIVIDER);
+		num_int_bits = 3;
+		num_dec_bits = 12;
+	} else {
+		ASSERT(false);
+		return;
+	}
+
 	for (i = 0; i < buffer_size; ++i) {
 		uint32_t reg_value =
 				fixed_point_to_int_frac(
 					dc_fixpt_clamp(
 						flt[i],
-						min_2_13,
-						max_2_13),
-						2,
-						13);
+						min,
+						max),
+						num_int_bits,
+						num_dec_bits);
 
 		matrix[i] = (uint16_t)reg_value;
 	}
@@ -129,10 +141,27 @@ static struct fixed31_32 int_frac_to_fixed_point(uint16_t arg,
  */
 void convert_hw_matrix(struct fixed31_32 *matrix,
 		       uint16_t *reg,
+			   enum cm_gamut_coef_format format,
 		       uint32_t buffer_size)
 {
-	for (uint32_t i = 0; i < buffer_size; ++i)
-		matrix[i] = int_frac_to_fixed_point(reg[i], 2, 13);
+	uint8_t num_int_bits;
+	uint8_t num_dec_bits;
+	uint32_t i;
+
+	if (format == CM_GAMUT_REMAP_COEF_FORMAT_S2_13) {
+		num_int_bits = 2;
+		num_dec_bits = 13;
+	} else if (format == CM_GAMUT_REMAP_COEF_FORMAT_S3_12) {
+		num_int_bits = 3;
+		num_dec_bits = 12;
+	} else {
+		ASSERT(false);
+		return;
+	}
+
+	for (i = 0; i < buffer_size; ++i)
+		matrix[i] = int_frac_to_fixed_point(reg[i],
+							num_int_bits, num_dec_bits);
 }
 
 static uint32_t find_gcd(uint32_t a, uint32_t b)
drivers/gpu/drm/amd/display/dc/basics/conversion.h +11 -1
index a433cef78496..c7bed2539fa8 100644
@@ -28,6 +28,14 @@
 
 #include "include/fixed31_32.h"
 
+#define DIVIDER 10000
+
+#define S2D13_MIN (-4 * DIVIDER)
+#define S2D13_MAX (39999)
+
+#define S3D12_MIN (-8 * DIVIDER)
+#define S3D12_MAX (79998)
+
 uint16_t fixed_point_to_int_frac(
 	struct fixed31_32 arg,
 	uint8_t integer_bits,
@@ -35,7 +43,8 @@ uint16_t fixed_point_to_int_frac(
 
 void convert_float_matrix(
 	uint16_t *matrix,
-	struct fixed31_32 *flt,
+	const struct fixed31_32 *flt,
+	enum cm_gamut_coef_format format,
 	uint32_t buffer_size);
 
 void reduce_fraction(uint32_t num, uint32_t den,
@@ -43,6 +52,7 @@ void reduce_fraction(uint32_t num, uint32_t den,
 
 void convert_hw_matrix(struct fixed31_32 *matrix,
 		       uint16_t *reg,
+			   enum cm_gamut_coef_format format,
 		       uint32_t buffer_size);
 
 static inline unsigned int log_2(unsigned int num)
drivers/gpu/drm/amd/display/dc/dc.h +1 -0
index 75c06a1752b5..07ebd98f0d3b 100644
@@ -315,6 +315,7 @@ struct mpc_color_caps {
 	struct lut3d_caps mcm_3d_lut_caps;
 	struct lut3d_caps rmcm_3d_lut_caps;
 	bool preblend;
+	struct fixed31_32 max_gamut_remap_coeff;
 };
 
 /**
drivers/gpu/drm/amd/display/dc/dce/dce_transform.c +2 -2
index 12c85c3afd6a..864491bfd7f7 100644
@@ -1145,8 +1145,8 @@ static void dce_transform_set_gamut_remap(
 		for (i = 0; i < GAMUT_MATRIX_SIZE; i++)
 			arr_matrix[i] = adjust->temperature_matrix[i];
 
-		convert_float_matrix(
-			arr_reg_val, arr_matrix, GAMUT_MATRIX_SIZE);
+		convert_float_matrix(arr_reg_val, arr_matrix,
+			CM_GAMUT_REMAP_COEF_FORMAT_S2_13, GAMUT_MATRIX_SIZE);
 
 		program_gamut_remap(xfm_dce, arr_reg_val);
 	}
drivers/gpu/drm/amd/display/dc/dpp/dcn10/dcn10_dpp_cm.c +4 -4
index 9788628cf0ad..ff17a9c9eed0 100644
@@ -171,8 +171,8 @@ void dpp1_cm_set_gamut_remap(
 		for (i = 0; i < 12; i++)
 			arr_matrix[i] = adjust->temperature_matrix[i];
 
-		convert_float_matrix(
-			arr_reg_val, arr_matrix, 12);
+		convert_float_matrix(arr_reg_val, arr_matrix,
+			CM_GAMUT_REMAP_COEF_FORMAT_S2_13, 12);
 
 		program_gamut_remap(dpp, arr_reg_val, GAMUT_REMAP_COEFF);
 	}
@@ -242,8 +242,8 @@ void dpp1_cm_get_gamut_remap(struct dpp *dpp_base,
 	}
 
 	adjust->gamut_adjust_type = GRAPHICS_GAMUT_ADJUST_TYPE_SW;
-	convert_hw_matrix(adjust->temperature_matrix,
-			  arr_reg_val, ARRAY_SIZE(arr_reg_val));
+	convert_hw_matrix(adjust->temperature_matrix, arr_reg_val,
+			CM_GAMUT_REMAP_COEF_FORMAT_S2_13, ARRAY_SIZE(arr_reg_val));
 }
 
 static void dpp1_cm_program_color_matrix(
drivers/gpu/drm/amd/display/dc/dpp/dcn20/dcn20_dpp_cm.c +4 -4
index 26f9485f165d..74cc176d9437 100644
@@ -227,8 +227,8 @@ void dpp2_cm_set_gamut_remap(
 		for (i = 0; i < 12; i++)
 			arr_matrix[i] = adjust->temperature_matrix[i];
 
-		convert_float_matrix(
-			arr_reg_val, arr_matrix, 12);
+		convert_float_matrix(arr_reg_val, arr_matrix,
+			CM_GAMUT_REMAP_COEF_FORMAT_S2_13, 12);
 
 		program_gamut_remap(dpp, arr_reg_val, DCN2_GAMUT_REMAP_COEF_A);
 	}
@@ -285,8 +285,8 @@ void dpp2_cm_get_gamut_remap(struct dpp *dpp_base,
 	}
 
 	adjust->gamut_adjust_type = GRAPHICS_GAMUT_ADJUST_TYPE_SW;
-	convert_hw_matrix(adjust->temperature_matrix,
-			  arr_reg_val, ARRAY_SIZE(arr_reg_val));
+	convert_hw_matrix(adjust->temperature_matrix, arr_reg_val,
+			CM_GAMUT_REMAP_COEF_FORMAT_S2_13, ARRAY_SIZE(arr_reg_val));
 }
 
 void dpp2_program_input_csc(
drivers/gpu/drm/amd/display/dc/dpp/dcn30/dcn30_dpp_cm.c +4 -4
index e01d8e9672fc..8fe3474411b7 100644
@@ -392,8 +392,8 @@ void dpp3_cm_set_gamut_remap(
 		for (i = 0; i < 12; i++)
 			arr_matrix[i] = adjust->temperature_matrix[i];
 
-		convert_float_matrix(
-			arr_reg_val, arr_matrix, 12);
+		convert_float_matrix(arr_reg_val, arr_matrix,
+				CM_GAMUT_REMAP_COEF_FORMAT_S2_13, 12);
 
 		//current coefficient set in use
 		REG_GET(CM_GAMUT_REMAP_CONTROL, CM_GAMUT_REMAP_MODE_CURRENT, &gamut_mode);
@@ -460,6 +460,6 @@ void dpp3_cm_get_gamut_remap(struct dpp *dpp_base,
 	}
 
 	adjust->gamut_adjust_type = GRAPHICS_GAMUT_ADJUST_TYPE_SW;
-	convert_hw_matrix(adjust->temperature_matrix,
-			  arr_reg_val, ARRAY_SIZE(arr_reg_val));
+	convert_hw_matrix(adjust->temperature_matrix, arr_reg_val,
+			CM_GAMUT_REMAP_COEF_FORMAT_S2_13, ARRAY_SIZE(arr_reg_val));
 }
drivers/gpu/drm/amd/display/dc/dwb/dcn30/dcn30_dwb_cm.c +2 -1
index 37adf0e6a166..5a611dd14581 100644
@@ -371,7 +371,8 @@ void dwb3_set_gamut_remap(
 		for (i = 0; i < 12; i++)
 			arr_matrix[i] = adjust.temperature_matrix[i];
 
-		convert_float_matrix(arr_reg_val, arr_matrix, 12);
+		convert_float_matrix(arr_reg_val, arr_matrix,
+			CM_GAMUT_REMAP_COEF_FORMAT_S2_13, 12);
 
 		REG_GET(DWB_GAMUT_REMAP_MODE, DWB_GAMUT_REMAP_MODE_CURRENT, &current_mode);
 
drivers/gpu/drm/amd/display/dc/mpc/dcn30/dcn30_mpc.c +29 -15

98 lines not on this page · raw message

drivers/gpu/drm/amd/display/dc/mpc/dcn401/dcn401_mpc.c +48 -21

152 lines not on this page · raw message

drivers/gpu/drm/amd/display/dc/mpc/dcn401/dcn401_mpc.h +4 -2
index 6d842d7b95c7..3d00d9497ed2 100644
@@ -242,13 +242,15 @@ void mpc_program_gamut_remap(
 	unsigned int mpcc_id,
 	const uint16_t *regval,
 	enum mpcc_gamut_remap_id gamut_remap_block_id,
-	enum mpcc_gamut_remap_mode_select mode_select);
+	enum mpcc_gamut_remap_mode_select mode_select,
+	enum cm_gamut_coef_format coef_format);
 
 void mpc_read_gamut_remap(struct mpc *mpc,
 	int mpcc_id,
 	uint16_t *regval,
 	enum mpcc_gamut_remap_id gamut_remap_block_id,
-	uint32_t *mode_select);
+	uint32_t *mode_select,
+	enum cm_gamut_coef_format *coef_format);
 
 void mpc401_get_3dlut_fast_load_status(
 	struct mpc *mpc,
drivers/gpu/drm/amd/display/dc/resource/dcn30/dcn30_resource.c +2 -0
index d11ab57afcdd..40fc66e64c1b 100644
@@ -31,6 +31,7 @@
 
 #include "resource.h"
 #include "include/irq_service_interface.h"
+#include "basics/conversion.h"
 #include "dcn20/dcn20_resource.h"
 
 #include "dcn30_resource.h"
@@ -2515,6 +2516,7 @@ static bool dcn30_resource_construct(
 	dc->caps.color.mpc.ogam_rom_caps.pq = 0;
 	dc->caps.color.mpc.ogam_rom_caps.hlg = 0;
 	dc->caps.color.mpc.ocsc = 1;
+	dc->caps.color.mpc.max_gamut_remap_coeff = dc_fixpt_from_fraction(S3D12_MAX, DIVIDER);
 
 	dc->caps.dp_hdmi21_pcon_support = true;
 	dc->caps.max_v_total = (1 << 15) - 1;
drivers/gpu/drm/amd/display/dc/resource/dcn301/dcn301_resource.c +2 -0
index 4ecf448d15b6..551565ae9ef2 100644
@@ -31,6 +31,7 @@
 
 #include "resource.h"
 #include "include/irq_service_interface.h"
+#include "basics/conversion.h"
 #include "dcn30/dcn30_resource.h"
 #include "dcn301_resource.h"
 
@@ -1516,6 +1517,7 @@ static bool dcn301_resource_construct(
 	dc->caps.color.mpc.ogam_rom_caps.pq = 0;
 	dc->caps.color.mpc.ogam_rom_caps.hlg = 0;
 	dc->caps.color.mpc.ocsc = 1;
+	dc->caps.color.mpc.max_gamut_remap_coeff = dc_fixpt_from_fraction(S3D12_MAX, DIVIDER);
 
 	dc->caps.dp_hdmi21_pcon_support = true;
 
drivers/gpu/drm/amd/display/dc/resource/dcn302/dcn302_resource.c +2 -0
index ae8918a4ad3e..2574e706631d 100644
@@ -27,6 +27,7 @@
 #include "dcn302_resource.h"
 #include "dcn302/dcn302_dccg.h"
 #include "irq/dcn302/irq_service_dcn302.h"
+#include "basics/conversion.h"
 
 #include "dcn30/dcn30_dio_link_encoder.h"
 #include "dcn30/dcn30_dio_stream_encoder.h"
@@ -1416,6 +1417,7 @@ static bool dcn302_resource_construct(
 	dc->caps.color.mpc.ogam_rom_caps.pq = 0;
 	dc->caps.color.mpc.ogam_rom_caps.hlg = 0;
 	dc->caps.color.mpc.ocsc = 1;
+	dc->caps.color.mpc.max_gamut_remap_coeff = dc_fixpt_from_fraction(S3D12_MAX, DIVIDER);
 
 	dc->caps.dp_hdmi21_pcon_support = true;
 
drivers/gpu/drm/amd/display/dc/resource/dcn303/dcn303_resource.c +2 -0
index 75e6f4e46f60..8b24628e3e14 100644
@@ -27,6 +27,7 @@
 #include "dcn303_resource.h"
 #include "dcn303/dcn303_dccg.h"
 #include "irq/dcn303/irq_service_dcn303.h"
+#include "basics/conversion.h"
 
 #include "dcn30/dcn30_dio_link_encoder.h"
 #include "dcn30/dcn30_dio_stream_encoder.h"
@@ -1360,6 +1361,7 @@ static bool dcn303_resource_construct(
 	dc->caps.color.mpc.ogam_rom_caps.pq = 0;
 	dc->caps.color.mpc.ogam_rom_caps.hlg = 0;
 	dc->caps.color.mpc.ocsc = 1;
+	dc->caps.color.mpc.max_gamut_remap_coeff = dc_fixpt_from_fraction(S3D12_MAX, DIVIDER);
 
 	dc->caps.dp_hdmi21_pcon_support = true;
 
drivers/gpu/drm/amd/display/dc/resource/dcn31/dcn31_resource.c +2 -0
index e29efa452c87..8bb2b8b29cbf 100644
@@ -31,6 +31,7 @@
 
 #include "resource.h"
 #include "include/irq_service_interface.h"
+#include "basics/conversion.h"
 #include "dcn31_resource.h"
 
 #include "dcn20/dcn20_resource.h"
@@ -2123,6 +2124,7 @@ static bool dcn31_resource_construct(
 	dc->caps.color.mpc.ogam_rom_caps.pq = 0;
 	dc->caps.color.mpc.ogam_rom_caps.hlg = 0;
 	dc->caps.color.mpc.ocsc = 1;
+	dc->caps.color.mpc.max_gamut_remap_coeff = dc_fixpt_from_fraction(S3D12_MAX, DIVIDER);
 
 	dc->caps.num_of_host_routers = 2;
 	dc->caps.num_of_dpias_per_host_router = 2;
drivers/gpu/drm/amd/display/dc/resource/dcn314/dcn314_resource.c +2 -0
index f50b3250dcba..372e05487847 100644
@@ -33,6 +33,7 @@
 
 #include "resource.h"
 #include "include/irq_service_interface.h"
+#include "basics/conversion.h"
 #include "dcn314_resource.h"
 
 #include "dcn20/dcn20_resource.h"
@@ -2051,6 +2052,7 @@ static bool dcn314_resource_construct(
 	dc->caps.color.mpc.ogam_rom_caps.pq = 0;
 	dc->caps.color.mpc.ogam_rom_caps.hlg = 0;
 	dc->caps.color.mpc.ocsc = 1;
+	dc->caps.color.mpc.max_gamut_remap_coeff = dc_fixpt_from_fraction(S3D12_MAX, DIVIDER);
 
 	dc->caps.max_disp_clock_khz_at_vmin = 650000;
 
drivers/gpu/drm/amd/display/dc/resource/dcn315/dcn315_resource.c +2 -0
index 8297f2f04c16..6e112ef0a49a 100644
@@ -31,6 +31,7 @@
 
 #include "resource.h"
 #include "include/irq_service_interface.h"
+#include "basics/conversion.h"
 #include "dcn315_resource.h"
 
 #include "dcn20/dcn20_resource.h"
@@ -2095,6 +2096,7 @@ static bool dcn315_resource_construct(
 	dc->caps.color.mpc.ogam_rom_caps.pq = 0;
 	dc->caps.color.mpc.ogam_rom_caps.hlg = 0;
 	dc->caps.color.mpc.ocsc = 1;
+	dc->caps.color.mpc.max_gamut_remap_coeff = dc_fixpt_from_fraction(S3D12_MAX, DIVIDER);
 
 	dc->config.no_native422_support = true;
 
drivers/gpu/drm/amd/display/dc/resource/dcn316/dcn316_resource.c +2 -0
index 046566ad1afe..b9d2567a4180 100644
@@ -31,6 +31,7 @@
 
 #include "resource.h"
 #include "include/irq_service_interface.h"
+#include "basics/conversion.h"
 #include "dcn316_resource.h"
 
 #include "dcn20/dcn20_resource.h"
@@ -1969,6 +1970,7 @@ static bool dcn316_resource_construct(
 	dc->caps.color.mpc.ogam_rom_caps.pq = 0;
 	dc->caps.color.mpc.ogam_rom_caps.hlg = 0;
 	dc->caps.color.mpc.ocsc = 1;
+	dc->caps.color.mpc.max_gamut_remap_coeff = dc_fixpt_from_fraction(S3D12_MAX, DIVIDER);
 
 	/* read VBIOS LTTPR caps */
 	{
drivers/gpu/drm/amd/display/dc/resource/dcn32/dcn32_resource.c +2 -0
index 004c5690f876..cd9d2087d14e 100644
@@ -32,6 +32,7 @@
 
 #include "resource.h"
 #include "include/irq_service_interface.h"
+#include "basics/conversion.h"
 #include "dcn32_resource.h"
 
 #include "dcn20/dcn20_resource.h"
@@ -2448,6 +2449,7 @@ static bool dcn32_resource_construct(
 	dc->caps.color.mpc.ogam_rom_caps.hlg = 0;
 	dc->caps.color.mpc.ocsc = 1;
 	dc->caps.color.mpc.preblend = true;
+	dc->caps.color.mpc.max_gamut_remap_coeff = dc_fixpt_from_fraction(S3D12_MAX, DIVIDER);
 
 	/* Use pipe context based otg sync logic */
 	dc->config.use_pipe_ctx_sync_logic = true;
drivers/gpu/drm/amd/display/dc/resource/dcn321/dcn321_resource.c +2 -0
index 53fd32249310..ff9c1379896e 100644
@@ -31,6 +31,7 @@
 
 #include "resource.h"
 #include "include/irq_service_interface.h"
+#include "basics/conversion.h"
 #include "dcn32/dcn32_resource.h"
 #include "dcn321_resource.h"
 
@@ -1939,6 +1940,7 @@ static bool dcn321_resource_construct(
 	dc->caps.color.mpc.ogam_rom_caps.hlg = 0;
 	dc->caps.color.mpc.ocsc = 1;
 	dc->caps.color.mpc.preblend = true;
+	dc->caps.color.mpc.max_gamut_remap_coeff = dc_fixpt_from_fraction(S3D12_MAX, DIVIDER);
 	/* HACK: Force FRL support until BIOS is ready. */
 	dc->config.force_hdmi21_frl_enc_enable = true;
 
drivers/gpu/drm/amd/display/dc/resource/dcn35/dcn35_resource.c +2 -0
index 5541b89b1350..1b9b6eb8b322 100644
@@ -32,6 +32,7 @@
 
 #include "resource.h"
 #include "include/irq_service_interface.h"
+#include "basics/conversion.h"
 #include "dcn35_resource.h"
 #include "dml2_0/dml2_wrapper.h"
 
@@ -2078,6 +2079,7 @@ static bool dcn35_resource_construct(
 	dc->caps.color.mpc.ogam_rom_caps.hlg = 0;
 	dc->caps.color.mpc.ocsc = 1;
 	dc->caps.color.mpc.preblend = true;
+	dc->caps.color.mpc.max_gamut_remap_coeff = dc_fixpt_from_fraction(S3D12_MAX, DIVIDER);
 
 	dc->caps.num_of_host_routers = 2;
 	dc->caps.num_of_dpias_per_host_router = 2;
drivers/gpu/drm/amd/display/dc/resource/dcn351/dcn351_resource.c +2 -0
index 053b4380f57e..2268ced16969 100644
@@ -10,6 +10,7 @@
 
 #include "resource.h"
 #include "include/irq_service_interface.h"
+#include "basics/conversion.h"
 #include "dcn351_resource.h"
 
 #include "dcn20/dcn20_resource.h"
@@ -2051,6 +2052,7 @@ static bool dcn351_resource_construct(
 	dc->caps.color.mpc.ogam_rom_caps.hlg = 0;
 	dc->caps.color.mpc.ocsc = 1;
 	dc->caps.color.mpc.preblend = true;
+	dc->caps.color.mpc.max_gamut_remap_coeff = dc_fixpt_from_fraction(S3D12_MAX, DIVIDER);
 
 	dc->caps.num_of_host_routers = 2;
 	dc->caps.num_of_dpias_per_host_router = 2;
drivers/gpu/drm/amd/display/dc/resource/dcn36/dcn36_resource.c +2 -0
index 592000cf9250..b1323e76801e 100644
@@ -10,6 +10,7 @@
 
 #include "resource.h"
 #include "include/irq_service_interface.h"
+#include "basics/conversion.h"
 #include "dcn36_resource.h"
 #include "dml2_0/dml2_wrapper.h"
 
@@ -2048,6 +2049,7 @@ static bool dcn36_resource_construct(
 	dc->caps.color.mpc.ogam_rom_caps.hlg = 0;
 	dc->caps.color.mpc.ocsc = 1;
 	dc->caps.color.mpc.preblend = true;
+	dc->caps.color.mpc.max_gamut_remap_coeff = dc_fixpt_from_fraction(S3D12_MAX, DIVIDER);
 
 	dc->caps.num_of_host_routers = 2;
 	dc->caps.num_of_dpias_per_host_router = 2;
drivers/gpu/drm/amd/display/dc/resource/dcn401/dcn401_resource.c +2 -0
index f7ba0509e6bd..181cb7135dfb 100644
@@ -10,6 +10,7 @@
 
 #include "resource.h"
 #include "include/irq_service_interface.h"
+#include "basics/conversion.h"
 #include "dcn401_resource.h"
 
 #include "dcn20/dcn20_resource.h"
@@ -2131,6 +2132,7 @@ static bool dcn401_resource_construct(
 	dc->caps.color.mpc.ogam_rom_caps.hlg = 0;
 	dc->caps.color.mpc.ocsc = 1;
 	dc->caps.color.mpc.preblend = true;
+	dc->caps.color.mpc.max_gamut_remap_coeff = dc_fixpt_from_fraction(S3D12_MAX, DIVIDER);
 	/* HACK: Force FRL support until BIOS is ready. */
 	dc->config.force_hdmi21_frl_enc_enable = true;
 	dc->config.use_spl = true;
drivers/gpu/drm/amd/display/dc/resource/dcn42/dcn42_resource.c +2 -0
index 67673a9e5155..dba1b69137f9 100644
@@ -9,6 +9,7 @@
 #include "dcn42/dcn42_init.h"
 
 #include "resource.h"
+#include "basics/conversion.h"
 #include "include/irq_service_interface.h"
 
 #include "dcn42_resource.h"
@@ -2110,6 +2111,7 @@ static bool dcn42_resource_construct(
 	dc->caps.color.mpc.rmcm_3d_lut_caps.mem_format_support.float_fp1_5_10 = 1;
 	dc->caps.color.mpc.rmcm_3d_lut_caps.mem_pixel_order_support.order_rgba = 1;
 	dc->caps.color.mpc.rmcm_3d_lut_caps.mem_pixel_order_support.order_bgra = 1;
+	dc->caps.color.mpc.max_gamut_remap_coeff = dc_fixpt_from_fraction(S3D12_MAX, DIVIDER);
 
 	dc->caps.num_of_host_routers = 3;
 	dc->caps.num_of_dpias_per_host_router = 2;
drivers/gpu/drm/amd/display/dc/resource/dcn42b/dcn42b_resource.c +2 -0
index 2334bc5b75b8..dbd6267340ac 100644
@@ -13,6 +13,7 @@
 
 #include "resource.h"
 #include "include/irq_service_interface.h"
+#include "basics/conversion.h"
 
 #include "dcn42b_resource.h"
 #include "dcn20/dcn20_resource.h"
@@ -2080,6 +2081,7 @@ static bool dcn42b_resource_construct(
 	dc->caps.color.mpc.rmcm_3d_lut_caps.mem_format_support.float_fp1_5_10 = 1;
 	dc->caps.color.mpc.rmcm_3d_lut_caps.mem_pixel_order_support.order_rgba = 1;
 	dc->caps.color.mpc.rmcm_3d_lut_caps.mem_pixel_order_support.order_bgra = 1;
+	dc->caps.color.mpc.max_gamut_remap_coeff = dc_fixpt_from_fraction(S3D12_MAX, DIVIDER);
 
 	dc->caps.num_of_host_routers = 0;
 	dc->caps.num_of_dpias_per_host_router = 0;
Signature · 1 line
2.53.0
#38 lore raw

Re: [PATCH 36/49] drm/amd/display: adjust floating point format for gamut remap when needed

Quoted 17 lines · Fangzhi Zuo

From: Clay King <[email protected]>

[Why]
The MPCCs different gamut remap matrices allow for S2D13 and S3D12 floating point formats, but only S2D13 is used. There may be cases where more integer bits are required.

[How]
Switch to S3D12 if any entries in the remap matrix cannot fit in S2D13. Otherwise, prefer the extra precision of S2D13. Communicate the max value that hw can support to dm via dc color caps.

---

...

drivers/gpu/drm/amd/display/dc/dc.h struct mpc_color_caps { · line 319

Quoted 10 lines
drivers/gpu/drm/amd/display/dc/dc.h +1 -0
index 75c06a1752b5..07ebd98f0d3b 100644
@@ -315,6 +315,7 @@ struct mpc_color_caps {
  	struct lut3d_caps mcm_3d_lut_caps;
  	struct lut3d_caps rmcm_3d_lut_caps;
  	bool preblend;
+	struct fixed31_32 max_gamut_remap_coeff;
  };

Hi!

FYI, this change is causing a warning during "make htmldocs" now:

WARNING: ..../drivers/gpu/drm/amd/display/dc/dc.h:327 struct member 'max_gamut_remap_coeff' not described in 'mpc_color_caps'

Could you maybe sent a patch to document it in the kerneldoc comment when you've got some spare time?

Thanks,
Thomas

#39 lore raw

PATCH 37/49 drm/amd/display: Reintroduce "convert dcn42 GPIO translation to lookup tables"

In reply to Fangzhi Zuo

From: Nicholas Carbones <[email protected]>

This reverts commit c371d98717539f687e6d96a63c74a7beb764c138.

---
 .../dc/gpio/dcn42/hw_translate_dcn42.c        | 193 +++++++-----------
 .../dc/gpio/dcn42/hw_translate_dcn42.c.orig   | 193 +++++++++++-------
 2 files changed, 193 insertions(+), 193 deletions(-)
drivers/gpu/drm/amd/display/dc/gpio/dcn42/hw_translate_dcn42.c +70 -123
index e7e1d9979876..7b2c4cd42450 100644
@@ -39,62 +39,76 @@
  * end *********************/
 
 
+static const struct gpio_id_offset_entry gpio_offsets[] = {
+	/* HPD */
+	GPIO_ENTRY(HPD0_DC_HPD_INT_STATUS, GPIO_ID_HPD, GPIO_HPD_1),
+	GPIO_ENTRY(HPD1_DC_HPD_INT_STATUS, GPIO_ID_HPD, GPIO_HPD_2),
+	GPIO_ENTRY(HPD2_DC_HPD_INT_STATUS, GPIO_ID_HPD, GPIO_HPD_3),
+	GPIO_ENTRY(HPD3_DC_HPD_INT_STATUS, GPIO_ID_HPD, GPIO_HPD_4),
+	GPIO_ENTRY(HPD4_DC_HPD_INT_STATUS, GPIO_ID_HPD, GPIO_HPD_5),
+};
+
+
+/* DDC */
+static const struct gpio_ddc_offset_entry ddc_offset_map[] = {
+	{ REG(DC_GPIO_DDC1_A), GPIO_DDC_LINE_DDC1 },
+	{ REG(DC_GPIO_DDC2_A), GPIO_DDC_LINE_DDC2 },
+	{ REG(DC_GPIO_DDC3_A), GPIO_DDC_LINE_DDC3 },
+	{ REG(DC_GPIO_DDC4_A), GPIO_DDC_LINE_DDC4 },
+	{ REG(DC_GPIO_DDC5_A), GPIO_DDC_LINE_DDC5 },
+	{ REG(DC_GPIO_DDCVGA_A), GPIO_DDC_LINE_DDC_VGA },
+};
+
+
+static const struct gpio_pin_entry gpio_pins[] = {
+	/* DDC */
+	GPIO_PIN_ENTRY(GPIO_ID_DDC_DATA, GPIO_DDC_LINE_DDC1,
+		DC_GPIO_DDC1_A, DC_GPIO_DDC1_A__DC_GPIO_DDC1DATA_A_MASK),
+	GPIO_PIN_ENTRY(GPIO_ID_DDC_DATA, GPIO_DDC_LINE_DDC2,
+		DC_GPIO_DDC2_A, DC_GPIO_DDC1_A__DC_GPIO_DDC1DATA_A_MASK),
+	GPIO_PIN_ENTRY(GPIO_ID_DDC_DATA, GPIO_DDC_LINE_DDC3,
+		DC_GPIO_DDC3_A, DC_GPIO_DDC1_A__DC_GPIO_DDC1DATA_A_MASK),
+	GPIO_PIN_ENTRY(GPIO_ID_DDC_DATA, GPIO_DDC_LINE_DDC4,
+		DC_GPIO_DDC4_A, DC_GPIO_DDC1_A__DC_GPIO_DDC1DATA_A_MASK),
+	GPIO_PIN_ENTRY(GPIO_ID_DDC_DATA, GPIO_DDC_LINE_DDC5,
+		DC_GPIO_DDC5_A, DC_GPIO_DDC1_A__DC_GPIO_DDC1DATA_A_MASK),
+	GPIO_PIN_ENTRY(GPIO_ID_DDC_DATA, GPIO_DDC_LINE_DDC_VGA,
+		DC_GPIO_DDCVGA_A, DC_GPIO_DDC1_A__DC_GPIO_DDC1DATA_A_MASK),
+	GPIO_PIN_ENTRY(GPIO_ID_DDC_CLOCK, GPIO_DDC_LINE_DDC1,
+		DC_GPIO_DDC1_A, DC_GPIO_DDC1_A__DC_GPIO_DDC1CLK_A_MASK),
+	GPIO_PIN_ENTRY(GPIO_ID_DDC_CLOCK, GPIO_DDC_LINE_DDC2,
+		DC_GPIO_DDC2_A, DC_GPIO_DDC1_A__DC_GPIO_DDC1CLK_A_MASK),
+	GPIO_PIN_ENTRY(GPIO_ID_DDC_CLOCK, GPIO_DDC_LINE_DDC3,
+		DC_GPIO_DDC3_A, DC_GPIO_DDC1_A__DC_GPIO_DDC1CLK_A_MASK),
+	GPIO_PIN_ENTRY(GPIO_ID_DDC_CLOCK, GPIO_DDC_LINE_DDC4,
+		DC_GPIO_DDC4_A, DC_GPIO_DDC1_A__DC_GPIO_DDC1CLK_A_MASK),
+	GPIO_PIN_ENTRY(GPIO_ID_DDC_CLOCK, GPIO_DDC_LINE_DDC5,
+		DC_GPIO_DDC5_A, DC_GPIO_DDC1_A__DC_GPIO_DDC1CLK_A_MASK),
+	GPIO_PIN_ENTRY(GPIO_ID_DDC_CLOCK, GPIO_DDC_LINE_DDC_VGA,
+		DC_GPIO_DDCVGA_A, DC_GPIO_DDC1_A__DC_GPIO_DDC1CLK_A_MASK),
+};
+
+
 static bool offset_to_id(
 	uint32_t offset,
 	uint32_t mask,
 	enum gpio_id *id,
 	uint32_t *en)
 {
-	(void)mask;
-	switch (offset) {
-	/* HPD */
-	case REG(HPD0_DC_HPD_INT_STATUS):
-		*id = GPIO_ID_HPD;
-		*en = GPIO_HPD_1;
-		return true;
-	case REG(HPD1_DC_HPD_INT_STATUS):
-		*id = GPIO_ID_HPD;
-		*en = GPIO_HPD_2;
+	if (dal_hw_translate_gpio_ddc_offset_to_id(
+			ddc_offset_map,
+			ARRAY_SIZE(ddc_offset_map),
+			offset, en))
 		return true;
-	case REG(HPD2_DC_HPD_INT_STATUS):
-		*id = GPIO_ID_HPD;
-		*en = GPIO_HPD_3;
-		return true;
-	case REG(HPD3_DC_HPD_INT_STATUS):
-		*id = GPIO_ID_HPD;
-		*en = GPIO_HPD_4;
-		return true;
-	case REG(HPD4_DC_HPD_INT_STATUS):
-		*id = GPIO_ID_HPD;
-		*en = GPIO_HPD_5;
-		return true;
-	/* DDC */
-	/* we don't care about the GPIO_ID for DDC
-	 * in DdcHandle it will use GPIO_ID_DDC_DATA/GPIO_ID_DDC_CLOCK
-	 * directly in the create method
-	 */
-	case REG(DC_GPIO_DDC1_A):
-		*en = GPIO_DDC_LINE_DDC1;
-		return true;
-	case REG(DC_GPIO_DDC2_A):
-		*en = GPIO_DDC_LINE_DDC2;
-		return true;
-	case REG(DC_GPIO_DDC3_A):
-		*en = GPIO_DDC_LINE_DDC3;
-		return true;
-	case REG(DC_GPIO_DDC4_A):
-		*en = GPIO_DDC_LINE_DDC4;
-		return true;
-	case REG(DC_GPIO_DDC5_A):
-		*en = GPIO_DDC_LINE_DDC5;
-		return true;
-	case REG(DC_GPIO_DDCVGA_A):
-		*en = GPIO_DDC_LINE_DDC_VGA;
+
+	if (dal_hw_translate_gpio_offset_to_id(
+			gpio_offsets,
+			ARRAY_SIZE(gpio_offsets),
+			offset, mask, id, en))
 		return true;
-	default:
-		ASSERT_CRITICAL(false);
-		return false;
-	}
+
+	ASSERT_CRITICAL(false);
+	return false;
 }
 
 
@@ -103,81 +117,14 @@ static bool id_to_offset(
 	uint32_t en,
 	struct gpio_pin_info *info)
 {
-	bool result = true;
-
-	switch (id) {
-	case GPIO_ID_DDC_DATA:
-		info->mask = DC_GPIO_DDC1_A__DC_GPIO_DDC1DATA_A_MASK;
-		switch (en) {
-		case GPIO_DDC_LINE_DDC1:
-			info->offset = REG(DC_GPIO_DDC1_A);
-		break;
-		case GPIO_DDC_LINE_DDC2:
-			info->offset = REG(DC_GPIO_DDC2_A);
-		break;
-		case GPIO_DDC_LINE_DDC3:
-			info->offset = REG(DC_GPIO_DDC3_A);
-		break;
-		case GPIO_DDC_LINE_DDC4:
-			info->offset = REG(DC_GPIO_DDC4_A);
-		break;
-		case GPIO_DDC_LINE_DDC5:
-			info->offset = REG(DC_GPIO_DDC5_A);
-		break;
-		case GPIO_DDC_LINE_DDC_VGA:
-			info->offset = REG(DC_GPIO_DDCVGA_A);
-		break;
-		case GPIO_DDC_LINE_I2C_PAD:
-		default:
-			ASSERT_CRITICAL(false);
-			result = false;
-		}
-	break;
-	case GPIO_ID_DDC_CLOCK:
-		info->mask = DC_GPIO_DDC1_A__DC_GPIO_DDC1CLK_A_MASK;
-		switch (en) {
-		case GPIO_DDC_LINE_DDC1:
-			info->offset = REG(DC_GPIO_DDC1_A);
-		break;
-		case GPIO_DDC_LINE_DDC2:
-			info->offset = REG(DC_GPIO_DDC2_A);
-		break;
-		case GPIO_DDC_LINE_DDC3:
-			info->offset = REG(DC_GPIO_DDC3_A);
-		break;
-		case GPIO_DDC_LINE_DDC4:
-			info->offset = REG(DC_GPIO_DDC4_A);
-		break;
-		case GPIO_DDC_LINE_DDC5:
-			info->offset = REG(DC_GPIO_DDC5_A);
-		break;
-		case GPIO_DDC_LINE_DDC_VGA:
-			info->offset = REG(DC_GPIO_DDCVGA_A);
-		break;
-		case GPIO_DDC_LINE_I2C_PAD:
-		default:
-			ASSERT_CRITICAL(false);
-			result = false;
-		}
-	break;
-	case GPIO_ID_SYNC:
-	case GPIO_ID_VIP_PAD:
-	default:
-		ASSERT_CRITICAL(false);
-		result = false;
-	}
-
-	if (result) {
-		info->offset_y = info->offset + 2;
-		info->offset_en = info->offset + 1;
-		info->offset_mask = info->offset - 1;
-
-		info->mask_y = info->mask;
-		info->mask_en = info->mask;
-		info->mask_mask = info->mask;
-	}
-
-	return result;
+	if (dal_hw_translate_id_to_offset(
+			gpio_pins,
+			ARRAY_SIZE(gpio_pins),
+			id, en, info))
+		return true;
+
+	ASSERT_CRITICAL(false);
+	return false;
 }
 
 
drivers/gpu/drm/amd/display/dc/gpio/dcn42/hw_translate_dcn42.c.orig +123 -70

213 lines not on this page · raw message

Signature · 1 line
2.53.0
#40 lore raw

PATCH 38/49 drm/amd/display: Prune per-tile Timing from Apple Studio Display Primary Tile

In reply to Fangzhi Zuo

[why]
The Apple Studio Display primary tile advertises both the full 5120x2880 mode and the per-tile 2560x2880 timing. With the secondary tile already hidden from userspace, the stray 2560x2880 mode on the primary connector can still be picked by compositors, defeating the single 5K stream goal.

[how]
Prune the per-tile timing from the primary connector during get_modes:
when the sink carries the disable_second_tile quirk and the connector is the primary tile (tile_h_loc == 0 && tile_v_loc == 0), drop any probed mode matching the advertised tile size (tile_h_size x tile_v_size) so userspace only sees the full 5120x2880 mode.

Fixes 22ea891606 ("drm/amd/display: hide Apple Studio Display secondary tile")
---
 .../display/amdgpu_dm/amdgpu_dm_connector.c   | 43 +++++++++++++++++++
 1 file changed, 43 insertions(+)
drivers/gpu/drm/amd/display/amdgpu_dm/amdgpu_dm_connector.c +43 -0
index 135107c73971..a8f089d4fb72 100644
@@ -2751,6 +2751,47 @@ void amdgpu_set_panel_orientation(struct drm_connector *connector)
 						       native_mode->vdisplay);
 }
 
+/*
+ * The Apple Studio Display primary tile advertises both the full 5120x2880
+ * mode and the per-tile 2560x2880 timing. As the secondary tile is hidden from
+ * userspace (see amdgpu_dm_hide_secondary_tile_from_userspace()), drop the
+ * per-tile timing from the primary connector so compositors only pick the full
+ * 5K mode.
+ */
+static void amdgpu_dm_prune_primary_tile_modes(struct drm_connector *connector)
+{
+	struct amdgpu_dm_connector *aconnector = to_amdgpu_dm_connector(connector);
+	struct drm_display_mode *mode, *t;
+
+	if (!aconnector->dc_sink)
+		return;
+
+	if (!aconnector->dc_sink->edid_caps.panel_patch.disable_second_tile)
+		return;
+
+	if (!connector->has_tile)
+		return;
+
+	/* Only prune the per-tile timing from the primary tile. */
+	if (connector->tile_h_loc || connector->tile_v_loc)
+		return;
+
+	list_for_each_entry_safe(mode, t, &connector->probed_modes, head) {
+		if (mode->hdisplay != connector->tile_h_size ||
+		    mode->vdisplay != connector->tile_v_size)
+			continue;
+
+		drm_dbg_kms(connector->dev,
+			    "[CONNECTOR:%d:%s] pruning per-tile %dx%d timing from primary Apple Studio Display tile\n",
+			    connector->base.id, connector->name,
+			    mode->hdisplay, mode->vdisplay);
+
+		list_del(&mode->head);
+		drm_mode_destroy(connector->dev, mode);
+		aconnector->num_modes--;
+	}
+}
+
 STATIC_IFN_KUNIT void amdgpu_dm_connector_ddc_get_modes(struct drm_connector *connector,
 					      const struct drm_edid *drm_edid)
 {
@@ -2763,6 +2804,8 @@ STATIC_IFN_KUNIT void amdgpu_dm_connector_ddc_get_modes(struct drm_connector *co
 		amdgpu_dm_connector->num_modes =
 				drm_edid_connector_add_modes(connector);
 
+		amdgpu_dm_prune_primary_tile_modes(connector);
+
 		/* sorting the probed modes before calling function
 		 * amdgpu_dm_get_native_mode() since EDID can have
 		 * more than one preferred mode. The modes that are
Signature · 1 line
2.53.0
#41 lore raw

PATCH 39/49 drm/amd/display: Add get replay residency function

In reply to Fangzhi Zuo

From: "Huang, Leon" <[email protected]>

[Why&How]
Add dc interface to export link service function for getting Replay residency

---
 drivers/gpu/drm/amd/display/dc/core/dc_link_exports.c | 7 +++++++
 drivers/gpu/drm/amd/display/dc/dc.h                   | 8 ++++++++
 2 files changed, 15 insertions(+)
drivers/gpu/drm/amd/display/dc/core/dc_link_exports.c +7 -0
index f25d4b3e11ac..14fc4ef482f1 100644
@@ -534,6 +534,13 @@ bool dc_link_set_pr_general_cmd(struct dc_link *link,
 	return link->dc->link_srv->dp_pr_set_general_cmd(link, general_cmd_data);
 }
 
+void dc_link_edp_replay_residency(const struct dc_link *link,
+		unsigned int *residency, bool is_start, enum pr_residency_mode mode)
+{
+	if (link && link->dc && link->dc->link_srv)
+		link->dc->link_srv->edp_replay_residency(link, residency, is_start, mode);
+}
+
 bool dc_link_get_pr_state(const struct dc_link *link, uint64_t *state)
 {
 	return link->dc->link_srv->dp_pr_get_state(link, state);
drivers/gpu/drm/amd/display/dc/dc.h +8 -0
index 07ebd98f0d3b..8eaa219132a6 100644
@@ -2984,6 +2984,14 @@ bool dc_link_update_pr_state(struct dc_link *link,
 bool dc_link_set_pr_general_cmd(struct dc_link *link,
 		struct dmub_cmd_pr_general_cmd_data *general_cmd_data);
 
+/*
+ * Measure Panel Replay residency for the given link.
+ * mode: PR_RESIDENCY_MODE_PHY, PR_RESIDENCY_MODE_ALPM, or
+ *       PR_RESIDENCY_MODE_ENABLEMENT_PERIOD
+ */
+void dc_link_edp_replay_residency(const struct dc_link *link,
+		unsigned int *residency, bool is_start, enum pr_residency_mode mode);
+
 /*
  * Get Panel Replay state:
  *
Signature · 1 line
2.53.0
#42 lore raw

PATCH 40/49 drm/amd/display: Fix divide-by-zero in calculate_mcache_setting on zero viewport

In reply to Fangzhi Zuo

From: George Zhang <[email protected]>

If a plane reaches calculate_mcache_setting with a zero-area viewport, calculate_mcache_setting exits early with num_mcaches == 0 and mvmpg_width/height == 0. This will cause a divide-by-zero panic and can also cause an underflow on num_mcaches.

Fix this by changing calculate_mcache_setting to bool and adding guards after each calculate_mcache_row_bytes call. If num_mcaches or mvmpg_width/height is zero, return a false. Callers will propagate the failure as a rejected mode, which prevents the panic.

---
 .../src/dml2_core/dml2_core_dcn4_calcs.c      | 31 +++++++++++++++----
 1 file changed, 25 insertions(+), 6 deletions(-)
drivers/gpu/drm/amd/display/dc/dml2_0/dml21/src/dml2_core/dml2_core_dcn4_calcs.c +25 -6
index fa78016b32fc..110ab26a6a39 100644
@@ -2453,7 +2453,7 @@ static void calculate_mcache_row_bytes(
 	DML_ASSERT(*p->num_mcaches > 0);
 }
 
-static void calculate_mcache_setting(
+static bool calculate_mcache_setting(
 	struct dml2_core_internal_scratch *scratch,
 	struct dml2_core_calcs_calculate_mcache_setting_params *p)
 {
@@ -2479,7 +2479,7 @@ static void calculate_mcache_setting(
 	*p->lc_comb_mcache = 0;
 
 	if (!p->dcc_enable)
-		return;
+		return true;
 
 	l->is_dual_plane = dml_is_420(p->source_format) || p->source_format == dml2_rgbe_alpha;
 
@@ -2516,7 +2516,14 @@ static void calculate_mcache_setting(
 	l->l_p.mvmpg_per_mcache_lb = &l->mvmpg_per_mcache_lb_l;
 
 	calculate_mcache_row_bytes(scratch, &l->l_p);
-	DML_ASSERT(*p->num_mcaches_l > 0);
+	if (*p->num_mcaches_l == 0 ||
+	    (p->surf_vert ? l->mvmpg_height_l : l->mvmpg_width_l) == 0) {
+		DML_LOG_VERBOSE("DML::%s: degenerate luma viewport (num_mcaches_l=%u mvmpg_%s_l=%u) — mode not supported\n",
+			__func__, *p->num_mcaches_l,
+			p->surf_vert ? "height" : "width",
+			p->surf_vert ? l->mvmpg_height_l : l->mvmpg_width_l);
+		return false;
+	}
 
 	if (l->is_dual_plane) {
 		l->c_p.num_chans = p->num_chans;
@@ -2552,7 +2559,14 @@ static void calculate_mcache_setting(
 		l->c_p.mvmpg_per_mcache_lb = &l->mvmpg_per_mcache_lb_c;
 
 		calculate_mcache_row_bytes(scratch, &l->c_p);
-		DML_ASSERT(*p->num_mcaches_c > 0);
+		if (*p->num_mcaches_c == 0 ||
+		    (p->surf_vert ? l->mvmpg_height_c : l->mvmpg_width_c) == 0) {
+			DML_LOG_VERBOSE("DML::%s: degenerate chroma viewport (num_mcaches_c=%u mvmpg_%s_c=%u) — mode not supported\n",
+				__func__, *p->num_mcaches_c,
+				p->surf_vert ? "height" : "width",
+				p->surf_vert ? l->mvmpg_height_c : l->mvmpg_width_c);
+			return false;
+		}
 	}
 
 	// Sharing for iMALL access
@@ -2662,6 +2676,7 @@ static void calculate_mcache_setting(
 
 	*p->mcache_shift_granularity_l = l->mvmpg_access_width_l;
 	*p->mcache_shift_granularity_c = l->mvmpg_access_width_c;
+	return true;
 }
 
 static void calculate_mall_bw_overhead_factor(
@@ -9490,7 +9505,10 @@ static bool dml_core_mode_support(struct dml2_core_calcs_mode_support_ex *in_out
 			calculate_mcache_setting_params->mall_comb_mcache_c = &mode_lib->ms.mall_comb_mcache_c[k];
 			calculate_mcache_setting_params->lc_comb_mcache = &mode_lib->ms.lc_comb_mcache[k];
 
-			calculate_mcache_setting(&mode_lib->scratch, calculate_mcache_setting_params);
+			if (!calculate_mcache_setting(&mode_lib->scratch, calculate_mcache_setting_params)) {
+				mode_lib->ms.support.ModeSupport = false;
+				return false;
+			}
 		}
 
 		calculate_mall_bw_overhead_factor(
@@ -10969,7 +10987,8 @@ static bool dml_core_mode_programming(struct dml2_core_calcs_mode_programming_ex
 			calculate_mcache_setting_params->mall_comb_mcache_l = &mode_lib->mp.mall_comb_mcache_l[k];
 			calculate_mcache_setting_params->mall_comb_mcache_c = &mode_lib->mp.mall_comb_mcache_c[k];
 			calculate_mcache_setting_params->lc_comb_mcache = &mode_lib->mp.lc_comb_mcache[k];
-			calculate_mcache_setting(&mode_lib->scratch, calculate_mcache_setting_params);
+			if (!calculate_mcache_setting(&mode_lib->scratch, calculate_mcache_setting_params))
+				return false;
 		}
 
 		calculate_mall_bw_overhead_factor(
Signature · 1 line
2.53.0
#43 lore raw

PATCH 41/49 drm/amd/display: check if dml21_add_phantom_plane() is successful

In reply to Fangzhi Zuo

From: Alex Deucher <[email protected]>

Verify that the phantom plane was allocated to avoid a later segfault.

Fixes 70839da63605 ("drm/amd/display: Add new DCN401 sources")
---
 .../drm/amd/display/dc/dml2_0/dml21/dml21_utils.c | 15 +++++++--------
 1 file changed, 7 insertions(+), 8 deletions(-)
drivers/gpu/drm/amd/display/dc/dml2_0/dml21/dml21_utils.c +7 -8
index 16e1315da2fa..012dff4cf3fa 100644
@@ -359,14 +359,13 @@ void dml21_handle_phantom_streams_planes(const struct dc *dc, struct dc_state *c
 					main_plane = main_stream_status->plane_states[dc_plane_index];
 
 					/* create phantom planes for subvp enabled plane */
-					dml21_add_phantom_plane(dml_ctx,
-							dc,
-							context,
-							phantom_stream,
-							main_plane,
-							&dml_ctx->v21.mode_programming.programming->plane_programming[dml_plane_index]);
-
-					phantoms_added = true;
+					if (dml21_add_phantom_plane(dml_ctx,
+								    dc,
+								    context,
+								    phantom_stream,
+								    main_plane,
+								    &dml_ctx->v21.mode_programming.programming->plane_programming[dml_plane_index]))
+						phantoms_added = true;
 				}
 			}
 		}
Signature · 1 line
2.53.0
#44 lore raw

PATCH 42/49 drm/amd/display: change dcc_rate from 1 to 2 for log use only

In reply to Fangzhi Zuo

From: Charlene Liu <[email protected]>

[why]
The dcc_rate value does not affect any watermark, TTU or DLG output; it only affects the Z8 stutter-related logging. The hardware DisplayModeSupported formula uses a dcc_rate of 4, while DML2 currently uses 1.

[how]
Change dcc_rate from 1 to 2 so the logged value is closer to the hardware formula.

---
 .../display/dc/dml2_0/dml21/dml21_translation_helper.c    | 8 ++++----
 1 file changed, 4 insertions(+), 4 deletions(-)
drivers/gpu/drm/amd/display/dc/dml2_0/dml21/dml21_translation_helper.c +4 -4
index a76dcde1efbf..47164fa150d9 100644
@@ -447,8 +447,8 @@ static void populate_dml21_dummy_surface_cfg(struct dml2_surface_cfg *surface, c
 	surface->plane0.pitch = ((surface->plane0.width + 127) / 128) * 128;
 	surface->plane1.pitch = 0;
 	surface->dcc.enable = false;
-	surface->dcc.informative.dcc_rate_plane0 = 1.0;
-	surface->dcc.informative.dcc_rate_plane1 = 1.0;
+	surface->dcc.informative.dcc_rate_plane0 = 2.0;
+	surface->dcc.informative.dcc_rate_plane1 = 2.0;
 	surface->dcc.informative.fraction_of_zero_size_request_plane0 = 0;
 	surface->dcc.informative.fraction_of_zero_size_request_plane1 = 0;
 	surface->tiling = dml2_sw_64kb_2d;
@@ -517,8 +517,8 @@ static void populate_dml21_surface_config_from_plane_state(
 	surface->plane1.height = plane_state->plane_size.chroma_size.height;
 	surface->plane1.width = plane_state->plane_size.chroma_size.width;
 	surface->dcc.enable = plane_state->dcc.enable;
-	surface->dcc.informative.dcc_rate_plane0 = 1.0;
-	surface->dcc.informative.dcc_rate_plane1 = 1.0;
+	surface->dcc.informative.dcc_rate_plane0 = 2.0;
+	surface->dcc.informative.dcc_rate_plane1 = 2.0;
 	surface->dcc.informative.fraction_of_zero_size_request_plane0 = plane_state->dcc.independent_64b_blks;
 	surface->dcc.informative.fraction_of_zero_size_request_plane1 = plane_state->dcc.independent_64b_blks_c;
 	surface->dcc.plane0.pitch = plane_state->dcc.meta_pitch;
Signature · 1 line
2.53.0
#45 lore raw

PATCH 43/49 drm/amd/display: enforce UCLK pstate support in mode_support

In reply to Fangzhi Zuo

From: Alexander Chechik <[email protected]>

[Why]
mode_support does not require UCLK pstate today, so later PMO optimization stages can push a plane's VActive latency-hiding margin below zero without rechecking that the config still supports UCLK pstate. This can blank the display on high-bandwidth configs.

[How]
Plumb the PMO-selected per-plane pstate method into mode_support and fail the config only when UCLK pstate is required (method != na) but not supported. For planes committed to a vactive method, require a non-negative VActive latency-hiding margin, and skip the check when all streams are blanked. No-op the PMO DCN42 pstate test (returning false only on the initial candidate so the optimize/FAMS2 stage-3 setup still runs), since reserved time is guaranteed by the override and the vactive margin is now enforced in core mode_support.

---
 .../dml21/src/dml2_core/dml2_core_dcn4.c      |  8 +++++
 .../src/dml2_core/dml2_core_dcn4_calcs.c      | 18 +++++++++++
 .../dml21/src/dml2_pmo/dml2_pmo_dcn42.c       | 32 ++++++-------------
 3 files changed, 36 insertions(+), 22 deletions(-)
drivers/gpu/drm/amd/display/dc/dml2_0/dml21/src/dml2_core/dml2_core_dcn4.c +8 -0
index 727b01ca18bf..45f1bf5e14bf 100644
@@ -554,6 +554,14 @@ bool core_dcn4_mode_support(struct dml2_core_mode_support_in_out *in_out)
 	l->mode_support_ex_params.min_clk_index = in_out->min_clk_index;
 	l->mode_support_ex_params.out_evaluation_info = &in_out->mode_support_result.cfg_support_info.clean_me_up.support_info;
 
+	for (i = 0; i < l->svp_expanded_display_cfg.num_planes; i++) {
+		if (i < in_out->display_cfg->display_config.num_planes)
+			core->clean_me_up.mode_lib.ms.uclk_pstate_switch_modes[i] =
+				in_out->display_cfg->stage3.pstate_switch_modes[i];
+		else
+			core->clean_me_up.mode_lib.ms.uclk_pstate_switch_modes[i] = dml2_pstate_method_na;
+	}
+
 	result = dml2_core_calcs_mode_support_ex(&l->mode_support_ex_params);
 
 	in_out->mode_support_result.cfg_support_info.is_supported = result;
drivers/gpu/drm/amd/display/dc/dml2_0/dml21/src/dml2_core/dml2_core_dcn4_calcs.c +18 -0
index 110ab26a6a39..da9a1c4e2bdc 100644
@@ -9637,6 +9637,22 @@ static bool dml_core_mode_support(struct dml2_core_calcs_mode_support_ex *in_out
 	DML_LOG_VERBOSE("DML::%s: ROBSupport = %u\n", __func__, mode_lib->ms.support.ROBSupport);
 #endif
 
+	mode_lib->ms.support.global_dram_clock_change_support_required = false;
+
+	if (!display_cfg->overrides.all_streams_blanked) {
+		for (k = 0; k < mode_lib->ms.num_active_planes; k++) {
+			if (mode_lib->ms.uclk_pstate_switch_modes[k] == dml2_pstate_method_na)
+				continue;
+
+			mode_lib->ms.support.global_dram_clock_change_support_required = true;
+
+			if ((mode_lib->ms.uclk_pstate_switch_modes[k] == dml2_pstate_method_vactive ||
+					mode_lib->ms.uclk_pstate_switch_modes[k] == dml2_pstate_method_fw_vactive_drr) &&
+					mode_lib->ms.VActiveLatencyHidingMargin[k] < 0)
+				mode_lib->ms.support.global_dram_clock_change_supported = false;
+		}
+	}
+
 	/*Mode Support, Voltage State and SOC Configuration*/
 	{
 		if (mode_lib->ms.support.ScaleRatioAndTapsSupport
@@ -9683,6 +9699,8 @@ static bool dml_core_mode_support(struct dml2_core_calcs_mode_support_ex *in_out
 			&& mode_lib->ms.support.DCCMetaBufferSizeNotExceeded
 			&& !mode_lib->ms.support.ExceededMALLSize
 			&& mode_lib->ms.support.g6_temp_read_support
+			&& (mode_lib->ms.support.global_dram_clock_change_supported
+				|| !mode_lib->ms.support.global_dram_clock_change_support_required)
 			&& ((!display_cfg->hostvm_enable && !s->ImmediateFlipRequired) || mode_lib->ms.support.ImmediateFlipSupport)) {
 			DML_LOG_VERBOSE("DML::%s: mode is supported\n", __func__);
 			mode_lib->ms.support.ModeSupport = true;
drivers/gpu/drm/amd/display/dc/dml2_0/dml21/src/dml2_pmo/dml2_pmo_dcn42.c +10 -22
index 790aef95caa6..57a6a7d5b740 100644
@@ -13,8 +13,6 @@
  * configurations, ensuring p-state watermark support in the blank period only.
  */
 
-static const double MIN_VACTIVE_MARGIN_PCT = 0.25; // We need more than non-zero margin because DET buffer granularity can alter vactive latency hiding
-
 static const struct dml2_pmo_pstate_strategy dcn42_strategy_list_1_display[] = {
 	// VBlank only
 	{
@@ -179,7 +177,7 @@ bool pmo_dcn42_init_for_pstate_support(struct dml2_pmo_init_for_pstate_support_i
 
 	// Figure out which streams can do vactive, and also build up implicit SVP and FAMS2 meta
 	for (stream_index = 0; stream_index < display_config->display_config.num_streams; stream_index++) {
-		if (dcn4_get_vactive_pstate_margin(display_config, s->pmo_dcn4.stream_plane_mask[stream_index]) >= (int)(MIN_VACTIVE_MARGIN_PCT * pmo->soc_bb->power_management_parameters.dram_clk_change_blackout_us))
+		if (dcn4_get_vactive_pstate_margin(display_config, s->pmo_dcn4.stream_plane_mask[stream_index]) >= 0)
 			dcn42_set_bit_in_bitfield(&s->pmo_dcn4.stream_vactive_capability_mask, stream_index);
 	}
 
@@ -259,27 +257,17 @@ bool pmo_dcn42_fams2_optimize_for_pstate_support(struct dml2_pmo_optimize_for_ps
 
 bool pmo_dcn42_test_for_pstate_support(struct dml2_pmo_test_for_pstate_support_in_out *in_out)
 {
-	const struct dml2_pmo_scratch *s = &in_out->instance->scratch;
-	bool p_state_supported = true;
-	unsigned int stream_index;
-
-	if (s->pmo_dcn4.cur_pstate_candidate < 0)
+	/* Return false on the initial candidate (cur_pstate_candidate == -1) so the
+	 * optimization phase runs at least one optimize iteration; otherwise the
+	 * FAMS2/stage-3 setup in the optimize callback is skipped.
+	 */
+	if (in_out->instance->scratch.pmo_dcn4.cur_pstate_candidate < 0)
 		return false;
 
-	for (stream_index = 0; stream_index < in_out->base_display_config->display_config.num_streams; stream_index++) {
-		if (s->pmo_dcn4.pstate_strategy_candidates[s->pmo_dcn4.cur_pstate_candidate].per_stream_pstate_method[stream_index] == dml2_pstate_method_vactive) {
-			if (dcn4_get_minimum_reserved_time_us_for_planes(in_out->base_display_config, s->pmo_dcn4.stream_plane_mask[stream_index]) < (int)in_out->instance->soc_bb->power_management_parameters.dram_clk_change_blackout_us ||
-			    dcn4_get_vactive_pstate_margin(in_out->base_display_config, s->pmo_dcn4.stream_plane_mask[stream_index]) < (int)(MIN_VACTIVE_MARGIN_PCT * in_out->instance->soc_bb->power_management_parameters.dram_clk_change_blackout_us)) {
-				p_state_supported = false;
-				break;
-			}
-		} else {
-			p_state_supported = false;
-			break;
-		}
-	}
-
-	return p_state_supported;
+	/* No-op: reserved time is guaranteed by the override and vactive p-state
+	 * margin is now enforced in core mode support.
+	 */
+	return true;
 }
 
 bool pmo_dcn42_initialize(struct dml2_pmo_initialize_in_out *in_out)
Signature · 1 line
2.53.0
#46 lore raw

PATCH 44/49 drm/amd/display: add DalForceMaxDisplayClock debug option to DML2

In reply to Fangzhi Zuo

From: Justin Chen <[email protected]>

[Why & How]
need to apply the debug option check for max displayclk.

---
 .../gpu/drm/amd/display/dc/dml2_0/dml21/dml21_wrapper_fpu.c  | 5 +++++
 1 file changed, 5 insertions(+)
drivers/gpu/drm/amd/display/dc/dml2_0/dml21/dml21_wrapper_fpu.c +5 -0
index 4e3d54c92e32..aba7dd65c539 100644
@@ -155,6 +155,11 @@ static void dml21_calculate_rq_and_dlg_params(const struct dc *dc, struct dc_sta
 		context->bw_ctx.bw.dcn.clk.max_supported_dppclk_khz = in_ctx->v21.dml_init.soc_bb.clk_table.dppclk.clk_values_khz[0];
 	}
 
+	if (dc->config.forced_clocks || dc->debug.max_disp_clk) {
+		context->bw_ctx.bw.dcn.clk.bw_dispclk_khz = context->bw_ctx.bw.dcn.clk.max_supported_dispclk_khz;
+		context->bw_ctx.bw.dcn.clk.bw_dppclk_khz = context->bw_ctx.bw.dcn.clk.max_supported_dppclk_khz;
+	}
+
 	/* get global mall allocation */
 	if (dc->res_pool->funcs->calculate_mall_ways_from_bytes) {
 		context->bw_ctx.bw.dcn.clk.num_ways = dc->res_pool->funcs->calculate_mall_ways_from_bytes(dc, context->bw_ctx.bw.dcn.mall_subvp_size_bytes);
Signature · 1 line
2.53.0
#47 lore raw

PATCH 45/49 drm/amd/display: Fixes for dcn42b_soc_bb.h

In reply to Fangzhi Zuo

From: Matthew Stewart <[email protected]>

[why]

Some values were found to be incorrect.

---
 .../dc/dml2_0/dml21/inc/bounding_boxes/dcn42b_soc_bb.h        | 4 ++--
 1 file changed, 2 insertions(+), 2 deletions(-)
drivers/gpu/drm/amd/display/dc/dml2_0/dml21/inc/bounding_boxes/dcn42b_soc_bb.h +2 -2
index 60ef56419846..5d844ff4b671 100644
@@ -210,7 +210,7 @@ static const struct dml2_soc_bb dml2_socbb_dcn42b = {
 	.fabric_datapath_to_dcn_data_return_bytes = 32,
 	.return_bus_width_bytes = 64,
 	.hostvm_min_page_size_kbytes = 4,
-	.gpuvm_min_page_size_kbytes = 256,
+	.gpuvm_min_page_size_kbytes = 4,
 	.gpuvm_max_page_table_levels = 1,
 	.hostvm_max_non_cached_page_table_levels = 2,
 	.phy_downspread_percent = 0.38,
@@ -236,7 +236,7 @@ static const struct dml2_ip_capabilities dml2_dcn42b_max_ip_caps = {
 	.config_return_buffer_segment_size_in_kbytes = 64,
 	.meta_fifo_size_in_kentries = 32,
 	.compressed_buffer_segment_size_in_kbytes = 64,
-	.cursor_buffer_size = 24,
+	.cursor_buffer_size = 42,
 	.max_flip_time_us = 110,
 	.max_flip_time_lines = 50,
 	.hostvm_mode = 0,
Signature · 1 line
2.53.0
#48 lore raw

PATCH 46/49 drm/amd/display: Fix rounding errors in CalculatePrefetchSchedule

In reply to Fangzhi Zuo

From: Matthew Stewart <[email protected]>

[why]

Rounding errors were causing mode validation to fail in some cases when it should not. (IE. Increasing fclk from a lower value could lead to validation failure, which should not happen.)

---
 .../dc/dml2_0/dml21/src/dml2_core/dml2_core_dcn4_calcs.c | 9 ++++++---
 1 file changed, 6 insertions(+), 3 deletions(-)
drivers/gpu/drm/amd/display/dc/dml2_0/dml21/src/dml2_core/dml2_core_dcn4_calcs.c +6 -3
index da9a1c4e2bdc..4ca6a4521f11 100644
@@ -5622,7 +5622,8 @@ static bool CalculatePrefetchSchedule(struct dml2_core_internal_scratch *scratch
 				+ 2 * (p->PixelPTEBytesPerRow * p->HostVMInefficiencyFactor + p->meta_row_bytes + tdlut_row_bytes)
 				+ *p->prefetch_sw_bytes)
 				/ (*p->Tpre_rounded - *p->Tno_bw);
-			s->Tsw_est1 = *p->prefetch_sw_bytes / s->prefetch_bw1;
+			/* due to rounding, VM can clamp to +1/4, Row can clamp to +2/4, giving SW less time */
+			s->Tsw_est1 = *p->prefetch_sw_bytes / s->prefetch_bw1 - 3.0 * s->LineTime / 4.0;
 		} else
 			s->prefetch_bw1 = 0;
 
@@ -5646,7 +5647,8 @@ static bool CalculatePrefetchSchedule(struct dml2_core_internal_scratch *scratch
 		if (*p->Tpre_rounded - *p->Tno_bw - 2.0 * s->Tr0_trips_rounded > 0) {
 			s->prefetch_bw2 = (vm_bytes * p->HostVMInefficiencyFactor + *p->prefetch_sw_bytes) /
 			(*p->Tpre_rounded - *p->Tno_bw - 2.0 * s->Tr0_trips_rounded);
-			s->Tsw_est2 = *p->prefetch_sw_bytes / s->prefetch_bw2;
+			/* due to rounding, VM can clamp to +1/4  */
+			s->Tsw_est2 = *p->prefetch_sw_bytes / s->prefetch_bw2 - 1.0 * s->LineTime / 4.0;
 		} else
 			s->prefetch_bw2 = 0;
 
@@ -5660,7 +5662,8 @@ static bool CalculatePrefetchSchedule(struct dml2_core_internal_scratch *scratch
 		if (*p->Tpre_rounded - s->Tvm_trips_rounded > 0) {
 			s->prefetch_bw3 = (2 * (p->PixelPTEBytesPerRow * p->HostVMInefficiencyFactor + p->meta_row_bytes + tdlut_row_bytes) + *p->prefetch_sw_bytes) /
 				(*p->Tpre_rounded - s->Tvm_trips_rounded);
-			s->Tsw_est3 = *p->prefetch_sw_bytes / s->prefetch_bw3;
+			/* due to rounding, Row can clamp to +2/4  */
+			s->Tsw_est3 = *p->prefetch_sw_bytes / s->prefetch_bw3 - 2.0 * s->LineTime / 4.0;
 		} else
 			s->prefetch_bw3 = 0;
 
Signature · 1 line
2.53.0
#49 lore raw

PATCH 47/49 drm/amd/display: plumb PMO per-plane pstate methods into mode_support

In reply to Fangzhi Zuo

From: Alexander Chechik <[email protected]>

[Why]
mode_support reads mode_lib.ms.uclk_pstate_switch_modes to enforce the vactive pstate margin, but nothing populates it: the memset clears it and the PMO selection is never passed in. The check always sees na and never runs, so a plane with negative vactive margin can still pass and blank the display.

[How]
Add a const per-plane pstate-method pointer to mode_support_ex, point it at stage3.pstate_switch_modes when stage 3 has run (NULL otherwise), and copy it into mode_lib.ms after the memset. Scope the support-required check to the vactive methods it governs (vactive, fw_vactive_drr) so SVP, DRR and vblank planes are not rejected by the vactive support flag.

---
 .../dml2_0/dml21/src/dml2_core/dml2_core_dcn4.c | 10 +++-------
 .../dml21/src/dml2_core/dml2_core_dcn4_calcs.c  | 17 +++++++++++++----
 .../src/dml2_core/dml2_core_shared_types.h      |  1 +
 3 files changed, 17 insertions(+), 11 deletions(-)
drivers/gpu/drm/amd/display/dc/dml2_0/dml21/src/dml2_core/dml2_core_dcn4.c +3 -7
index 45f1bf5e14bf..6ea36aedcf20 100644
@@ -554,13 +554,9 @@ bool core_dcn4_mode_support(struct dml2_core_mode_support_in_out *in_out)
 	l->mode_support_ex_params.min_clk_index = in_out->min_clk_index;
 	l->mode_support_ex_params.out_evaluation_info = &in_out->mode_support_result.cfg_support_info.clean_me_up.support_info;
 
-	for (i = 0; i < l->svp_expanded_display_cfg.num_planes; i++) {
-		if (i < in_out->display_cfg->display_config.num_planes)
-			core->clean_me_up.mode_lib.ms.uclk_pstate_switch_modes[i] =
-				in_out->display_cfg->stage3.pstate_switch_modes[i];
-		else
-			core->clean_me_up.mode_lib.ms.uclk_pstate_switch_modes[i] = dml2_pstate_method_na;
-	}
+	l->mode_support_ex_params.uclk_pstate_switch_modes =
+		in_out->display_cfg->stage3.performed ?
+			in_out->display_cfg->stage3.pstate_switch_modes : NULL;
 
 	result = dml2_core_calcs_mode_support_ex(&l->mode_support_ex_params);
 
drivers/gpu/drm/amd/display/dc/dml2_0/dml21/src/dml2_core/dml2_core_dcn4_calcs.c +13 -4
index 4ca6a4521f11..09452f3e49db 100644
@@ -8057,6 +8057,16 @@ static bool dml_core_mode_support(struct dml2_core_calcs_mode_support_ex *in_out
 	memset(&mode_lib->ms, 0, sizeof(struct dml2_core_internal_mode_support));
 
 	mode_lib->ms.num_active_planes = display_cfg->num_planes;
+
+	for (k = 0; k < mode_lib->ms.num_active_planes; k++) {
+		if (in_out_params->uclk_pstate_switch_modes &&
+				!dml_is_phantom_pipe(&display_cfg->plane_descriptors[k]))
+			mode_lib->ms.uclk_pstate_switch_modes[k] =
+				in_out_params->uclk_pstate_switch_modes[k];
+		else
+			mode_lib->ms.uclk_pstate_switch_modes[k] = dml2_pstate_method_na;
+	}
+
 	get_stream_output_bpp(s->OutputBpp, display_cfg);
 
 	mode_lib->ms.state_idx = in_out_params->min_clk_index;
@@ -9644,14 +9654,13 @@ static bool dml_core_mode_support(struct dml2_core_calcs_mode_support_ex *in_out
 
 	if (!display_cfg->overrides.all_streams_blanked) {
 		for (k = 0; k < mode_lib->ms.num_active_planes; k++) {
-			if (mode_lib->ms.uclk_pstate_switch_modes[k] == dml2_pstate_method_na)
+			if (mode_lib->ms.uclk_pstate_switch_modes[k] != dml2_pstate_method_vactive &&
+					mode_lib->ms.uclk_pstate_switch_modes[k] != dml2_pstate_method_fw_vactive_drr)
 				continue;
 
 			mode_lib->ms.support.global_dram_clock_change_support_required = true;
 
-			if ((mode_lib->ms.uclk_pstate_switch_modes[k] == dml2_pstate_method_vactive ||
-					mode_lib->ms.uclk_pstate_switch_modes[k] == dml2_pstate_method_fw_vactive_drr) &&
-					mode_lib->ms.VActiveLatencyHidingMargin[k] < 0)
+			if (mode_lib->ms.VActiveLatencyHidingMargin[k] < 0)
 				mode_lib->ms.support.global_dram_clock_change_supported = false;
 		}
 	}
drivers/gpu/drm/amd/display/dc/dml2_0/dml21/src/dml2_core/dml2_core_shared_types.h +1 -0
index 131cec64aa48..b8af72392176 100644
@@ -2333,6 +2333,7 @@ struct dml2_core_calcs_mode_support_ex {
 	int min_clk_index;
 	//unsigned int in_state_index;
 	struct dml2_core_internal_mode_support_info *out_evaluation_info;
+	const enum dml2_pstate_method *uclk_pstate_switch_modes;
 };
 
 struct core_display_cfg_support_info;
Signature · 1 line
2.53.0
#50 lore raw

PATCH 48/49 drm/amd/display: dispatch compressed FRL cap check inside dml1_frl_cap_chk_inter

In reply to Fangzhi Zuo

[why]
DSC over HDMI FRL (e.g. 4k144) was pruned by DML mode support because the compressed FRL cap check was never reached.

dml32_TruncToValidBPP() validates the FRL output by calling dml1_frl_cap_chk_inter() directly. The compressed-vs-uncompressed dispatch (if params->compressed -> dml1_frl_cap_chk_compressed()) had been moved up into the top-level dml1_frl_cap_chk() wrapper, leaving dml1_frl_cap_chk_inter() as uncompressed-only. As a result a DSC stream routed through TruncToValidBPP was validated against the full uncompressed bandwidth, failed the cap check, and the mode was pruned (vlevel == num_states).

[how]
Move the compressed dispatch back into dml1_frl_cap_chk_inter() so every caller of _inter() (including TruncToValidBPP) honours params->compressed. This matches the internal DAL tree.

---
 drivers/gpu/drm/amd/display/dc/dml/dml1_frl_cap_chk.c | 10 +++++-----
 1 file changed, 5 insertions(+), 5 deletions(-)
drivers/gpu/drm/amd/display/dc/dml/dml1_frl_cap_chk.c +5 -5
index 260f58a97fc7..da2c92e5c02f 100644
@@ -630,17 +630,17 @@ enum frl_cap_chk_result dml1_frl_cap_chk(struct frl_cap_chk_params *params)
 {
 	struct frl_cap_chk_intermediates inter;
 
-#if defined (CONFIG_DRM_AMD_DC_FP)
-	if (params->compressed)
-		return dml1_frl_cap_chk_compressed(params, &inter);
-#endif
-
 	return dml1_frl_cap_chk_inter(params, &inter);
 }
 
 enum frl_cap_chk_result dml1_frl_cap_chk_inter(struct frl_cap_chk_params *params,
 					       struct frl_cap_chk_intermediates *inter)
 {
+#if defined (CONFIG_DRM_AMD_DC_FP)
+	if (params->compressed)
+		return dml1_frl_cap_chk_compressed(params, inter);
+#endif
+
 	return dml1_frl_cap_chk_uncompressed(params, inter);
 }
 
Signature · 1 line
2.53.0
#51 lore raw

PATCH 49/49 drm/amd/display: Promote DC to 3.2.391

In reply to Fangzhi Zuo

From: "Santhosh, Ashwin" <[email protected]>

This DC patchset brings improvements in multiple areas. In summary, we have:
* Expand KUnit test
* dm refactor ongoing
* Fix apple 5k tiled monitor light up
* Fix frl dsc upstream mistake
* dcn42 fixes

---
 drivers/gpu/drm/amd/display/dc/dc.h | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)
drivers/gpu/drm/amd/display/dc/dc.h +1 -1
index 8eaa219132a6..63c0dec85697 100644
@@ -66,7 +66,7 @@ struct dcn_dsc_reg_state;
 struct dcn_optc_reg_state;
 struct dcn_dccg_reg_state;
 
-#define DC_VER "3.2.390"
+#define DC_VER "3.2.391"
 
 /**
  * MAX_SURFACES - representative of the upper bound of surfaces that can be piped to a single CRTC
Signature · 1 line
2.53.0