From patchwork Thu Jun 1 13:58:49 2017 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Rob Clark X-Patchwork-Id: 100924 Delivered-To: patch@linaro.org Received: by 10.140.96.100 with SMTP id j91csp816773qge; Thu, 1 Jun 2017 06:59:08 -0700 (PDT) X-Received: by 10.101.90.78 with SMTP id z14mr1401342pgs.44.1496325547998; Thu, 01 Jun 2017 06:59:07 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1496325547; cv=none; d=google.com; s=arc-20160816; b=bQQzBMDYVih3qs8ooXu6cGf5ZPQfR0AnHBrjyoHA3ikc5Ti3g1f+wjFvOiLYymSLor bTvlZrmq7k/qfDILU9oKRzKHT3w3Cxt9eA8hc+VHs8TDohWjVr/CUm4mzoAF68q5kxxa 4D25paa+Flgs/8gAF6LY91tpobzn586eIqnWHVl1rMq5eUAdL069I959lvKP4P012dTt LQKXgmyj+eRcDpEDxBOfZWo0XKxNmwi1RMpR5Xa1t/QvlHkgNorRixEXtbNhHPiqhrwK 5AG8mNi8ALqEpOYwHU1NyULN8RSsUqR0TLPpJxrRbYlZJjNPOhhXjQU7rGcZtmOmb4Hp JDfQ== 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=RTNlfQqp/Iky7b7SROr3CIfjaUt0jLxL0J4zVAP57c0=; b=zb2AOSqwK5l1KBbr50f+Awg6fuZJNL1Bep5/ArMczlJylO0VJ2Rb7j1rP9NR9O0dwc 0Cm9F0MynEFl5gg1uR0Hckz76lgrknsSszTuNgSbmUduOq4jwic7RodDK1C53KJtora/ VswCpopwW+L7XXv6E2mlDusEdaL5Mxc/9SI0+xrykZMgsJRuadX4XrEszC7RbVmKuiLb pBH7D2Oj9Rl3HMW1Ky4FR6+MPWVtEXTo0UPlqHmvCDY1O3Qj43xhoxayklYRHREnAHna YibpT1T8zDF8kLePcU5y1aXG3eSLtYi000vZPPFgWN9Wa0WXudx3RmhbxyUKV5r8Mv/O 5+Mw== ARC-Authentication-Results: i=1; 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 Return-Path: Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id l131si465709pfc.361.2017.06.01.06.59.07; Thu, 01 Jun 2017 06:59:07 -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 S1751193AbdFAN7H (ORCPT + 10 others); Thu, 1 Jun 2017 09:59:07 -0400 Received: from mail-qt0-f195.google.com ([209.85.216.195]:35451 "EHLO mail-qt0-f195.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1751083AbdFAN7G (ORCPT ); Thu, 1 Jun 2017 09:59:06 -0400 Received: by mail-qt0-f195.google.com with SMTP id r58so5759858qtb.2 for ; Thu, 01 Jun 2017 06:59:06 -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=J3y4uF3R55Z6lF4TnrBb1OSpTPjblbe7m+SiEZPRMf0=; b=DIFTYabfR2KnG4K+X1meu+6KJ8FaYkl81s7Qn0+TUlGEH1RXRL4ihJjIhJkr0Iao4Y R11/qDc96nXeaAnejM+9944zxo7zUFB3WtQEttXzZR2Ty/hmPc2n5rYi9W/9bgBhYXse kO3vXbYS4hGP7J191h/98EXx5qy1gTXlchmu0nSrncKATzjZPPmPT4shfwZZRl97ERjz OFIip15R21oKHN63a94Za4Vqly79F2jcoSZniAq/8XAWyGwGFQj4UTiVdA9aMm9d0iXV D7bbKoBL2nsx6TYuuTH+7oN+fMV3avEb0B6+0KTtXukQGQReGqUxNwpidOOMwDB9dFzp H0+Q== 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=J3y4uF3R55Z6lF4TnrBb1OSpTPjblbe7m+SiEZPRMf0=; b=ntaBSL3dmROcCQ7RjKyJ4/PDFj4CbRLCcMfcBF/2gcb6UQAJKQIpohmhAJ5hBX7V/a 3D6YQ7SWw7wzGY8G8esNK8b1SXJJWYxh1rR05B0BghISZ/CPcpSAH1ncCWL6VI/7da6y sD9aq9GxTAW+58PnyBEn2eTBdEtsruzGBMCziPjdvWYoLOUJYvxis4iaBncYBlrK+3XN 8XsyFUFRm5SaU9EZGc/CrWc46XZvIgtWKIsmvS+R9u4ckdYu4zzYZRJlfdGs4jcrOAgo AZDmd+VdW8lBH1qqlw8XQlUwgcUYSetG2ANzhUY8p3R+vObdrDV1ypgu4kDyNeij5Bl0 Pn1A== X-Gm-Message-State: AODbwcDJNb13GlUja/AfMuA7RSTemeG74+5nrWKpnPQx+USEEcNnhTE/ 0oNZRgZwygKo3FUBYTw= X-Received: by 10.237.45.129 with SMTP id i1mr1918084qtd.194.1496325545643; Thu, 01 Jun 2017 06:59:05 -0700 (PDT) Received: from localhost (nat-pool-bos-t.redhat.com. [66.187.233.206]) by smtp.gmail.com with ESMTPSA id x26sm1414976qtc.19.2017.06.01.06.59.04 (version=TLS1_2 cipher=ECDHE-RSA-CHACHA20-POLY1305 bits=256/256); Thu, 01 Jun 2017 06:59:04 -0700 (PDT) From: Rob Clark To: iommu@lists.linux-foundation.org Cc: linux-arm-msm@vger.kernel.org, Rob Herring , Robin Murphy , Will Deacon , Mark Rutland , Sricharan , Archit Taneja , Stanimir Varbanov , Rob Clark Subject: [PATCH 4/4] iommu: qcom: initialize secure page table Date: Thu, 1 Jun 2017 09:58:49 -0400 Message-Id: <20170601135849.14978-5-robdclark@gmail.com> X-Mailer: git-send-email 2.9.4 In-Reply-To: <20170601135849.14978-1-robdclark@gmail.com> References: <20170601135849.14978-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.4 -- 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 3b578e6..753ee0e 100644 --- a/drivers/iommu/qcom_iommu.c +++ b/drivers/iommu/qcom_iommu.c @@ -636,6 +636,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; @@ -733,6 +778,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; @@ -777,6 +833,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);