From patchwork Wed Aug 9 14:43:05 2017 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Rob Clark X-Patchwork-Id: 109732 Delivered-To: patch@linaro.org Received: by 10.140.95.78 with SMTP id h72csp968157qge; Wed, 9 Aug 2017 07:43:49 -0700 (PDT) X-Received: by 10.98.139.68 with SMTP id j65mr8622732pfe.261.1502289829653; Wed, 09 Aug 2017 07:43:49 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1502289829; cv=none; d=google.com; s=arc-20160816; b=V2vpbYBfEIa9AdjcU1R+MOn4yyxPFTjuMIUZx91yeqAHfQNmC8jnzexJTD6lhnensi x923mXKowC+KTQJGmQwcwllB77PEUApqPOKRnr+XvIz/WCv9yOfJTeDP36p6i9XkKstp AI2MSACIVdcv7osS8o1wm9T5pyiWjjMc5wYBQoq41bFEmRFWbnvPDTi2FKgCI6q1HWl2 IxOQDe4EoOlzTgOq4x+EaSAL4dbr823W2gdXJ3jlBCE3ipAcVcXB0zuwn8eNmljEij18 3jPCVHQwjCObs85oVfESg8heg73VChnJp6REQQmRRbMDdYYC5xCVQ4JKzqo5oe/wl51B JZmw== 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=JdOs17uIzerKEZ94y8mQ7uroUkr4Ocm7GFF+e/9ZlB0=; b=bi4Vxm8qjnrRFXEG5oyvb96pZIxebeaniKaNgQzYW97o6jCvUNN2EdKgGuY3FLwtI/ Oj17aVeHq9c+XrY2phvSsouvPt64CY7+YplHxChi77WRwBMuSTHiwhgxqOeZDxTcOADZ 80414lWPf6Yx86WIuTBCGHvc9A5nZtlAhkE6J3rCszwmH04HVywuLa5IsZ6aS7uPf/zF LRU/iOHK9rXRqAb0Br8zqzEIB0QGf+Ut61nTQGYOwQxHYvMST/8kdXk2lCmeIAJ2kP36 DbJlb2xMj9aIoo3X660zT4C0zlHCwdg1SDJQeFMbdvZvpjmY9K3+O04DmgQUq3WxsBgH 7abw== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@gmail.com header.s=20161025 header.b=QsEoP9Ek; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (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 144si2510450pgd.857.2017.08.09.07.43.49; Wed, 09 Aug 2017 07:43:49 -0700 (PDT) Received-SPF: pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) client-ip=209.132.180.67; Authentication-Results: mx.google.com; dkim=pass header.i=@gmail.com header.s=20161025 header.b=QsEoP9Ek; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=gmail.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1753403AbdHIOno (ORCPT + 25 others); Wed, 9 Aug 2017 10:43:44 -0400 Received: from mail-qk0-f196.google.com ([209.85.220.196]:33641 "EHLO mail-qk0-f196.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1753389AbdHIOnm (ORCPT ); Wed, 9 Aug 2017 10:43:42 -0400 Received: by mail-qk0-f196.google.com with SMTP id d145so5843452qkc.0; Wed, 09 Aug 2017 07:43:41 -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=QsEoP9Ek6JJbmokusKCotMDviC84s708+6BJI9Ei6R+uPc7ucNcVLQKhqbi5vr3cD+ PgtSF9kbk5ml7ZdiZ10iM1oDHlePKHSlll2JPOCMyJs4X0KFPkS5YVePyo+jHBGSD0Th oRAdIai8d4EsaO9+MyqRuldFjXJoDNna3k8RbjwM/fRcPX5ilqYzrJrBXs1czOkDT1Sw lis4dEed3F26FVMX8BGLxG3ZTnk46GH2ouUinl+QD9v0makj7yczquMVkOQWiPy4ey/Z d06JJ7xeaqNEOOHOC0x3uHHlJAptK+Q7Bqh4ZGri31FM8w0VidWi/KXNKL2f2YhiRxVq CtJg== 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=o2DwPYOvwEB4mE41h9k21tkFn/UKTQaHpciAOFKONk1ui+2LlEmMQYv+32lifloWsM +A1+yfLfrdymOPcusQQdRL0wkVuotqJJAOy6FoD1Ck6sgq94qWTjuGiO5gsghYvaA7zg BaHbcrs156sX3c1gw79rydV+RTzb9A7VDJ1eIZ8KaXAiKjbWNYAQgDOg3oOqobnGeKu0 jZuL952pEfCY3xz7yjfjTZ+H5hYeLA+t8HjCDkZ45Si29WtjcE9I4nYyR6etYoIn2erT fCktMkUsf1FOPX45JTDhKhJjOFFqEmiA10Dr3Fb3mHV5e5xsQOtQ1DXeyJTkQisngOxR xDJQ== X-Gm-Message-State: AHYfb5jwoXRM9WFGCGWPAZt93fFVO8f8H1EZlXyP5nW4dqVpnAvq5Ww8 4kf9a0J8xRs4gQ== X-Received: by 10.55.24.41 with SMTP id j41mr11077268qkh.114.1502289821312; Wed, 09 Aug 2017 07:43:41 -0700 (PDT) Received: from localhost ([2601:184:4780:aac0:25f8:dd96:a084:785a]) by smtp.gmail.com with ESMTPSA id r23sm2206818qtc.50.2017.08.09.07.43.40 (version=TLS1_2 cipher=ECDHE-RSA-CHACHA20-POLY1305 bits=256/256); Wed, 09 Aug 2017 07:43:40 -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 , Joerg Roedel , linux-kernel@vger.kernel.org Subject: [RESEND PATCH 4/4] iommu: qcom: initialize secure page table Date: Wed, 9 Aug 2017 10:43:05 -0400 Message-Id: <20170809144310.22855-5-robdclark@gmail.com> X-Mailer: git-send-email 2.13.0 In-Reply-To: <20170809144310.22855-1-robdclark@gmail.com> References: <20170809144310.22855-1-robdclark@gmail.com> Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@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 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);