address &= ~(0xfffULL);
 
-       cmd->data[0]  = pasid & PASID_MASK;
+       cmd->data[0]  = pasid;
        cmd->data[1]  = domid;
        cmd->data[2]  = lower_32_bits(address);
        cmd->data[3]  = upper_32_bits(address);
 
        cmd->data[0]  = devid;
        if (gn) {
-               cmd->data[1]  = pasid & PASID_MASK;
+               cmd->data[1]  = pasid;
                cmd->data[2]  = CMD_INV_IOMMU_PAGES_GN_MASK;
        }
        cmd->data[3]  = tag & 0x1ff;
 
 bool amd_iommu_np_cache __read_mostly;
 bool amd_iommu_iotlb_sup __read_mostly = true;
 
-u32 amd_iommu_max_pasids __read_mostly = ~0;
+u32 amd_iommu_max_pasid __read_mostly = ~0;
 
 bool amd_iommu_v2_present __read_mostly;
 bool amd_iommu_pc_present __read_mostly;
 
        if (iommu_feature(iommu, FEATURE_GT)) {
                int glxval;
-               u32 pasids;
-               u64 shift;
+               u32 max_pasid;
+               u64 pasmax;
 
-               shift   = iommu->features & FEATURE_PASID_MASK;
-               shift >>= FEATURE_PASID_SHIFT;
-               pasids  = (1 << shift);
+               pasmax = iommu->features & FEATURE_PASID_MASK;
+               pasmax >>= FEATURE_PASID_SHIFT;
+               max_pasid  = (1 << (pasmax + 1)) - 1;
 
-               amd_iommu_max_pasids = min(amd_iommu_max_pasids, pasids);
+               amd_iommu_max_pasid = min(amd_iommu_max_pasid, max_pasid);
+
+               BUG_ON(amd_iommu_max_pasid & ~PASID_MASK);
 
                glxval   = iommu->features & FEATURE_GLXVAL_MASK;
                glxval >>= FEATURE_GLXVAL_SHIFT;
 
 #define FEATURE_GLXVAL_SHIFT   14
 #define FEATURE_GLXVAL_MASK    (0x03ULL << FEATURE_GLXVAL_SHIFT)
 
-#define PASID_MASK             0x000fffff
+/* Note:
+ * The current driver only support 16-bit PASID.
+ * Currently, hardware only implement upto 16-bit PASID
+ * even though the spec says it could have upto 20 bits.
+ */
+#define PASID_MASK             0x0000ffff
 
 /* MMIO status bits */
 #define MMIO_STATUS_EVT_INT_MASK       (1 << 1)
  */
 extern u32 amd_iommu_unmap_flush;
 
-/* Smallest number of PASIDs supported by any IOMMU in the system */
-extern u32 amd_iommu_max_pasids;
+/* Smallest max PASID supported by any IOMMU in the system */
+extern u32 amd_iommu_max_pasid;
 
 extern bool amd_iommu_v2_present;