From: Alex Hung <[email protected]> [WHAT] Add KUnit tests for dm_dmub_hw_init() covering the alternate-channel p-state apertures: both apertures published to DML2, and a missing or invalid-size aperture leaving the feature disabled.
Cc: Bhawanpreet Lakha <[email protected]> Signed-off-by: Alex Hung <[email protected]> Signed-off-by: Chenyu Chen <[email protected]> --- .../amdgpu_dm/tests/amdgpu_dm_dmub_test.c | 92 +++++++++++++++++++ 1 file changed, 92 insertions(+) diff --git a/drivers/gpu/drm/amd/display/amdgpu_dm/tests/amdgpu_dm_dmub_test.c b/drivers/gpu/drm/amd/display/amdgpu_dm/tests/amdgpu_dm_dmub_test.c index 595a7dcb57ad..1a4fa8c7e00c 100644 --- a/drivers/gpu/drm/amd/display/amdgpu_dm/tests/amdgpu_dm_dmub_test.c +++ b/drivers/gpu/drm/amd/display/amdgpu_dm/tests/amdgpu_dm_dmub_test.c @@ -835,6 +835,96 @@ static void dm_test_dmub_hw_init_dmcu_abm(struct kunit *test) KUNIT_EXPECT_TRUE(test, abm->dmcu_is_running); } +/* + * Fake discovery MEM_RESERVED_INFO table: the real lookup in + * amdgpu_discovery_get_mem_reserved_region_by_id() walks this cached table. + */ + +#define DM_TEST_VRAM_START 0x8000000000ULL +#define DM_TEST_VRAM_BASE_OFFSET 0x40000000ULL +#define DM_TEST_APERTURE1_START 0x10000000ULL +#define DM_TEST_APERTURE2_START 0x30000000ULL +#define DM_TEST_APERTURE1_SIZE SZ_16M +#define DM_TEST_APERTURE2_SIZE SZ_32M +#define DM_TEST_MC_BASE(s) ((s) + DM_TEST_VRAM_START - DM_TEST_VRAM_BASE_OFFSET) + +static void dm_test_set_reserved_regions(struct kunit *test, struct amdgpu_device *adev, + u32 num_regions, u64 aperture2_size) +{ + struct mem_reserved_info_table_v1_0 *table; + + table = kunit_kzalloc(test, sizeof(*table), GFP_KERNEL); + KUNIT_ASSERT_NOT_NULL(test, table); + + table->list_num = cpu_to_le32(num_regions); + table->list[0].reserved_region_id = cpu_to_le32(G7_PSTATE_APERTURE1_ID); + table->list[0].reserved_region_size = cpu_to_le64(DM_TEST_APERTURE1_SIZE); + table->list[0].reserved_region_start = cpu_to_le64(DM_TEST_APERTURE1_START); + table->list[1].reserved_region_id = cpu_to_le32(G7_PSTATE_APERTURE2_ID); + table->list[1].reserved_region_size = cpu_to_le64(aperture2_size); + table->list[1].reserved_region_start = cpu_to_le64(DM_TEST_APERTURE2_START); + + adev->discovery.mem_reserved_table = table; + adev->gmc.vram_start = DM_TEST_VRAM_START; + adev->vm_manager.vram_base_offset = DM_TEST_VRAM_BASE_OFFSET; + adev->ip_versions[DCE_HWIP][0] = IP_VERSION(6, 0, 0); +} + +/** + * dm_test_dmub_hw_init_alt_channel_apertures - Test hw init publishes both p-state apertures + * @test: The KUnit test context + * + * With both G7 p-state apertures present in the discovery table, + * dm_dmub_hw_init() should translate each base into MC space and hand bits + * [47:16] and the size to DML2. + */ +static void dm_test_dmub_hw_init_alt_channel_apertures(struct kunit *test) +{ + struct amdgpu_device *adev = dm_test_alloc_adev_with_dmub(test); + struct dml2_soc_alt_ch_info *cfg = &adev->dm.dc->dml2_options.alt_ch_cfg; + + dm_test_set_reserved_regions(test, adev, 2, DM_TEST_APERTURE2_SIZE); + + KUNIT_EXPECT_EQ(test, dm_dmub_hw_init(adev), 0); + KUNIT_EXPECT_EQ(test, cfg->region_base_addr_47_16[0], + (u32)(DM_TEST_MC_BASE(DM_TEST_APERTURE1_START) >> 16)); + KUNIT_EXPECT_EQ(test, cfg->region_base_addr_47_16[1], + (u32)(DM_TEST_MC_BASE(DM_TEST_APERTURE2_START) >> 16)); + KUNIT_EXPECT_EQ(test, cfg->region_size_bytes[0], (u32)DM_TEST_APERTURE1_SIZE); + KUNIT_EXPECT_EQ(test, cfg->region_size_bytes[1], (u32)DM_TEST_APERTURE2_SIZE); +} + +/** + * dm_test_dmub_hw_init_alt_channel_rejected - Test unusable apertures disable the feature + * @test: The KUnit test context + * + * A missing aperture 2, a zero-sized one or one of at least 0xfff MiB disables + * the feature, and dm_dmub_hw_init() must not publish the valid aperture 1. + */ +static void dm_test_dmub_hw_init_alt_channel_rejected(struct kunit *test) +{ + static const struct { + u32 num_regions; + u64 aperture2_size; + } cases[] = { + { 1, DM_TEST_APERTURE2_SIZE }, + { 2, 0 }, + { 2, 0xfffULL << 20 }, + }; + struct amdgpu_device *adev; + unsigned int i; + + for (i = 0; i < ARRAY_SIZE(cases); i++) { + adev = dm_test_alloc_adev_with_dmub(test); + dm_test_set_reserved_regions(test, adev, cases[i].num_regions, + cases[i].aperture2_size); + + KUNIT_EXPECT_EQ(test, dm_dmub_hw_init(adev), 0); + KUNIT_EXPECT_EQ_MSG(test, adev->dm.dc->dml2_options.alt_ch_cfg.region_size_bytes[0], + 0, "case %u", i); + } +} + /* Tests for dm_dmub_hw_resume() */ /** @@ -1958,6 +2048,8 @@ static struct kunit_case amdgpu_dm_dmub_tests[] = { KUNIT_CASE(dm_test_dmub_hw_init_sanity_checks_dcn31), KUNIT_CASE(dm_test_dmub_hw_init_sanity_checks_dcn314), KUNIT_CASE(dm_test_dmub_hw_init_dmcu_abm), + KUNIT_CASE(dm_test_dmub_hw_init_alt_channel_apertures), + KUNIT_CASE(dm_test_dmub_hw_init_alt_channel_rejected), /* dm_dmub_hw_resume() */ KUNIT_CASE(dm_test_dmub_hw_resume_no_dmub_srv), KUNIT_CASE(dm_test_dmub_hw_resume_initialized_dmub), -- 2.43.0
