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 IOMMU_TEST_OP_MD_CHECK_IOTLB, 25 }; 26 27 enum { 28 MOCK_APERTURE_START = 1UL << 24, 29 MOCK_APERTURE_LAST = (1UL << 31) - 1, 30 }; 31 32 enum { 33 MOCK_FLAGS_ACCESS_WRITE = 1 << 0, 34 MOCK_FLAGS_ACCESS_SYZ = 1 << 16, 35 }; 36 37 enum { 38 MOCK_ACCESS_RW_WRITE = 1 << 0, 39 MOCK_ACCESS_RW_SLOW_PATH = 1 << 2, 40 }; 41 42 enum { 43 MOCK_FLAGS_ACCESS_CREATE_NEEDS_PIN_PAGES = 1 << 0, 44 }; 45 46 enum { 47 MOCK_FLAGS_DEVICE_NO_DIRTY = 1 << 0, 48 }; 49 50 enum { 51 MOCK_NESTED_DOMAIN_IOTLB_ID_MAX = 3, 52 MOCK_NESTED_DOMAIN_IOTLB_NUM = 4, 53 }; 54 55 struct iommu_test_cmd { 56 __u32 size; 57 __u32 op; 58 __u32 id; 59 __u32 __reserved; 60 union { 61 struct { 62 __aligned_u64 start; 63 __aligned_u64 length; 64 } add_reserved; 65 struct { 66 __u32 out_stdev_id; 67 __u32 out_hwpt_id; 68 /* out_idev_id is the standard iommufd_bind object */ 69 __u32 out_idev_id; 70 } mock_domain; 71 struct { 72 __u32 out_stdev_id; 73 __u32 out_hwpt_id; 74 __u32 out_idev_id; 75 /* Expand mock_domain to set mock device flags */ 76 __u32 dev_flags; 77 } mock_domain_flags; 78 struct { 79 __u32 pt_id; 80 } mock_domain_replace; 81 struct { 82 __aligned_u64 iova; 83 __aligned_u64 length; 84 __aligned_u64 uptr; 85 } check_map; 86 struct { 87 __aligned_u64 length; 88 __aligned_u64 uptr; 89 __u32 refs; 90 } check_refs; 91 struct { 92 __u32 out_access_fd; 93 __u32 flags; 94 } create_access; 95 struct { 96 __u32 access_pages_id; 97 } destroy_access_pages; 98 struct { 99 __u32 flags; 100 __u32 out_access_pages_id; 101 __aligned_u64 iova; 102 __aligned_u64 length; 103 __aligned_u64 uptr; 104 } access_pages; 105 struct { 106 __aligned_u64 iova; 107 __aligned_u64 length; 108 __aligned_u64 uptr; 109 __u32 flags; 110 } access_rw; 111 struct { 112 __u32 limit; 113 } memory_limit; 114 struct { 115 __u32 ioas_id; 116 } access_replace_ioas; 117 struct { 118 __u32 flags; 119 __aligned_u64 iova; 120 __aligned_u64 length; 121 __aligned_u64 page_size; 122 __aligned_u64 uptr; 123 __aligned_u64 out_nr_dirty; 124 } dirty; 125 struct { 126 __u32 id; 127 __u32 iotlb; 128 } check_iotlb; 129 }; 130 __u32 last; 131 }; 132 #define IOMMU_TEST_CMD _IO(IOMMUFD_TYPE, IOMMUFD_CMD_BASE + 32) 133 134 /* Mock structs for IOMMU_DEVICE_GET_HW_INFO ioctl */ 135 #define IOMMU_HW_INFO_TYPE_SELFTEST 0xfeedbeef 136 #define IOMMU_HW_INFO_SELFTEST_REGVAL 0xdeadbeef 137 138 struct iommu_test_hw_info { 139 __u32 flags; 140 __u32 test_reg; 141 }; 142 143 /* Should not be equal to any defined value in enum iommu_hwpt_data_type */ 144 #define IOMMU_HWPT_DATA_SELFTEST 0xdead 145 #define IOMMU_TEST_IOTLB_DEFAULT 0xbadbeef 146 147 /** 148 * struct iommu_hwpt_selftest 149 * 150 * @iotlb: default mock iotlb value, IOMMU_TEST_IOTLB_DEFAULT 151 */ 152 struct iommu_hwpt_selftest { 153 __u32 iotlb; 154 }; 155 156 /* Should not be equal to any defined value in enum iommu_hwpt_invalidate_data_type */ 157 #define IOMMU_HWPT_INVALIDATE_DATA_SELFTEST 0xdeadbeef 158 #define IOMMU_HWPT_INVALIDATE_DATA_SELFTEST_INVALID 0xdadbeef 159 160 /** 161 * struct iommu_hwpt_invalidate_selftest - Invalidation data for Mock driver 162 * (IOMMU_HWPT_INVALIDATE_DATA_SELFTEST) 163 * @flags: Invalidate flags 164 * @iotlb_id: Invalidate iotlb entry index 165 * 166 * If IOMMU_TEST_INVALIDATE_ALL is set in @flags, @iotlb_id will be ignored 167 */ 168 struct iommu_hwpt_invalidate_selftest { 169 #define IOMMU_TEST_INVALIDATE_FLAG_ALL (1 << 0) 170 __u32 flags; 171 __u32 iotlb_id; 172 }; 173 174 #endif 175