From patchwork Thu Dec 22 18:50:46 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Cristian Marussi X-Patchwork-Id: 35909 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:adf:e747:0:0:0:0:0 with SMTP id c7csp111079wrn; Thu, 22 Dec 2022 10:52:32 -0800 (PST) X-Google-Smtp-Source: AMrXdXss2iVxx9yThuu7ppikqiVH2MoI76Zuw98MU3yP0imybpaMrI515VpovIA+kI5JivnfVoMo X-Received: by 2002:a17:90b:4b0a:b0:223:415c:2b82 with SMTP id lx10-20020a17090b4b0a00b00223415c2b82mr7408126pjb.27.1671735152283; Thu, 22 Dec 2022 10:52:32 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1671735152; cv=none; d=google.com; s=arc-20160816; b=Q/VuNnKA0HWuiPvGW00Rbk0D3doNBdwdbqj6kfPKT67+O7/XFxfd23ou+VAo/ghj+I OziaCoBc9QIpbJTFfY1rcMNcyYLQ2X0ABZ+ugrvfiDr7Fs8GFWXmDK4zg2r3Q+ImyO7/ H5JvAJ62XrTfP2Bm51REV14qB94H4vfaDk+06+YdIgMPnT34vQFJ/ayv3MionVCtsi+l U5xVegWXIkpl3IqsvoLqTQzo+GpPqanSQ8XM/idcoiYhmX8lV89VEF7iN5viyOc4IL5l FK+yZLNFkBAG10xIpV59RsvoxwM+E5ZY+ynmGIh3o4N1HouJj33QEkcnEE/q8T5D+eiF H9Vg== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:content-transfer-encoding:mime-version :references:in-reply-to:message-id:date:subject:cc:to:from; bh=YtMZEla4+XUqYGFE51xJmqv1hxnUb6Dkv1f6TnOd70Q=; b=d3iDoEx3uEWHdkNccLdVMAvvrHNymxBiCEyL3xUUffZ2D8afUyfOmjskTLFSFtbGCh FmYC1Vpo9PkH4p/Kv7vLd5BeEHggt9JC+3vMli2EF8MdrVz8ca8+a2iW+7aY0kAIWYyn dLfrm1SaBAvXS5XOMQn/RkwfmDyE/v/9hvZFRPkGQYM7mNO72Q3N4zk4Q3KD/1djm5I2 GV3SLOYIdxM8DvC7jVA1oIbvn+68zbTlEm+1wn+qucBd4MHt4bJOcuEdcrI4g18VamWe 53kGgbUv9sSHnGY8iUQt6HUsTL9vMWgheFjrx8vE7nCpj9Hy0cTW8tYh1yOmtk9YLrpQ i9Ow== ARC-Authentication-Results: i=1; mx.google.com; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=fail (p=NONE sp=NONE dis=NONE) header.from=arm.com Received: from out1.vger.email (out1.vger.email. [2620:137:e000::1:20]) by mx.google.com with ESMTP id b3-20020a63cf43000000b00478eaccedbbsi1411993pgj.582.2022.12.22.10.52.19; Thu, 22 Dec 2022 10:52:32 -0800 (PST) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) client-ip=2620:137:e000::1:20; Authentication-Results: mx.google.com; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=fail (p=NONE sp=NONE dis=NONE) header.from=arm.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S235227AbiLVSvd (ORCPT + 99 others); Thu, 22 Dec 2022 13:51:33 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:60430 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S230183AbiLVSvQ (ORCPT ); Thu, 22 Dec 2022 13:51:16 -0500 Received: from foss.arm.com (foss.arm.com [217.140.110.172]) by lindbergh.monkeyblade.net (Postfix) with ESMTP id 26E872333A for ; Thu, 22 Dec 2022 10:51:15 -0800 (PST) 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 055DAAD7; Thu, 22 Dec 2022 10:51:56 -0800 (PST) Received: from e120937-lin.. (unknown [172.31.20.19]) by usa-sjc-imap-foss1.foss.arm.com (Postfix) with ESMTPSA id 71E693FA32; Thu, 22 Dec 2022 10:51:13 -0800 (PST) From: Cristian Marussi To: linux-kernel@vger.kernel.org, linux-arm-kernel@lists.infradead.org Cc: sudeep.holla@arm.com, james.quinlan@broadcom.com, f.fainelli@gmail.com, etienne.carriere@linaro.org, vincent.guittot@linaro.org, Ludvig.Parsson@axis.com, cristian.marussi@arm.com Subject: [PATCH 6/9] firmware: arm_scmi: Move handle get/set helpers Date: Thu, 22 Dec 2022 18:50:46 +0000 Message-Id: <20221222185049.737625-7-cristian.marussi@arm.com> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20221222185049.737625-1-cristian.marussi@arm.com> References: <20221222185049.737625-1-cristian.marussi@arm.com> MIME-Version: 1.0 X-Spam-Status: No, score=-4.2 required=5.0 tests=BAYES_00,RCVD_IN_DNSWL_MED, SPF_HELO_NONE,SPF_NONE autolearn=ham autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on lindbergh.monkeyblade.net Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org X-getmail-retrieved-from-mailbox: =?utf-8?q?INBOX?= X-GMAIL-THRID: =?utf-8?q?1752941358936430989?= X-GMAIL-MSGID: =?utf-8?q?1752941358936430989?= Move handle get/set helpers definitions into driver.c and invoke them through the bus notifier helper. Signed-off-by: Cristian Marussi --- drivers/firmware/arm_scmi/bus.c | 17 --------------- drivers/firmware/arm_scmi/common.h | 4 ---- drivers/firmware/arm_scmi/driver.c | 35 +++++++++++++++++++++--------- 3 files changed, 25 insertions(+), 31 deletions(-) diff --git a/drivers/firmware/arm_scmi/bus.c b/drivers/firmware/arm_scmi/bus.c index e63cc1194d43..61113def5a9a 100644 --- a/drivers/firmware/arm_scmi/bus.c +++ b/drivers/firmware/arm_scmi/bus.c @@ -344,27 +344,10 @@ scmi_device_create(struct device_node *np, struct device *parent, int protocol, void scmi_device_destroy(struct scmi_device *scmi_dev) { kfree_const(scmi_dev->name); - scmi_handle_put(scmi_dev->handle); ida_free(&scmi_bus_id, scmi_dev->id); device_unregister(&scmi_dev->dev); } -void scmi_device_link_add(struct device *consumer, struct device *supplier) -{ - struct device_link *link; - - link = device_link_add(consumer, supplier, DL_FLAG_AUTOREMOVE_CONSUMER); - - WARN_ON(!link); -} - -void scmi_set_handle(struct scmi_device *scmi_dev) -{ - scmi_dev->handle = scmi_handle_get(&scmi_dev->dev); - if (scmi_dev->handle) - scmi_device_link_add(&scmi_dev->dev, scmi_dev->handle->dev); -} - static int __scmi_devices_unregister(struct device *dev, void *data) { struct scmi_device *scmi_dev = to_scmi_dev(dev); diff --git a/drivers/firmware/arm_scmi/common.h b/drivers/firmware/arm_scmi/common.h index 0f411679df7e..07d34954c060 100644 --- a/drivers/firmware/arm_scmi/common.h +++ b/drivers/firmware/arm_scmi/common.h @@ -96,10 +96,6 @@ static inline void unpack_scmi_header(u32 msg_hdr, struct scmi_msg_hdr *hdr) struct scmi_revision_info * scmi_revision_area_get(const struct scmi_protocol_handle *ph); -int scmi_handle_put(const struct scmi_handle *handle); -void scmi_device_link_add(struct device *consumer, struct device *supplier); -struct scmi_handle *scmi_handle_get(struct device *dev); -void scmi_set_handle(struct scmi_device *scmi_dev); void scmi_setup_protocol_implemented(const struct scmi_protocol_handle *ph, u8 *prot_imp); diff --git a/drivers/firmware/arm_scmi/driver.c b/drivers/firmware/arm_scmi/driver.c index 73f640e9448f..8591b2c740c6 100644 --- a/drivers/firmware/arm_scmi/driver.c +++ b/drivers/firmware/arm_scmi/driver.c @@ -1890,13 +1890,6 @@ static bool scmi_is_transport_atomic(const struct scmi_handle *handle, return ret; } -static inline -struct scmi_handle *scmi_handle_get_from_info_unlocked(struct scmi_info *info) -{ - info->users++; - return &info->handle; -} - /** * scmi_handle_get() - Get the SCMI handle for a device * @@ -1908,7 +1901,7 @@ struct scmi_handle *scmi_handle_get_from_info_unlocked(struct scmi_info *info) * * Return: pointer to handle if successful, NULL on error */ -struct scmi_handle *scmi_handle_get(struct device *dev) +static struct scmi_handle *scmi_handle_get(struct device *dev) { struct list_head *p; struct scmi_info *info; @@ -1918,7 +1911,8 @@ struct scmi_handle *scmi_handle_get(struct device *dev) list_for_each(p, &scmi_list) { info = list_entry(p, struct scmi_info, node); if (dev->parent == info->dev) { - handle = scmi_handle_get_from_info_unlocked(info); + info->users++; + handle = &info->handle; break; } } @@ -1939,7 +1933,7 @@ struct scmi_handle *scmi_handle_get(struct device *dev) * Return: 0 is successfully released * if null was passed, it returns -EINVAL; */ -int scmi_handle_put(const struct scmi_handle *handle) +static int scmi_handle_put(const struct scmi_handle *handle) { struct scmi_info *info; @@ -1955,6 +1949,23 @@ int scmi_handle_put(const struct scmi_handle *handle) return 0; } +static void scmi_device_link_add(struct device *consumer, + struct device *supplier) +{ + struct device_link *link; + + link = device_link_add(consumer, supplier, DL_FLAG_AUTOREMOVE_CONSUMER); + + WARN_ON(!link); +} + +static void scmi_set_handle(struct scmi_device *scmi_dev) +{ + scmi_dev->handle = scmi_handle_get(&scmi_dev->dev); + if (scmi_dev->handle) + scmi_device_link_add(&scmi_dev->dev, scmi_dev->handle->dev); +} + static int __scmi_xfer_info_init(struct scmi_info *sinfo, struct scmi_xfers_info *info) { @@ -2234,8 +2245,12 @@ static int scmi_bus_notifier(struct notifier_block *nb, switch (action) { case BUS_NOTIFY_BIND_DRIVER: + /* setup handle now as the transport is ready */ + scmi_set_handle(sdev); break; case BUS_NOTIFY_UNBOUND_DRIVER: + scmi_handle_put(sdev->handle); + sdev->handle = NULL; break; default: return NOTIFY_DONE;