From patchwork Mon Jun 26 12:43:52 2017 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Rob Clark X-Patchwork-Id: 106325 Delivered-To: patch@linaro.org Received: by 10.182.135.102 with SMTP id pr6csp1295746obb; Mon, 26 Jun 2017 05:44:06 -0700 (PDT) X-Received: by 10.84.131.6 with SMTP id 6mr6980pld.33.1498481046861; Mon, 26 Jun 2017 05:44:06 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1498481046; cv=none; d=google.com; s=arc-20160816; b=0iSmS3ZjmRp796YWP5KZeRg2qQUfTCq0YgXSwkbtHxF9/2hcZfHbBFz8uyFQoGXZ5h EivB47fdMtGc/62Amo3wv1tbe0NCHDkOZ1hKHuIT5JcLHLi8IEREAoBYRxSAG8ua1W6A vH3q4rnfv6mKbh9DAwUoljgLKC9sf326P2RUr3HEs0+/pOjZMx+7A/B9W7dHaWcMf3dP zRcPMWHTIEdiSubUG/4Jskvrfr13R3K0dkTMd83B30kzFlgLCV6spW9BQDN3cTicUyPi LvOFgdHhfWfpR8pg8NCJkDBtlHEZPVYtYWUM19acQ5jlAyEm7aqt8A6MwJvSuv/0Wt7v iWGQ== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:references:in-reply-to:message-id:date :subject:cc:to:from:dkim-signature:arc-authentication-results; bh=7k3gyAJOcgkJiA0F+GvgIOC8WZQzx65sKQB5ELiHh70=; b=yWhxh6lyZeQui7NjWcJstKVvrCiLjCUO2RgyXqFI5S3bogBhFEx4O4KtHT74+3mKkA VQgBmEgl9aSv9NotcN8ZfFlWyL1f0pBYv0Rcdkz4tU5H9zXp2Hr35F2p/Lu1eChcSbAj KUtBGbqItuFbqR8u6dBuFO0evhRO5fLgAcf+QDw4d9HtKoHMqtzFZffCmyK+nwLyAjz/ ATik8OmbkoYFMPRYPPzu49diaJVDbdk9zXV/yf8rpBMmEP7fbsqVPCNgbO16Z8aChxSX pLkSrOso9QysqTlcXH3ibEo5eJMCpQ0ygZFgNA9xpqCvyJdXINzM7/ILf7g+nmHFXxHm GDxA== ARC-Authentication-Results: i=1; mx.google.com; dkim=neutral (body hash did not verify) header.i=@gmail.com header.b=VLOkT1y6; spf=pass (google.com: best guess record for domain of linux-arm-msm-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-arm-msm-owner@vger.kernel.org; dmarc=fail (p=NONE sp=NONE dis=NONE) header.from=gmail.com Return-Path: Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id 99si10331444plc.595.2017.06.26.05.44.06; Mon, 26 Jun 2017 05:44:06 -0700 (PDT) Received-SPF: pass (google.com: best guess record for domain of linux-arm-msm-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) client-ip=209.132.180.67; Authentication-Results: mx.google.com; dkim=neutral (body hash did not verify) header.i=@gmail.com header.b=VLOkT1y6; spf=pass (google.com: best guess record for domain of linux-arm-msm-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-arm-msm-owner@vger.kernel.org; dmarc=fail (p=NONE sp=NONE dis=NONE) header.from=gmail.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1751901AbdFZMoG (ORCPT + 10 others); Mon, 26 Jun 2017 08:44:06 -0400 Received: from mail-qt0-f193.google.com ([209.85.216.193]:34352 "EHLO mail-qt0-f193.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1751423AbdFZMoF (ORCPT ); Mon, 26 Jun 2017 08:44:05 -0400 Received: by mail-qt0-f193.google.com with SMTP id w6so29071qtg.1 for ; Mon, 26 Jun 2017 05:44:05 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=from:to:cc:subject:date:message-id:in-reply-to:references; bh=sLVGLqgqHl2OhpIFCr4rSDUiuLPLCCikp36A9xlFpfs=; b=VLOkT1y6RzCdjn9bL2ANQhSwr8H5nmyLtIRCbKpIl0UGxnx9RoP0R1Lp/oiEq3kJ5a 601DOAL3q3RPWLylSySeHYajw38hbeEMXoolOzA0/+tCireFbX6dMRBOwIC49K+Dd+ab gy3VpoHZr+9tHbfyUCV0wJyu5761HYBKOZGEvfUsVKSNYaac1OsXvqfx3/4Yk8uTSHkI C2WLfaxKMXwpYiVHBfOCRFWeSNA2+8y9ewEFQFqre+0iwJAg7mbvTbfU95XOe2lucu7p VSDAYNMHXtDNBN8n3emXi/XNsZ0EKjaajEZEEci8FytiKCQo2ckP8ewGS0uXZKleDiq1 cwYQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references; bh=sLVGLqgqHl2OhpIFCr4rSDUiuLPLCCikp36A9xlFpfs=; b=lfs07kA/08Ud5uQafZhYd7krio/ZQPpwx5hoZ7HJIZ6i4CBOH5GWRZFVeEQof1e3Vb STwOFseN1fa7fWSlE9HytFRtyuncoCPwCu28GdEYSD8hpGcoLev10oP5q/5/QlErheeQ t3LNnWnJMUNxQtnTSiCfuCgcuYbkxlaABc7yqDd6pX7TxHa2PPn51eNuVM2ywDxfnKw9 Z37hMGOU2soIR5t2NwIZacW6vxya4BonITSBqaCdNAoB2vHf1PMLBHQJHGAhi/30dHRe ++xJdL4Yuul6Gyy454oeaW+453Mk1GpImHtWFYOkso50+XJaD2EgdF9A0yGUu9yosFAV 40HA== X-Gm-Message-State: AKS2vOzWRZruY76dj+ZXZ5H0bqHXh3oz/E4jclRAUN/hEc+2B0vwhn7I F+8g64uN9bn2UA== X-Received: by 10.237.33.78 with SMTP id 72mr22390715qtc.99.1498481044648; Mon, 26 Jun 2017 05:44:04 -0700 (PDT) Received: from localhost ([144.121.20.162]) by smtp.gmail.com with ESMTPSA id i85sm8448566qke.66.2017.06.26.05.44.03 (version=TLS1_2 cipher=ECDHE-RSA-CHACHA20-POLY1305 bits=256/256); Mon, 26 Jun 2017 05:44:03 -0700 (PDT) From: Rob Clark To: iommu@lists.linux-foundation.org Cc: linux-arm-msm@vger.kernel.org, Archit Taneja , Rob Herring , Will Deacon , Sricharan , Mark Rutland , Stanimir Varbanov , Rob Clark Subject: [PATCH 4/4] iommu: qcom: initialize secure page table Date: Mon, 26 Jun 2017 08:43:52 -0400 Message-Id: <20170626124352.21726-5-robdclark@gmail.com> X-Mailer: git-send-email 2.9.4 In-Reply-To: <20170626124352.21726-1-robdclark@gmail.com> References: <20170626124352.21726-1-robdclark@gmail.com> Sender: linux-arm-msm-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-arm-msm@vger.kernel.org From: Stanimir Varbanov This basically gets the secure page table size, allocates memory for secure pagetables and passes the physical address to the trusted zone. Signed-off-by: Stanimir Varbanov Signed-off-by: Rob Clark --- drivers/iommu/qcom_iommu.c | 64 ++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 64 insertions(+) -- 2.9.4 -- To unsubscribe from this list: send the line "unsubscribe linux-arm-msm" in the body of a message to majordomo@vger.kernel.org More majordomo info at http://vger.kernel.org/majordomo-info.html diff --git a/drivers/iommu/qcom_iommu.c b/drivers/iommu/qcom_iommu.c index 33e984e..438f38a 100644 --- a/drivers/iommu/qcom_iommu.c +++ b/drivers/iommu/qcom_iommu.c @@ -593,6 +593,51 @@ static void qcom_iommu_disable_clocks(struct qcom_iommu_dev *qcom_iommu) clk_disable_unprepare(qcom_iommu->iface_clk); } +static int qcom_iommu_sec_ptbl_init(struct device *dev) +{ + size_t psize = 0; + unsigned int spare = 0; + void *cpu_addr; + dma_addr_t paddr; + unsigned long attrs; + static bool allocated = false; + int ret; + + if (allocated) + return 0; + + ret = qcom_scm_iommu_secure_ptbl_size(spare, &psize); + if (ret) { + dev_err(dev, "failed to get iommu secure pgtable size (%d)\n", + ret); + return ret; + } + + dev_info(dev, "iommu sec: pgtable size: %zu\n", psize); + + attrs = DMA_ATTR_NO_KERNEL_MAPPING; + + cpu_addr = dma_alloc_attrs(dev, psize, &paddr, GFP_KERNEL, attrs); + if (!cpu_addr) { + dev_err(dev, "failed to allocate %zu bytes for pgtable\n", + psize); + return -ENOMEM; + } + + ret = qcom_scm_iommu_secure_ptbl_init(paddr, psize, spare); + if (ret) { + dev_err(dev, "failed to init iommu pgtable (%d)\n", ret); + goto free_mem; + } + + allocated = true; + return 0; + +free_mem: + dma_free_attrs(dev, psize, cpu_addr, paddr, attrs); + return ret; +} + static int get_asid(const struct device_node *np) { u32 reg; @@ -689,6 +734,17 @@ static struct platform_driver qcom_iommu_ctx_driver = { .remove = qcom_iommu_ctx_remove, }; +static bool qcom_iommu_has_secure_context(struct qcom_iommu_dev *qcom_iommu) +{ + struct device_node *child; + + for_each_child_of_node(qcom_iommu->dev->of_node, child) + if (of_device_is_compatible(child, "qcom,msm-iommu-v1-sec")) + return true; + + return false; +} + static int qcom_iommu_device_probe(struct platform_device *pdev) { struct device_node *child; @@ -733,6 +789,14 @@ static int qcom_iommu_device_probe(struct platform_device *pdev) return -ENODEV; } + if (qcom_iommu_has_secure_context(qcom_iommu)) { + ret = qcom_iommu_sec_ptbl_init(dev); + if (ret) { + dev_err(dev, "cannot init secure pg table(%d)\n", ret); + return ret; + } + } + platform_set_drvdata(pdev, qcom_iommu); pm_runtime_enable(dev);