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