| 1 |
/* SPDX-License-Identifier: GPL-2.0 */ |
| 2 |
/* |
| 3 |
* System Control and Management Interface (SCMI) Message Protocol |
| 4 |
* driver common header file containing some definitions, structures |
| 5 |
* and function prototypes used in all the different SCMI protocols. |
| 6 |
* |
| 7 |
* Copyright (C) 2018-2024 ARM Ltd. |
| 8 |
*/ |
| 9 |
#ifndef _SCMI_COMMON_H |
| 10 |
#define _SCMI_COMMON_H |
| 11 |
|
| 12 |
#include <linux/bitfield.h> |
| 13 |
#include <linux/completion.h> |
| 14 |
#include <linux/device.h> |
| 15 |
#include <linux/errno.h> |
| 16 |
#include <linux/kernel.h> |
| 17 |
#include <linux/hashtable.h> |
| 18 |
#include <linux/list.h> |
| 19 |
#include <linux/module.h> |
| 20 |
#include <linux/refcount.h> |
| 21 |
#include <linux/scmi_protocol.h> |
| 22 |
#include <linux/spinlock.h> |
| 23 |
#include <linux/types.h> |
| 24 |
|
| 25 |
#include <linux/unaligned.h> |
| 26 |
|
| 27 |
#include "protocols.h" |
| 28 |
#include "notify.h" |
| 29 |
|
| 30 |
#define SCMI_MAX_CHANNELS 256 |
| 31 |
|
| 32 |
#define SCMI_MAX_RESPONSE_TIMEOUT (2 * MSEC_PER_SEC) |
| 33 |
|
| 34 |
#define SCMI_SHMEM_MAX_PAYLOAD_SIZE 104 |
| 35 |
|
| 36 |
enum scmi_error_codes { |
| 37 |
SCMI_SUCCESS = 0, /* Success */ |
| 38 |
SCMI_ERR_SUPPORT = -1, /* Not supported */ |
| 39 |
SCMI_ERR_PARAMS = -2, /* Invalid Parameters */ |
| 40 |
SCMI_ERR_ACCESS = -3, /* Invalid access/permission denied */ |
| 41 |
SCMI_ERR_ENTRY = -4, /* Not found */ |
| 42 |
SCMI_ERR_RANGE = -5, /* Value out of range */ |
| 43 |
SCMI_ERR_BUSY = -6, /* Device busy */ |
| 44 |
SCMI_ERR_COMMS = -7, /* Communication Error */ |
| 45 |
SCMI_ERR_GENERIC = -8, /* Generic Error */ |
| 46 |
SCMI_ERR_HARDWARE = -9, /* Hardware Error */ |
| 47 |
SCMI_ERR_PROTOCOL = -10,/* Protocol Error */ |
| 48 |
}; |
| 49 |
|
| 50 |
static const int scmi_linux_errmap[] = { |
| 51 |
/* better than switch case as long as return value is continuous */ |
| 52 |
0, /* SCMI_SUCCESS */ |
| 53 |
-EOPNOTSUPP, /* SCMI_ERR_SUPPORT */ |
| 54 |
-EINVAL, /* SCMI_ERR_PARAM */ |
| 55 |
-EACCES, /* SCMI_ERR_ACCESS */ |
| 56 |
-ENOENT, /* SCMI_ERR_ENTRY */ |
| 57 |
-ERANGE, /* SCMI_ERR_RANGE */ |
| 58 |
-EBUSY, /* SCMI_ERR_BUSY */ |
| 59 |
-ECOMM, /* SCMI_ERR_COMMS */ |
| 60 |
-EIO, /* SCMI_ERR_GENERIC */ |
| 61 |
-EREMOTEIO, /* SCMI_ERR_HARDWARE */ |
| 62 |
-EPROTO, /* SCMI_ERR_PROTOCOL */ |
| 63 |
}; |
| 64 |
|
| 65 |
static inline int scmi_to_linux_errno(int errno) |
| 66 |
{ |
| 67 |
int err_idx = -errno; |
| 68 |
|
| 69 |
if (err_idx >= SCMI_SUCCESS && err_idx < ARRAY_SIZE(scmi_linux_errmap)) |
| 70 |
return scmi_linux_errmap[err_idx]; |
| 71 |
return -EIO; |
| 72 |
} |
| 73 |
|
| 74 |
#define MSG_ID_MASK GENMASK(7, 0) |
| 75 |
#define MSG_XTRACT_ID(hdr) FIELD_GET(MSG_ID_MASK, (hdr)) |
| 76 |
#define MSG_TYPE_MASK GENMASK(9, 8) |
| 77 |
#define MSG_XTRACT_TYPE(hdr) FIELD_GET(MSG_TYPE_MASK, (hdr)) |
| 78 |
#define MSG_TYPE_COMMAND 0 |
| 79 |
#define MSG_TYPE_DELAYED_RESP 2 |
| 80 |
#define MSG_TYPE_NOTIFICATION 3 |
| 81 |
#define MSG_PROTOCOL_ID_MASK GENMASK(17, 10) |
| 82 |
#define MSG_XTRACT_PROT_ID(hdr) FIELD_GET(MSG_PROTOCOL_ID_MASK, (hdr)) |
| 83 |
#define MSG_TOKEN_ID_MASK GENMASK(27, 18) |
| 84 |
#define MSG_XTRACT_TOKEN(hdr) FIELD_GET(MSG_TOKEN_ID_MASK, (hdr)) |
| 85 |
#define MSG_TOKEN_MAX (MSG_XTRACT_TOKEN(MSG_TOKEN_ID_MASK) + 1) |
| 86 |
|
| 87 |
/* |
| 88 |
* Size of @pending_xfers hashtable included in @scmi_xfers_info; ideally, in |
| 89 |
* order to minimize space and collisions, this should equal max_msg, i.e. the |
| 90 |
* maximum number of in-flight messages on a specific platform, but such value |
| 91 |
* is only available at runtime while kernel hashtables are statically sized: |
| 92 |
* pick instead as a fixed static size the maximum number of entries that can |
| 93 |
* fit the whole table into one 4k page. |
| 94 |
*/ |
| 95 |
#define SCMI_PENDING_XFERS_HT_ORDER_SZ 9 |
| 96 |
|
| 97 |
/** |
| 98 |
* pack_scmi_header() - packs and returns 32-bit header |
| 99 |
* |
| 100 |
* @hdr: pointer to header containing all the information on message id, |
| 101 |
* protocol id, sequence id and type. |
| 102 |
* |
| 103 |
* Return: 32-bit packed message header to be sent to the platform. |
| 104 |
*/ |
| 105 |
static inline u32 pack_scmi_header(struct scmi_msg_hdr *hdr) |
| 106 |
{ |
| 107 |
return FIELD_PREP(MSG_ID_MASK, hdr->id) | |
| 108 |
FIELD_PREP(MSG_TYPE_MASK, hdr->type) | |
| 109 |
FIELD_PREP(MSG_TOKEN_ID_MASK, hdr->seq) | |
| 110 |
FIELD_PREP(MSG_PROTOCOL_ID_MASK, hdr->protocol_id); |
| 111 |
} |
| 112 |
|
| 113 |
/** |
| 114 |
* unpack_scmi_header() - unpacks and records message and protocol id |
| 115 |
* |
| 116 |
* @msg_hdr: 32-bit packed message header sent from the platform |
| 117 |
* @hdr: pointer to header to fetch message and protocol id. |
| 118 |
*/ |
| 119 |
static inline void unpack_scmi_header(u32 msg_hdr, struct scmi_msg_hdr *hdr) |
| 120 |
{ |
| 121 |
hdr->id = MSG_XTRACT_ID(msg_hdr); |
| 122 |
hdr->protocol_id = MSG_XTRACT_PROT_ID(msg_hdr); |
| 123 |
hdr->type = MSG_XTRACT_TYPE(msg_hdr); |
| 124 |
} |
| 125 |
|
| 126 |
/* |
| 127 |
* An helper macro to lookup an xfer from the @pending_xfers hashtable |
| 128 |
* using the message sequence number token as a key. |
| 129 |
*/ |
| 130 |
#define XFER_FIND(__ht, __k) \ |
| 131 |
({ \ |
| 132 |
typeof(__k) k_ = __k; \ |
| 133 |
struct scmi_xfer *xfer_ = NULL; \ |
| 134 |
\ |
| 135 |
hash_for_each_possible((__ht), xfer_, node, k_) \ |
| 136 |
if (xfer_->hdr.seq == k_) \ |
| 137 |
break; \ |
| 138 |
xfer_; \ |
| 139 |
}) |
| 140 |
|
| 141 |
struct scmi_revision_info * |
| 142 |
scmi_revision_area_get(const struct scmi_protocol_handle *ph); |
| 143 |
void scmi_setup_protocol_implemented(const struct scmi_protocol_handle *ph, |
| 144 |
u8 *prot_imp); |
| 145 |
|
| 146 |
extern const struct bus_type scmi_bus_type; |
| 147 |
|
| 148 |
#define SCMI_BUS_NOTIFY_DEVICE_REQUEST 0 |
| 149 |
#define SCMI_BUS_NOTIFY_DEVICE_UNREQUEST 1 |
| 150 |
extern struct blocking_notifier_head scmi_requested_devices_nh; |
| 151 |
|
| 152 |
struct scmi_device *scmi_device_create(struct device_node *np, |
| 153 |
struct device *parent, int protocol, |
| 154 |
const char *name); |
| 155 |
void scmi_device_destroy(struct device *parent, int protocol, const char *name); |
| 156 |
|
| 157 |
int scmi_protocol_acquire(const struct scmi_handle *handle, u8 protocol_id); |
| 158 |
void scmi_protocol_release(const struct scmi_handle *handle, u8 protocol_id); |
| 159 |
|
| 160 |
/* SCMI Transport */ |
| 161 |
/** |
| 162 |
* struct scmi_chan_info - Structure representing a SCMI channel information |
| 163 |
* |
| 164 |
* @id: An identifier for this channel: this matches the protocol number |
| 165 |
* used to initialize this channel |
| 166 |
* @dev: Reference to device in the SCMI hierarchy corresponding to this |
| 167 |
* channel |
| 168 |
* @is_p2a: A flag to identify a channel as P2A (RX) |
| 169 |
* @rx_timeout_ms: The configured RX timeout in milliseconds. |
| 170 |
* @max_msg_size: Maximum size of message payload. |
| 171 |
* @handle: Pointer to SCMI entity handle |
| 172 |
* @no_completion_irq: Flag to indicate that this channel has no completion |
| 173 |
* interrupt mechanism for synchronous commands. |
| 174 |
* This can be dynamically set by transports at run-time |
| 175 |
* inside their provided .chan_setup(). |
| 176 |
* @transport_info: Transport layer related information |
| 177 |
*/ |
| 178 |
struct scmi_chan_info { |
| 179 |
int id; |
| 180 |
struct device *dev; |
| 181 |
bool is_p2a; |
| 182 |
unsigned int rx_timeout_ms; |
| 183 |
unsigned int max_msg_size; |
| 184 |
struct scmi_handle *handle; |
| 185 |
bool no_completion_irq; |
| 186 |
void *transport_info; |
| 187 |
}; |
| 188 |
|
| 189 |
/** |
| 190 |
* struct scmi_transport_ops - Structure representing a SCMI transport ops |
| 191 |
* |
| 192 |
* @chan_available: Callback to check if channel is available or not |
| 193 |
* @chan_setup: Callback to allocate and setup a channel |
| 194 |
* @chan_free: Callback to free a channel |
| 195 |
* @get_max_msg: Optional callback to provide max_msg dynamically |
| 196 |
* Returns the maximum number of messages for the channel type |
| 197 |
* (tx or rx) that can be pending simultaneously in the system |
| 198 |
* @send_message: Callback to send a message |
| 199 |
* @mark_txdone: Callback to mark tx as done |
| 200 |
* @fetch_response: Callback to fetch response |
| 201 |
* @fetch_notification: Callback to fetch notification |
| 202 |
* @clear_channel: Callback to clear a channel |
| 203 |
* @poll_done: Callback to poll transfer status |
| 204 |
*/ |
| 205 |
struct scmi_transport_ops { |
| 206 |
bool (*chan_available)(struct device_node *of_node, int idx); |
| 207 |
int (*chan_setup)(struct scmi_chan_info *cinfo, struct device *dev, |
| 208 |
bool tx); |
| 209 |
int (*chan_free)(int id, void *p, void *data); |
| 210 |
unsigned int (*get_max_msg)(struct scmi_chan_info *base_cinfo); |
| 211 |
int (*send_message)(struct scmi_chan_info *cinfo, |
| 212 |
struct scmi_xfer *xfer); |
| 213 |
void (*mark_txdone)(struct scmi_chan_info *cinfo, int ret, |
| 214 |
struct scmi_xfer *xfer); |
| 215 |
void (*fetch_response)(struct scmi_chan_info *cinfo, |
| 216 |
struct scmi_xfer *xfer); |
| 217 |
void (*fetch_notification)(struct scmi_chan_info *cinfo, |
| 218 |
size_t max_len, struct scmi_xfer *xfer); |
| 219 |
void (*clear_channel)(struct scmi_chan_info *cinfo); |
| 220 |
bool (*poll_done)(struct scmi_chan_info *cinfo, struct scmi_xfer *xfer); |
| 221 |
}; |
| 222 |
|
| 223 |
/** |
| 224 |
* struct scmi_desc - Description of SoC integration |
| 225 |
* |
| 226 |
* @ops: Pointer to the transport specific ops structure |
| 227 |
* @max_rx_timeout_ms: Timeout for communication with SoC (in Milliseconds) |
| 228 |
* @max_msg: Maximum number of messages for a channel type (tx or rx) that can |
| 229 |
* be pending simultaneously in the system. May be overridden by the |
| 230 |
* get_max_msg op. |
| 231 |
* @max_msg_size: Maximum size of data payload per message that can be handled. |
| 232 |
* @atomic_threshold: Optional system wide DT-configured threshold, expressed |
| 233 |
* in microseconds, for atomic operations. |
| 234 |
* Only SCMI synchronous commands reported by the platform |
| 235 |
* to have an execution latency lesser-equal to the threshold |
| 236 |
* should be considered for atomic mode operation: such |
| 237 |
* decision is finally left up to the SCMI drivers. |
| 238 |
* @force_polling: Flag to force this whole transport to use SCMI core polling |
| 239 |
* mechanism instead of completion interrupts even if available. |
| 240 |
* @sync_cmds_completed_on_ret: Flag to indicate that the transport assures |
| 241 |
* synchronous-command messages are atomically |
| 242 |
* completed on .send_message: no need to poll |
| 243 |
* actively waiting for a response. |
| 244 |
* Used by core internally only when polling is |
| 245 |
* selected as a waiting for reply method: i.e. |
| 246 |
* if a completion irq was found use that anyway. |
| 247 |
* @atomic_enabled: Flag to indicate that this transport, which is assured not |
| 248 |
* to sleep anywhere on the TX path, can be used in atomic mode |
| 249 |
* when requested. |
| 250 |
*/ |
| 251 |
struct scmi_desc { |
| 252 |
const struct scmi_transport_ops *ops; |
| 253 |
int max_rx_timeout_ms; |
| 254 |
int max_msg; |
| 255 |
int max_msg_size; |
| 256 |
unsigned int atomic_threshold; |
| 257 |
const bool force_polling; |
| 258 |
const bool sync_cmds_completed_on_ret; |
| 259 |
const bool atomic_enabled; |
| 260 |
}; |
| 261 |
|
| 262 |
static inline bool is_polling_required(struct scmi_chan_info *cinfo, |
| 263 |
const struct scmi_desc *desc) |
| 264 |
{ |
| 265 |
return cinfo->no_completion_irq || desc->force_polling; |
| 266 |
} |
| 267 |
|
| 268 |
static inline bool is_transport_polling_capable(const struct scmi_desc *desc) |
| 269 |
{ |
| 270 |
return desc->ops->poll_done || desc->sync_cmds_completed_on_ret; |
| 271 |
} |
| 272 |
|
| 273 |
static inline bool is_polling_enabled(struct scmi_chan_info *cinfo, |
| 274 |
const struct scmi_desc *desc) |
| 275 |
{ |
| 276 |
return is_polling_required(cinfo, desc) && |
| 277 |
is_transport_polling_capable(desc); |
| 278 |
} |
| 279 |
|
| 280 |
void scmi_xfer_raw_put(const struct scmi_handle *handle, |
| 281 |
struct scmi_xfer *xfer); |
| 282 |
struct scmi_xfer *scmi_xfer_raw_get(const struct scmi_handle *handle); |
| 283 |
struct scmi_chan_info * |
| 284 |
scmi_xfer_raw_channel_get(const struct scmi_handle *handle, u8 protocol_id); |
| 285 |
|
| 286 |
int scmi_xfer_raw_inflight_register(const struct scmi_handle *handle, |
| 287 |
struct scmi_xfer *xfer); |
| 288 |
|
| 289 |
int scmi_xfer_raw_wait_for_message_response(struct scmi_chan_info *cinfo, |
| 290 |
struct scmi_xfer *xfer, |
| 291 |
unsigned int timeout_ms); |
| 292 |
|
| 293 |
enum debug_counters { |
| 294 |
SENT_OK, |
| 295 |
SENT_FAIL, |
| 296 |
SENT_FAIL_POLLING_UNSUPPORTED, |
| 297 |
SENT_FAIL_CHANNEL_NOT_FOUND, |
| 298 |
RESPONSE_OK, |
| 299 |
NOTIFICATION_OK, |
| 300 |
DELAYED_RESPONSE_OK, |
| 301 |
XFERS_RESPONSE_TIMEOUT, |
| 302 |
XFERS_RESPONSE_POLLED_TIMEOUT, |
| 303 |
RESPONSE_POLLED_OK, |
| 304 |
ERR_MSG_UNEXPECTED, |
| 305 |
ERR_MSG_INVALID, |
| 306 |
ERR_MSG_NOMEM, |
| 307 |
ERR_PROTOCOL, |
| 308 |
XFERS_INFLIGHT, |
| 309 |
SCMI_DEBUG_COUNTERS_LAST |
| 310 |
}; |
| 311 |
|
| 312 |
/** |
| 313 |
* struct scmi_debug_info - Debug common info |
| 314 |
* @top_dentry: A reference to the top debugfs dentry |
| 315 |
* @name: Name of this SCMI instance |
| 316 |
* @type: Type of this SCMI instance |
| 317 |
* @is_atomic: Flag to state if the transport of this instance is atomic |
| 318 |
* @counters: An array of atomic_c's used for tracking statistics (if enabled) |
| 319 |
*/ |
| 320 |
struct scmi_debug_info { |
| 321 |
struct dentry *top_dentry; |
| 322 |
const char *name; |
| 323 |
const char *type; |
| 324 |
bool is_atomic; |
| 325 |
atomic_t counters[SCMI_DEBUG_COUNTERS_LAST]; |
| 326 |
}; |
| 327 |
|
| 328 |
static inline void scmi_inc_count(struct scmi_debug_info *dbg, int stat) |
| 329 |
{ |
| 330 |
if (IS_ENABLED(CONFIG_ARM_SCMI_DEBUG_COUNTERS)) { |
| 331 |
if (dbg) |
| 332 |
atomic_inc(&dbg->counters[stat]); |
| 333 |
} |
| 334 |
} |
| 335 |
|
| 336 |
static inline void scmi_dec_count(struct scmi_debug_info *dbg, int stat) |
| 337 |
{ |
| 338 |
if (IS_ENABLED(CONFIG_ARM_SCMI_DEBUG_COUNTERS)) { |
| 339 |
if (dbg) |
| 340 |
atomic_dec(&dbg->counters[stat]); |
| 341 |
} |
| 342 |
} |
| 343 |
|
| 344 |
enum scmi_bad_msg { |
| 345 |
MSG_UNEXPECTED = -1, |
| 346 |
MSG_INVALID = -2, |
| 347 |
MSG_UNKNOWN = -3, |
| 348 |
MSG_NOMEM = -4, |
| 349 |
MSG_MBOX_SPURIOUS = -5, |
| 350 |
}; |
| 351 |
|
| 352 |
/* Used for compactness and signature validation of the function pointers being |
| 353 |
* passed. |
| 354 |
*/ |
| 355 |
typedef void (*shmem_copy_toio_t)(void __iomem *to, const void *from, |
| 356 |
size_t count); |
| 357 |
typedef void (*shmem_copy_fromio_t)(void *to, const void __iomem *from, |
| 358 |
size_t count); |
| 359 |
|
| 360 |
/** |
| 361 |
* struct scmi_shmem_io_ops - I/O operations to read from/write to |
| 362 |
* Shared Memory |
| 363 |
* |
| 364 |
* @toio: Copy data to the shared memory area |
| 365 |
* @fromio: Copy data from the shared memory area |
| 366 |
*/ |
| 367 |
struct scmi_shmem_io_ops { |
| 368 |
shmem_copy_fromio_t fromio; |
| 369 |
shmem_copy_toio_t toio; |
| 370 |
}; |
| 371 |
|
| 372 |
/* shmem related declarations */ |
| 373 |
struct scmi_shared_mem; |
| 374 |
|
| 375 |
/** |
| 376 |
* struct scmi_shared_mem_operations - Transport core operations for |
| 377 |
* Shared Memory |
| 378 |
* |
| 379 |
* @tx_prepare: Prepare the @xfer message for transmission on the chosen @shmem |
| 380 |
* @read_header: Read header of the message currently hold in @shmem |
| 381 |
* @fetch_response: Copy the message response from @shmem into @xfer |
| 382 |
* @fetch_notification: Copy the message notification from @shmem into @xfer |
| 383 |
* @clear_channel: Clear the @shmem channel busy flag |
| 384 |
* @poll_done: Check if poll has completed for @xfer on @shmem |
| 385 |
* @channel_free: Check if @shmem channel is marked as free |
| 386 |
* @channel_intr_enabled: Check is @shmem channel has requested a completion irq |
| 387 |
* @setup_iomap: Setup IO shared memory for channel @cinfo |
| 388 |
*/ |
| 389 |
struct scmi_shared_mem_operations { |
| 390 |
void (*tx_prepare)(struct scmi_shared_mem __iomem *shmem, |
| 391 |
struct scmi_xfer *xfer, |
| 392 |
struct scmi_chan_info *cinfo, |
| 393 |
shmem_copy_toio_t toio); |
| 394 |
u32 (*read_header)(struct scmi_shared_mem __iomem *shmem); |
| 395 |
|
| 396 |
void (*fetch_response)(struct scmi_shared_mem __iomem *shmem, |
| 397 |
struct scmi_xfer *xfer, |
| 398 |
shmem_copy_fromio_t fromio); |
| 399 |
void (*fetch_notification)(struct scmi_shared_mem __iomem *shmem, |
| 400 |
size_t max_len, struct scmi_xfer *xfer, |
| 401 |
shmem_copy_fromio_t fromio); |
| 402 |
void (*clear_channel)(struct scmi_shared_mem __iomem *shmem); |
| 403 |
bool (*poll_done)(struct scmi_shared_mem __iomem *shmem, |
| 404 |
struct scmi_xfer *xfer); |
| 405 |
bool (*channel_free)(struct scmi_shared_mem __iomem *shmem); |
| 406 |
bool (*channel_intr_enabled)(struct scmi_shared_mem __iomem *shmem); |
| 407 |
void __iomem *(*setup_iomap)(struct scmi_chan_info *cinfo, |
| 408 |
struct device *dev, |
| 409 |
bool tx, struct resource *res, |
| 410 |
struct scmi_shmem_io_ops **ops); |
| 411 |
}; |
| 412 |
|
| 413 |
const struct scmi_shared_mem_operations *scmi_shared_mem_operations_get(void); |
| 414 |
|
| 415 |
/* declarations for message passing transports */ |
| 416 |
struct scmi_msg_payld; |
| 417 |
|
| 418 |
/* Maximum overhead of message w.r.t. struct scmi_desc.max_msg_size */ |
| 419 |
#define SCMI_MSG_MAX_PROT_OVERHEAD (2 * sizeof(__le32)) |
| 420 |
|
| 421 |
/** |
| 422 |
* struct scmi_message_operations - Transport core operations for Message |
| 423 |
* |
| 424 |
* @response_size: Get calculated response size for @xfer |
| 425 |
* @command_size: Get calculated command size for @xfer |
| 426 |
* @tx_prepare: Prepare the @xfer message for transmission on the provided @msg |
| 427 |
* @read_header: Read header of the message currently hold in @msg |
| 428 |
* @fetch_response: Copy the message response from @msg into @xfer |
| 429 |
* @fetch_notification: Copy the message notification from @msg into @xfer |
| 430 |
*/ |
| 431 |
struct scmi_message_operations { |
| 432 |
size_t (*response_size)(struct scmi_xfer *xfer); |
| 433 |
size_t (*command_size)(struct scmi_xfer *xfer); |
| 434 |
void (*tx_prepare)(struct scmi_msg_payld *msg, struct scmi_xfer *xfer); |
| 435 |
u32 (*read_header)(struct scmi_msg_payld *msg); |
| 436 |
void (*fetch_response)(struct scmi_msg_payld *msg, size_t len, |
| 437 |
struct scmi_xfer *xfer); |
| 438 |
void (*fetch_notification)(struct scmi_msg_payld *msg, size_t len, |
| 439 |
size_t max_len, struct scmi_xfer *xfer); |
| 440 |
}; |
| 441 |
|
| 442 |
const struct scmi_message_operations *scmi_message_operations_get(void); |
| 443 |
|
| 444 |
/** |
| 445 |
* struct scmi_transport_core_operations - Transpoert core operations |
| 446 |
* |
| 447 |
* @bad_message_trace: An helper to report a malformed/unexpected message |
| 448 |
* @rx_callback: Callback to report received messages |
| 449 |
* @shmem: Datagram operations for shared memory based transports |
| 450 |
* @msg: Datagram operations for message based transports |
| 451 |
*/ |
| 452 |
struct scmi_transport_core_operations { |
| 453 |
void (*bad_message_trace)(struct scmi_chan_info *cinfo, |
| 454 |
u32 msg_hdr, enum scmi_bad_msg err); |
| 455 |
void (*rx_callback)(struct scmi_chan_info *cinfo, u32 msg_hdr, |
| 456 |
void *priv); |
| 457 |
const struct scmi_shared_mem_operations *shmem; |
| 458 |
const struct scmi_message_operations *msg; |
| 459 |
}; |
| 460 |
|
| 461 |
/** |
| 462 |
* struct scmi_transport - A structure representing a configured transport |
| 463 |
* |
| 464 |
* @supplier: Device representing the transport and acting as a supplier for |
| 465 |
* the core SCMI stack |
| 466 |
* @desc: Transport descriptor |
| 467 |
* @core_ops: A pointer to a pointer used by the core SCMI stack to make the |
| 468 |
* core transport operations accessible to the transports. |
| 469 |
*/ |
| 470 |
struct scmi_transport { |
| 471 |
struct device *supplier; |
| 472 |
struct scmi_desc desc; |
| 473 |
struct scmi_transport_core_operations **core_ops; |
| 474 |
}; |
| 475 |
|
| 476 |
#define DEFINE_SCMI_TRANSPORT_DRIVER(__tag, __drv, __desc, __match, __core_ops)\ |
| 477 |
static void __tag##_dev_free(void *data) \ |
| 478 |
{ \ |
| 479 |
struct platform_device *spdev = data; \ |
| 480 |
\ |
| 481 |
platform_device_unregister(spdev); \ |
| 482 |
} \ |
| 483 |
\ |
| 484 |
static int __tag##_probe(struct platform_device *pdev) \ |
| 485 |
{ \ |
| 486 |
struct device *dev = &pdev->dev; \ |
| 487 |
struct platform_device *spdev; \ |
| 488 |
struct scmi_transport strans; \ |
| 489 |
int ret; \ |
| 490 |
\ |
| 491 |
spdev = platform_device_alloc("arm-scmi", PLATFORM_DEVID_AUTO); \ |
| 492 |
if (!spdev) \ |
| 493 |
return -ENOMEM; \ |
| 494 |
\ |
| 495 |
device_set_of_node_from_dev(&spdev->dev, dev); \ |
| 496 |
\ |
| 497 |
strans.supplier = dev; \ |
| 498 |
memcpy(&strans.desc, &(__desc), sizeof(strans.desc)); \ |
| 499 |
strans.core_ops = &(__core_ops); \ |
| 500 |
\ |
| 501 |
ret = platform_device_add_data(spdev, &strans, sizeof(strans)); \ |
| 502 |
if (ret) \ |
| 503 |
goto err; \ |
| 504 |
\ |
| 505 |
spdev->dev.parent = dev; \ |
| 506 |
ret = platform_device_add(spdev); \ |
| 507 |
if (ret) \ |
| 508 |
goto err; \ |
| 509 |
\ |
| 510 |
return devm_add_action_or_reset(dev, __tag##_dev_free, spdev); \ |
| 511 |
\ |
| 512 |
err: \ |
| 513 |
platform_device_put(spdev); \ |
| 514 |
return ret; \ |
| 515 |
} \ |
| 516 |
\ |
| 517 |
static struct platform_driver __drv = { \ |
| 518 |
.driver = { \ |
| 519 |
.name = #__tag "_transport", \ |
| 520 |
.of_match_table = __match, \ |
| 521 |
}, \ |
| 522 |
.probe = __tag##_probe, \ |
| 523 |
} |
| 524 |
|
| 525 |
void scmi_notification_instance_data_set(const struct scmi_handle *handle, |
| 526 |
void *priv); |
| 527 |
void *scmi_notification_instance_data_get(const struct scmi_handle *handle); |
| 528 |
int scmi_inflight_count(const struct scmi_handle *handle); |
| 529 |
#endif /* _SCMI_COMMON_H */ |