Commit b53515fa authored by Cristian Marussi's avatar Cristian Marussi Committed by Sudeep Holla

firmware: arm_scmi: Make MBOX transport a standalone driver

Make SCMI mailbox transport a standalone driver that can be optionally
loaded as a module; while at it, create a dedicated subdirectory and
submenu for SCMI Transports.
Signed-off-by: default avatarCristian Marussi <cristian.marussi@arm.com>
Message-Id: <20240812173340.3912830-6-cristian.marussi@arm.com>
Signed-off-by: default avatarSudeep Holla <sudeep.holla@arm.com>
parent 8b76a8c9
...@@ -69,36 +69,7 @@ config ARM_SCMI_DEBUG_COUNTERS ...@@ -69,36 +69,7 @@ config ARM_SCMI_DEBUG_COUNTERS
such useful debug counters. This can be helpful for debugging and such useful debug counters. This can be helpful for debugging and
SCMI monitoring. SCMI monitoring.
config ARM_SCMI_HAVE_TRANSPORT source "drivers/firmware/arm_scmi/transports/Kconfig"
bool
help
This declares whether at least one SCMI transport has been configured.
Used to trigger a build bug when trying to build SCMI without any
configured transport.
config ARM_SCMI_HAVE_SHMEM
bool
help
This declares whether a shared memory based transport for SCMI is
available.
config ARM_SCMI_HAVE_MSG
bool
help
This declares whether a message passing based transport for SCMI is
available.
config ARM_SCMI_TRANSPORT_MAILBOX
bool "SCMI transport based on Mailbox"
depends on MAILBOX
select ARM_SCMI_HAVE_TRANSPORT
select ARM_SCMI_HAVE_SHMEM
default y
help
Enable mailbox based transport for SCMI.
If you want the ARM SCMI PROTOCOL stack to include support for a
transport based on mailboxes, answer Y.
config ARM_SCMI_TRANSPORT_OPTEE config ARM_SCMI_TRANSPORT_OPTEE
bool "SCMI transport based on OP-TEE service" bool "SCMI transport based on OP-TEE service"
......
...@@ -5,7 +5,6 @@ scmi-core-objs := $(scmi-bus-y) ...@@ -5,7 +5,6 @@ scmi-core-objs := $(scmi-bus-y)
scmi-driver-y = driver.o notify.o scmi-driver-y = driver.o notify.o
scmi-driver-$(CONFIG_ARM_SCMI_RAW_MODE_SUPPORT) += raw_mode.o scmi-driver-$(CONFIG_ARM_SCMI_RAW_MODE_SUPPORT) += raw_mode.o
scmi-transport-$(CONFIG_ARM_SCMI_HAVE_SHMEM) = shmem.o scmi-transport-$(CONFIG_ARM_SCMI_HAVE_SHMEM) = shmem.o
scmi-transport-$(CONFIG_ARM_SCMI_TRANSPORT_MAILBOX) += mailbox.o
scmi-transport-$(CONFIG_ARM_SCMI_TRANSPORT_SMC) += smc.o scmi-transport-$(CONFIG_ARM_SCMI_TRANSPORT_SMC) += smc.o
scmi-transport-$(CONFIG_ARM_SCMI_HAVE_MSG) += msg.o scmi-transport-$(CONFIG_ARM_SCMI_HAVE_MSG) += msg.o
scmi-transport-$(CONFIG_ARM_SCMI_TRANSPORT_VIRTIO) += virtio.o scmi-transport-$(CONFIG_ARM_SCMI_TRANSPORT_VIRTIO) += virtio.o
...@@ -14,6 +13,8 @@ scmi-protocols-y := base.o clock.o perf.o power.o reset.o sensors.o system.o vol ...@@ -14,6 +13,8 @@ scmi-protocols-y := base.o clock.o perf.o power.o reset.o sensors.o system.o vol
scmi-protocols-y += pinctrl.o scmi-protocols-y += pinctrl.o
scmi-module-objs := $(scmi-driver-y) $(scmi-protocols-y) $(scmi-transport-y) scmi-module-objs := $(scmi-driver-y) $(scmi-protocols-y) $(scmi-transport-y)
obj-$(CONFIG_ARM_SCMI_PROTOCOL) += transports/
obj-$(CONFIG_ARM_SCMI_PROTOCOL) += scmi-core.o obj-$(CONFIG_ARM_SCMI_PROTOCOL) += scmi-core.o
obj-$(CONFIG_ARM_SCMI_PROTOCOL) += scmi-module.o obj-$(CONFIG_ARM_SCMI_PROTOCOL) += scmi-module.o
......
...@@ -286,9 +286,6 @@ int scmi_xfer_raw_inflight_register(const struct scmi_handle *handle, ...@@ -286,9 +286,6 @@ int scmi_xfer_raw_inflight_register(const struct scmi_handle *handle,
int scmi_xfer_raw_wait_for_message_response(struct scmi_chan_info *cinfo, int scmi_xfer_raw_wait_for_message_response(struct scmi_chan_info *cinfo,
struct scmi_xfer *xfer, struct scmi_xfer *xfer,
unsigned int timeout_ms); unsigned int timeout_ms);
#ifdef CONFIG_ARM_SCMI_TRANSPORT_MAILBOX
extern const struct scmi_desc scmi_mailbox_desc;
#endif
#ifdef CONFIG_ARM_SCMI_TRANSPORT_SMC #ifdef CONFIG_ARM_SCMI_TRANSPORT_SMC
extern const struct scmi_desc scmi_smc_desc; extern const struct scmi_desc scmi_smc_desc;
#endif #endif
......
...@@ -3318,9 +3318,6 @@ ATTRIBUTE_GROUPS(versions); ...@@ -3318,9 +3318,6 @@ ATTRIBUTE_GROUPS(versions);
/* Each compatible listed below must have descriptor associated with it */ /* Each compatible listed below must have descriptor associated with it */
static const struct of_device_id scmi_of_match[] = { static const struct of_device_id scmi_of_match[] = {
#ifdef CONFIG_ARM_SCMI_TRANSPORT_MAILBOX
{ .compatible = "arm,scmi", .data = &scmi_mailbox_desc },
#endif
#ifdef CONFIG_ARM_SCMI_TRANSPORT_OPTEE #ifdef CONFIG_ARM_SCMI_TRANSPORT_OPTEE
{ .compatible = "linaro,scmi-optee", .data = &scmi_optee_desc }, { .compatible = "linaro,scmi-optee", .data = &scmi_optee_desc },
#endif #endif
......
# SPDX-License-Identifier: GPL-2.0-only
menu "SCMI Transport Drivers"
config ARM_SCMI_HAVE_TRANSPORT
bool
help
This declares whether at least one SCMI transport has been configured.
Used to trigger a build bug when trying to build SCMI without any
configured transport.
config ARM_SCMI_HAVE_SHMEM
bool
help
This declares whether a shared memory based transport for SCMI is
available.
config ARM_SCMI_HAVE_MSG
bool
help
This declares whether a message passing based transport for SCMI is
available.
config ARM_SCMI_TRANSPORT_MAILBOX
tristate "SCMI transport based on Mailbox"
depends on MAILBOX
select ARM_SCMI_HAVE_TRANSPORT
select ARM_SCMI_HAVE_SHMEM
default y
help
Enable mailbox based transport for SCMI.
If you want the ARM SCMI PROTOCOL stack to include support for a
transport based on mailboxes, answer Y.
This driver can also be built as a module. If so, the module
will be called scmi_transport_mailbox.
endmenu
# SPDX-License-Identifier: GPL-2.0-only
scmi_transport_mailbox-objs := mailbox.o
obj-$(CONFIG_ARM_SCMI_TRANSPORT_MAILBOX) += scmi_transport_mailbox.o
...@@ -3,7 +3,7 @@ ...@@ -3,7 +3,7 @@
* System Control and Management Interface (SCMI) Message Mailbox Transport * System Control and Management Interface (SCMI) Message Mailbox Transport
* driver. * driver.
* *
* Copyright (C) 2019 ARM Ltd. * Copyright (C) 2019-2024 ARM Ltd.
*/ */
#include <linux/err.h> #include <linux/err.h>
...@@ -11,9 +11,10 @@ ...@@ -11,9 +11,10 @@
#include <linux/mailbox_client.h> #include <linux/mailbox_client.h>
#include <linux/of.h> #include <linux/of.h>
#include <linux/of_address.h> #include <linux/of_address.h>
#include <linux/platform_device.h>
#include <linux/slab.h> #include <linux/slab.h>
#include "common.h" #include "../common.h"
/** /**
* struct scmi_mailbox - Structure representing a SCMI mailbox transport * struct scmi_mailbox - Structure representing a SCMI mailbox transport
...@@ -36,11 +37,13 @@ struct scmi_mailbox { ...@@ -36,11 +37,13 @@ struct scmi_mailbox {
#define client_to_scmi_mailbox(c) container_of(c, struct scmi_mailbox, cl) #define client_to_scmi_mailbox(c) container_of(c, struct scmi_mailbox, cl)
static struct scmi_transport_core_operations *core;
static void tx_prepare(struct mbox_client *cl, void *m) static void tx_prepare(struct mbox_client *cl, void *m)
{ {
struct scmi_mailbox *smbox = client_to_scmi_mailbox(cl); struct scmi_mailbox *smbox = client_to_scmi_mailbox(cl);
scmi_shmem_ops.tx_prepare(smbox->shmem, m, smbox->cinfo); core->shmem->tx_prepare(smbox->shmem, m, smbox->cinfo);
} }
static void rx_callback(struct mbox_client *cl, void *m) static void rx_callback(struct mbox_client *cl, void *m)
...@@ -56,15 +59,17 @@ static void rx_callback(struct mbox_client *cl, void *m) ...@@ -56,15 +59,17 @@ static void rx_callback(struct mbox_client *cl, void *m)
* a previous timed-out reply which arrived late could be wrongly * a previous timed-out reply which arrived late could be wrongly
* associated with the next pending transaction. * associated with the next pending transaction.
*/ */
if (cl->knows_txdone && !scmi_shmem_ops.channel_free(smbox->shmem)) { if (cl->knows_txdone &&
!core->shmem->channel_free(smbox->shmem)) {
dev_warn(smbox->cinfo->dev, "Ignoring spurious A2P IRQ !\n"); dev_warn(smbox->cinfo->dev, "Ignoring spurious A2P IRQ !\n");
scmi_bad_message_trace(smbox->cinfo, core->bad_message_trace(smbox->cinfo,
scmi_shmem_ops.read_header(smbox->shmem), core->shmem->read_header(smbox->shmem),
MSG_MBOX_SPURIOUS); MSG_MBOX_SPURIOUS);
return; return;
} }
scmi_rx_callback(smbox->cinfo, scmi_shmem_ops.read_header(smbox->shmem), NULL); core->rx_callback(smbox->cinfo,
core->shmem->read_header(smbox->shmem), NULL);
} }
static bool mailbox_chan_available(struct device_node *of_node, int idx) static bool mailbox_chan_available(struct device_node *of_node, int idx)
...@@ -192,7 +197,7 @@ static int mailbox_chan_setup(struct scmi_chan_info *cinfo, struct device *dev, ...@@ -192,7 +197,7 @@ static int mailbox_chan_setup(struct scmi_chan_info *cinfo, struct device *dev,
if (!smbox) if (!smbox)
return -ENOMEM; return -ENOMEM;
smbox->shmem = scmi_shmem_ops.setup_iomap(cinfo, dev, tx, NULL); smbox->shmem = core->shmem->setup_iomap(cinfo, dev, tx, NULL);
if (IS_ERR(smbox->shmem)) if (IS_ERR(smbox->shmem))
return PTR_ERR(smbox->shmem); return PTR_ERR(smbox->shmem);
...@@ -293,7 +298,7 @@ static void mailbox_fetch_response(struct scmi_chan_info *cinfo, ...@@ -293,7 +298,7 @@ static void mailbox_fetch_response(struct scmi_chan_info *cinfo,
{ {
struct scmi_mailbox *smbox = cinfo->transport_info; struct scmi_mailbox *smbox = cinfo->transport_info;
scmi_shmem_ops.fetch_response(smbox->shmem, xfer); core->shmem->fetch_response(smbox->shmem, xfer);
} }
static void mailbox_fetch_notification(struct scmi_chan_info *cinfo, static void mailbox_fetch_notification(struct scmi_chan_info *cinfo,
...@@ -301,7 +306,7 @@ static void mailbox_fetch_notification(struct scmi_chan_info *cinfo, ...@@ -301,7 +306,7 @@ static void mailbox_fetch_notification(struct scmi_chan_info *cinfo,
{ {
struct scmi_mailbox *smbox = cinfo->transport_info; struct scmi_mailbox *smbox = cinfo->transport_info;
scmi_shmem_ops.fetch_notification(smbox->shmem, max_len, xfer); core->shmem->fetch_notification(smbox->shmem, max_len, xfer);
} }
static void mailbox_clear_channel(struct scmi_chan_info *cinfo) static void mailbox_clear_channel(struct scmi_chan_info *cinfo)
...@@ -310,9 +315,9 @@ static void mailbox_clear_channel(struct scmi_chan_info *cinfo) ...@@ -310,9 +315,9 @@ static void mailbox_clear_channel(struct scmi_chan_info *cinfo)
struct mbox_chan *intr_chan; struct mbox_chan *intr_chan;
int ret; int ret;
scmi_shmem_ops.clear_channel(smbox->shmem); core->shmem->clear_channel(smbox->shmem);
if (!scmi_shmem_ops.channel_intr_enabled(smbox->shmem)) if (!core->shmem->channel_intr_enabled(smbox->shmem))
return; return;
if (smbox->chan_platform_receiver) if (smbox->chan_platform_receiver)
...@@ -335,7 +340,7 @@ mailbox_poll_done(struct scmi_chan_info *cinfo, struct scmi_xfer *xfer) ...@@ -335,7 +340,7 @@ mailbox_poll_done(struct scmi_chan_info *cinfo, struct scmi_xfer *xfer)
{ {
struct scmi_mailbox *smbox = cinfo->transport_info; struct scmi_mailbox *smbox = cinfo->transport_info;
return scmi_shmem_ops.poll_done(smbox->shmem, xfer); return core->shmem->poll_done(smbox->shmem, xfer);
} }
static const struct scmi_transport_ops scmi_mailbox_ops = { static const struct scmi_transport_ops scmi_mailbox_ops = {
...@@ -350,9 +355,22 @@ static const struct scmi_transport_ops scmi_mailbox_ops = { ...@@ -350,9 +355,22 @@ static const struct scmi_transport_ops scmi_mailbox_ops = {
.poll_done = mailbox_poll_done, .poll_done = mailbox_poll_done,
}; };
const struct scmi_desc scmi_mailbox_desc = { static const struct scmi_desc scmi_mailbox_desc = {
.ops = &scmi_mailbox_ops, .ops = &scmi_mailbox_ops,
.max_rx_timeout_ms = 30, /* We may increase this if required */ .max_rx_timeout_ms = 30, /* We may increase this if required */
.max_msg = 20, /* Limited by MBOX_TX_QUEUE_LEN */ .max_msg = 20, /* Limited by MBOX_TX_QUEUE_LEN */
.max_msg_size = 128, .max_msg_size = 128,
}; };
static const struct of_device_id scmi_of_match[] = {
{ .compatible = "arm,scmi" },
{ /* Sentinel */ },
};
DEFINE_SCMI_TRANSPORT_DRIVER(scmi_mailbox, scmi_mailbox_driver,
scmi_mailbox_desc, scmi_of_match, core);
module_platform_driver(scmi_mailbox_driver);
MODULE_AUTHOR("Sudeep Holla <sudeep.holla@arm.com>");
MODULE_DESCRIPTION("SCMI Mailbox Transport driver");
MODULE_LICENSE("GPL");
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment