[PATCH] iommu/amd: Add prefetch iommu pages command build function

From: Wesley Sheng
Date: Sat Sep 05 2020 - 21:20:02 EST


Add function to build prefetch iommu pages command

Signed-off-by: Wesley Sheng <wesley.sheng@xxxxxxx>
---
drivers/iommu/amd/amd_iommu_types.h | 2 ++
drivers/iommu/amd/iommu.c | 19 +++++++++++++++++++
2 files changed, 21 insertions(+)

diff --git a/drivers/iommu/amd/amd_iommu_types.h b/drivers/iommu/amd/amd_iommu_types.h
index baa31cd2411c..73734a0c4679 100644
--- a/drivers/iommu/amd/amd_iommu_types.h
+++ b/drivers/iommu/amd/amd_iommu_types.h
@@ -173,6 +173,7 @@
#define CMD_INV_IOMMU_PAGES 0x03
#define CMD_INV_IOTLB_PAGES 0x04
#define CMD_INV_IRT 0x05
+#define CMD_PF_IOMMU_PAGES 0x06
#define CMD_COMPLETE_PPR 0x07
#define CMD_INV_ALL 0x08

@@ -181,6 +182,7 @@
#define CMD_INV_IOMMU_PAGES_SIZE_MASK 0x01
#define CMD_INV_IOMMU_PAGES_PDE_MASK 0x02
#define CMD_INV_IOMMU_PAGES_GN_MASK 0x04
+#define CMD_PF_IOMMU_PAGES_INV_MASK 0x10

#define PPR_STATUS_MASK 0xf
#define PPR_STATUS_SHIFT 12
diff --git a/drivers/iommu/amd/iommu.c b/drivers/iommu/amd/iommu.c
index ba9f3dbc5b94..b3971595b0e9 100644
--- a/drivers/iommu/amd/iommu.c
+++ b/drivers/iommu/amd/iommu.c
@@ -976,6 +976,25 @@ static void build_inv_irt(struct iommu_cmd *cmd, u16 devid)
CMD_SET_TYPE(cmd, CMD_INV_IRT);
}

+static void build_pf_iommu_pages(struct iommu_cmd *cmd, u64 address,
+ u16 devid, int pfcnt, bool size,
+ bool inv)
+{
+ memset(cmd, 0, sizeof(*cmd));
+
+ address &= PAGE_MASK;
+
+ cmd->data[0] = devid;
+ cmd->data[0] |= (pfcnt & 0xff) << 24;
+ cmd->data[2] = lower_32_bits(address);
+ cmd->data[3] = upper_32_bits(address);
+ if (size)
+ cmd->data[2] |= CMD_INV_IOMMU_PAGES_SIZE_MASK;
+ if (inv)
+ cmd->data[2] |= CMD_PF_IOMMU_PAGES_INV_MASK;
+ CMD_SET_TYPE(cmd, CMD_PF_IOMMU_PAGES);
+}
+
/*
* Writes the command to the IOMMUs command buffer and informs the
* hardware about the new command.
--
2.16.2