12ff4bed7SJason Gunthorpe /* SPDX-License-Identifier: GPL-2.0 WITH Linux-syscall-note */ 22ff4bed7SJason Gunthorpe /* Copyright (c) 2021-2022, NVIDIA CORPORATION & AFFILIATES. 32ff4bed7SJason Gunthorpe */ 42ff4bed7SJason Gunthorpe #ifndef _UAPI_IOMMUFD_H 52ff4bed7SJason Gunthorpe #define _UAPI_IOMMUFD_H 62ff4bed7SJason Gunthorpe 72ff4bed7SJason Gunthorpe #include <linux/types.h> 82ff4bed7SJason Gunthorpe #include <linux/ioctl.h> 92ff4bed7SJason Gunthorpe 102ff4bed7SJason Gunthorpe #define IOMMUFD_TYPE (';') 112ff4bed7SJason Gunthorpe 122ff4bed7SJason Gunthorpe /** 132ff4bed7SJason Gunthorpe * DOC: General ioctl format 142ff4bed7SJason Gunthorpe * 152ff4bed7SJason Gunthorpe * The ioctl interface follows a general format to allow for extensibility. Each 162ff4bed7SJason Gunthorpe * ioctl is passed in a structure pointer as the argument providing the size of 172ff4bed7SJason Gunthorpe * the structure in the first u32. The kernel checks that any structure space 182ff4bed7SJason Gunthorpe * beyond what it understands is 0. This allows userspace to use the backward 192ff4bed7SJason Gunthorpe * compatible portion while consistently using the newer, larger, structures. 202ff4bed7SJason Gunthorpe * 212ff4bed7SJason Gunthorpe * ioctls use a standard meaning for common errnos: 222ff4bed7SJason Gunthorpe * 232ff4bed7SJason Gunthorpe * - ENOTTY: The IOCTL number itself is not supported at all 242ff4bed7SJason Gunthorpe * - E2BIG: The IOCTL number is supported, but the provided structure has 252ff4bed7SJason Gunthorpe * non-zero in a part the kernel does not understand. 262ff4bed7SJason Gunthorpe * - EOPNOTSUPP: The IOCTL number is supported, and the structure is 272ff4bed7SJason Gunthorpe * understood, however a known field has a value the kernel does not 282ff4bed7SJason Gunthorpe * understand or support. 292ff4bed7SJason Gunthorpe * - EINVAL: Everything about the IOCTL was understood, but a field is not 302ff4bed7SJason Gunthorpe * correct. 312ff4bed7SJason Gunthorpe * - ENOENT: An ID or IOVA provided does not exist. 322ff4bed7SJason Gunthorpe * - ENOMEM: Out of memory. 332ff4bed7SJason Gunthorpe * - EOVERFLOW: Mathematics overflowed. 342ff4bed7SJason Gunthorpe * 352ff4bed7SJason Gunthorpe * As well as additional errnos, within specific ioctls. 362ff4bed7SJason Gunthorpe */ 372ff4bed7SJason Gunthorpe enum { 382ff4bed7SJason Gunthorpe IOMMUFD_CMD_BASE = 0x80, 392ff4bed7SJason Gunthorpe IOMMUFD_CMD_DESTROY = IOMMUFD_CMD_BASE, 40aad37e71SJason Gunthorpe IOMMUFD_CMD_IOAS_ALLOC, 41aad37e71SJason Gunthorpe IOMMUFD_CMD_IOAS_ALLOW_IOVAS, 42aad37e71SJason Gunthorpe IOMMUFD_CMD_IOAS_COPY, 43aad37e71SJason Gunthorpe IOMMUFD_CMD_IOAS_IOVA_RANGES, 44aad37e71SJason Gunthorpe IOMMUFD_CMD_IOAS_MAP, 45aad37e71SJason Gunthorpe IOMMUFD_CMD_IOAS_UNMAP, 46aad37e71SJason Gunthorpe IOMMUFD_CMD_OPTION, 47d624d665SJason Gunthorpe IOMMUFD_CMD_VFIO_IOAS, 487074d7bdSJason Gunthorpe IOMMUFD_CMD_HWPT_ALLOC, 4955dd4023SYi Liu IOMMUFD_CMD_GET_HW_INFO, 50e2a4b294SJoao Martins IOMMUFD_CMD_HWPT_SET_DIRTY_TRACKING, 51b9a60d6fSJoao Martins IOMMUFD_CMD_HWPT_GET_DIRTY_BITMAP, 528c6eabaeSYi Liu IOMMUFD_CMD_HWPT_INVALIDATE, 532ff4bed7SJason Gunthorpe }; 542ff4bed7SJason Gunthorpe 552ff4bed7SJason Gunthorpe /** 562ff4bed7SJason Gunthorpe * struct iommu_destroy - ioctl(IOMMU_DESTROY) 572ff4bed7SJason Gunthorpe * @size: sizeof(struct iommu_destroy) 58aad37e71SJason Gunthorpe * @id: iommufd object ID to destroy. Can be any destroyable object type. 592ff4bed7SJason Gunthorpe * 602ff4bed7SJason Gunthorpe * Destroy any object held within iommufd. 612ff4bed7SJason Gunthorpe */ 622ff4bed7SJason Gunthorpe struct iommu_destroy { 632ff4bed7SJason Gunthorpe __u32 size; 642ff4bed7SJason Gunthorpe __u32 id; 652ff4bed7SJason Gunthorpe }; 662ff4bed7SJason Gunthorpe #define IOMMU_DESTROY _IO(IOMMUFD_TYPE, IOMMUFD_CMD_DESTROY) 672ff4bed7SJason Gunthorpe 68aad37e71SJason Gunthorpe /** 69aad37e71SJason Gunthorpe * struct iommu_ioas_alloc - ioctl(IOMMU_IOAS_ALLOC) 70aad37e71SJason Gunthorpe * @size: sizeof(struct iommu_ioas_alloc) 71aad37e71SJason Gunthorpe * @flags: Must be 0 72aad37e71SJason Gunthorpe * @out_ioas_id: Output IOAS ID for the allocated object 73aad37e71SJason Gunthorpe * 74aad37e71SJason Gunthorpe * Allocate an IO Address Space (IOAS) which holds an IO Virtual Address (IOVA) 75aad37e71SJason Gunthorpe * to memory mapping. 76aad37e71SJason Gunthorpe */ 77aad37e71SJason Gunthorpe struct iommu_ioas_alloc { 78aad37e71SJason Gunthorpe __u32 size; 79aad37e71SJason Gunthorpe __u32 flags; 80aad37e71SJason Gunthorpe __u32 out_ioas_id; 81aad37e71SJason Gunthorpe }; 82aad37e71SJason Gunthorpe #define IOMMU_IOAS_ALLOC _IO(IOMMUFD_TYPE, IOMMUFD_CMD_IOAS_ALLOC) 83aad37e71SJason Gunthorpe 84aad37e71SJason Gunthorpe /** 85aad37e71SJason Gunthorpe * struct iommu_iova_range - ioctl(IOMMU_IOVA_RANGE) 86aad37e71SJason Gunthorpe * @start: First IOVA 87aad37e71SJason Gunthorpe * @last: Inclusive last IOVA 88aad37e71SJason Gunthorpe * 89aad37e71SJason Gunthorpe * An interval in IOVA space. 90aad37e71SJason Gunthorpe */ 91aad37e71SJason Gunthorpe struct iommu_iova_range { 92aad37e71SJason Gunthorpe __aligned_u64 start; 93aad37e71SJason Gunthorpe __aligned_u64 last; 94aad37e71SJason Gunthorpe }; 95aad37e71SJason Gunthorpe 96aad37e71SJason Gunthorpe /** 97aad37e71SJason Gunthorpe * struct iommu_ioas_iova_ranges - ioctl(IOMMU_IOAS_IOVA_RANGES) 98aad37e71SJason Gunthorpe * @size: sizeof(struct iommu_ioas_iova_ranges) 99aad37e71SJason Gunthorpe * @ioas_id: IOAS ID to read ranges from 100aad37e71SJason Gunthorpe * @num_iovas: Input/Output total number of ranges in the IOAS 101aad37e71SJason Gunthorpe * @__reserved: Must be 0 102aad37e71SJason Gunthorpe * @allowed_iovas: Pointer to the output array of struct iommu_iova_range 103aad37e71SJason Gunthorpe * @out_iova_alignment: Minimum alignment required for mapping IOVA 104aad37e71SJason Gunthorpe * 105aad37e71SJason Gunthorpe * Query an IOAS for ranges of allowed IOVAs. Mapping IOVA outside these ranges 106aad37e71SJason Gunthorpe * is not allowed. num_iovas will be set to the total number of iovas and 107aad37e71SJason Gunthorpe * the allowed_iovas[] will be filled in as space permits. 108aad37e71SJason Gunthorpe * 109aad37e71SJason Gunthorpe * The allowed ranges are dependent on the HW path the DMA operation takes, and 110aad37e71SJason Gunthorpe * can change during the lifetime of the IOAS. A fresh empty IOAS will have a 111aad37e71SJason Gunthorpe * full range, and each attached device will narrow the ranges based on that 112aad37e71SJason Gunthorpe * device's HW restrictions. Detaching a device can widen the ranges. Userspace 113aad37e71SJason Gunthorpe * should query ranges after every attach/detach to know what IOVAs are valid 114aad37e71SJason Gunthorpe * for mapping. 115aad37e71SJason Gunthorpe * 116aad37e71SJason Gunthorpe * On input num_iovas is the length of the allowed_iovas array. On output it is 117aad37e71SJason Gunthorpe * the total number of iovas filled in. The ioctl will return -EMSGSIZE and set 118aad37e71SJason Gunthorpe * num_iovas to the required value if num_iovas is too small. In this case the 119aad37e71SJason Gunthorpe * caller should allocate a larger output array and re-issue the ioctl. 120aad37e71SJason Gunthorpe * 121aad37e71SJason Gunthorpe * out_iova_alignment returns the minimum IOVA alignment that can be given 122aad37e71SJason Gunthorpe * to IOMMU_IOAS_MAP/COPY. IOVA's must satisfy:: 123aad37e71SJason Gunthorpe * 124aad37e71SJason Gunthorpe * starting_iova % out_iova_alignment == 0 125aad37e71SJason Gunthorpe * (starting_iova + length) % out_iova_alignment == 0 126aad37e71SJason Gunthorpe * 127aad37e71SJason Gunthorpe * out_iova_alignment can be 1 indicating any IOVA is allowed. It cannot 128aad37e71SJason Gunthorpe * be higher than the system PAGE_SIZE. 129aad37e71SJason Gunthorpe */ 130aad37e71SJason Gunthorpe struct iommu_ioas_iova_ranges { 131aad37e71SJason Gunthorpe __u32 size; 132aad37e71SJason Gunthorpe __u32 ioas_id; 133aad37e71SJason Gunthorpe __u32 num_iovas; 134aad37e71SJason Gunthorpe __u32 __reserved; 135aad37e71SJason Gunthorpe __aligned_u64 allowed_iovas; 136aad37e71SJason Gunthorpe __aligned_u64 out_iova_alignment; 137aad37e71SJason Gunthorpe }; 138aad37e71SJason Gunthorpe #define IOMMU_IOAS_IOVA_RANGES _IO(IOMMUFD_TYPE, IOMMUFD_CMD_IOAS_IOVA_RANGES) 139aad37e71SJason Gunthorpe 140aad37e71SJason Gunthorpe /** 141aad37e71SJason Gunthorpe * struct iommu_ioas_allow_iovas - ioctl(IOMMU_IOAS_ALLOW_IOVAS) 142aad37e71SJason Gunthorpe * @size: sizeof(struct iommu_ioas_allow_iovas) 143aad37e71SJason Gunthorpe * @ioas_id: IOAS ID to allow IOVAs from 144aad37e71SJason Gunthorpe * @num_iovas: Input/Output total number of ranges in the IOAS 145aad37e71SJason Gunthorpe * @__reserved: Must be 0 146aad37e71SJason Gunthorpe * @allowed_iovas: Pointer to array of struct iommu_iova_range 147aad37e71SJason Gunthorpe * 148aad37e71SJason Gunthorpe * Ensure a range of IOVAs are always available for allocation. If this call 149aad37e71SJason Gunthorpe * succeeds then IOMMU_IOAS_IOVA_RANGES will never return a list of IOVA ranges 150aad37e71SJason Gunthorpe * that are narrower than the ranges provided here. This call will fail if 151aad37e71SJason Gunthorpe * IOMMU_IOAS_IOVA_RANGES is currently narrower than the given ranges. 152aad37e71SJason Gunthorpe * 153aad37e71SJason Gunthorpe * When an IOAS is first created the IOVA_RANGES will be maximally sized, and as 154aad37e71SJason Gunthorpe * devices are attached the IOVA will narrow based on the device restrictions. 155aad37e71SJason Gunthorpe * When an allowed range is specified any narrowing will be refused, ie device 156aad37e71SJason Gunthorpe * attachment can fail if the device requires limiting within the allowed range. 157aad37e71SJason Gunthorpe * 158aad37e71SJason Gunthorpe * Automatic IOVA allocation is also impacted by this call. MAP will only 159aad37e71SJason Gunthorpe * allocate within the allowed IOVAs if they are present. 160aad37e71SJason Gunthorpe * 161aad37e71SJason Gunthorpe * This call replaces the entire allowed list with the given list. 162aad37e71SJason Gunthorpe */ 163aad37e71SJason Gunthorpe struct iommu_ioas_allow_iovas { 164aad37e71SJason Gunthorpe __u32 size; 165aad37e71SJason Gunthorpe __u32 ioas_id; 166aad37e71SJason Gunthorpe __u32 num_iovas; 167aad37e71SJason Gunthorpe __u32 __reserved; 168aad37e71SJason Gunthorpe __aligned_u64 allowed_iovas; 169aad37e71SJason Gunthorpe }; 170aad37e71SJason Gunthorpe #define IOMMU_IOAS_ALLOW_IOVAS _IO(IOMMUFD_TYPE, IOMMUFD_CMD_IOAS_ALLOW_IOVAS) 171aad37e71SJason Gunthorpe 172aad37e71SJason Gunthorpe /** 173aad37e71SJason Gunthorpe * enum iommufd_ioas_map_flags - Flags for map and copy 174aad37e71SJason Gunthorpe * @IOMMU_IOAS_MAP_FIXED_IOVA: If clear the kernel will compute an appropriate 175aad37e71SJason Gunthorpe * IOVA to place the mapping at 176aad37e71SJason Gunthorpe * @IOMMU_IOAS_MAP_WRITEABLE: DMA is allowed to write to this mapping 177aad37e71SJason Gunthorpe * @IOMMU_IOAS_MAP_READABLE: DMA is allowed to read from this mapping 178aad37e71SJason Gunthorpe */ 179aad37e71SJason Gunthorpe enum iommufd_ioas_map_flags { 180aad37e71SJason Gunthorpe IOMMU_IOAS_MAP_FIXED_IOVA = 1 << 0, 181aad37e71SJason Gunthorpe IOMMU_IOAS_MAP_WRITEABLE = 1 << 1, 182aad37e71SJason Gunthorpe IOMMU_IOAS_MAP_READABLE = 1 << 2, 183aad37e71SJason Gunthorpe }; 184aad37e71SJason Gunthorpe 185aad37e71SJason Gunthorpe /** 186aad37e71SJason Gunthorpe * struct iommu_ioas_map - ioctl(IOMMU_IOAS_MAP) 187aad37e71SJason Gunthorpe * @size: sizeof(struct iommu_ioas_map) 188aad37e71SJason Gunthorpe * @flags: Combination of enum iommufd_ioas_map_flags 189aad37e71SJason Gunthorpe * @ioas_id: IOAS ID to change the mapping of 190aad37e71SJason Gunthorpe * @__reserved: Must be 0 191aad37e71SJason Gunthorpe * @user_va: Userspace pointer to start mapping from 192aad37e71SJason Gunthorpe * @length: Number of bytes to map 193aad37e71SJason Gunthorpe * @iova: IOVA the mapping was placed at. If IOMMU_IOAS_MAP_FIXED_IOVA is set 194aad37e71SJason Gunthorpe * then this must be provided as input. 195aad37e71SJason Gunthorpe * 196aad37e71SJason Gunthorpe * Set an IOVA mapping from a user pointer. If FIXED_IOVA is specified then the 197aad37e71SJason Gunthorpe * mapping will be established at iova, otherwise a suitable location based on 198aad37e71SJason Gunthorpe * the reserved and allowed lists will be automatically selected and returned in 199aad37e71SJason Gunthorpe * iova. 200aad37e71SJason Gunthorpe * 201aad37e71SJason Gunthorpe * If IOMMU_IOAS_MAP_FIXED_IOVA is specified then the iova range must currently 202aad37e71SJason Gunthorpe * be unused, existing IOVA cannot be replaced. 203aad37e71SJason Gunthorpe */ 204aad37e71SJason Gunthorpe struct iommu_ioas_map { 205aad37e71SJason Gunthorpe __u32 size; 206aad37e71SJason Gunthorpe __u32 flags; 207aad37e71SJason Gunthorpe __u32 ioas_id; 208aad37e71SJason Gunthorpe __u32 __reserved; 209aad37e71SJason Gunthorpe __aligned_u64 user_va; 210aad37e71SJason Gunthorpe __aligned_u64 length; 211aad37e71SJason Gunthorpe __aligned_u64 iova; 212aad37e71SJason Gunthorpe }; 213aad37e71SJason Gunthorpe #define IOMMU_IOAS_MAP _IO(IOMMUFD_TYPE, IOMMUFD_CMD_IOAS_MAP) 214aad37e71SJason Gunthorpe 215aad37e71SJason Gunthorpe /** 216aad37e71SJason Gunthorpe * struct iommu_ioas_copy - ioctl(IOMMU_IOAS_COPY) 217aad37e71SJason Gunthorpe * @size: sizeof(struct iommu_ioas_copy) 218aad37e71SJason Gunthorpe * @flags: Combination of enum iommufd_ioas_map_flags 219aad37e71SJason Gunthorpe * @dst_ioas_id: IOAS ID to change the mapping of 220aad37e71SJason Gunthorpe * @src_ioas_id: IOAS ID to copy from 221aad37e71SJason Gunthorpe * @length: Number of bytes to copy and map 222aad37e71SJason Gunthorpe * @dst_iova: IOVA the mapping was placed at. If IOMMU_IOAS_MAP_FIXED_IOVA is 223aad37e71SJason Gunthorpe * set then this must be provided as input. 224aad37e71SJason Gunthorpe * @src_iova: IOVA to start the copy 225aad37e71SJason Gunthorpe * 226aad37e71SJason Gunthorpe * Copy an already existing mapping from src_ioas_id and establish it in 227aad37e71SJason Gunthorpe * dst_ioas_id. The src iova/length must exactly match a range used with 228aad37e71SJason Gunthorpe * IOMMU_IOAS_MAP. 229aad37e71SJason Gunthorpe * 230aad37e71SJason Gunthorpe * This may be used to efficiently clone a subset of an IOAS to another, or as a 231aad37e71SJason Gunthorpe * kind of 'cache' to speed up mapping. Copy has an efficiency advantage over 232aad37e71SJason Gunthorpe * establishing equivalent new mappings, as internal resources are shared, and 233aad37e71SJason Gunthorpe * the kernel will pin the user memory only once. 234aad37e71SJason Gunthorpe */ 235aad37e71SJason Gunthorpe struct iommu_ioas_copy { 236aad37e71SJason Gunthorpe __u32 size; 237aad37e71SJason Gunthorpe __u32 flags; 238aad37e71SJason Gunthorpe __u32 dst_ioas_id; 239aad37e71SJason Gunthorpe __u32 src_ioas_id; 240aad37e71SJason Gunthorpe __aligned_u64 length; 241aad37e71SJason Gunthorpe __aligned_u64 dst_iova; 242aad37e71SJason Gunthorpe __aligned_u64 src_iova; 243aad37e71SJason Gunthorpe }; 244aad37e71SJason Gunthorpe #define IOMMU_IOAS_COPY _IO(IOMMUFD_TYPE, IOMMUFD_CMD_IOAS_COPY) 245aad37e71SJason Gunthorpe 246aad37e71SJason Gunthorpe /** 247aad37e71SJason Gunthorpe * struct iommu_ioas_unmap - ioctl(IOMMU_IOAS_UNMAP) 248aad37e71SJason Gunthorpe * @size: sizeof(struct iommu_ioas_unmap) 249aad37e71SJason Gunthorpe * @ioas_id: IOAS ID to change the mapping of 250aad37e71SJason Gunthorpe * @iova: IOVA to start the unmapping at 251aad37e71SJason Gunthorpe * @length: Number of bytes to unmap, and return back the bytes unmapped 252aad37e71SJason Gunthorpe * 253aad37e71SJason Gunthorpe * Unmap an IOVA range. The iova/length must be a superset of a previously 254aad37e71SJason Gunthorpe * mapped range used with IOMMU_IOAS_MAP or IOMMU_IOAS_COPY. Splitting or 255aad37e71SJason Gunthorpe * truncating ranges is not allowed. The values 0 to U64_MAX will unmap 256aad37e71SJason Gunthorpe * everything. 257aad37e71SJason Gunthorpe */ 258aad37e71SJason Gunthorpe struct iommu_ioas_unmap { 259aad37e71SJason Gunthorpe __u32 size; 260aad37e71SJason Gunthorpe __u32 ioas_id; 261aad37e71SJason Gunthorpe __aligned_u64 iova; 262aad37e71SJason Gunthorpe __aligned_u64 length; 263aad37e71SJason Gunthorpe }; 264aad37e71SJason Gunthorpe #define IOMMU_IOAS_UNMAP _IO(IOMMUFD_TYPE, IOMMUFD_CMD_IOAS_UNMAP) 265aad37e71SJason Gunthorpe 266aad37e71SJason Gunthorpe /** 267aad37e71SJason Gunthorpe * enum iommufd_option - ioctl(IOMMU_OPTION_RLIMIT_MODE) and 268aad37e71SJason Gunthorpe * ioctl(IOMMU_OPTION_HUGE_PAGES) 269aad37e71SJason Gunthorpe * @IOMMU_OPTION_RLIMIT_MODE: 270aad37e71SJason Gunthorpe * Change how RLIMIT_MEMLOCK accounting works. The caller must have privilege 271aad37e71SJason Gunthorpe * to invoke this. Value 0 (default) is user based accouting, 1 uses process 272aad37e71SJason Gunthorpe * based accounting. Global option, object_id must be 0 273aad37e71SJason Gunthorpe * @IOMMU_OPTION_HUGE_PAGES: 274aad37e71SJason Gunthorpe * Value 1 (default) allows contiguous pages to be combined when generating 275aad37e71SJason Gunthorpe * iommu mappings. Value 0 disables combining, everything is mapped to 276aad37e71SJason Gunthorpe * PAGE_SIZE. This can be useful for benchmarking. This is a per-IOAS 277aad37e71SJason Gunthorpe * option, the object_id must be the IOAS ID. 278aad37e71SJason Gunthorpe */ 279aad37e71SJason Gunthorpe enum iommufd_option { 280aad37e71SJason Gunthorpe IOMMU_OPTION_RLIMIT_MODE = 0, 281aad37e71SJason Gunthorpe IOMMU_OPTION_HUGE_PAGES = 1, 282aad37e71SJason Gunthorpe }; 283aad37e71SJason Gunthorpe 284aad37e71SJason Gunthorpe /** 285aad37e71SJason Gunthorpe * enum iommufd_option_ops - ioctl(IOMMU_OPTION_OP_SET) and 286aad37e71SJason Gunthorpe * ioctl(IOMMU_OPTION_OP_GET) 287aad37e71SJason Gunthorpe * @IOMMU_OPTION_OP_SET: Set the option's value 288aad37e71SJason Gunthorpe * @IOMMU_OPTION_OP_GET: Get the option's value 289aad37e71SJason Gunthorpe */ 290aad37e71SJason Gunthorpe enum iommufd_option_ops { 291aad37e71SJason Gunthorpe IOMMU_OPTION_OP_SET = 0, 292aad37e71SJason Gunthorpe IOMMU_OPTION_OP_GET = 1, 293aad37e71SJason Gunthorpe }; 294aad37e71SJason Gunthorpe 295aad37e71SJason Gunthorpe /** 296aad37e71SJason Gunthorpe * struct iommu_option - iommu option multiplexer 297aad37e71SJason Gunthorpe * @size: sizeof(struct iommu_option) 298aad37e71SJason Gunthorpe * @option_id: One of enum iommufd_option 299aad37e71SJason Gunthorpe * @op: One of enum iommufd_option_ops 300aad37e71SJason Gunthorpe * @__reserved: Must be 0 301aad37e71SJason Gunthorpe * @object_id: ID of the object if required 302aad37e71SJason Gunthorpe * @val64: Option value to set or value returned on get 303aad37e71SJason Gunthorpe * 304aad37e71SJason Gunthorpe * Change a simple option value. This multiplexor allows controlling options 305aad37e71SJason Gunthorpe * on objects. IOMMU_OPTION_OP_SET will load an option and IOMMU_OPTION_OP_GET 306aad37e71SJason Gunthorpe * will return the current value. 307aad37e71SJason Gunthorpe */ 308aad37e71SJason Gunthorpe struct iommu_option { 309aad37e71SJason Gunthorpe __u32 size; 310aad37e71SJason Gunthorpe __u32 option_id; 311aad37e71SJason Gunthorpe __u16 op; 312aad37e71SJason Gunthorpe __u16 __reserved; 313aad37e71SJason Gunthorpe __u32 object_id; 314aad37e71SJason Gunthorpe __aligned_u64 val64; 315aad37e71SJason Gunthorpe }; 316aad37e71SJason Gunthorpe #define IOMMU_OPTION _IO(IOMMUFD_TYPE, IOMMUFD_CMD_OPTION) 317d624d665SJason Gunthorpe 318d624d665SJason Gunthorpe /** 319d624d665SJason Gunthorpe * enum iommufd_vfio_ioas_op - IOMMU_VFIO_IOAS_* ioctls 320d624d665SJason Gunthorpe * @IOMMU_VFIO_IOAS_GET: Get the current compatibility IOAS 321d624d665SJason Gunthorpe * @IOMMU_VFIO_IOAS_SET: Change the current compatibility IOAS 322d624d665SJason Gunthorpe * @IOMMU_VFIO_IOAS_CLEAR: Disable VFIO compatibility 323d624d665SJason Gunthorpe */ 324d624d665SJason Gunthorpe enum iommufd_vfio_ioas_op { 325d624d665SJason Gunthorpe IOMMU_VFIO_IOAS_GET = 0, 326d624d665SJason Gunthorpe IOMMU_VFIO_IOAS_SET = 1, 327d624d665SJason Gunthorpe IOMMU_VFIO_IOAS_CLEAR = 2, 328d624d665SJason Gunthorpe }; 329d624d665SJason Gunthorpe 330d624d665SJason Gunthorpe /** 331d624d665SJason Gunthorpe * struct iommu_vfio_ioas - ioctl(IOMMU_VFIO_IOAS) 332d624d665SJason Gunthorpe * @size: sizeof(struct iommu_vfio_ioas) 333d624d665SJason Gunthorpe * @ioas_id: For IOMMU_VFIO_IOAS_SET the input IOAS ID to set 334d624d665SJason Gunthorpe * For IOMMU_VFIO_IOAS_GET will output the IOAS ID 335d624d665SJason Gunthorpe * @op: One of enum iommufd_vfio_ioas_op 336d624d665SJason Gunthorpe * @__reserved: Must be 0 337d624d665SJason Gunthorpe * 338d624d665SJason Gunthorpe * The VFIO compatibility support uses a single ioas because VFIO APIs do not 339d624d665SJason Gunthorpe * support the ID field. Set or Get the IOAS that VFIO compatibility will use. 340d624d665SJason Gunthorpe * When VFIO_GROUP_SET_CONTAINER is used on an iommufd it will get the 341d624d665SJason Gunthorpe * compatibility ioas, either by taking what is already set, or auto creating 342d624d665SJason Gunthorpe * one. From then on VFIO will continue to use that ioas and is not effected by 343d624d665SJason Gunthorpe * this ioctl. SET or CLEAR does not destroy any auto-created IOAS. 344d624d665SJason Gunthorpe */ 345d624d665SJason Gunthorpe struct iommu_vfio_ioas { 346d624d665SJason Gunthorpe __u32 size; 347d624d665SJason Gunthorpe __u32 ioas_id; 348d624d665SJason Gunthorpe __u16 op; 349d624d665SJason Gunthorpe __u16 __reserved; 350d624d665SJason Gunthorpe }; 351d624d665SJason Gunthorpe #define IOMMU_VFIO_IOAS _IO(IOMMUFD_TYPE, IOMMUFD_CMD_VFIO_IOAS) 3527074d7bdSJason Gunthorpe 3537074d7bdSJason Gunthorpe /** 3544ff54216SYi Liu * enum iommufd_hwpt_alloc_flags - Flags for HWPT allocation 355b5f9e632SNicolin Chen * @IOMMU_HWPT_ALLOC_NEST_PARENT: If set, allocate a HWPT that can serve as 356b5f9e632SNicolin Chen * the parent HWPT in a nesting configuration. 3575f9bdbf4SJoao Martins * @IOMMU_HWPT_ALLOC_DIRTY_TRACKING: Dirty tracking support for device IOMMU is 3585f9bdbf4SJoao Martins * enforced on device attachment 3594ff54216SYi Liu */ 3604ff54216SYi Liu enum iommufd_hwpt_alloc_flags { 3614ff54216SYi Liu IOMMU_HWPT_ALLOC_NEST_PARENT = 1 << 0, 3625f9bdbf4SJoao Martins IOMMU_HWPT_ALLOC_DIRTY_TRACKING = 1 << 1, 3634ff54216SYi Liu }; 3644ff54216SYi Liu 3654ff54216SYi Liu /** 36682b6661cSYi Liu * enum iommu_hwpt_vtd_s1_flags - Intel VT-d stage-1 page table 36782b6661cSYi Liu * entry attributes 36882b6661cSYi Liu * @IOMMU_VTD_S1_SRE: Supervisor request 36982b6661cSYi Liu * @IOMMU_VTD_S1_EAFE: Extended access enable 37082b6661cSYi Liu * @IOMMU_VTD_S1_WPE: Write protect enable 37182b6661cSYi Liu */ 37282b6661cSYi Liu enum iommu_hwpt_vtd_s1_flags { 37382b6661cSYi Liu IOMMU_VTD_S1_SRE = 1 << 0, 37482b6661cSYi Liu IOMMU_VTD_S1_EAFE = 1 << 1, 37582b6661cSYi Liu IOMMU_VTD_S1_WPE = 1 << 2, 37682b6661cSYi Liu }; 37782b6661cSYi Liu 37882b6661cSYi Liu /** 37982b6661cSYi Liu * struct iommu_hwpt_vtd_s1 - Intel VT-d stage-1 page table 38082b6661cSYi Liu * info (IOMMU_HWPT_DATA_VTD_S1) 38182b6661cSYi Liu * @flags: Combination of enum iommu_hwpt_vtd_s1_flags 38282b6661cSYi Liu * @pgtbl_addr: The base address of the stage-1 page table. 38382b6661cSYi Liu * @addr_width: The address width of the stage-1 page table 38482b6661cSYi Liu * @__reserved: Must be 0 38582b6661cSYi Liu */ 38682b6661cSYi Liu struct iommu_hwpt_vtd_s1 { 38782b6661cSYi Liu __aligned_u64 flags; 38882b6661cSYi Liu __aligned_u64 pgtbl_addr; 38982b6661cSYi Liu __u32 addr_width; 39082b6661cSYi Liu __u32 __reserved; 39182b6661cSYi Liu }; 39282b6661cSYi Liu 39382b6661cSYi Liu /** 394bd529dbbSNicolin Chen * enum iommu_hwpt_data_type - IOMMU HWPT Data Type 395bd529dbbSNicolin Chen * @IOMMU_HWPT_DATA_NONE: no data 39682b6661cSYi Liu * @IOMMU_HWPT_DATA_VTD_S1: Intel VT-d stage-1 page table 397bd529dbbSNicolin Chen */ 398bd529dbbSNicolin Chen enum iommu_hwpt_data_type { 399bd529dbbSNicolin Chen IOMMU_HWPT_DATA_NONE, 40082b6661cSYi Liu IOMMU_HWPT_DATA_VTD_S1, 401bd529dbbSNicolin Chen }; 402bd529dbbSNicolin Chen 403bd529dbbSNicolin Chen /** 4047074d7bdSJason Gunthorpe * struct iommu_hwpt_alloc - ioctl(IOMMU_HWPT_ALLOC) 4057074d7bdSJason Gunthorpe * @size: sizeof(struct iommu_hwpt_alloc) 4064ff54216SYi Liu * @flags: Combination of enum iommufd_hwpt_alloc_flags 4077074d7bdSJason Gunthorpe * @dev_id: The device to allocate this HWPT for 408bd529dbbSNicolin Chen * @pt_id: The IOAS or HWPT to connect this HWPT to 4097074d7bdSJason Gunthorpe * @out_hwpt_id: The ID of the new HWPT 4107074d7bdSJason Gunthorpe * @__reserved: Must be 0 411bd529dbbSNicolin Chen * @data_type: One of enum iommu_hwpt_data_type 412bd529dbbSNicolin Chen * @data_len: Length of the type specific data 413bd529dbbSNicolin Chen * @data_uptr: User pointer to the type specific data 4147074d7bdSJason Gunthorpe * 4157074d7bdSJason Gunthorpe * Explicitly allocate a hardware page table object. This is the same object 4167074d7bdSJason Gunthorpe * type that is returned by iommufd_device_attach() and represents the 4177074d7bdSJason Gunthorpe * underlying iommu driver's iommu_domain kernel object. 4187074d7bdSJason Gunthorpe * 419bd529dbbSNicolin Chen * A kernel-managed HWPT will be created with the mappings from the given 420bd529dbbSNicolin Chen * IOAS via the @pt_id. The @data_type for this allocation must be set to 421bd529dbbSNicolin Chen * IOMMU_HWPT_DATA_NONE. The HWPT can be allocated as a parent HWPT for a 422bd529dbbSNicolin Chen * nesting configuration by passing IOMMU_HWPT_ALLOC_NEST_PARENT via @flags. 423bd529dbbSNicolin Chen * 424bd529dbbSNicolin Chen * A user-managed nested HWPT will be created from a given parent HWPT via 425bd529dbbSNicolin Chen * @pt_id, in which the parent HWPT must be allocated previously via the 426bd529dbbSNicolin Chen * same ioctl from a given IOAS (@pt_id). In this case, the @data_type 427bd529dbbSNicolin Chen * must be set to a pre-defined type corresponding to an I/O page table 428bd529dbbSNicolin Chen * type supported by the underlying IOMMU hardware. 429bd529dbbSNicolin Chen * 430bd529dbbSNicolin Chen * If the @data_type is set to IOMMU_HWPT_DATA_NONE, @data_len and 431bd529dbbSNicolin Chen * @data_uptr should be zero. Otherwise, both @data_len and @data_uptr 432bd529dbbSNicolin Chen * must be given. 4337074d7bdSJason Gunthorpe */ 4347074d7bdSJason Gunthorpe struct iommu_hwpt_alloc { 4357074d7bdSJason Gunthorpe __u32 size; 4367074d7bdSJason Gunthorpe __u32 flags; 4377074d7bdSJason Gunthorpe __u32 dev_id; 4387074d7bdSJason Gunthorpe __u32 pt_id; 4397074d7bdSJason Gunthorpe __u32 out_hwpt_id; 4407074d7bdSJason Gunthorpe __u32 __reserved; 441bd529dbbSNicolin Chen __u32 data_type; 442bd529dbbSNicolin Chen __u32 data_len; 443bd529dbbSNicolin Chen __aligned_u64 data_uptr; 4447074d7bdSJason Gunthorpe }; 4457074d7bdSJason Gunthorpe #define IOMMU_HWPT_ALLOC _IO(IOMMUFD_TYPE, IOMMUFD_CMD_HWPT_ALLOC) 44660fedb26SLu Baolu 44760fedb26SLu Baolu /** 44803476e68SLu Baolu * enum iommu_hw_info_vtd_flags - Flags for VT-d hw_info 44903476e68SLu Baolu * @IOMMU_HW_INFO_VTD_ERRATA_772415_SPR17: If set, disallow read-only mappings 45003476e68SLu Baolu * on a nested_parent domain. 45103476e68SLu Baolu * https://www.intel.com/content/www/us/en/content-details/772415/content-details.html 45203476e68SLu Baolu */ 45303476e68SLu Baolu enum iommu_hw_info_vtd_flags { 45403476e68SLu Baolu IOMMU_HW_INFO_VTD_ERRATA_772415_SPR17 = 1 << 0, 45503476e68SLu Baolu }; 45603476e68SLu Baolu 45703476e68SLu Baolu /** 45855243393SYi Liu * struct iommu_hw_info_vtd - Intel VT-d hardware information 45955243393SYi Liu * 46003476e68SLu Baolu * @flags: Combination of enum iommu_hw_info_vtd_flags 46155243393SYi Liu * @__reserved: Must be 0 46255243393SYi Liu * 46355243393SYi Liu * @cap_reg: Value of Intel VT-d capability register defined in VT-d spec 46455243393SYi Liu * section 11.4.2 Capability Register. 46555243393SYi Liu * @ecap_reg: Value of Intel VT-d capability register defined in VT-d spec 46655243393SYi Liu * section 11.4.3 Extended Capability Register. 46755243393SYi Liu * 46855243393SYi Liu * User needs to understand the Intel VT-d specification to decode the 46955243393SYi Liu * register value. 47055243393SYi Liu */ 47155243393SYi Liu struct iommu_hw_info_vtd { 47255243393SYi Liu __u32 flags; 47355243393SYi Liu __u32 __reserved; 47455243393SYi Liu __aligned_u64 cap_reg; 47555243393SYi Liu __aligned_u64 ecap_reg; 47655243393SYi Liu }; 47755243393SYi Liu 47855243393SYi Liu /** 47960fedb26SLu Baolu * enum iommu_hw_info_type - IOMMU Hardware Info Types 48060fedb26SLu Baolu * @IOMMU_HW_INFO_TYPE_NONE: Used by the drivers that do not report hardware 48160fedb26SLu Baolu * info 48255243393SYi Liu * @IOMMU_HW_INFO_TYPE_INTEL_VTD: Intel VT-d iommu info type 48360fedb26SLu Baolu */ 48460fedb26SLu Baolu enum iommu_hw_info_type { 48560fedb26SLu Baolu IOMMU_HW_INFO_TYPE_NONE, 48655243393SYi Liu IOMMU_HW_INFO_TYPE_INTEL_VTD, 48760fedb26SLu Baolu }; 48855dd4023SYi Liu 48955dd4023SYi Liu /** 49076236838SJoao Martins * enum iommufd_hw_capabilities 49176236838SJoao Martins * @IOMMU_HW_CAP_DIRTY_TRACKING: IOMMU hardware support for dirty tracking 49276236838SJoao Martins * If available, it means the following APIs 49376236838SJoao Martins * are supported: 49476236838SJoao Martins * 49576236838SJoao Martins * IOMMU_HWPT_GET_DIRTY_BITMAP 49676236838SJoao Martins * IOMMU_HWPT_SET_DIRTY_TRACKING 49776236838SJoao Martins * 49876236838SJoao Martins */ 49976236838SJoao Martins enum iommufd_hw_capabilities { 50076236838SJoao Martins IOMMU_HW_CAP_DIRTY_TRACKING = 1 << 0, 50176236838SJoao Martins }; 50276236838SJoao Martins 50376236838SJoao Martins /** 50455dd4023SYi Liu * struct iommu_hw_info - ioctl(IOMMU_GET_HW_INFO) 50555dd4023SYi Liu * @size: sizeof(struct iommu_hw_info) 50655dd4023SYi Liu * @flags: Must be 0 50755dd4023SYi Liu * @dev_id: The device bound to the iommufd 50855dd4023SYi Liu * @data_len: Input the length of a user buffer in bytes. Output the length of 50955dd4023SYi Liu * data that kernel supports 51055dd4023SYi Liu * @data_uptr: User pointer to a user-space buffer used by the kernel to fill 51155dd4023SYi Liu * the iommu type specific hardware information data 51255dd4023SYi Liu * @out_data_type: Output the iommu hardware info type as defined in the enum 51355dd4023SYi Liu * iommu_hw_info_type. 51476236838SJoao Martins * @out_capabilities: Output the generic iommu capability info type as defined 51576236838SJoao Martins * in the enum iommu_hw_capabilities. 51655dd4023SYi Liu * @__reserved: Must be 0 51755dd4023SYi Liu * 51855dd4023SYi Liu * Query an iommu type specific hardware information data from an iommu behind 51955dd4023SYi Liu * a given device that has been bound to iommufd. This hardware info data will 52055dd4023SYi Liu * be used to sync capabilities between the virtual iommu and the physical 52155dd4023SYi Liu * iommu, e.g. a nested translation setup needs to check the hardware info, so 52255dd4023SYi Liu * a guest stage-1 page table can be compatible with the physical iommu. 52355dd4023SYi Liu * 52455dd4023SYi Liu * To capture an iommu type specific hardware information data, @data_uptr and 52555dd4023SYi Liu * its length @data_len must be provided. Trailing bytes will be zeroed if the 52655dd4023SYi Liu * user buffer is larger than the data that kernel has. Otherwise, kernel only 52755dd4023SYi Liu * fills the buffer using the given length in @data_len. If the ioctl succeeds, 52855dd4023SYi Liu * @data_len will be updated to the length that kernel actually supports, 52955dd4023SYi Liu * @out_data_type will be filled to decode the data filled in the buffer 53055dd4023SYi Liu * pointed by @data_uptr. Input @data_len == zero is allowed. 53155dd4023SYi Liu */ 53255dd4023SYi Liu struct iommu_hw_info { 53355dd4023SYi Liu __u32 size; 53455dd4023SYi Liu __u32 flags; 53555dd4023SYi Liu __u32 dev_id; 53655dd4023SYi Liu __u32 data_len; 53755dd4023SYi Liu __aligned_u64 data_uptr; 53855dd4023SYi Liu __u32 out_data_type; 53955dd4023SYi Liu __u32 __reserved; 54076236838SJoao Martins __aligned_u64 out_capabilities; 54155dd4023SYi Liu }; 54255dd4023SYi Liu #define IOMMU_GET_HW_INFO _IO(IOMMUFD_TYPE, IOMMUFD_CMD_GET_HW_INFO) 543e2a4b294SJoao Martins 544e2a4b294SJoao Martins /* 545e2a4b294SJoao Martins * enum iommufd_hwpt_set_dirty_tracking_flags - Flags for steering dirty 546e2a4b294SJoao Martins * tracking 547e2a4b294SJoao Martins * @IOMMU_HWPT_DIRTY_TRACKING_ENABLE: Enable dirty tracking 548e2a4b294SJoao Martins */ 549e2a4b294SJoao Martins enum iommufd_hwpt_set_dirty_tracking_flags { 550e2a4b294SJoao Martins IOMMU_HWPT_DIRTY_TRACKING_ENABLE = 1, 551e2a4b294SJoao Martins }; 552e2a4b294SJoao Martins 553e2a4b294SJoao Martins /** 554e2a4b294SJoao Martins * struct iommu_hwpt_set_dirty_tracking - ioctl(IOMMU_HWPT_SET_DIRTY_TRACKING) 555e2a4b294SJoao Martins * @size: sizeof(struct iommu_hwpt_set_dirty_tracking) 556e2a4b294SJoao Martins * @flags: Combination of enum iommufd_hwpt_set_dirty_tracking_flags 557e2a4b294SJoao Martins * @hwpt_id: HW pagetable ID that represents the IOMMU domain 558e2a4b294SJoao Martins * @__reserved: Must be 0 559e2a4b294SJoao Martins * 560e2a4b294SJoao Martins * Toggle dirty tracking on an HW pagetable. 561e2a4b294SJoao Martins */ 562e2a4b294SJoao Martins struct iommu_hwpt_set_dirty_tracking { 563e2a4b294SJoao Martins __u32 size; 564e2a4b294SJoao Martins __u32 flags; 565e2a4b294SJoao Martins __u32 hwpt_id; 566e2a4b294SJoao Martins __u32 __reserved; 567e2a4b294SJoao Martins }; 568e2a4b294SJoao Martins #define IOMMU_HWPT_SET_DIRTY_TRACKING _IO(IOMMUFD_TYPE, \ 569e2a4b294SJoao Martins IOMMUFD_CMD_HWPT_SET_DIRTY_TRACKING) 570b9a60d6fSJoao Martins 571b9a60d6fSJoao Martins /** 57260984813SJoao Martins * enum iommufd_hwpt_get_dirty_bitmap_flags - Flags for getting dirty bits 57360984813SJoao Martins * @IOMMU_HWPT_GET_DIRTY_BITMAP_NO_CLEAR: Just read the PTEs without clearing 57460984813SJoao Martins * any dirty bits metadata. This flag 57560984813SJoao Martins * can be passed in the expectation 57660984813SJoao Martins * where the next operation is an unmap 57760984813SJoao Martins * of the same IOVA range. 57860984813SJoao Martins * 57960984813SJoao Martins */ 58060984813SJoao Martins enum iommufd_hwpt_get_dirty_bitmap_flags { 58160984813SJoao Martins IOMMU_HWPT_GET_DIRTY_BITMAP_NO_CLEAR = 1, 58260984813SJoao Martins }; 58360984813SJoao Martins 58460984813SJoao Martins /** 585b9a60d6fSJoao Martins * struct iommu_hwpt_get_dirty_bitmap - ioctl(IOMMU_HWPT_GET_DIRTY_BITMAP) 586b9a60d6fSJoao Martins * @size: sizeof(struct iommu_hwpt_get_dirty_bitmap) 587b9a60d6fSJoao Martins * @hwpt_id: HW pagetable ID that represents the IOMMU domain 58860984813SJoao Martins * @flags: Combination of enum iommufd_hwpt_get_dirty_bitmap_flags 589b9a60d6fSJoao Martins * @__reserved: Must be 0 590b9a60d6fSJoao Martins * @iova: base IOVA of the bitmap first bit 591b9a60d6fSJoao Martins * @length: IOVA range size 592b9a60d6fSJoao Martins * @page_size: page size granularity of each bit in the bitmap 593b9a60d6fSJoao Martins * @data: bitmap where to set the dirty bits. The bitmap bits each 594b9a60d6fSJoao Martins * represent a page_size which you deviate from an arbitrary iova. 595b9a60d6fSJoao Martins * 596b9a60d6fSJoao Martins * Checking a given IOVA is dirty: 597b9a60d6fSJoao Martins * 598b9a60d6fSJoao Martins * data[(iova / page_size) / 64] & (1ULL << ((iova / page_size) % 64)) 599b9a60d6fSJoao Martins * 600b9a60d6fSJoao Martins * Walk the IOMMU pagetables for a given IOVA range to return a bitmap 601b9a60d6fSJoao Martins * with the dirty IOVAs. In doing so it will also by default clear any 602b9a60d6fSJoao Martins * dirty bit metadata set in the IOPTE. 603b9a60d6fSJoao Martins */ 604b9a60d6fSJoao Martins struct iommu_hwpt_get_dirty_bitmap { 605b9a60d6fSJoao Martins __u32 size; 606b9a60d6fSJoao Martins __u32 hwpt_id; 607b9a60d6fSJoao Martins __u32 flags; 608b9a60d6fSJoao Martins __u32 __reserved; 609b9a60d6fSJoao Martins __aligned_u64 iova; 610b9a60d6fSJoao Martins __aligned_u64 length; 611b9a60d6fSJoao Martins __aligned_u64 page_size; 612b9a60d6fSJoao Martins __aligned_u64 data; 613b9a60d6fSJoao Martins }; 614b9a60d6fSJoao Martins #define IOMMU_HWPT_GET_DIRTY_BITMAP _IO(IOMMUFD_TYPE, \ 615b9a60d6fSJoao Martins IOMMUFD_CMD_HWPT_GET_DIRTY_BITMAP) 616b9a60d6fSJoao Martins 6178c6eabaeSYi Liu /** 6188c6eabaeSYi Liu * enum iommu_hwpt_invalidate_data_type - IOMMU HWPT Cache Invalidation 6198c6eabaeSYi Liu * Data Type 6208c6eabaeSYi Liu * @IOMMU_HWPT_INVALIDATE_DATA_VTD_S1: Invalidation data for VTD_S1 6218c6eabaeSYi Liu */ 6228c6eabaeSYi Liu enum iommu_hwpt_invalidate_data_type { 6238c6eabaeSYi Liu IOMMU_HWPT_INVALIDATE_DATA_VTD_S1, 6248c6eabaeSYi Liu }; 6258c6eabaeSYi Liu 6268c6eabaeSYi Liu /** 627*393a5778SYi Liu * enum iommu_hwpt_vtd_s1_invalidate_flags - Flags for Intel VT-d 628*393a5778SYi Liu * stage-1 cache invalidation 629*393a5778SYi Liu * @IOMMU_VTD_INV_FLAGS_LEAF: Indicates whether the invalidation applies 630*393a5778SYi Liu * to all-levels page structure cache or just 631*393a5778SYi Liu * the leaf PTE cache. 632*393a5778SYi Liu */ 633*393a5778SYi Liu enum iommu_hwpt_vtd_s1_invalidate_flags { 634*393a5778SYi Liu IOMMU_VTD_INV_FLAGS_LEAF = 1 << 0, 635*393a5778SYi Liu }; 636*393a5778SYi Liu 637*393a5778SYi Liu /** 638*393a5778SYi Liu * struct iommu_hwpt_vtd_s1_invalidate - Intel VT-d cache invalidation 639*393a5778SYi Liu * (IOMMU_HWPT_INVALIDATE_DATA_VTD_S1) 640*393a5778SYi Liu * @addr: The start address of the range to be invalidated. It needs to 641*393a5778SYi Liu * be 4KB aligned. 642*393a5778SYi Liu * @npages: Number of contiguous 4K pages to be invalidated. 643*393a5778SYi Liu * @flags: Combination of enum iommu_hwpt_vtd_s1_invalidate_flags 644*393a5778SYi Liu * @__reserved: Must be 0 645*393a5778SYi Liu * 646*393a5778SYi Liu * The Intel VT-d specific invalidation data for user-managed stage-1 cache 647*393a5778SYi Liu * invalidation in nested translation. Userspace uses this structure to 648*393a5778SYi Liu * tell the impacted cache scope after modifying the stage-1 page table. 649*393a5778SYi Liu * 650*393a5778SYi Liu * Invalidating all the caches related to the page table by setting @addr 651*393a5778SYi Liu * to be 0 and @npages to be U64_MAX. 652*393a5778SYi Liu * 653*393a5778SYi Liu * The device TLB will be invalidated automatically if ATS is enabled. 654*393a5778SYi Liu */ 655*393a5778SYi Liu struct iommu_hwpt_vtd_s1_invalidate { 656*393a5778SYi Liu __aligned_u64 addr; 657*393a5778SYi Liu __aligned_u64 npages; 658*393a5778SYi Liu __u32 flags; 659*393a5778SYi Liu __u32 __reserved; 660*393a5778SYi Liu }; 661*393a5778SYi Liu 662*393a5778SYi Liu /** 6638c6eabaeSYi Liu * struct iommu_hwpt_invalidate - ioctl(IOMMU_HWPT_INVALIDATE) 6648c6eabaeSYi Liu * @size: sizeof(struct iommu_hwpt_invalidate) 6658c6eabaeSYi Liu * @hwpt_id: ID of a nested HWPT for cache invalidation 6668c6eabaeSYi Liu * @data_uptr: User pointer to an array of driver-specific cache invalidation 6678c6eabaeSYi Liu * data. 6688c6eabaeSYi Liu * @data_type: One of enum iommu_hwpt_invalidate_data_type, defining the data 6698c6eabaeSYi Liu * type of all the entries in the invalidation request array. It 6708c6eabaeSYi Liu * should be a type supported by the hwpt pointed by @hwpt_id. 6718c6eabaeSYi Liu * @entry_len: Length (in bytes) of a request entry in the request array 6728c6eabaeSYi Liu * @entry_num: Input the number of cache invalidation requests in the array. 6738c6eabaeSYi Liu * Output the number of requests successfully handled by kernel. 6748c6eabaeSYi Liu * @__reserved: Must be 0. 6758c6eabaeSYi Liu * 6768c6eabaeSYi Liu * Invalidate the iommu cache for user-managed page table. Modifications on a 6778c6eabaeSYi Liu * user-managed page table should be followed by this operation to sync cache. 6788c6eabaeSYi Liu * Each ioctl can support one or more cache invalidation requests in the array 6798c6eabaeSYi Liu * that has a total size of @entry_len * @entry_num. 6808c6eabaeSYi Liu * 6818c6eabaeSYi Liu * An empty invalidation request array by setting @entry_num==0 is allowed, and 6828c6eabaeSYi Liu * @entry_len and @data_uptr would be ignored in this case. This can be used to 6838c6eabaeSYi Liu * check if the given @data_type is supported or not by kernel. 6848c6eabaeSYi Liu */ 6858c6eabaeSYi Liu struct iommu_hwpt_invalidate { 6868c6eabaeSYi Liu __u32 size; 6878c6eabaeSYi Liu __u32 hwpt_id; 6888c6eabaeSYi Liu __aligned_u64 data_uptr; 6898c6eabaeSYi Liu __u32 data_type; 6908c6eabaeSYi Liu __u32 entry_len; 6918c6eabaeSYi Liu __u32 entry_num; 6928c6eabaeSYi Liu __u32 __reserved; 6938c6eabaeSYi Liu }; 6948c6eabaeSYi Liu #define IOMMU_HWPT_INVALIDATE _IO(IOMMUFD_TYPE, IOMMUFD_CMD_HWPT_INVALIDATE) 6952ff4bed7SJason Gunthorpe #endif 696