/* 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
/* * 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 9
/** * 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.
*/ staticinline u32 pack_scmi_header(struct scmi_msg_hdr *hdr)
{ return FIELD_PREP(MSG_ID_MASK, hdr->id) |
FIELD_PREP(MSG_TYPE_MASK, hdr->type) |
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.
*/ staticinlinevoid 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);
hdr->type = MSG_XTRACT_TYPE(msg_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) \
({ \
typeof(__k) k_ = __k; \ struct scmi_xfer *xfer_ = NULL; \
\
hash_for_each_possible((__ht), xfer_, node, k_) \ if (xfer_->hdr.seq == k_) \ break; \
xfer_; \
})
/* 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 * @is_p2a: A flag to identify a channel as P2A (RX) * @rx_timeout_ms: The configured RX timeout in milliseconds. * @max_msg_size: Maximum size of message payload. * @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 { int id; struct device *dev; bool is_p2a; unsignedint rx_timeout_ms; unsignedint max_msg_size; struct scmi_handle *handle; bool no_completion_irq; void *transport_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 { bool (*chan_available)(struct device_node *of_node, int idx); int (*chan_setup)(struct scmi_chan_info *cinfo, struct device *dev, bool tx); int (*chan_free)(int id, void *p, void *data); unsignedint (*get_max_msg)(struct scmi_chan_info *base_cinfo); int (*send_message)(struct scmi_chan_info *cinfo, struct scmi_xfer *xfer); void (*mark_txdone)(struct scmi_chan_info *cinfo, int ret, struct scmi_xfer *xfer); void (*fetch_response)(struct scmi_chan_info *cinfo, struct scmi_xfer *xfer); void (*fetch_notification)(struct scmi_chan_info *cinfo,
size_t max_len, struct scmi_xfer *xfer); void (*clear_channel)(struct scmi_chan_info *cinfo); bool (*poll_done)(struct scmi_chan_info *cinfo, struct scmi_xfer *xfer);
};
/** * 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 payload per message that can be handled. * @atomic_threshold: Optional system wide DT-configured threshold, expressed * in microseconds, for atomic operations. * Only SCMI synchronous commands reported by the platform * to have an execution latency lesser-equal to the threshold * should be considered for atomic mode operation: such * decision is finally left up to the SCMI drivers. * @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 { conststruct scmi_transport_ops *ops; int max_rx_timeout_ms; int max_msg; int max_msg_size; unsignedint atomic_threshold; constbool force_polling; constbool sync_cmds_completed_on_ret; constbool atomic_enabled;
};
/** * struct scmi_debug_info - Debug common info * @top_dentry: A reference to the top debugfs dentry * @name: Name of this SCMI instance * @type: Type of this SCMI instance * @is_atomic: Flag to state if the transport of this instance is atomic * @counters: An array of atomic_c's used for tracking statistics (if enabled)
*/ struct scmi_debug_info { struct dentry *top_dentry; constchar *name; constchar *type; bool is_atomic;
atomic_t counters[SCMI_DEBUG_COUNTERS_LAST];
};
staticinlinevoid scmi_inc_count(struct scmi_debug_info *dbg, int stat)
{ if (IS_ENABLED(CONFIG_ARM_SCMI_DEBUG_COUNTERS)) { if (dbg)
atomic_inc(&dbg->counters[stat]);
}
}
staticinlinevoid scmi_dec_count(struct scmi_debug_info *dbg, int stat)
{ if (IS_ENABLED(CONFIG_ARM_SCMI_DEBUG_COUNTERS)) { if (dbg)
atomic_dec(&dbg->counters[stat]);
}
}
/* Used for compactness and signature validation of the function pointers being * passed.
*/ typedefvoid (*shmem_copy_toio_t)(void __iomem *to, constvoid *from,
size_t count); typedefvoid (*shmem_copy_fromio_t)(void *to, constvoid __iomem *from,
size_t count);
/** * struct scmi_shmem_io_ops - I/O operations to read from/write to * Shared Memory * * @toio: Copy data to the shared memory area * @fromio: Copy data from the shared memory area
*/ struct scmi_shmem_io_ops {
shmem_copy_fromio_t fromio;
shmem_copy_toio_t toio;
};
/* 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 { void (*tx_prepare)(struct scmi_shared_mem __iomem *shmem, struct scmi_xfer *xfer, struct scmi_chan_info *cinfo,
shmem_copy_toio_t toio);
u32 (*read_header)(struct scmi_shared_mem __iomem *shmem);
/** * 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 { void (*bad_message_trace)(struct scmi_chan_info *cinfo,
u32 msg_hdr, enum scmi_bad_msg err); void (*rx_callback)(struct scmi_chan_info *cinfo, u32 msg_hdr, void *priv); conststruct scmi_shared_mem_operations *shmem; conststruct scmi_message_operations *msg;
};
/** * 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 { struct device *supplier; struct scmi_desc desc; struct scmi_transport_core_operations **core_ops;
};
Die Informationen auf dieser Webseite wurden
nach bestem Wissen sorgfältig zusammengestellt. Es wird jedoch weder Vollständigkeit, noch Richtigkeit,
noch Qualität der bereit gestellten Informationen zugesichert.
Bemerkung:
Die farbliche Syntaxdarstellung und die Messung sind noch experimentell.