Commit 3f9e40fa authored by JiangShui Yang's avatar JiangShui Yang Committed by JangShui Yang
Browse files

crypto: hisilicon/qm - get the type of iommu

driver inclusion
category: feature
bugzilla: https://gitee.com/openeuler/kernel/issues/I94L2V


CVE: NA

----------------------------------------------------------------------

Added the function is_iommu_used() for obtaining the IOMMU type in qm.c.
Driver checks the IOMMU type before registering to the UACCE subsystem.
If the IOMMU is disabled, the device does not register to the UACCE
subsystem in SVA mode.

In addition, the function sec_iommu_used_check() in sec_main.c for
obtaining the IOMMU type is deleted to avoid repeated function.

Signed-off-by: default avatarJiangShui Yang <yangjiangshui@h-partners.com>
Signed-off-by: default avatarWeili Qian <qianweili@huawei.com>
parent c0b0e895
Loading
Loading
Loading
Loading
+16 −0
Original line number Diff line number Diff line
@@ -6,6 +6,7 @@
#include <linux/dma-mapping.h>
#include <linux/idr.h>
#include <linux/io.h>
#include <linux/iommu.h>
#include <linux/irqreturn.h>
#include <linux/log2.h>
#include <linux/pm_runtime.h>
@@ -2771,6 +2772,20 @@ static int hisi_qp_memory_init(struct hisi_qm *qm, size_t dma_size, int id,
	return ret;
}

static inline bool is_iommu_used(struct device *dev)
{
	struct iommu_domain *domain;

	domain = iommu_get_domain_for_dev(dev);
	if (domain) {
		dev_info(dev, "iommu domain type = %u\n", domain->type);
		if (domain->type & __IOMMU_DOMAIN_PAGING)
			return true;
	}

	return false;
}

static void hisi_qm_pre_init(struct hisi_qm *qm)
{
	struct pci_dev *pdev = qm->pdev;
@@ -2786,6 +2801,7 @@ static void hisi_qm_pre_init(struct hisi_qm *qm)
	mutex_init(&qm->mailbox_lock);
	init_rwsem(&qm->qps_lock);
	qm->qp_in_used = 0;
	qm->use_iommu = is_iommu_used(&pdev->dev);
	if (test_bit(QM_SUPPORT_RPM, &qm->caps)) {
		if (!acpi_device_power_manageable(ACPI_COMPANION(&pdev->dev)))
			dev_info(&pdev->dev, "_PS0 and _PR0 are not defined");
+1 −1
Original line number Diff line number Diff line
@@ -600,7 +600,7 @@ static int sec_ctx_base_init(struct sec_ctx *ctx)
	ctx->dev = &sec->qm.pdev->dev;
	ctx->hlf_q_num = sec->ctx_q_num >> 1;

	ctx->pbuf_supported = ctx->sec->iommu_used;
	ctx->pbuf_supported = sec->qm.use_iommu;

	/* Half of queue depth is taken as fake requests limit in the queue. */
	ctx->fake_req_limit = ctx->qps[0]->sq_depth >> 1;
+0 −18
Original line number Diff line number Diff line
@@ -1190,23 +1190,6 @@ static void sec_probe_uninit(struct hisi_qm *qm)
	hisi_qm_dev_err_uninit(qm);
}

static void sec_iommu_used_check(struct sec_dev *sec)
{
	struct iommu_domain *domain;
	struct device *dev = &sec->qm.pdev->dev;

	domain = iommu_get_domain_for_dev(dev);

	/* Check if iommu is used */
	sec->iommu_used = false;
	if (domain) {
		if (domain->type & __IOMMU_DOMAIN_PAGING)
			sec->iommu_used = true;
		dev_info(dev, "SMMU Opened, the iommu type = %u\n",
			domain->type);
	}
}

static int sec_probe(struct pci_dev *pdev, const struct pci_device_id *id)
{
	struct sec_dev *sec;
@@ -1225,7 +1208,6 @@ static int sec_probe(struct pci_dev *pdev, const struct pci_device_id *id)
	}

	sec->ctx_q_num = ctx_q_num;
	sec_iommu_used_check(sec);

	ret = sec_probe_init(sec);
	if (ret) {
+1 −0
Original line number Diff line number Diff line
@@ -385,6 +385,7 @@ struct hisi_qm {
	struct work_struct cmd_process;

	bool use_sva;
	bool use_iommu;

	resource_size_t phys_base;
	resource_size_t db_phys_base;