Lines Matching refs:to

49  * bits for parity marking and such. This mechanism is similar to the
50 * old clists, but only contains the features we need to buffer the
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; \
69 to->to_nblocks++; \
72 #define TTYOUTQ_REMOVE_HEAD(to) do { \
73 to->to_firstblock = to->to_firstblock->tob_next; \
74 to->to_nblocks--; \
77 #define TTYOUTQ_RECYCLE(to, tob) do { \
78 if (to->to_quota <= to->to_nblocks) \
81 TTYOUTQ_INSERT_TAIL(to, tob); \
85 ttyoutq_flush(struct ttyoutq *to)
88 to->to_begin = 0;
89 to->to_end = 0;
93 ttyoutq_setsize(struct ttyoutq *to, struct tty *tp, size_t size)
97 to->to_quota = howmany(size, TTYOUTQ_DATASIZE);
99 while (to->to_quota > to->to_nblocks) {
102 * Add new blocks to the tail of the list.
105 * to allocate memory. This won't be a problem, because
107 * may cause us to allocate too many blocks, but this
114 TTYOUTQ_INSERT_TAIL(to, tob);
119 ttyoutq_free(struct ttyoutq *to)
123 ttyoutq_flush(to);
124 to->to_quota = 0;
126 while ((tob = to->to_firstblock) != NULL) {
127 TTYOUTQ_REMOVE_HEAD(to);
131 MPASS(to->to_nblocks == 0);
135 ttyoutq_read(struct ttyoutq *to, void *buf, size_t len)
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),
166 if (cend == to->to_end) {
168 to->to_begin = 0;
169 to->to_end = 0;
172 TTYOUTQ_REMOVE_HEAD(to);
173 to->to_begin = 0;
174 to->to_end -= TTYOUTQ_DATASIZE;
175 TTYOUTQ_RECYCLE(to, tob);
178 to->to_begin += clen;
187 * TTY drivers to directly copy data from the outq to userspace, instead
190 * We can only copy data directly if we need to read the entire block
191 * back to the user, because we temporarily remove the block from the
192 * queue. Otherwise we need to copy it to a temporary buffer first, to
196 ttyoutq_read_uio(struct ttyoutq *to, struct tty *tp, struct uio *uio)
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),
224 * - We need to read the block until the end.
225 * - We don't need to read the block until the end, but
226 * there is no data beyond it, which allows us to move
227 * the write pointer to a new block.
229 if (cend == TTYOUTQ_DATASIZE || cend == to->to_end) {
234 TTYOUTQ_REMOVE_HEAD(to);
235 to->to_begin = 0;
236 if (to->to_end <= TTYOUTQ_DATASIZE)
237 to->to_end = 0;
239 to->to_end -= TTYOUTQ_DATASIZE;
241 /* Temporary unlock and copy the data to userspace. */
246 /* Block can now be readded to the list. */
247 TTYOUTQ_RECYCLE(to, tob);
255 to->to_begin += clen;
256 MPASS(to->to_begin < TTYOUTQ_DATASIZE);
258 /* Temporary unlock and copy the data to userspace. */
272 ttyoutq_write(struct ttyoutq *to, const void *buf, size_t nbytes)
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;
293 tob = to->to_lastblock->tob_next;
298 to->to_lastblock = tob;
300 tob = to->to_lastblock;
310 to->to_end += l;
317 ttyoutq_write_nofrag(struct ttyoutq *to, const void *buf, size_t nbytes)
321 if (ttyoutq_bytesleft(to) < nbytes)
324 /* We should always be able to write it back. */
325 ret = ttyoutq_write(to, buf, nbytes);