Zephyr API Documentation 4.4.0-rc1
A Scalable Open Source RTOS
Loading...
Searching...
No Matches
transport.h
Go to the documentation of this file.
1/*
2 * Copyright 2024 NXP
3 *
4 * SPDX-License-Identifier: Apache-2.0
5 */
6
12
13#ifndef _INCLUDE_ZEPHYR_DRIVERS_FIRMWARE_SCMI_TRANSPORT_H_
14#define _INCLUDE_ZEPHYR_DRIVERS_FIRMWARE_SCMI_TRANSPORT_H_
15
16#include <zephyr/device.h>
17#include <zephyr/kernel.h>
18
25
26struct scmi_message;
27struct scmi_channel;
28
43typedef void (*scmi_channel_cb)(struct scmi_channel *chan);
44
55 void *data;
70 struct k_mutex lock;
71
77 struct k_sem sem;
78
80 bool ready;
88};
89
111 int (*init)(const struct device *transport);
112
130 int (*send_message)(const struct device *transport,
131 struct scmi_channel *chan,
132 struct scmi_message *msg,
133 bool use_polling);
134
148 int (*setup_chan)(const struct device *transport,
149 struct scmi_channel *chan,
150 bool tx);
151
165 int (*read_message)(const struct device *transport,
166 struct scmi_channel *chan,
167 struct scmi_message *msg);
168
183 bool (*channel_is_free)(const struct device *transport,
184 struct scmi_channel *chan);
185
203 struct scmi_channel *(*request_channel)(const struct device *transport,
204 uint32_t proto, bool tx);
205};
206
208
212static inline struct scmi_channel *
213scmi_transport_request_channel(const struct device *transport,
214 uint32_t proto, bool tx)
215{
216 const struct scmi_transport_api *api =
217 (const struct scmi_transport_api *)transport->api;
218
219 if (api->request_channel) {
220 return api->request_channel(transport, proto, tx);
221 }
222
223 return NULL;
224}
225
229static inline int scmi_transport_init(const struct device *transport)
230{
231 const struct scmi_transport_api *api =
232 (const struct scmi_transport_api *)transport->api;
233
234 if (api->init) {
235 return api->init(transport);
236 }
237
238 return 0;
239}
240
244static inline int scmi_transport_setup_chan(const struct device *transport,
245 struct scmi_channel *chan,
246 bool tx)
247{
248 const struct scmi_transport_api *api =
249 (const struct scmi_transport_api *)transport->api;
250
251 if (!api || !api->setup_chan) {
252 return -ENOSYS;
253 }
254
255 return api->setup_chan(transport, chan, tx);
256}
257
261static inline int scmi_transport_send_message(const struct device *transport,
262 struct scmi_channel *chan,
263 struct scmi_message *msg,
264 bool use_polling)
265{
266 const struct scmi_transport_api *api =
267 (const struct scmi_transport_api *)transport->api;
268
269 if (!api || !api->send_message) {
270 return -ENOSYS;
271 }
272
273 return api->send_message(transport, chan, msg, use_polling);
274}
275
279static inline int scmi_transport_read_message(const struct device *transport,
280 struct scmi_channel *chan,
281 struct scmi_message *msg)
282{
283 const struct scmi_transport_api *api =
284 (const struct scmi_transport_api *)transport->api;
285
286 if (!api || !api->read_message) {
287 return -ENOSYS;
288 }
289
290 return api->read_message(transport, chan, msg);
291}
292
296static inline bool scmi_transport_channel_is_free(const struct device *transport,
297 struct scmi_channel *chan)
298{
299 const struct scmi_transport_api *api =
300 (const struct scmi_transport_api *)transport->api;
301
302 if (!api || !api->channel_is_free) {
303 return -ENOSYS;
304 }
305
306 return api->channel_is_free(transport, chan);
307}
308
318int scmi_core_transport_init(const struct device *transport);
319
321
325
326#endif /* _INCLUDE_ZEPHYR_DRIVERS_FIRMWARE_SCMI_TRANSPORT_H_ */
void(* scmi_channel_cb)(struct scmi_channel *chan)
Callback function for message replies.
Definition transport.h:43
#define ENOSYS
Function not implemented.
Definition errno.h:82
#define NULL
Definition iar_missing_defs.h:20
Public kernel APIs.
#define bool
Definition stdbool.h:13
__UINT32_TYPE__ uint32_t
Definition stdint.h:90
Runtime device structure (in ROM) per driver instance.
Definition device.h:513
const void * api
Address of the API structure exposed by the device instance.
Definition device.h:519
Kernel mutex structure.
Definition kernel.h:3437
Semaphore structure.
Definition kernel.h:3663
SCMI channel structure.
Definition transport.h:53
void * data
channel private data
Definition transport.h:55
scmi_channel_cb cb
callback function.
Definition transport.h:62
bool polling_only
indicates if the channel requires polling-only operation.
Definition transport.h:87
SCMI message structure.
Definition protocol.h:110
SCMI transport driver operations.
Definition transport.h:97
int(* init)(const struct device *transport)
Initialize the transport driver.
Definition transport.h:111
int(* setup_chan)(const struct device *transport, struct scmi_channel *chan, bool tx)
Prepare a channel for communication.
Definition transport.h:148
struct scmi_channel *(* request_channel)(const struct device *transport, uint32_t proto, bool tx)
Request a channel dynamically.
Definition transport.h:203
bool(* channel_is_free)(const struct device *transport, struct scmi_channel *chan)
Check if a TX channel is free.
Definition transport.h:183
int(* read_message)(const struct device *transport, struct scmi_channel *chan, struct scmi_message *msg)
Read a message from the platform.
Definition transport.h:165
int(* send_message)(const struct device *transport, struct scmi_channel *chan, struct scmi_message *msg, bool use_polling)
Send a message to the platform.
Definition transport.h:130