s5p_mfc_iommu.h 1.9 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879
  1. /*
  2. * Copyright (C) 2015 Samsung Electronics Co.Ltd
  3. * Authors: Marek Szyprowski <[email protected]>
  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 as published by the
  7. * Free Software Foundation; either version 2 of the License, or (at your
  8. * option) any later version.
  9. */
  10. #ifndef S5P_MFC_IOMMU_H_
  11. #define S5P_MFC_IOMMU_H_
  12. #define S5P_MFC_IOMMU_DMA_BASE 0x20000000lu
  13. #define S5P_MFC_IOMMU_DMA_SIZE SZ_256M
  14. #if defined(CONFIG_EXYNOS_IOMMU) && defined(CONFIG_ARM_DMA_USE_IOMMU)
  15. #include <asm/dma-iommu.h>
  16. static inline bool exynos_is_iommu_available(struct device *dev)
  17. {
  18. return dev->archdata.iommu != NULL;
  19. }
  20. static inline void exynos_unconfigure_iommu(struct device *dev)
  21. {
  22. struct dma_iommu_mapping *mapping = to_dma_iommu_mapping(dev);
  23. arm_iommu_detach_device(dev);
  24. arm_iommu_release_mapping(mapping);
  25. }
  26. static inline int exynos_configure_iommu(struct device *dev,
  27. unsigned int base, unsigned int size)
  28. {
  29. struct dma_iommu_mapping *mapping = NULL;
  30. int ret;
  31. /* Disable the default mapping created by device core */
  32. if (to_dma_iommu_mapping(dev))
  33. exynos_unconfigure_iommu(dev);
  34. mapping = arm_iommu_create_mapping(dev->bus, base, size);
  35. if (IS_ERR(mapping)) {
  36. pr_warn("Failed to create IOMMU mapping for device %s\n",
  37. dev_name(dev));
  38. return PTR_ERR(mapping);
  39. }
  40. ret = arm_iommu_attach_device(dev, mapping);
  41. if (ret) {
  42. pr_warn("Failed to attached device %s to IOMMU_mapping\n",
  43. dev_name(dev));
  44. arm_iommu_release_mapping(mapping);
  45. return ret;
  46. }
  47. return 0;
  48. }
  49. #else
  50. static inline bool exynos_is_iommu_available(struct device *dev)
  51. {
  52. return false;
  53. }
  54. static inline int exynos_configure_iommu(struct device *dev,
  55. unsigned int base, unsigned int size)
  56. {
  57. return -ENOSYS;
  58. }
  59. static inline void exynos_unconfigure_iommu(struct device *dev) { }
  60. #endif
  61. #endif /* S5P_MFC_IOMMU_H_ */