Skip to content

Commit 1adf3cc

Browse files
LuBaolujoergroedel
authored andcommitted
iommu: Add max_pasids field in struct iommu_device
Use this field to keep the number of supported PASIDs that an IOMMU hardware is able to support. This is a generic attribute of an IOMMU and lifting it into the per-IOMMU device structure makes it possible to allocate a PASID for device without calls into the IOMMU drivers. Any iommu driver that supports PASID related features should set this field before enabling them on the devices. In the Intel IOMMU driver, intel_iommu_sm is moved to CONFIG_INTEL_IOMMU enclave so that the pasid_supported() helper could be used in dmar.c without compilation errors. Signed-off-by: Lu Baolu <[email protected]> Reviewed-by: Jean-Philippe Brucker <[email protected]> Reviewed-by: Kevin Tian <[email protected]> Reviewed-by: Jason Gunthorpe <[email protected]> Reviewed-by: Yi Liu <[email protected]> Tested-by: Zhangfei Gao <[email protected]> Tested-by: Tony Zhu <[email protected]> Link: https://lore.kernel.org/r/[email protected] Signed-off-by: Joerg Roedel <[email protected]>
1 parent 30a0b95 commit 1adf3cc

File tree

4 files changed

+12
-2
lines changed

4 files changed

+12
-2
lines changed

drivers/iommu/arm/arm-smmu-v3/arm-smmu-v3.c

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3543,6 +3543,7 @@ static int arm_smmu_device_hw_probe(struct arm_smmu_device *smmu)
35433543
/* SID/SSID sizes */
35443544
smmu->ssid_bits = FIELD_GET(IDR1_SSIDSIZE, reg);
35453545
smmu->sid_bits = FIELD_GET(IDR1_SIDSIZE, reg);
3546+
smmu->iommu.max_pasids = 1UL << smmu->ssid_bits;
35463547

35473548
/*
35483549
* If the SMMU supports fewer bits than would fill a single L2 stream

drivers/iommu/intel/dmar.c

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1104,6 +1104,13 @@ static int alloc_iommu(struct dmar_drhd_unit *drhd)
11041104

11051105
raw_spin_lock_init(&iommu->register_lock);
11061106

1107+
/*
1108+
* A value of N in PSS field of eCap register indicates hardware
1109+
* supports PASID field of N+1 bits.
1110+
*/
1111+
if (pasid_supported(iommu))
1112+
iommu->iommu.max_pasids = 2UL << ecap_pss(iommu->ecap);
1113+
11071114
/*
11081115
* This is only for hotplug; at boot time intel_iommu_enabled won't
11091116
* be set yet. When intel_iommu_init() runs, it registers the units

drivers/iommu/intel/iommu.h

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -480,8 +480,6 @@ enum {
480480
#define VTD_FLAG_IRQ_REMAP_PRE_ENABLED (1 << 1)
481481
#define VTD_FLAG_SVM_CAPABLE (1 << 2)
482482

483-
extern int intel_iommu_sm;
484-
485483
#define sm_supported(iommu) (intel_iommu_sm && ecap_smts((iommu)->ecap))
486484
#define pasid_supported(iommu) (sm_supported(iommu) && \
487485
ecap_pasid((iommu)->ecap))
@@ -795,6 +793,7 @@ struct context_entry *iommu_context_addr(struct intel_iommu *iommu, u8 bus,
795793
extern const struct iommu_ops intel_iommu_ops;
796794

797795
#ifdef CONFIG_INTEL_IOMMU
796+
extern int intel_iommu_sm;
798797
extern int iommu_calculate_agaw(struct intel_iommu *iommu);
799798
extern int iommu_calculate_max_sagaw(struct intel_iommu *iommu);
800799
extern int dmar_disabled;
@@ -810,6 +809,7 @@ static inline int iommu_calculate_max_sagaw(struct intel_iommu *iommu)
810809
}
811810
#define dmar_disabled (1)
812811
#define intel_iommu_enabled (0)
812+
#define intel_iommu_sm (0)
813813
#endif
814814

815815
static inline const char *decode_prq_descriptor(char *str, size_t size,

include/linux/iommu.h

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -322,12 +322,14 @@ struct iommu_domain_ops {
322322
* @list: Used by the iommu-core to keep a list of registered iommus
323323
* @ops: iommu-ops for talking to this iommu
324324
* @dev: struct device for sysfs handling
325+
* @max_pasids: number of supported PASIDs
325326
*/
326327
struct iommu_device {
327328
struct list_head list;
328329
const struct iommu_ops *ops;
329330
struct fwnode_handle *fwnode;
330331
struct device *dev;
332+
u32 max_pasids;
331333
};
332334

333335
/**

0 commit comments

Comments
 (0)