iommu.h 4.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161
  1. /* SPDX-License-Identifier: GPL-2.0 WITH Linux-syscall-note */
  2. /*
  3. * IOMMU user API definitions
  4. */
  5. #ifndef _UAPI_IOMMU_H
  6. #define _UAPI_IOMMU_H
  7. #include <linux/types.h>
  8. #define IOMMU_FAULT_PERM_READ (1 << 0) /* read */
  9. #define IOMMU_FAULT_PERM_WRITE (1 << 1) /* write */
  10. #define IOMMU_FAULT_PERM_EXEC (1 << 2) /* exec */
  11. #define IOMMU_FAULT_PERM_PRIV (1 << 3) /* privileged */
  12. /* Generic fault types, can be expanded IRQ remapping fault */
  13. enum iommu_fault_type {
  14. IOMMU_FAULT_DMA_UNRECOV = 1, /* unrecoverable fault */
  15. IOMMU_FAULT_PAGE_REQ, /* page request fault */
  16. };
  17. enum iommu_fault_reason {
  18. IOMMU_FAULT_REASON_UNKNOWN = 0,
  19. /* Could not access the PASID table (fetch caused external abort) */
  20. IOMMU_FAULT_REASON_PASID_FETCH,
  21. /* PASID entry is invalid or has configuration errors */
  22. IOMMU_FAULT_REASON_BAD_PASID_ENTRY,
  23. /*
  24. * PASID is out of range (e.g. exceeds the maximum PASID
  25. * supported by the IOMMU) or disabled.
  26. */
  27. IOMMU_FAULT_REASON_PASID_INVALID,
  28. /*
  29. * An external abort occurred fetching (or updating) a translation
  30. * table descriptor
  31. */
  32. IOMMU_FAULT_REASON_WALK_EABT,
  33. /*
  34. * Could not access the page table entry (Bad address),
  35. * actual translation fault
  36. */
  37. IOMMU_FAULT_REASON_PTE_FETCH,
  38. /* Protection flag check failed */
  39. IOMMU_FAULT_REASON_PERMISSION,
  40. /* access flag check failed */
  41. IOMMU_FAULT_REASON_ACCESS,
  42. /* Output address of a translation stage caused Address Size fault */
  43. IOMMU_FAULT_REASON_OOR_ADDRESS,
  44. };
  45. /**
  46. * struct iommu_fault_unrecoverable - Unrecoverable fault data
  47. * @reason: reason of the fault, from &enum iommu_fault_reason
  48. * @flags: parameters of this fault (IOMMU_FAULT_UNRECOV_* values)
  49. * @pasid: Process Address Space ID
  50. * @perm: requested permission access using by the incoming transaction
  51. * (IOMMU_FAULT_PERM_* values)
  52. * @addr: offending page address
  53. * @fetch_addr: address that caused a fetch abort, if any
  54. */
  55. struct iommu_fault_unrecoverable {
  56. __u32 reason;
  57. #define IOMMU_FAULT_UNRECOV_PASID_VALID (1 << 0)
  58. #define IOMMU_FAULT_UNRECOV_ADDR_VALID (1 << 1)
  59. #define IOMMU_FAULT_UNRECOV_FETCH_ADDR_VALID (1 << 2)
  60. __u32 flags;
  61. __u32 pasid;
  62. __u32 perm;
  63. __u64 addr;
  64. __u64 fetch_addr;
  65. };
  66. /**
  67. * struct iommu_fault_page_request - Page Request data
  68. * @flags: encodes whether the corresponding fields are valid and whether this
  69. * is the last page in group (IOMMU_FAULT_PAGE_REQUEST_* values).
  70. * When IOMMU_FAULT_PAGE_RESPONSE_NEEDS_PASID is set, the page response
  71. * must have the same PASID value as the page request. When it is clear,
  72. * the page response should not have a PASID.
  73. * @pasid: Process Address Space ID
  74. * @grpid: Page Request Group Index
  75. * @perm: requested page permissions (IOMMU_FAULT_PERM_* values)
  76. * @addr: page address
  77. * @private_data: device-specific private information
  78. */
  79. struct iommu_fault_page_request {
  80. #define IOMMU_FAULT_PAGE_REQUEST_PASID_VALID (1 << 0)
  81. #define IOMMU_FAULT_PAGE_REQUEST_LAST_PAGE (1 << 1)
  82. #define IOMMU_FAULT_PAGE_REQUEST_PRIV_DATA (1 << 2)
  83. #define IOMMU_FAULT_PAGE_RESPONSE_NEEDS_PASID (1 << 3)
  84. __u32 flags;
  85. __u32 pasid;
  86. __u32 grpid;
  87. __u32 perm;
  88. __u64 addr;
  89. __u64 private_data[2];
  90. };
  91. /**
  92. * struct iommu_fault - Generic fault data
  93. * @type: fault type from &enum iommu_fault_type
  94. * @padding: reserved for future use (should be zero)
  95. * @event: fault event, when @type is %IOMMU_FAULT_DMA_UNRECOV
  96. * @prm: Page Request message, when @type is %IOMMU_FAULT_PAGE_REQ
  97. * @padding2: sets the fault size to allow for future extensions
  98. */
  99. struct iommu_fault {
  100. __u32 type;
  101. __u32 padding;
  102. union {
  103. struct iommu_fault_unrecoverable event;
  104. struct iommu_fault_page_request prm;
  105. __u8 padding2[56];
  106. };
  107. };
  108. /**
  109. * enum iommu_page_response_code - Return status of fault handlers
  110. * @IOMMU_PAGE_RESP_SUCCESS: Fault has been handled and the page tables
  111. * populated, retry the access. This is "Success" in PCI PRI.
  112. * @IOMMU_PAGE_RESP_FAILURE: General error. Drop all subsequent faults from
  113. * this device if possible. This is "Response Failure" in PCI PRI.
  114. * @IOMMU_PAGE_RESP_INVALID: Could not handle this fault, don't retry the
  115. * access. This is "Invalid Request" in PCI PRI.
  116. */
  117. enum iommu_page_response_code {
  118. IOMMU_PAGE_RESP_SUCCESS = 0,
  119. IOMMU_PAGE_RESP_INVALID,
  120. IOMMU_PAGE_RESP_FAILURE,
  121. };
  122. /**
  123. * struct iommu_page_response - Generic page response information
  124. * @argsz: User filled size of this data
  125. * @version: API version of this structure
  126. * @flags: encodes whether the corresponding fields are valid
  127. * (IOMMU_FAULT_PAGE_RESPONSE_* values)
  128. * @pasid: Process Address Space ID
  129. * @grpid: Page Request Group Index
  130. * @code: response code from &enum iommu_page_response_code
  131. */
  132. struct iommu_page_response {
  133. __u32 argsz;
  134. #define IOMMU_PAGE_RESP_VERSION_1 1
  135. __u32 version;
  136. #define IOMMU_PAGE_RESP_PASID_VALID (1 << 0)
  137. __u32 flags;
  138. __u32 pasid;
  139. __u32 grpid;
  140. __u32 code;
  141. };
  142. #endif /* _UAPI_IOMMU_H */