6 /* All fields are private */
15 * @fifo: struct Fifo8 to initialise with new FIFO
16 * @capacity: capacity of the newly created FIFO
18 * Create a FIFO of the specified size. Clients should call fifo8_destroy()
19 * when finished using the fifo. The FIFO is initially empty.
22 void fifo8_create(Fifo8
*fifo
, uint32_t capacity
);
26 * @fifo: FIFO to cleanup
28 * Cleanup a FIFO created with fifo8_create(). Frees memory created for FIFO
29 *storage. The FIFO is no longer usable after this has been called.
32 void fifo8_destroy(Fifo8
*fifo
);
36 * @fifo: FIFO to push to
37 * @data: data byte to push
39 * Push a data byte to the FIFO. Behaviour is undefined if the FIFO is full.
40 * Clients are responsible for checking for fullness using fifo8_is_full().
43 void fifo8_push(Fifo8
*fifo
, uint8_t data
);
47 * @fifo: FIFO to push to
49 * @num: number of bytes to push
51 * Push a byte array to the FIFO. Behaviour is undefined if the FIFO is full.
52 * Clients are responsible for checking the space left in the FIFO using
56 void fifo8_push_all(Fifo8
*fifo
, const uint8_t *data
, uint32_t num
);
60 * @fifo: fifo to pop from
62 * Pop a data byte from the FIFO. Behaviour is undefined if the FIFO is empty.
63 * Clients are responsible for checking for emptyness using fifo8_is_empty().
65 * Returns: The popped data byte.
68 uint8_t fifo8_pop(Fifo8
*fifo
);
72 * @fifo: FIFO to pop from
73 * @max: maximum number of bytes to pop
74 * @numptr: pointer filled with number of bytes returned (can be NULL)
76 * Pop a number of elements from the FIFO up to a maximum of max. The buffer
77 * containing the popped data is returned. This buffer points directly into
78 * the FIFO backing store and data is invalidated once any of the fifo8_* APIs
79 * are called on the FIFO.
81 * The function may return fewer bytes than requested when the data wraps
82 * around in the ring buffer; in this case only a contiguous part of the data
85 * The number of valid bytes returned is populated in *numptr; will always
86 * return at least 1 byte. max must not be 0 or greater than the number of
89 * Clients are responsible for checking the availability of requested data
90 * using fifo8_num_used().
92 * Returns: A pointer to popped data.
94 const uint8_t *fifo8_pop_buf(Fifo8
*fifo
, uint32_t max
, uint32_t *numptr
);
97 * fifo8_peek_buf: read upto max bytes from the fifo
98 * @fifo: FIFO to read from
99 * @max: maximum number of bytes to peek
100 * @numptr: pointer filled with number of bytes returned (can be NULL)
102 * Peek into a number of elements from the FIFO up to a maximum of max.
103 * The buffer containing the data peeked into is returned. This buffer points
104 * directly into the FIFO backing store. Since data is invalidated once any
105 * of the fifo8_* APIs are called on the FIFO, it is the caller responsibility
106 * to access it before doing further API calls.
108 * The function may return fewer bytes than requested when the data wraps
109 * around in the ring buffer; in this case only a contiguous part of the data
112 * The number of valid bytes returned is populated in *numptr; will always
113 * return at least 1 byte. max must not be 0 or greater than the number of
116 * Clients are responsible for checking the availability of requested data
117 * using fifo8_num_used().
119 * Returns: A pointer to peekable data.
121 const uint8_t *fifo8_peek_buf(Fifo8
*fifo
, uint32_t max
, uint32_t *numptr
);
125 * @fifo: FIFO to reset
127 * Reset a FIFO. All data is discarded and the FIFO is emptied.
130 void fifo8_reset(Fifo8
*fifo
);
134 * @fifo: FIFO to check
136 * Check if a FIFO is empty.
138 * Returns: True if the fifo is empty, false otherwise.
141 bool fifo8_is_empty(Fifo8
*fifo
);
145 * @fifo: FIFO to check
147 * Check if a FIFO is full.
149 * Returns: True if the fifo is full, false otherwise.
152 bool fifo8_is_full(Fifo8
*fifo
);
156 * @fifo: FIFO to check
158 * Return the number of free bytes in the FIFO.
160 * Returns: Number of free bytes.
163 uint32_t fifo8_num_free(Fifo8
*fifo
);
167 * @fifo: FIFO to check
169 * Return the number of used bytes in the FIFO.
171 * Returns: Number of used bytes.
174 uint32_t fifo8_num_used(Fifo8
*fifo
);
176 extern const VMStateDescription vmstate_fifo8
;
178 #define VMSTATE_FIFO8_TEST(_field, _state, _test) { \
179 .name = (stringify(_field)), \
180 .field_exists = (_test), \
181 .size = sizeof(Fifo8), \
182 .vmsd = &vmstate_fifo8, \
183 .flags = VMS_STRUCT, \
184 .offset = vmstate_offset_value(_state, _field, Fifo8), \
187 #define VMSTATE_FIFO8(_field, _state) \
188 VMSTATE_FIFO8_TEST(_field, _state, NULL)
190 #endif /* QEMU_FIFO8_H */