From patchwork Wed Mar 1 17:42:55 2017 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Rob Clark X-Patchwork-Id: 94729 Delivered-To: patch@linaro.org Received: by 10.140.20.113 with SMTP id 104csp1913136qgi; Wed, 1 Mar 2017 09:43:24 -0800 (PST) X-Received: by 10.99.105.66 with SMTP id e63mr10134008pgc.104.1488390204099; Wed, 01 Mar 2017 09:43:24 -0800 (PST) Return-Path: Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id h16si5170504pli.228.2017.03.01.09.43.23; Wed, 01 Mar 2017 09:43:24 -0800 (PST) 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 S1752879AbdCARnX (ORCPT + 9 others); Wed, 1 Mar 2017 12:43:23 -0500 Received: from mail-yw0-f196.google.com ([209.85.161.196]:35134 "EHLO mail-yw0-f196.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1752602AbdCARnW (ORCPT ); Wed, 1 Mar 2017 12:43:22 -0500 Received: by mail-yw0-f196.google.com with SMTP id l16so4564672ywb.2 for ; Wed, 01 Mar 2017 09:43:21 -0800 (PST) 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=wSNfrICQ9nkYII1xjEEWLwB5sHyejwyxKs5VXPOcd90=; b=eMm6dZhBUBnos2dDsv6+MNgcoQSrMZd43KisrV1UYpO2vA3dSJxM2/IOpF1GkmkX4K EIKuijCsF4D34AO1U8zSjQ/1gLJ1M/NYynrN9Ep8ejkMvaS+JB9iNJpuwNNnhaY/YTAF Rz46eB4FuQ8/McsnjuD/Mo+kkNFMS8ZZhkisVdrlJ0n8gEWXqlBAcsroDfXsM8BhgdwY 4SMJinxe2K4yKZUfqsIEmJLvns7MbwSIuEfxPiNvQbbLNIDMDgQ4oQ/p5waaxrY5k0Ob RfYqVHoE/n40FaH/oreAtDujRNx/r7F5TUPrh+WwgcSyLFORgTAEd4wUbTxWznKpMoDR vUpA== 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=wSNfrICQ9nkYII1xjEEWLwB5sHyejwyxKs5VXPOcd90=; b=Z6AGECZugAaT7nixqCDfPD/w6O8RABM2vaLhsoRr0XE4oXs03gcYKXP3o/b3IrAQNc L/DjU0TXX1/Z/0C9AmSB1z1Z50t0ZWjNs/ZYyluVESBClyZ+dWEz/IzURKm8B99dYKEK bbgEzhvC3egb4c//qUQHnhqDRx5juk8JQhQeE2ZZcUej+jA6eKgcYv+CrZIO0A1/1xGr IfbtNz0RU933JvVovEm95A0Lx+iCpEKPiefosvlCCQmP/bXqqOhuLt4u9abbjj904deS CJ4lTujJzrtMdHAoCEr4+cciwzXfJFkC0esocf1iCZ8ueyvvPVloMV2XEdbCjhCab2Yl 1RWw== X-Gm-Message-State: AMke39kZa5NAkNldR14yrprDJcZQDDwpnb1FiaaNUve8QNZI6uQkrXbHQCCqwR5U0wX2Jg== X-Received: by 10.237.56.135 with SMTP id k7mr12031067qte.42.1488390200940; Wed, 01 Mar 2017 09:43:20 -0800 (PST) Received: from localhost ([2601:184:4780:aac0:25f8:dd96:a084:785a]) by smtp.gmail.com with ESMTPSA id 27sm3580400qkx.3.2017.03.01.09.43.20 (version=TLS1_2 cipher=ECDHE-RSA-CHACHA20-POLY1305 bits=256/256); Wed, 01 Mar 2017 09:43:20 -0800 (PST) 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: Wed, 1 Mar 2017 12:42:55 -0500 Message-Id: <20170301174258.14618-7-robdclark@gmail.com> X-Mailer: git-send-email 2.9.3 In-Reply-To: <20170301174258.14618-1-robdclark@gmail.com> References: <20170301174258.14618-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 bassicaly get the secure page table size, allocate memory and return back 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 5d3bb63..082ece7 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; @@ -693,6 +738,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: */