Zephyr API Documentation 4.0.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#ifndef _INCLUDE_ZEPHYR_DRIVERS_FIRMWARE_SCMI_TRANSPORT_H_
13#define _INCLUDE_ZEPHYR_DRIVERS_FIRMWARE_SCMI_TRANSPORT_H_
14
15#include <zephyr/device.h>
16#include <zephyr/kernel.h>
17
18struct scmi_message;
19struct scmi_channel;
20
35typedef void (*scmi_channel_cb)(struct scmi_channel *chan);
36
52 struct k_mutex lock;
58 struct k_sem sem;
60 void *data;
69 bool ready;
70};
71
73 int (*init)(const struct device *transport);
74 int (*send_message)(const struct device *transport,
75 struct scmi_channel *chan,
76 struct scmi_message *msg);
77 int (*setup_chan)(const struct device *transport,
78 struct scmi_channel *chan,
79 bool tx);
80 int (*read_message)(const struct device *transport,
81 struct scmi_channel *chan,
82 struct scmi_message *msg);
83 bool (*channel_is_free)(const struct device *transport,
84 struct scmi_channel *chan);
85 struct scmi_channel *(*request_channel)(const struct device *transport,
86 uint32_t proto, bool tx);
87};
88
109static inline struct scmi_channel *
111 uint32_t proto, bool tx)
112{
113 const struct scmi_transport_api *api =
114 (const struct scmi_transport_api *)transport->api;
115
116 if (api->request_channel) {
117 return api->request_channel(transport, proto, tx);
118 }
119
120 return NULL;
121}
122
142static inline int scmi_transport_init(const struct device *transport)
143{
144 const struct scmi_transport_api *api =
145 (const struct scmi_transport_api *)transport->api;
146
147 if (api->init) {
148 return api->init(transport);
149 }
150
151 return 0;
152}
153
170static inline int scmi_transport_setup_chan(const struct device *transport,
171 struct scmi_channel *chan,
172 bool tx)
173{
174 const struct scmi_transport_api *api =
175 (const struct scmi_transport_api *)transport->api;
176
177 if (!api || !api->setup_chan) {
178 return -ENOSYS;
179 }
180
181 return api->setup_chan(transport, chan, tx);
182}
183
199static inline int scmi_transport_send_message(const struct device *transport,
200 struct scmi_channel *chan,
201 struct scmi_message *msg)
202{
203 const struct scmi_transport_api *api =
204 (const struct scmi_transport_api *)transport->api;
205
206 if (!api || !api->send_message) {
207 return -ENOSYS;
208 }
209
210 return api->send_message(transport, chan, msg);
211}
212
225static inline int scmi_transport_read_message(const struct device *transport,
226 struct scmi_channel *chan,
227 struct scmi_message *msg)
228{
229 const struct scmi_transport_api *api =
230 (const struct scmi_transport_api *)transport->api;
231
232 if (!api || !api->read_message) {
233 return -ENOSYS;
234 }
235
236 return api->read_message(transport, chan, msg);
237}
238
250static inline bool scmi_transport_channel_is_free(const struct device *transport,
251 struct scmi_channel *chan)
252{
253 const struct scmi_transport_api *api =
254 (const struct scmi_transport_api *)transport->api;
255
256 if (!api || !api->channel_is_free) {
257 return -ENOSYS;
258 }
259
260 return api->channel_is_free(transport, chan);
261}
262
272int scmi_core_transport_init(const struct device *transport);
273
274#endif /* _INCLUDE_ZEPHYR_DRIVERS_FIRMWARE_SCMI_TRANSPORT_H_ */
#define ENOSYS
Function not implemented.
Definition errno.h:82
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:411
const void * api
Address of the API structure exposed by the device instance.
Definition device.h:417
Mutex Structure.
Definition kernel.h:3024
SCMI channel structure.
Definition transport.h:45
void * data
channel private data
Definition transport.h:60
bool ready
is the channel ready to be used by a protocol?
Definition transport.h:69
struct k_sem sem
binary semaphore.
Definition transport.h:58
struct k_mutex lock
channel lock.
Definition transport.h:52
scmi_channel_cb cb
callback function.
Definition transport.h:67
SCMI message structure.
Definition protocol.h:90
Definition transport.h:72
int(* init)(const struct device *transport)
Definition transport.h:73
int(* setup_chan)(const struct device *transport, struct scmi_channel *chan, bool tx)
Definition transport.h:77
struct scmi_channel *(* request_channel)(const struct device *transport, uint32_t proto, bool tx)
Definition transport.h:85
bool(* channel_is_free)(const struct device *transport, struct scmi_channel *chan)
Definition transport.h:83
int(* send_message)(const struct device *transport, struct scmi_channel *chan, struct scmi_message *msg)
Definition transport.h:74
int(* read_message)(const struct device *transport, struct scmi_channel *chan, struct scmi_message *msg)
Definition transport.h:80
void(* scmi_channel_cb)(struct scmi_channel *chan)
Callback function for message replies.
Definition transport.h:35
static bool scmi_transport_channel_is_free(const struct device *transport, struct scmi_channel *chan)
Check if an SCMI channel is free.
Definition transport.h:250
int scmi_core_transport_init(const struct device *transport)
Perfrom SCMI core initialization.
static int scmi_transport_setup_chan(const struct device *transport, struct scmi_channel *chan, bool tx)
Setup an SCMI channel.
Definition transport.h:170
static int scmi_transport_init(const struct device *transport)
Perform initialization for the transport layer driver.
Definition transport.h:142
static int scmi_transport_send_message(const struct device *transport, struct scmi_channel *chan, struct scmi_message *msg)
Send an SCMI channel.
Definition transport.h:199
static struct scmi_channel * scmi_transport_request_channel(const struct device *transport, uint32_t proto, bool tx)
Request an SCMI channel dynamically.
Definition transport.h:110
static int scmi_transport_read_message(const struct device *transport, struct scmi_channel *chan, struct scmi_message *msg)
Read an SCMI message.
Definition transport.h:225