1 /* SPDX-License-Identifier: GPL-2.0 WITH Linux-syscall-note */ 2 /* Copyright (c) 2021-2022, NVIDIA CORPORATION & AFFILIATES. 3 */ 4 #ifndef _UAPI_IOMMUFD_H 5 #define _UAPI_IOMMUFD_H 6 7 #include <linux/ioctl.h> 8 #include <linux/types.h> 9 10 #define IOMMUFD_TYPE (';') 11 12 /** 13 * DOC: General ioctl format 14 * 15 * The ioctl interface follows a general format to allow for extensibility. Each 16 * ioctl is passed in a structure pointer as the argument providing the size of 17 * the structure in the first u32. The kernel checks that any structure space 18 * beyond what it understands is 0. This allows userspace to use the backward 19 * compatible portion while consistently using the newer, larger, structures. 20 * 21 * ioctls use a standard meaning for common errnos: 22 * 23 * - ENOTTY: The IOCTL number itself is not supported at all 24 * - E2BIG: The IOCTL number is supported, but the provided structure has 25 * non-zero in a part the kernel does not understand. 26 * - EOPNOTSUPP: The IOCTL number is supported, and the structure is 27 * understood, however a known field has a value the kernel does not 28 * understand or support. 29 * - EINVAL: Everything about the IOCTL was understood, but a field is not 30 * correct. 31 * - ENOENT: An ID or IOVA provided does not exist. 32 * - ENOMEM: Out of memory. 33 * - EOVERFLOW: Mathematics overflowed. 34 * 35 * As well as additional errnos, within specific ioctls. 36 */ 37 enum { 38 IOMMUFD_CMD_BASE = 0x80, 39 IOMMUFD_CMD_DESTROY = IOMMUFD_CMD_BASE, 40 IOMMUFD_CMD_IOAS_ALLOC = 0x81, 41 IOMMUFD_CMD_IOAS_ALLOW_IOVAS = 0x82, 42 IOMMUFD_CMD_IOAS_COPY = 0x83, 43 IOMMUFD_CMD_IOAS_IOVA_RANGES = 0x84, 44 IOMMUFD_CMD_IOAS_MAP = 0x85, 45 IOMMUFD_CMD_IOAS_UNMAP = 0x86, 46 IOMMUFD_CMD_OPTION = 0x87, 47 IOMMUFD_CMD_VFIO_IOAS = 0x88, 48 IOMMUFD_CMD_HWPT_ALLOC = 0x89, 49 IOMMUFD_CMD_GET_HW_INFO = 0x8a, 50 IOMMUFD_CMD_HWPT_SET_DIRTY_TRACKING = 0x8b, 51 IOMMUFD_CMD_HWPT_GET_DIRTY_BITMAP = 0x8c, 52 IOMMUFD_CMD_HWPT_INVALIDATE = 0x8d, 53 IOMMUFD_CMD_FAULT_QUEUE_ALLOC = 0x8e, 54 IOMMUFD_CMD_IOAS_MAP_FILE = 0x8f, 55 IOMMUFD_CMD_VIOMMU_ALLOC = 0x90, 56 IOMMUFD_CMD_VDEVICE_ALLOC = 0x91, 57 IOMMUFD_CMD_IOAS_CHANGE_PROCESS = 0x92, 58 IOMMUFD_CMD_VEVENTQ_ALLOC = 0x93, 59 }; 60 61 /** 62 * struct iommu_destroy - ioctl(IOMMU_DESTROY) 63 * @size: sizeof(struct iommu_destroy) 64 * @id: iommufd object ID to destroy. Can be any destroyable object type. 65 * 66 * Destroy any object held within iommufd. 67 */ 68 struct iommu_destroy { 69 __u32 size; 70 __u32 id; 71 }; 72 #define IOMMU_DESTROY _IO(IOMMUFD_TYPE, IOMMUFD_CMD_DESTROY) 73 74 /** 75 * struct iommu_ioas_alloc - ioctl(IOMMU_IOAS_ALLOC) 76 * @size: sizeof(struct iommu_ioas_alloc) 77 * @flags: Must be 0 78 * @out_ioas_id: Output IOAS ID for the allocated object 79 * 80 * Allocate an IO Address Space (IOAS) which holds an IO Virtual Address (IOVA) 81 * to memory mapping. 82 */ 83 struct iommu_ioas_alloc { 84 __u32 size; 85 __u32 flags; 86 __u32 out_ioas_id; 87 }; 88 #define IOMMU_IOAS_ALLOC _IO(IOMMUFD_TYPE, IOMMUFD_CMD_IOAS_ALLOC) 89 90 /** 91 * struct iommu_iova_range - ioctl(IOMMU_IOVA_RANGE) 92 * @start: First IOVA 93 * @last: Inclusive last IOVA 94 * 95 * An interval in IOVA space. 96 */ 97 struct iommu_iova_range { 98 __aligned_u64 start; 99 __aligned_u64 last; 100 }; 101 102 /** 103 * struct iommu_ioas_iova_ranges - ioctl(IOMMU_IOAS_IOVA_RANGES) 104 * @size: sizeof(struct iommu_ioas_iova_ranges) 105 * @ioas_id: IOAS ID to read ranges from 106 * @num_iovas: Input/Output total number of ranges in the IOAS 107 * @__reserved: Must be 0 108 * @allowed_iovas: Pointer to the output array of struct iommu_iova_range 109 * @out_iova_alignment: Minimum alignment required for mapping IOVA 110 * 111 * Query an IOAS for ranges of allowed IOVAs. Mapping IOVA outside these ranges 112 * is not allowed. num_iovas will be set to the total number of iovas and 113 * the allowed_iovas[] will be filled in as space permits. 114 * 115 * The allowed ranges are dependent on the HW path the DMA operation takes, and 116 * can change during the lifetime of the IOAS. A fresh empty IOAS will have a 117 * full range, and each attached device will narrow the ranges based on that 118 * device's HW restrictions. Detaching a device can widen the ranges. Userspace 119 * should query ranges after every attach/detach to know what IOVAs are valid 120 * for mapping. 121 * 122 * On input num_iovas is the length of the allowed_iovas array. On output it is 123 * the total number of iovas filled in. The ioctl will return -EMSGSIZE and set 124 * num_iovas to the required value if num_iovas is too small. In this case the 125 * caller should allocate a larger output array and re-issue the ioctl. 126 * 127 * out_iova_alignment returns the minimum IOVA alignment that can be given 128 * to IOMMU_IOAS_MAP/COPY. IOVA's must satisfy:: 129 * 130 * starting_iova % out_iova_alignment == 0 131 * (starting_iova + length) % out_iova_alignment == 0 132 * 133 * out_iova_alignment can be 1 indicating any IOVA is allowed. It cannot 134 * be higher than the system PAGE_SIZE. 135 */ 136 struct iommu_ioas_iova_ranges { 137 __u32 size; 138 __u32 ioas_id; 139 __u32 num_iovas; 140 __u32 __reserved; 141 __aligned_u64 allowed_iovas; 142 __aligned_u64 out_iova_alignment; 143 }; 144 #define IOMMU_IOAS_IOVA_RANGES _IO(IOMMUFD_TYPE, IOMMUFD_CMD_IOAS_IOVA_RANGES) 145 146 /** 147 * struct iommu_ioas_allow_iovas - ioctl(IOMMU_IOAS_ALLOW_IOVAS) 148 * @size: sizeof(struct iommu_ioas_allow_iovas) 149 * @ioas_id: IOAS ID to allow IOVAs from 150 * @num_iovas: Input/Output total number of ranges in the IOAS 151 * @__reserved: Must be 0 152 * @allowed_iovas: Pointer to array of struct iommu_iova_range 153 * 154 * Ensure a range of IOVAs are always available for allocation. If this call 155 * succeeds then IOMMU_IOAS_IOVA_RANGES will never return a list of IOVA ranges 156 * that are narrower than the ranges provided here. This call will fail if 157 * IOMMU_IOAS_IOVA_RANGES is currently narrower than the given ranges. 158 * 159 * When an IOAS is first created the IOVA_RANGES will be maximally sized, and as 160 * devices are attached the IOVA will narrow based on the device restrictions. 161 * When an allowed range is specified any narrowing will be refused, ie device 162 * attachment can fail if the device requires limiting within the allowed range. 163 * 164 * Automatic IOVA allocation is also impacted by this call. MAP will only 165 * allocate within the allowed IOVAs if they are present. 166 * 167 * This call replaces the entire allowed list with the given list. 168 */ 169 struct iommu_ioas_allow_iovas { 170 __u32 size; 171 __u32 ioas_id; 172 __u32 num_iovas; 173 __u32 __reserved; 174 __aligned_u64 allowed_iovas; 175 }; 176 #define IOMMU_IOAS_ALLOW_IOVAS _IO(IOMMUFD_TYPE, IOMMUFD_CMD_IOAS_ALLOW_IOVAS) 177 178 /** 179 * enum iommufd_ioas_map_flags - Flags for map and copy 180 * @IOMMU_IOAS_MAP_FIXED_IOVA: If clear the kernel will compute an appropriate 181 * IOVA to place the mapping at 182 * @IOMMU_IOAS_MAP_WRITEABLE: DMA is allowed to write to this mapping 183 * @IOMMU_IOAS_MAP_READABLE: DMA is allowed to read from this mapping 184 */ 185 enum iommufd_ioas_map_flags { 186 IOMMU_IOAS_MAP_FIXED_IOVA = 1 << 0, 187 IOMMU_IOAS_MAP_WRITEABLE = 1 << 1, 188 IOMMU_IOAS_MAP_READABLE = 1 << 2, 189 }; 190 191 /** 192 * struct iommu_ioas_map - ioctl(IOMMU_IOAS_MAP) 193 * @size: sizeof(struct iommu_ioas_map) 194 * @flags: Combination of enum iommufd_ioas_map_flags 195 * @ioas_id: IOAS ID to change the mapping of 196 * @__reserved: Must be 0 197 * @user_va: Userspace pointer to start mapping from 198 * @length: Number of bytes to map 199 * @iova: IOVA the mapping was placed at. If IOMMU_IOAS_MAP_FIXED_IOVA is set 200 * then this must be provided as input. 201 * 202 * Set an IOVA mapping from a user pointer. If FIXED_IOVA is specified then the 203 * mapping will be established at iova, otherwise a suitable location based on 204 * the reserved and allowed lists will be automatically selected and returned in 205 * iova. 206 * 207 * If IOMMU_IOAS_MAP_FIXED_IOVA is specified then the iova range must currently 208 * be unused, existing IOVA cannot be replaced. 209 */ 210 struct iommu_ioas_map { 211 __u32 size; 212 __u32 flags; 213 __u32 ioas_id; 214 __u32 __reserved; 215 __aligned_u64 user_va; 216 __aligned_u64 length; 217 __aligned_u64 iova; 218 }; 219 #define IOMMU_IOAS_MAP _IO(IOMMUFD_TYPE, IOMMUFD_CMD_IOAS_MAP) 220 221 /** 222 * struct iommu_ioas_map_file - ioctl(IOMMU_IOAS_MAP_FILE) 223 * @size: sizeof(struct iommu_ioas_map_file) 224 * @flags: same as for iommu_ioas_map 225 * @ioas_id: same as for iommu_ioas_map 226 * @fd: the memfd to map 227 * @start: byte offset from start of file to map from 228 * @length: same as for iommu_ioas_map 229 * @iova: same as for iommu_ioas_map 230 * 231 * Set an IOVA mapping from a memfd file. All other arguments and semantics 232 * match those of IOMMU_IOAS_MAP. 233 */ 234 struct iommu_ioas_map_file { 235 __u32 size; 236 __u32 flags; 237 __u32 ioas_id; 238 __s32 fd; 239 __aligned_u64 start; 240 __aligned_u64 length; 241 __aligned_u64 iova; 242 }; 243 #define IOMMU_IOAS_MAP_FILE _IO(IOMMUFD_TYPE, IOMMUFD_CMD_IOAS_MAP_FILE) 244 245 /** 246 * struct iommu_ioas_copy - ioctl(IOMMU_IOAS_COPY) 247 * @size: sizeof(struct iommu_ioas_copy) 248 * @flags: Combination of enum iommufd_ioas_map_flags 249 * @dst_ioas_id: IOAS ID to change the mapping of 250 * @src_ioas_id: IOAS ID to copy from 251 * @length: Number of bytes to copy and map 252 * @dst_iova: IOVA the mapping was placed at. If IOMMU_IOAS_MAP_FIXED_IOVA is 253 * set then this must be provided as input. 254 * @src_iova: IOVA to start the copy 255 * 256 * Copy an already existing mapping from src_ioas_id and establish it in 257 * dst_ioas_id. The src iova/length must exactly match a range used with 258 * IOMMU_IOAS_MAP. 259 * 260 * This may be used to efficiently clone a subset of an IOAS to another, or as a 261 * kind of 'cache' to speed up mapping. Copy has an efficiency advantage over 262 * establishing equivalent new mappings, as internal resources are shared, and 263 * the kernel will pin the user memory only once. 264 */ 265 struct iommu_ioas_copy { 266 __u32 size; 267 __u32 flags; 268 __u32 dst_ioas_id; 269 __u32 src_ioas_id; 270 __aligned_u64 length; 271 __aligned_u64 dst_iova; 272 __aligned_u64 src_iova; 273 }; 274 #define IOMMU_IOAS_COPY _IO(IOMMUFD_TYPE, IOMMUFD_CMD_IOAS_COPY) 275 276 /** 277 * struct iommu_ioas_unmap - ioctl(IOMMU_IOAS_UNMAP) 278 * @size: sizeof(struct iommu_ioas_unmap) 279 * @ioas_id: IOAS ID to change the mapping of 280 * @iova: IOVA to start the unmapping at 281 * @length: Number of bytes to unmap, and return back the bytes unmapped 282 * 283 * Unmap an IOVA range. The iova/length must be a superset of a previously 284 * mapped range used with IOMMU_IOAS_MAP or IOMMU_IOAS_COPY. Splitting or 285 * truncating ranges is not allowed. The values 0 to U64_MAX will unmap 286 * everything. 287 */ 288 struct iommu_ioas_unmap { 289 __u32 size; 290 __u32 ioas_id; 291 __aligned_u64 iova; 292 __aligned_u64 length; 293 }; 294 #define IOMMU_IOAS_UNMAP _IO(IOMMUFD_TYPE, IOMMUFD_CMD_IOAS_UNMAP) 295 296 /** 297 * enum iommufd_option - ioctl(IOMMU_OPTION_RLIMIT_MODE) and 298 * ioctl(IOMMU_OPTION_HUGE_PAGES) 299 * @IOMMU_OPTION_RLIMIT_MODE: 300 * Change how RLIMIT_MEMLOCK accounting works. The caller must have privilege 301 * to invoke this. Value 0 (default) is user based accounting, 1 uses process 302 * based accounting. Global option, object_id must be 0 303 * @IOMMU_OPTION_HUGE_PAGES: 304 * Value 1 (default) allows contiguous pages to be combined when generating 305 * iommu mappings. Value 0 disables combining, everything is mapped to 306 * PAGE_SIZE. This can be useful for benchmarking. This is a per-IOAS 307 * option, the object_id must be the IOAS ID. 308 */ 309 enum iommufd_option { 310 IOMMU_OPTION_RLIMIT_MODE = 0, 311 IOMMU_OPTION_HUGE_PAGES = 1, 312 }; 313 314 /** 315 * enum iommufd_option_ops - ioctl(IOMMU_OPTION_OP_SET) and 316 * ioctl(IOMMU_OPTION_OP_GET) 317 * @IOMMU_OPTION_OP_SET: Set the option's value 318 * @IOMMU_OPTION_OP_GET: Get the option's value 319 */ 320 enum iommufd_option_ops { 321 IOMMU_OPTION_OP_SET = 0, 322 IOMMU_OPTION_OP_GET = 1, 323 }; 324 325 /** 326 * struct iommu_option - iommu option multiplexer 327 * @size: sizeof(struct iommu_option) 328 * @option_id: One of enum iommufd_option 329 * @op: One of enum iommufd_option_ops 330 * @__reserved: Must be 0 331 * @object_id: ID of the object if required 332 * @val64: Option value to set or value returned on get 333 * 334 * Change a simple option value. This multiplexor allows controlling options 335 * on objects. IOMMU_OPTION_OP_SET will load an option and IOMMU_OPTION_OP_GET 336 * will return the current value. 337 */ 338 struct iommu_option { 339 __u32 size; 340 __u32 option_id; 341 __u16 op; 342 __u16 __reserved; 343 __u32 object_id; 344 __aligned_u64 val64; 345 }; 346 #define IOMMU_OPTION _IO(IOMMUFD_TYPE, IOMMUFD_CMD_OPTION) 347 348 /** 349 * enum iommufd_vfio_ioas_op - IOMMU_VFIO_IOAS_* ioctls 350 * @IOMMU_VFIO_IOAS_GET: Get the current compatibility IOAS 351 * @IOMMU_VFIO_IOAS_SET: Change the current compatibility IOAS 352 * @IOMMU_VFIO_IOAS_CLEAR: Disable VFIO compatibility 353 */ 354 enum iommufd_vfio_ioas_op { 355 IOMMU_VFIO_IOAS_GET = 0, 356 IOMMU_VFIO_IOAS_SET = 1, 357 IOMMU_VFIO_IOAS_CLEAR = 2, 358 }; 359 360 /** 361 * struct iommu_vfio_ioas - ioctl(IOMMU_VFIO_IOAS) 362 * @size: sizeof(struct iommu_vfio_ioas) 363 * @ioas_id: For IOMMU_VFIO_IOAS_SET the input IOAS ID to set 364 * For IOMMU_VFIO_IOAS_GET will output the IOAS ID 365 * @op: One of enum iommufd_vfio_ioas_op 366 * @__reserved: Must be 0 367 * 368 * The VFIO compatibility support uses a single ioas because VFIO APIs do not 369 * support the ID field. Set or Get the IOAS that VFIO compatibility will use. 370 * When VFIO_GROUP_SET_CONTAINER is used on an iommufd it will get the 371 * compatibility ioas, either by taking what is already set, or auto creating 372 * one. From then on VFIO will continue to use that ioas and is not effected by 373 * this ioctl. SET or CLEAR does not destroy any auto-created IOAS. 374 */ 375 struct iommu_vfio_ioas { 376 __u32 size; 377 __u32 ioas_id; 378 __u16 op; 379 __u16 __reserved; 380 }; 381 #define IOMMU_VFIO_IOAS _IO(IOMMUFD_TYPE, IOMMUFD_CMD_VFIO_IOAS) 382 383 /** 384 * enum iommufd_hwpt_alloc_flags - Flags for HWPT allocation 385 * @IOMMU_HWPT_ALLOC_NEST_PARENT: If set, allocate a HWPT that can serve as 386 * the parent HWPT in a nesting configuration. 387 * @IOMMU_HWPT_ALLOC_DIRTY_TRACKING: Dirty tracking support for device IOMMU is 388 * enforced on device attachment 389 * @IOMMU_HWPT_FAULT_ID_VALID: The fault_id field of hwpt allocation data is 390 * valid. 391 * @IOMMU_HWPT_ALLOC_PASID: Requests a domain that can be used with PASID. The 392 * domain can be attached to any PASID on the device. 393 * Any domain attached to the non-PASID part of the 394 * device must also be flagged, otherwise attaching a 395 * PASID will blocked. 396 * For the user that wants to attach PASID, ioas is 397 * not recommended for both the non-PASID part 398 * and PASID part of the device. 399 * If IOMMU does not support PASID it will return 400 * error (-EOPNOTSUPP). 401 */ 402 enum iommufd_hwpt_alloc_flags { 403 IOMMU_HWPT_ALLOC_NEST_PARENT = 1 << 0, 404 IOMMU_HWPT_ALLOC_DIRTY_TRACKING = 1 << 1, 405 IOMMU_HWPT_FAULT_ID_VALID = 1 << 2, 406 IOMMU_HWPT_ALLOC_PASID = 1 << 3, 407 }; 408 409 /** 410 * enum iommu_hwpt_vtd_s1_flags - Intel VT-d stage-1 page table 411 * entry attributes 412 * @IOMMU_VTD_S1_SRE: Supervisor request 413 * @IOMMU_VTD_S1_EAFE: Extended access enable 414 * @IOMMU_VTD_S1_WPE: Write protect enable 415 */ 416 enum iommu_hwpt_vtd_s1_flags { 417 IOMMU_VTD_S1_SRE = 1 << 0, 418 IOMMU_VTD_S1_EAFE = 1 << 1, 419 IOMMU_VTD_S1_WPE = 1 << 2, 420 }; 421 422 /** 423 * struct iommu_hwpt_vtd_s1 - Intel VT-d stage-1 page table 424 * info (IOMMU_HWPT_DATA_VTD_S1) 425 * @flags: Combination of enum iommu_hwpt_vtd_s1_flags 426 * @pgtbl_addr: The base address of the stage-1 page table. 427 * @addr_width: The address width of the stage-1 page table 428 * @__reserved: Must be 0 429 */ 430 struct iommu_hwpt_vtd_s1 { 431 __aligned_u64 flags; 432 __aligned_u64 pgtbl_addr; 433 __u32 addr_width; 434 __u32 __reserved; 435 }; 436 437 /** 438 * struct iommu_hwpt_arm_smmuv3 - ARM SMMUv3 nested STE 439 * (IOMMU_HWPT_DATA_ARM_SMMUV3) 440 * 441 * @ste: The first two double words of the user space Stream Table Entry for 442 * the translation. Must be little-endian. 443 * Allowed fields: (Refer to "5.2 Stream Table Entry" in SMMUv3 HW Spec) 444 * - word-0: V, Cfg, S1Fmt, S1ContextPtr, S1CDMax 445 * - word-1: EATS, S1DSS, S1CIR, S1COR, S1CSH, S1STALLD 446 * 447 * -EIO will be returned if @ste is not legal or contains any non-allowed field. 448 * Cfg can be used to select a S1, Bypass or Abort configuration. A Bypass 449 * nested domain will translate the same as the nesting parent. The S1 will 450 * install a Context Descriptor Table pointing at userspace memory translated 451 * by the nesting parent. 452 */ 453 struct iommu_hwpt_arm_smmuv3 { 454 __aligned_le64 ste[2]; 455 }; 456 457 /** 458 * enum iommu_hwpt_data_type - IOMMU HWPT Data Type 459 * @IOMMU_HWPT_DATA_NONE: no data 460 * @IOMMU_HWPT_DATA_VTD_S1: Intel VT-d stage-1 page table 461 * @IOMMU_HWPT_DATA_ARM_SMMUV3: ARM SMMUv3 Context Descriptor Table 462 */ 463 enum iommu_hwpt_data_type { 464 IOMMU_HWPT_DATA_NONE = 0, 465 IOMMU_HWPT_DATA_VTD_S1 = 1, 466 IOMMU_HWPT_DATA_ARM_SMMUV3 = 2, 467 }; 468 469 /** 470 * struct iommu_hwpt_alloc - ioctl(IOMMU_HWPT_ALLOC) 471 * @size: sizeof(struct iommu_hwpt_alloc) 472 * @flags: Combination of enum iommufd_hwpt_alloc_flags 473 * @dev_id: The device to allocate this HWPT for 474 * @pt_id: The IOAS or HWPT or vIOMMU to connect this HWPT to 475 * @out_hwpt_id: The ID of the new HWPT 476 * @__reserved: Must be 0 477 * @data_type: One of enum iommu_hwpt_data_type 478 * @data_len: Length of the type specific data 479 * @data_uptr: User pointer to the type specific data 480 * @fault_id: The ID of IOMMUFD_FAULT object. Valid only if flags field of 481 * IOMMU_HWPT_FAULT_ID_VALID is set. 482 * @__reserved2: Padding to 64-bit alignment. Must be 0. 483 * 484 * Explicitly allocate a hardware page table object. This is the same object 485 * type that is returned by iommufd_device_attach() and represents the 486 * underlying iommu driver's iommu_domain kernel object. 487 * 488 * A kernel-managed HWPT will be created with the mappings from the given 489 * IOAS via the @pt_id. The @data_type for this allocation must be set to 490 * IOMMU_HWPT_DATA_NONE. The HWPT can be allocated as a parent HWPT for a 491 * nesting configuration by passing IOMMU_HWPT_ALLOC_NEST_PARENT via @flags. 492 * 493 * A user-managed nested HWPT will be created from a given vIOMMU (wrapping a 494 * parent HWPT) or a parent HWPT via @pt_id, in which the parent HWPT must be 495 * allocated previously via the same ioctl from a given IOAS (@pt_id). In this 496 * case, the @data_type must be set to a pre-defined type corresponding to an 497 * I/O page table type supported by the underlying IOMMU hardware. The device 498 * via @dev_id and the vIOMMU via @pt_id must be associated to the same IOMMU 499 * instance. 500 * 501 * If the @data_type is set to IOMMU_HWPT_DATA_NONE, @data_len and 502 * @data_uptr should be zero. Otherwise, both @data_len and @data_uptr 503 * must be given. 504 */ 505 struct iommu_hwpt_alloc { 506 __u32 size; 507 __u32 flags; 508 __u32 dev_id; 509 __u32 pt_id; 510 __u32 out_hwpt_id; 511 __u32 __reserved; 512 __u32 data_type; 513 __u32 data_len; 514 __aligned_u64 data_uptr; 515 __u32 fault_id; 516 __u32 __reserved2; 517 }; 518 #define IOMMU_HWPT_ALLOC _IO(IOMMUFD_TYPE, IOMMUFD_CMD_HWPT_ALLOC) 519 520 /** 521 * enum iommu_hw_info_vtd_flags - Flags for VT-d hw_info 522 * @IOMMU_HW_INFO_VTD_ERRATA_772415_SPR17: If set, disallow read-only mappings 523 * on a nested_parent domain. 524 * https://www.intel.com/content/www/us/en/content-details/772415/content-details.html 525 */ 526 enum iommu_hw_info_vtd_flags { 527 IOMMU_HW_INFO_VTD_ERRATA_772415_SPR17 = 1 << 0, 528 }; 529 530 /** 531 * struct iommu_hw_info_vtd - Intel VT-d hardware information 532 * 533 * @flags: Combination of enum iommu_hw_info_vtd_flags 534 * @__reserved: Must be 0 535 * 536 * @cap_reg: Value of Intel VT-d capability register defined in VT-d spec 537 * section 11.4.2 Capability Register. 538 * @ecap_reg: Value of Intel VT-d capability register defined in VT-d spec 539 * section 11.4.3 Extended Capability Register. 540 * 541 * User needs to understand the Intel VT-d specification to decode the 542 * register value. 543 */ 544 struct iommu_hw_info_vtd { 545 __u32 flags; 546 __u32 __reserved; 547 __aligned_u64 cap_reg; 548 __aligned_u64 ecap_reg; 549 }; 550 551 /** 552 * struct iommu_hw_info_arm_smmuv3 - ARM SMMUv3 hardware information 553 * (IOMMU_HW_INFO_TYPE_ARM_SMMUV3) 554 * 555 * @flags: Must be set to 0 556 * @__reserved: Must be 0 557 * @idr: Implemented features for ARM SMMU Non-secure programming interface 558 * @iidr: Information about the implementation and implementer of ARM SMMU, 559 * and architecture version supported 560 * @aidr: ARM SMMU architecture version 561 * 562 * For the details of @idr, @iidr and @aidr, please refer to the chapters 563 * from 6.3.1 to 6.3.6 in the SMMUv3 Spec. 564 * 565 * This reports the raw HW capability, and not all bits are meaningful to be 566 * read by userspace. Only the following fields should be used: 567 * 568 * idr[0]: ST_LEVEL, TERM_MODEL, STALL_MODEL, TTENDIAN , CD2L, ASID16, TTF 569 * idr[1]: SIDSIZE, SSIDSIZE 570 * idr[3]: BBML, RIL 571 * idr[5]: VAX, GRAN64K, GRAN16K, GRAN4K 572 * 573 * - S1P should be assumed to be true if a NESTED HWPT can be created 574 * - VFIO/iommufd only support platforms with COHACC, it should be assumed to be 575 * true. 576 * - ATS is a per-device property. If the VMM describes any devices as ATS 577 * capable in ACPI/DT it should set the corresponding idr. 578 * 579 * This list may expand in future (eg E0PD, AIE, PBHA, D128, DS etc). It is 580 * important that VMMs do not read bits outside the list to allow for 581 * compatibility with future kernels. Several features in the SMMUv3 582 * architecture are not currently supported by the kernel for nesting: HTTU, 583 * BTM, MPAM and others. 584 */ 585 struct iommu_hw_info_arm_smmuv3 { 586 __u32 flags; 587 __u32 __reserved; 588 __u32 idr[6]; 589 __u32 iidr; 590 __u32 aidr; 591 }; 592 593 /** 594 * enum iommu_hw_info_type - IOMMU Hardware Info Types 595 * @IOMMU_HW_INFO_TYPE_NONE: Used by the drivers that do not report hardware 596 * info 597 * @IOMMU_HW_INFO_TYPE_INTEL_VTD: Intel VT-d iommu info type 598 * @IOMMU_HW_INFO_TYPE_ARM_SMMUV3: ARM SMMUv3 iommu info type 599 */ 600 enum iommu_hw_info_type { 601 IOMMU_HW_INFO_TYPE_NONE = 0, 602 IOMMU_HW_INFO_TYPE_INTEL_VTD = 1, 603 IOMMU_HW_INFO_TYPE_ARM_SMMUV3 = 2, 604 }; 605 606 /** 607 * enum iommufd_hw_capabilities 608 * @IOMMU_HW_CAP_DIRTY_TRACKING: IOMMU hardware support for dirty tracking 609 * If available, it means the following APIs 610 * are supported: 611 * 612 * IOMMU_HWPT_GET_DIRTY_BITMAP 613 * IOMMU_HWPT_SET_DIRTY_TRACKING 614 * 615 */ 616 enum iommufd_hw_capabilities { 617 IOMMU_HW_CAP_DIRTY_TRACKING = 1 << 0, 618 }; 619 620 /** 621 * struct iommu_hw_info - ioctl(IOMMU_GET_HW_INFO) 622 * @size: sizeof(struct iommu_hw_info) 623 * @flags: Must be 0 624 * @dev_id: The device bound to the iommufd 625 * @data_len: Input the length of a user buffer in bytes. Output the length of 626 * data that kernel supports 627 * @data_uptr: User pointer to a user-space buffer used by the kernel to fill 628 * the iommu type specific hardware information data 629 * @out_data_type: Output the iommu hardware info type as defined in the enum 630 * iommu_hw_info_type. 631 * @out_capabilities: Output the generic iommu capability info type as defined 632 * in the enum iommu_hw_capabilities. 633 * @__reserved: Must be 0 634 * 635 * Query an iommu type specific hardware information data from an iommu behind 636 * a given device that has been bound to iommufd. This hardware info data will 637 * be used to sync capabilities between the virtual iommu and the physical 638 * iommu, e.g. a nested translation setup needs to check the hardware info, so 639 * a guest stage-1 page table can be compatible with the physical iommu. 640 * 641 * To capture an iommu type specific hardware information data, @data_uptr and 642 * its length @data_len must be provided. Trailing bytes will be zeroed if the 643 * user buffer is larger than the data that kernel has. Otherwise, kernel only 644 * fills the buffer using the given length in @data_len. If the ioctl succeeds, 645 * @data_len will be updated to the length that kernel actually supports, 646 * @out_data_type will be filled to decode the data filled in the buffer 647 * pointed by @data_uptr. Input @data_len == zero is allowed. 648 */ 649 struct iommu_hw_info { 650 __u32 size; 651 __u32 flags; 652 __u32 dev_id; 653 __u32 data_len; 654 __aligned_u64 data_uptr; 655 __u32 out_data_type; 656 __u32 __reserved; 657 __aligned_u64 out_capabilities; 658 }; 659 #define IOMMU_GET_HW_INFO _IO(IOMMUFD_TYPE, IOMMUFD_CMD_GET_HW_INFO) 660 661 /* 662 * enum iommufd_hwpt_set_dirty_tracking_flags - Flags for steering dirty 663 * tracking 664 * @IOMMU_HWPT_DIRTY_TRACKING_ENABLE: Enable dirty tracking 665 */ 666 enum iommufd_hwpt_set_dirty_tracking_flags { 667 IOMMU_HWPT_DIRTY_TRACKING_ENABLE = 1, 668 }; 669 670 /** 671 * struct iommu_hwpt_set_dirty_tracking - ioctl(IOMMU_HWPT_SET_DIRTY_TRACKING) 672 * @size: sizeof(struct iommu_hwpt_set_dirty_tracking) 673 * @flags: Combination of enum iommufd_hwpt_set_dirty_tracking_flags 674 * @hwpt_id: HW pagetable ID that represents the IOMMU domain 675 * @__reserved: Must be 0 676 * 677 * Toggle dirty tracking on an HW pagetable. 678 */ 679 struct iommu_hwpt_set_dirty_tracking { 680 __u32 size; 681 __u32 flags; 682 __u32 hwpt_id; 683 __u32 __reserved; 684 }; 685 #define IOMMU_HWPT_SET_DIRTY_TRACKING _IO(IOMMUFD_TYPE, \ 686 IOMMUFD_CMD_HWPT_SET_DIRTY_TRACKING) 687 688 /** 689 * enum iommufd_hwpt_get_dirty_bitmap_flags - Flags for getting dirty bits 690 * @IOMMU_HWPT_GET_DIRTY_BITMAP_NO_CLEAR: Just read the PTEs without clearing 691 * any dirty bits metadata. This flag 692 * can be passed in the expectation 693 * where the next operation is an unmap 694 * of the same IOVA range. 695 * 696 */ 697 enum iommufd_hwpt_get_dirty_bitmap_flags { 698 IOMMU_HWPT_GET_DIRTY_BITMAP_NO_CLEAR = 1, 699 }; 700 701 /** 702 * struct iommu_hwpt_get_dirty_bitmap - ioctl(IOMMU_HWPT_GET_DIRTY_BITMAP) 703 * @size: sizeof(struct iommu_hwpt_get_dirty_bitmap) 704 * @hwpt_id: HW pagetable ID that represents the IOMMU domain 705 * @flags: Combination of enum iommufd_hwpt_get_dirty_bitmap_flags 706 * @__reserved: Must be 0 707 * @iova: base IOVA of the bitmap first bit 708 * @length: IOVA range size 709 * @page_size: page size granularity of each bit in the bitmap 710 * @data: bitmap where to set the dirty bits. The bitmap bits each 711 * represent a page_size which you deviate from an arbitrary iova. 712 * 713 * Checking a given IOVA is dirty: 714 * 715 * data[(iova / page_size) / 64] & (1ULL << ((iova / page_size) % 64)) 716 * 717 * Walk the IOMMU pagetables for a given IOVA range to return a bitmap 718 * with the dirty IOVAs. In doing so it will also by default clear any 719 * dirty bit metadata set in the IOPTE. 720 */ 721 struct iommu_hwpt_get_dirty_bitmap { 722 __u32 size; 723 __u32 hwpt_id; 724 __u32 flags; 725 __u32 __reserved; 726 __aligned_u64 iova; 727 __aligned_u64 length; 728 __aligned_u64 page_size; 729 __aligned_u64 data; 730 }; 731 #define IOMMU_HWPT_GET_DIRTY_BITMAP _IO(IOMMUFD_TYPE, \ 732 IOMMUFD_CMD_HWPT_GET_DIRTY_BITMAP) 733 734 /** 735 * enum iommu_hwpt_invalidate_data_type - IOMMU HWPT Cache Invalidation 736 * Data Type 737 * @IOMMU_HWPT_INVALIDATE_DATA_VTD_S1: Invalidation data for VTD_S1 738 * @IOMMU_VIOMMU_INVALIDATE_DATA_ARM_SMMUV3: Invalidation data for ARM SMMUv3 739 */ 740 enum iommu_hwpt_invalidate_data_type { 741 IOMMU_HWPT_INVALIDATE_DATA_VTD_S1 = 0, 742 IOMMU_VIOMMU_INVALIDATE_DATA_ARM_SMMUV3 = 1, 743 }; 744 745 /** 746 * enum iommu_hwpt_vtd_s1_invalidate_flags - Flags for Intel VT-d 747 * stage-1 cache invalidation 748 * @IOMMU_VTD_INV_FLAGS_LEAF: Indicates whether the invalidation applies 749 * to all-levels page structure cache or just 750 * the leaf PTE cache. 751 */ 752 enum iommu_hwpt_vtd_s1_invalidate_flags { 753 IOMMU_VTD_INV_FLAGS_LEAF = 1 << 0, 754 }; 755 756 /** 757 * struct iommu_hwpt_vtd_s1_invalidate - Intel VT-d cache invalidation 758 * (IOMMU_HWPT_INVALIDATE_DATA_VTD_S1) 759 * @addr: The start address of the range to be invalidated. It needs to 760 * be 4KB aligned. 761 * @npages: Number of contiguous 4K pages to be invalidated. 762 * @flags: Combination of enum iommu_hwpt_vtd_s1_invalidate_flags 763 * @__reserved: Must be 0 764 * 765 * The Intel VT-d specific invalidation data for user-managed stage-1 cache 766 * invalidation in nested translation. Userspace uses this structure to 767 * tell the impacted cache scope after modifying the stage-1 page table. 768 * 769 * Invalidating all the caches related to the page table by setting @addr 770 * to be 0 and @npages to be U64_MAX. 771 * 772 * The device TLB will be invalidated automatically if ATS is enabled. 773 */ 774 struct iommu_hwpt_vtd_s1_invalidate { 775 __aligned_u64 addr; 776 __aligned_u64 npages; 777 __u32 flags; 778 __u32 __reserved; 779 }; 780 781 /** 782 * struct iommu_viommu_arm_smmuv3_invalidate - ARM SMMUv3 cache invalidation 783 * (IOMMU_VIOMMU_INVALIDATE_DATA_ARM_SMMUV3) 784 * @cmd: 128-bit cache invalidation command that runs in SMMU CMDQ. 785 * Must be little-endian. 786 * 787 * Supported command list only when passing in a vIOMMU via @hwpt_id: 788 * CMDQ_OP_TLBI_NSNH_ALL 789 * CMDQ_OP_TLBI_NH_VA 790 * CMDQ_OP_TLBI_NH_VAA 791 * CMDQ_OP_TLBI_NH_ALL 792 * CMDQ_OP_TLBI_NH_ASID 793 * CMDQ_OP_ATC_INV 794 * CMDQ_OP_CFGI_CD 795 * CMDQ_OP_CFGI_CD_ALL 796 * 797 * -EIO will be returned if the command is not supported. 798 */ 799 struct iommu_viommu_arm_smmuv3_invalidate { 800 __aligned_le64 cmd[2]; 801 }; 802 803 /** 804 * struct iommu_hwpt_invalidate - ioctl(IOMMU_HWPT_INVALIDATE) 805 * @size: sizeof(struct iommu_hwpt_invalidate) 806 * @hwpt_id: ID of a nested HWPT or a vIOMMU, for cache invalidation 807 * @data_uptr: User pointer to an array of driver-specific cache invalidation 808 * data. 809 * @data_type: One of enum iommu_hwpt_invalidate_data_type, defining the data 810 * type of all the entries in the invalidation request array. It 811 * should be a type supported by the hwpt pointed by @hwpt_id. 812 * @entry_len: Length (in bytes) of a request entry in the request array 813 * @entry_num: Input the number of cache invalidation requests in the array. 814 * Output the number of requests successfully handled by kernel. 815 * @__reserved: Must be 0. 816 * 817 * Invalidate iommu cache for user-managed page table or vIOMMU. Modifications 818 * on a user-managed page table should be followed by this operation, if a HWPT 819 * is passed in via @hwpt_id. Other caches, such as device cache or descriptor 820 * cache can be flushed if a vIOMMU is passed in via the @hwpt_id field. 821 * 822 * Each ioctl can support one or more cache invalidation requests in the array 823 * that has a total size of @entry_len * @entry_num. 824 * 825 * An empty invalidation request array by setting @entry_num==0 is allowed, and 826 * @entry_len and @data_uptr would be ignored in this case. This can be used to 827 * check if the given @data_type is supported or not by kernel. 828 */ 829 struct iommu_hwpt_invalidate { 830 __u32 size; 831 __u32 hwpt_id; 832 __aligned_u64 data_uptr; 833 __u32 data_type; 834 __u32 entry_len; 835 __u32 entry_num; 836 __u32 __reserved; 837 }; 838 #define IOMMU_HWPT_INVALIDATE _IO(IOMMUFD_TYPE, IOMMUFD_CMD_HWPT_INVALIDATE) 839 840 /** 841 * enum iommu_hwpt_pgfault_flags - flags for struct iommu_hwpt_pgfault 842 * @IOMMU_PGFAULT_FLAGS_PASID_VALID: The pasid field of the fault data is 843 * valid. 844 * @IOMMU_PGFAULT_FLAGS_LAST_PAGE: It's the last fault of a fault group. 845 */ 846 enum iommu_hwpt_pgfault_flags { 847 IOMMU_PGFAULT_FLAGS_PASID_VALID = (1 << 0), 848 IOMMU_PGFAULT_FLAGS_LAST_PAGE = (1 << 1), 849 }; 850 851 /** 852 * enum iommu_hwpt_pgfault_perm - perm bits for struct iommu_hwpt_pgfault 853 * @IOMMU_PGFAULT_PERM_READ: request for read permission 854 * @IOMMU_PGFAULT_PERM_WRITE: request for write permission 855 * @IOMMU_PGFAULT_PERM_EXEC: (PCIE 10.4.1) request with a PASID that has the 856 * Execute Requested bit set in PASID TLP Prefix. 857 * @IOMMU_PGFAULT_PERM_PRIV: (PCIE 10.4.1) request with a PASID that has the 858 * Privileged Mode Requested bit set in PASID TLP 859 * Prefix. 860 */ 861 enum iommu_hwpt_pgfault_perm { 862 IOMMU_PGFAULT_PERM_READ = (1 << 0), 863 IOMMU_PGFAULT_PERM_WRITE = (1 << 1), 864 IOMMU_PGFAULT_PERM_EXEC = (1 << 2), 865 IOMMU_PGFAULT_PERM_PRIV = (1 << 3), 866 }; 867 868 /** 869 * struct iommu_hwpt_pgfault - iommu page fault data 870 * @flags: Combination of enum iommu_hwpt_pgfault_flags 871 * @dev_id: id of the originated device 872 * @pasid: Process Address Space ID 873 * @grpid: Page Request Group Index 874 * @perm: Combination of enum iommu_hwpt_pgfault_perm 875 * @__reserved: Must be 0. 876 * @addr: Fault address 877 * @length: a hint of how much data the requestor is expecting to fetch. For 878 * example, if the PRI initiator knows it is going to do a 10MB 879 * transfer, it could fill in 10MB and the OS could pre-fault in 880 * 10MB of IOVA. It's default to 0 if there's no such hint. 881 * @cookie: kernel-managed cookie identifying a group of fault messages. The 882 * cookie number encoded in the last page fault of the group should 883 * be echoed back in the response message. 884 */ 885 struct iommu_hwpt_pgfault { 886 __u32 flags; 887 __u32 dev_id; 888 __u32 pasid; 889 __u32 grpid; 890 __u32 perm; 891 __u32 __reserved; 892 __aligned_u64 addr; 893 __u32 length; 894 __u32 cookie; 895 }; 896 897 /** 898 * enum iommufd_page_response_code - Return status of fault handlers 899 * @IOMMUFD_PAGE_RESP_SUCCESS: Fault has been handled and the page tables 900 * populated, retry the access. This is the 901 * "Success" defined in PCI 10.4.2.1. 902 * @IOMMUFD_PAGE_RESP_INVALID: Could not handle this fault, don't retry the 903 * access. This is the "Invalid Request" in PCI 904 * 10.4.2.1. 905 */ 906 enum iommufd_page_response_code { 907 IOMMUFD_PAGE_RESP_SUCCESS = 0, 908 IOMMUFD_PAGE_RESP_INVALID = 1, 909 }; 910 911 /** 912 * struct iommu_hwpt_page_response - IOMMU page fault response 913 * @cookie: The kernel-managed cookie reported in the fault message. 914 * @code: One of response code in enum iommufd_page_response_code. 915 */ 916 struct iommu_hwpt_page_response { 917 __u32 cookie; 918 __u32 code; 919 }; 920 921 /** 922 * struct iommu_fault_alloc - ioctl(IOMMU_FAULT_QUEUE_ALLOC) 923 * @size: sizeof(struct iommu_fault_alloc) 924 * @flags: Must be 0 925 * @out_fault_id: The ID of the new FAULT 926 * @out_fault_fd: The fd of the new FAULT 927 * 928 * Explicitly allocate a fault handling object. 929 */ 930 struct iommu_fault_alloc { 931 __u32 size; 932 __u32 flags; 933 __u32 out_fault_id; 934 __u32 out_fault_fd; 935 }; 936 #define IOMMU_FAULT_QUEUE_ALLOC _IO(IOMMUFD_TYPE, IOMMUFD_CMD_FAULT_QUEUE_ALLOC) 937 938 /** 939 * enum iommu_viommu_type - Virtual IOMMU Type 940 * @IOMMU_VIOMMU_TYPE_DEFAULT: Reserved for future use 941 * @IOMMU_VIOMMU_TYPE_ARM_SMMUV3: ARM SMMUv3 driver specific type 942 */ 943 enum iommu_viommu_type { 944 IOMMU_VIOMMU_TYPE_DEFAULT = 0, 945 IOMMU_VIOMMU_TYPE_ARM_SMMUV3 = 1, 946 }; 947 948 /** 949 * struct iommu_viommu_alloc - ioctl(IOMMU_VIOMMU_ALLOC) 950 * @size: sizeof(struct iommu_viommu_alloc) 951 * @flags: Must be 0 952 * @type: Type of the virtual IOMMU. Must be defined in enum iommu_viommu_type 953 * @dev_id: The device's physical IOMMU will be used to back the virtual IOMMU 954 * @hwpt_id: ID of a nesting parent HWPT to associate to 955 * @out_viommu_id: Output virtual IOMMU ID for the allocated object 956 * 957 * Allocate a virtual IOMMU object, representing the underlying physical IOMMU's 958 * virtualization support that is a security-isolated slice of the real IOMMU HW 959 * that is unique to a specific VM. Operations global to the IOMMU are connected 960 * to the vIOMMU, such as: 961 * - Security namespace for guest owned ID, e.g. guest-controlled cache tags 962 * - Non-device-affiliated event reporting, e.g. invalidation queue errors 963 * - Access to a sharable nesting parent pagetable across physical IOMMUs 964 * - Virtualization of various platforms IDs, e.g. RIDs and others 965 * - Delivery of paravirtualized invalidation 966 * - Direct assigned invalidation queues 967 * - Direct assigned interrupts 968 */ 969 struct iommu_viommu_alloc { 970 __u32 size; 971 __u32 flags; 972 __u32 type; 973 __u32 dev_id; 974 __u32 hwpt_id; 975 __u32 out_viommu_id; 976 }; 977 #define IOMMU_VIOMMU_ALLOC _IO(IOMMUFD_TYPE, IOMMUFD_CMD_VIOMMU_ALLOC) 978 979 /** 980 * struct iommu_vdevice_alloc - ioctl(IOMMU_VDEVICE_ALLOC) 981 * @size: sizeof(struct iommu_vdevice_alloc) 982 * @viommu_id: vIOMMU ID to associate with the virtual device 983 * @dev_id: The physical device to allocate a virtual instance on the vIOMMU 984 * @out_vdevice_id: Object handle for the vDevice. Pass to IOMMU_DESTORY 985 * @virt_id: Virtual device ID per vIOMMU, e.g. vSID of ARM SMMUv3, vDeviceID 986 * of AMD IOMMU, and vRID of a nested Intel VT-d to a Context Table 987 * 988 * Allocate a virtual device instance (for a physical device) against a vIOMMU. 989 * This instance holds the device's information (related to its vIOMMU) in a VM. 990 */ 991 struct iommu_vdevice_alloc { 992 __u32 size; 993 __u32 viommu_id; 994 __u32 dev_id; 995 __u32 out_vdevice_id; 996 __aligned_u64 virt_id; 997 }; 998 #define IOMMU_VDEVICE_ALLOC _IO(IOMMUFD_TYPE, IOMMUFD_CMD_VDEVICE_ALLOC) 999 1000 /** 1001 * struct iommu_ioas_change_process - ioctl(VFIO_IOAS_CHANGE_PROCESS) 1002 * @size: sizeof(struct iommu_ioas_change_process) 1003 * @__reserved: Must be 0 1004 * 1005 * This transfers pinned memory counts for every memory map in every IOAS 1006 * in the context to the current process. This only supports maps created 1007 * with IOMMU_IOAS_MAP_FILE, and returns EINVAL if other maps are present. 1008 * If the ioctl returns a failure status, then nothing is changed. 1009 * 1010 * This API is useful for transferring operation of a device from one process 1011 * to another, such as during userland live update. 1012 */ 1013 struct iommu_ioas_change_process { 1014 __u32 size; 1015 __u32 __reserved; 1016 }; 1017 1018 #define IOMMU_IOAS_CHANGE_PROCESS \ 1019 _IO(IOMMUFD_TYPE, IOMMUFD_CMD_IOAS_CHANGE_PROCESS) 1020 1021 /** 1022 * enum iommu_veventq_flag - flag for struct iommufd_vevent_header 1023 * @IOMMU_VEVENTQ_FLAG_LOST_EVENTS: vEVENTQ has lost vEVENTs 1024 */ 1025 enum iommu_veventq_flag { 1026 IOMMU_VEVENTQ_FLAG_LOST_EVENTS = (1U << 0), 1027 }; 1028 1029 /** 1030 * struct iommufd_vevent_header - Virtual Event Header for a vEVENTQ Status 1031 * @flags: Combination of enum iommu_veventq_flag 1032 * @sequence: The sequence index of a vEVENT in the vEVENTQ, with a range of 1033 * [0, INT_MAX] where the following index of INT_MAX is 0 1034 * 1035 * Each iommufd_vevent_header reports a sequence index of the following vEVENT: 1036 * ------------------------------------------------------------------------- 1037 * | header0 {sequence=0} | data0 | header1 {sequence=1} | data1 |...| dataN | 1038 * ------------------------------------------------------------------------- 1039 * And this sequence index is expected to be monotonic to the sequence index of 1040 * the previous vEVENT. If two adjacent sequence indexes has a delta larger than 1041 * 1, it means that delta - 1 number of vEVENTs has lost, e.g. two lost vEVENTs: 1042 * ------------------------------------------------------------------------- 1043 * | ... | header3 {sequence=3} | data3 | header6 {sequence=6} | data6 | ... | 1044 * ------------------------------------------------------------------------- 1045 * If a vEVENT lost at the tail of the vEVENTQ and there is no following vEVENT 1046 * providing the next sequence index, an IOMMU_VEVENTQ_FLAG_LOST_EVENTS header 1047 * would be added to the tail, and no data would follow this header: 1048 * --------------------------------------------------------------------------- 1049 * |..| header3 {sequence=3} | data3 | header4 {flags=LOST_EVENTS, sequence=4} | 1050 * --------------------------------------------------------------------------- 1051 */ 1052 struct iommufd_vevent_header { 1053 __u32 flags; 1054 __u32 sequence; 1055 }; 1056 1057 /** 1058 * enum iommu_veventq_type - Virtual Event Queue Type 1059 * @IOMMU_VEVENTQ_TYPE_DEFAULT: Reserved for future use 1060 * @IOMMU_VEVENTQ_TYPE_ARM_SMMUV3: ARM SMMUv3 Virtual Event Queue 1061 */ 1062 enum iommu_veventq_type { 1063 IOMMU_VEVENTQ_TYPE_DEFAULT = 0, 1064 IOMMU_VEVENTQ_TYPE_ARM_SMMUV3 = 1, 1065 }; 1066 1067 /** 1068 * struct iommu_vevent_arm_smmuv3 - ARM SMMUv3 Virtual Event 1069 * (IOMMU_VEVENTQ_TYPE_ARM_SMMUV3) 1070 * @evt: 256-bit ARM SMMUv3 Event record, little-endian. 1071 * Reported event records: (Refer to "7.3 Event records" in SMMUv3 HW Spec) 1072 * - 0x04 C_BAD_STE 1073 * - 0x06 F_STREAM_DISABLED 1074 * - 0x08 C_BAD_SUBSTREAMID 1075 * - 0x0a C_BAD_CD 1076 * - 0x10 F_TRANSLATION 1077 * - 0x11 F_ADDR_SIZE 1078 * - 0x12 F_ACCESS 1079 * - 0x13 F_PERMISSION 1080 * 1081 * StreamID field reports a virtual device ID. To receive a virtual event for a 1082 * device, a vDEVICE must be allocated via IOMMU_VDEVICE_ALLOC. 1083 */ 1084 struct iommu_vevent_arm_smmuv3 { 1085 __aligned_le64 evt[4]; 1086 }; 1087 1088 /** 1089 * struct iommu_veventq_alloc - ioctl(IOMMU_VEVENTQ_ALLOC) 1090 * @size: sizeof(struct iommu_veventq_alloc) 1091 * @flags: Must be 0 1092 * @viommu_id: virtual IOMMU ID to associate the vEVENTQ with 1093 * @type: Type of the vEVENTQ. Must be defined in enum iommu_veventq_type 1094 * @veventq_depth: Maximum number of events in the vEVENTQ 1095 * @out_veventq_id: The ID of the new vEVENTQ 1096 * @out_veventq_fd: The fd of the new vEVENTQ. User space must close the 1097 * successfully returned fd after using it 1098 * @__reserved: Must be 0 1099 * 1100 * Explicitly allocate a virtual event queue interface for a vIOMMU. A vIOMMU 1101 * can have multiple FDs for different types, but is confined to one per @type. 1102 * User space should open the @out_veventq_fd to read vEVENTs out of a vEVENTQ, 1103 * if there are vEVENTs available. A vEVENTQ will lose events due to overflow, 1104 * if the number of the vEVENTs hits @veventq_depth. 1105 * 1106 * Each vEVENT in a vEVENTQ encloses a struct iommufd_vevent_header followed by 1107 * a type-specific data structure, in a normal case: 1108 * ------------------------------------------------------------- 1109 * || header0 | data0 | header1 | data1 | ... | headerN | dataN || 1110 * ------------------------------------------------------------- 1111 * unless a tailing IOMMU_VEVENTQ_FLAG_LOST_EVENTS header is logged (refer to 1112 * struct iommufd_vevent_header). 1113 */ 1114 struct iommu_veventq_alloc { 1115 __u32 size; 1116 __u32 flags; 1117 __u32 viommu_id; 1118 __u32 type; 1119 __u32 veventq_depth; 1120 __u32 out_veventq_id; 1121 __u32 out_veventq_fd; 1122 __u32 __reserved; 1123 }; 1124 #define IOMMU_VEVENTQ_ALLOC _IO(IOMMUFD_TYPE, IOMMUFD_CMD_VEVENTQ_ALLOC) 1125 #endif 1126