iommu.h 3.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128
  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/errno.h>
  21. #define IOMMU_READ (1)
  22. #define IOMMU_WRITE (2)
  23. #define IOMMU_CACHE (4) /* DMA cache coherency */
  24. struct bus_type;
  25. struct device;
  26. struct iommu_domain {
  27. void *priv;
  28. };
  29. #define IOMMU_CAP_CACHE_COHERENCY 0x1
  30. #define IOMMU_CAP_INTR_REMAP 0x2 /* isolates device intrs */
  31. #ifdef CONFIG_IOMMU_API
  32. struct iommu_ops {
  33. int (*domain_init)(struct iommu_domain *domain);
  34. void (*domain_destroy)(struct iommu_domain *domain);
  35. int (*attach_dev)(struct iommu_domain *domain, struct device *dev);
  36. void (*detach_dev)(struct iommu_domain *domain, struct device *dev);
  37. int (*map)(struct iommu_domain *domain, unsigned long iova,
  38. phys_addr_t paddr, int gfp_order, int prot);
  39. int (*unmap)(struct iommu_domain *domain, unsigned long iova,
  40. int gfp_order);
  41. phys_addr_t (*iova_to_phys)(struct iommu_domain *domain,
  42. unsigned long iova);
  43. int (*domain_has_cap)(struct iommu_domain *domain,
  44. unsigned long cap);
  45. };
  46. extern void register_iommu(struct iommu_ops *ops);
  47. extern int bus_set_iommu(struct bus_type *bus, struct iommu_ops *ops);
  48. extern bool iommu_found(void);
  49. extern struct iommu_domain *iommu_domain_alloc(void);
  50. extern void iommu_domain_free(struct iommu_domain *domain);
  51. extern int iommu_attach_device(struct iommu_domain *domain,
  52. struct device *dev);
  53. extern void iommu_detach_device(struct iommu_domain *domain,
  54. struct device *dev);
  55. extern int iommu_map(struct iommu_domain *domain, unsigned long iova,
  56. phys_addr_t paddr, int gfp_order, int prot);
  57. extern int iommu_unmap(struct iommu_domain *domain, unsigned long iova,
  58. int gfp_order);
  59. extern phys_addr_t iommu_iova_to_phys(struct iommu_domain *domain,
  60. unsigned long iova);
  61. extern int iommu_domain_has_cap(struct iommu_domain *domain,
  62. unsigned long cap);
  63. #else /* CONFIG_IOMMU_API */
  64. struct iommu_ops {};
  65. static inline bool iommu_found(void)
  66. {
  67. return false;
  68. }
  69. static inline struct iommu_domain *iommu_domain_alloc(void)
  70. {
  71. return NULL;
  72. }
  73. static inline void iommu_domain_free(struct iommu_domain *domain)
  74. {
  75. }
  76. static inline int iommu_attach_device(struct iommu_domain *domain,
  77. struct device *dev)
  78. {
  79. return -ENODEV;
  80. }
  81. static inline void iommu_detach_device(struct iommu_domain *domain,
  82. struct device *dev)
  83. {
  84. }
  85. static inline int iommu_map(struct iommu_domain *domain, unsigned long iova,
  86. phys_addr_t paddr, int gfp_order, int prot)
  87. {
  88. return -ENODEV;
  89. }
  90. static inline int iommu_unmap(struct iommu_domain *domain, unsigned long iova,
  91. int gfp_order)
  92. {
  93. return -ENODEV;
  94. }
  95. static inline phys_addr_t iommu_iova_to_phys(struct iommu_domain *domain,
  96. unsigned long iova)
  97. {
  98. return 0;
  99. }
  100. static inline int domain_has_cap(struct iommu_domain *domain,
  101. unsigned long cap)
  102. {
  103. return 0;
  104. }
  105. #endif /* CONFIG_IOMMU_API */
  106. #endif /* __LINUX_IOMMU_H */