From patchwork Fri Jan 26 15:48:01 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: Rodrigo Siqueira Jordao X-Patchwork-Id: 13532853 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from gabe.freedesktop.org (gabe.freedesktop.org [131.252.210.177]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.lore.kernel.org (Postfix) with ESMTPS id C779DC48260 for ; Fri, 26 Jan 2024 15:51:36 +0000 (UTC) Received: from gabe.freedesktop.org (localhost [127.0.0.1]) by gabe.freedesktop.org (Postfix) with ESMTP id 46D4310FBC1; Fri, 26 Jan 2024 15:51:32 +0000 (UTC) Received: from NAM11-DM6-obe.outbound.protection.outlook.com (mail-dm6nam11on2052.outbound.protection.outlook.com [40.107.223.52]) by gabe.freedesktop.org (Postfix) with ESMTPS id 587C510FBC2; Fri, 26 Jan 2024 15:51:30 +0000 (UTC) ARC-Seal: i=1; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=none; b=W+Y1Bjqavcpo3NLYycdh9IPpHr/aPA6cb8gbvNu9P1dtoBoxTIoAHCRwkM4oDsSOcfZoZiiCag58rinSFzoHVi3bKOE4PkJ1k19hBWUwDJ+dAPCfYc9NAXYWUj2pGL7RUxqw/u4wvudBxNAaP1qqalsggRSe46HyicgZjlJPg12CXhFzB/t70JoDzILi8gJSKzaDDXowCrQZara500TbB3M31j/nji1ERNnZjyHy0BugUUrCCwbvnLGf+Jcq4u9vK2nVPxyaOZmK21ty+lXU8B68zWBhYWMLgFEZnBDQjC6h6RMe2V0mZMLT9SYcOqqDVxJYnUk3xY2vSuJsSFZiqw== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=microsoft.com; s=arcselector9901; h=From:Date:Subject:Message-ID:Content-Type:MIME-Version:X-MS-Exchange-AntiSpam-MessageData-ChunkCount:X-MS-Exchange-AntiSpam-MessageData-0:X-MS-Exchange-AntiSpam-MessageData-1; bh=MgNSpUKd2DbYguJdVHuJS3Znb09skLDIA8fhHAnCZSo=; b=RDOfaXK/IQMsPMZ5CfPJL7YILTJEZwbRGZvCcncCucq4b7OjCMa4HR23/iT2E9Cebmi1zMr7WRCW5cGiUwjinyHfp2OoES2BLFYtiVQ6rouNbybvmq/vZ5sQtqIrMG8lzwsxjTMAHO9OQfdAfZi5kAWYCkSfux5Gv38lwA/+JwiL2JlIcC8aAv8pjMLwzIa05KJ5RhE/oXFNiwVPrQZY3//bqvY5lwtoPBk1ElZ7vvkHif4its3BAAAZbfu81gWWsp4ZhSHz3Uc0VGbWV/g2ehO2PYBCjEQkIeTiDGLaEyw14koZxHniOdtoztpVGwX4oSdQBFghcSBhYUL/736I9Q== ARC-Authentication-Results: i=1; mx.microsoft.com 1; spf=pass (sender ip is 165.204.84.17) smtp.rcpttodomain=linux.ie smtp.mailfrom=amd.com; dmarc=pass (p=quarantine sp=quarantine pct=100) action=none header.from=amd.com; dkim=none (message not signed); arc=none (0) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=amd.com; s=selector1; h=From:Date:Subject:Message-ID:Content-Type:MIME-Version:X-MS-Exchange-SenderADCheck; bh=MgNSpUKd2DbYguJdVHuJS3Znb09skLDIA8fhHAnCZSo=; b=BlTxOvb827z2ETACHE2PUO1HyuPfvVfpU/gH9X8whf5fRWFJrwYrd4sm2iT84z1pydSD4KZwm4CpeJSpqf/UqES0ZnB64stzyU8PjrhD+0ScI3RVhVGkgO5c168BbFlr18RsyOnI1C14Mr/5hUL2shHnF87RAKLyNnuVPDJ0rTc= Received: from SJ0PR03CA0063.namprd03.prod.outlook.com (2603:10b6:a03:331::8) by DS0PR12MB7946.namprd12.prod.outlook.com (2603:10b6:8:151::13) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.7228.27; Fri, 26 Jan 2024 15:51:23 +0000 Received: from SJ1PEPF00001CDF.namprd05.prod.outlook.com (2603:10b6:a03:331:cafe::5f) by SJ0PR03CA0063.outlook.office365.com (2603:10b6:a03:331::8) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.7228.27 via Frontend Transport; Fri, 26 Jan 2024 15:51:23 +0000 X-MS-Exchange-Authentication-Results: spf=pass (sender IP is 165.204.84.17) smtp.mailfrom=amd.com; dkim=none (message not signed) header.d=none;dmarc=pass action=none header.from=amd.com; Received-SPF: Pass (protection.outlook.com: domain of amd.com designates 165.204.84.17 as permitted sender) receiver=protection.outlook.com; client-ip=165.204.84.17; helo=SATLEXMB04.amd.com; pr=C Received: from SATLEXMB04.amd.com (165.204.84.17) by SJ1PEPF00001CDF.mail.protection.outlook.com (10.167.242.7) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256) id 15.20.7202.16 via Frontend Transport; Fri, 26 Jan 2024 15:51:22 +0000 Received: from smtp.xilinx.com (10.180.168.240) by SATLEXMB04.amd.com (10.181.40.145) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256) id 15.1.2507.34; Fri, 26 Jan 2024 09:51:18 -0600 From: Rodrigo Siqueira To: Alex Deucher , , , David Airlie , Daniel Vetter , Maarten Lankhorst , Maxime Ripard , Thomas Zimmermann , Harry Wentland , Leo Li , "Rodrigo Siqueira" , Nicholas Choi , Daniel Latypov , David Gow , , Subject: [PATCH v4 1/8] drm/amd/display: Introduce KUnit tests for fixed31_32 library Date: Fri, 26 Jan 2024 08:48:01 -0700 Message-ID: <20240126155022.1184856-2-Rodrigo.Siqueira@amd.com> X-Mailer: git-send-email 2.43.0 In-Reply-To: <20240126155022.1184856-1-Rodrigo.Siqueira@amd.com> References: <20240126155022.1184856-1-Rodrigo.Siqueira@amd.com> MIME-Version: 1.0 X-Originating-IP: [10.180.168.240] X-ClientProxiedBy: SATLEXMB04.amd.com (10.181.40.145) To SATLEXMB04.amd.com (10.181.40.145) X-EOPAttributedMessage: 0 X-MS-PublicTrafficType: Email X-MS-TrafficTypeDiagnostic: SJ1PEPF00001CDF:EE_|DS0PR12MB7946:EE_ X-MS-Office365-Filtering-Correlation-Id: a9a9f236-f5f6-4957-dbe3-08dc1e86a592 X-MS-Exchange-SenderADCheck: 1 X-MS-Exchange-AntiSpam-Relay: 0 X-Microsoft-Antispam: BCL:0; X-Microsoft-Antispam-Message-Info: n8auX/zENLpccWpuaeiDjA2kajixzgYgQcJWD0YNjq0VPNk27QV1aE4L2/7Tt7/1IMbA/3N75o15RovIfpx5HkhTxOW/bBI/E2CrgRiWxtL9KUoBlFx+h1xtu+fePKDmy2S5xZo4qgG2KgFakgLiM8nHt7lhCfM+1VRplROCxOjfHRZI+Ria0yPP++PtQhOg3E9LTlbYTpOwb9epE2ajfRZ3DfqwMyhOzn5dNkitYTgVNWuipZWsPLBSGl+hUaBj7LXgE1tkxx6y1zvbx3YULIeyK49/5WdRDvb6QG12uXEPo01PI4PYP09oBQizPbUd8xMpNRx+t0ri0B5grZN/bF3ig0V1BxLhnfhenvhz2lvIKMg5MY+AUvq2UgW7aDZdStzrlLeQ/DQAW+m+qqp7DFlOA/TBUsybA7HMcaskwzp3cCerrcK8prWnGIFtVajrUWgMfsDZK0vprmZ88j60beZkP7buUBUF3nPxRgaaG87/8Daprtwt9C8OQGrwG2B6biLfnEI27OTt6ZwspQjMRp1gtC2qe1cOXStQWaGdmEOi0CLoSC58Y1x+QG69DxLIO+Wib0vk1O+/xy5pCq+ocse3Dzh2Ce3iZhJW6rKtHWYWn2ICbbWbnRpBn7dt6caSuaANtZUCpNwlLKzVZgd3H2h31DL1nmBagQwDFCTbVFLh0D/J6xUbe4tYFSD2l3IHOAjQ0u0usuXpMmx9UWpOeqj1jn0yhMJiKcrtXsjT9PXQeayTgy0cIPXCXvvXQJDcoDzO4lFuWzVSAAFoOjlhPpUREOoOIEaDLjTlk6MMIhs= X-Forefront-Antispam-Report: CIP:165.204.84.17; CTRY:US; LANG:en; SCL:1; SRV:; IPV:CAL; SFV:NSPM; H:SATLEXMB04.amd.com; PTR:InfoDomainNonexistent; CAT:NONE; SFS:(13230031)(4636009)(39860400002)(346002)(396003)(136003)(376002)(230922051799003)(1800799012)(186009)(451199024)(64100799003)(82310400011)(40470700004)(36840700001)(46966006)(921011)(41300700001)(426003)(336012)(26005)(66574015)(2616005)(40460700003)(40480700001)(1076003)(83380400001)(36756003)(36860700001)(54906003)(478600001)(16526019)(6666004)(47076005)(82740400003)(356005)(81166007)(5660300002)(110136005)(70586007)(7416002)(2906002)(316002)(86362001)(70206006)(30864003)(8676002)(8936002)(4326008)(36900700001); DIR:OUT; SFP:1101; X-OriginatorOrg: amd.com X-MS-Exchange-CrossTenant-OriginalArrivalTime: 26 Jan 2024 15:51:22.9115 (UTC) X-MS-Exchange-CrossTenant-Network-Message-Id: a9a9f236-f5f6-4957-dbe3-08dc1e86a592 X-MS-Exchange-CrossTenant-Id: 3dd8961f-e488-4e60-8e11-a82d994e183d X-MS-Exchange-CrossTenant-OriginalAttributedTenantConnectingIp: TenantId=3dd8961f-e488-4e60-8e11-a82d994e183d; Ip=[165.204.84.17]; Helo=[SATLEXMB04.amd.com] X-MS-Exchange-CrossTenant-AuthSource: SJ1PEPF00001CDF.namprd05.prod.outlook.com X-MS-Exchange-CrossTenant-AuthAs: Anonymous X-MS-Exchange-CrossTenant-FromEntityHeader: HybridOnPrem X-MS-Exchange-Transport-CrossTenantHeadersStamped: DS0PR12MB7946 X-BeenThere: dri-devel@lists.freedesktop.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: Direct Rendering Infrastructure - Development List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: tales.aparecida@gmail.com, Trevor Woerner , javierm@redhat.com, dri-devel@lists.freedesktop.org, mwen@igalia.com, =?utf-8?q?Ma=C3=ADra_Canal?= , amd-gfx@lists.freedesktop.org, Isabella Basso , andrealmeid@riseup.net, kunit-dev@googlegroups.com Errors-To: dri-devel-bounces@lists.freedesktop.org Sender: "dri-devel" From: Tales Aparecida The fixed31_32 library performs a lot of the mathematical operations involving fixed-point arithmetic and the conversion of integers to fixed-point representation. This unit tests intend to assure the proper functioning of the basic mathematical operations of fixed-point arithmetic, such as multiplication, conversion from fractional to fixed-point number, and more. Use kunit_tool to run: $ ./tools/testing/kunit/kunit.py run --arch=x86_64 \ --kunitconfig=drivers/gpu/drm/amd/display/tests/ Reviewed-by: David Gow Signed-off-by: Tales Aparecida Signed-off-by: Maíra Canal --- drivers/gpu/drm/amd/display/Kconfig | 13 + drivers/gpu/drm/amd/display/Makefile | 2 +- drivers/gpu/drm/amd/display/tests/Makefile | 12 + .../display/tests/dc/basics/fixpt31_32_test.c | 232 ++++++++++++++++++ 4 files changed, 258 insertions(+), 1 deletion(-) create mode 100644 drivers/gpu/drm/amd/display/tests/Makefile create mode 100644 drivers/gpu/drm/amd/display/tests/dc/basics/fixpt31_32_test.c diff --git a/drivers/gpu/drm/amd/display/Kconfig b/drivers/gpu/drm/amd/display/Kconfig index 901d1961b739..e35eef026097 100644 --- a/drivers/gpu/drm/amd/display/Kconfig +++ b/drivers/gpu/drm/amd/display/Kconfig @@ -51,4 +51,17 @@ config DRM_AMD_SECURE_DISPLAY This option enables the calculation of crc of specific region via debugfs. Cooperate with specific DMCU FW. +config AMD_DC_BASICS_KUNIT_TEST + bool "Enable KUnit tests for the 'basics' sub-component of DAL" if !KUNIT_ALL_TESTS + depends on DRM_AMD_DC && KUNIT + default KUNIT_ALL_TESTS + help + Enables unit tests for the Display Core. Only useful for kernel + devs running KUnit. + + For more information on KUnit and unit tests in general please refer to + the KUnit documentation in Documentation/dev-tools/kunit/. + + If unsure, say N. + endmenu diff --git a/drivers/gpu/drm/amd/display/Makefile b/drivers/gpu/drm/amd/display/Makefile index 92a5c5efcf92..e732a0987d9d 100644 --- a/drivers/gpu/drm/amd/display/Makefile +++ b/drivers/gpu/drm/amd/display/Makefile @@ -45,7 +45,7 @@ subdir-ccflags-y += -I$(FULL_AMD_DISPLAY_PATH)/modules/hdcp #TODO: remove when Timing Sync feature is complete subdir-ccflags-y += -DBUILD_FEATURE_TIMING_SYNC=0 -DAL_LIBS = amdgpu_dm dc modules/freesync modules/color modules/info_packet modules/power dmub/src +DAL_LIBS = amdgpu_dm dc modules/freesync modules/color modules/info_packet modules/power dmub/src tests DAL_LIBS += modules/hdcp diff --git a/drivers/gpu/drm/amd/display/tests/Makefile b/drivers/gpu/drm/amd/display/tests/Makefile new file mode 100644 index 000000000000..ef16497318e8 --- /dev/null +++ b/drivers/gpu/drm/amd/display/tests/Makefile @@ -0,0 +1,12 @@ +# SPDX-License-Identifier: MIT +# +# Makefile for the KUnit Tests for DC +# + +ifdef CONFIG_AMD_DC_BASICS_KUNIT_TEST + DC_TESTS += dc/basics/fixpt31_32_test.o +endif + +AMD_DAL_DC_TESTS = $(addprefix $(AMDDALPATH)/tests/,$(DC_TESTS)) + +AMD_DISPLAY_FILES += $(AMD_DAL_DC_TESTS) diff --git a/drivers/gpu/drm/amd/display/tests/dc/basics/fixpt31_32_test.c b/drivers/gpu/drm/amd/display/tests/dc/basics/fixpt31_32_test.c new file mode 100644 index 000000000000..2fc489203499 --- /dev/null +++ b/drivers/gpu/drm/amd/display/tests/dc/basics/fixpt31_32_test.c @@ -0,0 +1,232 @@ +// SPDX-License-Identifier: MIT +/* Unit tests for display/include/fixed31_32.h and dc/basics/fixpt31_32.c + * + * Copyright (C) 2022, Tales Aparecida + */ + +#include +#include "os_types.h" +#include "fixed31_32.h" + +static const struct fixed31_32 dc_fixpt_minus_one = { -0x100000000LL }; + +/** + * dc_fixpt_from_int_test - KUnit test for dc_fixpt_from_int + * @test: represents a running instance of a test. + */ +static void dc_fixpt_from_int_test(struct kunit *test) +{ + struct fixed31_32 res; + + res = dc_fixpt_from_int(0); + KUNIT_EXPECT_EQ(test, res.value, dc_fixpt_zero.value); + + res = dc_fixpt_from_int(1); + KUNIT_EXPECT_EQ(test, res.value, dc_fixpt_one.value); + + res = dc_fixpt_from_int(-1); + KUNIT_EXPECT_EQ(test, res.value, -dc_fixpt_one.value); + + res = dc_fixpt_from_int(INT_MAX); + KUNIT_EXPECT_EQ(test, res.value, 0x7FFFFFFF00000000LL); + + res = dc_fixpt_from_int(INT_MIN); + KUNIT_EXPECT_EQ(test, res.value, + 0x8000000000000000LL); /* implicit negative signal */ +} + +/** + * dc_fixpt_from_fraction_test - KUnit test for dc_fixpt_from_fraction + * @test: represents a running instance of a test. + */ +static void dc_fixpt_from_fraction_test(struct kunit *test) +{ + struct fixed31_32 res; + + /* Assert signal works as expected */ + res = dc_fixpt_from_fraction(1LL, 1LL); + KUNIT_EXPECT_EQ(test, res.value, dc_fixpt_one.value); + + res = dc_fixpt_from_fraction(-1LL, 1LL); + KUNIT_EXPECT_EQ(test, res.value, -dc_fixpt_one.value); + + res = dc_fixpt_from_fraction(1LL, -1LL); + KUNIT_EXPECT_EQ(test, res.value, -dc_fixpt_one.value); + + res = dc_fixpt_from_fraction(-1LL, -1LL); + KUNIT_EXPECT_EQ(test, res.value, dc_fixpt_one.value); + + /* Assert that the greatest parameter values works as expected */ + res = dc_fixpt_from_fraction(LLONG_MAX, LLONG_MAX); + KUNIT_EXPECT_EQ(test, res.value, dc_fixpt_one.value); + + res = dc_fixpt_from_fraction(LLONG_MIN, LLONG_MIN); + KUNIT_EXPECT_EQ(test, res.value, dc_fixpt_one.value); + + /* Edge case using the smallest fraction possible without LSB rounding */ + res = dc_fixpt_from_fraction(1, 1LL << (FIXED31_32_BITS_PER_FRACTIONAL_PART)); + KUNIT_EXPECT_EQ(test, res.value, dc_fixpt_epsilon.value); + + /* Edge case using the smallest fraction possible with LSB rounding */ + res = dc_fixpt_from_fraction(1, 1LL << (FIXED31_32_BITS_PER_FRACTIONAL_PART + 1)); + KUNIT_EXPECT_EQ(test, res.value, dc_fixpt_epsilon.value); + + /* Assert an nil numerator is a valid input */ + res = dc_fixpt_from_fraction(0LL, LLONG_MAX); + KUNIT_EXPECT_EQ(test, res.value, 0LL); + + /* Edge case using every bit of the decimal part without rounding */ + res = dc_fixpt_from_fraction(8589934590LL, 8589934592LL); + KUNIT_EXPECT_EQ(test, res.value, 0x0FFFFFFFFLL); + + res = dc_fixpt_from_fraction(-8589934590LL, 8589934592LL); + KUNIT_EXPECT_EQ(test, res.value, -0x0FFFFFFFFLL); + + /* Edge case using every bit of the decimal part then rounding LSB */ + res = dc_fixpt_from_fraction(8589934591LL, 8589934592LL); + KUNIT_EXPECT_EQ(test, res.value, dc_fixpt_one.value); + + res = dc_fixpt_from_fraction(-8589934591LL, 8589934592LL); + KUNIT_EXPECT_EQ(test, res.value, -dc_fixpt_one.value); + /* A repeating decimal in binary representation that doesn't round up the LSB */ + res = dc_fixpt_from_fraction(4, 3); + KUNIT_EXPECT_EQ(test, res.value, 0x0000000155555555LL); + + res = dc_fixpt_from_fraction(-4, 3); + KUNIT_EXPECT_EQ(test, res.value, -0x0000000155555555LL); + + /* A repeating decimal in binary representation that rounds up the LSB */ + res = dc_fixpt_from_fraction(5, 3); + KUNIT_EXPECT_EQ(test, res.value, 0x00000001AAAAAAABLL); + + res = dc_fixpt_from_fraction(-5, 3); + KUNIT_EXPECT_EQ(test, res.value, -0x00000001AAAAAAABLL); +} + +/** + * dc_fixpt_mul_test - KUnit test for dc_fixpt_mul + * @test: represents a running instance of a test. + */ +static void dc_fixpt_mul_test(struct kunit *test) +{ + struct fixed31_32 res; + struct fixed31_32 arg; + + /* Assert signal works as expected */ + res = dc_fixpt_mul(dc_fixpt_one, dc_fixpt_one); + KUNIT_EXPECT_EQ(test, res.value, dc_fixpt_one.value); + + res = dc_fixpt_mul(dc_fixpt_minus_one, dc_fixpt_one); + KUNIT_EXPECT_EQ(test, res.value, dc_fixpt_minus_one.value); + + res = dc_fixpt_mul(dc_fixpt_one, dc_fixpt_minus_one); + KUNIT_EXPECT_EQ(test, res.value, dc_fixpt_minus_one.value); + + res = dc_fixpt_mul(dc_fixpt_minus_one, dc_fixpt_minus_one); + KUNIT_EXPECT_EQ(test, res.value, dc_fixpt_one.value); + + /* Assert that the greatest parameter values works as expected */ + arg.value = LONG_MAX; + res = dc_fixpt_mul(arg, dc_fixpt_one); + KUNIT_EXPECT_EQ(test, res.value, arg.value); + + arg.value = LONG_MIN; + res = dc_fixpt_mul(arg, dc_fixpt_one); + KUNIT_EXPECT_EQ(test, res.value, arg.value); + + arg.value = LONG_MAX; + res = dc_fixpt_mul(dc_fixpt_one, arg); + KUNIT_EXPECT_EQ(test, res.value, arg.value); + + arg.value = LONG_MIN; + res = dc_fixpt_mul(dc_fixpt_one, arg); + KUNIT_EXPECT_EQ(test, res.value, arg.value); + + /* Assert it doesn't round LSB as expected */ + arg.value = 0x7FFFFFFF7fffffffLL; + res = dc_fixpt_mul(arg, dc_fixpt_epsilon); + KUNIT_EXPECT_EQ(test, res.value, 0x000000007FFFFFFF); + + /* Assert it rounds LSB as expected */ + arg.value = 0x7FFFFFFF80000000LL; + res = dc_fixpt_mul(arg, dc_fixpt_epsilon); + KUNIT_EXPECT_EQ(test, res.value, 0x0000000080000000); +} + +/** + * dc_fixpt_sqr_test - KUnit test for dc_fixpt_sqr + * @test: represents a running instance of a test. + */ +static void dc_fixpt_sqr_test(struct kunit *test) +{ + struct fixed31_32 res; + struct fixed31_32 arg; + + arg.value = dc_fixpt_one.value; + res = dc_fixpt_sqr(arg); + KUNIT_EXPECT_EQ(test, res.value, dc_fixpt_one.value); + + arg.value = dc_fixpt_minus_one.value; + res = dc_fixpt_sqr(arg); + KUNIT_EXPECT_EQ(test, res.value, dc_fixpt_one.value); + + arg.value = 0; + res = dc_fixpt_sqr(arg); + KUNIT_EXPECT_EQ(test, res.value, 0); + + /* Test some recognizable values */ + arg = dc_fixpt_from_int(100); + res = dc_fixpt_sqr(arg); + KUNIT_EXPECT_EQ(test, res.value, dc_fixpt_from_int(10000).value); + + arg = dc_fixpt_from_fraction(1, 100); + res = dc_fixpt_sqr(arg); + KUNIT_EXPECT_EQ(test, res.value, + dc_fixpt_from_fraction(1, 10000).value); + + /* LSB rounding */ + arg = dc_fixpt_from_fraction(3, 2); + res = dc_fixpt_sqr(arg); + KUNIT_EXPECT_EQ(test, res.value, + dc_fixpt_from_fraction(9, 4).value + 1LL); +} + +/** + * dc_fixpt_recip_test - KUnit test for dc_fixpt_recip + * @test: represents a running instance of a test. + */ +static void dc_fixpt_recip_test(struct kunit *test) +{ + struct fixed31_32 res; + struct fixed31_32 arg; + + /* Assert 1/1 works as expected */ + res = dc_fixpt_recip(dc_fixpt_one); + KUNIT_EXPECT_EQ(test, res.value, dc_fixpt_one.value); + + /* Assert smallest parameters work as expected. */ + arg.value = 3LL; + res = dc_fixpt_recip(arg); + KUNIT_EXPECT_EQ(test, res.value, 0x5555555555555555LL); + + arg.value = -3LL; + res = dc_fixpt_recip(arg); + KUNIT_EXPECT_EQ(test, res.value, -0x5555555555555555LL); +} + +static struct kunit_case dc_basics_fixpt31_32_test_cases[] = { + KUNIT_CASE(dc_fixpt_from_int_test), + KUNIT_CASE(dc_fixpt_from_fraction_test), + KUNIT_CASE(dc_fixpt_mul_test), + KUNIT_CASE(dc_fixpt_sqr_test), + KUNIT_CASE(dc_fixpt_recip_test), + {} +}; + +static struct kunit_suite dc_basics_fixpt31_32_test_suite = { + .name = "dc_basics_fixpt31_32", + .test_cases = dc_basics_fixpt31_32_test_cases, +}; + +kunit_test_suites(&dc_basics_fixpt31_32_test_suite); + From patchwork Fri Jan 26 15:48:02 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: Rodrigo Siqueira Jordao X-Patchwork-Id: 13532855 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from gabe.freedesktop.org (gabe.freedesktop.org [131.252.210.177]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.lore.kernel.org (Postfix) with ESMTPS id AA5AAC47DDF for ; Fri, 26 Jan 2024 15:51:44 +0000 (UTC) Received: from gabe.freedesktop.org (localhost [127.0.0.1]) by gabe.freedesktop.org (Postfix) with ESMTP id 58E3210FBD8; Fri, 26 Jan 2024 15:51:37 +0000 (UTC) Received: from NAM02-BN1-obe.outbound.protection.outlook.com (mail-bn1nam02on2063.outbound.protection.outlook.com [40.107.212.63]) by gabe.freedesktop.org (Postfix) with ESMTPS id 9C78810FBC1; Fri, 26 Jan 2024 15:51:31 +0000 (UTC) ARC-Seal: i=1; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=none; b=h8i2UlnPp08Jmkje3iMKp0JkBf4/xz1tdcUkC5dytmrJzlsCtkFyQxz+5jO/z2AfinolAZmLYQ/Dv2SttM3yGcTetTrqvuCG+o3MZgy0+6dYtf4jtvcF2WHHi5RoOI71Yg5Eq5i8unlR0Px3iYMpTIgyPEt7MpNg9gjksdTKuQ/d3u+6fkm9m+JPnF3wNX+0HRaZgalEkZb71H3PdS6UPHhmLeRKP1UhR4KDGEG5XxufIv8G8woO8KZi2GvjWxoTb+Mu7Q2Fv1KxFdEthOf/LYP8MzoP1YGRLUKwPRYZMwLGvG6PhEr5agGJRjiLe2QT2PB01C0x99Gf9KJjcgTu0g== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=microsoft.com; s=arcselector9901; h=From:Date:Subject:Message-ID:Content-Type:MIME-Version:X-MS-Exchange-AntiSpam-MessageData-ChunkCount:X-MS-Exchange-AntiSpam-MessageData-0:X-MS-Exchange-AntiSpam-MessageData-1; bh=hpcZbrx8X04XZwgi7BeOtouoGw4aVOZAXGAdjxSlg6I=; b=QXNdxLOqQFk9RT5XwI1scKvv3phy0corQpxE6V44YOlk4sPn2tR4xi/b4mfMFnT/6NCp5qvrBTDNVgsYjFJ1i2mO1JROieCk+U9C3Dn1lGYnIst+qzBAX6j4AZYElAbYO9SWO3PQ1PZ3TPtPDU3GNR18Ypu1B6y0IrKMigFdM8hee0MZtMVYstbKHEdyYvXTLESIeVls60MgedU1SgmdT9nSjRWk/ayqpxHXseODSoxHp3BfEUBwwi7g7wCiil8QpTGAxqS33YUYuF3b0BwIB7Eh6Xg3i4aJtEmgnzhDdq1y6Br5kNfhl/BKzyPYkfGP0sxCdq+OlmHLkawUaacC5Q== ARC-Authentication-Results: i=1; mx.microsoft.com 1; spf=pass (sender ip is 165.204.84.17) smtp.rcpttodomain=linux.ie smtp.mailfrom=amd.com; dmarc=pass (p=quarantine sp=quarantine pct=100) action=none header.from=amd.com; dkim=none (message not signed); arc=none (0) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=amd.com; s=selector1; h=From:Date:Subject:Message-ID:Content-Type:MIME-Version:X-MS-Exchange-SenderADCheck; bh=hpcZbrx8X04XZwgi7BeOtouoGw4aVOZAXGAdjxSlg6I=; b=w18yZREZFD1IQF+UIl80DdHb+YqFt5mX25pOat79pAefCLsOJS7mDWxaH4gMwYEv7OUJBJcKIDwzIdsh1XO8IPVL8Z0YLa7aUSwUp7hs+wI1ODhtZrXljN7HpHIUJ90kF3B3xhreZmZblKW7GOThfd8h3Mta+JSDZDHcnDXyDtM= Received: from SJ0PR03CA0075.namprd03.prod.outlook.com (2603:10b6:a03:331::20) by SA3PR12MB7784.namprd12.prod.outlook.com (2603:10b6:806:317::20) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.7228.22; Fri, 26 Jan 2024 15:51:25 +0000 Received: from SJ1PEPF00001CDF.namprd05.prod.outlook.com (2603:10b6:a03:331:cafe::48) by SJ0PR03CA0075.outlook.office365.com (2603:10b6:a03:331::20) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.7228.28 via Frontend Transport; Fri, 26 Jan 2024 15:51:25 +0000 X-MS-Exchange-Authentication-Results: spf=pass (sender IP is 165.204.84.17) smtp.mailfrom=amd.com; dkim=none (message not signed) header.d=none;dmarc=pass action=none header.from=amd.com; Received-SPF: Pass (protection.outlook.com: domain of amd.com designates 165.204.84.17 as permitted sender) receiver=protection.outlook.com; client-ip=165.204.84.17; helo=SATLEXMB04.amd.com; pr=C Received: from SATLEXMB04.amd.com (165.204.84.17) by SJ1PEPF00001CDF.mail.protection.outlook.com (10.167.242.7) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256) id 15.20.7202.16 via Frontend Transport; Fri, 26 Jan 2024 15:51:24 +0000 Received: from smtp.xilinx.com (10.180.168.240) by SATLEXMB04.amd.com (10.181.40.145) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256) id 15.1.2507.34; Fri, 26 Jan 2024 09:51:21 -0600 From: Rodrigo Siqueira To: Alex Deucher , , , David Airlie , Daniel Vetter , Maarten Lankhorst , Maxime Ripard , Thomas Zimmermann , Harry Wentland , Leo Li , "Rodrigo Siqueira" , Nicholas Choi , Daniel Latypov , David Gow , , Subject: [PATCH v4 2/8] drm/amd/display: Introduce KUnit tests to the bw_fixed library Date: Fri, 26 Jan 2024 08:48:02 -0700 Message-ID: <20240126155022.1184856-3-Rodrigo.Siqueira@amd.com> X-Mailer: git-send-email 2.43.0 In-Reply-To: <20240126155022.1184856-1-Rodrigo.Siqueira@amd.com> References: <20240126155022.1184856-1-Rodrigo.Siqueira@amd.com> MIME-Version: 1.0 X-Originating-IP: [10.180.168.240] X-ClientProxiedBy: SATLEXMB04.amd.com (10.181.40.145) To SATLEXMB04.amd.com (10.181.40.145) X-EOPAttributedMessage: 0 X-MS-PublicTrafficType: Email X-MS-TrafficTypeDiagnostic: SJ1PEPF00001CDF:EE_|SA3PR12MB7784:EE_ X-MS-Office365-Filtering-Correlation-Id: 3a383a1f-4152-49d6-7f66-08dc1e86a6ba X-MS-Exchange-SenderADCheck: 1 X-MS-Exchange-AntiSpam-Relay: 0 X-Microsoft-Antispam: BCL:0; X-Microsoft-Antispam-Message-Info: SIWY43HfKAMOLs0snIzulcgCoVWp39HeeofrbImOwkNiexeB03/+iJ0FloqR2MkUHP0/eqxRI6LaGTS5exsmbbl2NnLdtA++k8hVmcLS13KBM2wDey3uY2rF3sBE2CquoToH5cUSDtOgCLGX0EMYAA97OYEL8ikrXvnVzZC0KDPQSjRcEYO0bWkwkqw1i2/IqFleNFe5aDIW9tzm9BHF6a44gUnNa5nwT4KSNUYiF/btiOj6Q5cdLTTcQyWVgsGtmnoummHM0FfRJSTcY652bgEFrdpwwY9wA2ODvlk+HEoeDabMdpZDHLoh4uQkzRbAHNnmyM5f/iRWnrE26i5yJptLRqQgzrFWmRhXDpJifWdx7tlmIqf7wAhByH36qGcwJ/P5u9672C0Ezng6A8zM1hHmopAxQiuMNOCT7CmpwMWzranplNcC2EEbzOfYxCsU8ozw4CYSq887BWEZTyHqFDE7ABfc3pL3ddPCs4mwrXw+Uq8pAgtzIZ5PNbu+9qXyPfllRUrmvA/AI+8rufpElY9VxUoRu0Gt09uNWk98iy7CM8slvuFvJOQybcAJESqvrzc2qBapbyqEZ2y720ptZlMeFE75gSdWYOGai3TtqRqmfzouWhFC2WzZWlUyNghwDVgozb984abnBE2nJhbtPa6n99hfB8n7qt1SbAKND7pR7AfQPfg0JHG1agdTJ1qNxB130XvfRNqle2mi2OzYMVaOZ21dxmzSq3oELwP1VucgHn5iMzVsho+WezbzQFXAzflE4kAd4Uj8RHA1sAw7bg49Rlu1PVGhBRx7PoEp5G4= X-Forefront-Antispam-Report: CIP:165.204.84.17; CTRY:US; LANG:en; SCL:1; SRV:; IPV:CAL; SFV:NSPM; H:SATLEXMB04.amd.com; PTR:InfoDomainNonexistent; CAT:NONE; SFS:(13230031)(4636009)(39860400002)(376002)(396003)(346002)(136003)(230922051799003)(451199024)(1800799012)(64100799003)(82310400011)(186009)(46966006)(36840700001)(40470700004)(5660300002)(2906002)(30864003)(40460700003)(6666004)(426003)(82740400003)(83380400001)(26005)(36756003)(356005)(478600001)(81166007)(16526019)(41300700001)(7416002)(86362001)(2616005)(1076003)(36860700001)(336012)(47076005)(70206006)(316002)(54906003)(8936002)(8676002)(4326008)(921011)(110136005)(40480700001)(70586007)(36900700001); DIR:OUT; SFP:1101; X-OriginatorOrg: amd.com X-MS-Exchange-CrossTenant-OriginalArrivalTime: 26 Jan 2024 15:51:24.8958 (UTC) X-MS-Exchange-CrossTenant-Network-Message-Id: 3a383a1f-4152-49d6-7f66-08dc1e86a6ba X-MS-Exchange-CrossTenant-Id: 3dd8961f-e488-4e60-8e11-a82d994e183d X-MS-Exchange-CrossTenant-OriginalAttributedTenantConnectingIp: TenantId=3dd8961f-e488-4e60-8e11-a82d994e183d; Ip=[165.204.84.17]; Helo=[SATLEXMB04.amd.com] X-MS-Exchange-CrossTenant-AuthSource: SJ1PEPF00001CDF.namprd05.prod.outlook.com X-MS-Exchange-CrossTenant-AuthAs: Anonymous X-MS-Exchange-CrossTenant-FromEntityHeader: HybridOnPrem X-MS-Exchange-Transport-CrossTenantHeadersStamped: SA3PR12MB7784 X-BeenThere: dri-devel@lists.freedesktop.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: Direct Rendering Infrastructure - Development List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: tales.aparecida@gmail.com, Trevor Woerner , javierm@redhat.com, dri-devel@lists.freedesktop.org, mwen@igalia.com, =?utf-8?q?Ma=C3=ADra_Canal?= , amd-gfx@lists.freedesktop.org, Isabella Basso , andrealmeid@riseup.net, kunit-dev@googlegroups.com Errors-To: dri-devel-bounces@lists.freedesktop.org Sender: "dri-devel" From: Maíra Canal KUnit unifies the test structure and provides helper tools that simplify the development of tests. Basic use case allows running tests as regular processes, which makes easier to run unit tests on a development machine and to integrate the tests in a CI system. This commit introduces a unit test to the bw_fixed library, which performs a lot of the mathematical operations involving fixed-point arithmetic and the conversion of integers to fixed-point representation inside the Display Mode Library. As fixed-point representation is the base foundation of the DML calcs operations, this unit tests intend to assure the proper functioning of the basic mathematical operations of fixed-point arithmetic, such as multiplication, conversion from fractional to fixed-point number, and more. You can run it with: ./tools/testing/kunit/kunit.py run \ --arch=x86_64 \ --kunitconfig=drivers/gpu/drm/amd/display/tests/ Co-developed-by: Magali Lemes Signed-off-by: Magali Lemes Co-developed-by: Tales Aparecida Signed-off-by: Tales Aparecida Signed-off-by: Maíra Canal --- drivers/gpu/drm/amd/display/Kconfig | 13 + .../tests/dc/dml/calcs/bw_fixed_test.c | 323 ++++++++++++++++++ 2 files changed, 336 insertions(+) create mode 100644 drivers/gpu/drm/amd/display/tests/dc/dml/calcs/bw_fixed_test.c diff --git a/drivers/gpu/drm/amd/display/Kconfig b/drivers/gpu/drm/amd/display/Kconfig index e35eef026097..d54036dcac78 100644 --- a/drivers/gpu/drm/amd/display/Kconfig +++ b/drivers/gpu/drm/amd/display/Kconfig @@ -51,6 +51,19 @@ config DRM_AMD_SECURE_DISPLAY This option enables the calculation of crc of specific region via debugfs. Cooperate with specific DMCU FW. +config DCE_KUNIT_TEST + bool "Run all KUnit tests for DCE" if !KUNIT_ALL_TESTS + depends on DRM_AMD_DC && KUNIT + default KUNIT_ALL_TESTS + help + Enables unit tests for the Display Controller Engine. Only useful for kernel + devs running KUnit. + + For more information on KUnit and unit tests in general please refer to + the KUnit documentation in Documentation/dev-tools/kunit/. + + If unsure, say N. + config AMD_DC_BASICS_KUNIT_TEST bool "Enable KUnit tests for the 'basics' sub-component of DAL" if !KUNIT_ALL_TESTS depends on DRM_AMD_DC && KUNIT diff --git a/drivers/gpu/drm/amd/display/tests/dc/dml/calcs/bw_fixed_test.c b/drivers/gpu/drm/amd/display/tests/dc/dml/calcs/bw_fixed_test.c new file mode 100644 index 000000000000..1369da49f444 --- /dev/null +++ b/drivers/gpu/drm/amd/display/tests/dc/dml/calcs/bw_fixed_test.c @@ -0,0 +1,323 @@ +// SPDX-License-Identifier: MIT +/* + * KUnit tests for dml/calcs/bw_fixed.h + * + * Copyright (C) 2022, Magali Lemes + * Copyright (C) 2022, Maíra Canal + * Copyright (C) 2022, Tales Aparecida + */ + +#include +#include +#include "bw_fixed.h" + +/** + * DOC: Unit tests for AMDGPU DML calcs/bw_fixed.h + * + * bw_fixed.h performs a lot of the mathematical operations involving + * fixed-point arithmetic and the conversion of integers to fixed-point + * representation. + * + * As fixed-point representation is the base foundation of the DML calcs + * operations, these tests intend to assure the proper functioning of the + * basic mathematical operations of fixed-point arithmetic, such as + * multiplication, conversion from fractional to fixed-point number, and more. + * + */ + +/** + * abs_i64_test - KUnit test for abs_i64 + * @test: represents a running instance of a test. + */ +static void abs_i64_test(struct kunit *test) +{ + KUNIT_EXPECT_EQ(test, 0ULL, abs_i64(0LL)); + + /* Argument type limits */ + KUNIT_EXPECT_EQ(test, (uint64_t)MAX_I64, abs_i64(MAX_I64)); + KUNIT_EXPECT_EQ(test, (uint64_t)MAX_I64 + 1, abs_i64(MIN_I64)); +} + +/** + * bw_int_to_fixed_nonconst_test - KUnit test for bw_int_to_fixed_nonconst + * @test: represents a running instance of a test. + */ +static void bw_int_to_fixed_nonconst_test(struct kunit *test) +{ + struct bw_fixed res; + + /* Add BW_FIXED_BITS_PER_FRACTIONAL_PART trailing 0s to binary number */ + res = bw_int_to_fixed_nonconst(1000); /* 0x3E8 */ + KUNIT_EXPECT_EQ(test, 16777216000, res.value); /* 0x3E8000000 */ + + res = bw_int_to_fixed_nonconst(-1000); /* -0x3E8 */ + KUNIT_EXPECT_EQ(test, -16777216000, res.value); /* -0x3E8000000 */ + + res = bw_int_to_fixed_nonconst(0LL); + KUNIT_EXPECT_EQ(test, 0, res.value); + + /** + * Test corner cases, as the function's argument has to be an int64_t + * between BW_FIXED_MIN_I32 and BW_FIXED_MAX_I32. + */ + res = bw_int_to_fixed_nonconst(BW_FIXED_MAX_I32 - 1); /* 0x7FFFFFFFFE */ + KUNIT_EXPECT_EQ(test, 9223372036821221376, res.value); /* 0x7FFFFFFFFE000000 */ + + res = bw_int_to_fixed_nonconst(BW_FIXED_MIN_I32 + 1); /* -0x7FFFFFFFFF */ + KUNIT_EXPECT_EQ(test, -9223372036837998592, res.value); /* -0x7FFFFFFFFF000000 */ +} + +/** + * bw_frc_to_fixed_test - KUnit test for bw_frc_to_fixed + * @test: represents a running instance of a test. + */ +static void bw_frc_to_fixed_test(struct kunit *test) +{ + struct bw_fixed res; + + /* Extreme scenarios */ + + /* A fraction of N/N should result in "1.0" */ + res = bw_frc_to_fixed(MAX_I64, MAX_I64); + KUNIT_EXPECT_EQ(test, 1LL << BW_FIXED_BITS_PER_FRACTIONAL_PART, res.value); + + res = bw_frc_to_fixed(1, MAX_I64); + KUNIT_EXPECT_EQ(test, 0LL, res.value); + + res = bw_frc_to_fixed(0, MAX_I64); + KUNIT_EXPECT_EQ(test, 0LL, res.value); + + /* Turn a repeating decimal to the fixed-point representation */ + + /* A repeating decimal that doesn't round up the LSB */ + res = bw_frc_to_fixed(4, 3); + KUNIT_EXPECT_EQ(test, 22369621LL, res.value); /* 0x1555555 */ + + res = bw_frc_to_fixed(-4, 3); + KUNIT_EXPECT_EQ(test, -22369621LL, res.value); /* -0x1555555 */ + + res = bw_frc_to_fixed(99999997, 100000000); + KUNIT_EXPECT_EQ(test, 16777215LL, res.value); /* 0x0FFFFFF */ + + /* A repeating decimal that rounds up the MSB */ + res = bw_frc_to_fixed(5, 3); + KUNIT_EXPECT_EQ(test, 27962027LL, res.value); /* 0x1AAAAAB */ + + res = bw_frc_to_fixed(-5, 3); + KUNIT_EXPECT_EQ(test, -27962027LL, res.value); /* -0x1AAAAAB */ + + res = bw_frc_to_fixed(99999998, 100000000); + KUNIT_EXPECT_EQ(test, 1LL << BW_FIXED_BITS_PER_FRACTIONAL_PART, res.value); + + /* Turn a terminating decimal to the fixed-point representation */ + res = bw_frc_to_fixed(62609, 100); + KUNIT_EXPECT_EQ(test, 10504047165LL, res.value); /* 0X272170A3D */ + + res = bw_frc_to_fixed(-62609, 100); + KUNIT_EXPECT_EQ(test, -10504047165LL, res.value); /* -0X272170A3D */ +} + +/** + * bw_floor2_test - KUnit test for bw_floor2 + * @test: represents a running instance of a test. + */ +static void bw_floor2_test(struct kunit *test) +{ + struct bw_fixed arg; + struct bw_fixed significance; + struct bw_fixed res; + + /* Round 10 down to the nearest multiple of 3 */ + arg.value = 10; + significance.value = 3; + res = bw_floor2(arg, significance); + KUNIT_EXPECT_EQ(test, 9, res.value); + + /* Round 10 down to the nearest multiple of 5 */ + arg.value = 10; + significance.value = 5; + res = bw_floor2(arg, significance); + KUNIT_EXPECT_EQ(test, 10, res.value); + + /* Round 100 down to the nearest multiple of 7 */ + arg.value = 100; + significance.value = 7; + res = bw_floor2(arg, significance); + KUNIT_EXPECT_EQ(test, 98, res.value); + + /* Round an integer down to its nearest multiple should return itself */ + arg.value = MAX_I64; + significance.value = MAX_I64; + res = bw_floor2(arg, significance); + KUNIT_EXPECT_EQ(test, MAX_I64, res.value); + + arg.value = MIN_I64; + significance.value = MIN_I64; + res = bw_floor2(arg, significance); + KUNIT_EXPECT_EQ(test, MIN_I64, res.value); + + /* Value is a multiple of significance, result should be value */ + arg.value = MAX_I64; + significance.value = MIN_I64 + 1; + res = bw_floor2(arg, significance); + KUNIT_EXPECT_EQ(test, MAX_I64, res.value); + + /* Round 0 down to the nearest multiple of any number should return 0 */ + arg.value = 0; + significance.value = MAX_I64; + res = bw_floor2(arg, significance); + KUNIT_EXPECT_EQ(test, 0, res.value); + + arg.value = 0; + significance.value = MIN_I64; + res = bw_floor2(arg, significance); + KUNIT_EXPECT_EQ(test, 0, res.value); +} + +/** + * bw_ceil2_test - KUnit test for bw_ceil2 + * @test: represents a running instance of a test. + */ +static void bw_ceil2_test(struct kunit *test) +{ + struct bw_fixed arg; + struct bw_fixed significance; + struct bw_fixed res; + + /* Round 10 up to the nearest multiple of 3 */ + arg.value = 10; + significance.value = 3; + res = bw_ceil2(arg, significance); + KUNIT_EXPECT_EQ(test, 12, res.value); + + /* Round 10 up to the nearest multiple of 5 */ + arg.value = 10; + significance.value = 5; + res = bw_ceil2(arg, significance); + KUNIT_EXPECT_EQ(test, 10, res.value); + + /* Round 100 up to the nearest multiple of 7 */ + arg.value = 100; + significance.value = 7; + res = bw_ceil2(arg, significance); + KUNIT_EXPECT_EQ(test, 105, res.value); + + /* Round an integer up to its nearest multiple should return itself */ + arg.value = MAX_I64; + significance.value = MAX_I64; + res = bw_ceil2(arg, significance); + KUNIT_EXPECT_EQ(test, MAX_I64, res.value); + + arg.value = MIN_I64 + 1; + significance.value = MIN_I64 + 1; + res = bw_ceil2(arg, significance); + KUNIT_EXPECT_EQ(test, MIN_I64 + 1, res.value); + + /* Value is a multiple of significance, result should be value */ + arg.value = MAX_I64; + significance.value = MIN_I64 + 1; + res = bw_ceil2(arg, significance); + KUNIT_EXPECT_EQ(test, MAX_I64, res.value); + + /* Round 0 up to the nearest multiple of any number should return 0 */ + arg.value = 0; + significance.value = MAX_I64; + res = bw_ceil2(arg, significance); + KUNIT_EXPECT_EQ(test, 0, res.value); + + arg.value = 0; + significance.value = MIN_I64; + res = bw_ceil2(arg, significance); + KUNIT_EXPECT_EQ(test, 0, res.value); +} + +/** + * bw_mul_test - KUnit test for bw_mul + * @test: represents a running instance of a test. + */ +static void bw_mul_test(struct kunit *test) +{ + struct bw_fixed arg1; + struct bw_fixed arg2; + struct bw_fixed res; + struct bw_fixed expected; + + /* Extreme scenario */ + arg1.value = MAX_I64; + arg2.value = MIN_I64; + res = bw_mul(arg1, arg2); + KUNIT_EXPECT_EQ(test, BW_FIXED_MAX_I32 + 1, res.value); + + /* Testing multiplication property: x * 1 = x */ + arg1.value = 1; + arg2.value = MAX_I64; + res = bw_mul(arg1, arg2); + KUNIT_EXPECT_EQ(test, BW_FIXED_MAX_I32 + 1, res.value); + + arg1.value = 1; + arg2.value = MIN_I64; + res = bw_mul(arg1, arg2); + KUNIT_EXPECT_EQ(test, BW_FIXED_MIN_I32, res.value); + + /* Testing multiplication property: x * 0 = 0 */ + arg1.value = 0; + arg2.value = 0; + res = bw_mul(arg1, arg2); + KUNIT_EXPECT_EQ(test, 0, res.value); + + arg1.value = 0; + arg2.value = MAX_I64; + res = bw_mul(arg1, arg2); + KUNIT_EXPECT_EQ(test, 0, res.value); + + arg1.value = 0; + arg2.value = MIN_I64; + res = bw_mul(arg1, arg2); + KUNIT_EXPECT_EQ(test, 0, res.value); + + /* Testing multiplication between integers */ + res = bw_mul(bw_int_to_fixed(8), bw_int_to_fixed(10)); + KUNIT_EXPECT_EQ(test, 1342177280LL, res.value); /* 0x50000000 */ + + res = bw_mul(bw_int_to_fixed(10), bw_int_to_fixed(5)); + KUNIT_EXPECT_EQ(test, 838860800LL, res.value); /* 0x32000000 */ + + res = bw_mul(bw_int_to_fixed(-10), bw_int_to_fixed(7)); + KUNIT_EXPECT_EQ(test, -1174405120LL, res.value); /* -0x46000000 */ + + /* Testing multiplication between fractions and integers */ + res = bw_mul(bw_frc_to_fixed(4, 3), bw_int_to_fixed(3)); + expected = bw_int_to_fixed(4); + + /* + * As bw_frc_to_fixed(4, 3) didn't round up the fixed-point representation, + * the expected must be subtracted by 1. + */ + KUNIT_EXPECT_EQ(test, expected.value - 1, res.value); + + res = bw_mul(bw_frc_to_fixed(5, 3), bw_int_to_fixed(3)); + expected = bw_int_to_fixed(5); + + /* + * As bw_frc_to_fixed(5, 3) rounds up the fixed-point representation, + * the expected must be added by 1. + */ + KUNIT_EXPECT_EQ(test, expected.value + 1, res.value); +} + +static struct kunit_case bw_fixed_test_cases[] = { + KUNIT_CASE(abs_i64_test), + KUNIT_CASE(bw_int_to_fixed_nonconst_test), + KUNIT_CASE(bw_frc_to_fixed_test), + KUNIT_CASE(bw_floor2_test), + KUNIT_CASE(bw_ceil2_test), + KUNIT_CASE(bw_mul_test), + { } +}; + +static struct kunit_suite bw_fixed_test_suite = { + .name = "dml_calcs_bw_fixed", + .test_cases = bw_fixed_test_cases, +}; + +kunit_test_suites(&bw_fixed_test_suite); From patchwork Fri Jan 26 15:48:03 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: Rodrigo Siqueira Jordao X-Patchwork-Id: 13532856 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from gabe.freedesktop.org (gabe.freedesktop.org [131.252.210.177]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.lore.kernel.org (Postfix) with ESMTPS id BF0C7C48260 for ; Fri, 26 Jan 2024 15:51:46 +0000 (UTC) Received: from gabe.freedesktop.org (localhost [127.0.0.1]) by gabe.freedesktop.org (Postfix) with ESMTP id 65F9710FBE2; Fri, 26 Jan 2024 15:51:37 +0000 (UTC) Received: from NAM02-SN1-obe.outbound.protection.outlook.com (mail-sn1nam02on2075.outbound.protection.outlook.com [40.107.96.75]) by gabe.freedesktop.org (Postfix) with ESMTPS id C3FC810FBC3; Fri, 26 Jan 2024 15:51:31 +0000 (UTC) ARC-Seal: i=1; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=none; b=nHNXgACxssF/ykug+Oefm9GXL0xtpPmVsoVFT32q9XgCIcMOOH/DQ7+nPekIGp5Qgw/cocihVN1KlyN4d75I178lv/4xX4utxSRMWGzaU1TzM+ElroHfr9xPEChk3cRwvyCsKHu3uyC3x0t5CUVFSNcCNxj8Xt8iynjdBaeiOdsIqo1eGl0uZlL+F7FrZ0QuYrwSQxCg1TivRdH3kQiWsyVOrwys2WCKYPmZfeCSkVjam19nbjVG870JqFzNYjHhxiLAyuwmRY0G56jOBQ0+ZLilUa1KbTsjXCvjvDxDrpfKypNc29dP478r3Qjw3Y7LLnKh9nsOTs+ooR/og3WYLQ== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=microsoft.com; s=arcselector9901; h=From:Date:Subject:Message-ID:Content-Type:MIME-Version:X-MS-Exchange-AntiSpam-MessageData-ChunkCount:X-MS-Exchange-AntiSpam-MessageData-0:X-MS-Exchange-AntiSpam-MessageData-1; bh=guALh/LN/DFE1aPxTpITIvXFX9nEMMw3k+9LpnRm5nY=; b=BxLXZJfPNK+rBD3CWMwVIeN6FmoT7WYmnlcAjgDa1siobjKguUeqMyLjx24zoUWyabSeZ8W6RNyEKlfirexcuA344t45M5SoEONcpv/4lxj/fSy6rE9jvbmKBk8QoIsSW8KlI0NiSzKu5xOMPYURCnsxMX/Hysc8jcWCz4LgU/dntECQfDnkUjovr0l6L3d3q6F/YXqND8KHxHXfvD15Fdz+NhdrAoCXi2foiju7FlHVgrqFzr1MwwvqF0U+yV0Ikj69YxhrEWZTHlixVwE0aI+0Rab9D256aAw2VTTWr4MjFWrPHp1CdSosCkh+PdWwndZ2ZzQBHXVpHDP1wKrWZQ== ARC-Authentication-Results: i=1; mx.microsoft.com 1; spf=pass (sender ip is 165.204.84.17) smtp.rcpttodomain=linux.ie smtp.mailfrom=amd.com; dmarc=pass (p=quarantine sp=quarantine pct=100) action=none header.from=amd.com; dkim=none (message not signed); arc=none (0) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=amd.com; s=selector1; h=From:Date:Subject:Message-ID:Content-Type:MIME-Version:X-MS-Exchange-SenderADCheck; bh=guALh/LN/DFE1aPxTpITIvXFX9nEMMw3k+9LpnRm5nY=; b=0NBiwnbWfczfn/8FsXAlRC1m6T9X35s4Kl4+SUZLpILdW4mUVG85bcwbRepv4ijvVyj4cLgTezQK8FFkvWvsdeh16PGcjpNLXKWc0TJfuz/R7/GmbfCQPgx5kAkuLJp2lanKGBwGOidhFLYVeZQTvoz1sXmqZC7hllEjqN2HYi0= Received: from SJ0PR03CA0074.namprd03.prod.outlook.com (2603:10b6:a03:331::19) by DM4PR12MB7599.namprd12.prod.outlook.com (2603:10b6:8:109::12) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.7228.27; Fri, 26 Jan 2024 15:51:28 +0000 Received: from SJ1PEPF00001CDF.namprd05.prod.outlook.com (2603:10b6:a03:331:cafe::49) by SJ0PR03CA0074.outlook.office365.com (2603:10b6:a03:331::19) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.7228.24 via Frontend Transport; Fri, 26 Jan 2024 15:51:28 +0000 X-MS-Exchange-Authentication-Results: spf=pass (sender IP is 165.204.84.17) smtp.mailfrom=amd.com; dkim=none (message not signed) header.d=none;dmarc=pass action=none header.from=amd.com; Received-SPF: Pass (protection.outlook.com: domain of amd.com designates 165.204.84.17 as permitted sender) receiver=protection.outlook.com; client-ip=165.204.84.17; helo=SATLEXMB04.amd.com; pr=C Received: from SATLEXMB04.amd.com (165.204.84.17) by SJ1PEPF00001CDF.mail.protection.outlook.com (10.167.242.7) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256) id 15.20.7202.16 via Frontend Transport; Fri, 26 Jan 2024 15:51:27 +0000 Received: from smtp.xilinx.com (10.180.168.240) by SATLEXMB04.amd.com (10.181.40.145) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256) id 15.1.2507.34; Fri, 26 Jan 2024 09:51:24 -0600 From: Rodrigo Siqueira To: Alex Deucher , , , David Airlie , Daniel Vetter , Maarten Lankhorst , Maxime Ripard , Thomas Zimmermann , Harry Wentland , Leo Li , "Rodrigo Siqueira" , Nicholas Choi , Daniel Latypov , David Gow , , Subject: [PATCH v4 3/8] drm/amd/display: Introduce KUnit tests to display_rq_dlg_calc_20 Date: Fri, 26 Jan 2024 08:48:03 -0700 Message-ID: <20240126155022.1184856-4-Rodrigo.Siqueira@amd.com> X-Mailer: git-send-email 2.43.0 In-Reply-To: <20240126155022.1184856-1-Rodrigo.Siqueira@amd.com> References: <20240126155022.1184856-1-Rodrigo.Siqueira@amd.com> MIME-Version: 1.0 X-Originating-IP: [10.180.168.240] X-ClientProxiedBy: SATLEXMB04.amd.com (10.181.40.145) To SATLEXMB04.amd.com (10.181.40.145) X-EOPAttributedMessage: 0 X-MS-PublicTrafficType: Email X-MS-TrafficTypeDiagnostic: SJ1PEPF00001CDF:EE_|DM4PR12MB7599:EE_ X-MS-Office365-Filtering-Correlation-Id: 00089b16-2411-41f2-f510-08dc1e86a875 X-MS-Exchange-SenderADCheck: 1 X-MS-Exchange-AntiSpam-Relay: 0 X-Microsoft-Antispam: BCL:0; X-Microsoft-Antispam-Message-Info: 8IozJTWwcPkwCSKbIQwtj3IAmFFMEjSguoAZXSkO97Gp/s99OWcRok/Vo/M9sB710CjAj77hZJJNY8qZHM9hqVvzFDuFtfqWum4kKAdW04FPj6+0M20KB/PJutQkpz9hn8KlUiLtlmowrwB3UTpAmbakSqeD+LvKUzezUkaR4+biqnYw11LengWgDNgCeQOBxTLA9aivadN4h/TnT3oRsYp5Y6A0cBADOkldMcHcZYa3rFUai7/GCROJ0MlBPWimXrcD+GtfXAOjr8FTA6SZhcMprYMx3m3qcU5Wfyhlg0LxvR57wj7OcMhkPBB5aREPFFHaUJDcMbVZcaYGt6OkvhVia11evcRattgIY+M4G5wKm3yu5b5/Ld4HBXQD7JKVb0WJTrRXcrBk5CCjf+SWzYB/rDBxWaNMQtRAJlBKsHoTUMH2kQYL3pa4v+GpCNYn/6X1uOxqQhIvHWX5pB3mPa3LirgB1tGpMnGC/TtxyQ1KhxFfwKK6IWKxbaLSd2Ede2thkJp17+f5E7AWUmffAEhJcsRlXcF8VsqVTrHu9TNIMbcbZkTupv7zEI9bGt/FAZFMvOyzu+rhvHierF4GJyGxqs/obe3iAHnHCXEn6iiO88/QlikhMQwACe9yisccqY798wRNPk0RrVo07DS5q1PJpEzXFouSxfFKEweOdmRQS/L6CdU4YGOIPVhh1J54FROEBVr3g4mW9JnNYhU8jrJuHoDZ9sLaumblORqJwytezK4SeDsNKCYwf/rzmOlenGrjedEQn+Pn4LPCaPFNBSaC1m97aU/X85Lpg5OzdeY= X-Forefront-Antispam-Report: CIP:165.204.84.17; CTRY:US; LANG:en; SCL:1; SRV:; IPV:CAL; SFV:NSPM; H:SATLEXMB04.amd.com; PTR:InfoDomainNonexistent; CAT:NONE; SFS:(13230031)(4636009)(39860400002)(136003)(376002)(346002)(396003)(230922051799003)(186009)(64100799003)(82310400011)(1800799012)(451199024)(36840700001)(46966006)(40470700004)(356005)(6666004)(41300700001)(478600001)(40480700001)(82740400003)(36860700001)(40460700003)(47076005)(81166007)(26005)(336012)(426003)(66574015)(16526019)(2616005)(83380400001)(316002)(54906003)(5660300002)(7416002)(2906002)(8936002)(36756003)(4326008)(8676002)(110136005)(70586007)(70206006)(86362001)(1076003)(921011)(36900700001); DIR:OUT; SFP:1101; X-OriginatorOrg: amd.com X-MS-Exchange-CrossTenant-OriginalArrivalTime: 26 Jan 2024 15:51:27.7709 (UTC) X-MS-Exchange-CrossTenant-Network-Message-Id: 00089b16-2411-41f2-f510-08dc1e86a875 X-MS-Exchange-CrossTenant-Id: 3dd8961f-e488-4e60-8e11-a82d994e183d X-MS-Exchange-CrossTenant-OriginalAttributedTenantConnectingIp: TenantId=3dd8961f-e488-4e60-8e11-a82d994e183d; Ip=[165.204.84.17]; Helo=[SATLEXMB04.amd.com] X-MS-Exchange-CrossTenant-AuthSource: SJ1PEPF00001CDF.namprd05.prod.outlook.com X-MS-Exchange-CrossTenant-AuthAs: Anonymous X-MS-Exchange-CrossTenant-FromEntityHeader: HybridOnPrem X-MS-Exchange-Transport-CrossTenantHeadersStamped: DM4PR12MB7599 X-BeenThere: dri-devel@lists.freedesktop.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: Direct Rendering Infrastructure - Development List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: tales.aparecida@gmail.com, Trevor Woerner , javierm@redhat.com, dri-devel@lists.freedesktop.org, mwen@igalia.com, =?utf-8?q?Ma=C3=ADra_Canal?= , amd-gfx@lists.freedesktop.org, Isabella Basso , andrealmeid@riseup.net, kunit-dev@googlegroups.com Errors-To: dri-devel-bounces@lists.freedesktop.org Sender: "dri-devel" From: Isabella Basso This adds tests to the bit encoding format verification functions on the file. They're meant to be simpler so as to provide a proof of concept on testing DML code. Signed-off-by: Isabella Basso Signed-off-by: Maíra Canal --- drivers/gpu/drm/amd/display/Kconfig | 13 ++ .../dc/dml/dcn20/display_rq_dlg_calc_20.c | 4 + .../dml/dcn20/display_rq_dlg_calc_20_test.c | 124 ++++++++++++++++++ 3 files changed, 141 insertions(+) create mode 100644 drivers/gpu/drm/amd/display/tests/dc/dml/dcn20/display_rq_dlg_calc_20_test.c diff --git a/drivers/gpu/drm/amd/display/Kconfig b/drivers/gpu/drm/amd/display/Kconfig index d54036dcac78..877ba3be6aed 100644 --- a/drivers/gpu/drm/amd/display/Kconfig +++ b/drivers/gpu/drm/amd/display/Kconfig @@ -64,6 +64,19 @@ config DCE_KUNIT_TEST If unsure, say N. +config DML_KUNIT_TEST + bool "Run all KUnit tests for DML" if !KUNIT_ALL_TESTS + depends on DRM_AMD_DC_DCN && KUNIT + default KUNIT_ALL_TESTS + help + Enables unit tests for the Display Controller Engine. Only useful for kernel + devs running KUnit. + + For more information on KUnit and unit tests in general please refer to + the KUnit documentation in Documentation/dev-tools/kunit/. + + If unsure, say N. + config AMD_DC_BASICS_KUNIT_TEST bool "Enable KUnit tests for the 'basics' sub-component of DAL" if !KUNIT_ALL_TESTS depends on DRM_AMD_DC && KUNIT diff --git a/drivers/gpu/drm/amd/display/dc/dml/dcn20/display_rq_dlg_calc_20.c b/drivers/gpu/drm/amd/display/dc/dml/dcn20/display_rq_dlg_calc_20.c index 548cdef8a8ad..ab688c9ba0d1 100644 --- a/drivers/gpu/drm/amd/display/dc/dml/dcn20/display_rq_dlg_calc_20.c +++ b/drivers/gpu/drm/amd/display/dc/dml/dcn20/display_rq_dlg_calc_20.c @@ -1683,3 +1683,7 @@ static void calculate_ttu_cursor(struct display_mode_lib *mode_lib, ASSERT(*refcyc_per_req_delivery_cur < dml_pow(2, 13)); } } + +#if IS_ENABLED(CONFIG_DML_KUNIT_TEST) +#include "../../../tests/dc/dml/dcn20/display_rq_dlg_calc_20_test.c" +#endif diff --git a/drivers/gpu/drm/amd/display/tests/dc/dml/dcn20/display_rq_dlg_calc_20_test.c b/drivers/gpu/drm/amd/display/tests/dc/dml/dcn20/display_rq_dlg_calc_20_test.c new file mode 100644 index 000000000000..e6d3e356205c --- /dev/null +++ b/drivers/gpu/drm/amd/display/tests/dc/dml/dcn20/display_rq_dlg_calc_20_test.c @@ -0,0 +1,124 @@ +// SPDX-License-Identifier: MIT +/* + * KUnit tests for dml/dcn20/display_rq_dlg_calc_20.c + * + * Copyright (c) 2022, Isabella Basso + */ + +#include +#include "dml/display_mode_lib.h" + +/** + * get_bytes_per_element_test - KUnit test for get_bytes_per_element + * @test: represents a running instance of a test. + */ +static void get_bytes_per_element_test(struct kunit *test) +{ + /* last numbers should tell us the horizontal 4-element region binary + * size N used for subsampling, thus giving us N/8 bytes per element + */ + /* note that 4:4:4 is not subsampled */ + KUNIT_ASSERT_EQ(test, get_bytes_per_element(dm_444_16, false), 2); + KUNIT_ASSERT_EQ(test, get_bytes_per_element(dm_444_32, false), 4); + KUNIT_ASSERT_EQ(test, get_bytes_per_element(dm_444_64, false), 8); + + /* dcn20 doesn't support bit depths over 10b */ + KUNIT_ASSERT_EQ(test, get_bytes_per_element(dm_420_12, false), 0); + KUNIT_ASSERT_EQ(test, get_bytes_per_element(dm_420_12, true), 0); + + /* dm_444_XX are not dual plane */ + KUNIT_ASSERT_EQ(test, get_bytes_per_element(dm_444_16, true), 0); + KUNIT_ASSERT_EQ(test, get_bytes_per_element(dm_444_32, true), 0); + KUNIT_ASSERT_EQ(test, get_bytes_per_element(dm_444_64, true), 0); + + /* in the dm_42* values, last numbers specify bit depth, demanding we + * treat chroma and luma channels separately + */ + /* thus we'll now have ceil(N/8) bytes for luma */ + KUNIT_ASSERT_EQ(test, get_bytes_per_element(dm_420_8, false), 1); + KUNIT_ASSERT_EQ(test, get_bytes_per_element(dm_420_10, false), 2); + /* and double the luma value for accommodating blue and red chroma + * channels + */ + KUNIT_ASSERT_EQ(test, get_bytes_per_element(dm_420_8, true), 2); + KUNIT_ASSERT_EQ(test, get_bytes_per_element(dm_420_10, true), 4); + + /* monochrome encodings should mirror non-subsampled variants */ + KUNIT_ASSERT_EQ(test, get_bytes_per_element(dm_mono_8, false), + get_bytes_per_element(dm_444_8, false)); + KUNIT_ASSERT_EQ(test, get_bytes_per_element(dm_mono_16, false), + get_bytes_per_element(dm_444_16, false)); + KUNIT_ASSERT_EQ(test, get_bytes_per_element(dm_mono_16, true), 0); + + /* dcn20 doesn't support 4:2:2 chroma subsampling */ + KUNIT_ASSERT_EQ(test, get_bytes_per_element(dm_422_8, false), 0); + KUNIT_ASSERT_EQ(test, get_bytes_per_element(dm_422_8, true), 0); + KUNIT_ASSERT_EQ(test, get_bytes_per_element(dm_422_10, false), 0); + KUNIT_ASSERT_EQ(test, get_bytes_per_element(dm_422_10, true), 0); + + /* dcn20 doesn't support RGBE encodings */ + KUNIT_ASSERT_EQ(test, get_bytes_per_element(dm_rgbe, false), 0); + KUNIT_ASSERT_EQ(test, get_bytes_per_element(dm_rgbe, true), 0); + KUNIT_ASSERT_EQ(test, get_bytes_per_element(dm_rgbe_alpha, false), 0); + KUNIT_ASSERT_EQ(test, get_bytes_per_element(dm_rgbe_alpha, true), 0); + + /* as in the first values, _8 here represents horizontal binary length */ + KUNIT_ASSERT_EQ(test, get_bytes_per_element(dm_444_8, false), 1); + /* in a non-subsampled monochrome encoding chroma and luma should be the + * same length + */ + KUNIT_ASSERT_EQ(test, get_bytes_per_element(dm_444_8, false), + get_bytes_per_element(dm_444_8, true)); + + /* as dm_mono_8 == dm_444_8, it must behave the same way */ + KUNIT_ASSERT_EQ(test, get_bytes_per_element(dm_mono_8, false), + get_bytes_per_element(dm_mono_8, true)); +} + +/** + * is_dual_plane_test - KUnit test for is_dual_plane + * @test: represents a running instance of a test. + */ +static void is_dual_plane_test(struct kunit *test) +{ + /* strictly speaking monochrome formats are not dual plane, but they're + * included here for completeness + */ + int source_format_count = 11; + + for (int i = 0; i < source_format_count; i++) { + /* dcn20 doesn't support other dual plane formats */ + if (i == 3 || i == 4) + KUNIT_ASSERT_TRUE(test, is_dual_plane(i)); + else + KUNIT_ASSERT_FALSE(test, is_dual_plane(i)); + } +} + +/** + * get_blk_size_bytes_test - KUnit test for get_blk_size_bytes + * @test: represents a running instance of a test. + */ +static void get_blk_size_bytes_test(struct kunit *test) +{ + /* corresponds to 4^4 kB tiles */ + KUNIT_ASSERT_EQ(test, get_blk_size_bytes(dm_256k_tile), 256 * 1024); + /* corresponds to 4^3 kB tiles */ + KUNIT_ASSERT_EQ(test, get_blk_size_bytes(dm_64k_tile), 64 * 1024); + /* corresponds to 4^1 kB tiles */ + KUNIT_ASSERT_EQ(test, get_blk_size_bytes(dm_4k_tile), 4 * 1024); +} + +static struct kunit_case dcn20_rq_dlg_calc_20_test_cases[] = { + KUNIT_CASE(get_bytes_per_element_test), + KUNIT_CASE(is_dual_plane_test), + KUNIT_CASE(get_blk_size_bytes_test), + { } +}; + +static struct kunit_suite dcn20_rq_dlg_calc_20_test_suite = { + .name = "display_rq_dlg_calc_20", + .test_cases = dcn20_rq_dlg_calc_20_test_cases, +}; + +kunit_test_suites(&dcn20_rq_dlg_calc_20_test_suite); From patchwork Fri Jan 26 15:48:04 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: Rodrigo Siqueira Jordao X-Patchwork-Id: 13532854 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from gabe.freedesktop.org (gabe.freedesktop.org [131.252.210.177]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.lore.kernel.org (Postfix) with ESMTPS id 8E5C4C48260 for ; Fri, 26 Jan 2024 15:51:42 +0000 (UTC) Received: from gabe.freedesktop.org (localhost [127.0.0.1]) by gabe.freedesktop.org (Postfix) with ESMTP id 5A6CA10FBC3; Fri, 26 Jan 2024 15:51:36 +0000 (UTC) Received: from NAM10-DM6-obe.outbound.protection.outlook.com (mail-dm6nam10on2085.outbound.protection.outlook.com [40.107.93.85]) by gabe.freedesktop.org (Postfix) with ESMTPS id 4978710FBC3; Fri, 26 Jan 2024 15:51:35 +0000 (UTC) ARC-Seal: i=1; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=none; b=UHCOQX+1mQ39b6C4Km5ZrjhGOGfT4O/fGo3I57tnobXPBCFILoaoZJCtrVxj5Mw3reusbHpJCrIUvvh+gU2ZQPp599Jx9HBmxTOJWxw4ozTCDZmUef/wnRqxIgtmCr7ofCn/JFzkiyvSM2nO3yZbxj2KjaDkwwFk4A1RiUcv/reU/cdtBffXXhf76hnDtu4eD1dyr4CnVYIVDfuA/Wh2pBkRpz9tER/vqKfEhhhECskcJfaVjivCQbnZb53JIc6Dzeh6DnytIRMU+UHJidodPSlQXcTUncqAuwtGbPsyFuF7osLesAT0iXrJgqwj7aAFA+foq1a8fGrq0rLcrx4hAw== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=microsoft.com; s=arcselector9901; h=From:Date:Subject:Message-ID:Content-Type:MIME-Version:X-MS-Exchange-AntiSpam-MessageData-ChunkCount:X-MS-Exchange-AntiSpam-MessageData-0:X-MS-Exchange-AntiSpam-MessageData-1; bh=eT1zznPFODcvTivmlIHy/kNDzhT3QH4s6thgYL2wsA4=; b=PzGaxiR8cI/yFHtHBYqXbTmUz97HOrTWFAwMbCkSQJr8NDP2PrnQvXSoXwWnJQwIfKlzf/yMu0NzNqcGn0B38cSvoSXOZDXZpQaICG3ZfBOi/FfzRKkqcmQ/IJCcc65wNrxfibt+tm9aS2Ol6T001B7qwg1q8vMSRMkb0XVipwEgrn1DTM+Pn7wM/JlpULT1VZK8gsmv+m4GjgJkCjw8wSWTd3TH5qt1m0Aqj04FrhdZcejO8o5VAZ8k/jnWcCSJb9XDp2qq3cAVKhEjH2zfrkq/aiK1e8FxvUhglajadbf+ZZa5rLus3QSmc8NJkOoz7UB5OpHOxyv4CRU96y9NzQ== ARC-Authentication-Results: i=1; mx.microsoft.com 1; spf=pass (sender ip is 165.204.84.17) smtp.rcpttodomain=linux.ie smtp.mailfrom=amd.com; dmarc=pass (p=quarantine sp=quarantine pct=100) action=none header.from=amd.com; dkim=none (message not signed); arc=none (0) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=amd.com; s=selector1; h=From:Date:Subject:Message-ID:Content-Type:MIME-Version:X-MS-Exchange-SenderADCheck; bh=eT1zznPFODcvTivmlIHy/kNDzhT3QH4s6thgYL2wsA4=; b=HhjcTt/4xkAqXuMHctpeLahamAMlk8kyHRQHWL4WLoi/rl/sOrYQjSuS/jh/jgYclLOvSvd0gcNiRvlUBuNz/ePmPe5jvAGj0oCmjlR+nD5PNmMzLGwvjAvBpgr9MELnEwaT4KFhikwu8ttxLk0WoMHlhgBdcxnXOJJBV573Cug= Received: from SJ0PR13CA0048.namprd13.prod.outlook.com (2603:10b6:a03:2c2::23) by BL0PR12MB4994.namprd12.prod.outlook.com (2603:10b6:208:1ca::13) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.7228.27; Fri, 26 Jan 2024 15:51:31 +0000 Received: from SJ1PEPF00001CDD.namprd05.prod.outlook.com (2603:10b6:a03:2c2:cafe::fd) by SJ0PR13CA0048.outlook.office365.com (2603:10b6:a03:2c2::23) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.7249.15 via Frontend Transport; Fri, 26 Jan 2024 15:51:31 +0000 X-MS-Exchange-Authentication-Results: spf=pass (sender IP is 165.204.84.17) smtp.mailfrom=amd.com; dkim=none (message not signed) header.d=none;dmarc=pass action=none header.from=amd.com; Received-SPF: Pass (protection.outlook.com: domain of amd.com designates 165.204.84.17 as permitted sender) receiver=protection.outlook.com; client-ip=165.204.84.17; helo=SATLEXMB04.amd.com; pr=C Received: from SATLEXMB04.amd.com (165.204.84.17) by SJ1PEPF00001CDD.mail.protection.outlook.com (10.167.242.5) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256) id 15.20.7202.16 via Frontend Transport; Fri, 26 Jan 2024 15:51:30 +0000 Received: from smtp.xilinx.com (10.180.168.240) by SATLEXMB04.amd.com (10.181.40.145) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256) id 15.1.2507.34; Fri, 26 Jan 2024 09:51:26 -0600 From: Rodrigo Siqueira To: Alex Deucher , , , David Airlie , Daniel Vetter , Maarten Lankhorst , Maxime Ripard , Thomas Zimmermann , Harry Wentland , Leo Li , "Rodrigo Siqueira" , Nicholas Choi , Daniel Latypov , David Gow , , Subject: [PATCH v4 4/8] drm/amd/display: Introduce KUnit tests to the display_mode_vba library Date: Fri, 26 Jan 2024 08:48:04 -0700 Message-ID: <20240126155022.1184856-5-Rodrigo.Siqueira@amd.com> X-Mailer: git-send-email 2.43.0 In-Reply-To: <20240126155022.1184856-1-Rodrigo.Siqueira@amd.com> References: <20240126155022.1184856-1-Rodrigo.Siqueira@amd.com> MIME-Version: 1.0 X-Originating-IP: [10.180.168.240] X-ClientProxiedBy: SATLEXMB04.amd.com (10.181.40.145) To SATLEXMB04.amd.com (10.181.40.145) X-EOPAttributedMessage: 0 X-MS-PublicTrafficType: Email X-MS-TrafficTypeDiagnostic: SJ1PEPF00001CDD:EE_|BL0PR12MB4994:EE_ X-MS-Office365-Filtering-Correlation-Id: 8ce4cc1d-c8d8-4d5f-e439-08dc1e86aa59 X-MS-Exchange-SenderADCheck: 1 X-MS-Exchange-AntiSpam-Relay: 0 X-Microsoft-Antispam: BCL:0; X-Microsoft-Antispam-Message-Info: 7X8poANjSnzZIl8NqiA49pH/i1SeSs+Z2duMolQTFoRvrdxuIBLvcj7Ly/GF7PAruP+9SD+3fZeKJcKt48MvDRF1RIsMWVyy1cG+NBI1AjJLalMhVU7bC7/1pRLkQKMo1PjTPo8G9Qywfjx4pvTmG11M8RJ7js1orH+nWnqkZCRq5KeKmxDn1m9tvAf9NBO7Q7NoVo0nZLCziGLCkNHHUO4yucFRG0WyKJBb4i/LRlB7U6QoVZbRD4G4bQrbYhwW7Z41fmmEbdxOR97qTMETZkc+rZLwE2xvFgTfQJkzwBigqup//Vrf2hW1TY2/HR6viKYMn+IUExOun+o6n43w08V4WgoLW09OtvXC5uQkyyK+2WPdOKyFR2SlOCd0ftvrs+QNxvy4/g1xroEe5vCAWMsDMpBaf1llllqHiL7y8H4mC1q9VZ/d+hekS7Mde3HqtUnbxfsJcrpukSZEJ4rr/n1m55IIR2wfDOMVqKbMLYO+/ytuwWmlneVgjGnUNwtrI3GNyHXJCXBAnaG0V7FP8AnvuMfuZwptauoUyCqhF6ppoaKcBPSwoWDsfPSOlLT+MAoyIQ4YbY6O32mVSjxnF0rk8u48WRJ9LjfUFlgRL8LZ+NoRKhuITiPVmUF+1AtEFoq9tUDceYGMplTxaHyXKWnAhYpeinAXdHjhxQt2Hzxknw0fPgYJab/PIqyl9bjQBSzs5IvxpaVP1FophVfF1AYku5qiDN9KNTBMiK/mlDAQv8LKNY5znanzVPwzGaKTKf3zWjRVJ+owfpyUjjNa4CtirAc7gBuXgwNX0RX+kNI= X-Forefront-Antispam-Report: CIP:165.204.84.17; CTRY:US; LANG:en; SCL:1; SRV:; IPV:CAL; SFV:NSPM; H:SATLEXMB04.amd.com; PTR:InfoDomainNonexistent; CAT:NONE; SFS:(13230031)(4636009)(39860400002)(346002)(376002)(396003)(136003)(230922051799003)(82310400011)(64100799003)(451199024)(186009)(1800799012)(40470700004)(36840700001)(46966006)(110136005)(70206006)(70586007)(86362001)(36860700001)(356005)(19627235002)(54906003)(316002)(478600001)(82740400003)(81166007)(16526019)(26005)(6666004)(2616005)(1076003)(4326008)(8676002)(8936002)(5660300002)(83380400001)(426003)(336012)(30864003)(7416002)(40460700003)(40480700001)(2906002)(36756003)(921011)(47076005)(41300700001)(66899024)(36900700001); DIR:OUT; SFP:1101; X-OriginatorOrg: amd.com X-MS-Exchange-CrossTenant-OriginalArrivalTime: 26 Jan 2024 15:51:30.9267 (UTC) X-MS-Exchange-CrossTenant-Network-Message-Id: 8ce4cc1d-c8d8-4d5f-e439-08dc1e86aa59 X-MS-Exchange-CrossTenant-Id: 3dd8961f-e488-4e60-8e11-a82d994e183d X-MS-Exchange-CrossTenant-OriginalAttributedTenantConnectingIp: TenantId=3dd8961f-e488-4e60-8e11-a82d994e183d; Ip=[165.204.84.17]; Helo=[SATLEXMB04.amd.com] X-MS-Exchange-CrossTenant-AuthSource: SJ1PEPF00001CDD.namprd05.prod.outlook.com X-MS-Exchange-CrossTenant-AuthAs: Anonymous X-MS-Exchange-CrossTenant-FromEntityHeader: HybridOnPrem X-MS-Exchange-Transport-CrossTenantHeadersStamped: BL0PR12MB4994 X-BeenThere: dri-devel@lists.freedesktop.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: Direct Rendering Infrastructure - Development List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: tales.aparecida@gmail.com, Trevor Woerner , javierm@redhat.com, dri-devel@lists.freedesktop.org, mwen@igalia.com, =?utf-8?q?Ma=C3=ADra_Canal?= , amd-gfx@lists.freedesktop.org, Isabella Basso , andrealmeid@riseup.net, kunit-dev@googlegroups.com Errors-To: dri-devel-bounces@lists.freedesktop.org Sender: "dri-devel" From: Maíra Canal The display_mode_vba library deals with hundreds of display parameters and sometimes does it in odd ways. The addition of unit tests intends to assure the quality of the code delivered by HW engineers and, also make it possible to refactor the code decreasing concerns about adding bugs to the codebase. Signed-off-by: Maíra Canal --- drivers/gpu/drm/amd/display/tests/Makefile | 5 + .../tests/dc/dml/display_mode_vba_test.c | 741 ++++++++++++++++++ 2 files changed, 746 insertions(+) create mode 100644 drivers/gpu/drm/amd/display/tests/dc/dml/display_mode_vba_test.c diff --git a/drivers/gpu/drm/amd/display/tests/Makefile b/drivers/gpu/drm/amd/display/tests/Makefile index ef16497318e8..cc1e9edd38c3 100644 --- a/drivers/gpu/drm/amd/display/tests/Makefile +++ b/drivers/gpu/drm/amd/display/tests/Makefile @@ -7,6 +7,11 @@ ifdef CONFIG_AMD_DC_BASICS_KUNIT_TEST DC_TESTS += dc/basics/fixpt31_32_test.o endif +ifdef CONFIG_DML_KUNIT_TEST + CFLAGS_$(AMDDALPATH)/tests/dc/dml/display_mode_vba_test.o := $(dml_ccflags) + DC_TESTS += dc/dml/display_mode_vba_test.o +endif + AMD_DAL_DC_TESTS = $(addprefix $(AMDDALPATH)/tests/,$(DC_TESTS)) AMD_DISPLAY_FILES += $(AMD_DAL_DC_TESTS) diff --git a/drivers/gpu/drm/amd/display/tests/dc/dml/display_mode_vba_test.c b/drivers/gpu/drm/amd/display/tests/dc/dml/display_mode_vba_test.c new file mode 100644 index 000000000000..d3e3a9f50c3d --- /dev/null +++ b/drivers/gpu/drm/amd/display/tests/dc/dml/display_mode_vba_test.c @@ -0,0 +1,741 @@ +// SPDX-License-Identifier: MIT +/* + * KUnit tests for dml/display_mode_vba.h + * + * Copyright (C) 2022, Maíra Canal + */ + +#include +#include "dml/display_mode_lib.h" + +struct pixel_clock_adjustment_for_progressive_to_interlace_unit_expected { + const double pixel_clock[DC__NUM_DPP__MAX]; + const double pixel_clock_backend[DC__NUM_DPP__MAX]; +}; + +struct pixel_clock_adjustment_for_progressive_to_interlace_unit_test_case { + const char *desc; + const unsigned int number_of_active_planes; + const bool interlace[DC__NUM_DPP__MAX]; + const bool progressive_to_interlace_unit_in_OPP; + const double pixel_clock[DC__NUM_DPP__MAX]; + const struct pixel_clock_adjustment_for_progressive_to_interlace_unit_expected expected; +}; + +struct calculate_256B_block_sizes_test_case { + const char *desc; + const enum source_format_class source_pixel_format; + const enum dm_swizzle_mode surface_tiling; + const unsigned int byte_per_pixel_Y; + const unsigned int byte_per_pixel_C; + const unsigned int block_height_256_bytes_Y; + const unsigned int block_height_256_bytes_C; + const unsigned int block_width_256_bytes_Y; + const unsigned int block_width_256_bytes_C; +}; + +struct calculate_write_back_DISPCLK_test_case { + const char *desc; + const enum source_format_class writeback_pixel_format; + const double pixel_clock; + const double writeback_HRatio; + const double writeback_VRatio; + const unsigned int writeback_luma_HTaps; + const unsigned int writeback_luma_VTaps; + const unsigned int writeback_chroma_HTaps; + const unsigned int writeback_chroma_VTaps; + const double writeback_destination_width; + const unsigned int HTotal; + const unsigned int writeback_chroma_line_buffer_width; + const double calculate_write_back_DISPCLK; +}; + +/** + * pclk_adjustment_for_progressive_to_interlace_unit_test - KUnit test + * for PixelClockAdjustmentForProgressiveToInterlaceUnit + * @test: represents a running instance of a test. + */ +static void pclk_adjustment_for_progressive_to_interlace_unit_test(struct kunit *test) +{ + const struct pixel_clock_adjustment_for_progressive_to_interlace_unit_test_case + *test_param = test->param_value; + struct display_mode_lib *mode_lib; + size_t pixel_clock_size = DC__NUM_DPP__MAX * sizeof(const double); + size_t interlace_size = DC__NUM_DPP__MAX * sizeof(const bool); + + mode_lib = kunit_kzalloc(test, sizeof(struct display_mode_lib), + GFP_KERNEL); + KUNIT_ASSERT_NOT_ERR_OR_NULL(test, mode_lib); + + mode_lib->vba.NumberOfActivePlanes = test_param->number_of_active_planes; + memcpy(mode_lib->vba.Interlace, test_param->interlace, interlace_size); + mode_lib->vba.ProgressiveToInterlaceUnitInOPP = + test_param->progressive_to_interlace_unit_in_OPP; + memcpy(mode_lib->vba.PixelClock, test_param->pixel_clock, pixel_clock_size); + + PixelClockAdjustmentForProgressiveToInterlaceUnit(mode_lib); + + KUNIT_EXPECT_TRUE(test, !memcmp(mode_lib->vba.PixelClock, + test_param->expected.pixel_clock, + pixel_clock_size)); + KUNIT_EXPECT_TRUE(test, !memcmp(mode_lib->vba.PixelClockBackEnd, + test_param->expected.pixel_clock_backend, + pixel_clock_size)); +} + +/** + * calculate_256B_block_sizes_test - KUnit test for Calculate256BBlockSizes + * @test: represents a running instance of a test. + */ +static void calculate_256B_block_sizes_test(struct kunit *test) +{ + const struct calculate_256B_block_sizes_test_case *test_param = + test->param_value; + unsigned int *block_height_256_bytes_Y, *block_height_256_bytes_C; + unsigned int *block_width_256_bytes_Y, *block_width_256_bytes_C; + + block_height_256_bytes_Y = kunit_kzalloc(test, sizeof(unsigned int), GFP_KERNEL); + KUNIT_ASSERT_NOT_ERR_OR_NULL(test, block_height_256_bytes_Y); + + block_height_256_bytes_C = kunit_kzalloc(test, sizeof(unsigned int), GFP_KERNEL); + KUNIT_ASSERT_NOT_ERR_OR_NULL(test, block_height_256_bytes_C); + + block_width_256_bytes_Y = kunit_kzalloc(test, sizeof(unsigned int), GFP_KERNEL); + KUNIT_ASSERT_NOT_ERR_OR_NULL(test, block_width_256_bytes_Y); + + block_width_256_bytes_C = kunit_kzalloc(test, sizeof(unsigned int), GFP_KERNEL); + KUNIT_ASSERT_NOT_ERR_OR_NULL(test, block_width_256_bytes_C); + + Calculate256BBlockSizes(test_param->source_pixel_format, + test_param->surface_tiling, + test_param->byte_per_pixel_Y, + test_param->byte_per_pixel_C, + block_height_256_bytes_Y, + block_height_256_bytes_C, + block_width_256_bytes_Y, + block_width_256_bytes_C); + + KUNIT_EXPECT_EQ(test, *block_height_256_bytes_Y, + test_param->block_height_256_bytes_Y); + KUNIT_EXPECT_EQ(test, *block_height_256_bytes_C, + test_param->block_height_256_bytes_C); + KUNIT_EXPECT_EQ(test, *block_width_256_bytes_Y, + test_param->block_width_256_bytes_Y); + KUNIT_EXPECT_EQ(test, *block_width_256_bytes_C, + test_param->block_width_256_bytes_C); +} + +/** + * calculate_min_and_max_prefetch_mode_test - KUnit test for CalculateMinAndMaxPrefetchMode + * @test: represents a running instance of a test. + */ +static void calculate_min_and_max_prefetch_mode_test(struct kunit *test) +{ + unsigned int *min_prefetch_mode, *max_prefetch_mode; + + min_prefetch_mode = kunit_kzalloc(test, sizeof(unsigned int), GFP_KERNEL); + KUNIT_ASSERT_NOT_ERR_OR_NULL(test, min_prefetch_mode); + + max_prefetch_mode = kunit_kzalloc(test, sizeof(unsigned int), GFP_KERNEL); + KUNIT_ASSERT_NOT_ERR_OR_NULL(test, max_prefetch_mode); + + /* Try to allow DRAM self-refresh and MCLK switch */ + KUNIT_EXPECT_FALSE(test, CalculateMinAndMaxPrefetchMode + (dm_try_to_allow_self_refresh_and_mclk_switch, + min_prefetch_mode, max_prefetch_mode)); + KUNIT_EXPECT_EQ(test, *min_prefetch_mode, 0); + KUNIT_EXPECT_EQ(test, *max_prefetch_mode, 2); + + /* Allow DRAM self-refresh and MCLK switch */ + KUNIT_EXPECT_FALSE(test, CalculateMinAndMaxPrefetchMode + (dm_allow_self_refresh_and_mclk_switch, + min_prefetch_mode, max_prefetch_mode)); + KUNIT_EXPECT_EQ(test, *min_prefetch_mode, 0); + KUNIT_EXPECT_EQ(test, *max_prefetch_mode, 0); + + /* Allow only DRAM self-refresh */ + KUNIT_EXPECT_FALSE(test, CalculateMinAndMaxPrefetchMode + (dm_allow_self_refresh, + min_prefetch_mode, max_prefetch_mode)); + KUNIT_EXPECT_EQ(test, *min_prefetch_mode, 1); + KUNIT_EXPECT_EQ(test, *max_prefetch_mode, 1); + + /* Allow neither DRAM self-refresh nor MCLK switch */ + KUNIT_EXPECT_FALSE(test, CalculateMinAndMaxPrefetchMode + (dm_neither_self_refresh_nor_mclk_switch, + min_prefetch_mode, max_prefetch_mode)); + KUNIT_EXPECT_EQ(test, *min_prefetch_mode, 2); + KUNIT_EXPECT_EQ(test, *max_prefetch_mode, 2); + + /* Invalid self-refresh affinity */ + KUNIT_EXPECT_TRUE(test, CalculateMinAndMaxPrefetchMode(-1, + min_prefetch_mode, + max_prefetch_mode)); + KUNIT_EXPECT_EQ(test, *min_prefetch_mode, 0); + KUNIT_EXPECT_EQ(test, *max_prefetch_mode, 2); +} + +/** + * calculate_write_back_DISPCLK_test - KUnit test for CalculateWriteBackDISPCLK + * @test: represents a running instance of a test. + */ +static void calculate_write_back_DISPCLK_test(struct kunit *test) +{ + const struct calculate_write_back_DISPCLK_test_case *test_param = test->param_value; + double calculate_write_back_DISPCLK; + + DC_FP_START(); + calculate_write_back_DISPCLK = CalculateWriteBackDISPCLK + (test_param->writeback_pixel_format, + test_param->pixel_clock, test_param->writeback_HRatio, + test_param->writeback_VRatio, test_param->writeback_luma_HTaps, + test_param->writeback_luma_VTaps, test_param->writeback_chroma_HTaps, + test_param->writeback_chroma_VTaps, + test_param->writeback_destination_width, test_param->HTotal, + test_param->writeback_chroma_line_buffer_width); + DC_FP_END(); + + KUNIT_EXPECT_EQ(test, test_param->calculate_write_back_DISPCLK, + calculate_write_back_DISPCLK); +} + +static const struct pixel_clock_adjustment_for_progressive_to_interlace_unit_test_case +pixel_clock_adjustment_for_progressive_to_interlace_unit_cases[] = { + { + .desc = "No active planes", + .number_of_active_planes = 0, + .interlace = {false, false, false, false, false, false, false, false}, + .progressive_to_interlace_unit_in_OPP = false, + .pixel_clock = {0.00, 0.00, 0.00, 0.00, 0.00, 0.00, 0.00, 0.00}, + .expected = { + .pixel_clock = {0.00, 0.00, 0.00, 0.00, 0.00, 0.00, 0.00, 0.00}, + .pixel_clock_backend = {0.00, 0.00, 0.00, 0.00, 0.00, 0.00, 0.00, 0.00}, + }, + }, + { + .desc = "Two active planes with no interlaced output", + .number_of_active_planes = 2, + .interlace = {false, false, false, false, false, false, false, false}, + .progressive_to_interlace_unit_in_OPP = true, + .pixel_clock = {3200.00, 1360.00, 0.00, 0.00, 0.00, 0.00, 0.00, 0.00}, + .expected = { + .pixel_clock = {3200.00, 1360.00, 0.00, 0.00, 0.00, 0.00, 0.00, 0.00}, + .pixel_clock_backend = {3200.00, 1360.00, 0.00, 0.00, 0.00, 0.00, + 0.00, 0.00}, + }, + }, + { + .desc = "Three active planes with one interlaced plane", + .number_of_active_planes = 3, + .interlace = {false, true, false, false, false, false, false, false}, + .progressive_to_interlace_unit_in_OPP = true, + .pixel_clock = {3200.00, 1360.00, 400.00, 0.00, 0.00, 0.00, 0.00, 0.00}, + .expected = { + .pixel_clock = {3200.00, 2720.00, 400.00, 0.00, + 0.00, 0.00, 0.00, 0.00}, + .pixel_clock_backend = {3200.00, 1360.00, 400.00, 0.00, + 0.00, 0.00, 0.00, 0.00}, + }, + }, + { + .desc = "Five active planes with three interlaced planes", + .number_of_active_planes = 5, + .interlace = {false, true, false, true, true, false, false, false}, + .progressive_to_interlace_unit_in_OPP = true, + .pixel_clock = {3200.00, 1360.00, 400.00, 340.00, 680.00, 0.00, 0.00, 0.00}, + .expected = { + .pixel_clock = {3200.00, 2720.00, 400.00, 680.00, + 1360.00, 0.00, 0.00, 0.00}, + .pixel_clock_backend = {3200.00, 1360.00, 400.00, 340.00, + 680.00, 0.00, 0.00, 0.00}, + }, + }, + { + .desc = "Eight active planes with five interlaced planes", + .number_of_active_planes = 8, + .interlace = {true, true, false, true, true, false, true, false}, + .progressive_to_interlace_unit_in_OPP = true, + .pixel_clock = {3200.00, 1360.00, 400.00, 340.00, 680.00, 1360.00, 2720.00, 340.00}, + .expected = { + .pixel_clock = {6400.00, 2720.00, 400.00, 680.00, + 1360.00, 1360.00, 5440.00, 340.00}, + .pixel_clock_backend = {3200.00, 1360.00, 400.00, 340.00, + 680.00, 1360.00, 2720.00, 340.0}, + }, + }, + { + .desc = "Eight active planes with all planes interlaced", + .number_of_active_planes = 8, + .interlace = {true, true, true, true, true, true, true, true}, + .progressive_to_interlace_unit_in_OPP = true, + .pixel_clock = {3200.00, 1360.00, 400.00, 340.00, 680.00, 1360.00, 2720.00, 340.00}, + .expected = { + .pixel_clock = {6400.00, 2720.00, 800.0, 680.00, + 1360.00, 2720.00, 5440.0, 680.00}, + .pixel_clock_backend = {3200.00, 1360.00, 400.00, 340.00, + 680.00, 1360.00, 2720.00, 340.00}, + }, + }, + { + .desc = "Eight active planes with no interlaced plane", + .number_of_active_planes = 8, + .interlace = {false, false, false, false, false, false, false, false}, + .progressive_to_interlace_unit_in_OPP = false, + .pixel_clock = {3200.00, 1360.00, 400.00, 340.00, 680.00, 1360.00, 2720.00, 340.00}, + .expected = { + .pixel_clock = {3200.00, 1360.00, 400.00, 340.00, + 680.00, 1360.00, 2720.00, 340.00}, + .pixel_clock_backend = {3200.00, 1360.00, 400.00, 340.00, + 680.00, 1360.00, 2720.00, 340.00}, + }, + }, + { + .desc = "Eight active planes with no progressive_to_interlace_unit_in_OPP", + .number_of_active_planes = 8, + .interlace = {true, true, true, true, true, true, true, true}, + .progressive_to_interlace_unit_in_OPP = false, + .pixel_clock = {3200.00, 1360.00, 400.00, 340.00, 680.00, 1360.00, 2720.00, 340.00}, + .expected = { + .pixel_clock = {3200.00, 1360.00, 400.00, 340.00, + 680.00, 1360.00, 2720.00, 340.00}, + .pixel_clock_backend = {3200.00, 1360.00, 400.00, 340.00, + 680.00, 1360.00, 2720.00, 340.00}, + }, + }, +}; + +static const struct calculate_256B_block_sizes_test_case calculate_256B_block_sizes_cases[] = { + /* + * Here 16-bit specifies the number of bits in the horizontal 4-element region + * used for subsampling + */ + { + .desc = "4:4:4 16-bit encoding with linear swizzle", + .source_pixel_format = dm_444_16, + .surface_tiling = dm_sw_linear, + .byte_per_pixel_Y = 2, + .byte_per_pixel_C = 0, + .block_height_256_bytes_Y = 1, + .block_width_256_bytes_Y = 128, + .block_height_256_bytes_C = 0, + .block_width_256_bytes_C = 0, + }, + { + .desc = "4:4:4 16-bit encoding with 256B standard swizzle", + .source_pixel_format = dm_444_16, + .surface_tiling = dm_sw_256b_s, + .byte_per_pixel_Y = 2, + .byte_per_pixel_C = 0, + .block_height_256_bytes_Y = 8, + .block_width_256_bytes_Y = 16, + .block_height_256_bytes_C = 0, + .block_width_256_bytes_C = 0, + }, + /* + * Here 32-bit specifies the number of bits in the horizontal + * 4-element region used for subsampling + */ + { + .desc = "4:4:4 32-bit encoding with linear swizzle", + .source_pixel_format = dm_444_32, + .surface_tiling = dm_sw_linear, + .byte_per_pixel_Y = 4, + .byte_per_pixel_C = 0, + .block_height_256_bytes_Y = 1, + .block_width_256_bytes_Y = 64, + .block_height_256_bytes_C = 0, + .block_width_256_bytes_C = 0, + }, + { + .desc = "4:4:4 32-bit encoding with 256B display swizzle", + .source_pixel_format = dm_444_32, + .surface_tiling = dm_sw_256b_d, + .byte_per_pixel_Y = 4, + .byte_per_pixel_C = 0, + .block_height_256_bytes_Y = 8, + .block_width_256_bytes_Y = 8, + .block_height_256_bytes_C = 0, + .block_width_256_bytes_C = 0, + }, + /* + * Here 64-bit specifies the number of bits in the horizontal 4-element region + * used for subsampling + */ + { + .desc = "4:4:4 64-bit encoding with linear swizzle", + .source_pixel_format = dm_444_64, + .surface_tiling = dm_sw_linear, + .byte_per_pixel_Y = 8, + .byte_per_pixel_C = 0, + .block_height_256_bytes_Y = 1, + .block_width_256_bytes_Y = 32, + .block_height_256_bytes_C = 0, + .block_width_256_bytes_C = 0, + }, + { + .desc = "4:4:4 64-bit encoding with 4KB standard swizzle", + .source_pixel_format = dm_444_64, + .surface_tiling = dm_sw_4kb_s, + .byte_per_pixel_Y = 8, + .byte_per_pixel_C = 0, + .block_height_256_bytes_Y = 4, + .block_width_256_bytes_Y = 8, + .block_height_256_bytes_C = 0, + .block_width_256_bytes_C = 0, + }, + { + .desc = "4:4:4 8-bit encoding with linear swizzle", + .source_pixel_format = dm_444_8, + .surface_tiling = dm_sw_linear, + .byte_per_pixel_Y = 1, + .byte_per_pixel_C = 0, + .block_height_256_bytes_Y = 1, + .block_width_256_bytes_Y = 256, + .block_height_256_bytes_C = 0, + .block_width_256_bytes_C = 0, + }, + { + .desc = "4:4:4 8-bit encoding with 4KB display swizzle", + .source_pixel_format = dm_444_8, + .surface_tiling = dm_sw_4kb_d, + .byte_per_pixel_Y = 1, + .byte_per_pixel_C = 0, + .block_height_256_bytes_Y = 16, + .block_width_256_bytes_Y = 16, + .block_height_256_bytes_C = 0, + .block_width_256_bytes_C = 0, + }, + { + .desc = "8-bit mono encoding with linear swizzle", + .source_pixel_format = dm_mono_8, + .surface_tiling = dm_sw_linear, + .byte_per_pixel_Y = 1, + .byte_per_pixel_C = 0, + .block_height_256_bytes_Y = 1, + .block_width_256_bytes_Y = 256, + .block_height_256_bytes_C = 0, + .block_width_256_bytes_C = 0, + }, + { + .desc = "8-bit mono encoding with 64KB standard swizzle", + .source_pixel_format = dm_mono_8, + .surface_tiling = dm_sw_64kb_s, + .byte_per_pixel_Y = 1, + .byte_per_pixel_C = 0, + .block_height_256_bytes_Y = 16, + .block_width_256_bytes_Y = 16, + .block_height_256_bytes_C = 0, + .block_width_256_bytes_C = 0, + }, + { + .desc = "16-bit mono encoding with linear swizzle", + .source_pixel_format = dm_mono_16, + .surface_tiling = dm_sw_linear, + .byte_per_pixel_Y = 2, + .byte_per_pixel_C = 0, + .block_height_256_bytes_Y = 1, + .block_width_256_bytes_Y = 128, + .block_height_256_bytes_C = 0, + .block_width_256_bytes_C = 0, + }, + { + .desc = "16-bit mono encoding with 64KB display swizzle", + .source_pixel_format = dm_mono_16, + .surface_tiling = dm_sw_64kb_d, + .byte_per_pixel_Y = 2, + .byte_per_pixel_C = 0, + .block_height_256_bytes_Y = 8, + .block_width_256_bytes_Y = 16, + .block_height_256_bytes_C = 0, + .block_width_256_bytes_C = 0, + }, + { + .desc = "8-bit 4:2:0 encoding with linear swizzle", + .source_pixel_format = dm_420_8, + .surface_tiling = dm_sw_linear, + .byte_per_pixel_Y = 1, + .byte_per_pixel_C = 2, + .block_height_256_bytes_Y = 1, + .block_width_256_bytes_Y = 256, + .block_height_256_bytes_C = 1, + .block_width_256_bytes_C = 128, + }, + { + .desc = "8-bit 4:2:0 encoding with VAR standard swizzle", + .source_pixel_format = dm_420_8, + .surface_tiling = dm_sw_var_s, + .byte_per_pixel_Y = 1, + .byte_per_pixel_C = 2, + .block_height_256_bytes_Y = 16, + .block_width_256_bytes_Y = 16, + .block_height_256_bytes_C = 8, + .block_width_256_bytes_C = 16, + }, + { + .desc = "10-bit 4:2:0 encoding with linear swizzle", + .source_pixel_format = dm_420_10, + .surface_tiling = dm_sw_linear, + .byte_per_pixel_Y = 4.0 / 3.0, + .byte_per_pixel_C = 8.0 / 3.0, + .block_height_256_bytes_Y = 1, + .block_width_256_bytes_Y = 256, + .block_height_256_bytes_C = 1, + .block_width_256_bytes_C = 128, + }, + { + .desc = "10-bit 4:2:0 encoding with VAR display swizzle", + .source_pixel_format = dm_420_10, + .surface_tiling = dm_sw_var_d, + .byte_per_pixel_Y = 4.0 / 3.0, + .byte_per_pixel_C = 8.0 / 3.0, + .block_height_256_bytes_Y = 8, + .block_width_256_bytes_Y = 32, + .block_height_256_bytes_C = 8, + .block_width_256_bytes_C = 16, + }, +}; + +static const struct calculate_write_back_DISPCLK_test_case calculate_write_back_DISPCLK_cases[] = { + { + .desc = "Trivial test", + .writeback_pixel_format = dm_444_32, + .pixel_clock = 0.00, + .writeback_HRatio = 1.0, + .writeback_VRatio = 1.0, + .writeback_luma_HTaps = 4, + .writeback_luma_VTaps = 4, + .writeback_chroma_HTaps = 5, + .writeback_chroma_VTaps = 5, + .writeback_destination_width = 2400.0, + .HTotal = 1400, + .writeback_chroma_line_buffer_width = 2, + .calculate_write_back_DISPCLK = 0, + }, + { + .desc = "Simple Writeback Ratio", + .writeback_pixel_format = dm_444_32, + .pixel_clock = 1800.00, + .writeback_HRatio = 1.0, + .writeback_VRatio = 1.0, + .writeback_luma_HTaps = 4, + .writeback_luma_VTaps = 4, + .writeback_chroma_HTaps = 5, + .writeback_chroma_VTaps = 5, + .writeback_destination_width = 2400.0, + .HTotal = 1400, + .writeback_chroma_line_buffer_width = 2, + .calculate_write_back_DISPCLK = 0x1.e7c6a11ep+11, + }, + { + .desc = "Non-integer WritebackVRatio with same number of Luma and Chroma taps", + .writeback_pixel_format = dm_444_32, + .pixel_clock = 1360.00, + .writeback_HRatio = 1.0, + .writeback_VRatio = 1.5, + .writeback_luma_HTaps = 7, + .writeback_luma_VTaps = 7, + .writeback_chroma_HTaps = 7, + .writeback_chroma_VTaps = 7, + .writeback_destination_width = 400.56, + .HTotal = 1400, + .writeback_chroma_line_buffer_width = 4, + .calculate_write_back_DISPCLK = 0x1.5766666666666p+11, + }, + { + .desc = "No Writeback to Chroma Taps", + .writeback_pixel_format = dm_444_32, + .pixel_clock = 2720.72, + .writeback_HRatio = 1.0, + .writeback_VRatio = 1.5, + .writeback_luma_HTaps = 5, + .writeback_luma_VTaps = 5, + .writeback_chroma_HTaps = 0, + .writeback_chroma_VTaps = 0, + .writeback_destination_width = 2400.0, + .HTotal = 1400, + .writeback_chroma_line_buffer_width = 4, + .calculate_write_back_DISPCLK = 0x1.ba5e02226985ep+12, + }, + { + .desc = "No Writeback to Luma Taps", + .writeback_pixel_format = dm_444_32, + .pixel_clock = 1800.66, + .writeback_HRatio = 2.0, + .writeback_VRatio = 1.5, + .writeback_luma_HTaps = 0, + .writeback_luma_VTaps = 0, + .writeback_chroma_HTaps = 3, + .writeback_chroma_VTaps = 3, + .writeback_destination_width = 2400.0, + .HTotal = 1400, + .writeback_chroma_line_buffer_width = 4, + .calculate_write_back_DISPCLK = 0x1.85b6dabefdfd9p+11, + }, + { + .desc = "Reduce numeric error by decreasing pixel clock", + .writeback_pixel_format = dm_444_32, + .pixel_clock = 400.756, + .writeback_HRatio = 2.0, + .writeback_VRatio = 1.0, + .writeback_luma_HTaps = 5, + .writeback_luma_VTaps = 5, + .writeback_chroma_HTaps = 5, + .writeback_chroma_VTaps = 5, + .writeback_destination_width = 2400.0, + .HTotal = 1100, + .writeback_chroma_line_buffer_width = 2, + .calculate_write_back_DISPCLK = 0x1.4bb8ddb60f598p+10, + }, + { + .desc = "Increase numeric error by increasing pixel clock", + .writeback_pixel_format = dm_444_32, + .pixel_clock = 3200.8, + .writeback_HRatio = 2.0, + .writeback_VRatio = 1.0, + .writeback_luma_HTaps = 4, + .writeback_luma_VTaps = 4, + .writeback_chroma_HTaps = 2, + .writeback_chroma_VTaps = 2, + .writeback_destination_width = 1686.7, + .HTotal = 1100, + .writeback_chroma_line_buffer_width = 2, + .calculate_write_back_DISPCLK = 0x1.847ced698147bp+12, + }, + { + .desc = "Simple Writeback Ratio for 4:4:4 8-bit encoding", + .writeback_pixel_format = dm_444_8, + .pixel_clock = 1800.00, + .writeback_HRatio = 1.0, + .writeback_VRatio = 1.0, + .writeback_luma_HTaps = 4, + .writeback_luma_VTaps = 4, + .writeback_chroma_HTaps = 5, + .writeback_chroma_VTaps = 5, + .writeback_destination_width = 2400.0, + .HTotal = 1400, + .writeback_chroma_line_buffer_width = 2, + .calculate_write_back_DISPCLK = 0x1.24aa62p+12, + }, + { + .desc = "Non-integer WritebackVRatio with same number of Luma and Chroma taps for 4:4:4 64-bit encoding", + .writeback_pixel_format = dm_444_64, + .pixel_clock = 1360.00, + .writeback_HRatio = 1.0, + .writeback_VRatio = 1.5, + .writeback_luma_HTaps = 7, + .writeback_luma_VTaps = 7, + .writeback_chroma_HTaps = 7, + .writeback_chroma_VTaps = 7, + .writeback_destination_width = 400.56, + .HTotal = 1400, + .writeback_chroma_line_buffer_width = 4, + .calculate_write_back_DISPCLK = 0x1.576666p+11, + }, + { + .desc = "No Writeback to Chroma Taps for 4:2:0 8-bit encoding", + .writeback_pixel_format = dm_420_8, + .pixel_clock = 2720.72, + .writeback_HRatio = 1.0, + .writeback_VRatio = 1.5, + .writeback_luma_HTaps = 8, + .writeback_luma_VTaps = 8, + .writeback_chroma_HTaps = 0, + .writeback_chroma_VTaps = 0, + .writeback_destination_width = 1333.56, + .HTotal = 1400, + .writeback_chroma_line_buffer_width = 5, + .calculate_write_back_DISPCLK = 0x1.717f8p+12, + }, + { + .desc = "No Writeback to Luma Taps for 4:2:0 10-bit encoding", + .writeback_pixel_format = dm_420_10, + .pixel_clock = 1800.66, + .writeback_HRatio = 2.0, + .writeback_VRatio = 1.5, + .writeback_luma_HTaps = 0, + .writeback_luma_VTaps = 0, + .writeback_chroma_HTaps = 3, + .writeback_chroma_VTaps = 3, + .writeback_destination_width = 996.0, + .HTotal = 1400, + .writeback_chroma_line_buffer_width = 4, + .calculate_write_back_DISPCLK = 0x1.43767ep+10, + }, + { + .desc = "Reduce numeric error by decreasing pixel clock for 4:4:4 16-bit encoding", + .writeback_pixel_format = dm_444_16, + .pixel_clock = 340.456, + .writeback_HRatio = 2.0, + .writeback_VRatio = 1.0, + .writeback_luma_HTaps = 5, + .writeback_luma_VTaps = 5, + .writeback_chroma_HTaps = 5, + .writeback_chroma_VTaps = 5, + .writeback_destination_width = 2400.0, + .HTotal = 1181, + .writeback_chroma_line_buffer_width = 3, + .calculate_write_back_DISPCLK = 0x1.067b3p+10, + }, + { + .desc = "Increase numeric error by increasing pixel clock for 4:4:4 16-bit encoding", + .writeback_pixel_format = dm_444_16, + .pixel_clock = 4000.92, + .writeback_HRatio = 2.0, + .writeback_VRatio = 1.0, + .writeback_luma_HTaps = 3, + .writeback_luma_VTaps = 3, + .writeback_chroma_HTaps = 2, + .writeback_chroma_VTaps = 2, + .writeback_destination_width = 1686.7, + .HTotal = 1100, + .writeback_chroma_line_buffer_width = 2, + .calculate_write_back_DISPCLK = 0x1.84b5b8p+12, + }, +}; + +static void pixel_clock_adjustment_for_progressive_to_interlace_unit_test_to_desc +(const struct pixel_clock_adjustment_for_progressive_to_interlace_unit_test_case *t, + char *desc) +{ + strcpy(desc, t->desc); +} + +KUNIT_ARRAY_PARAM(pixel_clock_adjustment_for_progressive_to_interlace_unit, + pixel_clock_adjustment_for_progressive_to_interlace_unit_cases, + pixel_clock_adjustment_for_progressive_to_interlace_unit_test_to_desc); + +static void calculate_256B_block_sizes_test_to_desc +(const struct calculate_256B_block_sizes_test_case *t, char *desc) +{ + strcpy(desc, t->desc); +} + +KUNIT_ARRAY_PARAM(calculate_256B_block_sizes, calculate_256B_block_sizes_cases, + calculate_256B_block_sizes_test_to_desc); + +static void calculate_write_back_DISPCLK_test_to_desc(const struct + calculate_write_back_DISPCLK_test_case * t, char *desc) +{ + strcpy(desc, t->desc); +} + +KUNIT_ARRAY_PARAM(calculate_write_back_DISPCLK, calculate_write_back_DISPCLK_cases, + calculate_write_back_DISPCLK_test_to_desc); + +static struct kunit_case display_mode_vba_test_cases[] = { + KUNIT_CASE_PARAM(pclk_adjustment_for_progressive_to_interlace_unit_test, + pixel_clock_adjustment_for_progressive_to_interlace_unit_gen_params), + KUNIT_CASE_PARAM(calculate_256B_block_sizes_test, + calculate_256B_block_sizes_gen_params), + KUNIT_CASE(calculate_min_and_max_prefetch_mode_test), + KUNIT_CASE_PARAM(calculate_write_back_DISPCLK_test, + calculate_write_back_DISPCLK_gen_params), + {} +}; + +static struct kunit_suite display_mode_vba_test_suite = { + .name = "dml_display_mode_vba", + .test_cases = display_mode_vba_test_cases, +}; + +kunit_test_suite(display_mode_vba_test_suite); From patchwork Fri Jan 26 15:48:05 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: Rodrigo Siqueira Jordao X-Patchwork-Id: 13532858 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from gabe.freedesktop.org (gabe.freedesktop.org [131.252.210.177]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.lore.kernel.org (Postfix) with ESMTPS id 94F97C47422 for ; Fri, 26 Jan 2024 15:51:57 +0000 (UTC) Received: from gabe.freedesktop.org (localhost [127.0.0.1]) by gabe.freedesktop.org (Postfix) with ESMTP id C8D4610FBDD; Fri, 26 Jan 2024 15:51:50 +0000 (UTC) Received: from NAM02-DM3-obe.outbound.protection.outlook.com (mail-dm3nam02on2041.outbound.protection.outlook.com [40.107.95.41]) by gabe.freedesktop.org (Postfix) with ESMTPS id 373F310FBDF; Fri, 26 Jan 2024 15:51:40 +0000 (UTC) ARC-Seal: i=1; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=none; b=MlfWYX7R2jKC0klCsRRLy2p5vNCwUNJSsiBnI63Z+NMjHivXVEjN/JcNZyaoqHAm+znJsPEfjIU1eKkKtIYj0+nUDbIeMl8zNP9jKENayOkLrD03fSfuFPsNMEJmk+HFaTNV8bKOaECJl0TppnsjxxA2HIeWZBV7H6p1xGjjQU45678cnFtNCfcaRPhHKa3wRavlpxx+UN+CNeXXXaEf+GPDtgobmMuUvYQLC0f9qOPGYiIrv4H9YNm71cBqDe7mFRRC/18NLPLOI/pDgza705047FlmwH6g3e1POB6X+nLcCH6ENfziQTZaxiDf6cwZwRFvqjZADAHbsOvKgA1/wA== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=microsoft.com; s=arcselector9901; h=From:Date:Subject:Message-ID:Content-Type:MIME-Version:X-MS-Exchange-AntiSpam-MessageData-ChunkCount:X-MS-Exchange-AntiSpam-MessageData-0:X-MS-Exchange-AntiSpam-MessageData-1; bh=9fN/5aNfC9JxG/zdJCDq/JT8RYgv+ff2R5BBQPJJ4uY=; b=R7zOSDjDoCD4pW4vOE/gsi/c3w4KdNQMAACXciHQOIkq+zCgg2+jH2sNH6kMp4BBED9K6aDhMR5kMnz+zTGsKrZgkAdocI1NeTXtDfm40fd349d13SyNdivsWkPlL+iC0+dxu5IYizs9qeLhgixYnQiOVmyF5VWZ3I7pIWeoANMzxXDZJJFS6bBOkzspg6aRHCp0iexXLQiuG+Bb2aly+nhPjjOytL9kiXyVY3PAD3iurZfDZpttlRzYA4spKQcYlIbgSLRe97GSwumxBqEUxPm1Bc2UUk/z28y/fIiNN+E4yP9+Bl083FSXVL6B+riJIQ4DLu1PX+oZ5HRAPXNfrg== ARC-Authentication-Results: i=1; mx.microsoft.com 1; spf=pass (sender ip is 165.204.84.17) smtp.rcpttodomain=linux.ie smtp.mailfrom=amd.com; dmarc=pass (p=quarantine sp=quarantine pct=100) action=none header.from=amd.com; dkim=none (message not signed); arc=none (0) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=amd.com; s=selector1; h=From:Date:Subject:Message-ID:Content-Type:MIME-Version:X-MS-Exchange-SenderADCheck; bh=9fN/5aNfC9JxG/zdJCDq/JT8RYgv+ff2R5BBQPJJ4uY=; b=Dxk+dVxZbpY6Gwy4ywMLjLmfjAiVrMQrHGiLyzmJpYDVqKPoD2IlkJYr2AmV1Z/wbP8ZtSmdGtjT/7/2ViL0zBxkTX4p0dArK4RJ8mdZTm1s6iUVfNIy+yol41SuWr/tspw67jzoVBKyuI1uAHDKSoflgGETjaF4nKy26/bPfT8= Received: from SJ0PR03CA0086.namprd03.prod.outlook.com (2603:10b6:a03:331::31) by DS0PR12MB7557.namprd12.prod.outlook.com (2603:10b6:8:130::21) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.7228.22; Fri, 26 Jan 2024 15:51:34 +0000 Received: from SJ1PEPF00001CDF.namprd05.prod.outlook.com (2603:10b6:a03:331:cafe::4a) by SJ0PR03CA0086.outlook.office365.com (2603:10b6:a03:331::31) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.7228.22 via Frontend Transport; Fri, 26 Jan 2024 15:51:33 +0000 X-MS-Exchange-Authentication-Results: spf=pass (sender IP is 165.204.84.17) smtp.mailfrom=amd.com; dkim=none (message not signed) header.d=none;dmarc=pass action=none header.from=amd.com; Received-SPF: Pass (protection.outlook.com: domain of amd.com designates 165.204.84.17 as permitted sender) receiver=protection.outlook.com; client-ip=165.204.84.17; helo=SATLEXMB04.amd.com; pr=C Received: from SATLEXMB04.amd.com (165.204.84.17) by SJ1PEPF00001CDF.mail.protection.outlook.com (10.167.242.7) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256) id 15.20.7202.16 via Frontend Transport; Fri, 26 Jan 2024 15:51:33 +0000 Received: from smtp.xilinx.com (10.180.168.240) by SATLEXMB04.amd.com (10.181.40.145) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256) id 15.1.2507.34; Fri, 26 Jan 2024 09:51:29 -0600 From: Rodrigo Siqueira To: Alex Deucher , , , David Airlie , Daniel Vetter , Maarten Lankhorst , Maxime Ripard , Thomas Zimmermann , Harry Wentland , Leo Li , "Rodrigo Siqueira" , Nicholas Choi , Daniel Latypov , David Gow , , Subject: [PATCH v4 5/8] drm/amd/display: Introduce KUnit to dcn20/display_mode_vba_20 library Date: Fri, 26 Jan 2024 08:48:05 -0700 Message-ID: <20240126155022.1184856-6-Rodrigo.Siqueira@amd.com> X-Mailer: git-send-email 2.43.0 In-Reply-To: <20240126155022.1184856-1-Rodrigo.Siqueira@amd.com> References: <20240126155022.1184856-1-Rodrigo.Siqueira@amd.com> MIME-Version: 1.0 X-Originating-IP: [10.180.168.240] X-ClientProxiedBy: SATLEXMB04.amd.com (10.181.40.145) To SATLEXMB04.amd.com (10.181.40.145) X-EOPAttributedMessage: 0 X-MS-PublicTrafficType: Email X-MS-TrafficTypeDiagnostic: SJ1PEPF00001CDF:EE_|DS0PR12MB7557:EE_ X-MS-Office365-Filtering-Correlation-Id: da497d78-074f-4ff4-cc1a-08dc1e86abf8 X-MS-Exchange-SenderADCheck: 1 X-MS-Exchange-AntiSpam-Relay: 0 X-Microsoft-Antispam: BCL:0; X-Microsoft-Antispam-Message-Info: Lb038lHlPiuE094OfGLrOnMV/oYRVCctRWelVIwGxbZLniGJ3D0IeYrTeO5CCoykIBBOde/Nv+RtGhVTyFLkUK6AWKcu5kEe3X+NXmlUZt5kZ3OGu/7dCapFbIeAKG+dMwt6CbyQ/XM18t9WzmgCwa+7WQHR4BTArmzXLHSax0p1wTZfEmXFYS57zakudtQiUPvgUZ3WnDswM8rAieUSK0F6bejrPPN1mffJWH/aV82vYv3LC5ZSlQwxQZIkp1WmnM7EWsTZECudIuDsSEs8IkR6cuF8HE4BO98r1j2no6p7Is7gn6jcOqHpKLoZBboYlSOT0P1PhybTt2sOed9XMMMrr+pVS9oCaMCqGSDIeQ/rpUPIeT1HyypxzQTcouO/AB65yeOcWkhrYNIZwhdwWSEGE3KT86rNgIQMQW1Pw+IDrwg+fs5Y44sy7CP4VNv038ntfDU/uFzk1o2aJS1N8bWFry8/YpZf1dBIfunGsXK1SX60muanuklqWwinnpx5X0UzloSh3+qK3gJ+vW5mSLxUS/XbuZ565DbloPtgVPdI1YMh6BCN5wA5WsXJVxRqdM60r4xwvdTy2qmJr46kHSPgAArSSwV8xrrKzzbukRfM+YUsnALCNR1btFOFL4r1gMlF+5s9lahLBrQFLrSHkHSf/ka+E7xrfqRi43Oiw++1tn5MPwzIOAITBUiPVxxcugKp4ZPZTrVMU//IrsyGlFu3uIeSWpyAN41YSm0sq+ODGysqw1vA7IlbRMMZZHyuynOWwFUBC7PECneDToQvUM52P9i2HxQVdf1MRg7TCfw= X-Forefront-Antispam-Report: CIP:165.204.84.17; CTRY:US; LANG:en; SCL:1; SRV:; IPV:CAL; SFV:NSPM; H:SATLEXMB04.amd.com; PTR:InfoDomainNonexistent; CAT:NONE; SFS:(13230031)(4636009)(396003)(346002)(136003)(376002)(39860400002)(230922051799003)(64100799003)(1800799012)(451199024)(186009)(82310400011)(36840700001)(40470700004)(46966006)(921011)(66899024)(47076005)(316002)(70206006)(70586007)(2616005)(54906003)(478600001)(7416002)(110136005)(83380400001)(5660300002)(2906002)(30864003)(82740400003)(36860700001)(8676002)(4326008)(8936002)(6666004)(66574015)(336012)(1076003)(426003)(16526019)(26005)(86362001)(36756003)(41300700001)(356005)(40460700003)(40480700001)(81166007)(36900700001); DIR:OUT; SFP:1101; X-OriginatorOrg: amd.com X-MS-Exchange-CrossTenant-OriginalArrivalTime: 26 Jan 2024 15:51:33.6615 (UTC) X-MS-Exchange-CrossTenant-Network-Message-Id: da497d78-074f-4ff4-cc1a-08dc1e86abf8 X-MS-Exchange-CrossTenant-Id: 3dd8961f-e488-4e60-8e11-a82d994e183d X-MS-Exchange-CrossTenant-OriginalAttributedTenantConnectingIp: TenantId=3dd8961f-e488-4e60-8e11-a82d994e183d; Ip=[165.204.84.17]; Helo=[SATLEXMB04.amd.com] X-MS-Exchange-CrossTenant-AuthSource: SJ1PEPF00001CDF.namprd05.prod.outlook.com X-MS-Exchange-CrossTenant-AuthAs: Anonymous X-MS-Exchange-CrossTenant-FromEntityHeader: HybridOnPrem X-MS-Exchange-Transport-CrossTenantHeadersStamped: DS0PR12MB7557 X-BeenThere: dri-devel@lists.freedesktop.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: Direct Rendering Infrastructure - Development List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: tales.aparecida@gmail.com, Trevor Woerner , javierm@redhat.com, dri-devel@lists.freedesktop.org, mwen@igalia.com, =?utf-8?q?Ma=C3=ADra_Canal?= , amd-gfx@lists.freedesktop.org, Isabella Basso , andrealmeid@riseup.net, kunit-dev@googlegroups.com Errors-To: dri-devel-bounces@lists.freedesktop.org Sender: "dri-devel" From: Maíra Canal The display_mode_vba_20 deals with hundreds of display parameters for the DCN20 and sometimes does it in odd ways. The addition of unit tests intends to assure the quality of the code delivered by HW engineers and, also make it possible to refactor the code decreasing concerns about adding bugs to the codebase. Signed-off-by: Maíra Canal --- .../dc/dml/dcn20/display_mode_vba_20.c | 4 + .../dc/dml/dcn20/display_mode_vba_20_test.c | 888 ++++++++++++++++++ 2 files changed, 892 insertions(+) create mode 100644 drivers/gpu/drm/amd/display/tests/dc/dml/dcn20/display_mode_vba_20_test.c diff --git a/drivers/gpu/drm/amd/display/dc/dml/dcn20/display_mode_vba_20.c b/drivers/gpu/drm/amd/display/dc/dml/dcn20/display_mode_vba_20.c index 7bf4bb7ad044..29ef47028630 100644 --- a/drivers/gpu/drm/amd/display/dc/dml/dcn20/display_mode_vba_20.c +++ b/drivers/gpu/drm/amd/display/dc/dml/dcn20/display_mode_vba_20.c @@ -5116,3 +5116,7 @@ void dml20_ModeSupportAndSystemConfigurationFull(struct display_mode_lib *mode_l locals->OutputBppPerState[mode_lib->vba.VoltageLevel][k]; } } + +#if IS_ENABLED(CONFIG_DML_KUNIT_TEST) +#include "../../tests/dc/dml/dcn20/display_mode_vba_20_test.c" +#endif diff --git a/drivers/gpu/drm/amd/display/tests/dc/dml/dcn20/display_mode_vba_20_test.c b/drivers/gpu/drm/amd/display/tests/dc/dml/dcn20/display_mode_vba_20_test.c new file mode 100644 index 000000000000..eeeacc2758a3 --- /dev/null +++ b/drivers/gpu/drm/amd/display/tests/dc/dml/dcn20/display_mode_vba_20_test.c @@ -0,0 +1,888 @@ +// SPDX-License-Identifier: MIT +/* + * KUnit tests for dml/dcn20/display_mode_vba_20.c + * + * Copyright (C) 2022, Maíra Canal + */ + +#include +#include "dml/display_mode_enums.h" + +struct calculate_write_back_delay_test_case { + const char *desc; + const enum source_format_class writeback_pixel_format; + const double writeback_HRatio; + const double writeback_VRatio; + const unsigned int writeback_luma_HTaps; + const unsigned int writeback_luma_VTaps; + const unsigned int writeback_chroma_HTaps; + const unsigned int writeback_chroma_VTaps; + const unsigned int writeback_destination_width; + const double calculate_write_back_delay; +}; + +struct calculate_active_row_bandwidth_test_case { + const char *desc; + const bool GPUVM_enable; + const enum source_format_class source_pixel_format; + const double VRatio; + const bool DCC_enable; + const double line_time; + const unsigned int meta_row_byte_luma; + const unsigned int meta_row_byte_chroma; + const unsigned int meta_row_height_luma; + const unsigned int meta_row_height_chroma; + const unsigned int pixel_PTE_bytes_per_row_luma; + const unsigned int pixel_PTE_bytes_per_row_chroma; + const unsigned int dpte_row_height_luma; + const unsigned int dpte_row_height_chroma; + const double meta_row_bw; + const double dpte_row_bw; + const double qual_row_bw; +}; + +/** + * dscce_compute_delay_test - KUnit test for dscceComputeDelay + * @test: represents a running instance of a test. + */ +static void dscce_compute_delay_test(struct kunit *test) +{ + /* Testing all the valid values for bits per color (bpc): {8, 10, 12} */ + /* Testing all the valid values for number of slices: {1, 2, 3, 4} */ + + /* + * For 4:4:4 encoding, the minimum bpp value is 8 and is incremented by + * 1/16 of a bit. Moreover, the sliceWidth must be less than or equal to + * 5184/numSlices. + */ + + /* Minimum sliceWidth value on 4:4:4 encoding */ + KUNIT_EXPECT_EQ(test, dscceComputeDelay(8, 8.0, 1, 1, dm_444), 2004); + + KUNIT_EXPECT_EQ(test, dscceComputeDelay(8, 8.0625, 5184, 1, dm_444), 885); + + KUNIT_EXPECT_EQ(test, dscceComputeDelay(10, 8.125, 2592, 2, dm_444), 3495); + + KUNIT_EXPECT_EQ(test, dscceComputeDelay(10, 8.1875, 1728, 3, dm_444), 4356); + + KUNIT_EXPECT_EQ(test, dscceComputeDelay(12, 8.25, 864, 3, dm_444), 4425); + + KUNIT_EXPECT_EQ(test, dscceComputeDelay(12, 8.3125, 1296, 4, dm_444), 4854); + + /* + * For 4:2:0 encoding, the minimum bpp value is 6 and is incremented by + * 1/16 of a bit. Moreover, the sliceWidth must be less than or equal to + * 4096/numSlices. + */ + + /* Minimum sliceWidth value on 4:2:0 encoding */ + KUNIT_EXPECT_EQ(test, dscceComputeDelay(8, 6.0, 2, 1, dm_420), 2982); + + KUNIT_EXPECT_EQ(test, dscceComputeDelay(8, 6.0625, 4096, 1, dm_420), 1428); + + KUNIT_EXPECT_EQ(test, dscceComputeDelay(10, 6.125, 2048, 2, dm_420), 3522); + + KUNIT_EXPECT_EQ(test, dscceComputeDelay(10, 6.1875, 1365, 3, dm_420), 4200); + + KUNIT_EXPECT_EQ(test, dscceComputeDelay(12, 6.25, 682, 3, dm_420), 5706); + + KUNIT_EXPECT_EQ(test, dscceComputeDelay(12, 6.3125, 1024, 4, dm_420), 7746); + + /* + * For 4:2:2 encoding, the minimum bpp value is 7 and is incremented by + * 1/16 of a bit. Moreover, the sliceWidth must be less than or equal to + * 5184/numSlices. + */ + + /* Minimum sliceWidth value on n-4:2:2 encoding */ + KUNIT_EXPECT_EQ(test, dscceComputeDelay(8, 7.0, 2, 1, dm_n422), 2694); + + KUNIT_EXPECT_EQ(test, dscceComputeDelay(8, 7.0625, 5184, 1, dm_n422), 1332); + + KUNIT_EXPECT_EQ(test, dscceComputeDelay(10, 7.125, 2592, 2, dm_n422), 3966); + + KUNIT_EXPECT_EQ(test, dscceComputeDelay(10, 7.1875, 1728, 3, dm_n422), 4824); + + KUNIT_EXPECT_EQ(test, dscceComputeDelay(12, 7.25, 864, 3, dm_n422), 4962); + + KUNIT_EXPECT_EQ(test, dscceComputeDelay(12, 7.3125, 1296, 4, dm_n422), 9282); + + /* Minimum sliceWidth value on s-4:2:2 encoding */ + KUNIT_EXPECT_EQ(test, dscceComputeDelay(8, 7.0, 1, 1, dm_s422), 2226); + + KUNIT_EXPECT_EQ(test, dscceComputeDelay(8, 7.0625, 5184, 1, dm_s422), 960); + + KUNIT_EXPECT_EQ(test, dscceComputeDelay(10, 7.125, 2592, 2, dm_s422), 3570); + + KUNIT_EXPECT_EQ(test, dscceComputeDelay(10, 7.1875, 1728, 3, dm_s422), 4428); + + KUNIT_EXPECT_EQ(test, dscceComputeDelay(12, 7.25, 864, 3, dm_s422), 4497); + + KUNIT_EXPECT_EQ(test, dscceComputeDelay(12, 7.3125, 1296, 4, dm_s422), 4923); +} + +/** + * DSC_compute_delay_test - KUnit test for dscComputeDelay + * @test: represents a running instance of a test. + */ +static void DSC_compute_delay_test(struct kunit *test) +{ + /* 4:4:4 encoding */ + KUNIT_EXPECT_EQ(test, dscComputeDelay(dm_444), 30); + + /* 4:2:0 encoding */ + KUNIT_EXPECT_EQ(test, dscComputeDelay(dm_420), 48); + + /* 4:2:2 n-encoding */ + KUNIT_EXPECT_EQ(test, dscComputeDelay(dm_n422), 49); + + /* 4:2:2 s-encoding */ + KUNIT_EXPECT_EQ(test, dscComputeDelay(dm_s422), 30); +} + +/** + * calculate_TWait_test - KUnit test for CalculateTWait + * @test: represents a running instance of a test. + */ +static void calculate_TWait_test(struct kunit *test) +{ + /* Zeroed Prefetch Mode */ + + /* DRAMClockChangeLatency > UrgentLatencyPixelDataOnly > SREnterPlusExitTime*/ + KUNIT_EXPECT_EQ(test, CalculateTWait(0, 1300000, 1200000, 1000000), 2500000); + + /* DRAMClockChangeLatency > SREnterPlusExitTime > UrgentLatencyPixelDataOnly */ + KUNIT_EXPECT_EQ(test, CalculateTWait(0, 1300000, 900000, 1200000), 2200000); + + /* UrgentLatencyPixelDataOnly > DRAMClockChangeLatency > SREnterPlusExitTime */ + KUNIT_EXPECT_EQ(test, CalculateTWait(0, 1000000, 2000000, 900000), 3000000); + + /* UrgentLatencyPixelDataOnly > SREnterPlusExitTime > DRAMClockChangeLatency */ + KUNIT_EXPECT_EQ(test, CalculateTWait(0, 1000000, 1200000, 1100000), 2200000); + + /* SREnterPlusExitTime > DRAMClockChangeLatency > UrgentLatencyPixelDataOnly */ + KUNIT_EXPECT_EQ(test, CalculateTWait(0, 1000000, 900000, 2000000), 2000000); + + /* SREnterPlusExitTime > UrgentLatencyPixelDataOnly > DRAMClockChangeLatency */ + KUNIT_EXPECT_EQ(test, CalculateTWait(0, 1000000, 1200000, 1300000), 2200000); + + /* Prefetch Mode equals 1 */ + KUNIT_EXPECT_EQ(test, CalculateTWait(1, 2500000, 2000000, 900000), 2000000); + KUNIT_EXPECT_EQ(test, CalculateTWait(1, 1300000, 900000, 1200000), 1200000); + KUNIT_EXPECT_EQ(test, CalculateTWait(1, 1100000, 1200000, 1000000), 1200000); + KUNIT_EXPECT_EQ(test, CalculateTWait(1, 1000000, 1200000, 1100000), 1200000); + KUNIT_EXPECT_EQ(test, CalculateTWait(1, 1000000, 900000, 2000000), 2000000); + KUNIT_EXPECT_EQ(test, CalculateTWait(1, 1000000, 1200000, 1300000), 1300000); + + /* Prefetch Mode greater than 1 */ + KUNIT_EXPECT_EQ(test, CalculateTWait(1, 2500000, 2000000, 900000), 2000000); + KUNIT_EXPECT_EQ(test, CalculateTWait(2, 2500000, 900000, 2000000), 900000); + KUNIT_EXPECT_EQ(test, CalculateTWait(5, 1100000, 1200000, 1000000), 1200000); + KUNIT_EXPECT_EQ(test, CalculateTWait(4, 1000000, 1300000, 1200000), 1300000); + KUNIT_EXPECT_EQ(test, CalculateTWait(6, 1000000, 900000, 2000000), 900000); + KUNIT_EXPECT_EQ(test, CalculateTWait(3, 1000000, 1200000, 1300000), 1200000); +} + +/** + * calculate_write_back_delay_test - KUnit test for CalculateWriteBackDelay + * @test: represents a running instance of a test. + */ +static void calculate_write_back_delay_test(struct kunit *test) +{ + const struct calculate_write_back_delay_test_case *test_param = test->param_value; + double calculate_write_back_delay; + + DC_FP_START(); + calculate_write_back_delay = CalculateWriteBackDelay + (test_param->writeback_pixel_format, + test_param->writeback_HRatio, + test_param->writeback_VRatio, + test_param->writeback_luma_HTaps, + test_param->writeback_luma_VTaps, + test_param->writeback_chroma_HTaps, + test_param->writeback_chroma_VTaps, + test_param->writeback_destination_width); + DC_FP_END(); + + KUNIT_EXPECT_EQ(test, test_param->calculate_write_back_delay, + calculate_write_back_delay); +} + +/** + * calculate_active_row_bandwidth_test - KUnit test for CalculateActiveRowBandwidth + * @test: represents a running instance of a test. + */ +static void calculate_active_row_bandwidth_test(struct kunit *test) +{ + const struct calculate_active_row_bandwidth_test_case *test_param = test->param_value; + double *meta_row_bw, *dpte_row_bw, *qual_row_bw; + + meta_row_bw = kunit_kzalloc(test, sizeof(double), GFP_KERNEL); + KUNIT_ASSERT_NOT_ERR_OR_NULL(test, meta_row_bw); + + dpte_row_bw = kunit_kzalloc(test, sizeof(double), GFP_KERNEL); + KUNIT_ASSERT_NOT_ERR_OR_NULL(test, dpte_row_bw); + + qual_row_bw = kunit_kzalloc(test, sizeof(double), GFP_KERNEL); + KUNIT_ASSERT_NOT_ERR_OR_NULL(test, qual_row_bw); + + DC_FP_START(); + CalculateActiveRowBandwidth(test_param->GPUVM_enable, + test_param->source_pixel_format, + test_param->VRatio, + test_param->DCC_enable, + test_param->line_time, + test_param->meta_row_byte_luma, + test_param->meta_row_byte_chroma, + test_param->meta_row_height_luma, + test_param->meta_row_height_chroma, + test_param->pixel_PTE_bytes_per_row_luma, + test_param->pixel_PTE_bytes_per_row_chroma, + test_param->dpte_row_height_luma, + test_param->dpte_row_height_chroma, + meta_row_bw, + dpte_row_bw, + qual_row_bw); + DC_FP_END(); + + KUNIT_EXPECT_EQ(test, test_param->meta_row_bw, *meta_row_bw); + KUNIT_EXPECT_EQ(test, test_param->dpte_row_bw, *dpte_row_bw); + KUNIT_EXPECT_EQ(test, test_param->qual_row_bw, *qual_row_bw); +} + +/** + * trunc_to_valid_BPP_test - KUnit test for TruncToValidBPP + * @test: represents a running instance of a test. + */ +static void trunc_to_valid_BPP_test(struct kunit *test) +{ + /* HDMI output for 4:2:0 encoding */ + KUNIT_EXPECT_EQ(test, TruncToValidBPP(18.01, true, dm_hdmi, dm_420, 0), 18); + KUNIT_EXPECT_EQ(test, TruncToValidBPP(18, true, dm_hdmi, dm_420, 10), 18); + + KUNIT_EXPECT_EQ(test, TruncToValidBPP(15.01, false, dm_hdmi, dm_420, 0), 15); + KUNIT_EXPECT_EQ(test, TruncToValidBPP(15, false, dm_hdmi, dm_420, 8), 15); + + KUNIT_EXPECT_EQ(test, TruncToValidBPP(12.01, true, dm_hdmi, dm_420, 0), 12); + KUNIT_EXPECT_EQ(test, TruncToValidBPP(12, true, dm_hdmi, dm_420, 5), 12); + + KUNIT_EXPECT_EQ(test, TruncToValidBPP(11.99, false, dm_hdmi, dm_420, 5), BPP_INVALID); + + /* HDMI output for 4:2:0 encoding */ + KUNIT_EXPECT_EQ(test, TruncToValidBPP(36.01, true, dm_hdmi, dm_444, 0), 36); + KUNIT_EXPECT_EQ(test, TruncToValidBPP(36, true, dm_hdmi, dm_444, 10), 36); + + KUNIT_EXPECT_EQ(test, TruncToValidBPP(30.01, false, dm_hdmi, dm_444, 0), 30); + KUNIT_EXPECT_EQ(test, TruncToValidBPP(30, false, dm_hdmi, dm_444, 8), 30); + + KUNIT_EXPECT_EQ(test, TruncToValidBPP(24.01, true, dm_hdmi, dm_444, 0), 24); + KUNIT_EXPECT_EQ(test, TruncToValidBPP(24, true, dm_hdmi, dm_444, 5), 24); + + KUNIT_EXPECT_EQ(test, TruncToValidBPP(18.01, true, dm_hdmi, dm_444, 0), 18); + KUNIT_EXPECT_EQ(test, TruncToValidBPP(18, true, dm_hdmi, dm_444, 5), 18); + + KUNIT_EXPECT_EQ(test, TruncToValidBPP(17.99, false, dm_hdmi, dm_444, 5), BPP_INVALID); + + /* HDMI output for different encoding types */ + KUNIT_EXPECT_EQ(test, TruncToValidBPP(36.01, true, dm_hdmi, dm_n422, 0), 24); + KUNIT_EXPECT_EQ(test, TruncToValidBPP(36, true, dm_hdmi, dm_s422, 10), 24); + + KUNIT_EXPECT_EQ(test, TruncToValidBPP(30.01, false, dm_hdmi, dm_n422, 0), 20); + KUNIT_EXPECT_EQ(test, TruncToValidBPP(30, false, dm_hdmi, dm_s422, 8), 20); + + KUNIT_EXPECT_EQ(test, TruncToValidBPP(24.01, true, dm_hdmi, dm_n422, 0), 16); + KUNIT_EXPECT_EQ(test, TruncToValidBPP(24, true, dm_hdmi, dm_s422, 5), 16); + + KUNIT_EXPECT_EQ(test, TruncToValidBPP(15.99, false, dm_hdmi, dm_n422, 5), BPP_INVALID); + KUNIT_EXPECT_EQ(test, TruncToValidBPP(-1, true, dm_hdmi, dm_s422, 0), BPP_INVALID); + + /* Display Port output with DSC enabled and 4:2:0 encoding */ + KUNIT_EXPECT_EQ(test, TruncToValidBPP(5.99, true, dm_dp, dm_420, 0), BPP_INVALID); + KUNIT_EXPECT_EQ(test, TruncToValidBPP(-1, true, dm_dp, dm_420, 0), BPP_INVALID); + + KUNIT_EXPECT_EQ(test, TruncToValidBPP(12, true, dm_dp, dm_420, 8), 12); + KUNIT_EXPECT_EQ(test, TruncToValidBPP(1.5 * 8 - 1 / (double)16, true, dm_dp, + dm_420, 8), 11); + + KUNIT_EXPECT_EQ(test, TruncToValidBPP(7, true, dm_dp, dm_420, 3), 4); + KUNIT_EXPECT_EQ(test, TruncToValidBPP(1.5 * 9 - 1 / (double)16, true, dm_dp, + dm_420, 9), 13); + + KUNIT_EXPECT_EQ(test, TruncToValidBPP(6, true, dm_dp, dm_420, 8), 6); + KUNIT_EXPECT_EQ(test, TruncToValidBPP(6.25, true, dm_dp, dm_420, 8), 6); + KUNIT_EXPECT_EQ(test, TruncToValidBPP(6 + 1 / (double)3, true, dm_dp, dm_420, 8), 6); + KUNIT_EXPECT_EQ(test, TruncToValidBPP(6.50, true, dm_dp, dm_420, 8), 6); + KUNIT_EXPECT_EQ(test, TruncToValidBPP(6.75, true, dm_dp, dm_420, 8), 6); + + /* Embedded Display Port output with DSC enabled and n-4:2:2 encoding */ + KUNIT_EXPECT_EQ(test, TruncToValidBPP(6.99, true, dm_edp, dm_n422, 0), BPP_INVALID); + KUNIT_EXPECT_EQ(test, TruncToValidBPP(-1, true, dm_edp, dm_n422, 0), BPP_INVALID); + + KUNIT_EXPECT_EQ(test, TruncToValidBPP(16, true, dm_edp, dm_n422, 7), 14); + KUNIT_EXPECT_EQ(test, TruncToValidBPP(2 * 7 - 1 / (double)16, true, dm_edp, + dm_n422, 7), 13); + + KUNIT_EXPECT_EQ(test, TruncToValidBPP(7, true, dm_edp, dm_n422, 3), 6); + KUNIT_EXPECT_EQ(test, TruncToValidBPP(2 * 9 - 1 / (double)16, true, dm_edp, + dm_n422, 9), 17); + + KUNIT_EXPECT_EQ(test, TruncToValidBPP(11, true, dm_edp, dm_n422, 8), 11); + KUNIT_EXPECT_EQ(test, TruncToValidBPP(11 + 1 / (double)3, true, dm_edp, + dm_n422, 8), 11); + KUNIT_EXPECT_EQ(test, TruncToValidBPP(11.40, true, dm_edp, dm_n422, 8), 11); + KUNIT_EXPECT_EQ(test, TruncToValidBPP(11.50, true, dm_edp, dm_n422, 8), 11); + KUNIT_EXPECT_EQ(test, TruncToValidBPP(11.75, true, dm_edp, dm_n422, 8), 11); + KUNIT_EXPECT_EQ(test, TruncToValidBPP(11.95, true, dm_edp, dm_n422, 8), 11); + + /* Display Port 2.0 output with DSC enabled and 4:4:4 encoding */ + KUNIT_EXPECT_EQ(test, TruncToValidBPP(7.99, true, dm_dp2p0, dm_444, 0), BPP_INVALID); + KUNIT_EXPECT_EQ(test, TruncToValidBPP(-1, true, dm_dp2p0, dm_444, 0), BPP_INVALID); + + KUNIT_EXPECT_EQ(test, TruncToValidBPP(22, true, dm_dp2p0, dm_444, 11), 22); + KUNIT_EXPECT_EQ(test, TruncToValidBPP(3 * 7 - 1 / (double)16, true, dm_dp2p0, + dm_444, 7), 20); + + KUNIT_EXPECT_EQ(test, TruncToValidBPP(14, true, dm_dp2p0, dm_444, 3), 9); + KUNIT_EXPECT_EQ(test, TruncToValidBPP(3 * 9 - 1 / (double)16, true, dm_dp2p0, + dm_444, 9), 26); + + KUNIT_EXPECT_EQ(test, TruncToValidBPP(17, true, dm_dp2p0, dm_444, 7), 17); + KUNIT_EXPECT_EQ(test, TruncToValidBPP(17 + 1 / (double)3, true, dm_dp2p0, dm_444, 7), 17); + KUNIT_EXPECT_EQ(test, TruncToValidBPP(17.40, true, dm_dp2p0, dm_444, 7), 17); + KUNIT_EXPECT_EQ(test, TruncToValidBPP(17.50, true, dm_dp2p0, dm_444, 7), 17); + KUNIT_EXPECT_EQ(test, TruncToValidBPP(17.75, true, dm_dp2p0, dm_444, 7), 17); + KUNIT_EXPECT_EQ(test, TruncToValidBPP(17.95, true, dm_dp2p0, dm_444, 7), 17); + + /* WB output with DSC enabled and 4:2:2 s-encoding */ + KUNIT_EXPECT_EQ(test, TruncToValidBPP(7.99, true, dm_wb, dm_s422, 0), BPP_INVALID); + KUNIT_EXPECT_EQ(test, TruncToValidBPP(-1, true, dm_wb, dm_s422, 0), BPP_INVALID); + + KUNIT_EXPECT_EQ(test, TruncToValidBPP(22, true, dm_wb, dm_s422, 11), 22); + KUNIT_EXPECT_EQ(test, TruncToValidBPP(3 * 7 - 1 / (double)16, true, dm_wb, dm_s422, 7), 20); + + KUNIT_EXPECT_EQ(test, TruncToValidBPP(18, true, dm_wb, dm_s422, 3), 9); + KUNIT_EXPECT_EQ(test, TruncToValidBPP(3 * 9 - 1 / (double)16, true, dm_wb, dm_s422, 9), 26); + + KUNIT_EXPECT_EQ(test, TruncToValidBPP(17, true, dm_wb, dm_s422, 7), 17); + KUNIT_EXPECT_EQ(test, TruncToValidBPP(17 + 1 / (double)3, true, dm_wb, dm_s422, 7), 17); + KUNIT_EXPECT_EQ(test, TruncToValidBPP(17.40, true, dm_wb, dm_s422, 7), 17); + KUNIT_EXPECT_EQ(test, TruncToValidBPP(17.50, true, dm_wb, dm_s422, 7), 17); + KUNIT_EXPECT_EQ(test, TruncToValidBPP(17.75, true, dm_wb, dm_s422, 7), 17); + KUNIT_EXPECT_EQ(test, TruncToValidBPP(17.95, true, dm_wb, dm_s422, 7), 17); + + /* Display Port output with DSC disabled for 4:2:0 encoding */ + KUNIT_EXPECT_EQ(test, TruncToValidBPP(18.01, false, dm_dp, dm_420, 0), 18); + KUNIT_EXPECT_EQ(test, TruncToValidBPP(18, false, dm_dp, dm_420, 10), 18); + + KUNIT_EXPECT_EQ(test, TruncToValidBPP(15.01, false, dm_dp, dm_420, 0), 15); + KUNIT_EXPECT_EQ(test, TruncToValidBPP(15, false, dm_dp, dm_420, 8), 15); + + KUNIT_EXPECT_EQ(test, TruncToValidBPP(12.01, false, dm_dp, dm_420, 0), 12); + KUNIT_EXPECT_EQ(test, TruncToValidBPP(12, false, dm_dp, dm_420, 5), 12); + + KUNIT_EXPECT_EQ(test, TruncToValidBPP(11.99, false, dm_dp, dm_420, 5), BPP_INVALID); + + /* Embedded Display Port output with DSC disabled for 4:2:2 encoding */ + KUNIT_EXPECT_EQ(test, TruncToValidBPP(24.01, false, dm_edp, dm_s422, 0), 24); + KUNIT_EXPECT_EQ(test, TruncToValidBPP(24, false, dm_edp, dm_n422, 10), 24); + + KUNIT_EXPECT_EQ(test, TruncToValidBPP(20.01, false, dm_edp, dm_s422, 0), 20); + KUNIT_EXPECT_EQ(test, TruncToValidBPP(20, false, dm_edp, dm_n422, 8), 20); + + KUNIT_EXPECT_EQ(test, TruncToValidBPP(16.01, false, dm_edp, dm_s422, 0), 16); + KUNIT_EXPECT_EQ(test, TruncToValidBPP(16, false, dm_edp, dm_n422, 5), 16); + + KUNIT_EXPECT_EQ(test, TruncToValidBPP(15.99, false, dm_edp, dm_s422, 5), BPP_INVALID); + KUNIT_EXPECT_EQ(test, TruncToValidBPP(-1, false, dm_edp, dm_n422, 5), BPP_INVALID); + + /* WB output with DSC disabled for 4:4:4 encoding */ + KUNIT_EXPECT_EQ(test, TruncToValidBPP(36.01, false, dm_wb, dm_444, 0), 36); + KUNIT_EXPECT_EQ(test, TruncToValidBPP(36, false, dm_wb, dm_444, 10), 36); + + KUNIT_EXPECT_EQ(test, TruncToValidBPP(30.01, false, dm_wb, dm_444, 0), 30); + KUNIT_EXPECT_EQ(test, TruncToValidBPP(30, false, dm_wb, dm_444, 8), 30); + + KUNIT_EXPECT_EQ(test, TruncToValidBPP(24.01, false, dm_wb, dm_444, 0), 24); + KUNIT_EXPECT_EQ(test, TruncToValidBPP(24, false, dm_wb, dm_444, 5), 24); + + KUNIT_EXPECT_EQ(test, TruncToValidBPP(18.01, false, dm_wb, dm_444, 0), 18); + KUNIT_EXPECT_EQ(test, TruncToValidBPP(18, false, dm_wb, dm_444, 5), 18); + + KUNIT_EXPECT_EQ(test, TruncToValidBPP(17.99, false, dm_wb, dm_444, 5), BPP_INVALID); +} + +static const struct calculate_write_back_delay_test_case calculate_write_back_delay_cases[] = { + { + .desc = "Trivial test", + .writeback_pixel_format = dm_444_32, + .writeback_HRatio = 1.0, + .writeback_VRatio = 1.0, + .writeback_luma_HTaps = 0, + .writeback_luma_VTaps = 0, + .writeback_chroma_HTaps = 0, + .writeback_chroma_VTaps = 0, + .writeback_destination_width = 0, + .calculate_write_back_delay = 0x1p+2, + }, + { + .desc = "High Writeback HRatio and VRatio and zeroed taps", + .writeback_pixel_format = dm_444_32, + .writeback_HRatio = 2400.0, + .writeback_VRatio = 2500.0, + .writeback_luma_HTaps = 0, + .writeback_luma_VTaps = 0, + .writeback_chroma_HTaps = 0, + .writeback_chroma_VTaps = 0, + .writeback_destination_width = 0, + .calculate_write_back_delay = 0x1p+2, + }, + { + .desc = "Simple Writeback Ratio", + .writeback_pixel_format = dm_444_32, + .writeback_HRatio = 1.0, + .writeback_VRatio = 1.0, + .writeback_luma_HTaps = 4, + .writeback_luma_VTaps = 4, + .writeback_chroma_HTaps = 5, + .writeback_chroma_VTaps = 5, + .writeback_destination_width = 2400, + .calculate_write_back_delay = 0x1.2cap+11, + }, + { + .desc = "Non-integer WritebackVRatio with same number of Luma and Chroma taps", + .writeback_pixel_format = dm_444_32, + .writeback_HRatio = 1.0, + .writeback_VRatio = 2567.56, + .writeback_luma_HTaps = 7, + .writeback_luma_VTaps = 7, + .writeback_chroma_HTaps = 7, + .writeback_chroma_VTaps = 7, + .writeback_destination_width = 400, + .calculate_write_back_delay = 0x1.61p+9, + }, + { + .desc = "No Writeback to Chroma Taps", + .writeback_pixel_format = dm_444_32, + .writeback_HRatio = 1.0, + .writeback_VRatio = 1.5, + .writeback_luma_HTaps = 5, + .writeback_luma_VTaps = 5, + .writeback_chroma_HTaps = 0, + .writeback_chroma_VTaps = 0, + .writeback_destination_width = 2400, + .calculate_write_back_delay = 0x1.77cp+11, + }, + { + .desc = "No Writeback to Luma Taps", + .writeback_pixel_format = dm_444_32, + .writeback_HRatio = 2.0, + .writeback_VRatio = 1.5, + .writeback_luma_HTaps = 0, + .writeback_luma_VTaps = 0, + .writeback_chroma_HTaps = 3, + .writeback_chroma_VTaps = 3, + .writeback_destination_width = 3700, + .calculate_write_back_delay = 0x1p+2, + }, + { + .desc = "High Writeback HRatio and VRatio", + .writeback_pixel_format = dm_444_32, + .writeback_HRatio = 2500000.0, + .writeback_VRatio = 2000000.0, + .writeback_luma_HTaps = 4, + .writeback_luma_VTaps = 4, + .writeback_chroma_HTaps = 5, + .writeback_chroma_VTaps = 5, + .writeback_destination_width = 3400, + .calculate_write_back_delay = 0x1.be4cd8p-10, + }, + { + .desc = "Increase numeric error by increasing taps' Writeback", + .writeback_pixel_format = dm_444_32, + .writeback_HRatio = 3000.0, + .writeback_VRatio = 2450.0, + .writeback_luma_HTaps = 100, + .writeback_luma_VTaps = 100, + .writeback_chroma_HTaps = 200, + .writeback_chroma_VTaps = 200, + .writeback_destination_width = 1687, + .calculate_write_back_delay = 0x1.49eap+15, + }, + { + .desc = "Turning point of the Writeback HRatio and VRatio", + .writeback_pixel_format = dm_444_32, + .writeback_HRatio = 100000.0, + .writeback_VRatio = 100000.0, + .writeback_luma_HTaps = 100, + .writeback_luma_VTaps = 100, + .writeback_chroma_HTaps = 200, + .writeback_chroma_VTaps = 200, + .writeback_destination_width = 1687, + .calculate_write_back_delay = 0x1.b06ccap-2, + }, + { + .desc = "Simple Writeback Ratio for 4:4:4 8-bit encoding", + .writeback_pixel_format = dm_444_8, + .writeback_HRatio = 1.0, + .writeback_VRatio = 1.0, + .writeback_luma_HTaps = 4, + .writeback_luma_VTaps = 4, + .writeback_chroma_HTaps = 5, + .writeback_chroma_VTaps = 5, + .writeback_destination_width = 2400, + .calculate_write_back_delay = 0x1.77cp+11, + }, + { + .desc = "Non-integer WritebackVRatio with same number of Luma and Chroma taps for 4:4:4 64-bit encoding", + .writeback_pixel_format = dm_444_64, + .writeback_HRatio = 100000.0, + .writeback_VRatio = 100000.56, + .writeback_luma_HTaps = 7, + .writeback_luma_VTaps = 7, + .writeback_chroma_HTaps = 7, + .writeback_chroma_VTaps = 7, + .writeback_destination_width = 400, + .calculate_write_back_delay = 0x1.ceae7cp-8, + }, + { + .desc = "No Writeback to Chroma Taps for 4:2:0 8-bit encoding", + .writeback_pixel_format = dm_420_8, + .writeback_HRatio = 100000.00, + .writeback_VRatio = 100000.56, + .writeback_luma_HTaps = 8, + .writeback_luma_VTaps = 8, + .writeback_chroma_HTaps = 0, + .writeback_chroma_VTaps = 0, + .writeback_destination_width = 1333, + .calculate_write_back_delay = 0x1.b6c2d6p-6, + }, + { + .desc = "No Writeback to Luma Taps for 4:2:0 10-bit encoding", + .writeback_pixel_format = dm_420_10, + .writeback_HRatio = 200000.0, + .writeback_VRatio = 100000.56, + .writeback_luma_HTaps = 0, + .writeback_luma_VTaps = 0, + .writeback_chroma_HTaps = 3, + .writeback_chroma_VTaps = 3, + .writeback_destination_width = 996, + .calculate_write_back_delay = 0x1.ecd3f6p-9, + }, + { + .desc = "Reduce numeric error by decreasing Writeback HRatio and VRatio for 4:4:4 16-bit encoding", + .writeback_pixel_format = dm_444_16, + .writeback_HRatio = 2.0, + .writeback_VRatio = 1.0, + .writeback_luma_HTaps = 5, + .writeback_luma_VTaps = 5, + .writeback_chroma_HTaps = 5, + .writeback_chroma_VTaps = 5, + .writeback_destination_width = 2400.0, + .calculate_write_back_delay = 0x1.77cp+11, + }, +}; + +static const struct calculate_active_row_bandwidth_test_case calculate_active_row_bandwidth_cases[] = { + { + .desc = "Trivial Test", + .GPUVM_enable = false, + .source_pixel_format = -1, + .VRatio = 0.00, + .DCC_enable = false, + .line_time = 0.00, + .meta_row_byte_luma = 0, + .meta_row_byte_chroma = 0, + .meta_row_height_luma = 0, + .meta_row_height_chroma = 0, + .pixel_PTE_bytes_per_row_luma = 0, + .pixel_PTE_bytes_per_row_chroma = 0, + .dpte_row_height_luma = 0, + .dpte_row_height_chroma = 0, + .meta_row_bw = 0.00, + .dpte_row_bw = 0.00, + .qual_row_bw = 0.00, + }, + { + .desc = "Zeroed Bandwidth with non-zeroed values", + .GPUVM_enable = false, + .source_pixel_format = dm_420_8, + .VRatio = 1000.00, + .DCC_enable = false, + .line_time = 1000.00, + .meta_row_byte_luma = 120, + .meta_row_byte_chroma = 150, + .meta_row_height_luma = 200, + .meta_row_height_chroma = 200, + .pixel_PTE_bytes_per_row_luma = 8, + .pixel_PTE_bytes_per_row_chroma = 8, + .dpte_row_height_luma = 100, + .dpte_row_height_chroma = 100, + .meta_row_bw = 0.00, + .dpte_row_bw = 0.00, + .qual_row_bw = 0.00, + }, + { + .desc = "GPUVM enabled and DCC not enabled with 4:2:0 8-bit encoding", + .GPUVM_enable = true, + .source_pixel_format = dm_420_8, + .VRatio = 1000.00, + .DCC_enable = false, + .line_time = 1000.00, + .meta_row_byte_luma = 120, + .meta_row_byte_chroma = 150, + .meta_row_height_luma = 200, + .meta_row_height_chroma = 200, + .pixel_PTE_bytes_per_row_luma = 8, + .pixel_PTE_bytes_per_row_chroma = 8, + .dpte_row_height_luma = 100, + .dpte_row_height_chroma = 100, + .meta_row_bw = 0x0p+0, + .dpte_row_bw = 0x1.eb851eb851eb8p-4, + .qual_row_bw = 0x1.eb851eb851eb8p-4, + }, + { + .desc = "GPUVM enabled and DCC not enabled with 4:2:0 10-bit encoding", + .GPUVM_enable = true, + .source_pixel_format = dm_420_10, + .VRatio = 1000.00, + .DCC_enable = false, + .line_time = 1000.00, + .meta_row_byte_luma = 120, + .meta_row_byte_chroma = 150, + .meta_row_height_luma = 200, + .meta_row_height_chroma = 200, + .pixel_PTE_bytes_per_row_luma = 9, + .pixel_PTE_bytes_per_row_chroma = 9, + .dpte_row_height_luma = 230, + .dpte_row_height_chroma = 170, + .meta_row_bw = 0x0p+0, + .dpte_row_bw = 0x1.0cb3a88722f67p-4, + .qual_row_bw = 0x1.0cb3a88722f67p-4, + }, + { + .desc = "GPUVM enabled and DCC not enabled with 4:2:0 12-bit encoding", + .GPUVM_enable = true, + .source_pixel_format = dm_420_12, + .VRatio = 100.00, + .DCC_enable = false, + .line_time = 100.00, + .meta_row_byte_luma = 120, + .meta_row_byte_chroma = 150, + .meta_row_height_luma = 200, + .meta_row_height_chroma = 200, + .pixel_PTE_bytes_per_row_luma = 2, + .pixel_PTE_bytes_per_row_chroma = 2, + .dpte_row_height_luma = 10, + .dpte_row_height_chroma = 10, + .meta_row_bw = 0x0p+0, + .dpte_row_bw = 0x1.999999999999ap-3, + .qual_row_bw = 0x0p+0, + }, + { + .desc = "GPUVM enabled and DCC not enabled with 4:4:4 16-bit encoding", + .GPUVM_enable = true, + .source_pixel_format = dm_444_16, + .VRatio = 1000.00, + .DCC_enable = false, + .line_time = 1000.00, + .meta_row_byte_luma = 120, + .meta_row_byte_chroma = 150, + .meta_row_height_luma = 200, + .meta_row_height_chroma = 200, + .pixel_PTE_bytes_per_row_luma = 9, + .pixel_PTE_bytes_per_row_chroma = 9, + .dpte_row_height_luma = 230, + .dpte_row_height_chroma = 170, + .meta_row_bw = 0x0p+0, + .dpte_row_bw = 0x1.408e78356d141p-5, + .qual_row_bw = 0x0p+0, + }, + { + .desc = "GPUVM not enabled and DCC enabled with 4:2:0 8-bit encoding", + .GPUVM_enable = false, + .source_pixel_format = dm_420_8, + .VRatio = 1000.00, + .DCC_enable = true, + .line_time = 1000.00, + .meta_row_byte_luma = 120, + .meta_row_byte_chroma = 150, + .meta_row_height_luma = 200, + .meta_row_height_chroma = 200, + .pixel_PTE_bytes_per_row_luma = 8, + .pixel_PTE_bytes_per_row_chroma = 8, + .dpte_row_height_luma = 100, + .dpte_row_height_chroma = 100, + .meta_row_bw = 0x1.f333333333333p-1, + .dpte_row_bw = 0x0p+0, + .qual_row_bw = 0x1.f333333333333p-1, + }, + { + .desc = "GPUVM not enabled and DCC enabled with 4:2:0 10-bit encoding", + .GPUVM_enable = false, + .source_pixel_format = dm_420_10, + .VRatio = 700.00, + .DCC_enable = true, + .line_time = 1300.00, + .meta_row_byte_luma = 170, + .meta_row_byte_chroma = 350, + .meta_row_height_luma = 300, + .meta_row_height_chroma = 280, + .pixel_PTE_bytes_per_row_luma = 8, + .pixel_PTE_bytes_per_row_chroma = 8, + .dpte_row_height_luma = 100, + .dpte_row_height_chroma = 100, + .meta_row_bw = 0x1.4888888888889p-1, + .dpte_row_bw = 0x0p+0, + .qual_row_bw = 0x1.4888888888889p-1, + }, + { + .desc = "GPUVM not enabled and DCC enabled with 4:2:2 8-bit encoding", + .GPUVM_enable = false, + .source_pixel_format = dm_422_8, + .VRatio = 700.00, + .DCC_enable = true, + .line_time = 1300.00, + .meta_row_byte_luma = 170, + .meta_row_byte_chroma = 350, + .meta_row_height_luma = 300, + .meta_row_height_chroma = 280, + .pixel_PTE_bytes_per_row_luma = 8, + .pixel_PTE_bytes_per_row_chroma = 8, + .dpte_row_height_luma = 100, + .dpte_row_height_chroma = 100, + .meta_row_bw = 0x1.3873873873874p-2, + .dpte_row_bw = 0x0p+0, + .qual_row_bw = 0x0p+0, + }, + { + .desc = "GPUVM not enabled and DCC enabled with 4:4:4 8-bit encoding", + .GPUVM_enable = false, + .source_pixel_format = dm_444_8, + .VRatio = 1000.00, + .DCC_enable = true, + .line_time = 2000.00, + .meta_row_byte_luma = 190, + .meta_row_byte_chroma = 333, + .meta_row_height_luma = 200, + .meta_row_height_chroma = 210, + .pixel_PTE_bytes_per_row_luma = 9, + .pixel_PTE_bytes_per_row_chroma = 9, + .dpte_row_height_luma = 230, + .dpte_row_height_chroma = 170, + .meta_row_bw = 0x1.e666666666666p-2, + .dpte_row_bw = 0x0p+0, + .qual_row_bw = 0x0p+0, + }, + { + .desc = "GPUVM enabled and DCC enabled with 4:2:0 8-bit encoding", + .GPUVM_enable = true, + .source_pixel_format = dm_420_8, + .VRatio = 1000.00, + .DCC_enable = true, + .line_time = 2000.00, + .meta_row_byte_luma = 120, + .meta_row_byte_chroma = 150, + .meta_row_height_luma = 200, + .meta_row_height_chroma = 200, + .pixel_PTE_bytes_per_row_luma = 8, + .pixel_PTE_bytes_per_row_chroma = 8, + .dpte_row_height_luma = 100, + .dpte_row_height_chroma = 100, + .meta_row_bw = 0x1.f333333333333p-2, + .dpte_row_bw = 0x1.eb851eb851eb8p-5, + .qual_row_bw = 0x1.1851eb851eb85p-1, + }, + { + .desc = "GPUVM enabled and DCC enabled with 4:2:0 10-bit encoding", + .GPUVM_enable = true, + .source_pixel_format = dm_420_10, + .VRatio = 7000.00, + .DCC_enable = true, + .line_time = 1300.00, + .meta_row_byte_luma = 170, + .meta_row_byte_chroma = 350, + .meta_row_height_luma = 300, + .meta_row_height_chroma = 280, + .pixel_PTE_bytes_per_row_luma = 8, + .pixel_PTE_bytes_per_row_chroma = 8, + .dpte_row_height_luma = 100, + .dpte_row_height_chroma = 100, + .meta_row_bw = 0x1.9aaaaaaaaaaaap+2, + .dpte_row_bw = 0x1.4ad4ad4ad4ad5p-1, + .qual_row_bw = 0x1.c405405405405p+2, + }, + { + .desc = "GPUVM enabled and DCC enabled with 4:4:4 16-bit encoding", + .GPUVM_enable = true, + .source_pixel_format = dm_444_16, + .VRatio = 700.00, + .DCC_enable = true, + .line_time = 1300.00, + .meta_row_byte_luma = 70, + .meta_row_byte_chroma = 550, + .meta_row_height_luma = 310, + .meta_row_height_chroma = 280, + .pixel_PTE_bytes_per_row_luma = 7, + .pixel_PTE_bytes_per_row_chroma = 7, + .dpte_row_height_luma = 190, + .dpte_row_height_chroma = 340, + .meta_row_bw = 0x1.f2065a3416de5p-4, + .dpte_row_bw = 0x1.4506d72a14507p-6, + .qual_row_bw = 0x0p+0, + }, + { + .desc = "GPUVM enabled and DCC enabled with 4:4:4 32-bit encoding", + .GPUVM_enable = true, + .source_pixel_format = dm_444_32, + .VRatio = 700.00, + .DCC_enable = true, + .line_time = 1300.00, + .meta_row_byte_luma = 170, + .meta_row_byte_chroma = 350, + .meta_row_height_luma = 300, + .meta_row_height_chroma = 280, + .pixel_PTE_bytes_per_row_luma = 8, + .pixel_PTE_bytes_per_row_chroma = 8, + .dpte_row_height_luma = 100, + .dpte_row_height_chroma = 100, + .meta_row_bw = 0x1.3873873873874p-2, + .dpte_row_bw = 0x1.60e2dafa7c749p-5, + .qual_row_bw = 0x0p+0, + }, +}; + +static void calculate_write_back_delay_test_to_desc(const struct + calculate_write_back_delay_test_case * t, char *desc) +{ + strcpy(desc, t->desc); +} + +KUNIT_ARRAY_PARAM(calculate_write_back_delay, calculate_write_back_delay_cases, + calculate_write_back_delay_test_to_desc); + +static void calculate_active_row_bandwidth_test_to_desc(const struct + calculate_active_row_bandwidth_test_case * t, char *desc) +{ + strcpy(desc, t->desc); +} + +KUNIT_ARRAY_PARAM(calculate_active_row_bandwidth, calculate_active_row_bandwidth_cases, + calculate_active_row_bandwidth_test_to_desc); + +static struct kunit_case display_mode_vba_20_cases[] = { + KUNIT_CASE(dscce_compute_delay_test), + KUNIT_CASE(DSC_compute_delay_test), + KUNIT_CASE(calculate_TWait_test), + KUNIT_CASE_PARAM(calculate_write_back_delay_test, calculate_write_back_delay_gen_params), + KUNIT_CASE_PARAM(calculate_active_row_bandwidth_test, + calculate_active_row_bandwidth_gen_params), + KUNIT_CASE(trunc_to_valid_BPP_test), + { } +}; + +static struct kunit_suite display_mode_vba_20_suite = { + .name = "display_mode_vba_20", + .test_cases = display_mode_vba_20_cases, +}; + +kunit_test_suite(display_mode_vba_20_suite); From patchwork Fri Jan 26 15:48:06 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: Rodrigo Siqueira Jordao X-Patchwork-Id: 13532859 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from gabe.freedesktop.org (gabe.freedesktop.org [131.252.210.177]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.lore.kernel.org (Postfix) with ESMTPS id E432AC47422 for ; Fri, 26 Jan 2024 15:52:06 +0000 (UTC) Received: from gabe.freedesktop.org (localhost [127.0.0.1]) by gabe.freedesktop.org (Postfix) with ESMTP id 96B5110FBD1; Fri, 26 Jan 2024 15:51:55 +0000 (UTC) Received: from NAM12-BN8-obe.outbound.protection.outlook.com (mail-bn8nam12on2052.outbound.protection.outlook.com [40.107.237.52]) by gabe.freedesktop.org (Postfix) with ESMTPS id A460210FBCF; Fri, 26 Jan 2024 15:51:41 +0000 (UTC) ARC-Seal: i=1; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=none; b=kifs67r8Fn+Buuw370hrQ0vp9wtAT/tWNjwxtnuG7+GUGbo2gN4t0rUQkjlKB8CIGSKYsX7BhJdQjsfCq8XkhUTOzfJFOY/Sg+lULmwWGuAwsBRFXVeUZCqP7BoorArI+tILqMb9t2vcf34AG1kAZ6qRXt0BA3P5QVvTWVoKR3IL1iqCmGlKgOdjhAMvG7HXwKyXomegDZ7kPT73mZ6fQE5SZBWAEPx45usq6nXzY0RundLILcVx0V6Qyxkd7qxfsY0scaWhw/wecpzw1gOqiA9xm/Oat5mgNRUWXYhQlqKZCsJqq9Be9j+z6iEjM8dgH3OVylOMPn/9USB46TPLoQ== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=microsoft.com; s=arcselector9901; h=From:Date:Subject:Message-ID:Content-Type:MIME-Version:X-MS-Exchange-AntiSpam-MessageData-ChunkCount:X-MS-Exchange-AntiSpam-MessageData-0:X-MS-Exchange-AntiSpam-MessageData-1; bh=FK4M+PwvBidx5CFED5WYjetAQS5TrwEOkenqwr6IKCg=; b=h+fvRjvewlm4ZpjPQmNipkrNzyYbGGY1BBN36y760A4cQAPX7YvGOd63RKz+ecr+g5n6RcGo4+G4gG51hnkm14WEkOaNlxeZ3YVCLWiWqJgBgNdsC83Us1o5HuEKF/6mlCXqWc/6V4pVaCRtpHG1zPB+Iz0Kn9S2+ZXgUn/AgB+fUqbK8xoMo/jhbktE2fjy2ra+qanZzyHpFTWo0f2+ggZOUN1ybHnWFfYiUzUxxDNyg4hNn4xqCLR6ZDJSpFS60n6CDZVwoyRzfeLTf0lQ0W20VS6GYRMfh9l4FIA/dGh422G9lmqJO+5AP+0UP1nd1Yg81US8X6/WKtcqO5Z2AQ== ARC-Authentication-Results: i=1; mx.microsoft.com 1; spf=pass (sender ip is 165.204.84.17) smtp.rcpttodomain=linux.ie smtp.mailfrom=amd.com; dmarc=pass (p=quarantine sp=quarantine pct=100) action=none header.from=amd.com; dkim=none (message not signed); arc=none (0) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=amd.com; s=selector1; h=From:Date:Subject:Message-ID:Content-Type:MIME-Version:X-MS-Exchange-SenderADCheck; bh=FK4M+PwvBidx5CFED5WYjetAQS5TrwEOkenqwr6IKCg=; b=u0rdC0l56HSdWE35eIVoZnRZVfttmjHWhzMvN6RKc2VErWaipF9HBHhip8QqfiSOrDeMNzKfCl7OogveqHEN+GEk4KM2MWXF9G6NWWabN69Y44ieEoXalzKHWIiFfopx4BVbCINHUmAzLomyoeNqoeG0f/web+fS0cVwyZkgf2s= Received: from SJ0PR13CA0166.namprd13.prod.outlook.com (2603:10b6:a03:2c7::21) by SA1PR12MB7319.namprd12.prod.outlook.com (2603:10b6:806:2b5::19) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.7228.26; Fri, 26 Jan 2024 15:51:37 +0000 Received: from SJ1PEPF00001CE3.namprd05.prod.outlook.com (2603:10b6:a03:2c7:cafe::8a) by SJ0PR13CA0166.outlook.office365.com (2603:10b6:a03:2c7::21) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.7228.21 via Frontend Transport; Fri, 26 Jan 2024 15:51:36 +0000 X-MS-Exchange-Authentication-Results: spf=pass (sender IP is 165.204.84.17) smtp.mailfrom=amd.com; dkim=none (message not signed) header.d=none;dmarc=pass action=none header.from=amd.com; Received-SPF: Pass (protection.outlook.com: domain of amd.com designates 165.204.84.17 as permitted sender) receiver=protection.outlook.com; client-ip=165.204.84.17; helo=SATLEXMB04.amd.com; pr=C Received: from SATLEXMB04.amd.com (165.204.84.17) by SJ1PEPF00001CE3.mail.protection.outlook.com (10.167.242.11) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256) id 15.20.7202.16 via Frontend Transport; Fri, 26 Jan 2024 15:51:36 +0000 Received: from smtp.xilinx.com (10.180.168.240) by SATLEXMB04.amd.com (10.181.40.145) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256) id 15.1.2507.34; Fri, 26 Jan 2024 09:51:32 -0600 From: Rodrigo Siqueira To: Alex Deucher , , , David Airlie , Daniel Vetter , Maarten Lankhorst , Maxime Ripard , Thomas Zimmermann , Harry Wentland , Leo Li , "Rodrigo Siqueira" , Nicholas Choi , Daniel Latypov , David Gow , , Subject: [PATCH v4 6/8] drm/amd/display: Introduce KUnit tests for dcn20_fpu Date: Fri, 26 Jan 2024 08:48:06 -0700 Message-ID: <20240126155022.1184856-7-Rodrigo.Siqueira@amd.com> X-Mailer: git-send-email 2.43.0 In-Reply-To: <20240126155022.1184856-1-Rodrigo.Siqueira@amd.com> References: <20240126155022.1184856-1-Rodrigo.Siqueira@amd.com> MIME-Version: 1.0 X-Originating-IP: [10.180.168.240] X-ClientProxiedBy: SATLEXMB04.amd.com (10.181.40.145) To SATLEXMB04.amd.com (10.181.40.145) X-EOPAttributedMessage: 0 X-MS-PublicTrafficType: Email X-MS-TrafficTypeDiagnostic: SJ1PEPF00001CE3:EE_|SA1PR12MB7319:EE_ X-MS-Office365-Filtering-Correlation-Id: 2258eada-f18b-4ed5-b11e-08dc1e86adb4 X-MS-Exchange-SenderADCheck: 1 X-MS-Exchange-AntiSpam-Relay: 0 X-Microsoft-Antispam: BCL:0; X-Microsoft-Antispam-Message-Info: 4BsWX/q0gOLYXB5o9JoGVKiUwf3jyOnYtrZW4GTCVOel6iIsZf5ygV21rKGKcLxmf9XODy/up0xlxwQ8EGKLVeS+2neuKC3tPSvJtE2g0b7PvHtIYZ5iKlhw+gYS3WQeKyXnCXdwRVHAzbZmNXq0rFWltsX9azXcGkhkruVDd0Pep4XWfINzAyfU5+PTflfxjXODuLmDVj9BBTNpK0cWMee5kJ6e3+pZj3JsTDpcpDHv3QOuRo7qa4WjTpoOl4fuHNwrIsW8RSoMYImrWYJLdQVGifEMy7c+yfL+GdYcX66f14Vs9OITVS0+OYE+z2BaRED5x0gKhqpWBDlf1NR7qKF4dnCdQ+d3crCKyXXc4lbkrZCvLvIo18KsfcoV1ucnsx5gQP+b8By7PHAJl+8L8iQ5te8Lb7arG4n6jgsxODN77TpaZmPrm2lcwZAe6vN6zzi8RDIvkBen4aIvr/Wph8xOMybHseU2KwKclOl+QHScKOiNw/C5byQosGi3WX0bcDcNFoJ0JMlPTLHccDl4RlpzgUshGUXpTpOHEA8nPmPiAFAThqiX4YGMg1aFDMfUWnTEsh38bJaJS4I9ZGYQ1Ds6J78yUGzUX6rvWgaT5LGxAC9pZaUY4zWhlKWUe733lf3B3HCT+b2Eox/nQofcfagJHWXkCi8kGK45envfTOkSdmmbEbMtV1/KyDKdXSi7J1KfIVRdnE2GLb1p9avON6hp3tmkVfQD1fnwmIWOO9iMnSyEU+ynnbbCY+YHVKuWwO6gAZ4UI8KuFe62HuL1Fs/kSw+Vm6XWI4Og3sMFlBk= X-Forefront-Antispam-Report: CIP:165.204.84.17; CTRY:US; LANG:en; SCL:1; SRV:; IPV:CAL; SFV:NSPM; H:SATLEXMB04.amd.com; PTR:InfoDomainNonexistent; CAT:NONE; SFS:(13230031)(4636009)(396003)(39860400002)(376002)(136003)(346002)(230922051799003)(1800799012)(186009)(451199024)(82310400011)(64100799003)(46966006)(40470700004)(36840700001)(40460700003)(40480700001)(41300700001)(83380400001)(36756003)(921011)(86362001)(36860700001)(81166007)(2616005)(30864003)(16526019)(26005)(1076003)(426003)(66574015)(336012)(4326008)(82740400003)(356005)(110136005)(478600001)(2906002)(8936002)(316002)(70206006)(6666004)(70586007)(54906003)(47076005)(5660300002)(7416002)(8676002)(36900700001); DIR:OUT; SFP:1101; X-OriginatorOrg: amd.com X-MS-Exchange-CrossTenant-OriginalArrivalTime: 26 Jan 2024 15:51:36.5393 (UTC) X-MS-Exchange-CrossTenant-Network-Message-Id: 2258eada-f18b-4ed5-b11e-08dc1e86adb4 X-MS-Exchange-CrossTenant-Id: 3dd8961f-e488-4e60-8e11-a82d994e183d X-MS-Exchange-CrossTenant-OriginalAttributedTenantConnectingIp: TenantId=3dd8961f-e488-4e60-8e11-a82d994e183d; Ip=[165.204.84.17]; Helo=[SATLEXMB04.amd.com] X-MS-Exchange-CrossTenant-AuthSource: SJ1PEPF00001CE3.namprd05.prod.outlook.com X-MS-Exchange-CrossTenant-AuthAs: Anonymous X-MS-Exchange-CrossTenant-FromEntityHeader: HybridOnPrem X-MS-Exchange-Transport-CrossTenantHeadersStamped: SA1PR12MB7319 X-BeenThere: dri-devel@lists.freedesktop.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: Direct Rendering Infrastructure - Development List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: tales.aparecida@gmail.com, Trevor Woerner , javierm@redhat.com, dri-devel@lists.freedesktop.org, mwen@igalia.com, =?utf-8?q?Ma=C3=ADra_Canal?= , amd-gfx@lists.freedesktop.org, Isabella Basso , andrealmeid@riseup.net, kunit-dev@googlegroups.com Errors-To: dri-devel-bounces@lists.freedesktop.org Sender: "dri-devel" From: Magali Lemes This commit adds unit tests to the functions dcn20_cap_soc_clocks and dcn21_update_bw_bounding_box from dcn20/dcn20_fpu. Signed-off-by: Magali Lemes Signed-off-by: Maíra Canal --- drivers/gpu/drm/amd/display/tests/Makefile | 3 +- .../tests/dc/dml/dcn20/dcn20_fpu_test.c | 561 ++++++++++++++++++ 2 files changed, 563 insertions(+), 1 deletion(-) create mode 100644 drivers/gpu/drm/amd/display/tests/dc/dml/dcn20/dcn20_fpu_test.c diff --git a/drivers/gpu/drm/amd/display/tests/Makefile b/drivers/gpu/drm/amd/display/tests/Makefile index cc1e9edd38c3..a34677808e48 100644 --- a/drivers/gpu/drm/amd/display/tests/Makefile +++ b/drivers/gpu/drm/amd/display/tests/Makefile @@ -9,7 +9,8 @@ endif ifdef CONFIG_DML_KUNIT_TEST CFLAGS_$(AMDDALPATH)/tests/dc/dml/display_mode_vba_test.o := $(dml_ccflags) - DC_TESTS += dc/dml/display_mode_vba_test.o + CFLAGS_$(AMDDALPATH)/tests/dc/dml/dcn20/dcn20_fpu_test.o := $(dml_ccflags) + DC_TESTS += dc/dml/display_mode_vba_test.o dc/dml/dcn20/dcn20_fpu_test.o endif AMD_DAL_DC_TESTS = $(addprefix $(AMDDALPATH)/tests/,$(DC_TESTS)) diff --git a/drivers/gpu/drm/amd/display/tests/dc/dml/dcn20/dcn20_fpu_test.c b/drivers/gpu/drm/amd/display/tests/dc/dml/dcn20/dcn20_fpu_test.c new file mode 100644 index 000000000000..6b7ebb78fec9 --- /dev/null +++ b/drivers/gpu/drm/amd/display/tests/dc/dml/dcn20/dcn20_fpu_test.c @@ -0,0 +1,561 @@ +// SPDX-License-Identifier: MIT +/* + * KUnit tests for dml/dcn20/dcn20_fpu.h + * + * Copyright (C) 2022, Magali Lemes + */ + +#include + +#include "dc/inc/resource.h" +#include "dc/inc/hw/clk_mgr.h" +#include "dc/dcn21/dcn21_resource.h" + +#include "dml/dcn20/dcn20_fpu.h" + +/** + * DOC: Unit tests for AMDGPU DML dcn20/dcn20_fpu.h + */ + +struct dcn20_cap_soc_clocks_test_case { + const char *desc; + struct _vcs_dpi_soc_bounding_box_st bb; + struct pp_smu_nv_clock_table max_clocks; + const int clock_states; + const struct _vcs_dpi_voltage_scaling_st expected_clock_limits[DC__VOLTAGE_STATES]; +}; + +struct dcn21_update_bw_bounding_box_test_case { + const char *desc; + struct dc dc; + struct clk_bw_params bw_params; + const int clocks_to_compare; + const struct _vcs_dpi_voltage_scaling_st expected_clock_limits[DC__VOLTAGE_STATES]; +}; + +struct dcn20_cap_soc_clocks_test_case dcn20_cap_soc_clocks_test_cases[] = { + { + .desc = "4-state bounding box clock limits ", + .bb = { + .clock_limits = { + { + .dcfclk_mhz = 506.0, + .fabricclk_mhz = 506.0, + .dispclk_mhz = 1284.0, + .dppclk_mhz = 400.0, + .phyclk_mhz = 810.0, + .socclk_mhz = 506.0, + .dscclk_mhz = 428.0, + .dram_speed_mts = 1600.0, + }, + { + .dcfclk_mhz = 540.0, + .fabricclk_mhz = 540.0, + .dispclk_mhz = 1284.0, + .dppclk_mhz = 1284.0, + .phyclk_mhz = 810.0, + .socclk_mhz = 540.0, + .dscclk_mhz = 428.0, + .dram_speed_mts = 8000.0, + }, + { + .dcfclk_mhz = 675.0, + .fabricclk_mhz = 675.0, + .dispclk_mhz = 1284.0, + .dppclk_mhz = 1284.0, + .phyclk_mhz = 810.0, + .socclk_mhz = 675.0, + .dscclk_mhz = 428.0, + .dram_speed_mts = 10000.0, + }, + { + .dcfclk_mhz = 1265.0, + .fabricclk_mhz = 1266.0, + .dispclk_mhz = 1284.0, + .dppclk_mhz = 1284.0, + .phyclk_mhz = 810.0, + .socclk_mhz = 1266.0, + .dscclk_mhz = 428.0, + .dram_speed_mts = 15000.0, + }, + }, + .num_states = 4, + }, + .max_clocks = { + .dcfClockInKhz = 1265000, + .uClockInKhz = 875000, + .fabricClockInKhz = 0, + .displayClockInKhz = 1284000, + .dppClockInKhz = 0, + .phyClockInKhz = 810000, + .socClockInKhz = 1266000, + .dscClockInKhz = 0, + }, + .clock_states = 4, + .expected_clock_limits = { + { + .dcfclk_mhz = 506.0, + .fabricclk_mhz = 506.0, + .dispclk_mhz = 1284.0, + .dppclk_mhz = 400.0, + .phyclk_mhz = 810.0, + .socclk_mhz = 506.0, + .dscclk_mhz = 428.0, + .dram_speed_mts = 1600.0, + }, + { + .dcfclk_mhz = 540.0, + .fabricclk_mhz = 540.0, + .dispclk_mhz = 1284.0, + .dppclk_mhz = 1284.0, + .phyclk_mhz = 810.0, + .socclk_mhz = 540.0, + .dscclk_mhz = 428.0, + .dram_speed_mts = 8000.0, + }, + { + .dcfclk_mhz = 675.0, + .fabricclk_mhz = 675.0, + .dispclk_mhz = 1284.0, + .dppclk_mhz = 1284.0, + .phyclk_mhz = 810.0, + .socclk_mhz = 675.0, + .dscclk_mhz = 428.0, + .dram_speed_mts = 10000.0, + }, + { + .dcfclk_mhz = 1265.0, + .fabricclk_mhz = 1266.0, + .dispclk_mhz = 1284.0, + .dppclk_mhz = 1284.0, + .phyclk_mhz = 810.0, + .socclk_mhz = 1266.0, + .dscclk_mhz = 428.0, + .dram_speed_mts = 14000.0, + }, + }, + }, + { + .desc = "One duplicate clock state", + .bb = { + .clock_limits = { + { + .dcfclk_mhz = 506.0, + .fabricclk_mhz = 506.0, + .dispclk_mhz = 1284.0, + .dppclk_mhz = 400.0, + .phyclk_mhz = 810.0, + .socclk_mhz = 506.0, + .dscclk_mhz = 428.0, + .dram_speed_mts = 1600.0, + }, + { + .dcfclk_mhz = 675.0, + .fabricclk_mhz = 675.0, + .dispclk_mhz = 1284.0, + .dppclk_mhz = 1284.0, + .phyclk_mhz = 810.0, + .socclk_mhz = 675.0, + .dscclk_mhz = 428.0, + .dram_speed_mts = 10000.0, + }, + { + .dcfclk_mhz = 675.0, + .fabricclk_mhz = 675.0, + .dispclk_mhz = 1284.0, + .dppclk_mhz = 1284.0, + .phyclk_mhz = 810.0, + .socclk_mhz = 675.0, + .dscclk_mhz = 428.0, + .dram_speed_mts = 10000.0, + }, + { + .dcfclk_mhz = 1265.0, + .fabricclk_mhz = 1266.0, + .dispclk_mhz = 1284.0, + .dppclk_mhz = 1284.0, + .phyclk_mhz = 810.0, + .socclk_mhz = 1266.0, + .dscclk_mhz = 428.0, + .dram_speed_mts = 15000.0, + }, + }, + .num_states = 4, + }, + .max_clocks = { + .dcfClockInKhz = 1265000, + .uClockInKhz = 875000, + .fabricClockInKhz = 0, + .displayClockInKhz = 1284000, + .dppClockInKhz = 0, + .phyClockInKhz = 810000, + .socClockInKhz = 1266000, + .dscClockInKhz = 0, + }, + .clock_states = 3, + .expected_clock_limits = { + { + .dcfclk_mhz = 506.0, + .fabricclk_mhz = 506.0, + .dispclk_mhz = 1284.0, + .dppclk_mhz = 400.0, + .phyclk_mhz = 810.0, + .socclk_mhz = 506.0, + .dscclk_mhz = 428.0, + .dram_speed_mts = 1600.0, + }, + { + .dcfclk_mhz = 675.0, + .fabricclk_mhz = 675.0, + .dispclk_mhz = 1284.0, + .dppclk_mhz = 1284.0, + .phyclk_mhz = 810.0, + .socclk_mhz = 675.0, + .dscclk_mhz = 428.0, + .dram_speed_mts = 10000.0, + }, + { + .dcfclk_mhz = 675.0, + .fabricclk_mhz = 675.0, + .dispclk_mhz = 1284.0, + .dppclk_mhz = 1284.0, + .phyclk_mhz = 810.0, + .socclk_mhz = 675.0, + .dscclk_mhz = 428.0, + .dram_speed_mts = 10000.0, + }, + }, + }, + { + .desc = "Zeroed max clocks", + .bb = { + .clock_limits = { + { + .dcfclk_mhz = 506.0, + .fabricclk_mhz = 506.0, + .dispclk_mhz = 1284.0, + .dppclk_mhz = 400.0, + .phyclk_mhz = 810.0, + .socclk_mhz = 506.0, + .dscclk_mhz = 428.0, + .dram_speed_mts = 1600.0, + }, + }, + .num_states = 1, + }, + .max_clocks = { + .dcfClockInKhz = 0, + .uClockInKhz = 0, + .fabricClockInKhz = 0, + .displayClockInKhz = 0, + .dppClockInKhz = 0, + .phyClockInKhz = 0, + .socClockInKhz = 0, + .dscClockInKhz = 0, + }, + .clock_states = 1, + .expected_clock_limits = { + { + .dcfclk_mhz = 506.0, + .fabricclk_mhz = 506.0, + .dispclk_mhz = 1284.0, + .dppclk_mhz = 400.0, + .phyclk_mhz = 810.0, + .socclk_mhz = 506.0, + .dscclk_mhz = 428.0, + .dram_speed_mts = 1600.0, + }, + }, + }, +}; + +struct dcn21_update_bw_bounding_box_test_case dcn21_update_bw_bounding_box_test_data[] = { + { + .desc = "5-entry bounding box clocks table", + .dc = { + .res_pool = &(struct resource_pool) { + .pipe_count = 2, + .res_cap = &(struct resource_caps) { + .num_timing_generator = 3 + }, + }, + }, + .bw_params = { + .num_channels = 1, + .clk_table = { + .entries = { + { + .voltage = 0, + .dcfclk_mhz = 200, + .fclk_mhz = 400, + .memclk_mhz = 800, + .socclk_mhz = 0, + }, + { + .voltage = 0, + .dcfclk_mhz = 201, + .fclk_mhz = 800, + .memclk_mhz = 1600, + .socclk_mhz = 0, + }, + { + .voltage = 0, + .dcfclk_mhz = 553, + .fclk_mhz = 1067, + .memclk_mhz = 1067, + .socclk_mhz = 0, + }, + { + .voltage = 0, + .dcfclk_mhz = 602, + .fclk_mhz = 1333, + .memclk_mhz = 1600, + .socclk_mhz = 0, + }, + { + .voltage = 0, + .dispclk_mhz = 1372, + .dppclk_mhz = 1372, + .phyclk_mhz = 810, + .phyclk_d18_mhz = 667, + .dtbclk_mhz = 600, + }, + }, + + .num_entries = 5, + }, + }, + .expected_clock_limits = { + { + .state = 0, + .dcfclk_mhz = 200.0, + .fabricclk_mhz = 400.0, + .dispclk_mhz = 600.0, + .dppclk_mhz = 400.0, + .phyclk_mhz = 600.0, + .socclk_mhz = 0.0, + .dscclk_mhz = 205.67, + .dram_speed_mts = 1600.0, + }, + { + .state = 1, + .dcfclk_mhz = 200.0, + .fabricclk_mhz = 400.0, + .dispclk_mhz = 600.0, + .dppclk_mhz = 400.0, + .phyclk_mhz = 600.0, + .socclk_mhz = 0.0, + .dscclk_mhz = 205.67, + .dram_speed_mts = 1600.0, + }, + { + .state = 2, + .dcfclk_mhz = 201, + .fabricclk_mhz = 800.0, + .dispclk_mhz = 600.0, + .dppclk_mhz = 400.0, + .phyclk_mhz = 600.0, + .socclk_mhz = 0.0, + .dscclk_mhz = 205.67, + .dram_speed_mts = 3200.0, + }, + { + .state = 3, + .dcfclk_mhz = 553.0, + .fabricclk_mhz = 1067.0, + .dispclk_mhz = 757.89, + .dppclk_mhz = 685.71, + .phyclk_mhz = 600.0, + .socclk_mhz = 0.0, + .dscclk_mhz = 287.67, + .dram_speed_mts = 2134.0, + }, + { + .state = 4, + .dcfclk_mhz = 602.0, + .fabricclk_mhz = 1333.0, + .dispclk_mhz = 847.06, + .dppclk_mhz = 757.89, + .phyclk_mhz = 600.0, + .socclk_mhz = 0.0, + .dscclk_mhz = 318.334, + .dram_speed_mts = 3200.0, + }, + { + .state = 5, + .dcfclk_mhz = 0.0, + .fabricclk_mhz = 0.0, + .dispclk_mhz = 600.0, + .dppclk_mhz = 400.0, + .phyclk_mhz = 600.0, + .socclk_mhz = 0.0, + .dscclk_mhz = 205.67, + .dram_speed_mts = 0.0, + }, + { + .state = 6, + .dcfclk_mhz = 0.0, + .fabricclk_mhz = 0.0, + .dispclk_mhz = 600.0, + .dppclk_mhz = 400.0, + .phyclk_mhz = 600.0, + .socclk_mhz = 0.0, + .dscclk_mhz = 205.67, + .dram_speed_mts = 0.0, + }, + }, + .clocks_to_compare = 6, + }, +}; + +/** + * dcn20_cap_soc_clocks_test - KUnit test for dcn20_cap_soc_clocks + * @test: represents a running instance of a test. + */ +static void dcn20_cap_soc_clocks_test(struct kunit *test) +{ + struct dcn20_cap_soc_clocks_test_case *test_param = + (struct dcn20_cap_soc_clocks_test_case *)test->param_value; + int i; + + DC_FP_START(); + dcn20_cap_soc_clocks(&test_param->bb, test_param->max_clocks); + DC_FP_END(); + + /* Check if no clock limit is higher than the specified maximum */ + for (i = 0; i < test_param->bb.num_states; i++) { + KUNIT_EXPECT_EQ(test, test_param->bb.clock_limits[i].dcfclk_mhz, + test_param->expected_clock_limits[i].dcfclk_mhz); + KUNIT_EXPECT_EQ(test, test_param->bb.clock_limits[i].fabricclk_mhz, + test_param->expected_clock_limits[i].fabricclk_mhz); + KUNIT_EXPECT_EQ(test, test_param->bb.clock_limits[i].dispclk_mhz, + test_param->expected_clock_limits[i].dispclk_mhz); + KUNIT_EXPECT_EQ(test, test_param->bb.clock_limits[i].dppclk_mhz, + test_param->expected_clock_limits[i].dppclk_mhz); + KUNIT_EXPECT_EQ(test, test_param->bb.clock_limits[i].phyclk_mhz, + test_param->expected_clock_limits[i].phyclk_mhz); + KUNIT_EXPECT_EQ(test, test_param->bb.clock_limits[i].socclk_mhz, + test_param->expected_clock_limits[i].socclk_mhz); + KUNIT_EXPECT_EQ(test, test_param->bb.clock_limits[i].dscclk_mhz, + test_param->expected_clock_limits[i].dscclk_mhz); + KUNIT_EXPECT_EQ(test, test_param->bb.clock_limits[i].dram_speed_mts, + test_param->expected_clock_limits[i].dram_speed_mts); + } + + KUNIT_EXPECT_EQ(test, test_param->clock_states, test_param->bb.num_states); +} + +static struct _vcs_dpi_soc_bounding_box_st original_dcn2_1_soc; +static struct _vcs_dpi_ip_params_st original_dcn2_1_ip; + +/** + * dcn20_fpu_dcn21_update_bw_bounding_box_test_init - Store backup copies of DCN global structures + * @test: represents a running instance of a test. + */ +int dcn20_fpu_dcn21_update_bw_bounding_box_test_init(struct kunit *test) +{ + memcpy(&original_dcn2_1_soc, &dcn2_1_soc, sizeof(struct _vcs_dpi_soc_bounding_box_st)); + memcpy(&original_dcn2_1_ip, &dcn2_1_ip, sizeof(struct _vcs_dpi_ip_params_st)); + + return 0; +} + +/** + * dcn20_fpu_dcn21_update_bw_bounding_box_test_exit - Restore original values + * of DCN global structures + * @test: represents a running instance of a test. + */ +static void dcn20_fpu_dcn21_update_bw_bounding_box_test_exit(struct kunit *test) +{ + memcpy(&dcn2_1_soc, &original_dcn2_1_soc, sizeof(struct _vcs_dpi_soc_bounding_box_st)); + memcpy(&dcn2_1_ip, &original_dcn2_1_ip, sizeof(struct _vcs_dpi_ip_params_st)); +} + +/** + * dcn21_update_bw_bounding_box_test - KUnit test for dcn21_update_bw_bounding_box + * @test: represents a running instance of a test. + */ +static void dcn21_update_bw_bounding_box_test(struct kunit *test) +{ + struct dcn21_update_bw_bounding_box_test_case *test_param = + (struct dcn21_update_bw_bounding_box_test_case *)test->param_value; + int i; + + DC_FP_START(); + dcn21_update_bw_bounding_box(&test_param->dc, &test_param->bw_params); + DC_FP_END(); + + KUNIT_EXPECT_EQ(test, test_param->dc.res_pool->res_cap->num_timing_generator, + dcn2_1_ip.max_num_otg); + KUNIT_EXPECT_EQ(test, test_param->dc.res_pool->pipe_count, dcn2_1_ip.max_num_dpp); + KUNIT_EXPECT_EQ(test, test_param->bw_params.num_channels, dcn2_1_soc.num_chans); + + for (i = 0; i <= test_param->clocks_to_compare; i++) { + KUNIT_EXPECT_EQ(test, test_param->expected_clock_limits[i].state, + dcn2_1_soc.clock_limits[i].state); + KUNIT_EXPECT_EQ(test, test_param->expected_clock_limits[i].dcfclk_mhz, + dcn2_1_soc.clock_limits[i].dcfclk_mhz); + KUNIT_EXPECT_EQ(test, test_param->expected_clock_limits[i].fabricclk_mhz, + dcn2_1_soc.clock_limits[i].fabricclk_mhz); + KUNIT_EXPECT_EQ(test, test_param->expected_clock_limits[i].dispclk_mhz, + dcn2_1_soc.clock_limits[i].dispclk_mhz); + KUNIT_EXPECT_EQ(test, test_param->expected_clock_limits[i].dppclk_mhz, + dcn2_1_soc.clock_limits[i].dppclk_mhz); + KUNIT_EXPECT_EQ(test, test_param->expected_clock_limits[i].phyclk_mhz, + dcn2_1_soc.clock_limits[i].phyclk_mhz); + KUNIT_EXPECT_EQ(test, test_param->expected_clock_limits[i].socclk_mhz, + dcn2_1_soc.clock_limits[i].socclk_mhz); + KUNIT_EXPECT_EQ(test, test_param->expected_clock_limits[i].dscclk_mhz, + dcn2_1_soc.clock_limits[i].dscclk_mhz); + KUNIT_EXPECT_EQ(test, test_param->expected_clock_limits[i].dram_speed_mts, + dcn2_1_soc.clock_limits[i].dram_speed_mts); + } + + if (test_param->bw_params.clk_table.num_entries) + KUNIT_EXPECT_EQ(test, test_param->bw_params.clk_table.num_entries, + dcn2_1_soc.num_states); +} + +static void dcn20_cap_soc_clocks_test_to_desc(struct dcn20_cap_soc_clocks_test_case *t, char *desc) +{ + strcpy(desc, t->desc); +} + +static void dcn21_update_bw_bounding_box_test_to_desc +(struct dcn21_update_bw_bounding_box_test_case *t, char *desc) +{ + strcpy(desc, t->desc); +} + +KUNIT_ARRAY_PARAM(dcn20_cap_soc_clocks, + dcn20_cap_soc_clocks_test_cases, + dcn20_cap_soc_clocks_test_to_desc); + +static struct kunit_case dcn20_fpu_test_cases[] = { + KUNIT_CASE_PARAM(dcn20_cap_soc_clocks_test, dcn20_cap_soc_clocks_gen_params), + { } +}; + +static struct kunit_suite dcn20_fpu_test_suite = { + .name = "dml_dcn20_fpu", + .test_cases = dcn20_fpu_test_cases, +}; + +KUNIT_ARRAY_PARAM(dcn21_update_bw_bounding_box, + dcn21_update_bw_bounding_box_test_data, + dcn21_update_bw_bounding_box_test_to_desc); + +static struct kunit_case dcn20_fpu_dcn21_update_bw_bounding_box_test_cases[] = { + KUNIT_CASE_PARAM(dcn21_update_bw_bounding_box_test, + dcn21_update_bw_bounding_box_gen_params), + { } +}; + +static struct kunit_suite dcn21_update_bw_bounding_box_test_suite = { + .name = "dml_dcn20_fpu_dcn21_update_bw_bounding_box_test", + .init = dcn20_fpu_dcn21_update_bw_bounding_box_test_init, + .exit = dcn20_fpu_dcn21_update_bw_bounding_box_test_exit, + .test_cases = dcn20_fpu_dcn21_update_bw_bounding_box_test_cases, +}; + +kunit_test_suites(&dcn20_fpu_test_suite, &dcn21_update_bw_bounding_box_test_suite); From patchwork Fri Jan 26 15:48:07 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: Rodrigo Siqueira Jordao X-Patchwork-Id: 13532857 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from gabe.freedesktop.org (gabe.freedesktop.org [131.252.210.177]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.lore.kernel.org (Postfix) with ESMTPS id 80FD9C47DDF for ; Fri, 26 Jan 2024 15:51:52 +0000 (UTC) Received: from gabe.freedesktop.org (localhost [127.0.0.1]) by gabe.freedesktop.org (Postfix) with ESMTP id 5188C10FBCF; Fri, 26 Jan 2024 15:51:49 +0000 (UTC) Received: from NAM10-MW2-obe.outbound.protection.outlook.com (mail-mw2nam10on2084.outbound.protection.outlook.com [40.107.94.84]) by gabe.freedesktop.org (Postfix) with ESMTPS id 0000E10FBCE; Fri, 26 Jan 2024 15:51:45 +0000 (UTC) ARC-Seal: i=1; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=none; b=J+rzMToUX4rGDbD8yYJYNgdhRaaHWGKfpgqM/oT3KyqPnjF1jFkoxlF7Lea3f5j/dnaXucF9wsbGMWd7kEc8dOum3eYSmUBOkjRKlEBdUmnt1ze0sY1TAuaT6ikw0cr1Fu9+iqF5VEJH7TU32Ga9gaQXT2M493ONmQqLrcGxsxvRpSZWCQTn6+t4CiI7zc+TZ6POg13klgVDkTriXJBli+CALFLp6cVT9IgzMqMk2JwRhQHqFzMrgBxzRI2qH6jolFyPN33B6lBLy7LZquGw0Rk2s0Ug0w3bTc+1VO8mr+yxswsIBjtSVrUziD1lN6zS065usp+MW2NMJHP4ZRTXwg== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=microsoft.com; s=arcselector9901; h=From:Date:Subject:Message-ID:Content-Type:MIME-Version:X-MS-Exchange-AntiSpam-MessageData-ChunkCount:X-MS-Exchange-AntiSpam-MessageData-0:X-MS-Exchange-AntiSpam-MessageData-1; bh=7opKPDW2k9gFFGTydi7qJ406j3JTfN/1HUjdxLd922g=; b=YGMcGwMuc2WsDAd6VrC3z6xBsIBFIjpuvjiqysL9M2Kepr8l9aYrYRSDkFdf9N1bRRDBG3b6aet1IkcCsa3+4c3kPhdNnlIMszhSYy7j+ribaneWoPS/hX7ZvRvDHPrk9Fc9VLC/V04gEkuRSWMbV5BbhLFU1J350ewv4sxHY7nmm+rIckowBplI9y6B/wMuiKqm+hB5W63Oga+jhaZgupOm3xNvgpZ/AfPfoyLN9/2bSrHgcwYAuSgEYIdfHt4++rFgG9JKsuTwdPzVoCBdsDcFh+vpQcSUJnj2ViAbZFbPxD/APvaZ7dYMdQlKuLI/mtXbfQQM0S0r111q0gg2MQ== ARC-Authentication-Results: i=1; mx.microsoft.com 1; spf=pass (sender ip is 165.204.84.17) smtp.rcpttodomain=linux.ie smtp.mailfrom=amd.com; dmarc=pass (p=quarantine sp=quarantine pct=100) action=none header.from=amd.com; dkim=none (message not signed); arc=none (0) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=amd.com; s=selector1; h=From:Date:Subject:Message-ID:Content-Type:MIME-Version:X-MS-Exchange-SenderADCheck; bh=7opKPDW2k9gFFGTydi7qJ406j3JTfN/1HUjdxLd922g=; b=Z2cxeeJDbuf0MhCHaGpnkjbCHoJ77xUD3huhnahD3Bsf+0/yFpj5CvNM8urV23EgExghpioVbBRDb//hdbqGqxBdOO/ryCOheNvB5tXqRexOIOnc/IBoI/XwBSHVE6Eeg1Shvx3GUHc7DJpPdlZT3Kj+1vhDUD3gu7l6S1HD/+g= Received: from BYAPR21CA0020.namprd21.prod.outlook.com (2603:10b6:a03:114::30) by MW4PR12MB7000.namprd12.prod.outlook.com (2603:10b6:303:208::15) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.7202.39; Fri, 26 Jan 2024 15:51:40 +0000 Received: from SJ1PEPF00001CE0.namprd05.prod.outlook.com (2603:10b6:a03:114:cafe::a6) by BYAPR21CA0020.outlook.office365.com (2603:10b6:a03:114::30) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.7249.8 via Frontend Transport; Fri, 26 Jan 2024 15:51:39 +0000 X-MS-Exchange-Authentication-Results: spf=pass (sender IP is 165.204.84.17) smtp.mailfrom=amd.com; dkim=none (message not signed) header.d=none;dmarc=pass action=none header.from=amd.com; Received-SPF: Pass (protection.outlook.com: domain of amd.com designates 165.204.84.17 as permitted sender) receiver=protection.outlook.com; client-ip=165.204.84.17; helo=SATLEXMB04.amd.com; pr=C Received: from SATLEXMB04.amd.com (165.204.84.17) by SJ1PEPF00001CE0.mail.protection.outlook.com (10.167.242.8) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256) id 15.20.7202.16 via Frontend Transport; Fri, 26 Jan 2024 15:51:39 +0000 Received: from smtp.xilinx.com (10.180.168.240) by SATLEXMB04.amd.com (10.181.40.145) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256) id 15.1.2507.34; Fri, 26 Jan 2024 09:51:35 -0600 From: Rodrigo Siqueira To: Alex Deucher , , , David Airlie , Daniel Vetter , Maarten Lankhorst , Maxime Ripard , Thomas Zimmermann , Harry Wentland , Leo Li , "Rodrigo Siqueira" , Nicholas Choi , Daniel Latypov , David Gow , , Subject: [PATCH v4 7/8] drm/amd/display: Introduce KUnit tests to dc_dmub_srv library Date: Fri, 26 Jan 2024 08:48:07 -0700 Message-ID: <20240126155022.1184856-8-Rodrigo.Siqueira@amd.com> X-Mailer: git-send-email 2.43.0 In-Reply-To: <20240126155022.1184856-1-Rodrigo.Siqueira@amd.com> References: <20240126155022.1184856-1-Rodrigo.Siqueira@amd.com> MIME-Version: 1.0 X-Originating-IP: [10.180.168.240] X-ClientProxiedBy: SATLEXMB04.amd.com (10.181.40.145) To SATLEXMB04.amd.com (10.181.40.145) X-EOPAttributedMessage: 0 X-MS-PublicTrafficType: Email X-MS-TrafficTypeDiagnostic: SJ1PEPF00001CE0:EE_|MW4PR12MB7000:EE_ X-MS-Office365-Filtering-Correlation-Id: 9b2d0743-e58a-432f-796d-08dc1e86af76 X-MS-Exchange-SenderADCheck: 1 X-MS-Exchange-AntiSpam-Relay: 0 X-Microsoft-Antispam: BCL:0; X-Microsoft-Antispam-Message-Info: JeDCPr6/T6k6v6/pPFSW1PzP6mHAGS0nn8WNbnxJevOHlBNA+9dGxCQEhGHAcwWEycG8rOKFKb6dy+gMpf1/u0ztOesk2sXRpa28WfDhtr4QSbdYmO5HKOKBHSvy2phuV+b7D9kkLGVtDZgc0VgbmnuumtBP/8z1wvY8DY/AWjPJLoqKIL3GqNTRXVrgDQVYTZJQUEXdmM69EDYX4YYjdvma8R8ZrSCXmcTnT6ggsYml5CEQ25bzqI7nmM7cOl8nRS8O32bd+cgP5WKKdB4OTt23u2W+COQYM298UOrm4iqRLqPuitrNkhdD5rIHiRZSBsYX0tU6KvficYa5oQawQoFwCmi9CkWpyUOCjKbhf66xCUboJO8UQj3BgE47SVsziQ3v6MdGaaGAHxoSxKBb8rQstTTh9w4naDBN5r411HjYosxAEesfR59uPeprBVIhQ5Yx3LRbYpupua1J4+Nrsg1fn9FFI3mrSLzqk3D4VPxVAW3EougJn/YAV09kdkbNxEuI/z6/rwxIjl6iGeSm2e6W2ufkk2ucY8g44zAoD/eFN7GJJOYSezrFeTJZ1f+yXTL5WsHiEIBwnLF/1f2SIf3uVLaqAwMqu8KCMTGkeJlHvaNO0lsVrw9RAAA1P9pC6/fdOjZp6lH5Jz5nJ4FXNdhLNgwTFFkc4EtLO93x5DWjhoYLyjqnB5O0PULPjLaq+rEs31NIu97lS46KtTJkVmM0omTycep9+yLwMIoaVOXG0FilcNsko9SmSCpLlGhgFyR8Mi1beY8EW7fOGysHKtnLFXtNAAi//WjdJSSvvJg= X-Forefront-Antispam-Report: CIP:165.204.84.17; CTRY:US; LANG:en; SCL:1; SRV:; IPV:CAL; SFV:NSPM; H:SATLEXMB04.amd.com; PTR:InfoDomainNonexistent; CAT:NONE; SFS:(13230031)(4636009)(39860400002)(396003)(346002)(376002)(136003)(230922051799003)(451199024)(64100799003)(82310400011)(186009)(1800799012)(36840700001)(40470700004)(46966006)(54906003)(70206006)(478600001)(356005)(336012)(82740400003)(81166007)(86362001)(36756003)(41300700001)(83380400001)(426003)(26005)(8936002)(8676002)(4326008)(316002)(1076003)(36860700001)(110136005)(7416002)(70586007)(5660300002)(6666004)(2906002)(2616005)(16526019)(47076005)(66574015)(921011)(40460700003)(40480700001)(36900700001); DIR:OUT; SFP:1101; X-OriginatorOrg: amd.com X-MS-Exchange-CrossTenant-OriginalArrivalTime: 26 Jan 2024 15:51:39.5183 (UTC) X-MS-Exchange-CrossTenant-Network-Message-Id: 9b2d0743-e58a-432f-796d-08dc1e86af76 X-MS-Exchange-CrossTenant-Id: 3dd8961f-e488-4e60-8e11-a82d994e183d X-MS-Exchange-CrossTenant-OriginalAttributedTenantConnectingIp: TenantId=3dd8961f-e488-4e60-8e11-a82d994e183d; Ip=[165.204.84.17]; Helo=[SATLEXMB04.amd.com] X-MS-Exchange-CrossTenant-AuthSource: SJ1PEPF00001CE0.namprd05.prod.outlook.com X-MS-Exchange-CrossTenant-AuthAs: Anonymous X-MS-Exchange-CrossTenant-FromEntityHeader: HybridOnPrem X-MS-Exchange-Transport-CrossTenantHeadersStamped: MW4PR12MB7000 X-BeenThere: dri-devel@lists.freedesktop.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: Direct Rendering Infrastructure - Development List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: kernel test robot , tales.aparecida@gmail.com, Trevor Woerner , javierm@redhat.com, dri-devel@lists.freedesktop.org, mwen@igalia.com, =?utf-8?q?Ma=C3=ADra_Cana?= =?utf-8?q?l?= , amd-gfx@lists.freedesktop.org, Isabella Basso , andrealmeid@riseup.net, kunit-dev@googlegroups.com Errors-To: dri-devel-bounces@lists.freedesktop.org Sender: "dri-devel" From: Maíra Canal Add a unit test to the SubVP feature in order to avoid possible regressions and ensure code robustness. In particular, this new test validates the expected parameters when using 4k144 and 4k240 displays. Signed-off-by: Maíra Canal Signed-off-by: Rodrigo Siqueira Reported-by: kernel test robot --- drivers/gpu/drm/amd/display/Kconfig | 13 ++ drivers/gpu/drm/amd/display/dc/dc_dmub_srv.c | 4 + .../amd/display/tests/dc/dc_dmub_srv_test.c | 159 ++++++++++++++++++ 3 files changed, 176 insertions(+) create mode 100644 drivers/gpu/drm/amd/display/tests/dc/dc_dmub_srv_test.c diff --git a/drivers/gpu/drm/amd/display/Kconfig b/drivers/gpu/drm/amd/display/Kconfig index 877ba3be6aed..9724162d7509 100644 --- a/drivers/gpu/drm/amd/display/Kconfig +++ b/drivers/gpu/drm/amd/display/Kconfig @@ -90,4 +90,17 @@ config AMD_DC_BASICS_KUNIT_TEST If unsure, say N. +config AMD_DC_KUNIT_TEST + bool "Enable KUnit tests for the 'utils' sub-component of DAL" if !KUNIT_ALL_TESTS + depends on DRM_AMD_DC && KUNIT + default KUNIT_ALL_TESTS + help + Enables unit tests for the basics folder of Display Core. Only useful for + kernel devs running KUnit. + + For more information on KUnit and unit tests in general please refer to + the KUnit documentation in Documentation/dev-tools/kunit/. + + If unsure, say N. + endmenu diff --git a/drivers/gpu/drm/amd/display/dc/dc_dmub_srv.c b/drivers/gpu/drm/amd/display/dc/dc_dmub_srv.c index 2b79a0e5638e..181d1bcabb0f 100644 --- a/drivers/gpu/drm/amd/display/dc/dc_dmub_srv.c +++ b/drivers/gpu/drm/amd/display/dc/dc_dmub_srv.c @@ -1415,3 +1415,7 @@ bool dc_wake_and_execute_gpint(const struct dc_context *ctx, enum dmub_gpint_com return result; } + +#if IS_ENABLED(CONFIG_AMD_DC_KUNIT_TEST) +#include "../tests/dc/dc_dmub_srv_test.c" +#endif diff --git a/drivers/gpu/drm/amd/display/tests/dc/dc_dmub_srv_test.c b/drivers/gpu/drm/amd/display/tests/dc/dc_dmub_srv_test.c new file mode 100644 index 000000000000..d12c4e3816b5 --- /dev/null +++ b/drivers/gpu/drm/amd/display/tests/dc/dc_dmub_srv_test.c @@ -0,0 +1,159 @@ +// SPDX-License-Identifier: MIT +/* + * KUnit tests for dc_dmub_srv.c + * + * Copyright (C) 2022, Maíra Canal + */ + +#include +#include "dc_dmub_srv.h" + +/** + * DOC: overview + * + * The file dc_dumb_srv.c has many functions that work as an interface to + * generate some of the DMUB parameters. To offload some of the complexity from + * the DMUB, the 'dc_dmub_srv.c' file provides functions that perform + * mathematical calculations to generate the parameter that will be passed to + * the DMUB to enable specific configurations. + */ + +/** + * struct populate_subvp_cmd_drr_info_test_case - Fields for subvp validation + * + * The function populate_subvp_cmd_drr_info() performs calculations based on + * different pipe context timing values. This struct maintains those fields + * required to be passed to the populate_subvp_cmd_drr_info. + */ +struct populate_subvp_cmd_drr_info_test_case { + const char *desc; + /** + * @dc: In the specific context of populate_subvp_cmd_drr_info() test, + * we only care about the DC capabilities. + */ + struct dc *dc; + + /** + * @subvp_pipe: This parameter plays an essential role in the + * populate_subvp_cmd_drr_info validation because it will be used to + * derive some of the parameters for the max VTotal, but it is also + * employed in a pointer validation that extracts the phantom timing + * from the context. + */ + struct pipe_ctx *subvp_pipe; + + /** + * @vblank_pipe: This field keeps the DRR timing values used in the Max + * and Min VTotal calculation. + */ + struct pipe_ctx *vblank_pipe; + + /** + * @context: In the context of populate_subvp_cmd_drr_info(), this + * field it is only necessary to fulfill the requirements for + * dc_state_get_paired_subvp_stream() helper. + */ + struct dc_state *context; +}; + +const struct dc_stream_status mock_dc_stream_state_returned_from_get_paired = { + .mall_stream_config = (struct mall_stream_config) { + .paired_stream = &(struct dc_stream_state) { + .timing = { + .v_total = 216, + .h_total = 4000, + .v_addressable = 149, + .pix_clk_100hz = 5332500, + .v_front_porch = 1, + }, + } + } +}; + +struct pipe_ctx mock_vblank_pipe_parameter = { + .stream = &(struct dc_stream_state) { + .timing = { + .v_total = 2250, + .h_total = 4400, + .v_addressable = 2160, + .pix_clk_100hz = 23760000, + }, + }, +}; + +const struct pipe_ctx mock_subvp_pipe_parameter = { + .stream = &(struct dc_stream_state) { + .timing = { + .h_total = 4000, + .v_addressable = 2160, + .pix_clk_100hz = 5332500, + }, + }, +}; + +struct populate_subvp_cmd_drr_info_test_case subvp_4k144_4k240_case = { + .desc = "4k144 and 4k240 displays are the perfect scenario for SubVP", + .dc = &(struct dc) { + .caps = { + .subvp_prefetch_end_to_mall_start_us = 15, + .subvp_fw_processing_delay_us = 15, + } + }, + + .subvp_pipe = (struct pipe_ctx *) &mock_subvp_pipe_parameter, + .vblank_pipe = &mock_vblank_pipe_parameter, + .context = &(struct dc_state) { + .stream_count = 1, + .streams[0] = mock_subvp_pipe_parameter.stream, + .stream_status[0] = mock_dc_stream_state_returned_from_get_paired, + }, +}; + +/** + * populate_subvp_cmd_drr_info_with_4k144_4k240_parameters - Check two display with 4k144 and 4k240 + * + * @test: Kunit parameter + * + * One of the scenarios where SubVP can perform really well is in a + * high-resolution display with a high refresh rate. In this sense, this test + * targets the parameter configuration for 4k144 and 4k240. + */ +static void populate_subvp_cmd_drr_info_with_4k144_4k240_parameters(struct kunit *test) +{ + struct dmub_cmd_fw_assisted_mclk_switch_pipe_data_v2 *pipe_data; + struct populate_subvp_cmd_drr_info_test_case tmp = subvp_4k144_4k240_case; + + pipe_data = kunit_kzalloc(test, + sizeof(struct dmub_cmd_fw_assisted_mclk_switch_pipe_data_v2), + GFP_KERNEL); + + populate_subvp_cmd_drr_info(tmp.dc, + tmp.context, + tmp.subvp_pipe, + tmp.vblank_pipe, + pipe_data); + + // DRR must be in use + KUNIT_EXPECT_EQ(test, true, pipe_data->pipe_config.vblank_data.drr_info.drr_in_use); + + // Use ramp should not be enable + KUNIT_EXPECT_EQ(test, false, pipe_data->pipe_config.vblank_data.drr_info.use_ramping); + + // Expects 4ms for the DRR window size + KUNIT_EXPECT_EQ(test, 4, pipe_data->pipe_config.vblank_data.drr_info.drr_window_size_ms); + + KUNIT_EXPECT_EQ(test, 2906, pipe_data->pipe_config.vblank_data.drr_info.min_vtotal_supported); + KUNIT_EXPECT_EQ(test, 7267, pipe_data->pipe_config.vblank_data.drr_info.max_vtotal_supported); +} + +static struct kunit_case dc_dmub_srv_cases[] = { + KUNIT_CASE(populate_subvp_cmd_drr_info_with_4k144_4k240_parameters), + { } +}; + +static struct kunit_suite dc_dmub_srv_suite = { + .name = "dc_dmub_srv", + .test_cases = dc_dmub_srv_cases, +}; + +kunit_test_suite(dc_dmub_srv_suite); From patchwork Fri Jan 26 15:48:08 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: Rodrigo Siqueira Jordao X-Patchwork-Id: 13532860 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from gabe.freedesktop.org (gabe.freedesktop.org [131.252.210.177]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.lore.kernel.org (Postfix) with ESMTPS id 76347C47DDF for ; Fri, 26 Jan 2024 15:52:12 +0000 (UTC) Received: from gabe.freedesktop.org (localhost [127.0.0.1]) by gabe.freedesktop.org (Postfix) with ESMTP id 44D2010FBE8; Fri, 26 Jan 2024 15:52:05 +0000 (UTC) Received: from NAM11-BN8-obe.outbound.protection.outlook.com (mail-bn8nam11on2041.outbound.protection.outlook.com [40.107.236.41]) by gabe.freedesktop.org (Postfix) with ESMTPS id 28BE110FBE8; Fri, 26 Jan 2024 15:52:03 +0000 (UTC) ARC-Seal: i=1; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=none; b=bieElXL9kgH98927oXjpY5O+RlvQ7BmlV22eqpjcPlkN+wQfEDghPClyrxr+BaMnsNT4plB76tcD2dJCPMu42b+dbbmT3HabSujXWNCjWFWOtWwmf53u2+BAzyNlRw9VzDVlL+2UARv47Wj7TV/4saxPONN5X7FeBpPTITwd8iADo5UJEgaQuGEFh+4QxO9mbg5mLwEyfa41HQIqdXjUY0eL0rbbkOMUvaiTTmHYAjy9KKW0J3AK+E8WiFZtXQ6oKxGhDTRsEnz19ky+PqanDsTk6mrK5xeUSe0WYTFknx0R8/w9K6Kr6z31TUmlR66Kv1k0K2zXIQO+JqPT3o1ECg== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=microsoft.com; s=arcselector9901; h=From:Date:Subject:Message-ID:Content-Type:MIME-Version:X-MS-Exchange-AntiSpam-MessageData-ChunkCount:X-MS-Exchange-AntiSpam-MessageData-0:X-MS-Exchange-AntiSpam-MessageData-1; bh=ND5YXrI7/KUyD6sV4ioHID51OXLoPcuh8HMMxaJElpc=; b=dHeVA95Un00TjbWYEtkcBlIZgx+wby5ndHz8rLfDOjsGWMZz4KLQWGkClAatfpl3SW409HtZAFx614T0SnEMUbDE/pelfgOVgxt1uEom0fW6FLlD7kPnCJ5HFMxBZ15WdUS/H7kiNvbMv8OTSNVZRVubcGhTcldF9jZMHabQbJaGByAmSrMrFTF6WyHHSdld/S4U7TeVw27XYBjv/uhtyZKhSovWXJbqgNTr09szDW8J2A/Hna7eEXBVyjo2QCp4eN97fFpdmAh5mDnROFqXv0urEg8nZ5QtLRkvX4UYCstd8m1gmnb321h4AxFqOF8Di7sPajOQ+D4l1qB9zLg2yQ== ARC-Authentication-Results: i=1; mx.microsoft.com 1; spf=pass (sender ip is 165.204.84.17) smtp.rcpttodomain=linux.ie smtp.mailfrom=amd.com; dmarc=pass (p=quarantine sp=quarantine pct=100) action=none header.from=amd.com; dkim=none (message not signed); arc=none (0) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=amd.com; s=selector1; h=From:Date:Subject:Message-ID:Content-Type:MIME-Version:X-MS-Exchange-SenderADCheck; bh=ND5YXrI7/KUyD6sV4ioHID51OXLoPcuh8HMMxaJElpc=; b=aZy3rF9aepK12T9zWSyTprD4+wykC337Fx42xoS4//03h9LIjXA0/JLGqGSG5459fJlAEH1oUb6m8I+JN+OrzFpHkxU71UeIIlVmNrLXi/5Ph93sIdxL95npdy5h1du4K65s/ZRVPZJuNrOBWzMqlPw5JRrSrrK3xXleXLqMg/E= Received: from BYAPR21CA0029.namprd21.prod.outlook.com (2603:10b6:a03:114::39) by CH0PR12MB5283.namprd12.prod.outlook.com (2603:10b6:610:d6::12) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.7228.27; Fri, 26 Jan 2024 15:51:42 +0000 Received: from SJ1PEPF00001CE0.namprd05.prod.outlook.com (2603:10b6:a03:114:cafe::63) by BYAPR21CA0029.outlook.office365.com (2603:10b6:a03:114::39) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.7249.8 via Frontend Transport; Fri, 26 Jan 2024 15:51:41 +0000 X-MS-Exchange-Authentication-Results: spf=pass (sender IP is 165.204.84.17) smtp.mailfrom=amd.com; dkim=none (message not signed) header.d=none;dmarc=pass action=none header.from=amd.com; Received-SPF: Pass (protection.outlook.com: domain of amd.com designates 165.204.84.17 as permitted sender) receiver=protection.outlook.com; client-ip=165.204.84.17; helo=SATLEXMB04.amd.com; pr=C Received: from SATLEXMB04.amd.com (165.204.84.17) by SJ1PEPF00001CE0.mail.protection.outlook.com (10.167.242.8) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256) id 15.20.7202.16 via Frontend Transport; Fri, 26 Jan 2024 15:51:41 +0000 Received: from smtp.xilinx.com (10.180.168.240) by SATLEXMB04.amd.com (10.181.40.145) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256) id 15.1.2507.34; Fri, 26 Jan 2024 09:51:38 -0600 From: Rodrigo Siqueira To: Alex Deucher , , , David Airlie , Daniel Vetter , Maarten Lankhorst , Maxime Ripard , Thomas Zimmermann , Harry Wentland , Leo Li , "Rodrigo Siqueira" , Nicholas Choi , Daniel Latypov , David Gow , , Subject: [PATCH v4 8/8] Documentation/gpu: Add Display Core Unit Test documentation Date: Fri, 26 Jan 2024 08:48:08 -0700 Message-ID: <20240126155022.1184856-9-Rodrigo.Siqueira@amd.com> X-Mailer: git-send-email 2.43.0 In-Reply-To: <20240126155022.1184856-1-Rodrigo.Siqueira@amd.com> References: <20240126155022.1184856-1-Rodrigo.Siqueira@amd.com> MIME-Version: 1.0 X-Originating-IP: [10.180.168.240] X-ClientProxiedBy: SATLEXMB04.amd.com (10.181.40.145) To SATLEXMB04.amd.com (10.181.40.145) X-EOPAttributedMessage: 0 X-MS-PublicTrafficType: Email X-MS-TrafficTypeDiagnostic: SJ1PEPF00001CE0:EE_|CH0PR12MB5283:EE_ X-MS-Office365-Filtering-Correlation-Id: 197224d9-d691-40e3-7e98-08dc1e86b0bf X-MS-Exchange-SenderADCheck: 1 X-MS-Exchange-AntiSpam-Relay: 0 X-Microsoft-Antispam: BCL:0; X-Microsoft-Antispam-Message-Info: i3FBHXRxkj2aDQbZ9VydwGkgnxuNCpMLRTPZPyixv9Sr7wwDuWiCH2gGX785Bng8LtYTNWj4Xv1dszvodOsmYeYTL5oI5gUR8CKdkQXBJka8diRRl3dNXWn2JQ6uEdnd+2OVW7kQ86XfGkDbfrEIk2Zt8LQu+Cej+8qJTyHMOLHRhJagQzoTSV9e72x4EtX97e6U0eE11C56bLRp2xRzsfRIodeN3+I83NFz4fJ1GeW3Fsw6eluo091nEzZe2fTpfJgAfVsJm/B/bIFsHotH2k9X/BxRWrwTRz2IVDF+YtLYsMHMf0fqFkknsLu02kNfmR1wwHK4AtPkgE021U9mgYGEolZY7tr9vacEkGghY1XEDiVMwUNnbpRh1TaauR5ZYEBPpVJ4QHJUIzG+1HoQD+fsHm5KAfUY6qfs7/gaxiL4f8CfC0SKo9UldDhiEgpgwghB9BS7/Q0GmQWIBBepKrmb+GQsGv37YInkDR1/NkzYzh0Wd3SPrbzZaMwQQ1A8fXSHk3Nex11f5sKPvls7VpNYdeTdHsjW9yPpY6tZMZKVQKgqc8ApnLcXQcmcdS5xCnLEgna/Wysi4JFdF9MgNtUH2BlbCZa/4dl90Z3h6CId4mzBBiJxby385npjBM33zio2eT0034/7THMiJqbNN8VHwmASpNmTak8CbTizwQ816WHNcpK9qMSbxkYzalwwMttCY6HUqic/xmaDONMhj6AQR3tfWGRTZKk1EN43gvs71uFiY1QpTrAg/o11UUJkAKDNiEx7qXeFm64lSIl/l1cPf25YG6fqK6vHsGYGMc0= X-Forefront-Antispam-Report: CIP:165.204.84.17; CTRY:US; LANG:en; SCL:1; SRV:; IPV:CAL; SFV:NSPM; H:SATLEXMB04.amd.com; PTR:InfoDomainNonexistent; CAT:NONE; SFS:(13230031)(4636009)(346002)(136003)(396003)(39860400002)(376002)(230922051799003)(451199024)(64100799003)(1800799012)(82310400011)(186009)(46966006)(40470700004)(36840700001)(921011)(40480700001)(40460700003)(66574015)(6666004)(2616005)(1076003)(26005)(426003)(478600001)(336012)(16526019)(110136005)(86362001)(70206006)(54906003)(70586007)(316002)(4326008)(8676002)(83380400001)(8936002)(47076005)(41300700001)(82740400003)(66899024)(5660300002)(36756003)(356005)(81166007)(36860700001)(7416002)(2906002)(36900700001); DIR:OUT; SFP:1101; X-OriginatorOrg: amd.com X-MS-Exchange-CrossTenant-OriginalArrivalTime: 26 Jan 2024 15:51:41.6433 (UTC) X-MS-Exchange-CrossTenant-Network-Message-Id: 197224d9-d691-40e3-7e98-08dc1e86b0bf X-MS-Exchange-CrossTenant-Id: 3dd8961f-e488-4e60-8e11-a82d994e183d X-MS-Exchange-CrossTenant-OriginalAttributedTenantConnectingIp: TenantId=3dd8961f-e488-4e60-8e11-a82d994e183d; Ip=[165.204.84.17]; Helo=[SATLEXMB04.amd.com] X-MS-Exchange-CrossTenant-AuthSource: SJ1PEPF00001CE0.namprd05.prod.outlook.com X-MS-Exchange-CrossTenant-AuthAs: Anonymous X-MS-Exchange-CrossTenant-FromEntityHeader: HybridOnPrem X-MS-Exchange-Transport-CrossTenantHeadersStamped: CH0PR12MB5283 X-BeenThere: dri-devel@lists.freedesktop.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: Direct Rendering Infrastructure - Development List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: tales.aparecida@gmail.com, Trevor Woerner , javierm@redhat.com, dri-devel@lists.freedesktop.org, mwen@igalia.com, =?utf-8?q?Ma=C3=ADra_Canal?= , amd-gfx@lists.freedesktop.org, Isabella Basso , andrealmeid@riseup.net, kunit-dev@googlegroups.com Errors-To: dri-devel-bounces@lists.freedesktop.org Sender: "dri-devel" From: Maíra Canal Explain how to run the KUnit tests present in the AMDGPU's Display Core and clarify which architectures and tools can be used to run the tests. Moreover, explains how to add new tests to the existing tests. Signed-off-by: Maíra Canal --- .../gpu/amdgpu/display/display-test.rst | 88 +++++++++++++++++++ Documentation/gpu/amdgpu/display/index.rst | 1 + 2 files changed, 89 insertions(+) create mode 100644 Documentation/gpu/amdgpu/display/display-test.rst diff --git a/Documentation/gpu/amdgpu/display/display-test.rst b/Documentation/gpu/amdgpu/display/display-test.rst new file mode 100644 index 000000000000..a8c136ce87b7 --- /dev/null +++ b/Documentation/gpu/amdgpu/display/display-test.rst @@ -0,0 +1,88 @@ +.. SPDX-License-Identifier: GPL-2.0+ + +======================== +Display Core Unit Tests +======================== + +Display core provides a set of unit tests, currently focused on the Display Mode +Library. The unit tests use KUnit (Kernel Unit Testing Framework), a common +framework for unit tests within the Linux Kernel. + +This section covers the specifics of the tests for the AMDGPU driver. For general +information about KUnit, please refer to Documentation/dev-tools/kunit/start.rst. + +How to run the tests? +===================== + +In order to facilitate running the test suite, a configuration file is present +in ``drivers/gpu/drm/amd/display/tests/dc/.kunitconfig``. This configuration file +can be used to run the kunit_tool, a Python script (``tools/testing/kunit/kunit.py``) +used to configure, build, exec, parse and run tests. + +.. code-block:: bash + + $ ./tools/testing/kunit/kunit.py run --arch=x86_64 \ + --kunitconfig=drivers/gpu/drm/amd/display/tests + +Currently, the Display Core Unit Tests are only supported on x86_64. + +Moreover, the tests can also be run on real hardware or in other emulation +environments. To include the Display Core Unit Tests on a deployable kernel, +you might add the following config options to your ``.config``: + +.. code-block:: none + + CONFIG_KUNIT=y + CONFIG_AMDGPU=m + CONFIG_AMD_DC_BASICS_KUNIT_TEST=y + CONFIG_AMD_DC_KUNIT_TEST=y + CONFIG_DCE_KUNIT_TEST=y + CONFIG_DML_KUNIT_TEST=y + +Once the kernel is built and installed, you can load the ``amdgpu`` module +to run all tests available. + +Also, the tests can be added to the kernel as built-in modules, by adding the +following config options to your ``.config``: + +.. code-block:: none + + CONFIG_KUNIT=y + CONFIG_AMDGPU=y + CONFIG_AMD_DC_BASICS_KUNIT_TEST=y + CONFIG_AMD_DC_KUNIT_TEST=y + CONFIG_DCE_KUNIT_TEST=y + CONFIG_DML_KUNIT_TEST=y + +In order to run specific tests, you can check the filter options from KUnit on +Documentation/dev-tools/kunit/kunit-tool.rst. + +How to add new tests? +===================== + +Tests covering different parts of the Display Core are always welcomed. Adding +a new test is a simple procedure, that consists in creating a unit test file +and adding the following guard to the end of the tested file when you are +testing static functions: + +.. code-block:: c + + #ifdef CONFIG_MY_KUNIT_TEST + #include "my_kunit_test.c" + #endif + +If you are not testing static functions, you should use the Makefile placed on +``display/tests``. In order to add a test to the Makefile, you can just add +the following entry to the Makefile: + +.. code-block:: make + + ifdef CONFIG_MY_KUNIT_TEST + DC_TESTS += my_kunit_test.o + endif + +The ``display/tests`` folder replicates the folder hierarchy of the ``display`` +folder, so this must be considered while adding new tests. + +More information on how to write unit tests with the KUnit API can be provided +on Documentation/dev-tools/kunit/api/test.rst. diff --git a/Documentation/gpu/amdgpu/display/index.rst b/Documentation/gpu/amdgpu/display/index.rst index f8a4f53d70d8..9b13f0f3524f 100644 --- a/Documentation/gpu/amdgpu/display/index.rst +++ b/Documentation/gpu/amdgpu/display/index.rst @@ -29,4 +29,5 @@ table of content: dc-debug.rst dcn-overview.rst mpo-overview.rst + display-test.rst dc-glossary.rst