| 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 | |
| 23 | /* RCS, CCS, and BCS engines are allowed on the graphics IP */ |
| 24 | mask &= ~(XE_HW_ENGINE_RCS_MASK | |
| 25 | XE_HW_ENGINE_CCS_MASK | |
| 26 | XE_HW_ENGINE_BCS_MASK); |
| 27 | |
| 28 | /* Any remaining engines are an error */ |
| 29 | KUNIT_ASSERT_EQ(test, mask, 0); |
| 30 | } |
| 31 | |
| 32 | static void check_media_ip(struct kunit *test) |
| 33 | { |
| 34 | const struct xe_ip *param = test->param_value; |
| 35 | const struct xe_media_desc *media = param->desc; |
| 36 | u64 mask = media->hw_engine_mask; |
| 37 | |
| 38 | /* VCS, VECS and GSCCS engines are allowed on the media IP */ |
| 39 | mask &= ~(XE_HW_ENGINE_VCS_MASK | |
| 40 | XE_HW_ENGINE_VECS_MASK | |
| 41 | XE_HW_ENGINE_GSCCS_MASK); |
| 42 | |
| 43 | /* Any remaining engines are an error */ |
| 44 | KUNIT_ASSERT_EQ(test, mask, 0); |
| 45 | } |
| 46 | |
| 47 | static void check_platform_desc(struct kunit *test) |
| 48 | { |
| 49 | const struct pci_device_id *pci = test->param_value; |
| 50 | const struct xe_device_desc *desc = |
| 51 | (const struct xe_device_desc *)pci->driver_data; |
| 52 | |
| 53 | KUNIT_EXPECT_GT(test, desc->dma_mask_size, 0); |
| 54 | |
| 55 | KUNIT_EXPECT_GT(test, (unsigned int)desc->max_gt_per_tile, 0); |
| 56 | KUNIT_EXPECT_LE(test, (unsigned int)desc->max_gt_per_tile, XE_MAX_GT_PER_TILE); |
| 57 | |
| 58 | KUNIT_EXPECT_GT(test, desc->va_bits, 0); |
| 59 | KUNIT_EXPECT_LE(test, desc->va_bits, 64); |
| 60 | |
| 61 | KUNIT_EXPECT_GT(test, desc->vm_max_level, 0); |
| 62 | } |
| 63 | |
| 64 | static struct kunit_case xe_pci_tests[] = { |
| 65 | KUNIT_CASE_PARAM(check_graphics_ip, xe_pci_graphics_ip_gen_param), |
| 66 | KUNIT_CASE_PARAM(check_media_ip, xe_pci_media_ip_gen_param), |
| 67 | KUNIT_CASE_PARAM(check_platform_desc, xe_pci_id_gen_param), |
| 68 | {} |
| 69 | }; |
| 70 | |
| 71 | static struct kunit_suite xe_pci_test_suite = { |
| 72 | .name = "xe_pci" , |
| 73 | .test_cases = xe_pci_tests, |
| 74 | }; |
| 75 | |
| 76 | kunit_test_suite(xe_pci_test_suite); |
| 77 | |