exynos_drm_iommu.h 3.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134
  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. priv->mapping = iommu_get_domain_for_dev(priv->dma_dev);
  48. return 0;
  49. }
  50. static inline void __exynos_iommu_release_mapping(struct exynos_drm_private *priv)
  51. {
  52. priv->mapping = NULL;
  53. }
  54. static inline int __exynos_iommu_attach(struct exynos_drm_private *priv,
  55. struct device *dev)
  56. {
  57. struct iommu_domain *domain = priv->mapping;
  58. if (dev != priv->dma_dev)
  59. return iommu_attach_device(domain, dev);
  60. return 0;
  61. }
  62. static inline void __exynos_iommu_detach(struct exynos_drm_private *priv,
  63. struct device *dev)
  64. {
  65. struct iommu_domain *domain = priv->mapping;
  66. if (dev != priv->dma_dev)
  67. iommu_detach_device(domain, dev);
  68. }
  69. #else
  70. #error Unsupported architecture and IOMMU/DMA-mapping glue code
  71. #endif
  72. int drm_create_iommu_mapping(struct drm_device *drm_dev);
  73. void drm_release_iommu_mapping(struct drm_device *drm_dev);
  74. int drm_iommu_attach_device(struct drm_device *drm_dev,
  75. struct device *subdrv_dev);
  76. void drm_iommu_detach_device(struct drm_device *dev_dev,
  77. struct device *subdrv_dev);
  78. static inline bool is_drm_iommu_supported(struct drm_device *drm_dev)
  79. {
  80. struct exynos_drm_private *priv = drm_dev->dev_private;
  81. return priv->mapping ? true : false;
  82. }
  83. #else
  84. static inline int drm_create_iommu_mapping(struct drm_device *drm_dev)
  85. {
  86. return 0;
  87. }
  88. static inline void drm_release_iommu_mapping(struct drm_device *drm_dev)
  89. {
  90. }
  91. static inline int drm_iommu_attach_device(struct drm_device *drm_dev,
  92. struct device *subdrv_dev)
  93. {
  94. return 0;
  95. }
  96. static inline void drm_iommu_detach_device(struct drm_device *drm_dev,
  97. struct device *subdrv_dev)
  98. {
  99. }
  100. static inline bool is_drm_iommu_supported(struct drm_device *drm_dev)
  101. {
  102. return false;
  103. }
  104. #endif
  105. #endif