FILE
iommufd_test.h
File preview with syntax highlighting.
linux-6.19.14/drivers/iommu/iommufd/iommufd_test.h
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/iommufd.h> 8#include <linux/types.h> 9 10enum { 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 IOMMU_TEST_OP_TRIGGER_IOPF, 26 IOMMU_TEST_OP_DEV_CHECK_CACHE, 27 IOMMU_TEST_OP_TRIGGER_VEVENT, 28 IOMMU_TEST_OP_PASID_ATTACH, 29 IOMMU_TEST_OP_PASID_REPLACE, 30 IOMMU_TEST_OP_PASID_DETACH, 31 IOMMU_TEST_OP_PASID_CHECK_HWPT, 32 IOMMU_TEST_OP_DMABUF_GET, 33 IOMMU_TEST_OP_DMABUF_REVOKE, 34}; 35 36enum { 37 MOCK_IOMMUPT_DEFAULT = 0, 38 MOCK_IOMMUPT_HUGE, 39 MOCK_IOMMUPT_AMDV1, 40}; 41 42/* These values are true for MOCK_IOMMUPT_DEFAULT */ 43enum { 44 MOCK_APERTURE_START = 1UL << 24, 45 MOCK_APERTURE_LAST = (1UL << 31) - 1, 46 MOCK_PAGE_SIZE = 2048, 47 MOCK_HUGE_PAGE_SIZE = 512 * MOCK_PAGE_SIZE, 48}; 49 50enum { 51 MOCK_FLAGS_ACCESS_WRITE = 1 << 0, 52 MOCK_FLAGS_ACCESS_SYZ = 1 << 16, 53}; 54 55enum { 56 MOCK_ACCESS_RW_WRITE = 1 << 0, 57 MOCK_ACCESS_RW_SLOW_PATH = 1 << 2, 58}; 59 60enum { 61 MOCK_FLAGS_ACCESS_CREATE_NEEDS_PIN_PAGES = 1 << 0, 62}; 63 64enum { 65 MOCK_FLAGS_DEVICE_NO_DIRTY = 1 << 0, 66 MOCK_FLAGS_DEVICE_PASID = 1 << 2, 67}; 68 69enum { 70 MOCK_NESTED_DOMAIN_IOTLB_ID_MAX = 3, 71 MOCK_NESTED_DOMAIN_IOTLB_NUM = 4, 72}; 73 74enum { 75 MOCK_DEV_CACHE_ID_MAX = 3, 76 MOCK_DEV_CACHE_NUM = 4, 77}; 78 79/* Reserved for special pasid replace test */ 80#define IOMMU_TEST_PASID_RESERVED 1024 81 82struct iommu_test_cmd { 83 __u32 size; 84 __u32 op; 85 __u32 id; 86 __u32 __reserved; 87 union { 88 struct { 89 __aligned_u64 start; 90 __aligned_u64 length; 91 } add_reserved; 92 struct { 93 __u32 out_stdev_id; 94 __u32 out_hwpt_id; 95 /* out_idev_id is the standard iommufd_bind object */ 96 __u32 out_idev_id; 97 } mock_domain; 98 struct { 99 __u32 out_stdev_id; 100 __u32 out_hwpt_id; 101 __u32 out_idev_id; 102 /* Expand mock_domain to set mock device flags */ 103 __u32 dev_flags; 104 } mock_domain_flags; 105 struct { 106 __u32 pt_id; 107 } mock_domain_replace; 108 struct { 109 __aligned_u64 iova; 110 __aligned_u64 length; 111 __aligned_u64 uptr; 112 } check_map; 113 struct { 114 __aligned_u64 length; 115 __aligned_u64 uptr; 116 __u32 refs; 117 } check_refs; 118 struct { 119 __u32 out_access_fd; 120 __u32 flags; 121 } create_access; 122 struct { 123 __u32 access_pages_id; 124 } destroy_access_pages; 125 struct { 126 __u32 flags; 127 __u32 out_access_pages_id; 128 __aligned_u64 iova; 129 __aligned_u64 length; 130 __aligned_u64 uptr; 131 } access_pages; 132 struct { 133 __aligned_u64 iova; 134 __aligned_u64 length; 135 __aligned_u64 uptr; 136 __u32 flags; 137 } access_rw; 138 struct { 139 __u32 limit; 140 } memory_limit; 141 struct { 142 __u32 ioas_id; 143 } access_replace_ioas; 144 struct { 145 __u32 flags; 146 __aligned_u64 iova; 147 __aligned_u64 length; 148 __aligned_u64 page_size; 149 __aligned_u64 uptr; 150 __aligned_u64 out_nr_dirty; 151 } dirty; 152 struct { 153 __u32 id; 154 __u32 iotlb; 155 } check_iotlb; 156 struct { 157 __u32 dev_id; 158 __u32 pasid; 159 __u32 grpid; 160 __u32 perm; 161 __u64 addr; 162 } trigger_iopf; 163 struct { 164 __u32 id; 165 __u32 cache; 166 } check_dev_cache; 167 struct { 168 __u32 dev_id; 169 } trigger_vevent; 170 struct { 171 __u32 pasid; 172 __u32 pt_id; 173 /* @id is stdev_id */ 174 } pasid_attach; 175 struct { 176 __u32 pasid; 177 __u32 pt_id; 178 /* @id is stdev_id */ 179 } pasid_replace; 180 struct { 181 __u32 pasid; 182 /* @id is stdev_id */ 183 } pasid_detach; 184 struct { 185 __u32 pasid; 186 __u32 hwpt_id; 187 /* @id is stdev_id */ 188 } pasid_check; 189 struct { 190 __u32 length; 191 __u32 open_flags; 192 } dmabuf_get; 193 struct { 194 __s32 dmabuf_fd; 195 __u32 revoked; 196 } dmabuf_revoke; 197 }; 198 __u32 last; 199}; 200#define IOMMU_TEST_CMD _IO(IOMMUFD_TYPE, IOMMUFD_CMD_BASE + 32) 201 202/* Mock device/iommu PASID width */ 203#define MOCK_PASID_WIDTH 20 204 205/* Mock structs for IOMMU_DEVICE_GET_HW_INFO ioctl */ 206#define IOMMU_HW_INFO_TYPE_SELFTEST 0xfeedbeef 207#define IOMMU_HW_INFO_SELFTEST_REGVAL 0xdeadbeef 208 209struct iommu_test_hw_info { 210 __u32 flags; 211 __u32 test_reg; 212}; 213 214/* Should not be equal to any defined value in enum iommu_hwpt_data_type */ 215#define IOMMU_HWPT_DATA_SELFTEST 0xdead 216#define IOMMU_TEST_IOTLB_DEFAULT 0xbadbeef 217#define IOMMU_TEST_DEV_CACHE_DEFAULT 0xbaddad 218 219/** 220 * struct iommu_hwpt_selftest 221 * 222 * @iotlb: default mock iotlb value, IOMMU_TEST_IOTLB_DEFAULT 223 */ 224struct iommu_hwpt_selftest { 225 __u32 iotlb; 226 __u32 pagetable_type; 227}; 228 229/* Should not be equal to any defined value in enum iommu_hwpt_invalidate_data_type */ 230#define IOMMU_HWPT_INVALIDATE_DATA_SELFTEST 0xdeadbeef 231#define IOMMU_HWPT_INVALIDATE_DATA_SELFTEST_INVALID 0xdadbeef 232 233/** 234 * struct iommu_hwpt_invalidate_selftest - Invalidation data for Mock driver 235 * (IOMMU_HWPT_INVALIDATE_DATA_SELFTEST) 236 * @flags: Invalidate flags 237 * @iotlb_id: Invalidate iotlb entry index 238 * 239 * If IOMMU_TEST_INVALIDATE_ALL is set in @flags, @iotlb_id will be ignored 240 */ 241struct iommu_hwpt_invalidate_selftest { 242#define IOMMU_TEST_INVALIDATE_FLAG_ALL (1 << 0) 243 __u32 flags; 244 __u32 iotlb_id; 245}; 246 247#define IOMMU_VIOMMU_TYPE_SELFTEST 0xdeadbeef 248 249/** 250 * struct iommu_viommu_selftest - vIOMMU data for Mock driver 251 * (IOMMU_VIOMMU_TYPE_SELFTEST) 252 * @in_data: Input random data from user space 253 * @out_data: Output data (matching @in_data) to user space 254 * @out_mmap_offset: The offset argument for mmap syscall 255 * @out_mmap_length: The length argument for mmap syscall 256 * 257 * Simply set @out_data=@in_data for a loopback test 258 */ 259struct iommu_viommu_selftest { 260 __u32 in_data; 261 __u32 out_data; 262 __aligned_u64 out_mmap_offset; 263 __aligned_u64 out_mmap_length; 264}; 265 266/* Should not be equal to any defined value in enum iommu_viommu_invalidate_data_type */ 267#define IOMMU_VIOMMU_INVALIDATE_DATA_SELFTEST 0xdeadbeef 268#define IOMMU_VIOMMU_INVALIDATE_DATA_SELFTEST_INVALID 0xdadbeef 269 270/** 271 * struct iommu_viommu_invalidate_selftest - Invalidation data for Mock VIOMMU 272 * (IOMMU_VIOMMU_INVALIDATE_DATA_SELFTEST) 273 * @flags: Invalidate flags 274 * @cache_id: Invalidate cache entry index 275 * 276 * If IOMMU_TEST_INVALIDATE_ALL is set in @flags, @cache_id will be ignored 277 */ 278struct iommu_viommu_invalidate_selftest { 279#define IOMMU_TEST_INVALIDATE_FLAG_ALL (1 << 0) 280 __u32 flags; 281 __u32 vdev_id; 282 __u32 cache_id; 283}; 284 285#define IOMMU_VEVENTQ_TYPE_SELFTEST 0xbeefbeef 286 287struct iommu_viommu_event_selftest { 288 __u32 virt_id; 289}; 290 291#define IOMMU_HW_QUEUE_TYPE_SELFTEST 0xdeadbeef 292#define IOMMU_TEST_HW_QUEUE_MAX 2 293 294#endif
~/
Read-only file preview.