From patchwork Thu May 25 17:33:40 2017 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Rob Clark X-Patchwork-Id: 9748823 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 0B97360209 for ; Thu, 25 May 2017 17:34:17 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id E9A8527B81 for ; Thu, 25 May 2017 17:34:16 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id DE1B227F4B; Thu, 25 May 2017 17:34:16 +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 4B4BF27B81 for ; Thu, 25 May 2017 17:34:16 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S968351AbdEYReP (ORCPT ); Thu, 25 May 2017 13:34:15 -0400 Received: from mail-qt0-f195.google.com ([209.85.216.195]:36401 "EHLO mail-qt0-f195.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S967984AbdEYReO (ORCPT ); Thu, 25 May 2017 13:34:14 -0400 Received: by mail-qt0-f195.google.com with SMTP id j13so31027307qta.3 for ; Thu, 25 May 2017 10:34:14 -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=RRf4Vev8iARgD39mdT/fhU03JEdsxg9x98Hspm11eN8=; b=IECfpvJl3txQaouBsatTEF6HVjjQwv/TRP4uAhzIhMyvkX10VyO/7Ak79ATai2Mx6v L/HEXHBTEGpUweBd9XY8Eu+lA04RMhIpwi95d6oyXypiQ9dut72TmkNNpCOFjJoqudXJ axWqglJTprF1v4fum9ZHUiBroeKgXIJKfFWakM92doZdY7PO83b4XKwwY3cRyrFzy33K bu+jw0U8efTHLV7B3mJW0PSOZ31Rxfxnz9H8NKumXz2FBRfC/wIbiT1TzGiNYJ8n/S9u KG3ysUL06ValfuiKJrZu0N1/TzqsK6WLEuKvDsGWWp/oB/470LgWpFM7+MwRyH2u6HLU Iuow== 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=RRf4Vev8iARgD39mdT/fhU03JEdsxg9x98Hspm11eN8=; b=KDymsZA1FEkt+P+pv3pfm+4otCaNjINDGlsKWcH++l3E4jTSCw417MIdG5fM078roi J2k/GZ7pdcthp3ymuRX+zKM/dN5hgQYjyk/J/ue6pX+WG4ROBo7qa4yFxrx5YHPLG7N1 LNcR0r++20KSRJ9vxbRHRKYXIkRgrucS1G8sw+MxDGhYrsOOpvUOVE92FxLGr5OKfqUd vPFbx8NT7R6tFqEXZOIhaLBinw7lFxQ1AVPBf+p0i4EQKhHqnCCjC1r2VdLMt5wNZkXw wpMewL4yJmuC4seSjS0tpJ7SwbSUriq8gh/sjHIyWbSaFmac28S4KLqtzt7+SFDLAjGg Hn2A== X-Gm-Message-State: AODbwcAVOmASAVfNsgMZAtTjTttqqSTXlcLDffnsoD/Nc21JnIHz/61G 8LcM2KqJ3WQJMw== X-Received: by 10.200.51.111 with SMTP id u44mr41362563qta.122.1495733653690; Thu, 25 May 2017 10:34:13 -0700 (PDT) Received: from localhost (nat-pool-bos-t.redhat.com. [66.187.233.206]) by smtp.gmail.com with ESMTPSA id 69sm5511531qkc.18.2017.05.25.10.34.12 (version=TLS1_2 cipher=ECDHE-RSA-CHACHA20-POLY1305 bits=256/256); Thu, 25 May 2017 10:34:12 -0700 (PDT) From: Rob Clark To: iommu@lists.linux-foundation.org Cc: linux-arm-msm@vger.kernel.org, Rob Herring , Robin Murphy , Will Deacon , Sricharan , Mark Rutland , Stanimir Varbanov , Archit Taneja , Rob Clark Subject: [PATCH 4/4] iommu: qcom: initialize secure page table Date: Thu, 25 May 2017 13:33:40 -0400 Message-Id: <20170525173340.26904-5-robdclark@gmail.com> X-Mailer: git-send-email 2.9.4 In-Reply-To: <20170525173340.26904-1-robdclark@gmail.com> References: <20170525173340.26904-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 bfaf97c..3033862 100644 --- a/drivers/iommu/qcom_iommu.c +++ b/drivers/iommu/qcom_iommu.c @@ -632,6 +632,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; @@ -718,6 +763,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 qcom_iommu_dev *qcom_iommu; @@ -754,6 +810,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);