From patchwork Mon Aug 24 18:37:36 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Rob Clark X-Patchwork-Id: 11734103 Return-Path: Received: from mail.kernel.org (pdx-korg-mail-1.web.codeaurora.org [172.30.200.123]) by pdx-korg-patchwork-2.web.codeaurora.org (Postfix) with ESMTP id 9E3A713A4 for ; Mon, 24 Aug 2020 18:44:42 +0000 (UTC) Received: from merlin.infradead.org (merlin.infradead.org [205.233.59.134]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by mail.kernel.org (Postfix) with ESMTPS id 780DD2075B for ; Mon, 24 Aug 2020 18:44:42 +0000 (UTC) Authentication-Results: mail.kernel.org; dkim=pass (2048-bit key) header.d=lists.infradead.org header.i=@lists.infradead.org header.b="CHgjsUg+"; dkim=fail reason="signature verification failed" (2048-bit key) header.d=gmail.com header.i=@gmail.com header.b="JUmO5RNk" DMARC-Filter: OpenDMARC Filter v1.3.2 mail.kernel.org 780DD2075B Authentication-Results: mail.kernel.org; dmarc=fail (p=none dis=none) header.from=gmail.com Authentication-Results: mail.kernel.org; spf=none smtp.mailfrom=linux-arm-kernel-bounces+patchwork-linux-arm=patchwork.kernel.org@lists.infradead.org DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=lists.infradead.org; s=merlin.20170209; h=Sender:Content-Transfer-Encoding: Content-Type:Cc:List-Subscribe:List-Help:List-Post:List-Archive: List-Unsubscribe:List-Id:MIME-Version:References:In-Reply-To:Message-Id:Date: Subject:To:From:Reply-To:Content-ID:Content-Description:Resent-Date: Resent-From:Resent-Sender:Resent-To:Resent-Cc:Resent-Message-ID:List-Owner; bh=AXRzOhDdx6KKyGhDayJPTODE46qJzlqYjtFMhn2JXzs=; b=CHgjsUg+HVblpSg7sk2EgEDRA ZzKQIax8Te8BVll/hmRUg3UnS6gHftUOnlLQvhCImoIrdR00XIsBDeyzHa8hUPxclQ5yIE69B0F8h lhoLDlxdRe3WmJYw06bM53zRLDFu6JinGhzbk4phMGOtt03uPis1UqWKdeBF1E3qU9XE17AXKuf+G Q7DZ1Y1ZukKq1tXgQ8ceaowmIlGS025xr36xJUhvKAT1vtYOCEnb/6JCgtub126T+QrjQxxzIGqB7 bwN3QhHirb+NTEVUpw6bSIZs+tPefmkCivFTJNN80H5UUC8q0wMBfmrZenwnzj39Uo1fR011WqFzh AVFJuq6aw==; Received: from localhost ([::1] helo=merlin.infradead.org) by merlin.infradead.org with esmtp (Exim 4.92.3 #3 (Red Hat Linux)) id 1kAHQA-0006T6-Gz; Mon, 24 Aug 2020 18:42:19 +0000 Received: from mail-pf1-x442.google.com ([2607:f8b0:4864:20::442]) by merlin.infradead.org with esmtps (Exim 4.92.3 #3 (Red Hat Linux)) id 1kAHPn-0006JT-IO for linux-arm-kernel@lists.infradead.org; Mon, 24 Aug 2020 18:42:07 +0000 Received: by mail-pf1-x442.google.com with SMTP id d188so5315070pfd.2 for ; Mon, 24 Aug 2020 11:41:55 -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 :mime-version:content-transfer-encoding; bh=Vh+B4OHEn3CAh3E4JWZmp8fkzNNMb5LEBb6Hamyy8Tc=; b=JUmO5RNkDzqb3ssc2377CipQcQnEwTUif8OMzJ8UJsCGRqUqiZ7bsPNRytHRETWgzA z/BwDi92y+BLYtJV15XE9znsz21+H5xltJCyFgQKWKCx4S3InX2g+Wi83LXwUKyU/jec OnhSg1FfXqBW5lwwN8VOFVoM6NSUQR5PvME5AuhuA7OftYymdJ2qlRkt7ptgbaR9Vf7v xKexsuhO1vNxJmYrrQ5xvdU9IGII3U0WVydOLZHF/nyeMHmar5ZeQJ6RlhWPftLDUZcN m8zTp6VhI/lR9lG4e669vVRaxVZEQa7cn6U1O41VGMi7sIA51s1uC7oC7PRUm5Xv82sy 5zQA== 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:mime-version:content-transfer-encoding; bh=Vh+B4OHEn3CAh3E4JWZmp8fkzNNMb5LEBb6Hamyy8Tc=; b=g4O5GCqfzzUlQtqYZ0urwFw4Fu4GCc/oYxQqsOzR2im2UmD5l3IEWMWmNtKrrGwGxh cvIwyXGH73zJVnpofpk6QiIyR4+dEf5yDS8zHxbNDzw72puTJqHuc53I2JD4Hv9tYi/P aWhLirFfXwWLyewCdopQtIF+5IV36vJxuLXwNvFLlaCEQoxIVd0Y4P29XWU0RZc6tlUt w4PPSgQpear6WwJU0Kg1d1GJu/tIhZENxnC/yU6oTlQpAojUGMShBhZ7NkyW8AA5RiCn vSF9nOW0v/tlqJZfYx2w8MMxOFeFQ7qDKo1D1wIpSFtH8uCU6X5OD2fzzNPM2J1pG6Gt Qy8A== X-Gm-Message-State: AOAM530+sa+HePiZjU3YdaVE+iXpyN2UoySpqzsX98GH6uGOhmpTPcGs sKHh/83dYMxbuQiD0kiL6R0= X-Google-Smtp-Source: ABdhPJw9/fDa2Sn4zgacdwxlaMCq/xKaWR5ndwkzMvOuKgpXpEP0Fd8T5IIeGdHrXE3OUHQFHgFobw== X-Received: by 2002:a63:1457:: with SMTP id 23mr4343869pgu.80.1598294513011; Mon, 24 Aug 2020 11:41:53 -0700 (PDT) Received: from localhost ([2601:1c0:5200:a6:307:a401:7b76:c6e5]) by smtp.gmail.com with ESMTPSA id e127sm3923071pfe.152.2020.08.24.11.41.50 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 24 Aug 2020 11:41:50 -0700 (PDT) From: Rob Clark To: dri-devel@lists.freedesktop.org, iommu@lists.linux-foundation.org Subject: [PATCH 02/20] iommu/arm-smmu: Pass io-pgtable config to implementation specific function Date: Mon, 24 Aug 2020 11:37:36 -0700 Message-Id: <20200824183825.1778810-3-robdclark@gmail.com> X-Mailer: git-send-email 2.26.2 In-Reply-To: <20200824183825.1778810-1-robdclark@gmail.com> References: <20200824183825.1778810-1-robdclark@gmail.com> MIME-Version: 1.0 X-CRM114-Version: 20100106-BlameMichelson ( TRE 0.8.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20200824_144155_930684_FDFB19D0 X-CRM114-Status: GOOD ( 17.91 ) X-Spam-Score: -0.2 (/) X-Spam-Report: SpamAssassin version 3.4.4 on merlin.infradead.org summary: Content analysis details: (-0.2 points) pts rule name description ---- ---------------------- -------------------------------------------------- -0.0 RCVD_IN_DNSWL_NONE RBL: Sender listed at https://www.dnswl.org/, no trust [2607:f8b0:4864:20:0:0:0:442 listed in] [list.dnswl.org] 0.0 FREEMAIL_FROM Sender email is commonly abused enduser mail provider [robdclark[at]gmail.com] 0.0 SPF_HELO_NONE SPF: HELO does not publish an SPF Record -0.0 SPF_PASS SPF: sender matches SPF record 0.1 DKIM_SIGNED Message has a DKIM or DK signature, not necessarily valid -0.1 DKIM_VALID_AU Message has a valid DKIM or DK signature from author's domain -0.1 DKIM_VALID_EF Message has a valid DKIM or DK signature from envelope-from domain -0.1 DKIM_VALID Message has at least one valid DKIM or DK signature X-BeenThere: linux-arm-kernel@lists.infradead.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: Akhil P Oommen , Bjorn Andersson , Eric Anholt , Thierry Reding , Vivek Gautam , AngeloGioacchino Del Regno , Will Deacon , Rob Clark , Sai Prakash Ranjan , Jonathan Marek , Joerg Roedel , Ben Dooks , Sibi Sankar , Brian Masney , freedreno@lists.freedesktop.org, Joerg Roedel , Stephen Boyd , John Stultz , "moderated list:ARM SMMU DRIVERS" , Greg Kroah-Hartman , Jordan Crouse , open list , Robin Murphy Sender: "linux-arm-kernel" Errors-To: linux-arm-kernel-bounces+patchwork-linux-arm=patchwork.kernel.org@lists.infradead.org From: Jordan Crouse Construct the io-pgtable config before calling the implementation specific init_context function and pass it so the implementation specific function can get a chance to change it before the io-pgtable is created. Signed-off-by: Jordan Crouse Signed-off-by: Rob Clark --- drivers/iommu/arm/arm-smmu/arm-smmu-impl.c | 3 ++- drivers/iommu/arm/arm-smmu/arm-smmu.c | 11 ++++++----- drivers/iommu/arm/arm-smmu/arm-smmu.h | 3 ++- 3 files changed, 10 insertions(+), 7 deletions(-) diff --git a/drivers/iommu/arm/arm-smmu/arm-smmu-impl.c b/drivers/iommu/arm/arm-smmu/arm-smmu-impl.c index f4ff124a1967..a9861dcd0884 100644 --- a/drivers/iommu/arm/arm-smmu/arm-smmu-impl.c +++ b/drivers/iommu/arm/arm-smmu/arm-smmu-impl.c @@ -68,7 +68,8 @@ static int cavium_cfg_probe(struct arm_smmu_device *smmu) return 0; } -static int cavium_init_context(struct arm_smmu_domain *smmu_domain) +static int cavium_init_context(struct arm_smmu_domain *smmu_domain, + struct io_pgtable_cfg *pgtbl_cfg) { struct cavium_smmu *cs = container_of(smmu_domain->smmu, struct cavium_smmu, smmu); diff --git a/drivers/iommu/arm/arm-smmu/arm-smmu.c b/drivers/iommu/arm/arm-smmu/arm-smmu.c index 09c42af9f31e..37d8d49299b4 100644 --- a/drivers/iommu/arm/arm-smmu/arm-smmu.c +++ b/drivers/iommu/arm/arm-smmu/arm-smmu.c @@ -795,11 +795,6 @@ static int arm_smmu_init_domain_context(struct iommu_domain *domain, cfg->asid = cfg->cbndx; smmu_domain->smmu = smmu; - if (smmu->impl && smmu->impl->init_context) { - ret = smmu->impl->init_context(smmu_domain); - if (ret) - goto out_unlock; - } pgtbl_cfg = (struct io_pgtable_cfg) { .pgsize_bitmap = smmu->pgsize_bitmap, @@ -810,6 +805,12 @@ static int arm_smmu_init_domain_context(struct iommu_domain *domain, .iommu_dev = smmu->dev, }; + if (smmu->impl && smmu->impl->init_context) { + ret = smmu->impl->init_context(smmu_domain, &pgtbl_cfg); + if (ret) + goto out_clear_smmu; + } + if (smmu_domain->non_strict) pgtbl_cfg.quirks |= IO_PGTABLE_QUIRK_NON_STRICT; diff --git a/drivers/iommu/arm/arm-smmu/arm-smmu.h b/drivers/iommu/arm/arm-smmu/arm-smmu.h index d890a4a968e8..83294516ac08 100644 --- a/drivers/iommu/arm/arm-smmu/arm-smmu.h +++ b/drivers/iommu/arm/arm-smmu/arm-smmu.h @@ -386,7 +386,8 @@ struct arm_smmu_impl { u64 val); int (*cfg_probe)(struct arm_smmu_device *smmu); int (*reset)(struct arm_smmu_device *smmu); - int (*init_context)(struct arm_smmu_domain *smmu_domain); + int (*init_context)(struct arm_smmu_domain *smmu_domain, + struct io_pgtable_cfg *cfg); void (*tlb_sync)(struct arm_smmu_device *smmu, int page, int sync, int status); int (*def_domain_type)(struct device *dev); From patchwork Mon Aug 24 18:37:37 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Rob Clark X-Patchwork-Id: 11734279 Return-Path: Received: from mail.kernel.org (pdx-korg-mail-1.web.codeaurora.org [172.30.200.123]) by pdx-korg-patchwork-2.web.codeaurora.org (Postfix) with ESMTP id 85979109B for ; Mon, 24 Aug 2020 19:48:00 +0000 (UTC) Received: from merlin.infradead.org (merlin.infradead.org [205.233.59.134]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by mail.kernel.org (Postfix) with ESMTPS id 59C5120706 for ; Mon, 24 Aug 2020 19:48:00 +0000 (UTC) Authentication-Results: mail.kernel.org; dkim=pass (2048-bit key) header.d=lists.infradead.org header.i=@lists.infradead.org header.b="gee7m3w5"; dkim=fail reason="signature verification failed" (2048-bit key) header.d=gmail.com header.i=@gmail.com header.b="QupFDcDQ" DMARC-Filter: OpenDMARC Filter v1.3.2 mail.kernel.org 59C5120706 Authentication-Results: mail.kernel.org; dmarc=fail (p=none dis=none) header.from=gmail.com Authentication-Results: mail.kernel.org; spf=none smtp.mailfrom=linux-arm-kernel-bounces+patchwork-linux-arm=patchwork.kernel.org@lists.infradead.org DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=lists.infradead.org; s=merlin.20170209; h=Sender:Content-Transfer-Encoding: Content-Type:Cc:List-Subscribe:List-Help:List-Post:List-Archive: List-Unsubscribe:List-Id:MIME-Version:References:In-Reply-To:Message-Id:Date: Subject:To:From:Reply-To:Content-ID:Content-Description:Resent-Date: Resent-From:Resent-Sender:Resent-To:Resent-Cc:Resent-Message-ID:List-Owner; bh=Z4J8Af1X6SnBhFwbg3cWqCxMopP5TJlkmyV7OAEN9VY=; b=gee7m3w5WsBHja95JMfOHVjrC E0Ms6U/vaE3u2o3LxOBCJVGowhxD1vAFrj4E0BHqjB9buVaN7F97hozUxTQM15/jBBN2TLDXVARI2 TcyMc1gvQf/cEFzPKKSr2sCCGvSDA2l88x2q01Hgc1m/jcqbD3us3YqcPm7MiW1mzJ4pxJBJY05wM hWoBawfS5l80naPt/lXmVKstS1BlRI5BA5+desZI9wWncO8ePjVrXtN7cWJoRMEEUMpQGdTa37sxH G26hGO/tlB/lFiopnVxjeHtnKDwcqQyaZSDvkamydtOAVJyKaUO2BiDUXPkMLKKleF6OolkDT6Yuc Hp51DV2nQ==; Received: from localhost ([::1] helo=merlin.infradead.org) by merlin.infradead.org with esmtp (Exim 4.92.3 #3 (Red Hat Linux)) id 1kAIQI-0006mI-71; Mon, 24 Aug 2020 19:46:30 +0000 Received: from mail-pg1-x541.google.com ([2607:f8b0:4864:20::541]) by merlin.infradead.org with esmtps (Exim 4.92.3 #3 (Red Hat Linux)) id 1kAHPs-0006Lt-0O for linux-arm-kernel@lists.infradead.org; Mon, 24 Aug 2020 18:42:14 +0000 Received: by mail-pg1-x541.google.com with SMTP id i10so4997501pgk.1 for ; Mon, 24 Aug 2020 11:41:59 -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 :mime-version:content-transfer-encoding; bh=UKeW4IJzF0CN62iFUBZf8N+0bUvXfOukk7MmGMWb73s=; b=QupFDcDQ+J/BaRegO7eha4+W6WwIpAwNtCuueunU/Y/sIUrOPF6mxnGAeRETIyCS9z 5jIDNS/oX7L3yzUY32LxAJia+VBQ9/wo7RmNYccWOYesqVTFba96QlyrsFlIwS1RXM0z F9o0Nm7Aqj9tYGNwaj1qKEHCLghoGaOkjZ81BDEpbFj9zH6o44UA7diBGGGoVYYl9Ogg FgU8yOPrK5XQW8QlEnjxPDgptp99FMIj2Fq3CJLqDbawVqOALIdqDaWqHDJNsNVQF66B TkgKrNn/0ND6uGJb4BagXQ5NFy40qmczg7hakt4rgG7Fqoj1E9KonvWfdmjoH+5M6qcc oMQA== 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:mime-version:content-transfer-encoding; bh=UKeW4IJzF0CN62iFUBZf8N+0bUvXfOukk7MmGMWb73s=; b=Mop50iMArckklTvIp3lADKE01dVDAmtkomh9XU43t2FNm2ni11yvdREbvL+uosZJGg yeZjyP8m7nD//2WlyhOvvi3xIJc0S1gOU5nSYsSKlvyjjs3dCTR4fmjuwO+gKNj94uXp zg179ljs4IAQ+lx/kIqPywZx0gT53WiAmbDk2VZEinUuR8XywL00RmPu9T+twQRxP1yY U1BSZLEL+hAZHKQf1AlEaxFrSTPjzaJU9F3t83Dth7XCrGyKcRYravztskE702hH9p/c 3nX3W31Dq5w89obUdpBLKtRwY5YSdumOBqIHJIW9johfqtO3Cy4wqsavcm35xa+GArB6 MJPA== X-Gm-Message-State: AOAM531cPSPNh8k+Jgg8SkY5NC6oPcoS7ejwygnNr6xjdxvNtKE3YvUe h6dLzZ9JD99ScdTtz4mZfIE= X-Google-Smtp-Source: ABdhPJxn13wAUy7w/ZA3PkY4X0k1/D35A+O3YPsK8fwkZ0jAk5+bBLMZwY56hTkxAOOJZKTpQNkmdQ== X-Received: by 2002:a17:902:82c7:: with SMTP id u7mr4781570plz.310.1598294517871; Mon, 24 Aug 2020 11:41:57 -0700 (PDT) Received: from localhost ([2601:1c0:5200:a6:307:a401:7b76:c6e5]) by smtp.gmail.com with ESMTPSA id z17sm12923442pfq.38.2020.08.24.11.41.56 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 24 Aug 2020 11:41:56 -0700 (PDT) From: Rob Clark To: dri-devel@lists.freedesktop.org, iommu@lists.linux-foundation.org Subject: [PATCH 03/20] iommu/arm-smmu: Add support for split pagetables Date: Mon, 24 Aug 2020 11:37:37 -0700 Message-Id: <20200824183825.1778810-4-robdclark@gmail.com> X-Mailer: git-send-email 2.26.2 In-Reply-To: <20200824183825.1778810-1-robdclark@gmail.com> References: <20200824183825.1778810-1-robdclark@gmail.com> MIME-Version: 1.0 X-CRM114-Version: 20100106-BlameMichelson ( TRE 0.8.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20200824_144200_279088_A8C816CE X-CRM114-Status: GOOD ( 19.63 ) X-Spam-Score: -0.2 (/) X-Spam-Report: SpamAssassin version 3.4.4 on merlin.infradead.org summary: Content analysis details: (-0.2 points) pts rule name description ---- ---------------------- -------------------------------------------------- -0.0 RCVD_IN_DNSWL_NONE RBL: Sender listed at https://www.dnswl.org/, no trust [2607:f8b0:4864:20:0:0:0:541 listed in] [list.dnswl.org] 0.0 FREEMAIL_FROM Sender email is commonly abused enduser mail provider [robdclark[at]gmail.com] 0.0 SPF_HELO_NONE SPF: HELO does not publish an SPF Record -0.0 SPF_PASS SPF: sender matches SPF record 0.1 DKIM_SIGNED Message has a DKIM or DK signature, not necessarily valid -0.1 DKIM_VALID_AU Message has a valid DKIM or DK signature from author's domain -0.1 DKIM_VALID_EF Message has a valid DKIM or DK signature from envelope-from domain -0.1 DKIM_VALID Message has at least one valid DKIM or DK signature X-BeenThere: linux-arm-kernel@lists.infradead.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: Akhil P Oommen , Bjorn Andersson , Eric Anholt , Vivek Gautam , AngeloGioacchino Del Regno , Will Deacon , Rob Clark , Sai Prakash Ranjan , Jonathan Marek , Joerg Roedel , Jon Hunter , Ben Dooks , Sibi Sankar , Brian Masney , freedreno@lists.freedesktop.org, Joerg Roedel , Stephen Boyd , John Stultz , "moderated list:ARM SMMU DRIVERS" , Greg Kroah-Hartman , Jordan Crouse , open list , Robin Murphy Sender: "linux-arm-kernel" Errors-To: linux-arm-kernel-bounces+patchwork-linux-arm=patchwork.kernel.org@lists.infradead.org From: Jordan Crouse Enable TTBR1 for a context bank if IO_PGTABLE_QUIRK_ARM_TTBR1 is selected by the io-pgtable configuration. Signed-off-by: Jordan Crouse Signed-off-by: Rob Clark --- drivers/iommu/arm/arm-smmu/arm-smmu.c | 21 ++++++++++++++++----- drivers/iommu/arm/arm-smmu/arm-smmu.h | 25 +++++++++++++++++++------ 2 files changed, 35 insertions(+), 11 deletions(-) diff --git a/drivers/iommu/arm/arm-smmu/arm-smmu.c b/drivers/iommu/arm/arm-smmu/arm-smmu.c index 37d8d49299b4..976d43a7f2ff 100644 --- a/drivers/iommu/arm/arm-smmu/arm-smmu.c +++ b/drivers/iommu/arm/arm-smmu/arm-smmu.c @@ -552,11 +552,15 @@ static void arm_smmu_init_context_bank(struct arm_smmu_domain *smmu_domain, cb->ttbr[0] = pgtbl_cfg->arm_v7s_cfg.ttbr; cb->ttbr[1] = 0; } else { - cb->ttbr[0] = pgtbl_cfg->arm_lpae_s1_cfg.ttbr; - cb->ttbr[0] |= FIELD_PREP(ARM_SMMU_TTBRn_ASID, - cfg->asid); + cb->ttbr[0] = FIELD_PREP(ARM_SMMU_TTBRn_ASID, + cfg->asid); cb->ttbr[1] = FIELD_PREP(ARM_SMMU_TTBRn_ASID, - cfg->asid); + cfg->asid); + + if (pgtbl_cfg->quirks & IO_PGTABLE_QUIRK_ARM_TTBR1) + cb->ttbr[1] |= pgtbl_cfg->arm_lpae_s1_cfg.ttbr; + else + cb->ttbr[0] |= pgtbl_cfg->arm_lpae_s1_cfg.ttbr; } } else { cb->ttbr[0] = pgtbl_cfg->arm_lpae_s2_cfg.vttbr; @@ -822,7 +826,14 @@ static int arm_smmu_init_domain_context(struct iommu_domain *domain, /* Update the domain's page sizes to reflect the page table format */ domain->pgsize_bitmap = pgtbl_cfg.pgsize_bitmap; - domain->geometry.aperture_end = (1UL << ias) - 1; + + if (pgtbl_cfg.quirks & IO_PGTABLE_QUIRK_ARM_TTBR1) { + domain->geometry.aperture_start = ~0UL << ias; + domain->geometry.aperture_end = ~0UL; + } else { + domain->geometry.aperture_end = (1UL << ias) - 1; + } + domain->geometry.force_aperture = true; /* Initialise the context bank with our page table cfg */ diff --git a/drivers/iommu/arm/arm-smmu/arm-smmu.h b/drivers/iommu/arm/arm-smmu/arm-smmu.h index 83294516ac08..f3e456893f28 100644 --- a/drivers/iommu/arm/arm-smmu/arm-smmu.h +++ b/drivers/iommu/arm/arm-smmu/arm-smmu.h @@ -169,10 +169,12 @@ enum arm_smmu_cbar_type { #define ARM_SMMU_CB_TCR 0x30 #define ARM_SMMU_TCR_EAE BIT(31) #define ARM_SMMU_TCR_EPD1 BIT(23) +#define ARM_SMMU_TCR_A1 BIT(22) #define ARM_SMMU_TCR_TG0 GENMASK(15, 14) #define ARM_SMMU_TCR_SH0 GENMASK(13, 12) #define ARM_SMMU_TCR_ORGN0 GENMASK(11, 10) #define ARM_SMMU_TCR_IRGN0 GENMASK(9, 8) +#define ARM_SMMU_TCR_EPD0 BIT(7) #define ARM_SMMU_TCR_T0SZ GENMASK(5, 0) #define ARM_SMMU_VTCR_RES1 BIT(31) @@ -350,12 +352,23 @@ struct arm_smmu_domain { static inline u32 arm_smmu_lpae_tcr(struct io_pgtable_cfg *cfg) { - return ARM_SMMU_TCR_EPD1 | - FIELD_PREP(ARM_SMMU_TCR_TG0, cfg->arm_lpae_s1_cfg.tcr.tg) | - FIELD_PREP(ARM_SMMU_TCR_SH0, cfg->arm_lpae_s1_cfg.tcr.sh) | - FIELD_PREP(ARM_SMMU_TCR_ORGN0, cfg->arm_lpae_s1_cfg.tcr.orgn) | - FIELD_PREP(ARM_SMMU_TCR_IRGN0, cfg->arm_lpae_s1_cfg.tcr.irgn) | - FIELD_PREP(ARM_SMMU_TCR_T0SZ, cfg->arm_lpae_s1_cfg.tcr.tsz); + u32 tcr = FIELD_PREP(ARM_SMMU_TCR_TG0, cfg->arm_lpae_s1_cfg.tcr.tg) | + FIELD_PREP(ARM_SMMU_TCR_SH0, cfg->arm_lpae_s1_cfg.tcr.sh) | + FIELD_PREP(ARM_SMMU_TCR_ORGN0, cfg->arm_lpae_s1_cfg.tcr.orgn) | + FIELD_PREP(ARM_SMMU_TCR_IRGN0, cfg->arm_lpae_s1_cfg.tcr.irgn) | + FIELD_PREP(ARM_SMMU_TCR_T0SZ, cfg->arm_lpae_s1_cfg.tcr.tsz); + + /* + * When TTBR1 is selected shift the TCR fields by 16 bits and disable + * translation in TTBR0 + */ + if (cfg->quirks & IO_PGTABLE_QUIRK_ARM_TTBR1) { + tcr = (tcr << 16) & ~ARM_SMMU_TCR_A1; + tcr |= ARM_SMMU_TCR_EPD0; + } else + tcr |= ARM_SMMU_TCR_EPD1; + + return tcr; } static inline u32 arm_smmu_lpae_tcr2(struct io_pgtable_cfg *cfg) From patchwork Mon Aug 24 18:37:38 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Rob Clark X-Patchwork-Id: 11734105 Return-Path: Received: from mail.kernel.org (pdx-korg-mail-1.web.codeaurora.org [172.30.200.123]) by pdx-korg-patchwork-2.web.codeaurora.org (Postfix) with ESMTP id A92CF13A4 for ; Mon, 24 Aug 2020 18:45:25 +0000 (UTC) Received: from merlin.infradead.org (merlin.infradead.org [205.233.59.134]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by mail.kernel.org (Postfix) with ESMTPS id 7182420702 for ; Mon, 24 Aug 2020 18:45:25 +0000 (UTC) Authentication-Results: mail.kernel.org; dkim=pass (2048-bit key) header.d=lists.infradead.org header.i=@lists.infradead.org header.b="RDh1DWFz"; dkim=fail reason="signature verification failed" (2048-bit key) header.d=gmail.com header.i=@gmail.com header.b="HY44/UZ/" DMARC-Filter: OpenDMARC Filter v1.3.2 mail.kernel.org 7182420702 Authentication-Results: mail.kernel.org; dmarc=fail (p=none dis=none) header.from=gmail.com Authentication-Results: mail.kernel.org; spf=none smtp.mailfrom=linux-arm-kernel-bounces+patchwork-linux-arm=patchwork.kernel.org@lists.infradead.org DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=lists.infradead.org; s=merlin.20170209; h=Sender:Content-Transfer-Encoding: Content-Type:Cc:List-Subscribe:List-Help:List-Post:List-Archive: List-Unsubscribe:List-Id:MIME-Version:References:In-Reply-To:Message-Id:Date: Subject:To:From:Reply-To:Content-ID:Content-Description:Resent-Date: Resent-From:Resent-Sender:Resent-To:Resent-Cc:Resent-Message-ID:List-Owner; bh=xP+bDklortGM9EOuO9ude/vmT5Fl0FC9imFmzxlnlCo=; b=RDh1DWFzvb+suvMR6k94XtAEm iZ2JbTZTEKXjOQWVoKG61qrfqqHsu/YAadGwPfoWkCEKRLP04u4+OfFufzsiL5YDvc0LWZUxyEBQk dyMNAQ/zqEuN/TFb/zIuU+xZeiuGIysA62ySmZTEnDs8PAzKhWF89WtxwzfAUyfEQ+yLyWqht3eFY JwTNO4elmKsbNPCu1G/+Re+SYHVpYlxEawKAKfapCdxeDo72FrzTiUsfn0HjX72Kb5s5vb1/BEfEP yAg2Q6DjRly4IKgzhGlqOWhpgIzEJrAr1JrPpo3go8flz2vsgm/rSax4Rt3uAUor/sK3Crrq70kv8 ebIYrAIug==; Received: from localhost ([::1] helo=merlin.infradead.org) by merlin.infradead.org with esmtp (Exim 4.92.3 #3 (Red Hat Linux)) id 1kAHR9-0006qp-3H; Mon, 24 Aug 2020 18:43:19 +0000 Received: from mail-pj1-x1043.google.com ([2607:f8b0:4864:20::1043]) by merlin.infradead.org with esmtps (Exim 4.92.3 #3 (Red Hat Linux)) id 1kAHPy-0006PN-Pw for linux-arm-kernel@lists.infradead.org; Mon, 24 Aug 2020 18:42:25 +0000 Received: by mail-pj1-x1043.google.com with SMTP id d4so4655281pjx.5 for ; Mon, 24 Aug 2020 11:42: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 :mime-version:content-transfer-encoding; bh=JJBCzjdmyb2nZnzBMd/gov55QLqdNUOfxSOvqrduYU8=; b=HY44/UZ/nLE7X8pcuz4VJ5HV9Ykr5wcVm2VByp+t0CzJ0h5mJvjGNHTYllu4a3r3mC RukCtL3sRFhU/I3E6Us9H9ph9W4pus32g4mY3QiTVvYv8khTj8jNeBO47E43ZUMAvPu1 wMmbEX1Jn6xgOc4H89uBgwmV0M+d5FW50OwdpP99vUSpG8ZT/dDnuQPzgLZ0P9ch7seR /6YCqPMyOW06ysuxLTOy7JnxNkIGQDWXfuS4wPzVtiBWU30DgwHXhhYKKGgeqCMtKBJO axaR3FWQabZrYRR1RmHljPHhHCUsjVq3GWfkrAtQXRuflYc6gskI36DKQieTGfsW1eEe IBzA== 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:mime-version:content-transfer-encoding; bh=JJBCzjdmyb2nZnzBMd/gov55QLqdNUOfxSOvqrduYU8=; b=QupaakAxYsb8n9tnnxvvZhKPxYvoUxszZ/MPaAmxJwVllIqc1eR3fNBovz3YJR4aJQ JIwYZGhIFS+Nrdv7SodmUsy0hvYVevGG+HR7edB3ejHycFWFBswSoLxyiKsd/v6TWUuI hD3O7kqrYK1yB16Oz2jP+tTqjo4ZePLPto9YSL2vqHTFhvJ2FZqsNrGCyYSPesJhUkTB GtY3WAAav1iK3ReJNVMCnIpUMRIK8h47PwFTJJSbf5+sO9AnvXUo5+SR6fLy0/CiCGsX +55HI2p6LU97zY2RKOTj2//MNsh+JEZui40xFLGv+8qJSdUvBNoSvmNXzr3/JPZ63gUi jmow== X-Gm-Message-State: AOAM531bUVfNYnCuGvK2FGdvjXp78xYq2rZElKIEOaRous6tIU5G6w6k 1PTmCVT5ILAn54wGzQ7p/2w= X-Google-Smtp-Source: ABdhPJxmZ3rKA6ZbIy+IHcA9BbxPvwO33teorMHX+NeaV8ySRNf/bYk1IHwDtqfKF/fGnXZC8uEEuQ== X-Received: by 2002:a17:90a:ce94:: with SMTP id g20mr475969pju.61.1598294524710; Mon, 24 Aug 2020 11:42:04 -0700 (PDT) Received: from localhost ([2601:1c0:5200:a6:307:a401:7b76:c6e5]) by smtp.gmail.com with ESMTPSA id z1sm10216599pgf.94.2020.08.24.11.42.02 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 24 Aug 2020 11:42:03 -0700 (PDT) From: Rob Clark To: dri-devel@lists.freedesktop.org, iommu@lists.linux-foundation.org Subject: [PATCH 04/20] iommu/arm-smmu: Prepare for the adreno-smmu implementation Date: Mon, 24 Aug 2020 11:37:38 -0700 Message-Id: <20200824183825.1778810-5-robdclark@gmail.com> X-Mailer: git-send-email 2.26.2 In-Reply-To: <20200824183825.1778810-1-robdclark@gmail.com> References: <20200824183825.1778810-1-robdclark@gmail.com> MIME-Version: 1.0 X-CRM114-Version: 20100106-BlameMichelson ( TRE 0.8.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20200824_144207_008860_CCAD27BC X-CRM114-Status: GOOD ( 24.48 ) X-Spam-Score: -0.2 (/) X-Spam-Report: SpamAssassin version 3.4.4 on merlin.infradead.org summary: Content analysis details: (-0.2 points) pts rule name description ---- ---------------------- -------------------------------------------------- -0.0 RCVD_IN_DNSWL_NONE RBL: Sender listed at https://www.dnswl.org/, no trust [2607:f8b0:4864:20:0:0:0:1043 listed in] [list.dnswl.org] 0.0 FREEMAIL_FROM Sender email is commonly abused enduser mail provider [robdclark[at]gmail.com] 0.0 SPF_HELO_NONE SPF: HELO does not publish an SPF Record -0.0 SPF_PASS SPF: sender matches SPF record 0.1 DKIM_SIGNED Message has a DKIM or DK signature, not necessarily valid -0.1 DKIM_VALID_AU Message has a valid DKIM or DK signature from author's domain -0.1 DKIM_VALID_EF Message has a valid DKIM or DK signature from envelope-from domain -0.1 DKIM_VALID Message has at least one valid DKIM or DK signature X-BeenThere: linux-arm-kernel@lists.infradead.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: Akhil P Oommen , Bjorn Andersson , Eric Anholt , Vivek Gautam , AngeloGioacchino Del Regno , Will Deacon , Rob Clark , Sai Prakash Ranjan , Jonathan Marek , Joerg Roedel , Ben Dooks , Sibi Sankar , Brian Masney , freedreno@lists.freedesktop.org, Joerg Roedel , Pritesh Raithatha , John Stultz , Stephen Boyd , "moderated list:ARM SMMU DRIVERS" , Greg Kroah-Hartman , Jordan Crouse , open list , Robin Murphy Sender: "linux-arm-kernel" Errors-To: linux-arm-kernel-bounces+patchwork-linux-arm=patchwork.kernel.org@lists.infradead.org From: Jordan Crouse Do a bit of prep work to add the upcoming adreno-smmu implementation. Add an hook to allow the implementation to choose which context banks to allocate. Move some of the common structs to arm-smmu.h in anticipation of them being used by the implementations and update some of the existing hooks to pass more information that the implementation will need. These modifications will be used by the upcoming Adreno SMMU implementation to identify the GPU device and properly configure it for pagetable switching. Co-developed-by: Rob Clark Signed-off-by: Jordan Crouse Signed-off-by: Rob Clark --- drivers/iommu/arm/arm-smmu/arm-smmu-impl.c | 2 +- drivers/iommu/arm/arm-smmu/arm-smmu.c | 69 ++++++---------------- drivers/iommu/arm/arm-smmu/arm-smmu.h | 51 +++++++++++++++- 3 files changed, 68 insertions(+), 54 deletions(-) diff --git a/drivers/iommu/arm/arm-smmu/arm-smmu-impl.c b/drivers/iommu/arm/arm-smmu/arm-smmu-impl.c index a9861dcd0884..88f17cc33023 100644 --- a/drivers/iommu/arm/arm-smmu/arm-smmu-impl.c +++ b/drivers/iommu/arm/arm-smmu/arm-smmu-impl.c @@ -69,7 +69,7 @@ static int cavium_cfg_probe(struct arm_smmu_device *smmu) } static int cavium_init_context(struct arm_smmu_domain *smmu_domain, - struct io_pgtable_cfg *pgtbl_cfg) + struct io_pgtable_cfg *pgtbl_cfg, struct device *dev) { struct cavium_smmu *cs = container_of(smmu_domain->smmu, struct cavium_smmu, smmu); diff --git a/drivers/iommu/arm/arm-smmu/arm-smmu.c b/drivers/iommu/arm/arm-smmu/arm-smmu.c index 976d43a7f2ff..e63a480d7f71 100644 --- a/drivers/iommu/arm/arm-smmu/arm-smmu.c +++ b/drivers/iommu/arm/arm-smmu/arm-smmu.c @@ -65,41 +65,10 @@ module_param(disable_bypass, bool, S_IRUGO); MODULE_PARM_DESC(disable_bypass, "Disable bypass streams such that incoming transactions from devices that are not attached to an iommu domain will report an abort back to the device and will not be allowed to pass through the SMMU."); -struct arm_smmu_s2cr { - struct iommu_group *group; - int count; - enum arm_smmu_s2cr_type type; - enum arm_smmu_s2cr_privcfg privcfg; - u8 cbndx; -}; - #define s2cr_init_val (struct arm_smmu_s2cr){ \ .type = disable_bypass ? S2CR_TYPE_FAULT : S2CR_TYPE_BYPASS, \ } -struct arm_smmu_smr { - u16 mask; - u16 id; - bool valid; -}; - -struct arm_smmu_cb { - u64 ttbr[2]; - u32 tcr[2]; - u32 mair[2]; - struct arm_smmu_cfg *cfg; -}; - -struct arm_smmu_master_cfg { - struct arm_smmu_device *smmu; - s16 smendx[]; -}; -#define INVALID_SMENDX -1 -#define cfg_smendx(cfg, fw, i) \ - (i >= fw->num_ids ? INVALID_SMENDX : cfg->smendx[i]) -#define for_each_cfg_sme(cfg, fw, i, idx) \ - for (i = 0; idx = cfg_smendx(cfg, fw, i), i < fw->num_ids; ++i) - static bool using_legacy_binding, using_generic_binding; static inline int arm_smmu_rpm_get(struct arm_smmu_device *smmu) @@ -234,19 +203,6 @@ static int arm_smmu_register_legacy_master(struct device *dev, } #endif /* CONFIG_ARM_SMMU_LEGACY_DT_BINDINGS */ -static int __arm_smmu_alloc_bitmap(unsigned long *map, int start, int end) -{ - int idx; - - do { - idx = find_next_zero_bit(map, end, start); - if (idx == end) - return -ENOSPC; - } while (test_and_set_bit(idx, map)); - - return idx; -} - static void __arm_smmu_free_bitmap(unsigned long *map, int idx) { clear_bit(idx, map); @@ -578,7 +534,7 @@ static void arm_smmu_init_context_bank(struct arm_smmu_domain *smmu_domain, } } -static void arm_smmu_write_context_bank(struct arm_smmu_device *smmu, int idx) +void arm_smmu_write_context_bank(struct arm_smmu_device *smmu, int idx) { u32 reg; bool stage1; @@ -665,7 +621,8 @@ static void arm_smmu_write_context_bank(struct arm_smmu_device *smmu, int idx) } static int arm_smmu_init_domain_context(struct iommu_domain *domain, - struct arm_smmu_device *smmu) + struct arm_smmu_device *smmu, + struct device *dev) { int irq, start, ret = 0; unsigned long ias, oas; @@ -780,10 +737,20 @@ static int arm_smmu_init_domain_context(struct iommu_domain *domain, ret = -EINVAL; goto out_unlock; } - ret = __arm_smmu_alloc_bitmap(smmu->context_map, start, + + smmu_domain->smmu = smmu; + + if (smmu->impl && smmu->impl->alloc_context_bank) + ret = smmu->impl->alloc_context_bank(smmu_domain, dev, + start, smmu->num_context_banks); + else + ret = __arm_smmu_alloc_bitmap(smmu->context_map, start, smmu->num_context_banks); - if (ret < 0) + + if (ret < 0) { + smmu_domain->smmu = NULL; goto out_unlock; + } cfg->cbndx = ret; if (smmu->version < ARM_SMMU_V2) { @@ -798,8 +765,6 @@ static int arm_smmu_init_domain_context(struct iommu_domain *domain, else cfg->asid = cfg->cbndx; - smmu_domain->smmu = smmu; - pgtbl_cfg = (struct io_pgtable_cfg) { .pgsize_bitmap = smmu->pgsize_bitmap, .ias = ias, @@ -810,7 +775,7 @@ static int arm_smmu_init_domain_context(struct iommu_domain *domain, }; if (smmu->impl && smmu->impl->init_context) { - ret = smmu->impl->init_context(smmu_domain, &pgtbl_cfg); + ret = smmu->impl->init_context(smmu_domain, &pgtbl_cfg, dev); if (ret) goto out_clear_smmu; } @@ -1194,7 +1159,7 @@ static int arm_smmu_attach_dev(struct iommu_domain *domain, struct device *dev) return ret; /* Ensure that the domain is finalised */ - ret = arm_smmu_init_domain_context(domain, smmu); + ret = arm_smmu_init_domain_context(domain, smmu, dev); if (ret < 0) goto rpm_put; diff --git a/drivers/iommu/arm/arm-smmu/arm-smmu.h b/drivers/iommu/arm/arm-smmu/arm-smmu.h index f3e456893f28..59ff3fc5c6c8 100644 --- a/drivers/iommu/arm/arm-smmu/arm-smmu.h +++ b/drivers/iommu/arm/arm-smmu/arm-smmu.h @@ -256,6 +256,21 @@ enum arm_smmu_implementation { QCOM_SMMUV2, }; +struct arm_smmu_s2cr { + struct iommu_group *group; + int count; + enum arm_smmu_s2cr_type type; + enum arm_smmu_s2cr_privcfg privcfg; + u8 cbndx; +}; + +struct arm_smmu_smr { + u16 mask; + u16 id; + bool valid; + bool pinned; +}; + struct arm_smmu_device { struct device *dev; @@ -331,6 +346,13 @@ struct arm_smmu_cfg { }; #define ARM_SMMU_INVALID_IRPTNDX 0xff +struct arm_smmu_cb { + u64 ttbr[2]; + u32 tcr[2]; + u32 mair[2]; + struct arm_smmu_cfg *cfg; +}; + enum arm_smmu_domain_stage { ARM_SMMU_DOMAIN_S1 = 0, ARM_SMMU_DOMAIN_S2, @@ -350,6 +372,11 @@ struct arm_smmu_domain { struct iommu_domain domain; }; +struct arm_smmu_master_cfg { + struct arm_smmu_device *smmu; + s16 smendx[]; +}; + static inline u32 arm_smmu_lpae_tcr(struct io_pgtable_cfg *cfg) { u32 tcr = FIELD_PREP(ARM_SMMU_TCR_TG0, cfg->arm_lpae_s1_cfg.tcr.tg) | @@ -400,14 +427,35 @@ struct arm_smmu_impl { int (*cfg_probe)(struct arm_smmu_device *smmu); int (*reset)(struct arm_smmu_device *smmu); int (*init_context)(struct arm_smmu_domain *smmu_domain, - struct io_pgtable_cfg *cfg); + struct io_pgtable_cfg *cfg, struct device *dev); void (*tlb_sync)(struct arm_smmu_device *smmu, int page, int sync, int status); int (*def_domain_type)(struct device *dev); irqreturn_t (*global_fault)(int irq, void *dev); irqreturn_t (*context_fault)(int irq, void *dev); + int (*alloc_context_bank)(struct arm_smmu_domain *smmu_domain, + struct device *dev, int start, int max); }; +#define INVALID_SMENDX -1 +#define cfg_smendx(cfg, fw, i) \ + (i >= fw->num_ids ? INVALID_SMENDX : cfg->smendx[i]) +#define for_each_cfg_sme(cfg, fw, i, idx) \ + for (i = 0; idx = cfg_smendx(cfg, fw, i), i < fw->num_ids; ++i) + +static inline int __arm_smmu_alloc_bitmap(unsigned long *map, int start, int end) +{ + int idx; + + do { + idx = find_next_zero_bit(map, end, start); + if (idx == end) + return -ENOSPC; + } while (test_and_set_bit(idx, map)); + + return idx; +} + static inline void __iomem *arm_smmu_page(struct arm_smmu_device *smmu, int n) { return smmu->base + (n << smmu->pgshift); @@ -472,6 +520,7 @@ struct arm_smmu_device *arm_smmu_impl_init(struct arm_smmu_device *smmu); struct arm_smmu_device *nvidia_smmu_impl_init(struct arm_smmu_device *smmu); struct arm_smmu_device *qcom_smmu_impl_init(struct arm_smmu_device *smmu); +void arm_smmu_write_context_bank(struct arm_smmu_device *smmu, int idx); int arm_mmu500_reset(struct arm_smmu_device *smmu); #endif /* _ARM_SMMU_H */ From patchwork Mon Aug 24 18:37:42 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Rob Clark X-Patchwork-Id: 11734107 Return-Path: Received: from mail.kernel.org (pdx-korg-mail-1.web.codeaurora.org [172.30.200.123]) by pdx-korg-patchwork-2.web.codeaurora.org (Postfix) with ESMTP id 4E07C1510 for ; Mon, 24 Aug 2020 18:45:42 +0000 (UTC) Received: from merlin.infradead.org (merlin.infradead.org [205.233.59.134]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by mail.kernel.org (Postfix) with ESMTPS id 2739C20738 for ; Mon, 24 Aug 2020 18:45:42 +0000 (UTC) Authentication-Results: mail.kernel.org; dkim=pass (2048-bit key) header.d=lists.infradead.org header.i=@lists.infradead.org header.b="hu+8NJDQ"; dkim=fail reason="signature verification failed" (2048-bit key) header.d=gmail.com header.i=@gmail.com header.b="PuQRr8H0" DMARC-Filter: OpenDMARC Filter v1.3.2 mail.kernel.org 2739C20738 Authentication-Results: mail.kernel.org; dmarc=fail (p=none dis=none) header.from=gmail.com Authentication-Results: mail.kernel.org; spf=none smtp.mailfrom=linux-arm-kernel-bounces+patchwork-linux-arm=patchwork.kernel.org@lists.infradead.org DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=lists.infradead.org; s=merlin.20170209; h=Sender:Content-Transfer-Encoding: Content-Type:Cc:List-Subscribe:List-Help:List-Post:List-Archive: List-Unsubscribe:List-Id:MIME-Version:References:In-Reply-To:Message-Id:Date: Subject:To:From:Reply-To:Content-ID:Content-Description:Resent-Date: Resent-From:Resent-Sender:Resent-To:Resent-Cc:Resent-Message-ID:List-Owner; bh=jc0NJCDp7ZGxhq8raQfSLsajvjs78iVcq7F5RP1+4vw=; b=hu+8NJDQr0+LoeBVy2KyW2o7a 6P6Vly/YxAWtEUDdyorPN3ED3ptxTbWQGKQXZABbrn+kb7X0BhE3WIl9hC3TjVU5IbSXMS/aDjcHa raYKn3MvVkjf7cbIPLgBSVy0j+OzZlRW6s54lWb9dHpiAjiq/eO2lCwn1kciioZqfQAoelVGWuM4J 5Hs73M+7YVER28iPmQGu7YexIMwhxQOa5OYBK/Yx4LrkLbgijs8IUt4VBzT5kC/+h5feANlzv2KLF xYwDz1ZRFPn8ctTWVCBXq2KnI2YTK/Qu/v3ODd2ByPCEcRwPnnYglWtf+F0HDQfbgwJV0B5ODdIA5 HvVTWFCkA==; Received: from localhost ([::1] helo=merlin.infradead.org) by merlin.infradead.org with esmtp (Exim 4.92.3 #3 (Red Hat Linux)) id 1kAHRd-00078b-FL; Mon, 24 Aug 2020 18:43:49 +0000 Received: from mail-pf1-x444.google.com ([2607:f8b0:4864:20::444]) by merlin.infradead.org with esmtps (Exim 4.92.3 #3 (Red Hat Linux)) id 1kAHQG-0006X4-Lu for linux-arm-kernel@lists.infradead.org; Mon, 24 Aug 2020 18:42:37 +0000 Received: by mail-pf1-x444.google.com with SMTP id t185so2199138pfd.13 for ; Mon, 24 Aug 2020 11:42:23 -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 :mime-version:content-transfer-encoding; bh=kSk9Ml31XbJOG2f57h64F+Z+u/H7LjegKljJVlxq3/o=; b=PuQRr8H0J0Wm/JwS7TDm/n1aaDYpCp+u0Xhtd6ySCS+jIDk3G8tZ+NTj4I9yJl9Xi0 ESlNd1bOyyh7orw4FugAlt6b+4E1XyjwB3dT9M21/hTZnBuqymaPtGRryP6vooFDmeCg WBeYpuFK/VhIFBz/ID3oiWyAmocmTWpc71sVReALesHl5XDdOuMmx5BRB2l0jgjEdjjL 7NTUSfmUhr5gmrltKw5aeVI4wrDhmcyD8K51sVTFDE2s9RgvK0yi5wbt0jyc43vGwnz6 llUJuwX98+NWd8VFREqSV3FObuRD5JQgg65Tdc9SiDaD++ha9SxdK+F2yxcFANSDRVgN 6ErA== 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:mime-version:content-transfer-encoding; bh=kSk9Ml31XbJOG2f57h64F+Z+u/H7LjegKljJVlxq3/o=; b=ris03Cc2HpxpdhDP+Ld+YFAFUWYofrF5zPwFKbto1d1E+kk/jWwD8Q+cp2e48CjLzU HrY7Zn5crrHXMJee9vyLySIV7tN7k7+Pt31TZY8//TIOScSNT28h44L2QNxT2SgxPE4U oYAN/wrcm3YN9/UUjrGHq6q/92yUqEKQ1qIYivGRRdbAaztcowyWpPc2WzJwmSoIT2VE NWew5lRzY+5KKoofRJ/owm44t/t0OytKbPuGw2r41tPzirh0PGTg4QSHWYxC5z79zli0 rtWTRM+Fw7+91y5NKr1zUjKOqYO+sHBAHhKvjY/uMw7K+WR9m6cGVs6zDKoIuwqaEaIO c8/g== X-Gm-Message-State: AOAM532LJ6Qf07e0lThRlN3T8BFLyp5dngsYMvMzBxlvHH8dxxLIbbmD pHHtfdh3FqJhPHk9JXbdhWU= X-Google-Smtp-Source: ABdhPJypoRetU1pm/hYk35duEuEDV/9I1qEX2ndUelby0c1VRDwOv61H6tDsCuRdB0ISZKdafjLiDQ== X-Received: by 2002:a17:902:7792:: with SMTP id o18mr4697906pll.150.1598294542026; Mon, 24 Aug 2020 11:42:22 -0700 (PDT) Received: from localhost ([2601:1c0:5200:a6:307:a401:7b76:c6e5]) by smtp.gmail.com with ESMTPSA id p12sm11985571pff.110.2020.08.24.11.42.20 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 24 Aug 2020 11:42:20 -0700 (PDT) From: Rob Clark To: dri-devel@lists.freedesktop.org, iommu@lists.linux-foundation.org Subject: [PATCH 08/20] iommu/arm-smmu: constify some helpers Date: Mon, 24 Aug 2020 11:37:42 -0700 Message-Id: <20200824183825.1778810-9-robdclark@gmail.com> X-Mailer: git-send-email 2.26.2 In-Reply-To: <20200824183825.1778810-1-robdclark@gmail.com> References: <20200824183825.1778810-1-robdclark@gmail.com> MIME-Version: 1.0 X-CRM114-Version: 20100106-BlameMichelson ( TRE 0.8.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20200824_144224_909028_C39A6C1A X-CRM114-Status: GOOD ( 11.96 ) X-Spam-Score: -0.2 (/) X-Spam-Report: SpamAssassin version 3.4.4 on merlin.infradead.org summary: Content analysis details: (-0.2 points) pts rule name description ---- ---------------------- -------------------------------------------------- -0.0 RCVD_IN_DNSWL_NONE RBL: Sender listed at https://www.dnswl.org/, no trust [2607:f8b0:4864:20:0:0:0:444 listed in] [list.dnswl.org] 0.0 FREEMAIL_FROM Sender email is commonly abused enduser mail provider [robdclark[at]gmail.com] 0.0 SPF_HELO_NONE SPF: HELO does not publish an SPF Record -0.0 SPF_PASS SPF: sender matches SPF record 0.1 DKIM_SIGNED Message has a DKIM or DK signature, not necessarily valid -0.1 DKIM_VALID_AU Message has a valid DKIM or DK signature from author's domain -0.1 DKIM_VALID_EF Message has a valid DKIM or DK signature from envelope-from domain -0.1 DKIM_VALID Message has at least one valid DKIM or DK signature X-BeenThere: linux-arm-kernel@lists.infradead.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: Akhil P Oommen , Bjorn Andersson , Eric Anholt , Vivek Gautam , AngeloGioacchino Del Regno , Will Deacon , Rob Clark , Sai Prakash Ranjan , Jonathan Marek , Joerg Roedel , Ben Dooks , Sibi Sankar , Brian Masney , Joerg Roedel , Stephen Boyd , John Stultz , Jordan Crouse , "moderated list:ARM SMMU DRIVERS" , freedreno@lists.freedesktop.org, open list , Robin Murphy Sender: "linux-arm-kernel" Errors-To: linux-arm-kernel-bounces+patchwork-linux-arm=patchwork.kernel.org@lists.infradead.org From: Rob Clark Sprinkle a few `const`s where helpers don't need write access. Signed-off-by: Rob Clark --- drivers/iommu/arm/arm-smmu/arm-smmu.h | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/drivers/iommu/arm/arm-smmu/arm-smmu.h b/drivers/iommu/arm/arm-smmu/arm-smmu.h index 59ff3fc5c6c8..27c83333fc50 100644 --- a/drivers/iommu/arm/arm-smmu/arm-smmu.h +++ b/drivers/iommu/arm/arm-smmu/arm-smmu.h @@ -377,7 +377,7 @@ struct arm_smmu_master_cfg { s16 smendx[]; }; -static inline u32 arm_smmu_lpae_tcr(struct io_pgtable_cfg *cfg) +static inline u32 arm_smmu_lpae_tcr(const struct io_pgtable_cfg *cfg) { u32 tcr = FIELD_PREP(ARM_SMMU_TCR_TG0, cfg->arm_lpae_s1_cfg.tcr.tg) | FIELD_PREP(ARM_SMMU_TCR_SH0, cfg->arm_lpae_s1_cfg.tcr.sh) | @@ -398,13 +398,13 @@ static inline u32 arm_smmu_lpae_tcr(struct io_pgtable_cfg *cfg) return tcr; } -static inline u32 arm_smmu_lpae_tcr2(struct io_pgtable_cfg *cfg) +static inline u32 arm_smmu_lpae_tcr2(const struct io_pgtable_cfg *cfg) { return FIELD_PREP(ARM_SMMU_TCR2_PASIZE, cfg->arm_lpae_s1_cfg.tcr.ips) | FIELD_PREP(ARM_SMMU_TCR2_SEP, ARM_SMMU_TCR2_SEP_UPSTREAM); } -static inline u32 arm_smmu_lpae_vtcr(struct io_pgtable_cfg *cfg) +static inline u32 arm_smmu_lpae_vtcr(const struct io_pgtable_cfg *cfg) { return ARM_SMMU_VTCR_RES1 | FIELD_PREP(ARM_SMMU_VTCR_PS, cfg->arm_lpae_s2_cfg.vtcr.ps) | From patchwork Mon Aug 24 18:37:43 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Rob Clark X-Patchwork-Id: 11734099 Return-Path: Received: from mail.kernel.org (pdx-korg-mail-1.web.codeaurora.org [172.30.200.123]) by pdx-korg-patchwork-2.web.codeaurora.org (Postfix) with ESMTP id C131A138A for ; Mon, 24 Aug 2020 18:44:25 +0000 (UTC) Received: from merlin.infradead.org (merlin.infradead.org [205.233.59.134]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by mail.kernel.org (Postfix) with ESMTPS id 76A0B2075B for ; Mon, 24 Aug 2020 18:44:25 +0000 (UTC) Authentication-Results: mail.kernel.org; dkim=pass (2048-bit key) header.d=lists.infradead.org header.i=@lists.infradead.org header.b="hQ8k5L7e"; dkim=fail reason="signature verification failed" (2048-bit key) header.d=gmail.com header.i=@gmail.com header.b="jFCdi/0j" DMARC-Filter: OpenDMARC Filter v1.3.2 mail.kernel.org 76A0B2075B Authentication-Results: mail.kernel.org; dmarc=fail (p=none dis=none) header.from=gmail.com Authentication-Results: mail.kernel.org; spf=none smtp.mailfrom=linux-arm-kernel-bounces+patchwork-linux-arm=patchwork.kernel.org@lists.infradead.org DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=lists.infradead.org; s=merlin.20170209; h=Sender:Content-Transfer-Encoding: Content-Type:Cc:List-Subscribe:List-Help:List-Post:List-Archive: List-Unsubscribe:List-Id:MIME-Version:References:In-Reply-To:Message-Id:Date: Subject:To:From:Reply-To:Content-ID:Content-Description:Resent-Date: Resent-From:Resent-Sender:Resent-To:Resent-Cc:Resent-Message-ID:List-Owner; bh=BRZLUSzlg5YcT7Z5ArFP75sQ4aTestqiX8gLaQXiUpI=; b=hQ8k5L7eQntzIz1757w9DO3A5 dv97+fMS180CpkxyrXO+zz80uUJKgiF0jRyOVJRMZrBXxd3fVhSNP5oig7mOJtzJNV/66Ea92Vwfg xOhcumduynw92Do3mmEktGlQ+2LGTnA5D+IYxmLcId3X8LL3oL2JlenyJunqINPOs26lCSW1LQkd6 Lm364cUF+JbQ6ndJjXdvyHUy92vMtPkR7gs1AtN2mFgNdueHm+41317NfZI2uGL4SAO0oedOh1ju1 Vu+i68ITuDjFhEIYj1Buwf9S5ZXO7rVnJeWfmHIsRkbErBdGzjpGmh+EVFiJ7eiO5ruP9FewmmgAx g6buk621g==; Received: from localhost ([::1] helo=merlin.infradead.org) by merlin.infradead.org with esmtp (Exim 4.92.3 #3 (Red Hat Linux)) id 1kAHRs-0007GC-AC; Mon, 24 Aug 2020 18:44:04 +0000 Received: from mail-pg1-x544.google.com ([2607:f8b0:4864:20::544]) by merlin.infradead.org with esmtps (Exim 4.92.3 #3 (Red Hat Linux)) id 1kAHQN-0006aa-O6 for linux-arm-kernel@lists.infradead.org; Mon, 24 Aug 2020 18:42:47 +0000 Received: by mail-pg1-x544.google.com with SMTP id o5so4996096pgb.2 for ; Mon, 24 Aug 2020 11:42:31 -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 :mime-version:content-transfer-encoding; bh=LzdV0h2igfBRYjOSWYcy1X96vcmzxH8Zm32RY0I1KrA=; b=jFCdi/0jmLMbS4y1qeQ0Nv6b7oucP/OGpcP69nHuqjb73rPITKS90zoLDvLeUugBJF 45/0OSUGupa2dgKgtzeJ+Te5rk9ueP05eN4FTfNnU4jtxyACpK3CJ+HwRahO549p14rI 8ktw/8/HjxkEY1llqAB96cjWPPwFMjhddctbiqYnpjqQAJ0g6zAt640pvB15YFE4fbae 2NK6zi2Oz/0NZkpbYncembz6pBFk9STd+NwdoljCL3k/9dg0BkEewk+31aOFkzgrO31M FWg+7EpRLwJVqZSl+3WDh1uWI3eJSd2LcXHLrKc7h2RA5K/6JthwjQOWilnKY01gfjCU RKpw== 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:mime-version:content-transfer-encoding; bh=LzdV0h2igfBRYjOSWYcy1X96vcmzxH8Zm32RY0I1KrA=; b=cgCTvcWkqOy/WOQKcwDkNNlqh/zJvFQUlBC1j5InfjJ4Du9bgJePduVSkMk9agSoTE mYks1JP/7O9vdDK+I+yJuPdsDNyiXlFFCw1mQxyuali0/hjrvXDEn6J9NOBga7d5fibu VdTEXKl1TGdNnb3TCMVdg9LUwI4+nTPo0DSbDLGXG5+9IpP/j5tCnFPiDhHGta1KRoQb tW2Y/wotBNh1bVEv1ELVifBfcXQvHGz1ec6xym4HvNISdOHMew0y9pk4SGpqKbS+lZG+ PLDn+uKxvi7Qs9gyB99UvfL+Wd0mANk+oesW8HRpa1jNlV71uyFsmOVwJjmCevtTqoD0 kJmQ== X-Gm-Message-State: AOAM532kUL6pqd2jTxLUqBP7n6thjeXVRolOKdwrWAB6yMsPtt/6itQN qXaI2YW5YZmUK6lYGa5XTEc= X-Google-Smtp-Source: ABdhPJwellslLlyP1/E5Z8vclGH9VJmAOjaIGhTi1sGJu4wktDGgkPGnj+dh12eRoLXleOaDpAvtOQ== X-Received: by 2002:a63:aa04:: with SMTP id e4mr4065470pgf.318.1598294549313; Mon, 24 Aug 2020 11:42:29 -0700 (PDT) Received: from localhost ([2601:1c0:5200:a6:307:a401:7b76:c6e5]) by smtp.gmail.com with ESMTPSA id z127sm856327pfc.113.2020.08.24.11.42.27 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 24 Aug 2020 11:42:28 -0700 (PDT) From: Rob Clark To: dri-devel@lists.freedesktop.org, iommu@lists.linux-foundation.org Subject: [PATCH 09/20] iommu/arm-smmu-qcom: Add implementation for the adreno GPU SMMU Date: Mon, 24 Aug 2020 11:37:43 -0700 Message-Id: <20200824183825.1778810-10-robdclark@gmail.com> X-Mailer: git-send-email 2.26.2 In-Reply-To: <20200824183825.1778810-1-robdclark@gmail.com> References: <20200824183825.1778810-1-robdclark@gmail.com> MIME-Version: 1.0 X-CRM114-Version: 20100106-BlameMichelson ( TRE 0.8.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20200824_144232_131758_71716091 X-CRM114-Status: GOOD ( 26.43 ) X-Spam-Score: -0.2 (/) X-Spam-Report: SpamAssassin version 3.4.4 on merlin.infradead.org summary: Content analysis details: (-0.2 points) pts rule name description ---- ---------------------- -------------------------------------------------- -0.0 RCVD_IN_DNSWL_NONE RBL: Sender listed at https://www.dnswl.org/, no trust [2607:f8b0:4864:20:0:0:0:544 listed in] [list.dnswl.org] 0.0 FREEMAIL_FROM Sender email is commonly abused enduser mail provider [robdclark[at]gmail.com] 0.0 SPF_HELO_NONE SPF: HELO does not publish an SPF Record -0.0 SPF_PASS SPF: sender matches SPF record 0.1 DKIM_SIGNED Message has a DKIM or DK signature, not necessarily valid -0.1 DKIM_VALID_AU Message has a valid DKIM or DK signature from author's domain -0.1 DKIM_VALID_EF Message has a valid DKIM or DK signature from envelope-from domain -0.1 DKIM_VALID Message has at least one valid DKIM or DK signature X-BeenThere: linux-arm-kernel@lists.infradead.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: Hanna Hawa , Akhil P Oommen , Bjorn Andersson , Eric Anholt , Vivek Gautam , AngeloGioacchino Del Regno , Will Deacon , Rob Clark , Sai Prakash Ranjan , Jonathan Marek , Joerg Roedel , Ben Dooks , Sibi Sankar , Brian Masney , Joerg Roedel , Stephen Boyd , John Stultz , "moderated list:ARM SMMU DRIVERS" , freedreno@lists.freedesktop.org, Jordan Crouse , open list , Robin Murphy Sender: "linux-arm-kernel" Errors-To: linux-arm-kernel-bounces+patchwork-linux-arm=patchwork.kernel.org@lists.infradead.org From: Jordan Crouse Add a special implementation for the SMMU attached to most Adreno GPU target triggered from the qcom,adreno-smmu compatible string. The new Adreno SMMU implementation will enable split pagetables (TTBR1) for the domain attached to the GPU device (SID 0) and hard code it context bank 0 so the GPU hardware can implement per-instance pagetables. Co-developed-by: Rob Clark Signed-off-by: Jordan Crouse Signed-off-by: Rob Clark --- drivers/iommu/arm/arm-smmu/arm-smmu-impl.c | 3 + drivers/iommu/arm/arm-smmu/arm-smmu-qcom.c | 149 ++++++++++++++++++++- drivers/iommu/arm/arm-smmu/arm-smmu.h | 1 + 3 files changed, 151 insertions(+), 2 deletions(-) diff --git a/drivers/iommu/arm/arm-smmu/arm-smmu-impl.c b/drivers/iommu/arm/arm-smmu/arm-smmu-impl.c index 88f17cc33023..d199b4bff15d 100644 --- a/drivers/iommu/arm/arm-smmu/arm-smmu-impl.c +++ b/drivers/iommu/arm/arm-smmu/arm-smmu-impl.c @@ -223,6 +223,9 @@ struct arm_smmu_device *arm_smmu_impl_init(struct arm_smmu_device *smmu) of_device_is_compatible(np, "qcom,sm8250-smmu-500")) return qcom_smmu_impl_init(smmu); + if (of_device_is_compatible(smmu->dev->of_node, "qcom,adreno-smmu")) + return qcom_adreno_smmu_impl_init(smmu); + if (of_device_is_compatible(np, "marvell,ap806-smmu-500")) smmu->impl = &mrvl_mmu500_impl; diff --git a/drivers/iommu/arm/arm-smmu/arm-smmu-qcom.c b/drivers/iommu/arm/arm-smmu/arm-smmu-qcom.c index be4318044f96..5640d9960610 100644 --- a/drivers/iommu/arm/arm-smmu/arm-smmu-qcom.c +++ b/drivers/iommu/arm/arm-smmu/arm-smmu-qcom.c @@ -3,6 +3,7 @@ * Copyright (c) 2019, The Linux Foundation. All rights reserved. */ +#include #include #include @@ -12,6 +13,132 @@ struct qcom_smmu { struct arm_smmu_device smmu; }; +#define QCOM_ADRENO_SMMU_GPU_SID 0 + +static bool qcom_adreno_smmu_is_gpu_device(struct device *dev) +{ + struct iommu_fwspec *fwspec = dev_iommu_fwspec_get(dev); + int i; + + /* + * The GPU will always use SID 0 so that is a handy way to uniquely + * identify it and configure it for per-instance pagetables + */ + for (i = 0; i < fwspec->num_ids; i++) { + u16 sid = FIELD_GET(ARM_SMMU_SMR_ID, fwspec->ids[i]); + + if (sid == QCOM_ADRENO_SMMU_GPU_SID) + return true; + } + + return false; +} + +static const struct io_pgtable_cfg *qcom_adreno_smmu_get_ttbr1_cfg( + const void *cookie) +{ + struct arm_smmu_domain *smmu_domain = (void *)cookie; + struct io_pgtable *pgtable = + io_pgtable_ops_to_pgtable(smmu_domain->pgtbl_ops); + return &pgtable->cfg; +} + +/* + * Local implementation to configure TTBR0 with the specified pagetable config. + * The GPU driver will call this to enable TTBR0 when per-instance pagetables + * are active + */ + +static int qcom_adreno_smmu_set_ttbr0_cfg(const void *cookie, + const struct io_pgtable_cfg *pgtbl_cfg) +{ + struct arm_smmu_domain *smmu_domain = (void *)cookie; + struct io_pgtable *pgtable = io_pgtable_ops_to_pgtable(smmu_domain->pgtbl_ops); + struct arm_smmu_cfg *cfg = &smmu_domain->cfg; + struct arm_smmu_cb *cb = &smmu_domain->smmu->cbs[cfg->cbndx]; + + /* The domain must have split pagetables already enabled */ + if (cb->tcr[0] & ARM_SMMU_TCR_EPD1) + return -EINVAL; + + /* If the pagetable config is NULL, disable TTBR0 */ + if (!pgtbl_cfg) { + /* Do nothing if it is already disabled */ + if ((cb->tcr[0] & ARM_SMMU_TCR_EPD0)) + return -EINVAL; + + /* Set TCR to the original configuration */ + cb->tcr[0] = arm_smmu_lpae_tcr(&pgtable->cfg); + cb->ttbr[0] = FIELD_PREP(ARM_SMMU_TTBRn_ASID, cb->cfg->asid); + } else { + u32 tcr = cb->tcr[0]; + + /* Don't call this again if TTBR0 is already enabled */ + if (!(cb->tcr[0] & ARM_SMMU_TCR_EPD0)) + return -EINVAL; + + tcr |= arm_smmu_lpae_tcr(pgtbl_cfg); + tcr &= ~(ARM_SMMU_TCR_EPD0 | ARM_SMMU_TCR_EPD1); + + cb->tcr[0] = tcr; + cb->ttbr[0] = pgtbl_cfg->arm_lpae_s1_cfg.ttbr; + cb->ttbr[0] |= FIELD_PREP(ARM_SMMU_TTBRn_ASID, cb->cfg->asid); + } + + arm_smmu_write_context_bank(smmu_domain->smmu, cb->cfg->cbndx); + + return 0; +} + +static int qcom_adreno_smmu_alloc_context_bank(struct arm_smmu_domain *smmu_domain, + struct device *dev, int start, int count) +{ + struct arm_smmu_device *smmu = smmu_domain->smmu; + + /* + * Assign context bank 0 to the GPU device so the GPU hardware can + * switch pagetables + */ + if (qcom_adreno_smmu_is_gpu_device(dev)) { + start = 0; + count = 1; + } else { + start = 1; + } + + return __arm_smmu_alloc_bitmap(smmu->context_map, start, count); +} + +static int qcom_adreno_smmu_init_context(struct arm_smmu_domain *smmu_domain, + struct io_pgtable_cfg *pgtbl_cfg, struct device *dev) +{ + struct adreno_smmu_priv *priv; + + /* Only enable split pagetables for the GPU device (SID 0) */ + if (!qcom_adreno_smmu_is_gpu_device(dev)) + return 0; + + /* + * All targets that use the qcom,adreno-smmu compatible string *should* + * be AARCH64 stage 1 but double check because the arm-smmu code assumes + * that is the case when the TTBR1 quirk is enabled + */ + if ((smmu_domain->stage == ARM_SMMU_DOMAIN_S1) && + (smmu_domain->cfg.fmt == ARM_SMMU_CTX_FMT_AARCH64)) + pgtbl_cfg->quirks |= IO_PGTABLE_QUIRK_ARM_TTBR1; + + /* + * Initialize private interface with GPU: + */ + + priv = dev_get_drvdata(dev); + priv->cookie = smmu_domain; + priv->get_ttbr1_cfg = qcom_adreno_smmu_get_ttbr1_cfg; + priv->set_ttbr0_cfg = qcom_adreno_smmu_set_ttbr0_cfg; + + return 0; +} + static const struct of_device_id qcom_smmu_client_of_match[] __maybe_unused = { { .compatible = "qcom,adreno" }, { .compatible = "qcom,mdp4" }, @@ -65,7 +192,15 @@ static const struct arm_smmu_impl qcom_smmu_impl = { .reset = qcom_smmu500_reset, }; -struct arm_smmu_device *qcom_smmu_impl_init(struct arm_smmu_device *smmu) +static const struct arm_smmu_impl qcom_adreno_smmu_impl = { + .init_context = qcom_adreno_smmu_init_context, + .def_domain_type = qcom_smmu_def_domain_type, + .reset = qcom_smmu500_reset, + .alloc_context_bank = qcom_adreno_smmu_alloc_context_bank, +}; + +static struct arm_smmu_device *qcom_smmu_create(struct arm_smmu_device *smmu, + const struct arm_smmu_impl *impl) { struct qcom_smmu *qsmmu; @@ -75,8 +210,18 @@ struct arm_smmu_device *qcom_smmu_impl_init(struct arm_smmu_device *smmu) qsmmu->smmu = *smmu; - qsmmu->smmu.impl = &qcom_smmu_impl; + qsmmu->smmu.impl = impl; devm_kfree(smmu->dev, smmu); return &qsmmu->smmu; } + +struct arm_smmu_device *qcom_smmu_impl_init(struct arm_smmu_device *smmu) +{ + return qcom_smmu_create(smmu, &qcom_smmu_impl); +} + +struct arm_smmu_device *qcom_adreno_smmu_impl_init(struct arm_smmu_device *smmu) +{ + return qcom_smmu_create(smmu, &qcom_adreno_smmu_impl); +} diff --git a/drivers/iommu/arm/arm-smmu/arm-smmu.h b/drivers/iommu/arm/arm-smmu/arm-smmu.h index 27c83333fc50..cd75a33967bb 100644 --- a/drivers/iommu/arm/arm-smmu/arm-smmu.h +++ b/drivers/iommu/arm/arm-smmu/arm-smmu.h @@ -519,6 +519,7 @@ static inline void arm_smmu_writeq(struct arm_smmu_device *smmu, int page, struct arm_smmu_device *arm_smmu_impl_init(struct arm_smmu_device *smmu); struct arm_smmu_device *nvidia_smmu_impl_init(struct arm_smmu_device *smmu); struct arm_smmu_device *qcom_smmu_impl_init(struct arm_smmu_device *smmu); +struct arm_smmu_device *qcom_adreno_smmu_impl_init(struct arm_smmu_device *smmu); void arm_smmu_write_context_bank(struct arm_smmu_device *smmu, int idx); int arm_mmu500_reset(struct arm_smmu_device *smmu); From patchwork Mon Aug 24 18:37:44 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Rob Clark X-Patchwork-Id: 11734113 Return-Path: Received: from mail.kernel.org (pdx-korg-mail-1.web.codeaurora.org [172.30.200.123]) by pdx-korg-patchwork-2.web.codeaurora.org (Postfix) with ESMTP id DCD2A14E5 for ; Mon, 24 Aug 2020 18:59:59 +0000 (UTC) Received: from merlin.infradead.org (merlin.infradead.org [205.233.59.134]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by mail.kernel.org (Postfix) with ESMTPS id B1185206BE for ; Mon, 24 Aug 2020 18:59:59 +0000 (UTC) Authentication-Results: mail.kernel.org; dkim=pass (2048-bit key) header.d=lists.infradead.org header.i=@lists.infradead.org header.b="Nbf3xziD"; dkim=fail reason="signature verification failed" (2048-bit key) header.d=infradead.org header.i=@infradead.org header.b="YAVL4HVC"; dkim=fail reason="signature verification failed" (2048-bit key) header.d=gmail.com header.i=@gmail.com header.b="vDZcQosI" DMARC-Filter: OpenDMARC Filter v1.3.2 mail.kernel.org B1185206BE Authentication-Results: mail.kernel.org; dmarc=fail (p=none dis=none) header.from=gmail.com Authentication-Results: mail.kernel.org; spf=none smtp.mailfrom=linux-arm-kernel-bounces+patchwork-linux-arm=patchwork.kernel.org@lists.infradead.org DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=lists.infradead.org; s=merlin.20170209; h=Sender:Content-Transfer-Encoding: Content-Type:Cc:List-Subscribe:List-Help:List-Post:List-Archive: List-Unsubscribe:List-Id:MIME-Version:References:In-Reply-To:Message-Id:Date: Subject:To:From:Reply-To:Content-ID:Content-Description:Resent-Date: Resent-From:Resent-Sender:Resent-To:Resent-Cc:Resent-Message-ID:List-Owner; bh=XzipRUBYjGT949na1lPYe62r7R1kLez6PXIzNsah8JU=; b=Nbf3xziD+TVTgCnu1HkXJthTe 61oLPE1VYZcrF3SrLbbkbJLb30C3OfCjDzvuzZ1CXljG67kL2YN6+7yGIkjLNU/hn9XWX5TwRzY5T 5JtFNlb8PTHCP0lm4lD7t5rzFSlt1LisXE/9cob5F+0HlOytBTLXjCC/A4J3J5w8r0K3xYIPMWaU8 3MKpD8eiIbah1w2x+QXrZADsfCTiPY4+N3rfj0+oGH0JYAZrNLVQ8+wRzP01QayYhhBSkAF26Astq BGzKcILkLuXMkLjg7GwiTvDPu7q+gEKVsMSx9zpdvU/REX7ELCqI9pdWP1tlDFadR+Ypn45D/oAb1 Tmid7caGA==; Received: from localhost ([::1] helo=merlin.infradead.org) by merlin.infradead.org with esmtp (Exim 4.92.3 #3 (Red Hat Linux)) id 1kAHh5-0003cD-E4; Mon, 24 Aug 2020 18:59:47 +0000 Received: from casper.infradead.org ([2001:8b0:10b:1236::1]) by merlin.infradead.org with esmtps (Exim 4.92.3 #3 (Red Hat Linux)) id 1kAHh4-0003c0-FD for linux-arm-kernel@merlin.infradead.org; Mon, 24 Aug 2020 18:59:46 +0000 DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=infradead.org; s=casper.20170209; h=Content-Transfer-Encoding:MIME-Version: References:In-Reply-To:Message-Id:Date:Subject:Cc:To:From:Sender:Reply-To: Content-Type:Content-ID:Content-Description; bh=8jrJbdIXQQAFjo/ry7i+txJOnZIwex0ahQyZ/9frdio=; b=YAVL4HVCsbifBn044QlN9dJaty +GZw6PXSMFIKwQ5WB22tcMo6QkXCibNM7CvJmv+ph2C5itkjVBfdTde2dKfR4cDgmdyXLT7ScIe2C jB/vT43aOM2qQ05IlR9D2+mpbV+3c46FWBJbb02gca63eOxkzxULOJZgHkD8ZwyX70RflK++8VXIu kCLxx0fxMHNxYcp1IcncwDeIh3cjt4w5l4cpMnqeQBQHzyEmeV2op6ORYxk8BEPX8O4JhodjEiJ9s NZvLYshksXvh2M/1M0XradkGdweC72+IoiAi9OlhpvjFAxQlIJirQWIBOiB1mUGGdpujEihweCRP6 GZh4ot3Q==; Received: from mail-pf1-x442.google.com ([2607:f8b0:4864:20::442]) by casper.infradead.org with esmtps (Exim 4.92.3 #3 (Red Hat Linux)) id 1kAHQT-0001id-LI for linux-arm-kernel@lists.infradead.org; Mon, 24 Aug 2020 18:42:43 +0000 Received: by mail-pf1-x442.google.com with SMTP id u20so5322702pfn.0 for ; Mon, 24 Aug 2020 11:42:34 -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 :mime-version:content-transfer-encoding; bh=8jrJbdIXQQAFjo/ry7i+txJOnZIwex0ahQyZ/9frdio=; b=vDZcQosIOwttT+7YVD0YcJH63i/4ANBtWVWvB3iylHAaQulSk6Zt7LO0aYaQGeR8La Nf8A20AmUnyBL5dyL5YvhbxVitCshAaCyxzgTjfew1FhVN8rwvRSHF+nw1IRTCT+HJEy LgfiPuvEKOs/thV8w202+qBEZDCU+r1Zl8SLot+h3dwwLhotl/DUgl81PJRW1yM79dcZ 9QGffNgb65T+Rovp82CSbUGQINp+vpJ8/XXTWUFo6wLY6s7ajEGZZXyDUVmzzrVB1BeB DA6m6erABwDeEATCGThEYV5o1xN7WllNV2le6drxEfsYY72ehk5qdU1vkRSxeuJJeZFW XY5w== 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:mime-version:content-transfer-encoding; bh=8jrJbdIXQQAFjo/ry7i+txJOnZIwex0ahQyZ/9frdio=; b=MoT4df7ZjVEvPIFZRgFrsHSNrq3+YfkuIfHcaeemJi6qZLKyawck1kcR+Qm6wXl5Ze 59vv6PrR4Wxp4VZQqhC7Gzt/Wq0wDdYjXVzh+EEMs0FtRvgy/zo3w51SdXgZWt92HyJh HLM2tJHkH0YGpOdK/ee2ox5710s4yd2WsPN9rWRaUxjGR3JPok1m/PD5fgUYBSRnq8py telb1lLQNwJeW2SsuLr2BORysLAZnT2WMo/dQBvsnazEaqTHncRcZeW5ZF+ZTpEVR9va 3yQwb9OuChcSCFelwST9EJP2ocq2Z91uH+n5Kk+tld+HZdoEVwNAhDsq6uFnlfivco4u zpMA== X-Gm-Message-State: AOAM532Dciu5kFAXm0G1UbJXmhDS8jAzI6WNGks7g5L3PW0T9u4BAiZI 9sd359e2ULzkf/0PmgxxrUs= X-Google-Smtp-Source: ABdhPJz3GfCDsrY2e8D8NgnMkrpU5oev72R67ENvd+ltLeKwaHWMDwrcr34kf5ZWRUkLqlnrTXmo9w== X-Received: by 2002:a63:ca4e:: with SMTP id o14mr4352543pgi.213.1598294551624; Mon, 24 Aug 2020 11:42:31 -0700 (PDT) Received: from localhost ([2601:1c0:5200:a6:307:a401:7b76:c6e5]) by smtp.gmail.com with ESMTPSA id il13sm251907pjb.0.2020.08.24.11.42.30 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 24 Aug 2020 11:42:30 -0700 (PDT) From: Rob Clark To: dri-devel@lists.freedesktop.org, iommu@lists.linux-foundation.org Subject: [PATCH 10/20] dt-bindings: arm-smmu: Add compatible string for Adreno GPU SMMU Date: Mon, 24 Aug 2020 11:37:44 -0700 Message-Id: <20200824183825.1778810-11-robdclark@gmail.com> X-Mailer: git-send-email 2.26.2 In-Reply-To: <20200824183825.1778810-1-robdclark@gmail.com> References: <20200824183825.1778810-1-robdclark@gmail.com> MIME-Version: 1.0 X-CRM114-Version: 20100106-BlameMichelson ( TRE 0.8.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20200824_194237_805683_C5EE1047 X-CRM114-Status: GOOD ( 11.70 ) X-Spam-Score: -2.1 (--) X-Spam-Report: SpamAssassin version 3.4.4 on casper.infradead.org summary: Content analysis details: (-2.1 points, 5.0 required) pts rule name description ---- ---------------------- -------------------------------------------------- -1.9 BAYES_00 BODY: Bayes spam probability is 0 to 1% [score: 0.0000] -0.0 RCVD_IN_DNSWL_NONE RBL: Sender listed at https://www.dnswl.org/, no trust [2607:f8b0:4864:20:0:0:0:442 listed in] [list.dnswl.org] 0.0 SPF_HELO_NONE SPF: HELO does not publish an SPF Record -0.0 SPF_PASS SPF: sender matches SPF record 0.0 FREEMAIL_FROM Sender email is commonly abused enduser mail provider [robdclark[at]gmail.com] 0.1 DKIM_SIGNED Message has a DKIM or DK signature, not necessarily valid -0.1 DKIM_VALID_AU Message has a valid DKIM or DK signature from author's domain -0.1 DKIM_VALID Message has at least one valid DKIM or DK signature -0.1 DKIM_VALID_EF Message has a valid DKIM or DK signature from envelope-from domain X-BeenThere: linux-arm-kernel@lists.infradead.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: Akhil P Oommen , Bjorn Andersson , Eric Anholt , Vivek Gautam , AngeloGioacchino Del Regno , Will Deacon , Rob Clark , Rob Herring , Sai Prakash Ranjan , Jonathan Marek , Joerg Roedel , Ben Dooks , Sibi Sankar , Brian Masney , "open list:OPEN FIRMWARE AND FLATTENED DEVICE TREE BINDINGS" , Joerg Roedel , Stephen Boyd , Jordan Crouse , Rob Herring , John Stultz , "moderated list:ARM SMMU DRIVERS" , freedreno@lists.freedesktop.org, open list , Robin Murphy Sender: "linux-arm-kernel" Errors-To: linux-arm-kernel-bounces+patchwork-linux-arm=patchwork.kernel.org@lists.infradead.org From: Jordan Crouse Every Qcom Adreno GPU has an embedded SMMU for its own use. These devices depend on unique features such as split pagetables, different stall/halt requirements and other settings. Identify them with a compatible string so that they can be identified in the arm-smmu implementation specific code. Signed-off-by: Jordan Crouse Reviewed-by: Rob Herring Signed-off-by: Rob Clark --- Documentation/devicetree/bindings/iommu/arm,smmu.yaml | 9 +++++++-- 1 file changed, 7 insertions(+), 2 deletions(-) diff --git a/Documentation/devicetree/bindings/iommu/arm,smmu.yaml b/Documentation/devicetree/bindings/iommu/arm,smmu.yaml index 503160a7b9a0..3b63f2ae24db 100644 --- a/Documentation/devicetree/bindings/iommu/arm,smmu.yaml +++ b/Documentation/devicetree/bindings/iommu/arm,smmu.yaml @@ -28,8 +28,6 @@ properties: - enum: - qcom,msm8996-smmu-v2 - qcom,msm8998-smmu-v2 - - qcom,sc7180-smmu-v2 - - qcom,sdm845-smmu-v2 - const: qcom,smmu-v2 - description: Qcom SoCs implementing "arm,mmu-500" @@ -40,6 +38,13 @@ properties: - qcom,sm8150-smmu-500 - qcom,sm8250-smmu-500 - const: arm,mmu-500 + - description: Qcom Adreno GPUs implementing "arm,smmu-v2" + items: + - enum: + - qcom,sc7180-smmu-v2 + - qcom,sdm845-smmu-v2 + - const: qcom,adreno-smmu + - const: qcom,smmu-v2 - description: Marvell SoCs implementing "arm,mmu-500" items: - const: marvell,ap806-smmu-500 From patchwork Mon Aug 24 18:37:53 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Rob Clark X-Patchwork-Id: 11734115 Return-Path: Received: from mail.kernel.org (pdx-korg-mail-1.web.codeaurora.org [172.30.200.123]) by pdx-korg-patchwork-2.web.codeaurora.org (Postfix) with ESMTP id 4A71D14E5 for ; Mon, 24 Aug 2020 19:00:12 +0000 (UTC) Received: from merlin.infradead.org (merlin.infradead.org [205.233.59.134]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by mail.kernel.org (Postfix) with ESMTPS id 22BFF206BE for ; Mon, 24 Aug 2020 19:00:12 +0000 (UTC) Authentication-Results: mail.kernel.org; dkim=pass (2048-bit key) header.d=lists.infradead.org header.i=@lists.infradead.org header.b="CmTtVXmO"; dkim=fail reason="signature verification failed" (2048-bit key) header.d=infradead.org header.i=@infradead.org header.b="DrvuHNrB"; dkim=fail reason="signature verification failed" (2048-bit key) header.d=gmail.com header.i=@gmail.com header.b="QiFL1Ay9" DMARC-Filter: OpenDMARC Filter v1.3.2 mail.kernel.org 22BFF206BE Authentication-Results: mail.kernel.org; dmarc=fail (p=none dis=none) header.from=gmail.com Authentication-Results: mail.kernel.org; spf=none smtp.mailfrom=linux-arm-kernel-bounces+patchwork-linux-arm=patchwork.kernel.org@lists.infradead.org DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=lists.infradead.org; s=merlin.20170209; h=Sender:Content-Transfer-Encoding: Content-Type:Cc:List-Subscribe:List-Help:List-Post:List-Archive: List-Unsubscribe:List-Id:MIME-Version:References:In-Reply-To:Message-Id:Date: Subject:To:From:Reply-To:Content-ID:Content-Description:Resent-Date: Resent-From:Resent-Sender:Resent-To:Resent-Cc:Resent-Message-ID:List-Owner; bh=aqQNj/Ticq6Xdi7azWhzNYaSrJa7bRe5uqu67d/Pmi8=; b=CmTtVXmODmCr3iwcID+iHfH8D 196LHnUurAvDG9cnPAlb03dbX1BIWESqPIeHUUbv7AkT3mrYXsLF4zoeSwjfUjxj4vaco0HnJD/55 GKGiaeEEtiRvbt1S69YD77mSTAScIjdw+WtuufdAHJssBWvZ15L2NxFjjwNF7SeOnsX8RigK3umJs fgUV4rlUCsxygT9Ql+G1pFNmbX7BeT7js3wuHKTRnPV1BtVlnsKmBMjOakMvvSNIgbL3jCJ+6DqDa z2ydoK+iBV7tob0qpqzYAFT+j9vzsilSCu5d6Mg7eH3K4362YPOfuHM2wbys+s4nTKCsIythv/f88 BefNSCHWg==; Received: from localhost ([::1] helo=merlin.infradead.org) by merlin.infradead.org with esmtp (Exim 4.92.3 #3 (Red Hat Linux)) id 1kAHhI-0003fK-Cf; Mon, 24 Aug 2020 19:00:00 +0000 Received: from casper.infradead.org ([2001:8b0:10b:1236::1]) by merlin.infradead.org with esmtps (Exim 4.92.3 #3 (Red Hat Linux)) id 1kAHhA-0003c0-IR for linux-arm-kernel@merlin.infradead.org; Mon, 24 Aug 2020 18:59:52 +0000 DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=infradead.org; s=casper.20170209; h=Content-Transfer-Encoding:MIME-Version: References:In-Reply-To:Message-Id:Date:Subject:Cc:To:From:Sender:Reply-To: Content-Type:Content-ID:Content-Description; bh=ORHfJz2e9TNUi11ClButtEprelkWs9RC+Iw7WuZZvQo=; b=DrvuHNrBJmCI0Uykfg47UJS6py qgVylRkiqNWJacjV+oXbK8ynEplcuONia2/vCpal+zt78e3SHSO5OGj+k6djTL0GgeqxUHRVyql1O uLcwCOzPzfNZyeHU3kbvz5vJbECeP+KO2Kri9DrD8vpKkTfS0FX472u9a64xpcAnp8i/RbwZRiyYF k5ZUjm4TfQrgxaYFZyA8NjLtFPMJRgeq4kNbnE5bfP3WFYQ1D8jsDKgAOq34z/6vL8vZ1YEaARQMv kk7wHtsm74AW8IxHdh6StY7Ck2x92OpMF2jRf+aSg11HjgQP8K3s3GCXyB3pKrK4xS8PZXd+1WZeE 2Djp5Cbg==; Received: from mail-pg1-x544.google.com ([2607:f8b0:4864:20::544]) by casper.infradead.org with esmtps (Exim 4.92.3 #3 (Red Hat Linux)) id 1kAHR3-0001ra-7u for linux-arm-kernel@lists.infradead.org; Mon, 24 Aug 2020 18:43:20 +0000 Received: by mail-pg1-x544.google.com with SMTP id p37so4998452pgl.3 for ; Mon, 24 Aug 2020 11:43:12 -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 :mime-version:content-transfer-encoding; bh=ORHfJz2e9TNUi11ClButtEprelkWs9RC+Iw7WuZZvQo=; b=QiFL1Ay9VZ+o7FljpSkk11RnZQkof5/enbgvZ9/7pqco8XN9U1Hp4Elf8D9nIZRA8C nGD5FCRG+OzA+aDgKTU0oOJMz4fa3mXl7u0lD7n28ZSbHqCti/Zt9QxkqsHpaM4NLC3o enFNf1XQmCmKZJIaP6vQYsb6HzRH3aKXBN4KuqFyPm4ANqDduI5Ao/TPi5ukL0LW4gBC 5Uctli6acz1d1aIAAnhKPO5aVrIgSAIZBf3VtqRMv/BoPdq5cT0VOvc+6VYRRTGd2uh/ 5F8EkZDgWqrbkgaT3QhaajydJj2zkeaBerdXPu5aXqu0i6rs20/nOHeGwvzMmO/X3iAP 0afg== 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:mime-version:content-transfer-encoding; bh=ORHfJz2e9TNUi11ClButtEprelkWs9RC+Iw7WuZZvQo=; b=rAFxNM5WmE5ZU6Hym1FR9au3xz+5TY3VPnbfm3FiB10XjdMIroQGD8j+95GGmSFohv KKc9eWTtmuB9h2V3pH3ahc1655rkAEQopAdvEOy2Wm5Vzy3YG6c/9DuWwvVNV/jKO8Et DDQhwQY0hhC/8dBQPSJX2OsaJW4p0irX5Ga1pAr5Q/BCnORzscgVmBNmRSB+dOvtJ1Jv 85veRX4y9sX0w83go183lrXIXyBzBy8zGfNkMQObN5XDZR0UEgbcOItOq0q0sumhPiOD QTcSQZth738qfTmoaro0nK25oKgMpr+BJmDcBIKu7+3gCzBKGgoqPwQX0SgNa8o7Msmt oYkw== X-Gm-Message-State: AOAM531a09MVivKRmuOXYGthxbnxk+GjTYS/TF9D0u5t/bwPrYwo9pTr InHXMpyTF+EiSYQl5wS86+E= X-Google-Smtp-Source: ABdhPJwn5FgCJ9VyPOqih4HSDVzsr7XdR6VCZfi5iJqTQOJt7mF0wpqzXVZYMoaHoEoWg8tPnsqkYA== X-Received: by 2002:a17:902:7b82:: with SMTP id w2mr4753119pll.39.1598294590126; Mon, 24 Aug 2020 11:43:10 -0700 (PDT) Received: from localhost ([2601:1c0:5200:a6:307:a401:7b76:c6e5]) by smtp.gmail.com with ESMTPSA id l5sm3347202pga.43.2020.08.24.11.43.08 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 24 Aug 2020 11:43:08 -0700 (PDT) From: Rob Clark To: dri-devel@lists.freedesktop.org, iommu@lists.linux-foundation.org Subject: [PATCH 19/20] iommu/arm-smmu: add a way for implementations to influence SCTLR Date: Mon, 24 Aug 2020 11:37:53 -0700 Message-Id: <20200824183825.1778810-20-robdclark@gmail.com> X-Mailer: git-send-email 2.26.2 In-Reply-To: <20200824183825.1778810-1-robdclark@gmail.com> References: <20200824183825.1778810-1-robdclark@gmail.com> MIME-Version: 1.0 X-CRM114-Version: 20100106-BlameMichelson ( TRE 0.8.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20200824_194313_639138_E60B1D59 X-CRM114-Status: GOOD ( 14.38 ) X-Spam-Score: -2.1 (--) X-Spam-Report: SpamAssassin version 3.4.4 on casper.infradead.org summary: Content analysis details: (-2.1 points, 5.0 required) pts rule name description ---- ---------------------- -------------------------------------------------- -1.9 BAYES_00 BODY: Bayes spam probability is 0 to 1% [score: 0.0000] -0.0 RCVD_IN_DNSWL_NONE RBL: Sender listed at https://www.dnswl.org/, no trust [2607:f8b0:4864:20:0:0:0:544 listed in] [list.dnswl.org] 0.0 SPF_HELO_NONE SPF: HELO does not publish an SPF Record -0.0 SPF_PASS SPF: sender matches SPF record 0.0 FREEMAIL_FROM Sender email is commonly abused enduser mail provider [robdclark[at]gmail.com] 0.1 DKIM_SIGNED Message has a DKIM or DK signature, not necessarily valid -0.1 DKIM_VALID_AU Message has a valid DKIM or DK signature from author's domain -0.1 DKIM_VALID Message has at least one valid DKIM or DK signature -0.1 DKIM_VALID_EF Message has a valid DKIM or DK signature from envelope-from domain X-BeenThere: linux-arm-kernel@lists.infradead.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: Akhil P Oommen , Bjorn Andersson , Eric Anholt , Vivek Gautam , AngeloGioacchino Del Regno , Will Deacon , Rob Clark , Sai Prakash Ranjan , Jonathan Marek , Joerg Roedel , Ben Dooks , Sibi Sankar , Thierry Reding , Brian Masney , freedreno@lists.freedesktop.org, Joerg Roedel , Stephen Boyd , Nicolin Chen , John Stultz , "moderated list:ARM SMMU DRIVERS" , Greg Kroah-Hartman , Jordan Crouse , open list , Robin Murphy Sender: "linux-arm-kernel" Errors-To: linux-arm-kernel-bounces+patchwork-linux-arm=patchwork.kernel.org@lists.infradead.org From: Rob Clark For the Adreno GPU's SMMU, we want SCTLR.HUPCF set to ensure that pending translations are not terminated on iova fault. Otherwise a terminated CP read could hang the GPU by returning invalid command-stream data. Signed-off-by: Rob Clark --- drivers/iommu/arm/arm-smmu/arm-smmu-qcom.c | 6 ++++++ drivers/iommu/arm/arm-smmu/arm-smmu.c | 3 +++ drivers/iommu/arm/arm-smmu/arm-smmu.h | 3 +++ 3 files changed, 12 insertions(+) diff --git a/drivers/iommu/arm/arm-smmu/arm-smmu-qcom.c b/drivers/iommu/arm/arm-smmu/arm-smmu-qcom.c index 5640d9960610..2aa6249050ff 100644 --- a/drivers/iommu/arm/arm-smmu/arm-smmu-qcom.c +++ b/drivers/iommu/arm/arm-smmu/arm-smmu-qcom.c @@ -127,6 +127,12 @@ static int qcom_adreno_smmu_init_context(struct arm_smmu_domain *smmu_domain, (smmu_domain->cfg.fmt == ARM_SMMU_CTX_FMT_AARCH64)) pgtbl_cfg->quirks |= IO_PGTABLE_QUIRK_ARM_TTBR1; + /* + * On the GPU device we want to process subsequent transactions after a + * fault to keep the GPU from hanging + */ + smmu_domain->cfg.sctlr_set |= ARM_SMMU_SCTLR_HUPCF; + /* * Initialize private interface with GPU: */ diff --git a/drivers/iommu/arm/arm-smmu/arm-smmu.c b/drivers/iommu/arm/arm-smmu/arm-smmu.c index e63a480d7f71..bbec5793faf8 100644 --- a/drivers/iommu/arm/arm-smmu/arm-smmu.c +++ b/drivers/iommu/arm/arm-smmu/arm-smmu.c @@ -617,6 +617,9 @@ void arm_smmu_write_context_bank(struct arm_smmu_device *smmu, int idx) if (IS_ENABLED(CONFIG_CPU_BIG_ENDIAN)) reg |= ARM_SMMU_SCTLR_E; + reg |= cfg->sctlr_set; + reg &= ~cfg->sctlr_clr; + arm_smmu_cb_write(smmu, idx, ARM_SMMU_CB_SCTLR, reg); } diff --git a/drivers/iommu/arm/arm-smmu/arm-smmu.h b/drivers/iommu/arm/arm-smmu/arm-smmu.h index cd75a33967bb..2df3a70a8a41 100644 --- a/drivers/iommu/arm/arm-smmu/arm-smmu.h +++ b/drivers/iommu/arm/arm-smmu/arm-smmu.h @@ -144,6 +144,7 @@ enum arm_smmu_cbar_type { #define ARM_SMMU_CB_SCTLR 0x0 #define ARM_SMMU_SCTLR_S1_ASIDPNE BIT(12) #define ARM_SMMU_SCTLR_CFCFG BIT(7) +#define ARM_SMMU_SCTLR_HUPCF BIT(8) #define ARM_SMMU_SCTLR_CFIE BIT(6) #define ARM_SMMU_SCTLR_CFRE BIT(5) #define ARM_SMMU_SCTLR_E BIT(4) @@ -341,6 +342,8 @@ struct arm_smmu_cfg { u16 asid; u16 vmid; }; + u32 sctlr_set; /* extra bits to set in SCTLR */ + u32 sctlr_clr; /* bits to mask in SCTLR */ enum arm_smmu_cbar_type cbar; enum arm_smmu_context_fmt fmt; };