return !(addr_width < BITS_PER_LONG && pfn >> addr_width);
 }
 
+/*
+ * Calculate the Supported Adjusted Guest Address Widths of an IOMMU.
+ * Refer to 11.4.2 of the VT-d spec for the encoding of each bit of
+ * the returned SAGAW.
+ */
+static unsigned long __iommu_calculate_sagaw(struct intel_iommu *iommu)
+{
+       unsigned long fl_sagaw, sl_sagaw;
+
+       fl_sagaw = BIT(2) | (cap_fl1gp_support(iommu->cap) ? BIT(3) : 0);
+       sl_sagaw = cap_sagaw(iommu->cap);
+
+       /* Second level only. */
+       if (!sm_supported(iommu) || !ecap_flts(iommu->ecap))
+               return sl_sagaw;
+
+       /* First level only. */
+       if (!ecap_slts(iommu->ecap))
+               return fl_sagaw;
+
+       return fl_sagaw & sl_sagaw;
+}
+
 static int __iommu_calculate_agaw(struct intel_iommu *iommu, int max_gaw)
 {
        unsigned long sagaw;
        int agaw;
 
-       sagaw = cap_sagaw(iommu->cap);
-       for (agaw = width_to_agaw(max_gaw);
-            agaw >= 0; agaw--) {
+       sagaw = __iommu_calculate_sagaw(iommu);
+       for (agaw = width_to_agaw(max_gaw); agaw >= 0; agaw--) {
                if (test_bit(agaw, &sagaw))
                        break;
        }