36#include <sys/kernel.h>
63#define TTYOUTQ_INSERT_TAIL(to, tob) do { \
64 if (to->to_end == 0) { \
65 tob->tob_next = to->to_firstblock; \
66 to->to_firstblock = tob; \
68 tob->tob_next = to->to_lastblock->tob_next; \
69 to->to_lastblock->tob_next = tob; \
74#define TTYOUTQ_REMOVE_HEAD(to) do { \
75 to->to_firstblock = to->to_firstblock->tob_next; \
79#define TTYOUTQ_RECYCLE(to, tob) do { \
80 if (to->to_quota <= to->to_nblocks) \
81 uma_zfree(ttyoutq_zone, tob); \
83 TTYOUTQ_INSERT_TAIL(to, tob); \
99 to->to_quota = howmany(size, TTYOUTQ_DATASIZE);
101 while (to->to_quota > to->to_nblocks) {
134 while ((tob = to->to_firstblock) != NULL) {
139 MPASS(to->to_nblocks == 0);
149 size_t cbegin, cend, clen;
152 if (to->to_begin == to->to_end)
154 tob = to->to_firstblock;
164 cbegin = to->to_begin;
165 cend = MIN(MIN(to->to_end, to->to_begin + len),
167 clen = cend - cbegin;
170 memcpy(cbuf, tob->
tob_data + cbegin, clen);
174 if (cend == to->to_end) {
178 }
else if (cend == TTYOUTQ_DATASIZE) {
182 to->to_end -= TTYOUTQ_DATASIZE;
186 to->to_begin += clen;
190 return (cbuf - (
char *)
buf);
207 while (uio->uio_resid > 0) {
210 size_t cbegin, cend, clen;
213 if (to->to_begin == to->to_end)
215 tob = to->to_firstblock;
225 cbegin = to->to_begin;
226 cend = MIN(MIN(to->to_end, to->to_begin + uio->uio_resid),
228 clen = cend - cbegin;
237 if (cend == TTYOUTQ_DATASIZE || cend == to->to_end) {
244 if (to->to_end <= TTYOUTQ_DATASIZE)
247 to->to_end -= TTYOUTQ_DATASIZE;
257 char ob[TTYOUTQ_DATASIZE - 1];
262 memcpy(ob, tob->
tob_data + cbegin, clen);
263 to->to_begin += clen;
264 MPASS(to->to_begin < TTYOUTQ_DATASIZE);
268 error =
uiomove(ob, clen, uio);
282 const char *cbuf =
buf;
288 boff = to->to_end % TTYOUTQ_DATASIZE;
290 if (to->to_end == 0) {
292 MPASS(to->to_begin == 0);
293 tob = to->to_firstblock;
298 to->to_lastblock = tob;
299 }
else if (boff == 0) {
306 to->to_lastblock = tob;
308 tob = to->to_lastblock;
312 l = MIN(
nbytes, TTYOUTQ_DATASIZE - boff);
314 memcpy(tob->
tob_data + boff, cbuf, l);
321 return (cbuf - (
const char *)
buf);
329 if (ttyoutq_bytesleft(to) <
nbytes)
344 NULL, NULL, NULL, NULL, UMA_ALIGN_PTR, 0);
char tob_data[TTYOUTQ_DATASIZE]
struct ttyoutq_block * tob_next
int uiomove(void *cp, int n, struct uio *uio)
#define TTYOUTQ_RECYCLE(to, tob)
int ttyoutq_write_nofrag(struct ttyoutq *to, const void *buf, size_t nbytes)
static void ttyoutq_startup(void *dummy)
int ttyoutq_read_uio(struct ttyoutq *to, struct tty *tp, struct uio *uio)
size_t ttyoutq_read(struct ttyoutq *to, void *buf, size_t len)
int ttyoutq_setsize(struct ttyoutq *to, struct tty *tp, size_t size)
#define TTYOUTQ_REMOVE_HEAD(to)
static uma_zone_t ttyoutq_zone
SYSINIT(ttyoutq, SI_SUB_DRIVERS, SI_ORDER_FIRST, ttyoutq_startup, NULL)
void ttyoutq_free(struct ttyoutq *to)
#define TTYOUTQ_INSERT_TAIL(to, tob)
void ttyoutq_flush(struct ttyoutq *to)
size_t ttyoutq_write(struct ttyoutq *to, const void *buf, size_t nbytes)