From patchwork Mon Jul 24 17:22: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: 13325067 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 D8204C001DF for ; Mon, 24 Jul 2023 17:25:20 +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=pis82y5dgkQWSYVbH/ZzSLifKHxuqYCLEqEoKpeORnI=; b=qOFP7nYNlcifOc 1bpF/VGKuryvA3FFQtuynn+oZwxgm4ezfmJUVqNWRMoCZ/3L89l1B/BiiR1nT6SNwKltWY7f9Ff3+ 0Lo2dlwx4rCXTOepN+IUgKH/MpEnxqCOfL5TU5BpYFTq/ZydloqJcXSUnxUSjz5M/LRXBfp2Kj1OU bXXGnIHGTfhO7mTFCk06PYZeVP7dJJ1OJZJvhYubYZcrtfch8/0Ul+4rp8HTW+zn6gVt3a4oWdamC Y4S9RAo2zZWi4sv29+Ayh4Iylju33iiizbnYVNcv3jpaxjj4DFSvwCOkKAs9iDZPIw/aHBJNlXQSt 6R5dYcGbtPYO09CPtaXg==; Received: from localhost ([::1] helo=bombadil.infradead.org) by bombadil.infradead.org with esmtp (Exim 4.96 #2 (Red Hat Linux)) id 1qNzIz-0052Jm-0q; Mon, 24 Jul 2023 17:25:09 +0000 Received: from mail-mw2nam04on20605.outbound.protection.outlook.com ([2a01:111:f400:7e8c::605] helo=NAM04-MW2-obe.outbound.protection.outlook.com) by bombadil.infradead.org with esmtps (Exim 4.96 #2 (Red Hat Linux)) id 1qNzGd-005096-1h; Mon, 24 Jul 2023 17:22:45 +0000 ARC-Seal: i=1; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=none; b=AKTqdWxnaWGWIfvfd0ZblD8ksY6xuOYhyu9V4g/1OnDV3h5uz04mMke0GbmuKhl2jeetdp9XfgsgRmEB8yg+OhftY4TvUE6BSPD9gyDOJPM9Hh7yp5nVZZHUF4QWXHX15IlDoCWkIHMAqr5iOO/YX/2vk4QKr0awl/AIE4geug9EFABQ7Ag26xp+zUJZZatWK6V1fD9QNeXuF7/3yMkpr7tinUiOCOawVIxEBC4Wa7H3U1aJNh2mAUNlO76CpP0VM6z98DgI8aTjrmPcV0Q7pVKRFB0PzQQmGIWOs2Ez5xe+101WiBP1xaQ8d2KLO2gLUhJyQY8YAwdnCqGhLuNtwg== 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=in6joumP4T9PJ/Zm3F4gwx6DiyGqPKh/ZEpIN97DBICvRfLPXYMFmw7Jp0/bIEJjfqejmbAXU6lbVqHYngXG41WvVFfsRUCW+nR1WpAbN3r2MOkonR3quKIoasjnNz+GU+nGS1X2Wf3NteXWoAmc+i+QsVahXbxBd46i/yObpH446vsXlOoniqbH5/jWNrF4kpUW71ScrHECXBRzLQkokFWT65I9K26bFNX2IrzNLsR24DuhmOCiAe8jt2xjCgCkYq0lLPgopP/obtobY54G1Pozsg5Wv9Xq+eI0DHoPtQWuHG7KX/QJocsPIYNA3jNBXGmYUKGYHrh3DMhkMoeknw== 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=Ax/8ecXdTo2xBgcZ02lnb5U8yH+X292I77q8dJljakTDrpObTbMPoCeuadqSe2fPPIh29up1egWGQBvn2mkyfsrOlDuTzhIDY9+fmLIdkOZNPKKGLrDPQcUUjhMsmQGBL17bShu4YeNt5PIPuxz0ve9fUexrAnSeOu4sWMpvs4QPDgKzNPF03HdemRl5CDPxeDSxb9S81AKVRkekCDfuJXab1+KyrCJvdSxM4YnN1OccOabSQIM606O2cibNXenXU7Eh3z75yFsfQY9Qvq89yzKTzF8hsQsmAWLHlBSZkcQYL1V2Bjd+XXKjbhEowLB7QmxWWOMBBQMS/yTqhUpZOg== 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 CH0PR12MB5252.namprd12.prod.outlook.com (2603:10b6:610:d3::24) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.6609.32; Mon, 24 Jul 2023 17:22:28 +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.6609.032; Mon, 24 Jul 2023 17:22:28 +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 v5 17/25] iommu/qcom_iommu: Add an IOMMU_IDENTITIY_DOMAIN Date: Mon, 24 Jul 2023 14:22:07 -0300 Message-ID: <17-v5-d0a204c678c7+3d16a-iommu_all_defdom_jgg@nvidia.com> In-Reply-To: <0-v5-d0a204c678c7+3d16a-iommu_all_defdom_jgg@nvidia.com> References: X-ClientProxiedBy: MN2PR22CA0027.namprd22.prod.outlook.com (2603:10b6:208:238::32) To LV2PR12MB5869.namprd12.prod.outlook.com (2603:10b6:408:176::16) MIME-Version: 1.0 X-MS-PublicTrafficType: Email X-MS-TrafficTypeDiagnostic: LV2PR12MB5869:EE_|CH0PR12MB5252:EE_ X-MS-Office365-Filtering-Correlation-Id: f8f2ae72-57c9-41e5-fc2a-08db8c6a8988 X-MS-Exchange-SenderADCheck: 1 X-MS-Exchange-AntiSpam-Relay: 0 X-Microsoft-Antispam: BCL:0; X-Microsoft-Antispam-Message-Info: Z9cm2tRL2mm6ZVT60zv3q8hcUAxShBB0B3C6DcgsntCTqeA4eK3tHoqIC0yjvwlhRitI7fNQd9FYzfD4F75v5DhWIqt9+w2nCOEVt6WzXKJscBfy4Xfu1o/yfLQzSeNNrKgB5j91mwy+RCmK7rFwWd32LemD+GwIh8WtCQxFcP0DAcklLLF/pSMY6d3623B+qRbGnvrmHjTvRiTQ7wSVNUQ6syRbzJWRqGnL3RRQwlLUN6o8iXwNrCWfTwaRpEgUG42bnm2cJG0qmRfHQ9M7P5bs/63lmZ0sEIjNlFHyjefX7eQP7YJi5yUUYeaALS20ML0XWAl1UcKCrqeC278QlUGYax9EbFH7sG1JFa2nX8n3J+bSWKal0rPPbWCNg/X0yNJmfziKc3oBi/kLteijN/K2EL0x+Q/4fU6wqb5wsCmzW63bWh8tSoDAqLVp0zwRjEo1V1xVcBuWygcPjQk7bhHUz/VuUUwyNVLHS6XztgpRogzrd8zNrYOtbgAqJ8Qo3MdS5LguSfl1t1erEB52FULZJWcPLOrMbKWe295qu/XtUyu2p4UbVSX5o4PF9JK+QT0qgw+kj/+oxCJN2skHwmrmSnDtL9aNjNEcMd7XEDE= 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)(376002)(346002)(396003)(136003)(39860400002)(366004)(451199021)(2906002)(2616005)(83380400001)(4326008)(316002)(6512007)(66476007)(66556008)(66946007)(107886003)(41300700001)(6486002)(36756003)(478600001)(6666004)(86362001)(110136005)(54906003)(921005)(38100700002)(186003)(7406005)(7416002)(8676002)(8936002)(6506007)(5660300002)(26005);DIR:OUT;SFP:1101; X-MS-Exchange-AntiSpam-MessageData-ChunkCount: 1 X-MS-Exchange-AntiSpam-MessageData-0: 5OoJsfb9nu6T1aNTnkfxzAOMSxIIVlSu159uTB98TPeaWWFjiCA/VVG5K9e6v7hefcqoF3vag6Aoh6R4tFCuoQvehMyCKswyimBRZeWiaE5DGco5lofUiAkbUkgzOS1lgprmm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+EQGveH+jNdoHtzvjAio69wkWkZBAhcxbUfIWKWGdwLWAeA9gt5t1MPCnX9HnDZfYB2hSm8SZIfoY/XwozmN/5cmY5O592ZJjRAO2JxA/K7Y+uCXT/f52pQjQ237Q0ckfNvJS948iA8CVwcO4EKOA+MAP3GoV16S8OZRc15ZH7RAtWaZ6wyH5cshrv7zBFDhx8YsnMiSCBBUJS+wYX0cdn8hLapWlvA5x93amCXaiBN7ir0XMobsz7Fqp1AazFVaFH/ZNy2ZrNhyrscbBZHazmMioZMIn4B5E22EZ4CruLjJJ5fEyL4wL8+EFOxAEW6SzTtQEjzJsH+jOS+R1Cbpat9yeiYL1R+4ldxtoxHq/Y7eROjLHSx4l4lTVQpY/qA X-OriginatorOrg: Nvidia.com X-MS-Exchange-CrossTenant-Network-Message-Id: f8f2ae72-57c9-41e5-fc2a-08db8c6a8988 X-MS-Exchange-CrossTenant-AuthSource: LV2PR12MB5869.namprd12.prod.outlook.com X-MS-Exchange-CrossTenant-AuthAs: Internal X-MS-Exchange-CrossTenant-OriginalArrivalTime: 24 Jul 2023 17:22:20.6306 (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: RF46/EyTnGLqQn+sqaTimN/aSWpcsperwBj34XEmm+627NZW5QzpE7jN13hHEgM1 X-MS-Exchange-Transport-CrossTenantHeadersStamped: CH0PR12MB5252 X-CRM114-Version: 20100106-BlameMichelson ( TRE 0.8.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20230724_102243_607561_17E16B2F X-CRM114-Status: GOOD ( 13.23 ) X-BeenThere: linux-rockchip@lists.infradead.org X-Mailman-Version: 2.1.34 Precedence: list List-Id: Upstream kernel work for Rockchip platforms List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Sender: "Linux-rockchip" Errors-To: linux-rockchip-bounces+linux-rockchip=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,