From patchwork Wed Feb 1 12:53:28 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: 13124407 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 AC7C9C05027 for ; Wed, 1 Feb 2023 14:26:11 +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=KAxl+hZ6433NBNlURKZDm5AUwsrDkMR0cLpnUDsFC8w=; b=AeJBdU+uEslxNT X7ttxfu6RXQZ3/1mBgiVjuUBFSXnzMgLcrkZXvtaSRojwgo5aP34aZ9kv3XN5HP82JU79kaO+ReTT 1wrZK3oep9ybzX5Dz6OD3yWfeFzclCmRoQ1+TE6YouzkTqZF3lqb5mfRVlj9CILbcbseV1MI4Hzdq ydWY17wGJLCESj4F381i3M+gCOaWwThtESNbaw4s+Qg53voZgpcKmmBAzNey3EQtrjVK0ilMgVqFR 2gSMIuN4L1Gy/2Kr5WJ5xGoXyYZGCDmF4CPID4gYuFwE4wJmLRnjG4+KjWV0hJCrDGZKDlOMBpxxi EorPL3QFRW7qpT1viupw==; Received: from localhost ([::1] helo=bombadil.infradead.org) by bombadil.infradead.org with esmtp (Exim 4.94.2 #2 (Red Hat Linux)) id 1pNE2j-00CKYn-OR; Wed, 01 Feb 2023 14:24:58 +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 1pNDhV-00CBhk-AX for linux-arm-kernel@bombadil.infradead.org; Wed, 01 Feb 2023 14:03:01 +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=6jBsZPV3gipM57S7lAbp42QSD9Ff7K7v1FMixncXNZ8=; b=kD96iDIIgMFlMEE9Zv/SrgSgEl 7R63ekUEkWrIoa7oXzzHm2fXsZIdL7DpUIdcYtpEPfcpRub54iVc6AekuFGZcQOfVY09OdzsE+mHC aa4xGqc8UAPjZf8cXy2pcLAzsrqXYhucGUDwFstRQNxFs+fEIytX7uqo1eHbQH0l3KAFaRi/Zkflb AKqiBoIbRsF34fg42CsXTRQuZQ9hkKT2D9CLBQKicLCl/JP+tRXnEjWu/IPJm7FEI9w5pjbe4DRV0 zfTRlKNyVwkVi1qgufiDLwArtCnskUhaM1cOCJDdzXiWAdHCtrfj/jp5zopBTMXnonihuEnR1Dufm i6RIvfbQ==; Received: from mail-wm1-x333.google.com ([2a00:1450:4864:20::333]) by desiato.infradead.org with esmtps (Exim 4.96 #2 (Red Hat Linux)) id 1pNChs-004m6Q-1x for linux-arm-kernel@lists.infradead.org; Wed, 01 Feb 2023 12:59:25 +0000 Received: by mail-wm1-x333.google.com with SMTP id k16so12616439wms.2 for ; Wed, 01 Feb 2023 04:59:55 -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=6jBsZPV3gipM57S7lAbp42QSD9Ff7K7v1FMixncXNZ8=; b=jqqn6lEE7IVGOwDOGUD7sfXW39/KCeRyDY2/IuSjMlatK+c9ZDof8lJLlOvnpmvWTA tlSQGbKWdoTrC/MOU9HAgwktipxQF610xlaH/dYWp+pmmSLnjBtuGF9Qz95H06qb4MwO yAncx8QkWUkTvExb8Th18C0UWALTn9rEn+/sdpo30zE2K+g2rBF/PNys2yCbMr6w+Wmp DDS1ImzyVxYg4MQ2uUELVaL6vRyTQgT4Fqez6mH6JQcaaAothn5+3OPvFjFMrR8thoAg NqSNMBiuDqpmnSyRybV9FGZN/QmMk9u78DMmhJDZ3DZf9x1VV6qC7nVG8reMe3AtwLcM EisA== 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=6jBsZPV3gipM57S7lAbp42QSD9Ff7K7v1FMixncXNZ8=; b=uIsx4x0+2eRlvf9XEu+1p4kKb4rF+q+FwJnG7pk05pEX8ZjIpTfZ9I5kVcGPA5xwIL g8Ej++CYtpc4fJCEtsNq8YszESy0avG7g9uhFrN46pFQqlvtF96a5yQSEku98xmH6Vcy UcB/JqDkf1n8LbtdLO8a3s/lKmKrXdgqYgUz0xKS2c69+6NoWNEGgYHyLXQBX/Bzjtoz y0qhsnLtUSd2zMefCTgd+VNqr8/64pXINyBEBMDMCglm4ggkGMkZqUYc3SVOUK0SA0hF Ro+T2ThzhhoIE3lklRbGm31ss9bPyYPtggb4tMtZWsZrsodWxm49dxqZuanBTmDqZQ5/ QWfQ== X-Gm-Message-State: AO0yUKVc5nlvi8HTzp77HIyEJLP3ohkamQHGx5zISKAMTaEzFKEfZSk7 oUpr1wJUOUZ3DAkrJD93gzHjF1eCosXTDNVl X-Google-Smtp-Source: AK7set8FozBKO7/9zd4lyvhy8/1NGzLPtlJydoeNS4hNBerIjmIljLa1nO5xlOdJHO+Uy2Ds9zc7/A== X-Received: by 2002:a05:600c:3d0b:b0:3d0:7fee:8a70 with SMTP id bh11-20020a05600c3d0b00b003d07fee8a70mr2118223wmb.19.1675256394202; Wed, 01 Feb 2023 04:59:54 -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.53 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 01 Feb 2023 04:59:53 -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 44/45] iommu/arm-smmu-v3-kvm: Support power management with SCMI SMC Date: Wed, 1 Feb 2023 12:53:28 +0000 Message-Id: <20230201125328.2186498-45-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_125921_823324_024FE1DD X-CRM114-Status: GOOD ( 20.03 ) 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 Discover SCMI parameters for the SMMUv3 power domain, and pass them to the hypervisor. Power management must use a method based on SMC, so the hypervisor driver can catch them and keep the software state in sync with the hardware. Signed-off-by: Jean-Philippe Brucker --- .../iommu/arm/arm-smmu-v3/arm-smmu-v3-kvm.c | 76 +++++++++++++++++++ 1 file changed, 76 insertions(+) diff --git a/drivers/iommu/arm/arm-smmu-v3/arm-smmu-v3-kvm.c b/drivers/iommu/arm/arm-smmu-v3/arm-smmu-v3-kvm.c index 930d78f6e29f..198e41d808b0 100644 --- a/drivers/iommu/arm/arm-smmu-v3/arm-smmu-v3-kvm.c +++ b/drivers/iommu/arm/arm-smmu-v3/arm-smmu-v3-kvm.c @@ -6,6 +6,7 @@ */ #include #include +#include #include #include @@ -495,6 +496,75 @@ static int kvm_arm_smmu_device_reset(struct host_arm_smmu_device *host_smmu) return 0; } +static int kvm_arm_probe_scmi_pd(struct device_node *scmi_node, + struct kvm_power_domain *pd) +{ + int ret; + struct resource res; + struct of_phandle_args args; + + pd->type = KVM_POWER_DOMAIN_ARM_SCMI; + + ret = of_parse_phandle_with_args(scmi_node, "shmem", NULL, 0, &args); + if (ret) + return ret; + + ret = of_address_to_resource(args.np, 0, &res); + if (ret) + goto out_put_nodes; + + ret = of_property_read_u32(scmi_node, "arm,smc-id", + &pd->arm_scmi.smc_id); + if (ret) + goto out_put_nodes; + + /* + * The shared buffer is unmapped from the host while a request is in + * flight, so it has to be on its own page. + */ + if (!IS_ALIGNED(res.start, SZ_64K) || resource_size(&res) < SZ_64K) { + ret = -EINVAL; + goto out_put_nodes; + } + + pd->arm_scmi.shmem_base = res.start; + pd->arm_scmi.shmem_size = resource_size(&res); + +out_put_nodes: + of_node_put(args.np); + return ret; +} + +/* TODO: Move this. None of it is specific to SMMU */ +static int kvm_arm_probe_power_domain(struct device *dev, + struct kvm_power_domain *pd) +{ + int ret; + struct device_node *parent; + struct of_phandle_args args; + + if (!of_get_property(dev->of_node, "power-domains", NULL)) + return 0; + + ret = of_parse_phandle_with_args(dev->of_node, "power-domains", + "#power-domain-cells", 0, &args); + if (ret) + return ret; + + parent = of_get_parent(args.np); + if (parent && of_device_is_compatible(parent, "arm,scmi-smc") && + args.args_count > 0) { + pd->arm_scmi.domain_id = args.args[0]; + ret = kvm_arm_probe_scmi_pd(parent, pd); + } else { + dev_err(dev, "Unsupported PM method for %pOF\n", args.np); + ret = -EINVAL; + } + of_node_put(parent); + of_node_put(args.np); + return ret; +} + static void *kvm_arm_smmu_alloc_domains(struct arm_smmu_device *smmu) { return (void *)devm_get_free_pages(smmu->dev, GFP_KERNEL | __GFP_ZERO, @@ -513,6 +583,7 @@ static int kvm_arm_smmu_probe(struct platform_device *pdev) struct device *dev = &pdev->dev; struct host_arm_smmu_device *host_smmu; struct hyp_arm_smmu_v3_device *hyp_smmu; + struct kvm_power_domain power_domain = {}; if (kvm_arm_smmu_cur >= kvm_arm_smmu_count) return -ENOSPC; @@ -530,6 +601,10 @@ static int kvm_arm_smmu_probe(struct platform_device *pdev) if (ret || bypass) return ret ?: -EINVAL; + ret = kvm_arm_probe_power_domain(dev, &power_domain); + if (ret) + return ret; + res = platform_get_resource(pdev, IORESOURCE_MEM, 0); size = resource_size(res); if (size < SZ_128K) { @@ -606,6 +681,7 @@ static int kvm_arm_smmu_probe(struct platform_device *pdev) hyp_smmu->mmio_size = size; hyp_smmu->features = smmu->features; hyp_smmu->iommu.pgtable_cfg = cfg; + hyp_smmu->iommu.power_domain = power_domain; kvm_arm_smmu_cur++;