From patchwork Tue Mar 14 15:18:08 2017 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Rob Clark X-Patchwork-Id: 95300 Delivered-To: patch@linaro.org Received: by 10.140.89.134 with SMTP id v6csp306130qgd; Tue, 14 Mar 2017 08:18:51 -0700 (PDT) X-Received: by 10.99.116.10 with SMTP id p10mr43686553pgc.74.1489504731428; Tue, 14 Mar 2017 08:18:51 -0700 (PDT) Return-Path: Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id d125si15070688pfg.72.2017.03.14.08.18.51; Tue, 14 Mar 2017 08:18:51 -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; 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 S1751142AbdCNPSt (ORCPT + 9 others); Tue, 14 Mar 2017 11:18:49 -0400 Received: from mail-qt0-f196.google.com ([209.85.216.196]:35074 "EHLO mail-qt0-f196.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1751015AbdCNPSr (ORCPT ); Tue, 14 Mar 2017 11:18:47 -0400 Received: by mail-qt0-f196.google.com with SMTP id r5so10379322qtb.2 for ; Tue, 14 Mar 2017 08:18:46 -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=BHc+F3uGpbA45hFmpbgGr9e7yHE5eIhqlJcvroganvM=; b=bvYLwrIA59OBMwZ7adTXv/pLEpyHLAXYsV8HyOdv1vlc16Yv2a0L3xRfFT6xkX0kdC GArlVqtR9epgtGekUYOfrdgKvKloVf4lFrsGP6VggwJKGUysbpPYielpsML/30h76Pi7 WriDfSRFFThJ2ZQwpd3hteaLay5A6OoQ2xC0xBLk+hHn4RGRC93RA/iepwr0jpghMAOr 7u+C8dIGHdytpSpRkqZWZXQXcV35mDQgidFGd+LZruUvBIoiQL8Bnc7wVITNgG3S8JHy M3U0O0IWJzmC6apmrluOn6EzF8sZEisqp5DMfT5CU9Od7nH/SsFeLr6mwyiZB4x2OeUF kgtw== 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=BHc+F3uGpbA45hFmpbgGr9e7yHE5eIhqlJcvroganvM=; b=t4OwWMm1kLseZ77E20gf/F3f3e5jtWcFDQTXT7f7piax/7bi3R51/3aZK7a/iSZHzR uFJwGcmi9wE96hF1fHLPdmBEPiNH2v4nS/WHgM76czrIMvePjDgvwopDngw5jJht4vm4 jHNL0YfMVO5gkyreK8oRDkZDGPhPOjwMGi5ICfaECF5xAkCi9EdNL3+fM/7hY9HZF+cD fF8Ft3Hkr4fW3B23OvE0zGwRLahWqBBGg/DjbNUp1DmDwimSO4rRO1Bu6XqF7GYKm7jY eOY7Ju9cZ7pKo7YyeQVzf2XvxQ5ov6esHEQA8WO1ZrcA0xFQy8TwQv+mbeBkTB60mTFN 1Tsw== X-Gm-Message-State: AMke39kjVlHDy7oSSpZELGZ66JBrUxr2yL9omw4KIy0IGgqOfhE+ujfwIIRrHKE6JJ5DiQ== X-Received: by 10.200.48.209 with SMTP id w17mr41976093qta.179.1489504720629; Tue, 14 Mar 2017 08:18:40 -0700 (PDT) Received: from localhost ([2601:184:4780:aac0:25f8:dd96:a084:785a]) by smtp.gmail.com with ESMTPSA id c19sm14595587qtc.29.2017.03.14.08.18.39 (version=TLS1_2 cipher=ECDHE-RSA-CHACHA20-POLY1305 bits=256/256); Tue, 14 Mar 2017 08:18:39 -0700 (PDT) From: Rob Clark To: iommu@lists.linux-foundation.org Cc: linux-arm-msm@vger.kernel.org, Robin Murphy , Will Deacon , Sricharan , Mark Rutland , Stanimir Varbanov , Rob Clark Subject: [PATCH 6/9] iommu: qcom: initialize secure page table Date: Tue, 14 Mar 2017 11:18:08 -0400 Message-Id: <20170314151811.17234-7-robdclark@gmail.com> X-Mailer: git-send-email 2.9.3 In-Reply-To: <20170314151811.17234-1-robdclark@gmail.com> References: <20170314151811.17234-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.3 -- 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 6b7adbf..743a628 100644 --- a/drivers/iommu/qcom_iommu.c +++ b/drivers/iommu/qcom_iommu.c @@ -608,6 +608,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 qcom_iommu_ctx_probe(struct platform_device *pdev) { struct qcom_iommu_ctx *ctx; @@ -688,6 +733,17 @@ static struct platform_driver qcom_iommu_ctx_driver = { }; module_platform_driver(qcom_iommu_ctx_driver); +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 qcom_iommu_dev *qcom_iommu; @@ -724,6 +780,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); /* register context bank devices, which are child nodes: */