From patchwork Wed Aug 23 16:47:30 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Jason Gunthorpe X-Patchwork-Id: 13362870 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from bombadil.infradead.org (bombadil.infradead.org [198.137.202.133]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.lore.kernel.org (Postfix) with ESMTPS id C11A6C79F6A for ; Wed, 23 Aug 2023 16:48:16 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=lists.infradead.org; s=bombadil.20210309; h=Sender:List-Subscribe:List-Help :List-Post:List-Archive:List-Unsubscribe:List-Id:MIME-Version:Content-Type: Content-Transfer-Encoding:References:In-Reply-To:Message-ID:Date:Subject:Cc: To:From:Reply-To:Content-ID:Content-Description:Resent-Date:Resent-From: Resent-Sender:Resent-To:Resent-Cc:Resent-Message-ID:List-Owner; bh=X3TeIM1SAg45W6SvBh7RWvFnlBirSJTSHcccY6cpEOQ=; b=aztqTqktxZNSK6Zgk8XOHe2P2Y cEMuK/d9ciscuhjn+WbQolpV4h/R1oLj8i+mPJnFWKoPpkgNftvvxecKJecm5eFVJs3HZ6cDudwQE qclmmu2FnXHLoy1s0oXqWbRNVxaxCpfNAskPoHa5HJnzaJXl6Qe6PjGGmhMHpcNIvTf7drcdqjQ+N TiNEcBBIKDekVPFBFM5AXrEb5svGC1KJwPfpMwoDpdtqeYtqoXzpXnYJTimShz8INFWJvdRrRJIrS 2zgBKQhxpXWmybzVN2CvbjNRfGJIQtFE4C7fISo+dMdtNclrMm9Rdbe7pG76IFdXcK2HrarfkbtcF Iw7YD5Aw==; Received: from localhost ([::1] helo=bombadil.infradead.org) by bombadil.infradead.org with esmtp (Exim 4.96 #2 (Red Hat Linux)) id 1qYr1j-0016Ue-0O; Wed, 23 Aug 2023 16:48:15 +0000 Received: from mail-bn8nam12on2061b.outbound.protection.outlook.com ([2a01:111:f400:fe5b::61b] helo=NAM12-BN8-obe.outbound.protection.outlook.com) by bombadil.infradead.org with esmtps (Exim 4.96 #2 (Red Hat Linux)) id 1qYr1O-001692-0n; Wed, 23 Aug 2023 16:47:56 +0000 ARC-Seal: i=1; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=none; b=R2L2m14dJX2herp+cSfrfyyjh6LULsUDu3FmJ70BpYuMlJajFE2yEg1VPrFaURnjX/tDvK4Ds2LZM381Klxm+VXTZWij/LzrXWQv4vx3wLPhsC+ZOs2Q6VEPmsi1HaQPLtzmtOAkMT2RO6fBDcTdA30VSV8D/MzFrBLZbFmrPhQp1u+PRpdO+2LBwfTzyxVWRtjFPggC/ILcoz0KpjOXTy/CLal6ZOiuIKTietaHyxUA42oMZery774ZpuD1/NvF+QtfQeMoeBjDwaz2qOOSsx9RG1dX+eV7NuajkvPFyLdNYq0lUi+k0V07tF33/1Rq3rNV8PHU68w8t/B7Dmc7UA== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=microsoft.com; s=arcselector9901; h=From:Date:Subject:Message-ID:Content-Type:MIME-Version:X-MS-Exchange-AntiSpam-MessageData-ChunkCount:X-MS-Exchange-AntiSpam-MessageData-0:X-MS-Exchange-AntiSpam-MessageData-1; bh=X3TeIM1SAg45W6SvBh7RWvFnlBirSJTSHcccY6cpEOQ=; b=PZ3pWUuJNWy/Qr7PsruQ5HUDtdSoL3KcMlc4wuOCn9W+0zoXBeYt+SpPNwsw45fJidmawOabs1Mj4ZCZWcG/ICU3ImhBjWADzqQGPFG1yNBJcLoJrzlfhOyL48ifZ8/kInnWFJMxuqar3CYC1aNjXGHkhMuLlKegz4GoqXvkTN8sGSnuRQtkds263GuwIwPHoRskVdOc1YtE1TIXLOzWHQgKpW95Rq3HTmIKn7pKasIRLqCEytZIPFCrWYlG2p4uTNKySEkFee7U7F6LD1g2pY4Jef7fhNcXgOCnXW8qVKtb9Ht1HWvKpNGFXPySBfdsop07vIGA9p54iXnRrAY46g== ARC-Authentication-Results: i=1; mx.microsoft.com 1; spf=pass smtp.mailfrom=nvidia.com; dmarc=pass action=none header.from=nvidia.com; dkim=pass header.d=nvidia.com; arc=none DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=Nvidia.com; s=selector2; h=From:Date:Subject:Message-ID:Content-Type:MIME-Version:X-MS-Exchange-SenderADCheck; bh=X3TeIM1SAg45W6SvBh7RWvFnlBirSJTSHcccY6cpEOQ=; b=k57zNjc63FKPAT3t2Yojr8QnT/dp0i96XR6mCrifxaU8GZe2NaRQtWHYRIETB3717o4MdVPx0lp0CM/GUeGRbji+SwmatIGhqofCW1ysO+r2eyDXanYvRz6D+WudSE8KKzCpGAgRwWD3Mil4V/wa8KMsYgC43Ew4+KADPeMdPjqQfLZOBk00q9zT/caFGo/S+y79eG5zVbEYt6nWq2jhdy+aiJhX6YL1ehAwPTeBPZC5jecIhXILzrZ2kZCZ75bKlM4x9UvX+Hs9EaQDdYnq8hpPFmQxpR6d8Yf+fymEnQapnybwvl5SUwI1F3m7AaCoumupd4uPt5wsi1Cgu5kg4g== Authentication-Results: dkim=none (message not signed) header.d=none;dmarc=none action=none header.from=nvidia.com; Received: from LV2PR12MB5869.namprd12.prod.outlook.com (2603:10b6:408:176::16) by CY5PR12MB6346.namprd12.prod.outlook.com (2603:10b6:930:21::12) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.6699.24; Wed, 23 Aug 2023 16:47:42 +0000 Received: from LV2PR12MB5869.namprd12.prod.outlook.com ([fe80::5111:16e8:5afe:1da1]) by LV2PR12MB5869.namprd12.prod.outlook.com ([fe80::5111:16e8:5afe:1da1%6]) with mapi id 15.20.6699.020; Wed, 23 Aug 2023 16:47:42 +0000 From: Jason Gunthorpe To: Andy Gross , Alim Akhtar , Bjorn Andersson , AngeloGioacchino Del Regno , Baolin Wang , Christophe Leroy , Gerald Schaefer , Heiko Stuebner , iommu@lists.linux.dev, Jernej Skrabec , Jonathan Hunter , Joerg Roedel , Kevin Tian , Konrad Dybcio , Krzysztof Kozlowski , linux-arm-kernel@lists.infradead.org, linux-arm-msm@vger.kernel.org, linux-mediatek@lists.infradead.org, linux-rockchip@lists.infradead.org, linux-s390@vger.kernel.org, linux-samsung-soc@vger.kernel.org, linux-sunxi@lists.linux.dev, linux-tegra@vger.kernel.org, Russell King , linuxppc-dev@lists.ozlabs.org, Matthias Brugger , Matthew Rosato , Michael Ellerman , Nicholas Piggin , Orson Zhai , Rob Clark , Robin Murphy , Samuel Holland , Thierry Reding , Krishna Reddy , Chen-Yu Tsai , Will Deacon , Yong Wu , Chunyan Zhang Cc: Lu Baolu , Dmitry Osipenko , Marek Szyprowski , Nicolin Chen , Niklas Schnelle , Steven Price , Thierry Reding Subject: [PATCH v7 16/24] iommu/qcom_iommu: Add an IOMMU_IDENTITIY_DOMAIN Date: Wed, 23 Aug 2023 13:47:30 -0300 Message-ID: <16-v7-de04a3217c48+15055-iommu_all_defdom_jgg@nvidia.com> In-Reply-To: <0-v7-de04a3217c48+15055-iommu_all_defdom_jgg@nvidia.com> References: X-ClientProxiedBy: CH0PR03CA0350.namprd03.prod.outlook.com (2603:10b6:610:11a::24) To LV2PR12MB5869.namprd12.prod.outlook.com (2603:10b6:408:176::16) MIME-Version: 1.0 X-MS-PublicTrafficType: Email X-MS-TrafficTypeDiagnostic: LV2PR12MB5869:EE_|CY5PR12MB6346:EE_ X-MS-Office365-Filtering-Correlation-Id: c49e4d99-bd83-451f-4af3-08dba3f8aa48 X-MS-Exchange-SenderADCheck: 1 X-MS-Exchange-AntiSpam-Relay: 0 X-Microsoft-Antispam: BCL:0; X-Microsoft-Antispam-Message-Info: pUKUsYEqz+0mnIB2pSdY7M2JMRfJCToch6+kMyJtJ4ltBDn+jOrU+WecNUCdUpsmxmDDe/wjqnsgwlcPyeY4vRS/0PXrEU0fwg9xvMpWB+2NaGCvKtG2OORUMXIEn1v45BWaxfq8+yRQm4HNIdQV7rXYcwzzcPb4eA5xLkxpno6BVaFMJozgbf9Tdm5b393FimdN7seKdkS9TcXjk8md3ej/J7UQ78B9zg+JZ6rH5Qa/t2Fdadak6FcsxIf2rcjc6PyqrSAU2jWpjzVGxi51CyOFSNUhXxxB0HWRb8Z/sPtE00qGIWIuNAKpZZNOB+BLVv/lrcZO2r4fnn8pTLwhm8pe+rZxUcfW16fXQy0b7ZRjHB/xRphvjL53/YohXlcD+iC0ggswLRvwiRUB3vlxWM8HQuu+FCUskcfbPM7O4EgCWvsaPqPrYoR3WmbDyh9uHYvv19zem4JqZyXYORT6JHKIZyvd4MKcZy8crNAcI0d7y1X6JHkSDSMUh57g2OIRpnAgJugi1293LfcGuFX5y5uGNgfgiZPOyaPFCAKukzrAGKckqJqmcydvbtW4AZrymCWpRAzJPLHqsd+GXzwsDOTD453BPHGs6Qbpx5SqtMc= X-Forefront-Antispam-Report: CIP:255.255.255.255;CTRY:;LANG:en;SCL:1;SRV:;IPV:NLI;SFV:NSPM;H:LV2PR12MB5869.namprd12.prod.outlook.com;PTR:;CAT:NONE;SFS:(13230031)(376002)(396003)(136003)(346002)(366004)(39860400002)(186009)(1800799009)(451199024)(54906003)(66476007)(66946007)(6512007)(316002)(66556008)(110136005)(8676002)(8936002)(107886003)(2616005)(4326008)(36756003)(41300700001)(921005)(478600001)(6666004)(6506007)(38100700002)(6486002)(83380400001)(7416002)(2906002)(7406005)(86362001)(5660300002)(26005);DIR:OUT;SFP:1101; X-MS-Exchange-AntiSpam-MessageData-ChunkCount: 1 X-MS-Exchange-AntiSpam-MessageData-0: bTY+KPioPExDszZcPNP1IcQ+rn30iY8EYgPsXxZMdUxd0EgWO/FZGiSGV/wKqJzeRAL64Y2rieQjzLLrizNs5kWnLTngxY/SbT3vsShVoc9i3j3qJ4r843qnNhfqTni2Hv45RY4Dau2upCacH+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SwAKd6k1iAI9SVb5VzRBeDDx/BsYKaNf/XvUhGLldtLoXCXmjrRuv7IYzZsekjUi9egknVBf0c45YaUkqFwuZW4hRQf/aWi05cw7lnq0ec9Hblqbvh7XhUyy5HUZ89/e1oJs/KpMvoyGLg7lp6S/hh55tGs7uf7ynpuYSfc0KFUL3BQxBkC/om+LC4hqeqbQgMyeVfZEs0/AjTW5fuTHHt+Vrgu0CKwENVWI+7bb74MJ2cjljEeCm98/49jQd55tf1B6tEGs95TuIxSTpbIxl289Kqyap9Uf0bGUNApwdbam5wxBM4RcMMsx7Np1JHB4DHxWHPRivB8d/wkh55ukG8AQbfvIDYpv8xUUgku1zv3sfF0V8yzOQyK2vXx/ce7 X-OriginatorOrg: Nvidia.com X-MS-Exchange-CrossTenant-Network-Message-Id: c49e4d99-bd83-451f-4af3-08dba3f8aa48 X-MS-Exchange-CrossTenant-AuthSource: LV2PR12MB5869.namprd12.prod.outlook.com X-MS-Exchange-CrossTenant-AuthAs: Internal X-MS-Exchange-CrossTenant-OriginalArrivalTime: 23 Aug 2023 16:47:41.0571 (UTC) X-MS-Exchange-CrossTenant-FromEntityHeader: Hosted X-MS-Exchange-CrossTenant-Id: 43083d15-7273-40c1-b7db-39efd9ccc17a X-MS-Exchange-CrossTenant-MailboxType: HOSTED X-MS-Exchange-CrossTenant-UserPrincipalName: 2ZVwSydoKxg1sB7ifiMfZXEmIKEtt6G3krM7Ijrw+xqiV4hRE3SnCkAGK7s5fpyt X-MS-Exchange-Transport-CrossTenantHeadersStamped: CY5PR12MB6346 X-CRM114-Version: 20100106-BlameMichelson ( TRE 0.8.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20230823_094754_307684_04BAFAB7 X-CRM114-Status: GOOD ( 13.35 ) X-BeenThere: linux-mediatek@lists.infradead.org X-Mailman-Version: 2.1.34 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Sender: "Linux-mediatek" Errors-To: linux-mediatek-bounces+linux-mediatek=archiver.kernel.org@lists.infradead.org This brings back the ops->detach_dev() code that commit 1b932ceddd19 ("iommu: Remove detach_dev callbacks") deleted and turns it into an IDENTITY domain. Reviewed-by: Lu Baolu Signed-off-by: Jason Gunthorpe Reviewed-by: Jerry Snitselaar --- drivers/iommu/arm/arm-smmu/qcom_iommu.c | 39 +++++++++++++++++++++++++ 1 file changed, 39 insertions(+) diff --git a/drivers/iommu/arm/arm-smmu/qcom_iommu.c b/drivers/iommu/arm/arm-smmu/qcom_iommu.c index 775a3cbaff4ed0..bc45d18f350cb9 100644 --- a/drivers/iommu/arm/arm-smmu/qcom_iommu.c +++ b/drivers/iommu/arm/arm-smmu/qcom_iommu.c @@ -400,6 +400,44 @@ static int qcom_iommu_attach_dev(struct iommu_domain *domain, struct device *dev return 0; } +static int qcom_iommu_identity_attach(struct iommu_domain *identity_domain, + struct device *dev) +{ + struct iommu_domain *domain = iommu_get_domain_for_dev(dev); + struct qcom_iommu_domain *qcom_domain; + struct iommu_fwspec *fwspec = dev_iommu_fwspec_get(dev); + struct qcom_iommu_dev *qcom_iommu = to_iommu(dev); + unsigned int i; + + if (domain == identity_domain || !domain) + return 0; + + qcom_domain = to_qcom_iommu_domain(domain); + if (WARN_ON(!qcom_domain->iommu)) + return -EINVAL; + + pm_runtime_get_sync(qcom_iommu->dev); + for (i = 0; i < fwspec->num_ids; i++) { + struct qcom_iommu_ctx *ctx = to_ctx(qcom_domain, fwspec->ids[i]); + + /* Disable the context bank: */ + iommu_writel(ctx, ARM_SMMU_CB_SCTLR, 0); + + ctx->domain = NULL; + } + pm_runtime_put_sync(qcom_iommu->dev); + return 0; +} + +static struct iommu_domain_ops qcom_iommu_identity_ops = { + .attach_dev = qcom_iommu_identity_attach, +}; + +static struct iommu_domain qcom_iommu_identity_domain = { + .type = IOMMU_DOMAIN_IDENTITY, + .ops = &qcom_iommu_identity_ops, +}; + static int qcom_iommu_map(struct iommu_domain *domain, unsigned long iova, phys_addr_t paddr, size_t pgsize, size_t pgcount, int prot, gfp_t gfp, size_t *mapped) @@ -565,6 +603,7 @@ static int qcom_iommu_of_xlate(struct device *dev, struct of_phandle_args *args) } static const struct iommu_ops qcom_iommu_ops = { + .identity_domain = &qcom_iommu_identity_domain, .capable = qcom_iommu_capable, .domain_alloc = qcom_iommu_domain_alloc, .probe_device = qcom_iommu_probe_device,