From patchwork Thu Jul 13 12:07:47 2017 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Rob Clark X-Patchwork-Id: 107674 Delivered-To: patch@linaro.org Received: by 10.182.45.195 with SMTP id p3csp2186382obm; Thu, 13 Jul 2017 05:08:05 -0700 (PDT) X-Received: by 10.84.217.7 with SMTP id o7mr9600395pli.156.1499947685010; Thu, 13 Jul 2017 05:08:05 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1499947685; cv=none; d=google.com; s=arc-20160816; b=qn57fOe33NYcQ4b8SkEc8L9aCg4WX+23rTXEB1KTfz/d+9YTcHFbQLr9ttYBPqu/cZ w0CAYHv8SxuL9KLEfrI2dZSAP5wbVqF4sSHLI+0+97UVaEoyi3YUevCCyUiNbOBeTNsN cB5fidPKPeR7D7TlMybSTz5hb11JnMQzokLjFQt3D5oWPjy97KxyYU00incKZHx00UV/ p5yEqhTmxF1lW4mxgjp89uJNWMB826WBy+QHb61v7zVCqeaRidGGNj1+QssGfnIW2cY5 qpKmbtmpONz5fvrA1lIaICB1xSoqLbiEzUmnlIta8SkiUlWMBgQTflfBEOWeJnaXlgth SwEg== 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=vC7VRVyn2NOpGN7okgXjk6vZ04HxHedSeOJDODzuGsc=; b=c3nTmOUVVzNhMYZb/ApW6/yx1DXKDHjRi6zLJfk6mpJRZsnknRDseaoChd/y+7+e53 FmDGkGw/uDIbAvULZFaxpzCIyJe4K2Pu3hKmsj64GpoctGzuYVnHqUoKGdooEoMz0SiK 81xEO1oX8YxCNI+7MvlaDVUUu6CBrZ2Nv8wc64LWA9mhWGiD3SA2wh+1oKnj0neB82gG A8YYUKxiaBZfKEmYsj3VfkLxfz22e4HOp/qjKOCXnHD+T//g/VaHjLvyUWaEHpkoQUrz lbrwQmwDmHRAjYIVmYwsZ0nYegNsGSVb8vWM1CS9/HmOLl+o1O53D63dgJDVOmL5EVFU C0MA== ARC-Authentication-Results: i=1; mx.google.com; dkim=neutral (body hash did not verify) header.i=@gmail.com header.b=S+sPs8RZ; 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 a7si3962472pfh.442.2017.07.13.05.08.04; Thu, 13 Jul 2017 05:08:04 -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=S+sPs8RZ; 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 S1751204AbdGMMIE (ORCPT + 10 others); Thu, 13 Jul 2017 08:08:04 -0400 Received: from mail-qt0-f195.google.com ([209.85.216.195]:32869 "EHLO mail-qt0-f195.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1751106AbdGMMID (ORCPT ); Thu, 13 Jul 2017 08:08:03 -0400 Received: by mail-qt0-f195.google.com with SMTP id c20so5724954qte.0 for ; Thu, 13 Jul 2017 05:08:03 -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=JdOs17uIzerKEZ94y8mQ7uroUkr4Ocm7GFF+e/9ZlB0=; b=S+sPs8RZLaNwtv9CueCO1w3Z+BuUkf0RWitu3PySWNQyUV0B59aCsyW3JW1tNZIGbv 3d02WcYWpubUx2dR1qFhvW0qJopBTm+LNPIGo+x1cwHM148k2YFK5sOyEH5yTrD5mqQI sVphAjueM0gZ3LTftaaiKusjYquP7MarAZnwsu7zvAnUHbPMPQoQgMfDpY1gLLt7Wdgt EGljcE89gxEq+NTjT1LkMxMsup0Ebam+ykQ1aSF6n3np7M7o7yhrFYsprh5962T1SSUw vh4iAopoK5b1yLRRlYr7F2fWUUI/tDdA6TzMomKIVFmPZyZgKp0Av5oDm6miFHXcXvI6 rqvw== 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=JdOs17uIzerKEZ94y8mQ7uroUkr4Ocm7GFF+e/9ZlB0=; b=ff8aslNN4GCbP+98ViA84D5+tKZwAXyuFV/ArLz1NNa7tBKWAXxC9kUEBpA83/SkzP 1jRptTZP3TbkNLUAQl91xghClzPH10xXcpL2dLif7blSlT9avATsTDoeN2/FQn74PE2j Qoxsnm88JD8ijOHf8j1R6O+9v1qaDPfIWQDm6NHM1xGt3/v3o4vIsnYMN/iQWZVncMI4 ApUt1CS7A6Cm3eR8ebq+ghJsHxU+orFqtlsbhdapqAcUrrw2ydc2Low1amBc6Nx7PnIu vvakwGHFjcFt6e4Q2lrdqsWyXAnQyXZmmvJpu6HuEU79pqfwxVfgwntNI6QLOzsTxDLZ 1glg== X-Gm-Message-State: AIVw110EfGyKBtLs31chj7n0oy0XOpy8wqL64nOQ1av3qSbyvxyYVhNC aqXt2sB9aZ7JtA== X-Received: by 10.237.63.245 with SMTP id w50mr4586299qth.135.1499947682734; Thu, 13 Jul 2017 05:08:02 -0700 (PDT) Received: from localhost ([144.121.20.162]) by smtp.gmail.com with ESMTPSA id l50sm4383322qtf.35.2017.07.13.05.08.01 (version=TLS1_2 cipher=ECDHE-RSA-CHACHA20-POLY1305 bits=256/256); Thu, 13 Jul 2017 05:08:01 -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 , Robin Murphy , Stanimir Varbanov , Rob Clark Subject: [RESEND PATCH 4/4] iommu: qcom: initialize secure page table Date: Thu, 13 Jul 2017 08:07:47 -0400 Message-Id: <20170713120747.20490-5-robdclark@gmail.com> X-Mailer: git-send-email 2.13.0 In-Reply-To: <20170713120747.20490-1-robdclark@gmail.com> References: <20170713120747.20490-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.13.0 -- 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 860cad1cb167..48b62aa52787 100644 --- a/drivers/iommu/qcom_iommu.c +++ b/drivers/iommu/qcom_iommu.c @@ -604,6 +604,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; @@ -700,6 +745,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; @@ -744,6 +800,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);