xref: /linux/drivers/iommu/iommufd/iommufd_test.h (revision 7f4f3b14e8079ecde096bd734af10e30d40c27b7)
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 
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 	IOMMU_TEST_OP_TRIGGER_IOPF,
26 	IOMMU_TEST_OP_DEV_CHECK_CACHE,
27 };
28 
29 enum {
30 	MOCK_APERTURE_START = 1UL << 24,
31 	MOCK_APERTURE_LAST = (1UL << 31) - 1,
32 };
33 
34 enum {
35 	MOCK_FLAGS_ACCESS_WRITE = 1 << 0,
36 	MOCK_FLAGS_ACCESS_SYZ = 1 << 16,
37 };
38 
39 enum {
40 	MOCK_ACCESS_RW_WRITE = 1 << 0,
41 	MOCK_ACCESS_RW_SLOW_PATH = 1 << 2,
42 };
43 
44 enum {
45 	MOCK_FLAGS_ACCESS_CREATE_NEEDS_PIN_PAGES = 1 << 0,
46 };
47 
48 enum {
49 	MOCK_FLAGS_DEVICE_NO_DIRTY = 1 << 0,
50 	MOCK_FLAGS_DEVICE_HUGE_IOVA = 1 << 1,
51 };
52 
53 enum {
54 	MOCK_NESTED_DOMAIN_IOTLB_ID_MAX = 3,
55 	MOCK_NESTED_DOMAIN_IOTLB_NUM = 4,
56 };
57 
58 enum {
59 	MOCK_DEV_CACHE_ID_MAX = 3,
60 	MOCK_DEV_CACHE_NUM = 4,
61 };
62 
63 struct iommu_test_cmd {
64 	__u32 size;
65 	__u32 op;
66 	__u32 id;
67 	__u32 __reserved;
68 	union {
69 		struct {
70 			__aligned_u64 start;
71 			__aligned_u64 length;
72 		} add_reserved;
73 		struct {
74 			__u32 out_stdev_id;
75 			__u32 out_hwpt_id;
76 			/* out_idev_id is the standard iommufd_bind object */
77 			__u32 out_idev_id;
78 		} mock_domain;
79 		struct {
80 			__u32 out_stdev_id;
81 			__u32 out_hwpt_id;
82 			__u32 out_idev_id;
83 			/* Expand mock_domain to set mock device flags */
84 			__u32 dev_flags;
85 		} mock_domain_flags;
86 		struct {
87 			__u32 pt_id;
88 		} mock_domain_replace;
89 		struct {
90 			__aligned_u64 iova;
91 			__aligned_u64 length;
92 			__aligned_u64 uptr;
93 		} check_map;
94 		struct {
95 			__aligned_u64 length;
96 			__aligned_u64 uptr;
97 			__u32 refs;
98 		} check_refs;
99 		struct {
100 			__u32 out_access_fd;
101 			__u32 flags;
102 		} create_access;
103 		struct {
104 			__u32 access_pages_id;
105 		} destroy_access_pages;
106 		struct {
107 			__u32 flags;
108 			__u32 out_access_pages_id;
109 			__aligned_u64 iova;
110 			__aligned_u64 length;
111 			__aligned_u64 uptr;
112 		} access_pages;
113 		struct {
114 			__aligned_u64 iova;
115 			__aligned_u64 length;
116 			__aligned_u64 uptr;
117 			__u32 flags;
118 		} access_rw;
119 		struct {
120 			__u32 limit;
121 		} memory_limit;
122 		struct {
123 			__u32 ioas_id;
124 		} access_replace_ioas;
125 		struct {
126 			__u32 flags;
127 			__aligned_u64 iova;
128 			__aligned_u64 length;
129 			__aligned_u64 page_size;
130 			__aligned_u64 uptr;
131 			__aligned_u64 out_nr_dirty;
132 		} dirty;
133 		struct {
134 			__u32 id;
135 			__u32 iotlb;
136 		} check_iotlb;
137 		struct {
138 			__u32 dev_id;
139 			__u32 pasid;
140 			__u32 grpid;
141 			__u32 perm;
142 			__u64 addr;
143 		} trigger_iopf;
144 		struct {
145 			__u32 id;
146 			__u32 cache;
147 		} check_dev_cache;
148 	};
149 	__u32 last;
150 };
151 #define IOMMU_TEST_CMD _IO(IOMMUFD_TYPE, IOMMUFD_CMD_BASE + 32)
152 
153 /* Mock structs for IOMMU_DEVICE_GET_HW_INFO ioctl */
154 #define IOMMU_HW_INFO_TYPE_SELFTEST	0xfeedbeef
155 #define IOMMU_HW_INFO_SELFTEST_REGVAL	0xdeadbeef
156 
157 struct iommu_test_hw_info {
158 	__u32 flags;
159 	__u32 test_reg;
160 };
161 
162 /* Should not be equal to any defined value in enum iommu_hwpt_data_type */
163 #define IOMMU_HWPT_DATA_SELFTEST 0xdead
164 #define IOMMU_TEST_IOTLB_DEFAULT 0xbadbeef
165 #define IOMMU_TEST_DEV_CACHE_DEFAULT 0xbaddad
166 
167 /**
168  * struct iommu_hwpt_selftest
169  *
170  * @iotlb: default mock iotlb value, IOMMU_TEST_IOTLB_DEFAULT
171  */
172 struct iommu_hwpt_selftest {
173 	__u32 iotlb;
174 };
175 
176 /* Should not be equal to any defined value in enum iommu_hwpt_invalidate_data_type */
177 #define IOMMU_HWPT_INVALIDATE_DATA_SELFTEST 0xdeadbeef
178 #define IOMMU_HWPT_INVALIDATE_DATA_SELFTEST_INVALID 0xdadbeef
179 
180 /**
181  * struct iommu_hwpt_invalidate_selftest - Invalidation data for Mock driver
182  *                                         (IOMMU_HWPT_INVALIDATE_DATA_SELFTEST)
183  * @flags: Invalidate flags
184  * @iotlb_id: Invalidate iotlb entry index
185  *
186  * If IOMMU_TEST_INVALIDATE_ALL is set in @flags, @iotlb_id will be ignored
187  */
188 struct iommu_hwpt_invalidate_selftest {
189 #define IOMMU_TEST_INVALIDATE_FLAG_ALL	(1 << 0)
190 	__u32 flags;
191 	__u32 iotlb_id;
192 };
193 
194 #define IOMMU_VIOMMU_TYPE_SELFTEST 0xdeadbeef
195 
196 /* Should not be equal to any defined value in enum iommu_viommu_invalidate_data_type */
197 #define IOMMU_VIOMMU_INVALIDATE_DATA_SELFTEST 0xdeadbeef
198 #define IOMMU_VIOMMU_INVALIDATE_DATA_SELFTEST_INVALID 0xdadbeef
199 
200 /**
201  * struct iommu_viommu_invalidate_selftest - Invalidation data for Mock VIOMMU
202  *                                        (IOMMU_VIOMMU_INVALIDATE_DATA_SELFTEST)
203  * @flags: Invalidate flags
204  * @cache_id: Invalidate cache entry index
205  *
206  * If IOMMU_TEST_INVALIDATE_ALL is set in @flags, @cache_id will be ignored
207  */
208 struct iommu_viommu_invalidate_selftest {
209 #define IOMMU_TEST_INVALIDATE_FLAG_ALL (1 << 0)
210 	__u32 flags;
211 	__u32 vdev_id;
212 	__u32 cache_id;
213 };
214 
215 #endif
216