From patchwork Fri Jun 9 19:56:05 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Jason Gunthorpe X-Patchwork-Id: 13274410 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 25997C7EE2E for ; Fri, 9 Jun 2023 19:58:30 +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=dcZdKtfb7ZbTUl EIIZHHIwKw+7mbsYwT8TW3hl1lLB9xyNrKuBtC1xtw9FXFwMT/IK1VMwDc7C7VRZnwq/nZJFgpjyZ MMlIKfSejcdvFr5S6Ze2CGpqG4+zl7QIgKxOMczuZeiSZgPxFTIGXkJiBx5F9rCTAiOe8xCAn7Ksz SsjKvf23SARZzAmMsZIdFj7p2rfw6kCMXPOS62QzO+CsiTfCTj8+6+fiGUWmTDhoP/8GjaQnt5iwe qDFOW+Kow73sHVUZmb1lTzkoNWEcnzavhozU62LqeFEofkVUKVDHrE4pEM9lVUA3rVAOU96Izg+0D 2kpZAY3dumYxX+I+iO2Q==; Received: from localhost ([::1] helo=bombadil.infradead.org) by bombadil.infradead.org with esmtp (Exim 4.96 #2 (Red Hat Linux)) id 1q7iFC-00E5t1-1P; Fri, 09 Jun 2023 19:57:58 +0000 Received: from mail-dm6nam12on20619.outbound.protection.outlook.com ([2a01:111:f400:fe59::619] helo=NAM12-DM6-obe.outbound.protection.outlook.com) by bombadil.infradead.org with esmtps (Exim 4.96 #2 (Red Hat Linux)) id 1q7iDt-00E4Rz-1y; Fri, 09 Jun 2023 19:56:40 +0000 ARC-Seal: i=1; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=none; b=DUhaSW6FLAKsF22ZQkxvR5mfvdwDD7ntvIPEJu1oO+QchS15kTr9eMZPB9YWc0e5jT0SpbCZ/s82CbfJkVXUgjKYssxJe+MwHG/deiNWMJSVHxfl3DirXjVf1c27JqyFk+PFFHqZTTTt7v5EzOLRhPRh6ofwyUxmnV2w0nGB6nIFHtjx8yOq3WAnzvxUCawvC7GjCG4qlz9Nqt9bnrmFG6+H3f6xN+mWbL9gUPaMFjYAUSwfxIhkrwI/pSEwixr36xOGfPiUhbKlVnccdHO7aPpdln1p2V5WdR7GgsOF7faTARYVFu+J9obkVXBukhRjumrWd0JpvhQN4Bx3eRjaBw== 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=YsGO0DZcsA8XNwY1re1ayIHExIBXGVVTn5Xt6oBRUEurDDvJvg7cfRnzk3l/gEaB9JlO8daGCi2ERV3zJkLFQOGxdI1AWALZLHFIU0B/s0/7enI8XDjJfSM78HEuKrAwb6Y6ZiSq82bHrOS+9OEjqmMo06GUdo6s6aD8TJSpKlYwRfAWRvCga5gborwHcWS4PjGfM+2P7aCXUhK5gPdtMfHRsOYioCE70QEDn7KlH/2CyeGDSpzyuSVi95bsTJCYLifaQcT2qCCEIx67tlbOVyRApcpNyrFnJhLQu7yvHxqlUFLSjmOlZEQX03vHYTxaqiIF50Ux72Om7x5uvk3dmQ== 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=SYWfI2E08V0MZD2zP5Z2khMoHV/VlfnS4F1b3JzKvT0MR3mY/p79+QvoFPcppaQmFvnFxS4aD3/zGOcKAx6ps3KqYixKxueSrFsnJzwPYPNrgqVpoGxe19cSmeAtv1+abHeEpaU4MhsttGjAdLSlcZRb3BFRf0GgoGCmFRnazGShSR5wJBQhXOSd6EY31oM2QGWTZ1kkZZbXIKpcs0ARMYWSQByol1AxAXOXGQrUebawInJt2vF7ULWa0yom6b7rVXYExtLrYe5DYhQv9hH6/L1pQp6M27SXTHOpMVaCT7Puui68TFBzR2PA1lPZihvFh/EjfvmW2tQz3HyqdQCaDw== 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 MN0PR12MB5785.namprd12.prod.outlook.com (2603:10b6:208:374::17) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.6455.36; Fri, 9 Jun 2023 19:56:24 +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.6455.030; Fri, 9 Jun 2023 19:56:24 +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 v3 17/25] iommu/qcom_iommu: Add an IOMMU_IDENTITIY_DOMAIN Date: Fri, 9 Jun 2023 16:56:05 -0300 Message-Id: <17-v3-89830a6c7841+43d-iommu_all_defdom_jgg@nvidia.com> In-Reply-To: <0-v3-89830a6c7841+43d-iommu_all_defdom_jgg@nvidia.com> References: X-ClientProxiedBy: BY3PR05CA0049.namprd05.prod.outlook.com (2603:10b6:a03:39b::24) To LV2PR12MB5869.namprd12.prod.outlook.com (2603:10b6:408:176::16) MIME-Version: 1.0 X-MS-PublicTrafficType: Email X-MS-TrafficTypeDiagnostic: LV2PR12MB5869:EE_|MN0PR12MB5785:EE_ X-MS-Office365-Filtering-Correlation-Id: 2d044f47-6379-4147-eb4f-08db69239947 X-MS-Exchange-SenderADCheck: 1 X-MS-Exchange-AntiSpam-Relay: 0 X-Microsoft-Antispam: BCL:0; X-Microsoft-Antispam-Message-Info: UhVWq6Ui7oIi60oQfbS3VmDpT776EfAmTjgZZHAvyaT6H6iJuQYGo/MOxHOyJ+3H9gQOZ42q7OcSLGyvmVvlR/OMVUb9sDLO5sXkrdyfAtCAbAZQ5nVF99K5q+A3VaBr/e2mx8xd4NGoqe1uBltCY8cNySVJSbtFrB6jRsqNT8UZz4jALFUYvGqwgV/4XZtvtZD1xKUF6plawjZVZRRSgovWNf3KA6kpYdkNV0N9DFJYuZuY0HpqS6kE65uZv4IOuX/CGb/F9lLXjBdaqYmMLkXpRO1JMXvEW6OnZw4XkEPZzlVdPHl0MfC4RMkR4C2JF6xXefoAE4zl+kB2M6VCjgYvtLXQ95MfZiXTizXaJIRT2hoZlULYXtT/nG6GAhRbWU+2ekNrDyMSnG69qNBe8KCSd1TtGqeTBqgMB6z22scJZMEhLkR8yNNWhncI+2AM7rRvHxG7K4UskwM9FnPBZh3lpm4rNuPtCoOUegtH4zYSH27EqcxNr/9BIDX1Ec605AlzE1RgSHRBmsz1A+Wz/k0/OrvXHQp+lvrJYq/aigoq6woaI11QxVqR9nvcC4QrQSgUpFHDQJH3Tmv55CQI1SkjTHAEt3a+hmA9vS0/mVE= 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)(136003)(39860400002)(346002)(366004)(376002)(451199021)(83380400001)(7416002)(7406005)(110136005)(478600001)(8676002)(8936002)(4326008)(86362001)(66476007)(66946007)(921005)(66556008)(5660300002)(38100700002)(41300700001)(316002)(6666004)(6486002)(36756003)(2906002)(54906003)(6512007)(107886003)(186003)(26005)(6506007)(2616005);DIR:OUT;SFP:1101; X-MS-Exchange-AntiSpam-MessageData-ChunkCount: 1 X-MS-Exchange-AntiSpam-MessageData-0: v5cpA/R4ovTaXYcwTZ0htqcineiQNZ9+zAevzNrLhLu39FPT0o7V79yBTsYyFIqxZ0u3hIG14lDxiH97L4h4mokYJ/wgfqTfxMbAKqeZ69e+SOcQXTVwtjAFxh5TmJteGiL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GMRlUDONT0KyrS0ltxdxHmVpj2FRrSMS8BMMPSEb//t4NKIX05dAGpoitO8e55ZyA2OoWrMgi+AV5waKNbm8wlBXUfeWNB1enE4wJ+S5SenCfjtBBSdeIn2U6ZcA6whiRnzztfLVCGq6dyaQE/QSwjogECQl4bw9i0XuIuEKnDI+oOaQJSOYBdpgzWo0IgR6Jpe43NRb5cYcR/E5TrJCAqPFuZrpOJLzjtOnl11f7ULZp4AQIEq75ubOZemMTESM5fEyf5UvTvBfloaoUjNZ2o/LPaTaQW+hMU+7DaPk2UEA7oVOd/n68OGV5Qd6/cSqwkVaat94zKMzVZYOpppKwstwu3Xoynpm08k7b317SDKwlj/yJ3oiNQju6AKwAidDIl6tsR X-OriginatorOrg: Nvidia.com X-MS-Exchange-CrossTenant-Network-Message-Id: 2d044f47-6379-4147-eb4f-08db69239947 X-MS-Exchange-CrossTenant-AuthSource: LV2PR12MB5869.namprd12.prod.outlook.com X-MS-Exchange-CrossTenant-AuthAs: Internal X-MS-Exchange-CrossTenant-OriginalArrivalTime: 09 Jun 2023 19:56:22.1349 (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: weLx1i3Iq+qh9NLdHRht027kguqogtdFSq1+rtL1PePc/rRzW0IY/nbsgnstUyp/ X-MS-Exchange-Transport-CrossTenantHeadersStamped: MN0PR12MB5785 X-CRM114-Version: 20100106-BlameMichelson ( TRE 0.8.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20230609_125637_692348_A3D1F1D8 X-CRM114-Status: GOOD ( 13.47 ) 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,