From nobody Tue Feb 10 11:23:35 2026 Received: from foss.arm.com (foss.arm.com [217.140.110.172]) by smtp.subspace.kernel.org (Postfix) with ESMTP id 144C0396D0B; Wed, 14 Jan 2026 11:47:32 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=217.140.110.172 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1768391254; cv=none; b=W3bv9fkHqQHNZrSsdisVSDz0KjT4C1o6zEg1oiX8bZDpt5TWcGB4PZkP9Zh09of2jMXYGE0js5sAsSTwBLw9bamRoQScSCW5OZJ41+ydmhKTz1/IRnmNlTF/yEir/Mrql0eEIg6f9/Yh/DviSPMwPL8++1b3XG7SfMZrE74WOhU= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1768391254; c=relaxed/simple; bh=S9I3UhAClWcqsGV6B1ZKFE6EF344tHX0qpPTnzW7EQM=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=Kc2L6324FPE940TTXemMzg0HGTwykgyGjAOjCZXa75DqY5dWITTMuEVpvkgWjGn9Y59Kr1Y+yJubbVggTDoyS8rdS4j/PHJhuwDFfBoaK6m4G8NvcW+2F+bpyk3tqylC0YCjAqQ3W3ftaldMo49W2etGWtPKsHDn1mKA3sPkAHs= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=arm.com; spf=pass smtp.mailfrom=arm.com; arc=none smtp.client-ip=217.140.110.172 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=arm.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=arm.com 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 D22D8339; Wed, 14 Jan 2026 03:47:25 -0800 (PST) Received: from pluto.fritz.box (usa-sjc-mx-foss1.foss.arm.com [172.31.20.19]) by usa-sjc-imap-foss1.foss.arm.com (Postfix) with ESMTPSA id 134D23F59E; Wed, 14 Jan 2026 03:47:28 -0800 (PST) From: Cristian Marussi To: linux-kernel@vger.kernel.org, linux-arm-kernel@lists.infradead.org, arm-scmi@vger.kernel.org, linux-fsdevel@vger.kernel.org Cc: sudeep.holla@arm.com, james.quinlan@broadcom.com, f.fainelli@gmail.com, vincent.guittot@linaro.org, etienne.carriere@st.com, peng.fan@oss.nxp.com, michal.simek@amd.com, dan.carpenter@linaro.org, d-gole@ti.com, jonathan.cameron@huawei.com, elif.topuz@arm.com, lukasz.luba@arm.com, philip.radford@arm.com, souvik.chakravarty@arm.com, Cristian Marussi Subject: [PATCH v2 03/17] firmware: arm_scmi: Allow protocols to register for notifications Date: Wed, 14 Jan 2026 11:46:07 +0000 Message-ID: <20260114114638.2290765-4-cristian.marussi@arm.com> X-Mailer: git-send-email 2.52.0 In-Reply-To: <20260114114638.2290765-1-cristian.marussi@arm.com> References: <20260114114638.2290765-1-cristian.marussi@arm.com> Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable Content-Type: text/plain; charset="utf-8" Allow protocols themselves to register for their own notifications and providing their own notifier callbacks. While at that, allow for a protocol to register events with compilation-time unknown report/event sizes: such events will use the maximum transport size. Signed-off-by: Cristian Marussi --- v1-->v2 - Fixed multiline comment format --- drivers/firmware/arm_scmi/common.h | 4 ++++ drivers/firmware/arm_scmi/driver.c | 12 ++++++++++++ drivers/firmware/arm_scmi/notify.c | 28 ++++++++++++++++++++------- drivers/firmware/arm_scmi/notify.h | 8 ++++++-- drivers/firmware/arm_scmi/protocols.h | 6 ++++++ 5 files changed, 49 insertions(+), 9 deletions(-) diff --git a/drivers/firmware/arm_scmi/common.h b/drivers/firmware/arm_scmi= /common.h index 3b24831094b6..9f9a5a4bcf35 100644 --- a/drivers/firmware/arm_scmi/common.h +++ b/drivers/firmware/arm_scmi/common.h @@ -17,6 +17,7 @@ #include #include #include +#include #include #include #include @@ -527,5 +528,8 @@ static struct platform_driver __drv =3D { \ void scmi_notification_instance_data_set(const struct scmi_handle *handle, void *priv); void *scmi_notification_instance_data_get(const struct scmi_handle *handle= ); +int scmi_notifier_register(const struct scmi_handle *handle, u8 proto_id, + u8 evt_id, const u32 *src_id, + struct notifier_block *nb); int scmi_inflight_count(const struct scmi_handle *handle); #endif /* _SCMI_COMMON_H */ diff --git a/drivers/firmware/arm_scmi/driver.c b/drivers/firmware/arm_scmi= /driver.c index b198c58da1dd..1085c70ca457 100644 --- a/drivers/firmware/arm_scmi/driver.c +++ b/drivers/firmware/arm_scmi/driver.c @@ -1657,6 +1657,17 @@ static void *scmi_get_protocol_priv(const struct scm= i_protocol_handle *ph) return pi->priv; } =20 +static int +scmi_register_instance_notifier(const struct scmi_protocol_handle *ph, + u8 evt_id, const u32 *src_id, + struct notifier_block *nb) +{ + const struct scmi_protocol_instance *pi =3D ph_to_pi(ph); + + return scmi_notifier_register(pi->handle, pi->proto->id, + evt_id, src_id, nb); +} + static const struct scmi_xfer_ops xfer_ops =3D { .version_get =3D version_get, .xfer_get_init =3D xfer_get_init, @@ -2156,6 +2167,7 @@ scmi_alloc_init_protocol_instance(struct scmi_info *i= nfo, pi->ph.hops =3D &helpers_ops; pi->ph.set_priv =3D scmi_set_protocol_priv; pi->ph.get_priv =3D scmi_get_protocol_priv; + pi->ph.notifier_register =3D scmi_register_instance_notifier; refcount_set(&pi->users, 1); /* proto->init is assured NON NULL by scmi_protocol_register */ ret =3D pi->proto->instance_init(&pi->ph); diff --git a/drivers/firmware/arm_scmi/notify.c b/drivers/firmware/arm_scmi= /notify.c index 78e9e27dc9ec..e84b4dbefe82 100644 --- a/drivers/firmware/arm_scmi/notify.c +++ b/drivers/firmware/arm_scmi/notify.c @@ -593,7 +593,13 @@ int scmi_notify(const struct scmi_handle *handle, u8 p= roto_id, u8 evt_id, if (!r_evt) return -EINVAL; =20 - if (len > r_evt->evt->max_payld_sz) { + /* + * Events with a zero max_payld_sz are sized to be of the maximum + * size allowed by the transport: no need to be size-checked here + * since the transport layer would have already dropped such + * over-sized messages. + */ + if (r_evt->evt->max_payld_sz && len > r_evt->evt->max_payld_sz) { dev_err(handle->dev, "discard badly sized message\n"); return -EINVAL; } @@ -752,7 +758,7 @@ int scmi_register_protocol_events(const struct scmi_han= dle *handle, u8 proto_id, const struct scmi_protocol_handle *ph, const struct scmi_protocol_events *ee) { - int i; + int i, max_msg_sz; unsigned int num_sources; size_t payld_sz =3D 0; struct scmi_registered_events_desc *pd; @@ -767,6 +773,8 @@ int scmi_register_protocol_events(const struct scmi_han= dle *handle, u8 proto_id, if (!ni) return -ENOMEM; =20 + max_msg_sz =3D ph->hops->get_max_msg_size(ph); + /* num_sources cannot be <=3D 0 */ if (ee->num_sources) { num_sources =3D ee->num_sources; @@ -779,8 +787,13 @@ int scmi_register_protocol_events(const struct scmi_ha= ndle *handle, u8 proto_id, } =20 evt =3D ee->evts; - for (i =3D 0; i < ee->num_events; i++) + for (i =3D 0; i < ee->num_events; i++) { + if (evt[i].max_payld_sz =3D=3D 0) { + payld_sz =3D max_msg_sz; + break; + } payld_sz =3D max_t(size_t, payld_sz, evt[i].max_payld_sz); + } payld_sz +=3D sizeof(struct scmi_event_header); =20 pd =3D scmi_allocate_registered_events_desc(ni, proto_id, ee->queue_sz, @@ -809,7 +822,8 @@ int scmi_register_protocol_events(const struct scmi_han= dle *handle, u8 proto_id, mutex_init(&r_evt->sources_mtx); =20 r_evt->report =3D devm_kzalloc(ni->handle->dev, - evt->max_report_sz, GFP_KERNEL); + evt->max_report_sz ?: max_msg_sz, + GFP_KERNEL); if (!r_evt->report) return -ENOMEM; =20 @@ -1373,9 +1387,9 @@ static int scmi_event_handler_enable_events(struct sc= mi_event_handler *hndl) * * Return: 0 on Success */ -static int scmi_notifier_register(const struct scmi_handle *handle, - u8 proto_id, u8 evt_id, const u32 *src_id, - struct notifier_block *nb) +int scmi_notifier_register(const struct scmi_handle *handle, + u8 proto_id, u8 evt_id, const u32 *src_id, + struct notifier_block *nb) { int ret =3D 0; u32 evt_key; diff --git a/drivers/firmware/arm_scmi/notify.h b/drivers/firmware/arm_scmi= /notify.h index 76758a736cf4..ecfa4b746487 100644 --- a/drivers/firmware/arm_scmi/notify.h +++ b/drivers/firmware/arm_scmi/notify.h @@ -18,8 +18,12 @@ /** * struct scmi_event - Describes an event to be supported * @id: Event ID - * @max_payld_sz: Max possible size for the payload of a notification mess= age - * @max_report_sz: Max possible size for the report of a notification mess= age + * @max_payld_sz: Max possible size for the payload of a notification mess= age. + * Set to zero to use the maximum payload size allowed by the + * transport. + * @max_report_sz: Max possible size for the report of a notification mess= age. + * Set to zero to use the maximum payload size allowed by the + * transport. * * Each SCMI protocol, during its initialization phase, can describe the e= vents * it wishes to support in a few struct scmi_event and pass them to the co= re diff --git a/drivers/firmware/arm_scmi/protocols.h b/drivers/firmware/arm_s= cmi/protocols.h index d62c4469d1fd..afca1336267b 100644 --- a/drivers/firmware/arm_scmi/protocols.h +++ b/drivers/firmware/arm_scmi/protocols.h @@ -163,6 +163,9 @@ struct scmi_proto_helpers_ops; * can be used by the protocol implementation to generate SCMI messages. * @set_priv: A method to set protocol private data for this instance. * @get_priv: A method to get protocol private data previously set. + * @notifier_register: A method to register interest for notifications from + * within a protocol implementation unit: notifiers can + * be registered only for the same protocol. * * This structure represents a protocol initialized against specific SCMI * instance and it will be used as follows: @@ -182,6 +185,9 @@ struct scmi_protocol_handle { int (*set_priv)(const struct scmi_protocol_handle *ph, void *priv, u32 version); void *(*get_priv)(const struct scmi_protocol_handle *ph); + int (*notifier_register)(const struct scmi_protocol_handle *ph, + u8 evt_id, const u32 *src_id, + struct notifier_block *nb); }; =20 /** --=20 2.52.0