Linux kernel mirror (for testing) git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git
kernel os linux

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>

authored by

Peter Hilber and committed by
Sudeep Holla
f301bba0 c92c3e38

+133
+6
drivers/firmware/arm_scmi/Kconfig
··· 36 36 This declares whether a shared memory based transport for SCMI is 37 37 available. 38 38 39 + config ARM_SCMI_HAVE_MSG 40 + bool 41 + help 42 + This declares whether a message passing based transport for SCMI is 43 + available. 44 + 39 45 config ARM_SCMI_TRANSPORT_MAILBOX 40 46 bool "SCMI transport based on Mailbox" 41 47 depends on MAILBOX
+1
drivers/firmware/arm_scmi/Makefile
··· 4 4 scmi-transport-$(CONFIG_ARM_SCMI_HAVE_SHMEM) = shmem.o 5 5 scmi-transport-$(CONFIG_ARM_SCMI_TRANSPORT_MAILBOX) += mailbox.o 6 6 scmi-transport-$(CONFIG_ARM_SCMI_TRANSPORT_SMC) += smc.o 7 + scmi-transport-$(CONFIG_ARM_SCMI_HAVE_MSG) += msg.o 7 8 scmi-protocols-y = base.o clock.o perf.o power.o reset.o sensors.o system.o voltage.o 8 9 scmi-module-objs := $(scmi-bus-y) $(scmi-driver-y) $(scmi-protocols-y) \ 9 10 $(scmi-transport-y)
+15
drivers/firmware/arm_scmi/common.h
··· 432 432 bool shmem_poll_done(struct scmi_shared_mem __iomem *shmem, 433 433 struct scmi_xfer *xfer); 434 434 435 + /* declarations for message passing transports */ 436 + struct scmi_msg_payld; 437 + 438 + /* Maximum overhead of message w.r.t. struct scmi_desc.max_msg_size */ 439 + #define SCMI_MSG_MAX_PROT_OVERHEAD (2 * sizeof(__le32)) 440 + 441 + size_t msg_response_size(struct scmi_xfer *xfer); 442 + size_t msg_command_size(struct scmi_xfer *xfer); 443 + void msg_tx_prepare(struct scmi_msg_payld *msg, struct scmi_xfer *xfer); 444 + u32 msg_read_header(struct scmi_msg_payld *msg); 445 + void msg_fetch_response(struct scmi_msg_payld *msg, size_t len, 446 + struct scmi_xfer *xfer); 447 + void msg_fetch_notification(struct scmi_msg_payld *msg, size_t len, 448 + size_t max_len, struct scmi_xfer *xfer); 449 + 435 450 void scmi_notification_instance_data_set(const struct scmi_handle *handle, 436 451 void *priv); 437 452 void *scmi_notification_instance_data_get(const struct scmi_handle *handle);
+111
drivers/firmware/arm_scmi/msg.c
··· 1 + // SPDX-License-Identifier: GPL-2.0 2 + /* 3 + * For transports using message passing. 4 + * 5 + * Derived from shm.c. 6 + * 7 + * Copyright (C) 2019-2021 ARM Ltd. 8 + * Copyright (C) 2020-2021 OpenSynergy GmbH 9 + */ 10 + 11 + #include <linux/types.h> 12 + 13 + #include "common.h" 14 + 15 + /* 16 + * struct scmi_msg_payld - Transport SDU layout 17 + * 18 + * The SCMI specification requires all parameters, message headers, return 19 + * arguments or any protocol data to be expressed in little endian format only. 20 + */ 21 + struct scmi_msg_payld { 22 + __le32 msg_header; 23 + __le32 msg_payload[]; 24 + }; 25 + 26 + /** 27 + * msg_command_size() - Actual size of transport SDU for command. 28 + * 29 + * @xfer: message which core has prepared for sending 30 + * 31 + * Return: transport SDU size. 32 + */ 33 + size_t msg_command_size(struct scmi_xfer *xfer) 34 + { 35 + return sizeof(struct scmi_msg_payld) + xfer->tx.len; 36 + } 37 + 38 + /** 39 + * msg_response_size() - Maximum size of transport SDU for response. 40 + * 41 + * @xfer: message which core has prepared for sending 42 + * 43 + * Return: transport SDU size. 44 + */ 45 + size_t msg_response_size(struct scmi_xfer *xfer) 46 + { 47 + return sizeof(struct scmi_msg_payld) + sizeof(__le32) + xfer->rx.len; 48 + } 49 + 50 + /** 51 + * msg_tx_prepare() - Set up transport SDU for command. 52 + * 53 + * @msg: transport SDU for command 54 + * @xfer: message which is being sent 55 + */ 56 + void msg_tx_prepare(struct scmi_msg_payld *msg, struct scmi_xfer *xfer) 57 + { 58 + msg->msg_header = cpu_to_le32(pack_scmi_header(&xfer->hdr)); 59 + if (xfer->tx.buf) 60 + memcpy(msg->msg_payload, xfer->tx.buf, xfer->tx.len); 61 + } 62 + 63 + /** 64 + * msg_read_header() - Read SCMI header from transport SDU. 65 + * 66 + * @msg: transport SDU 67 + * 68 + * Return: SCMI header 69 + */ 70 + u32 msg_read_header(struct scmi_msg_payld *msg) 71 + { 72 + return le32_to_cpu(msg->msg_header); 73 + } 74 + 75 + /** 76 + * msg_fetch_response() - Fetch response SCMI payload from transport SDU. 77 + * 78 + * @msg: transport SDU with response 79 + * @len: transport SDU size 80 + * @xfer: message being responded to 81 + */ 82 + void msg_fetch_response(struct scmi_msg_payld *msg, size_t len, 83 + struct scmi_xfer *xfer) 84 + { 85 + size_t prefix_len = sizeof(*msg) + sizeof(msg->msg_payload[0]); 86 + 87 + xfer->hdr.status = le32_to_cpu(msg->msg_payload[0]); 88 + xfer->rx.len = min_t(size_t, xfer->rx.len, 89 + len >= prefix_len ? len - prefix_len : 0); 90 + 91 + /* Take a copy to the rx buffer.. */ 92 + memcpy(xfer->rx.buf, &msg->msg_payload[1], xfer->rx.len); 93 + } 94 + 95 + /** 96 + * msg_fetch_notification() - Fetch notification payload from transport SDU. 97 + * 98 + * @msg: transport SDU with notification 99 + * @len: transport SDU size 100 + * @max_len: maximum SCMI payload size to fetch 101 + * @xfer: notification message 102 + */ 103 + void msg_fetch_notification(struct scmi_msg_payld *msg, size_t len, 104 + size_t max_len, struct scmi_xfer *xfer) 105 + { 106 + xfer->rx.len = min_t(size_t, max_len, 107 + len >= sizeof(*msg) ? len - sizeof(*msg) : 0); 108 + 109 + /* Take a copy to the rx buffer.. */ 110 + memcpy(xfer->rx.buf, msg->msg_payload, xfer->rx.len); 111 + }