Received: by 2002:a05:6358:f14:b0:e5:3b68:ec04 with SMTP id b20csp546767rwj; Thu, 22 Dec 2022 11:04:09 -0800 (PST) X-Google-Smtp-Source: AMrXdXvTYd84Q1HIdeWevQ8kpOrFdTTuuBVG1dIBW9D81uH+JU3Zrg2Muu8dAz8X4oHcw4Lb4Kk0 X-Received: by 2002:a05:6402:3454:b0:47f:ab65:b3f4 with SMTP id l20-20020a056402345400b0047fab65b3f4mr1897958edc.39.1671735848832; Thu, 22 Dec 2022 11:04:08 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1671735848; cv=none; d=google.com; s=arc-20160816; b=fKpxLCQI+ai8H5snZNBoIrNgeA0NwtTnvJcUTo6upOwIPS/dACWtcD+zBEWXQ8MK90 fGdeHzDwLQPTlsNvJIQdBwV9Sb3cRW3CidgALR/9GaHXBgXBeB6jDHfbRnqa73JX2wQR XJmcD/hgOyDoyJMdSdiAsijJfNlJuYvjC0gMu+vdmu9aPlkAUZ6qA22NsHVB41uMcVid mpnJFdBB+nYox/+BmiTv3U5s3uYkqHp0RqzFTp0Yy1hV2umypqjtElqryLMutpYMrXgM RDJhULbGJjXZjiiyJFhdbm6P0+fgk4Vrj7lNQE8BTV4vPV9+KThg3KhC8DSCj6xeFYKO +aAQ== 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 Return-Path: Received: from out1.vger.email (out1.vger.email. [2620:137:e000::1:20]) by mx.google.com with ESMTP id b23-20020aa7cd17000000b00477e889f2a6si1062709edw.53.2022.12.22.11.03.52; Thu, 22 Dec 2022 11:04:08 -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 + 69 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 Content-Transfer-Encoding: 8bit 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 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); -- 2.34.1