]> git.ipfire.org Git - thirdparty/kernel/linux.git/commitdiff
iommu/amd: Introduce iommu_dev_data.max_pasids
authorVasant Hegde <vasant.hegde@amd.com>
Thu, 18 Apr 2024 10:33:51 +0000 (10:33 +0000)
committerJoerg Roedel <jroedel@suse.de>
Fri, 26 Apr 2024 10:15:59 +0000 (12:15 +0200)
This variable will track the number of PASIDs supported by the device.
If IOMMU or device doesn't support PASID then it will be zero.

This will be used while allocating GCR3 table to decide required number
of PASID table levels. Also in PASID bind path it will use this variable
to check whether device supports PASID or not.

Signed-off-by: Vasant Hegde <vasant.hegde@amd.com>
Reviewed-by: Jason Gunthorpe <jgg@nvidia.com>
Link: https://lore.kernel.org/r/20240418103400.6229-7-vasant.hegde@amd.com
Signed-off-by: Joerg Roedel <jroedel@suse.de>
drivers/iommu/amd/amd_iommu_types.h
drivers/iommu/amd/iommu.c

index d1fed5fc219b344fda4efd22b38b7b01ebebd84c..03442e86ae4484d694c8c422f9dd5a18d65dc5bd 100644 (file)
@@ -813,6 +813,7 @@ struct iommu_dev_data {
        struct device *dev;
        u16 devid;                        /* PCI Device ID */
 
+       u32 max_pasids;                   /* Max supported PASIDs */
        u32 flags;                        /* Holds AMD_IOMMU_DEVICE_FLAG_<*> */
        int ats_qdep;
        u8 ats_enabled  :1;               /* ATS state */
index 0decab9581069463359b00af67e61a9cc79075e1..7daf6d75d964ef5cb122d667363c0cae5621ef22 100644 (file)
@@ -2104,6 +2104,7 @@ static struct iommu_device *amd_iommu_probe_device(struct device *dev)
 {
        struct iommu_device *iommu_dev;
        struct amd_iommu *iommu;
+       struct iommu_dev_data *dev_data;
        int ret;
 
        if (!check_device(dev))
@@ -2130,6 +2131,17 @@ static struct iommu_device *amd_iommu_probe_device(struct device *dev)
                iommu_dev = &iommu->iommu;
        }
 
+       /*
+        * If IOMMU and device supports PASID then it will contain max
+        * supported PASIDs, else it will be zero.
+        */
+       dev_data = dev_iommu_priv_get(dev);
+       if (amd_iommu_pasid_supported() && dev_is_pci(dev) &&
+           pdev_pasid_supported(dev_data)) {
+               dev_data->max_pasids = min_t(u32, iommu->iommu.max_pasids,
+                                            pci_max_pasids(to_pci_dev(dev)));
+       }
+
        iommu_completion_wait(iommu);
 
        return iommu_dev;