qcom-iommu-debug.h 2.7 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576
  1. /* SPDX-License-Identifier: GPL-2.0-only */
  2. /*
  3. * Copyright (c) 2015-2021, The Linux Foundation. All rights reserved.
  4. * Copyright (c) 2022, Qualcomm Innovation Center, Inc. All rights reserved.
  5. */
  6. #ifndef __DRIVERS_IOMMU_QCOM_IOMMU_DEBUG_H__
  7. #define __DRIVERS_IOMMU_QCOM_IOMMU_DEBUG_H__
  8. #include <linux/device.h>
  9. #include <linux/debugfs.h>
  10. #include <linux/iommu.h>
  11. #include <linux/completion.h>
  12. #include <linux/mutex.h>
  13. #define MSI_IOVA_BASE 0x8000000
  14. #define MSI_IOVA_LENGTH 0x100000
  15. #define ARM_SMMU_SMR_ID GENMASK(15, 0)
  16. struct iommu_debug_device {
  17. struct device *self;
  18. u32 nr_children;
  19. char *buffer;
  20. struct dentry *root_dir;
  21. /* for usecase under test */
  22. struct device *test_dev;
  23. struct iommu_domain *domain;
  24. u32 usecase_nr;
  25. bool fastmap_usecase;
  26. /* Protects test_dev */
  27. struct mutex state_lock;
  28. /* For waiting for child probe to complete */
  29. struct completion probe_wait;
  30. /* Used for atos */
  31. u64 iova;
  32. /* number of iterations */
  33. u32 nr_iters;
  34. };
  35. struct device *iommu_debug_usecase_reset(struct iommu_debug_device *ddev);
  36. struct device *iommu_debug_switch_usecase(struct iommu_debug_device *ddev, u32 usecase_nr);
  37. int iommu_debug_check_mapping_flags(struct device *dev, dma_addr_t iova, size_t size,
  38. phys_addr_t expected_pa, u32 flags);
  39. #define iommu_debug_check_mapping(d, i, s, p) \
  40. iommu_debug_check_mapping_flags(d, i, s, p, 0)
  41. /* Only checks a single page */
  42. #define iommu_debug_check_mapping_fast(d, i, s, p) \
  43. iommu_debug_check_mapping_flags(d, i, PAGE_SIZE, p, 0)
  44. int iommu_debug_check_mapping_sg_flags(struct device *dev, struct scatterlist *sgl,
  45. unsigned int pgoffset, unsigned int dma_nents,
  46. unsigned int nents, u32 flags);
  47. #define iommu_debug_check_mapping_sg(d, s, o, e1, e2) \
  48. iommu_debug_check_mapping_sg_flags(d, s, o, e1, e2, 0)
  49. /* Only checks the last page of first sgl */
  50. static inline int iommu_debug_check_mapping_sg_fast(struct device *dev, struct scatterlist *sgl,
  51. unsigned int pgoffset, unsigned int dma_nents,
  52. unsigned int nents)
  53. {
  54. pgoffset = PAGE_ALIGN(sgl->offset + sgl->length) >> PAGE_SHIFT;
  55. return iommu_debug_check_mapping_sg_flags(dev, sgl, pgoffset - 1, dma_nents, 1, 0);
  56. }
  57. extern const struct file_operations iommu_debug_functional_arm_dma_api_fops;
  58. extern const struct file_operations iommu_debug_functional_fast_dma_api_fops;
  59. extern const struct file_operations iommu_debug_atos_fops;
  60. extern const struct file_operations iommu_debug_map_fops;
  61. extern const struct file_operations iommu_debug_unmap_fops;
  62. extern const struct file_operations iommu_debug_dma_map_fops;
  63. extern const struct file_operations iommu_debug_dma_unmap_fops;
  64. extern const struct file_operations iommu_debug_test_virt_addr_fops;
  65. extern const struct file_operations iommu_debug_profiling_fops;
  66. #endif