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 * @size: 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 * @num: actual number of returned bytes
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 *num; will always return
86 * at least 1 byte. max must not be 0 or greater than the number of bytes in
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 *num
);
98 * @fifo: FIFO to reset
100 * Reset a FIFO. All data is discarded and the FIFO is emptied.
103 void fifo8_reset(Fifo8
*fifo
);
107 * @fifo: FIFO to check
109 * Check if a FIFO is empty.
111 * Returns: True if the fifo is empty, false otherwise.
114 bool fifo8_is_empty(Fifo8
*fifo
);
118 * @fifo: FIFO to check
120 * Check if a FIFO is full.
122 * Returns: True if the fifo is full, false otherwise.
125 bool fifo8_is_full(Fifo8
*fifo
);
129 * @fifo: FIFO to check
131 * Return the number of free bytes in the FIFO.
133 * Returns: Number of free bytes.
136 uint32_t fifo8_num_free(Fifo8
*fifo
);
140 * @fifo: FIFO to check
142 * Return the number of used bytes in the FIFO.
144 * Returns: Number of used bytes.
147 uint32_t fifo8_num_used(Fifo8
*fifo
);
149 extern const VMStateDescription vmstate_fifo8
;
151 #define VMSTATE_FIFO8_TEST(_field, _state, _test) { \
152 .name = (stringify(_field)), \
153 .field_exists = (_test), \
154 .size = sizeof(Fifo8), \
155 .vmsd = &vmstate_fifo8, \
156 .flags = VMS_STRUCT, \
157 .offset = vmstate_offset_value(_state, _field, Fifo8), \
160 #define VMSTATE_FIFO8(_field, _state) \
161 VMSTATE_FIFO8_TEST(_field, _state, NULL)
163 #endif /* QEMU_FIFO8_H */