From patchwork Wed Feb 1 12:53:16 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Jean-Philippe Brucker X-Patchwork-Id: 13124409 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 5096FC05027 for ; Wed, 1 Feb 2023 14:27:45 +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=kRIxEB4keWI8UnhURUOch9LBNCx0E59oYHfZ/5pPOzc=; b=Zpb1RoYC6KrRNl G8e6+3Q+gMC64vxECMsJgeIqbxg6NuDujRKkqfvUc+g4aqRiQMF9ioI73lQECseFQJufp5GL6HJl/ t6UcPuBHga62YL0izuseSjWsXhwsaYGNpzHuGxgp7UweLpZFFG1MZnnNF/ccZtw+OpFyMIMDZxeTx 06YTQs9YOcbM9Jyau1GvXDZ9eU+EI0x3jhMK8op08FrW/ps7C1BB/dgQlYh96SD5aPjHwVx9kkc/V 44Vx32DzdSv4GHKpc8b/NsHKH8duMaWvLhJ1dFpUzWWvX8yKhr8/CCDNOtCV0XAku7tChSDirTYop C02T+U8WB8qh4D0K+f/g==; Received: from localhost ([::1] helo=bombadil.infradead.org) by bombadil.infradead.org with esmtp (Exim 4.94.2 #2 (Red Hat Linux)) id 1pNE4E-00CLFS-8o; Wed, 01 Feb 2023 14:26:30 +0000 Received: from desiato.infradead.org ([2001:8b0:10b:1:d65d:64ff:fe57:4e05]) by bombadil.infradead.org with esmtps (Exim 4.94.2 #2 (Red Hat Linux)) id 1pNDhZ-00CBiH-6d for linux-arm-kernel@bombadil.infradead.org; Wed, 01 Feb 2023 14:03:05 +0000 DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=infradead.org; s=desiato.20200630; h=Content-Transfer-Encoding:MIME-Version :References:In-Reply-To:Message-Id:Date:Subject:Cc:To:From:Sender:Reply-To: Content-Type:Content-ID:Content-Description; bh=+zOq2rLtD1YPFldzTAQlw7NyDrjfoS45oyn9F6B1b8s=; b=Q42Bi99XVrNXfCgu109837xF0X MeqiRRLXjiB7khDoRGOnl74zs2XHQzaVnlAo4SOEMNS/iJKlwLFM4URFNPHURAEkKUAzVuW7QmHgU KVo+EsML6cemvrWNiCsnLwcBRE0gKhgY9M7nRASu88QEEjBn3eZSvlnR1MXqKZC+zkNEIZqTR2f+p hTMY5aByiCS7S18su9RniOXYOB25zv9N/WLnk9EJqt7wUOgKk1nJzXjHfM/kWLCzsKlQQ70ylD+5+ J0x668TzJVZ2OsbztSqsIbbpqxiNj3MaWhvBW8a98ygJ0lLi94+Ys9VTKs6XJZuur7ROsfLT0EmDa FDc4AtpQ==; Received: from mail-wr1-x430.google.com ([2a00:1450:4864:20::430]) by desiato.infradead.org with esmtps (Exim 4.96 #2 (Red Hat Linux)) id 1pNChk-004m3g-0t for linux-arm-kernel@lists.infradead.org; Wed, 01 Feb 2023 12:59:15 +0000 Received: by mail-wr1-x430.google.com with SMTP id o18so7754289wrj.3 for ; Wed, 01 Feb 2023 04:59:46 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linaro.org; s=google; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:from:to:cc:subject:date :message-id:reply-to; bh=+zOq2rLtD1YPFldzTAQlw7NyDrjfoS45oyn9F6B1b8s=; b=aNGPAFo2QKGeiRP5S5IH7xD7mskfsJdtbRW+20Bv+RmyiyxyCq2QbNzd/p4ud8dL71 2clglqcQlUZsX+DdlDGVOeXwo4LKP8WX8Ta0Mg2gbAN2H4dvoVB84P8hg2hapAAqUcZw BYYg8mMY1ePI+J8iL2xyozLfJc+Nim3Tx9NkA26QTNpDAMx6xebA044v+p2gqibEx2Wh 7nOUuQHMLK8yf2LC4uW6bNg5hP4vzKvP6/p4NEyyU5mrCgrSfBiS/wvn/dTXWM2dIRIs eTJq3Xd+YQsEF/IsVuqdRrdKTkxT1Rwuut/DLKd18BdqyKdS74/8xQEtN6nWCXLvagsu ypSA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=+zOq2rLtD1YPFldzTAQlw7NyDrjfoS45oyn9F6B1b8s=; b=KatpBFjXbsod23idq9YsUzkEXn1QmLr+hbGeNC0gNZAEZH48uiSibuGWvk36fXfrGm LhhQAWr+tnJ5Wfd9pU3h7c+GygBCCu6vwqhzrnT7C1q500gManBY7RvROmRfqhkGFc1q Snj6TKPOJdBlNYLTkx/t+lWZqR3+HZediK7ZBdey+plXOUA9pdci6y/5fk56zy3IMiix lYAvXdC4xUr6Cv2cOpxUBf5NRh0+thU0iqZS2k5JEWbil8UGANq4zJ3GMv4FkHHc++q8 ude7tVA4tX9KlaBSRxmWXQ1sbPQv2Xi5j8Inm3V8jDYJqFVLQaXuJKVg++Yvl9I1DH5f jVmg== X-Gm-Message-State: AO0yUKUrEU9nggC1GQAuaHh8ZznyuVWt4gyA92VauQKczFjWqfCXPKvv qJA8bQKFA/8K8dn2LY0Ly/RF0w== X-Google-Smtp-Source: AK7set9KtmjqqwgFLZB2FNx7zyl09FQwFd6hG2Sf0+3Gpskf/K+qKqsqUvXHqew395vtDLCSbNyrtA== X-Received: by 2002:a05:6000:1706:b0:2be:5366:8cdf with SMTP id n6-20020a056000170600b002be53668cdfmr2833558wrc.20.1675256384693; Wed, 01 Feb 2023 04:59:44 -0800 (PST) Received: from localhost.localdomain (054592b0.skybroadband.com. [5.69.146.176]) by smtp.gmail.com with ESMTPSA id m15-20020a056000024f00b002bfae16ee2fsm17972811wrz.111.2023.02.01.04.59.44 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 01 Feb 2023 04:59:44 -0800 (PST) From: Jean-Philippe Brucker To: maz@kernel.org, catalin.marinas@arm.com, will@kernel.org, joro@8bytes.org Cc: robin.murphy@arm.com, james.morse@arm.com, suzuki.poulose@arm.com, oliver.upton@linux.dev, yuzenghui@huawei.com, smostafa@google.com, dbrazdil@google.com, ryan.roberts@arm.com, linux-arm-kernel@lists.infradead.org, kvmarm@lists.linux.dev, iommu@lists.linux.dev, Jean-Philippe Brucker Subject: [RFC PATCH 32/45] iommu/arm-smmu-v3: Move IOMMU registration to arm-smmu-v3-common.c Date: Wed, 1 Feb 2023 12:53:16 +0000 Message-Id: <20230201125328.2186498-33-jean-philippe@linaro.org> X-Mailer: git-send-email 2.39.0 In-Reply-To: <20230201125328.2186498-1-jean-philippe@linaro.org> References: <20230201125328.2186498-1-jean-philippe@linaro.org> MIME-Version: 1.0 X-CRM114-Version: 20100106-BlameMichelson ( TRE 0.8.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20230201_125912_698738_D5BE753F X-CRM114-Status: GOOD ( 15.33 ) 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 The KVM driver will need to implement a few IOMMU ops, so move the helpers to arm-smmu-v3-common. Signed-off-by: Jean-Philippe Brucker --- drivers/iommu/arm/arm-smmu-v3/arm-smmu-v3.h | 4 +++ .../arm/arm-smmu-v3/arm-smmu-v3-common.c | 34 +++++++++++++++++++ drivers/iommu/arm/arm-smmu-v3/arm-smmu-v3.c | 17 ++-------- 3 files changed, 40 insertions(+), 15 deletions(-) diff --git a/drivers/iommu/arm/arm-smmu-v3/arm-smmu-v3.h b/drivers/iommu/arm/arm-smmu-v3/arm-smmu-v3.h index 345aac378712..87034da361ca 100644 --- a/drivers/iommu/arm/arm-smmu-v3/arm-smmu-v3.h +++ b/drivers/iommu/arm/arm-smmu-v3/arm-smmu-v3.h @@ -290,6 +290,10 @@ int arm_smmu_init_one_queue(struct arm_smmu_device *smmu, int arm_smmu_init_l2_strtab(struct arm_smmu_device *smmu, u32 sid); int arm_smmu_init_strtab(struct arm_smmu_device *smmu); +int arm_smmu_register_iommu(struct arm_smmu_device *smmu, + struct iommu_ops *ops, phys_addr_t ioaddr); +void arm_smmu_unregister_iommu(struct arm_smmu_device *smmu); + int arm_smmu_write_ctx_desc(struct arm_smmu_domain *smmu_domain, int ssid, struct arm_smmu_ctx_desc *cd); void arm_smmu_tlb_inv_asid(struct arm_smmu_device *smmu, u16 asid); diff --git a/drivers/iommu/arm/arm-smmu-v3/arm-smmu-v3-common.c b/drivers/iommu/arm/arm-smmu-v3/arm-smmu-v3-common.c index 4e945df5d64f..7faf28c5a8b4 100644 --- a/drivers/iommu/arm/arm-smmu-v3/arm-smmu-v3-common.c +++ b/drivers/iommu/arm/arm-smmu-v3/arm-smmu-v3-common.c @@ -112,6 +112,13 @@ int arm_smmu_fw_probe(struct platform_device *pdev, return arm_smmu_device_acpi_probe(pdev, smmu, bypass); } +#ifdef CONFIG_ARM_SMMU_V3_SVA +bool __weak arm_smmu_sva_supported(struct arm_smmu_device *smmu) +{ + return false; +} +#endif + int arm_smmu_device_hw_probe(struct arm_smmu_device *smmu) { u32 reg; @@ -591,3 +598,30 @@ int arm_smmu_init_strtab(struct arm_smmu_device *smmu) set_bit(0, smmu->vmid_map); return 0; } + +int arm_smmu_register_iommu(struct arm_smmu_device *smmu, + struct iommu_ops *ops, phys_addr_t ioaddr) +{ + int ret; + struct device *dev = smmu->dev; + + ret = iommu_device_sysfs_add(&smmu->iommu, dev, NULL, + "smmu3.%pa", &ioaddr); + if (ret) + return ret; + + ret = iommu_device_register(&smmu->iommu, ops, dev); + if (ret) { + dev_err(dev, "Failed to register iommu\n"); + iommu_device_sysfs_remove(&smmu->iommu); + return ret; + } + + return 0; +} + +void arm_smmu_unregister_iommu(struct arm_smmu_device *smmu) +{ + iommu_device_unregister(&smmu->iommu); + iommu_device_sysfs_remove(&smmu->iommu); +} diff --git a/drivers/iommu/arm/arm-smmu-v3/arm-smmu-v3.c b/drivers/iommu/arm/arm-smmu-v3/arm-smmu-v3.c index 7cb171304953..a972c00700cc 100644 --- a/drivers/iommu/arm/arm-smmu-v3/arm-smmu-v3.c +++ b/drivers/iommu/arm/arm-smmu-v3/arm-smmu-v3.c @@ -3257,27 +3257,14 @@ static int arm_smmu_device_probe(struct platform_device *pdev) return ret; /* And we're up. Go go go! */ - ret = iommu_device_sysfs_add(&smmu->iommu, dev, NULL, - "smmu3.%pa", &ioaddr); - if (ret) - return ret; - - ret = iommu_device_register(&smmu->iommu, &arm_smmu_ops, dev); - if (ret) { - dev_err(dev, "Failed to register iommu\n"); - iommu_device_sysfs_remove(&smmu->iommu); - return ret; - } - - return 0; + return arm_smmu_register_iommu(smmu, &arm_smmu_ops, ioaddr); } static int arm_smmu_device_remove(struct platform_device *pdev) { struct arm_smmu_device *smmu = platform_get_drvdata(pdev); - iommu_device_unregister(&smmu->iommu); - iommu_device_sysfs_remove(&smmu->iommu); + arm_smmu_unregister_iommu(smmu); arm_smmu_device_disable(smmu); iopf_queue_free(smmu->evtq.iopf);