From nobody Mon Feb 9 04:45:28 2026 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 vger.kernel.org (vger.kernel.org [23.128.96.18]) by smtp.lore.kernel.org (Postfix) with ESMTP id 5357FC6FD1D for ; Tue, 4 Apr 2023 11:51:23 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S234664AbjDDLvV (ORCPT ); Tue, 4 Apr 2023 07:51:21 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:55954 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S234997AbjDDLvA (ORCPT ); Tue, 4 Apr 2023 07:51:00 -0400 Received: from foss.arm.com (foss.arm.com [217.140.110.172]) by lindbergh.monkeyblade.net (Postfix) with ESMTP id D5CB530C1; Tue, 4 Apr 2023 04:50:52 -0700 (PDT) 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 1CEDAFEC; Tue, 4 Apr 2023 04:51:37 -0700 (PDT) Received: from e120937-lin.. (unknown [172.31.20.19]) by usa-sjc-imap-foss1.foss.arm.com (Postfix) with ESMTPSA id 282F83F762; Tue, 4 Apr 2023 04:50:51 -0700 (PDT) From: Cristian Marussi To: linux-kernel@vger.kernel.org, linux-arm-kernel@lists.infradead.org, devicetree@vger.kernel.org Cc: sudeep.holla@arm.com, vincent.guittot@linaro.org, souvik.chakravarty@arm.com, nicola.mazzucato@arm.com, Cristian Marussi , Rob Herring , Krzysztof Kozlowski Subject: [PATCH v3 1/2] dt-bindings: firmware: arm,scmi: Support mailboxes unidirectional channels Date: Tue, 4 Apr 2023 12:50:25 +0100 Message-Id: <20230404115026.2828149-2-cristian.marussi@arm.com> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20230404115026.2828149-1-cristian.marussi@arm.com> References: <20230404115026.2828149-1-cristian.marussi@arm.com> MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org Content-Type: text/plain; charset="utf-8" SCMI defines two kinds of communication channels between the agent and the platform: one bidirectional 'a2p' channel used by the agent to send SCMI commands and synchronously receive the related replies, and an optional 'p2a' unidirectional channel used to asynchronously receive delayed responses and notifications emitted from the platform. When configuring an SCMI transport based on mailboxes, the current binding supports only mailboxes providing bidirectional channels: in such a case one mailbox channel can be easily assigned to each SCMI channel as above described. In case, instead, to have to deal with mailboxes providing only distinct unidirectional channels, it becomes necessary to extend the binding in order to be able to bind 2 distinct unidirectional mailbox channels to the same SCMI 'a2p' channel. Bidirectional and unidirectional channels support for the SCMI mailbox transport can coexist by carefully considering the effective combination of defined 'mboxes' and 'shmem' descriptors. Signed-off-by: Cristian Marussi Reviewed-by: Rob Herring --- Cc: Rob Herring Cc: Krzysztof Kozlowski Cc: devicetree@vger.kernel.org v2 --> v3 - coalesced oneOf entries using proper minItems - removed unidirectional channels example v1 --> v2 - added mbox-names unidirectional definitions and example --- .../bindings/firmware/arm,scmi.yaml | 48 +++++++++++++++---- 1 file changed, 38 insertions(+), 10 deletions(-) diff --git a/Documentation/devicetree/bindings/firmware/arm,scmi.yaml b/Doc= umentation/devicetree/bindings/firmware/arm,scmi.yaml index 2f7c51c75e85..5824c43e9893 100644 --- a/Documentation/devicetree/bindings/firmware/arm,scmi.yaml +++ b/Documentation/devicetree/bindings/firmware/arm,scmi.yaml @@ -56,17 +56,38 @@ properties: description: Specifies the mailboxes used to communicate with SCMI compliant firmware. - items: - - const: tx - - const: rx + oneOf: + - items: + - const: tx + - const: rx + minItems: 1 + - items: + - const: tx + - const: tx_reply + - const: rx + minItems: 2 =20 mboxes: description: List of phandle and mailbox channel specifiers. It should contain - exactly one or two mailboxes, one for transmitting messages("tx") - and another optional for receiving the notifications("rx") if suppor= ted. + exactly one, two or three mailboxes; the first one or two for transm= itting + messages ("tx") and another optional ("rx") for receiving notificati= ons + and delayed responses, if supported by the platform. + The number of mailboxes needed for transmitting messages depends on = the + type of channels exposed by the specific underlying mailbox controll= er; + one single channel descriptor is enough if such channel is bidirecti= onal, + while two channel descriptors are needed to represent the SCMI ("tx") + channel if the underlying mailbox channels are of unidirectional typ= e. + The effective combination in numbers of mboxes and shmem descriptors= let + the SCMI subsystem determine unambiguosly which type of SCMI channel= s are + made available by the underlying mailbox controller and how to use t= hem. + 1 mbox / 1 shmem =3D> SCMI TX over 1 mailbox bidirectional channel + 2 mbox / 2 shmem =3D> SCMI TX and RX over 2 mailbox bidirectional c= hannels + 2 mbox / 1 shmem =3D> SCMI TX over 2 mailbox unidirectional channels + 3 mbox / 2 shmem =3D> SCMI TX and RX over 3 mailbox unidirectional = channels + Any other combination of mboxes and shmem is invalid. minItems: 1 - maxItems: 2 + maxItems: 3 =20 shmem: description: @@ -228,13 +249,20 @@ $defs: maxItems: 1 =20 mbox-names: - items: - - const: tx - - const: rx + oneOf: + - items: + - const: tx + - const: rx + minItems: 1 + - items: + - const: tx + - const: tx_reply + - const: rx + minItems: 2 =20 mboxes: minItems: 1 - maxItems: 2 + maxItems: 3 =20 shmem: minItems: 1 --=20 2.34.1 From nobody Mon Feb 9 04:45:28 2026 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 vger.kernel.org (vger.kernel.org [23.128.96.18]) by smtp.lore.kernel.org (Postfix) with ESMTP id 53F43C761A6 for ; Tue, 4 Apr 2023 11:51:27 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S235004AbjDDLvZ (ORCPT ); Tue, 4 Apr 2023 07:51:25 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:56086 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S234971AbjDDLvD (ORCPT ); Tue, 4 Apr 2023 07:51:03 -0400 Received: from foss.arm.com (foss.arm.com [217.140.110.172]) by lindbergh.monkeyblade.net (Postfix) with ESMTP id 9765435A1; Tue, 4 Apr 2023 04:50:54 -0700 (PDT) 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 8E3B0153B; Tue, 4 Apr 2023 04:51:38 -0700 (PDT) Received: from e120937-lin.. (unknown [172.31.20.19]) by usa-sjc-imap-foss1.foss.arm.com (Postfix) with ESMTPSA id D24843F762; Tue, 4 Apr 2023 04:50:52 -0700 (PDT) From: Cristian Marussi To: linux-kernel@vger.kernel.org, linux-arm-kernel@lists.infradead.org, devicetree@vger.kernel.org Cc: sudeep.holla@arm.com, vincent.guittot@linaro.org, souvik.chakravarty@arm.com, nicola.mazzucato@arm.com, Cristian Marussi Subject: [PATCH v3 2/2] firmware: arm_scmi: Add support for unidirectional mailbox channels Date: Tue, 4 Apr 2023 12:50:26 +0100 Message-Id: <20230404115026.2828149-3-cristian.marussi@arm.com> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20230404115026.2828149-1-cristian.marussi@arm.com> References: <20230404115026.2828149-1-cristian.marussi@arm.com> MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org Content-Type: text/plain; charset="utf-8" Extend the SCMI transport layer to support mailbox controllers that expose communication channels that are unidirectional by nature. Signed-off-by: Cristian Marussi --- drivers/firmware/arm_scmi/mailbox.c | 95 +++++++++++++++++++++++++---- 1 file changed, 84 insertions(+), 11 deletions(-) diff --git a/drivers/firmware/arm_scmi/mailbox.c b/drivers/firmware/arm_scm= i/mailbox.c index 112c285deb97..1efa5e9392c4 100644 --- a/drivers/firmware/arm_scmi/mailbox.c +++ b/drivers/firmware/arm_scmi/mailbox.c @@ -19,13 +19,15 @@ * struct scmi_mailbox - Structure representing a SCMI mailbox transport * * @cl: Mailbox Client - * @chan: Transmit/Receive mailbox channel + * @chan: Transmit/Receive mailbox uni/bi-directional channel + * @chan_receiver: Optional Receiver mailbox unidirectional channel * @cinfo: SCMI channel info * @shmem: Transmit/Receive shared memory area */ struct scmi_mailbox { struct mbox_client cl; struct mbox_chan *chan; + struct mbox_chan *chan_receiver; struct scmi_chan_info *cinfo; struct scmi_shared_mem __iomem *shmem; }; @@ -48,30 +50,62 @@ static void rx_callback(struct mbox_client *cl, void *m) =20 static bool mailbox_chan_available(struct device_node *of_node, int idx) { + int num_mb; + + /* + * Just check if bidirrectional channels are involved, and check the + * index accordingly; proper full validation will be made later + * in mailbox_chan_setup(). + */ + num_mb =3D of_count_phandle_with_args(of_node, "mboxes", "#mbox-cells"); + if (num_mb =3D=3D 3 && idx =3D=3D 1) + idx =3D 2; + return !of_parse_phandle_with_args(of_node, "mboxes", "#mbox-cells", idx, NULL); } =20 -static int mailbox_chan_validate(struct device *cdev) +/** + * mailbox_chan_validate - Validate transport configuration and map chann= els + * + * @cdev: Reference to the underlying transport device carrying the + * of_node descriptor to analyze. + * @a2p_rx_chan: A reference to an optional unidirectional channel to use + * for replies on the a2p channel. Set as zero if not present. + * @p2a_chan: A reference to the optional p2a channel. + * Set as zero if not present. + * + * At first, validate the transport configuration as described in terms of + * 'mboxes' and 'shmem', then determin which mailbox channel indexes are + * appropriate to be use in the current configuration. + * + * Return: 0 on Success or error + */ +static int mailbox_chan_validate(struct device *cdev, + int *a2p_rx_chan, int *p2a_chan) { int num_mb, num_sh, ret =3D 0; struct device_node *np =3D cdev->of_node; =20 num_mb =3D of_count_phandle_with_args(np, "mboxes", "#mbox-cells"); num_sh =3D of_count_phandle_with_args(np, "shmem", NULL); + dev_dbg(cdev, "Found %d mboxes and %d shmems !\n", num_mb, num_sh); + /* Bail out if mboxes and shmem descriptors are inconsistent */ - if (num_mb <=3D 0 || num_sh > 2 || num_mb !=3D num_sh) { - dev_warn(cdev, "Invalid channel descriptor for '%s'\n", - of_node_full_name(np)); + if (num_mb <=3D 0 || num_sh <=3D 0 || num_sh > 2 || num_mb > 3 || + (num_mb =3D=3D 1 && num_sh !=3D 1) || (num_mb =3D=3D 3 && num_sh !=3D= 2)) { + dev_warn(cdev, + "Invalid channel descriptor for '%s' - mbs:%d shm:%d\n", + of_node_full_name(np), num_mb, num_sh); return -EINVAL; } =20 + /* Bail out if provided shmem descriptors do not refer distinct areas */ if (num_sh > 1) { struct device_node *np_tx, *np_rx; =20 np_tx =3D of_parse_phandle(np, "shmem", 0); np_rx =3D of_parse_phandle(np, "shmem", 1); - /* SCMI Tx and Rx shared mem areas have to be distinct */ if (!np_tx || !np_rx || np_tx =3D=3D np_rx) { dev_warn(cdev, "Invalid shmem descriptor for '%s'\n", of_node_full_name(np)); @@ -82,6 +116,29 @@ static int mailbox_chan_validate(struct device *cdev) of_node_put(np_rx); } =20 + /* Calculate channels IDs to use depending on mboxes/shmem layout */ + if (!ret) { + switch (num_mb) { + case 1: + *a2p_rx_chan =3D 0; + *p2a_chan =3D 0; + break; + case 2: + if (num_sh =3D=3D 2) { + *a2p_rx_chan =3D 0; + *p2a_chan =3D 1; + } else { + *a2p_rx_chan =3D 1; + *p2a_chan =3D 0; + } + break; + case 3: + *a2p_rx_chan =3D 1; + *p2a_chan =3D 2; + break; + } + } + return ret; } =20 @@ -92,15 +149,18 @@ static int mailbox_chan_setup(struct scmi_chan_info *c= info, struct device *dev, struct device *cdev =3D cinfo->dev; struct scmi_mailbox *smbox; struct device_node *shmem; - int ret, idx =3D tx ? 0 : 1; + int ret, a2p_rx_chan, p2a_chan, idx =3D tx ? 0 : 1; struct mbox_client *cl; resource_size_t size; struct resource res; =20 - ret =3D mailbox_chan_validate(cdev); + ret =3D mailbox_chan_validate(cdev, &a2p_rx_chan, &p2a_chan); if (ret) return ret; =20 + if (!tx && !p2a_chan) + return -ENODEV; + smbox =3D devm_kzalloc(dev, sizeof(*smbox), GFP_KERNEL); if (!smbox) return -ENOMEM; @@ -130,15 +190,26 @@ static int mailbox_chan_setup(struct scmi_chan_info *= cinfo, struct device *dev, cl->tx_block =3D false; cl->knows_txdone =3D tx; =20 - smbox->chan =3D mbox_request_channel(cl, tx ? 0 : 1); + smbox->chan =3D mbox_request_channel(cl, tx ? 0 : p2a_chan); if (IS_ERR(smbox->chan)) { ret =3D PTR_ERR(smbox->chan); if (ret !=3D -EPROBE_DEFER) - dev_err(cdev, "failed to request SCMI %s mailbox\n", - tx ? "Tx" : "Rx"); + dev_err(cdev, + "failed to request SCMI %s mailbox\n", desc); return ret; } =20 + /* Additional unidirectional channel for TX if needed */ + if (tx && a2p_rx_chan) { + smbox->chan_receiver =3D mbox_request_channel(cl, a2p_rx_chan); + if (IS_ERR(smbox->chan_receiver)) { + ret =3D PTR_ERR(smbox->chan_receiver); + if (ret !=3D -EPROBE_DEFER) + dev_err(cdev, "failed to request SCMI Tx Receiver mailbox\n"); + return ret; + } + } + cinfo->transport_info =3D smbox; smbox->cinfo =3D cinfo; =20 @@ -152,8 +223,10 @@ static int mailbox_chan_free(int id, void *p, void *da= ta) =20 if (smbox && !IS_ERR(smbox->chan)) { mbox_free_channel(smbox->chan); + mbox_free_channel(smbox->chan_receiver); cinfo->transport_info =3D NULL; smbox->chan =3D NULL; + smbox->chan_receiver =3D NULL; smbox->cinfo =3D NULL; } =20 --=20 2.34.1