Skip to content

Commit 010bf56

Browse files
Kyung Min Parkjoergroedel
authored andcommitted
iommu/vt-d: Move capability check code to cap_audit files
Move IOMMU capability check and sanity check code to cap_audit files. Also implement some helper functions for sanity checks. Signed-off-by: Kyung Min Park <[email protected]> Signed-off-by: Lu Baolu <[email protected]> Link: https://lore.kernel.org/r/[email protected] Link: https://lore.kernel.org/r/[email protected] Signed-off-by: Joerg Roedel <[email protected]>
1 parent ad3d190 commit 010bf56

File tree

3 files changed

+42
-74
lines changed

3 files changed

+42
-74
lines changed

drivers/iommu/intel/cap_audit.c

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -183,3 +183,23 @@ int intel_cap_audit(enum cap_audit_type type, struct intel_iommu *iommu)
183183

184184
return -EFAULT;
185185
}
186+
187+
bool intel_cap_smts_sanity(void)
188+
{
189+
return ecap_smts(intel_iommu_ecap_sanity);
190+
}
191+
192+
bool intel_cap_pasid_sanity(void)
193+
{
194+
return ecap_pasid(intel_iommu_ecap_sanity);
195+
}
196+
197+
bool intel_cap_nest_sanity(void)
198+
{
199+
return ecap_nest(intel_iommu_ecap_sanity);
200+
}
201+
202+
bool intel_cap_flts_sanity(void)
203+
{
204+
return ecap_flts(intel_iommu_ecap_sanity);
205+
}

drivers/iommu/intel/cap_audit.h

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -107,4 +107,24 @@ enum cap_audit_type {
107107
CAP_AUDIT_HOTPLUG_IRQR,
108108
};
109109

110+
bool intel_cap_smts_sanity(void);
111+
bool intel_cap_pasid_sanity(void);
112+
bool intel_cap_nest_sanity(void);
113+
bool intel_cap_flts_sanity(void);
114+
115+
static inline bool scalable_mode_support(void)
116+
{
117+
return (intel_iommu_sm && intel_cap_smts_sanity());
118+
}
119+
120+
static inline bool pasid_mode_support(void)
121+
{
122+
return scalable_mode_support() && intel_cap_pasid_sanity();
123+
}
124+
125+
static inline bool nested_mode_support(void)
126+
{
127+
return scalable_mode_support() && intel_cap_nest_sanity();
128+
}
129+
110130
int intel_cap_audit(enum cap_audit_type type, struct intel_iommu *iommu);

drivers/iommu/intel/iommu.c

Lines changed: 2 additions & 74 deletions
Original file line numberDiff line numberDiff line change
@@ -1864,25 +1864,7 @@ static void free_dmar_iommu(struct intel_iommu *iommu)
18641864
*/
18651865
static bool first_level_by_default(void)
18661866
{
1867-
struct dmar_drhd_unit *drhd;
1868-
struct intel_iommu *iommu;
1869-
static int first_level_support = -1;
1870-
1871-
if (likely(first_level_support != -1))
1872-
return first_level_support;
1873-
1874-
first_level_support = 1;
1875-
1876-
rcu_read_lock();
1877-
for_each_active_iommu(iommu, drhd) {
1878-
if (!sm_supported(iommu) || !ecap_flts(iommu->ecap)) {
1879-
first_level_support = 0;
1880-
break;
1881-
}
1882-
}
1883-
rcu_read_unlock();
1884-
1885-
return first_level_support;
1867+
return scalable_mode_support() && intel_cap_flts_sanity();
18861868
}
18871869

18881870
static struct dmar_domain *alloc_domain(int flags)
@@ -5058,60 +5040,6 @@ static phys_addr_t intel_iommu_iova_to_phys(struct iommu_domain *domain,
50585040
return phys;
50595041
}
50605042

5061-
static inline bool scalable_mode_support(void)
5062-
{
5063-
struct dmar_drhd_unit *drhd;
5064-
struct intel_iommu *iommu;
5065-
bool ret = true;
5066-
5067-
rcu_read_lock();
5068-
for_each_active_iommu(iommu, drhd) {
5069-
if (!sm_supported(iommu)) {
5070-
ret = false;
5071-
break;
5072-
}
5073-
}
5074-
rcu_read_unlock();
5075-
5076-
return ret;
5077-
}
5078-
5079-
static inline bool iommu_pasid_support(void)
5080-
{
5081-
struct dmar_drhd_unit *drhd;
5082-
struct intel_iommu *iommu;
5083-
bool ret = true;
5084-
5085-
rcu_read_lock();
5086-
for_each_active_iommu(iommu, drhd) {
5087-
if (!pasid_supported(iommu)) {
5088-
ret = false;
5089-
break;
5090-
}
5091-
}
5092-
rcu_read_unlock();
5093-
5094-
return ret;
5095-
}
5096-
5097-
static inline bool nested_mode_support(void)
5098-
{
5099-
struct dmar_drhd_unit *drhd;
5100-
struct intel_iommu *iommu;
5101-
bool ret = true;
5102-
5103-
rcu_read_lock();
5104-
for_each_active_iommu(iommu, drhd) {
5105-
if (!sm_supported(iommu) || !ecap_nest(iommu->ecap)) {
5106-
ret = false;
5107-
break;
5108-
}
5109-
}
5110-
rcu_read_unlock();
5111-
5112-
return ret;
5113-
}
5114-
51155043
static bool intel_iommu_capable(enum iommu_cap cap)
51165044
{
51175045
if (cap == IOMMU_CAP_CACHE_COHERENCY)
@@ -5352,7 +5280,7 @@ intel_iommu_dev_has_feat(struct device *dev, enum iommu_dev_features feat)
53525280
int ret;
53535281

53545282
if (!dev_is_pci(dev) || dmar_disabled ||
5355-
!scalable_mode_support() || !iommu_pasid_support())
5283+
!scalable_mode_support() || !pasid_mode_support())
53565284
return false;
53575285

53585286
ret = pci_pasid_features(to_pci_dev(dev));

0 commit comments

Comments
 (0)