From patchwork Thu Aug 3 00:07:59 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Jason Gunthorpe X-Patchwork-Id: 13339015 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 765CDC00528 for ; Thu, 3 Aug 2023 00:09:50 +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=JmN8wx0ZcwrsXaWrD4Fv2q50YdIFx6jmaYZV5yW4VDs=; b=AaFKC62Bc1f5OxC/mIo5T1Cptx X1nerI4t6n6qfW6uDTFX4DWHH0iD/3hnefBmxaLvgYyE4r5t57GATgPX/YlznZcEeyfow5inzUadr PDu0izBMzs56IjaHVwMoBs9jEq5OXMgDOwTrUOYeAtJY/x1NRLZEegf6CFX2oj0wBUsdTYOWzcYqD pPCHmh/XPFV4dZmxEJT4U/PhXZCeljX1aEP130mGBf5nvp8GhZjm4j4DaF39j72gfkAhCsAeAzNa+ 2R7m06vKvILhlEqUi1Zvu0sPtD0f0uiAR4ikiSBHb095HL9SyHgxELPAt8BfzKVkmNBNB2i397+Nj WwZrDLWQ==; Received: from localhost ([::1] helo=bombadil.infradead.org) by bombadil.infradead.org with esmtp (Exim 4.96 #2 (Red Hat Linux)) id 1qRLuV-006DuN-1w; Thu, 03 Aug 2023 00:09:47 +0000 Received: from mail-dm6nam10on20631.outbound.protection.outlook.com ([2a01:111:f400:7e88::631] helo=NAM10-DM6-obe.outbound.protection.outlook.com) by bombadil.infradead.org with esmtps (Exim 4.96 #2 (Red Hat Linux)) id 1qRLtP-006Cej-26; Thu, 03 Aug 2023 00:08:43 +0000 ARC-Seal: i=1; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=none; b=hHisLxSi+4jLMD7MkiOHDeaihslrWy6c6RCzgUZojd0e/8TAY46rg+y1E/kPp83s1It030eBRZAYh1BMI6vIrPm9rVDGXXLcf1QL2dSomBTLxvX/y80HthYJ0CmFDXuGbJe+45fRfUMPcNqIugr/LP+YLElVgDbPj6c7JdF/hlYiZu8phaHPb8ImBVrq23FuFzmPZqkID5Nf4DipSoj5Gc7tqNny3O0y3daNPTESOiwUOXII/WTWY+J/7SBDY6yB7lh7sDNllx2350gMPYkv6jHDBkDLE2D5ZB6gBvhkM51C4hwCp1nmresXVxkIWk9119KYj1QRpYZ4v712UaonkA== 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=JmN8wx0ZcwrsXaWrD4Fv2q50YdIFx6jmaYZV5yW4VDs=; b=ijXWaITT4m/k+U8RItHeH7lQhWnOoN9e+dYhROgBC7kaX6a+Si2NZ1Swdlat6QhKwWUx8An6PBdyZ0DEVpw6qIShUDdJ4p+M/44L2YxgpUShZvqv08kAuwQJGfCABuMbB/k0DL408vRzDtRILeliotkprcvrb8e/wWEhFAxMZOf+5wGlpJ5cSV0rUyyQ89tjfzQIT6XNoDSQPDT8Bx6012EhE9wZjijrnGtWB04MQf2HoamWomH9r5/oX7AUA6yvAg/6834ZbOHPnJozx73UUTJSdVRj21xNUyUelIBu6eQQLSkautMH2ujlYKbKOoCFS/erYm0Wnccp9WnYCfgLtA== 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=JmN8wx0ZcwrsXaWrD4Fv2q50YdIFx6jmaYZV5yW4VDs=; b=lmArX2IETs3KDYjkejFRDvWq6eOortul75dZtslAVOEKu4fuihckB4Zr5xI8aBiAdzuo9e8mBtx4XesPbKUuVvaACsFeE2AjylyUNiJ4+NQ2PyARa0Hc5ARhC683k9elXBXAOGwgx7/KNxXh7e+ZL5/2FLB7WpzpjvX7fibyUW8aOmVT6gNYvToGWKbSROAGMaHuP/MrWjnjDt7HN5hgwb75+n2IrhBSQIhtOg2rxTuf79rvggJWwB/LedxPH/ZIe+nL4ROz3iBsD1CSBVe8sqLvdUcPK3pviTQhD2Vh8mpFwtIQvLDXOt8uBQRw6JJguDw+u3uxKFGc1thV/nKNjw== 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 MN0PR12MB5809.namprd12.prod.outlook.com (2603:10b6:208:375::7) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.6631.44; Thu, 3 Aug 2023 00:08:19 +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.6631.045; Thu, 3 Aug 2023 00:08:19 +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 v6 12/25] iommu/tegra-smmu: Support DMA domains in tegra Date: Wed, 2 Aug 2023 21:07:59 -0300 Message-ID: <12-v6-e8114faedade+425-iommu_all_defdom_jgg@nvidia.com> In-Reply-To: <0-v6-e8114faedade+425-iommu_all_defdom_jgg@nvidia.com> References: X-ClientProxiedBy: MN2PR15CA0058.namprd15.prod.outlook.com (2603:10b6:208:237::27) To LV2PR12MB5869.namprd12.prod.outlook.com (2603:10b6:408:176::16) MIME-Version: 1.0 X-MS-PublicTrafficType: Email X-MS-TrafficTypeDiagnostic: LV2PR12MB5869:EE_|MN0PR12MB5809:EE_ X-MS-Office365-Filtering-Correlation-Id: 8b5fc274-ff7e-4a03-60d8-08db93b5bc0a X-MS-Exchange-SenderADCheck: 1 X-MS-Exchange-AntiSpam-Relay: 0 X-Microsoft-Antispam: BCL:0; X-Microsoft-Antispam-Message-Info: QfhU6sPo5NHqygwmcbXxZe0VHlJUMsGlov8K/oNrXFamb8RKp3iW4K8B6HyiaZKpsR8a8gOFQgwdlyp1C7L6dXNDokGPHiV353j3+Enu2sT0d0lHy73tdn9nAxtEM6t9JPTtQy6IXDAi2VBR5QX3jk+xBrH9Hzl0uleIbxeXsA/pOwdF4FL8AQzqgo2yki90HNenT2vACJePq7ICBIrYOyB7esMBE2CsHr88vV7/u7Mxw2nT6ZjWAM0x3fAQkyzLIeTNgB//z7Awf5ofe6zeK2cdpD2eS81QE8T1GN13HE9nkZZtMHv236SCNn17WRAkzHYoPK8W8VDz/4y02pkwBKVB/Ntarb47bfSoCLovcLnZI7impf8Dtf/0oWLCT/hJu1MaNjWzeUqQ8aD/L5CPmqfGlclOp1CXVpRf8yUUGYKoHigAXYsz9BWCJaBY7184usDaPM8AsU670T6QwR/Uug8y6RSuA5KY7KT1uS7YMOCiGvdR5lKaiXelo3E8aNYvS36YqK10IEXVYZt+jTj0K08+COB3zvUey8oLcenPo6wl8OzzJh7IyWMlksVj94ygBo5dnwMNpdNpkg+P4qa2W51JjxgILU47vXrLzy5Syh8= 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:(13230028)(4636009)(366004)(376002)(396003)(136003)(346002)(39860400002)(451199021)(110136005)(6512007)(54906003)(6486002)(6666004)(921005)(478600001)(38100700002)(41300700001)(5660300002)(316002)(66476007)(66946007)(8676002)(4326008)(8936002)(66556008)(2616005)(83380400001)(7406005)(26005)(107886003)(186003)(6506007)(7416002)(86362001)(36756003)(2906002);DIR:OUT;SFP:1101; X-MS-Exchange-AntiSpam-MessageData-ChunkCount: 1 X-MS-Exchange-AntiSpam-MessageData-0: aRh9/Z6xMjQOOB72bsMdpCOH67ZStuyPOosUNm8aHFuBW/eU/CBPhO37VTG99Sql5lmS3KcRgPacypXWk4ke48EsWOX8qdlUm5koYzXZu/I2ZLBRuV1RE82oulpVIUqIlyf5PwUlUyHn0irfd1Ujzfy34kdTV+xkCeUBejwEX5dZr841pYX/njXF+e0V2sYBWqQsO40RKr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p66ZFRtlw1xLAf21sMKZa+GGE5I3D3EI9gpeSybDv+jASJOVqSqVcwS4r2KBwifHAAfpNlOLux+Ke5PXr7Jx37XO41wcyrm7IlrO4VdelNlH6itndFLYGrZUFMeYKFceV+m2d0OWYDqc8B1CmTMtcSvEimj/xd43P/Amtzx4bSwdB9jT3Kq8Qo+pNJqFcbPS9L/1pxAFT3lw8YxPrgjkMf1WraD+Ie2sgH+zzcH4iokXw1IaE9sb6bLFBvVGNvdiF0s95gwmvN9q/eNoPBpAGZNHx2nUWeaprPCUs4j5HesYkqPB4xBvmL+9VPrFuQ X-OriginatorOrg: Nvidia.com X-MS-Exchange-CrossTenant-Network-Message-Id: 8b5fc274-ff7e-4a03-60d8-08db93b5bc0a X-MS-Exchange-CrossTenant-AuthSource: LV2PR12MB5869.namprd12.prod.outlook.com X-MS-Exchange-CrossTenant-AuthAs: Internal X-MS-Exchange-CrossTenant-OriginalArrivalTime: 03 Aug 2023 00:08:15.9124 (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: qM+gGfVuC2f0PmK/NtUb+v5Hs0/bxJ0LyNhbgRWdT0Qelu27Ve3R5UgWHTPkADOL X-MS-Exchange-Transport-CrossTenantHeadersStamped: MN0PR12MB5809 X-CRM114-Version: 20100106-BlameMichelson ( TRE 0.8.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20230802_170839_713784_1EDB2D27 X-CRM114-Status: GOOD ( 13.43 ) 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 All ARM64 iommu drivers should support IOMMU_DOMAIN_DMA to enable dma-iommu.c. tegra is blocking dma-iommu usage, and also default_domain's, because it wants an identity translation. This is needed for some device quirk. The correct way to do this is to support IDENTITY domains and use ops->def_domain_type() to return IOMMU_DOMAIN_IDENTITY for only the quirky devices. Add support for IOMMU_DOMAIN_DMA and force IOMMU_DOMAIN_IDENTITY mode for everything so no behavior changes. Signed-off-by: Jason Gunthorpe --- drivers/iommu/tegra-smmu.c | 8 +++++++- 1 file changed, 7 insertions(+), 1 deletion(-) diff --git a/drivers/iommu/tegra-smmu.c b/drivers/iommu/tegra-smmu.c index f63f1d4f0bd10f..6cba034905edbf 100644 --- a/drivers/iommu/tegra-smmu.c +++ b/drivers/iommu/tegra-smmu.c @@ -276,7 +276,7 @@ static struct iommu_domain *tegra_smmu_domain_alloc(unsigned type) { struct tegra_smmu_as *as; - if (type != IOMMU_DOMAIN_UNMANAGED) + if (type != IOMMU_DOMAIN_UNMANAGED && type != IOMMU_DOMAIN_DMA) return NULL; as = kzalloc(sizeof(*as), GFP_KERNEL); @@ -989,6 +989,12 @@ static int tegra_smmu_def_domain_type(struct device *dev) } static const struct iommu_ops tegra_smmu_ops = { + /* + * FIXME: For now we want to run all translation in IDENTITY mode, + * better would be to have a def_domain_type op do this for just the + * quirky device. + */ + .default_domain = &tegra_smmu_identity_domain, .identity_domain = &tegra_smmu_identity_domain, .def_domain_type = &tegra_smmu_def_domain_type, .domain_alloc = tegra_smmu_domain_alloc,