1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
|
// SPDX-License-Identifier: GPL-2.0 OR MIT
/*
* KUnit tests for amdgpu_dm_quirks.c
*
* Copyright 2026 Advanced Micro Devices, Inc.
*/
#include <kunit/test.h>
#include <linux/pci.h>
#include "dc.h"
#include "amdgpu_mode.h"
#include "amdgpu_dm.h"
/* Tests for retrieve_dmi_info() */
/*
* Verify that retrieve_dmi_info() always initialises aux_hpd_discon_quirk to
* false, even when the caller had previously set it to true.
*/
/**
* dm_test_quirks_aux_hpd_discon_reset - Test Quirks aux hpd discon reset
* @test: The KUnit test context
*/
static void dm_test_quirks_aux_hpd_discon_reset(struct kunit *test)
{
struct amdgpu_display_manager *dm;
dm = kunit_kzalloc(test, sizeof(*dm), GFP_KERNEL);
KUNIT_ASSERT_NOT_ERR_OR_NULL(test, dm);
dm->aux_hpd_discon_quirk = true;
retrieve_dmi_info(dm);
/*
* In a KUnit / UML environment no real DMI table is present, so
* dmi_check_system() returns 0 and retrieve_dmi_info() leaves the
* quirk at its initialised-to-false value.
*/
KUNIT_EXPECT_FALSE(test, dm->aux_hpd_discon_quirk);
}
/*
* Verify that retrieve_dmi_info() always initialises edp0_on_dp1_quirk to
* false, even when the caller had previously set it to true.
*/
/**
* dm_test_quirks_edp0_on_dp1_reset - Test Quirks edp0 on dp1 reset
* @test: The KUnit test context
*/
static void dm_test_quirks_edp0_on_dp1_reset(struct kunit *test)
{
struct amdgpu_display_manager *dm;
dm = kunit_kzalloc(test, sizeof(*dm), GFP_KERNEL);
KUNIT_ASSERT_NOT_ERR_OR_NULL(test, dm);
dm->edp0_on_dp1_quirk = true;
retrieve_dmi_info(dm);
KUNIT_EXPECT_FALSE(test, dm->edp0_on_dp1_quirk);
}
/*
* Verify that when no DMI match is found both quirks remain false after a
* fresh (zero-initialised) dm is passed to retrieve_dmi_info().
*/
/**
* dm_test_quirks_no_dmi_match_both_false - Test Quirks no dmi match both false
* @test: The KUnit test context
*/
static void dm_test_quirks_no_dmi_match_both_false(struct kunit *test)
{
struct amdgpu_display_manager *dm;
dm = kunit_kzalloc(test, sizeof(*dm), GFP_KERNEL);
KUNIT_ASSERT_NOT_ERR_OR_NULL(test, dm);
retrieve_dmi_info(dm);
KUNIT_EXPECT_FALSE(test, dm->aux_hpd_discon_quirk);
KUNIT_EXPECT_FALSE(test, dm->edp0_on_dp1_quirk);
}
/* Tests for dm_should_disable_stutter() */
/**
* dm_test_should_disable_stutter_match - Test the quirk device matches
* @test: The KUnit test context
*/
static void dm_test_should_disable_stutter_match(struct kunit *test)
{
struct pci_dev *pdev;
pdev = kunit_kzalloc(test, sizeof(*pdev), GFP_KERNEL);
KUNIT_ASSERT_NOT_NULL(test, pdev);
pdev->vendor = 0x1002;
pdev->device = 0x15dd;
pdev->subsystem_vendor = 0x1002;
pdev->subsystem_device = 0x15dd;
pdev->revision = 0xc8;
KUNIT_EXPECT_TRUE(test, dm_should_disable_stutter(pdev));
}
/**
* dm_test_should_disable_stutter_no_match - Test a non-quirk device does not match
* @test: The KUnit test context
*/
static void dm_test_should_disable_stutter_no_match(struct kunit *test)
{
struct pci_dev *pdev;
pdev = kunit_kzalloc(test, sizeof(*pdev), GFP_KERNEL);
KUNIT_ASSERT_NOT_NULL(test, pdev);
pdev->vendor = 0x1002;
pdev->device = 0x1234;
KUNIT_EXPECT_FALSE(test, dm_should_disable_stutter(pdev));
}
/**
* dm_test_should_disable_stutter_revision_differs - Test a partial match (revision) fails
* @test: The KUnit test context
*/
static void dm_test_should_disable_stutter_revision_differs(struct kunit *test)
{
struct pci_dev *pdev;
pdev = kunit_kzalloc(test, sizeof(*pdev), GFP_KERNEL);
KUNIT_ASSERT_NOT_NULL(test, pdev);
/* Everything matches the quirk except the revision */
pdev->vendor = 0x1002;
pdev->device = 0x15dd;
pdev->subsystem_vendor = 0x1002;
pdev->subsystem_device = 0x15dd;
pdev->revision = 0x00;
KUNIT_EXPECT_FALSE(test, dm_should_disable_stutter(pdev));
}
static struct kunit_case amdgpu_dm_quirks_tests[] = {
/* retrieve_dmi_info */
KUNIT_CASE(dm_test_quirks_aux_hpd_discon_reset),
KUNIT_CASE(dm_test_quirks_edp0_on_dp1_reset),
KUNIT_CASE(dm_test_quirks_no_dmi_match_both_false),
/* dm_should_disable_stutter */
KUNIT_CASE(dm_test_should_disable_stutter_match),
KUNIT_CASE(dm_test_should_disable_stutter_no_match),
KUNIT_CASE(dm_test_should_disable_stutter_revision_differs),
{}
};
static struct kunit_suite amdgpu_dm_quirks_test_suite = {
.name = "amdgpu_dm_quirks",
.test_cases = amdgpu_dm_quirks_tests,
};
kunit_test_suite(amdgpu_dm_quirks_test_suite);
MODULE_AUTHOR("AMD");
MODULE_DESCRIPTION("KUnit tests for amdgpu_dm_quirks");
MODULE_LICENSE("Dual MIT/GPL");
|