firmware: arm_scmi: Make scmi core independent of the transport type
v6 cover firmware: arm_scmi: Make scmi core independent of the transport type
Hello,
This patchset makes the scmi core (driver.c) independent of mailbox transport.
V5->V6:
- Divide the patchset into multiple logical patches.
- Create shmem.c to separate out shared mem related helpers.
- Make mark_txdone() optional.
- Drop inclusion of stddef.h.
V4->V5:
- struct scmi_shared_mem is moved to mailbox.c and it is completely handled by transport layer now.
- And so lots of ops change due to this.
- Fixed a bug from previous version where wrong dev structure was getting passed to devm_kzalloc().
V3->V4:
- Rebased on top of linux-next.
V2->V3:
- Added more ops to the structure to read/write/memcpy data
- Payload is moved to mailbox.c and is handled in transport specific way now. This resulted in lots of changes.
V1->V2:
- Dropped __iomem from payload data.
- Moved transport ops to scmi_desc, and that has a per transport instance now which is differentiated using the compatible string.
- Converted IS_ERR_OR_NULL to IS_ERR.
Viresh Kumar (3):
firmware: arm_scmi: Update doc style comments
firmware: arm_scmi: Move macros and helpers to common.h
firmware: arm_scmi: Make scmi core independent of the transport type
drivers/firmware/arm_scmi/Makefile | 3 +- drivers/firmware/arm_scmi/common.h | 112 ++++++++++- drivers/firmware/arm_scmi/driver.c | 293 ++++------------------------ drivers/firmware/arm_scmi/mailbox.c | 184 +++++++++++++++++ drivers/firmware/arm_scmi/shmem.c | 82 ++++++++ 5 files changed, 412 insertions(+), 262 deletions(-) create mode 100644 drivers/firmware/arm_scmi/mailbox.c create mode 100644 drivers/firmware/arm_scmi/shmem.c
Signature · 1 line
2.21.0.rc0.269.g1a574e7a288b
PATCH v6 1/3 firmware: arm_scmi: Update doc style comments
Fix minor formatting issues with the doc style comments.
--- drivers/firmware/arm_scmi/common.h | 4 ++-- drivers/firmware/arm_scmi/driver.c | 2 +- 2 files changed, 3 insertions(+), 3 deletions(-)
drivers/firmware/arm_scmi/common.h +2 -2
@@ -33,8 +33,8 @@ enum scmi_common_cmd {/** * struct scmi_msg_resp_prot_version - Response for a message * -* @major_version: Major version of the ABI that firmware supports * @minor_version: Minor version of the ABI that firmware supports +* @major_version: Major version of the ABI that firmware supports * * In general, ABI version changes follow the rule that minor version increments * are backward compatible. Major revision changes in ABI may not be
@@ -88,7 +88,7 @@ struct scmi_msg {* message. If request-ACK protocol is used, we can reuse the same * buffer for the rx path as we use for the tx path. * @done: command message transmit completion event -* @async: pointer to delayed response message received event completion +* @async_done: pointer to delayed response message received event completion */ struct scmi_xfer {int transfer_id;
drivers/firmware/arm_scmi/driver.c +1 -1
@@ -119,9 +119,9 @@ struct scmi_chan_info {* * @dev: Device pointer * @desc: SoC description for this instance -* @handle: Instance of SCMI handle to send to clients * @version: SCMI revision information containing protocol version, * implementation version and (sub-)vendor identification. +* @handle: Instance of SCMI handle to send to clients * @tx_minfo: Universal Transmit Message management info * @tx_idr: IDR object to map protocol id to Tx channel info pointer * @rx_idr: IDR object to map protocol id to Rx channel info pointer
Signature · 1 line
2.21.0.rc0.269.g1a574e7a288b
PATCH v6 2/3 firmware: arm_scmi: Move macros and helpers to common.h
In reply to Viresh KumarMove message header specific macros and helper routines to common.h as they will be used outside of driver.c in a later commit.
--- drivers/firmware/arm_scmi/common.h | 40 ++++++++++++++++++++++++++++++ drivers/firmware/arm_scmi/driver.c | 40 ------------------------------ 2 files changed, 40 insertions(+), 40 deletions(-)
drivers/firmware/arm_scmi/common.h +40 -0
@@ -47,6 +47,19 @@ struct scmi_msg_resp_prot_version {__le16 major_version; }; +#define MSG_ID_MASK GENMASK(7, 0) +#define MSG_XTRACT_ID (hdr) FIELD_GET(MSG_ID_MASK, (hdr)) +#define MSG_TYPE_MASK GENMASK(9, 8) +#define MSG_XTRACT_TYPE (hdr) FIELD_GET(MSG_TYPE_MASK, (hdr)) +#define MSG_TYPE_COMMAND 0 +#define MSG_TYPE_DELAYED_RESP 2 +#define MSG_TYPE_NOTIFICATION 3 +#define MSG_PROTOCOL_ID_MASK GENMASK(17, 10) +#define MSG_XTRACT_PROT_ID (hdr) FIELD_GET(MSG_PROTOCOL_ID_MASK, (hdr)) +#define MSG_TOKEN_ID_MASK GENMASK(27, 18) +#define MSG_XTRACT_TOKEN (hdr) FIELD_GET(MSG_TOKEN_ID_MASK, (hdr)) +#define MSG_TOKEN_MAX (MSG_XTRACT_TOKEN(MSG_TOKEN_ID_MASK) + 1) +/** * struct scmi_msg_hdr - Message(Tx/Rx) header *
@@ -67,6 +80,33 @@ struct scmi_msg_hdr {bool poll_completion; }; +/** +* pack_scmi_header() - packs and returns 32-bit header +* +* @hdr: pointer to header containing all the information on message id, +* protocol id and sequence id. +* +* Return: 32-bit packed message header to be sent to the platform. +*/ +static inline u32 pack_scmi_header (struct scmi_msg_hdr *hdr) +{ +return FIELD_PREP (MSG_ID_MASK , hdr->id) | +FIELD_PREP (MSG_TOKEN_ID_MASK , hdr->seq) | +FIELD_PREP (MSG_PROTOCOL_ID_MASK , hdr->protocol_id); +} + +/** +* unpack_scmi_header() - unpacks and records message and protocol id +* +* @msg_hdr: 32-bit packed message header sent from the platform +* @hdr: pointer to header to fetch message and protocol id. +*/ +static inline void unpack_scmi_header (u32 msg_hdr,struct scmi_msg_hdr *hdr) +{ + hdr->id =MSG_XTRACT_ID (msg_hdr); + hdr->protocol_id =MSG_XTRACT_PROT_ID (msg_hdr); +} +/** * struct scmi_msg - Message(Tx/Rx) structure *
drivers/firmware/arm_scmi/driver.c +0 -40
@@ -32,19 +32,6 @@#define CREATE_TRACE_POINTS #include <trace/events/scmi.h> -#define MSG_ID_MASK GENMASK(7, 0) -#define MSG_XTRACT_ID (hdr) FIELD_GET(MSG_ID_MASK, (hdr)) -#define MSG_TYPE_MASK GENMASK(9, 8) -#define MSG_XTRACT_TYPE (hdr) FIELD_GET(MSG_TYPE_MASK, (hdr)) -#define MSG_TYPE_COMMAND 0 -#define MSG_TYPE_DELAYED_RESP 2 -#define MSG_TYPE_NOTIFICATION 3 -#define MSG_PROTOCOL_ID_MASK GENMASK(17, 10) -#define MSG_XTRACT_PROT_ID (hdr) FIELD_GET(MSG_PROTOCOL_ID_MASK, (hdr)) -#define MSG_TOKEN_ID_MASK GENMASK(27, 18) -#define MSG_XTRACT_TOKEN (hdr) FIELD_GET(MSG_TOKEN_ID_MASK, (hdr)) -#define MSG_TOKEN_MAX (MSG_XTRACT_TOKEN(MSG_TOKEN_ID_MASK) + 1) -enum scmi_error_codes {SCMI_SUCCESS =0 ,/* Success */ SCMI_ERR_SUPPORT =-1 ,/* Not supported */
@@ -210,33 +197,6 @@ static void scmi_fetch_response(struct scmi_xfer *xfer,memcpy_fromio (xfer->rx.buf, mem->msg_payload +4 , xfer->rx.len); } -/** -* pack_scmi_header() - packs and returns 32-bit header -* -* @hdr: pointer to header containing all the information on message id, -* protocol id and sequence id. -* -* Return: 32-bit packed message header to be sent to the platform. -*/ -static inline u32 pack_scmi_header (struct scmi_msg_hdr *hdr) -{ -return FIELD_PREP (MSG_ID_MASK , hdr->id) | -FIELD_PREP (MSG_TOKEN_ID_MASK , hdr->seq) | -FIELD_PREP (MSG_PROTOCOL_ID_MASK , hdr->protocol_id); -} - -/** -* unpack_scmi_header() - unpacks and records message and protocol id -* -* @msg_hdr: 32-bit packed message header sent from the platform -* @hdr: pointer to header to fetch message and protocol id. -*/ -static inline void unpack_scmi_header (u32 msg_hdr,struct scmi_msg_hdr *hdr) -{ - hdr->id =MSG_XTRACT_ID (msg_hdr); - hdr->protocol_id =MSG_XTRACT_PROT_ID (msg_hdr); -} -/** * scmi_tx_prepare() - mailbox client callback to prepare for the transfer *
Signature · 1 line
2.21.0.rc0.269.g1a574e7a288b
PATCH v6 3/3 firmware: arm_scmi: Make scmi core independent of the transport type
In reply to Viresh KumarThe SCMI specification is fairly independent of the transport protocol, which can be a simple mailbox (already implemented) or anything else. The current Linux implementation however is very much dependent on the mailbox transport layer.
This patch makes the SCMI core code (driver.c) independent of the mailbox transport layer and moves all mailbox related code to a new
file: mailbox.c and all struct shared_mem related code to a new file:shmem.c.
We can now implement more transport protocols to transport SCMI messages.
The transport protocols just need to provide struct scmi_transport_ops, with its version of the callbacks to enable exchange of SCMI messages.
--- drivers/firmware/arm_scmi/Makefile | 3 +- drivers/firmware/arm_scmi/common.h | 68 ++++++++ drivers/firmware/arm_scmi/driver.c | 251 ++++------------------------ drivers/firmware/arm_scmi/mailbox.c | 184 ++++++++++++++++++++ drivers/firmware/arm_scmi/shmem.c | 82 +++++++++ 5 files changed, 369 insertions(+), 219 deletions(-) create mode 100644 drivers/firmware/arm_scmi/mailbox.c create mode 100644 drivers/firmware/arm_scmi/shmem.c
drivers/firmware/arm_scmi/Makefile +2 -1
@@ -1,6 +1,7 @@ # SPDX-License-Identifier: GPL-2.0-only -obj-y = scmi-bus.o scmi-driver.o scmi-protocols.o +obj-y = scmi-bus.o scmi-driver.o scmi-protocols.o scmi-transport.o scmi-bus-y = bus.o scmi-driver-y = driver.o +scmi-transport-y = mailbox.o shmem.o scmi-protocols-y = base.o clock.o perf.o power.o reset.o sensors.o obj-$(CONFIG_ARM_SCMI_POWER_DOMAIN) += scmi_pm_domain.o
drivers/firmware/arm_scmi/common.h +68 -0
71 lines not on this page · raw message
drivers/firmware/arm_scmi/driver.c +33 -218
417 lines not on this page · raw message
drivers/firmware/arm_scmi/mailbox.c new file +184 -0
184 lines not on this page · raw message
drivers/firmware/arm_scmi/shmem.c new file +82 -0
82 lines not on this page · raw message
Signature · 1 line
2.21.0.rc0.269.g1a574e7a288b
Quoted 5 lines · Viresh Kumar
Hello,
This patchset makes the scmi core (
driver.c) independent of mailbox transport.
This version looks all good to me. I will apply for v5.7 once the merge window is closed and v5.6-rc1 is tagged. Thanks for doing this.
--
Regards,
Sudeep