mirror of
https://mirrors.bfsu.edu.cn/git/linux.git
synced 2024-11-15 00:04:15 +08:00
firmware: arm_scmi: Add message passing abstractions for transports
Add abstractions for future transports using message passing, such as virtio. Derive the abstractions from the shared memory abstractions. Abstract the transport SDU through the opaque struct scmi_msg_payld. Also enable the transport to determine all other required information about the transport SDU. Link: https://lore.kernel.org/r/20210803131024.40280-12-cristian.marussi@arm.com Signed-off-by: Peter Hilber <peter.hilber@opensynergy.com> [ Cristian: Adapted to new SCMI Kconfig layout, updated Copyrights ] Signed-off-by: Cristian Marussi <cristian.marussi@arm.com> Signed-off-by: Sudeep Holla <sudeep.holla@arm.com>
This commit is contained in:
parent
c92c3e382e
commit
f301bba0ca
@ -36,6 +36,12 @@ config ARM_SCMI_HAVE_SHMEM
|
||||
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
|
||||
|
@ -4,6 +4,7 @@ scmi-driver-y = driver.o notify.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_HAVE_MSG) += msg.o
|
||||
scmi-protocols-y = base.o clock.o perf.o power.o reset.o sensors.o system.o voltage.o
|
||||
scmi-module-objs := $(scmi-bus-y) $(scmi-driver-y) $(scmi-protocols-y) \
|
||||
$(scmi-transport-y)
|
||||
|
@ -432,6 +432,21 @@ void shmem_clear_channel(struct scmi_shared_mem __iomem *shmem);
|
||||
bool shmem_poll_done(struct scmi_shared_mem __iomem *shmem,
|
||||
struct scmi_xfer *xfer);
|
||||
|
||||
/* declarations for message passing transports */
|
||||
struct scmi_msg_payld;
|
||||
|
||||
/* Maximum overhead of message w.r.t. struct scmi_desc.max_msg_size */
|
||||
#define SCMI_MSG_MAX_PROT_OVERHEAD (2 * sizeof(__le32))
|
||||
|
||||
size_t msg_response_size(struct scmi_xfer *xfer);
|
||||
size_t msg_command_size(struct scmi_xfer *xfer);
|
||||
void msg_tx_prepare(struct scmi_msg_payld *msg, struct scmi_xfer *xfer);
|
||||
u32 msg_read_header(struct scmi_msg_payld *msg);
|
||||
void msg_fetch_response(struct scmi_msg_payld *msg, size_t len,
|
||||
struct scmi_xfer *xfer);
|
||||
void msg_fetch_notification(struct scmi_msg_payld *msg, size_t len,
|
||||
size_t max_len, struct scmi_xfer *xfer);
|
||||
|
||||
void scmi_notification_instance_data_set(const struct scmi_handle *handle,
|
||||
void *priv);
|
||||
void *scmi_notification_instance_data_get(const struct scmi_handle *handle);
|
||||
|
111
drivers/firmware/arm_scmi/msg.c
Normal file
111
drivers/firmware/arm_scmi/msg.c
Normal file
@ -0,0 +1,111 @@
|
||||
// SPDX-License-Identifier: GPL-2.0
|
||||
/*
|
||||
* For transports using message passing.
|
||||
*
|
||||
* Derived from shm.c.
|
||||
*
|
||||
* Copyright (C) 2019-2021 ARM Ltd.
|
||||
* Copyright (C) 2020-2021 OpenSynergy GmbH
|
||||
*/
|
||||
|
||||
#include <linux/types.h>
|
||||
|
||||
#include "common.h"
|
||||
|
||||
/*
|
||||
* struct scmi_msg_payld - Transport SDU layout
|
||||
*
|
||||
* The SCMI specification requires all parameters, message headers, return
|
||||
* arguments or any protocol data to be expressed in little endian format only.
|
||||
*/
|
||||
struct scmi_msg_payld {
|
||||
__le32 msg_header;
|
||||
__le32 msg_payload[];
|
||||
};
|
||||
|
||||
/**
|
||||
* msg_command_size() - Actual size of transport SDU for command.
|
||||
*
|
||||
* @xfer: message which core has prepared for sending
|
||||
*
|
||||
* Return: transport SDU size.
|
||||
*/
|
||||
size_t msg_command_size(struct scmi_xfer *xfer)
|
||||
{
|
||||
return sizeof(struct scmi_msg_payld) + xfer->tx.len;
|
||||
}
|
||||
|
||||
/**
|
||||
* msg_response_size() - Maximum size of transport SDU for response.
|
||||
*
|
||||
* @xfer: message which core has prepared for sending
|
||||
*
|
||||
* Return: transport SDU size.
|
||||
*/
|
||||
size_t msg_response_size(struct scmi_xfer *xfer)
|
||||
{
|
||||
return sizeof(struct scmi_msg_payld) + sizeof(__le32) + xfer->rx.len;
|
||||
}
|
||||
|
||||
/**
|
||||
* msg_tx_prepare() - Set up transport SDU for command.
|
||||
*
|
||||
* @msg: transport SDU for command
|
||||
* @xfer: message which is being sent
|
||||
*/
|
||||
void msg_tx_prepare(struct scmi_msg_payld *msg, struct scmi_xfer *xfer)
|
||||
{
|
||||
msg->msg_header = cpu_to_le32(pack_scmi_header(&xfer->hdr));
|
||||
if (xfer->tx.buf)
|
||||
memcpy(msg->msg_payload, xfer->tx.buf, xfer->tx.len);
|
||||
}
|
||||
|
||||
/**
|
||||
* msg_read_header() - Read SCMI header from transport SDU.
|
||||
*
|
||||
* @msg: transport SDU
|
||||
*
|
||||
* Return: SCMI header
|
||||
*/
|
||||
u32 msg_read_header(struct scmi_msg_payld *msg)
|
||||
{
|
||||
return le32_to_cpu(msg->msg_header);
|
||||
}
|
||||
|
||||
/**
|
||||
* msg_fetch_response() - Fetch response SCMI payload from transport SDU.
|
||||
*
|
||||
* @msg: transport SDU with response
|
||||
* @len: transport SDU size
|
||||
* @xfer: message being responded to
|
||||
*/
|
||||
void msg_fetch_response(struct scmi_msg_payld *msg, size_t len,
|
||||
struct scmi_xfer *xfer)
|
||||
{
|
||||
size_t prefix_len = sizeof(*msg) + sizeof(msg->msg_payload[0]);
|
||||
|
||||
xfer->hdr.status = le32_to_cpu(msg->msg_payload[0]);
|
||||
xfer->rx.len = min_t(size_t, xfer->rx.len,
|
||||
len >= prefix_len ? len - prefix_len : 0);
|
||||
|
||||
/* Take a copy to the rx buffer.. */
|
||||
memcpy(xfer->rx.buf, &msg->msg_payload[1], xfer->rx.len);
|
||||
}
|
||||
|
||||
/**
|
||||
* msg_fetch_notification() - Fetch notification payload from transport SDU.
|
||||
*
|
||||
* @msg: transport SDU with notification
|
||||
* @len: transport SDU size
|
||||
* @max_len: maximum SCMI payload size to fetch
|
||||
* @xfer: notification message
|
||||
*/
|
||||
void msg_fetch_notification(struct scmi_msg_payld *msg, size_t len,
|
||||
size_t max_len, struct scmi_xfer *xfer)
|
||||
{
|
||||
xfer->rx.len = min_t(size_t, max_len,
|
||||
len >= sizeof(*msg) ? len - sizeof(*msg) : 0);
|
||||
|
||||
/* Take a copy to the rx buffer.. */
|
||||
memcpy(xfer->rx.buf, msg->msg_payload, xfer->rx.len);
|
||||
}
|
Loading…
Reference in New Issue
Block a user