iommu.h 22 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698
  1. /*
  2. * Copyright (C) 2007-2008 Advanced Micro Devices, Inc.
  3. * Author: Joerg Roedel <joerg.roedel@amd.com>
  4. *
  5. * This program is free software; you can redistribute it and/or modify it
  6. * under the terms of the GNU General Public License version 2 as published
  7. * by the Free Software Foundation.
  8. *
  9. * This program is distributed in the hope that it will be useful,
  10. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  11. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  12. * GNU General Public License for more details.
  13. *
  14. * You should have received a copy of the GNU General Public License
  15. * along with this program; if not, write to the Free Software
  16. * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
  17. */
  18. #ifndef __LINUX_IOMMU_H
  19. #define __LINUX_IOMMU_H
  20. #include <linux/scatterlist.h>
  21. #include <linux/device.h>
  22. #include <linux/types.h>
  23. #include <linux/errno.h>
  24. #include <linux/err.h>
  25. #include <linux/of.h>
  26. #define IOMMU_READ (1 << 0)
  27. #define IOMMU_WRITE (1 << 1)
  28. #define IOMMU_CACHE (1 << 2) /* DMA cache coherency */
  29. #define IOMMU_NOEXEC (1 << 3)
  30. #define IOMMU_MMIO (1 << 4) /* e.g. things like MSI doorbells */
  31. /*
  32. * Where the bus hardware includes a privilege level as part of its access type
  33. * markings, and certain devices are capable of issuing transactions marked as
  34. * either 'supervisor' or 'user', the IOMMU_PRIV flag requests that the other
  35. * given permission flags only apply to accesses at the higher privilege level,
  36. * and that unprivileged transactions should have as little access as possible.
  37. * This would usually imply the same permissions as kernel mappings on the CPU,
  38. * if the IOMMU page table format is equivalent.
  39. */
  40. #define IOMMU_PRIV (1 << 5)
  41. struct iommu_ops;
  42. struct iommu_group;
  43. struct bus_type;
  44. struct device;
  45. struct iommu_domain;
  46. struct notifier_block;
  47. /* iommu fault flags */
  48. #define IOMMU_FAULT_READ 0x0
  49. #define IOMMU_FAULT_WRITE 0x1
  50. typedef int (*iommu_fault_handler_t)(struct iommu_domain *,
  51. struct device *, unsigned long, int, void *);
  52. struct iommu_domain_geometry {
  53. dma_addr_t aperture_start; /* First address that can be mapped */
  54. dma_addr_t aperture_end; /* Last address that can be mapped */
  55. bool force_aperture; /* DMA only allowed in mappable range? */
  56. };
  57. /* Domain feature flags */
  58. #define __IOMMU_DOMAIN_PAGING (1U << 0) /* Support for iommu_map/unmap */
  59. #define __IOMMU_DOMAIN_DMA_API (1U << 1) /* Domain for use in DMA-API
  60. implementation */
  61. #define __IOMMU_DOMAIN_PT (1U << 2) /* Domain is identity mapped */
  62. /*
  63. * This are the possible domain-types
  64. *
  65. * IOMMU_DOMAIN_BLOCKED - All DMA is blocked, can be used to isolate
  66. * devices
  67. * IOMMU_DOMAIN_IDENTITY - DMA addresses are system physical addresses
  68. * IOMMU_DOMAIN_UNMANAGED - DMA mappings managed by IOMMU-API user, used
  69. * for VMs
  70. * IOMMU_DOMAIN_DMA - Internally used for DMA-API implementations.
  71. * This flag allows IOMMU drivers to implement
  72. * certain optimizations for these domains
  73. */
  74. #define IOMMU_DOMAIN_BLOCKED (0U)
  75. #define IOMMU_DOMAIN_IDENTITY (__IOMMU_DOMAIN_PT)
  76. #define IOMMU_DOMAIN_UNMANAGED (__IOMMU_DOMAIN_PAGING)
  77. #define IOMMU_DOMAIN_DMA (__IOMMU_DOMAIN_PAGING | \
  78. __IOMMU_DOMAIN_DMA_API)
  79. struct iommu_domain {
  80. unsigned type;
  81. const struct iommu_ops *ops;
  82. unsigned long pgsize_bitmap; /* Bitmap of page sizes in use */
  83. iommu_fault_handler_t handler;
  84. void *handler_token;
  85. struct iommu_domain_geometry geometry;
  86. void *iova_cookie;
  87. };
  88. enum iommu_cap {
  89. IOMMU_CAP_CACHE_COHERENCY, /* IOMMU can enforce cache coherent DMA
  90. transactions */
  91. IOMMU_CAP_INTR_REMAP, /* IOMMU supports interrupt isolation */
  92. IOMMU_CAP_NOEXEC, /* IOMMU_NOEXEC flag */
  93. };
  94. /*
  95. * Following constraints are specifc to FSL_PAMUV1:
  96. * -aperture must be power of 2, and naturally aligned
  97. * -number of windows must be power of 2, and address space size
  98. * of each window is determined by aperture size / # of windows
  99. * -the actual size of the mapped region of a window must be power
  100. * of 2 starting with 4KB and physical address must be naturally
  101. * aligned.
  102. * DOMAIN_ATTR_FSL_PAMUV1 corresponds to the above mentioned contraints.
  103. * The caller can invoke iommu_domain_get_attr to check if the underlying
  104. * iommu implementation supports these constraints.
  105. */
  106. enum iommu_attr {
  107. DOMAIN_ATTR_GEOMETRY,
  108. DOMAIN_ATTR_PAGING,
  109. DOMAIN_ATTR_WINDOWS,
  110. DOMAIN_ATTR_FSL_PAMU_STASH,
  111. DOMAIN_ATTR_FSL_PAMU_ENABLE,
  112. DOMAIN_ATTR_FSL_PAMUV1,
  113. DOMAIN_ATTR_NESTING, /* two stages of translation */
  114. DOMAIN_ATTR_MAX,
  115. };
  116. /* These are the possible reserved region types */
  117. enum iommu_resv_type {
  118. /* Memory regions which must be mapped 1:1 at all times */
  119. IOMMU_RESV_DIRECT,
  120. /* Arbitrary "never map this or give it to a device" address ranges */
  121. IOMMU_RESV_RESERVED,
  122. /* Hardware MSI region (untranslated) */
  123. IOMMU_RESV_MSI,
  124. /* Software-managed MSI translation window */
  125. IOMMU_RESV_SW_MSI,
  126. };
  127. /**
  128. * struct iommu_resv_region - descriptor for a reserved memory region
  129. * @list: Linked list pointers
  130. * @start: System physical start address of the region
  131. * @length: Length of the region in bytes
  132. * @prot: IOMMU Protection flags (READ/WRITE/...)
  133. * @type: Type of the reserved region
  134. */
  135. struct iommu_resv_region {
  136. struct list_head list;
  137. phys_addr_t start;
  138. size_t length;
  139. int prot;
  140. enum iommu_resv_type type;
  141. };
  142. #ifdef CONFIG_IOMMU_API
  143. /**
  144. * struct iommu_ops - iommu ops and capabilities
  145. * @capable: check capability
  146. * @domain_alloc: allocate iommu domain
  147. * @domain_free: free iommu domain
  148. * @attach_dev: attach device to an iommu domain
  149. * @detach_dev: detach device from an iommu domain
  150. * @map: map a physically contiguous memory region to an iommu domain
  151. * @unmap: unmap a physically contiguous memory region from an iommu domain
  152. * @flush_tlb_all: Synchronously flush all hardware TLBs for this domain
  153. * @tlb_range_add: Add a given iova range to the flush queue for this domain
  154. * @tlb_sync: Flush all queued ranges from the hardware TLBs and empty flush
  155. * queue
  156. * @iova_to_phys: translate iova to physical address
  157. * @add_device: add device to iommu grouping
  158. * @remove_device: remove device from iommu grouping
  159. * @device_group: find iommu group for a particular device
  160. * @domain_get_attr: Query domain attributes
  161. * @domain_set_attr: Change domain attributes
  162. * @get_resv_regions: Request list of reserved regions for a device
  163. * @put_resv_regions: Free list of reserved regions for a device
  164. * @apply_resv_region: Temporary helper call-back for iova reserved ranges
  165. * @domain_window_enable: Configure and enable a particular window for a domain
  166. * @domain_window_disable: Disable a particular window for a domain
  167. * @domain_set_windows: Set the number of windows for a domain
  168. * @domain_get_windows: Return the number of windows for a domain
  169. * @of_xlate: add OF master IDs to iommu grouping
  170. * @pgsize_bitmap: bitmap of all possible supported page sizes
  171. */
  172. struct iommu_ops {
  173. bool (*capable)(enum iommu_cap);
  174. /* Domain allocation and freeing by the iommu driver */
  175. struct iommu_domain *(*domain_alloc)(unsigned iommu_domain_type);
  176. void (*domain_free)(struct iommu_domain *);
  177. int (*attach_dev)(struct iommu_domain *domain, struct device *dev);
  178. void (*detach_dev)(struct iommu_domain *domain, struct device *dev);
  179. int (*map)(struct iommu_domain *domain, unsigned long iova,
  180. phys_addr_t paddr, size_t size, int prot);
  181. size_t (*unmap)(struct iommu_domain *domain, unsigned long iova,
  182. size_t size);
  183. void (*flush_iotlb_all)(struct iommu_domain *domain);
  184. void (*iotlb_range_add)(struct iommu_domain *domain,
  185. unsigned long iova, size_t size);
  186. void (*iotlb_sync)(struct iommu_domain *domain);
  187. phys_addr_t (*iova_to_phys)(struct iommu_domain *domain, dma_addr_t iova);
  188. int (*add_device)(struct device *dev);
  189. void (*remove_device)(struct device *dev);
  190. struct iommu_group *(*device_group)(struct device *dev);
  191. 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);
  195. /* Request/Free a list of reserved regions for a device */
  196. void (*get_resv_regions)(struct device *dev, struct list_head *list);
  197. void (*put_resv_regions)(struct device *dev, struct list_head *list);
  198. void (*apply_resv_region)(struct device *dev,
  199. struct iommu_domain *domain,
  200. struct iommu_resv_region *region);
  201. /* Window handling functions */
  202. int (*domain_window_enable)(struct iommu_domain *domain, u32 wnd_nr,
  203. phys_addr_t paddr, u64 size, int prot);
  204. void (*domain_window_disable)(struct iommu_domain *domain, u32 wnd_nr);
  205. /* Set the number of windows per domain */
  206. int (*domain_set_windows)(struct iommu_domain *domain, u32 w_count);
  207. /* Get the number of windows per domain */
  208. u32 (*domain_get_windows)(struct iommu_domain *domain);
  209. int (*of_xlate)(struct device *dev, struct of_phandle_args *args);
  210. bool (*is_attach_deferred)(struct iommu_domain *domain, struct device *dev);
  211. unsigned long pgsize_bitmap;
  212. };
  213. /**
  214. * struct iommu_device - IOMMU core representation of one IOMMU hardware
  215. * instance
  216. * @list: Used by the iommu-core to keep a list of registered iommus
  217. * @ops: iommu-ops for talking to this iommu
  218. * @dev: struct device for sysfs handling
  219. */
  220. struct iommu_device {
  221. struct list_head list;
  222. const struct iommu_ops *ops;
  223. struct fwnode_handle *fwnode;
  224. struct device *dev;
  225. };
  226. int iommu_device_register(struct iommu_device *iommu);
  227. void iommu_device_unregister(struct iommu_device *iommu);
  228. int iommu_device_sysfs_add(struct iommu_device *iommu,
  229. struct device *parent,
  230. const struct attribute_group **groups,
  231. const char *fmt, ...) __printf(4, 5);
  232. void iommu_device_sysfs_remove(struct iommu_device *iommu);
  233. int iommu_device_link(struct iommu_device *iommu, struct device *link);
  234. void iommu_device_unlink(struct iommu_device *iommu, struct device *link);
  235. static inline void iommu_device_set_ops(struct iommu_device *iommu,
  236. const struct iommu_ops *ops)
  237. {
  238. iommu->ops = ops;
  239. }
  240. static inline void iommu_device_set_fwnode(struct iommu_device *iommu,
  241. struct fwnode_handle *fwnode)
  242. {
  243. iommu->fwnode = fwnode;
  244. }
  245. static inline struct iommu_device *dev_to_iommu_device(struct device *dev)
  246. {
  247. return (struct iommu_device *)dev_get_drvdata(dev);
  248. }
  249. #define IOMMU_GROUP_NOTIFY_ADD_DEVICE 1 /* Device added */
  250. #define IOMMU_GROUP_NOTIFY_DEL_DEVICE 2 /* Pre Device removed */
  251. #define IOMMU_GROUP_NOTIFY_BIND_DRIVER 3 /* Pre Driver bind */
  252. #define IOMMU_GROUP_NOTIFY_BOUND_DRIVER 4 /* Post Driver bind */
  253. #define IOMMU_GROUP_NOTIFY_UNBIND_DRIVER 5 /* Pre Driver unbind */
  254. #define IOMMU_GROUP_NOTIFY_UNBOUND_DRIVER 6 /* Post Driver unbind */
  255. extern int bus_set_iommu(struct bus_type *bus, const struct iommu_ops *ops);
  256. extern bool iommu_present(struct bus_type *bus);
  257. extern bool iommu_capable(struct bus_type *bus, enum iommu_cap cap);
  258. extern struct iommu_domain *iommu_domain_alloc(struct bus_type *bus);
  259. extern struct iommu_group *iommu_group_get_by_id(int id);
  260. extern void iommu_domain_free(struct iommu_domain *domain);
  261. extern int iommu_attach_device(struct iommu_domain *domain,
  262. struct device *dev);
  263. extern void iommu_detach_device(struct iommu_domain *domain,
  264. struct device *dev);
  265. extern struct iommu_domain *iommu_get_domain_for_dev(struct device *dev);
  266. extern int iommu_map(struct iommu_domain *domain, unsigned long iova,
  267. phys_addr_t paddr, size_t size, int prot);
  268. extern size_t iommu_unmap(struct iommu_domain *domain, unsigned long iova,
  269. size_t size);
  270. extern size_t iommu_unmap_fast(struct iommu_domain *domain,
  271. unsigned long iova, size_t size);
  272. extern size_t iommu_map_sg(struct iommu_domain *domain, unsigned long iova,
  273. struct scatterlist *sg,unsigned int nents, int prot);
  274. extern phys_addr_t iommu_iova_to_phys(struct iommu_domain *domain, dma_addr_t iova);
  275. extern void iommu_set_fault_handler(struct iommu_domain *domain,
  276. iommu_fault_handler_t handler, void *token);
  277. extern void iommu_get_resv_regions(struct device *dev, struct list_head *list);
  278. extern void iommu_put_resv_regions(struct device *dev, struct list_head *list);
  279. extern int iommu_request_dm_for_dev(struct device *dev);
  280. extern struct iommu_resv_region *
  281. iommu_alloc_resv_region(phys_addr_t start, size_t length, int prot,
  282. enum iommu_resv_type type);
  283. extern int iommu_get_group_resv_regions(struct iommu_group *group,
  284. struct list_head *head);
  285. extern int iommu_attach_group(struct iommu_domain *domain,
  286. struct iommu_group *group);
  287. extern void iommu_detach_group(struct iommu_domain *domain,
  288. struct iommu_group *group);
  289. extern struct iommu_group *iommu_group_alloc(void);
  290. extern void *iommu_group_get_iommudata(struct iommu_group *group);
  291. extern void iommu_group_set_iommudata(struct iommu_group *group,
  292. void *iommu_data,
  293. void (*release)(void *iommu_data));
  294. extern int iommu_group_set_name(struct iommu_group *group, const char *name);
  295. extern int iommu_group_add_device(struct iommu_group *group,
  296. struct device *dev);
  297. extern void iommu_group_remove_device(struct device *dev);
  298. extern int iommu_group_for_each_dev(struct iommu_group *group, void *data,
  299. int (*fn)(struct device *, void *));
  300. extern struct iommu_group *iommu_group_get(struct device *dev);
  301. extern struct iommu_group *iommu_group_ref_get(struct iommu_group *group);
  302. extern void iommu_group_put(struct iommu_group *group);
  303. extern int iommu_group_register_notifier(struct iommu_group *group,
  304. struct notifier_block *nb);
  305. extern int iommu_group_unregister_notifier(struct iommu_group *group,
  306. struct notifier_block *nb);
  307. extern int iommu_group_id(struct iommu_group *group);
  308. extern struct iommu_group *iommu_group_get_for_dev(struct device *dev);
  309. extern struct iommu_domain *iommu_group_default_domain(struct iommu_group *);
  310. extern int iommu_domain_get_attr(struct iommu_domain *domain, enum iommu_attr,
  311. void *data);
  312. extern int iommu_domain_set_attr(struct iommu_domain *domain, enum iommu_attr,
  313. void *data);
  314. /* Window handling function prototypes */
  315. extern int iommu_domain_window_enable(struct iommu_domain *domain, u32 wnd_nr,
  316. phys_addr_t offset, u64 size,
  317. int prot);
  318. extern void iommu_domain_window_disable(struct iommu_domain *domain, u32 wnd_nr);
  319. extern int report_iommu_fault(struct iommu_domain *domain, struct device *dev,
  320. unsigned long iova, int flags);
  321. static inline void iommu_flush_tlb_all(struct iommu_domain *domain)
  322. {
  323. if (domain->ops->flush_iotlb_all)
  324. domain->ops->flush_iotlb_all(domain);
  325. }
  326. static inline void iommu_tlb_range_add(struct iommu_domain *domain,
  327. unsigned long iova, size_t size)
  328. {
  329. if (domain->ops->iotlb_range_add)
  330. domain->ops->iotlb_range_add(domain, iova, size);
  331. }
  332. static inline void iommu_tlb_sync(struct iommu_domain *domain)
  333. {
  334. if (domain->ops->iotlb_sync)
  335. domain->ops->iotlb_sync(domain);
  336. }
  337. /* PCI device grouping function */
  338. extern struct iommu_group *pci_device_group(struct device *dev);
  339. /* Generic device grouping function */
  340. extern struct iommu_group *generic_device_group(struct device *dev);
  341. /* FSL-MC device grouping function */
  342. struct iommu_group *fsl_mc_device_group(struct device *dev);
  343. /**
  344. * struct iommu_fwspec - per-device IOMMU instance data
  345. * @ops: ops for this device's IOMMU
  346. * @iommu_fwnode: firmware handle for this device's IOMMU
  347. * @iommu_priv: IOMMU driver private data for this device
  348. * @num_ids: number of associated device IDs
  349. * @ids: IDs which this device may present to the IOMMU
  350. */
  351. struct iommu_fwspec {
  352. const struct iommu_ops *ops;
  353. struct fwnode_handle *iommu_fwnode;
  354. void *iommu_priv;
  355. unsigned int num_ids;
  356. u32 ids[1];
  357. };
  358. int iommu_fwspec_init(struct device *dev, struct fwnode_handle *iommu_fwnode,
  359. const struct iommu_ops *ops);
  360. void iommu_fwspec_free(struct device *dev);
  361. int iommu_fwspec_add_ids(struct device *dev, u32 *ids, int num_ids);
  362. const struct iommu_ops *iommu_ops_from_fwnode(struct fwnode_handle *fwnode);
  363. #else /* CONFIG_IOMMU_API */
  364. struct iommu_ops {};
  365. struct iommu_group {};
  366. struct iommu_fwspec {};
  367. struct iommu_device {};
  368. static inline bool iommu_present(struct bus_type *bus)
  369. {
  370. return false;
  371. }
  372. static inline bool iommu_capable(struct bus_type *bus, enum iommu_cap cap)
  373. {
  374. return false;
  375. }
  376. static inline struct iommu_domain *iommu_domain_alloc(struct bus_type *bus)
  377. {
  378. return NULL;
  379. }
  380. static inline struct iommu_group *iommu_group_get_by_id(int id)
  381. {
  382. return NULL;
  383. }
  384. static inline void iommu_domain_free(struct iommu_domain *domain)
  385. {
  386. }
  387. static inline int iommu_attach_device(struct iommu_domain *domain,
  388. struct device *dev)
  389. {
  390. return -ENODEV;
  391. }
  392. static inline void iommu_detach_device(struct iommu_domain *domain,
  393. struct device *dev)
  394. {
  395. }
  396. static inline struct iommu_domain *iommu_get_domain_for_dev(struct device *dev)
  397. {
  398. return NULL;
  399. }
  400. static inline int iommu_map(struct iommu_domain *domain, unsigned long iova,
  401. phys_addr_t paddr, size_t size, int prot)
  402. {
  403. return -ENODEV;
  404. }
  405. static inline size_t iommu_unmap(struct iommu_domain *domain,
  406. unsigned long iova, size_t size)
  407. {
  408. return 0;
  409. }
  410. static inline size_t iommu_unmap_fast(struct iommu_domain *domain,
  411. unsigned long iova, int gfp_order)
  412. {
  413. return 0;
  414. }
  415. static inline size_t iommu_map_sg(struct iommu_domain *domain,
  416. unsigned long iova, struct scatterlist *sg,
  417. unsigned int nents, int prot)
  418. {
  419. return 0;
  420. }
  421. static inline void iommu_flush_tlb_all(struct iommu_domain *domain)
  422. {
  423. }
  424. static inline void iommu_tlb_range_add(struct iommu_domain *domain,
  425. unsigned long iova, size_t size)
  426. {
  427. }
  428. static inline void iommu_tlb_sync(struct iommu_domain *domain)
  429. {
  430. }
  431. static inline int iommu_domain_window_enable(struct iommu_domain *domain,
  432. u32 wnd_nr, phys_addr_t paddr,
  433. u64 size, int prot)
  434. {
  435. return -ENODEV;
  436. }
  437. static inline void iommu_domain_window_disable(struct iommu_domain *domain,
  438. u32 wnd_nr)
  439. {
  440. }
  441. static inline phys_addr_t iommu_iova_to_phys(struct iommu_domain *domain, dma_addr_t iova)
  442. {
  443. return 0;
  444. }
  445. static inline void iommu_set_fault_handler(struct iommu_domain *domain,
  446. iommu_fault_handler_t handler, void *token)
  447. {
  448. }
  449. static inline void iommu_get_resv_regions(struct device *dev,
  450. struct list_head *list)
  451. {
  452. }
  453. static inline void iommu_put_resv_regions(struct device *dev,
  454. struct list_head *list)
  455. {
  456. }
  457. static inline int iommu_get_group_resv_regions(struct iommu_group *group,
  458. struct list_head *head)
  459. {
  460. return -ENODEV;
  461. }
  462. static inline int iommu_request_dm_for_dev(struct device *dev)
  463. {
  464. return -ENODEV;
  465. }
  466. static inline int iommu_attach_group(struct iommu_domain *domain,
  467. struct iommu_group *group)
  468. {
  469. return -ENODEV;
  470. }
  471. static inline void iommu_detach_group(struct iommu_domain *domain,
  472. struct iommu_group *group)
  473. {
  474. }
  475. static inline struct iommu_group *iommu_group_alloc(void)
  476. {
  477. return ERR_PTR(-ENODEV);
  478. }
  479. static inline void *iommu_group_get_iommudata(struct iommu_group *group)
  480. {
  481. return NULL;
  482. }
  483. static inline void iommu_group_set_iommudata(struct iommu_group *group,
  484. void *iommu_data,
  485. void (*release)(void *iommu_data))
  486. {
  487. }
  488. static inline int iommu_group_set_name(struct iommu_group *group,
  489. const char *name)
  490. {
  491. return -ENODEV;
  492. }
  493. static inline int iommu_group_add_device(struct iommu_group *group,
  494. struct device *dev)
  495. {
  496. return -ENODEV;
  497. }
  498. static inline void iommu_group_remove_device(struct device *dev)
  499. {
  500. }
  501. static inline int iommu_group_for_each_dev(struct iommu_group *group,
  502. void *data,
  503. int (*fn)(struct device *, void *))
  504. {
  505. return -ENODEV;
  506. }
  507. static inline struct iommu_group *iommu_group_get(struct device *dev)
  508. {
  509. return NULL;
  510. }
  511. static inline void iommu_group_put(struct iommu_group *group)
  512. {
  513. }
  514. static inline int iommu_group_register_notifier(struct iommu_group *group,
  515. struct notifier_block *nb)
  516. {
  517. return -ENODEV;
  518. }
  519. static inline int iommu_group_unregister_notifier(struct iommu_group *group,
  520. struct notifier_block *nb)
  521. {
  522. return 0;
  523. }
  524. static inline int iommu_group_id(struct iommu_group *group)
  525. {
  526. return -ENODEV;
  527. }
  528. static inline int iommu_domain_get_attr(struct iommu_domain *domain,
  529. enum iommu_attr attr, void *data)
  530. {
  531. return -EINVAL;
  532. }
  533. static inline int iommu_domain_set_attr(struct iommu_domain *domain,
  534. enum iommu_attr attr, void *data)
  535. {
  536. return -EINVAL;
  537. }
  538. static inline int iommu_device_register(struct iommu_device *iommu)
  539. {
  540. return -ENODEV;
  541. }
  542. static inline void iommu_device_set_ops(struct iommu_device *iommu,
  543. const struct iommu_ops *ops)
  544. {
  545. }
  546. static inline void iommu_device_set_fwnode(struct iommu_device *iommu,
  547. struct fwnode_handle *fwnode)
  548. {
  549. }
  550. static inline struct iommu_device *dev_to_iommu_device(struct device *dev)
  551. {
  552. return NULL;
  553. }
  554. static inline void iommu_device_unregister(struct iommu_device *iommu)
  555. {
  556. }
  557. static inline int iommu_device_sysfs_add(struct iommu_device *iommu,
  558. struct device *parent,
  559. const struct attribute_group **groups,
  560. const char *fmt, ...)
  561. {
  562. return -ENODEV;
  563. }
  564. static inline void iommu_device_sysfs_remove(struct iommu_device *iommu)
  565. {
  566. }
  567. static inline int iommu_device_link(struct device *dev, struct device *link)
  568. {
  569. return -EINVAL;
  570. }
  571. static inline void iommu_device_unlink(struct device *dev, struct device *link)
  572. {
  573. }
  574. static inline int iommu_fwspec_init(struct device *dev,
  575. struct fwnode_handle *iommu_fwnode,
  576. const struct iommu_ops *ops)
  577. {
  578. return -ENODEV;
  579. }
  580. static inline void iommu_fwspec_free(struct device *dev)
  581. {
  582. }
  583. static inline int iommu_fwspec_add_ids(struct device *dev, u32 *ids,
  584. int num_ids)
  585. {
  586. return -ENODEV;
  587. }
  588. static inline
  589. const struct iommu_ops *iommu_ops_from_fwnode(struct fwnode_handle *fwnode)
  590. {
  591. return NULL;
  592. }
  593. #endif /* CONFIG_IOMMU_API */
  594. #ifdef CONFIG_IOMMU_DEBUGFS
  595. extern struct dentry *iommu_debugfs_dir;
  596. void iommu_debugfs_setup(void);
  597. #else
  598. static inline void iommu_debugfs_setup(void) {}
  599. #endif
  600. #endif /* __LINUX_IOMMU_H */