From patchwork Fri Jun 16 19:02:46 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Jason Gunthorpe X-Patchwork-Id: 13283141 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 32EC5C001DE for ; Fri, 16 Jun 2023 19:03:34 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1345868AbjFPTDc (ORCPT ); Fri, 16 Jun 2023 15:03:32 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:42936 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1345666AbjFPTD0 (ORCPT ); Fri, 16 Jun 2023 15:03:26 -0400 Received: from NAM10-BN7-obe.outbound.protection.outlook.com (mail-bn7nam10on2046.outbound.protection.outlook.com [40.107.92.46]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 0CC043AB5; Fri, 16 Jun 2023 12:03:09 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=none; b=lgOTRIFmaQWbuvdM+Yv2hcPi4DGkWUBqiQFysiw3G9FLN+4MuCWGhfJrANLpOgjlF/lHymaITwOfHL+SukChyYQyW8Bbyg1+7Ro/e75cXR57SQOkl0eZ//T1mbG45hG5ovn7H0T6EOwlzfwYNFZT9kPBCy5+dzhzp9k22FkHqStdKykuxMm6ApKjzgeaKY0yshvXpInnRXIFNt7qnVZeYGqcvqxvqHhxob4993r7tJuyG0tIcerWKCXN0eJBeB3a6/wxiV/z8UIRXT8H7caQ3hDUWQ1MsbCHP4tHcc67OWL1O5NjO1ndD/b0+BGqQmv1vrOBLceiTQoAS2X7HAes0A== 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=JplaZHxMiUJROKD+qTnd9x2wQ0YQIobZhUNJsZ+z69o=; b=TslVR7pJ2gqGuj8PMNq8nzTuWaEIG9qlmU60ON/1qQB+JnpzHjCDk/GEw7ll87IS2YXa3c/dt7sMWsNTcscYK2BlmdpOacR2cG5lD7oujC/pZ9mc0shxpZHuFJCiqOEovNfws5Wd7HUQCt2c6Uh2dJcKPbnZLXF6tnnE3sekZfDiwmnzR6F6ti29UAURwghdCk2c3S1puxoPc6CKZIUsMuirRhGrXEYQS/blDIZDWWmP3e0oOe/WrQeRfNnQOVNBmDh4CJUhK0RgzNTyEs8qSJV3tMxPqGYI4HJrNpBjuYIy4Idf9Ccz1vmxYWg5pxykL31+Z0Ujp0JXwwJt3M0Eog== 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=JplaZHxMiUJROKD+qTnd9x2wQ0YQIobZhUNJsZ+z69o=; b=QRznYFwus6PCopc1qnLso6vsRVDhssJbrFoBW7BcqUCDCzuckUeiOB6L25c40gDQFpn0GfDsQ2WZnrvhh3MTPZgsqiKUvUQ8GO3mFfsXtMcasLobE005KyV5yzsRBl2SPpFIqLvy/ayaLRh/TwohOU8zJD7lsudaPMzMYVbipC2XetNPxThWe9+xD4O7vAQF7NHKuk2CkzKGnp6Ir6S+p33JKcnQJpKhrj2dQ4cOonbdNfvE+kNuWGdDisQJabj7QmiK9gKCzQoVdmL31+LLj3yRKiCCUtiA4Y/sUvcFCB7qyxYzr2svXF89scIRZVtCshdkscjr63bAMA73i6rVgg== 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 SJ1PR12MB6051.namprd12.prod.outlook.com (2603:10b6:a03:48a::18) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.6477.37; Fri, 16 Jun 2023 19:02:59 +0000 Received: from LV2PR12MB5869.namprd12.prod.outlook.com ([fe80::f7a7:a561:87e9:5fab]) by LV2PR12MB5869.namprd12.prod.outlook.com ([fe80::f7a7:a561:87e9:5fab%7]) with mapi id 15.20.6477.037; Fri, 16 Jun 2023 19:02:59 +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 v4 17/25] iommu/qcom_iommu: Add an IOMMU_IDENTITIY_DOMAIN Date: Fri, 16 Jun 2023 16:02:46 -0300 Message-Id: <17-v4-874277bde66e+1a9f6-iommu_all_defdom_jgg@nvidia.com> In-Reply-To: <0-v4-874277bde66e+1a9f6-iommu_all_defdom_jgg@nvidia.com> References: X-ClientProxiedBy: MN2PR20CA0054.namprd20.prod.outlook.com (2603:10b6:208:235::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_|SJ1PR12MB6051:EE_ X-MS-Office365-Filtering-Correlation-Id: 72f61003-6088-4c58-3c5f-08db6e9c4b0e X-MS-Exchange-SenderADCheck: 1 X-MS-Exchange-AntiSpam-Relay: 0 X-Microsoft-Antispam: BCL:0; X-Microsoft-Antispam-Message-Info: mbpUyd5bj5mRBJ1CWromeW25uppkt8W7LHUch1TCM9X1t7OBxf/qGQSpTBF+3OvPz6djlT390zKuMA0hlWOtgnLvXRM1jFYIaP5uVXZC1hIWrrweWcZYO2MFsenSl9gbkibExeSIsj7bji3OpKOHqWdwLzC/+6IZVMnnV18Tut4qUeAyhOZhVPY5IKGEVqACNN/VfHREQ3EuFI/8B788hd6FFfgQkKdNO8r7k2oQfcj2EWh+h1spUjZZRYZ7XIsQyXf4AINFADU9c5SfUMW25SsZ862EUhURSH6fbuig3ZxPYeoJVmvwaJx4X9d/WpfpmrdGNU5ZDrQK1fWCxg2TP4H0BGV959TabkOjVyt/jPLHzISPkz3z7afXnF4LDSYfkkcanoMV65xOv49p8KcHx6+fNGmA29qvum00CpdWw66LWfmedHMmzUgMAMmuBQwhL9OvYwoZl14dweRVyxIY4zDrTLLg3o0rumyl7eVeAiMkeI0knZYfQp4lT7R2WXPtQV+fpt1s1YhtuJMqHs21AW7ohnRVWp9q0IwQilcXZVfkr//fdsyGfTsezy2PrvWSkkdq5xOqrXEhi92SIIjXzj/Xpt6Z7XmmqR4EO48Aj8E= 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)(366004)(346002)(39860400002)(136003)(376002)(451199021)(2906002)(83380400001)(2616005)(36756003)(86362001)(921005)(38100700002)(8676002)(8936002)(5660300002)(107886003)(66556008)(316002)(478600001)(66476007)(66946007)(4326008)(6666004)(6486002)(186003)(7416002)(6506007)(54906003)(7406005)(110136005)(41300700001)(26005)(6512007);DIR:OUT;SFP:1101; X-MS-Exchange-AntiSpam-MessageData-ChunkCount: 1 X-MS-Exchange-AntiSpam-MessageData-0: PKCEE4valAP33d4nw3GQMpAVppM2vKSKObW2xRijtBqlxijqMsndDNmdbPUdlS22eNSXnq98RZEXPxzSAhxENlP6A2mhltrwxWRoEOcHEykB5j1m4rkEra/0/iWOXatwnhc6v7XX17tIl2RVLgCTiUHg8QuhSQbZ6BePp6ha0l5eH/SBtAuOOhqM+w1kc9MpegqTN2NlCrbwpDJvbcMwk1isLS2yJ2zVNfut/g/bSGzIIS78USX71IcF0wS58KHUxkn5JQ0fii8Bmmh/SPVEBQwx5wfGrRtLRTiA6iJ68iDCEgCF/MN0sh3xdPptj3CfDXaEYgeQnhkccP7Y/WzkAQEkQV8acoea1p5bL+SmsfMjzETsE8nYcOEvgdKtK3820vYNgi9nPq+A7vpd2LGp+E/ErUIsGFlMirW53yAMr5EcKCn4TfW600oc4sm0KLSteclZl1qDkZ7syDywKbr48cQ3C5815IBFFFaYwUVyalYjdfBFFDklOEwRLVLByqSxgDmpfJt6fbjhQ/IngAVYjonJG1xVvc0/4YWAeDfN5u9fdffoL6FpiR4p3sbWERksqLNXJp8dFjneVgFcmk1WZMRYZCylfxTB2JJ0//dvhQWJY7p9zd55xYU88e++BT5hXHfCJCw7qzwktU37sETiIR5Vp8cAWbPGhePo4zFp7J1HOWLLtVjlC9wyrs245RNaH/Ev6jjrqkc3HEyeZrOYeKXuv721aGdLo/PZSxnzLC799Gk7GMoEOjB9XOzhr0ID25KtC0sCVYlBqsHZa/UK3fg4YKHkxWCxiSGnNG5mJEmLKlJcq4z+ZubRtsI+QFImz+G1p9gQVrzT1P0zK2Wvj5dDDO5XDQSnxcXFNUNzuY3XDRIKHxzIAE4x6XmrDQdni55jf5whh1Uq3wTdxvK4+OE9uPpmDwMdzP3cFQoHeDIt7cUdLqjRsLS78YZ8dewJixoQG5mlR16d0wARc9GqSF6N810oVXHqxcATnIj3XuIxTkwRnpG2HVIMvwqEc/502P+RAJjW4+oOk0BY6NUsosojRwDtsQw6+OP5teQnALDDIcPrNXPoVpLTr/4FHoOxxMiwdm35s5ZZzXD9A3x3fT3PUJjEpHN4+lbnWN0GOunS3ak6DjnC9LedvEHt6Uj+jplnZKcONAwfc0HTJBpyEu9pfphBmCM7/2yYRgUf+gwfuD4g2fgWKSgRLt47cj7MEBjVUwEl+x3mTeUDk1/Tzd/4sm6StFLwKXMw5RNMSTIhJbJxBOAO//17hcOJjziewN70khosBFubFxzDZwIDJKECi0kiKVb1ZhEIsOZal3wuZm6uq1Lz/LcDP3+5dAnJo/Y4ICDyulCqp7Dt33TnXQIyJa4fAssfdwf1iAiDrZ9WS1lds+uYmTC14QkIWYVWtIk9fCLwauMa6GjLe+LWUqjTSNTZtii/dI6ZTTSdJB+vWEDhzCjI2krjUTLuA1+64KAy5VjvpI5o3ac7WVHhrct0TwcgLZj5AKs2RLTYIbjsfWctHPbx8REINIe0RhBaUYV1QESX+N2s8I3V24FKLxtUn8vxWTGobY3jSTC6CJ3L7FcmH/A3YUfAt9nClDft X-OriginatorOrg: Nvidia.com X-MS-Exchange-CrossTenant-Network-Message-Id: 72f61003-6088-4c58-3c5f-08db6e9c4b0e X-MS-Exchange-CrossTenant-AuthSource: LV2PR12MB5869.namprd12.prod.outlook.com X-MS-Exchange-CrossTenant-AuthAs: Internal X-MS-Exchange-CrossTenant-OriginalArrivalTime: 16 Jun 2023 19:02:55.8024 (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: it+Nk831SPDoQ4rSqGeUUoaboc6VOf4zj56+vJBJY8/zib/sdrwMxDtXeuJi31Cn X-MS-Exchange-Transport-CrossTenantHeadersStamped: SJ1PR12MB6051 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 --- 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,