• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 /* SPDX-License-Identifier: GPL-2.0-only */
2 /*
3  * Copyright (C) 2007-2008 Advanced Micro Devices, Inc.
4  * Author: Joerg Roedel <joerg.roedel@amd.com>
5  */
6 
7 #ifndef __LINUX_IOMMU_H
8 #define __LINUX_IOMMU_H
9 
10 #include <linux/scatterlist.h>
11 #include <linux/device.h>
12 #include <linux/types.h>
13 #include <linux/errno.h>
14 #include <linux/err.h>
15 #include <linux/of.h>
16 #include <linux/ioasid.h>
17 #include <uapi/linux/iommu.h>
18 
19 #define IOMMU_READ	(1 << 0)
20 #define IOMMU_WRITE	(1 << 1)
21 #define IOMMU_CACHE	(1 << 2) /* DMA cache coherency */
22 #define IOMMU_NOEXEC	(1 << 3)
23 #define IOMMU_MMIO	(1 << 4) /* e.g. things like MSI doorbells */
24 /*
25  * Where the bus hardware includes a privilege level as part of its access type
26  * markings, and certain devices are capable of issuing transactions marked as
27  * either 'supervisor' or 'user', the IOMMU_PRIV flag requests that the other
28  * given permission flags only apply to accesses at the higher privilege level,
29  * and that unprivileged transactions should have as little access as possible.
30  * This would usually imply the same permissions as kernel mappings on the CPU,
31  * if the IOMMU page table format is equivalent.
32  */
33 #define IOMMU_PRIV	(1 << 5)
34 /*
35  * Allow caching in a transparent outer level of cache, also known as
36  * the last-level or system cache, with a read/write allocation policy.
37  * Does not depend on IOMMU_CACHE. Incompatible with IOMMU_SYS_CACHE_NWA.
38  */
39 #define IOMMU_SYS_CACHE	(1 << 6)
40 /*
41  * Allow caching in a transparent outer level of cache, also known as
42  * the last-level or system cache, with a read allocation policy.
43  * Does not depend on IOMMU_CACHE. Incompatible with IOMMU_SYS_CACHE.
44  */
45 #define IOMMU_SYS_CACHE_NWA (1 << 7)
46 
47 struct iommu_ops;
48 struct iommu_group;
49 struct bus_type;
50 struct device;
51 struct iommu_domain;
52 struct notifier_block;
53 struct iommu_sva;
54 struct iommu_fault_event;
55 
56 /* iommu fault flags */
57 #define IOMMU_FAULT_READ	0x0
58 #define IOMMU_FAULT_WRITE	0x1
59 
60 typedef int (*iommu_fault_handler_t)(struct iommu_domain *,
61 			struct device *, unsigned long, int, void *);
62 typedef int (*iommu_dev_fault_handler_t)(struct iommu_fault *, void *);
63 
64 struct iommu_domain_geometry {
65 	dma_addr_t aperture_start; /* First address that can be mapped    */
66 	dma_addr_t aperture_end;   /* Last address that can be mapped     */
67 	bool force_aperture;       /* DMA only allowed in mappable range? */
68 };
69 
70 /* Domain feature flags */
71 #define __IOMMU_DOMAIN_PAGING	(1U << 0)  /* Support for iommu_map/unmap */
72 #define __IOMMU_DOMAIN_DMA_API	(1U << 1)  /* Domain for use in DMA-API
73 					      implementation              */
74 #define __IOMMU_DOMAIN_PT	(1U << 2)  /* Domain is identity mapped   */
75 
76 /*
77  * This are the possible domain-types
78  *
79  *	IOMMU_DOMAIN_BLOCKED	- All DMA is blocked, can be used to isolate
80  *				  devices
81  *	IOMMU_DOMAIN_IDENTITY	- DMA addresses are system physical addresses
82  *	IOMMU_DOMAIN_UNMANAGED	- DMA mappings managed by IOMMU-API user, used
83  *				  for VMs
84  *	IOMMU_DOMAIN_DMA	- Internally used for DMA-API implementations.
85  *				  This flag allows IOMMU drivers to implement
86  *				  certain optimizations for these domains
87  */
88 #define IOMMU_DOMAIN_BLOCKED	(0U)
89 #define IOMMU_DOMAIN_IDENTITY	(__IOMMU_DOMAIN_PT)
90 #define IOMMU_DOMAIN_UNMANAGED	(__IOMMU_DOMAIN_PAGING)
91 #define IOMMU_DOMAIN_DMA	(__IOMMU_DOMAIN_PAGING |	\
92 				 __IOMMU_DOMAIN_DMA_API)
93 
94 struct iommu_domain {
95 	unsigned type;
96 	const struct iommu_ops *ops;
97 	unsigned long pgsize_bitmap;	/* Bitmap of page sizes in use */
98 	iommu_fault_handler_t handler;
99 	void *handler_token;
100 	struct iommu_domain_geometry geometry;
101 	void *iova_cookie;
102 };
103 
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 */
108 	IOMMU_CAP_NOEXEC,		/* IOMMU_NOEXEC flag */
109 };
110 
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 
124 enum iommu_attr {
125 	DOMAIN_ATTR_GEOMETRY,
126 	DOMAIN_ATTR_PAGING,
127 	DOMAIN_ATTR_WINDOWS,
128 	DOMAIN_ATTR_FSL_PAMU_STASH,
129 	DOMAIN_ATTR_FSL_PAMU_ENABLE,
130 	DOMAIN_ATTR_FSL_PAMUV1,
131 	DOMAIN_ATTR_NESTING,	/* two stages of translation */
132 	DOMAIN_ATTR_DMA_USE_FLUSH_QUEUE,
133 	DOMAIN_ATTR_MAX,
134 };
135 
136 /* These are the possible reserved region types */
137 enum iommu_resv_type {
138 	/* Memory regions which must be mapped 1:1 at all times */
139 	IOMMU_RESV_DIRECT,
140 	/*
141 	 * Memory regions which are advertised to be 1:1 but are
142 	 * commonly considered relaxable in some conditions,
143 	 * for instance in device assignment use case (USB, Graphics)
144 	 */
145 	IOMMU_RESV_DIRECT_RELAXABLE,
146 	/* Arbitrary "never map this or give it to a device" address ranges */
147 	IOMMU_RESV_RESERVED,
148 	/* Hardware MSI region (untranslated) */
149 	IOMMU_RESV_MSI,
150 	/* Software-managed MSI translation window */
151 	IOMMU_RESV_SW_MSI,
152 };
153 
154 /**
155  * struct iommu_resv_region - descriptor for a reserved memory region
156  * @list: Linked list pointers
157  * @start: System physical start address of the region
158  * @length: Length of the region in bytes
159  * @prot: IOMMU Protection flags (READ/WRITE/...)
160  * @type: Type of the reserved region
161  */
162 struct iommu_resv_region {
163 	struct list_head	list;
164 	phys_addr_t		start;
165 	size_t			length;
166 	int			prot;
167 	enum iommu_resv_type	type;
168 };
169 
170 /* Per device IOMMU features */
171 enum iommu_dev_features {
172 	IOMMU_DEV_FEAT_AUX,	/* Aux-domain feature */
173 	IOMMU_DEV_FEAT_SVA,	/* Shared Virtual Addresses */
174 };
175 
176 #define IOMMU_PASID_INVALID	(-1U)
177 
178 #ifdef CONFIG_IOMMU_API
179 
180 /**
181  * struct iommu_iotlb_gather - Range information for a pending IOTLB flush
182  *
183  * @start: IOVA representing the start of the range to be flushed
184  * @end: IOVA representing the end of the range to be flushed (inclusive)
185  * @pgsize: The interval at which to perform the flush
186  *
187  * This structure is intended to be updated by multiple calls to the
188  * ->unmap() function in struct iommu_ops before eventually being passed
189  * into ->iotlb_sync().
190  */
191 struct iommu_iotlb_gather {
192 	unsigned long		start;
193 	unsigned long		end;
194 	size_t			pgsize;
195 };
196 
197 /**
198  * struct iommu_ops - iommu ops and capabilities
199  * @capable: check capability
200  * @domain_alloc: allocate iommu domain
201  * @domain_free: free iommu domain
202  * @attach_dev: attach device to an iommu domain
203  * @detach_dev: detach device from an iommu domain
204  * @map: map a physically contiguous memory region to an iommu domain
205  * @map_pages: map a physically contiguous set of pages of the same size to
206  *             an iommu domain.
207  * @map_sg: map a scatter-gather list of physically contiguous chunks to
208  *          an iommu domain.
209  * @unmap: unmap a physically contiguous memory region from an iommu domain
210  * @unmap_pages: unmap a number of pages of the same size from an iommu domain
211  * @flush_iotlb_all: Synchronously flush all hardware TLBs for this domain
212  * @iotlb_sync_map: Sync mappings created recently using @map to the hardware
213  * @iotlb_sync: Flush all queued ranges from the hardware TLBs and empty flush
214  *            queue
215  * @iova_to_phys: translate iova to physical address
216  * @probe_device: Add device to iommu driver handling
217  * @release_device: Remove device from iommu driver handling
218  * @probe_finalize: Do final setup work after the device is added to an IOMMU
219  *                  group and attached to the groups domain
220  * @device_group: find iommu group for a particular device
221  * @domain_get_attr: Query domain attributes
222  * @domain_set_attr: Change domain attributes
223  * @get_resv_regions: Request list of reserved regions for a device
224  * @put_resv_regions: Free list of reserved regions for a device
225  * @apply_resv_region: Temporary helper call-back for iova reserved ranges
226  * @domain_window_enable: Configure and enable a particular window for a domain
227  * @domain_window_disable: Disable a particular window for a domain
228  * @of_xlate: add OF master IDs to iommu grouping
229  * @is_attach_deferred: Check if domain attach should be deferred from iommu
230  *                      driver init to device driver init (default no)
231  * @dev_has/enable/disable_feat: per device entries to check/enable/disable
232  *                               iommu specific features.
233  * @dev_feat_enabled: check enabled feature
234  * @aux_attach/detach_dev: aux-domain specific attach/detach entries.
235  * @aux_get_pasid: get the pasid given an aux-domain
236  * @sva_bind: Bind process address space to device
237  * @sva_unbind: Unbind process address space from device
238  * @sva_get_pasid: Get PASID associated to a SVA handle
239  * @page_response: handle page request response
240  * @cache_invalidate: invalidate translation caches
241  * @sva_bind_gpasid: bind guest pasid and mm
242  * @sva_unbind_gpasid: unbind guest pasid and mm
243  * @def_domain_type: device default domain type, return value:
244  *		- IOMMU_DOMAIN_IDENTITY: must use an identity domain
245  *		- IOMMU_DOMAIN_DMA: must use a dma domain
246  *		- 0: use the default setting
247  * @pgsize_bitmap: bitmap of all possible supported page sizes
248  * @owner: Driver module providing these ops
249  */
250 struct iommu_ops {
251 	bool (*capable)(enum iommu_cap);
252 
253 	/* Domain allocation and freeing by the iommu driver */
254 	struct iommu_domain *(*domain_alloc)(unsigned iommu_domain_type);
255 	void (*domain_free)(struct iommu_domain *);
256 
257 	int (*attach_dev)(struct iommu_domain *domain, struct device *dev);
258 	void (*detach_dev)(struct iommu_domain *domain, struct device *dev);
259 	int (*map)(struct iommu_domain *domain, unsigned long iova,
260 		   phys_addr_t paddr, size_t size, int prot, gfp_t gfp);
261 	int (*map_pages)(struct iommu_domain *domain, unsigned long iova,
262 			 phys_addr_t paddr, size_t pgsize, size_t pgcount,
263 			 int prot, gfp_t gfp, size_t *mapped);
264 	int (*map_sg)(struct iommu_domain *domain, unsigned long iova,
265 		      struct scatterlist *sg, unsigned int nents, int prot,
266 		      gfp_t gfp, size_t *mapped);
267 	size_t (*unmap)(struct iommu_domain *domain, unsigned long iova,
268 		     size_t size, struct iommu_iotlb_gather *iotlb_gather);
269 	size_t (*unmap_pages)(struct iommu_domain *domain, unsigned long iova,
270 			      size_t pgsize, size_t pgcount,
271 			      struct iommu_iotlb_gather *iotlb_gather);
272 	void (*flush_iotlb_all)(struct iommu_domain *domain);
273 	void (*iotlb_sync_map)(struct iommu_domain *domain, unsigned long iova,
274 			       size_t size);
275 	void (*iotlb_sync)(struct iommu_domain *domain,
276 			   struct iommu_iotlb_gather *iotlb_gather);
277 	phys_addr_t (*iova_to_phys)(struct iommu_domain *domain, dma_addr_t iova);
278 	struct iommu_device *(*probe_device)(struct device *dev);
279 	void (*release_device)(struct device *dev);
280 	void (*probe_finalize)(struct device *dev);
281 	struct iommu_group *(*device_group)(struct device *dev);
282 	int (*domain_get_attr)(struct iommu_domain *domain,
283 			       enum iommu_attr attr, void *data);
284 	int (*domain_set_attr)(struct iommu_domain *domain,
285 			       enum iommu_attr attr, void *data);
286 
287 	/* Request/Free a list of reserved regions for a device */
288 	void (*get_resv_regions)(struct device *dev, struct list_head *list);
289 	void (*put_resv_regions)(struct device *dev, struct list_head *list);
290 	void (*apply_resv_region)(struct device *dev,
291 				  struct iommu_domain *domain,
292 				  struct iommu_resv_region *region);
293 
294 	/* Window handling functions */
295 	int (*domain_window_enable)(struct iommu_domain *domain, u32 wnd_nr,
296 				    phys_addr_t paddr, u64 size, int prot);
297 	void (*domain_window_disable)(struct iommu_domain *domain, u32 wnd_nr);
298 
299 	int (*of_xlate)(struct device *dev, struct of_phandle_args *args);
300 	bool (*is_attach_deferred)(struct iommu_domain *domain, struct device *dev);
301 
302 	/* Per device IOMMU features */
303 	bool (*dev_has_feat)(struct device *dev, enum iommu_dev_features f);
304 	bool (*dev_feat_enabled)(struct device *dev, enum iommu_dev_features f);
305 	int (*dev_enable_feat)(struct device *dev, enum iommu_dev_features f);
306 	int (*dev_disable_feat)(struct device *dev, enum iommu_dev_features f);
307 
308 	/* Aux-domain specific attach/detach entries */
309 	int (*aux_attach_dev)(struct iommu_domain *domain, struct device *dev);
310 	void (*aux_detach_dev)(struct iommu_domain *domain, struct device *dev);
311 	int (*aux_get_pasid)(struct iommu_domain *domain, struct device *dev);
312 
313 	struct iommu_sva *(*sva_bind)(struct device *dev, struct mm_struct *mm,
314 				      void *drvdata);
315 	void (*sva_unbind)(struct iommu_sva *handle);
316 	u32 (*sva_get_pasid)(struct iommu_sva *handle);
317 
318 	int (*page_response)(struct device *dev,
319 			     struct iommu_fault_event *evt,
320 			     struct iommu_page_response *msg);
321 	int (*cache_invalidate)(struct iommu_domain *domain, struct device *dev,
322 				struct iommu_cache_invalidate_info *inv_info);
323 	int (*sva_bind_gpasid)(struct iommu_domain *domain,
324 			struct device *dev, struct iommu_gpasid_bind_data *data);
325 
326 	int (*sva_unbind_gpasid)(struct device *dev, u32 pasid);
327 
328 	int (*def_domain_type)(struct device *dev);
329 
330 	unsigned long pgsize_bitmap;
331 	struct module *owner;
332 };
333 
334 /**
335  * struct iommu_device - IOMMU core representation of one IOMMU hardware
336  *			 instance
337  * @list: Used by the iommu-core to keep a list of registered iommus
338  * @ops: iommu-ops for talking to this iommu
339  * @dev: struct device for sysfs handling
340  */
341 struct iommu_device {
342 	struct list_head list;
343 	const struct iommu_ops *ops;
344 	struct fwnode_handle *fwnode;
345 	struct device *dev;
346 };
347 
348 /**
349  * struct iommu_fault_event - Generic fault event
350  *
351  * Can represent recoverable faults such as a page requests or
352  * unrecoverable faults such as DMA or IRQ remapping faults.
353  *
354  * @fault: fault descriptor
355  * @list: pending fault event list, used for tracking responses
356  */
357 struct iommu_fault_event {
358 	struct iommu_fault fault;
359 	struct list_head list;
360 };
361 
362 /**
363  * struct iommu_fault_param - per-device IOMMU fault data
364  * @handler: Callback function to handle IOMMU faults at device level
365  * @data: handler private data
366  * @faults: holds the pending faults which needs response
367  * @lock: protect pending faults list
368  */
369 struct iommu_fault_param {
370 	iommu_dev_fault_handler_t handler;
371 	void *data;
372 	struct list_head faults;
373 	struct mutex lock;
374 };
375 
376 /**
377  * struct dev_iommu - Collection of per-device IOMMU data
378  *
379  * @fault_param: IOMMU detected device fault reporting data
380  * @fwspec:	 IOMMU fwspec data
381  * @iommu_dev:	 IOMMU device this device is linked to
382  * @priv:	 IOMMU Driver private data
383  *
384  * TODO: migrate other per device data pointers under iommu_dev_data, e.g.
385  *	struct iommu_group	*iommu_group;
386  */
387 struct dev_iommu {
388 	struct mutex lock;
389 	struct iommu_fault_param	*fault_param;
390 	struct iommu_fwspec		*fwspec;
391 	struct iommu_device		*iommu_dev;
392 	void				*priv;
393 };
394 
395 int  iommu_device_register(struct iommu_device *iommu);
396 void iommu_device_unregister(struct iommu_device *iommu);
397 int  iommu_device_sysfs_add(struct iommu_device *iommu,
398 			    struct device *parent,
399 			    const struct attribute_group **groups,
400 			    const char *fmt, ...) __printf(4, 5);
401 void iommu_device_sysfs_remove(struct iommu_device *iommu);
402 int  iommu_device_link(struct iommu_device   *iommu, struct device *link);
403 void iommu_device_unlink(struct iommu_device *iommu, struct device *link);
404 
__iommu_device_set_ops(struct iommu_device * iommu,const struct iommu_ops * ops)405 static inline void __iommu_device_set_ops(struct iommu_device *iommu,
406 					  const struct iommu_ops *ops)
407 {
408 	iommu->ops = ops;
409 }
410 
411 #define iommu_device_set_ops(iommu, ops)				\
412 do {									\
413 	struct iommu_ops *__ops = (struct iommu_ops *)(ops);		\
414 	__ops->owner = THIS_MODULE;					\
415 	__iommu_device_set_ops(iommu, __ops);				\
416 } while (0)
417 
iommu_device_set_fwnode(struct iommu_device * iommu,struct fwnode_handle * fwnode)418 static inline void iommu_device_set_fwnode(struct iommu_device *iommu,
419 					   struct fwnode_handle *fwnode)
420 {
421 	iommu->fwnode = fwnode;
422 }
423 
dev_to_iommu_device(struct device * dev)424 static inline struct iommu_device *dev_to_iommu_device(struct device *dev)
425 {
426 	return (struct iommu_device *)dev_get_drvdata(dev);
427 }
428 
iommu_iotlb_gather_init(struct iommu_iotlb_gather * gather)429 static inline void iommu_iotlb_gather_init(struct iommu_iotlb_gather *gather)
430 {
431 	*gather = (struct iommu_iotlb_gather) {
432 		.start	= ULONG_MAX,
433 	};
434 }
435 
436 #define IOMMU_GROUP_NOTIFY_ADD_DEVICE		1 /* Device added */
437 #define IOMMU_GROUP_NOTIFY_DEL_DEVICE		2 /* Pre Device removed */
438 #define IOMMU_GROUP_NOTIFY_BIND_DRIVER		3 /* Pre Driver bind */
439 #define IOMMU_GROUP_NOTIFY_BOUND_DRIVER		4 /* Post Driver bind */
440 #define IOMMU_GROUP_NOTIFY_UNBIND_DRIVER	5 /* Pre Driver unbind */
441 #define IOMMU_GROUP_NOTIFY_UNBOUND_DRIVER	6 /* Post Driver unbind */
442 
443 extern int bus_set_iommu(struct bus_type *bus, const struct iommu_ops *ops);
444 extern int bus_iommu_probe(struct bus_type *bus);
445 extern bool iommu_present(struct bus_type *bus);
446 extern bool iommu_capable(struct bus_type *bus, enum iommu_cap cap);
447 extern struct iommu_domain *iommu_domain_alloc(struct bus_type *bus);
448 extern struct iommu_group *iommu_group_get_by_id(int id);
449 extern void iommu_domain_free(struct iommu_domain *domain);
450 extern int iommu_attach_device(struct iommu_domain *domain,
451 			       struct device *dev);
452 extern void iommu_detach_device(struct iommu_domain *domain,
453 				struct device *dev);
454 extern int iommu_uapi_cache_invalidate(struct iommu_domain *domain,
455 				       struct device *dev,
456 				       void __user *uinfo);
457 
458 extern int iommu_uapi_sva_bind_gpasid(struct iommu_domain *domain,
459 				      struct device *dev, void __user *udata);
460 extern int iommu_uapi_sva_unbind_gpasid(struct iommu_domain *domain,
461 					struct device *dev, void __user *udata);
462 extern int iommu_sva_unbind_gpasid(struct iommu_domain *domain,
463 				   struct device *dev, ioasid_t pasid);
464 extern struct iommu_domain *iommu_get_domain_for_dev(struct device *dev);
465 extern struct iommu_domain *iommu_get_dma_domain(struct device *dev);
466 extern int iommu_map(struct iommu_domain *domain, unsigned long iova,
467 		     phys_addr_t paddr, size_t size, int prot);
468 extern int iommu_map_atomic(struct iommu_domain *domain, unsigned long iova,
469 			    phys_addr_t paddr, size_t size, int prot);
470 extern size_t iommu_unmap(struct iommu_domain *domain, unsigned long iova,
471 			  size_t size);
472 extern size_t iommu_unmap_fast(struct iommu_domain *domain,
473 			       unsigned long iova, size_t size,
474 			       struct iommu_iotlb_gather *iotlb_gather);
475 extern size_t iommu_map_sg(struct iommu_domain *domain, unsigned long iova,
476 			   struct scatterlist *sg,unsigned int nents, int prot);
477 extern size_t iommu_map_sg_atomic(struct iommu_domain *domain,
478 				  unsigned long iova, struct scatterlist *sg,
479 				  unsigned int nents, int prot);
480 extern phys_addr_t iommu_iova_to_phys(struct iommu_domain *domain, dma_addr_t iova);
481 extern void iommu_set_fault_handler(struct iommu_domain *domain,
482 			iommu_fault_handler_t handler, void *token);
483 
484 extern void iommu_get_resv_regions(struct device *dev, struct list_head *list);
485 extern void iommu_put_resv_regions(struct device *dev, struct list_head *list);
486 extern void generic_iommu_put_resv_regions(struct device *dev,
487 					   struct list_head *list);
488 extern void iommu_set_default_passthrough(bool cmd_line);
489 extern void iommu_set_default_translated(bool cmd_line);
490 extern bool iommu_default_passthrough(void);
491 extern struct iommu_resv_region *
492 iommu_alloc_resv_region(phys_addr_t start, size_t length, int prot,
493 			enum iommu_resv_type type);
494 extern int iommu_get_group_resv_regions(struct iommu_group *group,
495 					struct list_head *head);
496 
497 extern int iommu_attach_group(struct iommu_domain *domain,
498 			      struct iommu_group *group);
499 extern void iommu_detach_group(struct iommu_domain *domain,
500 			       struct iommu_group *group);
501 extern struct iommu_group *iommu_group_alloc(void);
502 extern void *iommu_group_get_iommudata(struct iommu_group *group);
503 extern void iommu_group_set_iommudata(struct iommu_group *group,
504 				      void *iommu_data,
505 				      void (*release)(void *iommu_data));
506 extern int iommu_group_set_name(struct iommu_group *group, const char *name);
507 extern int iommu_group_add_device(struct iommu_group *group,
508 				  struct device *dev);
509 extern void iommu_group_remove_device(struct device *dev);
510 extern int iommu_group_for_each_dev(struct iommu_group *group, void *data,
511 				    int (*fn)(struct device *, void *));
512 extern struct iommu_group *iommu_group_get(struct device *dev);
513 extern struct iommu_group *iommu_group_ref_get(struct iommu_group *group);
514 extern void iommu_group_put(struct iommu_group *group);
515 extern int iommu_group_register_notifier(struct iommu_group *group,
516 					 struct notifier_block *nb);
517 extern int iommu_group_unregister_notifier(struct iommu_group *group,
518 					   struct notifier_block *nb);
519 extern int iommu_register_device_fault_handler(struct device *dev,
520 					iommu_dev_fault_handler_t handler,
521 					void *data);
522 
523 extern int iommu_unregister_device_fault_handler(struct device *dev);
524 
525 extern int iommu_report_device_fault(struct device *dev,
526 				     struct iommu_fault_event *evt);
527 extern int iommu_page_response(struct device *dev,
528 			       struct iommu_page_response *msg);
529 
530 extern int iommu_group_id(struct iommu_group *group);
531 extern struct iommu_domain *iommu_group_default_domain(struct iommu_group *);
532 
533 extern int iommu_domain_get_attr(struct iommu_domain *domain, enum iommu_attr,
534 				 void *data);
535 extern int iommu_domain_set_attr(struct iommu_domain *domain, enum iommu_attr,
536 				 void *data);
537 
538 /* Window handling function prototypes */
539 extern int iommu_domain_window_enable(struct iommu_domain *domain, u32 wnd_nr,
540 				      phys_addr_t offset, u64 size,
541 				      int prot);
542 extern void iommu_domain_window_disable(struct iommu_domain *domain, u32 wnd_nr);
543 
544 extern int report_iommu_fault(struct iommu_domain *domain, struct device *dev,
545 			      unsigned long iova, int flags);
546 
iommu_flush_iotlb_all(struct iommu_domain * domain)547 static inline void iommu_flush_iotlb_all(struct iommu_domain *domain)
548 {
549 	if (domain->ops->flush_iotlb_all)
550 		domain->ops->flush_iotlb_all(domain);
551 }
552 
iommu_iotlb_sync(struct iommu_domain * domain,struct iommu_iotlb_gather * iotlb_gather)553 static inline void iommu_iotlb_sync(struct iommu_domain *domain,
554 				  struct iommu_iotlb_gather *iotlb_gather)
555 {
556 	if (domain->ops->iotlb_sync)
557 		domain->ops->iotlb_sync(domain, iotlb_gather);
558 
559 	iommu_iotlb_gather_init(iotlb_gather);
560 }
561 
iommu_iotlb_gather_add_page(struct iommu_domain * domain,struct iommu_iotlb_gather * gather,unsigned long iova,size_t size)562 static inline void iommu_iotlb_gather_add_page(struct iommu_domain *domain,
563 					       struct iommu_iotlb_gather *gather,
564 					       unsigned long iova, size_t size)
565 {
566 	unsigned long start = iova, end = start + size - 1;
567 
568 	/*
569 	 * If the new page is disjoint from the current range or is mapped at
570 	 * a different granularity, then sync the TLB so that the gather
571 	 * structure can be rewritten.
572 	 */
573 	if (gather->pgsize != size ||
574 	    end + 1 < gather->start || start > gather->end + 1) {
575 		if (gather->pgsize)
576 			iommu_iotlb_sync(domain, gather);
577 		gather->pgsize = size;
578 	}
579 
580 	if (gather->end < end)
581 		gather->end = end;
582 
583 	if (gather->start > start)
584 		gather->start = start;
585 }
586 
587 /* PCI device grouping function */
588 extern struct iommu_group *pci_device_group(struct device *dev);
589 /* Generic device grouping function */
590 extern struct iommu_group *generic_device_group(struct device *dev);
591 /* FSL-MC device grouping function */
592 struct iommu_group *fsl_mc_device_group(struct device *dev);
593 
594 /**
595  * struct iommu_fwspec - per-device IOMMU instance data
596  * @ops: ops for this device's IOMMU
597  * @iommu_fwnode: firmware handle for this device's IOMMU
598  * @iommu_priv: IOMMU driver private data for this device
599  * @num_pasid_bits: number of PASID bits supported by this device
600  * @num_ids: number of associated device IDs
601  * @ids: IDs which this device may present to the IOMMU
602  */
603 struct iommu_fwspec {
604 	const struct iommu_ops	*ops;
605 	struct fwnode_handle	*iommu_fwnode;
606 	u32			flags;
607 	u32			num_pasid_bits;
608 	unsigned int		num_ids;
609 	u32			ids[];
610 };
611 
612 /* ATS is supported */
613 #define IOMMU_FWSPEC_PCI_RC_ATS			(1 << 0)
614 
615 /**
616  * struct iommu_sva - handle to a device-mm bond
617  */
618 struct iommu_sva {
619 	struct device			*dev;
620 };
621 
622 int iommu_fwspec_init(struct device *dev, struct fwnode_handle *iommu_fwnode,
623 		      const struct iommu_ops *ops);
624 void iommu_fwspec_free(struct device *dev);
625 int iommu_fwspec_add_ids(struct device *dev, u32 *ids, int num_ids);
626 const struct iommu_ops *iommu_ops_from_fwnode(struct fwnode_handle *fwnode);
627 
dev_iommu_fwspec_get(struct device * dev)628 static inline struct iommu_fwspec *dev_iommu_fwspec_get(struct device *dev)
629 {
630 	if (dev->iommu)
631 		return dev->iommu->fwspec;
632 	else
633 		return NULL;
634 }
635 
dev_iommu_fwspec_set(struct device * dev,struct iommu_fwspec * fwspec)636 static inline void dev_iommu_fwspec_set(struct device *dev,
637 					struct iommu_fwspec *fwspec)
638 {
639 	dev->iommu->fwspec = fwspec;
640 }
641 
dev_iommu_priv_get(struct device * dev)642 static inline void *dev_iommu_priv_get(struct device *dev)
643 {
644 	if (dev->iommu)
645 		return dev->iommu->priv;
646 	else
647 		return NULL;
648 }
649 
dev_iommu_priv_set(struct device * dev,void * priv)650 static inline void dev_iommu_priv_set(struct device *dev, void *priv)
651 {
652 	dev->iommu->priv = priv;
653 }
654 
655 int iommu_probe_device(struct device *dev);
656 void iommu_release_device(struct device *dev);
657 
658 bool iommu_dev_has_feature(struct device *dev, enum iommu_dev_features f);
659 int iommu_dev_enable_feature(struct device *dev, enum iommu_dev_features f);
660 int iommu_dev_disable_feature(struct device *dev, enum iommu_dev_features f);
661 bool iommu_dev_feature_enabled(struct device *dev, enum iommu_dev_features f);
662 int iommu_aux_attach_device(struct iommu_domain *domain, struct device *dev);
663 void iommu_aux_detach_device(struct iommu_domain *domain, struct device *dev);
664 int iommu_aux_get_pasid(struct iommu_domain *domain, struct device *dev);
665 
666 struct iommu_sva *iommu_sva_bind_device(struct device *dev,
667 					struct mm_struct *mm,
668 					void *drvdata);
669 void iommu_sva_unbind_device(struct iommu_sva *handle);
670 u32 iommu_sva_get_pasid(struct iommu_sva *handle);
671 
672 #else /* CONFIG_IOMMU_API */
673 
674 struct iommu_ops {};
675 struct iommu_group {};
676 struct iommu_fwspec {};
677 struct iommu_device {};
678 struct iommu_fault_param {};
679 struct iommu_iotlb_gather {};
680 
iommu_present(struct bus_type * bus)681 static inline bool iommu_present(struct bus_type *bus)
682 {
683 	return false;
684 }
685 
iommu_capable(struct bus_type * bus,enum iommu_cap cap)686 static inline bool iommu_capable(struct bus_type *bus, enum iommu_cap cap)
687 {
688 	return false;
689 }
690 
iommu_domain_alloc(struct bus_type * bus)691 static inline struct iommu_domain *iommu_domain_alloc(struct bus_type *bus)
692 {
693 	return NULL;
694 }
695 
iommu_group_get_by_id(int id)696 static inline struct iommu_group *iommu_group_get_by_id(int id)
697 {
698 	return NULL;
699 }
700 
iommu_domain_free(struct iommu_domain * domain)701 static inline void iommu_domain_free(struct iommu_domain *domain)
702 {
703 }
704 
iommu_attach_device(struct iommu_domain * domain,struct device * dev)705 static inline int iommu_attach_device(struct iommu_domain *domain,
706 				      struct device *dev)
707 {
708 	return -ENODEV;
709 }
710 
iommu_detach_device(struct iommu_domain * domain,struct device * dev)711 static inline void iommu_detach_device(struct iommu_domain *domain,
712 				       struct device *dev)
713 {
714 }
715 
iommu_get_domain_for_dev(struct device * dev)716 static inline struct iommu_domain *iommu_get_domain_for_dev(struct device *dev)
717 {
718 	return NULL;
719 }
720 
iommu_map(struct iommu_domain * domain,unsigned long iova,phys_addr_t paddr,size_t size,int prot)721 static inline int iommu_map(struct iommu_domain *domain, unsigned long iova,
722 			    phys_addr_t paddr, size_t size, int prot)
723 {
724 	return -ENODEV;
725 }
726 
iommu_map_atomic(struct iommu_domain * domain,unsigned long iova,phys_addr_t paddr,size_t size,int prot)727 static inline int iommu_map_atomic(struct iommu_domain *domain,
728 				   unsigned long iova, phys_addr_t paddr,
729 				   size_t size, int prot)
730 {
731 	return -ENODEV;
732 }
733 
iommu_unmap(struct iommu_domain * domain,unsigned long iova,size_t size)734 static inline size_t iommu_unmap(struct iommu_domain *domain,
735 				 unsigned long iova, size_t size)
736 {
737 	return 0;
738 }
739 
iommu_unmap_fast(struct iommu_domain * domain,unsigned long iova,int gfp_order,struct iommu_iotlb_gather * iotlb_gather)740 static inline size_t iommu_unmap_fast(struct iommu_domain *domain,
741 				      unsigned long iova, int gfp_order,
742 				      struct iommu_iotlb_gather *iotlb_gather)
743 {
744 	return 0;
745 }
746 
iommu_map_sg(struct iommu_domain * domain,unsigned long iova,struct scatterlist * sg,unsigned int nents,int prot)747 static inline size_t iommu_map_sg(struct iommu_domain *domain,
748 				  unsigned long iova, struct scatterlist *sg,
749 				  unsigned int nents, int prot)
750 {
751 	return 0;
752 }
753 
iommu_map_sg_atomic(struct iommu_domain * domain,unsigned long iova,struct scatterlist * sg,unsigned int nents,int prot)754 static inline size_t iommu_map_sg_atomic(struct iommu_domain *domain,
755 				  unsigned long iova, struct scatterlist *sg,
756 				  unsigned int nents, int prot)
757 {
758 	return 0;
759 }
760 
iommu_flush_iotlb_all(struct iommu_domain * domain)761 static inline void iommu_flush_iotlb_all(struct iommu_domain *domain)
762 {
763 }
764 
iommu_iotlb_sync(struct iommu_domain * domain,struct iommu_iotlb_gather * iotlb_gather)765 static inline void iommu_iotlb_sync(struct iommu_domain *domain,
766 				  struct iommu_iotlb_gather *iotlb_gather)
767 {
768 }
769 
iommu_domain_window_enable(struct iommu_domain * domain,u32 wnd_nr,phys_addr_t paddr,u64 size,int prot)770 static inline int iommu_domain_window_enable(struct iommu_domain *domain,
771 					     u32 wnd_nr, phys_addr_t paddr,
772 					     u64 size, int prot)
773 {
774 	return -ENODEV;
775 }
776 
iommu_domain_window_disable(struct iommu_domain * domain,u32 wnd_nr)777 static inline void iommu_domain_window_disable(struct iommu_domain *domain,
778 					       u32 wnd_nr)
779 {
780 }
781 
iommu_iova_to_phys(struct iommu_domain * domain,dma_addr_t iova)782 static inline phys_addr_t iommu_iova_to_phys(struct iommu_domain *domain, dma_addr_t iova)
783 {
784 	return 0;
785 }
786 
iommu_set_fault_handler(struct iommu_domain * domain,iommu_fault_handler_t handler,void * token)787 static inline void iommu_set_fault_handler(struct iommu_domain *domain,
788 				iommu_fault_handler_t handler, void *token)
789 {
790 }
791 
iommu_get_resv_regions(struct device * dev,struct list_head * list)792 static inline void iommu_get_resv_regions(struct device *dev,
793 					struct list_head *list)
794 {
795 }
796 
iommu_put_resv_regions(struct device * dev,struct list_head * list)797 static inline void iommu_put_resv_regions(struct device *dev,
798 					struct list_head *list)
799 {
800 }
801 
iommu_get_group_resv_regions(struct iommu_group * group,struct list_head * head)802 static inline int iommu_get_group_resv_regions(struct iommu_group *group,
803 					       struct list_head *head)
804 {
805 	return -ENODEV;
806 }
807 
iommu_set_default_passthrough(bool cmd_line)808 static inline void iommu_set_default_passthrough(bool cmd_line)
809 {
810 }
811 
iommu_set_default_translated(bool cmd_line)812 static inline void iommu_set_default_translated(bool cmd_line)
813 {
814 }
815 
iommu_default_passthrough(void)816 static inline bool iommu_default_passthrough(void)
817 {
818 	return true;
819 }
820 
iommu_attach_group(struct iommu_domain * domain,struct iommu_group * group)821 static inline int iommu_attach_group(struct iommu_domain *domain,
822 				     struct iommu_group *group)
823 {
824 	return -ENODEV;
825 }
826 
iommu_detach_group(struct iommu_domain * domain,struct iommu_group * group)827 static inline void iommu_detach_group(struct iommu_domain *domain,
828 				      struct iommu_group *group)
829 {
830 }
831 
iommu_group_alloc(void)832 static inline struct iommu_group *iommu_group_alloc(void)
833 {
834 	return ERR_PTR(-ENODEV);
835 }
836 
iommu_group_get_iommudata(struct iommu_group * group)837 static inline void *iommu_group_get_iommudata(struct iommu_group *group)
838 {
839 	return NULL;
840 }
841 
iommu_group_set_iommudata(struct iommu_group * group,void * iommu_data,void (* release)(void * iommu_data))842 static inline void iommu_group_set_iommudata(struct iommu_group *group,
843 					     void *iommu_data,
844 					     void (*release)(void *iommu_data))
845 {
846 }
847 
iommu_group_set_name(struct iommu_group * group,const char * name)848 static inline int iommu_group_set_name(struct iommu_group *group,
849 				       const char *name)
850 {
851 	return -ENODEV;
852 }
853 
iommu_group_add_device(struct iommu_group * group,struct device * dev)854 static inline int iommu_group_add_device(struct iommu_group *group,
855 					 struct device *dev)
856 {
857 	return -ENODEV;
858 }
859 
iommu_group_remove_device(struct device * dev)860 static inline void iommu_group_remove_device(struct device *dev)
861 {
862 }
863 
iommu_group_for_each_dev(struct iommu_group * group,void * data,int (* fn)(struct device *,void *))864 static inline int iommu_group_for_each_dev(struct iommu_group *group,
865 					   void *data,
866 					   int (*fn)(struct device *, void *))
867 {
868 	return -ENODEV;
869 }
870 
iommu_group_get(struct device * dev)871 static inline struct iommu_group *iommu_group_get(struct device *dev)
872 {
873 	return NULL;
874 }
875 
iommu_group_put(struct iommu_group * group)876 static inline void iommu_group_put(struct iommu_group *group)
877 {
878 }
879 
iommu_group_register_notifier(struct iommu_group * group,struct notifier_block * nb)880 static inline int iommu_group_register_notifier(struct iommu_group *group,
881 						struct notifier_block *nb)
882 {
883 	return -ENODEV;
884 }
885 
iommu_group_unregister_notifier(struct iommu_group * group,struct notifier_block * nb)886 static inline int iommu_group_unregister_notifier(struct iommu_group *group,
887 						  struct notifier_block *nb)
888 {
889 	return 0;
890 }
891 
892 static inline
iommu_register_device_fault_handler(struct device * dev,iommu_dev_fault_handler_t handler,void * data)893 int iommu_register_device_fault_handler(struct device *dev,
894 					iommu_dev_fault_handler_t handler,
895 					void *data)
896 {
897 	return -ENODEV;
898 }
899 
iommu_unregister_device_fault_handler(struct device * dev)900 static inline int iommu_unregister_device_fault_handler(struct device *dev)
901 {
902 	return 0;
903 }
904 
905 static inline
iommu_report_device_fault(struct device * dev,struct iommu_fault_event * evt)906 int iommu_report_device_fault(struct device *dev, struct iommu_fault_event *evt)
907 {
908 	return -ENODEV;
909 }
910 
iommu_page_response(struct device * dev,struct iommu_page_response * msg)911 static inline int iommu_page_response(struct device *dev,
912 				      struct iommu_page_response *msg)
913 {
914 	return -ENODEV;
915 }
916 
iommu_group_id(struct iommu_group * group)917 static inline int iommu_group_id(struct iommu_group *group)
918 {
919 	return -ENODEV;
920 }
921 
iommu_domain_get_attr(struct iommu_domain * domain,enum iommu_attr attr,void * data)922 static inline int iommu_domain_get_attr(struct iommu_domain *domain,
923 					enum iommu_attr attr, void *data)
924 {
925 	return -EINVAL;
926 }
927 
iommu_domain_set_attr(struct iommu_domain * domain,enum iommu_attr attr,void * data)928 static inline int iommu_domain_set_attr(struct iommu_domain *domain,
929 					enum iommu_attr attr, void *data)
930 {
931 	return -EINVAL;
932 }
933 
iommu_device_register(struct iommu_device * iommu)934 static inline int  iommu_device_register(struct iommu_device *iommu)
935 {
936 	return -ENODEV;
937 }
938 
iommu_device_set_ops(struct iommu_device * iommu,const struct iommu_ops * ops)939 static inline void iommu_device_set_ops(struct iommu_device *iommu,
940 					const struct iommu_ops *ops)
941 {
942 }
943 
iommu_device_set_fwnode(struct iommu_device * iommu,struct fwnode_handle * fwnode)944 static inline void iommu_device_set_fwnode(struct iommu_device *iommu,
945 					   struct fwnode_handle *fwnode)
946 {
947 }
948 
dev_to_iommu_device(struct device * dev)949 static inline struct iommu_device *dev_to_iommu_device(struct device *dev)
950 {
951 	return NULL;
952 }
953 
iommu_iotlb_gather_init(struct iommu_iotlb_gather * gather)954 static inline void iommu_iotlb_gather_init(struct iommu_iotlb_gather *gather)
955 {
956 }
957 
iommu_iotlb_gather_add_page(struct iommu_domain * domain,struct iommu_iotlb_gather * gather,unsigned long iova,size_t size)958 static inline void iommu_iotlb_gather_add_page(struct iommu_domain *domain,
959 					       struct iommu_iotlb_gather *gather,
960 					       unsigned long iova, size_t size)
961 {
962 }
963 
iommu_device_unregister(struct iommu_device * iommu)964 static inline void iommu_device_unregister(struct iommu_device *iommu)
965 {
966 }
967 
iommu_device_sysfs_add(struct iommu_device * iommu,struct device * parent,const struct attribute_group ** groups,const char * fmt,...)968 static inline int  iommu_device_sysfs_add(struct iommu_device *iommu,
969 					  struct device *parent,
970 					  const struct attribute_group **groups,
971 					  const char *fmt, ...)
972 {
973 	return -ENODEV;
974 }
975 
iommu_device_sysfs_remove(struct iommu_device * iommu)976 static inline void iommu_device_sysfs_remove(struct iommu_device *iommu)
977 {
978 }
979 
iommu_device_link(struct device * dev,struct device * link)980 static inline int iommu_device_link(struct device *dev, struct device *link)
981 {
982 	return -EINVAL;
983 }
984 
iommu_device_unlink(struct device * dev,struct device * link)985 static inline void iommu_device_unlink(struct device *dev, struct device *link)
986 {
987 }
988 
iommu_fwspec_init(struct device * dev,struct fwnode_handle * iommu_fwnode,const struct iommu_ops * ops)989 static inline int iommu_fwspec_init(struct device *dev,
990 				    struct fwnode_handle *iommu_fwnode,
991 				    const struct iommu_ops *ops)
992 {
993 	return -ENODEV;
994 }
995 
iommu_fwspec_free(struct device * dev)996 static inline void iommu_fwspec_free(struct device *dev)
997 {
998 }
999 
iommu_fwspec_add_ids(struct device * dev,u32 * ids,int num_ids)1000 static inline int iommu_fwspec_add_ids(struct device *dev, u32 *ids,
1001 				       int num_ids)
1002 {
1003 	return -ENODEV;
1004 }
1005 
1006 static inline
iommu_ops_from_fwnode(struct fwnode_handle * fwnode)1007 const struct iommu_ops *iommu_ops_from_fwnode(struct fwnode_handle *fwnode)
1008 {
1009 	return NULL;
1010 }
1011 
1012 static inline bool
iommu_dev_has_feature(struct device * dev,enum iommu_dev_features feat)1013 iommu_dev_has_feature(struct device *dev, enum iommu_dev_features feat)
1014 {
1015 	return false;
1016 }
1017 
1018 static inline bool
iommu_dev_feature_enabled(struct device * dev,enum iommu_dev_features feat)1019 iommu_dev_feature_enabled(struct device *dev, enum iommu_dev_features feat)
1020 {
1021 	return false;
1022 }
1023 
1024 static inline int
iommu_dev_enable_feature(struct device * dev,enum iommu_dev_features feat)1025 iommu_dev_enable_feature(struct device *dev, enum iommu_dev_features feat)
1026 {
1027 	return -ENODEV;
1028 }
1029 
1030 static inline int
iommu_dev_disable_feature(struct device * dev,enum iommu_dev_features feat)1031 iommu_dev_disable_feature(struct device *dev, enum iommu_dev_features feat)
1032 {
1033 	return -ENODEV;
1034 }
1035 
1036 static inline int
iommu_aux_attach_device(struct iommu_domain * domain,struct device * dev)1037 iommu_aux_attach_device(struct iommu_domain *domain, struct device *dev)
1038 {
1039 	return -ENODEV;
1040 }
1041 
1042 static inline void
iommu_aux_detach_device(struct iommu_domain * domain,struct device * dev)1043 iommu_aux_detach_device(struct iommu_domain *domain, struct device *dev)
1044 {
1045 }
1046 
1047 static inline int
iommu_aux_get_pasid(struct iommu_domain * domain,struct device * dev)1048 iommu_aux_get_pasid(struct iommu_domain *domain, struct device *dev)
1049 {
1050 	return -ENODEV;
1051 }
1052 
1053 static inline struct iommu_sva *
iommu_sva_bind_device(struct device * dev,struct mm_struct * mm,void * drvdata)1054 iommu_sva_bind_device(struct device *dev, struct mm_struct *mm, void *drvdata)
1055 {
1056 	return NULL;
1057 }
1058 
iommu_sva_unbind_device(struct iommu_sva * handle)1059 static inline void iommu_sva_unbind_device(struct iommu_sva *handle)
1060 {
1061 }
1062 
iommu_sva_get_pasid(struct iommu_sva * handle)1063 static inline u32 iommu_sva_get_pasid(struct iommu_sva *handle)
1064 {
1065 	return IOMMU_PASID_INVALID;
1066 }
1067 
1068 static inline int
iommu_uapi_cache_invalidate(struct iommu_domain * domain,struct device * dev,struct iommu_cache_invalidate_info * inv_info)1069 iommu_uapi_cache_invalidate(struct iommu_domain *domain,
1070 			    struct device *dev,
1071 			    struct iommu_cache_invalidate_info *inv_info)
1072 {
1073 	return -ENODEV;
1074 }
1075 
iommu_uapi_sva_bind_gpasid(struct iommu_domain * domain,struct device * dev,void __user * udata)1076 static inline int iommu_uapi_sva_bind_gpasid(struct iommu_domain *domain,
1077 					     struct device *dev, void __user *udata)
1078 {
1079 	return -ENODEV;
1080 }
1081 
iommu_uapi_sva_unbind_gpasid(struct iommu_domain * domain,struct device * dev,void __user * udata)1082 static inline int iommu_uapi_sva_unbind_gpasid(struct iommu_domain *domain,
1083 					       struct device *dev, void __user *udata)
1084 {
1085 	return -ENODEV;
1086 }
1087 
iommu_sva_unbind_gpasid(struct iommu_domain * domain,struct device * dev,ioasid_t pasid)1088 static inline int iommu_sva_unbind_gpasid(struct iommu_domain *domain,
1089 					  struct device *dev,
1090 					  ioasid_t pasid)
1091 {
1092 	return -ENODEV;
1093 }
1094 
dev_iommu_fwspec_get(struct device * dev)1095 static inline struct iommu_fwspec *dev_iommu_fwspec_get(struct device *dev)
1096 {
1097 	return NULL;
1098 }
1099 #endif /* CONFIG_IOMMU_API */
1100 
1101 /**
1102  * iommu_map_sgtable - Map the given buffer to the IOMMU domain
1103  * @domain:	The IOMMU domain to perform the mapping
1104  * @iova:	The start address to map the buffer
1105  * @sgt:	The sg_table object describing the buffer
1106  * @prot:	IOMMU protection bits
1107  *
1108  * Creates a mapping at @iova for the buffer described by a scatterlist
1109  * stored in the given sg_table object in the provided IOMMU domain.
1110  */
iommu_map_sgtable(struct iommu_domain * domain,unsigned long iova,struct sg_table * sgt,int prot)1111 static inline size_t iommu_map_sgtable(struct iommu_domain *domain,
1112 			unsigned long iova, struct sg_table *sgt, int prot)
1113 {
1114 	return iommu_map_sg(domain, iova, sgt->sgl, sgt->orig_nents, prot);
1115 }
1116 
1117 #ifdef CONFIG_IOMMU_DEBUGFS
1118 extern	struct dentry *iommu_debugfs_dir;
1119 void iommu_debugfs_setup(void);
1120 #else
iommu_debugfs_setup(void)1121 static inline void iommu_debugfs_setup(void) {}
1122 #endif
1123 
1124 #endif /* __LINUX_IOMMU_H */
1125