/* SPDX-License-Identifier: GPL-2.0 */ /* * System Control and Management Interface (SCMI) Message Protocol * driver common header file containing some definitions, structures * and function prototypes used in all the different SCMI protocols. * * Copyright (C) 2018-2024 ARM Ltd. */ #ifndef _SCMI_COMMON_H #define _SCMI_COMMON_H #include <linux/bitfield.h> #include <linux/completion.h> #include <linux/device.h> #include <linux/errno.h> #include <linux/kernel.h> #include <linux/hashtable.h> #include <linux/list.h> #include <linux/module.h> #include <linux/refcount.h> #include <linux/scmi_protocol.h> #include <linux/spinlock.h> #include <linux/types.h> #include <linux/unaligned.h> #include "protocols.h" #include "notify.h" #define SCMI_MAX_CHANNELS … #define SCMI_MAX_RESPONSE_TIMEOUT … enum scmi_error_codes { … }; static const int scmi_linux_errmap[] = …; static inline int scmi_to_linux_errno(int errno) { … } #define MSG_ID_MASK … #define MSG_XTRACT_ID(hdr) … #define MSG_TYPE_MASK … #define MSG_XTRACT_TYPE(hdr) … #define MSG_TYPE_COMMAND … #define MSG_TYPE_DELAYED_RESP … #define MSG_TYPE_NOTIFICATION … #define MSG_PROTOCOL_ID_MASK … #define MSG_XTRACT_PROT_ID(hdr) … #define MSG_TOKEN_ID_MASK … #define MSG_XTRACT_TOKEN(hdr) … #define MSG_TOKEN_MAX … /* * Size of @pending_xfers hashtable included in @scmi_xfers_info; ideally, in * order to minimize space and collisions, this should equal max_msg, i.e. the * maximum number of in-flight messages on a specific platform, but such value * is only available at runtime while kernel hashtables are statically sized: * pick instead as a fixed static size the maximum number of entries that can * fit the whole table into one 4k page. */ #define SCMI_PENDING_XFERS_HT_ORDER_SZ … /** * pack_scmi_header() - packs and returns 32-bit header * * @hdr: pointer to header containing all the information on message id, * protocol id, sequence id and type. * * Return: 32-bit packed message header to be sent to the platform. */ static inline u32 pack_scmi_header(struct scmi_msg_hdr *hdr) { … } /** * 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) { … } /* * An helper macro to lookup an xfer from the @pending_xfers hashtable * using the message sequence number token as a key. */ #define XFER_FIND(__ht, __k) … struct scmi_revision_info * scmi_revision_area_get(const struct scmi_protocol_handle *ph); void scmi_setup_protocol_implemented(const struct scmi_protocol_handle *ph, u8 *prot_imp); extern const struct bus_type scmi_bus_type; #define SCMI_BUS_NOTIFY_DEVICE_REQUEST … #define SCMI_BUS_NOTIFY_DEVICE_UNREQUEST … extern struct blocking_notifier_head scmi_requested_devices_nh; struct scmi_device *scmi_device_create(struct device_node *np, struct device *parent, int protocol, const char *name); void scmi_device_destroy(struct device *parent, int protocol, const char *name); int scmi_protocol_acquire(const struct scmi_handle *handle, u8 protocol_id); void scmi_protocol_release(const struct scmi_handle *handle, u8 protocol_id); /* SCMI Transport */ /** * struct scmi_chan_info - Structure representing a SCMI channel information * * @id: An identifier for this channel: this matches the protocol number * used to initialize this channel * @dev: Reference to device in the SCMI hierarchy corresponding to this * channel * @rx_timeout_ms: The configured RX timeout in milliseconds. * @handle: Pointer to SCMI entity handle * @no_completion_irq: Flag to indicate that this channel has no completion * interrupt mechanism for synchronous commands. * This can be dynamically set by transports at run-time * inside their provided .chan_setup(). * @transport_info: Transport layer related information */ struct scmi_chan_info { … }; /** * struct scmi_transport_ops - Structure representing a SCMI transport ops * * @chan_available: Callback to check if channel is available or not * @chan_setup: Callback to allocate and setup a channel * @chan_free: Callback to free a channel * @get_max_msg: Optional callback to provide max_msg dynamically * Returns the maximum number of messages for the channel type * (tx or rx) that can be pending simultaneously in the system * @send_message: Callback to send a message * @mark_txdone: Callback to mark tx as done * @fetch_response: Callback to fetch response * @fetch_notification: Callback to fetch notification * @clear_channel: Callback to clear a channel * @poll_done: Callback to poll transfer status */ struct scmi_transport_ops { … }; /** * struct scmi_desc - Description of SoC integration * * @ops: Pointer to the transport specific ops structure * @max_rx_timeout_ms: Timeout for communication with SoC (in Milliseconds) * @max_msg: Maximum number of messages for a channel type (tx or rx) that can * be pending simultaneously in the system. May be overridden by the * get_max_msg op. * @max_msg_size: Maximum size of data per message that can be handled. * @force_polling: Flag to force this whole transport to use SCMI core polling * mechanism instead of completion interrupts even if available. * @sync_cmds_completed_on_ret: Flag to indicate that the transport assures * synchronous-command messages are atomically * completed on .send_message: no need to poll * actively waiting for a response. * Used by core internally only when polling is * selected as a waiting for reply method: i.e. * if a completion irq was found use that anyway. * @atomic_enabled: Flag to indicate that this transport, which is assured not * to sleep anywhere on the TX path, can be used in atomic mode * when requested. */ struct scmi_desc { … }; static inline bool is_polling_required(struct scmi_chan_info *cinfo, const struct scmi_desc *desc) { … } static inline bool is_transport_polling_capable(const struct scmi_desc *desc) { … } static inline bool is_polling_enabled(struct scmi_chan_info *cinfo, const struct scmi_desc *desc) { … } void scmi_xfer_raw_put(const struct scmi_handle *handle, struct scmi_xfer *xfer); struct scmi_xfer *scmi_xfer_raw_get(const struct scmi_handle *handle); struct scmi_chan_info * scmi_xfer_raw_channel_get(const struct scmi_handle *handle, u8 protocol_id); int scmi_xfer_raw_inflight_register(const struct scmi_handle *handle, struct scmi_xfer *xfer); int scmi_xfer_raw_wait_for_message_response(struct scmi_chan_info *cinfo, struct scmi_xfer *xfer, unsigned int timeout_ms); enum debug_counters { … }; static inline void scmi_inc_count(atomic_t *arr, int stat) { … } enum scmi_bad_msg { … }; /* shmem related declarations */ struct scmi_shared_mem; /** * struct scmi_shared_mem_operations - Transport core operations for * Shared Memory * * @tx_prepare: Prepare the @xfer message for transmission on the chosen @shmem * @read_header: Read header of the message currently hold in @shmem * @fetch_response: Copy the message response from @shmem into @xfer * @fetch_notification: Copy the message notification from @shmem into @xfer * @clear_channel: Clear the @shmem channel busy flag * @poll_done: Check if poll has completed for @xfer on @shmem * @channel_free: Check if @shmem channel is marked as free * @channel_intr_enabled: Check is @shmem channel has requested a completion irq * @setup_iomap: Setup IO shared memory for channel @cinfo */ struct scmi_shared_mem_operations { … }; const struct scmi_shared_mem_operations *scmi_shared_mem_operations_get(void); /* 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 … /** * struct scmi_message_operations - Transport core operations for Message * * @response_size: Get calculated response size for @xfer * @command_size: Get calculated command size for @xfer * @tx_prepare: Prepare the @xfer message for transmission on the provided @msg * @read_header: Read header of the message currently hold in @msg * @fetch_response: Copy the message response from @msg into @xfer * @fetch_notification: Copy the message notification from @msg into @xfer */ struct scmi_message_operations { … }; const struct scmi_message_operations *scmi_message_operations_get(void); /** * struct scmi_transport_core_operations - Transpoert core operations * * @bad_message_trace: An helper to report a malformed/unexpected message * @rx_callback: Callback to report received messages * @shmem: Datagram operations for shared memory based transports * @msg: Datagram operations for message based transports */ struct scmi_transport_core_operations { … }; /** * struct scmi_transport - A structure representing a configured transport * * @supplier: Device representing the transport and acting as a supplier for * the core SCMI stack * @desc: Transport descriptor * @core_ops: A pointer to a pointer used by the core SCMI stack to make the * core transport operations accessible to the transports. */ struct scmi_transport { … }; #define DEFINE_SCMI_TRANSPORT_DRIVER(__tag, __drv, __desc, __match, __core_ops) … void scmi_notification_instance_data_set(const struct scmi_handle *handle, void *priv); void *scmi_notification_instance_data_get(const struct scmi_handle *handle); #endif /* _SCMI_COMMON_H */