cap_audit.h 3.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131
  1. /* SPDX-License-Identifier: GPL-2.0 */
  2. /*
  3. * cap_audit.h - audit iommu capabilities header
  4. *
  5. * Copyright (C) 2021 Intel Corporation
  6. *
  7. * Author: Kyung Min Park <[email protected]>
  8. */
  9. /*
  10. * Capability Register Mask
  11. */
  12. #define CAP_FL5LP_MASK BIT_ULL(60)
  13. #define CAP_PI_MASK BIT_ULL(59)
  14. #define CAP_FL1GP_MASK BIT_ULL(56)
  15. #define CAP_RD_MASK BIT_ULL(55)
  16. #define CAP_WD_MASK BIT_ULL(54)
  17. #define CAP_MAMV_MASK GENMASK_ULL(53, 48)
  18. #define CAP_NFR_MASK GENMASK_ULL(47, 40)
  19. #define CAP_PSI_MASK BIT_ULL(39)
  20. #define CAP_SLLPS_MASK GENMASK_ULL(37, 34)
  21. #define CAP_FRO_MASK GENMASK_ULL(33, 24)
  22. #define CAP_ZLR_MASK BIT_ULL(22)
  23. #define CAP_MGAW_MASK GENMASK_ULL(21, 16)
  24. #define CAP_SAGAW_MASK GENMASK_ULL(12, 8)
  25. #define CAP_CM_MASK BIT_ULL(7)
  26. #define CAP_PHMR_MASK BIT_ULL(6)
  27. #define CAP_PLMR_MASK BIT_ULL(5)
  28. #define CAP_RWBF_MASK BIT_ULL(4)
  29. #define CAP_AFL_MASK BIT_ULL(3)
  30. #define CAP_NDOMS_MASK GENMASK_ULL(2, 0)
  31. /*
  32. * Extended Capability Register Mask
  33. */
  34. #define ECAP_RPS_MASK BIT_ULL(49)
  35. #define ECAP_SMPWC_MASK BIT_ULL(48)
  36. #define ECAP_FLTS_MASK BIT_ULL(47)
  37. #define ECAP_SLTS_MASK BIT_ULL(46)
  38. #define ECAP_SLADS_MASK BIT_ULL(45)
  39. #define ECAP_VCS_MASK BIT_ULL(44)
  40. #define ECAP_SMTS_MASK BIT_ULL(43)
  41. #define ECAP_PDS_MASK BIT_ULL(42)
  42. #define ECAP_DIT_MASK BIT_ULL(41)
  43. #define ECAP_PASID_MASK BIT_ULL(40)
  44. #define ECAP_PSS_MASK GENMASK_ULL(39, 35)
  45. #define ECAP_EAFS_MASK BIT_ULL(34)
  46. #define ECAP_NWFS_MASK BIT_ULL(33)
  47. #define ECAP_SRS_MASK BIT_ULL(31)
  48. #define ECAP_ERS_MASK BIT_ULL(30)
  49. #define ECAP_PRS_MASK BIT_ULL(29)
  50. #define ECAP_NEST_MASK BIT_ULL(26)
  51. #define ECAP_MTS_MASK BIT_ULL(25)
  52. #define ECAP_MHMV_MASK GENMASK_ULL(23, 20)
  53. #define ECAP_IRO_MASK GENMASK_ULL(17, 8)
  54. #define ECAP_SC_MASK BIT_ULL(7)
  55. #define ECAP_PT_MASK BIT_ULL(6)
  56. #define ECAP_EIM_MASK BIT_ULL(4)
  57. #define ECAP_DT_MASK BIT_ULL(2)
  58. #define ECAP_QI_MASK BIT_ULL(1)
  59. #define ECAP_C_MASK BIT_ULL(0)
  60. /*
  61. * u64 intel_iommu_cap_sanity, intel_iommu_ecap_sanity will be adjusted as each
  62. * IOMMU gets audited.
  63. */
  64. #define DO_CHECK_FEATURE_MISMATCH(a, b, cap, feature, MASK) \
  65. do { \
  66. if (cap##_##feature(a) != cap##_##feature(b)) { \
  67. intel_iommu_##cap##_sanity &= ~(MASK); \
  68. pr_info("IOMMU feature %s inconsistent", #feature); \
  69. } \
  70. } while (0)
  71. #define CHECK_FEATURE_MISMATCH(a, b, cap, feature, MASK) \
  72. DO_CHECK_FEATURE_MISMATCH((a)->cap, (b)->cap, cap, feature, MASK)
  73. #define CHECK_FEATURE_MISMATCH_HOTPLUG(b, cap, feature, MASK) \
  74. do { \
  75. if (cap##_##feature(intel_iommu_##cap##_sanity)) \
  76. DO_CHECK_FEATURE_MISMATCH(intel_iommu_##cap##_sanity, \
  77. (b)->cap, cap, feature, MASK); \
  78. } while (0)
  79. #define MINIMAL_FEATURE_IOMMU(iommu, cap, MASK) \
  80. do { \
  81. u64 min_feature = intel_iommu_##cap##_sanity & (MASK); \
  82. min_feature = min_t(u64, min_feature, (iommu)->cap & (MASK)); \
  83. intel_iommu_##cap##_sanity = (intel_iommu_##cap##_sanity & ~(MASK)) | \
  84. min_feature; \
  85. } while (0)
  86. #define MINIMAL_FEATURE_HOTPLUG(iommu, cap, feature, MASK, mismatch) \
  87. do { \
  88. if ((intel_iommu_##cap##_sanity & (MASK)) > \
  89. (cap##_##feature((iommu)->cap))) \
  90. mismatch = true; \
  91. else \
  92. (iommu)->cap = ((iommu)->cap & ~(MASK)) | \
  93. (intel_iommu_##cap##_sanity & (MASK)); \
  94. } while (0)
  95. enum cap_audit_type {
  96. CAP_AUDIT_STATIC_DMAR,
  97. CAP_AUDIT_STATIC_IRQR,
  98. CAP_AUDIT_HOTPLUG_DMAR,
  99. CAP_AUDIT_HOTPLUG_IRQR,
  100. };
  101. bool intel_cap_smts_sanity(void);
  102. bool intel_cap_pasid_sanity(void);
  103. bool intel_cap_nest_sanity(void);
  104. bool intel_cap_flts_sanity(void);
  105. bool intel_cap_slts_sanity(void);
  106. static inline bool scalable_mode_support(void)
  107. {
  108. return (intel_iommu_sm && intel_cap_smts_sanity());
  109. }
  110. static inline bool pasid_mode_support(void)
  111. {
  112. return scalable_mode_support() && intel_cap_pasid_sanity();
  113. }
  114. static inline bool nested_mode_support(void)
  115. {
  116. return scalable_mode_support() && intel_cap_nest_sanity();
  117. }
  118. int intel_cap_audit(enum cap_audit_type type, struct intel_iommu *iommu);