blob: 8f545eadb080360aed741c23dcdcd122f0997832 [file] [log] [blame]
Joerg Roedel4a77a6c2008-11-26 17:02:33 +01001/*
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
Laura Abbott74315cc2011-06-08 17:29:11 -040022#include <linux/errno.h>
Wang YanQing9a08d372013-04-19 09:38:04 +080023#include <linux/err.h>
Will Deacond0f60a42014-08-27 16:15:59 +010024#include <linux/of.h>
Thierry Reding76582d02012-07-25 16:24:49 +020025#include <linux/types.h>
Olav Haugan315786e2014-10-25 09:55:16 -070026#include <linux/scatterlist.h>
Shuah Khan56fa4842013-09-24 15:21:20 -060027#include <trace/events/iommu.h>
Laura Abbott74315cc2011-06-08 17:29:11 -040028
Will Deaconca13bb32013-11-05 15:59:53 +000029#define IOMMU_READ (1 << 0)
30#define IOMMU_WRITE (1 << 1)
31#define IOMMU_CACHE (1 << 2) /* DMA cache coherency */
Antonios Motakisa720b412014-10-13 14:06:16 +010032#define IOMMU_NOEXEC (1 << 3)
Robin Murphy31e68502016-04-05 12:39:30 +010033#define IOMMU_MMIO (1 << 4) /* e.g. things like MSI doorbells */
Joerg Roedel4a77a6c2008-11-26 17:02:33 +010034
Joerg Roedel905d66c2011-09-06 16:03:26 +020035struct iommu_ops;
Alex Williamsond72e31c2012-05-30 14:18:53 -060036struct iommu_group;
Joerg Roedelff217762011-08-26 16:48:26 +020037struct bus_type;
Joerg Roedel4a77a6c2008-11-26 17:02:33 +010038struct device;
Ohad Ben-Cohen4f3f8d92011-09-13 15:25:23 -040039struct iommu_domain;
Joerg Roedelba1eabfa2012-08-03 15:55:41 +020040struct notifier_block;
Ohad Ben-Cohen4f3f8d92011-09-13 15:25:23 -040041
42/* iommu fault flags */
Sushmita Susheelendra5e36b912015-06-02 15:46:24 -060043#define IOMMU_FAULT_READ (1 << 0)
44#define IOMMU_FAULT_WRITE (1 << 1)
45#define IOMMU_FAULT_TRANSLATION (1 << 2)
46#define IOMMU_FAULT_PERMISSION (1 << 3)
Mitchel Humpherys0cc54a22015-08-19 10:57:55 -070047#define IOMMU_FAULT_EXTERNAL (1 << 4)
48#define IOMMU_FAULT_TRANSACTION_STALLED (1 << 5)
Ohad Ben-Cohen4f3f8d92011-09-13 15:25:23 -040049
50typedef int (*iommu_fault_handler_t)(struct iommu_domain *,
Ohad Ben-Cohen77ca2332012-05-21 20:20:05 +030051 struct device *, unsigned long, int, void *);
Joerg Roedel4a77a6c2008-11-26 17:02:33 +010052
Joerg Roedel0ff64f82012-01-26 19:40:53 +010053struct iommu_domain_geometry {
54 dma_addr_t aperture_start; /* First address that can be mapped */
55 dma_addr_t aperture_end; /* Last address that can be mapped */
56 bool force_aperture; /* DMA only allowed in mappable range? */
57};
58
Joerg Roedel8539c7c2015-03-26 13:43:05 +010059/* Domain feature flags */
60#define __IOMMU_DOMAIN_PAGING (1U << 0) /* Support for iommu_map/unmap */
61#define __IOMMU_DOMAIN_DMA_API (1U << 1) /* Domain for use in DMA-API
62 implementation */
63#define __IOMMU_DOMAIN_PT (1U << 2) /* Domain is identity mapped */
64
65/*
66 * This are the possible domain-types
67 *
68 * IOMMU_DOMAIN_BLOCKED - All DMA is blocked, can be used to isolate
69 * devices
70 * IOMMU_DOMAIN_IDENTITY - DMA addresses are system physical addresses
71 * IOMMU_DOMAIN_UNMANAGED - DMA mappings managed by IOMMU-API user, used
72 * for VMs
73 * IOMMU_DOMAIN_DMA - Internally used for DMA-API implementations.
74 * This flag allows IOMMU drivers to implement
75 * certain optimizations for these domains
76 */
77#define IOMMU_DOMAIN_BLOCKED (0U)
78#define IOMMU_DOMAIN_IDENTITY (__IOMMU_DOMAIN_PT)
79#define IOMMU_DOMAIN_UNMANAGED (__IOMMU_DOMAIN_PAGING)
80#define IOMMU_DOMAIN_DMA (__IOMMU_DOMAIN_PAGING | \
81 __IOMMU_DOMAIN_DMA_API)
82
Joerg Roedel4a77a6c2008-11-26 17:02:33 +010083struct iommu_domain {
Joerg Roedel8539c7c2015-03-26 13:43:05 +010084 unsigned type;
Thierry Redingb22f6432014-06-27 09:03:12 +020085 const struct iommu_ops *ops;
Robin Murphyd16e0fa2016-04-07 18:42:06 +010086 unsigned long pgsize_bitmap; /* Bitmap of page sizes in use */
Ohad Ben-Cohen4f3f8d92011-09-13 15:25:23 -040087 iommu_fault_handler_t handler;
Ohad Ben-Cohen77ca2332012-05-21 20:20:05 +030088 void *handler_token;
Joerg Roedel0ff64f82012-01-26 19:40:53 +010089 struct iommu_domain_geometry geometry;
Robin Murphy0db2e5d2015-10-01 20:13:58 +010090 void *iova_cookie;
Joerg Roedel4a77a6c2008-11-26 17:02:33 +010091};
92
Joerg Roedel1aed0742014-09-03 18:34:04 +020093enum iommu_cap {
94 IOMMU_CAP_CACHE_COHERENCY, /* IOMMU can enforce cache coherent DMA
95 transactions */
96 IOMMU_CAP_INTR_REMAP, /* IOMMU supports interrupt isolation */
Antonios Motakisc4986642014-10-13 14:06:17 +010097 IOMMU_CAP_NOEXEC, /* IOMMU_NOEXEC flag */
Joerg Roedel1aed0742014-09-03 18:34:04 +020098};
Sheng Yangdbb9fd82009-03-18 15:33:06 +080099
Varun Sethi7cabf492013-07-15 10:20:56 +0530100/*
101 * Following constraints are specifc to FSL_PAMUV1:
102 * -aperture must be power of 2, and naturally aligned
103 * -number of windows must be power of 2, and address space size
104 * of each window is determined by aperture size / # of windows
105 * -the actual size of the mapped region of a window must be power
106 * of 2 starting with 4KB and physical address must be naturally
107 * aligned.
108 * DOMAIN_ATTR_FSL_PAMUV1 corresponds to the above mentioned contraints.
109 * The caller can invoke iommu_domain_get_attr to check if the underlying
110 * iommu implementation supports these constraints.
111 */
112
Joerg Roedel0cd76dd2012-01-26 19:40:52 +0100113enum iommu_attr {
Joerg Roedel0ff64f82012-01-26 19:40:53 +0100114 DOMAIN_ATTR_GEOMETRY,
Joerg Roedeld2e12162013-01-29 13:49:04 +0100115 DOMAIN_ATTR_PAGING,
Joerg Roedel69356712013-02-04 14:00:01 +0100116 DOMAIN_ATTR_WINDOWS,
Varun Sethi7cabf492013-07-15 10:20:56 +0530117 DOMAIN_ATTR_FSL_PAMU_STASH,
118 DOMAIN_ATTR_FSL_PAMU_ENABLE,
119 DOMAIN_ATTR_FSL_PAMUV1,
Will Deaconc02607a2014-09-29 10:05:06 -0600120 DOMAIN_ATTR_NESTING, /* two stages of translation */
Mitchel Humpherys19f19d52014-11-24 12:31:02 -0800121 DOMAIN_ATTR_PT_BASE_ADDR,
Jeremy Gebbene352bb02015-06-16 10:54:01 -0600122 DOMAIN_ATTR_CONTEXT_BANK,
Joerg Roedela8b8a882013-01-29 14:36:31 +0100123 DOMAIN_ATTR_MAX,
Joerg Roedel0cd76dd2012-01-26 19:40:52 +0100124};
125
Joerg Roedela1015c22015-05-28 18:41:33 +0200126/**
127 * struct iommu_dm_region - descriptor for a direct mapped memory region
128 * @list: Linked list pointers
129 * @start: System physical start address of the region
130 * @length: Length of the region in bytes
131 * @prot: IOMMU Protection flags (READ/WRITE/...)
132 */
133struct iommu_dm_region {
134 struct list_head list;
135 phys_addr_t start;
136 size_t length;
137 int prot;
138};
139
Joerg Roedel39d4ebb2011-09-06 16:48:40 +0200140#ifdef CONFIG_IOMMU_API
141
Ohad Ben-Cohen7d3002c2011-11-10 11:32:26 +0200142/**
143 * struct iommu_ops - iommu ops and capabilities
Magnus Damm0d9bacb2016-01-19 14:28:48 +0900144 * @capable: check capability
145 * @domain_alloc: allocate iommu domain
146 * @domain_free: free iommu domain
Ohad Ben-Cohen7d3002c2011-11-10 11:32:26 +0200147 * @attach_dev: attach device to an iommu domain
148 * @detach_dev: detach device from an iommu domain
149 * @map: map a physically contiguous memory region to an iommu domain
150 * @unmap: unmap a physically contiguous memory region from an iommu domain
Olav Haugan315786e2014-10-25 09:55:16 -0700151 * @map_sg: map a scatter-gather list of physically contiguous memory chunks
152 * to an iommu domain
Ohad Ben-Cohen7d3002c2011-11-10 11:32:26 +0200153 * @iova_to_phys: translate iova to physical address
Mitchel Humpherys36b8c322015-07-06 15:24:22 -0700154 * @iova_to_phys_hard: translate iova to physical address using IOMMU hardware
Alex Williamsond72e31c2012-05-30 14:18:53 -0600155 * @add_device: add device to iommu grouping
156 * @remove_device: remove device from iommu grouping
Magnus Damm0d9bacb2016-01-19 14:28:48 +0900157 * @device_group: find iommu group for a particular device
Joerg Roedel0cd76dd2012-01-26 19:40:52 +0100158 * @domain_get_attr: Query domain attributes
159 * @domain_set_attr: Change domain attributes
Magnus Damm0d9bacb2016-01-19 14:28:48 +0900160 * @get_dm_regions: Request list of direct mapping requirements for a device
161 * @put_dm_regions: Free list of direct mapping requirements for a device
Joerg Roedel33b21a62016-07-05 13:07:53 +0200162 * @apply_dm_region: Temporary helper call-back for iova reserved ranges
Magnus Damm0d9bacb2016-01-19 14:28:48 +0900163 * @domain_window_enable: Configure and enable a particular window for a domain
164 * @domain_window_disable: Disable a particular window for a domain
165 * @domain_set_windows: Set the number of windows for a domain
166 * @domain_get_windows: Return the number of windows for a domain
Will Deacond0f60a42014-08-27 16:15:59 +0100167 * @of_xlate: add OF master IDs to iommu grouping
Robin Murphyd16e0fa2016-04-07 18:42:06 +0100168 * @pgsize_bitmap: bitmap of all possible supported page sizes
Ohad Ben-Cohen7d3002c2011-11-10 11:32:26 +0200169 */
Joerg Roedel4a77a6c2008-11-26 17:02:33 +0100170struct iommu_ops {
Joerg Roedel3c0e0ca2014-09-03 18:47:25 +0200171 bool (*capable)(enum iommu_cap);
Joerg Roedel938c4702015-03-26 13:43:04 +0100172
173 /* Domain allocation and freeing by the iommu driver */
Joerg Roedel8539c7c2015-03-26 13:43:05 +0100174 struct iommu_domain *(*domain_alloc)(unsigned iommu_domain_type);
Joerg Roedel938c4702015-03-26 13:43:04 +0100175 void (*domain_free)(struct iommu_domain *);
176
Joerg Roedel4a77a6c2008-11-26 17:02:33 +0100177 int (*attach_dev)(struct iommu_domain *domain, struct device *dev);
178 void (*detach_dev)(struct iommu_domain *domain, struct device *dev);
Joerg Roedel67651782010-01-21 16:32:27 +0100179 int (*map)(struct iommu_domain *domain, unsigned long iova,
Ohad Ben-Cohen50090652011-11-10 11:32:25 +0200180 phys_addr_t paddr, size_t size, int prot);
181 size_t (*unmap)(struct iommu_domain *domain, unsigned long iova,
182 size_t size);
Olav Haugan315786e2014-10-25 09:55:16 -0700183 size_t (*map_sg)(struct iommu_domain *domain, unsigned long iova,
184 struct scatterlist *sg, unsigned int nents, int prot);
Varun Sethibb5547ac2013-03-29 01:23:58 +0530185 phys_addr_t (*iova_to_phys)(struct iommu_domain *domain, dma_addr_t iova);
Mitchel Humpherys36b8c322015-07-06 15:24:22 -0700186 phys_addr_t (*iova_to_phys_hard)(struct iommu_domain *domain,
187 dma_addr_t iova);
Alex Williamsond72e31c2012-05-30 14:18:53 -0600188 int (*add_device)(struct device *dev);
189 void (*remove_device)(struct device *dev);
Joerg Roedel46c6b2b2015-10-21 23:51:36 +0200190 struct iommu_group *(*device_group)(struct device *dev);
Joerg Roedel0cd76dd2012-01-26 19:40:52 +0100191 int (*domain_get_attr)(struct iommu_domain *domain,
192 enum iommu_attr attr, void *data);
193 int (*domain_set_attr)(struct iommu_domain *domain,
194 enum iommu_attr attr, void *data);
Joerg Roedeld7787d52013-01-29 14:26:20 +0100195
Joerg Roedela1015c22015-05-28 18:41:33 +0200196 /* Request/Free a list of direct mapping requirements for a device */
197 void (*get_dm_regions)(struct device *dev, struct list_head *list);
198 void (*put_dm_regions)(struct device *dev, struct list_head *list);
Joerg Roedel33b21a62016-07-05 13:07:53 +0200199 void (*apply_dm_region)(struct device *dev, struct iommu_domain *domain,
200 struct iommu_dm_region *region);
Joerg Roedela1015c22015-05-28 18:41:33 +0200201
Joerg Roedeld7787d52013-01-29 14:26:20 +0100202 /* Window handling functions */
203 int (*domain_window_enable)(struct iommu_domain *domain, u32 wnd_nr,
Varun Sethi80f97f02013-03-29 01:24:00 +0530204 phys_addr_t paddr, u64 size, int prot);
Joerg Roedeld7787d52013-01-29 14:26:20 +0100205 void (*domain_window_disable)(struct iommu_domain *domain, u32 wnd_nr);
Magnus Damm0d9bacb2016-01-19 14:28:48 +0900206 /* Set the number of windows per domain */
Joerg Roedel69356712013-02-04 14:00:01 +0100207 int (*domain_set_windows)(struct iommu_domain *domain, u32 w_count);
Magnus Damm0d9bacb2016-01-19 14:28:48 +0900208 /* Get the number of windows per domain */
Joerg Roedel69356712013-02-04 14:00:01 +0100209 u32 (*domain_get_windows)(struct iommu_domain *domain);
Joerg Roedeld7787d52013-01-29 14:26:20 +0100210
Will Deacond0f60a42014-08-27 16:15:59 +0100211 int (*of_xlate)(struct device *dev, struct of_phandle_args *args);
Will Deacond0f60a42014-08-27 16:15:59 +0100212
Ohad Ben-Cohen7d3002c2011-11-10 11:32:26 +0200213 unsigned long pgsize_bitmap;
Joerg Roedel4a77a6c2008-11-26 17:02:33 +0100214};
215
Alex Williamsond72e31c2012-05-30 14:18:53 -0600216#define IOMMU_GROUP_NOTIFY_ADD_DEVICE 1 /* Device added */
217#define IOMMU_GROUP_NOTIFY_DEL_DEVICE 2 /* Pre Device removed */
218#define IOMMU_GROUP_NOTIFY_BIND_DRIVER 3 /* Pre Driver bind */
219#define IOMMU_GROUP_NOTIFY_BOUND_DRIVER 4 /* Post Driver bind */
220#define IOMMU_GROUP_NOTIFY_UNBIND_DRIVER 5 /* Pre Driver unbind */
221#define IOMMU_GROUP_NOTIFY_UNBOUND_DRIVER 6 /* Post Driver unbind */
222
Thierry Redingb22f6432014-06-27 09:03:12 +0200223extern int bus_set_iommu(struct bus_type *bus, const struct iommu_ops *ops);
Joerg Roedela1b60c12011-09-06 18:46:34 +0200224extern bool iommu_present(struct bus_type *bus);
Joerg Roedel3c0e0ca2014-09-03 18:47:25 +0200225extern bool iommu_capable(struct bus_type *bus, enum iommu_cap cap);
Joerg Roedel905d66c2011-09-06 16:03:26 +0200226extern struct iommu_domain *iommu_domain_alloc(struct bus_type *bus);
Alexey Kardashevskiyaa16bea2013-03-25 10:23:49 +1100227extern struct iommu_group *iommu_group_get_by_id(int id);
Joerg Roedel4a77a6c2008-11-26 17:02:33 +0100228extern void iommu_domain_free(struct iommu_domain *domain);
229extern int iommu_attach_device(struct iommu_domain *domain,
230 struct device *dev);
231extern void iommu_detach_device(struct iommu_domain *domain,
232 struct device *dev);
Joerg Roedel2c1296d2015-05-28 18:41:32 +0200233extern struct iommu_domain *iommu_get_domain_for_dev(struct device *dev);
Joerg Roedelcefc53c2010-01-08 13:35:09 +0100234extern int iommu_map(struct iommu_domain *domain, unsigned long iova,
Ohad Ben-Cohen7d3002c2011-11-10 11:32:26 +0200235 phys_addr_t paddr, size_t size, int prot);
236extern size_t iommu_unmap(struct iommu_domain *domain, unsigned long iova,
237 size_t size);
Olav Haugan315786e2014-10-25 09:55:16 -0700238extern size_t default_iommu_map_sg(struct iommu_domain *domain, unsigned long iova,
239 struct scatterlist *sg,unsigned int nents,
240 int prot);
Varun Sethibb5547ac2013-03-29 01:23:58 +0530241extern phys_addr_t iommu_iova_to_phys(struct iommu_domain *domain, dma_addr_t iova);
Mitchel Humpherys36b8c322015-07-06 15:24:22 -0700242extern phys_addr_t iommu_iova_to_phys_hard(struct iommu_domain *domain,
243 dma_addr_t iova);
Ohad Ben-Cohen4f3f8d92011-09-13 15:25:23 -0400244extern void iommu_set_fault_handler(struct iommu_domain *domain,
Ohad Ben-Cohen77ca2332012-05-21 20:20:05 +0300245 iommu_fault_handler_t handler, void *token);
Alex Williamsond72e31c2012-05-30 14:18:53 -0600246
Joerg Roedela1015c22015-05-28 18:41:33 +0200247extern void iommu_get_dm_regions(struct device *dev, struct list_head *list);
248extern void iommu_put_dm_regions(struct device *dev, struct list_head *list);
Joerg Roedeld290f1e2015-05-28 18:41:36 +0200249extern int iommu_request_dm_for_dev(struct device *dev);
Joerg Roedela1015c22015-05-28 18:41:33 +0200250
Alex Williamsond72e31c2012-05-30 14:18:53 -0600251extern int iommu_attach_group(struct iommu_domain *domain,
252 struct iommu_group *group);
253extern void iommu_detach_group(struct iommu_domain *domain,
254 struct iommu_group *group);
255extern struct iommu_group *iommu_group_alloc(void);
256extern void *iommu_group_get_iommudata(struct iommu_group *group);
257extern void iommu_group_set_iommudata(struct iommu_group *group,
258 void *iommu_data,
259 void (*release)(void *iommu_data));
260extern int iommu_group_set_name(struct iommu_group *group, const char *name);
261extern int iommu_group_add_device(struct iommu_group *group,
262 struct device *dev);
263extern void iommu_group_remove_device(struct device *dev);
264extern int iommu_group_for_each_dev(struct iommu_group *group, void *data,
265 int (*fn)(struct device *, void *));
266extern struct iommu_group *iommu_group_get(struct device *dev);
267extern void iommu_group_put(struct iommu_group *group);
268extern int iommu_group_register_notifier(struct iommu_group *group,
269 struct notifier_block *nb);
270extern int iommu_group_unregister_notifier(struct iommu_group *group,
271 struct notifier_block *nb);
272extern int iommu_group_id(struct iommu_group *group);
Alex Williamson104a1c12014-07-03 09:51:18 -0600273extern struct iommu_group *iommu_group_get_for_dev(struct device *dev);
Joerg Roedel6827ca82015-05-28 18:41:35 +0200274extern struct iommu_domain *iommu_group_default_domain(struct iommu_group *);
Ohad Ben-Cohen4f3f8d92011-09-13 15:25:23 -0400275
Joerg Roedel0cd76dd2012-01-26 19:40:52 +0100276extern int iommu_domain_get_attr(struct iommu_domain *domain, enum iommu_attr,
277 void *data);
278extern int iommu_domain_set_attr(struct iommu_domain *domain, enum iommu_attr,
279 void *data);
Alex Williamsonc61959e2014-06-12 16:12:24 -0600280struct device *iommu_device_create(struct device *parent, void *drvdata,
281 const struct attribute_group **groups,
Nicolas Iooss8db14862015-07-17 16:23:42 -0700282 const char *fmt, ...) __printf(4, 5);
Alex Williamsonc61959e2014-06-12 16:12:24 -0600283void iommu_device_destroy(struct device *dev);
284int iommu_device_link(struct device *dev, struct device *link);
285void iommu_device_unlink(struct device *dev, struct device *link);
Ohad Ben-Cohen4f3f8d92011-09-13 15:25:23 -0400286
Joerg Roedeld7787d52013-01-29 14:26:20 +0100287/* Window handling function prototypes */
288extern int iommu_domain_window_enable(struct iommu_domain *domain, u32 wnd_nr,
Varun Sethi80f97f02013-03-29 01:24:00 +0530289 phys_addr_t offset, u64 size,
290 int prot);
Joerg Roedeld7787d52013-01-29 14:26:20 +0100291extern void iommu_domain_window_disable(struct iommu_domain *domain, u32 wnd_nr);
Ohad Ben-Cohen4f3f8d92011-09-13 15:25:23 -0400292/**
293 * report_iommu_fault() - report about an IOMMU fault to the IOMMU framework
294 * @domain: the iommu domain where the fault has happened
295 * @dev: the device where the fault has happened
296 * @iova: the faulting address
297 * @flags: mmu fault flags (e.g. IOMMU_FAULT_READ/IOMMU_FAULT_WRITE/...)
298 *
299 * This function should be called by the low-level IOMMU implementations
300 * whenever IOMMU faults happen, to allow high-level users, that are
301 * interested in such events, to know about them.
302 *
303 * This event may be useful for several possible use cases:
304 * - mere logging of the event
305 * - dynamic TLB/PTE loading
306 * - if restarting of the faulting device is required
307 *
308 * Returns 0 on success and an appropriate error code otherwise (if dynamic
309 * PTE/TLB loading will one day be supported, implementations will be able
310 * to tell whether it succeeded or not according to this return value).
Ohad Ben-Cohen0ed6d2d2011-09-27 07:36:40 -0400311 *
312 * Specifically, -ENOSYS is returned if a fault handler isn't installed
313 * (though fault handlers can also return -ENOSYS, in case they want to
314 * elicit the default behavior of the IOMMU drivers).
Sushmita Susheelendra5e36b912015-06-02 15:46:24 -0600315
316 * Client fault handler returns -EBUSY to signal to the IOMMU driver
317 * that the client will take responsibility for any further fault
318 * handling, including clearing fault status registers or retrying
319 * the faulting transaction.
Ohad Ben-Cohen4f3f8d92011-09-13 15:25:23 -0400320 */
321static inline int report_iommu_fault(struct iommu_domain *domain,
322 struct device *dev, unsigned long iova, int flags)
323{
Ohad Ben-Cohen0ed6d2d2011-09-27 07:36:40 -0400324 int ret = -ENOSYS;
Ohad Ben-Cohen4f3f8d92011-09-13 15:25:23 -0400325
326 /*
327 * if upper layers showed interest and installed a fault handler,
328 * invoke it.
329 */
330 if (domain->handler)
Ohad Ben-Cohen77ca2332012-05-21 20:20:05 +0300331 ret = domain->handler(domain, dev, iova, flags,
332 domain->handler_token);
Ohad Ben-Cohen4f3f8d92011-09-13 15:25:23 -0400333
Shuah Khan56fa4842013-09-24 15:21:20 -0600334 trace_io_page_fault(dev, iova, flags);
Ohad Ben-Cohen4f3f8d92011-09-13 15:25:23 -0400335 return ret;
336}
Joerg Roedel4a77a6c2008-11-26 17:02:33 +0100337
Olav Haugan315786e2014-10-25 09:55:16 -0700338static inline size_t iommu_map_sg(struct iommu_domain *domain,
339 unsigned long iova, struct scatterlist *sg,
340 unsigned int nents, int prot)
341{
342 return domain->ops->map_sg(domain, iova, sg, nents, prot);
343}
344
Joerg Roedel5e622922015-10-21 23:51:37 +0200345/* PCI device grouping function */
346extern struct iommu_group *pci_device_group(struct device *dev);
Joerg Roedel6eab5562015-10-21 23:51:38 +0200347/* Generic device grouping function */
348extern struct iommu_group *generic_device_group(struct device *dev);
Joerg Roedel5e622922015-10-21 23:51:37 +0200349
Joerg Roedel4a77a6c2008-11-26 17:02:33 +0100350#else /* CONFIG_IOMMU_API */
351
Joerg Roedel39d4ebb2011-09-06 16:48:40 +0200352struct iommu_ops {};
Alex Williamsond72e31c2012-05-30 14:18:53 -0600353struct iommu_group {};
Joerg Roedel4a77a6c2008-11-26 17:02:33 +0100354
Joerg Roedela1b60c12011-09-06 18:46:34 +0200355static inline bool iommu_present(struct bus_type *bus)
Joerg Roedel4a77a6c2008-11-26 17:02:33 +0100356{
357 return false;
358}
359
Joerg Roedel3c0e0ca2014-09-03 18:47:25 +0200360static inline bool iommu_capable(struct bus_type *bus, enum iommu_cap cap)
361{
362 return false;
363}
364
Joerg Roedel905d66c2011-09-06 16:03:26 +0200365static inline struct iommu_domain *iommu_domain_alloc(struct bus_type *bus)
Joerg Roedel4a77a6c2008-11-26 17:02:33 +0100366{
367 return NULL;
368}
369
Alexey Kardashevskiyb62dfd22013-11-21 17:41:14 +1100370static inline struct iommu_group *iommu_group_get_by_id(int id)
371{
372 return NULL;
373}
374
Joerg Roedel4a77a6c2008-11-26 17:02:33 +0100375static inline void iommu_domain_free(struct iommu_domain *domain)
376{
377}
378
379static inline int iommu_attach_device(struct iommu_domain *domain,
380 struct device *dev)
381{
382 return -ENODEV;
383}
384
385static inline void iommu_detach_device(struct iommu_domain *domain,
386 struct device *dev)
387{
388}
389
Joerg Roedel2c1296d2015-05-28 18:41:32 +0200390static inline struct iommu_domain *iommu_get_domain_for_dev(struct device *dev)
391{
392 return NULL;
393}
394
Joerg Roedelcefc53c2010-01-08 13:35:09 +0100395static inline int iommu_map(struct iommu_domain *domain, unsigned long iova,
396 phys_addr_t paddr, int gfp_order, int prot)
397{
398 return -ENODEV;
399}
400
401static inline int iommu_unmap(struct iommu_domain *domain, unsigned long iova,
402 int gfp_order)
403{
404 return -ENODEV;
405}
406
Olav Haugan315786e2014-10-25 09:55:16 -0700407static inline size_t iommu_map_sg(struct iommu_domain *domain,
408 unsigned long iova, struct scatterlist *sg,
409 unsigned int nents, int prot)
410{
411 return -ENODEV;
412}
413
Joerg Roedeld7787d52013-01-29 14:26:20 +0100414static inline int iommu_domain_window_enable(struct iommu_domain *domain,
415 u32 wnd_nr, phys_addr_t paddr,
Varun Sethi80f97f02013-03-29 01:24:00 +0530416 u64 size, int prot)
Joerg Roedeld7787d52013-01-29 14:26:20 +0100417{
418 return -ENODEV;
419}
420
421static inline void iommu_domain_window_disable(struct iommu_domain *domain,
422 u32 wnd_nr)
423{
424}
425
Varun Sethibb5547ac2013-03-29 01:23:58 +0530426static inline phys_addr_t iommu_iova_to_phys(struct iommu_domain *domain, dma_addr_t iova)
Joerg Roedel4a77a6c2008-11-26 17:02:33 +0100427{
428 return 0;
429}
430
Mitchel Humpherys36b8c322015-07-06 15:24:22 -0700431static inline phys_addr_t iommu_iova_to_phys_hard(struct iommu_domain *domain,
432 dma_addr_t iova)
433{
434 return 0;
435}
436
Ohad Ben-Cohen4f3f8d92011-09-13 15:25:23 -0400437static inline void iommu_set_fault_handler(struct iommu_domain *domain,
Ohad Ben-Cohen77ca2332012-05-21 20:20:05 +0300438 iommu_fault_handler_t handler, void *token)
Ohad Ben-Cohen4f3f8d92011-09-13 15:25:23 -0400439{
440}
441
Joerg Roedela1015c22015-05-28 18:41:33 +0200442static inline void iommu_get_dm_regions(struct device *dev,
443 struct list_head *list)
444{
445}
446
447static inline void iommu_put_dm_regions(struct device *dev,
448 struct list_head *list)
449{
450}
451
Joerg Roedeld290f1e2015-05-28 18:41:36 +0200452static inline int iommu_request_dm_for_dev(struct device *dev)
453{
454 return -ENODEV;
455}
456
Alex Williamsonbef83de2012-09-24 21:23:25 -0600457static inline int iommu_attach_group(struct iommu_domain *domain,
458 struct iommu_group *group)
Alex Williamson14604322011-10-21 15:56:05 -0400459{
460 return -ENODEV;
461}
462
Alex Williamsonbef83de2012-09-24 21:23:25 -0600463static inline void iommu_detach_group(struct iommu_domain *domain,
464 struct iommu_group *group)
Alex Williamsond72e31c2012-05-30 14:18:53 -0600465{
466}
467
Alex Williamsonbef83de2012-09-24 21:23:25 -0600468static inline struct iommu_group *iommu_group_alloc(void)
Alex Williamsond72e31c2012-05-30 14:18:53 -0600469{
470 return ERR_PTR(-ENODEV);
471}
472
Alex Williamsonbef83de2012-09-24 21:23:25 -0600473static inline void *iommu_group_get_iommudata(struct iommu_group *group)
Alex Williamsond72e31c2012-05-30 14:18:53 -0600474{
475 return NULL;
476}
477
Alex Williamsonbef83de2012-09-24 21:23:25 -0600478static inline void iommu_group_set_iommudata(struct iommu_group *group,
479 void *iommu_data,
480 void (*release)(void *iommu_data))
Alex Williamsond72e31c2012-05-30 14:18:53 -0600481{
482}
483
Alex Williamsonbef83de2012-09-24 21:23:25 -0600484static inline int iommu_group_set_name(struct iommu_group *group,
485 const char *name)
Alex Williamsond72e31c2012-05-30 14:18:53 -0600486{
487 return -ENODEV;
488}
489
Alex Williamsonbef83de2012-09-24 21:23:25 -0600490static inline int iommu_group_add_device(struct iommu_group *group,
491 struct device *dev)
Alex Williamsond72e31c2012-05-30 14:18:53 -0600492{
493 return -ENODEV;
494}
495
Alex Williamsonbef83de2012-09-24 21:23:25 -0600496static inline void iommu_group_remove_device(struct device *dev)
Alex Williamsond72e31c2012-05-30 14:18:53 -0600497{
498}
499
Alex Williamsonbef83de2012-09-24 21:23:25 -0600500static inline int iommu_group_for_each_dev(struct iommu_group *group,
501 void *data,
502 int (*fn)(struct device *, void *))
Alex Williamsond72e31c2012-05-30 14:18:53 -0600503{
504 return -ENODEV;
505}
506
Alex Williamsonbef83de2012-09-24 21:23:25 -0600507static inline struct iommu_group *iommu_group_get(struct device *dev)
Alex Williamsond72e31c2012-05-30 14:18:53 -0600508{
509 return NULL;
510}
511
Alex Williamsonbef83de2012-09-24 21:23:25 -0600512static inline void iommu_group_put(struct iommu_group *group)
Alex Williamsond72e31c2012-05-30 14:18:53 -0600513{
514}
515
Alex Williamsonbef83de2012-09-24 21:23:25 -0600516static inline int iommu_group_register_notifier(struct iommu_group *group,
517 struct notifier_block *nb)
Alex Williamsond72e31c2012-05-30 14:18:53 -0600518{
519 return -ENODEV;
520}
521
Alex Williamsonbef83de2012-09-24 21:23:25 -0600522static inline int iommu_group_unregister_notifier(struct iommu_group *group,
523 struct notifier_block *nb)
Alex Williamsond72e31c2012-05-30 14:18:53 -0600524{
525 return 0;
526}
527
Alex Williamsonbef83de2012-09-24 21:23:25 -0600528static inline int iommu_group_id(struct iommu_group *group)
Alex Williamsond72e31c2012-05-30 14:18:53 -0600529{
530 return -ENODEV;
531}
Joerg Roedel4a77a6c2008-11-26 17:02:33 +0100532
Joerg Roedel0cd76dd2012-01-26 19:40:52 +0100533static inline int iommu_domain_get_attr(struct iommu_domain *domain,
534 enum iommu_attr attr, void *data)
535{
536 return -EINVAL;
537}
538
539static inline int iommu_domain_set_attr(struct iommu_domain *domain,
540 enum iommu_attr attr, void *data)
541{
542 return -EINVAL;
543}
544
Alex Williamsone09f8ea52014-07-07 14:31:36 -0600545static inline struct device *iommu_device_create(struct device *parent,
546 void *drvdata,
547 const struct attribute_group **groups,
548 const char *fmt, ...)
Alex Williamsonc61959e2014-06-12 16:12:24 -0600549{
550 return ERR_PTR(-ENODEV);
551}
552
Alex Williamsone09f8ea52014-07-07 14:31:36 -0600553static inline void iommu_device_destroy(struct device *dev)
Alex Williamsonc61959e2014-06-12 16:12:24 -0600554{
555}
556
Alex Williamsone09f8ea52014-07-07 14:31:36 -0600557static inline int iommu_device_link(struct device *dev, struct device *link)
Alex Williamsonc61959e2014-06-12 16:12:24 -0600558{
559 return -EINVAL;
560}
561
Alex Williamsone09f8ea52014-07-07 14:31:36 -0600562static inline void iommu_device_unlink(struct device *dev, struct device *link)
Alex Williamsonc61959e2014-06-12 16:12:24 -0600563{
564}
565
Joerg Roedel4a77a6c2008-11-26 17:02:33 +0100566#endif /* CONFIG_IOMMU_API */
567
568#endif /* __LINUX_IOMMU_H */