exynos_drm_iommu.h 3.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157
  1. /* exynos_drm_iommu.h
  2. *
  3. * Copyright (c) 2012 Samsung Electronics Co., Ltd.
  4. * Authoer: Inki Dae <inki.dae@samsung.com>
  5. *
  6. * This program is free software; you can redistribute it and/or modify it
  7. * under the terms of the GNU General Public License as published by the
  8. * Free Software Foundation; either version 2 of the License, or (at your
  9. * option) any later version.
  10. */
  11. #ifndef _EXYNOS_DRM_IOMMU_H_
  12. #define _EXYNOS_DRM_IOMMU_H_
  13. #define EXYNOS_DEV_ADDR_START 0x20000000
  14. #define EXYNOS_DEV_ADDR_SIZE 0x40000000
  15. #ifdef CONFIG_DRM_EXYNOS_IOMMU
  16. #if defined(CONFIG_ARM_DMA_USE_IOMMU)
  17. #include <asm/dma-iommu.h>
  18. static inline int __exynos_iommu_create_mapping(struct exynos_drm_private *priv,
  19. unsigned long start, unsigned long size)
  20. {
  21. priv->mapping = arm_iommu_create_mapping(&platform_bus_type, start,
  22. size);
  23. return IS_ERR(priv->mapping);
  24. }
  25. static inline void
  26. __exynos_iommu_release_mapping(struct exynos_drm_private *priv)
  27. {
  28. arm_iommu_release_mapping(priv->mapping);
  29. }
  30. static inline int __exynos_iommu_attach(struct exynos_drm_private *priv,
  31. struct device *dev)
  32. {
  33. if (dev->archdata.mapping)
  34. arm_iommu_detach_device(dev);
  35. return arm_iommu_attach_device(dev, priv->mapping);
  36. }
  37. static inline void __exynos_iommu_detach(struct exynos_drm_private *priv,
  38. struct device *dev)
  39. {
  40. arm_iommu_detach_device(dev);
  41. }
  42. #elif defined(CONFIG_IOMMU_DMA)
  43. #include <linux/dma-iommu.h>
  44. static inline int __exynos_iommu_create_mapping(struct exynos_drm_private *priv,
  45. unsigned long start, unsigned long size)
  46. {
  47. struct iommu_domain *domain;
  48. int ret;
  49. domain = iommu_domain_alloc(priv->dma_dev->bus);
  50. if (!domain)
  51. return -ENOMEM;
  52. ret = iommu_get_dma_cookie(domain);
  53. if (ret)
  54. goto free_domain;
  55. ret = iommu_dma_init_domain(domain, start, size, NULL);
  56. if (ret)
  57. goto put_cookie;
  58. priv->mapping = domain;
  59. return 0;
  60. put_cookie:
  61. iommu_put_dma_cookie(domain);
  62. free_domain:
  63. iommu_domain_free(domain);
  64. return ret;
  65. }
  66. static inline void __exynos_iommu_release_mapping(struct exynos_drm_private *priv)
  67. {
  68. struct iommu_domain *domain = priv->mapping;
  69. iommu_put_dma_cookie(domain);
  70. iommu_domain_free(domain);
  71. priv->mapping = NULL;
  72. }
  73. static inline int __exynos_iommu_attach(struct exynos_drm_private *priv,
  74. struct device *dev)
  75. {
  76. struct iommu_domain *domain = priv->mapping;
  77. return iommu_attach_device(domain, dev);
  78. }
  79. static inline void __exynos_iommu_detach(struct exynos_drm_private *priv,
  80. struct device *dev)
  81. {
  82. struct iommu_domain *domain = priv->mapping;
  83. iommu_detach_device(domain, dev);
  84. }
  85. #else
  86. #error Unsupported architecture and IOMMU/DMA-mapping glue code
  87. #endif
  88. int drm_create_iommu_mapping(struct drm_device *drm_dev);
  89. void drm_release_iommu_mapping(struct drm_device *drm_dev);
  90. int drm_iommu_attach_device(struct drm_device *drm_dev,
  91. struct device *subdrv_dev);
  92. void drm_iommu_detach_device(struct drm_device *dev_dev,
  93. struct device *subdrv_dev);
  94. static inline bool is_drm_iommu_supported(struct drm_device *drm_dev)
  95. {
  96. struct exynos_drm_private *priv = drm_dev->dev_private;
  97. return priv->mapping ? true : false;
  98. }
  99. #else
  100. static inline int drm_create_iommu_mapping(struct drm_device *drm_dev)
  101. {
  102. return 0;
  103. }
  104. static inline void drm_release_iommu_mapping(struct drm_device *drm_dev)
  105. {
  106. }
  107. static inline int drm_iommu_attach_device(struct drm_device *drm_dev,
  108. struct device *subdrv_dev)
  109. {
  110. return 0;
  111. }
  112. static inline void drm_iommu_detach_device(struct drm_device *drm_dev,
  113. struct device *subdrv_dev)
  114. {
  115. }
  116. static inline bool is_drm_iommu_supported(struct drm_device *drm_dev)
  117. {
  118. return false;
  119. }
  120. #endif
  121. #endif