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