1 /* SPDX-License-Identifier: GPL-2.0 */ 2 /* Copyright (c) 2021-2022, NVIDIA CORPORATION & AFFILIATES. 3 */ 4 #ifndef _UAPI_IOMMUFD_TEST_H 5 #define _UAPI_IOMMUFD_TEST_H 6 7 #include <linux/types.h> 8 #include <linux/iommufd.h> 9 10 enum { 11 IOMMU_TEST_OP_ADD_RESERVED = 1, 12 IOMMU_TEST_OP_MOCK_DOMAIN, 13 IOMMU_TEST_OP_MD_CHECK_MAP, 14 IOMMU_TEST_OP_MD_CHECK_REFS, 15 IOMMU_TEST_OP_CREATE_ACCESS, 16 IOMMU_TEST_OP_DESTROY_ACCESS_PAGES, 17 IOMMU_TEST_OP_ACCESS_PAGES, 18 IOMMU_TEST_OP_ACCESS_RW, 19 IOMMU_TEST_OP_SET_TEMP_MEMORY_LIMIT, 20 IOMMU_TEST_OP_MOCK_DOMAIN_REPLACE, 21 IOMMU_TEST_OP_ACCESS_REPLACE_IOAS, 22 IOMMU_TEST_OP_MOCK_DOMAIN_FLAGS, 23 IOMMU_TEST_OP_DIRTY, 24 }; 25 26 enum { 27 MOCK_APERTURE_START = 1UL << 24, 28 MOCK_APERTURE_LAST = (1UL << 31) - 1, 29 }; 30 31 enum { 32 MOCK_FLAGS_ACCESS_WRITE = 1 << 0, 33 MOCK_FLAGS_ACCESS_SYZ = 1 << 16, 34 }; 35 36 enum { 37 MOCK_ACCESS_RW_WRITE = 1 << 0, 38 MOCK_ACCESS_RW_SLOW_PATH = 1 << 2, 39 }; 40 41 enum { 42 MOCK_FLAGS_ACCESS_CREATE_NEEDS_PIN_PAGES = 1 << 0, 43 }; 44 45 enum { 46 MOCK_FLAGS_DEVICE_NO_DIRTY = 1 << 0, 47 }; 48 49 enum { 50 MOCK_NESTED_DOMAIN_IOTLB_ID_MAX = 3, 51 MOCK_NESTED_DOMAIN_IOTLB_NUM = 4, 52 }; 53 54 struct iommu_test_cmd { 55 __u32 size; 56 __u32 op; 57 __u32 id; 58 __u32 __reserved; 59 union { 60 struct { 61 __aligned_u64 start; 62 __aligned_u64 length; 63 } add_reserved; 64 struct { 65 __u32 out_stdev_id; 66 __u32 out_hwpt_id; 67 /* out_idev_id is the standard iommufd_bind object */ 68 __u32 out_idev_id; 69 } mock_domain; 70 struct { 71 __u32 out_stdev_id; 72 __u32 out_hwpt_id; 73 __u32 out_idev_id; 74 /* Expand mock_domain to set mock device flags */ 75 __u32 dev_flags; 76 } mock_domain_flags; 77 struct { 78 __u32 pt_id; 79 } mock_domain_replace; 80 struct { 81 __aligned_u64 iova; 82 __aligned_u64 length; 83 __aligned_u64 uptr; 84 } check_map; 85 struct { 86 __aligned_u64 length; 87 __aligned_u64 uptr; 88 __u32 refs; 89 } check_refs; 90 struct { 91 __u32 out_access_fd; 92 __u32 flags; 93 } create_access; 94 struct { 95 __u32 access_pages_id; 96 } destroy_access_pages; 97 struct { 98 __u32 flags; 99 __u32 out_access_pages_id; 100 __aligned_u64 iova; 101 __aligned_u64 length; 102 __aligned_u64 uptr; 103 } access_pages; 104 struct { 105 __aligned_u64 iova; 106 __aligned_u64 length; 107 __aligned_u64 uptr; 108 __u32 flags; 109 } access_rw; 110 struct { 111 __u32 limit; 112 } memory_limit; 113 struct { 114 __u32 ioas_id; 115 } access_replace_ioas; 116 struct { 117 __u32 flags; 118 __aligned_u64 iova; 119 __aligned_u64 length; 120 __aligned_u64 page_size; 121 __aligned_u64 uptr; 122 __aligned_u64 out_nr_dirty; 123 } dirty; 124 }; 125 __u32 last; 126 }; 127 #define IOMMU_TEST_CMD _IO(IOMMUFD_TYPE, IOMMUFD_CMD_BASE + 32) 128 129 /* Mock structs for IOMMU_DEVICE_GET_HW_INFO ioctl */ 130 #define IOMMU_HW_INFO_TYPE_SELFTEST 0xfeedbeef 131 #define IOMMU_HW_INFO_SELFTEST_REGVAL 0xdeadbeef 132 133 struct iommu_test_hw_info { 134 __u32 flags; 135 __u32 test_reg; 136 }; 137 138 /* Should not be equal to any defined value in enum iommu_hwpt_data_type */ 139 #define IOMMU_HWPT_DATA_SELFTEST 0xdead 140 #define IOMMU_TEST_IOTLB_DEFAULT 0xbadbeef 141 142 /** 143 * struct iommu_hwpt_selftest 144 * 145 * @iotlb: default mock iotlb value, IOMMU_TEST_IOTLB_DEFAULT 146 */ 147 struct iommu_hwpt_selftest { 148 __u32 iotlb; 149 }; 150 151 #endif 152