xref: /linux/include/uapi/linux/virtio_iommu.h (revision d9c5252295218df4cfe64353aa860d7b5c8700ef)
1 /* SPDX-License-Identifier: BSD-3-Clause */
2 /*
3  * Virtio-iommu definition v0.9
4  *
5  * Copyright (C) 2018 Arm Ltd.
6  */
7 #ifndef _UAPI_LINUX_VIRTIO_IOMMU_H
8 #define _UAPI_LINUX_VIRTIO_IOMMU_H
9 
10 #include <linux/types.h>
11 
12 /* Feature bits */
13 #define VIRTIO_IOMMU_F_INPUT_RANGE		0
14 #define VIRTIO_IOMMU_F_DOMAIN_BITS		1
15 #define VIRTIO_IOMMU_F_MAP_UNMAP		2
16 #define VIRTIO_IOMMU_F_BYPASS			3
17 #define VIRTIO_IOMMU_F_PROBE			4
18 
19 struct virtio_iommu_range {
20 	__u64					start;
21 	__u64					end;
22 };
23 
24 struct virtio_iommu_config {
25 	/* Supported page sizes */
26 	__u64					page_size_mask;
27 	/* Supported IOVA range */
28 	struct virtio_iommu_range		input_range;
29 	/* Max domain ID size */
30 	__u8					domain_bits;
31 	__u8					padding[3];
32 	/* Probe buffer size */
33 	__u32					probe_size;
34 };
35 
36 /* Request types */
37 #define VIRTIO_IOMMU_T_ATTACH			0x01
38 #define VIRTIO_IOMMU_T_DETACH			0x02
39 #define VIRTIO_IOMMU_T_MAP			0x03
40 #define VIRTIO_IOMMU_T_UNMAP			0x04
41 #define VIRTIO_IOMMU_T_PROBE			0x05
42 
43 /* Status types */
44 #define VIRTIO_IOMMU_S_OK			0x00
45 #define VIRTIO_IOMMU_S_IOERR			0x01
46 #define VIRTIO_IOMMU_S_UNSUPP			0x02
47 #define VIRTIO_IOMMU_S_DEVERR			0x03
48 #define VIRTIO_IOMMU_S_INVAL			0x04
49 #define VIRTIO_IOMMU_S_RANGE			0x05
50 #define VIRTIO_IOMMU_S_NOENT			0x06
51 #define VIRTIO_IOMMU_S_FAULT			0x07
52 
53 struct virtio_iommu_req_head {
54 	__u8					type;
55 	__u8					reserved[3];
56 };
57 
58 struct virtio_iommu_req_tail {
59 	__u8					status;
60 	__u8					reserved[3];
61 };
62 
63 struct virtio_iommu_req_attach {
64 	struct virtio_iommu_req_head		head;
65 	__le32					domain;
66 	__le32					endpoint;
67 	__u8					reserved[8];
68 	struct virtio_iommu_req_tail		tail;
69 };
70 
71 struct virtio_iommu_req_detach {
72 	struct virtio_iommu_req_head		head;
73 	__le32					domain;
74 	__le32					endpoint;
75 	__u8					reserved[8];
76 	struct virtio_iommu_req_tail		tail;
77 };
78 
79 #define VIRTIO_IOMMU_MAP_F_READ			(1 << 0)
80 #define VIRTIO_IOMMU_MAP_F_WRITE		(1 << 1)
81 #define VIRTIO_IOMMU_MAP_F_EXEC			(1 << 2)
82 #define VIRTIO_IOMMU_MAP_F_MMIO			(1 << 3)
83 
84 #define VIRTIO_IOMMU_MAP_F_MASK			(VIRTIO_IOMMU_MAP_F_READ |	\
85 						 VIRTIO_IOMMU_MAP_F_WRITE |	\
86 						 VIRTIO_IOMMU_MAP_F_EXEC |	\
87 						 VIRTIO_IOMMU_MAP_F_MMIO)
88 
89 struct virtio_iommu_req_map {
90 	struct virtio_iommu_req_head		head;
91 	__le32					domain;
92 	__le64					virt_start;
93 	__le64					virt_end;
94 	__le64					phys_start;
95 	__le32					flags;
96 	struct virtio_iommu_req_tail		tail;
97 };
98 
99 struct virtio_iommu_req_unmap {
100 	struct virtio_iommu_req_head		head;
101 	__le32					domain;
102 	__le64					virt_start;
103 	__le64					virt_end;
104 	__u8					reserved[4];
105 	struct virtio_iommu_req_tail		tail;
106 };
107 
108 #define VIRTIO_IOMMU_PROBE_T_NONE		0
109 #define VIRTIO_IOMMU_PROBE_T_RESV_MEM		1
110 
111 #define VIRTIO_IOMMU_PROBE_T_MASK		0xfff
112 
113 struct virtio_iommu_probe_property {
114 	__le16					type;
115 	__le16					length;
116 };
117 
118 #define VIRTIO_IOMMU_RESV_MEM_T_RESERVED	0
119 #define VIRTIO_IOMMU_RESV_MEM_T_MSI		1
120 
121 struct virtio_iommu_probe_resv_mem {
122 	struct virtio_iommu_probe_property	head;
123 	__u8					subtype;
124 	__u8					reserved[3];
125 	__le64					start;
126 	__le64					end;
127 };
128 
129 struct virtio_iommu_req_probe {
130 	struct virtio_iommu_req_head		head;
131 	__le32					endpoint;
132 	__u8					reserved[64];
133 
134 	__u8					properties[];
135 
136 	/*
137 	 * Tail follows the variable-length properties array. No padding,
138 	 * property lengths are all aligned on 8 bytes.
139 	 */
140 };
141 
142 /* Fault types */
143 #define VIRTIO_IOMMU_FAULT_R_UNKNOWN		0
144 #define VIRTIO_IOMMU_FAULT_R_DOMAIN		1
145 #define VIRTIO_IOMMU_FAULT_R_MAPPING		2
146 
147 #define VIRTIO_IOMMU_FAULT_F_READ		(1 << 0)
148 #define VIRTIO_IOMMU_FAULT_F_WRITE		(1 << 1)
149 #define VIRTIO_IOMMU_FAULT_F_EXEC		(1 << 2)
150 #define VIRTIO_IOMMU_FAULT_F_ADDRESS		(1 << 8)
151 
152 struct virtio_iommu_fault {
153 	__u8					reason;
154 	__u8					reserved[3];
155 	__le32					flags;
156 	__le32					endpoint;
157 	__u8					reserved2[4];
158 	__le64					address;
159 };
160 
161 #endif
162