From patchwork Thu Jun 23 12:47:39 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Cristian Marussi X-Patchwork-Id: 12892338 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 59E63CCA47C for ; Thu, 23 Jun 2022 12:49:26 +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=DHk5c/VWiqZellrxheGmDp3XDd9K+Yg56fPPydn9Tdw=; b=x5orS9K70CrdMe DZoyDS4kqaqjX5IqASIrFLrrJscK/+RwsitaufobAuNeCcrfu/tEe0qM8BLPp3MaOWfQkwZwP8bCu GZMW4BSB3GJtJOUcMXJpMbbdH7ag1qk4VelTJQwfLSS1WM8CfJFTevDuZRG/kh3UnXUk75G03XO0z cjeaGRIYDVkB3JoHgw1910aR116ccNIYe4sfllqx5+UJsShVqL0QdIYA5zX/5XVd0epJCraCQV5V4 frmg2jNt6SpMoF0Gd+C3r7XCaY2go6ODBmh/SfZEirfBljaF80yNJ0P2Ioc/Tf9ruajRn0KzA1K/2 /471VQaoT7ZZDGR5GvMg==; Received: from localhost ([::1] helo=bombadil.infradead.org) by bombadil.infradead.org with esmtp (Exim 4.94.2 #2 (Red Hat Linux)) id 1o4MG8-00F4nJ-LJ; Thu, 23 Jun 2022 12:48:32 +0000 Received: from foss.arm.com ([217.140.110.172]) by bombadil.infradead.org with esmtp (Exim 4.94.2 #2 (Red Hat Linux)) id 1o4MFh-00F4d2-7P for linux-arm-kernel@lists.infradead.org; Thu, 23 Jun 2022 12:48:08 +0000 Received: from usa-sjc-imap-foss1.foss.arm.com (unknown [10.121.207.14]) by usa-sjc-mx-foss1.foss.arm.com (Postfix) with ESMTP id A454D1474; Thu, 23 Jun 2022 05:48:00 -0700 (PDT) Received: from e120937-lin.home (unknown [172.31.20.19]) by usa-sjc-imap-foss1.foss.arm.com (Postfix) with ESMTPSA id 9184B3F534; Thu, 23 Jun 2022 05:47:59 -0700 (PDT) From: Cristian Marussi To: linux-kernel@vger.kernel.org, linux-arm-kernel@lists.infradead.org Cc: sudeep.holla@arm.com, vincent.guittot@linaro.org, f.fainelli@gmail.com, Cristian Marussi Subject: [PATCH 2/5] firmware: arm_scmi: Support only one single SystemPower device Date: Thu, 23 Jun 2022 13:47:39 +0100 Message-Id: <20220623124742.2492164-3-cristian.marussi@arm.com> X-Mailer: git-send-email 2.32.0 In-Reply-To: <20220623124742.2492164-1-cristian.marussi@arm.com> References: <20220623124742.2492164-1-cristian.marussi@arm.com> MIME-Version: 1.0 X-CRM114-Version: 20100106-BlameMichelson ( TRE 0.8.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20220623_054805_348726_BDF0C087 X-CRM114-Status: GOOD ( 10.57 ) 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 In order to minimize SCMI platform fw-side complexity, only one single SCMI platform should be in charge of SCMI SystemPower protocol communications with the OSPM: enforce the existence of one single unique device associated with SystemPower protocol across any possible number of SCMI platforms, and warn if a system tries to register different SystemPower devices from multiple platforms. Signed-off-by: Cristian Marussi --- drivers/firmware/arm_scmi/bus.c | 31 ++++++++++++++++++++++++++++++- 1 file changed, 30 insertions(+), 1 deletion(-) diff --git a/drivers/firmware/arm_scmi/bus.c b/drivers/firmware/arm_scmi/bus.c index a7cbf4d09081..476855d3dccb 100644 --- a/drivers/firmware/arm_scmi/bus.c +++ b/drivers/firmware/arm_scmi/bus.c @@ -19,6 +19,11 @@ static DEFINE_IDA(scmi_bus_id); static DEFINE_IDR(scmi_protocols); static DEFINE_SPINLOCK(protocol_lock); +/* Track globally the creation of SCMI SystemPower related devices */ +static bool scmi_syspower_registered; +/* Protect access to scmi_syspower_registered */ +static DEFINE_MUTEX(scmi_syspower_mtx); + static const struct scmi_device_id * scmi_dev_match_id(struct scmi_device *scmi_dev, struct scmi_driver *scmi_drv) { @@ -207,11 +212,31 @@ scmi_device_create(struct device_node *np, struct device *parent, int protocol, scmi_dev->dev.release = scmi_device_release; dev_set_name(&scmi_dev->dev, "scmi_dev.%d", id); + mutex_lock(&scmi_syspower_mtx); + if (protocol == SCMI_PROTOCOL_SYSTEM && scmi_syspower_registered) { + dev_warn(parent, + "SCMI SystemPower protocol device must be unique !\n"); + + mutex_unlock(&scmi_syspower_mtx); + ida_free(&scmi_bus_id, id); + kfree_const(scmi_dev->name); + kfree(scmi_dev); + return NULL; + } + retval = device_register(&scmi_dev->dev); - if (retval) + if (retval) { + mutex_unlock(&scmi_syspower_mtx); goto put_dev; + } + + if (protocol == SCMI_PROTOCOL_SYSTEM) + scmi_syspower_registered = true; + + mutex_unlock(&scmi_syspower_mtx); return scmi_dev; + put_dev: kfree_const(scmi_dev->name); put_device(&scmi_dev->dev); @@ -221,6 +246,10 @@ scmi_device_create(struct device_node *np, struct device *parent, int protocol, void scmi_device_destroy(struct scmi_device *scmi_dev) { + mutex_lock(&scmi_syspower_mtx); + if (scmi_dev->protocol_id == SCMI_PROTOCOL_SYSTEM) + scmi_syspower_registered = false; + mutex_unlock(&scmi_syspower_mtx); kfree_const(scmi_dev->name); scmi_handle_put(scmi_dev->handle); ida_free(&scmi_bus_id, scmi_dev->id);