// SPDX-License-Identifier: GPL-2.0 /* * System Control and Management Interface (SCMI) Message Protocol driver * * SCMI Message Protocol is used between the System Control Processor(SCP) * and the Application Processors(AP). The Message Handling Unit(MHU) * provides a mechanism for inter-processor communication between SCP's * Cortex M3 and AP. * * SCP offers control and management of the core/cluster power states, * various power domain DVFS including the core/cluster, certain system * clocks configuration, thermal sensors and many others. * * Copyright (C) 2018-2025 ARM Ltd.
*/
/* List of all SCMI devices active in system */ static LIST_HEAD(scmi_list); /* Protection for the entire list */ static DEFINE_MUTEX(scmi_list_mutex); /* Track the unique id for the transfers for debug & profiling purpose */ static atomic_t transfer_last_id;
staticstruct dentry *scmi_top_dentry;
/** * struct scmi_xfers_info - Structure to manage transfer information * * @xfer_alloc_table: Bitmap table for allocated messages. * Index of this bitmap table is also used for message * sequence identifier. * @xfer_lock: Protection for message allocation * @max_msg: Maximum number of messages that can be pending * @free_xfers: A free list for available to use xfers. It is initialized with * a number of xfers equal to the maximum allowed in-flight * messages. * @pending_xfers: An hashtable, indexed by msg_hdr.seq, used to keep all the * currently in-flight messages.
*/ struct scmi_xfers_info { unsignedlong *xfer_alloc_table;
spinlock_t xfer_lock; int max_msg; struct hlist_head free_xfers;
DECLARE_HASHTABLE(pending_xfers, SCMI_PENDING_XFERS_HT_ORDER_SZ);
};
/** * struct scmi_protocol_instance - Describe an initialized protocol instance. * @handle: Reference to the SCMI handle associated to this protocol instance. * @proto: A reference to the protocol descriptor. * @gid: A reference for per-protocol devres management. * @users: A refcount to track effective users of this protocol. * @priv: Reference for optional protocol private data. * @version: Protocol version supported by the platform as detected at runtime. * @negotiated_version: When the platform supports a newer protocol version, * the agent will try to negotiate with the platform the * usage of the newest version known to it, since * backward compatibility is NOT automatically assured. * This field is NON-zero when a successful negotiation * has completed. * @ph: An embedded protocol handle that will be passed down to protocol * initialization code to identify this instance. * * Each protocol is initialized independently once for each SCMI platform in * which is defined by DT and implemented by the SCMI server fw.
*/ struct scmi_protocol_instance { conststruct scmi_handle *handle; conststruct scmi_protocol *proto; void *gid;
refcount_t users; void *priv; unsignedint version; unsignedint negotiated_version; struct scmi_protocol_handle ph;
};
/** * struct scmi_info - Structure representing a SCMI instance * * @id: A sequence number starting from zero identifying this instance * @dev: Device pointer * @desc: SoC description for this instance * @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 * @rx_minfo: Universal Receive 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 * @protocols: IDR for protocols' instance descriptors initialized for * this SCMI instance: populated on protocol's first attempted * usage. * @protocols_mtx: A mutex to protect protocols instances initialization. * @protocols_imp: List of protocols implemented, currently maximum of * scmi_revision_info.num_protocols elements allocated by the * base protocol * @active_protocols: IDR storing device_nodes for protocols actually defined * in the DT and confirmed as implemented by fw. * @notify_priv: Pointer to private data structure specific to notifications. * @node: List head * @users: Number of users of this instance * @bus_nb: A notifier to listen for device bind/unbind on the scmi bus * @dev_req_nb: A notifier to listen for device request/unrequest on the scmi * bus * @devreq_mtx: A mutex to serialize device creation for this SCMI instance * @dbg: A pointer to debugfs related data (if any) * @raw: An opaque reference handle used by SCMI Raw mode.
*/ struct scmi_info { int id; struct device *dev; conststruct scmi_desc *desc; struct scmi_revision_info version; struct scmi_handle handle; struct scmi_xfers_info tx_minfo; struct scmi_xfers_info rx_minfo; struct idr tx_idr; struct idr rx_idr; struct idr protocols; /* Ensure mutual exclusive access to protocols instance array */ struct mutex protocols_mtx;
u8 *protocols_imp; struct idr active_protocols; void *notify_priv; struct list_head node; int users; struct notifier_block bus_nb; struct notifier_block dev_req_nb; /* Serialize device creation process for this instance */ struct mutex devreq_mtx; struct scmi_debug_info *dbg; void *raw;
};
/* Searching for closest match ...*/
proto = __scmi_vendor_protocol_lookup(protocol_id, vendor_id,
sub_vendor_id, impl_ver); if (proto) return proto;
/* Any match just on vendor/sub_vendor ? */ if (impl_ver) {
proto = __scmi_vendor_protocol_lookup(protocol_id, vendor_id,
sub_vendor_id, 0); if (proto) return proto;
}
/* Any match just on the vendor ? */ if (sub_vendor_id)
proto = __scmi_vendor_protocol_lookup(protocol_id, vendor_id,
NULL, 0); return proto;
}
proto = scmi_vendor_protocol_lookup(protocol_id, version->vendor_id,
version->sub_vendor_id,
version->impl_ver); if (!proto) { int ret;
pr_debug("Looking for '" SCMI_VENDOR_MODULE_ALIAS_FMT "'\n",
protocol_id, version->vendor_id);
/* Note that vendor_id is mandatory for vendor protocols */
ret = request_module(SCMI_VENDOR_MODULE_ALIAS_FMT,
protocol_id, version->vendor_id); if (ret) {
pr_warn("Problem loading module for protocol 0x%x\n",
protocol_id); return NULL;
}
/* Lookup again, once modules loaded */
proto = scmi_vendor_protocol_lookup(protocol_id,
version->vendor_id,
version->sub_vendor_id,
version->impl_ver);
}
if (protocol_id < SCMI_PROTOCOL_VENDOR_BASE)
proto = xa_load(&scmi_protocols, protocol_id); else
proto = scmi_vendor_protocol_get(protocol_id, version);
if (!proto || !try_module_get(proto->owner)) {
pr_warn("SCMI Protocol 0x%x not found!\n", protocol_id); return NULL;
}
staticvoid scmi_protocol_put(conststruct scmi_protocol *proto)
{ if (proto)
module_put(proto->owner);
}
staticint scmi_vendor_protocol_check(conststruct scmi_protocol *proto)
{ if (!proto->vendor_id) {
pr_err("missing vendor_id for protocol 0x%x\n", proto->id); return -EINVAL;
}
if (strlen(proto->vendor_id) >= SCMI_SHORT_NAME_MAX_SIZE) {
pr_err("malformed vendor_id for protocol 0x%x\n", proto->id); return -EINVAL;
}
if (proto->sub_vendor_id &&
strlen(proto->sub_vendor_id) >= SCMI_SHORT_NAME_MAX_SIZE) {
pr_err("malformed sub_vendor_id for protocol 0x%x\n",
proto->id); return -EINVAL;
}
return 0;
}
int scmi_protocol_register(conststruct scmi_protocol *proto)
{ int ret; unsignedlong key;
if (!proto) {
pr_err("invalid protocol\n"); return -EINVAL;
}
if (!proto->instance_init) {
pr_err("missing init for protocol 0x%x\n", proto->id); return -EINVAL;
}
if (proto->id >= SCMI_PROTOCOL_VENDOR_BASE &&
scmi_vendor_protocol_check(proto)) return -EINVAL;
/* * Calculate a protocol key to register this protocol with the core; * key value 0 is considered invalid.
*/
key = scmi_protocol_key_calculate(proto->id, proto->vendor_id,
proto->sub_vendor_id,
proto->impl_ver); if (!key) return -EINVAL;
ret = xa_insert(&scmi_protocols, key, (void *)proto, GFP_KERNEL); if (ret) {
pr_err("unable to allocate SCMI protocol slot for 0x%x - err %d\n",
proto->id, ret); return ret;
}
/** * scmi_create_protocol_devices - Create devices for all pending requests for * this SCMI instance. * * @np: The device node describing the protocol * @info: The SCMI instance descriptor * @prot_id: The protocol ID * @name: The optional name of the device to be created: if not provided this * call will lead to the creation of all the devices currently requested * for the specified protocol.
*/ staticvoid scmi_create_protocol_devices(struct device_node *np, struct scmi_info *info, int prot_id, constchar *name)
{
mutex_lock(&info->devreq_mtx);
scmi_device_create(np, info->dev, prot_id, name);
mutex_unlock(&info->devreq_mtx);
}
/* Ensure protocols_private_data has been updated */
smp_rmb(); return info->notify_priv;
}
/** * scmi_xfer_token_set - Reserve and set new token for the xfer at hand * * @minfo: Pointer to Tx/Rx Message management info based on channel type * @xfer: The xfer to act upon * * Pick the next unused monotonically increasing token and set it into * xfer->hdr.seq: picking a monotonically increasing value avoids immediate * reuse of freshly completed or timed-out xfers, thus mitigating the risk * of incorrect association of a late and expired xfer with a live in-flight * transaction, both happening to re-use the same token identifier. * * Since platform is NOT required to answer our request in-order we should * account for a few rare but possible scenarios: * * - exactly 'next_token' may be NOT available so pick xfer_id >= next_token * using find_next_zero_bit() starting from candidate next_token bit * * - all tokens ahead upto (MSG_TOKEN_ID_MASK - 1) are used in-flight but we * are plenty of free tokens at start, so try a second pass using * find_next_zero_bit() and starting from 0. * * X = used in-flight * * Normal * ------ * * |- xfer_id picked * -----------+---------------------------------------------------------- * | | |X|X|X| | | | | | ... ... ... ... ... ... ... ... ... ... ...|X|X| * ---------------------------------------------------------------------- * ^ * |- next_token * * Out-of-order pending at start * ----------------------------- * * |- xfer_id picked, last_token fixed * -----+---------------------------------------------------------------- * |X|X| | | | |X|X| ... ... ... ... ... ... ... ... ... ... ... ...|X| | * ---------------------------------------------------------------------- * ^ * |- next_token * * * Out-of-order pending at end * --------------------------- * * |- xfer_id picked, last_token fixed * -----+---------------------------------------------------------------- * |X|X| | | | |X|X| ... ... ... ... ... ... ... ... ... ... |X|X|X||X|X| * ---------------------------------------------------------------------- * ^ * |- next_token * * Context: Assumes to be called with @xfer_lock already acquired. * * Return: 0 on Success or error
*/ staticint scmi_xfer_token_set(struct scmi_xfers_info *minfo, struct scmi_xfer *xfer)
{ unsignedlong xfer_id, next_token;
/* * Pick a candidate monotonic token in range [0, MSG_TOKEN_MAX - 1] * using the pre-allocated transfer_id as a base. * Note that the global transfer_id is shared across all message types * so there could be holes in the allocated set of monotonic sequence * numbers, but that is going to limit the effectiveness of the * mitigation only in very rare limit conditions.
*/
next_token = (xfer->transfer_id & (MSG_TOKEN_MAX - 1));
/* Pick the next available xfer_id >= next_token */
xfer_id = find_next_zero_bit(minfo->xfer_alloc_table,
MSG_TOKEN_MAX, next_token); if (xfer_id == MSG_TOKEN_MAX) { /* * After heavily out-of-order responses, there are no free * tokens ahead, but only at start of xfer_alloc_table so * try again from the beginning.
*/
xfer_id = find_next_zero_bit(minfo->xfer_alloc_table,
MSG_TOKEN_MAX, 0); /* * Something is wrong if we got here since there can be a * maximum number of (MSG_TOKEN_MAX - 1) in-flight messages * but we have not found any free token [0, MSG_TOKEN_MAX - 1].
*/ if (WARN_ON_ONCE(xfer_id == MSG_TOKEN_MAX)) return -ENOMEM;
}
/* Update +/- last_token accordingly if we skipped some hole */ if (xfer_id != next_token)
atomic_add((int)(xfer_id - next_token), &transfer_last_id);
xfer->hdr.seq = (u16)xfer_id;
return 0;
}
/** * scmi_xfer_token_clear - Release the token * * @minfo: Pointer to Tx/Rx Message management info based on channel type * @xfer: The xfer to act upon
*/ staticinlinevoid scmi_xfer_token_clear(struct scmi_xfers_info *minfo, struct scmi_xfer *xfer)
{
clear_bit(xfer->hdr.seq, minfo->xfer_alloc_table);
}
/** * scmi_xfer_inflight_register_unlocked - Register the xfer as in-flight * * @xfer: The xfer to register * @minfo: Pointer to Tx/Rx Message management info based on channel type * * Note that this helper assumes that the xfer to be registered as in-flight * had been built using an xfer sequence number which still corresponds to a * free slot in the xfer_alloc_table. * * Context: Assumes to be called with @xfer_lock already acquired.
*/ staticinlinevoid
scmi_xfer_inflight_register_unlocked(struct scmi_xfer *xfer, struct scmi_xfers_info *minfo)
{ /* In this context minfo will be tx_minfo due to the xfer pending */ struct scmi_info *info = tx_minfo_to_scmi_info(minfo);
/** * scmi_xfer_inflight_register - Try to register an xfer as in-flight * * @xfer: The xfer to register * @minfo: Pointer to Tx/Rx Message management info based on channel type * * Note that this helper does NOT assume anything about the sequence number * that was baked into the provided xfer, so it checks at first if it can * be mapped to a free slot and fails with an error if another xfer with the * same sequence number is currently still registered as in-flight. * * Return: 0 on Success or -EBUSY if sequence number embedded in the xfer * could not rbe mapped to a free slot in the xfer_alloc_table.
*/ staticint scmi_xfer_inflight_register(struct scmi_xfer *xfer, struct scmi_xfers_info *minfo)
{ int ret = 0; unsignedlong flags;
spin_lock_irqsave(&minfo->xfer_lock, flags); if (!test_bit(xfer->hdr.seq, minfo->xfer_alloc_table))
scmi_xfer_inflight_register_unlocked(xfer, minfo); else
ret = -EBUSY;
spin_unlock_irqrestore(&minfo->xfer_lock, flags);
return ret;
}
/** * scmi_xfer_raw_inflight_register - An helper to register the given xfer as in * flight on the TX channel, if possible. * * @handle: Pointer to SCMI entity handle * @xfer: The xfer to register * * Return: 0 on Success, error otherwise
*/ int scmi_xfer_raw_inflight_register(conststruct scmi_handle *handle, struct scmi_xfer *xfer)
{ struct scmi_info *info = handle_to_scmi_info(handle);
/** * scmi_xfer_pending_set - Pick a proper sequence number and mark the xfer * as pending in-flight * * @xfer: The xfer to act upon * @minfo: Pointer to Tx/Rx Message management info based on channel type * * Return: 0 on Success or error otherwise
*/ staticinlineint scmi_xfer_pending_set(struct scmi_xfer *xfer, struct scmi_xfers_info *minfo)
{ int ret; unsignedlong flags;
spin_lock_irqsave(&minfo->xfer_lock, flags); /* Set a new monotonic token as the xfer sequence number */
ret = scmi_xfer_token_set(minfo, xfer); if (!ret)
scmi_xfer_inflight_register_unlocked(xfer, minfo);
spin_unlock_irqrestore(&minfo->xfer_lock, flags);
return ret;
}
/** * scmi_xfer_get() - Allocate one message * * @handle: Pointer to SCMI entity handle * @minfo: Pointer to Tx/Rx Message management info based on channel type * * Helper function which is used by various message functions that are * exposed to clients of this driver for allocating a message traffic event. * * Picks an xfer from the free list @free_xfers (if any available) and perform * a basic initialization. * * Note that, at this point, still no sequence number is assigned to the * allocated xfer, nor it is registered as a pending transaction. * * The successfully initialized xfer is refcounted. * * Context: Holds @xfer_lock while manipulating @free_xfers. * * Return: An initialized xfer if all went fine, else pointer error.
*/ staticstruct scmi_xfer *scmi_xfer_get(conststruct scmi_handle *handle, struct scmi_xfers_info *minfo)
{ unsignedlong flags; struct scmi_xfer *xfer;
spin_lock_irqsave(&minfo->xfer_lock, flags); if (hlist_empty(&minfo->free_xfers)) {
spin_unlock_irqrestore(&minfo->xfer_lock, flags); return ERR_PTR(-ENOMEM);
}
/* grab an xfer from the free_list */
xfer = hlist_entry(minfo->free_xfers.first, struct scmi_xfer, node);
hlist_del_init(&xfer->node);
/* * Allocate transfer_id early so that can be used also as base for * monotonic sequence number generation if needed.
*/
xfer->transfer_id = atomic_inc_return(&transfer_last_id);
/** * scmi_xfer_raw_get - Helper to get a bare free xfer from the TX channel * * @handle: Pointer to SCMI entity handle * * Note that xfer is taken from the TX channel structures. * * Return: A valid xfer on Success, or an error-pointer otherwise
*/ struct scmi_xfer *scmi_xfer_raw_get(conststruct scmi_handle *handle)
{ struct scmi_xfer *xfer; struct scmi_info *info = handle_to_scmi_info(handle);
xfer = scmi_xfer_get(handle, &info->tx_minfo); if (!IS_ERR(xfer))
xfer->flags |= SCMI_XFER_FLAG_IS_RAW;
return xfer;
}
/** * scmi_xfer_raw_channel_get - Helper to get a reference to the proper channel * to use for a specific protocol_id Raw transaction. * * @handle: Pointer to SCMI entity handle * @protocol_id: Identifier of the protocol * * Note that in a regular SCMI stack, usually, a protocol has to be defined in * the DT to have an associated channel and be usable; but in Raw mode any * protocol in range is allowed, re-using the Base channel, so as to enable * fuzzing on any protocol without the need of a fully compiled DT. * * Return: A reference to the channel to use, or an ERR_PTR
*/ struct scmi_chan_info *
scmi_xfer_raw_channel_get(conststruct scmi_handle *handle, u8 protocol_id)
{ struct scmi_chan_info *cinfo; struct scmi_info *info = handle_to_scmi_info(handle);
cinfo = idr_find(&info->tx_idr, protocol_id); if (!cinfo) { if (protocol_id == SCMI_PROTOCOL_BASE) return ERR_PTR(-EINVAL); /* Use Base channel for protocols not defined for DT */
cinfo = idr_find(&info->tx_idr, SCMI_PROTOCOL_BASE); if (!cinfo) return ERR_PTR(-EINVAL);
dev_warn_once(handle->dev, "Using Base channel for protocol 0x%X\n",
protocol_id);
}
return cinfo;
}
/** * __scmi_xfer_put() - Release a message * * @minfo: Pointer to Tx/Rx Message management info based on channel type * @xfer: message that was reserved by scmi_xfer_get * * After refcount check, possibly release an xfer, clearing the token slot, * removing xfer from @pending_xfers and putting it back into free_xfers. * * This holds a spinlock to maintain integrity of internal data structures.
*/ staticvoid
__scmi_xfer_put(struct scmi_xfers_info *minfo, struct scmi_xfer *xfer)
{ unsignedlong flags;
spin_lock_irqsave(&minfo->xfer_lock, flags); if (refcount_dec_and_test(&xfer->users)) { if (xfer->pending) { struct scmi_info *info = tx_minfo_to_scmi_info(minfo);
/** * scmi_xfer_raw_put - Release an xfer that was taken by @scmi_xfer_raw_get * * @handle: Pointer to SCMI entity handle * @xfer: A reference to the xfer to put * * Note that as with other xfer_put() handlers the xfer is really effectively * released only if there are no more users on the system.
*/ void scmi_xfer_raw_put(conststruct scmi_handle *handle, struct scmi_xfer *xfer)
{ struct scmi_info *info = handle_to_scmi_info(handle);
return __scmi_xfer_put(&info->tx_minfo, xfer);
}
/** * scmi_xfer_lookup_unlocked - Helper to lookup an xfer_id * * @minfo: Pointer to Tx/Rx Message management info based on channel type * @xfer_id: Token ID to lookup in @pending_xfers * * Refcounting is untouched. * * Context: Assumes to be called with @xfer_lock already acquired. * * Return: A valid xfer on Success or error otherwise
*/ staticstruct scmi_xfer *
scmi_xfer_lookup_unlocked(struct scmi_xfers_info *minfo, u16 xfer_id)
{ struct scmi_xfer *xfer = NULL;
if (test_bit(xfer_id, minfo->xfer_alloc_table))
xfer = XFER_FIND(minfo->pending_xfers, xfer_id);
return xfer ?: ERR_PTR(-EINVAL);
}
/** * scmi_bad_message_trace - A helper to trace weird messages * * @cinfo: A reference to the channel descriptor on which the message was * received * @msg_hdr: Message header to track * @err: A specific error code used as a status value in traces. * * This helper can be used to trace any kind of weird, incomplete, unexpected, * timed-out message that arrives and as such, can be traced only referring to * the header content, since the payload is missing/unreliable.
*/ staticvoid scmi_bad_message_trace(struct scmi_chan_info *cinfo, u32 msg_hdr, enum scmi_bad_msg err)
{ char *tag; struct scmi_info *info = handle_to_scmi_info(cinfo->handle);
switch (MSG_XTRACT_TYPE(msg_hdr)) { case MSG_TYPE_COMMAND:
tag = "!RESP"; break; case MSG_TYPE_DELAYED_RESP:
tag = "!DLYD"; break; case MSG_TYPE_NOTIFICATION:
tag = "!NOTI"; break; default:
tag = "!UNKN"; break;
}
/** * scmi_msg_response_validate - Validate message type against state of related * xfer * * @cinfo: A reference to the channel descriptor. * @msg_type: Message type to check * @xfer: A reference to the xfer to validate against @msg_type * * This function checks if @msg_type is congruent with the current state of * a pending @xfer; if an asynchronous delayed response is received before the * related synchronous response (Out-of-Order Delayed Response) the missing * synchronous response is assumed to be OK and completed, carrying on with the * Delayed Response: this is done to address the case in which the underlying * SCMI transport can deliver such out-of-order responses. * * Context: Assumes to be called with xfer->lock already acquired. * * Return: 0 on Success, error otherwise
*/ staticinlineint scmi_msg_response_validate(struct scmi_chan_info *cinfo,
u8 msg_type, struct scmi_xfer *xfer)
{ /* * Even if a response was indeed expected on this slot at this point, * a buggy platform could wrongly reply feeding us an unexpected * delayed response we're not prepared to handle: bail-out safely * blaming firmware.
*/ if (msg_type == MSG_TYPE_DELAYED_RESP && !xfer->async_done) {
dev_err(cinfo->dev, "Delayed Response for %d not expected! Buggy F/W ?\n",
xfer->hdr.seq); return -EINVAL;
}
switch (xfer->state) { case SCMI_XFER_SENT_OK: if (msg_type == MSG_TYPE_DELAYED_RESP) { /* * Delayed Response expected but delivered earlier. * Assume message RESPONSE was OK and skip state.
*/
xfer->hdr.status = SCMI_SUCCESS;
xfer->state = SCMI_XFER_RESP_OK;
complete(&xfer->done);
dev_warn(cinfo->dev, "Received valid OoO Delayed Response for %d\n",
xfer->hdr.seq);
} break; case SCMI_XFER_RESP_OK: if (msg_type != MSG_TYPE_DELAYED_RESP) return -EINVAL; break; case SCMI_XFER_DRESP_OK: /* No further message expected once in SCMI_XFER_DRESP_OK */ return -EINVAL;
}
return 0;
}
/** * scmi_xfer_state_update - Update xfer state * * @xfer: A reference to the xfer to update * @msg_type: Type of message being processed. * * Note that this message is assumed to have been already successfully validated * by @scmi_msg_response_validate(), so here we just update the state. * * Context: Assumes to be called on an xfer exclusively acquired using the * busy flag.
*/ staticinlinevoid scmi_xfer_state_update(struct scmi_xfer *xfer, u8 msg_type)
{
xfer->hdr.type = msg_type;
staticbool scmi_xfer_acquired(struct scmi_xfer *xfer)
{ int ret;
ret = atomic_cmpxchg(&xfer->busy, SCMI_XFER_FREE, SCMI_XFER_BUSY);
return ret == SCMI_XFER_FREE;
}
/** * scmi_xfer_command_acquire - Helper to lookup and acquire a command xfer * * @cinfo: A reference to the channel descriptor. * @msg_hdr: A message header to use as lookup key * * When a valid xfer is found for the sequence number embedded in the provided * msg_hdr, reference counting is properly updated and exclusive access to this * xfer is granted till released with @scmi_xfer_command_release. * * Return: A valid @xfer on Success or error otherwise.
*/ staticinlinestruct scmi_xfer *
scmi_xfer_command_acquire(struct scmi_chan_info *cinfo, u32 msg_hdr)
{ int ret; unsignedlong flags; struct scmi_xfer *xfer; struct scmi_info *info = handle_to_scmi_info(cinfo->handle); struct scmi_xfers_info *minfo = &info->tx_minfo;
u8 msg_type = MSG_XTRACT_TYPE(msg_hdr);
u16 xfer_id = MSG_XTRACT_TOKEN(msg_hdr);
/* Are we even expecting this? */
spin_lock_irqsave(&minfo->xfer_lock, flags);
xfer = scmi_xfer_lookup_unlocked(minfo, xfer_id); if (IS_ERR(xfer)) {
dev_err(cinfo->dev, "Message for %d type %d is not expected!\n",
xfer_id, msg_type);
spin_unlock_irqrestore(&minfo->xfer_lock, flags);
spin_lock_irqsave(&xfer->lock, flags);
ret = scmi_msg_response_validate(cinfo, msg_type, xfer); /* * If a pending xfer was found which was also in a congruent state with * the received message, acquire exclusive access to it setting the busy * flag. * Spins only on the rare limit condition of concurrent reception of * RESP and DRESP for the same xfer.
*/ if (!ret) {
spin_until_cond(scmi_xfer_acquired(xfer));
scmi_xfer_state_update(xfer, msg_type);
}
spin_unlock_irqrestore(&xfer->lock, flags);
if (ret) {
dev_err(cinfo->dev, "Invalid message type:%d for %d - HDR:0x%X state:%d\n",
msg_type, xfer_id, msg_hdr, xfer->state);
unpack_scmi_header(msg_hdr, &xfer->hdr); if (priv) /* Ensure order between xfer->priv store and following ops */
smp_store_mb(xfer->priv, priv);
info->desc->ops->fetch_notification(cinfo, info->desc->max_msg_size,
xfer);
xfer = scmi_xfer_command_acquire(cinfo, msg_hdr); if (IS_ERR(xfer)) { if (IS_ENABLED(CONFIG_ARM_SCMI_RAW_MODE_SUPPORT))
scmi_raw_error_report(info->raw, cinfo, msg_hdr, priv);
if (MSG_XTRACT_TYPE(msg_hdr) == MSG_TYPE_DELAYED_RESP)
scmi_clear_channel(info, cinfo); return;
}
/* rx.len could be shrunk in the sync do_xfer, so reset to maxsz */ if (xfer->hdr.type == MSG_TYPE_DELAYED_RESP)
xfer->rx.len = info->desc->max_msg_size;
if (priv) /* Ensure order between xfer->priv store and following ops */
smp_store_mb(xfer->priv, priv);
info->desc->ops->fetch_response(cinfo, xfer);
if (IS_ENABLED(CONFIG_ARM_SCMI_RAW_MODE_SUPPORT)) { /* * When in polling mode avoid to queue the Raw xfer on the IRQ * RX path since it will be already queued at the end of the TX * poll loop.
*/ if (!xfer->hdr.poll_completion ||
xfer->hdr.type == MSG_TYPE_DELAYED_RESP)
scmi_raw_message_report(info->raw, xfer,
SCMI_RAW_REPLY_QUEUE,
cinfo->id);
}
scmi_xfer_command_release(info, xfer);
}
/** * scmi_rx_callback() - callback for receiving messages * * @cinfo: SCMI channel info * @msg_hdr: Message header * @priv: Transport specific private data. * * Processes one received message to appropriate transfer information and * signals completion of the transfer. * * NOTE: This function will be invoked in IRQ context, hence should be * as optimal as possible.
*/ staticvoid scmi_rx_callback(struct scmi_chan_info *cinfo, u32 msg_hdr, void *priv)
{
u8 msg_type = MSG_XTRACT_TYPE(msg_hdr);
switch (msg_type) { case MSG_TYPE_NOTIFICATION:
scmi_handle_notification(cinfo, msg_hdr, priv); break; case MSG_TYPE_COMMAND: case MSG_TYPE_DELAYED_RESP:
scmi_handle_response(cinfo, msg_hdr, priv); break; default:
WARN_ONCE(1, "received unknown msg_type:%d\n", msg_type);
scmi_bad_message_trace(cinfo, msg_hdr, MSG_UNKNOWN); break;
}
}
/** * xfer_put() - Release a transmit message * * @ph: Pointer to SCMI protocol handle * @xfer: message that was reserved by xfer_get_init
*/ staticvoid xfer_put(conststruct scmi_protocol_handle *ph, struct scmi_xfer *xfer)
{ conststruct scmi_protocol_instance *pi = ph_to_pi(ph); struct scmi_info *info = handle_to_scmi_info(pi->handle);
/* * Poll also on xfer->done so that polling can be forcibly terminated * in case of out-of-order receptions of delayed responses
*/ return info->desc->ops->poll_done(cinfo, xfer) ||
(*ooo = try_wait_for_completion(&xfer->done)) ||
ktime_after(ktime_get(), stop);
}
if (xfer->hdr.poll_completion) { /* * Real polling is needed only if transport has NOT declared * itself to support synchronous commands replies.
*/ if (!desc->sync_cmds_completed_on_ret) { bool ooo = false;
/* * Poll on xfer using transport provided .poll_done(); * assumes no completion interrupt was available.
*/
ktime_t stop = ktime_add_ms(ktime_get(), timeout_ms);
spin_until_cond(scmi_xfer_done_no_timeout(cinfo, xfer,
stop, &ooo)); if (!ooo && !info->desc->ops->poll_done(cinfo, xfer)) {
dev_err(dev, "timed out in resp(caller: %pS) - polling\n",
(void *)_RET_IP_);
ret = -ETIMEDOUT;
scmi_inc_count(info->dbg, XFERS_RESPONSE_POLLED_TIMEOUT);
}
}
if (!ret) { unsignedlong flags;
/* * Do not fetch_response if an out-of-order delayed * response is being processed.
*/
spin_lock_irqsave(&xfer->lock, flags); if (xfer->state == SCMI_XFER_SENT_OK) {
desc->ops->fetch_response(cinfo, xfer);
xfer->state = SCMI_XFER_RESP_OK;
}
spin_unlock_irqrestore(&xfer->lock, flags);
if (IS_ENABLED(CONFIG_ARM_SCMI_RAW_MODE_SUPPORT)) {
scmi_raw_message_report(info->raw, xfer,
SCMI_RAW_REPLY_QUEUE,
cinfo->id);
}
}
} else { /* And we wait for the response. */ if (!wait_for_completion_timeout(&xfer->done,
msecs_to_jiffies(timeout_ms))) {
dev_err(dev, "timed out in resp(caller: %pS)\n",
(void *)_RET_IP_);
ret = -ETIMEDOUT;
scmi_inc_count(info->dbg, XFERS_RESPONSE_TIMEOUT);
}
}
return ret;
}
/** * scmi_wait_for_message_response - An helper to group all the possible ways of * waiting for a synchronous message response. * * @cinfo: SCMI channel info * @xfer: Reference to the transfer being waited for. * * Chooses waiting strategy (sleep-waiting vs busy-waiting) depending on * configuration flags like xfer->hdr.poll_completion. * * Return: 0 on Success, error otherwise.
*/ staticint scmi_wait_for_message_response(struct scmi_chan_info *cinfo, struct scmi_xfer *xfer)
{ struct scmi_info *info = handle_to_scmi_info(cinfo->handle); struct device *dev = info->dev;
/** * scmi_xfer_raw_wait_for_message_response - An helper to wait for a message * reply to an xfer raw request on a specific channel for the required timeout. * * @cinfo: SCMI channel info * @xfer: Reference to the transfer being waited for. * @timeout_ms: The maximum timeout in milliseconds * * Return: 0 on Success, error otherwise.
*/ int scmi_xfer_raw_wait_for_message_response(struct scmi_chan_info *cinfo, struct scmi_xfer *xfer, unsignedint timeout_ms)
{ int ret; struct scmi_info *info = handle_to_scmi_info(cinfo->handle); struct device *dev = info->dev;
ret = scmi_wait_for_reply(dev, info->desc, cinfo, xfer, timeout_ms); if (ret)
dev_dbg(dev, "timed out in RAW response - HDR:%08X\n",
pack_scmi_header(&xfer->hdr));
return ret;
}
/** * do_xfer() - Do one transfer * * @ph: Pointer to SCMI protocol handle * @xfer: Transfer to initiate and wait for response * * Return: -ETIMEDOUT in case of no response, if transmit error, * return corresponding error, else if all goes well, * return 0.
*/ staticint do_xfer(conststruct scmi_protocol_handle *ph, struct scmi_xfer *xfer)
{ int ret; conststruct scmi_protocol_instance *pi = ph_to_pi(ph); struct scmi_info *info = handle_to_scmi_info(pi->handle); struct device *dev = info->dev; struct scmi_chan_info *cinfo;
/* Check for polling request on custom command xfers at first */ if (xfer->hdr.poll_completion &&
!is_transport_polling_capable(info->desc)) {
dev_warn_once(dev, "Polling mode is not supported by transport.\n");
scmi_inc_count(info->dbg, SENT_FAIL_POLLING_UNSUPPORTED); return -EINVAL;
}
cinfo = idr_find(&info->tx_idr, pi->proto->id); if (unlikely(!cinfo)) {
scmi_inc_count(info->dbg, SENT_FAIL_CHANNEL_NOT_FOUND); return -EINVAL;
} /* True ONLY if also supported by transport. */ if (is_polling_enabled(cinfo, info->desc))
xfer->hdr.poll_completion = true;
/* * Initialise protocol id now from protocol handle to avoid it being * overridden by mistake (or malice) by the protocol code mangling with * the scmi_xfer structure prior to this.
*/
xfer->hdr.protocol_id = pi->proto->id;
reinit_completion(&xfer->done);
/* Clear any stale status */
xfer->hdr.status = SCMI_SUCCESS;
xfer->state = SCMI_XFER_SENT_OK; /* * Even though spinlocking is not needed here since no race is possible * on xfer->state due to the monotonically increasing tokens allocation, * we must anyway ensure xfer->state initialization is not re-ordered * after the .send_message() to be sure that on the RX path an early * ISR calling scmi_rx_callback() cannot see an old stale xfer->state.
*/
smp_mb();
ret = info->desc->ops->send_message(cinfo, xfer); if (ret < 0) {
dev_dbg(dev, "Failed to send message %d\n", ret);
scmi_inc_count(info->dbg, SENT_FAIL); return ret;
}
ret = scmi_wait_for_message_response(cinfo, xfer); if (!ret && xfer->hdr.status) {
ret = scmi_to_linux_errno(xfer->hdr.status);
scmi_inc_count(info->dbg, ERR_PROTOCOL);
}
if (info->desc->ops->mark_txdone)
info->desc->ops->mark_txdone(cinfo, ret, xfer);
/** * do_xfer_with_response() - Do one transfer and wait until the delayed * response is received * * @ph: Pointer to SCMI protocol handle * @xfer: Transfer to initiate and wait for response * * Using asynchronous commands in atomic/polling mode should be avoided since * it could cause long busy-waiting here, so ignore polling for the delayed * response and WARN if it was requested for this command transaction since * upper layers should refrain from issuing such kind of requests. * * The only other option would have been to refrain from using any asynchronous * command even if made available, when an atomic transport is detected, and * instead forcibly use the synchronous version (thing that can be easily * attained at the protocol layer), but this would also have led to longer * stalls of the channel for synchronous commands and possibly timeouts. * (in other words there is usually a good reason if a platform provides an * asynchronous version of a command and we should prefer to use it...just not * when using atomic/polling mode) * * Return: -ETIMEDOUT in case of no delayed response, if transmit error, * return corresponding error, else if all goes well, return 0.
*/ staticint do_xfer_with_response(conststruct scmi_protocol_handle *ph, struct scmi_xfer *xfer)
{ int ret, timeout = msecs_to_jiffies(SCMI_MAX_RESPONSE_TIMEOUT);
DECLARE_COMPLETION_ONSTACK(async_response);
xfer->async_done = &async_response;
/* * Delayed responses should not be polled, so an async command should * not have been used when requiring an atomic/poll context; WARN and * perform instead a sleeping wait. * (Note Async + IgnoreDelayedResponses are sent via do_xfer)
*/
WARN_ON_ONCE(xfer->hdr.poll_completion);
ret = do_xfer(ph, xfer); if (!ret) { if (!wait_for_completion_timeout(xfer->async_done, timeout)) {
dev_err(ph->dev, "timed out in delayed resp(caller: %pS)\n",
(void *)_RET_IP_);
ret = -ETIMEDOUT;
} elseif (xfer->hdr.status) {
ret = scmi_to_linux_errno(xfer->hdr.status);
}
}
xfer->async_done = NULL; return ret;
}
/** * xfer_get_init() - Allocate and initialise one message for transmit * * @ph: Pointer to SCMI protocol handle * @msg_id: Message identifier * @tx_size: transmit message size * @rx_size: receive message size * @p: pointer to the allocated and initialised message * * This function allocates the message using @scmi_xfer_get and * initialise the header. * * Return: 0 if all went fine with @p pointing to message, else * corresponding error.
*/ staticint xfer_get_init(conststruct scmi_protocol_handle *ph,
u8 msg_id, size_t tx_size, size_t rx_size, struct scmi_xfer **p)
{ int ret; struct scmi_xfer *xfer; conststruct scmi_protocol_instance *pi = ph_to_pi(ph); struct scmi_info *info = handle_to_scmi_info(pi->handle); struct scmi_xfers_info *minfo = &info->tx_minfo; struct device *dev = info->dev;
/* Ensure we have sane transfer sizes */ if (rx_size > info->desc->max_msg_size ||
tx_size > info->desc->max_msg_size) return -ERANGE;
xfer = scmi_xfer_get(pi->handle, minfo); if (IS_ERR(xfer)) {
ret = PTR_ERR(xfer);
dev_err(dev, "failed to get free message slot(%d)\n", ret); return ret;
}
/* Pick a sequence number and register this xfer as in-flight */
ret = scmi_xfer_pending_set(xfer, minfo); if (ret) {
dev_err(pi->handle->dev, "Failed to get monotonic token %d\n", ret);
__scmi_xfer_put(minfo, xfer); return ret;
}
/** * version_get() - command to get the revision of the SCMI entity * * @ph: Pointer to SCMI protocol handle * @version: Holds returned version of protocol. * * Updates the SCMI information in the internal data structure. * * Return: 0 if all went fine, else return appropriate error.
*/ staticint version_get(conststruct scmi_protocol_handle *ph, u32 *version)
{ int ret;
__le32 *rev_info; struct scmi_xfer *t;
ret = xfer_get_init(ph, PROTOCOL_VERSION, 0, sizeof(*version), &t); if (ret) return ret;
ret = do_xfer(ph, t); if (!ret) {
rev_info = t->rx.buf;
*version = le32_to_cpu(*rev_info);
}
xfer_put(ph, t); return ret;
}
/** * scmi_set_protocol_priv - Set protocol specific data at init time * * @ph: A reference to the protocol handle. * @priv: The private data to set. * @version: The detected protocol version for the core to register. * * Return: 0 on Success
*/ staticint scmi_set_protocol_priv(conststruct scmi_protocol_handle *ph, void *priv, u32 version)
{ struct scmi_protocol_instance *pi = ph_to_pi(ph);
pi->priv = priv;
pi->version = version;
return 0;
}
/** * scmi_get_protocol_priv - Set protocol specific data at init time * * @ph: A reference to the protocol handle. * * Return: Protocol private data if any was set.
*/ staticvoid *scmi_get_protocol_priv(conststruct scmi_protocol_handle *ph)
{ conststruct scmi_protocol_instance *pi = ph_to_pi(ph);
/** * scmi_common_extended_name_get - Common helper to get extended resources name * @ph: A protocol handle reference. * @cmd_id: The specific command ID to use. * @res_id: The specific resource ID to use. * @flags: A pointer to specific flags to use, if any. * @name: A pointer to the preallocated area where the retrieved name will be * stored as a NULL terminated string. * @len: The len in bytes of the @name char array. * * Return: 0 on Succcess
*/ staticint scmi_common_extended_name_get(conststruct scmi_protocol_handle *ph,
u8 cmd_id, u32 res_id, u32 *flags, char *name, size_t len)
{ int ret;
size_t txlen; struct scmi_xfer *t; struct scmi_msg_resp_domain_name_get *resp;
txlen = !flags ? sizeof(res_id) : sizeof(res_id) + sizeof(*flags);
ret = ph->xops->xfer_get_init(ph, cmd_id, txlen, sizeof(*resp), &t); if (ret) goto out;
ret = ph->xops->do_xfer(ph, t); if (!ret)
strscpy(name, resp->name, len);
ph->xops->xfer_put(ph, t);
out: if (ret)
dev_warn(ph->dev, "Failed to get extended name - id:%u (ret:%d). Using %s\n",
res_id, ret, name); return ret;
}
/** * scmi_common_get_max_msg_size - Get maximum message size * @ph: A protocol handle reference. * * Return: Maximum message size for the current protocol.
*/ staticint scmi_common_get_max_msg_size(conststruct scmi_protocol_handle *ph)
{ conststruct scmi_protocol_instance *pi = ph_to_pi(ph); struct scmi_info *info = handle_to_scmi_info(pi->handle);
return info->desc->max_msg_size;
}
/** * scmi_protocol_msg_check - Check protocol message attributes * * @ph: A reference to the protocol handle. * @message_id: The ID of the message to check. * @attributes: A parameter to optionally return the retrieved message * attributes, in case of Success. * * An helper to check protocol message attributes for a specific protocol * and message pair. * * Return: 0 on SUCCESS
*/ staticint scmi_protocol_msg_check(conststruct scmi_protocol_handle *ph,
u32 message_id, u32 *attributes)
{ int ret; struct scmi_xfer *t;
ret = xfer_get_init(ph, PROTOCOL_MESSAGE_ATTRIBUTES, sizeof(__le32), 0, &t); if (ret) return ret;
put_unaligned_le32(message_id, t->tx.buf);
ret = do_xfer(ph, t); if (!ret && attributes)
*attributes = get_unaligned_le32(t->rx.buf);
xfer_put(ph, t);
return ret;
}
/** * struct scmi_iterator - Iterator descriptor * @msg: A reference to the message TX buffer; filled by @prepare_message with * a proper custom command payload for each multi-part command request. * @resp: A reference to the response RX buffer; used by @update_state and * @process_response to parse the multi-part replies. * @t: A reference to the underlying xfer initialized and used transparently by * the iterator internal routines. * @ph: A reference to the associated protocol handle to be used. * @ops: A reference to the custom provided iterator operations. * @state: The current iterator state; used and updated in turn by the iterators * internal routines and by the caller-provided @scmi_iterator_ops. * @priv: A reference to optional private data as provided by the caller and * passed back to the @@scmi_iterator_ops.
*/ struct scmi_iterator { void *msg; void *resp; struct scmi_xfer *t; conststruct scmi_protocol_handle *ph; struct scmi_iterator_ops *ops; struct scmi_iterator_state state; void *priv;
};
do {
iops->prepare_message(i->msg, st->desc_index, i->priv);
ret = ph->xops->do_xfer(ph, i->t); if (ret) break;
st->rx_len = i->t->rx.len;
ret = iops->update_state(st, i->resp, i->priv); if (ret) break;
if (st->num_returned > st->max_resources - st->desc_index) {
dev_err(ph->dev, "No. of resources can't exceed %d\n",
st->max_resources);
ret = -EINVAL; break;
}
for (st->loop_idx = 0; st->loop_idx < st->num_returned;
st->loop_idx++) {
ret = iops->process_response(ph, i->resp, st, i->priv); if (ret) goto out;
}
st->desc_index += st->num_returned;
ph->xops->reset_rx_to_maxsz(ph, i->t); /* * check for both returned and remaining to avoid infinite * loop due to buggy firmware
*/
} while (st->num_returned && st->num_remaining);
/* Check if the MSG_ID supports fastchannel */
ret = scmi_protocol_msg_check(ph, message_id, &attributes);
SCMI_QUIRK(perf_level_get_fc_force, QUIRK_PERF_FC_FORCE); if (ret || !MSG_SUPPORTS_FASTCHANNEL(attributes)) {
dev_dbg(ph->dev, "Skip FC init for 0x%02X/%d domain:%d - ret:%d\n",
pi->proto->id, message_id, domain, ret); return;
}
if (!p_addr) {
ret = -EINVAL; goto err_out;
}
ret = ph->xops->xfer_get_init(ph, describe_id, sizeof(*info), sizeof(*resp), &t); if (ret) goto err_out;
info = t->tx.buf;
info->domain = cpu_to_le32(domain);
info->message_id = cpu_to_le32(message_id);
/* * Bail out on error leaving fc_info addresses zeroed; this includes * the case in which the requested domain/message_id does NOT support * fastchannels at all.
*/
ret = ph->xops->do_xfer(ph, t); if (ret) goto err_xfer;
resp = t->rx.buf;
flags = le32_to_cpu(resp->attr);
size = le32_to_cpu(resp->chan_size); if (size != valid_size) {
ret = -EINVAL; goto err_xfer;
}
if (rate_limit)
*rate_limit = le32_to_cpu(resp->rate_limit) & GENMASK(19, 0);
dev_dbg(ph->dev, "Using valid FC for protocol %X [MSG_ID:%u / RES_ID:%u]\n",
pi->proto->id, message_id, domain);
return;
err_db_mem:
devm_kfree(ph->dev, db);
err_db:
*p_addr = NULL;
err_xfer:
ph->xops->xfer_put(ph, t);
err_out:
dev_warn(ph->dev, "Failed to get FC for protocol %X [MSG_ID:%u / RES_ID:%u] - ret:%d. Using regular messaging.\n",
pi->proto->id, message_id, domain, ret);
}
#define SCMI_PROTO_FC_RING_DB(w) \ do { \
u##w val = 0; \
\ if (db->mask) \
val = ioread##w(db->addr) & db->mask; \
iowrite##w((u##w)db->set | val, db->addr); \
} while (0)
staticvoid scmi_common_fastchannel_db_ring(struct scmi_fc_db_info *db)
{ if (!db || !db->addr) return;
/** * scmi_revision_area_get - Retrieve version memory area. * * @ph: A reference to the protocol handle. * * A helper to grab the version memory area reference during SCMI Base protocol * initialization. * * Return: A reference to the version memory area associated to the SCMI * instance underlying this protocol handle.
*/ struct scmi_revision_info *
scmi_revision_area_get(conststruct scmi_protocol_handle *ph)
{ conststruct scmi_protocol_instance *pi = ph_to_pi(ph);
return pi->handle->version;
}
/** * scmi_protocol_version_negotiate - Negotiate protocol version * * @ph: A reference to the protocol handle. * * An helper to negotiate a protocol version different from the latest * advertised as supported from the platform: on Success backward * compatibility is assured by the platform. * * Return: 0 on Success
*/ staticint scmi_protocol_version_negotiate(struct scmi_protocol_handle *ph)
{ int ret; struct scmi_xfer *t; struct scmi_protocol_instance *pi = ph_to_pi(ph);
/* At first check if NEGOTIATE_PROTOCOL_VERSION is supported ... */
ret = scmi_protocol_msg_check(ph, NEGOTIATE_PROTOCOL_VERSION, NULL); if (ret) return ret;
/* ... then attempt protocol version negotiation */
ret = xfer_get_init(ph, NEGOTIATE_PROTOCOL_VERSION, sizeof(__le32), 0, &t); if (ret) return ret;
put_unaligned_le32(pi->proto->supported_version, t->tx.buf);
ret = do_xfer(ph, t); if (!ret)
pi->negotiated_version = pi->proto->supported_version;
xfer_put(ph, t);
return ret;
}
/** * scmi_alloc_init_protocol_instance - Allocate and initialize a protocol * instance descriptor. * @info: The reference to the related SCMI instance. * @proto: The protocol descriptor. * * Allocate a new protocol instance descriptor, using the provided @proto * description, against the specified SCMI instance @info, and initialize it; * all resources management is handled via a dedicated per-protocol devres * group. * * Context: Assumes to be called with @protocols_mtx already acquired. * Return: A reference to a freshly allocated and initialized protocol instance * or ERR_PTR on failure. On failure the @proto reference is at first * put using @scmi_protocol_put() before releasing all the devres group.
*/ staticstruct scmi_protocol_instance *
scmi_alloc_init_protocol_instance(struct scmi_info *info, conststruct scmi_protocol *proto)
{ int ret = -ENOMEM; void *gid; struct scmi_protocol_instance *pi; conststruct scmi_handle *handle = &info->handle;
/* Protocol specific devres group */
gid = devres_open_group(handle->dev, NULL, GFP_KERNEL); if (!gid) {
scmi_protocol_put(proto); goto out;
}
pi = devm_kzalloc(handle->dev, sizeof(*pi), GFP_KERNEL); if (!pi) goto clean;
pi->gid = gid;
pi->proto = proto;
pi->handle = handle;
pi->ph.dev = handle->dev;
pi->ph.xops = &xfer_ops;
pi->ph.hops = &helpers_ops;
pi->ph.set_priv = scmi_set_protocol_priv;
pi->ph.get_priv = scmi_get_protocol_priv;
refcount_set(&pi->users, 1); /* proto->init is assured NON NULL by scmi_protocol_register */
ret = pi->proto->instance_init(&pi->ph); if (ret) goto clean;
ret = idr_alloc(&info->protocols, pi, proto->id, proto->id + 1,
GFP_KERNEL); if (ret != proto->id) goto clean;
/* * Warn but ignore events registration errors since we do not want * to skip whole protocols if their notifications are messed up.
*/ if (pi->proto->events) {
ret = scmi_register_protocol_events(handle, pi->proto->id,
&pi->ph,
pi->proto->events); if (ret)
dev_warn(handle->dev, "Protocol:%X - Events Registration Failed - err:%d\n",
pi->proto->id, ret);
}
if (pi->version > proto->supported_version) {
ret = scmi_protocol_version_negotiate(&pi->ph); if (!ret) {
dev_info(handle->dev, "Protocol 0x%X successfully negotiated version 0x%X\n",
proto->id, pi->negotiated_version);
} else {
dev_warn(handle->dev, "Detected UNSUPPORTED higher version 0x%X for protocol 0x%X.\n",
pi->version, pi->proto->id);
dev_warn(handle->dev, "Trying version 0x%X. Backward compatibility is NOT assured.\n",
pi->proto->supported_version);
}
}
return pi;
clean: /* Take care to put the protocol module's owner before releasing all */
scmi_protocol_put(proto);
devres_release_group(handle->dev, gid);
out: return ERR_PTR(ret);
}
/** * scmi_get_protocol_instance - Protocol initialization helper. * @handle: A reference to the SCMI platform instance. * @protocol_id: The protocol being requested. * * In case the required protocol has never been requested before for this * instance, allocate and initialize all the needed structures while handling * resource allocation with a dedicated per-protocol devres subgroup. * * Return: A reference to an initialized protocol instance or error on failure:
--> --------------------
--> maximum size reached
--> --------------------
Messung V0.5
¤ Dauer der Verarbeitung: 0.25 Sekunden
(vorverarbeitet)
¤
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.