30 #include <sys/cdefs.h>
33 #include <sys/param.h>
34 #include <sys/kernel.h>
36 #include <sys/queue.h>
37 #include <sys/systm.h>
61 #define TTYOUTQ_INSERT_TAIL(to, tob) do { \
62 if (to->to_end == 0) { \
63 tob->tob_next = to->to_firstblock; \
64 to->to_firstblock = tob; \
66 tob->tob_next = to->to_lastblock->tob_next; \
67 to->to_lastblock->tob_next = tob; \
72 #define TTYOUTQ_REMOVE_HEAD(to) do { \
73 to->to_firstblock = to->to_firstblock->tob_next; \
77 #define TTYOUTQ_RECYCLE(to, tob) do { \
78 if (to->to_quota <= to->to_nblocks) \
79 uma_zfree(ttyoutq_zone, tob); \
81 TTYOUTQ_INSERT_TAIL(to, tob); \
97 to->to_quota = howmany(size, TTYOUTQ_DATASIZE);
99 while (to->to_quota > to->to_nblocks) {
126 while ((tob = to->to_firstblock) != NULL) {
131 MPASS(to->to_nblocks == 0);
141 size_t cbegin, cend, clen;
144 if (to->to_begin == to->to_end)
146 tob = to->to_firstblock;
156 cbegin = to->to_begin;
157 cend = MIN(MIN(to->to_end, to->to_begin + len),
159 clen = cend - cbegin;
162 memcpy(cbuf, tob->
tob_data + cbegin, clen);
166 if (cend == to->to_end) {
170 }
else if (cend == TTYOUTQ_DATASIZE) {
174 to->to_end -= TTYOUTQ_DATASIZE;
178 to->to_begin += clen;
182 return (cbuf - (
char *)buf);
199 while (uio->uio_resid > 0) {
202 size_t cbegin, cend, clen;
205 if (to->to_begin == to->to_end)
207 tob = to->to_firstblock;
217 cbegin = to->to_begin;
218 cend = MIN(MIN(to->to_end, to->to_begin + uio->uio_resid),
220 clen = cend - cbegin;
229 if (cend == TTYOUTQ_DATASIZE || cend == to->to_end) {
236 if (to->to_end <= TTYOUTQ_DATASIZE)
239 to->to_end -= TTYOUTQ_DATASIZE;
249 char ob[TTYOUTQ_DATASIZE - 1];
254 memcpy(ob, tob->
tob_data + cbegin, clen);
255 to->to_begin += clen;
256 MPASS(to->to_begin < TTYOUTQ_DATASIZE);
260 error =
uiomove(ob, clen, uio);
274 const char *cbuf =
buf;
280 boff = to->to_end % TTYOUTQ_DATASIZE;
282 if (to->to_end == 0) {
284 MPASS(to->to_begin == 0);
285 tob = to->to_firstblock;
290 to->to_lastblock = tob;
291 }
else if (boff == 0) {
298 to->to_lastblock = tob;
300 tob = to->to_lastblock;
304 l = MIN(nbytes, TTYOUTQ_DATASIZE - boff);
306 memcpy(tob->
tob_data + boff, cbuf, l);
313 return (cbuf - (
const char *)buf);
321 if (ttyoutq_bytesleft(to) < nbytes)
326 MPASS(ret == nbytes);
336 NULL, NULL, NULL, NULL, UMA_ALIGN_PTR, 0);
SYSINIT(ttyoutq, SI_SUB_DRIVERS, SI_ORDER_FIRST, ttyoutq_startup, NULL)
void ttyoutq_free(struct ttyoutq *to)
size_t ttyoutq_write(struct ttyoutq *to, const void *buf, size_t nbytes)
#define TTYOUTQ_REMOVE_HEAD(to)
static uma_zone_t ttyoutq_zone
void ttyoutq_setsize(struct ttyoutq *to, struct tty *tp, size_t size)
static void ttyoutq_startup(void *dummy)
char tob_data[TTYOUTQ_DATASIZE]
size_t ttyoutq_read(struct ttyoutq *to, void *buf, size_t len)
int ttyoutq_read_uio(struct ttyoutq *to, struct tty *tp, struct uio *uio)
int uiomove(void *cp, int n, struct uio *uio)
void ttyoutq_flush(struct ttyoutq *to)
struct ttyoutq_block * tob_next
#define TTYOUTQ_RECYCLE(to, tob)
int ttyoutq_write_nofrag(struct ttyoutq *to, const void *buf, size_t nbytes)
#define TTYOUTQ_INSERT_TAIL(to, tob)