2
0

iommufd.h 36 KB

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