From patchwork Tue May 16 00:00:50 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Jason Gunthorpe X-Patchwork-Id: 13242401 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from bombadil.infradead.org (bombadil.infradead.org [198.137.202.133]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.lore.kernel.org (Postfix) with ESMTPS id A9DA2C7EE26 for ; Tue, 16 May 2023 00:01:55 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=lists.infradead.org; s=bombadil.20210309; h=Sender: Content-Transfer-Encoding:Content-Type:List-Subscribe:List-Help:List-Post: List-Archive:List-Unsubscribe:List-Id:MIME-Version:References:In-Reply-To: Message-Id:Date:Subject:Cc:To:From:Reply-To:Content-ID:Content-Description: Resent-Date:Resent-From:Resent-Sender:Resent-To:Resent-Cc:Resent-Message-ID: List-Owner; bh=ayoa6h1rEGtun6obvTk532DJ9TnEZGiSykKOFhuHF7c=; b=2l4+7iP2CWfLPo hRwQCA5gyntZIG19EjKeB7n3RkcGJyaoCLMUmTDoNlx9r8T2qbxVieFZr3KG9bONBT82/gpXfddku cax03gGr8+EhtFQeqoDZJrMqYMHEyDlTRCNAiEP6wfSho61fZb6jsujCiq8ENV1LCcXVxfMT2yZmo 01eb+zA5WQ+uezkWBRjn5YPHoSrVkNMMvAgjZWWWiBjsTNr/K/hcQ2QXVEel3Y+uew/49VDDRI0YP p0YMxmhruhUtS3PDSTNg2yFuSDxRhs3UtO1WvWMiYFbNQ0KRks+rUPRIxiXgX8HBeV0i5kEPaq5PN XymW42ElXrNKnjaNS9pQ==; Received: from localhost ([::1] helo=bombadil.infradead.org) by bombadil.infradead.org with esmtp (Exim 4.96 #2 (Red Hat Linux)) id 1pyi87-003qJm-0m; Tue, 16 May 2023 00:01:27 +0000 Received: from mail-bn8nam11on20600.outbound.protection.outlook.com ([2a01:111:f400:7eae::600] helo=NAM11-BN8-obe.outbound.protection.outlook.com) by bombadil.infradead.org with esmtps (Exim 4.96 #2 (Red Hat Linux)) id 1pyi7v-003q3k-0X; Tue, 16 May 2023 00:01:16 +0000 ARC-Seal: i=1; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=none; b=ZM73a/qW2BYzB0Hnsv3mWDoZZDMheH7ETzyA22Z5ty2PL/aRQXTGLc6U4dsDcgZ7uaDd6o6Xg5JZQKVcbzrDYr+Xwyr4eSIU2XwyykQAdw1Apd6wmW+ZKMdwpKcBIpmce1Yb3qTwbW2+70T/RzW7OBzwpltzS1bgArRdfqmdUtO9UR2szD/VEBGHq9dbgva510mR2HFJlyINFY/6vQFLWikyPcACSrFZHJbynBlStxUz+jYGZpsZ7U42cfMU9Hr4NKKSezcf29eai6LHGjWVEBAotgCkgAfHq7bXZMYpdRCt30sLdzujcktMABv/TWqRBOm0Snaa4QN12kcEDdeLAA== 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=JP2yqzCWb+T+Rg4yOqjTvz+z1m6mK7YlTyjbYLS9+D1ciOAHq1iIm9myGG7hyf53gi6P75/EcrwHLD2ofR2l7P8+VMlmdi1FXVzMSE8c2tHpv0JW2D71MvjW5PBdTvOSXX41EzK0eCfI1P6Lhn17F5tvrkhJQBF7Q53q8odQPKGSNpInjT7xZUDGdldALdUho42vKoXpZ6n/Z7Njqyz2fIM59DnjqaJMwIMKQEznLMz+rn/515tjCGtmaPR2gbqFqNyfT86eb/t774oTuTYuv23UmABStTw7kMtDvtce51zo8+9aQ9vhX2THxYXYiELGT+k3Tf2ZzSsWApoNhB9bwg== 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=HLlUQD0zDTN6fbvMWaXg1wFcp/aErGluIXYr0KXocRuJaAkCaJyyq/z7dlP/qVfZ7wxH3dmIlPs0Y2yY0sUiiIDxeJZrYKoIeeLfHxcXsUJ+Gq/VWJmrxaJUwtsWltqvSUkBqrJrSg0o84Jo3NOg9edZ5nSP/qa8hD1Gv7BXLoC+j7LvoG34nGXcmDR4S4HEDAGI1GBhEvUkW9HplFVMBrpD9YELfZDPIkjp+rAcS79x/DOopAwgcl1Po5w1CPf3+hUL+/u4MbPYKAhZ/+WFg1Dkm+/Sw+2IyqvbWw1WKB7R28iW9Whm8XgvrEASOVscVH7VtI9PP/RHHKFmSfS1oA== 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 PH7PR12MB6786.namprd12.prod.outlook.com (2603:10b6:510:1ac::18) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.6387.30; Tue, 16 May 2023 00:01:03 +0000 Received: from LV2PR12MB5869.namprd12.prod.outlook.com ([fe80::f7a7:a561:87e9:5fab]) by LV2PR12MB5869.namprd12.prod.outlook.com ([fe80::f7a7:a561:87e9:5fab%6]) with mapi id 15.20.6387.030; Tue, 16 May 2023 00:01:03 +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, Marek Szyprowski , 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 , Nicolin Chen , Niklas Schnelle , Steven Price , Thierry Reding Subject: [PATCH v2 17/25] iommu/qcom_iommu: Add an IOMMU_IDENTITIY_DOMAIN Date: Mon, 15 May 2023 21:00:50 -0300 Message-Id: <17-v2-8d1dc464eac9+10f-iommu_all_defdom_jgg@nvidia.com> In-Reply-To: <0-v2-8d1dc464eac9+10f-iommu_all_defdom_jgg@nvidia.com> References: X-ClientProxiedBy: MN2PR15CA0049.namprd15.prod.outlook.com (2603:10b6:208:237::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_|PH7PR12MB6786:EE_ X-MS-Office365-Filtering-Correlation-Id: 7e237edf-cdec-43f8-0b09-08db55a0a232 X-MS-Exchange-SenderADCheck: 1 X-MS-Exchange-AntiSpam-Relay: 0 X-Microsoft-Antispam: BCL:0; X-Microsoft-Antispam-Message-Info: orLASM+ABEWLxfla6fGFA6BwZNVY7wk0zsAaFrhgSCF/8IYSxL05WW19xEEROmZphqi4wBIQQHzZI1mUEFchCgSYqmBYCr8o1ts7v8FfSyud5AHkcY699Lcq5l6tzjSVS2x4GuDyWExRBZShAM5ILS2BTkhAwqU+VTt8FV0QSc4IWfewEphOH8xmHrt5QR8e4CHfp+MJza5nV0SA8Mws97MG/jN0Hj5FXD85SW9zXD8Iu5XFcMCx2w49VP6qZnE2mpGuAzHhnfbuEE/mMCU2k96/VvdBTF0iUwALSnE3IARQ/6h2I3sZrVIE4okWN6tuX3U97bN0qLrPwkzsNaHUF4X0l8ekMrNJA34s6jHSryS1k6wSOc97/ZPP+8r4xMXW1NttyAYD27s6/9TDc0sOHDLUNBlgpAgSiBlJltxiEJO1v1aDMkw9SQEzZ3LDyc8CY1nRp1dvlaVjgG8VWu7at0Vh30Q1H6xfhoNgst3r/j40G3Mt8RibK3p2hFo5b5kKXYRzH0L9wTRT2teil+wFWUbzEwK3x9UjHfK24HGjSKOVvvfqrqgZAdJJW0GSE2manvXpOU6vY1Ar36DtofUzz9llfbxB7WLJw7aLG7k2w+g= 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)(136003)(396003)(376002)(366004)(451199021)(83380400001)(4326008)(41300700001)(316002)(2906002)(921005)(36756003)(38100700002)(6512007)(6506007)(26005)(6486002)(478600001)(107886003)(66556008)(66946007)(66476007)(2616005)(86362001)(5660300002)(8936002)(8676002)(110136005)(54906003)(7416002)(7406005)(186003)(6666004);DIR:OUT;SFP:1101; X-MS-Exchange-AntiSpam-MessageData-ChunkCount: 1 X-MS-Exchange-AntiSpam-MessageData-0: sF33eyK/zgi2IRQN+dK2wi4sfDsXTP+9j7qXmlOgGom6XBeQUvlgAsWq13D+0DJvfEfkyk0Iz5bCDO3OydxjQCL/UNPicTkiIRaxFecV6o/Gcr8S+wjJxL8TUPM790W9voWs/A1YVZvyEq9gAeyRrWIZ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8q+MeL3Ecller01bvL3AGzuTPfbzwH/lHuT/BCybq8KWqzGItmY7hs5icTGXJLv+CS0U7JXfgSBZKKiqYmW8mEaloxLzO/szr8KX7usasbDF89+GBqxARZuocvN9NvuHK/cUC7WHtXbwx3+lJO3GnV2HG3nQO+WjmmqFFMV2q8h35flvu8eX0Tmx6e4ZswStO5ij8r/j8Fq4JMmVo5+IQOUmzoU+EtIJojtHGNpGYL9zf4/gpyACAZb5kfC4Qros14cb5UoDNymibpTdq9v8xq+Swj9Gnvp0tCqJUoSPii2BXXfz0+3/28Bg1Bmol/WNRU4eHFY0KY86rd1o+LSqrE7zJsjS36l9TzlaS5tRm9Drd+wR5Df96 X-OriginatorOrg: Nvidia.com X-MS-Exchange-CrossTenant-Network-Message-Id: 7e237edf-cdec-43f8-0b09-08db55a0a232 X-MS-Exchange-CrossTenant-AuthSource: LV2PR12MB5869.namprd12.prod.outlook.com X-MS-Exchange-CrossTenant-AuthAs: Internal X-MS-Exchange-CrossTenant-OriginalArrivalTime: 16 May 2023 00:01:01.0198 (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: GszyChCSFhO5fbvuOIYKTcv2TAxw4Vog8OyKxrtRccEipQqyKXFq7YZ5JHIloiVC X-MS-Exchange-Transport-CrossTenantHeadersStamped: PH7PR12MB6786 X-CRM114-Version: 20100106-BlameMichelson ( TRE 0.8.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20230515_170115_220563_6855DBA8 X-CRM114-Status: GOOD ( 13.62 ) X-BeenThere: linux-arm-kernel@lists.infradead.org X-Mailman-Version: 2.1.34 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Sender: "linux-arm-kernel" Errors-To: linux-arm-kernel-bounces+linux-arm-kernel=archiver.kernel.org@lists.infradead.org This brings back the ops->detach_dev() code that commit 1b932ceddd19 ("iommu: Remove detach_dev callbacks") deleted and turns it into an IDENTITY domain. 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,