xref: /linux/drivers/iommu/iommufd/iommufd_test.h (revision 55ec81f7517fad09135f65552cea0a3ee84fff30)
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 };
23 
24 enum {
25 	MOCK_APERTURE_START = 1UL << 24,
26 	MOCK_APERTURE_LAST = (1UL << 31) - 1,
27 };
28 
29 enum {
30 	MOCK_FLAGS_ACCESS_WRITE = 1 << 0,
31 	MOCK_FLAGS_ACCESS_SYZ = 1 << 16,
32 };
33 
34 enum {
35 	MOCK_ACCESS_RW_WRITE = 1 << 0,
36 	MOCK_ACCESS_RW_SLOW_PATH = 1 << 2,
37 };
38 
39 enum {
40 	MOCK_FLAGS_ACCESS_CREATE_NEEDS_PIN_PAGES = 1 << 0,
41 };
42 
43 struct iommu_test_cmd {
44 	__u32 size;
45 	__u32 op;
46 	__u32 id;
47 	__u32 __reserved;
48 	union {
49 		struct {
50 			__aligned_u64 start;
51 			__aligned_u64 length;
52 		} add_reserved;
53 		struct {
54 			__u32 out_stdev_id;
55 			__u32 out_hwpt_id;
56 			/* out_idev_id is the standard iommufd_bind object */
57 			__u32 out_idev_id;
58 		} mock_domain;
59 		struct {
60 			__u32 pt_id;
61 		} mock_domain_replace;
62 		struct {
63 			__aligned_u64 iova;
64 			__aligned_u64 length;
65 			__aligned_u64 uptr;
66 		} check_map;
67 		struct {
68 			__aligned_u64 length;
69 			__aligned_u64 uptr;
70 			__u32 refs;
71 		} check_refs;
72 		struct {
73 			__u32 out_access_fd;
74 			__u32 flags;
75 		} create_access;
76 		struct {
77 			__u32 access_pages_id;
78 		} destroy_access_pages;
79 		struct {
80 			__u32 flags;
81 			__u32 out_access_pages_id;
82 			__aligned_u64 iova;
83 			__aligned_u64 length;
84 			__aligned_u64 uptr;
85 		} access_pages;
86 		struct {
87 			__aligned_u64 iova;
88 			__aligned_u64 length;
89 			__aligned_u64 uptr;
90 			__u32 flags;
91 		} access_rw;
92 		struct {
93 			__u32 limit;
94 		} memory_limit;
95 		struct {
96 			__u32 ioas_id;
97 		} access_replace_ioas;
98 	};
99 	__u32 last;
100 };
101 #define IOMMU_TEST_CMD _IO(IOMMUFD_TYPE, IOMMUFD_CMD_BASE + 32)
102 
103 /* Mock structs for IOMMU_DEVICE_GET_HW_INFO ioctl */
104 #define IOMMU_HW_INFO_TYPE_SELFTEST	0xfeedbeef
105 #define IOMMU_HW_INFO_SELFTEST_REGVAL	0xdeadbeef
106 
107 struct iommu_test_hw_info {
108 	__u32 flags;
109 	__u32 test_reg;
110 };
111 
112 #endif
113