1f7cbfa71SZhenzhong Duan /* SPDX-License-Identifier: GPL-2.0 WITH Linux-syscall-note */ 2f7cbfa71SZhenzhong Duan /* Copyright (c) 2021-2022, NVIDIA CORPORATION & AFFILIATES. 3f7cbfa71SZhenzhong Duan */ 4f7cbfa71SZhenzhong Duan #ifndef _IOMMUFD_H 5f7cbfa71SZhenzhong Duan #define _IOMMUFD_H 6f7cbfa71SZhenzhong Duan 7f7cbfa71SZhenzhong Duan #include <linux/types.h> 8f7cbfa71SZhenzhong Duan #include <linux/ioctl.h> 9f7cbfa71SZhenzhong Duan 10f7cbfa71SZhenzhong Duan #define IOMMUFD_TYPE (';') 11f7cbfa71SZhenzhong Duan 12f7cbfa71SZhenzhong Duan /** 13f7cbfa71SZhenzhong Duan * DOC: General ioctl format 14f7cbfa71SZhenzhong Duan * 15f7cbfa71SZhenzhong Duan * The ioctl interface follows a general format to allow for extensibility. Each 16f7cbfa71SZhenzhong Duan * ioctl is passed in a structure pointer as the argument providing the size of 17f7cbfa71SZhenzhong Duan * the structure in the first u32. The kernel checks that any structure space 18f7cbfa71SZhenzhong Duan * beyond what it understands is 0. This allows userspace to use the backward 19f7cbfa71SZhenzhong Duan * compatible portion while consistently using the newer, larger, structures. 20f7cbfa71SZhenzhong Duan * 21f7cbfa71SZhenzhong Duan * ioctls use a standard meaning for common errnos: 22f7cbfa71SZhenzhong Duan * 23f7cbfa71SZhenzhong Duan * - ENOTTY: The IOCTL number itself is not supported at all 24f7cbfa71SZhenzhong Duan * - E2BIG: The IOCTL number is supported, but the provided structure has 25f7cbfa71SZhenzhong Duan * non-zero in a part the kernel does not understand. 26f7cbfa71SZhenzhong Duan * - EOPNOTSUPP: The IOCTL number is supported, and the structure is 27f7cbfa71SZhenzhong Duan * understood, however a known field has a value the kernel does not 28f7cbfa71SZhenzhong Duan * understand or support. 29f7cbfa71SZhenzhong Duan * - EINVAL: Everything about the IOCTL was understood, but a field is not 30f7cbfa71SZhenzhong Duan * correct. 31f7cbfa71SZhenzhong Duan * - ENOENT: An ID or IOVA provided does not exist. 32f7cbfa71SZhenzhong Duan * - ENOMEM: Out of memory. 33f7cbfa71SZhenzhong Duan * - EOVERFLOW: Mathematics overflowed. 34f7cbfa71SZhenzhong Duan * 35f7cbfa71SZhenzhong Duan * As well as additional errnos, within specific ioctls. 36f7cbfa71SZhenzhong Duan */ 37f7cbfa71SZhenzhong Duan enum { 38f7cbfa71SZhenzhong Duan IOMMUFD_CMD_BASE = 0x80, 39f7cbfa71SZhenzhong Duan IOMMUFD_CMD_DESTROY = IOMMUFD_CMD_BASE, 40f7cbfa71SZhenzhong Duan IOMMUFD_CMD_IOAS_ALLOC, 41f7cbfa71SZhenzhong Duan IOMMUFD_CMD_IOAS_ALLOW_IOVAS, 42f7cbfa71SZhenzhong Duan IOMMUFD_CMD_IOAS_COPY, 43f7cbfa71SZhenzhong Duan IOMMUFD_CMD_IOAS_IOVA_RANGES, 44f7cbfa71SZhenzhong Duan IOMMUFD_CMD_IOAS_MAP, 45f7cbfa71SZhenzhong Duan IOMMUFD_CMD_IOAS_UNMAP, 46f7cbfa71SZhenzhong Duan IOMMUFD_CMD_OPTION, 47f7cbfa71SZhenzhong Duan IOMMUFD_CMD_VFIO_IOAS, 48f7cbfa71SZhenzhong Duan IOMMUFD_CMD_HWPT_ALLOC, 49f7cbfa71SZhenzhong Duan IOMMUFD_CMD_GET_HW_INFO, 50efb91426SDaniel Henrique Barboza IOMMUFD_CMD_HWPT_SET_DIRTY_TRACKING, 51efb91426SDaniel Henrique Barboza IOMMUFD_CMD_HWPT_GET_DIRTY_BITMAP, 52*6a02465fSDaniel Henrique Barboza IOMMUFD_CMD_HWPT_INVALIDATE, 53f7cbfa71SZhenzhong Duan }; 54f7cbfa71SZhenzhong Duan 55f7cbfa71SZhenzhong Duan /** 56f7cbfa71SZhenzhong Duan * struct iommu_destroy - ioctl(IOMMU_DESTROY) 57f7cbfa71SZhenzhong Duan * @size: sizeof(struct iommu_destroy) 58f7cbfa71SZhenzhong Duan * @id: iommufd object ID to destroy. Can be any destroyable object type. 59f7cbfa71SZhenzhong Duan * 60f7cbfa71SZhenzhong Duan * Destroy any object held within iommufd. 61f7cbfa71SZhenzhong Duan */ 62f7cbfa71SZhenzhong Duan struct iommu_destroy { 63f7cbfa71SZhenzhong Duan __u32 size; 64f7cbfa71SZhenzhong Duan __u32 id; 65f7cbfa71SZhenzhong Duan }; 66f7cbfa71SZhenzhong Duan #define IOMMU_DESTROY _IO(IOMMUFD_TYPE, IOMMUFD_CMD_DESTROY) 67f7cbfa71SZhenzhong Duan 68f7cbfa71SZhenzhong Duan /** 69f7cbfa71SZhenzhong Duan * struct iommu_ioas_alloc - ioctl(IOMMU_IOAS_ALLOC) 70f7cbfa71SZhenzhong Duan * @size: sizeof(struct iommu_ioas_alloc) 71f7cbfa71SZhenzhong Duan * @flags: Must be 0 72f7cbfa71SZhenzhong Duan * @out_ioas_id: Output IOAS ID for the allocated object 73f7cbfa71SZhenzhong Duan * 74f7cbfa71SZhenzhong Duan * Allocate an IO Address Space (IOAS) which holds an IO Virtual Address (IOVA) 75f7cbfa71SZhenzhong Duan * to memory mapping. 76f7cbfa71SZhenzhong Duan */ 77f7cbfa71SZhenzhong Duan struct iommu_ioas_alloc { 78f7cbfa71SZhenzhong Duan __u32 size; 79f7cbfa71SZhenzhong Duan __u32 flags; 80f7cbfa71SZhenzhong Duan __u32 out_ioas_id; 81f7cbfa71SZhenzhong Duan }; 82f7cbfa71SZhenzhong Duan #define IOMMU_IOAS_ALLOC _IO(IOMMUFD_TYPE, IOMMUFD_CMD_IOAS_ALLOC) 83f7cbfa71SZhenzhong Duan 84f7cbfa71SZhenzhong Duan /** 85f7cbfa71SZhenzhong Duan * struct iommu_iova_range - ioctl(IOMMU_IOVA_RANGE) 86f7cbfa71SZhenzhong Duan * @start: First IOVA 87f7cbfa71SZhenzhong Duan * @last: Inclusive last IOVA 88f7cbfa71SZhenzhong Duan * 89f7cbfa71SZhenzhong Duan * An interval in IOVA space. 90f7cbfa71SZhenzhong Duan */ 91f7cbfa71SZhenzhong Duan struct iommu_iova_range { 92f7cbfa71SZhenzhong Duan __aligned_u64 start; 93f7cbfa71SZhenzhong Duan __aligned_u64 last; 94f7cbfa71SZhenzhong Duan }; 95f7cbfa71SZhenzhong Duan 96f7cbfa71SZhenzhong Duan /** 97f7cbfa71SZhenzhong Duan * struct iommu_ioas_iova_ranges - ioctl(IOMMU_IOAS_IOVA_RANGES) 98f7cbfa71SZhenzhong Duan * @size: sizeof(struct iommu_ioas_iova_ranges) 99f7cbfa71SZhenzhong Duan * @ioas_id: IOAS ID to read ranges from 100f7cbfa71SZhenzhong Duan * @num_iovas: Input/Output total number of ranges in the IOAS 101f7cbfa71SZhenzhong Duan * @__reserved: Must be 0 102f7cbfa71SZhenzhong Duan * @allowed_iovas: Pointer to the output array of struct iommu_iova_range 103f7cbfa71SZhenzhong Duan * @out_iova_alignment: Minimum alignment required for mapping IOVA 104f7cbfa71SZhenzhong Duan * 105f7cbfa71SZhenzhong Duan * Query an IOAS for ranges of allowed IOVAs. Mapping IOVA outside these ranges 106f7cbfa71SZhenzhong Duan * is not allowed. num_iovas will be set to the total number of iovas and 107f7cbfa71SZhenzhong Duan * the allowed_iovas[] will be filled in as space permits. 108f7cbfa71SZhenzhong Duan * 109f7cbfa71SZhenzhong Duan * The allowed ranges are dependent on the HW path the DMA operation takes, and 110f7cbfa71SZhenzhong Duan * can change during the lifetime of the IOAS. A fresh empty IOAS will have a 111f7cbfa71SZhenzhong Duan * full range, and each attached device will narrow the ranges based on that 112f7cbfa71SZhenzhong Duan * device's HW restrictions. Detaching a device can widen the ranges. Userspace 113f7cbfa71SZhenzhong Duan * should query ranges after every attach/detach to know what IOVAs are valid 114f7cbfa71SZhenzhong Duan * for mapping. 115f7cbfa71SZhenzhong Duan * 116f7cbfa71SZhenzhong Duan * On input num_iovas is the length of the allowed_iovas array. On output it is 117f7cbfa71SZhenzhong Duan * the total number of iovas filled in. The ioctl will return -EMSGSIZE and set 118f7cbfa71SZhenzhong Duan * num_iovas to the required value if num_iovas is too small. In this case the 119f7cbfa71SZhenzhong Duan * caller should allocate a larger output array and re-issue the ioctl. 120f7cbfa71SZhenzhong Duan * 121f7cbfa71SZhenzhong Duan * out_iova_alignment returns the minimum IOVA alignment that can be given 122f7cbfa71SZhenzhong Duan * to IOMMU_IOAS_MAP/COPY. IOVA's must satisfy:: 123f7cbfa71SZhenzhong Duan * 124f7cbfa71SZhenzhong Duan * starting_iova % out_iova_alignment == 0 125f7cbfa71SZhenzhong Duan * (starting_iova + length) % out_iova_alignment == 0 126f7cbfa71SZhenzhong Duan * 127f7cbfa71SZhenzhong Duan * out_iova_alignment can be 1 indicating any IOVA is allowed. It cannot 128f7cbfa71SZhenzhong Duan * be higher than the system PAGE_SIZE. 129f7cbfa71SZhenzhong Duan */ 130f7cbfa71SZhenzhong Duan struct iommu_ioas_iova_ranges { 131f7cbfa71SZhenzhong Duan __u32 size; 132f7cbfa71SZhenzhong Duan __u32 ioas_id; 133f7cbfa71SZhenzhong Duan __u32 num_iovas; 134f7cbfa71SZhenzhong Duan __u32 __reserved; 135f7cbfa71SZhenzhong Duan __aligned_u64 allowed_iovas; 136f7cbfa71SZhenzhong Duan __aligned_u64 out_iova_alignment; 137f7cbfa71SZhenzhong Duan }; 138f7cbfa71SZhenzhong Duan #define IOMMU_IOAS_IOVA_RANGES _IO(IOMMUFD_TYPE, IOMMUFD_CMD_IOAS_IOVA_RANGES) 139f7cbfa71SZhenzhong Duan 140f7cbfa71SZhenzhong Duan /** 141f7cbfa71SZhenzhong Duan * struct iommu_ioas_allow_iovas - ioctl(IOMMU_IOAS_ALLOW_IOVAS) 142f7cbfa71SZhenzhong Duan * @size: sizeof(struct iommu_ioas_allow_iovas) 143f7cbfa71SZhenzhong Duan * @ioas_id: IOAS ID to allow IOVAs from 144f7cbfa71SZhenzhong Duan * @num_iovas: Input/Output total number of ranges in the IOAS 145f7cbfa71SZhenzhong Duan * @__reserved: Must be 0 146f7cbfa71SZhenzhong Duan * @allowed_iovas: Pointer to array of struct iommu_iova_range 147f7cbfa71SZhenzhong Duan * 148f7cbfa71SZhenzhong Duan * Ensure a range of IOVAs are always available for allocation. If this call 149f7cbfa71SZhenzhong Duan * succeeds then IOMMU_IOAS_IOVA_RANGES will never return a list of IOVA ranges 150f7cbfa71SZhenzhong Duan * that are narrower than the ranges provided here. This call will fail if 151f7cbfa71SZhenzhong Duan * IOMMU_IOAS_IOVA_RANGES is currently narrower than the given ranges. 152f7cbfa71SZhenzhong Duan * 153f7cbfa71SZhenzhong Duan * When an IOAS is first created the IOVA_RANGES will be maximally sized, and as 154f7cbfa71SZhenzhong Duan * devices are attached the IOVA will narrow based on the device restrictions. 155f7cbfa71SZhenzhong Duan * When an allowed range is specified any narrowing will be refused, ie device 156f7cbfa71SZhenzhong Duan * attachment can fail if the device requires limiting within the allowed range. 157f7cbfa71SZhenzhong Duan * 158f7cbfa71SZhenzhong Duan * Automatic IOVA allocation is also impacted by this call. MAP will only 159f7cbfa71SZhenzhong Duan * allocate within the allowed IOVAs if they are present. 160f7cbfa71SZhenzhong Duan * 161f7cbfa71SZhenzhong Duan * This call replaces the entire allowed list with the given list. 162f7cbfa71SZhenzhong Duan */ 163f7cbfa71SZhenzhong Duan struct iommu_ioas_allow_iovas { 164f7cbfa71SZhenzhong Duan __u32 size; 165f7cbfa71SZhenzhong Duan __u32 ioas_id; 166f7cbfa71SZhenzhong Duan __u32 num_iovas; 167f7cbfa71SZhenzhong Duan __u32 __reserved; 168f7cbfa71SZhenzhong Duan __aligned_u64 allowed_iovas; 169f7cbfa71SZhenzhong Duan }; 170f7cbfa71SZhenzhong Duan #define IOMMU_IOAS_ALLOW_IOVAS _IO(IOMMUFD_TYPE, IOMMUFD_CMD_IOAS_ALLOW_IOVAS) 171f7cbfa71SZhenzhong Duan 172f7cbfa71SZhenzhong Duan /** 173f7cbfa71SZhenzhong Duan * enum iommufd_ioas_map_flags - Flags for map and copy 174f7cbfa71SZhenzhong Duan * @IOMMU_IOAS_MAP_FIXED_IOVA: If clear the kernel will compute an appropriate 175f7cbfa71SZhenzhong Duan * IOVA to place the mapping at 176f7cbfa71SZhenzhong Duan * @IOMMU_IOAS_MAP_WRITEABLE: DMA is allowed to write to this mapping 177f7cbfa71SZhenzhong Duan * @IOMMU_IOAS_MAP_READABLE: DMA is allowed to read from this mapping 178f7cbfa71SZhenzhong Duan */ 179f7cbfa71SZhenzhong Duan enum iommufd_ioas_map_flags { 180f7cbfa71SZhenzhong Duan IOMMU_IOAS_MAP_FIXED_IOVA = 1 << 0, 181f7cbfa71SZhenzhong Duan IOMMU_IOAS_MAP_WRITEABLE = 1 << 1, 182f7cbfa71SZhenzhong Duan IOMMU_IOAS_MAP_READABLE = 1 << 2, 183f7cbfa71SZhenzhong Duan }; 184f7cbfa71SZhenzhong Duan 185f7cbfa71SZhenzhong Duan /** 186f7cbfa71SZhenzhong Duan * struct iommu_ioas_map - ioctl(IOMMU_IOAS_MAP) 187f7cbfa71SZhenzhong Duan * @size: sizeof(struct iommu_ioas_map) 188f7cbfa71SZhenzhong Duan * @flags: Combination of enum iommufd_ioas_map_flags 189f7cbfa71SZhenzhong Duan * @ioas_id: IOAS ID to change the mapping of 190f7cbfa71SZhenzhong Duan * @__reserved: Must be 0 191f7cbfa71SZhenzhong Duan * @user_va: Userspace pointer to start mapping from 192f7cbfa71SZhenzhong Duan * @length: Number of bytes to map 193f7cbfa71SZhenzhong Duan * @iova: IOVA the mapping was placed at. If IOMMU_IOAS_MAP_FIXED_IOVA is set 194f7cbfa71SZhenzhong Duan * then this must be provided as input. 195f7cbfa71SZhenzhong Duan * 196f7cbfa71SZhenzhong Duan * Set an IOVA mapping from a user pointer. If FIXED_IOVA is specified then the 197f7cbfa71SZhenzhong Duan * mapping will be established at iova, otherwise a suitable location based on 198f7cbfa71SZhenzhong Duan * the reserved and allowed lists will be automatically selected and returned in 199f7cbfa71SZhenzhong Duan * iova. 200f7cbfa71SZhenzhong Duan * 201f7cbfa71SZhenzhong Duan * If IOMMU_IOAS_MAP_FIXED_IOVA is specified then the iova range must currently 202f7cbfa71SZhenzhong Duan * be unused, existing IOVA cannot be replaced. 203f7cbfa71SZhenzhong Duan */ 204f7cbfa71SZhenzhong Duan struct iommu_ioas_map { 205f7cbfa71SZhenzhong Duan __u32 size; 206f7cbfa71SZhenzhong Duan __u32 flags; 207f7cbfa71SZhenzhong Duan __u32 ioas_id; 208f7cbfa71SZhenzhong Duan __u32 __reserved; 209f7cbfa71SZhenzhong Duan __aligned_u64 user_va; 210f7cbfa71SZhenzhong Duan __aligned_u64 length; 211f7cbfa71SZhenzhong Duan __aligned_u64 iova; 212f7cbfa71SZhenzhong Duan }; 213f7cbfa71SZhenzhong Duan #define IOMMU_IOAS_MAP _IO(IOMMUFD_TYPE, IOMMUFD_CMD_IOAS_MAP) 214f7cbfa71SZhenzhong Duan 215f7cbfa71SZhenzhong Duan /** 216f7cbfa71SZhenzhong Duan * struct iommu_ioas_copy - ioctl(IOMMU_IOAS_COPY) 217f7cbfa71SZhenzhong Duan * @size: sizeof(struct iommu_ioas_copy) 218f7cbfa71SZhenzhong Duan * @flags: Combination of enum iommufd_ioas_map_flags 219f7cbfa71SZhenzhong Duan * @dst_ioas_id: IOAS ID to change the mapping of 220f7cbfa71SZhenzhong Duan * @src_ioas_id: IOAS ID to copy from 221f7cbfa71SZhenzhong Duan * @length: Number of bytes to copy and map 222f7cbfa71SZhenzhong Duan * @dst_iova: IOVA the mapping was placed at. If IOMMU_IOAS_MAP_FIXED_IOVA is 223f7cbfa71SZhenzhong Duan * set then this must be provided as input. 224f7cbfa71SZhenzhong Duan * @src_iova: IOVA to start the copy 225f7cbfa71SZhenzhong Duan * 226f7cbfa71SZhenzhong Duan * Copy an already existing mapping from src_ioas_id and establish it in 227f7cbfa71SZhenzhong Duan * dst_ioas_id. The src iova/length must exactly match a range used with 228f7cbfa71SZhenzhong Duan * IOMMU_IOAS_MAP. 229f7cbfa71SZhenzhong Duan * 230f7cbfa71SZhenzhong Duan * This may be used to efficiently clone a subset of an IOAS to another, or as a 231f7cbfa71SZhenzhong Duan * kind of 'cache' to speed up mapping. Copy has an efficiency advantage over 232f7cbfa71SZhenzhong Duan * establishing equivalent new mappings, as internal resources are shared, and 233f7cbfa71SZhenzhong Duan * the kernel will pin the user memory only once. 234f7cbfa71SZhenzhong Duan */ 235f7cbfa71SZhenzhong Duan struct iommu_ioas_copy { 236f7cbfa71SZhenzhong Duan __u32 size; 237f7cbfa71SZhenzhong Duan __u32 flags; 238f7cbfa71SZhenzhong Duan __u32 dst_ioas_id; 239f7cbfa71SZhenzhong Duan __u32 src_ioas_id; 240f7cbfa71SZhenzhong Duan __aligned_u64 length; 241f7cbfa71SZhenzhong Duan __aligned_u64 dst_iova; 242f7cbfa71SZhenzhong Duan __aligned_u64 src_iova; 243f7cbfa71SZhenzhong Duan }; 244f7cbfa71SZhenzhong Duan #define IOMMU_IOAS_COPY _IO(IOMMUFD_TYPE, IOMMUFD_CMD_IOAS_COPY) 245f7cbfa71SZhenzhong Duan 246f7cbfa71SZhenzhong Duan /** 247f7cbfa71SZhenzhong Duan * struct iommu_ioas_unmap - ioctl(IOMMU_IOAS_UNMAP) 248f7cbfa71SZhenzhong Duan * @size: sizeof(struct iommu_ioas_unmap) 249f7cbfa71SZhenzhong Duan * @ioas_id: IOAS ID to change the mapping of 250f7cbfa71SZhenzhong Duan * @iova: IOVA to start the unmapping at 251f7cbfa71SZhenzhong Duan * @length: Number of bytes to unmap, and return back the bytes unmapped 252f7cbfa71SZhenzhong Duan * 253f7cbfa71SZhenzhong Duan * Unmap an IOVA range. The iova/length must be a superset of a previously 254f7cbfa71SZhenzhong Duan * mapped range used with IOMMU_IOAS_MAP or IOMMU_IOAS_COPY. Splitting or 255f7cbfa71SZhenzhong Duan * truncating ranges is not allowed. The values 0 to U64_MAX will unmap 256f7cbfa71SZhenzhong Duan * everything. 257f7cbfa71SZhenzhong Duan */ 258f7cbfa71SZhenzhong Duan struct iommu_ioas_unmap { 259f7cbfa71SZhenzhong Duan __u32 size; 260f7cbfa71SZhenzhong Duan __u32 ioas_id; 261f7cbfa71SZhenzhong Duan __aligned_u64 iova; 262f7cbfa71SZhenzhong Duan __aligned_u64 length; 263f7cbfa71SZhenzhong Duan }; 264f7cbfa71SZhenzhong Duan #define IOMMU_IOAS_UNMAP _IO(IOMMUFD_TYPE, IOMMUFD_CMD_IOAS_UNMAP) 265f7cbfa71SZhenzhong Duan 266f7cbfa71SZhenzhong Duan /** 267f7cbfa71SZhenzhong Duan * enum iommufd_option - ioctl(IOMMU_OPTION_RLIMIT_MODE) and 268f7cbfa71SZhenzhong Duan * ioctl(IOMMU_OPTION_HUGE_PAGES) 269f7cbfa71SZhenzhong Duan * @IOMMU_OPTION_RLIMIT_MODE: 270f7cbfa71SZhenzhong Duan * Change how RLIMIT_MEMLOCK accounting works. The caller must have privilege 271f7cbfa71SZhenzhong Duan * to invoke this. Value 0 (default) is user based accouting, 1 uses process 272f7cbfa71SZhenzhong Duan * based accounting. Global option, object_id must be 0 273f7cbfa71SZhenzhong Duan * @IOMMU_OPTION_HUGE_PAGES: 274f7cbfa71SZhenzhong Duan * Value 1 (default) allows contiguous pages to be combined when generating 275f7cbfa71SZhenzhong Duan * iommu mappings. Value 0 disables combining, everything is mapped to 276f7cbfa71SZhenzhong Duan * PAGE_SIZE. This can be useful for benchmarking. This is a per-IOAS 277f7cbfa71SZhenzhong Duan * option, the object_id must be the IOAS ID. 278f7cbfa71SZhenzhong Duan */ 279f7cbfa71SZhenzhong Duan enum iommufd_option { 280f7cbfa71SZhenzhong Duan IOMMU_OPTION_RLIMIT_MODE = 0, 281f7cbfa71SZhenzhong Duan IOMMU_OPTION_HUGE_PAGES = 1, 282f7cbfa71SZhenzhong Duan }; 283f7cbfa71SZhenzhong Duan 284f7cbfa71SZhenzhong Duan /** 285f7cbfa71SZhenzhong Duan * enum iommufd_option_ops - ioctl(IOMMU_OPTION_OP_SET) and 286f7cbfa71SZhenzhong Duan * ioctl(IOMMU_OPTION_OP_GET) 287f7cbfa71SZhenzhong Duan * @IOMMU_OPTION_OP_SET: Set the option's value 288f7cbfa71SZhenzhong Duan * @IOMMU_OPTION_OP_GET: Get the option's value 289f7cbfa71SZhenzhong Duan */ 290f7cbfa71SZhenzhong Duan enum iommufd_option_ops { 291f7cbfa71SZhenzhong Duan IOMMU_OPTION_OP_SET = 0, 292f7cbfa71SZhenzhong Duan IOMMU_OPTION_OP_GET = 1, 293f7cbfa71SZhenzhong Duan }; 294f7cbfa71SZhenzhong Duan 295f7cbfa71SZhenzhong Duan /** 296f7cbfa71SZhenzhong Duan * struct iommu_option - iommu option multiplexer 297f7cbfa71SZhenzhong Duan * @size: sizeof(struct iommu_option) 298f7cbfa71SZhenzhong Duan * @option_id: One of enum iommufd_option 299f7cbfa71SZhenzhong Duan * @op: One of enum iommufd_option_ops 300f7cbfa71SZhenzhong Duan * @__reserved: Must be 0 301f7cbfa71SZhenzhong Duan * @object_id: ID of the object if required 302f7cbfa71SZhenzhong Duan * @val64: Option value to set or value returned on get 303f7cbfa71SZhenzhong Duan * 304f7cbfa71SZhenzhong Duan * Change a simple option value. This multiplexor allows controlling options 305f7cbfa71SZhenzhong Duan * on objects. IOMMU_OPTION_OP_SET will load an option and IOMMU_OPTION_OP_GET 306f7cbfa71SZhenzhong Duan * will return the current value. 307f7cbfa71SZhenzhong Duan */ 308f7cbfa71SZhenzhong Duan struct iommu_option { 309f7cbfa71SZhenzhong Duan __u32 size; 310f7cbfa71SZhenzhong Duan __u32 option_id; 311f7cbfa71SZhenzhong Duan __u16 op; 312f7cbfa71SZhenzhong Duan __u16 __reserved; 313f7cbfa71SZhenzhong Duan __u32 object_id; 314f7cbfa71SZhenzhong Duan __aligned_u64 val64; 315f7cbfa71SZhenzhong Duan }; 316f7cbfa71SZhenzhong Duan #define IOMMU_OPTION _IO(IOMMUFD_TYPE, IOMMUFD_CMD_OPTION) 317f7cbfa71SZhenzhong Duan 318f7cbfa71SZhenzhong Duan /** 319f7cbfa71SZhenzhong Duan * enum iommufd_vfio_ioas_op - IOMMU_VFIO_IOAS_* ioctls 320f7cbfa71SZhenzhong Duan * @IOMMU_VFIO_IOAS_GET: Get the current compatibility IOAS 321f7cbfa71SZhenzhong Duan * @IOMMU_VFIO_IOAS_SET: Change the current compatibility IOAS 322f7cbfa71SZhenzhong Duan * @IOMMU_VFIO_IOAS_CLEAR: Disable VFIO compatibility 323f7cbfa71SZhenzhong Duan */ 324f7cbfa71SZhenzhong Duan enum iommufd_vfio_ioas_op { 325f7cbfa71SZhenzhong Duan IOMMU_VFIO_IOAS_GET = 0, 326f7cbfa71SZhenzhong Duan IOMMU_VFIO_IOAS_SET = 1, 327f7cbfa71SZhenzhong Duan IOMMU_VFIO_IOAS_CLEAR = 2, 328f7cbfa71SZhenzhong Duan }; 329f7cbfa71SZhenzhong Duan 330f7cbfa71SZhenzhong Duan /** 331f7cbfa71SZhenzhong Duan * struct iommu_vfio_ioas - ioctl(IOMMU_VFIO_IOAS) 332f7cbfa71SZhenzhong Duan * @size: sizeof(struct iommu_vfio_ioas) 333f7cbfa71SZhenzhong Duan * @ioas_id: For IOMMU_VFIO_IOAS_SET the input IOAS ID to set 334f7cbfa71SZhenzhong Duan * For IOMMU_VFIO_IOAS_GET will output the IOAS ID 335f7cbfa71SZhenzhong Duan * @op: One of enum iommufd_vfio_ioas_op 336f7cbfa71SZhenzhong Duan * @__reserved: Must be 0 337f7cbfa71SZhenzhong Duan * 338f7cbfa71SZhenzhong Duan * The VFIO compatibility support uses a single ioas because VFIO APIs do not 339f7cbfa71SZhenzhong Duan * support the ID field. Set or Get the IOAS that VFIO compatibility will use. 340f7cbfa71SZhenzhong Duan * When VFIO_GROUP_SET_CONTAINER is used on an iommufd it will get the 341f7cbfa71SZhenzhong Duan * compatibility ioas, either by taking what is already set, or auto creating 342f7cbfa71SZhenzhong Duan * one. From then on VFIO will continue to use that ioas and is not effected by 343f7cbfa71SZhenzhong Duan * this ioctl. SET or CLEAR does not destroy any auto-created IOAS. 344f7cbfa71SZhenzhong Duan */ 345f7cbfa71SZhenzhong Duan struct iommu_vfio_ioas { 346f7cbfa71SZhenzhong Duan __u32 size; 347f7cbfa71SZhenzhong Duan __u32 ioas_id; 348f7cbfa71SZhenzhong Duan __u16 op; 349f7cbfa71SZhenzhong Duan __u16 __reserved; 350f7cbfa71SZhenzhong Duan }; 351f7cbfa71SZhenzhong Duan #define IOMMU_VFIO_IOAS _IO(IOMMUFD_TYPE, IOMMUFD_CMD_VFIO_IOAS) 352f7cbfa71SZhenzhong Duan 353f7cbfa71SZhenzhong Duan /** 354efb91426SDaniel Henrique Barboza * enum iommufd_hwpt_alloc_flags - Flags for HWPT allocation 355efb91426SDaniel Henrique Barboza * @IOMMU_HWPT_ALLOC_NEST_PARENT: If set, allocate a HWPT that can serve as 356efb91426SDaniel Henrique Barboza * the parent HWPT in a nesting configuration. 357efb91426SDaniel Henrique Barboza * @IOMMU_HWPT_ALLOC_DIRTY_TRACKING: Dirty tracking support for device IOMMU is 358efb91426SDaniel Henrique Barboza * enforced on device attachment 359efb91426SDaniel Henrique Barboza */ 360efb91426SDaniel Henrique Barboza enum iommufd_hwpt_alloc_flags { 361efb91426SDaniel Henrique Barboza IOMMU_HWPT_ALLOC_NEST_PARENT = 1 << 0, 362efb91426SDaniel Henrique Barboza IOMMU_HWPT_ALLOC_DIRTY_TRACKING = 1 << 1, 363efb91426SDaniel Henrique Barboza }; 364efb91426SDaniel Henrique Barboza 365efb91426SDaniel Henrique Barboza /** 366efb91426SDaniel Henrique Barboza * enum iommu_hwpt_vtd_s1_flags - Intel VT-d stage-1 page table 367efb91426SDaniel Henrique Barboza * entry attributes 368efb91426SDaniel Henrique Barboza * @IOMMU_VTD_S1_SRE: Supervisor request 369efb91426SDaniel Henrique Barboza * @IOMMU_VTD_S1_EAFE: Extended access enable 370efb91426SDaniel Henrique Barboza * @IOMMU_VTD_S1_WPE: Write protect enable 371efb91426SDaniel Henrique Barboza */ 372efb91426SDaniel Henrique Barboza enum iommu_hwpt_vtd_s1_flags { 373efb91426SDaniel Henrique Barboza IOMMU_VTD_S1_SRE = 1 << 0, 374efb91426SDaniel Henrique Barboza IOMMU_VTD_S1_EAFE = 1 << 1, 375efb91426SDaniel Henrique Barboza IOMMU_VTD_S1_WPE = 1 << 2, 376efb91426SDaniel Henrique Barboza }; 377efb91426SDaniel Henrique Barboza 378efb91426SDaniel Henrique Barboza /** 379efb91426SDaniel Henrique Barboza * struct iommu_hwpt_vtd_s1 - Intel VT-d stage-1 page table 380efb91426SDaniel Henrique Barboza * info (IOMMU_HWPT_DATA_VTD_S1) 381efb91426SDaniel Henrique Barboza * @flags: Combination of enum iommu_hwpt_vtd_s1_flags 382efb91426SDaniel Henrique Barboza * @pgtbl_addr: The base address of the stage-1 page table. 383efb91426SDaniel Henrique Barboza * @addr_width: The address width of the stage-1 page table 384efb91426SDaniel Henrique Barboza * @__reserved: Must be 0 385efb91426SDaniel Henrique Barboza */ 386efb91426SDaniel Henrique Barboza struct iommu_hwpt_vtd_s1 { 387efb91426SDaniel Henrique Barboza __aligned_u64 flags; 388efb91426SDaniel Henrique Barboza __aligned_u64 pgtbl_addr; 389efb91426SDaniel Henrique Barboza __u32 addr_width; 390efb91426SDaniel Henrique Barboza __u32 __reserved; 391efb91426SDaniel Henrique Barboza }; 392efb91426SDaniel Henrique Barboza 393efb91426SDaniel Henrique Barboza /** 394efb91426SDaniel Henrique Barboza * enum iommu_hwpt_data_type - IOMMU HWPT Data Type 395efb91426SDaniel Henrique Barboza * @IOMMU_HWPT_DATA_NONE: no data 396efb91426SDaniel Henrique Barboza * @IOMMU_HWPT_DATA_VTD_S1: Intel VT-d stage-1 page table 397efb91426SDaniel Henrique Barboza */ 398efb91426SDaniel Henrique Barboza enum iommu_hwpt_data_type { 399efb91426SDaniel Henrique Barboza IOMMU_HWPT_DATA_NONE, 400efb91426SDaniel Henrique Barboza IOMMU_HWPT_DATA_VTD_S1, 401efb91426SDaniel Henrique Barboza }; 402efb91426SDaniel Henrique Barboza 403efb91426SDaniel Henrique Barboza /** 404f7cbfa71SZhenzhong Duan * struct iommu_hwpt_alloc - ioctl(IOMMU_HWPT_ALLOC) 405f7cbfa71SZhenzhong Duan * @size: sizeof(struct iommu_hwpt_alloc) 406efb91426SDaniel Henrique Barboza * @flags: Combination of enum iommufd_hwpt_alloc_flags 407f7cbfa71SZhenzhong Duan * @dev_id: The device to allocate this HWPT for 408efb91426SDaniel Henrique Barboza * @pt_id: The IOAS or HWPT to connect this HWPT to 409f7cbfa71SZhenzhong Duan * @out_hwpt_id: The ID of the new HWPT 410f7cbfa71SZhenzhong Duan * @__reserved: Must be 0 411efb91426SDaniel Henrique Barboza * @data_type: One of enum iommu_hwpt_data_type 412efb91426SDaniel Henrique Barboza * @data_len: Length of the type specific data 413efb91426SDaniel Henrique Barboza * @data_uptr: User pointer to the type specific data 414f7cbfa71SZhenzhong Duan * 415f7cbfa71SZhenzhong Duan * Explicitly allocate a hardware page table object. This is the same object 416f7cbfa71SZhenzhong Duan * type that is returned by iommufd_device_attach() and represents the 417f7cbfa71SZhenzhong Duan * underlying iommu driver's iommu_domain kernel object. 418f7cbfa71SZhenzhong Duan * 419efb91426SDaniel Henrique Barboza * A kernel-managed HWPT will be created with the mappings from the given 420efb91426SDaniel Henrique Barboza * IOAS via the @pt_id. The @data_type for this allocation must be set to 421efb91426SDaniel Henrique Barboza * IOMMU_HWPT_DATA_NONE. The HWPT can be allocated as a parent HWPT for a 422efb91426SDaniel Henrique Barboza * nesting configuration by passing IOMMU_HWPT_ALLOC_NEST_PARENT via @flags. 423efb91426SDaniel Henrique Barboza * 424efb91426SDaniel Henrique Barboza * A user-managed nested HWPT will be created from a given parent HWPT via 425efb91426SDaniel Henrique Barboza * @pt_id, in which the parent HWPT must be allocated previously via the 426efb91426SDaniel Henrique Barboza * same ioctl from a given IOAS (@pt_id). In this case, the @data_type 427efb91426SDaniel Henrique Barboza * must be set to a pre-defined type corresponding to an I/O page table 428efb91426SDaniel Henrique Barboza * type supported by the underlying IOMMU hardware. 429efb91426SDaniel Henrique Barboza * 430efb91426SDaniel Henrique Barboza * If the @data_type is set to IOMMU_HWPT_DATA_NONE, @data_len and 431efb91426SDaniel Henrique Barboza * @data_uptr should be zero. Otherwise, both @data_len and @data_uptr 432efb91426SDaniel Henrique Barboza * must be given. 433f7cbfa71SZhenzhong Duan */ 434f7cbfa71SZhenzhong Duan struct iommu_hwpt_alloc { 435f7cbfa71SZhenzhong Duan __u32 size; 436f7cbfa71SZhenzhong Duan __u32 flags; 437f7cbfa71SZhenzhong Duan __u32 dev_id; 438f7cbfa71SZhenzhong Duan __u32 pt_id; 439f7cbfa71SZhenzhong Duan __u32 out_hwpt_id; 440f7cbfa71SZhenzhong Duan __u32 __reserved; 441efb91426SDaniel Henrique Barboza __u32 data_type; 442efb91426SDaniel Henrique Barboza __u32 data_len; 443efb91426SDaniel Henrique Barboza __aligned_u64 data_uptr; 444f7cbfa71SZhenzhong Duan }; 445f7cbfa71SZhenzhong Duan #define IOMMU_HWPT_ALLOC _IO(IOMMUFD_TYPE, IOMMUFD_CMD_HWPT_ALLOC) 446f7cbfa71SZhenzhong Duan 447f7cbfa71SZhenzhong Duan /** 448efb91426SDaniel Henrique Barboza * enum iommu_hw_info_vtd_flags - Flags for VT-d hw_info 449efb91426SDaniel Henrique Barboza * @IOMMU_HW_INFO_VTD_ERRATA_772415_SPR17: If set, disallow read-only mappings 450efb91426SDaniel Henrique Barboza * on a nested_parent domain. 451efb91426SDaniel Henrique Barboza * https://www.intel.com/content/www/us/en/content-details/772415/content-details.html 452efb91426SDaniel Henrique Barboza */ 453efb91426SDaniel Henrique Barboza enum iommu_hw_info_vtd_flags { 454efb91426SDaniel Henrique Barboza IOMMU_HW_INFO_VTD_ERRATA_772415_SPR17 = 1 << 0, 455efb91426SDaniel Henrique Barboza }; 456efb91426SDaniel Henrique Barboza 457efb91426SDaniel Henrique Barboza /** 458f7cbfa71SZhenzhong Duan * struct iommu_hw_info_vtd - Intel VT-d hardware information 459f7cbfa71SZhenzhong Duan * 460efb91426SDaniel Henrique Barboza * @flags: Combination of enum iommu_hw_info_vtd_flags 461f7cbfa71SZhenzhong Duan * @__reserved: Must be 0 462f7cbfa71SZhenzhong Duan * 463f7cbfa71SZhenzhong Duan * @cap_reg: Value of Intel VT-d capability register defined in VT-d spec 464f7cbfa71SZhenzhong Duan * section 11.4.2 Capability Register. 465f7cbfa71SZhenzhong Duan * @ecap_reg: Value of Intel VT-d capability register defined in VT-d spec 466f7cbfa71SZhenzhong Duan * section 11.4.3 Extended Capability Register. 467f7cbfa71SZhenzhong Duan * 468f7cbfa71SZhenzhong Duan * User needs to understand the Intel VT-d specification to decode the 469f7cbfa71SZhenzhong Duan * register value. 470f7cbfa71SZhenzhong Duan */ 471f7cbfa71SZhenzhong Duan struct iommu_hw_info_vtd { 472f7cbfa71SZhenzhong Duan __u32 flags; 473f7cbfa71SZhenzhong Duan __u32 __reserved; 474f7cbfa71SZhenzhong Duan __aligned_u64 cap_reg; 475f7cbfa71SZhenzhong Duan __aligned_u64 ecap_reg; 476f7cbfa71SZhenzhong Duan }; 477f7cbfa71SZhenzhong Duan 478f7cbfa71SZhenzhong Duan /** 479f7cbfa71SZhenzhong Duan * enum iommu_hw_info_type - IOMMU Hardware Info Types 480f7cbfa71SZhenzhong Duan * @IOMMU_HW_INFO_TYPE_NONE: Used by the drivers that do not report hardware 481f7cbfa71SZhenzhong Duan * info 482f7cbfa71SZhenzhong Duan * @IOMMU_HW_INFO_TYPE_INTEL_VTD: Intel VT-d iommu info type 483f7cbfa71SZhenzhong Duan */ 484f7cbfa71SZhenzhong Duan enum iommu_hw_info_type { 485f7cbfa71SZhenzhong Duan IOMMU_HW_INFO_TYPE_NONE, 486f7cbfa71SZhenzhong Duan IOMMU_HW_INFO_TYPE_INTEL_VTD, 487f7cbfa71SZhenzhong Duan }; 488f7cbfa71SZhenzhong Duan 489f7cbfa71SZhenzhong Duan /** 490efb91426SDaniel Henrique Barboza * enum iommufd_hw_capabilities 491efb91426SDaniel Henrique Barboza * @IOMMU_HW_CAP_DIRTY_TRACKING: IOMMU hardware support for dirty tracking 492efb91426SDaniel Henrique Barboza * If available, it means the following APIs 493efb91426SDaniel Henrique Barboza * are supported: 494efb91426SDaniel Henrique Barboza * 495efb91426SDaniel Henrique Barboza * IOMMU_HWPT_GET_DIRTY_BITMAP 496efb91426SDaniel Henrique Barboza * IOMMU_HWPT_SET_DIRTY_TRACKING 497efb91426SDaniel Henrique Barboza * 498efb91426SDaniel Henrique Barboza */ 499efb91426SDaniel Henrique Barboza enum iommufd_hw_capabilities { 500efb91426SDaniel Henrique Barboza IOMMU_HW_CAP_DIRTY_TRACKING = 1 << 0, 501efb91426SDaniel Henrique Barboza }; 502efb91426SDaniel Henrique Barboza 503efb91426SDaniel Henrique Barboza /** 504f7cbfa71SZhenzhong Duan * struct iommu_hw_info - ioctl(IOMMU_GET_HW_INFO) 505f7cbfa71SZhenzhong Duan * @size: sizeof(struct iommu_hw_info) 506f7cbfa71SZhenzhong Duan * @flags: Must be 0 507f7cbfa71SZhenzhong Duan * @dev_id: The device bound to the iommufd 508f7cbfa71SZhenzhong Duan * @data_len: Input the length of a user buffer in bytes. Output the length of 509f7cbfa71SZhenzhong Duan * data that kernel supports 510f7cbfa71SZhenzhong Duan * @data_uptr: User pointer to a user-space buffer used by the kernel to fill 511f7cbfa71SZhenzhong Duan * the iommu type specific hardware information data 512f7cbfa71SZhenzhong Duan * @out_data_type: Output the iommu hardware info type as defined in the enum 513f7cbfa71SZhenzhong Duan * iommu_hw_info_type. 514efb91426SDaniel Henrique Barboza * @out_capabilities: Output the generic iommu capability info type as defined 515efb91426SDaniel Henrique Barboza * in the enum iommu_hw_capabilities. 516f7cbfa71SZhenzhong Duan * @__reserved: Must be 0 517f7cbfa71SZhenzhong Duan * 518f7cbfa71SZhenzhong Duan * Query an iommu type specific hardware information data from an iommu behind 519f7cbfa71SZhenzhong Duan * a given device that has been bound to iommufd. This hardware info data will 520f7cbfa71SZhenzhong Duan * be used to sync capabilities between the virtual iommu and the physical 521f7cbfa71SZhenzhong Duan * iommu, e.g. a nested translation setup needs to check the hardware info, so 522f7cbfa71SZhenzhong Duan * a guest stage-1 page table can be compatible with the physical iommu. 523f7cbfa71SZhenzhong Duan * 524f7cbfa71SZhenzhong Duan * To capture an iommu type specific hardware information data, @data_uptr and 525f7cbfa71SZhenzhong Duan * its length @data_len must be provided. Trailing bytes will be zeroed if the 526f7cbfa71SZhenzhong Duan * user buffer is larger than the data that kernel has. Otherwise, kernel only 527f7cbfa71SZhenzhong Duan * fills the buffer using the given length in @data_len. If the ioctl succeeds, 528f7cbfa71SZhenzhong Duan * @data_len will be updated to the length that kernel actually supports, 529f7cbfa71SZhenzhong Duan * @out_data_type will be filled to decode the data filled in the buffer 530f7cbfa71SZhenzhong Duan * pointed by @data_uptr. Input @data_len == zero is allowed. 531f7cbfa71SZhenzhong Duan */ 532f7cbfa71SZhenzhong Duan struct iommu_hw_info { 533f7cbfa71SZhenzhong Duan __u32 size; 534f7cbfa71SZhenzhong Duan __u32 flags; 535f7cbfa71SZhenzhong Duan __u32 dev_id; 536f7cbfa71SZhenzhong Duan __u32 data_len; 537f7cbfa71SZhenzhong Duan __aligned_u64 data_uptr; 538f7cbfa71SZhenzhong Duan __u32 out_data_type; 539f7cbfa71SZhenzhong Duan __u32 __reserved; 540efb91426SDaniel Henrique Barboza __aligned_u64 out_capabilities; 541f7cbfa71SZhenzhong Duan }; 542f7cbfa71SZhenzhong Duan #define IOMMU_GET_HW_INFO _IO(IOMMUFD_TYPE, IOMMUFD_CMD_GET_HW_INFO) 543efb91426SDaniel Henrique Barboza 544efb91426SDaniel Henrique Barboza /* 545efb91426SDaniel Henrique Barboza * enum iommufd_hwpt_set_dirty_tracking_flags - Flags for steering dirty 546efb91426SDaniel Henrique Barboza * tracking 547efb91426SDaniel Henrique Barboza * @IOMMU_HWPT_DIRTY_TRACKING_ENABLE: Enable dirty tracking 548efb91426SDaniel Henrique Barboza */ 549efb91426SDaniel Henrique Barboza enum iommufd_hwpt_set_dirty_tracking_flags { 550efb91426SDaniel Henrique Barboza IOMMU_HWPT_DIRTY_TRACKING_ENABLE = 1, 551efb91426SDaniel Henrique Barboza }; 552efb91426SDaniel Henrique Barboza 553efb91426SDaniel Henrique Barboza /** 554efb91426SDaniel Henrique Barboza * struct iommu_hwpt_set_dirty_tracking - ioctl(IOMMU_HWPT_SET_DIRTY_TRACKING) 555efb91426SDaniel Henrique Barboza * @size: sizeof(struct iommu_hwpt_set_dirty_tracking) 556efb91426SDaniel Henrique Barboza * @flags: Combination of enum iommufd_hwpt_set_dirty_tracking_flags 557efb91426SDaniel Henrique Barboza * @hwpt_id: HW pagetable ID that represents the IOMMU domain 558efb91426SDaniel Henrique Barboza * @__reserved: Must be 0 559efb91426SDaniel Henrique Barboza * 560efb91426SDaniel Henrique Barboza * Toggle dirty tracking on an HW pagetable. 561efb91426SDaniel Henrique Barboza */ 562efb91426SDaniel Henrique Barboza struct iommu_hwpt_set_dirty_tracking { 563efb91426SDaniel Henrique Barboza __u32 size; 564efb91426SDaniel Henrique Barboza __u32 flags; 565efb91426SDaniel Henrique Barboza __u32 hwpt_id; 566efb91426SDaniel Henrique Barboza __u32 __reserved; 567efb91426SDaniel Henrique Barboza }; 568efb91426SDaniel Henrique Barboza #define IOMMU_HWPT_SET_DIRTY_TRACKING _IO(IOMMUFD_TYPE, \ 569efb91426SDaniel Henrique Barboza IOMMUFD_CMD_HWPT_SET_DIRTY_TRACKING) 570efb91426SDaniel Henrique Barboza 571efb91426SDaniel Henrique Barboza /** 572efb91426SDaniel Henrique Barboza * enum iommufd_hwpt_get_dirty_bitmap_flags - Flags for getting dirty bits 573efb91426SDaniel Henrique Barboza * @IOMMU_HWPT_GET_DIRTY_BITMAP_NO_CLEAR: Just read the PTEs without clearing 574efb91426SDaniel Henrique Barboza * any dirty bits metadata. This flag 575efb91426SDaniel Henrique Barboza * can be passed in the expectation 576efb91426SDaniel Henrique Barboza * where the next operation is an unmap 577efb91426SDaniel Henrique Barboza * of the same IOVA range. 578efb91426SDaniel Henrique Barboza * 579efb91426SDaniel Henrique Barboza */ 580efb91426SDaniel Henrique Barboza enum iommufd_hwpt_get_dirty_bitmap_flags { 581efb91426SDaniel Henrique Barboza IOMMU_HWPT_GET_DIRTY_BITMAP_NO_CLEAR = 1, 582efb91426SDaniel Henrique Barboza }; 583efb91426SDaniel Henrique Barboza 584efb91426SDaniel Henrique Barboza /** 585efb91426SDaniel Henrique Barboza * struct iommu_hwpt_get_dirty_bitmap - ioctl(IOMMU_HWPT_GET_DIRTY_BITMAP) 586efb91426SDaniel Henrique Barboza * @size: sizeof(struct iommu_hwpt_get_dirty_bitmap) 587efb91426SDaniel Henrique Barboza * @hwpt_id: HW pagetable ID that represents the IOMMU domain 588efb91426SDaniel Henrique Barboza * @flags: Combination of enum iommufd_hwpt_get_dirty_bitmap_flags 589efb91426SDaniel Henrique Barboza * @__reserved: Must be 0 590efb91426SDaniel Henrique Barboza * @iova: base IOVA of the bitmap first bit 591efb91426SDaniel Henrique Barboza * @length: IOVA range size 592efb91426SDaniel Henrique Barboza * @page_size: page size granularity of each bit in the bitmap 593efb91426SDaniel Henrique Barboza * @data: bitmap where to set the dirty bits. The bitmap bits each 594efb91426SDaniel Henrique Barboza * represent a page_size which you deviate from an arbitrary iova. 595efb91426SDaniel Henrique Barboza * 596efb91426SDaniel Henrique Barboza * Checking a given IOVA is dirty: 597efb91426SDaniel Henrique Barboza * 598efb91426SDaniel Henrique Barboza * data[(iova / page_size) / 64] & (1ULL << ((iova / page_size) % 64)) 599efb91426SDaniel Henrique Barboza * 600efb91426SDaniel Henrique Barboza * Walk the IOMMU pagetables for a given IOVA range to return a bitmap 601efb91426SDaniel Henrique Barboza * with the dirty IOVAs. In doing so it will also by default clear any 602efb91426SDaniel Henrique Barboza * dirty bit metadata set in the IOPTE. 603efb91426SDaniel Henrique Barboza */ 604efb91426SDaniel Henrique Barboza struct iommu_hwpt_get_dirty_bitmap { 605efb91426SDaniel Henrique Barboza __u32 size; 606efb91426SDaniel Henrique Barboza __u32 hwpt_id; 607efb91426SDaniel Henrique Barboza __u32 flags; 608efb91426SDaniel Henrique Barboza __u32 __reserved; 609efb91426SDaniel Henrique Barboza __aligned_u64 iova; 610efb91426SDaniel Henrique Barboza __aligned_u64 length; 611efb91426SDaniel Henrique Barboza __aligned_u64 page_size; 612efb91426SDaniel Henrique Barboza __aligned_u64 data; 613efb91426SDaniel Henrique Barboza }; 614efb91426SDaniel Henrique Barboza #define IOMMU_HWPT_GET_DIRTY_BITMAP _IO(IOMMUFD_TYPE, \ 615efb91426SDaniel Henrique Barboza IOMMUFD_CMD_HWPT_GET_DIRTY_BITMAP) 616efb91426SDaniel Henrique Barboza 617*6a02465fSDaniel Henrique Barboza /** 618*6a02465fSDaniel Henrique Barboza * enum iommu_hwpt_invalidate_data_type - IOMMU HWPT Cache Invalidation 619*6a02465fSDaniel Henrique Barboza * Data Type 620*6a02465fSDaniel Henrique Barboza * @IOMMU_HWPT_INVALIDATE_DATA_VTD_S1: Invalidation data for VTD_S1 621*6a02465fSDaniel Henrique Barboza */ 622*6a02465fSDaniel Henrique Barboza enum iommu_hwpt_invalidate_data_type { 623*6a02465fSDaniel Henrique Barboza IOMMU_HWPT_INVALIDATE_DATA_VTD_S1, 624*6a02465fSDaniel Henrique Barboza }; 625*6a02465fSDaniel Henrique Barboza 626*6a02465fSDaniel Henrique Barboza /** 627*6a02465fSDaniel Henrique Barboza * enum iommu_hwpt_vtd_s1_invalidate_flags - Flags for Intel VT-d 628*6a02465fSDaniel Henrique Barboza * stage-1 cache invalidation 629*6a02465fSDaniel Henrique Barboza * @IOMMU_VTD_INV_FLAGS_LEAF: Indicates whether the invalidation applies 630*6a02465fSDaniel Henrique Barboza * to all-levels page structure cache or just 631*6a02465fSDaniel Henrique Barboza * the leaf PTE cache. 632*6a02465fSDaniel Henrique Barboza */ 633*6a02465fSDaniel Henrique Barboza enum iommu_hwpt_vtd_s1_invalidate_flags { 634*6a02465fSDaniel Henrique Barboza IOMMU_VTD_INV_FLAGS_LEAF = 1 << 0, 635*6a02465fSDaniel Henrique Barboza }; 636*6a02465fSDaniel Henrique Barboza 637*6a02465fSDaniel Henrique Barboza /** 638*6a02465fSDaniel Henrique Barboza * struct iommu_hwpt_vtd_s1_invalidate - Intel VT-d cache invalidation 639*6a02465fSDaniel Henrique Barboza * (IOMMU_HWPT_INVALIDATE_DATA_VTD_S1) 640*6a02465fSDaniel Henrique Barboza * @addr: The start address of the range to be invalidated. It needs to 641*6a02465fSDaniel Henrique Barboza * be 4KB aligned. 642*6a02465fSDaniel Henrique Barboza * @npages: Number of contiguous 4K pages to be invalidated. 643*6a02465fSDaniel Henrique Barboza * @flags: Combination of enum iommu_hwpt_vtd_s1_invalidate_flags 644*6a02465fSDaniel Henrique Barboza * @__reserved: Must be 0 645*6a02465fSDaniel Henrique Barboza * 646*6a02465fSDaniel Henrique Barboza * The Intel VT-d specific invalidation data for user-managed stage-1 cache 647*6a02465fSDaniel Henrique Barboza * invalidation in nested translation. Userspace uses this structure to 648*6a02465fSDaniel Henrique Barboza * tell the impacted cache scope after modifying the stage-1 page table. 649*6a02465fSDaniel Henrique Barboza * 650*6a02465fSDaniel Henrique Barboza * Invalidating all the caches related to the page table by setting @addr 651*6a02465fSDaniel Henrique Barboza * to be 0 and @npages to be U64_MAX. 652*6a02465fSDaniel Henrique Barboza * 653*6a02465fSDaniel Henrique Barboza * The device TLB will be invalidated automatically if ATS is enabled. 654*6a02465fSDaniel Henrique Barboza */ 655*6a02465fSDaniel Henrique Barboza struct iommu_hwpt_vtd_s1_invalidate { 656*6a02465fSDaniel Henrique Barboza __aligned_u64 addr; 657*6a02465fSDaniel Henrique Barboza __aligned_u64 npages; 658*6a02465fSDaniel Henrique Barboza __u32 flags; 659*6a02465fSDaniel Henrique Barboza __u32 __reserved; 660*6a02465fSDaniel Henrique Barboza }; 661*6a02465fSDaniel Henrique Barboza 662*6a02465fSDaniel Henrique Barboza /** 663*6a02465fSDaniel Henrique Barboza * struct iommu_hwpt_invalidate - ioctl(IOMMU_HWPT_INVALIDATE) 664*6a02465fSDaniel Henrique Barboza * @size: sizeof(struct iommu_hwpt_invalidate) 665*6a02465fSDaniel Henrique Barboza * @hwpt_id: ID of a nested HWPT for cache invalidation 666*6a02465fSDaniel Henrique Barboza * @data_uptr: User pointer to an array of driver-specific cache invalidation 667*6a02465fSDaniel Henrique Barboza * data. 668*6a02465fSDaniel Henrique Barboza * @data_type: One of enum iommu_hwpt_invalidate_data_type, defining the data 669*6a02465fSDaniel Henrique Barboza * type of all the entries in the invalidation request array. It 670*6a02465fSDaniel Henrique Barboza * should be a type supported by the hwpt pointed by @hwpt_id. 671*6a02465fSDaniel Henrique Barboza * @entry_len: Length (in bytes) of a request entry in the request array 672*6a02465fSDaniel Henrique Barboza * @entry_num: Input the number of cache invalidation requests in the array. 673*6a02465fSDaniel Henrique Barboza * Output the number of requests successfully handled by kernel. 674*6a02465fSDaniel Henrique Barboza * @__reserved: Must be 0. 675*6a02465fSDaniel Henrique Barboza * 676*6a02465fSDaniel Henrique Barboza * Invalidate the iommu cache for user-managed page table. Modifications on a 677*6a02465fSDaniel Henrique Barboza * user-managed page table should be followed by this operation to sync cache. 678*6a02465fSDaniel Henrique Barboza * Each ioctl can support one or more cache invalidation requests in the array 679*6a02465fSDaniel Henrique Barboza * that has a total size of @entry_len * @entry_num. 680*6a02465fSDaniel Henrique Barboza * 681*6a02465fSDaniel Henrique Barboza * An empty invalidation request array by setting @entry_num==0 is allowed, and 682*6a02465fSDaniel Henrique Barboza * @entry_len and @data_uptr would be ignored in this case. This can be used to 683*6a02465fSDaniel Henrique Barboza * check if the given @data_type is supported or not by kernel. 684*6a02465fSDaniel Henrique Barboza */ 685*6a02465fSDaniel Henrique Barboza struct iommu_hwpt_invalidate { 686*6a02465fSDaniel Henrique Barboza __u32 size; 687*6a02465fSDaniel Henrique Barboza __u32 hwpt_id; 688*6a02465fSDaniel Henrique Barboza __aligned_u64 data_uptr; 689*6a02465fSDaniel Henrique Barboza __u32 data_type; 690*6a02465fSDaniel Henrique Barboza __u32 entry_len; 691*6a02465fSDaniel Henrique Barboza __u32 entry_num; 692*6a02465fSDaniel Henrique Barboza __u32 __reserved; 693*6a02465fSDaniel Henrique Barboza }; 694*6a02465fSDaniel Henrique Barboza #define IOMMU_HWPT_INVALIDATE _IO(IOMMUFD_TYPE, IOMMUFD_CMD_HWPT_INVALIDATE) 695f7cbfa71SZhenzhong Duan #endif 696