From patchwork Thu Dec 22 18:50:44 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Cristian Marussi X-Patchwork-Id: 35906 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:adf:e747:0:0:0:0:0 with SMTP id c7csp110910wrn; Thu, 22 Dec 2022 10:51:56 -0800 (PST) X-Google-Smtp-Source: AMrXdXsJZ65ylxNxLP0JktS63wO4pYIyNkpHcdpX5kL2d+J5IksieDjDlsF6v1X+cglnP45gwWxe X-Received: by 2002:a17:903:40c1:b0:189:3580:48dd with SMTP id t1-20020a17090340c100b00189358048ddmr7395320pld.37.1671735116703; Thu, 22 Dec 2022 10:51:56 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1671735116; cv=none; d=google.com; s=arc-20160816; b=UHzWTEAOIphTHkG2Wcjzge4bLoGQh7HtGURbKsInTZ3q0JCG1MMd46lPkXUV4QtYOt N7GxgRbvKhT/eHVKMPaWyFRg5MWaelBhwRfbQmC62R+B76uM14UmkSuoHVYk7ho/5TnW 10558TaMCkCPV5UpU7ze7Y1qsUaLLiawCWGA1Z0byeBS/+ZB3e2+Wh6kRYhpJ8NNarTP Lbus8CuNJyIiRwbPO1RJB9/g+FKIfQvI2rSsZaslr5/B7dSaNbLO5EC6Z+P4bMLHX4Vp MryeZVC8mA++9Xg7jQq6fO7Ze2WtaEY+fZXJWr5gXncdRvvbnQomzY7q5PVQ64yqGCV7 /lwg== 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=fivTTtEcXnEbT3OBdgXN9PE/Nnrdky+QoDoVwCcmczk=; b=Cqxi1xeMEpkI/6lu3pi5TMWaw/Y/liRww1x3NjhcGwLOvhB0xC/AEccjzeNzEM6U9O G7gFraNXxj0NNNiXeJy2bHAPkBwpUB12Quj9PXnp4hNCOXhU9x5uDcQ+MyiQgdznbL+E 4J3h8kHKhuDeM94qeAEMgyGmkLapP/VRDnp455iUsFHGTi9Z3VhYghteUCHdi4kUiwmE W4pPMODRVv3gqQ8HI1ebMWyzU9TX/ttegX6Qlf0DLWAc+qt19mQ0uU+nzvdCSAX++45N JpAGzCcoZj/hAMHrWYpt/ZdJBoIVfiimewZgfrOm9awDTzuqhPIFKJLW9yDUEaOyoVq0 5bGQ== 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 k8-20020a170902c40800b00189ac5a51c2si1355784plk.157.2022.12.22.10.51.44; Thu, 22 Dec 2022 10:51:56 -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 S230409AbiLVSvU (ORCPT + 99 others); Thu, 22 Dec 2022 13:51:20 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:60406 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S230181AbiLVSvN (ORCPT ); Thu, 22 Dec 2022 13:51:13 -0500 Received: from foss.arm.com (foss.arm.com [217.140.110.172]) by lindbergh.monkeyblade.net (Postfix) with ESMTP id C44A322B0A for ; Thu, 22 Dec 2022 10:51:11 -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 A0892153B; Thu, 22 Dec 2022 10:51:52 -0800 (PST) Received: from e120937-lin.. (unknown [172.31.20.19]) by usa-sjc-imap-foss1.foss.arm.com (Postfix) with ESMTPSA id 4B5383FA32; Thu, 22 Dec 2022 10:51:10 -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 4/9] firmware: arm_scmi: Add common notifier helpers Date: Thu, 22 Dec 2022 18:50:44 +0000 Message-Id: <20221222185049.737625-5-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?1752941321646088853?= X-GMAIL-MSGID: =?utf-8?q?1752941321646088853?= Add a pair of notifier chains and generic empty notifier callbacks: still currently unused but they will be used to act properly on device request and creation events. Signed-off-by: Cristian Marussi --- drivers/firmware/arm_scmi/bus.c | 6 ++- drivers/firmware/arm_scmi/common.h | 5 ++ drivers/firmware/arm_scmi/driver.c | 83 +++++++++++++++++++++++++++++- 3 files changed, 92 insertions(+), 2 deletions(-) diff --git a/drivers/firmware/arm_scmi/bus.c b/drivers/firmware/arm_scmi/bus.c index 089957f5fb9b..bed566f58029 100644 --- a/drivers/firmware/arm_scmi/bus.c +++ b/drivers/firmware/arm_scmi/bus.c @@ -15,6 +15,9 @@ #include "common.h" +BLOCKING_NOTIFIER_HEAD(scmi_requested_devices_nh); +EXPORT_SYMBOL_GPL(scmi_requested_devices_nh); + static DEFINE_IDA(scmi_bus_id); static const struct scmi_device_id * @@ -94,12 +97,13 @@ static void scmi_dev_remove(struct device *dev) scmi_drv->remove(scmi_dev); } -static struct bus_type scmi_bus_type = { +struct bus_type scmi_bus_type = { .name = "scmi_protocol", .match = scmi_dev_match, .probe = scmi_dev_probe, .remove = scmi_dev_remove, }; +EXPORT_SYMBOL_GPL(scmi_bus_type); int scmi_driver_register(struct scmi_driver *driver, struct module *owner, const char *mod_name) diff --git a/drivers/firmware/arm_scmi/common.h b/drivers/firmware/arm_scmi/common.h index 6a38244494fd..7ddae90eb945 100644 --- a/drivers/firmware/arm_scmi/common.h +++ b/drivers/firmware/arm_scmi/common.h @@ -105,6 +105,11 @@ void scmi_setup_protocol_implemented(const struct scmi_protocol_handle *ph, int __init scmi_bus_init(void); void __exit scmi_bus_exit(void); +extern struct bus_type scmi_bus_type; + +#define SCMI_BUS_NOTIFY_DEVICE_REQUEST 0 +#define SCMI_BUS_NOTIFY_DEVICE_UNREQUEST 1 +extern struct blocking_notifier_head scmi_requested_devices_nh; int scmi_protocol_acquire(const struct scmi_handle *handle, u8 protocol_id); void scmi_protocol_release(const struct scmi_handle *handle, u8 protocol_id); diff --git a/drivers/firmware/arm_scmi/driver.c b/drivers/firmware/arm_scmi/driver.c index d1e32ea6d90a..62760bed1645 100644 --- a/drivers/firmware/arm_scmi/driver.c +++ b/drivers/firmware/arm_scmi/driver.c @@ -150,6 +150,9 @@ struct scmi_protocol_instance { * @notify_priv: Pointer to private data structure specific to notifications. * @node: List head * @users: Number of users of this instance + * @bus_nb: A notifier to listen for device bind/unbind on the scmi bus + * @dev_req_nb: A notifier to listen for device request/unrequest on the scmi + * bus */ struct scmi_info { struct device *dev; @@ -169,9 +172,13 @@ struct scmi_info { void *notify_priv; struct list_head node; int users; + struct notifier_block bus_nb; + struct notifier_block dev_req_nb; }; #define handle_to_scmi_info(h) container_of(h, struct scmi_info, handle) +#define bus_nb_to_scmi_info(nb) container_of(nb, struct scmi_info, bus_nb) +#define req_nb_to_scmi_info(nb) container_of(nb, struct scmi_info, dev_req_nb) static const int scmi_linux_errmap[] = { /* better than switch case as long as return value is continuous */ @@ -2509,6 +2516,60 @@ static void scmi_cleanup_txrx_channels(struct scmi_info *info) scmi_cleanup_channels(info, &info->rx_idr); } +static int scmi_bus_notifier(struct notifier_block *nb, + unsigned long action, void *data) +{ + struct scmi_info *info = bus_nb_to_scmi_info(nb); + struct scmi_device *sdev = to_scmi_dev(data); + + /* Skip transport devices and devices of different SCMI instances */ + if (!strncmp(sdev->name, "__scmi_transport_device", 23) || + sdev->dev.parent != info->dev) + return NOTIFY_DONE; + + switch (action) { + case BUS_NOTIFY_BIND_DRIVER: + break; + case BUS_NOTIFY_UNBOUND_DRIVER: + break; + default: + return NOTIFY_DONE; + } + + dev_dbg(info->dev, "Device %s (%s) is now %s\n", dev_name(&sdev->dev), + sdev->name, action == BUS_NOTIFY_BIND_DRIVER ? + "about to be BOUND." : "UNBOUND."); + + return NOTIFY_OK; +} + +static int scmi_device_request_notifier(struct notifier_block *nb, + unsigned long action, void *data) +{ + struct device_node *np; + struct scmi_device_id *id_table = data; + struct scmi_info *info = req_nb_to_scmi_info(nb); + + np = idr_find(&info->active_protocols, id_table->protocol_id); + if (!np) + return NOTIFY_DONE; + + dev_dbg(info->dev, "%sRequested device (%s) for protocol 0x%x\n", + action == SCMI_BUS_NOTIFY_DEVICE_REQUEST ? "" : "UN-", + id_table->name, id_table->protocol_id); + + switch (action) { + case SCMI_BUS_NOTIFY_DEVICE_REQUEST: + break; + case SCMI_BUS_NOTIFY_DEVICE_UNREQUEST: + break; + default: + return NOTIFY_DONE; + } + + return NOTIFY_OK; +} + static int scmi_probe(struct platform_device *pdev) { int ret; @@ -2528,6 +2589,8 @@ static int scmi_probe(struct platform_device *pdev) info->dev = dev; info->desc = desc; + info->bus_nb.notifier_call = scmi_bus_notifier; + info->dev_req_nb.notifier_call = scmi_device_request_notifier; INIT_LIST_HEAD(&info->node); idr_init(&info->protocols); mutex_init(&info->protocols_mtx); @@ -2563,10 +2626,19 @@ static int scmi_probe(struct platform_device *pdev) if (ret) return ret; - ret = scmi_xfer_info_init(info); + ret = bus_register_notifier(&scmi_bus_type, &info->bus_nb); if (ret) goto clear_txrx_setup; + ret = blocking_notifier_chain_register(&scmi_requested_devices_nh, + &info->dev_req_nb); + if (ret) + goto clear_bus_notifier; + + ret = scmi_xfer_info_init(info); + if (ret) + goto clear_dev_req_notifier; + if (scmi_notification_init(handle)) dev_err(dev, "SCMI Notifications NOT available.\n"); @@ -2624,6 +2696,11 @@ static int scmi_probe(struct platform_device *pdev) notification_exit: scmi_notification_exit(&info->handle); +clear_dev_req_notifier: + blocking_notifier_chain_unregister(&scmi_requested_devices_nh, + &info->dev_req_nb); +clear_bus_notifier: + bus_unregister_notifier(&scmi_bus_type, &info->bus_nb); clear_txrx_setup: scmi_cleanup_txrx_channels(info); return ret; @@ -2652,6 +2729,10 @@ static int scmi_remove(struct platform_device *pdev) of_node_put(child); idr_destroy(&info->active_protocols); + blocking_notifier_chain_unregister(&scmi_requested_devices_nh, + &info->dev_req_nb); + bus_unregister_notifier(&scmi_bus_type, &info->bus_nb); + /* Safe to free channels since no more users */ scmi_cleanup_txrx_channels(info);