Joerg Roedel | 4a77a6c | 2008-11-26 17:02:33 +0100 | [diff] [blame] | 1 | /* |
| 2 | * Copyright (C) 2007-2008 Advanced Micro Devices, Inc. |
| 3 | * Author: Joerg Roedel <joerg.roedel@amd.com> |
| 4 | * |
| 5 | * This program is free software; you can redistribute it and/or modify it |
| 6 | * under the terms of the GNU General Public License version 2 as published |
| 7 | * by the Free Software Foundation. |
| 8 | * |
| 9 | * This program is distributed in the hope that it will be useful, |
| 10 | * but WITHOUT ANY WARRANTY; without even the implied warranty of |
| 11 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
| 12 | * GNU General Public License for more details. |
| 13 | * |
| 14 | * You should have received a copy of the GNU General Public License |
| 15 | * along with this program; if not, write to the Free Software |
| 16 | * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA |
| 17 | */ |
| 18 | |
| 19 | #ifndef __LINUX_IOMMU_H |
| 20 | #define __LINUX_IOMMU_H |
| 21 | |
Joerg Roedel | e8245c1 | 2017-04-26 15:34:06 +0200 | [diff] [blame] | 22 | #include <linux/scatterlist.h> |
| 23 | #include <linux/device.h> |
| 24 | #include <linux/types.h> |
Laura Abbott | 74315cc | 2011-06-08 17:29:11 -0400 | [diff] [blame] | 25 | #include <linux/errno.h> |
Wang YanQing | 9a08d37 | 2013-04-19 09:38:04 +0800 | [diff] [blame] | 26 | #include <linux/err.h> |
Will Deacon | d0f60a4 | 2014-08-27 16:15:59 +0100 | [diff] [blame] | 27 | #include <linux/of.h> |
Laura Abbott | 74315cc | 2011-06-08 17:29:11 -0400 | [diff] [blame] | 28 | |
Will Deacon | ca13bb3 | 2013-11-05 15:59:53 +0000 | [diff] [blame] | 29 | #define IOMMU_READ (1 << 0) |
| 30 | #define IOMMU_WRITE (1 << 1) |
| 31 | #define IOMMU_CACHE (1 << 2) /* DMA cache coherency */ |
Antonios Motakis | a720b41 | 2014-10-13 14:06:16 +0100 | [diff] [blame] | 32 | #define IOMMU_NOEXEC (1 << 3) |
Robin Murphy | 31e6850 | 2016-04-05 12:39:30 +0100 | [diff] [blame] | 33 | #define IOMMU_MMIO (1 << 4) /* e.g. things like MSI doorbells */ |
Mitchel Humpherys | 579b2a6 | 2017-01-06 18:58:08 +0530 | [diff] [blame] | 34 | /* |
Robin Murphy | adf5e51 | 2017-01-27 12:22:54 +0000 | [diff] [blame] | 35 | * Where the bus hardware includes a privilege level as part of its access type |
| 36 | * markings, and certain devices are capable of issuing transactions marked as |
| 37 | * either 'supervisor' or 'user', the IOMMU_PRIV flag requests that the other |
| 38 | * given permission flags only apply to accesses at the higher privilege level, |
| 39 | * and that unprivileged transactions should have as little access as possible. |
| 40 | * This would usually imply the same permissions as kernel mappings on the CPU, |
| 41 | * if the IOMMU page table format is equivalent. |
Mitchel Humpherys | 579b2a6 | 2017-01-06 18:58:08 +0530 | [diff] [blame] | 42 | */ |
| 43 | #define IOMMU_PRIV (1 << 5) |
Joerg Roedel | 4a77a6c | 2008-11-26 17:02:33 +0100 | [diff] [blame] | 44 | |
Joerg Roedel | 905d66c | 2011-09-06 16:03:26 +0200 | [diff] [blame] | 45 | struct iommu_ops; |
Alex Williamson | d72e31c | 2012-05-30 14:18:53 -0600 | [diff] [blame] | 46 | struct iommu_group; |
Joerg Roedel | ff21776 | 2011-08-26 16:48:26 +0200 | [diff] [blame] | 47 | struct bus_type; |
Joerg Roedel | 4a77a6c | 2008-11-26 17:02:33 +0100 | [diff] [blame] | 48 | struct device; |
Ohad Ben-Cohen | 4f3f8d9 | 2011-09-13 15:25:23 -0400 | [diff] [blame] | 49 | struct iommu_domain; |
Joerg Roedel | ba1eabfa | 2012-08-03 15:55:41 +0200 | [diff] [blame] | 50 | struct notifier_block; |
Jean-Philippe Brucker | 26b25a2 | 2019-04-10 16:15:16 +0100 | [diff] [blame] | 51 | struct iommu_sva; |
Ohad Ben-Cohen | 4f3f8d9 | 2011-09-13 15:25:23 -0400 | [diff] [blame] | 52 | |
| 53 | /* iommu fault flags */ |
| 54 | #define IOMMU_FAULT_READ 0x0 |
| 55 | #define IOMMU_FAULT_WRITE 0x1 |
| 56 | |
| 57 | typedef int (*iommu_fault_handler_t)(struct iommu_domain *, |
Ohad Ben-Cohen | 77ca233 | 2012-05-21 20:20:05 +0300 | [diff] [blame] | 58 | struct device *, unsigned long, int, void *); |
Jean-Philippe Brucker | 26b25a2 | 2019-04-10 16:15:16 +0100 | [diff] [blame] | 59 | typedef int (*iommu_mm_exit_handler_t)(struct device *dev, struct iommu_sva *, |
| 60 | void *); |
Joerg Roedel | 4a77a6c | 2008-11-26 17:02:33 +0100 | [diff] [blame] | 61 | |
Joerg Roedel | 0ff64f8 | 2012-01-26 19:40:53 +0100 | [diff] [blame] | 62 | struct iommu_domain_geometry { |
| 63 | dma_addr_t aperture_start; /* First address that can be mapped */ |
| 64 | dma_addr_t aperture_end; /* Last address that can be mapped */ |
| 65 | bool force_aperture; /* DMA only allowed in mappable range? */ |
| 66 | }; |
| 67 | |
Joerg Roedel | 8539c7c | 2015-03-26 13:43:05 +0100 | [diff] [blame] | 68 | /* Domain feature flags */ |
| 69 | #define __IOMMU_DOMAIN_PAGING (1U << 0) /* Support for iommu_map/unmap */ |
| 70 | #define __IOMMU_DOMAIN_DMA_API (1U << 1) /* Domain for use in DMA-API |
| 71 | implementation */ |
| 72 | #define __IOMMU_DOMAIN_PT (1U << 2) /* Domain is identity mapped */ |
| 73 | |
| 74 | /* |
| 75 | * This are the possible domain-types |
| 76 | * |
| 77 | * IOMMU_DOMAIN_BLOCKED - All DMA is blocked, can be used to isolate |
| 78 | * devices |
| 79 | * IOMMU_DOMAIN_IDENTITY - DMA addresses are system physical addresses |
| 80 | * IOMMU_DOMAIN_UNMANAGED - DMA mappings managed by IOMMU-API user, used |
| 81 | * for VMs |
| 82 | * IOMMU_DOMAIN_DMA - Internally used for DMA-API implementations. |
| 83 | * This flag allows IOMMU drivers to implement |
| 84 | * certain optimizations for these domains |
| 85 | */ |
| 86 | #define IOMMU_DOMAIN_BLOCKED (0U) |
| 87 | #define IOMMU_DOMAIN_IDENTITY (__IOMMU_DOMAIN_PT) |
| 88 | #define IOMMU_DOMAIN_UNMANAGED (__IOMMU_DOMAIN_PAGING) |
| 89 | #define IOMMU_DOMAIN_DMA (__IOMMU_DOMAIN_PAGING | \ |
| 90 | __IOMMU_DOMAIN_DMA_API) |
| 91 | |
Joerg Roedel | 4a77a6c | 2008-11-26 17:02:33 +0100 | [diff] [blame] | 92 | struct iommu_domain { |
Joerg Roedel | 8539c7c | 2015-03-26 13:43:05 +0100 | [diff] [blame] | 93 | unsigned type; |
Thierry Reding | b22f643 | 2014-06-27 09:03:12 +0200 | [diff] [blame] | 94 | const struct iommu_ops *ops; |
Robin Murphy | d16e0fa | 2016-04-07 18:42:06 +0100 | [diff] [blame] | 95 | unsigned long pgsize_bitmap; /* Bitmap of page sizes in use */ |
Ohad Ben-Cohen | 4f3f8d9 | 2011-09-13 15:25:23 -0400 | [diff] [blame] | 96 | iommu_fault_handler_t handler; |
Ohad Ben-Cohen | 77ca233 | 2012-05-21 20:20:05 +0300 | [diff] [blame] | 97 | void *handler_token; |
Joerg Roedel | 0ff64f8 | 2012-01-26 19:40:53 +0100 | [diff] [blame] | 98 | struct iommu_domain_geometry geometry; |
Robin Murphy | 0db2e5d | 2015-10-01 20:13:58 +0100 | [diff] [blame] | 99 | void *iova_cookie; |
Joerg Roedel | 4a77a6c | 2008-11-26 17:02:33 +0100 | [diff] [blame] | 100 | }; |
| 101 | |
Joerg Roedel | 1aed074 | 2014-09-03 18:34:04 +0200 | [diff] [blame] | 102 | enum iommu_cap { |
| 103 | IOMMU_CAP_CACHE_COHERENCY, /* IOMMU can enforce cache coherent DMA |
| 104 | transactions */ |
| 105 | IOMMU_CAP_INTR_REMAP, /* IOMMU supports interrupt isolation */ |
Antonios Motakis | c498664 | 2014-10-13 14:06:17 +0100 | [diff] [blame] | 106 | IOMMU_CAP_NOEXEC, /* IOMMU_NOEXEC flag */ |
Joerg Roedel | 1aed074 | 2014-09-03 18:34:04 +0200 | [diff] [blame] | 107 | }; |
Sheng Yang | dbb9fd8 | 2009-03-18 15:33:06 +0800 | [diff] [blame] | 108 | |
Varun Sethi | 7cabf49 | 2013-07-15 10:20:56 +0530 | [diff] [blame] | 109 | /* |
| 110 | * Following constraints are specifc to FSL_PAMUV1: |
| 111 | * -aperture must be power of 2, and naturally aligned |
| 112 | * -number of windows must be power of 2, and address space size |
| 113 | * of each window is determined by aperture size / # of windows |
| 114 | * -the actual size of the mapped region of a window must be power |
| 115 | * of 2 starting with 4KB and physical address must be naturally |
| 116 | * aligned. |
| 117 | * DOMAIN_ATTR_FSL_PAMUV1 corresponds to the above mentioned contraints. |
| 118 | * The caller can invoke iommu_domain_get_attr to check if the underlying |
| 119 | * iommu implementation supports these constraints. |
| 120 | */ |
| 121 | |
Joerg Roedel | 0cd76dd | 2012-01-26 19:40:52 +0100 | [diff] [blame] | 122 | enum iommu_attr { |
Joerg Roedel | 0ff64f8 | 2012-01-26 19:40:53 +0100 | [diff] [blame] | 123 | DOMAIN_ATTR_GEOMETRY, |
Joerg Roedel | d2e1216 | 2013-01-29 13:49:04 +0100 | [diff] [blame] | 124 | DOMAIN_ATTR_PAGING, |
Joerg Roedel | 6935671 | 2013-02-04 14:00:01 +0100 | [diff] [blame] | 125 | DOMAIN_ATTR_WINDOWS, |
Varun Sethi | 7cabf49 | 2013-07-15 10:20:56 +0530 | [diff] [blame] | 126 | DOMAIN_ATTR_FSL_PAMU_STASH, |
| 127 | DOMAIN_ATTR_FSL_PAMU_ENABLE, |
| 128 | DOMAIN_ATTR_FSL_PAMUV1, |
Will Deacon | c02607a | 2014-09-29 10:05:06 -0600 | [diff] [blame] | 129 | DOMAIN_ATTR_NESTING, /* two stages of translation */ |
Zhen Lei | 2da274c | 2018-09-20 17:10:22 +0100 | [diff] [blame] | 130 | DOMAIN_ATTR_DMA_USE_FLUSH_QUEUE, |
Joerg Roedel | a8b8a88a | 2013-01-29 14:36:31 +0100 | [diff] [blame] | 131 | DOMAIN_ATTR_MAX, |
Joerg Roedel | 0cd76dd | 2012-01-26 19:40:52 +0100 | [diff] [blame] | 132 | }; |
| 133 | |
Eric Auger | d30ddca | 2017-01-19 20:57:48 +0000 | [diff] [blame] | 134 | /* These are the possible reserved region types */ |
Robin Murphy | 9d3a4de | 2017-03-16 17:00:16 +0000 | [diff] [blame] | 135 | enum iommu_resv_type { |
| 136 | /* Memory regions which must be mapped 1:1 at all times */ |
| 137 | IOMMU_RESV_DIRECT, |
| 138 | /* Arbitrary "never map this or give it to a device" address ranges */ |
| 139 | IOMMU_RESV_RESERVED, |
| 140 | /* Hardware MSI region (untranslated) */ |
| 141 | IOMMU_RESV_MSI, |
| 142 | /* Software-managed MSI translation window */ |
| 143 | IOMMU_RESV_SW_MSI, |
| 144 | }; |
Eric Auger | d30ddca | 2017-01-19 20:57:48 +0000 | [diff] [blame] | 145 | |
Joerg Roedel | a1015c2 | 2015-05-28 18:41:33 +0200 | [diff] [blame] | 146 | /** |
Eric Auger | e5b5234 | 2017-01-19 20:57:47 +0000 | [diff] [blame] | 147 | * struct iommu_resv_region - descriptor for a reserved memory region |
Joerg Roedel | a1015c2 | 2015-05-28 18:41:33 +0200 | [diff] [blame] | 148 | * @list: Linked list pointers |
| 149 | * @start: System physical start address of the region |
| 150 | * @length: Length of the region in bytes |
| 151 | * @prot: IOMMU Protection flags (READ/WRITE/...) |
Eric Auger | d30ddca | 2017-01-19 20:57:48 +0000 | [diff] [blame] | 152 | * @type: Type of the reserved region |
Joerg Roedel | a1015c2 | 2015-05-28 18:41:33 +0200 | [diff] [blame] | 153 | */ |
Eric Auger | e5b5234 | 2017-01-19 20:57:47 +0000 | [diff] [blame] | 154 | struct iommu_resv_region { |
Joerg Roedel | a1015c2 | 2015-05-28 18:41:33 +0200 | [diff] [blame] | 155 | struct list_head list; |
| 156 | phys_addr_t start; |
| 157 | size_t length; |
| 158 | int prot; |
Robin Murphy | 9d3a4de | 2017-03-16 17:00:16 +0000 | [diff] [blame] | 159 | enum iommu_resv_type type; |
Joerg Roedel | a1015c2 | 2015-05-28 18:41:33 +0200 | [diff] [blame] | 160 | }; |
| 161 | |
Lu Baolu | a3a1959 | 2019-03-25 09:30:28 +0800 | [diff] [blame] | 162 | /* Per device IOMMU features */ |
| 163 | enum iommu_dev_features { |
| 164 | IOMMU_DEV_FEAT_AUX, /* Aux-domain feature */ |
Jean-Philippe Brucker | 26b25a2 | 2019-04-10 16:15:16 +0100 | [diff] [blame] | 165 | IOMMU_DEV_FEAT_SVA, /* Shared Virtual Addresses */ |
| 166 | }; |
| 167 | |
| 168 | #define IOMMU_PASID_INVALID (-1U) |
| 169 | |
| 170 | /** |
| 171 | * struct iommu_sva_ops - device driver callbacks for an SVA context |
| 172 | * |
| 173 | * @mm_exit: called when the mm is about to be torn down by exit_mmap. After |
| 174 | * @mm_exit returns, the device must not issue any more transaction |
| 175 | * with the PASID given as argument. |
| 176 | * |
| 177 | * The @mm_exit handler is allowed to sleep. Be careful about the |
| 178 | * locks taken in @mm_exit, because they might lead to deadlocks if |
| 179 | * they are also held when dropping references to the mm. Consider the |
| 180 | * following call chain: |
| 181 | * mutex_lock(A); mmput(mm) -> exit_mm() -> @mm_exit() -> mutex_lock(A) |
| 182 | * Using mmput_async() prevents this scenario. |
| 183 | * |
| 184 | */ |
| 185 | struct iommu_sva_ops { |
| 186 | iommu_mm_exit_handler_t mm_exit; |
Lu Baolu | a3a1959 | 2019-03-25 09:30:28 +0800 | [diff] [blame] | 187 | }; |
| 188 | |
Joerg Roedel | 39d4ebb | 2011-09-06 16:48:40 +0200 | [diff] [blame] | 189 | #ifdef CONFIG_IOMMU_API |
| 190 | |
Ohad Ben-Cohen | 7d3002c | 2011-11-10 11:32:26 +0200 | [diff] [blame] | 191 | /** |
| 192 | * struct iommu_ops - iommu ops and capabilities |
Magnus Damm | 0d9bacb | 2016-01-19 14:28:48 +0900 | [diff] [blame] | 193 | * @capable: check capability |
| 194 | * @domain_alloc: allocate iommu domain |
| 195 | * @domain_free: free iommu domain |
Ohad Ben-Cohen | 7d3002c | 2011-11-10 11:32:26 +0200 | [diff] [blame] | 196 | * @attach_dev: attach device to an iommu domain |
| 197 | * @detach_dev: detach device from an iommu domain |
| 198 | * @map: map a physically contiguous memory region to an iommu domain |
| 199 | * @unmap: unmap a physically contiguous memory region from an iommu domain |
Tom Murphy | db04d4a | 2019-02-11 15:50:33 +0000 | [diff] [blame] | 200 | * @flush_iotlb_all: Synchronously flush all hardware TLBs for this domain |
tom | 51eb780 | 2018-12-04 18:27:34 +0000 | [diff] [blame] | 201 | * @iotlb_range_add: Add a given iova range to the flush queue for this domain |
Geert Uytterhoeven | 2405bc1 | 2019-02-20 14:00:52 +0100 | [diff] [blame] | 202 | * @iotlb_sync_map: Sync mappings created recently using @map to the hardware |
tom | 51eb780 | 2018-12-04 18:27:34 +0000 | [diff] [blame] | 203 | * @iotlb_sync: Flush all queued ranges from the hardware TLBs and empty flush |
Joerg Roedel | add02cfd | 2017-08-23 15:50:04 +0200 | [diff] [blame] | 204 | * queue |
Ohad Ben-Cohen | 7d3002c | 2011-11-10 11:32:26 +0200 | [diff] [blame] | 205 | * @iova_to_phys: translate iova to physical address |
Alex Williamson | d72e31c | 2012-05-30 14:18:53 -0600 | [diff] [blame] | 206 | * @add_device: add device to iommu grouping |
| 207 | * @remove_device: remove device from iommu grouping |
Magnus Damm | 0d9bacb | 2016-01-19 14:28:48 +0900 | [diff] [blame] | 208 | * @device_group: find iommu group for a particular device |
Joerg Roedel | 0cd76dd | 2012-01-26 19:40:52 +0100 | [diff] [blame] | 209 | * @domain_get_attr: Query domain attributes |
| 210 | * @domain_set_attr: Change domain attributes |
Eric Auger | e5b5234 | 2017-01-19 20:57:47 +0000 | [diff] [blame] | 211 | * @get_resv_regions: Request list of reserved regions for a device |
| 212 | * @put_resv_regions: Free list of reserved regions for a device |
| 213 | * @apply_resv_region: Temporary helper call-back for iova reserved ranges |
Magnus Damm | 0d9bacb | 2016-01-19 14:28:48 +0900 | [diff] [blame] | 214 | * @domain_window_enable: Configure and enable a particular window for a domain |
| 215 | * @domain_window_disable: Disable a particular window for a domain |
Will Deacon | d0f60a4 | 2014-08-27 16:15:59 +0100 | [diff] [blame] | 216 | * @of_xlate: add OF master IDs to iommu grouping |
Geert Uytterhoeven | a7055d5 | 2019-02-20 14:00:53 +0100 | [diff] [blame] | 217 | * @is_attach_deferred: Check if domain attach should be deferred from iommu |
| 218 | * driver init to device driver init (default no) |
Lu Baolu | a3a1959 | 2019-03-25 09:30:28 +0800 | [diff] [blame] | 219 | * @dev_has/enable/disable_feat: per device entries to check/enable/disable |
| 220 | * iommu specific features. |
| 221 | * @dev_feat_enabled: check enabled feature |
| 222 | * @aux_attach/detach_dev: aux-domain specific attach/detach entries. |
| 223 | * @aux_get_pasid: get the pasid given an aux-domain |
Jean-Philippe Brucker | 26b25a2 | 2019-04-10 16:15:16 +0100 | [diff] [blame] | 224 | * @sva_bind: Bind process address space to device |
| 225 | * @sva_unbind: Unbind process address space from device |
| 226 | * @sva_get_pasid: Get PASID associated to a SVA handle |
Robin Murphy | d16e0fa | 2016-04-07 18:42:06 +0100 | [diff] [blame] | 227 | * @pgsize_bitmap: bitmap of all possible supported page sizes |
Ohad Ben-Cohen | 7d3002c | 2011-11-10 11:32:26 +0200 | [diff] [blame] | 228 | */ |
Joerg Roedel | 4a77a6c | 2008-11-26 17:02:33 +0100 | [diff] [blame] | 229 | struct iommu_ops { |
Joerg Roedel | 3c0e0ca | 2014-09-03 18:47:25 +0200 | [diff] [blame] | 230 | bool (*capable)(enum iommu_cap); |
Joerg Roedel | 938c470 | 2015-03-26 13:43:04 +0100 | [diff] [blame] | 231 | |
| 232 | /* Domain allocation and freeing by the iommu driver */ |
Joerg Roedel | 8539c7c | 2015-03-26 13:43:05 +0100 | [diff] [blame] | 233 | struct iommu_domain *(*domain_alloc)(unsigned iommu_domain_type); |
Joerg Roedel | 938c470 | 2015-03-26 13:43:04 +0100 | [diff] [blame] | 234 | void (*domain_free)(struct iommu_domain *); |
| 235 | |
Joerg Roedel | 4a77a6c | 2008-11-26 17:02:33 +0100 | [diff] [blame] | 236 | int (*attach_dev)(struct iommu_domain *domain, struct device *dev); |
| 237 | void (*detach_dev)(struct iommu_domain *domain, struct device *dev); |
Joerg Roedel | 6765178 | 2010-01-21 16:32:27 +0100 | [diff] [blame] | 238 | int (*map)(struct iommu_domain *domain, unsigned long iova, |
Ohad Ben-Cohen | 5009065 | 2011-11-10 11:32:25 +0200 | [diff] [blame] | 239 | phys_addr_t paddr, size_t size, int prot); |
| 240 | size_t (*unmap)(struct iommu_domain *domain, unsigned long iova, |
| 241 | size_t size); |
Joerg Roedel | add02cfd | 2017-08-23 15:50:04 +0200 | [diff] [blame] | 242 | void (*flush_iotlb_all)(struct iommu_domain *domain); |
| 243 | void (*iotlb_range_add)(struct iommu_domain *domain, |
| 244 | unsigned long iova, size_t size); |
Dmitry Osipenko | 1d7ae53 | 2018-12-12 23:38:47 +0300 | [diff] [blame] | 245 | void (*iotlb_sync_map)(struct iommu_domain *domain); |
Joerg Roedel | add02cfd | 2017-08-23 15:50:04 +0200 | [diff] [blame] | 246 | void (*iotlb_sync)(struct iommu_domain *domain); |
Varun Sethi | bb5547a | 2013-03-29 01:23:58 +0530 | [diff] [blame] | 247 | phys_addr_t (*iova_to_phys)(struct iommu_domain *domain, dma_addr_t iova); |
Alex Williamson | d72e31c | 2012-05-30 14:18:53 -0600 | [diff] [blame] | 248 | int (*add_device)(struct device *dev); |
| 249 | void (*remove_device)(struct device *dev); |
Joerg Roedel | 46c6b2b | 2015-10-21 23:51:36 +0200 | [diff] [blame] | 250 | struct iommu_group *(*device_group)(struct device *dev); |
Joerg Roedel | 0cd76dd | 2012-01-26 19:40:52 +0100 | [diff] [blame] | 251 | int (*domain_get_attr)(struct iommu_domain *domain, |
| 252 | enum iommu_attr attr, void *data); |
| 253 | int (*domain_set_attr)(struct iommu_domain *domain, |
| 254 | enum iommu_attr attr, void *data); |
Joerg Roedel | d7787d5 | 2013-01-29 14:26:20 +0100 | [diff] [blame] | 255 | |
Eric Auger | e5b5234 | 2017-01-19 20:57:47 +0000 | [diff] [blame] | 256 | /* Request/Free a list of reserved regions for a device */ |
| 257 | void (*get_resv_regions)(struct device *dev, struct list_head *list); |
| 258 | void (*put_resv_regions)(struct device *dev, struct list_head *list); |
| 259 | void (*apply_resv_region)(struct device *dev, |
| 260 | struct iommu_domain *domain, |
| 261 | struct iommu_resv_region *region); |
Joerg Roedel | a1015c2 | 2015-05-28 18:41:33 +0200 | [diff] [blame] | 262 | |
Joerg Roedel | d7787d5 | 2013-01-29 14:26:20 +0100 | [diff] [blame] | 263 | /* Window handling functions */ |
| 264 | int (*domain_window_enable)(struct iommu_domain *domain, u32 wnd_nr, |
Varun Sethi | 80f97f0 | 2013-03-29 01:24:00 +0530 | [diff] [blame] | 265 | phys_addr_t paddr, u64 size, int prot); |
Joerg Roedel | d7787d5 | 2013-01-29 14:26:20 +0100 | [diff] [blame] | 266 | void (*domain_window_disable)(struct iommu_domain *domain, u32 wnd_nr); |
| 267 | |
Will Deacon | d0f60a4 | 2014-08-27 16:15:59 +0100 | [diff] [blame] | 268 | int (*of_xlate)(struct device *dev, struct of_phandle_args *args); |
Baoquan He | e01d191 | 2017-08-09 16:33:40 +0800 | [diff] [blame] | 269 | bool (*is_attach_deferred)(struct iommu_domain *domain, struct device *dev); |
Will Deacon | d0f60a4 | 2014-08-27 16:15:59 +0100 | [diff] [blame] | 270 | |
Lu Baolu | a3a1959 | 2019-03-25 09:30:28 +0800 | [diff] [blame] | 271 | /* Per device IOMMU features */ |
| 272 | bool (*dev_has_feat)(struct device *dev, enum iommu_dev_features f); |
| 273 | bool (*dev_feat_enabled)(struct device *dev, enum iommu_dev_features f); |
| 274 | int (*dev_enable_feat)(struct device *dev, enum iommu_dev_features f); |
| 275 | int (*dev_disable_feat)(struct device *dev, enum iommu_dev_features f); |
| 276 | |
| 277 | /* Aux-domain specific attach/detach entries */ |
| 278 | int (*aux_attach_dev)(struct iommu_domain *domain, struct device *dev); |
| 279 | void (*aux_detach_dev)(struct iommu_domain *domain, struct device *dev); |
| 280 | int (*aux_get_pasid)(struct iommu_domain *domain, struct device *dev); |
| 281 | |
Jean-Philippe Brucker | 26b25a2 | 2019-04-10 16:15:16 +0100 | [diff] [blame] | 282 | struct iommu_sva *(*sva_bind)(struct device *dev, struct mm_struct *mm, |
| 283 | void *drvdata); |
| 284 | void (*sva_unbind)(struct iommu_sva *handle); |
| 285 | int (*sva_get_pasid)(struct iommu_sva *handle); |
| 286 | |
Ohad Ben-Cohen | 7d3002c | 2011-11-10 11:32:26 +0200 | [diff] [blame] | 287 | unsigned long pgsize_bitmap; |
Joerg Roedel | 4a77a6c | 2008-11-26 17:02:33 +0100 | [diff] [blame] | 288 | }; |
| 289 | |
Joerg Roedel | b0119e8 | 2017-02-01 13:23:08 +0100 | [diff] [blame] | 290 | /** |
| 291 | * struct iommu_device - IOMMU core representation of one IOMMU hardware |
| 292 | * instance |
| 293 | * @list: Used by the iommu-core to keep a list of registered iommus |
| 294 | * @ops: iommu-ops for talking to this iommu |
Joerg Roedel | 39ab955 | 2017-02-01 16:56:46 +0100 | [diff] [blame] | 295 | * @dev: struct device for sysfs handling |
Joerg Roedel | b0119e8 | 2017-02-01 13:23:08 +0100 | [diff] [blame] | 296 | */ |
| 297 | struct iommu_device { |
| 298 | struct list_head list; |
| 299 | const struct iommu_ops *ops; |
Joerg Roedel | c73e1ac | 2017-02-07 18:18:46 +0100 | [diff] [blame] | 300 | struct fwnode_handle *fwnode; |
Joerg Roedel | 2926a2aa | 2017-08-14 17:19:26 +0200 | [diff] [blame] | 301 | struct device *dev; |
Joerg Roedel | b0119e8 | 2017-02-01 13:23:08 +0100 | [diff] [blame] | 302 | }; |
| 303 | |
| 304 | int iommu_device_register(struct iommu_device *iommu); |
| 305 | void iommu_device_unregister(struct iommu_device *iommu); |
Joerg Roedel | 39ab955 | 2017-02-01 16:56:46 +0100 | [diff] [blame] | 306 | int iommu_device_sysfs_add(struct iommu_device *iommu, |
| 307 | struct device *parent, |
| 308 | const struct attribute_group **groups, |
| 309 | const char *fmt, ...) __printf(4, 5); |
| 310 | void iommu_device_sysfs_remove(struct iommu_device *iommu); |
Joerg Roedel | e3d10af | 2017-02-01 17:23:22 +0100 | [diff] [blame] | 311 | int iommu_device_link(struct iommu_device *iommu, struct device *link); |
| 312 | void iommu_device_unlink(struct iommu_device *iommu, struct device *link); |
Joerg Roedel | b0119e8 | 2017-02-01 13:23:08 +0100 | [diff] [blame] | 313 | |
| 314 | static inline void iommu_device_set_ops(struct iommu_device *iommu, |
| 315 | const struct iommu_ops *ops) |
| 316 | { |
| 317 | iommu->ops = ops; |
| 318 | } |
| 319 | |
Joerg Roedel | c73e1ac | 2017-02-07 18:18:46 +0100 | [diff] [blame] | 320 | static inline void iommu_device_set_fwnode(struct iommu_device *iommu, |
| 321 | struct fwnode_handle *fwnode) |
| 322 | { |
| 323 | iommu->fwnode = fwnode; |
| 324 | } |
| 325 | |
Joerg Roedel | 2926a2aa | 2017-08-14 17:19:26 +0200 | [diff] [blame] | 326 | static inline struct iommu_device *dev_to_iommu_device(struct device *dev) |
| 327 | { |
| 328 | return (struct iommu_device *)dev_get_drvdata(dev); |
| 329 | } |
| 330 | |
Alex Williamson | d72e31c | 2012-05-30 14:18:53 -0600 | [diff] [blame] | 331 | #define IOMMU_GROUP_NOTIFY_ADD_DEVICE 1 /* Device added */ |
| 332 | #define IOMMU_GROUP_NOTIFY_DEL_DEVICE 2 /* Pre Device removed */ |
| 333 | #define IOMMU_GROUP_NOTIFY_BIND_DRIVER 3 /* Pre Driver bind */ |
| 334 | #define IOMMU_GROUP_NOTIFY_BOUND_DRIVER 4 /* Post Driver bind */ |
| 335 | #define IOMMU_GROUP_NOTIFY_UNBIND_DRIVER 5 /* Pre Driver unbind */ |
| 336 | #define IOMMU_GROUP_NOTIFY_UNBOUND_DRIVER 6 /* Post Driver unbind */ |
| 337 | |
Thierry Reding | b22f643 | 2014-06-27 09:03:12 +0200 | [diff] [blame] | 338 | extern int bus_set_iommu(struct bus_type *bus, const struct iommu_ops *ops); |
Joerg Roedel | a1b60c1 | 2011-09-06 18:46:34 +0200 | [diff] [blame] | 339 | extern bool iommu_present(struct bus_type *bus); |
Joerg Roedel | 3c0e0ca | 2014-09-03 18:47:25 +0200 | [diff] [blame] | 340 | extern bool iommu_capable(struct bus_type *bus, enum iommu_cap cap); |
Joerg Roedel | 905d66c | 2011-09-06 16:03:26 +0200 | [diff] [blame] | 341 | extern struct iommu_domain *iommu_domain_alloc(struct bus_type *bus); |
Alexey Kardashevskiy | aa16bea | 2013-03-25 10:23:49 +1100 | [diff] [blame] | 342 | extern struct iommu_group *iommu_group_get_by_id(int id); |
Joerg Roedel | 4a77a6c | 2008-11-26 17:02:33 +0100 | [diff] [blame] | 343 | extern void iommu_domain_free(struct iommu_domain *domain); |
| 344 | extern int iommu_attach_device(struct iommu_domain *domain, |
| 345 | struct device *dev); |
| 346 | extern void iommu_detach_device(struct iommu_domain *domain, |
| 347 | struct device *dev); |
Joerg Roedel | 2c1296d | 2015-05-28 18:41:32 +0200 | [diff] [blame] | 348 | extern struct iommu_domain *iommu_get_domain_for_dev(struct device *dev); |
Robin Murphy | 6af588f | 2018-09-12 16:24:12 +0100 | [diff] [blame] | 349 | extern struct iommu_domain *iommu_get_dma_domain(struct device *dev); |
Joerg Roedel | cefc53c | 2010-01-08 13:35:09 +0100 | [diff] [blame] | 350 | extern int iommu_map(struct iommu_domain *domain, unsigned long iova, |
Ohad Ben-Cohen | 7d3002c | 2011-11-10 11:32:26 +0200 | [diff] [blame] | 351 | phys_addr_t paddr, size_t size, int prot); |
| 352 | extern size_t iommu_unmap(struct iommu_domain *domain, unsigned long iova, |
Joerg Roedel | add02cfd | 2017-08-23 15:50:04 +0200 | [diff] [blame] | 353 | size_t size); |
| 354 | extern size_t iommu_unmap_fast(struct iommu_domain *domain, |
| 355 | unsigned long iova, size_t size); |
Christoph Hellwig | d88e61f | 2018-07-30 09:36:26 +0200 | [diff] [blame] | 356 | extern size_t iommu_map_sg(struct iommu_domain *domain, unsigned long iova, |
| 357 | struct scatterlist *sg,unsigned int nents, int prot); |
Varun Sethi | bb5547a | 2013-03-29 01:23:58 +0530 | [diff] [blame] | 358 | extern phys_addr_t iommu_iova_to_phys(struct iommu_domain *domain, dma_addr_t iova); |
Ohad Ben-Cohen | 4f3f8d9 | 2011-09-13 15:25:23 -0400 | [diff] [blame] | 359 | extern void iommu_set_fault_handler(struct iommu_domain *domain, |
Ohad Ben-Cohen | 77ca233 | 2012-05-21 20:20:05 +0300 | [diff] [blame] | 360 | iommu_fault_handler_t handler, void *token); |
Alex Williamson | d72e31c | 2012-05-30 14:18:53 -0600 | [diff] [blame] | 361 | |
Eric Auger | e5b5234 | 2017-01-19 20:57:47 +0000 | [diff] [blame] | 362 | extern void iommu_get_resv_regions(struct device *dev, struct list_head *list); |
| 363 | extern void iommu_put_resv_regions(struct device *dev, struct list_head *list); |
Joerg Roedel | d290f1e | 2015-05-28 18:41:36 +0200 | [diff] [blame] | 364 | extern int iommu_request_dm_for_dev(struct device *dev); |
Eric Auger | 2b20cbb | 2017-01-19 20:57:49 +0000 | [diff] [blame] | 365 | extern struct iommu_resv_region * |
Robin Murphy | 9d3a4de | 2017-03-16 17:00:16 +0000 | [diff] [blame] | 366 | iommu_alloc_resv_region(phys_addr_t start, size_t length, int prot, |
| 367 | enum iommu_resv_type type); |
Eric Auger | 6c65fb3 | 2017-01-19 20:57:51 +0000 | [diff] [blame] | 368 | extern int iommu_get_group_resv_regions(struct iommu_group *group, |
| 369 | struct list_head *head); |
Joerg Roedel | a1015c2 | 2015-05-28 18:41:33 +0200 | [diff] [blame] | 370 | |
Alex Williamson | d72e31c | 2012-05-30 14:18:53 -0600 | [diff] [blame] | 371 | extern int iommu_attach_group(struct iommu_domain *domain, |
| 372 | struct iommu_group *group); |
| 373 | extern void iommu_detach_group(struct iommu_domain *domain, |
| 374 | struct iommu_group *group); |
| 375 | extern struct iommu_group *iommu_group_alloc(void); |
| 376 | extern void *iommu_group_get_iommudata(struct iommu_group *group); |
| 377 | extern void iommu_group_set_iommudata(struct iommu_group *group, |
| 378 | void *iommu_data, |
| 379 | void (*release)(void *iommu_data)); |
| 380 | extern int iommu_group_set_name(struct iommu_group *group, const char *name); |
| 381 | extern int iommu_group_add_device(struct iommu_group *group, |
| 382 | struct device *dev); |
| 383 | extern void iommu_group_remove_device(struct device *dev); |
| 384 | extern int iommu_group_for_each_dev(struct iommu_group *group, void *data, |
| 385 | int (*fn)(struct device *, void *)); |
| 386 | extern struct iommu_group *iommu_group_get(struct device *dev); |
Robin Murphy | 13f59a7 | 2016-11-11 17:59:21 +0000 | [diff] [blame] | 387 | extern struct iommu_group *iommu_group_ref_get(struct iommu_group *group); |
Alex Williamson | d72e31c | 2012-05-30 14:18:53 -0600 | [diff] [blame] | 388 | extern void iommu_group_put(struct iommu_group *group); |
| 389 | extern int iommu_group_register_notifier(struct iommu_group *group, |
| 390 | struct notifier_block *nb); |
| 391 | extern int iommu_group_unregister_notifier(struct iommu_group *group, |
| 392 | struct notifier_block *nb); |
| 393 | extern int iommu_group_id(struct iommu_group *group); |
Alex Williamson | 104a1c1 | 2014-07-03 09:51:18 -0600 | [diff] [blame] | 394 | extern struct iommu_group *iommu_group_get_for_dev(struct device *dev); |
Joerg Roedel | 6827ca8 | 2015-05-28 18:41:35 +0200 | [diff] [blame] | 395 | extern struct iommu_domain *iommu_group_default_domain(struct iommu_group *); |
Ohad Ben-Cohen | 4f3f8d9 | 2011-09-13 15:25:23 -0400 | [diff] [blame] | 396 | |
Joerg Roedel | 0cd76dd | 2012-01-26 19:40:52 +0100 | [diff] [blame] | 397 | extern int iommu_domain_get_attr(struct iommu_domain *domain, enum iommu_attr, |
| 398 | void *data); |
| 399 | extern int iommu_domain_set_attr(struct iommu_domain *domain, enum iommu_attr, |
| 400 | void *data); |
Ohad Ben-Cohen | 4f3f8d9 | 2011-09-13 15:25:23 -0400 | [diff] [blame] | 401 | |
Joerg Roedel | d7787d5 | 2013-01-29 14:26:20 +0100 | [diff] [blame] | 402 | /* Window handling function prototypes */ |
| 403 | extern int iommu_domain_window_enable(struct iommu_domain *domain, u32 wnd_nr, |
Varun Sethi | 80f97f0 | 2013-03-29 01:24:00 +0530 | [diff] [blame] | 404 | phys_addr_t offset, u64 size, |
| 405 | int prot); |
Joerg Roedel | d7787d5 | 2013-01-29 14:26:20 +0100 | [diff] [blame] | 406 | extern void iommu_domain_window_disable(struct iommu_domain *domain, u32 wnd_nr); |
Ohad Ben-Cohen | 4f3f8d9 | 2011-09-13 15:25:23 -0400 | [diff] [blame] | 407 | |
Joerg Roedel | 207c6e3 | 2017-04-26 15:39:28 +0200 | [diff] [blame] | 408 | extern int report_iommu_fault(struct iommu_domain *domain, struct device *dev, |
| 409 | unsigned long iova, int flags); |
Joerg Roedel | 4a77a6c | 2008-11-26 17:02:33 +0100 | [diff] [blame] | 410 | |
Joerg Roedel | add02cfd | 2017-08-23 15:50:04 +0200 | [diff] [blame] | 411 | static inline void iommu_flush_tlb_all(struct iommu_domain *domain) |
| 412 | { |
| 413 | if (domain->ops->flush_iotlb_all) |
| 414 | domain->ops->flush_iotlb_all(domain); |
| 415 | } |
| 416 | |
| 417 | static inline void iommu_tlb_range_add(struct iommu_domain *domain, |
| 418 | unsigned long iova, size_t size) |
| 419 | { |
| 420 | if (domain->ops->iotlb_range_add) |
| 421 | domain->ops->iotlb_range_add(domain, iova, size); |
| 422 | } |
| 423 | |
| 424 | static inline void iommu_tlb_sync(struct iommu_domain *domain) |
| 425 | { |
| 426 | if (domain->ops->iotlb_sync) |
| 427 | domain->ops->iotlb_sync(domain); |
| 428 | } |
| 429 | |
Joerg Roedel | 5e62292 | 2015-10-21 23:51:37 +0200 | [diff] [blame] | 430 | /* PCI device grouping function */ |
| 431 | extern struct iommu_group *pci_device_group(struct device *dev); |
Joerg Roedel | 6eab556 | 2015-10-21 23:51:38 +0200 | [diff] [blame] | 432 | /* Generic device grouping function */ |
| 433 | extern struct iommu_group *generic_device_group(struct device *dev); |
Nipun Gupta | eab03e2 | 2018-09-10 19:19:18 +0530 | [diff] [blame] | 434 | /* FSL-MC device grouping function */ |
| 435 | struct iommu_group *fsl_mc_device_group(struct device *dev); |
Joerg Roedel | 5e62292 | 2015-10-21 23:51:37 +0200 | [diff] [blame] | 436 | |
Robin Murphy | 57f98d2 | 2016-09-13 10:54:14 +0100 | [diff] [blame] | 437 | /** |
| 438 | * struct iommu_fwspec - per-device IOMMU instance data |
| 439 | * @ops: ops for this device's IOMMU |
| 440 | * @iommu_fwnode: firmware handle for this device's IOMMU |
| 441 | * @iommu_priv: IOMMU driver private data for this device |
| 442 | * @num_ids: number of associated device IDs |
| 443 | * @ids: IDs which this device may present to the IOMMU |
| 444 | */ |
| 445 | struct iommu_fwspec { |
| 446 | const struct iommu_ops *ops; |
| 447 | struct fwnode_handle *iommu_fwnode; |
| 448 | void *iommu_priv; |
Jean-Philippe Brucker | 5702ee2 | 2019-04-17 19:24:42 +0100 | [diff] [blame] | 449 | u32 flags; |
Robin Murphy | 57f98d2 | 2016-09-13 10:54:14 +0100 | [diff] [blame] | 450 | unsigned int num_ids; |
| 451 | u32 ids[1]; |
| 452 | }; |
| 453 | |
Jean-Philippe Brucker | 5702ee2 | 2019-04-17 19:24:42 +0100 | [diff] [blame] | 454 | /* ATS is supported */ |
| 455 | #define IOMMU_FWSPEC_PCI_RC_ATS (1 << 0) |
| 456 | |
Jean-Philippe Brucker | 26b25a2 | 2019-04-10 16:15:16 +0100 | [diff] [blame] | 457 | /** |
| 458 | * struct iommu_sva - handle to a device-mm bond |
| 459 | */ |
| 460 | struct iommu_sva { |
| 461 | struct device *dev; |
| 462 | const struct iommu_sva_ops *ops; |
| 463 | }; |
| 464 | |
Robin Murphy | 57f98d2 | 2016-09-13 10:54:14 +0100 | [diff] [blame] | 465 | int iommu_fwspec_init(struct device *dev, struct fwnode_handle *iommu_fwnode, |
| 466 | const struct iommu_ops *ops); |
| 467 | void iommu_fwspec_free(struct device *dev); |
| 468 | int iommu_fwspec_add_ids(struct device *dev, u32 *ids, int num_ids); |
Joerg Roedel | 534766d | 2017-01-31 16:58:42 +0100 | [diff] [blame] | 469 | const struct iommu_ops *iommu_ops_from_fwnode(struct fwnode_handle *fwnode); |
Robin Murphy | 57f98d2 | 2016-09-13 10:54:14 +0100 | [diff] [blame] | 470 | |
Joerg Roedel | b4ef725 | 2018-11-28 13:35:24 +0100 | [diff] [blame] | 471 | static inline struct iommu_fwspec *dev_iommu_fwspec_get(struct device *dev) |
| 472 | { |
| 473 | return dev->iommu_fwspec; |
| 474 | } |
| 475 | |
| 476 | static inline void dev_iommu_fwspec_set(struct device *dev, |
| 477 | struct iommu_fwspec *fwspec) |
| 478 | { |
| 479 | dev->iommu_fwspec = fwspec; |
| 480 | } |
| 481 | |
Joerg Roedel | cc5aed4 | 2018-11-30 10:31:59 +0100 | [diff] [blame] | 482 | int iommu_probe_device(struct device *dev); |
| 483 | void iommu_release_device(struct device *dev); |
| 484 | |
Lu Baolu | a3a1959 | 2019-03-25 09:30:28 +0800 | [diff] [blame] | 485 | bool iommu_dev_has_feature(struct device *dev, enum iommu_dev_features f); |
| 486 | int iommu_dev_enable_feature(struct device *dev, enum iommu_dev_features f); |
| 487 | int iommu_dev_disable_feature(struct device *dev, enum iommu_dev_features f); |
| 488 | bool iommu_dev_feature_enabled(struct device *dev, enum iommu_dev_features f); |
| 489 | int iommu_aux_attach_device(struct iommu_domain *domain, struct device *dev); |
| 490 | void iommu_aux_detach_device(struct iommu_domain *domain, struct device *dev); |
| 491 | int iommu_aux_get_pasid(struct iommu_domain *domain, struct device *dev); |
| 492 | |
Jean-Philippe Brucker | 26b25a2 | 2019-04-10 16:15:16 +0100 | [diff] [blame] | 493 | struct iommu_sva *iommu_sva_bind_device(struct device *dev, |
| 494 | struct mm_struct *mm, |
| 495 | void *drvdata); |
| 496 | void iommu_sva_unbind_device(struct iommu_sva *handle); |
| 497 | int iommu_sva_set_ops(struct iommu_sva *handle, |
| 498 | const struct iommu_sva_ops *ops); |
| 499 | int iommu_sva_get_pasid(struct iommu_sva *handle); |
| 500 | |
Joerg Roedel | 4a77a6c | 2008-11-26 17:02:33 +0100 | [diff] [blame] | 501 | #else /* CONFIG_IOMMU_API */ |
| 502 | |
Joerg Roedel | 39d4ebb | 2011-09-06 16:48:40 +0200 | [diff] [blame] | 503 | struct iommu_ops {}; |
Alex Williamson | d72e31c | 2012-05-30 14:18:53 -0600 | [diff] [blame] | 504 | struct iommu_group {}; |
Robin Murphy | 57f98d2 | 2016-09-13 10:54:14 +0100 | [diff] [blame] | 505 | struct iommu_fwspec {}; |
Joerg Roedel | b0119e8 | 2017-02-01 13:23:08 +0100 | [diff] [blame] | 506 | struct iommu_device {}; |
Joerg Roedel | 4a77a6c | 2008-11-26 17:02:33 +0100 | [diff] [blame] | 507 | |
Joerg Roedel | a1b60c1 | 2011-09-06 18:46:34 +0200 | [diff] [blame] | 508 | static inline bool iommu_present(struct bus_type *bus) |
Joerg Roedel | 4a77a6c | 2008-11-26 17:02:33 +0100 | [diff] [blame] | 509 | { |
| 510 | return false; |
| 511 | } |
| 512 | |
Joerg Roedel | 3c0e0ca | 2014-09-03 18:47:25 +0200 | [diff] [blame] | 513 | static inline bool iommu_capable(struct bus_type *bus, enum iommu_cap cap) |
| 514 | { |
| 515 | return false; |
| 516 | } |
| 517 | |
Joerg Roedel | 905d66c | 2011-09-06 16:03:26 +0200 | [diff] [blame] | 518 | static inline struct iommu_domain *iommu_domain_alloc(struct bus_type *bus) |
Joerg Roedel | 4a77a6c | 2008-11-26 17:02:33 +0100 | [diff] [blame] | 519 | { |
| 520 | return NULL; |
| 521 | } |
| 522 | |
Alexey Kardashevskiy | b62dfd2 | 2013-11-21 17:41:14 +1100 | [diff] [blame] | 523 | static inline struct iommu_group *iommu_group_get_by_id(int id) |
| 524 | { |
| 525 | return NULL; |
| 526 | } |
| 527 | |
Joerg Roedel | 4a77a6c | 2008-11-26 17:02:33 +0100 | [diff] [blame] | 528 | static inline void iommu_domain_free(struct iommu_domain *domain) |
| 529 | { |
| 530 | } |
| 531 | |
| 532 | static inline int iommu_attach_device(struct iommu_domain *domain, |
| 533 | struct device *dev) |
| 534 | { |
| 535 | return -ENODEV; |
| 536 | } |
| 537 | |
| 538 | static inline void iommu_detach_device(struct iommu_domain *domain, |
| 539 | struct device *dev) |
| 540 | { |
| 541 | } |
| 542 | |
Joerg Roedel | 2c1296d | 2015-05-28 18:41:32 +0200 | [diff] [blame] | 543 | static inline struct iommu_domain *iommu_get_domain_for_dev(struct device *dev) |
| 544 | { |
| 545 | return NULL; |
| 546 | } |
| 547 | |
Joerg Roedel | cefc53c | 2010-01-08 13:35:09 +0100 | [diff] [blame] | 548 | static inline int iommu_map(struct iommu_domain *domain, unsigned long iova, |
Dmitry Osipenko | ebae3e8 | 2017-07-05 20:27:53 +0300 | [diff] [blame] | 549 | phys_addr_t paddr, size_t size, int prot) |
Joerg Roedel | cefc53c | 2010-01-08 13:35:09 +0100 | [diff] [blame] | 550 | { |
| 551 | return -ENODEV; |
| 552 | } |
| 553 | |
Suravee Suthikulpanit | c5611a8 | 2018-02-05 05:45:53 -0500 | [diff] [blame] | 554 | static inline size_t iommu_unmap(struct iommu_domain *domain, |
| 555 | unsigned long iova, size_t size) |
Joerg Roedel | cefc53c | 2010-01-08 13:35:09 +0100 | [diff] [blame] | 556 | { |
Suravee Suthikulpanit | c5611a8 | 2018-02-05 05:45:53 -0500 | [diff] [blame] | 557 | return 0; |
Joerg Roedel | cefc53c | 2010-01-08 13:35:09 +0100 | [diff] [blame] | 558 | } |
| 559 | |
Suravee Suthikulpanit | c5611a8 | 2018-02-05 05:45:53 -0500 | [diff] [blame] | 560 | static inline size_t iommu_unmap_fast(struct iommu_domain *domain, |
| 561 | unsigned long iova, int gfp_order) |
Joerg Roedel | 4a77a6c | 2008-11-26 17:02:33 +0100 | [diff] [blame] | 562 | { |
Suravee Suthikulpanit | c5611a8 | 2018-02-05 05:45:53 -0500 | [diff] [blame] | 563 | return 0; |
Joerg Roedel | 4a77a6c | 2008-11-26 17:02:33 +0100 | [diff] [blame] | 564 | } |
| 565 | |
Olav Haugan | 315786e | 2014-10-25 09:55:16 -0700 | [diff] [blame] | 566 | static inline size_t iommu_map_sg(struct iommu_domain *domain, |
| 567 | unsigned long iova, struct scatterlist *sg, |
| 568 | unsigned int nents, int prot) |
| 569 | { |
Suravee Suthikulpanit | c5611a8 | 2018-02-05 05:45:53 -0500 | [diff] [blame] | 570 | return 0; |
Olav Haugan | 315786e | 2014-10-25 09:55:16 -0700 | [diff] [blame] | 571 | } |
| 572 | |
Joerg Roedel | add02cfd | 2017-08-23 15:50:04 +0200 | [diff] [blame] | 573 | static inline void iommu_flush_tlb_all(struct iommu_domain *domain) |
| 574 | { |
| 575 | } |
| 576 | |
| 577 | static inline void iommu_tlb_range_add(struct iommu_domain *domain, |
| 578 | unsigned long iova, size_t size) |
| 579 | { |
| 580 | } |
| 581 | |
| 582 | static inline void iommu_tlb_sync(struct iommu_domain *domain) |
| 583 | { |
| 584 | } |
| 585 | |
Joerg Roedel | d7787d5 | 2013-01-29 14:26:20 +0100 | [diff] [blame] | 586 | static inline int iommu_domain_window_enable(struct iommu_domain *domain, |
| 587 | u32 wnd_nr, phys_addr_t paddr, |
Varun Sethi | 80f97f0 | 2013-03-29 01:24:00 +0530 | [diff] [blame] | 588 | u64 size, int prot) |
Joerg Roedel | d7787d5 | 2013-01-29 14:26:20 +0100 | [diff] [blame] | 589 | { |
| 590 | return -ENODEV; |
| 591 | } |
| 592 | |
| 593 | static inline void iommu_domain_window_disable(struct iommu_domain *domain, |
| 594 | u32 wnd_nr) |
| 595 | { |
| 596 | } |
| 597 | |
Varun Sethi | bb5547a | 2013-03-29 01:23:58 +0530 | [diff] [blame] | 598 | static inline phys_addr_t iommu_iova_to_phys(struct iommu_domain *domain, dma_addr_t iova) |
Joerg Roedel | 4a77a6c | 2008-11-26 17:02:33 +0100 | [diff] [blame] | 599 | { |
| 600 | return 0; |
| 601 | } |
| 602 | |
Ohad Ben-Cohen | 4f3f8d9 | 2011-09-13 15:25:23 -0400 | [diff] [blame] | 603 | static inline void iommu_set_fault_handler(struct iommu_domain *domain, |
Ohad Ben-Cohen | 77ca233 | 2012-05-21 20:20:05 +0300 | [diff] [blame] | 604 | iommu_fault_handler_t handler, void *token) |
Ohad Ben-Cohen | 4f3f8d9 | 2011-09-13 15:25:23 -0400 | [diff] [blame] | 605 | { |
| 606 | } |
| 607 | |
Eric Auger | e5b5234 | 2017-01-19 20:57:47 +0000 | [diff] [blame] | 608 | static inline void iommu_get_resv_regions(struct device *dev, |
Joerg Roedel | a1015c2 | 2015-05-28 18:41:33 +0200 | [diff] [blame] | 609 | struct list_head *list) |
| 610 | { |
| 611 | } |
| 612 | |
Eric Auger | e5b5234 | 2017-01-19 20:57:47 +0000 | [diff] [blame] | 613 | static inline void iommu_put_resv_regions(struct device *dev, |
Joerg Roedel | a1015c2 | 2015-05-28 18:41:33 +0200 | [diff] [blame] | 614 | struct list_head *list) |
| 615 | { |
| 616 | } |
| 617 | |
Eric Auger | 6c65fb3 | 2017-01-19 20:57:51 +0000 | [diff] [blame] | 618 | static inline int iommu_get_group_resv_regions(struct iommu_group *group, |
| 619 | struct list_head *head) |
| 620 | { |
| 621 | return -ENODEV; |
| 622 | } |
| 623 | |
Joerg Roedel | d290f1e | 2015-05-28 18:41:36 +0200 | [diff] [blame] | 624 | static inline int iommu_request_dm_for_dev(struct device *dev) |
| 625 | { |
| 626 | return -ENODEV; |
| 627 | } |
| 628 | |
Alex Williamson | bef83de | 2012-09-24 21:23:25 -0600 | [diff] [blame] | 629 | static inline int iommu_attach_group(struct iommu_domain *domain, |
| 630 | struct iommu_group *group) |
Alex Williamson | 1460432 | 2011-10-21 15:56:05 -0400 | [diff] [blame] | 631 | { |
| 632 | return -ENODEV; |
| 633 | } |
| 634 | |
Alex Williamson | bef83de | 2012-09-24 21:23:25 -0600 | [diff] [blame] | 635 | static inline void iommu_detach_group(struct iommu_domain *domain, |
| 636 | struct iommu_group *group) |
Alex Williamson | d72e31c | 2012-05-30 14:18:53 -0600 | [diff] [blame] | 637 | { |
| 638 | } |
| 639 | |
Alex Williamson | bef83de | 2012-09-24 21:23:25 -0600 | [diff] [blame] | 640 | static inline struct iommu_group *iommu_group_alloc(void) |
Alex Williamson | d72e31c | 2012-05-30 14:18:53 -0600 | [diff] [blame] | 641 | { |
| 642 | return ERR_PTR(-ENODEV); |
| 643 | } |
| 644 | |
Alex Williamson | bef83de | 2012-09-24 21:23:25 -0600 | [diff] [blame] | 645 | static inline void *iommu_group_get_iommudata(struct iommu_group *group) |
Alex Williamson | d72e31c | 2012-05-30 14:18:53 -0600 | [diff] [blame] | 646 | { |
| 647 | return NULL; |
| 648 | } |
| 649 | |
Alex Williamson | bef83de | 2012-09-24 21:23:25 -0600 | [diff] [blame] | 650 | static inline void iommu_group_set_iommudata(struct iommu_group *group, |
| 651 | void *iommu_data, |
| 652 | void (*release)(void *iommu_data)) |
Alex Williamson | d72e31c | 2012-05-30 14:18:53 -0600 | [diff] [blame] | 653 | { |
| 654 | } |
| 655 | |
Alex Williamson | bef83de | 2012-09-24 21:23:25 -0600 | [diff] [blame] | 656 | static inline int iommu_group_set_name(struct iommu_group *group, |
| 657 | const char *name) |
Alex Williamson | d72e31c | 2012-05-30 14:18:53 -0600 | [diff] [blame] | 658 | { |
| 659 | return -ENODEV; |
| 660 | } |
| 661 | |
Alex Williamson | bef83de | 2012-09-24 21:23:25 -0600 | [diff] [blame] | 662 | static inline int iommu_group_add_device(struct iommu_group *group, |
| 663 | struct device *dev) |
Alex Williamson | d72e31c | 2012-05-30 14:18:53 -0600 | [diff] [blame] | 664 | { |
| 665 | return -ENODEV; |
| 666 | } |
| 667 | |
Alex Williamson | bef83de | 2012-09-24 21:23:25 -0600 | [diff] [blame] | 668 | static inline void iommu_group_remove_device(struct device *dev) |
Alex Williamson | d72e31c | 2012-05-30 14:18:53 -0600 | [diff] [blame] | 669 | { |
| 670 | } |
| 671 | |
Alex Williamson | bef83de | 2012-09-24 21:23:25 -0600 | [diff] [blame] | 672 | static inline int iommu_group_for_each_dev(struct iommu_group *group, |
| 673 | void *data, |
| 674 | int (*fn)(struct device *, void *)) |
Alex Williamson | d72e31c | 2012-05-30 14:18:53 -0600 | [diff] [blame] | 675 | { |
| 676 | return -ENODEV; |
| 677 | } |
| 678 | |
Alex Williamson | bef83de | 2012-09-24 21:23:25 -0600 | [diff] [blame] | 679 | static inline struct iommu_group *iommu_group_get(struct device *dev) |
Alex Williamson | d72e31c | 2012-05-30 14:18:53 -0600 | [diff] [blame] | 680 | { |
| 681 | return NULL; |
| 682 | } |
| 683 | |
Alex Williamson | bef83de | 2012-09-24 21:23:25 -0600 | [diff] [blame] | 684 | static inline void iommu_group_put(struct iommu_group *group) |
Alex Williamson | d72e31c | 2012-05-30 14:18:53 -0600 | [diff] [blame] | 685 | { |
| 686 | } |
| 687 | |
Alex Williamson | bef83de | 2012-09-24 21:23:25 -0600 | [diff] [blame] | 688 | static inline int iommu_group_register_notifier(struct iommu_group *group, |
| 689 | struct notifier_block *nb) |
Alex Williamson | d72e31c | 2012-05-30 14:18:53 -0600 | [diff] [blame] | 690 | { |
| 691 | return -ENODEV; |
| 692 | } |
| 693 | |
Alex Williamson | bef83de | 2012-09-24 21:23:25 -0600 | [diff] [blame] | 694 | static inline int iommu_group_unregister_notifier(struct iommu_group *group, |
| 695 | struct notifier_block *nb) |
Alex Williamson | d72e31c | 2012-05-30 14:18:53 -0600 | [diff] [blame] | 696 | { |
| 697 | return 0; |
| 698 | } |
| 699 | |
Alex Williamson | bef83de | 2012-09-24 21:23:25 -0600 | [diff] [blame] | 700 | static inline int iommu_group_id(struct iommu_group *group) |
Alex Williamson | d72e31c | 2012-05-30 14:18:53 -0600 | [diff] [blame] | 701 | { |
| 702 | return -ENODEV; |
| 703 | } |
Joerg Roedel | 4a77a6c | 2008-11-26 17:02:33 +0100 | [diff] [blame] | 704 | |
Joerg Roedel | 0cd76dd | 2012-01-26 19:40:52 +0100 | [diff] [blame] | 705 | static inline int iommu_domain_get_attr(struct iommu_domain *domain, |
| 706 | enum iommu_attr attr, void *data) |
| 707 | { |
| 708 | return -EINVAL; |
| 709 | } |
| 710 | |
| 711 | static inline int iommu_domain_set_attr(struct iommu_domain *domain, |
| 712 | enum iommu_attr attr, void *data) |
| 713 | { |
| 714 | return -EINVAL; |
| 715 | } |
| 716 | |
Joerg Roedel | b0119e8 | 2017-02-01 13:23:08 +0100 | [diff] [blame] | 717 | static inline int iommu_device_register(struct iommu_device *iommu) |
Alex Williamson | c61959e | 2014-06-12 16:12:24 -0600 | [diff] [blame] | 718 | { |
Joerg Roedel | b0119e8 | 2017-02-01 13:23:08 +0100 | [diff] [blame] | 719 | return -ENODEV; |
Alex Williamson | c61959e | 2014-06-12 16:12:24 -0600 | [diff] [blame] | 720 | } |
| 721 | |
Joerg Roedel | b0119e8 | 2017-02-01 13:23:08 +0100 | [diff] [blame] | 722 | static inline void iommu_device_set_ops(struct iommu_device *iommu, |
| 723 | const struct iommu_ops *ops) |
| 724 | { |
| 725 | } |
| 726 | |
Joerg Roedel | c73e1ac | 2017-02-07 18:18:46 +0100 | [diff] [blame] | 727 | static inline void iommu_device_set_fwnode(struct iommu_device *iommu, |
| 728 | struct fwnode_handle *fwnode) |
| 729 | { |
| 730 | } |
| 731 | |
Joerg Roedel | 2926a2aa | 2017-08-14 17:19:26 +0200 | [diff] [blame] | 732 | static inline struct iommu_device *dev_to_iommu_device(struct device *dev) |
| 733 | { |
| 734 | return NULL; |
| 735 | } |
| 736 | |
Joerg Roedel | b0119e8 | 2017-02-01 13:23:08 +0100 | [diff] [blame] | 737 | static inline void iommu_device_unregister(struct iommu_device *iommu) |
| 738 | { |
| 739 | } |
| 740 | |
Joerg Roedel | 39ab955 | 2017-02-01 16:56:46 +0100 | [diff] [blame] | 741 | static inline int iommu_device_sysfs_add(struct iommu_device *iommu, |
| 742 | struct device *parent, |
| 743 | const struct attribute_group **groups, |
| 744 | const char *fmt, ...) |
| 745 | { |
| 746 | return -ENODEV; |
| 747 | } |
| 748 | |
| 749 | static inline void iommu_device_sysfs_remove(struct iommu_device *iommu) |
Alex Williamson | c61959e | 2014-06-12 16:12:24 -0600 | [diff] [blame] | 750 | { |
| 751 | } |
| 752 | |
Alex Williamson | e09f8ea | 2014-07-07 14:31:36 -0600 | [diff] [blame] | 753 | static inline int iommu_device_link(struct device *dev, struct device *link) |
Alex Williamson | c61959e | 2014-06-12 16:12:24 -0600 | [diff] [blame] | 754 | { |
| 755 | return -EINVAL; |
| 756 | } |
| 757 | |
Alex Williamson | e09f8ea | 2014-07-07 14:31:36 -0600 | [diff] [blame] | 758 | static inline void iommu_device_unlink(struct device *dev, struct device *link) |
Alex Williamson | c61959e | 2014-06-12 16:12:24 -0600 | [diff] [blame] | 759 | { |
| 760 | } |
| 761 | |
Robin Murphy | 57f98d2 | 2016-09-13 10:54:14 +0100 | [diff] [blame] | 762 | static inline int iommu_fwspec_init(struct device *dev, |
| 763 | struct fwnode_handle *iommu_fwnode, |
| 764 | const struct iommu_ops *ops) |
| 765 | { |
| 766 | return -ENODEV; |
| 767 | } |
| 768 | |
| 769 | static inline void iommu_fwspec_free(struct device *dev) |
| 770 | { |
| 771 | } |
| 772 | |
| 773 | static inline int iommu_fwspec_add_ids(struct device *dev, u32 *ids, |
| 774 | int num_ids) |
| 775 | { |
| 776 | return -ENODEV; |
| 777 | } |
| 778 | |
Lorenzo Pieralisi | e4f10ff | 2016-11-21 10:01:36 +0000 | [diff] [blame] | 779 | static inline |
Joerg Roedel | 534766d | 2017-01-31 16:58:42 +0100 | [diff] [blame] | 780 | const struct iommu_ops *iommu_ops_from_fwnode(struct fwnode_handle *fwnode) |
Lorenzo Pieralisi | e4f10ff | 2016-11-21 10:01:36 +0000 | [diff] [blame] | 781 | { |
| 782 | return NULL; |
| 783 | } |
| 784 | |
Lu Baolu | a3a1959 | 2019-03-25 09:30:28 +0800 | [diff] [blame] | 785 | static inline bool |
| 786 | iommu_dev_has_feature(struct device *dev, enum iommu_dev_features feat) |
| 787 | { |
| 788 | return false; |
| 789 | } |
| 790 | |
| 791 | static inline bool |
| 792 | iommu_dev_feature_enabled(struct device *dev, enum iommu_dev_features feat) |
| 793 | { |
| 794 | return false; |
| 795 | } |
| 796 | |
| 797 | static inline int |
| 798 | iommu_dev_enable_feature(struct device *dev, enum iommu_dev_features feat) |
| 799 | { |
| 800 | return -ENODEV; |
| 801 | } |
| 802 | |
| 803 | static inline int |
| 804 | iommu_dev_disable_feature(struct device *dev, enum iommu_dev_features feat) |
| 805 | { |
| 806 | return -ENODEV; |
| 807 | } |
| 808 | |
| 809 | static inline int |
| 810 | iommu_aux_attach_device(struct iommu_domain *domain, struct device *dev) |
| 811 | { |
| 812 | return -ENODEV; |
| 813 | } |
| 814 | |
| 815 | static inline void |
| 816 | iommu_aux_detach_device(struct iommu_domain *domain, struct device *dev) |
| 817 | { |
| 818 | } |
| 819 | |
| 820 | static inline int |
| 821 | iommu_aux_get_pasid(struct iommu_domain *domain, struct device *dev) |
| 822 | { |
| 823 | return -ENODEV; |
| 824 | } |
| 825 | |
Jean-Philippe Brucker | 26b25a2 | 2019-04-10 16:15:16 +0100 | [diff] [blame] | 826 | static inline struct iommu_sva * |
| 827 | iommu_sva_bind_device(struct device *dev, struct mm_struct *mm, void *drvdata) |
| 828 | { |
| 829 | return NULL; |
| 830 | } |
| 831 | |
| 832 | static inline void iommu_sva_unbind_device(struct iommu_sva *handle) |
| 833 | { |
| 834 | } |
| 835 | |
| 836 | static inline int iommu_sva_set_ops(struct iommu_sva *handle, |
| 837 | const struct iommu_sva_ops *ops) |
| 838 | { |
| 839 | return -EINVAL; |
| 840 | } |
| 841 | |
| 842 | static inline int iommu_sva_get_pasid(struct iommu_sva *handle) |
| 843 | { |
| 844 | return IOMMU_PASID_INVALID; |
| 845 | } |
| 846 | |
Joerg Roedel | 4a77a6c | 2008-11-26 17:02:33 +0100 | [diff] [blame] | 847 | #endif /* CONFIG_IOMMU_API */ |
| 848 | |
Gary R Hook | bad614b | 2018-06-12 16:41:21 -0500 | [diff] [blame] | 849 | #ifdef CONFIG_IOMMU_DEBUGFS |
| 850 | extern struct dentry *iommu_debugfs_dir; |
| 851 | void iommu_debugfs_setup(void); |
| 852 | #else |
| 853 | static inline void iommu_debugfs_setup(void) {} |
| 854 | #endif |
| 855 | |
Joerg Roedel | 4a77a6c | 2008-11-26 17:02:33 +0100 | [diff] [blame] | 856 | #endif /* __LINUX_IOMMU_H */ |