Orange Pi5 kernel

Deprecated Linux kernel 5.10.110 for OrangePi 5/5B/5+ boards

3 Commits   0 Branches   0 Tags   |
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   1) /* SPDX-License-Identifier: GPL-2.0 */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   2) /*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   3)  * System Control and Management Interface (SCMI) Message Protocol
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   4)  * driver common header file containing some definitions, structures
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   5)  * and function prototypes used in all the different SCMI protocols.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   6)  *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   7)  * Copyright (C) 2018 ARM Ltd.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   8)  */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   9) #ifndef _SCMI_COMMON_H
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  10) #define _SCMI_COMMON_H
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  11) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  12) #include <linux/bitfield.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  13) #include <linux/completion.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  14) #include <linux/device.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  15) #include <linux/errno.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  16) #include <linux/kernel.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  17) #include <linux/module.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  18) #include <linux/scmi_protocol.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  19) #include <linux/types.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  20) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  21) #include <asm/unaligned.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  22) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  23) #include "notify.h"
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  24) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  25) #define PROTOCOL_REV_MINOR_MASK	GENMASK(15, 0)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  26) #define PROTOCOL_REV_MAJOR_MASK	GENMASK(31, 16)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  27) #define PROTOCOL_REV_MAJOR(x)	(u16)(FIELD_GET(PROTOCOL_REV_MAJOR_MASK, (x)))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  28) #define PROTOCOL_REV_MINOR(x)	(u16)(FIELD_GET(PROTOCOL_REV_MINOR_MASK, (x)))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  29) #define MAX_PROTOCOLS_IMP	16
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  30) #define MAX_OPPS		16
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  31) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  32) enum scmi_common_cmd {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  33) 	PROTOCOL_VERSION = 0x0,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  34) 	PROTOCOL_ATTRIBUTES = 0x1,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  35) 	PROTOCOL_MESSAGE_ATTRIBUTES = 0x2,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  36) };
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  37) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  38) /**
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  39)  * struct scmi_msg_resp_prot_version - Response for a message
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  40)  *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  41)  * @minor_version: Minor version of the ABI that firmware supports
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  42)  * @major_version: Major version of the ABI that firmware supports
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  43)  *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  44)  * In general, ABI version changes follow the rule that minor version increments
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  45)  * are backward compatible. Major revision changes in ABI may not be
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  46)  * backward compatible.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  47)  *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  48)  * Response to a generic message with message type SCMI_MSG_VERSION
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  49)  */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  50) struct scmi_msg_resp_prot_version {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  51) 	__le16 minor_version;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  52) 	__le16 major_version;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  53) };
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  54) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  55) #define MSG_ID_MASK		GENMASK(7, 0)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  56) #define MSG_XTRACT_ID(hdr)	FIELD_GET(MSG_ID_MASK, (hdr))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  57) #define MSG_TYPE_MASK		GENMASK(9, 8)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  58) #define MSG_XTRACT_TYPE(hdr)	FIELD_GET(MSG_TYPE_MASK, (hdr))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  59) #define MSG_TYPE_COMMAND	0
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  60) #define MSG_TYPE_DELAYED_RESP	2
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  61) #define MSG_TYPE_NOTIFICATION	3
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  62) #define MSG_PROTOCOL_ID_MASK	GENMASK(17, 10)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  63) #define MSG_XTRACT_PROT_ID(hdr)	FIELD_GET(MSG_PROTOCOL_ID_MASK, (hdr))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  64) #define MSG_TOKEN_ID_MASK	GENMASK(27, 18)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  65) #define MSG_XTRACT_TOKEN(hdr)	FIELD_GET(MSG_TOKEN_ID_MASK, (hdr))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  66) #define MSG_TOKEN_MAX		(MSG_XTRACT_TOKEN(MSG_TOKEN_ID_MASK) + 1)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  67) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  68) /**
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  69)  * struct scmi_msg_hdr - Message(Tx/Rx) header
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  70)  *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  71)  * @id: The identifier of the message being sent
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  72)  * @protocol_id: The identifier of the protocol used to send @id message
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  73)  * @seq: The token to identify the message. When a message returns, the
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  74)  *	platform returns the whole message header unmodified including the
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  75)  *	token
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  76)  * @status: Status of the transfer once it's complete
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  77)  * @poll_completion: Indicate if the transfer needs to be polled for
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  78)  *	completion or interrupt mode is used
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  79)  */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  80) struct scmi_msg_hdr {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  81) 	u8 id;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  82) 	u8 protocol_id;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  83) 	u16 seq;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  84) 	u32 status;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  85) 	bool poll_completion;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  86) };
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  87) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  88) /**
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  89)  * pack_scmi_header() - packs and returns 32-bit header
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  90)  *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  91)  * @hdr: pointer to header containing all the information on message id,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  92)  *	protocol id and sequence id.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  93)  *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  94)  * Return: 32-bit packed message header to be sent to the platform.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  95)  */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  96) static inline u32 pack_scmi_header(struct scmi_msg_hdr *hdr)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  97) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  98) 	return FIELD_PREP(MSG_ID_MASK, hdr->id) |
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  99) 		FIELD_PREP(MSG_TOKEN_ID_MASK, hdr->seq) |
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 100) 		FIELD_PREP(MSG_PROTOCOL_ID_MASK, hdr->protocol_id);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 101) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 102) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 103) /**
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 104)  * unpack_scmi_header() - unpacks and records message and protocol id
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 105)  *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 106)  * @msg_hdr: 32-bit packed message header sent from the platform
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 107)  * @hdr: pointer to header to fetch message and protocol id.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 108)  */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 109) static inline void unpack_scmi_header(u32 msg_hdr, struct scmi_msg_hdr *hdr)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 110) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 111) 	hdr->id = MSG_XTRACT_ID(msg_hdr);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 112) 	hdr->protocol_id = MSG_XTRACT_PROT_ID(msg_hdr);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 113) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 114) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 115) /**
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 116)  * struct scmi_msg - Message(Tx/Rx) structure
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 117)  *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 118)  * @buf: Buffer pointer
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 119)  * @len: Length of data in the Buffer
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 120)  */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 121) struct scmi_msg {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 122) 	void *buf;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 123) 	size_t len;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 124) };
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 125) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 126) /**
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 127)  * struct scmi_xfer - Structure representing a message flow
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 128)  *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 129)  * @transfer_id: Unique ID for debug & profiling purpose
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 130)  * @hdr: Transmit message header
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 131)  * @tx: Transmit message
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 132)  * @rx: Receive message, the buffer should be pre-allocated to store
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 133)  *	message. If request-ACK protocol is used, we can reuse the same
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 134)  *	buffer for the rx path as we use for the tx path.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 135)  * @done: command message transmit completion event
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 136)  * @async_done: pointer to delayed response message received event completion
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 137)  */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 138) struct scmi_xfer {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 139) 	int transfer_id;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 140) 	struct scmi_msg_hdr hdr;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 141) 	struct scmi_msg tx;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 142) 	struct scmi_msg rx;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 143) 	struct completion done;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 144) 	struct completion *async_done;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 145) };
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 146) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 147) struct scmi_xfer_ops;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 148) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 149) /**
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 150)  * struct scmi_protocol_handle  - Reference to an initialized protocol instance
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 151)  *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 152)  * @dev: A reference to the associated SCMI instance device (handle->dev).
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 153)  * @xops: A reference to a struct holding refs to the core xfer operations that
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 154)  *	  can be used by the protocol implementation to generate SCMI messages.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 155)  * @set_priv: A method to set protocol private data for this instance.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 156)  * @get_priv: A method to get protocol private data previously set.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 157)  *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 158)  * This structure represents a protocol initialized against specific SCMI
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 159)  * instance and it will be used as follows:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 160)  * - as a parameter fed from the core to the protocol initialization code so
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 161)  *   that it can access the core xfer operations to build and generate SCMI
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 162)  *   messages exclusively for the specific underlying protocol instance.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 163)  * - as an opaque handle fed by an SCMI driver user when it tries to access
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 164)  *   this protocol through its own protocol operations.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 165)  *   In this case this handle will be returned as an opaque object together
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 166)  *   with the related protocol operations when the SCMI driver tries to access
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 167)  *   the protocol.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 168)  */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 169) struct scmi_protocol_handle {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 170) 	struct device *dev;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 171) 	const struct scmi_xfer_ops *xops;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 172) 	int (*set_priv)(const struct scmi_protocol_handle *ph, void *priv);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 173) 	void *(*get_priv)(const struct scmi_protocol_handle *ph);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 174) };
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 175) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 176) /**
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 177)  * struct scmi_xfer_ops  - References to the core SCMI xfer operations.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 178)  * @version_get: Get this version protocol.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 179)  * @xfer_get_init: Initialize one struct xfer if any xfer slot is free.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 180)  * @reset_rx_to_maxsz: Reset rx size to max transport size.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 181)  * @do_xfer: Do the SCMI transfer.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 182)  * @do_xfer_with_response: Do the SCMI transfer waiting for a response.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 183)  * @xfer_put: Free the xfer slot.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 184)  *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 185)  * Note that all this operations expect a protocol handle as first parameter;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 186)  * they then internally use it to infer the underlying protocol number: this
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 187)  * way is not possible for a protocol implementation to forge messages for
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 188)  * another protocol.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 189)  */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 190) struct scmi_xfer_ops {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 191) 	int (*version_get)(const struct scmi_protocol_handle *ph, u32 *version);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 192) 	int (*xfer_get_init)(const struct scmi_protocol_handle *ph, u8 msg_id,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 193) 			     size_t tx_size, size_t rx_size,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 194) 			     struct scmi_xfer **p);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 195) 	void (*reset_rx_to_maxsz)(const struct scmi_protocol_handle *ph,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 196) 				  struct scmi_xfer *xfer);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 197) 	int (*do_xfer)(const struct scmi_protocol_handle *ph,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 198) 		       struct scmi_xfer *xfer);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 199) 	int (*do_xfer_with_response)(const struct scmi_protocol_handle *ph,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 200) 				     struct scmi_xfer *xfer);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 201) 	void (*xfer_put)(const struct scmi_protocol_handle *ph,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 202) 			 struct scmi_xfer *xfer);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 203) };
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 204) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 205) struct scmi_revision_info *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 206) scmi_get_revision_area(const struct scmi_protocol_handle *ph);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 207) int scmi_handle_put(const struct scmi_handle *handle);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 208) struct scmi_handle *scmi_handle_get(struct device *dev);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 209) void scmi_set_handle(struct scmi_device *scmi_dev);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 210) void scmi_setup_protocol_implemented(const struct scmi_protocol_handle *ph,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 211) 				     u8 *prot_imp);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 212) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 213) typedef int (*scmi_prot_init_ph_fn_t)(const struct scmi_protocol_handle *);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 214) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 215) /**
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 216)  * struct scmi_protocol  - Protocol descriptor
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 217)  * @id: Protocol ID.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 218)  * @owner: Module reference if any.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 219)  * @init_instance: Mandatory protocol initialization function.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 220)  * @deinit_instance: Optional protocol de-initialization function.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 221)  * @ops: Optional reference to the operations provided by the protocol and
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 222)  *	 exposed in scmi_protocol.h.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 223)  * @events: An optional reference to the events supported by this protocol.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 224)  */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 225) struct scmi_protocol {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 226) 	const u8				id;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 227) 	struct module				*owner;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 228) 	const scmi_prot_init_ph_fn_t		init_instance;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 229) 	const scmi_prot_init_ph_fn_t		deinit_instance;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 230) 	const void				*ops;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 231) 	const struct scmi_protocol_events	*events;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 232) };
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 233) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 234) int __init scmi_bus_init(void);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 235) void __exit scmi_bus_exit(void);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 236) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 237) #define DECLARE_SCMI_REGISTER_UNREGISTER(func)		\
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 238) 	int __init scmi_##func##_register(void);	\
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 239) 	void __exit scmi_##func##_unregister(void)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 240) DECLARE_SCMI_REGISTER_UNREGISTER(base);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 241) DECLARE_SCMI_REGISTER_UNREGISTER(clock);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 242) DECLARE_SCMI_REGISTER_UNREGISTER(perf);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 243) DECLARE_SCMI_REGISTER_UNREGISTER(power);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 244) DECLARE_SCMI_REGISTER_UNREGISTER(reset);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 245) DECLARE_SCMI_REGISTER_UNREGISTER(sensors);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 246) DECLARE_SCMI_REGISTER_UNREGISTER(voltage);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 247) DECLARE_SCMI_REGISTER_UNREGISTER(system);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 248) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 249) #define DEFINE_SCMI_PROTOCOL_REGISTER_UNREGISTER(name, proto) \
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 250) int __init scmi_##name##_register(void) \
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 251) { \
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 252) 	return scmi_protocol_register(&(proto)); \
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 253) } \
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 254) \
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 255) void __exit scmi_##name##_unregister(void) \
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 256) { \
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 257) 	scmi_protocol_unregister(&(proto)); \
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 258) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 259) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 260) const struct scmi_protocol *scmi_get_protocol(int protocol_id);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 261) void scmi_put_protocol(int protocol_id);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 262) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 263) int scmi_acquire_protocol(const struct scmi_handle *handle, u8 protocol_id);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 264) void scmi_release_protocol(const struct scmi_handle *handle, u8 protocol_id);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 265) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 266) /* SCMI Transport */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 267) /**
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 268)  * struct scmi_chan_info - Structure representing a SCMI channel information
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 269)  *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 270)  * @dev: Reference to device in the SCMI hierarchy corresponding to this
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 271)  *	 channel
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 272)  * @handle: Pointer to SCMI entity handle
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 273)  * @transport_info: Transport layer related information
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 274)  */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 275) struct scmi_chan_info {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 276) 	struct device *dev;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 277) 	struct scmi_handle *handle;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 278) 	void *transport_info;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 279) };
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 280) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 281) /**
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 282)  * struct scmi_transport_ops - Structure representing a SCMI transport ops
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 283)  *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 284)  * @chan_available: Callback to check if channel is available or not
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 285)  * @chan_setup: Callback to allocate and setup a channel
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 286)  * @chan_free: Callback to free a channel
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 287)  * @send_message: Callback to send a message
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 288)  * @mark_txdone: Callback to mark tx as done
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 289)  * @fetch_response: Callback to fetch response
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 290)  * @fetch_notification: Callback to fetch notification
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 291)  * @clear_channel: Callback to clear a channel
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 292)  * @poll_done: Callback to poll transfer status
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 293)  */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 294) struct scmi_transport_ops {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 295) 	bool (*chan_available)(struct device *dev, int idx);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 296) 	int (*chan_setup)(struct scmi_chan_info *cinfo, struct device *dev,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 297) 			  bool tx);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 298) 	int (*chan_free)(int id, void *p, void *data);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 299) 	int (*send_message)(struct scmi_chan_info *cinfo,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 300) 			    struct scmi_xfer *xfer);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 301) 	void (*mark_txdone)(struct scmi_chan_info *cinfo, int ret);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 302) 	void (*fetch_response)(struct scmi_chan_info *cinfo,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 303) 			       struct scmi_xfer *xfer);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 304) 	void (*fetch_notification)(struct scmi_chan_info *cinfo,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 305) 				   size_t max_len, struct scmi_xfer *xfer);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 306) 	void (*clear_channel)(struct scmi_chan_info *cinfo);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 307) 	bool (*poll_done)(struct scmi_chan_info *cinfo, struct scmi_xfer *xfer);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 308) };
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 309) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 310) int scmi_request_protocol_device(const struct scmi_device_id *id_table);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 311) void scmi_unrequest_protocol_device(const struct scmi_device_id *id_table);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 312) struct scmi_device *scmi_find_child_dev(struct device *parent,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 313) 					int prot_id, const char *name);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 314) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 315) /**
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 316)  * struct scmi_desc - Description of SoC integration
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 317)  *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 318)  * @ops: Pointer to the transport specific ops structure
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 319)  * @max_rx_timeout_ms: Timeout for communication with SoC (in Milliseconds)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 320)  * @max_msg: Maximum number of messages that can be pending
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 321)  *	simultaneously in the system
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 322)  * @max_msg_size: Maximum size of data per message that can be handled.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 323)  */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 324) struct scmi_desc {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 325) 	const struct scmi_transport_ops *ops;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 326) 	int max_rx_timeout_ms;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 327) 	int max_msg;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 328) 	int max_msg_size;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 329) };
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 330) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 331) extern const struct scmi_desc scmi_mailbox_desc;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 332) #ifdef CONFIG_HAVE_ARM_SMCCC_DISCOVERY
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 333) extern const struct scmi_desc scmi_smc_desc;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 334) #endif
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 335) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 336) void scmi_rx_callback(struct scmi_chan_info *cinfo, u32 msg_hdr);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 337) void scmi_free_channel(struct scmi_chan_info *cinfo, struct idr *idr, int id);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 338) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 339) /* shmem related declarations */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 340) struct scmi_shared_mem;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 341) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 342) void shmem_tx_prepare(struct scmi_shared_mem __iomem *shmem,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 343) 		      struct scmi_xfer *xfer);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 344) u32 shmem_read_header(struct scmi_shared_mem __iomem *shmem);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 345) void shmem_fetch_response(struct scmi_shared_mem __iomem *shmem,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 346) 			  struct scmi_xfer *xfer);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 347) void shmem_fetch_notification(struct scmi_shared_mem __iomem *shmem,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 348) 			      size_t max_len, struct scmi_xfer *xfer);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 349) void shmem_clear_channel(struct scmi_shared_mem __iomem *shmem);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 350) bool shmem_poll_done(struct scmi_shared_mem __iomem *shmem,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 351) 		     struct scmi_xfer *xfer);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 352) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 353) void scmi_set_notification_instance_data(const struct scmi_handle *handle,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 354) 					 void *priv);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 355) void *scmi_get_notification_instance_data(const struct scmi_handle *handle);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 356) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 357) #endif /* _SCMI_COMMON_H */