The pgsize bitmap is used to advertise the page sizes our hardware supports
to the IOMMU core, which will then use this information to split physically
contiguous memory regions it is mapping into page sizes that we support.

Traditionally the IOMMU core just handed us the mappings directly, after
making sure the size is an order of a 4KiB page and that the mapping has
natural alignment. To retain this behavior, we currently advertise that we
support all page sizes that are an order of 4KiB.

We are about to utilize the new IOMMU map/unmap_pages APIs. We could change
this to advertise the real page sizes we support.

Signed-off-by: Lu Baolu <baolu...@linux.intel.com>
---
 drivers/iommu/intel/iommu.c | 38 ++++++++++++++++++-------------------
 1 file changed, 19 insertions(+), 19 deletions(-)

diff --git a/drivers/iommu/intel/iommu.c b/drivers/iommu/intel/iommu.c
index 741d25ded717..240af636d51e 100644
--- a/drivers/iommu/intel/iommu.c
+++ b/drivers/iommu/intel/iommu.c
@@ -85,24 +85,6 @@
 #define LEVEL_STRIDE           (9)
 #define LEVEL_MASK             (((u64)1 << LEVEL_STRIDE) - 1)
 
-/*
- * This bitmap is used to advertise the page sizes our hardware support
- * to the IOMMU core, which will then use this information to split
- * physically contiguous memory regions it is mapping into page sizes
- * that we support.
- *
- * Traditionally the IOMMU core just handed us the mappings directly,
- * after making sure the size is an order of a 4KiB page and that the
- * mapping has natural alignment.
- *
- * To retain this behavior, we currently advertise that we support
- * all page sizes that are an order of 4KiB.
- *
- * If at some point we'd like to utilize the IOMMU core's new behavior,
- * we could change this to advertise the real page sizes we support.
- */
-#define INTEL_IOMMU_PGSIZES    (~0xFFFUL)
-
 static inline int agaw_to_level(int agaw)
 {
        return agaw + 2;
@@ -736,6 +718,23 @@ static int domain_update_device_node(struct dmar_domain 
*domain)
 
 static void domain_update_iotlb(struct dmar_domain *domain);
 
+/* Return the super pagesize bitmap if supported. */
+static unsigned long domain_super_pgsize_bitmap(struct dmar_domain *domain)
+{
+       unsigned long bitmap = 0;
+
+       /*
+        * 1-level super page supports page size of 2MiB, 2-level super page
+        * supports page size of both 2MiB and 1GiB.
+        */
+       if (domain->iommu_superpage == 1)
+               bitmap |= SZ_2M;
+       else if (domain->iommu_superpage == 2)
+               bitmap |= SZ_2M | SZ_1G;
+
+       return bitmap;
+}
+
 /* Some capabilities may be different across iommus */
 static void domain_update_iommu_cap(struct dmar_domain *domain)
 {
@@ -762,6 +761,7 @@ static void domain_update_iommu_cap(struct dmar_domain 
*domain)
        else
                domain->domain.geometry.aperture_end = 
__DOMAIN_MAX_ADDR(domain->gaw);
 
+       domain->domain.pgsize_bitmap |= domain_super_pgsize_bitmap(domain);
        domain_update_iotlb(domain);
 }
 
@@ -5607,7 +5607,7 @@ const struct iommu_ops intel_iommu_ops = {
        .dev_disable_feat       = intel_iommu_dev_disable_feat,
        .is_attach_deferred     = intel_iommu_is_attach_deferred,
        .def_domain_type        = device_def_domain_type,
-       .pgsize_bitmap          = INTEL_IOMMU_PGSIZES,
+       .pgsize_bitmap          = SZ_4K,
 #ifdef CONFIG_INTEL_IOMMU_SVM
        .cache_invalidate       = intel_iommu_sva_invalidate,
        .sva_bind_gpasid        = intel_svm_bind_gpasid,
-- 
2.25.1

_______________________________________________
iommu mailing list
iommu@lists.linux-foundation.org
https://lists.linuxfoundation.org/mailman/listinfo/iommu

Reply via email to