12 #include <gpxe/list.h>
15 * I/O buffer alignment
17 * I/O buffers allocated via alloc_iob() are guaranteed to be
18 * physically aligned to this boundary. Some cards cannot DMA across
19 * a 4kB boundary. With a standard Ethernet MTU, aligning to a 2kB
20 * boundary is sufficient to guarantee no 4kB boundary crossings. For
21 * a jumbo Ethernet MTU, a packet may be larger than 4kB anyway.
23 #define IOB_ALIGN 2048
26 * Minimum I/O buffer length
28 * alloc_iob() will round up the allocated length to this size if
29 * necessary. This is used on behalf of hardware that is not capable
35 * A persistent I/O buffer
37 * This data structure encapsulates a long-lived I/O buffer. The
38 * buffer may be passed between multiple owners, queued for possible
39 * retransmission, etc.
42 /** List of which this buffer is a member
44 * The list must belong to the current owner of the buffer.
45 * Different owners may maintain different lists (e.g. a
46 * retransmission list for TCP).
48 struct list_head list;
50 /** Start of the buffer */
56 /** End of the buffer */
61 * Reserve space at start of I/O buffer
64 * @v len Length to reserve
65 * @ret data Pointer to new start of buffer
67 static inline void * iob_reserve ( struct io_buffer *iobuf, size_t len ) {
70 assert ( iobuf->tail <= iobuf->end );
75 * Add data to start of I/O buffer
78 * @v len Length to add
79 * @ret data Pointer to new start of buffer
81 static inline void * iob_push ( struct io_buffer *iobuf, size_t len ) {
83 assert ( iobuf->data >= iobuf->head );
88 * Remove data from start of I/O buffer
91 * @v len Length to remove
92 * @ret data Pointer to new start of buffer
94 static inline void * iob_pull ( struct io_buffer *iobuf, size_t len ) {
96 assert ( iobuf->data <= iobuf->tail );
101 * Add data to end of I/O buffer
103 * @v iobuf I/O buffer
104 * @v len Length to add
105 * @ret data Pointer to newly added space
107 static inline void * iob_put ( struct io_buffer *iobuf, size_t len ) {
108 void *old_tail = iobuf->tail;
110 assert ( iobuf->tail <= iobuf->end );
115 * Remove data from end of I/O buffer
117 * @v iobuf I/O buffer
118 * @v len Length to remove
120 static inline void iob_unput ( struct io_buffer *iobuf, size_t len ) {
122 assert ( iobuf->tail >= iobuf->data );
126 * Empty an I/O buffer
128 * @v iobuf I/O buffer
130 static inline void iob_empty ( struct io_buffer *iobuf ) {
131 iobuf->tail = iobuf->data;
135 * Calculate length of data in an I/O buffer
137 * @v iobuf I/O buffer
138 * @ret len Length of data in buffer
140 static inline size_t iob_len ( struct io_buffer *iobuf ) {
141 return ( iobuf->tail - iobuf->data );
145 * Calculate available space at start of an I/O buffer
147 * @v iobuf I/O buffer
148 * @ret len Length of data available at start of buffer
150 static inline size_t iob_headroom ( struct io_buffer *iobuf ) {
151 return ( iobuf->data - iobuf->head );
155 * Calculate available space at end of an I/O buffer
157 * @v iobuf I/O buffer
158 * @ret len Length of data available at end of buffer
160 static inline size_t iob_tailroom ( struct io_buffer *iobuf ) {
161 return ( iobuf->end - iobuf->tail );
164 extern struct io_buffer * alloc_iob ( size_t len );
165 extern void free_iob ( struct io_buffer *iobuf );
166 extern void iob_pad ( struct io_buffer *iobuf, size_t min_len );
168 #endif /* _GPXE_IOBUF_H */