xref: /linux/drivers/gpu/drm/xe/tests/xe_pci_test.c (revision f5bd7da05a5988506dedcb3e67aecb3a13a4cdf0)
1 // SPDX-License-Identifier: GPL-2.0
2 /*
3  * Copyright © 2023 Intel Corporation
4  */
5 
6 #include <drm/drm_drv.h>
7 #include <drm/drm_kunit_helpers.h>
8 
9 #include <kunit/test.h>
10 
11 #include "tests/xe_test.h"
12 
13 #include "xe_device.h"
14 #include "xe_pci_test.h"
15 #include "xe_pci_types.h"
16 
17 static void check_graphics_ip(struct kunit *test)
18 {
19 	const struct xe_ip *param = test->param_value;
20 	const struct xe_graphics_desc *graphics = param->desc;
21 	u64 mask = graphics->hw_engine_mask;
22 	u8 fuse_regs = graphics->num_geometry_xecore_fuse_regs +
23 		graphics->num_compute_xecore_fuse_regs;
24 
25 	/* RCS, CCS, and BCS engines are allowed on the graphics IP */
26 	mask &= ~(XE_HW_ENGINE_RCS_MASK |
27 		  XE_HW_ENGINE_CCS_MASK |
28 		  XE_HW_ENGINE_BCS_MASK);
29 
30 	/* Any remaining engines are an error */
31 	KUNIT_ASSERT_EQ(test, mask, 0);
32 
33 	/*
34 	 * All graphics IP should have at least one geometry and/or compute
35 	 * XeCore fuse register.
36 	 */
37 	KUNIT_ASSERT_GE(test, fuse_regs, 1);
38 }
39 
40 static void check_media_ip(struct kunit *test)
41 {
42 	const struct xe_ip *param = test->param_value;
43 	const struct xe_media_desc *media = param->desc;
44 	u64 mask = media->hw_engine_mask;
45 
46 	/* VCS, VECS and GSCCS engines are allowed on the media IP */
47 	mask &= ~(XE_HW_ENGINE_VCS_MASK |
48 		  XE_HW_ENGINE_VECS_MASK |
49 		  XE_HW_ENGINE_GSCCS_MASK);
50 
51 	/* Any remaining engines are an error */
52 	KUNIT_ASSERT_EQ(test, mask, 0);
53 }
54 
55 static void check_platform_desc(struct kunit *test)
56 {
57 	const struct pci_device_id *pci = test->param_value;
58 	const struct xe_device_desc *desc =
59 		(const struct xe_device_desc *)pci->driver_data;
60 
61 	KUNIT_EXPECT_GT(test, desc->dma_mask_size, 0);
62 
63 	KUNIT_EXPECT_GT(test, (unsigned int)desc->max_gt_per_tile, 0);
64 	KUNIT_EXPECT_LE(test, (unsigned int)desc->max_gt_per_tile, XE_MAX_GT_PER_TILE);
65 
66 	KUNIT_EXPECT_GT(test, desc->va_bits, 0);
67 	KUNIT_EXPECT_LE(test, desc->va_bits, 64);
68 
69 	KUNIT_EXPECT_GT(test, desc->vm_max_level, 0);
70 }
71 
72 static struct kunit_case xe_pci_tests[] = {
73 	KUNIT_CASE_PARAM(check_graphics_ip, xe_pci_graphics_ip_gen_param),
74 	KUNIT_CASE_PARAM(check_media_ip, xe_pci_media_ip_gen_param),
75 	KUNIT_CASE_PARAM(check_platform_desc, xe_pci_id_gen_param),
76 	{}
77 };
78 
79 static struct kunit_suite xe_pci_test_suite = {
80 	.name = "xe_pci",
81 	.test_cases = xe_pci_tests,
82 };
83 
84 kunit_test_suite(xe_pci_test_suite);
85