5 #include <linux/types.h>
6 #include <linux/errno.h>
11 #include <linux/string.h>
12 #include <linux/slab.h>
13 #include <linux/sched.h>
15 #include <linux/wait.h>
16 #include <linux/bitops.h>
18 #include <linux/module.h>
33 while ((thead = tty->
buf.head) !=
NULL) {
37 while ((thead = tty->
buf.free) !=
NULL) {
42 tty->
buf.memory_used = 0;
61 if (tty->
buf.memory_used + size > 65536)
73 tty->
buf.memory_used += size;
91 tty->
buf.memory_used -= b->
size;
113 static void __tty_buffer_flush(
struct tty_struct *tty)
117 while ((thead = tty->
buf.head) !=
NULL) {
119 tty_buffer_free(tty, thead);
145 spin_unlock_irqrestore(&tty->
buf.lock, flags);
150 __tty_buffer_flush(tty);
151 spin_unlock_irqrestore(&tty->
buf.lock, flags);
169 while ((*tbh) !=
NULL) {
171 if (t->
size >= size) {
177 tty->
buf.memory_used += t->
size;
180 tbh = &((*tbh)->next);
183 size = (size + 0xFF) & ~0xFF;
184 return tty_buffer_alloc(tty, size);
197 static int __tty_buffer_request_room(
struct tty_struct *tty,
size_t size)
204 if ((b = tty->
buf.tail) !=
NULL)
211 if ((n = tty_buffer_find(tty, size)) !=
NULL) {
242 length = __tty_buffer_request_room(tty, size);
243 spin_unlock_irqrestore(&tty->
buf.lock, flags);
262 const unsigned char *chars,
char flag,
size_t size)
272 space = __tty_buffer_request_room(tty, goal);
276 spin_unlock_irqrestore(&tty->
buf.lock, flags);
282 spin_unlock_irqrestore(&tty->
buf.lock, flags);
307 const unsigned char *chars,
const char *
flags,
size_t size)
313 unsigned long __flags;
317 space = __tty_buffer_request_room(tty, goal);
321 spin_unlock_irqrestore(&tty->
buf.lock, __flags);
327 spin_unlock_irqrestore(&tty->
buf.lock, __flags);
354 tty->
buf.tail->commit = tty->
buf.tail->used;
355 spin_unlock_irqrestore(&tty->
buf.lock, flags);
383 space = __tty_buffer_request_room(tty, size);
391 spin_unlock_irqrestore(&tty->
buf.lock, flags);
413 unsigned char **chars,
char **
flags,
size_t size)
416 unsigned long __flags;
420 space = __tty_buffer_request_room(tty, size);
428 spin_unlock_irqrestore(&tty->
buf.lock, __flags);
462 while ((head = tty->
buf.head) !=
NULL) {
465 unsigned char *flag_buf;
472 tty_buffer_free(tty, head);
487 spin_unlock_irqrestore(&tty->
buf.lock, flags);
488 disc->
ops->receive_buf(tty, char_buf,
498 __tty_buffer_flush(tty);
502 spin_unlock_irqrestore(&tty->
buf.lock, flags);
538 tty->
buf.tail->commit = tty->
buf.tail->used;
539 spin_unlock_irqrestore(&tty->
buf.lock, flags);
542 flush_to_ldisc(&tty->
buf.work);
564 tty->
buf.memory_used = 0;