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