1
1
/*
2
- * Copyright 2022, UNSW ???
2
+ * Copyright 2022, UNSW
3
+ *
4
+ * SPDX-License-Identifier: BSD-2-Clause
3
5
*/
4
6
5
- #pragma once
7
+ #pragma once
6
8
7
9
#include <stdint.h>
8
10
#include <stddef.h>
@@ -35,7 +37,6 @@ typedef struct ring_handle {
35
37
notify_fn notify ;
36
38
} ring_handle_t ;
37
39
38
-
39
40
/**
40
41
* Initialise the shared ring buffer.
41
42
*
@@ -44,7 +45,7 @@ typedef struct ring_handle {
44
45
* @param used pointer to 'used' ring in shared memory.
45
46
* @param notify function pointer used to notify the other user.
46
47
* @param buffer_init 1 indicates the read and write indices in shared memory need to be initialised.
47
- * 0 inidicates they do not. Only one side of the shared memory regions needs to do this.
48
+ * 0 inidicates they do not. Only one side of the shared memory regions needs to do this.
48
49
*/
49
50
void ring_init (ring_handle_t * ring , ring_buffer_t * avail , ring_buffer_t * used , notify_fn notify , int buffer_init );
50
51
@@ -55,7 +56,7 @@ void ring_init(ring_handle_t *ring, ring_buffer_t *avail, ring_buffer_t *used, n
55
56
*
56
57
* @return true indicates the buffer is empty, false otherwise.
57
58
*/
58
- static inline int ring_empty (ring_buffer_t * ring )
59
+ static inline int ring_empty (ring_buffer_t * ring )
59
60
{
60
61
return !((ring -> write_idx - ring -> read_idx ) % CONFIG_LIB_SHARED_RINGBUFFER_DESC_COUNT );
61
62
}
@@ -74,11 +75,11 @@ static inline int ring_full(ring_buffer_t *ring)
74
75
75
76
/**
76
77
* Notify the other user of changes to the shared ring buffers.
77
- *
78
+ *
78
79
* @param ring the ring handle used.
79
80
*
80
81
*/
81
- static inline void notify (ring_handle_t * ring )
82
+ static inline void notify (ring_handle_t * ring )
82
83
{
83
84
return ring -> notify ();
84
85
}
@@ -89,15 +90,15 @@ static inline void notify(ring_handle_t *ring)
89
90
* @param ring Ring buffer to enqueue into.
90
91
* @param buffer address into shared memory where data is stored.
91
92
* @param len length of data inside the buffer above.
92
- * @param cookie optional pointer to data required on dequeueing.
93
+ * @param cookie optional pointer to data required on dequeueing.
93
94
*
94
95
* @return -1 when ring is empty, 0 on success.
95
96
*/
96
- static inline int enqueue (ring_buffer_t * ring , uintptr_t buffer , unsigned int len , void * cookie )
97
+ static inline int enqueue (ring_buffer_t * ring , uintptr_t buffer , unsigned int len , void * cookie )
97
98
{
98
99
if (ring_full (ring )) {
99
100
ZF_LOGE ("Ring full" );
100
- return -1 ;
101
+ return -1 ;
101
102
}
102
103
103
104
ring -> buffers [ring -> write_idx % CONFIG_LIB_SHARED_RINGBUFFER_DESC_COUNT ].encoded_addr = buffer ;
@@ -116,11 +117,11 @@ static inline int enqueue(ring_buffer_t *ring, uintptr_t buffer, unsigned int le
116
117
* @param ring Ring buffer to Dequeue from.
117
118
* @param buffer pointer to the address of where to store buffer address.
118
119
* @param len pointer to variable to store length of data dequeueing.
119
- * @param cookie pointer optional pointer to data required on dequeueing.
120
+ * @param cookie pointer optional pointer to data required on dequeueing.
120
121
*
121
122
* @return -1 when ring is empty, 0 on success.
122
123
*/
123
- static inline int dequeue (ring_buffer_t * ring , uintptr_t * addr , unsigned int * len , void * * cookie )
124
+ static inline int dequeue (ring_buffer_t * ring , uintptr_t * addr , unsigned int * len , void * * cookie )
124
125
{
125
126
if (ring_empty (ring )) {
126
127
ZF_LOGF ("Ring is empty" );
@@ -139,16 +140,16 @@ static inline int dequeue(ring_buffer_t *ring, uintptr_t *addr, unsigned int *le
139
140
140
141
/**
141
142
* Enqueue an element into an available ring buffer.
142
- * This indicates the buffer address parameter is currently available for use.
143
+ * This indicates the buffer address parameter is currently available for use.
143
144
*
144
145
* @param ring Ring handle to enqueue into.
145
146
* @param buffer address into shared memory where data is stored.
146
147
* @param len length of data inside the buffer above.
147
- * @param cookie optional pointer to data required on dequeueing.
148
+ * @param cookie optional pointer to data required on dequeueing.
148
149
*
149
150
* @return -1 when ring is empty, 0 on success.
150
151
*/
151
- static inline int enqueue_avail (ring_handle_t * ring , uintptr_t addr , unsigned int len , void * cookie )
152
+ static inline int enqueue_avail (ring_handle_t * ring , uintptr_t addr , unsigned int len , void * cookie )
152
153
{
153
154
return enqueue (ring -> avail_ring , addr , len , cookie );
154
155
}
@@ -160,11 +161,11 @@ static inline int enqueue_avail(ring_handle_t *ring, uintptr_t addr, unsigned in
160
161
* @param ring Ring handle to enqueue into.
161
162
* @param buffer address into shared memory where data is stored.
162
163
* @param len length of data inside the buffer above.
163
- * @param cookie optional pointer to data required on dequeueing.
164
+ * @param cookie optional pointer to data required on dequeueing.
164
165
*
165
166
* @return -1 when ring is empty, 0 on success.
166
167
*/
167
- static inline int enqueue_used (ring_handle_t * ring , uintptr_t addr , unsigned int len , void * cookie )
168
+ static inline int enqueue_used (ring_handle_t * ring , uintptr_t addr , unsigned int len , void * cookie )
168
169
{
169
170
return enqueue (ring -> used_ring , addr , len , cookie );
170
171
}
@@ -175,11 +176,11 @@ static inline int enqueue_used(ring_handle_t *ring, uintptr_t addr, unsigned int
175
176
* @param ring Ring handle to dequeue from.
176
177
* @param buffer pointer to the address of where to store buffer address.
177
178
* @param len pointer to variable to store length of data dequeueing.
178
- * @param cookie pointer optional pointer to data required on dequeueing.
179
+ * @param cookie pointer optional pointer to data required on dequeueing.
179
180
*
180
181
* @return -1 when ring is empty, 0 on success.
181
182
*/
182
- static inline int dequeue_avail (ring_handle_t * ring , uintptr_t * addr , unsigned int * len , void * * cookie )
183
+ static inline int dequeue_avail (ring_handle_t * ring , uintptr_t * addr , unsigned int * len , void * * cookie )
183
184
{
184
185
return dequeue (ring -> avail_ring , addr , len , cookie );
185
186
}
@@ -190,19 +191,19 @@ static inline int dequeue_avail(ring_handle_t *ring, uintptr_t *addr, unsigned i
190
191
* @param ring Ring handle to dequeue from.
191
192
* @param buffer pointer to the address of where to store buffer address.
192
193
* @param len pointer to variable to store length of data dequeueing.
193
- * @param cookie pointer optional pointer to data required on dequeueing.
194
+ * @param cookie pointer optional pointer to data required on dequeueing.
194
195
*
195
196
* @return -1 when ring is empty, 0 on success.
196
197
*/
197
- static inline int dequeue_used (ring_handle_t * ring , uintptr_t * addr , unsigned int * len , void * * cookie )
198
+ static inline int dequeue_used (ring_handle_t * ring , uintptr_t * addr , unsigned int * len , void * * cookie )
198
199
{
199
200
return dequeue (ring -> used_ring , addr , len , cookie );
200
201
}
201
202
202
203
/**
203
204
* Dequeue an element from a ring buffer.
204
205
* This function is intended for use by the driver, to collect a pointer
205
- * into this structure to be passed around as a cookie.
206
+ * into this structure to be passed around as a cookie.
206
207
*
207
208
* @param ring Ring buffer to dequeue from.
208
209
* @param addr pointer to the address of where to store buffer address.
@@ -211,7 +212,6 @@ static inline int dequeue_used(ring_handle_t *ring, uintptr_t *addr, unsigned in
211
212
*
212
213
* @return -1 when ring is empty, 0 on success.
213
214
*/
214
-
215
215
static int driver_dequeue (ring_buffer_t * ring , uintptr_t * addr , unsigned int * len , void * * cookie )
216
216
{
217
217
if (!((ring -> write_idx - ring -> read_idx ) % CONFIG_LIB_SHARED_RINGBUFFER_DESC_COUNT )) {
@@ -228,4 +228,4 @@ static int driver_dequeue(ring_buffer_t *ring, uintptr_t *addr, unsigned int *le
228
228
ring -> read_idx ++ ;
229
229
230
230
return 0 ;
231
- }
231
+ }
0 commit comments