Zephyr Project API 4.4.99
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, uint32_t hdr);
44
55 void *data;
70 struct k_mutex lock;
71
77 struct k_sem sem;
78
80 bool ready;
88};
89
110 int (*init)(const struct device *transport);
111
128 int (*send_message)(const struct device *transport,
129 struct scmi_channel *chan,
130 struct scmi_message *msg,
131 bool use_polling);
132
145 int (*setup_chan)(const struct device *transport,
146 struct scmi_channel *chan,
147 bool tx);
148
161 int (*read_message)(const struct device *transport,
162 struct scmi_channel *chan,
163 struct scmi_message *msg);
164
178 bool (*channel_is_free)(const struct device *transport,
179 struct scmi_channel *chan);
180
198 struct scmi_channel *(*request_channel)(const struct device *transport,
199 uint32_t proto, bool tx);
200};
201
203
207static inline struct scmi_channel *
208scmi_transport_request_channel(const struct device *transport,
209 uint32_t proto, bool tx)
210{
211 const struct scmi_transport_api *api =
212 (const struct scmi_transport_api *)transport->api;
213
214 if (api->request_channel) {
215 return api->request_channel(transport, proto, tx);
216 }
217
218 return NULL;
219}
220
224static inline int scmi_transport_init(const struct device *transport)
225{
226 const struct scmi_transport_api *api =
227 (const struct scmi_transport_api *)transport->api;
228
229 if (api->init) {
230 return api->init(transport);
231 }
232
233 return 0;
234}
235
239static inline int scmi_transport_setup_chan(const struct device *transport,
240 struct scmi_channel *chan,
241 bool tx)
242{
243 const struct scmi_transport_api *api =
244 (const struct scmi_transport_api *)transport->api;
245
246 if (!api || !api->setup_chan) {
247 return -ENOSYS;
248 }
249
250 return api->setup_chan(transport, chan, tx);
251}
252
256static inline int scmi_transport_send_message(const struct device *transport,
257 struct scmi_channel *chan,
258 struct scmi_message *msg,
259 bool use_polling)
260{
261 const struct scmi_transport_api *api =
262 (const struct scmi_transport_api *)transport->api;
263
264 if (!api || !api->send_message) {
265 return -ENOSYS;
266 }
267
268 return api->send_message(transport, chan, msg, use_polling);
269}
270
274static inline int scmi_transport_read_message(const struct device *transport,
275 struct scmi_channel *chan,
276 struct scmi_message *msg)
277{
278 const struct scmi_transport_api *api =
279 (const struct scmi_transport_api *)transport->api;
280
281 if (!api || !api->read_message) {
282 return -ENOSYS;
283 }
284
285 return api->read_message(transport, chan, msg);
286}
287
291static inline bool scmi_transport_channel_is_free(const struct device *transport,
292 struct scmi_channel *chan)
293{
294 const struct scmi_transport_api *api =
295 (const struct scmi_transport_api *)transport->api;
296
297 if (!api || !api->channel_is_free) {
298 return -ENOSYS;
299 }
300
301 return api->channel_is_free(transport, chan);
302}
303
311int scmi_core_transport_init(const struct device *transport);
312
314
318
319#endif /* _INCLUDE_ZEPHYR_DRIVERS_FIRMWARE_SCMI_TRANSPORT_H_ */
void(* scmi_channel_cb)(struct scmi_channel *chan, uint32_t hdr)
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:3477
Semaphore structure.
Definition kernel.h:3703
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:194
SCMI transport driver operations.
Definition transport.h:97
int(* init)(const struct device *transport)
Initialize the transport driver.
Definition transport.h:110
int(* setup_chan)(const struct device *transport, struct scmi_channel *chan, bool tx)
Prepare a channel for communication.
Definition transport.h:145
struct scmi_channel *(* request_channel)(const struct device *transport, uint32_t proto, bool tx)
Request a channel dynamically.
Definition transport.h:198
bool(* channel_is_free)(const struct device *transport, struct scmi_channel *chan)
Check if a TX channel is free.
Definition transport.h:178
int(* read_message)(const struct device *transport, struct scmi_channel *chan, struct scmi_message *msg)
Read a message from the platform.
Definition transport.h:161
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:128