2
0

smmu-internal.h 3.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899
  1. /*
  2. * ARM SMMU support - Internal API
  3. *
  4. * Copyright (c) 2017 Red Hat, Inc.
  5. * Copyright (C) 2014-2016 Broadcom Corporation
  6. * Written by Prem Mallappa, Eric Auger
  7. *
  8. * This program is free software; you can redistribute it and/or modify
  9. * it under the terms of the GNU General Public License version 2 as
  10. * published by the Free Software Foundation.
  11. *
  12. * This program is distributed in the hope that it will be useful,
  13. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  14. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  15. * General Public License for more details.
  16. *
  17. * You should have received a copy of the GNU General Public License along
  18. * with this program; if not, see <http://www.gnu.org/licenses/>.
  19. */
  20. #ifndef HW_ARM_SMMU_INTERNAL_H
  21. #define HW_ARM_SMMU_INTERNAL_H
  22. #define TBI0(tbi) ((tbi) & 0x1)
  23. #define TBI1(tbi) ((tbi) & 0x2 >> 1)
  24. /* PTE Manipulation */
  25. #define ARM_LPAE_PTE_TYPE_SHIFT 0
  26. #define ARM_LPAE_PTE_TYPE_MASK 0x3
  27. #define ARM_LPAE_PTE_TYPE_BLOCK 1
  28. #define ARM_LPAE_PTE_TYPE_TABLE 3
  29. #define ARM_LPAE_L3_PTE_TYPE_RESERVED 1
  30. #define ARM_LPAE_L3_PTE_TYPE_PAGE 3
  31. #define ARM_LPAE_PTE_VALID (1 << 0)
  32. #define PTE_ADDRESS(pte, shift) \
  33. (extract64(pte, shift, 47 - shift + 1) << shift)
  34. #define is_invalid_pte(pte) (!(pte & ARM_LPAE_PTE_VALID))
  35. #define is_reserved_pte(pte, level) \
  36. ((level == 3) && \
  37. ((pte & ARM_LPAE_PTE_TYPE_MASK) == ARM_LPAE_L3_PTE_TYPE_RESERVED))
  38. #define is_block_pte(pte, level) \
  39. ((level < 3) && \
  40. ((pte & ARM_LPAE_PTE_TYPE_MASK) == ARM_LPAE_PTE_TYPE_BLOCK))
  41. #define is_table_pte(pte, level) \
  42. ((level < 3) && \
  43. ((pte & ARM_LPAE_PTE_TYPE_MASK) == ARM_LPAE_PTE_TYPE_TABLE))
  44. #define is_page_pte(pte, level) \
  45. ((level == 3) && \
  46. ((pte & ARM_LPAE_PTE_TYPE_MASK) == ARM_LPAE_L3_PTE_TYPE_PAGE))
  47. /* access permissions */
  48. #define PTE_AP(pte) \
  49. (extract64(pte, 6, 2))
  50. #define PTE_APTABLE(pte) \
  51. (extract64(pte, 61, 2))
  52. /*
  53. * TODO: At the moment all transactions are considered as privileged (EL1)
  54. * as IOMMU translation callback does not pass user/priv attributes.
  55. */
  56. #define is_permission_fault(ap, perm) \
  57. (((perm) & IOMMU_WO) && ((ap) & 0x2))
  58. #define PTE_AP_TO_PERM(ap) \
  59. (IOMMU_ACCESS_FLAG(true, !((ap) & 0x2)))
  60. /* Level Indexing */
  61. static inline int level_shift(int level, int granule_sz)
  62. {
  63. return granule_sz + (3 - level) * (granule_sz - 3);
  64. }
  65. static inline uint64_t level_page_mask(int level, int granule_sz)
  66. {
  67. return ~(MAKE_64BIT_MASK(0, level_shift(level, granule_sz)));
  68. }
  69. static inline
  70. uint64_t iova_level_offset(uint64_t iova, int inputsize,
  71. int level, int gsz)
  72. {
  73. return ((iova & MAKE_64BIT_MASK(0, inputsize)) >> level_shift(level, gsz)) &
  74. MAKE_64BIT_MASK(0, gsz - 3);
  75. }
  76. #endif