Lines Matching defs:ivc
15 #include "ivc.h"
74 static inline bool ivc_channel_empty(const struct ivc *ivc,
86 (void)ivc;
98 if (((wr_count - rd_count) > ivc->nframes) || (wr_count == rd_count)) {
105 static inline bool ivc_channel_full(const struct ivc *ivc,
111 (void)ivc;
117 return ((wr_count - rd_count) >= ivc->nframes);
120 static inline uint32_t ivc_channel_avail_count(const struct ivc *ivc,
126 (void)ivc;
137 static inline void ivc_advance_tx(struct ivc *ivc)
139 ivc->tx_channel->w_count++;
141 if (ivc->w_pos == (ivc->nframes - (uint32_t)1U)) {
142 ivc->w_pos = 0U;
144 ivc->w_pos++;
148 static inline void ivc_advance_rx(struct ivc *ivc)
150 ivc->rx_channel->r_count++;
152 if (ivc->r_pos == (ivc->nframes - (uint32_t)1U)) {
153 ivc->r_pos = 0U;
155 ivc->r_pos++;
159 static inline int32_t ivc_check_read(const struct ivc *ivc)
169 if (ivc->tx_channel->state != ivc_state_established) {
179 if (!ivc_channel_empty(ivc, ivc->rx_channel)) {
183 return ivc_channel_empty(ivc, ivc->rx_channel) ? -ENOMEM : 0;
186 static inline int32_t ivc_check_write(const struct ivc *ivc)
188 if (ivc->tx_channel->state != ivc_state_established) {
192 if (!ivc_channel_full(ivc, ivc->tx_channel)) {
196 return ivc_channel_full(ivc, ivc->tx_channel) ? -ENOMEM : 0;
199 bool tegra_ivc_can_read(const struct ivc *ivc)
201 return ivc_check_read(ivc) == 0;
204 bool tegra_ivc_can_write(const struct ivc *ivc)
206 return ivc_check_write(ivc) == 0;
209 bool tegra_ivc_tx_empty(const struct ivc *ivc)
211 return ivc_channel_empty(ivc, ivc->tx_channel);
221 static void *ivc_frame_pointer(const struct ivc *ivc,
225 assert(frame < ivc->nframes);
227 calc_frame_offset(frame, ivc->frame_size, 0));
230 int32_t tegra_ivc_read(struct ivc *ivc, void *buf, size_t max_read)
239 if (max_read > ivc->frame_size) {
243 result = ivc_check_read(ivc);
254 src = ivc_frame_pointer(ivc, ivc->rx_channel, ivc->r_pos);
258 ivc_advance_rx(ivc);
270 if (ivc_channel_avail_count(ivc, ivc->rx_channel) == (ivc->nframes - (uint32_t)1U)) {
271 ivc->notify(ivc);
278 void *tegra_ivc_read_get_next_frame(const struct ivc *ivc)
280 if (ivc_check_read(ivc) != 0) {
290 return ivc_frame_pointer(ivc, ivc->rx_channel, ivc->r_pos);
293 int32_t tegra_ivc_read_advance(struct ivc *ivc)
300 int32_t result = ivc_check_read(ivc);
305 ivc_advance_rx(ivc);
317 if (ivc_channel_avail_count(ivc, ivc->rx_channel) == (ivc->nframes - (uint32_t)1U)) {
318 ivc->notify(ivc);
324 int32_t tegra_ivc_write(struct ivc *ivc, const void *buf, size_t size)
329 if ((buf == NULL) || (ivc == NULL)) {
333 if (size > ivc->frame_size) {
337 result = ivc_check_write(ivc);
342 p = ivc_frame_pointer(ivc, ivc->tx_channel, ivc->w_pos);
344 (void)memset(p, 0, ivc->frame_size);
353 ivc_advance_tx(ivc);
365 if (ivc_channel_avail_count(ivc, ivc->tx_channel) == 1U) {
366 ivc->notify(ivc);
373 void *tegra_ivc_write_get_next_frame(const struct ivc *ivc)
375 if (ivc_check_write(ivc) != 0) {
379 return ivc_frame_pointer(ivc, ivc->tx_channel, ivc->w_pos);
383 int32_t tegra_ivc_write_advance(struct ivc *ivc)
385 int32_t result = ivc_check_write(ivc);
396 ivc_advance_tx(ivc);
408 if (ivc_channel_avail_count(ivc, ivc->tx_channel) == (uint32_t)1U) {
409 ivc->notify(ivc);
415 void tegra_ivc_channel_reset(const struct ivc *ivc)
417 ivc->tx_channel->state = ivc_state_sync;
418 ivc->notify(ivc);
440 int32_t tegra_ivc_channel_notified(struct ivc *ivc)
445 peer_state = ivc->rx_channel->state;
459 ivc->tx_channel->w_count = 0U;
460 ivc->rx_channel->r_count = 0U;
462 ivc->w_pos = 0U;
463 ivc->r_pos = 0U;
475 ivc->tx_channel->state = ivc_state_ack;
480 ivc->notify(ivc);
482 } else if ((ivc->tx_channel->state == (uint32_t)ivc_state_sync) &&
495 ivc->tx_channel->w_count = 0U;
496 ivc->rx_channel->r_count = 0U;
498 ivc->w_pos = 0U;
499 ivc->r_pos = 0U;
512 ivc->tx_channel->state = ivc_state_established;
517 ivc->notify(ivc);
519 } else if (ivc->tx_channel->state == (uint32_t)ivc_state_ack) {
533 ivc->tx_channel->state = ivc_state_established;
538 ivc->notify(ivc);
549 return ((ivc->tx_channel->state == (uint32_t)ivc_state_established) ? 0 : -EAGAIN);
586 ERROR("ivc channel start not aligned: %lx\n", queue_base1);
590 ERROR("ivc channel start not aligned: %lx\n", queue_base2);
619 int32_t tegra_ivc_init(struct ivc *ivc, uintptr_t rx_base, uintptr_t tx_base,
626 if ((ivc == NULL) || (notify == NULL)) {
643 ivc->rx_channel = (struct ivc_channel_header *)rx_base;
644 ivc->tx_channel = (struct ivc_channel_header *)tx_base;
645 ivc->notify = notify;
646 ivc->frame_size = frame_size;
647 ivc->nframes = nframes;
648 ivc->w_pos = 0U;
649 ivc->r_pos = 0U;