iommu.c 2.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107
  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. #include <linux/bug.h>
  19. #include <linux/types.h>
  20. #include <linux/errno.h>
  21. #include <linux/iommu.h>
  22. static struct iommu_ops *iommu_ops;
  23. void register_iommu(struct iommu_ops *ops)
  24. {
  25. if (iommu_ops)
  26. BUG();
  27. iommu_ops = ops;
  28. }
  29. bool iommu_found(void)
  30. {
  31. return iommu_ops != NULL;
  32. }
  33. EXPORT_SYMBOL_GPL(iommu_found);
  34. struct iommu_domain *iommu_domain_alloc(void)
  35. {
  36. struct iommu_domain *domain;
  37. int ret;
  38. domain = kmalloc(sizeof(*domain), GFP_KERNEL);
  39. if (!domain)
  40. return NULL;
  41. ret = iommu_ops->domain_init(domain);
  42. if (ret)
  43. goto out_free;
  44. return domain;
  45. out_free:
  46. kfree(domain);
  47. return NULL;
  48. }
  49. EXPORT_SYMBOL_GPL(iommu_domain_alloc);
  50. void iommu_domain_free(struct iommu_domain *domain)
  51. {
  52. iommu_ops->domain_destroy(domain);
  53. kfree(domain);
  54. }
  55. EXPORT_SYMBOL_GPL(iommu_domain_free);
  56. int iommu_attach_device(struct iommu_domain *domain, struct device *dev)
  57. {
  58. return iommu_ops->attach_dev(domain, dev);
  59. }
  60. EXPORT_SYMBOL_GPL(iommu_attach_device);
  61. void iommu_detach_device(struct iommu_domain *domain, struct device *dev)
  62. {
  63. iommu_ops->detach_dev(domain, dev);
  64. }
  65. EXPORT_SYMBOL_GPL(iommu_detach_device);
  66. int iommu_map_range(struct iommu_domain *domain, unsigned long iova,
  67. phys_addr_t paddr, size_t size, int prot)
  68. {
  69. return iommu_ops->map(domain, iova, paddr, size, prot);
  70. }
  71. EXPORT_SYMBOL_GPL(iommu_map_range);
  72. void iommu_unmap_range(struct iommu_domain *domain, unsigned long iova,
  73. size_t size)
  74. {
  75. iommu_ops->unmap(domain, iova, size);
  76. }
  77. EXPORT_SYMBOL_GPL(iommu_unmap_range);
  78. phys_addr_t iommu_iova_to_phys(struct iommu_domain *domain,
  79. unsigned long iova)
  80. {
  81. return iommu_ops->iova_to_phys(domain, iova);
  82. }
  83. EXPORT_SYMBOL_GPL(iommu_iova_to_phys);
  84. int iommu_domain_has_cap(struct iommu_domain *domain,
  85. unsigned long cap)
  86. {
  87. return iommu_ops->domain_has_cap(domain, cap);
  88. }
  89. EXPORT_SYMBOL_GPL(iommu_domain_has_cap);