From patchwork Thu May 4 13:34:36 2017 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Rob Clark X-Patchwork-Id: 9711991 X-Patchwork-Delegate: agross@codeaurora.org Return-Path: Received: from mail.wl.linuxfoundation.org (pdx-wl-mail.web.codeaurora.org [172.30.200.125]) by pdx-korg-patchwork.web.codeaurora.org (Postfix) with ESMTP id C65D960387 for ; Thu, 4 May 2017 13:35:19 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id BA70128665 for ; Thu, 4 May 2017 13:35:19 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id AEF2128698; Thu, 4 May 2017 13:35:19 +0000 (UTC) X-Spam-Checker-Version: SpamAssassin 3.3.1 (2010-03-16) on pdx-wl-mail.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-6.3 required=2.0 tests=BAYES_00, DKIM_ADSP_CUSTOM_MED, DKIM_SIGNED, FREEMAIL_FROM, RCVD_IN_DNSWL_HI, RCVD_IN_SORBS_SPAM, T_DKIM_INVALID autolearn=ham version=3.3.1 Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 8BBB828678 for ; Thu, 4 May 2017 13:35:18 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1754263AbdEDNfR (ORCPT ); Thu, 4 May 2017 09:35:17 -0400 Received: from mail-qk0-f194.google.com ([209.85.220.194]:33433 "EHLO mail-qk0-f194.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1754240AbdEDNfQ (ORCPT ); Thu, 4 May 2017 09:35:16 -0400 Received: by mail-qk0-f194.google.com with SMTP id o85so1752287qkh.0 for ; Thu, 04 May 2017 06:35:16 -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=IMaAZ3a1M9mgCHExaLOg+DFq3ShBFRtLMJ0UFH7IbMc=; b=KGxfmvDhm4LWSO/PsiQ8mKVKOnqltocVOnzMICxjv7naS/1nN+t/XWSml/NUrFDiB9 IwO387SZrl+eYZqWaMsnECMVr8FcnUmlylf4wQ7PQPQ+H1RLvZZLUD1wjyBnm4FFKKC+ npizrakF6bG69GoWm4DRAWQdpLGyUkPgHmHccl4DnUUoMJ56wTRHMZf69+ulqnZuRjLQ oqG3Z4VaM9nH6yF6y6RUpq8cZQG/ZbNQXsBvQldREVuTJOkAKLKmO3XAMUD8Hdk7iuTr HCB6VeNuN0jNRUJ8Gn0rjyKb+0BH20Brf4UfQUw46HZJzqbo0v2dRU+hWNOwIcq4XVci rulw== 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=IMaAZ3a1M9mgCHExaLOg+DFq3ShBFRtLMJ0UFH7IbMc=; b=aCgNkiIiVN70mv+6CYt/UltlOcC/OiLmbLXHxRWe3GlwLST9SghyY1laQ6gKlMrIo2 V1sIx/ACaIAlJgy0E41odkOGIrPx5hUYcQGPkIQCE4B9oxNGij1BfzDqxVYcM73NYTJ9 g85v1OkSe5JT8Cia2ol3YN1j4uHd9H0tciszzkcL4XhpxJb6g9UR6HS/ucUJoT2Zo2U8 jPjO1H/0AGEAoW9fWsvL61lKlsAVl4LOFvGn4g071w5W6AKHHkP9RdwKpA09L1JDPsIm J/c8ttdoWceTV6lBBhONctJgIDh/IOlG+yfOy8ibva8/E8xfF1L3Tce+CbG4E+UvhTid semg== X-Gm-Message-State: AODbwcD7skv+Z+L703dvOEfQNYqS+GOO5XYZwLxHi9gdnt2h2R0ush5B bmUobJLLxLn07Yk+HzA= X-Received: by 10.55.98.71 with SMTP id w68mr394926qkb.124.1493904916049; Thu, 04 May 2017 06:35:16 -0700 (PDT) Received: from localhost (nat-pool-bos-t.redhat.com. [66.187.233.206]) by smtp.gmail.com with ESMTPSA id r40sm1584649qkr.13.2017.05.04.06.35.14 (version=TLS1_2 cipher=ECDHE-RSA-CHACHA20-POLY1305 bits=256/256); Thu, 04 May 2017 06:35:15 -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 , Archit Taneja , Rob Herring , Rob Clark Subject: [PATCH 4/4] iommu: qcom: initialize secure page table Date: Thu, 4 May 2017 09:34:36 -0400 Message-Id: <20170504133436.24288-5-robdclark@gmail.com> X-Mailer: git-send-email 2.9.3 In-Reply-To: <20170504133436.24288-1-robdclark@gmail.com> References: <20170504133436.24288-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 X-Virus-Scanned: ClamAV using ClamSMTP 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(+) diff --git a/drivers/iommu/qcom_iommu.c b/drivers/iommu/qcom_iommu.c index 1cf7c8e..a35d4cc 100644 --- a/drivers/iommu/qcom_iommu.c +++ b/drivers/iommu/qcom_iommu.c @@ -615,6 +615,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; @@ -695,6 +740,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; @@ -731,6 +787,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: */