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 | b578e4b | 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 | e038dfd | 2015-04-01 19:03:31 -0700 | [diff] [blame] | 34 | #define IOMMU_PRIV (1 << 5) |
Patrick Daly | 2330148 | 2017-10-12 16:18:25 -0700 | [diff] [blame] | 35 | #define IOMMU_GUARD (1 << 28) /* Guard Page */ |
Patrick Daly | a0c45d4 | 2016-11-03 13:28:24 -0700 | [diff] [blame] | 36 | /* Use upstream device's bus attribute */ |
| 37 | #define IOMMU_USE_UPSTREAM_HINT (1 << 6) |
Joerg Roedel | 4a77a6c | 2008-11-26 17:02:33 +0100 | [diff] [blame] | 38 | |
Joerg Roedel | 905d66c | 2011-09-06 16:03:26 +0200 | [diff] [blame] | 39 | struct iommu_ops; |
Alex Williamson | d72e31c | 2012-05-30 14:18:53 -0600 | [diff] [blame] | 40 | struct iommu_group; |
Joerg Roedel | ff21776 | 2011-08-26 16:48:26 +0200 | [diff] [blame] | 41 | struct bus_type; |
Joerg Roedel | 4a77a6c | 2008-11-26 17:02:33 +0100 | [diff] [blame] | 42 | struct device; |
Ohad Ben-Cohen | 4f3f8d9 | 2011-09-13 15:25:23 -0400 | [diff] [blame] | 43 | struct iommu_domain; |
Joerg Roedel | ba1eabfa | 2012-08-03 15:55:41 +0200 | [diff] [blame] | 44 | struct notifier_block; |
Ohad Ben-Cohen | 4f3f8d9 | 2011-09-13 15:25:23 -0400 | [diff] [blame] | 45 | |
| 46 | /* iommu fault flags */ |
Sushmita Susheelendra | 5e36b91 | 2015-06-02 15:46:24 -0600 | [diff] [blame] | 47 | #define IOMMU_FAULT_READ (1 << 0) |
| 48 | #define IOMMU_FAULT_WRITE (1 << 1) |
| 49 | #define IOMMU_FAULT_TRANSLATION (1 << 2) |
| 50 | #define IOMMU_FAULT_PERMISSION (1 << 3) |
Mitchel Humpherys | 0cc54a2 | 2015-08-19 10:57:55 -0700 | [diff] [blame] | 51 | #define IOMMU_FAULT_EXTERNAL (1 << 4) |
| 52 | #define IOMMU_FAULT_TRANSACTION_STALLED (1 << 5) |
Ohad Ben-Cohen | 4f3f8d9 | 2011-09-13 15:25:23 -0400 | [diff] [blame] | 53 | |
| 54 | typedef int (*iommu_fault_handler_t)(struct iommu_domain *, |
Ohad Ben-Cohen | 77ca233 | 2012-05-21 20:20:05 +0300 | [diff] [blame] | 55 | struct device *, unsigned long, int, void *); |
Joerg Roedel | 4a77a6c | 2008-11-26 17:02:33 +0100 | [diff] [blame] | 56 | |
Joerg Roedel | 0ff64f8 | 2012-01-26 19:40:53 +0100 | [diff] [blame] | 57 | struct iommu_domain_geometry { |
| 58 | dma_addr_t aperture_start; /* First address that can be mapped */ |
| 59 | dma_addr_t aperture_end; /* Last address that can be mapped */ |
| 60 | bool force_aperture; /* DMA only allowed in mappable range? */ |
| 61 | }; |
| 62 | |
Mitchel Humpherys | 3679a50 | 2016-02-12 14:10:31 -0800 | [diff] [blame] | 63 | struct iommu_pgtbl_info { |
| 64 | void *pmds; |
| 65 | }; |
| 66 | |
Joerg Roedel | 8539c7c | 2015-03-26 13:43:05 +0100 | [diff] [blame] | 67 | /* Domain feature flags */ |
| 68 | #define __IOMMU_DOMAIN_PAGING (1U << 0) /* Support for iommu_map/unmap */ |
| 69 | #define __IOMMU_DOMAIN_DMA_API (1U << 1) /* Domain for use in DMA-API |
| 70 | implementation */ |
| 71 | #define __IOMMU_DOMAIN_PT (1U << 2) /* Domain is identity mapped */ |
| 72 | |
| 73 | /* |
| 74 | * This are the possible domain-types |
| 75 | * |
| 76 | * IOMMU_DOMAIN_BLOCKED - All DMA is blocked, can be used to isolate |
| 77 | * devices |
| 78 | * IOMMU_DOMAIN_IDENTITY - DMA addresses are system physical addresses |
| 79 | * IOMMU_DOMAIN_UNMANAGED - DMA mappings managed by IOMMU-API user, used |
| 80 | * for VMs |
| 81 | * IOMMU_DOMAIN_DMA - Internally used for DMA-API implementations. |
| 82 | * This flag allows IOMMU drivers to implement |
| 83 | * certain optimizations for these domains |
| 84 | */ |
| 85 | #define IOMMU_DOMAIN_BLOCKED (0U) |
| 86 | #define IOMMU_DOMAIN_IDENTITY (__IOMMU_DOMAIN_PT) |
| 87 | #define IOMMU_DOMAIN_UNMANAGED (__IOMMU_DOMAIN_PAGING) |
| 88 | #define IOMMU_DOMAIN_DMA (__IOMMU_DOMAIN_PAGING | \ |
| 89 | __IOMMU_DOMAIN_DMA_API) |
| 90 | |
Liam Mark | 599835a | 2015-06-05 17:10:00 -0700 | [diff] [blame] | 91 | |
| 92 | #define IOMMU_DOMAIN_NAME_LEN 32 |
Joerg Roedel | 4a77a6c | 2008-11-26 17:02:33 +0100 | [diff] [blame] | 93 | struct iommu_domain { |
Joerg Roedel | 8539c7c | 2015-03-26 13:43:05 +0100 | [diff] [blame] | 94 | unsigned type; |
Thierry Reding | b22f643 | 2014-06-27 09:03:12 +0200 | [diff] [blame] | 95 | const struct iommu_ops *ops; |
Robin Murphy | d16e0fa | 2016-04-07 18:42:06 +0100 | [diff] [blame] | 96 | unsigned long pgsize_bitmap; /* Bitmap of page sizes in use */ |
Ohad Ben-Cohen | 4f3f8d9 | 2011-09-13 15:25:23 -0400 | [diff] [blame] | 97 | iommu_fault_handler_t handler; |
Ohad Ben-Cohen | 77ca233 | 2012-05-21 20:20:05 +0300 | [diff] [blame] | 98 | void *handler_token; |
Joerg Roedel | 0ff64f8 | 2012-01-26 19:40:53 +0100 | [diff] [blame] | 99 | struct iommu_domain_geometry geometry; |
Robin Murphy | 0db2e5d | 2015-10-01 20:13:58 +0100 | [diff] [blame] | 100 | void *iova_cookie; |
Liam Mark | 599835a | 2015-06-05 17:10:00 -0700 | [diff] [blame] | 101 | char name[IOMMU_DOMAIN_NAME_LEN]; |
Joerg Roedel | 4a77a6c | 2008-11-26 17:02:33 +0100 | [diff] [blame] | 102 | }; |
| 103 | |
Joerg Roedel | 1aed074 | 2014-09-03 18:34:04 +0200 | [diff] [blame] | 104 | enum iommu_cap { |
| 105 | IOMMU_CAP_CACHE_COHERENCY, /* IOMMU can enforce cache coherent DMA |
| 106 | transactions */ |
| 107 | IOMMU_CAP_INTR_REMAP, /* IOMMU supports interrupt isolation */ |
Antonios Motakis | c498664 | 2014-10-13 14:06:17 +0100 | [diff] [blame] | 108 | IOMMU_CAP_NOEXEC, /* IOMMU_NOEXEC flag */ |
Joerg Roedel | 1aed074 | 2014-09-03 18:34:04 +0200 | [diff] [blame] | 109 | }; |
Sheng Yang | dbb9fd8 | 2009-03-18 15:33:06 +0800 | [diff] [blame] | 110 | |
Varun Sethi | 7cabf49 | 2013-07-15 10:20:56 +0530 | [diff] [blame] | 111 | /* |
| 112 | * Following constraints are specifc to FSL_PAMUV1: |
| 113 | * -aperture must be power of 2, and naturally aligned |
| 114 | * -number of windows must be power of 2, and address space size |
| 115 | * of each window is determined by aperture size / # of windows |
| 116 | * -the actual size of the mapped region of a window must be power |
| 117 | * of 2 starting with 4KB and physical address must be naturally |
| 118 | * aligned. |
| 119 | * DOMAIN_ATTR_FSL_PAMUV1 corresponds to the above mentioned contraints. |
| 120 | * The caller can invoke iommu_domain_get_attr to check if the underlying |
| 121 | * iommu implementation supports these constraints. |
| 122 | */ |
| 123 | |
Joerg Roedel | 0cd76dd | 2012-01-26 19:40:52 +0100 | [diff] [blame] | 124 | enum iommu_attr { |
Joerg Roedel | 0ff64f8 | 2012-01-26 19:40:53 +0100 | [diff] [blame] | 125 | DOMAIN_ATTR_GEOMETRY, |
Joerg Roedel | d2e1216 | 2013-01-29 13:49:04 +0100 | [diff] [blame] | 126 | DOMAIN_ATTR_PAGING, |
Joerg Roedel | 6935671 | 2013-02-04 14:00:01 +0100 | [diff] [blame] | 127 | DOMAIN_ATTR_WINDOWS, |
Varun Sethi | 7cabf49 | 2013-07-15 10:20:56 +0530 | [diff] [blame] | 128 | DOMAIN_ATTR_FSL_PAMU_STASH, |
| 129 | DOMAIN_ATTR_FSL_PAMU_ENABLE, |
| 130 | DOMAIN_ATTR_FSL_PAMUV1, |
Will Deacon | c02607a | 2014-09-29 10:05:06 -0600 | [diff] [blame] | 131 | DOMAIN_ATTR_NESTING, /* two stages of translation */ |
Mitchel Humpherys | 19f19d5 | 2014-11-24 12:31:02 -0800 | [diff] [blame] | 132 | DOMAIN_ATTR_PT_BASE_ADDR, |
Jeremy Gebben | e352bb0 | 2015-06-16 10:54:01 -0600 | [diff] [blame] | 133 | DOMAIN_ATTR_CONTEXT_BANK, |
Jeremy Gebben | 1b34ee1 | 2015-07-10 16:43:23 -0600 | [diff] [blame] | 134 | DOMAIN_ATTR_DYNAMIC, |
Jeremy Gebben | e70da58 | 2015-07-10 16:43:22 -0600 | [diff] [blame] | 135 | DOMAIN_ATTR_TTBR0, |
| 136 | DOMAIN_ATTR_CONTEXTIDR, |
| 137 | DOMAIN_ATTR_PROCID, |
Mitchel Humpherys | e78b0a5 | 2015-09-25 17:26:31 -0700 | [diff] [blame] | 138 | DOMAIN_ATTR_NON_FATAL_FAULTS, |
Patrick Daly | bb82f96 | 2016-03-10 15:25:51 -0800 | [diff] [blame] | 139 | DOMAIN_ATTR_S1_BYPASS, |
Patrick Daly | 023ffedb | 2016-07-06 17:39:30 -0700 | [diff] [blame] | 140 | DOMAIN_ATTR_ATOMIC, |
Patrick Daly | 67be369 | 2016-07-08 15:09:41 -0700 | [diff] [blame] | 141 | DOMAIN_ATTR_SECURE_VMID, |
Mitchel Humpherys | 60581e1 | 2016-02-12 13:53:20 -0800 | [diff] [blame] | 142 | DOMAIN_ATTR_FAST, |
Mitchel Humpherys | 3679a50 | 2016-02-12 14:10:31 -0800 | [diff] [blame] | 143 | DOMAIN_ATTR_PGTBL_INFO, |
Patrick Daly | 0b37c5a | 2016-11-09 13:29:11 -0800 | [diff] [blame] | 144 | DOMAIN_ATTR_USE_UPSTREAM_HINT, |
Patrick Daly | ef6c1dc | 2016-11-16 14:35:23 -0800 | [diff] [blame] | 145 | DOMAIN_ATTR_EARLY_MAP, |
Mitchel Humpherys | 67ec627 | 2016-06-07 14:55:50 -0700 | [diff] [blame] | 146 | DOMAIN_ATTR_PAGE_TABLE_IS_COHERENT, |
Liam Mark | 07edfbf | 2016-12-20 11:35:44 -0800 | [diff] [blame] | 147 | DOMAIN_ATTR_PAGE_TABLE_FORCE_COHERENT, |
Charan Teja Reddy | c682e47 | 2017-04-20 19:11:20 +0530 | [diff] [blame] | 148 | DOMAIN_ATTR_CB_STALL_DISABLE, |
Patrick Daly | 1e27992 | 2017-09-06 15:57:45 -0700 | [diff] [blame] | 149 | DOMAIN_ATTR_UPSTREAM_IOVA_ALLOCATOR, |
Patrick Daly | 83174c1 | 2017-10-26 12:31:15 -0700 | [diff] [blame] | 150 | DOMAIN_ATTR_MMU500_ERRATA_MIN_ALIGN, |
Prakash Gupta | c2e909a | 2018-03-29 11:23:06 +0530 | [diff] [blame] | 151 | DOMAIN_ATTR_FORCE_IOVA_GUARD_PAGE, |
Joerg Roedel | a8b8a88a | 2013-01-29 14:36:31 +0100 | [diff] [blame] | 152 | DOMAIN_ATTR_MAX, |
Joerg Roedel | 0cd76dd | 2012-01-26 19:40:52 +0100 | [diff] [blame] | 153 | }; |
| 154 | |
Joerg Roedel | a1015c2 | 2015-05-28 18:41:33 +0200 | [diff] [blame] | 155 | /** |
| 156 | * struct iommu_dm_region - descriptor for a direct mapped memory region |
| 157 | * @list: Linked list pointers |
| 158 | * @start: System physical start address of the region |
| 159 | * @length: Length of the region in bytes |
| 160 | * @prot: IOMMU Protection flags (READ/WRITE/...) |
| 161 | */ |
| 162 | struct iommu_dm_region { |
| 163 | struct list_head list; |
| 164 | phys_addr_t start; |
| 165 | size_t length; |
| 166 | int prot; |
| 167 | }; |
| 168 | |
Mitchel Humpherys | c75ae49 | 2015-07-15 18:27:36 -0700 | [diff] [blame] | 169 | extern struct dentry *iommu_debugfs_top; |
| 170 | |
Joerg Roedel | 39d4ebb | 2011-09-06 16:48:40 +0200 | [diff] [blame] | 171 | #ifdef CONFIG_IOMMU_API |
| 172 | |
Ohad Ben-Cohen | 7d3002c | 2011-11-10 11:32:26 +0200 | [diff] [blame] | 173 | /** |
| 174 | * struct iommu_ops - iommu ops and capabilities |
Magnus Damm | 0d9bacb | 2016-01-19 14:28:48 +0900 | [diff] [blame] | 175 | * @capable: check capability |
| 176 | * @domain_alloc: allocate iommu domain |
| 177 | * @domain_free: free iommu domain |
Ohad Ben-Cohen | 7d3002c | 2011-11-10 11:32:26 +0200 | [diff] [blame] | 178 | * @attach_dev: attach device to an iommu domain |
| 179 | * @detach_dev: detach device from an iommu domain |
| 180 | * @map: map a physically contiguous memory region to an iommu domain |
| 181 | * @unmap: unmap a physically contiguous memory region from an iommu domain |
Olav Haugan | 315786e | 2014-10-25 09:55:16 -0700 | [diff] [blame] | 182 | * @map_sg: map a scatter-gather list of physically contiguous memory chunks |
| 183 | * to an iommu domain |
Ohad Ben-Cohen | 7d3002c | 2011-11-10 11:32:26 +0200 | [diff] [blame] | 184 | * @iova_to_phys: translate iova to physical address |
Mitchel Humpherys | 36b8c32 | 2015-07-06 15:24:22 -0700 | [diff] [blame] | 185 | * @iova_to_phys_hard: translate iova to physical address using IOMMU hardware |
Alex Williamson | d72e31c | 2012-05-30 14:18:53 -0600 | [diff] [blame] | 186 | * @add_device: add device to iommu grouping |
| 187 | * @remove_device: remove device from iommu grouping |
Magnus Damm | 0d9bacb | 2016-01-19 14:28:48 +0900 | [diff] [blame] | 188 | * @device_group: find iommu group for a particular device |
Joerg Roedel | 0cd76dd | 2012-01-26 19:40:52 +0100 | [diff] [blame] | 189 | * @domain_get_attr: Query domain attributes |
| 190 | * @domain_set_attr: Change domain attributes |
Magnus Damm | 0d9bacb | 2016-01-19 14:28:48 +0900 | [diff] [blame] | 191 | * @get_dm_regions: Request list of direct mapping requirements for a device |
| 192 | * @put_dm_regions: Free list of direct mapping requirements for a device |
Joerg Roedel | 33b21a6 | 2016-07-05 13:07:53 +0200 | [diff] [blame] | 193 | * @apply_dm_region: Temporary helper call-back for iova reserved ranges |
Magnus Damm | 0d9bacb | 2016-01-19 14:28:48 +0900 | [diff] [blame] | 194 | * @domain_window_enable: Configure and enable a particular window for a domain |
| 195 | * @domain_window_disable: Disable a particular window for a domain |
| 196 | * @domain_set_windows: Set the number of windows for a domain |
| 197 | * @domain_get_windows: Return the number of windows for a domain |
Will Deacon | d0f60a4 | 2014-08-27 16:15:59 +0100 | [diff] [blame] | 198 | * @of_xlate: add OF master IDs to iommu grouping |
Robin Murphy | d16e0fa | 2016-04-07 18:42:06 +0100 | [diff] [blame] | 199 | * @pgsize_bitmap: bitmap of all possible supported page sizes |
Mitchel Humpherys | 8488df2 | 2015-07-09 16:59:02 -0700 | [diff] [blame] | 200 | * @trigger_fault: trigger a fault on the device attached to an iommu domain |
Mitchel Humpherys | 3ede5d9 | 2015-08-21 14:06:14 -0700 | [diff] [blame] | 201 | * @reg_read: read an IOMMU register |
| 202 | * @reg_write: write an IOMMU register |
Mitchel Humpherys | 39bad0c | 2015-12-03 11:17:23 -0800 | [diff] [blame] | 203 | * @tlbi_domain: Invalidate all TLBs covering an iommu domain |
Mitchel Humpherys | 4264f19 | 2015-12-14 16:04:46 -0800 | [diff] [blame] | 204 | * @enable_config_clocks: Enable all config clocks for this domain's IOMMU |
| 205 | * @disable_config_clocks: Disable all config clocks for this domain's IOMMU |
Ohad Ben-Cohen | 7d3002c | 2011-11-10 11:32:26 +0200 | [diff] [blame] | 206 | */ |
Joerg Roedel | 4a77a6c | 2008-11-26 17:02:33 +0100 | [diff] [blame] | 207 | struct iommu_ops { |
Joerg Roedel | 3c0e0ca | 2014-09-03 18:47:25 +0200 | [diff] [blame] | 208 | bool (*capable)(enum iommu_cap); |
Joerg Roedel | 938c470 | 2015-03-26 13:43:04 +0100 | [diff] [blame] | 209 | |
| 210 | /* Domain allocation and freeing by the iommu driver */ |
Joerg Roedel | 8539c7c | 2015-03-26 13:43:05 +0100 | [diff] [blame] | 211 | struct iommu_domain *(*domain_alloc)(unsigned iommu_domain_type); |
Joerg Roedel | 938c470 | 2015-03-26 13:43:04 +0100 | [diff] [blame] | 212 | void (*domain_free)(struct iommu_domain *); |
| 213 | |
Joerg Roedel | 4a77a6c | 2008-11-26 17:02:33 +0100 | [diff] [blame] | 214 | int (*attach_dev)(struct iommu_domain *domain, struct device *dev); |
| 215 | void (*detach_dev)(struct iommu_domain *domain, struct device *dev); |
Joerg Roedel | 6765178 | 2010-01-21 16:32:27 +0100 | [diff] [blame] | 216 | int (*map)(struct iommu_domain *domain, unsigned long iova, |
Ohad Ben-Cohen | 5009065 | 2011-11-10 11:32:25 +0200 | [diff] [blame] | 217 | phys_addr_t paddr, size_t size, int prot); |
| 218 | size_t (*unmap)(struct iommu_domain *domain, unsigned long iova, |
| 219 | size_t size); |
Olav Haugan | 315786e | 2014-10-25 09:55:16 -0700 | [diff] [blame] | 220 | size_t (*map_sg)(struct iommu_domain *domain, unsigned long iova, |
| 221 | struct scatterlist *sg, unsigned int nents, int prot); |
Varun Sethi | bb5547ac | 2013-03-29 01:23:58 +0530 | [diff] [blame] | 222 | phys_addr_t (*iova_to_phys)(struct iommu_domain *domain, dma_addr_t iova); |
Mitchel Humpherys | 36b8c32 | 2015-07-06 15:24:22 -0700 | [diff] [blame] | 223 | phys_addr_t (*iova_to_phys_hard)(struct iommu_domain *domain, |
| 224 | dma_addr_t iova); |
Alex Williamson | d72e31c | 2012-05-30 14:18:53 -0600 | [diff] [blame] | 225 | int (*add_device)(struct device *dev); |
| 226 | void (*remove_device)(struct device *dev); |
Joerg Roedel | 46c6b2b | 2015-10-21 23:51:36 +0200 | [diff] [blame] | 227 | struct iommu_group *(*device_group)(struct device *dev); |
Joerg Roedel | 0cd76dd | 2012-01-26 19:40:52 +0100 | [diff] [blame] | 228 | int (*domain_get_attr)(struct iommu_domain *domain, |
| 229 | enum iommu_attr attr, void *data); |
| 230 | int (*domain_set_attr)(struct iommu_domain *domain, |
| 231 | enum iommu_attr attr, void *data); |
Joerg Roedel | d7787d5 | 2013-01-29 14:26:20 +0100 | [diff] [blame] | 232 | |
Joerg Roedel | a1015c2 | 2015-05-28 18:41:33 +0200 | [diff] [blame] | 233 | /* Request/Free a list of direct mapping requirements for a device */ |
| 234 | void (*get_dm_regions)(struct device *dev, struct list_head *list); |
| 235 | void (*put_dm_regions)(struct device *dev, struct list_head *list); |
Joerg Roedel | 33b21a6 | 2016-07-05 13:07:53 +0200 | [diff] [blame] | 236 | void (*apply_dm_region)(struct device *dev, struct iommu_domain *domain, |
| 237 | struct iommu_dm_region *region); |
Joerg Roedel | a1015c2 | 2015-05-28 18:41:33 +0200 | [diff] [blame] | 238 | |
Joerg Roedel | d7787d5 | 2013-01-29 14:26:20 +0100 | [diff] [blame] | 239 | /* Window handling functions */ |
| 240 | int (*domain_window_enable)(struct iommu_domain *domain, u32 wnd_nr, |
Varun Sethi | 80f97f0 | 2013-03-29 01:24:00 +0530 | [diff] [blame] | 241 | phys_addr_t paddr, u64 size, int prot); |
Joerg Roedel | d7787d5 | 2013-01-29 14:26:20 +0100 | [diff] [blame] | 242 | void (*domain_window_disable)(struct iommu_domain *domain, u32 wnd_nr); |
Magnus Damm | 0d9bacb | 2016-01-19 14:28:48 +0900 | [diff] [blame] | 243 | /* Set the number of windows per domain */ |
Joerg Roedel | 6935671 | 2013-02-04 14:00:01 +0100 | [diff] [blame] | 244 | int (*domain_set_windows)(struct iommu_domain *domain, u32 w_count); |
Magnus Damm | 0d9bacb | 2016-01-19 14:28:48 +0900 | [diff] [blame] | 245 | /* Get the number of windows per domain */ |
Joerg Roedel | 6935671 | 2013-02-04 14:00:01 +0100 | [diff] [blame] | 246 | u32 (*domain_get_windows)(struct iommu_domain *domain); |
Mitchel Humpherys | 8488df2 | 2015-07-09 16:59:02 -0700 | [diff] [blame] | 247 | void (*trigger_fault)(struct iommu_domain *domain, unsigned long flags); |
Mitchel Humpherys | 39bad0c | 2015-12-03 11:17:23 -0800 | [diff] [blame] | 248 | void (*tlbi_domain)(struct iommu_domain *domain); |
Mitchel Humpherys | 4264f19 | 2015-12-14 16:04:46 -0800 | [diff] [blame] | 249 | int (*enable_config_clocks)(struct iommu_domain *domain); |
| 250 | void (*disable_config_clocks)(struct iommu_domain *domain); |
Sudarshan Rajagopalan | 7a0b4bb | 2017-04-04 19:10:06 -0700 | [diff] [blame] | 251 | uint64_t (*iova_to_pte)(struct iommu_domain *domain, |
| 252 | dma_addr_t iova); |
Joerg Roedel | d7787d5 | 2013-01-29 14:26:20 +0100 | [diff] [blame] | 253 | |
Will Deacon | d0f60a4 | 2014-08-27 16:15:59 +0100 | [diff] [blame] | 254 | int (*of_xlate)(struct device *dev, struct of_phandle_args *args); |
Will Deacon | d0f60a4 | 2014-08-27 16:15:59 +0100 | [diff] [blame] | 255 | |
Liam Mark | 5bb6422 | 2016-12-09 14:36:07 -0800 | [diff] [blame] | 256 | bool (*is_iova_coherent)(struct iommu_domain *domain, dma_addr_t iova); |
Ohad Ben-Cohen | 7d3002c | 2011-11-10 11:32:26 +0200 | [diff] [blame] | 257 | unsigned long pgsize_bitmap; |
Joerg Roedel | 4a77a6c | 2008-11-26 17:02:33 +0100 | [diff] [blame] | 258 | }; |
| 259 | |
Alex Williamson | d72e31c | 2012-05-30 14:18:53 -0600 | [diff] [blame] | 260 | #define IOMMU_GROUP_NOTIFY_ADD_DEVICE 1 /* Device added */ |
| 261 | #define IOMMU_GROUP_NOTIFY_DEL_DEVICE 2 /* Pre Device removed */ |
| 262 | #define IOMMU_GROUP_NOTIFY_BIND_DRIVER 3 /* Pre Driver bind */ |
| 263 | #define IOMMU_GROUP_NOTIFY_BOUND_DRIVER 4 /* Post Driver bind */ |
| 264 | #define IOMMU_GROUP_NOTIFY_UNBIND_DRIVER 5 /* Pre Driver unbind */ |
| 265 | #define IOMMU_GROUP_NOTIFY_UNBOUND_DRIVER 6 /* Post Driver unbind */ |
| 266 | |
Thierry Reding | b22f643 | 2014-06-27 09:03:12 +0200 | [diff] [blame] | 267 | 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] | 268 | extern bool iommu_present(struct bus_type *bus); |
Joerg Roedel | 3c0e0ca | 2014-09-03 18:47:25 +0200 | [diff] [blame] | 269 | extern bool iommu_capable(struct bus_type *bus, enum iommu_cap cap); |
Joerg Roedel | 905d66c | 2011-09-06 16:03:26 +0200 | [diff] [blame] | 270 | extern struct iommu_domain *iommu_domain_alloc(struct bus_type *bus); |
Alexey Kardashevskiy | aa16bea | 2013-03-25 10:23:49 +1100 | [diff] [blame] | 271 | extern struct iommu_group *iommu_group_get_by_id(int id); |
Joerg Roedel | 4a77a6c | 2008-11-26 17:02:33 +0100 | [diff] [blame] | 272 | extern void iommu_domain_free(struct iommu_domain *domain); |
| 273 | extern int iommu_attach_device(struct iommu_domain *domain, |
| 274 | struct device *dev); |
| 275 | extern void iommu_detach_device(struct iommu_domain *domain, |
| 276 | struct device *dev); |
Joerg Roedel | 2c1296d | 2015-05-28 18:41:32 +0200 | [diff] [blame] | 277 | extern struct iommu_domain *iommu_get_domain_for_dev(struct device *dev); |
Mitchel Humpherys | fad2592 | 2015-05-01 17:13:21 -0700 | [diff] [blame] | 278 | extern size_t iommu_pgsize(unsigned long pgsize_bitmap, |
| 279 | unsigned long addr_merge, size_t size); |
Joerg Roedel | cefc53c | 2010-01-08 13:35:09 +0100 | [diff] [blame] | 280 | extern int iommu_map(struct iommu_domain *domain, unsigned long iova, |
Ohad Ben-Cohen | 7d3002c | 2011-11-10 11:32:26 +0200 | [diff] [blame] | 281 | phys_addr_t paddr, size_t size, int prot); |
| 282 | extern size_t iommu_unmap(struct iommu_domain *domain, unsigned long iova, |
| 283 | size_t size); |
Liam Mark | 599835a | 2015-06-05 17:10:00 -0700 | [diff] [blame] | 284 | extern size_t iommu_map_sg(struct iommu_domain *domain, unsigned long iova, |
| 285 | struct scatterlist *sg, unsigned int nents, |
| 286 | int prot); |
Olav Haugan | 315786e | 2014-10-25 09:55:16 -0700 | [diff] [blame] | 287 | extern size_t default_iommu_map_sg(struct iommu_domain *domain, unsigned long iova, |
| 288 | struct scatterlist *sg,unsigned int nents, |
| 289 | int prot); |
Varun Sethi | bb5547ac | 2013-03-29 01:23:58 +0530 | [diff] [blame] | 290 | extern phys_addr_t iommu_iova_to_phys(struct iommu_domain *domain, dma_addr_t iova); |
Mitchel Humpherys | 36b8c32 | 2015-07-06 15:24:22 -0700 | [diff] [blame] | 291 | extern phys_addr_t iommu_iova_to_phys_hard(struct iommu_domain *domain, |
| 292 | dma_addr_t iova); |
Liam Mark | 5bb6422 | 2016-12-09 14:36:07 -0800 | [diff] [blame] | 293 | extern bool iommu_is_iova_coherent(struct iommu_domain *domain, |
| 294 | dma_addr_t iova); |
Ohad Ben-Cohen | 4f3f8d9 | 2011-09-13 15:25:23 -0400 | [diff] [blame] | 295 | extern void iommu_set_fault_handler(struct iommu_domain *domain, |
Ohad Ben-Cohen | 77ca233 | 2012-05-21 20:20:05 +0300 | [diff] [blame] | 296 | iommu_fault_handler_t handler, void *token); |
Alex Williamson | d72e31c | 2012-05-30 14:18:53 -0600 | [diff] [blame] | 297 | |
Joerg Roedel | a1015c2 | 2015-05-28 18:41:33 +0200 | [diff] [blame] | 298 | extern void iommu_get_dm_regions(struct device *dev, struct list_head *list); |
| 299 | extern void iommu_put_dm_regions(struct device *dev, struct list_head *list); |
Joerg Roedel | d290f1e | 2015-05-28 18:41:36 +0200 | [diff] [blame] | 300 | extern int iommu_request_dm_for_dev(struct device *dev); |
Joerg Roedel | a1015c2 | 2015-05-28 18:41:33 +0200 | [diff] [blame] | 301 | |
Alex Williamson | d72e31c | 2012-05-30 14:18:53 -0600 | [diff] [blame] | 302 | extern int iommu_attach_group(struct iommu_domain *domain, |
| 303 | struct iommu_group *group); |
| 304 | extern void iommu_detach_group(struct iommu_domain *domain, |
| 305 | struct iommu_group *group); |
| 306 | extern struct iommu_group *iommu_group_alloc(void); |
| 307 | extern void *iommu_group_get_iommudata(struct iommu_group *group); |
| 308 | extern void iommu_group_set_iommudata(struct iommu_group *group, |
| 309 | void *iommu_data, |
| 310 | void (*release)(void *iommu_data)); |
| 311 | extern int iommu_group_set_name(struct iommu_group *group, const char *name); |
| 312 | extern int iommu_group_add_device(struct iommu_group *group, |
| 313 | struct device *dev); |
| 314 | extern void iommu_group_remove_device(struct device *dev); |
| 315 | extern int iommu_group_for_each_dev(struct iommu_group *group, void *data, |
| 316 | int (*fn)(struct device *, void *)); |
| 317 | extern struct iommu_group *iommu_group_get(struct device *dev); |
| 318 | extern void iommu_group_put(struct iommu_group *group); |
| 319 | extern int iommu_group_register_notifier(struct iommu_group *group, |
| 320 | struct notifier_block *nb); |
| 321 | extern int iommu_group_unregister_notifier(struct iommu_group *group, |
| 322 | struct notifier_block *nb); |
| 323 | extern int iommu_group_id(struct iommu_group *group); |
Alex Williamson | 104a1c1 | 2014-07-03 09:51:18 -0600 | [diff] [blame] | 324 | extern struct iommu_group *iommu_group_get_for_dev(struct device *dev); |
Joerg Roedel | 6827ca8 | 2015-05-28 18:41:35 +0200 | [diff] [blame] | 325 | extern struct iommu_domain *iommu_group_default_domain(struct iommu_group *); |
Ohad Ben-Cohen | 4f3f8d9 | 2011-09-13 15:25:23 -0400 | [diff] [blame] | 326 | |
Joerg Roedel | 0cd76dd | 2012-01-26 19:40:52 +0100 | [diff] [blame] | 327 | extern int iommu_domain_get_attr(struct iommu_domain *domain, enum iommu_attr, |
| 328 | void *data); |
| 329 | extern int iommu_domain_set_attr(struct iommu_domain *domain, enum iommu_attr, |
| 330 | void *data); |
Alex Williamson | c61959e | 2014-06-12 16:12:24 -0600 | [diff] [blame] | 331 | struct device *iommu_device_create(struct device *parent, void *drvdata, |
| 332 | const struct attribute_group **groups, |
Nicolas Iooss | 8db1486 | 2015-07-17 16:23:42 -0700 | [diff] [blame] | 333 | const char *fmt, ...) __printf(4, 5); |
Alex Williamson | c61959e | 2014-06-12 16:12:24 -0600 | [diff] [blame] | 334 | void iommu_device_destroy(struct device *dev); |
| 335 | int iommu_device_link(struct device *dev, struct device *link); |
| 336 | void iommu_device_unlink(struct device *dev, struct device *link); |
Ohad Ben-Cohen | 4f3f8d9 | 2011-09-13 15:25:23 -0400 | [diff] [blame] | 337 | |
Joerg Roedel | d7787d5 | 2013-01-29 14:26:20 +0100 | [diff] [blame] | 338 | /* Window handling function prototypes */ |
| 339 | 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] | 340 | phys_addr_t offset, u64 size, |
| 341 | int prot); |
Joerg Roedel | d7787d5 | 2013-01-29 14:26:20 +0100 | [diff] [blame] | 342 | extern void iommu_domain_window_disable(struct iommu_domain *domain, u32 wnd_nr); |
Sudarshan Rajagopalan | 7a0b4bb | 2017-04-04 19:10:06 -0700 | [diff] [blame] | 343 | |
| 344 | extern uint64_t iommu_iova_to_pte(struct iommu_domain *domain, |
| 345 | dma_addr_t iova); |
Sushmita Susheelendra | 5e36b91 | 2015-06-02 15:46:24 -0600 | [diff] [blame] | 346 | |
Joerg Roedel | 2f4ae01d | 2017-04-26 15:39:28 +0200 | [diff] [blame] | 347 | extern int report_iommu_fault(struct iommu_domain *domain, struct device *dev, |
| 348 | unsigned long iova, int flags); |
Joerg Roedel | 4a77a6c | 2008-11-26 17:02:33 +0100 | [diff] [blame] | 349 | |
Mitchel Humpherys | 8488df2 | 2015-07-09 16:59:02 -0700 | [diff] [blame] | 350 | extern void iommu_trigger_fault(struct iommu_domain *domain, |
| 351 | unsigned long flags); |
| 352 | |
Mitchel Humpherys | 3ede5d9 | 2015-08-21 14:06:14 -0700 | [diff] [blame] | 353 | extern unsigned long iommu_reg_read(struct iommu_domain *domain, |
| 354 | unsigned long offset); |
| 355 | extern void iommu_reg_write(struct iommu_domain *domain, unsigned long offset, |
| 356 | unsigned long val); |
Joerg Roedel | 5e62292 | 2015-10-21 23:51:37 +0200 | [diff] [blame] | 357 | /* PCI device grouping function */ |
| 358 | extern struct iommu_group *pci_device_group(struct device *dev); |
Joerg Roedel | 6eab556 | 2015-10-21 23:51:38 +0200 | [diff] [blame] | 359 | /* Generic device grouping function */ |
| 360 | extern struct iommu_group *generic_device_group(struct device *dev); |
Joerg Roedel | 5e62292 | 2015-10-21 23:51:37 +0200 | [diff] [blame] | 361 | |
Mitchel Humpherys | 39bad0c | 2015-12-03 11:17:23 -0800 | [diff] [blame] | 362 | static inline void iommu_tlbiall(struct iommu_domain *domain) |
| 363 | { |
| 364 | if (domain->ops->tlbi_domain) |
| 365 | domain->ops->tlbi_domain(domain); |
| 366 | } |
| 367 | |
Mitchel Humpherys | 4264f19 | 2015-12-14 16:04:46 -0800 | [diff] [blame] | 368 | static inline int iommu_enable_config_clocks(struct iommu_domain *domain) |
| 369 | { |
| 370 | if (domain->ops->enable_config_clocks) |
| 371 | return domain->ops->enable_config_clocks(domain); |
| 372 | return 0; |
| 373 | } |
| 374 | |
| 375 | static inline void iommu_disable_config_clocks(struct iommu_domain *domain) |
| 376 | { |
| 377 | if (domain->ops->disable_config_clocks) |
| 378 | domain->ops->disable_config_clocks(domain); |
| 379 | } |
| 380 | |
Robin Murphy | 57f98d2 | 2016-09-13 10:54:14 +0100 | [diff] [blame] | 381 | /** |
| 382 | * struct iommu_fwspec - per-device IOMMU instance data |
| 383 | * @ops: ops for this device's IOMMU |
| 384 | * @iommu_fwnode: firmware handle for this device's IOMMU |
| 385 | * @iommu_priv: IOMMU driver private data for this device |
| 386 | * @num_ids: number of associated device IDs |
| 387 | * @ids: IDs which this device may present to the IOMMU |
| 388 | */ |
| 389 | struct iommu_fwspec { |
| 390 | const struct iommu_ops *ops; |
| 391 | struct fwnode_handle *iommu_fwnode; |
| 392 | void *iommu_priv; |
| 393 | unsigned int num_ids; |
| 394 | u32 ids[1]; |
| 395 | }; |
| 396 | |
| 397 | int iommu_fwspec_init(struct device *dev, struct fwnode_handle *iommu_fwnode, |
| 398 | const struct iommu_ops *ops); |
| 399 | void iommu_fwspec_free(struct device *dev); |
| 400 | int iommu_fwspec_add_ids(struct device *dev, u32 *ids, int num_ids); |
Patrick Daly | 1e3c16c | 2017-04-12 17:59:07 -0700 | [diff] [blame] | 401 | int iommu_fwspec_get_id(struct device *dev, u32 *id); |
Patrick Daly | 958973c | 2017-04-28 19:45:18 -0700 | [diff] [blame] | 402 | int iommu_is_available(struct device *dev); |
Robin Murphy | 57f98d2 | 2016-09-13 10:54:14 +0100 | [diff] [blame] | 403 | |
Joerg Roedel | 4a77a6c | 2008-11-26 17:02:33 +0100 | [diff] [blame] | 404 | #else /* CONFIG_IOMMU_API */ |
| 405 | |
Joerg Roedel | 39d4ebb | 2011-09-06 16:48:40 +0200 | [diff] [blame] | 406 | struct iommu_ops {}; |
Alex Williamson | d72e31c | 2012-05-30 14:18:53 -0600 | [diff] [blame] | 407 | struct iommu_group {}; |
Robin Murphy | 57f98d2 | 2016-09-13 10:54:14 +0100 | [diff] [blame] | 408 | struct iommu_fwspec {}; |
Joerg Roedel | 4a77a6c | 2008-11-26 17:02:33 +0100 | [diff] [blame] | 409 | |
Joerg Roedel | a1b60c1 | 2011-09-06 18:46:34 +0200 | [diff] [blame] | 410 | static inline bool iommu_present(struct bus_type *bus) |
Joerg Roedel | 4a77a6c | 2008-11-26 17:02:33 +0100 | [diff] [blame] | 411 | { |
| 412 | return false; |
| 413 | } |
| 414 | |
Joerg Roedel | 3c0e0ca | 2014-09-03 18:47:25 +0200 | [diff] [blame] | 415 | static inline bool iommu_capable(struct bus_type *bus, enum iommu_cap cap) |
| 416 | { |
| 417 | return false; |
| 418 | } |
| 419 | |
Joerg Roedel | 905d66c | 2011-09-06 16:03:26 +0200 | [diff] [blame] | 420 | static inline struct iommu_domain *iommu_domain_alloc(struct bus_type *bus) |
Joerg Roedel | 4a77a6c | 2008-11-26 17:02:33 +0100 | [diff] [blame] | 421 | { |
| 422 | return NULL; |
| 423 | } |
| 424 | |
Alexey Kardashevskiy | b62dfd2 | 2013-11-21 17:41:14 +1100 | [diff] [blame] | 425 | static inline struct iommu_group *iommu_group_get_by_id(int id) |
| 426 | { |
| 427 | return NULL; |
| 428 | } |
| 429 | |
Joerg Roedel | 4a77a6c | 2008-11-26 17:02:33 +0100 | [diff] [blame] | 430 | static inline void iommu_domain_free(struct iommu_domain *domain) |
| 431 | { |
| 432 | } |
| 433 | |
| 434 | static inline int iommu_attach_device(struct iommu_domain *domain, |
| 435 | struct device *dev) |
| 436 | { |
| 437 | return -ENODEV; |
| 438 | } |
| 439 | |
| 440 | static inline void iommu_detach_device(struct iommu_domain *domain, |
| 441 | struct device *dev) |
| 442 | { |
| 443 | } |
| 444 | |
Joerg Roedel | 2c1296d | 2015-05-28 18:41:32 +0200 | [diff] [blame] | 445 | static inline struct iommu_domain *iommu_get_domain_for_dev(struct device *dev) |
| 446 | { |
| 447 | return NULL; |
| 448 | } |
| 449 | |
Joerg Roedel | cefc53c | 2010-01-08 13:35:09 +0100 | [diff] [blame] | 450 | static inline int iommu_map(struct iommu_domain *domain, unsigned long iova, |
| 451 | phys_addr_t paddr, int gfp_order, int prot) |
| 452 | { |
| 453 | return -ENODEV; |
| 454 | } |
| 455 | |
| 456 | static inline int iommu_unmap(struct iommu_domain *domain, unsigned long iova, |
| 457 | int gfp_order) |
| 458 | { |
| 459 | return -ENODEV; |
| 460 | } |
| 461 | |
Olav Haugan | 315786e | 2014-10-25 09:55:16 -0700 | [diff] [blame] | 462 | static inline size_t iommu_map_sg(struct iommu_domain *domain, |
| 463 | unsigned long iova, struct scatterlist *sg, |
| 464 | unsigned int nents, int prot) |
| 465 | { |
| 466 | return -ENODEV; |
| 467 | } |
| 468 | |
Joerg Roedel | d7787d5 | 2013-01-29 14:26:20 +0100 | [diff] [blame] | 469 | static inline int iommu_domain_window_enable(struct iommu_domain *domain, |
| 470 | u32 wnd_nr, phys_addr_t paddr, |
Varun Sethi | 80f97f0 | 2013-03-29 01:24:00 +0530 | [diff] [blame] | 471 | u64 size, int prot) |
Joerg Roedel | d7787d5 | 2013-01-29 14:26:20 +0100 | [diff] [blame] | 472 | { |
| 473 | return -ENODEV; |
| 474 | } |
| 475 | |
| 476 | static inline void iommu_domain_window_disable(struct iommu_domain *domain, |
| 477 | u32 wnd_nr) |
| 478 | { |
| 479 | } |
| 480 | |
Varun Sethi | bb5547ac | 2013-03-29 01:23:58 +0530 | [diff] [blame] | 481 | 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] | 482 | { |
| 483 | return 0; |
| 484 | } |
| 485 | |
Mitchel Humpherys | 36b8c32 | 2015-07-06 15:24:22 -0700 | [diff] [blame] | 486 | static inline phys_addr_t iommu_iova_to_phys_hard(struct iommu_domain *domain, |
| 487 | dma_addr_t iova) |
| 488 | { |
| 489 | return 0; |
| 490 | } |
| 491 | |
Liam Mark | 5bb6422 | 2016-12-09 14:36:07 -0800 | [diff] [blame] | 492 | static inline bool iommu_is_iova_coherent(struct iommu_domain *domain, |
| 493 | dma_addr_t iova) |
| 494 | { |
| 495 | return 0; |
| 496 | } |
| 497 | |
Ohad Ben-Cohen | 4f3f8d9 | 2011-09-13 15:25:23 -0400 | [diff] [blame] | 498 | static inline void iommu_set_fault_handler(struct iommu_domain *domain, |
Ohad Ben-Cohen | 77ca233 | 2012-05-21 20:20:05 +0300 | [diff] [blame] | 499 | iommu_fault_handler_t handler, void *token) |
Ohad Ben-Cohen | 4f3f8d9 | 2011-09-13 15:25:23 -0400 | [diff] [blame] | 500 | { |
| 501 | } |
| 502 | |
Joerg Roedel | a1015c2 | 2015-05-28 18:41:33 +0200 | [diff] [blame] | 503 | static inline void iommu_get_dm_regions(struct device *dev, |
| 504 | struct list_head *list) |
| 505 | { |
| 506 | } |
| 507 | |
| 508 | static inline void iommu_put_dm_regions(struct device *dev, |
| 509 | struct list_head *list) |
| 510 | { |
| 511 | } |
| 512 | |
Joerg Roedel | d290f1e | 2015-05-28 18:41:36 +0200 | [diff] [blame] | 513 | static inline int iommu_request_dm_for_dev(struct device *dev) |
| 514 | { |
| 515 | return -ENODEV; |
| 516 | } |
| 517 | |
Alex Williamson | bef83de | 2012-09-24 21:23:25 -0600 | [diff] [blame] | 518 | static inline int iommu_attach_group(struct iommu_domain *domain, |
| 519 | struct iommu_group *group) |
Alex Williamson | 1460432 | 2011-10-21 15:56:05 -0400 | [diff] [blame] | 520 | { |
| 521 | return -ENODEV; |
| 522 | } |
| 523 | |
Alex Williamson | bef83de | 2012-09-24 21:23:25 -0600 | [diff] [blame] | 524 | static inline void iommu_detach_group(struct iommu_domain *domain, |
| 525 | struct iommu_group *group) |
Alex Williamson | d72e31c | 2012-05-30 14:18:53 -0600 | [diff] [blame] | 526 | { |
| 527 | } |
| 528 | |
Alex Williamson | bef83de | 2012-09-24 21:23:25 -0600 | [diff] [blame] | 529 | static inline struct iommu_group *iommu_group_alloc(void) |
Alex Williamson | d72e31c | 2012-05-30 14:18:53 -0600 | [diff] [blame] | 530 | { |
| 531 | return ERR_PTR(-ENODEV); |
| 532 | } |
| 533 | |
Alex Williamson | bef83de | 2012-09-24 21:23:25 -0600 | [diff] [blame] | 534 | static inline void *iommu_group_get_iommudata(struct iommu_group *group) |
Alex Williamson | d72e31c | 2012-05-30 14:18:53 -0600 | [diff] [blame] | 535 | { |
| 536 | return NULL; |
| 537 | } |
| 538 | |
Alex Williamson | bef83de | 2012-09-24 21:23:25 -0600 | [diff] [blame] | 539 | static inline void iommu_group_set_iommudata(struct iommu_group *group, |
| 540 | void *iommu_data, |
| 541 | void (*release)(void *iommu_data)) |
Alex Williamson | d72e31c | 2012-05-30 14:18:53 -0600 | [diff] [blame] | 542 | { |
| 543 | } |
| 544 | |
Alex Williamson | bef83de | 2012-09-24 21:23:25 -0600 | [diff] [blame] | 545 | static inline int iommu_group_set_name(struct iommu_group *group, |
| 546 | const char *name) |
Alex Williamson | d72e31c | 2012-05-30 14:18:53 -0600 | [diff] [blame] | 547 | { |
| 548 | return -ENODEV; |
| 549 | } |
| 550 | |
Alex Williamson | bef83de | 2012-09-24 21:23:25 -0600 | [diff] [blame] | 551 | static inline int iommu_group_add_device(struct iommu_group *group, |
| 552 | struct device *dev) |
Alex Williamson | d72e31c | 2012-05-30 14:18:53 -0600 | [diff] [blame] | 553 | { |
| 554 | return -ENODEV; |
| 555 | } |
| 556 | |
Alex Williamson | bef83de | 2012-09-24 21:23:25 -0600 | [diff] [blame] | 557 | static inline void iommu_group_remove_device(struct device *dev) |
Alex Williamson | d72e31c | 2012-05-30 14:18:53 -0600 | [diff] [blame] | 558 | { |
| 559 | } |
| 560 | |
Alex Williamson | bef83de | 2012-09-24 21:23:25 -0600 | [diff] [blame] | 561 | static inline int iommu_group_for_each_dev(struct iommu_group *group, |
| 562 | void *data, |
| 563 | int (*fn)(struct device *, void *)) |
Alex Williamson | d72e31c | 2012-05-30 14:18:53 -0600 | [diff] [blame] | 564 | { |
| 565 | return -ENODEV; |
| 566 | } |
| 567 | |
Alex Williamson | bef83de | 2012-09-24 21:23:25 -0600 | [diff] [blame] | 568 | static inline struct iommu_group *iommu_group_get(struct device *dev) |
Alex Williamson | d72e31c | 2012-05-30 14:18:53 -0600 | [diff] [blame] | 569 | { |
| 570 | return NULL; |
| 571 | } |
| 572 | |
Alex Williamson | bef83de | 2012-09-24 21:23:25 -0600 | [diff] [blame] | 573 | static inline void iommu_group_put(struct iommu_group *group) |
Alex Williamson | d72e31c | 2012-05-30 14:18:53 -0600 | [diff] [blame] | 574 | { |
| 575 | } |
| 576 | |
Alex Williamson | bef83de | 2012-09-24 21:23:25 -0600 | [diff] [blame] | 577 | static inline int iommu_group_register_notifier(struct iommu_group *group, |
| 578 | struct notifier_block *nb) |
Alex Williamson | d72e31c | 2012-05-30 14:18:53 -0600 | [diff] [blame] | 579 | { |
| 580 | return -ENODEV; |
| 581 | } |
| 582 | |
Alex Williamson | bef83de | 2012-09-24 21:23:25 -0600 | [diff] [blame] | 583 | static inline int iommu_group_unregister_notifier(struct iommu_group *group, |
| 584 | struct notifier_block *nb) |
Alex Williamson | d72e31c | 2012-05-30 14:18:53 -0600 | [diff] [blame] | 585 | { |
| 586 | return 0; |
| 587 | } |
| 588 | |
Alex Williamson | bef83de | 2012-09-24 21:23:25 -0600 | [diff] [blame] | 589 | static inline int iommu_group_id(struct iommu_group *group) |
Alex Williamson | d72e31c | 2012-05-30 14:18:53 -0600 | [diff] [blame] | 590 | { |
| 591 | return -ENODEV; |
| 592 | } |
Joerg Roedel | 4a77a6c | 2008-11-26 17:02:33 +0100 | [diff] [blame] | 593 | |
Joerg Roedel | 0cd76dd | 2012-01-26 19:40:52 +0100 | [diff] [blame] | 594 | static inline int iommu_domain_get_attr(struct iommu_domain *domain, |
| 595 | enum iommu_attr attr, void *data) |
| 596 | { |
| 597 | return -EINVAL; |
| 598 | } |
| 599 | |
| 600 | static inline int iommu_domain_set_attr(struct iommu_domain *domain, |
| 601 | enum iommu_attr attr, void *data) |
| 602 | { |
| 603 | return -EINVAL; |
| 604 | } |
| 605 | |
Alex Williamson | e09f8ea5 | 2014-07-07 14:31:36 -0600 | [diff] [blame] | 606 | static inline struct device *iommu_device_create(struct device *parent, |
| 607 | void *drvdata, |
| 608 | const struct attribute_group **groups, |
| 609 | const char *fmt, ...) |
Alex Williamson | c61959e | 2014-06-12 16:12:24 -0600 | [diff] [blame] | 610 | { |
| 611 | return ERR_PTR(-ENODEV); |
| 612 | } |
| 613 | |
Alex Williamson | e09f8ea5 | 2014-07-07 14:31:36 -0600 | [diff] [blame] | 614 | static inline void iommu_device_destroy(struct device *dev) |
Alex Williamson | c61959e | 2014-06-12 16:12:24 -0600 | [diff] [blame] | 615 | { |
| 616 | } |
| 617 | |
Alex Williamson | e09f8ea5 | 2014-07-07 14:31:36 -0600 | [diff] [blame] | 618 | static inline int iommu_device_link(struct device *dev, struct device *link) |
Alex Williamson | c61959e | 2014-06-12 16:12:24 -0600 | [diff] [blame] | 619 | { |
| 620 | return -EINVAL; |
| 621 | } |
| 622 | |
Alex Williamson | e09f8ea5 | 2014-07-07 14:31:36 -0600 | [diff] [blame] | 623 | static inline void iommu_device_unlink(struct device *dev, struct device *link) |
Alex Williamson | c61959e | 2014-06-12 16:12:24 -0600 | [diff] [blame] | 624 | { |
| 625 | } |
| 626 | |
Mitchel Humpherys | 8488df2 | 2015-07-09 16:59:02 -0700 | [diff] [blame] | 627 | static inline void iommu_trigger_fault(struct iommu_domain *domain, |
| 628 | unsigned long flags) |
| 629 | { |
| 630 | } |
| 631 | |
Mitchel Humpherys | 3ede5d9 | 2015-08-21 14:06:14 -0700 | [diff] [blame] | 632 | static inline unsigned long iommu_reg_read(struct iommu_domain *domain, |
| 633 | unsigned long offset) |
| 634 | { |
| 635 | return 0; |
| 636 | } |
| 637 | |
| 638 | static inline void iommu_reg_write(struct iommu_domain *domain, |
| 639 | unsigned long val, unsigned long offset) |
| 640 | { |
| 641 | } |
| 642 | |
Mitchel Humpherys | 39bad0c | 2015-12-03 11:17:23 -0800 | [diff] [blame] | 643 | static inline void iommu_tlbiall(struct iommu_domain *domain) |
| 644 | { |
| 645 | } |
| 646 | |
Mitchel Humpherys | 4264f19 | 2015-12-14 16:04:46 -0800 | [diff] [blame] | 647 | static inline int iommu_enable_config_clocks(struct iommu_domain *domain) |
| 648 | { |
| 649 | return 0; |
| 650 | } |
| 651 | |
| 652 | static inline void iommu_disable_config_clocks(struct iommu_domain *domain) |
| 653 | { |
| 654 | } |
| 655 | |
Robin Murphy | 57f98d2 | 2016-09-13 10:54:14 +0100 | [diff] [blame] | 656 | static inline int iommu_fwspec_init(struct device *dev, |
| 657 | struct fwnode_handle *iommu_fwnode, |
| 658 | const struct iommu_ops *ops) |
| 659 | { |
| 660 | return -ENODEV; |
| 661 | } |
| 662 | |
| 663 | static inline void iommu_fwspec_free(struct device *dev) |
| 664 | { |
| 665 | } |
| 666 | |
| 667 | static inline int iommu_fwspec_add_ids(struct device *dev, u32 *ids, |
| 668 | int num_ids) |
| 669 | { |
| 670 | return -ENODEV; |
| 671 | } |
| 672 | |
Runmin Wang | 8cfebef | 2017-04-28 13:59:58 -0700 | [diff] [blame] | 673 | static inline int iommu_fwspec_get_id(struct device *dev, u32 *id) |
Patrick Daly | 1e3c16c | 2017-04-12 17:59:07 -0700 | [diff] [blame] | 674 | { |
| 675 | return -ENODEV; |
| 676 | } |
| 677 | |
Patrick Daly | 958973c | 2017-04-28 19:45:18 -0700 | [diff] [blame] | 678 | static inline int iommu_is_available(struct device *dev) |
| 679 | { |
| 680 | return -ENODEV; |
| 681 | } |
Joerg Roedel | 4a77a6c | 2008-11-26 17:02:33 +0100 | [diff] [blame] | 682 | #endif /* CONFIG_IOMMU_API */ |
| 683 | |
| 684 | #endif /* __LINUX_IOMMU_H */ |