xref: /linux/drivers/gpu/drm/xe/tests/xe_rtp_tables_test.c (revision 67f8bc848ee31831336bd478e57d2f993551902e)
1e9845449SViolet Monti // SPDX-License-Identifier: GPL-2.0
2e9845449SViolet Monti /*
3e9845449SViolet Monti  * Copyright © 2026 Intel Corporation
4e9845449SViolet Monti  */
5e9845449SViolet Monti 
6e9845449SViolet Monti #include <kunit/test.h>
7e9845449SViolet Monti 
8*483c9f54SMatt Roper #include "xe_reg_whitelist.h"
9e9845449SViolet Monti #include "xe_rtp_types.h"
10e9845449SViolet Monti #include "xe_tuning.h"
11e9845449SViolet Monti #include "xe_wa.h"
12e9845449SViolet Monti 
13e9845449SViolet Monti #define RTP_TABLE_PARAM(table)									\
14e9845449SViolet Monti 	static const void *table##_gen_params(struct kunit *test,				\
15e9845449SViolet Monti 					     const void *prev, char *desc)			\
16e9845449SViolet Monti 	{											\
17e9845449SViolet Monti 		typeof((table.entries)[0]) *__next = prev ?					\
18e9845449SViolet Monti 			((typeof(__next))prev) + 1 : (table.entries);				\
19e9845449SViolet Monti 		if (__next - table.entries < table.n_entries) {					\
20e9845449SViolet Monti 			scnprintf(desc, KUNIT_PARAM_DESC_SIZE, #table "/%s", __next->name);	\
21e9845449SViolet Monti 			return __next;								\
22e9845449SViolet Monti 		}										\
23e9845449SViolet Monti 		return NULL;									\
24e9845449SViolet Monti 	}
25e9845449SViolet Monti 
26e9845449SViolet Monti static void xe_rtp_table_gt_test(struct kunit *test)
27e9845449SViolet Monti {
28e9845449SViolet Monti 	const struct xe_rtp_entry_sr *entry = test->param_value;
29e9845449SViolet Monti 
30e9845449SViolet Monti 	for (int i = 0; i < entry->n_rules; i++) {
31e9845449SViolet Monti 		KUNIT_EXPECT_TRUE(test,
32e9845449SViolet Monti 				  entry->rules[i].match_type != XE_RTP_MATCH_ENGINE_CLASS ||
33e9845449SViolet Monti 				  entry->flags & XE_RTP_ENTRY_FLAG_FOREACH_ENGINE);
34e9845449SViolet Monti 		KUNIT_EXPECT_TRUE(test,
35e9845449SViolet Monti 				  entry->rules[i].match_type != XE_RTP_MATCH_NOT_ENGINE_CLASS ||
36e9845449SViolet Monti 				  entry->flags & XE_RTP_ENTRY_FLAG_FOREACH_ENGINE);
37e9845449SViolet Monti 	}
38e9845449SViolet Monti }
39e9845449SViolet Monti 
40e9845449SViolet Monti RTP_TABLE_PARAM(gt_was);
41e9845449SViolet Monti RTP_TABLE_PARAM(gt_tunings);
42e9845449SViolet Monti 
43e2cfc5bcSViolet Monti static void xe_rtp_table_oob_test(struct kunit *test)
44e2cfc5bcSViolet Monti {
45e2cfc5bcSViolet Monti 	const struct xe_rtp_entry *entry = test->param_value;
46e2cfc5bcSViolet Monti 
47e2cfc5bcSViolet Monti 	for (int i = 0; i < entry->n_rules; i++) {
48e2cfc5bcSViolet Monti 		u8 match_type = entry->rules[i].match_type;
49e2cfc5bcSViolet Monti 
50e2cfc5bcSViolet Monti 		KUNIT_EXPECT_NE(test, match_type, XE_RTP_MATCH_ENGINE_CLASS);
51e2cfc5bcSViolet Monti 		KUNIT_EXPECT_NE(test, match_type, XE_RTP_MATCH_NOT_ENGINE_CLASS);
52e2cfc5bcSViolet Monti 	}
53e2cfc5bcSViolet Monti }
54e2cfc5bcSViolet Monti 
55e2cfc5bcSViolet Monti RTP_TABLE_PARAM(oob_was);
56e2cfc5bcSViolet Monti 
5794e15e89SViolet Monti static void xe_rtp_table_dev_oob_test(struct kunit *test)
5894e15e89SViolet Monti {
5994e15e89SViolet Monti 	const struct xe_rtp_entry *entry = test->param_value;
6094e15e89SViolet Monti 
6194e15e89SViolet Monti 	for (int i = 0; i < entry->n_rules; i++) {
6294e15e89SViolet Monti 		u8 match_type = entry->rules[i].match_type;
6394e15e89SViolet Monti 
6494e15e89SViolet Monti 		KUNIT_EXPECT_NE(test, match_type, XE_RTP_MATCH_ENGINE_CLASS);
6594e15e89SViolet Monti 		KUNIT_EXPECT_NE(test, match_type, XE_RTP_MATCH_NOT_ENGINE_CLASS);
6694e15e89SViolet Monti 		KUNIT_EXPECT_NE(test, match_type, XE_RTP_MATCH_GRAPHICS_VERSION);
6794e15e89SViolet Monti 		KUNIT_EXPECT_NE(test, match_type, XE_RTP_MATCH_GRAPHICS_VERSION_RANGE);
6894e15e89SViolet Monti 		KUNIT_EXPECT_NE(test, match_type, XE_RTP_MATCH_GRAPHICS_VERSION_ANY_GT);
6994e15e89SViolet Monti 		KUNIT_EXPECT_NE(test, match_type, XE_RTP_MATCH_GRAPHICS_STEP);
7094e15e89SViolet Monti 		KUNIT_EXPECT_NE(test, match_type, XE_RTP_MATCH_MEDIA_VERSION);
7194e15e89SViolet Monti 		KUNIT_EXPECT_NE(test, match_type, XE_RTP_MATCH_MEDIA_VERSION_RANGE);
7294e15e89SViolet Monti 		KUNIT_EXPECT_NE(test, match_type, XE_RTP_MATCH_MEDIA_VERSION_ANY_GT);
7394e15e89SViolet Monti 		KUNIT_EXPECT_NE(test, match_type, XE_RTP_MATCH_MEDIA_STEP);
7494e15e89SViolet Monti 	}
7594e15e89SViolet Monti }
7694e15e89SViolet Monti 
7794e15e89SViolet Monti RTP_TABLE_PARAM(device_oob_was);
7894e15e89SViolet Monti 
79*483c9f54SMatt Roper static void xe_rtp_table_missing_upper_bound_test(struct kunit *test)
80*483c9f54SMatt Roper {
81*483c9f54SMatt Roper 	const struct xe_rtp_entry_sr *entry = test->param_value;
82*483c9f54SMatt Roper 
83*483c9f54SMatt Roper 	for (int i = 0; i < entry->n_rules; i++) {
84*483c9f54SMatt Roper 		u8 match_type = entry->rules[i].match_type;
85*483c9f54SMatt Roper 
86*483c9f54SMatt Roper 		KUNIT_EXPECT_FALSE(test,
87*483c9f54SMatt Roper 				   match_type == XE_RTP_MATCH_GRAPHICS_VERSION_RANGE &&
88*483c9f54SMatt Roper 				   entry->rules[i].ver_end == XE_RTP_END_VERSION_UNDEFINED);
89*483c9f54SMatt Roper 		KUNIT_EXPECT_FALSE(test,
90*483c9f54SMatt Roper 				   match_type == XE_RTP_MATCH_MEDIA_VERSION_RANGE &&
91*483c9f54SMatt Roper 				   entry->rules[i].ver_end == XE_RTP_END_VERSION_UNDEFINED);
92*483c9f54SMatt Roper 	}
93*483c9f54SMatt Roper }
94*483c9f54SMatt Roper 
95*483c9f54SMatt Roper RTP_TABLE_PARAM(register_whitelist);
96*483c9f54SMatt Roper 
97e9845449SViolet Monti static struct kunit_case xe_rtp_table_tests[] = {
98e9845449SViolet Monti 	KUNIT_CASE_PARAM(xe_rtp_table_gt_test, gt_was_gen_params),
99e9845449SViolet Monti 	KUNIT_CASE_PARAM(xe_rtp_table_gt_test, gt_tunings_gen_params),
100e2cfc5bcSViolet Monti 	KUNIT_CASE_PARAM(xe_rtp_table_oob_test, oob_was_gen_params),
10194e15e89SViolet Monti 	KUNIT_CASE_PARAM(xe_rtp_table_dev_oob_test, device_oob_was_gen_params),
102*483c9f54SMatt Roper 	KUNIT_CASE_PARAM(xe_rtp_table_missing_upper_bound_test,
103*483c9f54SMatt Roper 			 register_whitelist_gen_params),
104e9845449SViolet Monti 	{}
105e9845449SViolet Monti };
106e9845449SViolet Monti 
107e9845449SViolet Monti static struct kunit_suite xe_rtp_tables_test_suite = {
108e9845449SViolet Monti 	.name = "xe_rtp_tables_test",
109e9845449SViolet Monti 	.test_cases = xe_rtp_table_tests,
110e9845449SViolet Monti };
111e9845449SViolet Monti 
112e9845449SViolet Monti kunit_test_suite(xe_rtp_tables_test_suite);
113