blob: 6f366f257fba758aecd95ca2d4dfb3898d0887bf [file] [log] [blame]
Alan Coxe0495732008-10-13 10:36:58 +01001/*
2 * Tty buffer allocation management
3 */
4
5#include <linux/types.h>
6#include <linux/errno.h>
7#include <linux/tty.h>
8#include <linux/tty_driver.h>
9#include <linux/tty_flip.h>
10#include <linux/timer.h>
11#include <linux/string.h>
12#include <linux/slab.h>
13#include <linux/sched.h>
14#include <linux/init.h>
15#include <linux/wait.h>
16#include <linux/bitops.h>
17#include <linux/delay.h>
18#include <linux/module.h>
19
20/**
21 * tty_buffer_free_all - free buffers used by a tty
22 * @tty: tty to free from
23 *
24 * Remove all the buffers pending on a tty whether queued with data
25 * or in the free ring. Must be called when the tty is no longer in use
26 *
27 * Locking: none
28 */
29
30void tty_buffer_free_all(struct tty_struct *tty)
31{
32 struct tty_buffer *thead;
33 while ((thead = tty->buf.head) != NULL) {
34 tty->buf.head = thead->next;
35 kfree(thead);
36 }
37 while ((thead = tty->buf.free) != NULL) {
38 tty->buf.free = thead->next;
39 kfree(thead);
40 }
41 tty->buf.tail = NULL;
42 tty->buf.memory_used = 0;
43}
44
45/**
46 * tty_buffer_alloc - allocate a tty buffer
47 * @tty: tty device
48 * @size: desired size (characters)
49 *
50 * Allocate a new tty buffer to hold the desired number of characters.
51 * Return NULL if out of memory or the allocation would exceed the
52 * per device queue
53 *
54 * Locking: Caller must hold tty->buf.lock
55 */
56
57static struct tty_buffer *tty_buffer_alloc(struct tty_struct *tty, size_t size)
58{
59 struct tty_buffer *p;
60
61 if (tty->buf.memory_used + size > 65536)
62 return NULL;
63 p = kmalloc(sizeof(struct tty_buffer) + 2 * size, GFP_ATOMIC);
64 if (p == NULL)
65 return NULL;
66 p->used = 0;
67 p->size = size;
68 p->next = NULL;
69 p->commit = 0;
70 p->read = 0;
71 p->char_buf_ptr = (char *)(p->data);
72 p->flag_buf_ptr = (unsigned char *)p->char_buf_ptr + size;
73 tty->buf.memory_used += size;
74 return p;
75}
76
77/**
78 * tty_buffer_free - free a tty buffer
79 * @tty: tty owning the buffer
80 * @b: the buffer to free
81 *
82 * Free a tty buffer, or add it to the free list according to our
83 * internal strategy
84 *
85 * Locking: Caller must hold tty->buf.lock
86 */
87
88static void tty_buffer_free(struct tty_struct *tty, struct tty_buffer *b)
89{
90 /* Dumb strategy for now - should keep some stats */
91 tty->buf.memory_used -= b->size;
92 WARN_ON(tty->buf.memory_used < 0);
93
94 if (b->size >= 512)
95 kfree(b);
96 else {
97 b->next = tty->buf.free;
98 tty->buf.free = b;
99 }
100}
101
102/**
103 * __tty_buffer_flush - flush full tty buffers
104 * @tty: tty to flush
105 *
106 * flush all the buffers containing receive data. Caller must
107 * hold the buffer lock and must have ensured no parallel flush to
108 * ldisc is running.
109 *
110 * Locking: Caller must hold tty->buf.lock
111 */
112
113static void __tty_buffer_flush(struct tty_struct *tty)
114{
115 struct tty_buffer *thead;
116
117 while ((thead = tty->buf.head) != NULL) {
118 tty->buf.head = thead->next;
119 tty_buffer_free(tty, thead);
120 }
121 tty->buf.tail = NULL;
122}
123
124/**
125 * tty_buffer_flush - flush full tty buffers
126 * @tty: tty to flush
127 *
128 * flush all the buffers containing receive data. If the buffer is
129 * being processed by flush_to_ldisc then we defer the processing
130 * to that function
131 *
132 * Locking: none
133 */
134
135void tty_buffer_flush(struct tty_struct *tty)
136{
Jiri Slaby2fc20662012-10-18 22:26:44 +0200137 struct tty_port *port = tty->port;
Alan Coxe0495732008-10-13 10:36:58 +0100138 unsigned long flags;
139 spin_lock_irqsave(&tty->buf.lock, flags);
140
141 /* If the data is being pushed to the tty layer then we can't
142 process it here. Instead set a flag and the flush_to_ldisc
143 path will process the flush request before it exits */
Jiri Slaby2fc20662012-10-18 22:26:44 +0200144 if (test_bit(TTYP_FLUSHING, &port->iflags)) {
145 set_bit(TTYP_FLUSHPENDING, &port->iflags);
Alan Coxe0495732008-10-13 10:36:58 +0100146 spin_unlock_irqrestore(&tty->buf.lock, flags);
147 wait_event(tty->read_wait,
Jiri Slaby2fc20662012-10-18 22:26:44 +0200148 test_bit(TTYP_FLUSHPENDING, &port->iflags) == 0);
Alan Coxe0495732008-10-13 10:36:58 +0100149 return;
150 } else
151 __tty_buffer_flush(tty);
152 spin_unlock_irqrestore(&tty->buf.lock, flags);
153}
154
155/**
156 * tty_buffer_find - find a free tty buffer
157 * @tty: tty owning the buffer
158 * @size: characters wanted
159 *
160 * Locate an existing suitable tty buffer or if we are lacking one then
161 * allocate a new one. We round our buffers off in 256 character chunks
162 * to get better allocation behaviour.
163 *
164 * Locking: Caller must hold tty->buf.lock
165 */
166
167static struct tty_buffer *tty_buffer_find(struct tty_struct *tty, size_t size)
168{
169 struct tty_buffer **tbh = &tty->buf.free;
170 while ((*tbh) != NULL) {
171 struct tty_buffer *t = *tbh;
172 if (t->size >= size) {
173 *tbh = t->next;
174 t->next = NULL;
175 t->used = 0;
176 t->commit = 0;
177 t->read = 0;
178 tty->buf.memory_used += t->size;
179 return t;
180 }
181 tbh = &((*tbh)->next);
182 }
183 /* Round the buffer size out */
184 size = (size + 0xFF) & ~0xFF;
185 return tty_buffer_alloc(tty, size);
186 /* Should possibly check if this fails for the largest buffer we
187 have queued and recycle that ? */
188}
Alan Coxe0495732008-10-13 10:36:58 +0100189/**
Xiaobing Tuc56a00a2012-03-16 03:00:26 +0000190 * __tty_buffer_request_room - grow tty buffer if needed
Alan Coxe0495732008-10-13 10:36:58 +0100191 * @tty: tty structure
192 * @size: size desired
193 *
194 * Make at least size bytes of linear space available for the tty
195 * buffer. If we fail return the size we managed to find.
Xiaobing Tuc56a00a2012-03-16 03:00:26 +0000196 * Locking: Caller must hold tty->buf.lock
Alan Coxe0495732008-10-13 10:36:58 +0100197 */
Xiaobing Tuc56a00a2012-03-16 03:00:26 +0000198static int __tty_buffer_request_room(struct tty_struct *tty, size_t size)
Alan Coxe0495732008-10-13 10:36:58 +0100199{
200 struct tty_buffer *b, *n;
201 int left;
Alan Coxe0495732008-10-13 10:36:58 +0100202 /* OPTIMISATION: We could keep a per tty "zero" sized buffer to
203 remove this conditional if its worth it. This would be invisible
204 to the callers */
205 if ((b = tty->buf.tail) != NULL)
206 left = b->size - b->used;
207 else
208 left = 0;
209
210 if (left < size) {
211 /* This is the slow path - looking for new buffers to use */
212 if ((n = tty_buffer_find(tty, size)) != NULL) {
213 if (b != NULL) {
214 b->next = n;
215 b->commit = b->used;
216 } else
217 tty->buf.head = n;
218 tty->buf.tail = n;
219 } else
220 size = left;
221 }
222
Alan Coxe0495732008-10-13 10:36:58 +0100223 return size;
224}
Xiaobing Tuc56a00a2012-03-16 03:00:26 +0000225
226
227/**
228 * tty_buffer_request_room - grow tty buffer if needed
229 * @tty: tty structure
230 * @size: size desired
231 *
232 * Make at least size bytes of linear space available for the tty
233 * buffer. If we fail return the size we managed to find.
234 *
235 * Locking: Takes tty->buf.lock
236 */
237int tty_buffer_request_room(struct tty_struct *tty, size_t size)
238{
239 unsigned long flags;
240 int length;
241
242 spin_lock_irqsave(&tty->buf.lock, flags);
243 length = __tty_buffer_request_room(tty, size);
244 spin_unlock_irqrestore(&tty->buf.lock, flags);
245 return length;
246}
Alan Coxe0495732008-10-13 10:36:58 +0100247EXPORT_SYMBOL_GPL(tty_buffer_request_room);
248
249/**
Alan Cox2832fc12010-02-18 16:43:54 +0000250 * tty_insert_flip_string_fixed_flag - Add characters to the tty buffer
Alan Coxe0495732008-10-13 10:36:58 +0100251 * @tty: tty structure
252 * @chars: characters
Alan Cox2832fc12010-02-18 16:43:54 +0000253 * @flag: flag value for each character
Alan Coxe0495732008-10-13 10:36:58 +0100254 * @size: size
255 *
256 * Queue a series of bytes to the tty buffering. All the characters
Johan Hovoldccc5ca82010-05-07 19:58:32 +0200257 * passed are marked with the supplied flag. Returns the number added.
Alan Coxe0495732008-10-13 10:36:58 +0100258 *
259 * Locking: Called functions may take tty->buf.lock
260 */
261
Alan Cox2832fc12010-02-18 16:43:54 +0000262int tty_insert_flip_string_fixed_flag(struct tty_struct *tty,
263 const unsigned char *chars, char flag, size_t size)
Alan Coxe0495732008-10-13 10:36:58 +0100264{
265 int copied = 0;
266 do {
Fang Wenqid4bee0a2010-03-09 18:54:28 +0800267 int goal = min_t(size_t, size - copied, TTY_BUFFER_PAGE);
Xiaobing Tuc56a00a2012-03-16 03:00:26 +0000268 int space;
269 unsigned long flags;
270 struct tty_buffer *tb;
271
272 spin_lock_irqsave(&tty->buf.lock, flags);
273 space = __tty_buffer_request_room(tty, goal);
274 tb = tty->buf.tail;
Alan Coxe0495732008-10-13 10:36:58 +0100275 /* If there is no space then tb may be NULL */
Xiaobing Tuc56a00a2012-03-16 03:00:26 +0000276 if (unlikely(space == 0)) {
277 spin_unlock_irqrestore(&tty->buf.lock, flags);
Alan Coxe0495732008-10-13 10:36:58 +0100278 break;
Xiaobing Tuc56a00a2012-03-16 03:00:26 +0000279 }
Alan Coxe0495732008-10-13 10:36:58 +0100280 memcpy(tb->char_buf_ptr + tb->used, chars, space);
Alan Cox2832fc12010-02-18 16:43:54 +0000281 memset(tb->flag_buf_ptr + tb->used, flag, space);
Alan Coxe0495732008-10-13 10:36:58 +0100282 tb->used += space;
Xiaobing Tuc56a00a2012-03-16 03:00:26 +0000283 spin_unlock_irqrestore(&tty->buf.lock, flags);
Alan Coxe0495732008-10-13 10:36:58 +0100284 copied += space;
285 chars += space;
286 /* There is a small chance that we need to split the data over
287 several buffers. If this is the case we must loop */
288 } while (unlikely(size > copied));
289 return copied;
290}
Alan Cox2832fc12010-02-18 16:43:54 +0000291EXPORT_SYMBOL(tty_insert_flip_string_fixed_flag);
Alan Coxe0495732008-10-13 10:36:58 +0100292
293/**
294 * tty_insert_flip_string_flags - Add characters to the tty buffer
295 * @tty: tty structure
296 * @chars: characters
297 * @flags: flag bytes
298 * @size: size
299 *
300 * Queue a series of bytes to the tty buffering. For each character
301 * the flags array indicates the status of the character. Returns the
302 * number added.
303 *
304 * Locking: Called functions may take tty->buf.lock
305 */
306
307int tty_insert_flip_string_flags(struct tty_struct *tty,
308 const unsigned char *chars, const char *flags, size_t size)
309{
310 int copied = 0;
311 do {
Fang Wenqid4bee0a2010-03-09 18:54:28 +0800312 int goal = min_t(size_t, size - copied, TTY_BUFFER_PAGE);
Xiaobing Tuc56a00a2012-03-16 03:00:26 +0000313 int space;
314 unsigned long __flags;
315 struct tty_buffer *tb;
316
317 spin_lock_irqsave(&tty->buf.lock, __flags);
318 space = __tty_buffer_request_room(tty, goal);
319 tb = tty->buf.tail;
Alan Coxe0495732008-10-13 10:36:58 +0100320 /* If there is no space then tb may be NULL */
Xiaobing Tuc56a00a2012-03-16 03:00:26 +0000321 if (unlikely(space == 0)) {
322 spin_unlock_irqrestore(&tty->buf.lock, __flags);
Alan Coxe0495732008-10-13 10:36:58 +0100323 break;
Xiaobing Tuc56a00a2012-03-16 03:00:26 +0000324 }
Alan Coxe0495732008-10-13 10:36:58 +0100325 memcpy(tb->char_buf_ptr + tb->used, chars, space);
326 memcpy(tb->flag_buf_ptr + tb->used, flags, space);
327 tb->used += space;
Xiaobing Tuc56a00a2012-03-16 03:00:26 +0000328 spin_unlock_irqrestore(&tty->buf.lock, __flags);
Alan Coxe0495732008-10-13 10:36:58 +0100329 copied += space;
330 chars += space;
331 flags += space;
332 /* There is a small chance that we need to split the data over
333 several buffers. If this is the case we must loop */
334 } while (unlikely(size > copied));
335 return copied;
336}
337EXPORT_SYMBOL(tty_insert_flip_string_flags);
338
339/**
340 * tty_schedule_flip - push characters to ldisc
341 * @tty: tty to push from
342 *
343 * Takes any pending buffers and transfers their ownership to the
344 * ldisc side of the queue. It then schedules those characters for
345 * processing by the line discipline.
Ivo Siebencee4ad12012-09-27 14:02:05 +0200346 * Note that this function can only be used when the low_latency flag
347 * is unset. Otherwise the workqueue won't be flushed.
Alan Coxe0495732008-10-13 10:36:58 +0100348 *
349 * Locking: Takes tty->buf.lock
350 */
351
352void tty_schedule_flip(struct tty_struct *tty)
353{
354 unsigned long flags;
355 spin_lock_irqsave(&tty->buf.lock, flags);
356 if (tty->buf.tail != NULL)
357 tty->buf.tail->commit = tty->buf.tail->used;
358 spin_unlock_irqrestore(&tty->buf.lock, flags);
Linus Torvaldsf23eb2b2011-03-22 16:17:32 -0700359 schedule_work(&tty->buf.work);
Alan Coxe0495732008-10-13 10:36:58 +0100360}
361EXPORT_SYMBOL(tty_schedule_flip);
362
363/**
364 * tty_prepare_flip_string - make room for characters
365 * @tty: tty
366 * @chars: return pointer for character write area
367 * @size: desired size
368 *
369 * Prepare a block of space in the buffer for data. Returns the length
370 * available and buffer pointer to the space which is now allocated and
371 * accounted for as ready for normal characters. This is used for drivers
372 * that need their own block copy routines into the buffer. There is no
373 * guarantee the buffer is a DMA target!
374 *
375 * Locking: May call functions taking tty->buf.lock
376 */
377
378int tty_prepare_flip_string(struct tty_struct *tty, unsigned char **chars,
379 size_t size)
380{
Xiaobing Tuc56a00a2012-03-16 03:00:26 +0000381 int space;
382 unsigned long flags;
383 struct tty_buffer *tb;
384
385 spin_lock_irqsave(&tty->buf.lock, flags);
386 space = __tty_buffer_request_room(tty, size);
387
388 tb = tty->buf.tail;
Alan Coxe0495732008-10-13 10:36:58 +0100389 if (likely(space)) {
Alan Coxe0495732008-10-13 10:36:58 +0100390 *chars = tb->char_buf_ptr + tb->used;
391 memset(tb->flag_buf_ptr + tb->used, TTY_NORMAL, space);
392 tb->used += space;
393 }
Xiaobing Tuc56a00a2012-03-16 03:00:26 +0000394 spin_unlock_irqrestore(&tty->buf.lock, flags);
Alan Coxe0495732008-10-13 10:36:58 +0100395 return space;
396}
397EXPORT_SYMBOL_GPL(tty_prepare_flip_string);
398
399/**
400 * tty_prepare_flip_string_flags - make room for characters
401 * @tty: tty
402 * @chars: return pointer for character write area
403 * @flags: return pointer for status flag write area
404 * @size: desired size
405 *
406 * Prepare a block of space in the buffer for data. Returns the length
407 * available and buffer pointer to the space which is now allocated and
408 * accounted for as ready for characters. This is used for drivers
409 * that need their own block copy routines into the buffer. There is no
410 * guarantee the buffer is a DMA target!
411 *
412 * Locking: May call functions taking tty->buf.lock
413 */
414
415int tty_prepare_flip_string_flags(struct tty_struct *tty,
416 unsigned char **chars, char **flags, size_t size)
417{
Xiaobing Tuc56a00a2012-03-16 03:00:26 +0000418 int space;
419 unsigned long __flags;
420 struct tty_buffer *tb;
421
422 spin_lock_irqsave(&tty->buf.lock, __flags);
423 space = __tty_buffer_request_room(tty, size);
424
425 tb = tty->buf.tail;
Alan Coxe0495732008-10-13 10:36:58 +0100426 if (likely(space)) {
Alan Coxe0495732008-10-13 10:36:58 +0100427 *chars = tb->char_buf_ptr + tb->used;
428 *flags = tb->flag_buf_ptr + tb->used;
429 tb->used += space;
430 }
Xiaobing Tuc56a00a2012-03-16 03:00:26 +0000431 spin_unlock_irqrestore(&tty->buf.lock, __flags);
Alan Coxe0495732008-10-13 10:36:58 +0100432 return space;
433}
434EXPORT_SYMBOL_GPL(tty_prepare_flip_string_flags);
435
436
437
438/**
439 * flush_to_ldisc
440 * @work: tty structure passed from work queue.
441 *
442 * This routine is called out of the software interrupt to flush data
443 * from the buffer chain to the line discipline.
444 *
445 * Locking: holds tty->buf.lock to guard buffer list. Drops the lock
446 * while invoking the line discipline receive_buf method. The
447 * receive_buf method is single threaded for each tty instance.
448 */
449
450static void flush_to_ldisc(struct work_struct *work)
451{
452 struct tty_struct *tty =
Linus Torvaldsf23eb2b2011-03-22 16:17:32 -0700453 container_of(work, struct tty_struct, buf.work);
Jiri Slaby2fc20662012-10-18 22:26:44 +0200454 struct tty_port *port = tty->port;
Alan Coxe0495732008-10-13 10:36:58 +0100455 unsigned long flags;
456 struct tty_ldisc *disc;
Alan Coxe0495732008-10-13 10:36:58 +0100457
458 disc = tty_ldisc_ref(tty);
459 if (disc == NULL) /* !TTY_LDISC */
460 return;
461
462 spin_lock_irqsave(&tty->buf.lock, flags);
Linus Torvalds45242002009-10-14 08:59:49 -0700463
Jiri Slaby2fc20662012-10-18 22:26:44 +0200464 if (!test_and_set_bit(TTYP_FLUSHING, &port->iflags)) {
Linus Torvalds81de9162011-06-08 07:46:30 -0700465 struct tty_buffer *head;
Linus Torvalds45242002009-10-14 08:59:49 -0700466 while ((head = tty->buf.head) != NULL) {
467 int count;
468 char *char_buf;
469 unsigned char *flag_buf;
470
471 count = head->commit - head->read;
Alan Coxe0495732008-10-13 10:36:58 +0100472 if (!count) {
473 if (head->next == NULL)
474 break;
Linus Torvalds45242002009-10-14 08:59:49 -0700475 tty->buf.head = head->next;
476 tty_buffer_free(tty, head);
Alan Coxe0495732008-10-13 10:36:58 +0100477 continue;
478 }
479 /* Ldisc or user is trying to flush the buffers
480 we are feeding to the ldisc, stop feeding the
481 line discipline as we want to empty the queue */
Jiri Slaby2fc20662012-10-18 22:26:44 +0200482 if (test_bit(TTYP_FLUSHPENDING, &port->iflags))
Alan Coxe0495732008-10-13 10:36:58 +0100483 break;
Linus Torvalds81de9162011-06-08 07:46:30 -0700484 if (!tty->receive_room)
Linus Torvalds55db4c62011-06-04 06:33:24 +0900485 break;
486 if (count > tty->receive_room)
487 count = tty->receive_room;
Alan Coxe0495732008-10-13 10:36:58 +0100488 char_buf = head->char_buf_ptr + head->read;
489 flag_buf = head->flag_buf_ptr + head->read;
Linus Torvalds55db4c62011-06-04 06:33:24 +0900490 head->read += count;
Alan Coxe0495732008-10-13 10:36:58 +0100491 spin_unlock_irqrestore(&tty->buf.lock, flags);
Linus Torvalds55db4c62011-06-04 06:33:24 +0900492 disc->ops->receive_buf(tty, char_buf,
Alan Coxe0495732008-10-13 10:36:58 +0100493 flag_buf, count);
494 spin_lock_irqsave(&tty->buf.lock, flags);
495 }
Jiri Slaby2fc20662012-10-18 22:26:44 +0200496 clear_bit(TTYP_FLUSHING, &port->iflags);
Alan Coxe0495732008-10-13 10:36:58 +0100497 }
Linus Torvalds45242002009-10-14 08:59:49 -0700498
Alan Coxe0495732008-10-13 10:36:58 +0100499 /* We may have a deferred request to flush the input buffer,
500 if so pull the chain under the lock and empty the queue */
Jiri Slaby2fc20662012-10-18 22:26:44 +0200501 if (test_bit(TTYP_FLUSHPENDING, &port->iflags)) {
Alan Coxe0495732008-10-13 10:36:58 +0100502 __tty_buffer_flush(tty);
Jiri Slaby2fc20662012-10-18 22:26:44 +0200503 clear_bit(TTYP_FLUSHPENDING, &port->iflags);
Alan Coxe0495732008-10-13 10:36:58 +0100504 wake_up(&tty->read_wait);
505 }
Alan Coxe0495732008-10-13 10:36:58 +0100506 spin_unlock_irqrestore(&tty->buf.lock, flags);
507
508 tty_ldisc_deref(disc);
509}
510
511/**
OGAWA Hirofumie043e422009-07-29 12:15:56 -0700512 * tty_flush_to_ldisc
513 * @tty: tty to push
514 *
515 * Push the terminal flip buffers to the line discipline.
516 *
517 * Must not be called from IRQ context.
518 */
519void tty_flush_to_ldisc(struct tty_struct *tty)
520{
Ivo Siebencee4ad12012-09-27 14:02:05 +0200521 if (!tty->low_latency)
522 flush_work(&tty->buf.work);
OGAWA Hirofumie043e422009-07-29 12:15:56 -0700523}
524
525/**
Alan Coxe0495732008-10-13 10:36:58 +0100526 * tty_flip_buffer_push - terminal
527 * @tty: tty to push
528 *
529 * Queue a push of the terminal flip buffers to the line discipline. This
530 * function must not be called from IRQ context if tty->low_latency is set.
531 *
532 * In the event of the queue being busy for flipping the work will be
533 * held off and retried later.
534 *
535 * Locking: tty buffer lock. Driver locks in low latency mode.
536 */
537
538void tty_flip_buffer_push(struct tty_struct *tty)
539{
540 unsigned long flags;
541 spin_lock_irqsave(&tty->buf.lock, flags);
542 if (tty->buf.tail != NULL)
543 tty->buf.tail->commit = tty->buf.tail->used;
544 spin_unlock_irqrestore(&tty->buf.lock, flags);
545
546 if (tty->low_latency)
Linus Torvaldsf23eb2b2011-03-22 16:17:32 -0700547 flush_to_ldisc(&tty->buf.work);
Alan Coxe0495732008-10-13 10:36:58 +0100548 else
Linus Torvaldsf23eb2b2011-03-22 16:17:32 -0700549 schedule_work(&tty->buf.work);
Alan Coxe0495732008-10-13 10:36:58 +0100550}
551EXPORT_SYMBOL(tty_flip_buffer_push);
552
553/**
554 * tty_buffer_init - prepare a tty buffer structure
555 * @tty: tty to initialise
556 *
557 * Set up the initial state of the buffer management for a tty device.
558 * Must be called before the other tty buffer functions are used.
559 *
560 * Locking: none
561 */
562
563void tty_buffer_init(struct tty_struct *tty)
564{
565 spin_lock_init(&tty->buf.lock);
566 tty->buf.head = NULL;
567 tty->buf.tail = NULL;
568 tty->buf.free = NULL;
569 tty->buf.memory_used = 0;
Linus Torvaldsf23eb2b2011-03-22 16:17:32 -0700570 INIT_WORK(&tty->buf.work, flush_to_ldisc);
Alan Coxe0495732008-10-13 10:36:58 +0100571}
572