From patchwork Thu Aug 3 00:07:48 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Jason Gunthorpe X-Patchwork-Id: 709697 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 vger.kernel.org (vger.kernel.org [23.128.96.18]) by smtp.lore.kernel.org (Postfix) with ESMTP id 982F8C25B75 for ; Thu, 3 Aug 2023 00:10:06 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S233582AbjHCAKE (ORCPT ); Wed, 2 Aug 2023 20:10:04 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:56378 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S233564AbjHCAJf (ORCPT ); Wed, 2 Aug 2023 20:09:35 -0400 Received: from NAM12-MW2-obe.outbound.protection.outlook.com (mail-mw2nam12on2069.outbound.protection.outlook.com [40.107.244.69]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 5D48235B0; Wed, 2 Aug 2023 17:09:28 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=none; b=Kk8SP6tNr5zU60eqF8RxgoUsO6lUSVP0I/QMATqQ9OsAh4p0WulBZ0XpMmHIzkPw0xpFlQwD9s0NrrsNm8PqG+QuqHIcwsOVBPrTVxzwAXRHo6IZks7+JOvNkaj+/SyRGB5JP3r+lNq0JTE9NcJq74bCHKkJEGH9EZYlMSdvzytqzbbBlwqyGPFZldrsV2lWaO1/Jg7ymyKlUJY+5aV25TyoioVWb9mG1F43u1u51su+Pf7cKe55FP7MWdhyh0QyVaJLQEv+WMN1u7Ea5RZcnX8MpDHwr2eAmTd+9MhJbrZ2okXeo6DUByyGvh405VydoMVPNSCRwWh8/nZDuqQM4A== 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=EK2gs2gxwmqDvnsbxx19mnnuEldKr5sxQDHk/fU2WJA=; b=VfljL0xhCThB2QEZW/2YRKPpQriBqhkspc+wZurxGRgMtOw20FPBg1o+sm4kf9egXLnfPyKQg/E+lMbVk/JJbQ1t8WCO8a385ao249f/BjG3JKjnOaIWHmKpIruJlMKk/C7c+ov3ApUM4h3SUZzQ/ucqDTY65k25snkUw7Uln5YJM4i7tEuIBkMvRMjQYq1UjU9I5No9AtxjNZchrRxXP+5JxNyafm6CKoA2AbnD5N+cxJWMPROjd+vQaHKnePLrbmcWkExPsaAtbAOIWLIUMJxOr48Zm+AQkZM8sdfpC2Lnt2XAFBxAo2Ikcvv25zqKwicqreYplcf5mKNzX893RQ== 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=EK2gs2gxwmqDvnsbxx19mnnuEldKr5sxQDHk/fU2WJA=; b=VZsw5JYJ3HnWVulTrFcv3fN1tIt3xCrvXpHgruk6bcJBh3zlnK7RtHFi1A+XbaLvrLMD7RwCdw0t0Gw4pXIRjTJjJLAOdbvCge9DyuYvaQt2HO1UJXWFXIkCi1uZ0MGGbKcqtIgbIbjAx3sOPSK6mRxB2SUjVLOoOryqtYSGGzfR6GVGnUFMgNls5jDO45nHY+kdfsCGMmZ3ll8wUnOwuyKvaQ9MoTgWsAwLCecaJrku9YCa35qm2RPfK7bFt2eRRdWLtoNnPLhalkth7LgSbmp7Wp6HNjib+lvMXrbmENYEajTs4T9fpnixPSbcuNNDRn8T3+XGX0ErfhzOKYEcMQ== 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 DM4PR12MB6085.namprd12.prod.outlook.com (2603:10b6:8:b3::16) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.6631.47; Thu, 3 Aug 2023 00:08:26 +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:26 +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 01/25] iommu: Add iommu_ops->identity_domain Date: Wed, 2 Aug 2023 21:07:48 -0300 Message-ID: <1-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: BL1PR13CA0298.namprd13.prod.outlook.com (2603:10b6:208:2bc::33) To LV2PR12MB5869.namprd12.prod.outlook.com (2603:10b6:408:176::16) MIME-Version: 1.0 X-MS-PublicTrafficType: Email X-MS-TrafficTypeDiagnostic: LV2PR12MB5869:EE_|DM4PR12MB6085:EE_ X-MS-Office365-Filtering-Correlation-Id: 520d6bf9-61ad-48fe-93fe-08db93b5bd2f X-MS-Exchange-SenderADCheck: 1 X-MS-Exchange-AntiSpam-Relay: 0 X-Microsoft-Antispam: BCL:0; X-Microsoft-Antispam-Message-Info: 50AH99N8k4Rrkac2FbeENv/aCQrL/1LcJ3/IYs17avlJlprnhvq5AdhDgYM4Yld0jQx9km8Kanuy1p9v3ksDOsz6f26c5KqAdFtwMMlKGqW4Gg5kosgKwM6/7OhsEDQGTkGq0G2jb8mUwEsZ3tb1YEEe6AZVtPY6UFA2KKgX4pIrA0O4QsF7cUfuM7Lq6vfqFUFUAMQys1fenftYp//+GN82M+VfI+MFIbrR/8ggCFhhuVleO8kYwKSmIvCTyJP2oePIJhGkBZt0Uml5hem+BrC2UZBFMWwidxr7iF2GLCBEdW2Ii+/vfo+6bnNQV1YMInQhqGhEir0oArlGGrZjeMBq/KbGj/SxWcTAbcvDR/odB/ebGz3mM8pyVgVEy/S/jOZXmDFcQedN2Qc/EXLsJJUVRkHw/IJ04ql5iFT4vo2kT8af2wH+F1Jmtp7erj7D/BtumOqYT/xTYRCBtOOJjozissybnCdqiH+0qkaSMNdEbBg92F9OoYOzLn419Dij2IFJBtIWQ1+7td0lk/7wrDPGrXWZpOBBRkHE5k37YL0o07mGHAuecxBIZDJWlfSbNLdtG7EclAhHOHMOCSTlakAGd7V9yKRbKvh8eJYsAhXvsB9xsZ1Dwljl+k0RvzoUqTVlVsC+4pDH67nI952dABJrqEntcgwrZQEeocyaMbA= 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)(396003)(346002)(366004)(39860400002)(376002)(136003)(451199021)(7416002)(36756003)(86362001)(7406005)(54906003)(478600001)(110136005)(38100700002)(921005)(83380400001)(186003)(2616005)(6506007)(107886003)(26005)(41300700001)(8676002)(8936002)(6512007)(6666004)(6486002)(316002)(66476007)(66556008)(5660300002)(4326008)(2906002)(66946007)(4216001); DIR:OUT; SFP:1101; X-MS-Exchange-AntiSpam-MessageData-ChunkCount: 1 X-MS-Exchange-AntiSpam-MessageData-0: XJFfjpCNpVqIlKzHuB5TnDeP6rO8DuvFGcPSoacvzFPofsNGaVO1xpqJViSW3G0j089MgwJAEU9sMaUWAB01xkCCTaPsuMyG4+CyMNvAMrH0dXC69AL9Q9rjFcioYMd+TKTepFWAwYgkol/DZ9ynSyEzVgo8YG/LBQYo909QmV4tc40w9AwCeJFktc0TjF9WvFODIfsIS0WZUL7HD8PpT3pHzIGLDwb68/AcQ4ARU9asEV9MV/VRUl+GU7oYgGxLhWInKpSLE+EGVfJ1C2nqmhJUDxsbPZWvD+cpatBXAPkXJ3CUoA4r0DiLmeEkV9zMqw8X6XJ3MJ4m6XPOcBRad3UapxrgDu6Msj1a5pvk5dymfqV1RxZQ9x9S8AsIPbBCNpEHSkMwv3BCUfXwIaTNubbbm2PrM1/F1NPcuoi/jhW9BrL4q6kGPGi4BbeaAjxz4BHp9tsowN8pUyrA54bi1UGuZLl9VIu6lasc8F2M8RryUTeiX5scMFPZo3rqh9hT8HFsIXpPRtNHbm0NpuwkjcjWTyBeKh6/YWMXMBQXU8yChzyIbB6Uk5ywqhtG2XUDzAT/ekRCYzyNeJdcf7FYXDYCb4dbhvU7VmA9Mhh2ydJLNravrZ5zLWA67Dnt+tjeaOLcisE5ZA2kKR2GQFPG53fWaaClrjn+nFd2QIp/mwlc1YKllRDS/QLWXkI4LsZx0ij20Qf8+Y1TriD57h2B7LHdsAPcA0U1hDJpPcZXG7afYVs8pgMzrbzsg5f1YL/w5kA7zKeHsE+5JWE+/y4QWyshd+DJJ99CxGjgBIcw76zwCU4qXTYk+AeqFLLkyz+xNtzaXg4+o1xYRSGBpiCmReyiRLbJPtyvxUL3sQMfHMVSBxLYtcSl2TbrEa2UlcDSBPgEcNAqQzvI5pk4tjcedApc3Fxv/Aosc2N8/S0Owd+Wuc8P/PGDsu2mWhiIAL2Zt7WEq4eshhE9h7OSHuxeVJCDasMuwqPW9SMxDsAfQBf900Xd5hQbMQ9bett10sf3LminiH4Ti5xvl98XUHtfgwRzhfGFW/Jdoao83KRkcqvdgOPsfQRmrfzL7MF5yh4KEouSRH5dKJTIsLYBKUQ0ToaV3LrJIO2bsYbMqTy8m4SjhDSvs2TcArSwlC4g20RjmRrjpvvXyMWxqMXTJScEM2GjY31I9gYr73fHLsLxFf9aKDY6q6p8WLgs/il2Ksz71ge0ebH1b+6h9OL+9T7Kl+9f32tIKjnRoTFQCDDoyNJo6fqM3T7nMWNyqCenbWeK7wtTUxFhfRHR87GDTnHG3EswmNUY5xDoLaXkDay6JJVOmD28ksELK6cbojE9ydZweZzStpKpsHIs5Aszvk6mnMBeXoO8pAbcn/eMSdj00AB5jv4b3D05l991HySZzdBVBbwZJUiD/zcwhdqEWNidKQ5ypkJ1lw2/O8GqIsyWFrv39U6+uQW7tBLzQaeqWaeHGCsGkJeX0/CpJXJumC88DkOd768KfvrFuDPGIrceIjPUF7PW2U3zO7NqkMvRD8nmnJrMf5AtURJG7lgVju/LYP8uJA/5ofPbmngF4O+k208m+t+86zDigrAwpFtM0f7H X-OriginatorOrg: Nvidia.com X-MS-Exchange-CrossTenant-Network-Message-Id: 520d6bf9-61ad-48fe-93fe-08db93b5bd2f 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:17.8458 (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: o8PSJwqD7u+esauLafi6xRtVQuhXwv6yJQ3oZdFHDJtWnXSHmNFb8UFgzgGaDjnk X-MS-Exchange-Transport-CrossTenantHeadersStamped: DM4PR12MB6085 Precedence: bulk List-ID: X-Mailing-List: linux-arm-msm@vger.kernel.org This allows a driver to set a global static to an IDENTITY domain and the core code will automatically use it whenever an IDENTITY domain is requested. By making it always available it means the IDENTITY can be used in error handling paths to force the iommu driver into a known state. Devices implementing global static identity domains should avoid failing their attach_dev ops. Convert rockchip to use the new mechanism. Tested-by: Steven Price Tested-by: Marek Szyprowski Tested-by: Nicolin Chen Reviewed-by: Lu Baolu Signed-off-by: Jason Gunthorpe --- drivers/iommu/iommu.c | 3 +++ drivers/iommu/rockchip-iommu.c | 9 +-------- include/linux/iommu.h | 3 +++ 3 files changed, 7 insertions(+), 8 deletions(-) diff --git a/drivers/iommu/iommu.c b/drivers/iommu/iommu.c index 4352a149a935e8..5e3cdc9f3a9e78 100644 --- a/drivers/iommu/iommu.c +++ b/drivers/iommu/iommu.c @@ -1931,6 +1931,9 @@ static struct iommu_domain *__iommu_domain_alloc(const struct bus_type *bus, if (bus == NULL || bus->iommu_ops == NULL) return NULL; + if (alloc_type == IOMMU_DOMAIN_IDENTITY && bus->iommu_ops->identity_domain) + return bus->iommu_ops->identity_domain; + domain = bus->iommu_ops->domain_alloc(alloc_type); if (!domain) return NULL; diff --git a/drivers/iommu/rockchip-iommu.c b/drivers/iommu/rockchip-iommu.c index 8ff69fbf9f65db..033678f2f8b3ab 100644 --- a/drivers/iommu/rockchip-iommu.c +++ b/drivers/iommu/rockchip-iommu.c @@ -989,13 +989,8 @@ static int rk_iommu_identity_attach(struct iommu_domain *identity_domain, return 0; } -static void rk_iommu_identity_free(struct iommu_domain *domain) -{ -} - static struct iommu_domain_ops rk_identity_ops = { .attach_dev = rk_iommu_identity_attach, - .free = rk_iommu_identity_free, }; static struct iommu_domain rk_identity_domain = { @@ -1059,9 +1054,6 @@ static struct iommu_domain *rk_iommu_domain_alloc(unsigned type) { struct rk_iommu_domain *rk_domain; - if (type == IOMMU_DOMAIN_IDENTITY) - return &rk_identity_domain; - if (type != IOMMU_DOMAIN_UNMANAGED && type != IOMMU_DOMAIN_DMA) return NULL; @@ -1186,6 +1178,7 @@ static int rk_iommu_of_xlate(struct device *dev, } static const struct iommu_ops rk_iommu_ops = { + .identity_domain = &rk_identity_domain, .domain_alloc = rk_iommu_domain_alloc, .probe_device = rk_iommu_probe_device, .release_device = rk_iommu_release_device, diff --git a/include/linux/iommu.h b/include/linux/iommu.h index b1dcb1b9b17040..e05c93b6c37fba 100644 --- a/include/linux/iommu.h +++ b/include/linux/iommu.h @@ -254,6 +254,8 @@ struct iommu_iotlb_gather { * will be blocked by the hardware. * @pgsize_bitmap: bitmap of all possible supported page sizes * @owner: Driver module providing these ops + * @identity_domain: An always available, always attachable identity + * translation. */ struct iommu_ops { bool (*capable)(struct device *dev, enum iommu_cap); @@ -287,6 +289,7 @@ struct iommu_ops { const struct iommu_domain_ops *default_domain_ops; unsigned long pgsize_bitmap; struct module *owner; + struct iommu_domain *identity_domain; }; /** From patchwork Thu Aug 3 00:07:54 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Jason Gunthorpe X-Patchwork-Id: 709699 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 vger.kernel.org (vger.kernel.org [23.128.96.18]) by smtp.lore.kernel.org (Postfix) with ESMTP id 1788AC25B73 for ; Thu, 3 Aug 2023 00:10:02 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S233270AbjHCAKA (ORCPT ); Wed, 2 Aug 2023 20:10:00 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:56258 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S229873AbjHCAJc (ORCPT ); Wed, 2 Aug 2023 20:09:32 -0400 Received: from NAM10-DM6-obe.outbound.protection.outlook.com (mail-dm6nam10on2077.outbound.protection.outlook.com [40.107.93.77]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id A13A13583; Wed, 2 Aug 2023 17:09:24 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=none; b=fSLQm0O9tiDjsaPKEfB5NsgJDv4Jjb72wRq5XulX/x4VeLThARSLGD49izC1sAFwpNcZ91W/qNo2Vqa3emEuoU8n8klF7i+S/gTnG34/aNrccZ8L0xfH33p9VVrMMu1w3hxeWrMMtAco86iQ8M5aSXbjRT7tHXYweJTMY6mDuloO1mishuy7ZZKmh7xJ+jLNa7sfTclAGvZ2uw3C3qNN9D0mWK/2kYm0hk09FrfKv3laNr7oXCL8IuSVgwS0SqP9V3w6e0ssvMr8nAQ98lfoNdytWjnL4LDkC20OUunaPnqFNFyBFMa4gPyUMbMhNay7lzWk51sIiKwFwBw98ml6vw== 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=dijjnmcTwEIG43n1u0a4rcB854nzj8vKoYIf9eO0DwA=; b=aI6CjzoyMe/VqT8Hm+XrGGSPjcu/V6kvb93JPEY/Yb/jfMCFSYZY9s/++aHtPupQjyX08gHN23tNE3XYYOAeyZB54D7/mvnvc82aK+soTm9WDcogkkjXb4/JCHiJFrNiGu7mt/8cgdvhym84FklEabN9IPGxRXGEppcmuMXaxJtpRY+NhqYyRTXzbdmgNK6G7P5V4aTAb/2O15cUHx8xLF26vyxjJLWGHlgTJHUr6Bt6W6A5DQx4OdjQ3pCWL/MnyW5cBGa261qrr6+vLH5LBdTw9whKHoNQ/ltGLwgxouMvsI3DIW+Hs+2x62TUVe+2hKhJTwSoYIva0pu7APhgug== 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=dijjnmcTwEIG43n1u0a4rcB854nzj8vKoYIf9eO0DwA=; b=IpNWsbFLwT3iE2BuWL7CeJ1t36J/k1T470jqgcVTtewAGnBovWK8UB6h7ksm2W498AGDbaq7E2p3bJrrHHHa3uikNPTUdl+Lq1fNMpFlYJaNfMXLuNjEDrLimNfEhqvvGVHZFix9b8pVmocr1LJrirtsoJCLxNqMlwZ0e1xP3+3xgf9mHodS8CDeRNWkgiHcCb/Av98wwwOSrYUyH89jCQ1iuBxQXHuPcL9YnaMrgiNeen4DFyaKoKcpPBkubVrMxuPolDqsX3efUfW/IYeBlv39ZOLIOHlM7cQggGDjCnfTnKHDjq/d64262xOKGovl2yipRHmB3BedgV4Bqo3GKQ== 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:17 +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:17 +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 07/25] iommu/mtk_iommu_v1: Implement an IDENTITY domain Date: Wed, 2 Aug 2023 21:07:54 -0300 Message-ID: <7-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: BLAPR03CA0138.namprd03.prod.outlook.com (2603:10b6:208:32e::23) 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: a0b1ba6b-2722-4a3e-33e9-08db93b5bb74 X-MS-Exchange-SenderADCheck: 1 X-MS-Exchange-AntiSpam-Relay: 0 X-Microsoft-Antispam: BCL:0; X-Microsoft-Antispam-Message-Info: bwbp1uribbGDBzANtO+GmqWXt84LaEU0PUZHZ1kSuYhxFJDpi3sqODop8qsstm+6yD5UyJ6Cz/V477HAp6O3HQhlPDJIEKPSCleadnTW3GGdFxkk1tzoZzenn4gzDlGLDpzRPppILhudR3SVwA8FZpemvAh2+89/cd+4PGV1lm1jQdtub0iK0+HtIr10fc0WV9sz/iVb+nlnPd7MLQSns3lKsqk8aGsZoy2DiCibmu75zXI8zROMPZjyz63/7cV0k8DfdRVj97/CamzpWC+T1O1PW00db+rdK/RyXymTmvvJwqirn1EOMq7F70A2CFDTGnw3DpYbDDiO22Gcfpaj3XDb+C9D9+A3uIetYfuLVTR4dkfCYt88QCk67o/sExpEoSrxCSejYrI4jsHluCDoEIwz5ygNSitphy4caRHLbwypNU5ZWcq9CvOr3qW46fx4XCLy+IlDairTS2xw9o7S1dnXj9jO4nXVg86wkVoP9tqlpk5waNl0PLIIm4b8kjPfC4uLLB7DegTA1VAgZ6z4lk7gPzhQTNYNkhRWB6GCCa9AEE4wo97Y03GzONqnQm1WTcvpz7Pj4eiX4umOQoGRa6+s+GVgSBHLeO4gnu9M5RC5VGqZwQnFaFJdcp04mODl 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)(4216001); DIR:OUT; SFP:1101; X-MS-Exchange-AntiSpam-MessageData-ChunkCount: 1 X-MS-Exchange-AntiSpam-MessageData-0: DxeVhio6hDmGjfTnErs4FgIxW5ELfrGJb/zn002NGqYbtAT8LZOlnOkyZf4kXSavRg8YurPP8N24/SbYrTKkfTIGn0fIRCxlxoo+wsRYNGubk/yzFNHRCTbr7kPjS+P7qfgYZZ4G/cGl0sQx8GP8J2eUuR0Vx79J8ZEZytPMX0b85pBXVEwScfgnJcYCcROARnfPH+nthK/OotEtyWnjJy0o8vyddSTyC4XKfwmLcD9Iqmj17Msz9TxumD2S7DJYVk1iRoE8kVpLbBHxzPKdPnKq6yLDQqiiAHcJvNp8DaU4Hmc6uJcfIIQ9pWaSTboUEqZePA0AEjNajVoqF5oB9DoTtnLay2maLlR8ZAWO+SJQRIXXx9leOTEiEsj4WSnV6M8XfmElwOWM2uxVQZ13zwLqz3xB4xRtP7wk+hqyjaOL5KcmkVjhbEzXRnlNKTYMykd+vaSxKzmJd1uRROM2P0bAbluDWt2f4+hQJPuRxXiS0Q21NaiGjvj3ZnvYsJi5daF3yIFm8Pw4bukO7DMXynJ5OWBjBHm4ycOwoYEjiTx3cuQlJeBzY+v5PcMISzKkt0LMODxyjSNrd6z9qcNl4M1iFMJ2Wchm31h50DrE79W0korF5PRdbxz5rFPlKpeXpDiUCOwg4K9Q19MrxcKJLlCki/5ooEYgNdQZ/XghI21PSk7zlU6AqDHmmXAEBkf8AcPy1yAeXswtrL0j2qu66LkPQ7CDHAz3mI/Z7Ypj13WBP5JtycqWHUxLnhaWEAfAZFRavCGYPeIxy2GHuxTdz6kvvnFXM0AFkdD0ROgMOUVDtBtxUX4ZHezGHYkQdShn1pANDzd7r8CFHSYSRPGx555FUFzEvIu3k4dvcQZqwMiueJSzuThTJLvptcyfZTmvrBpw+1oaQDauVfk3RixYhjqUhiuxYDdkzJeJyY74KuDM9q4mCWlxf/LfZGWoaTG0WzB9fRkyfD7Olb1wPKg9GxS7pjrZWqZ1wllzPMz3tY5xYPu8iHuaYUBeeMx51QzUQ2nhTzlBvZsoLjRTCVBxt7N6BGCyWPSHT0oG0p4yOu0WpcFSQJQ7UJHzEWjcDqeTW2X95iN4Jd6q9adZ4WkaAVabBafmLRn8cwph5Xr2BPvlqd2EqO+8cvrTRXDXMSCpqmb0mMWJsy4hixDGLkxU0DhhLDFiSMHEGlRqt3Ln+DgSM8a9+xegS0gt5hlIVrntphwlFKOB8O2O3LpFNMab09VCfMCLifCnt5mRAX022u0cz7/T+GWBxb3RpMPxSCcRupio7fIxvE4Dln2BM6iY8SHAO1O081WhXyzM4YgHSDpv3Fjje4tuhot6ZwmoacJFkMYU9N60Au2iIyEmPOBr7RHeJA4Kq5CWQRmW6OTm5/f/cegYsZSrhfXsv2pdOy/ibrD7B67XT4YgCJOufR61Hb4MkWxcAslCcM0qYBFg4xIdONyF7LpOrq1wyv/SGPToB6lNO3qPfKFF2AUgU8qJshk9RLiBEs0kXiSJYTaAOozYVujLt+ZMq/xmDweihJOUbBTG2yqs4OezXZv81JDXc5Nkb+6dHGmXhbrmVUymRXjL5tkrlSfm7VIPpoNYlDnY X-OriginatorOrg: Nvidia.com X-MS-Exchange-CrossTenant-Network-Message-Id: a0b1ba6b-2722-4a3e-33e9-08db93b5bb74 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.0165 (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: PwkZaMtcWxYh0+SyIrAjWfa5e6RGVwC/CY3xaz421zqQxV1ZDrDk6xt4eZyRctvg X-MS-Exchange-Transport-CrossTenantHeadersStamped: MN0PR12MB5809 Precedence: bulk List-ID: X-Mailing-List: linux-arm-msm@vger.kernel.org What mtk does during mtk_iommu_v1_set_platform_dma() is actually putting the iommu into identity mode. Make this available as a proper IDENTITY domain. The mtk_iommu_v1_def_domain_type() from commit 8bbe13f52cb7 ("iommu/mediatek-v1: Add def_domain_type") explains this was needed to allow probe_finalize() to be called, but now the IDENTITY domain will do the same job so change the returned def_domain_type. mkt_v1 is the only driver that returns IOMMU_DOMAIN_UNMANAGED from def_domain_type(). This allows the next patch to enforce an IDENTITY domain policy for this driver. Signed-off-by: Jason Gunthorpe --- drivers/iommu/mtk_iommu_v1.c | 21 +++++++++++++++++++-- 1 file changed, 19 insertions(+), 2 deletions(-) diff --git a/drivers/iommu/mtk_iommu_v1.c b/drivers/iommu/mtk_iommu_v1.c index 8a0a5e5d049f4a..cc3e7d53d33ad9 100644 --- a/drivers/iommu/mtk_iommu_v1.c +++ b/drivers/iommu/mtk_iommu_v1.c @@ -319,11 +319,27 @@ static int mtk_iommu_v1_attach_device(struct iommu_domain *domain, struct device return 0; } -static void mtk_iommu_v1_set_platform_dma(struct device *dev) +static int mtk_iommu_v1_identity_attach(struct iommu_domain *identity_domain, + struct device *dev) { struct mtk_iommu_v1_data *data = dev_iommu_priv_get(dev); mtk_iommu_v1_config(data, dev, false); + return 0; +} + +static struct iommu_domain_ops mtk_iommu_v1_identity_ops = { + .attach_dev = mtk_iommu_v1_identity_attach, +}; + +static struct iommu_domain mtk_iommu_v1_identity_domain = { + .type = IOMMU_DOMAIN_IDENTITY, + .ops = &mtk_iommu_v1_identity_ops, +}; + +static void mtk_iommu_v1_set_platform_dma(struct device *dev) +{ + mtk_iommu_v1_identity_attach(&mtk_iommu_v1_identity_domain, dev); } static int mtk_iommu_v1_map(struct iommu_domain *domain, unsigned long iova, @@ -443,7 +459,7 @@ static int mtk_iommu_v1_create_mapping(struct device *dev, struct of_phandle_arg static int mtk_iommu_v1_def_domain_type(struct device *dev) { - return IOMMU_DOMAIN_UNMANAGED; + return IOMMU_DOMAIN_IDENTITY; } static struct iommu_device *mtk_iommu_v1_probe_device(struct device *dev) @@ -578,6 +594,7 @@ static int mtk_iommu_v1_hw_init(const struct mtk_iommu_v1_data *data) } static const struct iommu_ops mtk_iommu_v1_ops = { + .identity_domain = &mtk_iommu_v1_identity_domain, .domain_alloc = mtk_iommu_v1_domain_alloc, .probe_device = mtk_iommu_v1_probe_device, .probe_finalize = mtk_iommu_v1_probe_finalize, From patchwork Thu Aug 3 00:07:55 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Jason Gunthorpe X-Patchwork-Id: 709694 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 vger.kernel.org (vger.kernel.org [23.128.96.18]) by smtp.lore.kernel.org (Postfix) with ESMTP id 2C142C25B5F for ; Thu, 3 Aug 2023 00:10:14 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S232039AbjHCAKM (ORCPT ); Wed, 2 Aug 2023 20:10:12 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:55682 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S232525AbjHCAJx (ORCPT ); Wed, 2 Aug 2023 20:09:53 -0400 Received: from NAM10-DM6-obe.outbound.protection.outlook.com (mail-dm6nam10on2065.outbound.protection.outlook.com [40.107.93.65]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 82BC33AB1; Wed, 2 Aug 2023 17:09:38 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=none; b=KLMjlBVc2o+1heVEzUQ/SoD+54U6HpXnc97NurzXgHO3xIBtro2FPy72xLHaEkMlsCSM0EsEO+yGue4CKyOxcU0F0pR0vk2DZxs91l/2KcOD7oQtegBDkDEEinzpZtNECyx/zEXKxjuH/cQsrGHHf9Mvjoq5TKSBwRHoOylecaR9jfLuv4XlBhTAg/ddL9zfXP2KQBKa+8AbiW/Z68Tg43Vb90H9VRWCo5aHIAIETwgraOnUkYkFkJu1l/RBJzYdZwyz9qdZhL7xZXhQr9s+JMI1UINYiG7AxxMbK/Wkzlgd/RUfKJ90raNz1/0GBdqIYy7Rhkk83R1u+fmemu6l4Q== 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=c/DHZV+QkYH14EZX/DKDDPvM+4tG5SMjo0AaHDfOmFc=; b=Xavk7qwkmeUu+GOcY2xoor5NgY0Grca7jfgM4nYFlh4eF7Os3fHioVITsp1v6+XVF3V2lbR61L1nSS/ziX1CdYJnPNVTutaPtVFYC560piP0AIN05KYc0nI2MrK5EbIbVfyME5I6ZTxc61gEhjeMm9l4aizqLwwRRiqPFDKPZeS3MaDhw3a38s/1KTxHw8S5hYGQBp5KvDeIDk1FHTAtKUvH0mFmoeaV0wZVKr3jduIlgDX5y6tRxMOj1VVV0JK5sxpuodtqUE9hS3qeHJ2ayCXvogsa5NLeurt4jcA8PWoY6oQUM22fubw5gXP7E96iqDkhAKg7edqvmJQ2ESuwvQ== 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=c/DHZV+QkYH14EZX/DKDDPvM+4tG5SMjo0AaHDfOmFc=; b=MeIo1Z9dVM7L6AFeQDR6BRMfRaamE6EG9eQNpPf4maqt1kKu4CmrE5tudwW5DHN6n/idyyWbCHFDa4rCBQ/BxQF1z4Dkuh1smS6JBpEhInDChzlW2yMY1+SiYCp03CTBGwrPc0y+FnVvcYlLnIqG7c1JdkLobL6OEXFntEKxMnEP2isKejeCkR5ijDBmvKmEd0wQBDt+HYDeD6EbfUC5EbEwKaxMxhccF3EE8aPHNPzKjme/ym6OBtDmBsp8NWeikvA8AXe5Kq5RebaG36okkB4Vpua0WiA/MsuU3wu3xBI2B3/ZYkqv9laf/ePKUGFzuArIcGQmV0YB0C7gL0iGJQ== 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:21 +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:21 +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 08/25] iommu: Reorganize iommu_get_default_domain_type() to respect def_domain_type() Date: Wed, 2 Aug 2023 21:07:55 -0300 Message-ID: <8-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: BLAPR03CA0128.namprd03.prod.outlook.com (2603:10b6:208:32e::13) 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: 6cbe9e7a-6647-474f-84b2-08db93b5bc4f X-MS-Exchange-SenderADCheck: 1 X-MS-Exchange-AntiSpam-Relay: 0 X-Microsoft-Antispam: BCL:0; X-Microsoft-Antispam-Message-Info: cqBW0d97T+9BChQvk36dvaeeml5s6usLtfRH0tIaf6O2QzryEHUbbY1b3LdTBtsXlij2EoMdHFZIcI8d6+ePYyAZtsc+tlE0Fwu+swjMBJu0R7SMHzCly4NaVfpHsECi9WsqYBQ/qoPZU4HvQzcmFy3/+PMUsINyvckS7HsNkuK202BQBlIRpDLn9jeABNbABcyQ5eCQezAu1m/c1yruAa1i9DPwhpDSf5W1phifG7Qv4EEXUi0J/hHvSeNnam7iwM61B5MuIfX30JcBUyy3ibNjb7VT1hgV2xTsUCG5aoWLe6kPNid3bpJRlvtjwaJ89g9SH2cg6qO9XcAqTgof5e0NOmiDXh9I2HtEpNA92M5Wffe7BPHNHeUXkC9GsZmxQBgyH/S1qfKZQGb8nF+Y2IAwFZH+0QJLMPzCuVlh3ga615MjX9KotSOVLV8xJwFq2h6iq/cRW2gLrPa0o2FQWiA70lUX4QP/pq8seOxthfgH7NsrAMZ65H4q47IA9PnsIBOIlbIlVDo2dbUz7B/calxLmBQn41DdPiekkn9ATl4hlRNAhY58ClOmf7Ewi41MJYYzMnAyw4noHD7gvne/gN8uPUAYm9pBIFANWCk+HZplR+XYT2wCjtsUCcp5Rbp2 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)(4216001); DIR:OUT; SFP:1101; X-MS-Exchange-AntiSpam-MessageData-ChunkCount: 1 X-MS-Exchange-AntiSpam-MessageData-0: 7scw/Iy5nj5d85WkijeTXBkbwuSBpcsTnNpTI4ApJqSitUpufLfEP6G285Tp9gSCSS3gS+rMRezJojsCkl4wT4PSLbNWu+YXnTY8JpD3+mzWRXfF7r6jUfckscQlxOvkaETSPeptDfB4DH7nC9NSdfbHpg6raiSbg8Kmq3Wwz3PbOriZsZmRnLHSpcf2mx+g5p4zUY7yj06HpvGrqrnmm/JFz1E9eQiHbKEqGwse49rceo5l4lQ7PRcDdLxic6FZ+fsPZrCG7Q91B0qVQzlQVwgFU6TznZ+aPShzq/g5f5TLVY++Kptw00Hs3LE10CCVgAb4DfxIGz5Bhsuq12RNSJFJU2P/DMuSd8oGu099PIQTRN1TE8mrHF+Btp0R7LAMhL/9RS7uE0iGR4bZHhQP05lXGYMWjR3EB0StF8yI7o95nF+TVjNkkaHLEnPGKhE9kCxlyvI3e5eAUdSF8mPMC3R27lz0xtsqLA1tbB/JFIAKybc9ZCb88aGmbuoTLMQEvnDZRVJp1P/KHOsWVWyTSN38agik8t5I1c0nCUU1ZJ80g0xxFyDryRqRv3Sz5ci2GvC4z+J0SSCAvq2BWOxohA9218Kb88IKPugyvvOFefNBFm+6apcl16dj/tdfrlmzP8iZ5fQR7QVdLS3YYxUz327BwZ3+m2OD2MkYwxLJYPSXEeaFlGLup0HFL1R+vG5UjsQojrcqPZKD2Zir+VnH8OIm/WnCysghoyLf1GOB364J7O3yDwJKdUId0m68c+ooaA0taP2nTyb2hRKgqZ06cIKchn3gfvY68D4RM2Tghp4eC1EAI2nKD5U/w5t/ZC8qsAmn1UEZZn/qM1fAEMsPH9TtZRYNgV0a+KLkX34apkLVItGne/NkRuBApdTgq6wA0mom1anz+mfYfXPLLIOAYyazUHZyMOx7Ojb5nqmq+616eMd/muuQ96dbVSztLN51a0XsdeA8zPTFsUJDUSJmURYk90mlnE+XuI9oR76P5G/PhMx/33nIKI24S2IXS4QL1wqvDHfkHACkJVvYmWCuGeK1NwTNDR4MHC5Ti1wy6sX57fokukJRkTyXqDqqwB7Yd2p1hxSXvNRoGmMszhoj+A2iEdyTe1BtKeQ0WPy2K2tHNvdVvGEUn4TKuEJxf4EJYmz3tbuiCO0dLqK7JHJT4n7ilT7kbBsnRnZKNQQS/jncttLUVO/J2NB2VFq0i02Lvrshx6DVSGBqY4OBne5fFkJ5Ni+WgH+TCVijeHEJxykTtS6+i/x0y59ju3ufQM+vhW4deL4MPyPASI6WkLMmLQiEIEwhFZO9Gv8lxQ2XYa4Vwp2tM/uQ0BQTQoNqy5QLkkbz6Q9fJAvEOLRHbFOfVewrD0O+czA+9tEgujL7inTteQLcmyHOp13wi9Nvac6SsSDJY9FShnouN8f3b6xUxHNGAqQB9Oqbs6LZF1SSX8W4lNx5NqTDxyk026RHaQ0JXl4/YcYO1UJY3Pmu9sJfsjhPUCaQrP4lVnqMfgx9YV5rGnICtusG5x9enF5NFbVfnfJhTYtrigE47y3Pkyosb6xhb/h0K2HrDP8LlEiKgassfbIwEVwjlKb0kwNA2iY3 X-OriginatorOrg: Nvidia.com X-MS-Exchange-CrossTenant-Network-Message-Id: 6cbe9e7a-6647-474f-84b2-08db93b5bc4f 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:16.3858 (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: lgnlGrO0FrOT2P5k6j7nR5vB/sh14ozFAgxD6wVH5neE9VDkCQgpeemRm/OA1ly0 X-MS-Exchange-Transport-CrossTenantHeadersStamped: MN0PR12MB5809 Precedence: bulk List-ID: X-Mailing-List: linux-arm-msm@vger.kernel.org Except for dart every driver returns 0 or IDENTITY from def_domain_type(). The drivers that return IDENTITY have some kind of good reason, typically that quirky hardware really can't support anything other than IDENTITY. Arrange things so that if the driver says it needs IDENTITY then iommu_get_default_domain_type() either fails or returns IDENTITY. It will never reject the driver's override to IDENTITY. The only real functional difference is that the PCI untrusted flag is now ignored for quirky HW instead of overriding the IOMMU driver. This makes the next patch cleaner that wants to force IDENTITY always for ARM_IOMMU because there is no support for DMA. Tested-by: Steven Price Tested-by: Marek Szyprowski Tested-by: Nicolin Chen Reviewed-by: Lu Baolu Signed-off-by: Jason Gunthorpe --- drivers/iommu/iommu.c | 66 +++++++++++++++++++++---------------------- 1 file changed, 33 insertions(+), 33 deletions(-) diff --git a/drivers/iommu/iommu.c b/drivers/iommu/iommu.c index c64365169b678d..53174179102d17 100644 --- a/drivers/iommu/iommu.c +++ b/drivers/iommu/iommu.c @@ -1669,19 +1669,6 @@ struct iommu_group *fsl_mc_device_group(struct device *dev) } EXPORT_SYMBOL_GPL(fsl_mc_device_group); -static int iommu_get_def_domain_type(struct device *dev) -{ - const struct iommu_ops *ops = dev_iommu_ops(dev); - - if (dev_is_pci(dev) && to_pci_dev(dev)->untrusted) - return IOMMU_DOMAIN_DMA; - - if (ops->def_domain_type) - return ops->def_domain_type(dev); - - return 0; -} - static struct iommu_domain * __iommu_group_alloc_default_domain(const struct bus_type *bus, struct iommu_group *group, int req_type) @@ -1775,36 +1762,49 @@ static int iommu_bus_notifier(struct notifier_block *nb, static int iommu_get_default_domain_type(struct iommu_group *group, int target_type) { + const struct iommu_ops *ops = dev_iommu_ops( + list_first_entry(&group->devices, struct group_device, list) + ->dev); int best_type = target_type; struct group_device *gdev; struct device *last_dev; + int type; lockdep_assert_held(&group->mutex); - for_each_group_device(group, gdev) { - unsigned int type = iommu_get_def_domain_type(gdev->dev); - - if (best_type && type && best_type != type) { - if (target_type) { - dev_err_ratelimited( - gdev->dev, - "Device cannot be in %s domain\n", - iommu_domain_type_str(target_type)); - return -1; - } - - dev_warn( - gdev->dev, - "Device needs domain type %s, but device %s in the same iommu group requires type %s - using default\n", - iommu_domain_type_str(type), dev_name(last_dev), - iommu_domain_type_str(best_type)); - return 0; + type = best_type; + if (ops->def_domain_type) { + type = ops->def_domain_type(gdev->dev); + if (best_type && type && best_type != type) + goto err; } - if (!best_type) - best_type = type; + + if (dev_is_pci(gdev->dev) && to_pci_dev(gdev->dev)->untrusted) { + type = IOMMU_DOMAIN_DMA; + if (best_type && type && best_type != type) + goto err; + } + best_type = type; last_dev = gdev->dev; } return best_type; + +err: + if (target_type) { + dev_err_ratelimited( + gdev->dev, + "Device cannot be in %s domain - it is forcing %s\n", + iommu_domain_type_str(target_type), + iommu_domain_type_str(type)); + return -1; + } + + dev_warn( + gdev->dev, + "Device needs domain type %s, but device %s in the same iommu group requires type %s - using default\n", + iommu_domain_type_str(type), dev_name(last_dev), + iommu_domain_type_str(best_type)); + return 0; } static void iommu_group_do_probe_finalize(struct device *dev) From patchwork Thu Aug 3 00:07:57 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Jason Gunthorpe X-Patchwork-Id: 709692 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 vger.kernel.org (vger.kernel.org [23.128.96.18]) by smtp.lore.kernel.org (Postfix) with ESMTP id 9E629C04FE1 for ; Thu, 3 Aug 2023 00:30:45 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S229624AbjHCAan (ORCPT ); Wed, 2 Aug 2023 20:30:43 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:36450 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S229832AbjHCAam (ORCPT ); Wed, 2 Aug 2023 20:30:42 -0400 Received: from NAM02-SN1-obe.outbound.protection.outlook.com (mail-sn1nam02on2046.outbound.protection.outlook.com [40.107.96.46]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 633F713D; Wed, 2 Aug 2023 17:30:41 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=none; b=iXS1EGv5y8t6SYjHNxUs/8B6U3N172RH0FDqffgXQreP7nzbNwK7A/SI9HKeDzpCfP7D7xgsvak4cYsTI15sGSP8h6sxBXNtK2LIHz/QKcfjAFUgLP2p8aIV/XwnELd9fSYhMpAvfvSoYBfSyecKzakeYxSizR41r/TUXvjOqS2seIdNCy8RjMI1GcV6i9eH1t8sfZA80DayW9HfKlbCf//RM5x5YPaxLWSPx2r8XHtSXQAVfuUlUiUlqhH1pULkGynG1gan2n2vfPJsks3xdxmS8FZcwdpc2S9fgDIv6DvGWr61b1YgOtlZDheymOC+Zai29b013UNogqzBVCS2TA== 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=tuioqqLJ9nwTxiQOZ8nAoXdBA08XbZNNbPO6KQsUrqM=; b=QWlAVH940jarLjjhXOd3ThQAYZcJsaVIx+2S0Gsf8VQCwHPGOwl3l/6LeR16NY1zq3Gr56uhfFDbMu7BsneZF6llZPndcJTEr1603XkrFRSD78MDYQhA5nyXSRWXI58PX0wxSECelmXskE0MLpVq8uyPWfFye0ZCfStLoAzbPLi3qFt/97saEuq+V0DEKfgixfHypofri7D9NSpY57VLaERok4o7k7dUDx8phCmKpWZRr0ftKDVD/XyTthNCc78Skm2A9GM5WwGNqVbuUuj8NloYHKRfjSQqenLY7R7o5fmNCZxKT4QyudMRv3w2J8JbNWv6HwODwqsPr7kvMrtEbA== 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=tuioqqLJ9nwTxiQOZ8nAoXdBA08XbZNNbPO6KQsUrqM=; b=g0+/CMjkbB0WkpBc1Jb8tLQu/bgnMaYBQtdGVjcXhfkWOJk1Iu22MKLFTxwHfp4Lt7nFbn9K7I+t6m2bK2qXoK1rqhglELdkEbsr91aMrp1HteRem8AF5OQ8QFCtKcx8MLOVA+zsdJMNOQB1tFSfgJwWyMPMrhRgX2mPKiPKyuhv3tNUDvysH38vo70tq9uW/x/CnjY8u9t7UZM5+blGiZpbyCfF8fIBMse1gC+0j/N5ZCW4hANRJ0drWsDavAYmBLFg7ULVnNGSdWL71FtEqoymoJeR8Tq4Vs9sH33KvA8h37k2e8ZiTscVnqp8MSbQMY2DbaI7bjx5YOlnopV9sw== 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 MW4PR12MB7261.namprd12.prod.outlook.com (2603:10b6:303:229::22) 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:30:38 +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:30:37 +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 10/25] iommu/exynos: Implement an IDENTITY domain Date: Wed, 2 Aug 2023 21:07:57 -0300 Message-ID: <10-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: BL1PR13CA0105.namprd13.prod.outlook.com (2603:10b6:208:2b9::20) To LV2PR12MB5869.namprd12.prod.outlook.com (2603:10b6:408:176::16) MIME-Version: 1.0 X-MS-PublicTrafficType: Email X-MS-TrafficTypeDiagnostic: LV2PR12MB5869:EE_|MW4PR12MB7261:EE_ X-MS-Office365-Filtering-Correlation-Id: fe4e2eac-ba95-477e-3675-08db93b8d829 X-MS-Exchange-SenderADCheck: 1 X-MS-Exchange-AntiSpam-Relay: 0 X-Microsoft-Antispam: BCL:0; X-Microsoft-Antispam-Message-Info: MUqS/SigT+Lw+qA+VxMrInqdOfhZ0+DU3x9N3jt73QgswMJrEUCNTVNtB3p/ot8+dPoggF/qG3+h2k7cUXfwkUEHK9Gfwg7B2hEkRvc+g2KjLrQm1H3UU8Xx6TPXT3M83KCN3uMlUpkRFf6i4EovXdtjEsWOq3G3MLUgMgtrgTRtaAgWZ6Z6TZYiFa/DLH3Y+xMcd/Cxy5tJp6EpysQ8hoC/jc3SdQCbn0bUWOadU27oS+JtzUdDJxH5EzJA3DtmpQBabC2ns4MC8E1tG5/7QqpHL+la8b0sy2ePkWIkww4z6Hoq1CYMA8D7ZAyoTYKV7qJFgNPwy/lTJhqc/xafBKmWukJtf0aL3FRK9n1HUiRHupyIh0sJXDssHSH385yqhHirX45CXeWYSaxBDqGzd67ckQ9WIHB7qxPoHepwB09ns6zFsw+gCI2yqIemnWUcH2Gqc+YmW1DoL/XRu8I4jhZBiHocQse9tzlZdjtdsw7LuEncR0PeiIl1nb1i3/+6lI7DuFf/htC2R0i+C4UVZFnPnwxFH9UgPFjIoe1fhoLVSMpHLEBaqvaSyhzd0VdOsadSQWXe8ixIznUJeTZSz6QzLpMvnL1AEV+wpQufVF8= 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)(346002)(39860400002)(396003)(376002)(366004)(136003)(451199021)(5660300002)(2616005)(36756003)(38100700002)(921005)(2906002)(316002)(26005)(83380400001)(186003)(7406005)(6506007)(8676002)(8936002)(6666004)(7416002)(54906003)(6512007)(66476007)(6486002)(478600001)(41300700001)(86362001)(66556008)(110136005)(4326008)(66946007)(107886003); DIR:OUT; SFP:1101; X-MS-Exchange-AntiSpam-MessageData-ChunkCount: 1 X-MS-Exchange-AntiSpam-MessageData-0: 3SU21KRJgYLd5Qz2aSpGPO0VMxmPq19wvehnmoOQLZsWgdqalNgsj5PMLexSyxBn9nCHygqNXivnp2/xMMkyktEeqVcGJZApcA7YjE0r0y7ikANVRFs7h8pNnXByQbIIdSMoJ8kjHmh10Geoc7KesPrYGoOhafeW76r+x72P9PY/+cWhnTQ7kU4lnFofMgYoUc2+Pva0Y12jUYpEPLWDl3JAwK4vtHnKXoi8gfAu4Cf4yVo9ar3vsftpS0UQHEnLpciLo6I4mmNmniWJePhk5oBay3+ixK8YTV5DOg09FXprKqQMjWqBAzw1TZjqI4iBnSp4yqJgcegiG0XCPrYbFVgRmMg2sf5QkOSCOeJ5OmANZ15YpsSIjNiAtRa4EGC0u2Hd//gQrvRLgRRhvsvHu4BDNlFDgY07oP0CxD+OcsnIXdH4vHqR+HSaWLN5zvAgTIH8wTCuGul4Dp/2AdmPHlCQFa58yeQyZWW7OwAS0Kx9R1VfbCSXIeF1T5PDvn4cyF9DvbQAXH2xTKh/s0Malw08ku+2kmnFmkIqS8nUkZnvQZT3bxJrvaxHZm7gT2HdTOfnBxo/9tdwH4/+ODGNTft/1mgh6FpwL7+q07gmkMMn16LfVGM73tX2wGH+482jVi8esw8kz8xunLbeNQgMWU9ebov87e4p1OWMvXyYxsVVxqK6AWbDjxh7ZLszX+Cv85mqutGcrsV91kV9X2JRbm4A5R0k7igbVdUe6QGuKWPmusih11w7J/PHtfDbJvL2uXgmd9nGHlE9SwLnP6A8Z3Sjk6XqdiuErmCYieQ50itxap3kwtwlyrF6+LNbNsVbSqRcaKZ9TNjZZNTIK+8akjmbhMSIIKIBJBWXDQhgb32d0eOK1O+ayw1F6tDEsGv3vacH7A0MBd9nJDwefRemXbzh8HuLVnRJHnkzsageLt2j8UxSnagcapfs4qguOP07o9LVoVeuhdHoD6VxiJr4L/VL+aMx/N8RLPVL69d2tFvRll/gN7skDdKi7YsxV8gHoERqnJaquUaQTLBHK8CFxboc/6cooh6Bj1S7UC+jp0A8XkNCrXmto09YPFELh3sJJJLyikISG5ssvRV10B2CnV9UsBdaaFGakd0+q68WiazWGhysG1m8KEBkdvB0Y9m/adFlf7jTryFmTdG9r4bl9IGF7dgMAOGcb/ui1fBwOxVRc4hXwD9GyfQDbmbM6Ff5YE4I/v48s3LIc1CLbF3hBw3Iez9k646ULPqUkAZkoASTSUeNIpmpIuOceWeCFQCVVgUAeh3ij9U66eTTVOH7tl7GMYjUHkz00cpCrIoLht2CE/kbLyO16UDlcCrtL6/HQH2bQZAqx3GlyOXcJhLzun6Mzh6HWeuFOk6dRoZQ8IJ5I7v2h0LWQc1tuUM41OVzxOot4AVsEdazjNRxZ+LeCubj8+J1CnPehsXL/KBgFZV05v4wInxupfJLGZaLnTXAzmOlCyo2vV4E++F3HMBjh11DkNGtJppK86eNMoEiWtPbQ9cF9VtY/zOCXa+6s9nzqHfaBcx8nI41jMd18I9R/Pj6r1xFGSAxGm/4VvBYt79943ElYsBTQA7be5oQSNbe X-OriginatorOrg: Nvidia.com X-MS-Exchange-CrossTenant-Network-Message-Id: fe4e2eac-ba95-477e-3675-08db93b8d829 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:30:31.4370 (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: QaeELlwN5/gdlODTRf6qSAv4wC5aJkyKljfzTVP1NSPLkHrWU4tbh8waSM/ogcMd X-MS-Exchange-Transport-CrossTenantHeadersStamped: MW4PR12MB7261 Precedence: bulk List-ID: X-Mailing-List: linux-arm-msm@vger.kernel.org What exynos calls exynos_iommu_detach_device is actually putting the iommu into identity mode. Move to the new core support for ARM_DMA_USE_IOMMU by defining ops->identity_domain. Tested-by: Marek Szyprowski Acked-by: Marek Szyprowski Signed-off-by: Jason Gunthorpe --- drivers/iommu/exynos-iommu.c | 66 +++++++++++++++++------------------- 1 file changed, 32 insertions(+), 34 deletions(-) diff --git a/drivers/iommu/exynos-iommu.c b/drivers/iommu/exynos-iommu.c index c275fe71c4db32..5e12b85dfe8705 100644 --- a/drivers/iommu/exynos-iommu.c +++ b/drivers/iommu/exynos-iommu.c @@ -24,6 +24,7 @@ typedef u32 sysmmu_iova_t; typedef u32 sysmmu_pte_t; +static struct iommu_domain exynos_identity_domain; /* We do not consider super section mapping (16MB) */ #define SECT_ORDER 20 @@ -829,7 +830,7 @@ static int __maybe_unused exynos_sysmmu_suspend(struct device *dev) struct exynos_iommu_owner *owner = dev_iommu_priv_get(master); mutex_lock(&owner->rpm_lock); - if (data->domain) { + if (&data->domain->domain != &exynos_identity_domain) { dev_dbg(data->sysmmu, "saving state\n"); __sysmmu_disable(data); } @@ -847,7 +848,7 @@ static int __maybe_unused exynos_sysmmu_resume(struct device *dev) struct exynos_iommu_owner *owner = dev_iommu_priv_get(master); mutex_lock(&owner->rpm_lock); - if (data->domain) { + if (&data->domain->domain != &exynos_identity_domain) { dev_dbg(data->sysmmu, "restoring state\n"); __sysmmu_enable(data); } @@ -980,17 +981,20 @@ static void exynos_iommu_domain_free(struct iommu_domain *iommu_domain) kfree(domain); } -static void exynos_iommu_detach_device(struct iommu_domain *iommu_domain, - struct device *dev) +static int exynos_iommu_identity_attach(struct iommu_domain *identity_domain, + struct device *dev) { - struct exynos_iommu_domain *domain = to_exynos_domain(iommu_domain); struct exynos_iommu_owner *owner = dev_iommu_priv_get(dev); - phys_addr_t pagetable = virt_to_phys(domain->pgtable); + struct exynos_iommu_domain *domain; + phys_addr_t pagetable; struct sysmmu_drvdata *data, *next; unsigned long flags; - if (!has_sysmmu(dev) || owner->domain != iommu_domain) - return; + if (owner->domain == identity_domain) + return 0; + + domain = to_exynos_domain(owner->domain); + pagetable = virt_to_phys(domain->pgtable); mutex_lock(&owner->rpm_lock); @@ -1009,15 +1013,25 @@ static void exynos_iommu_detach_device(struct iommu_domain *iommu_domain, list_del_init(&data->domain_node); spin_unlock(&data->lock); } - owner->domain = NULL; + owner->domain = identity_domain; spin_unlock_irqrestore(&domain->lock, flags); mutex_unlock(&owner->rpm_lock); - dev_dbg(dev, "%s: Detached IOMMU with pgtable %pa\n", __func__, - &pagetable); + dev_dbg(dev, "%s: Restored IOMMU to IDENTITY from pgtable %pa\n", + __func__, &pagetable); + return 0; } +static struct iommu_domain_ops exynos_identity_ops = { + .attach_dev = exynos_iommu_identity_attach, +}; + +static struct iommu_domain exynos_identity_domain = { + .type = IOMMU_DOMAIN_IDENTITY, + .ops = &exynos_identity_ops, +}; + static int exynos_iommu_attach_device(struct iommu_domain *iommu_domain, struct device *dev) { @@ -1026,12 +1040,11 @@ static int exynos_iommu_attach_device(struct iommu_domain *iommu_domain, struct sysmmu_drvdata *data; phys_addr_t pagetable = virt_to_phys(domain->pgtable); unsigned long flags; + int err; - if (!has_sysmmu(dev)) - return -ENODEV; - - if (owner->domain) - exynos_iommu_detach_device(owner->domain, dev); + err = exynos_iommu_identity_attach(&exynos_identity_domain, dev); + if (err) + return err; mutex_lock(&owner->rpm_lock); @@ -1407,26 +1420,12 @@ static struct iommu_device *exynos_iommu_probe_device(struct device *dev) return &data->iommu; } -static void exynos_iommu_set_platform_dma(struct device *dev) -{ - struct exynos_iommu_owner *owner = dev_iommu_priv_get(dev); - - if (owner->domain) { - struct iommu_group *group = iommu_group_get(dev); - - if (group) { - exynos_iommu_detach_device(owner->domain, dev); - iommu_group_put(group); - } - } -} - static void exynos_iommu_release_device(struct device *dev) { struct exynos_iommu_owner *owner = dev_iommu_priv_get(dev); struct sysmmu_drvdata *data; - exynos_iommu_set_platform_dma(dev); + WARN_ON(exynos_iommu_identity_attach(&exynos_identity_domain, dev)); list_for_each_entry(data, &owner->controllers, owner_node) device_link_del(data->link); @@ -1457,6 +1456,7 @@ static int exynos_iommu_of_xlate(struct device *dev, INIT_LIST_HEAD(&owner->controllers); mutex_init(&owner->rpm_lock); + owner->domain = &exynos_identity_domain; dev_iommu_priv_set(dev, owner); } @@ -1471,11 +1471,9 @@ static int exynos_iommu_of_xlate(struct device *dev, } static const struct iommu_ops exynos_iommu_ops = { + .identity_domain = &exynos_identity_domain, .domain_alloc = exynos_iommu_domain_alloc, .device_group = generic_device_group, -#ifdef CONFIG_ARM - .set_platform_dma_ops = exynos_iommu_set_platform_dma, -#endif .probe_device = exynos_iommu_probe_device, .release_device = exynos_iommu_release_device, .pgsize_bitmap = SECT_SIZE | LPAGE_SIZE | SPAGE_SIZE, From patchwork Thu Aug 3 00:07:58 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Jason Gunthorpe X-Patchwork-Id: 709704 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 vger.kernel.org (vger.kernel.org [23.128.96.18]) by smtp.lore.kernel.org (Postfix) with ESMTP id E5595C05052 for ; Thu, 3 Aug 2023 00:09:23 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S231634AbjHCAJW (ORCPT ); Wed, 2 Aug 2023 20:09:22 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:53632 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S232803AbjHCAJH (ORCPT ); Wed, 2 Aug 2023 20:09:07 -0400 Received: from NAM10-DM6-obe.outbound.protection.outlook.com (mail-dm6nam10on2065.outbound.protection.outlook.com [40.107.93.65]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id EC83D3C3A; Wed, 2 Aug 2023 17:08:43 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=none; b=ZZqDF+r936W3tHqMRXyqiIQghwocYzqVrj35zmeGIUBWSqkDXGDFYi8V6TKtgC9SyTw9UWfABvwsPDCpbPiitZoehvD01khnhIsuNy5gqQ6N9qiK7GD6KukFXkaWbYHl38EQO0LDFW4Ij/pbB9rADRisMVNOxMKgfxfeOFmlm2U6FC54/hU0xwXkjIYajnx+m5NYz0Xt/c+lb7w1cB7VZf5TplhS0kJcoV+rClIiKjnXpq3+fSbIAL9yE5nOy+tPCUciziKIWVDhcg+xe0t1VIQBpA+v/ejXCFuiUc3VvUvB0ACHrBDEqZL8/UJX5SfoQjuZIY0zf5n4iGI830USQQ== 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=MJsrCPZt05R68MxKoBpco2NR/z5JZDCOUNeUC4SYSu0=; b=BcmDUu2xI3qz04yvwBNZLVe+UHOGVJmH6nHyW8wkJxFROtJ+bGkHsY1e6fU1+LKZ2C+gGh1gVRx23HDrg3fcurU0ZqicitxqxgjH1NAZG1JgQwRPEYJCC4qNCjVHhhnLf6vQWPz7giQFAdQJ8KHICZc74qJgAN5W/MhuArDuM7RtHa+F1dDqhWZJC9yGunYNVVxL7kcmsNKUYFzZyfzXVAgc4LuCPbUl1aiMYhmKRPGUNUrRs04+zkw0e6g5tNHPKMpz5LYpDHDmmEH5Al8DahD85jqX5iRVxeDZmgUcS5SXHfU66s3H79ctzekEG3MM5YLlD4rm74aR+MdKI4/xSQ== 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=MJsrCPZt05R68MxKoBpco2NR/z5JZDCOUNeUC4SYSu0=; b=HyYtDj3T6ksLLCbv+tEPQSLh1ux268Fcw8Lf6j18GbMs4OVK4VnhUO+L0903oShBq/PGnSkmD58wxxfpgXgaAX4thNUIutLUuJW/kBgWVh5yNIStLuk0P+CK5wGt26iNBPxV3EAFfE9o0Mch96cM3bfupAOSFjUl0EspJ9aHPuYU+2DpDrfYR23nXVrfjRnWyctt28BGtJt+obdFJmY9Q7r5n1FMn3jSKbMIXgC7yD/bwmRP/2OVBEKRDm8cOWMBlmP8ep1pBz1FzPhslLXxm6rzXSbVximl/+4+ULwu+QD5SbIs/W6oF0hoifpQPR/memrWVzrwMU/OJNQFMicgTg== 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:14 +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:14 +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 11/25] iommu/tegra-smmu: Implement an IDENTITY domain Date: Wed, 2 Aug 2023 21:07:58 -0300 Message-ID: <11-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: MN2PR16CA0039.namprd16.prod.outlook.com (2603:10b6:208:234::8) 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: c3ff1e60-18b6-4324-5749-08db93b5bacd X-MS-Exchange-SenderADCheck: 1 X-MS-Exchange-AntiSpam-Relay: 0 X-Microsoft-Antispam: BCL:0; X-Microsoft-Antispam-Message-Info: km481S6zUt3BizvCPrNjPB7bsM2KEdiLqqUElAIjmmSXxs1wcOfqp19k7aRlFRsFTIrb8iTx2DCNPhgObc1omBWXaxvl7N7CWBHxogmaKnW20iWsj+TFvlcpySd38QGhSA5PHeXtitBM/ZdkSrbAIf86u+9EjIq9c9CiW5+z4SrAqcy4VET9i/hZAp2jdi2S//jHK06+ExU0/cpBXbG0YZrlJbP01S0BwPUZ20q2V0a80a7Vw1MEpU7dHaxTMgtXWwMgOhSBoIe7HOy74qBcucXKep0Xuuvp25CI+P1ZrhqhMFf9Xyqh/LxSIAcQaLrJ4/0KSDeVjYBSx4vubMVgLmVFoo4HphlDBijwdTeYWzFOqfWQMq4Pna10kM0LjKGU2I7lTk6ZTdz+ZXn0RlV98HpZBXyUyUZAl+hQeUdVy+XddUabkRY2lJi+AIY010J1T2sl1kaoV/dGQFuu23+c80i9CpBY5vPi4e2lohHRzyhs4teyyBGhFW8lreJbAllb7wGgO2hHlP7FAF01AMNBHo7pPJV+E60EMsUulVXvX7Rcd9mnzO9FstMXMK4cjaoAIcZTxhDQjb2uQO6TOzNQEV4A041jqzhAq16SYf7LXZQ= 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: VJp5qCnymMI+GeUB1bykehnTkbZPXkqMRQpFCQ8N0UEm5Xvza73KjA12xbr5Lce/HMgHCipzF3c5tZy99EN1g2RAYRLiGegK6UDwcHNHo/2lXzfUyVa7JkqKvC8XqpxUnj/Ey9JxHeWuDDXiAQN88V+f8u4ogJ6YCdhL3D+vtFzRejwJ6fXgBZ0tnIH0Nq2jUNTWxXBrP4kbnXCW11F0LCYcbuI0bFo+jM6Btf9ppnerGSlRlICXdaiOMRESroZBhlhdQtg6t0nhC2asl4mPRWCQa/IuUjOZHo3MiHS6XMS8fewCZtLQLfPp3kaSGczw+hGHBbdMKZcVDGX/86rmM8/3m69T8ovXnplstb1K9FG13mWUmrSU8GAle7M7lVWrb/FejO0bZKhBL5sizX6ZeSJfpCGV6T3KeAdeIRKtsymJnvKVm+jqMyfog0/tFPu6VbIM2ox2pmSGgki8ilC6Sfia7X13cb23uE/blsUTPOTE5JTosGwFYuOyudqYsd8CX9nqU2DKNfQLEaodcu1WQoyX3DR/3jLITCQJsn9Kff/ZCgmWs+KIz+ZaaMtTdj6/NsEsBaCSFkcNcb0udzeKnIAaj4wWFdhJdEaBPWY9UGH9Mffp6tn7eCwJYgJ12QSXi3Q09WTYv32O5Dt6InUT3lPWvlS8zW/b0V9wtKtAbfhMzPZBMzwxZis4PZUeWv235D1dNJ8WA1AXJ+rBSTLDySHSvCXrdd2qDuH6lnW/SFWryJvDlBmUW6rZc0dL2efBpUQWrQY0ROD8kJZwZgtOBhJLRd+AokqYeuFLx17R5LRZH3bDhwyuY4ooa0dNYMxP0GpAsIwSLEEXsBCWDisrTw3WRdGoi5Dy1rKsrnv7MnX55v5LYdwSpAvkEo39EBamwzRALN7Aip9sOAuvtyIjzWINAzPVrf7r81yM6qxI0AIsvgdIR6XqrYTalejb/2bNThid/TllpUisoPjNVNWLamikGejjYaVXpRN4cQXws8Q1aHqblsvVY447DFaAaJI2mtmtIbXphIFS/rvU0Oe5wBr6v+5+iQrXh/sFXKhn7x1b0Lfaro7Q5TyzzhbpGEeK6hNk6e01SWI/wy+YUvh2/MKDTzP0egGe/YwCe8xQqV6mePVb1ruX6WKF2iasxrcGCEeFwGNRl5JjysfYRNo03NMfD+I/s2jvq6Py2i1aDKt0nhH3B3EsmdN0p1ckurtM6dgPi9IIOyTY/tsoI6oTE6QyYLVob04MOxU4NgOHc9F29+J+vcDSdSM1YB87ZeCu6s87wF5rp+nom2cpvbWu8V6XtZXJUJ1Z8u/8B1uGYuC1WiXxntNRTeHtAdv721LnisCPiN0zkL4SA6nW5iI1ZBJKdzXpzR9ltSo4dN/ocdweUzfZjHuqrrKEoxTYfICUVKnmkK1FCsk4isAjz5Uevy2EIf8tKXcNVrDd+7jZT1skzx34gBf1Hee1xXPCfY4Q1RzJAfemG9wfRBD1oULlxJtMjrao1Id35t8Ztztc4bV/ETyUrKK9774Is5360tkJ/eW/uwBIVHCWpLsW6ATdraAeQsGDUyLnBnr67e5DhxaV+x7QYJHxJiJ+YR3PjK1B X-OriginatorOrg: Nvidia.com X-MS-Exchange-CrossTenant-Network-Message-Id: c3ff1e60-18b6-4324-5749-08db93b5bacd 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:13.8849 (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: 8lmFMrGjQKXSSTGK30q+jKWxCyvAPb7LRQthtTxFfdZgyNa2zmhv3cTQkgQyawjK X-MS-Exchange-Transport-CrossTenantHeadersStamped: MN0PR12MB5809 Precedence: bulk List-ID: X-Mailing-List: linux-arm-msm@vger.kernel.org What tegra-smmu does during tegra_smmu_set_platform_dma() is actually putting the iommu into identity mode. Move to the new core support for ARM_DMA_USE_IOMMU by defining ops->identity_domain. Signed-off-by: Jason Gunthorpe Reviewed-by: Lu Baolu --- drivers/iommu/tegra-smmu.c | 37 ++++++++++++++++++++++++++++++++----- 1 file changed, 32 insertions(+), 5 deletions(-) diff --git a/drivers/iommu/tegra-smmu.c b/drivers/iommu/tegra-smmu.c index 1cbf063ccf147a..f63f1d4f0bd10f 100644 --- a/drivers/iommu/tegra-smmu.c +++ b/drivers/iommu/tegra-smmu.c @@ -511,23 +511,39 @@ static int tegra_smmu_attach_dev(struct iommu_domain *domain, return err; } -static void tegra_smmu_set_platform_dma(struct device *dev) +static int tegra_smmu_identity_attach(struct iommu_domain *identity_domain, + struct device *dev) { struct iommu_domain *domain = iommu_get_domain_for_dev(dev); struct iommu_fwspec *fwspec = dev_iommu_fwspec_get(dev); - struct tegra_smmu_as *as = to_smmu_as(domain); - struct tegra_smmu *smmu = as->smmu; + struct tegra_smmu_as *as; + struct tegra_smmu *smmu; unsigned int index; if (!fwspec) - return; + return -ENODEV; + if (domain == identity_domain || !domain) + return 0; + + as = to_smmu_as(domain); + smmu = as->smmu; for (index = 0; index < fwspec->num_ids; index++) { tegra_smmu_disable(smmu, fwspec->ids[index], as->id); tegra_smmu_as_unprepare(smmu, as); } + return 0; } +static struct iommu_domain_ops tegra_smmu_identity_ops = { + .attach_dev = tegra_smmu_identity_attach, +}; + +static struct iommu_domain tegra_smmu_identity_domain = { + .type = IOMMU_DOMAIN_IDENTITY, + .ops = &tegra_smmu_identity_ops, +}; + static void tegra_smmu_set_pde(struct tegra_smmu_as *as, unsigned long iova, u32 value) { @@ -962,11 +978,22 @@ static int tegra_smmu_of_xlate(struct device *dev, return iommu_fwspec_add_ids(dev, &id, 1); } +static int tegra_smmu_def_domain_type(struct device *dev) +{ + /* + * FIXME: For now we want to run all translation in IDENTITY mode, due + * to some device quirks. Better would be to just quirk the troubled + * devices. + */ + return IOMMU_DOMAIN_IDENTITY; +} + static const struct iommu_ops tegra_smmu_ops = { + .identity_domain = &tegra_smmu_identity_domain, + .def_domain_type = &tegra_smmu_def_domain_type, .domain_alloc = tegra_smmu_domain_alloc, .probe_device = tegra_smmu_probe_device, .device_group = tegra_smmu_device_group, - .set_platform_dma_ops = tegra_smmu_set_platform_dma, .of_xlate = tegra_smmu_of_xlate, .pgsize_bitmap = SZ_4K, .default_domain_ops = &(const struct iommu_domain_ops) { 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: 709696 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 vger.kernel.org (vger.kernel.org [23.128.96.18]) by smtp.lore.kernel.org (Postfix) with ESMTP id 632BFC07E8D for ; Thu, 3 Aug 2023 00:10:09 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S230523AbjHCAKH (ORCPT ); Wed, 2 Aug 2023 20:10:07 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:55540 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S229889AbjHCAJv (ORCPT ); Wed, 2 Aug 2023 20:09:51 -0400 Received: from NAM10-DM6-obe.outbound.protection.outlook.com (mail-dm6nam10on20601.outbound.protection.outlook.com [IPv6:2a01:111:f400:7e88::601]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id A557C3A9D; Wed, 2 Aug 2023 17:09:33 -0700 (PDT) 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+e0V2sYBWqQsO40RKrKSJx4xnbbGTQ+ze55TAR0OCLyAuUvfmJXvVrfIzqvzL5YZxWiTAHGsW1w4YcE1esfOb1sN+AKrcZlRsiS2Nq1jHwL4fUKAO20fDIY2flGDeeb17wAvP5CCIkm28ABjJRAw3RoYWJRgjjf/O4OLd+vZZBsGOmS2T75nBHUpY0/BvQq16p570chwmh5bXHTjKCbA/TxuP3O5+pMlr0AK5GX27xnyaLJpJWDz1L33l5ezEi8k+alDba24zONRMBqUkkKq6GjaJEEDDTohoHxpItWDG8qtW/X6O8j8FpfHZu+mQlO6XRgq+9YwBjQlL/IrBOjsbTZZLVGS0RnzhxUAQs+H/OyM+apH7A/ny4pJAf6ykT+e5SYcenmHfHqfh/xi9x70Ow2BmKviHVYHP+tl+fSJq6L9DxPHpDBwPUdDv3SzJmw32QR05j/fGR0Avt/wmVqIjbkwlp5ew8hJf6V8f1+8o2IVH6IPL9YPNrx+a9DawdscxGxJk3GEJ/RuXsJENN3PxMY/1gSnCKinL8vnSyz5hgOVFmvP77V7ZwVWr+t5K2bmnA9Tuujth+bFh8RgbElvOIXJGyqdNcaPlZAs+Q0gPqQrkIZngwH6BeA9eV2eyqjPnHCZENal8Es+zHjr8HB5YlhL60D1qZrfxk3tJbJFzvoXBNNwuMwjEZ7Y3yBcP6HizIxQOKydxBYGGdRnMSUuycYTubjDqUq/QjQFWm9j0k5AtQ2jUOxn5iOSTCOQ3JBvNcBDIVyMdO5RK89rb50c5wNF2QG0Ml6Tos8UtcPKWQIN3mfdPJyKYs+uKlytSu3VdRsClpwUPUBLbm3tFuRptxhYBdroGGP2U29C81bKToNjwL+BsBdAt/KkiwiIU92DBlssDJszLEKGUWqTDLvYugW3x7qWXr+3sKpijwh92M2WHMcto0YCbJ9VJxriNQNvww1dTkGQs1nOMwtn9gcmWBOwlmFvHjKT58Ue8/lD9LxOaWRs4mMhbw+tPwzQRVRXKk79Opo4v6oiHXtpWygHBksJnAj8CXNK4KtuJ08CclbPEjr80RpH57Dst3j+wfertavXemxFA8p66ZFRtlw1xLAf21sMKZa+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 Precedence: bulk List-ID: X-Mailing-List: linux-arm-msm@vger.kernel.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, From patchwork Thu Aug 3 00:08:00 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Jason Gunthorpe X-Patchwork-Id: 709700 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 vger.kernel.org (vger.kernel.org [23.128.96.18]) by smtp.lore.kernel.org (Postfix) with ESMTP id 1E578C41513 for ; Thu, 3 Aug 2023 00:10:01 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S233329AbjHCAJ7 (ORCPT ); Wed, 2 Aug 2023 20:09:59 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:55784 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S233270AbjHCAJ2 (ORCPT ); Wed, 2 Aug 2023 20:09:28 -0400 Received: from NAM12-MW2-obe.outbound.protection.outlook.com (mail-mw2nam12on2046.outbound.protection.outlook.com [40.107.244.46]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 2CB2E1FF3; Wed, 2 Aug 2023 17:09:15 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=none; b=mOpPibG6jHK6uaaUhFLjuz3i1EIUhIrzXLTld6UL70Op1ZQY3AyGBagLyU7bXHUlI3VwWjmCSKAEq5ZyYonJPJEPmqig5J5UtHD6EqeYA5zd4pOgKqFKS7GdcjZfXoEU4XY/tipsq82BrXoWNZfNEiqYsh9eodOGLy4AvwEsGerap4B7LLHHDJt8lBzlCOlkTeu39K1Skm2eRzrJ3wm8vPv5g1pgJQVj0Av2luCe01ySLvFv1qAt7KSiVcaCDBuMzKgJHbCh3ZhqkouPQZaacShfVXNTUCQvKpia9BnpyIKOsM3a4tBtNn2unjisqh06HLol2mzP/5UaaJOeOmtqIg== 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=P0slDXFYbJM//zyjPKYXqKC9rH+RXKJstRFeiCBm71E=; b=SDIFxY7fNv//SckNaYdDj2V91MpcUDz3LgQSw310nePWyZADnXD5+8UAKXlrQClxa9UkGw6N60rlXpbzK6sBYO9bTrboUJLggGGS3gFjNxa/hT00qsJiNny1M2j2HWikfUYRqYW3gAou9soxZHw7u0gtiDmdzWF+1wnwx7a+2b1XdqR5wSGOURhotzG4iALsLo2Xwwi7Lnq39B4Xapo9HQE2N/x0jIUBMqxzgISjcdUR6WnXt+0oeSpPIdnYQSJn4sdj24Ho0popRkxvU41g+aGrpRGa7de/SRPjCXaB1DoNJTOkIE8M1t9IBmrypwFxtA+IDO/QrAQRJzIbU4ixbA== 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=P0slDXFYbJM//zyjPKYXqKC9rH+RXKJstRFeiCBm71E=; b=Zhz5pgVr25D2Qcsmu7vorP5Dr/2/cf1KbtgedaxhKRXPKEuzCyoWEpSEgWm+T0z9K0nrPaIHC5U4GhGFVTBk9TKf6qvs6EktdDvvrhJE6sObjx09mx1nLB5vasPF92qWrS7fq4IHbIORJB80it73DXMyn7dR4fQ10eITpwg+6U7M98kw5MzywpLLGg/B4VgdnfYMVDcIy4/v2wYCwe3cFE7Da7DyY1IawXJEz7YbNs9kT+zSBMkqoA3DaOpZ1Okm6VRxlwhLO0Ov+mRaKXM1/f3r8+Nd0tXn9e8xMBwC/c2pcaRiHRD4c6Y3CRZUlXV9OWNiEoGHAaB/tP/skoz1hg== 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 DM4PR12MB6085.namprd12.prod.outlook.com (2603:10b6:8:b3::16) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.6631.47; Thu, 3 Aug 2023 00:08:25 +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:25 +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 13/25] iommu/omap: Implement an IDENTITY domain Date: Wed, 2 Aug 2023 21:08:00 -0300 Message-ID: <13-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: MN2PR15CA0038.namprd15.prod.outlook.com (2603:10b6:208:237::7) To LV2PR12MB5869.namprd12.prod.outlook.com (2603:10b6:408:176::16) MIME-Version: 1.0 X-MS-PublicTrafficType: Email X-MS-TrafficTypeDiagnostic: LV2PR12MB5869:EE_|DM4PR12MB6085:EE_ X-MS-Office365-Filtering-Correlation-Id: 1c10c5de-d8ef-471e-28b8-08db93b5bcbd X-MS-Exchange-SenderADCheck: 1 X-MS-Exchange-AntiSpam-Relay: 0 X-Microsoft-Antispam: BCL:0; X-Microsoft-Antispam-Message-Info: 9xwzZP6XEdgGZN2wGCWXZ4982UgKxwasjQzF5OrsXmoOYDSpQNqNC4V+JHfQpUpHJDv4oIWTjqNIfj1jtCPqrtb2r8Mih7WmHuIDrO2H7zfGv40jK/ttD72UFJpgMJlktqVEDveAwJnHbygyifKhlEXad71ZULl63uuwPvoqrdytRcnkud5T2qpittx7Cz45cCpKk9ow/v5ZTqv8tO+H4U+7uNNO7uvPg8ciWHDx2qTjpyYCV+C++JKL9DfHXx8huQwm6vOu3MqDcaEeUDLDFA9ea9JcNNLRvFmw/8B/nQEk7LuxN+uXfb6iogbsfa6azYzKV7ezoUtW1pdxMsKzneKFTGmwMkCSQ9ojxvYaXu7ZCHXvV/B+2YalcltbtoCbroHa7l2aOSot4xCVFqQQ9+Gq64K5dSEEhDfn/FTq4R3M/AOtzph0Rb2mkumvWp52fCZCUIcpgfjP9Jc2VEfARo6Vcesp35GARB9tVyxBcrOSEnx0yzAYE0rOR6DLLflAzf1yFp0Zu2eY36H/Esjx96yjpyatPvyQx0qb/bfj/aCx9Z0mJ87IIuegrUjJo75kM121KL2gx8sDdx8gY48GJn+cNjQ4N9K8MU1kYYcZ5ToJJ0lHDPY+gKnMdyvrNdmJ9xoy9AKMP+vASE4eA99fbA== 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)(396003)(346002)(366004)(39860400002)(376002)(136003)(451199021)(7416002)(36756003)(86362001)(7406005)(54906003)(478600001)(110136005)(38100700002)(921005)(83380400001)(186003)(2616005)(6506007)(107886003)(26005)(41300700001)(8676002)(8936002)(6512007)(6666004)(6486002)(316002)(66476007)(66556008)(5660300002)(4326008)(2906002)(66946007); DIR:OUT; SFP:1101; X-MS-Exchange-AntiSpam-MessageData-ChunkCount: 1 X-MS-Exchange-AntiSpam-MessageData-0: Q5ZEuJ9CD7uye8c9BVPXG/fW/zrIUP9jjdZz5QJe85bLbmJ1BeRgO+hWw/WL0bVW9OlVRfWSIUHTq0Ccq9uiSmqD6rumDdUy85lZ+zTKom0WjtFXbZ2pyP0uICT2zV8310i/feZLcnZ+C67+yDg6+sfTNqSeYq1MYa9DKSJXoH4sBSjo2mWxDQxW6skEMI4JnsNpgU/FSziZEjr0dpr+wCCO7zxThCFeSgAgUK8f79sGOn5rywfqNpnp1lUdQJPLk2+91VHnZFfbnTw63QuCyOs3FZR33hwoqXiLEpTOfR1fBw2WGMA6zoqnmchFOLmbrCxjhRe7gXhlRMvERFfN2GZwsseZJS2hFxHM1Ddy0DJ3OaqGb6vjupBbiKhxBNUCn7nltHf8Mq1Palzu43/n9oQP0nATXpRm1OEd392085tnHZYxcID99Cc0XhQ3v2lgHpybF/xC+7OWz+ufr6z5m0YHWzAApuWHk/Ap6KbvibKooZ8Sd5ttMdr8TqfPx0o0sH6askM6vabxYSK8+9SS+MFEk8z9rb1mhFh5ZL8z8mrZqEQLkzXmNClltQinMXaFrsk9e5/l0UouPI0gXgHuS477g+sGHLNGzVQYKWkdHlWSUyS+mgLxFRF7sU66ID6mIMz89aZskeyEDx1jy6gSvE674GVZxE0dY7oVmmm5BfIokSWG0DI07gtYIBtBBRUAgbPtp2xIrwcuQ+/PaUvoCtbELc4ig00XZMCU8P8kZcPB2U0J5zJRBpuJZxsILTxFCiVy06T2FO/in7CJECeUjC9sBbCAubDhNe1/B3gjZzzu70y0ZnlhypgFJApo5tExyRcwRGyPLboGt0a7EY7qq4K6ONFlmllvqfj4RDDUjNGLjM7gwLjhFzJY5ZMMFytCHsV8HkGxSfD7eOcXvQZ8fw11kalaQ5esqD8K+TVpV3IecsJWKMHpO8l05scy3coUPL+TslBNiNclwVq2H4cknAzeXuuL6gGm1kgmDCjUrEdvSufDdogkgxbGUHcZesUoFp5qpar0hVrU8boIjF1OpSeIasjYo7VDsQD7MXaksgQP1+u4Ih4SRVXEI7WzutV1nsqzTwWXztVpeQt+3hZ/nO2Fow8jvbK9xWqGLZtIP93p+LuBdNOl8KHb0c+FG3P2nKpMlH/vjyUURShf5qJaun+Ou/Ucx0EagKCfqt9k3xblMzMmBlsuTjXdjYOnw6u91VkbAEai2TJlhAe69/6Shw2m5Aa8byJL3Ri1GPgt9v2vhAdQ9TF7rNkv5TviIhxPqmuhN2Q0IGvcjmnslWwSfX0LBuIm353tFfqdsdLxoAU2XEp6x2wifTAsQRi3BKkRQSSr1ss+i038kEDuE8o2ny/5fV4lwOSifpcndtIbNg8/MGLta8xTX4EcQ9tfygW9LcMSDONi3RgX+dJxL2saWWRivUMLkFM02pLq9/pyGohs0rB4WitHdA39aIWk3h3xr1xOm175n4QmAVWuBFSgM562gZxdgS/oGQz4Rx3mEuhnmb987BtATIFCOY8SzlA3aqPlH3ZpQVYtYmO/rfVQq/kuCVPeq2+gZNZl9gFmMRIP+u4kkf5OW79wPcvF85T3 X-OriginatorOrg: Nvidia.com X-MS-Exchange-CrossTenant-Network-Message-Id: 1c10c5de-d8ef-471e-28b8-08db93b5bcbd 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:17.5691 (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: GBOvA6iWgm05Y8A3/kcqla2tepa5dSNtdo8tUCqfu2DlJcSdWrynF3eFBdbEmJW5 X-MS-Exchange-Transport-CrossTenantHeadersStamped: DM4PR12MB6085 Precedence: bulk List-ID: X-Mailing-List: linux-arm-msm@vger.kernel.org What omap does during omap_iommu_set_platform_dma() is actually putting the iommu into identity mode. Move to the new core support for ARM_DMA_USE_IOMMU by defining ops->identity_domain. This driver does not support IOMMU_DOMAIN_DMA, however it cannot be compiled on ARM64 either. Most likely it is fine to support dma-iommu.c Signed-off-by: Jason Gunthorpe Reviewed-by: Lu Baolu --- drivers/iommu/omap-iommu.c | 21 ++++++++++++++++++--- 1 file changed, 18 insertions(+), 3 deletions(-) diff --git a/drivers/iommu/omap-iommu.c b/drivers/iommu/omap-iommu.c index 537e402f9bba97..34340ef15241bc 100644 --- a/drivers/iommu/omap-iommu.c +++ b/drivers/iommu/omap-iommu.c @@ -1555,16 +1555,31 @@ static void _omap_iommu_detach_dev(struct omap_iommu_domain *omap_domain, omap_domain->dev = NULL; } -static void omap_iommu_set_platform_dma(struct device *dev) +static int omap_iommu_identity_attach(struct iommu_domain *identity_domain, + struct device *dev) { struct iommu_domain *domain = iommu_get_domain_for_dev(dev); - struct omap_iommu_domain *omap_domain = to_omap_domain(domain); + struct omap_iommu_domain *omap_domain; + if (domain == identity_domain || !domain) + return 0; + + omap_domain = to_omap_domain(domain); spin_lock(&omap_domain->lock); _omap_iommu_detach_dev(omap_domain, dev); spin_unlock(&omap_domain->lock); + return 0; } +static struct iommu_domain_ops omap_iommu_identity_ops = { + .attach_dev = omap_iommu_identity_attach, +}; + +static struct iommu_domain omap_iommu_identity_domain = { + .type = IOMMU_DOMAIN_IDENTITY, + .ops = &omap_iommu_identity_ops, +}; + static struct iommu_domain *omap_iommu_domain_alloc(unsigned type) { struct omap_iommu_domain *omap_domain; @@ -1732,11 +1747,11 @@ static struct iommu_group *omap_iommu_device_group(struct device *dev) } static const struct iommu_ops omap_iommu_ops = { + .identity_domain = &omap_iommu_identity_domain, .domain_alloc = omap_iommu_domain_alloc, .probe_device = omap_iommu_probe_device, .release_device = omap_iommu_release_device, .device_group = omap_iommu_device_group, - .set_platform_dma_ops = omap_iommu_set_platform_dma, .pgsize_bitmap = OMAP_IOMMU_PGSIZES, .default_domain_ops = &(const struct iommu_domain_ops) { .attach_dev = omap_iommu_attach_dev, From patchwork Thu Aug 3 00:08:04 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Jason Gunthorpe X-Patchwork-Id: 709698 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 vger.kernel.org (vger.kernel.org [23.128.96.18]) by smtp.lore.kernel.org (Postfix) with ESMTP id 9BD09C04FE2 for ; Thu, 3 Aug 2023 00:10:04 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S233765AbjHCAKD (ORCPT ); Wed, 2 Aug 2023 20:10:03 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:56312 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S233489AbjHCAJf (ORCPT ); Wed, 2 Aug 2023 20:09:35 -0400 Received: from NAM10-DM6-obe.outbound.protection.outlook.com (mail-dm6nam10on2065.outbound.protection.outlook.com [40.107.93.65]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id D96543598; Wed, 2 Aug 2023 17:09:26 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=none; b=f8QPix9bAREJfygh16yFoe/yRuP85pyQ6mJSoaRl6vr1z/GhijtMCIr81KmWJgrr1q5rq6Njok29fCl4iS0v0aD1/G74waOiuNN5LnlQffIg3AF0unADULZPIztdb97gq6GkPIskS+BwcoOi6GEi2Sez87GeqfeipoTVGuSkKsUw7s37tlLmSvYbuA3iNe/D3wLnDGTwn8S4F2Z6iZAjeAvXsYmE3GLXd62K5jBJdFNleAf900pWpREBzSFqNI3bIY1N/Ua33Yk+6dMrLEOe75OvSpd5c13FYt50oo0FlwmGlwjp7vWxVCemO5MR4A6JpzaHSTF8R+HRBeC7LPvf9g== 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=xHnIih7z1NsYVt0Tt2cxqsqWFhB4lKuFjuoGFmx4KEU=; b=Vheo70njVrparIqjmPSP1h6U1iLhUgXw+fkm+y/nHA2aJl1hKSsH9ExkrZ57/tfEf8oEEBB4iqUxxsz8VwliUxSVDnrVvc+qoDQ797Mq9fNoAjq7Y/IPyBl7aDtrraau572FhNs28QYvH89f4/F8BBzb/rkSmLIchb5LojRBTKqAWs3vw+dFmEkT8mkjrU0z01FzNcRqhXLfEhiMEIaOO2bRpYg63z1qU475//URMeNzicrib6FjDxLNMOPmgyjDdPvqYGsRHteXgPckJoWccpvqAaJfEJt6V/jr1LZ1tj/O4DjtEIOpXoVi9UgMK1fhQXd+mM0Po7UtYvwh1h3tng== 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=xHnIih7z1NsYVt0Tt2cxqsqWFhB4lKuFjuoGFmx4KEU=; b=aIwzqC9AVGZBHlRUBWZuYACYORVOmyfcFRXiKlEDM7p+Mh9gCHt67yDf7fyUaPgaSxRXXDRzIq8+AoP88vspGcNDUlq5iWwGDGe1Gpn2NsgihWF0pS10+k7QsV/qU8my937FmSk78HlfooiMswHZ3Hx/s0sE5v2i0o4xFtb44TSPygreegpL2nqRZjYFqGvdFAj5ahpQG/DcuNnk4iobWIEKl5CK8hFrfs+dyDH8Yc3XqaKRbZB9bOlhwKJptPiqcu3KQu3axeajSMlqI9bx+BWOBDysha7NDxiCaisA5uPVf28QnVCbFxSXyeCTzJaMdTM0dsG0ZlWr1JZme7gETg== 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:18 +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:18 +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 17/25] iommu/qcom_iommu: Add an IOMMU_IDENTITIY_DOMAIN Date: Wed, 2 Aug 2023 21:08:04 -0300 Message-ID: <17-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: BL1PR13CA0292.namprd13.prod.outlook.com (2603:10b6:208:2bc::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: db21c8dd-34cc-4330-cbe8-08db93b5bbaf X-MS-Exchange-SenderADCheck: 1 X-MS-Exchange-AntiSpam-Relay: 0 X-Microsoft-Antispam: BCL:0; X-Microsoft-Antispam-Message-Info: LrKhc6q39mImebtkpZmcn5qo5skn7GeKMXmPTTiaBfEnUaaS5mW4qYKeTWCeVh4BYobeeFpalr7JRoJJB14fG9vfFGecmg2drX08UsR0nf94mbgVeFMitJxyMb+ywnjlStE7iimoPM9lHxOzeG4CM4Mbq6gf07PS3HT9jfVa2BOU+EEniVz1JdDqDuSHc1iN73g/LILIlkGsSbPFJ2BtuMWxp8yiGcYXg/Qo6mfxIx2IoD51RZe9YDRx3yFbzKBRCNVXcG3d6tJLiU+0ACa5zbGqEQLTJziHwLV7hV3vV0qhNr4dYG1hUSBk3KqJwnuUAoNzYC0y+soT46ZZyYe768Ds4D3FEnjHGrZ5QOAfzaSeXuIkj7iotI0K21eUmuLPOXZBCb4J53zGJ1i1iyV+EFvxwL/oPgUJtHhqdGshBKsCkkOnMTvQgD0LlttBO/75N0/6kd3DShpBJ6reboyhVJqiQAzrHopWK7IT+XiqFj4hZKEK12poxwg+FSZtBWj8KLv9TB2c/iwdn6RZJosQAuQeilEpQ1BUpr7RHCk9vb34kkmk+NU4CydAkqXMKNnsdXAv5IlN/SAoI2e60+iazT0t3O4kfL/wHFD3Eiz8HoI= 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: Coz0fTy5/bn7Mn7T9bfbVgVot+BJWoxxzCPm48J8NilatgbsGkndgzRV+3gWBOiicbhO3sauwI/KsNRFUPn3CBWn6OQrDxxe4ZLmGCVKcHFjZzZWyxvO/1Ulds4T+w24+0Kgz5BQimehKEUGtxLEMjCHt6Pc16m47oVSpPCtQwjQqHLfggrKcH8rKHBb/d+l9BZQiktBL8dmhHwMQXYW0DdxPoqQO3Qd5if0Xik6v8ANtkWfJZwLwQkfIUrq4mNuw/0sGU9RtcP4klfOTl/Nfld0BPxBJMZF4c9BDSP5ZcmwgmH0TKY71nDRXIN3lScevv/lYP25HC/g1eqswveVJ4bPK265vaMK/bTHNK5CHUghxc153sCo7QNJ3MkheAJAw18sbgoXqrJeFVXBYx+g046RPpKOVfqhQgIEPOaiOZXFoOjj2Vg/OXtG0KHiE1FJqY+yvm6FQDIIseL/kCW7rmRvH5g/aVnPIpMGXI/v/iF0NACxXEixC1mnd/YbdCiBQJE16FMHnbPLVeyYikEOd2B+25UWCzZcqv3sGr8Dh0WqUAVMi5L5EadYDlblYnlP6OcpACJM264Ex+jMpDErIpOEHXTy12x+riLATLV9jFuoc8AS8kYkD4dS9bEOAFA6PYi4bcA3BwUa5Pc1PgfFiSE5KUToxaXh92ius9hEvgi8obThFoYhZjbbl7ohzGmTq38n9uLH8jEZb54WKLAEVyq2zX8v+3qzbUAnDoKbp0soJVeCgBvXMB1kBQmmZ8G/Uu6EKywTgBMA1FeVflEj+n0ehXglbSi3+8VWuB4o0y9ghT9zQvyXDIsUx+SGW+GKk5JzGAw1spwhXDawu5Vh2R66B+bjIoICqVodhVgxS1kWYHusEfT+cq2aII32GS7QkQFbgH7cJhOZJEyzrnyOSUxNYBDjmDJMpL0ouLueJH8ViVShY2eZi55JL9MrS/EGhEUcShcI31LsLjpyPVlz6srDPr+SVRGSE7cRq5a4RS1BJuig8vx96a4dMsKSbadIrxJHOEpqSsduFJgpD1HmrX91CWrh1rxddJ/FlJca5TEOu1cj2prCtXpjfHAFt+3s3jm5dHzfEazpCT6lNCBspiGlbSiyHYnyl2D6qAE7waGR95PV1ifqb5LKLZqiJF1XYPdqIFY5yWxQWPHFW810iho/ShHM5ByvBIWBGAsjYO6WjUCJbSjhtDC9HLIshyoda0o2AIO0QB4Wszeettssx/bj5xn8iCld5XWPxo3/S384L5SVNcOVQpQhFyK8mzVz5XLZSiOQpxHXGX6DwCVaaXFpbQ/FviafwM4hwfnY+FMxm/jnZ7o9jTj47UU+iB9VFeft7jJnz7wLsr2cLceldS/DtCylydDN7OVS2zxZkWQYCW6CDokE31ToGhD5KTUfCnrKZRsINeokNz2KBzayhGiSWD9edyMjNW9vJnZuvYtq4qQSD8cGa7QOH2EQFYm7r8I0bdBv1NfMUU3ennJvPcs6IthgRx8WSajdDxNEHXn4TZOJhyxRKB6ycBIqprXihEo1BVnQaaVTw3pPKKWo0Q5pIay5vsTPFjdbibxOJ3b27MIlItCisCX/J2oyWDNN X-OriginatorOrg: Nvidia.com X-MS-Exchange-CrossTenant-Network-Message-Id: db21c8dd-34cc-4330-cbe8-08db93b5bbaf 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.3235 (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: cS2Wd8juQ8ichQVgsL82fAobHlP60hgJZojXdSqyBL2IILwh7VkMzub6UstcgPC+ X-MS-Exchange-Transport-CrossTenantHeadersStamped: MN0PR12MB5809 Precedence: bulk List-ID: X-Mailing-List: linux-arm-msm@vger.kernel.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. Signed-off-by: Jason Gunthorpe Reviewed-by: Lu Baolu --- 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 a503ed758ec302..9d7b9d8b4386d4 100644 --- a/drivers/iommu/arm/arm-smmu/qcom_iommu.c +++ b/drivers/iommu/arm/arm-smmu/qcom_iommu.c @@ -387,6 +387,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) @@ -553,6 +591,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, From patchwork Thu Aug 3 00:08:06 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Jason Gunthorpe X-Patchwork-Id: 709693 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 vger.kernel.org (vger.kernel.org [23.128.96.18]) by smtp.lore.kernel.org (Postfix) with ESMTP id 75615C27C4F for ; Thu, 3 Aug 2023 00:10:15 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S232735AbjHCAKO (ORCPT ); Wed, 2 Aug 2023 20:10:14 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:55718 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S231874AbjHCAJy (ORCPT ); Wed, 2 Aug 2023 20:09:54 -0400 Received: from NAM10-DM6-obe.outbound.protection.outlook.com (mail-dm6nam10on2077.outbound.protection.outlook.com [40.107.93.77]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 369AF3ABA; Wed, 2 Aug 2023 17:09:39 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=none; b=QNrEWueMnOUiexLFc2X6dwlStMlqTBLxWHRST6NeREjUk94VRkxn5PcrqOJ+fGbVD7uvzK2ws4K1muO8a7UN0iIWr4mIUzXXXCT24BsGG1KxF4iqDwyBhKLbt/85vjUUYjRMODPR59MeeWa6b3Wu2P/xdYCCYAwjhkzSSlPVjt0yraMkk3xCjk3FrVW72sEg+Q7/MoD+4c7kbTtcnYXrLGWz0nwkGYz/g9RlYTaGafWKdMDnY3lA5EtvwS0Nk07WFFwRvvmnIEiPcmO+QiH6qr0F1Se/cYplGgSmRrOkJNBdNL9ivSld2OBq8X96PmkrbNvDyc0IgPeuDA6qHwuNiQ== 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=2PBD3BXOVWRc/f35qHZJJJCRX+RoW6GH1RDzoMlN1lo=; b=CMzvzAiXqt/JGZED/N2Z3EV+z7VOQGO4KQ9ex6tnuvOvd5nldj72TSmQDYBdTLfPZ9J4VXUQbjAHaRDpV13ZLo8QvXyPpBkLzX5UeT35wGoDSdAEXQDefpTiOih3g/YBscYmeRhEjLCmVJFEW6WXc/QUMEafbJgovOOj0I6ljoWRGz9eNPUN1Ja9hUNmiN55WAPtcDkd3+N+ch+HFC84TZhBILi8R2MHwHKiXE1dZgs1AIm+cRqwEGuKmKx1DQP1a0TcK1LaPO273oR+SJiuw4nHLzQYpjckz4CCHHtl6v2qNMb8k2ChVQvjMgODB6GdstNr76fG4baXcip8PiofCQ== 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=2PBD3BXOVWRc/f35qHZJJJCRX+RoW6GH1RDzoMlN1lo=; b=m8hlS1R7uUnQ0X0ivQgKoVMe2TxCz6tDf70YKlSpMOoVBC09VbZFg034yD3Pi5kn12cLjxULk/VkXO4crQfedHuJgqR0ksevc89QHE8zQbURdzODA7TtAW5pWHxTrVn86ZY5GgTN8mZtreIb+C2pLbrIO/gPC/YrB7GinoAIJVPJNelTBjGDEZ3AJAAbb1bDt4ychQlizl7DPDGFeKZYssbIxhkb4w8BC2V59ORes3b5oqYUY1DDdWgFYKGXIqcWuAg/XuCefdkb2vrV6fB2eXTDSI8gVQItCtCr5LuERZLviCpxWnzKb84iuIYfOLDKK4/m+TWAMtOU0brU0MMHsQ== 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:15 +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:15 +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 19/25] iommu/mtk_iommu: Add an IOMMU_IDENTITIY_DOMAIN Date: Wed, 2 Aug 2023 21:08:06 -0300 Message-ID: <19-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: BLAPR03CA0127.namprd03.prod.outlook.com (2603:10b6:208:32e::12) 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: 3225a828-dfe6-4eef-b3b7-08db93b5bb0d X-MS-Exchange-SenderADCheck: 1 X-MS-Exchange-AntiSpam-Relay: 0 X-Microsoft-Antispam: BCL:0; X-Microsoft-Antispam-Message-Info: fQ6NE1JIp6e35ENq5wO6GMYsRFI0KXLUWvyH0MD7Az2GeB+IJRCkwIUdkpnwkJocpwjtRvreYvjNdjJrMgy8qFqEU4vw3R0kA3CGOU5dh7LEsCyV0RXee8X/XfHsiteGHMS4UTLX+KxmyhMML9rJd62H4BaM8nkT8LizG4CrUw4E9EJ3blcfRd97GkYvzNDp57g8dCQxen5ITJH2P96tmpAstyshLHHyTBgY422R43UcJ9/t+2oVScKG2kyiryTeOle+vFSclYwbRCPHSnCtrsDZMqsd1Js788M5FOOBYVJdfVEDplR13+VfRF5y59SW7GzVM5JK7vY9veIJ/yAFhlhbggj149LqrU5AewbEcgFBRyumMqXqbFhZhP6zEzz5GjldqiHiXNYgkU7Xq/j82oEaS3x66eIs8TOEoHjavb6HsW6SCAQJLmfSZVcKU3sQIZWyoNchCkrneIIY8UZ6SzKellt9zcJjosf4ywFMWcs1PSDWNezePREla5PDxsULTS5aFk35qIHfn1bwvV9o6OJnsuOYlp42SzXW6BdqZ8mXL2bKVnuHFZejXzJ2Az/+FR8BRlr34UpeZTslsR9oMQp9Oes0UV1apJoDheYGIy4= 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: WBsrs6JzdjKbl+poKKzs09KIldiMTQQm/pczdvksjsKF+oUSIuF6pYoHHO6OqfPg70/wwDuNSRaZNVZUHhpwG16v2NYY6jS53OVivcEr9Ue8ZVfgytDc/aNJ3xTQJkAvcSDDiwSSfwzU2/OQhLauqHXs6aYza5WcWBC3cGUwMkHdf977bQIx27CQy94WW2V8SEOJ7etaQyXUng4L929rwRBn5+FxOcAP2ymfVDJFbwZ3EzfnApUn6KQkq9n/v6r1Qp8cXksiMHBNM93NjFTXzBhnT5Hk7wnPbcPI2juCc5BWmLmEZ42xEMXnceMPLzsSOekl43z6JtEPINu2fKdGBG14/lUN05pQG+lkghbBlk9lUzYpXTQhxbHN4bE/9FDxepFviOkPX2GbzLS4PICBQ6rOuH2EoqUiEZ9YOBZX0RuDrYJf8390U4aBoaJ4h444aT0bznXh+Y6qaI9cINpJB+xcHrglY6hTehH6l1h9q07M3Zxt6cPtrfaucnjWpazjjj9EAuKMb/pSGURktCP/MkMAyfMkJUxp7405ddt61+bPQimdcfZf2XKaFFo2ARj4Gfb9lP96PgbbCv0WF04V/qNm1aiplEg23X+MckLb75TUj9PAtoFRRZLXHFCY0iJsMKPGP8chqYy8kOhgkIq4fDn7Qx8pGYS/zprISNGy3z7Ds/56OgJ1/tMr8QrWKKrv+lwrIzTvk2hOXncKBcAQgM8NTrn1vSBUd7Kd308ICmRzdz9vexCnm7UZ+PxocFu/DrYXagZtJ043raACtoMuk83aB99AD97Kmyrrb5UmEtF49EOYf6ax5g/V40quHGYV5jciuk3DpgCPAKRMmLMZS/ttpkVaw67q3gm0lfjN26fsdKKYIm1WjezclEtzRW52Bu/3nwoRgRSdHa4jj7kniR8UhP2nWAhSa8vYeFE9OBfxut2LJ9XgIRODaF4SL0qMmKYWUBKaJgflR7u2JskYnr+gF46iIaBpOKgvNy2XXURx03x4FD5GS6nZhfEJESiAb6AvWl6gxqw/LDjrVY34/gMiS2NTa49LBgSIGtw2/vCFMsYLz4NXUWm1+rhlU8LkeogQcEHH9M0WDiK1FWSbaD4GJnCG8hc5iJpwTRdq80PyzZCisIKs9P1ZqOsY5qbUhjQUV+t6Gszd57h05wwDjRgNa7jfXziCtzmsyU/AYSKRE48ZslRXPpykN5znjdOfv/nrxXPtyepU8QeSL0gG1Or2nJtdfNJWWVMJU+vVy9Uuut5//9A7vW92QfWo0E7vs44Uo8QUhdhiUv3pN7boxTuoJqi/KO53Inmj7QLbba27nRJxZwjj2/jB0JLVdyakK/1eiveB2Rr86fkIeXo4lgcFY5YCz2hZE17YmyF8SbH/EELNkGmuzatIokMcsv1e0r2499JDRlDYakKCvNDRIGZD+yu7xUhxR1TJ5ikkERh4s+IYL79Ii3PJzBzgev5dqOVGq7ylbqny7XA6rGM0W2GKDfCZsX3m5WLJXjFlp5BvLwkh4RDKfjAiryGSLR0swjy+x/N4hcsoHYb1mFLioNv+qNjeiRSEEEuuGRFrL2K4VzoUZeRsTiKkNHnzzwnk X-OriginatorOrg: Nvidia.com X-MS-Exchange-CrossTenant-Network-Message-Id: 3225a828-dfe6-4eef-b3b7-08db93b5bb0d 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:14.2758 (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: DI1VL8RhrcKWWECllTB+EZUuUL+Yn+0p+AQpehmasTCGxwxzW+XaY2JFf/FCZJoZ X-MS-Exchange-Transport-CrossTenantHeadersStamped: MN0PR12MB5809 Precedence: bulk List-ID: X-Mailing-List: linux-arm-msm@vger.kernel.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. Signed-off-by: Jason Gunthorpe Reviewed-by: Lu Baolu --- drivers/iommu/mtk_iommu.c | 23 +++++++++++++++++++++++ 1 file changed, 23 insertions(+) diff --git a/drivers/iommu/mtk_iommu.c b/drivers/iommu/mtk_iommu.c index e93906d6e112e8..fdb7f5162b1d64 100644 --- a/drivers/iommu/mtk_iommu.c +++ b/drivers/iommu/mtk_iommu.c @@ -753,6 +753,28 @@ static int mtk_iommu_attach_device(struct iommu_domain *domain, return ret; } +static int mtk_iommu_identity_attach(struct iommu_domain *identity_domain, + struct device *dev) +{ + struct iommu_domain *domain = iommu_get_domain_for_dev(dev); + struct mtk_iommu_data *data = dev_iommu_priv_get(dev); + + if (domain == identity_domain || !domain) + return 0; + + mtk_iommu_config(data, dev, false, 0); + return 0; +} + +static struct iommu_domain_ops mtk_iommu_identity_ops = { + .attach_dev = mtk_iommu_identity_attach, +}; + +static struct iommu_domain mtk_iommu_identity_domain = { + .type = IOMMU_DOMAIN_IDENTITY, + .ops = &mtk_iommu_identity_ops, +}; + static int mtk_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) @@ -972,6 +994,7 @@ static void mtk_iommu_get_resv_regions(struct device *dev, } static const struct iommu_ops mtk_iommu_ops = { + .identity_domain = &mtk_iommu_identity_domain, .domain_alloc = mtk_iommu_domain_alloc, .probe_device = mtk_iommu_probe_device, .release_device = mtk_iommu_release_device, From patchwork Thu Aug 3 00:08:07 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Jason Gunthorpe X-Patchwork-Id: 709695 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 vger.kernel.org (vger.kernel.org [23.128.96.18]) by smtp.lore.kernel.org (Postfix) with ESMTP id D3FC9C10F19 for ; Thu, 3 Aug 2023 00:10:12 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S233701AbjHCAKL (ORCPT ); Wed, 2 Aug 2023 20:10:11 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:55660 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S231396AbjHCAJw (ORCPT ); Wed, 2 Aug 2023 20:09:52 -0400 Received: from NAM10-DM6-obe.outbound.protection.outlook.com (mail-dm6nam10on2077.outbound.protection.outlook.com [40.107.93.77]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 4FD5B3AAC; Wed, 2 Aug 2023 17:09:37 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=none; b=blF+8kSr7VOcTeLDBtZyzRCwu4I5+hE14x/Cpr8ykeoxaORfLyNYKXslfcT2uES41zNb4RLpyw95y2eOSn8OdYis53mijRFPlDQO91/2fJeqWW/kd0H9Hpqbtu8M7wW4I/I7h7+dg3pm4QByjxXOxKM0jPSIMvv6xaZtEy62tV6GwJUF26GzrkB572heEX7S+IwTEQ6aJllG5bn14VxJXU0vAmYR/BnZLG21R/sfp8vm4po5Wd6qP11fspwUc/gYHTGVeZ7wRTeWEgtfnoqVG9afTUeLFVr3dxT0MW5jRkk8umsBvizzcjM0pzUzwRs57TwOSTcMyO09BEV4pPKCDA== 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=O8cvW84AteYGsHkKJoxDmgX1gvmm/kLqlAnWOZtGp1s=; b=d3YsHCHfWZzKzKbAg8VyFQ9t84mrS9Q6PfsEOyyPUg+Z86RPV10gxaJ9DAbsU+3A0bNS6/Sgml+z0SUphQT42YRyKM1omA74aErUrn6I/iYBfuM6BueygppX16c33ynH2zxEmaYkKNdltIk+xNuKe+1t3pL8PdtItGxuHsQelTZmsaj2GOZM1dA8nHYDE8+oeXrAhwT1gsHHhB0ZMMlwknN7z8AogD+HOmEr8gnlUYnubV4RZEZfDhIPvAhroZFkIhI1Tyav8vTM3xaXT4Q11XSFkjAVk1JjjfocMYDFj58uwDf7bpdFbzhk+RqaWUdvUG3Iv5k04RiQ+bsxktcHig== 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=O8cvW84AteYGsHkKJoxDmgX1gvmm/kLqlAnWOZtGp1s=; b=kHhcmsf28oZhFH2Te8iaMg3eJdL6RMI7EnuCofFuYtz0lrRM7LQWxQ6j/56yNEi3qq+qwl3xp1rrwFrZEHVsrU3TQu2YzoLL4qAsig/8ClQ0OUQFXiXqgCc3MbB1O/If9PfdoYZ3/XbaVcRrO79El4lQlYfK3u3xsPOlls311hJxHiME9wqVXy35sCiHG2yQJzILJFlhCkdvs+kFtXJjkq4TyWH+RuWz56tnpXx6yKFORHV9+fSowAsdAYLgsCFK67nkXQB/I1Woe9Q+oInRMPpdYRkSuv/GlrUQZmYXeIml0JEU/R/U0cz3bL0S/2PN9nnEbqcuNnG4HqqQI2HPFw== 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:20 +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:20 +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 20/25] iommu/sun50i: Add an IOMMU_IDENTITIY_DOMAIN Date: Wed, 2 Aug 2023 21:08:07 -0300 Message-ID: <20-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: BL1PR13CA0283.namprd13.prod.outlook.com (2603:10b6:208:2bc::18) 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: b5d6420b-9c1f-4a3f-84a0-08db93b5bc30 X-MS-Exchange-SenderADCheck: 1 X-MS-Exchange-AntiSpam-Relay: 0 X-Microsoft-Antispam: BCL:0; X-Microsoft-Antispam-Message-Info: aeQyStlrZHYPiSHQAvqqYwwbYtIsht1/FZUwE2WMGPFopMbbdRxzswARY15TuSciFtEKDhryeN1J547QzZBB4WsQ7Cd+MpmlJkAnFM+7pcDaDbf00LyXN2N/I1wQKJju1sFwZ7jVqH7B+Ja0z6Fn9htW13+fpuxOsWUuH8yA0XRBxdu6iNTavodMvQK6buEsr+D2WydNMdBk+LAR40c6l97rZhK6Jdy04IEmA7lItT0hYULf5hwdzq18GqqrI7bdMGtj5sTB7LP5oGipsUELS+ZRiHWbkWLre8rEUwLBqo/frsxMqU7AROK50L3k0sW34Vnez5Q2h0m45nxchc+YanVZSrZck7NDE3h8bOP7McwFNfnyhici421DRhwrkjAisdMej1UJzdWmlLiX3OZgDZcs9+JOBIBVxR8o0xKPU0P0XuU0tHnIGbA7C21FUwzEWXZrDC1/n/p/BakARlRCcMHCd6l2suPG5fh/tWVpRCOkpu93N8UTK00eR2lDZYrEk11jQCCAqxzU2hxAsgQGHliLrioqS1MbjfM/8gPO6w9DASn/TWxye/tqOWYynV7dfvOZNBp/V1OscAcDN5i2EiYkrhqFS+t7C4TjgFgC8Cc= 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: BLEeDltAnik2j+r3SVBKA5FpnmDirlUm8OExRLUQT94+2xkDwRhn4Qxk1TmJkkSyxZ7Fz43FjMTrPKAUXUW+mjNroiMIEX6HgBHeHWtGlZCTUiM5cuCMgrJZ3a6y/4NFpBJu5Rr4XO/zZsP2DUCeVwVjwujrK1jESrMYoGIcdptjUMVW9AqGldBTWIiEh8CKrZndkkcdCIuw1GCzzKxw5tXK6eqapfepwX9Plai0RWZAoeXB7fzHCh/WqvMXRPvD4QA8sY/gDeMyUHTFlsISA20orwrgmuemXnADRtanJbbPrveZK7r/jtUCbSiYo8Hmyo9rCA/+XE9IjohphAdho2cnH9tOoXynMj1x8Wn02KW+p+BXSvjqdj3yJve1z1JQ0y6jeGTn192Q6FWIh0HfgvhOoJ47dDxKiurVxpXFigKzhQ0hWA3YZ2t9iR0uZItnrfo+R69L0scbcWBq9Jg8TDREhCtFi7oEXtBEdNL+LvtGfpT6KxJUaFLf92xKW1uqtWyzXrXzD5ATpdgFH9OqfRbdN1W9Lgu55yFBb8WzBBUONLIc56HKvG83bf2SrrQyG7mzfN2H0+F7y7UvRSY1Hp0C16lnpTQyK3CXsBbPfxTlGAXVlrJGMps/x1Y2mGA0pvO6qCy2xQ8i2vxlm+FfxYGzCP1R6Dde+X3ZRCIH487XcHmYoWr48hIJyF6ROKychK47x8ChMhbPMhmGL3UDCh4giRMpyjYYPewmdFHXKyag4MJDUxllJK2I0ehjmsF8yfpDprzxG2dTcgTEaakRSVXjQQpepEVnrurjXNu4G6vEwLokqlzrPw1ajI4Q8Tgy6tk773b73EGgIZ8h3c2x35EeGhxwtNByCCzQbv2rCdjV4XWsYj4TCkO6/aTVnPt9v24KQeCU0/KuOjVjYr6YPNRj2jNxHOPUelxCqJaKMeBWHGV/bKbtOT1f8fx/elvTh6MAdnD5F3qZTKjt1H71mWcdgJAJ3tWBnHWc+2RAJ+gyTooT1YjBOgBon01nieAPn8sM1x03q5cMbKWzIHuWbL/XWol8WTwnU8mEKvHp54C/sTBIgayKzbfBlZdsZfsSvdnm+JypQUVMz47BW2nfONZqNXkJt/ZT2PYE5nVB7JOOr8k0N8itzsuXOSZoIpFq0QrbRxElgl7UrIAPtq3G66NIgkxSHjeo+c07R+1/faJqpglumTnxRx+rB9JB0iT5dlfgb4qxEXWki6z4VYbRN09L0D/L3wMDWA9qoy1N8SRAZA02rlIdgWECmENagr/I1nN6bMsU4Md+gu8WfoDmYm7u6TNwPlTePWr0QRcq4UZdrWK8yA+DsZ/4Iij6rb4VYZDd6/59vTiyJRbHEfHg8dfIFa0DKW2O+iWMRy787SQp1w2oeEbuW+fzHgM38w2C7pXMCWKW1eOgW6+tPp/08FRjHTGLdYhmlD96awNWoACXG5BMDoqkY5wi5FLFetxxxiMseUXmAWrHU8O7qt797DjaOC/hY3DbJTnH++k8yyzKf363cs/17N5Yoq6dlyHlWe4QlMfSfphEXaeDkbSZDyEf0K4NfEc5NBHR7Lh/A3LhLBxwqphAgArtNlrbJZl0 X-OriginatorOrg: Nvidia.com X-MS-Exchange-CrossTenant-Network-Message-Id: b5d6420b-9c1f-4a3f-84a0-08db93b5bc30 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:16.1498 (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: KkG28XrfXg4JL1hTJf5XAE25CkDZamlkGstmA/eHTbzSLcH/UgxXxBXxRE+0WIY2 X-MS-Exchange-Transport-CrossTenantHeadersStamped: MN0PR12MB5809 Precedence: bulk List-ID: X-Mailing-List: linux-arm-msm@vger.kernel.org Prior to commit 1b932ceddd19 ("iommu: Remove detach_dev callbacks") the sun50i_iommu_detach_device() function was being called by ops->detach_dev(). This is an IDENTITY domain so convert sun50i_iommu_detach_device() into sun50i_iommu_identity_attach() and a full IDENTITY domain and thus hook it back up the same was as the old ops->detach_dev(). Signed-off-by: Jason Gunthorpe --- drivers/iommu/sun50i-iommu.c | 26 +++++++++++++++++++------- 1 file changed, 19 insertions(+), 7 deletions(-) diff --git a/drivers/iommu/sun50i-iommu.c b/drivers/iommu/sun50i-iommu.c index 74c5cb93e90027..0bf08b120cf105 100644 --- a/drivers/iommu/sun50i-iommu.c +++ b/drivers/iommu/sun50i-iommu.c @@ -757,21 +757,32 @@ static void sun50i_iommu_detach_domain(struct sun50i_iommu *iommu, iommu->domain = NULL; } -static void sun50i_iommu_detach_device(struct iommu_domain *domain, - struct device *dev) +static int sun50i_iommu_identity_attach(struct iommu_domain *identity_domain, + struct device *dev) { - struct sun50i_iommu_domain *sun50i_domain = to_sun50i_domain(domain); struct sun50i_iommu *iommu = dev_iommu_priv_get(dev); + struct sun50i_iommu_domain *sun50i_domain; dev_dbg(dev, "Detaching from IOMMU domain\n"); - if (iommu->domain != domain) - return; + if (iommu->domain == identity_domain) + return 0; + sun50i_domain = to_sun50i_domain(iommu->domain); if (refcount_dec_and_test(&sun50i_domain->refcnt)) sun50i_iommu_detach_domain(iommu, sun50i_domain); + return 0; } +static struct iommu_domain_ops sun50i_iommu_identity_ops = { + .attach_dev = sun50i_iommu_identity_attach, +}; + +static struct iommu_domain sun50i_iommu_identity_domain = { + .type = IOMMU_DOMAIN_IDENTITY, + .ops = &sun50i_iommu_identity_ops, +}; + static int sun50i_iommu_attach_device(struct iommu_domain *domain, struct device *dev) { @@ -789,8 +800,7 @@ static int sun50i_iommu_attach_device(struct iommu_domain *domain, if (iommu->domain == domain) return 0; - if (iommu->domain) - sun50i_iommu_detach_device(iommu->domain, dev); + sun50i_iommu_identity_attach(&sun50i_iommu_identity_domain, dev); sun50i_iommu_attach_domain(iommu, sun50i_domain); @@ -827,6 +837,7 @@ static int sun50i_iommu_of_xlate(struct device *dev, } static const struct iommu_ops sun50i_iommu_ops = { + .identity_domain = &sun50i_iommu_identity_domain, .pgsize_bitmap = SZ_4K, .device_group = sun50i_iommu_device_group, .domain_alloc = sun50i_iommu_domain_alloc, @@ -985,6 +996,7 @@ static int sun50i_iommu_probe(struct platform_device *pdev) if (!iommu) return -ENOMEM; spin_lock_init(&iommu->iommu_lock); + iommu->domain = &sun50i_iommu_identity_domain; platform_set_drvdata(pdev, iommu); iommu->dev = &pdev->dev; From patchwork Thu Aug 3 00:08:11 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Jason Gunthorpe X-Patchwork-Id: 709702 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 vger.kernel.org (vger.kernel.org [23.128.96.18]) by smtp.lore.kernel.org (Postfix) with ESMTP id 46451C04A94 for ; Thu, 3 Aug 2023 00:09:56 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S233691AbjHCAJz (ORCPT ); Wed, 2 Aug 2023 20:09:55 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:55682 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S232039AbjHCAJZ (ORCPT ); Wed, 2 Aug 2023 20:09:25 -0400 Received: from NAM10-DM6-obe.outbound.protection.outlook.com (mail-dm6nam10on20601.outbound.protection.outlook.com [IPv6:2a01:111:f400:7e88::601]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 3EA073ABC; Wed, 2 Aug 2023 17:09:02 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=none; b=I47fsNi+eujAuIe2y7m6tIF97SFKcgN/hybz4LjN2+/UZfYeUW0Ze0gm9MU2ObkTrYXO7nWxoIekEVCLSMxJgd2f9IJul2MZA0RA20y3f6sHVPExauuKttolkwv00OWNOZIRZn1Ul33ujbpk1gAoJxnFT6/pUpk+0vKusH2BAHS+0RFVPY/qOrKu6eVZ2igDaG+Gng3nxZlP3bT9Xf+0l8BJZavTYRrUqrZhJjyFmY9PUZLFqQJ7V990P4F8fUeVmPJh3adNRiy1OHLuRVfhvka/awb27olbKxswefvUVIR9cbVrUBZt8uVXT9jxxApRsK+DDRdlZ80ZuRckEJLrLg== 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=Qg6RwPc3o59Fy/WU3EeeG9ZakmbO8tBMyKbd8yYPm1c=; b=W8mT9JMGd9knT0/C6flLXlJp/km2oeUY9IfMSdMfutNeZ3daduUqjp+WD/oM5qHxgNQdGXPrW/Qtr4thDaSkpxu+qdalGEge+g0FivJFvQopcnvh/UvGrpF+QzPGdhTyYRblhjRqz7ldA/akxFHyuVWhY7mY8+BzGEIn0y8QIUXS6e6ehSBC7mwysVnF7k+U5k8R0b1c5ex476qOQUjo1GW8J71+BtzKDkXIn7DTQrl7OZ5NXW134av260FV0CcgukIhcQh5VXfddR8klfyFzeTdgvU07nolEI+ujNjxHnPMfqXU/fPIPbKxqYn7cM3JC6HAmP8ldxpTTg8glT2A8g== 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=Qg6RwPc3o59Fy/WU3EeeG9ZakmbO8tBMyKbd8yYPm1c=; b=ROLzmJfDwu/0FxZcGwcHO4n0Tcspx5hyB2wFecgagQDfgXfcnRJ4wzt6YF18Fri5kCANIVv18WwEvs/tz9V5Jqr0cJaAsTGG8jSjBa5jh3uppozepqXCtb9l9RcbiBaV7/nSlGZ2ZdV3oFebuNzdwMmvTyqzZ8O0pUB7c2JB9vJ3aS27UvmAvmXrG1QeyauvQP9AQhiyZZKikfXjZxBQ1AdCHGAC0d5zajRaHCTmVHXMlFW6tseyjx73418F/HZe6vOf0HRT3BGoMhokBj9INLcUoZkcKpA2QpLriyZ2FxaJGM3Wk7ybdXqCxxqEuevV4gbiupIHWVlN7wolRpQHxQ== 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:16 +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:16 +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 24/25] iommu: Convert simple drivers with DOMAIN_DMA to domain_alloc_paging() Date: Wed, 2 Aug 2023 21:08:11 -0300 Message-ID: <24-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: BLAPR03CA0126.namprd03.prod.outlook.com (2603:10b6:208:32e::11) 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: 953e61f9-b265-46ad-9eda-08db93b5bb19 X-MS-Exchange-SenderADCheck: 1 X-MS-Exchange-AntiSpam-Relay: 0 X-Microsoft-Antispam: BCL:0; X-Microsoft-Antispam-Message-Info: iqQl5aqQw6vSByh3mvSpOFfJaPTQAOupNPt3z6irEZxCXGPXAytB5y+Gh5yA+vBSqp943bF8yipnaiDaIJwq9xhGbvuxWtgoMM83IpAT36T2LGISIcX897+hXWQCcoOWH1rOW3NumIm6YCuT06lfRefieeQNImcijzYwg5ztuWe0EHQNeHTIjlsm92wD2aZhKWFaJo2ZKrdjO+bLBJYcK3pg9KT6fyctWC0bt2OiB8+JcAVBVqRq/rqwggg4Hxfa6wJknSAWySYfyA9JeXfBOS4aYNl+YB0txzi7EnSisN/bQWq3i/b489Afi9JI8HyLPPmxycFGCYnT95HBw/XGKdwDSN5jfwVln7dvv4anQ7Md9zR3FmNcF0/87Uqu+w5ysDPyLA3GDWdj6pXhvNCnd4ylT/vlEFu7FA4SRu0UKxvardDUEtYB5K338ettFgE5a43phL8xPmemxHB1sc3oGo7ngiykblJlJdfkxOgMYTyvTET+icZY1+Y/aYJSOsSiobqUafm1civGAkRqiUHXJw2/16ph5F4MSnuCyxbR6SOCfsGbtuWjMGb4a3Aii2X8tE2B9R5P+tDr46XN0r8B41bcaTG2Eu+mtmLWlalInaE= 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: 4s6/sWxJlDTqoOP8Lu+ozo9ic1RZlURkPx+0vVAYmm+ozAk/BH+/1FydFj8tW5Wm1O2xms+OJGKHo7CWzszo6zG/lW9NPT7YYlLiwrG+j2Y1oYOm3pcEMKg9+Wofc63T0yYfEAIiQM4x9+SnaMeUsqT8lqaAwOt80cnuRrsa5PO+ozr75MUmn45KQTQ/7eyxMn/l/0wZrQtHTFIV0eL5WIax6K3voLrGEiPuSaxVnIRiKc12Qt/OBFxRphK2RZ3Z3UO6wy8Jr0SmuCKk0VSBjD14vH/Y8DZXTAT/RiqFbDLtGLV/0Mreb4gKZeGQcAoPsg3ITTcQwpaNzu6k3HQAuDM8yTwP6J/6w47yNG8OJtkOEw9zfNaUBJoRLJP+DgsO1Laiqvd8pCKDMFp+KbosmneaQXI93OX1yFas1y1QbHQhvhI8NxQBZj0or3+THAqcc45M6Bn2kSAGYIM6cUvL+O1Az1URT1zESTjVwft7OYl2KNlfSaj9Jl4y2KOGBLqFC9zCOWe3m8qc8RqSxn21YlQZiECxzbtkaHBTU84ykv94lDfdD2MWMXBKnEfZXvfMZyjTkXOZFvf4p7zR8RnGHNsBAVNz3OrFEl7goNb5gH2EiC/4HFbEAHLfq4TDsTxIzxs27IB5oqgCF1+siwTx0F8ewbgb15+wnBK51Xfm/d0L0yoe845oDBmv+n6V8H5B4FNp3LLeQSSmTUBpezRg3ZxoKm57XpvN5OaQ4kmm340uTwBd8eVqAHV67KsXIaH/wZXbnDEvjD/PNXa+0ynexzTn0Ts+ZJl9/fWon6QK8OWjVs0d58N+bEbkec/h47ZKFQdXov6uiJPsKJRLmfFbiLfek6/ZyJr59MxVoiYoqODw6kz+GNT+YuqdEfR4yDoXoQXkfPiH4k7GAtzhTediXUNlnbP+0gUtp1+UO/Mne5yi3gVRywdNzdtDpewrzjW8ix561vGI6OOPn7DyNyPYt5aFu8sBDYkFeHOAaattKzjiMk4CMfCCIfUeeRm4JonebWgRmkgm/myI8uUSAhRXXeqAqwg4vLu6nAckKnR51cRidUIvnletPJYNiBxv9f9ALJsy5KohbdIutIfMN15RTjHJ4LKH0NKddKiEZZWXpL4qG3PDPHncvqqBxvjV4M+J5+9fJKpp+nbBu9kC/s+DLBQsJu9N4ekr/13xlR2l62b3A/ndD4FgoCyaal8EIhz/ug1/r1Uk4E+ic0rFA0s2IYU9Cq82qdOh9nDGOk+wo29g7QCfMRjKWLZs7ZJLmIPsCsyzLBmoM2exCPY/SPEdI9vSWFQDvt4yndZ9qCOHaaGeiXFVotcZl1JcXHA5zP0aSHe5L6Um6dxdbQh0jeterA80vjzNpMvoDcP5EuiofsEZCouwrAa4NdA3ozSzDYBzArqhrCraUJHh8vHj5gfKmZZ+xN2jLEetIKH5Y1ZdIs8b3qbLL0yTK8GRWG/AFpCbhSb43PX6v5Cpr7tw1Al0O+XAcRX2D1MUP/kIC348R1KWuYQm6usyBlIOENF/1KxuDTIg10Im/dbOcI6zuFyUyQE6/wcSovxRo8KvegvmRLo74zulN8ia0I0hYYQt7J08 X-OriginatorOrg: Nvidia.com X-MS-Exchange-CrossTenant-Network-Message-Id: 953e61f9-b265-46ad-9eda-08db93b5bb19 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:14.4554 (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: 3kw9KTZgc7MvYDmtit+OCk24sWBx2NpPMpPDtVIxIP1Q3e75MOnu2qbRj0ayok1J X-MS-Exchange-Transport-CrossTenantHeadersStamped: MN0PR12MB5809 Precedence: bulk List-ID: X-Mailing-List: linux-arm-msm@vger.kernel.org These drivers are all trivially converted since the function is only called if the domain type is going to be IOMMU_DOMAIN_UNMANAGED/DMA. Tested-by: Heiko Stuebner Tested-by: Steven Price Tested-by: Marek Szyprowski Tested-by: Nicolin Chen Signed-off-by: Jason Gunthorpe Reviewed-by: Lu Baolu --- drivers/iommu/arm/arm-smmu/qcom_iommu.c | 6 ++---- drivers/iommu/exynos-iommu.c | 7 ++----- drivers/iommu/ipmmu-vmsa.c | 7 ++----- drivers/iommu/mtk_iommu.c | 7 ++----- drivers/iommu/rockchip-iommu.c | 7 ++----- drivers/iommu/sprd-iommu.c | 7 ++----- drivers/iommu/sun50i-iommu.c | 9 +++------ drivers/iommu/tegra-smmu.c | 7 ++----- 8 files changed, 17 insertions(+), 40 deletions(-) diff --git a/drivers/iommu/arm/arm-smmu/qcom_iommu.c b/drivers/iommu/arm/arm-smmu/qcom_iommu.c index 9d7b9d8b4386d4..a2140fdc65ed58 100644 --- a/drivers/iommu/arm/arm-smmu/qcom_iommu.c +++ b/drivers/iommu/arm/arm-smmu/qcom_iommu.c @@ -319,12 +319,10 @@ static int qcom_iommu_init_domain(struct iommu_domain *domain, return ret; } -static struct iommu_domain *qcom_iommu_domain_alloc(unsigned type) +static struct iommu_domain *qcom_iommu_domain_alloc_paging(struct device *dev) { struct qcom_iommu_domain *qcom_domain; - if (type != IOMMU_DOMAIN_UNMANAGED && type != IOMMU_DOMAIN_DMA) - return NULL; /* * Allocate the domain and initialise some of its data structures. * We can't really do anything meaningful until we've added a @@ -593,7 +591,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, + .domain_alloc_paging = qcom_iommu_domain_alloc_paging, .probe_device = qcom_iommu_probe_device, .device_group = generic_device_group, .of_xlate = qcom_iommu_of_xlate, diff --git a/drivers/iommu/exynos-iommu.c b/drivers/iommu/exynos-iommu.c index 5e12b85dfe8705..d6dead2ed10c11 100644 --- a/drivers/iommu/exynos-iommu.c +++ b/drivers/iommu/exynos-iommu.c @@ -887,7 +887,7 @@ static inline void exynos_iommu_set_pte(sysmmu_pte_t *ent, sysmmu_pte_t val) DMA_TO_DEVICE); } -static struct iommu_domain *exynos_iommu_domain_alloc(unsigned type) +static struct iommu_domain *exynos_iommu_domain_alloc_paging(struct device *dev) { struct exynos_iommu_domain *domain; dma_addr_t handle; @@ -896,9 +896,6 @@ static struct iommu_domain *exynos_iommu_domain_alloc(unsigned type) /* Check if correct PTE offsets are initialized */ BUG_ON(PG_ENT_SHIFT < 0 || !dma_dev); - if (type != IOMMU_DOMAIN_DMA && type != IOMMU_DOMAIN_UNMANAGED) - return NULL; - domain = kzalloc(sizeof(*domain), GFP_KERNEL); if (!domain) return NULL; @@ -1472,7 +1469,7 @@ static int exynos_iommu_of_xlate(struct device *dev, static const struct iommu_ops exynos_iommu_ops = { .identity_domain = &exynos_identity_domain, - .domain_alloc = exynos_iommu_domain_alloc, + .domain_alloc_paging = exynos_iommu_domain_alloc_paging, .device_group = generic_device_group, .probe_device = exynos_iommu_probe_device, .release_device = exynos_iommu_release_device, diff --git a/drivers/iommu/ipmmu-vmsa.c b/drivers/iommu/ipmmu-vmsa.c index de958e411a92e0..27d36347e0fced 100644 --- a/drivers/iommu/ipmmu-vmsa.c +++ b/drivers/iommu/ipmmu-vmsa.c @@ -566,13 +566,10 @@ static irqreturn_t ipmmu_irq(int irq, void *dev) * IOMMU Operations */ -static struct iommu_domain *ipmmu_domain_alloc(unsigned type) +static struct iommu_domain *ipmmu_domain_alloc_paging(struct device *dev) { struct ipmmu_vmsa_domain *domain; - if (type != IOMMU_DOMAIN_UNMANAGED && type != IOMMU_DOMAIN_DMA) - return NULL; - domain = kzalloc(sizeof(*domain), GFP_KERNEL); if (!domain) return NULL; @@ -891,7 +888,7 @@ static struct iommu_group *ipmmu_find_group(struct device *dev) static const struct iommu_ops ipmmu_ops = { .identity_domain = &ipmmu_iommu_identity_domain, - .domain_alloc = ipmmu_domain_alloc, + .domain_alloc_paging = ipmmu_domain_alloc_paging, .probe_device = ipmmu_probe_device, .release_device = ipmmu_release_device, .probe_finalize = ipmmu_probe_finalize, diff --git a/drivers/iommu/mtk_iommu.c b/drivers/iommu/mtk_iommu.c index fdb7f5162b1d64..3590d3399add32 100644 --- a/drivers/iommu/mtk_iommu.c +++ b/drivers/iommu/mtk_iommu.c @@ -667,13 +667,10 @@ static int mtk_iommu_domain_finalise(struct mtk_iommu_domain *dom, return 0; } -static struct iommu_domain *mtk_iommu_domain_alloc(unsigned type) +static struct iommu_domain *mtk_iommu_domain_alloc_paging(struct device *dev) { struct mtk_iommu_domain *dom; - if (type != IOMMU_DOMAIN_DMA && type != IOMMU_DOMAIN_UNMANAGED) - return NULL; - dom = kzalloc(sizeof(*dom), GFP_KERNEL); if (!dom) return NULL; @@ -995,7 +992,7 @@ static void mtk_iommu_get_resv_regions(struct device *dev, static const struct iommu_ops mtk_iommu_ops = { .identity_domain = &mtk_iommu_identity_domain, - .domain_alloc = mtk_iommu_domain_alloc, + .domain_alloc_paging = mtk_iommu_domain_alloc_paging, .probe_device = mtk_iommu_probe_device, .release_device = mtk_iommu_release_device, .device_group = mtk_iommu_device_group, diff --git a/drivers/iommu/rockchip-iommu.c b/drivers/iommu/rockchip-iommu.c index a582525d36f8cc..5deb64b9cbe4b5 100644 --- a/drivers/iommu/rockchip-iommu.c +++ b/drivers/iommu/rockchip-iommu.c @@ -1043,13 +1043,10 @@ static int rk_iommu_attach_device(struct iommu_domain *domain, return ret; } -static struct iommu_domain *rk_iommu_domain_alloc(unsigned type) +static struct iommu_domain *rk_iommu_domain_alloc_paging(struct device *dev) { struct rk_iommu_domain *rk_domain; - if (type != IOMMU_DOMAIN_UNMANAGED && type != IOMMU_DOMAIN_DMA) - return NULL; - if (!dma_dev) return NULL; @@ -1172,7 +1169,7 @@ static int rk_iommu_of_xlate(struct device *dev, static const struct iommu_ops rk_iommu_ops = { .identity_domain = &rk_identity_domain, - .domain_alloc = rk_iommu_domain_alloc, + .domain_alloc_paging = rk_iommu_domain_alloc_paging, .probe_device = rk_iommu_probe_device, .release_device = rk_iommu_release_device, .device_group = rk_iommu_device_group, diff --git a/drivers/iommu/sprd-iommu.c b/drivers/iommu/sprd-iommu.c index 39e34fdeccda78..af68b3a2c123ab 100644 --- a/drivers/iommu/sprd-iommu.c +++ b/drivers/iommu/sprd-iommu.c @@ -133,13 +133,10 @@ sprd_iommu_pgt_size(struct iommu_domain *domain) SPRD_IOMMU_PAGE_SHIFT) * sizeof(u32); } -static struct iommu_domain *sprd_iommu_domain_alloc(unsigned int domain_type) +static struct iommu_domain *sprd_iommu_domain_alloc_paging(struct device *dev) { struct sprd_iommu_domain *dom; - if (domain_type != IOMMU_DOMAIN_DMA && domain_type != IOMMU_DOMAIN_UNMANAGED) - return NULL; - dom = kzalloc(sizeof(*dom), GFP_KERNEL); if (!dom) return NULL; @@ -419,7 +416,7 @@ static int sprd_iommu_of_xlate(struct device *dev, struct of_phandle_args *args) static const struct iommu_ops sprd_iommu_ops = { - .domain_alloc = sprd_iommu_domain_alloc, + .domain_alloc_paging = sprd_iommu_domain_alloc_paging, .probe_device = sprd_iommu_probe_device, .device_group = sprd_iommu_device_group, .of_xlate = sprd_iommu_of_xlate, diff --git a/drivers/iommu/sun50i-iommu.c b/drivers/iommu/sun50i-iommu.c index 0bf08b120cf105..056832a367c2af 100644 --- a/drivers/iommu/sun50i-iommu.c +++ b/drivers/iommu/sun50i-iommu.c @@ -667,14 +667,11 @@ static phys_addr_t sun50i_iommu_iova_to_phys(struct iommu_domain *domain, sun50i_iova_get_page_offset(iova); } -static struct iommu_domain *sun50i_iommu_domain_alloc(unsigned type) +static struct iommu_domain * +sun50i_iommu_domain_alloc_paging(struct device *paging) { struct sun50i_iommu_domain *sun50i_domain; - if (type != IOMMU_DOMAIN_DMA && - type != IOMMU_DOMAIN_UNMANAGED) - return NULL; - sun50i_domain = kzalloc(sizeof(*sun50i_domain), GFP_KERNEL); if (!sun50i_domain) return NULL; @@ -840,7 +837,7 @@ static const struct iommu_ops sun50i_iommu_ops = { .identity_domain = &sun50i_iommu_identity_domain, .pgsize_bitmap = SZ_4K, .device_group = sun50i_iommu_device_group, - .domain_alloc = sun50i_iommu_domain_alloc, + .domain_alloc_paging = sun50i_iommu_domain_alloc_paging, .of_xlate = sun50i_iommu_of_xlate, .probe_device = sun50i_iommu_probe_device, .default_domain_ops = &(const struct iommu_domain_ops) { diff --git a/drivers/iommu/tegra-smmu.c b/drivers/iommu/tegra-smmu.c index 6cba034905edbf..69c40c191ce4f0 100644 --- a/drivers/iommu/tegra-smmu.c +++ b/drivers/iommu/tegra-smmu.c @@ -272,13 +272,10 @@ static void tegra_smmu_free_asid(struct tegra_smmu *smmu, unsigned int id) clear_bit(id, smmu->asids); } -static struct iommu_domain *tegra_smmu_domain_alloc(unsigned type) +static struct iommu_domain *tegra_smmu_domain_alloc_paging(struct device *dev) { struct tegra_smmu_as *as; - if (type != IOMMU_DOMAIN_UNMANAGED && type != IOMMU_DOMAIN_DMA) - return NULL; - as = kzalloc(sizeof(*as), GFP_KERNEL); if (!as) return NULL; @@ -997,7 +994,7 @@ static const struct iommu_ops tegra_smmu_ops = { .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, + .domain_alloc_paging = tegra_smmu_domain_alloc_paging, .probe_device = tegra_smmu_probe_device, .device_group = tegra_smmu_device_group, .of_xlate = tegra_smmu_of_xlate, From patchwork Thu Aug 3 00:08:12 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Jason Gunthorpe X-Patchwork-Id: 709701 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 vger.kernel.org (vger.kernel.org [23.128.96.18]) by smtp.lore.kernel.org (Postfix) with ESMTP id 5B3C3C07E8B for ; Thu, 3 Aug 2023 00:09:57 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S232949AbjHCAJ4 (ORCPT ); Wed, 2 Aug 2023 20:09:56 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:54012 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S230261AbjHCAJ0 (ORCPT ); Wed, 2 Aug 2023 20:09:26 -0400 Received: from NAM10-DM6-obe.outbound.protection.outlook.com (mail-dm6nam10on2065.outbound.protection.outlook.com [40.107.93.65]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id EFA562D43; Wed, 2 Aug 2023 17:09:06 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=none; b=AA172BgyzkSxtCR2C8uLoaBHFJIpc0z1kTwgJjg/5TH+FDDV7eFL/zH3XymPUNOUwaaifmkdgiaeOTZncrjl7Tt2bLRvQYRDuWIAJfLjv7wxJA8QI8P7fzLKbW+uR9EUlo2GTwhB9JtkRjZqxW6OG7zDjmTGPY+YjDnNM9aMmGjptOx3UkGahB2CzffJ6FscJYe/9iJu21ZIkonUqGNpF5fZQB7GFhCO9k4evuqJsVojzHVIvGyFwp026enkrn6BHRVdd7szdkKDabzSvkQ5pzsisJj3bfhVGgzhwjeUKvKhaccq8R/A9ZR+/sApeIDlbvHkrlGH0j1QVk8DkZcLhA== 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=R/uxLFw6T9ll/W7V4Vb06QW+koECiUEA49Foq4D3zXw=; b=HYS0uKXd2sq+5FiGUPkI12i80NkP1D6NNJnOZxU0WeY3FCTa1eY2P1/x5pzz+1E4SxlR5y4bfmX2Rhy6zkL1gt0hT6jQHlkYbd/A75EmDU35QU2X+Ho9sfBm0I4UzgSvxR/IYlEzh3XJZZnAiHLv52qnoOLQrQ/S6xsyU3dMnIP3ZaUOWaCF5KVPHxYv504AfoIVuYMQbxxocLYN3/o0n4QCUZQPzEOzDP2n6v7eCx8J55E+HWnf5HzpVoH+F4mS6xsvOf+nyhyGIysntelV7x9U6F838Vh6iLazkIdNtzXmotK7V3EqxTFoyBsr4iesw0W7hihK6f9gwdR3nqGiFg== 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=R/uxLFw6T9ll/W7V4Vb06QW+koECiUEA49Foq4D3zXw=; b=SZsBcUDBQ8OlpHvq3cDuIABZrHE+lrQgjesaYfZXC44Qpx7PfDOuHJ65xcX1MwicFInYe2dm/OnBf1CEI5mV3Kk2DORa3O64w1cYMl5AYAJlQO1xOwxAtOMjLK/46gccpNT+qK1wiet0YzYR2DC/IZ/OxjSooQoRYfIN1osFaUPxokyYnDDkAjBwbiGAj+4mQh8g9Hg7+lCMY2PDt2bPYN/FumrAk74nUu2yIENwABl8ClRgphNXVjzyPjLzZ3PSKH7vxFA/RGQgJtW8ZKLR9vu697i5bHG6GbD3FmoDP2JleNvS1I3A19b6It+FGqEFOn+R29CoVRPzh+DcTfykZQ== 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:16 +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:16 +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 25/25] iommu: Convert remaining simple drivers to domain_alloc_paging() Date: Wed, 2 Aug 2023 21:08:12 -0300 Message-ID: <25-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: BLAPR03CA0140.namprd03.prod.outlook.com (2603:10b6:208:32e::25) 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: 76aed0b4-7a47-4ecc-fb43-08db93b5bb59 X-MS-Exchange-SenderADCheck: 1 X-MS-Exchange-AntiSpam-Relay: 0 X-Microsoft-Antispam: BCL:0; X-Microsoft-Antispam-Message-Info: d9V0WfQLWpAns9iJCJcDCVyhbw3SfELKZqw5ct5uCW75vXDviK+YtOZ5Q7GU2DYwKVpiVFs6d95k51+Ec3x4feMMnCIlAwOCZxGd9g5xj+6aPvNRRjn/HVpGsFcjhexUrj9+gSbs6MzdhcpGN0eqVskrOw3p9iF8vZKLqUofPQFQB+YD66JZzLB3SP5S5TT+j85l3sC1xafY/Qrh8fLZ16B4WzEHKs/dZqPYVDTp8eSEkpNOuAhXBuNSuLZjhp3Mv8BjS1yNaD37Lq0dCRsx1d+NE/44SqGxNrJT3+PEa4zgBWm6DdSBQD8nbitJc5KJG6870w2EpTg0DjTIMGxupf47cWwGYvAAymC0Wo0utuuZFmIVN9lLKc00WQla8eOeZkyGnCxaaqESfavJmjjI5apQlCWrDisVIvOCAmnRYHxPdQEyBk/ckwDNGi4lTTIX9TYByDAC/D0j3bj8es5UWoF/8mZr7s8zn2CFxJyrEGE3gY6sUEQuEPKnTWqKAtEuRvckkxEpIQFPRm3D2tpWHml3ywxIHWy0VQxlcZ4lQSqWC0G9IxTuJEDyaoFYwa4+seoeMU1uYU92vFKfgF7MUn5K9KhITLleuWkoLZxVPL4= 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: /F0PRCaaw4vFFP1W5WoverMFLO+cFAK2M1+MtOS/log9/Gv6XuMLTpq0fePPVd4pnD2hw7tWnhy2kWoI1Q5ll2PSjEcZ1ZZDqAB8OH6MFwV1KAjVse1NrMQywsxvorhFE3ZsPI2YQk41SkFRyVPk+FAopaxKzXbg5gxwkKWvgKn+Vem50kNp965lAG/rpGL0N4j8LEvm7Xe95pIGM7I76gBKim1w/gPvcYAw/N3Q4raJ7Rto/eOxoWMiy1210CaDfz5x8FeAVO1s2wNeho5Lw1h7F3h00XxyUmXsojrNxfqne0egVyHfsKesSP7b1u8s+LfKA+/9hVF6LsBQYbU2WGoApuNWRlCdvN2MmTcQ7i7bwfWmaWZ0l7yPWp7RSs+II447Raa7F2XbAVITNxXEQpc19IJrswEBxHv+VBHz71tV9YcJDqShXEFThveplTMoFKNIouqDps7z4bbJSpd/yWKi/hpfmXhTXczgFnJRuARtJVN8ayBQW2SiGpP6V1a0De+Cu9iFqkmEgJfsBzqUyH6YtZ+37vvWUBjWMCdmfHTIpeAEml8OSodFagvoniUQ+hlFEZSeagWycDrIrFeprfeLJ/T9/wx/pHedDa91ddLZD5XUtSdSAvcmioNanfc6oCOVIax6H0uT/4wf5Iva9BA7fP0eD9baBkb//aqoiDOuzd4oDUyVxibS3uQKanuQm35FkYgUywgBnUxh+H7hspUBVMTNQNVIHIpDeoXsMVceMWqZ4eWGky4BtDA0R/2Rgzv29IdSUjYDuxflIcMu/bCcBZOHeiPJe6QFcR1R/gQE6vTbWLvx01xb2+R76bwAJnPcnoamb+PlVhV920NleITCojPqPE7dtEMskdzgxhuQgCGHM5zoccjdsYuwCU15ZiO6fww8Q5tAoHSfIUcwnzlmhPq0OdVsZqRX4Pqx+eP1anNcKy7w5Gx6Vci3bi+JpaWUcQh4a7KRzDKlyqEQI/tIaqn2U24cSuMNiRbNrU0UsfXMJ75gRh4fDTKsM7yobxAV2f37PwPeaAcqy66KrAWCar71dbNtzz2+ntakSn9aiM71whfYoH9Ufkg9mnNxrNLPHNM5UBf9ZCz8SQXWwozklu69GTr9Rd6koynRXZeud++aaT8VhZdQRSOyg58rUpF4cdL+y3zp5s1hB+byZeKnxuQXOpBMGbpEqiv3ywZ+oI8sLZQ4glMJhRBJsbPmLuvFsV1PTcwd/hhpAr9Y0u9Bw0/7JbsXSYaLVWweiU/UMffU0IMPjG2iZ+f0zwNZIKGKK+4Gx8i1RHxUld0YsLODlPpnx8iroj30RGBVjBTmw7OzClcnNzFjtFRWDMFx6Ou2Up0xV2XxKXeAdUjrfdkPrr+nisQzZ+sasdx6VsQvfB0iNHfg2CZxz21Q5PdljsPeR1sWOqWv/m/fpN5Sb4+zxK0nIixanl3+1j9leUZPY5XntlLAS2YuRY49F/vR59gEcrP4ZyZsmp2+E78fx6wlNzb+53xTe5MhbubG4zUqYy+tLhwZ3A1prJw77ou0WctlgK/MKgrHUbSvAatRpngCpETrQ6D02OVVvf24LEzxCQW86/jEi0ap1AgXBIIG X-OriginatorOrg: Nvidia.com X-MS-Exchange-CrossTenant-Network-Message-Id: 76aed0b4-7a47-4ecc-fb43-08db93b5bb59 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:14.8045 (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: b7YO9+kzZyULdrW2J0Aaore3W2eoIPOKf6av8YZ1VTvDdnyovarZR2XfWodrtdHH X-MS-Exchange-Transport-CrossTenantHeadersStamped: MN0PR12MB5809 Precedence: bulk List-ID: X-Mailing-List: linux-arm-msm@vger.kernel.org These drivers don't support IOMMU_DOMAIN_DMA, so this commit effectively allows them to support that mode. The prior work to require default_domains makes this safe because every one of these drivers is either compilation incompatible with dma-iommu.c, or already establishing a default_domain. In both cases alloc_domain() will never be called with IOMMU_DOMAIN_DMA for these drivers so it is safe to drop the test. Removing these tests clarifies that the domain allocation path is only about the functionality of a paging domain and has nothing to do with policy of how the paging domain is used for UNMANAGED/DMA/DMA_FQ. Tested-by: Niklas Schnelle Tested-by: Steven Price Tested-by: Marek Szyprowski Tested-by: Nicolin Chen Signed-off-by: Jason Gunthorpe Reviewed-by: Lu Baolu --- drivers/iommu/msm_iommu.c | 7 ++----- drivers/iommu/mtk_iommu_v1.c | 7 ++----- drivers/iommu/omap-iommu.c | 7 ++----- drivers/iommu/s390-iommu.c | 7 ++----- 4 files changed, 8 insertions(+), 20 deletions(-) diff --git a/drivers/iommu/msm_iommu.c b/drivers/iommu/msm_iommu.c index 26ed81cfeee897..a163cee0b7242d 100644 --- a/drivers/iommu/msm_iommu.c +++ b/drivers/iommu/msm_iommu.c @@ -302,13 +302,10 @@ static void __program_context(void __iomem *base, int ctx, SET_M(base, ctx, 1); } -static struct iommu_domain *msm_iommu_domain_alloc(unsigned type) +static struct iommu_domain *msm_iommu_domain_alloc_paging(struct device *dev) { struct msm_priv *priv; - if (type != IOMMU_DOMAIN_UNMANAGED) - return NULL; - priv = kzalloc(sizeof(*priv), GFP_KERNEL); if (!priv) goto fail_nomem; @@ -691,7 +688,7 @@ irqreturn_t msm_iommu_fault_handler(int irq, void *dev_id) static struct iommu_ops msm_iommu_ops = { .identity_domain = &msm_iommu_identity_domain, - .domain_alloc = msm_iommu_domain_alloc, + .domain_alloc_paging = msm_iommu_domain_alloc_paging, .probe_device = msm_iommu_probe_device, .device_group = generic_device_group, .pgsize_bitmap = MSM_IOMMU_PGSIZES, diff --git a/drivers/iommu/mtk_iommu_v1.c b/drivers/iommu/mtk_iommu_v1.c index 7c0c1d50df5f75..67e044c1a7d93b 100644 --- a/drivers/iommu/mtk_iommu_v1.c +++ b/drivers/iommu/mtk_iommu_v1.c @@ -270,13 +270,10 @@ static int mtk_iommu_v1_domain_finalise(struct mtk_iommu_v1_data *data) return 0; } -static struct iommu_domain *mtk_iommu_v1_domain_alloc(unsigned type) +static struct iommu_domain *mtk_iommu_v1_domain_alloc_paging(struct device *dev) { struct mtk_iommu_v1_domain *dom; - if (type != IOMMU_DOMAIN_UNMANAGED) - return NULL; - dom = kzalloc(sizeof(*dom), GFP_KERNEL); if (!dom) return NULL; @@ -585,7 +582,7 @@ static int mtk_iommu_v1_hw_init(const struct mtk_iommu_v1_data *data) static const struct iommu_ops mtk_iommu_v1_ops = { .identity_domain = &mtk_iommu_v1_identity_domain, - .domain_alloc = mtk_iommu_v1_domain_alloc, + .domain_alloc_paging = mtk_iommu_v1_domain_alloc_paging, .probe_device = mtk_iommu_v1_probe_device, .probe_finalize = mtk_iommu_v1_probe_finalize, .release_device = mtk_iommu_v1_release_device, diff --git a/drivers/iommu/omap-iommu.c b/drivers/iommu/omap-iommu.c index 34340ef15241bc..fcf99bd195b32e 100644 --- a/drivers/iommu/omap-iommu.c +++ b/drivers/iommu/omap-iommu.c @@ -1580,13 +1580,10 @@ static struct iommu_domain omap_iommu_identity_domain = { .ops = &omap_iommu_identity_ops, }; -static struct iommu_domain *omap_iommu_domain_alloc(unsigned type) +static struct iommu_domain *omap_iommu_domain_alloc_paging(struct device *dev) { struct omap_iommu_domain *omap_domain; - if (type != IOMMU_DOMAIN_UNMANAGED) - return NULL; - omap_domain = kzalloc(sizeof(*omap_domain), GFP_KERNEL); if (!omap_domain) return NULL; @@ -1748,7 +1745,7 @@ static struct iommu_group *omap_iommu_device_group(struct device *dev) static const struct iommu_ops omap_iommu_ops = { .identity_domain = &omap_iommu_identity_domain, - .domain_alloc = omap_iommu_domain_alloc, + .domain_alloc_paging = omap_iommu_domain_alloc_paging, .probe_device = omap_iommu_probe_device, .release_device = omap_iommu_release_device, .device_group = omap_iommu_device_group, diff --git a/drivers/iommu/s390-iommu.c b/drivers/iommu/s390-iommu.c index f0c867c57a5b9b..5695ad71d60e24 100644 --- a/drivers/iommu/s390-iommu.c +++ b/drivers/iommu/s390-iommu.c @@ -39,13 +39,10 @@ static bool s390_iommu_capable(struct device *dev, enum iommu_cap cap) } } -static struct iommu_domain *s390_domain_alloc(unsigned domain_type) +static struct iommu_domain *s390_domain_alloc_paging(struct device *dev) { struct s390_domain *s390_domain; - if (domain_type != IOMMU_DOMAIN_UNMANAGED) - return NULL; - s390_domain = kzalloc(sizeof(*s390_domain), GFP_KERNEL); if (!s390_domain) return NULL; @@ -447,7 +444,7 @@ void zpci_destroy_iommu(struct zpci_dev *zdev) static const struct iommu_ops s390_iommu_ops = { .default_domain = &s390_iommu_platform_domain, .capable = s390_iommu_capable, - .domain_alloc = s390_domain_alloc, + .domain_alloc_paging = s390_domain_alloc_paging, .probe_device = s390_iommu_probe_device, .release_device = s390_iommu_release_device, .device_group = generic_device_group,