TTY Buffer¶
Here, we document functions for taking care of tty buffer and their flipping. Drivers are supposed to fill the buffer by one of those functions below and then flip the buffer, so that the data are passed to line discipline for further processing.
Flip Buffer Management¶
-
size_t tty_prepare_flip_string(struct tty_port *port, u8 **chars, size_t size)¶
make room for characters
參數
struct tty_port *porttty port
u8 **charsreturn pointer for character write area
size_t sizedesired size
描述
Prepare a block of space in the buffer for data.
This is used for drivers that need their own block copy routines into the buffer. There is no guarantee the buffer is a DMA target!
Return
the length available and buffer pointer (chars) to the space which is now allocated and accounted for as ready for normal characters.
-
size_t tty_ldisc_receive_buf(struct tty_ldisc *ld, const u8 *p, const u8 *f, size_t count)¶
forward data to line discipline
參數
struct tty_ldisc *ldline discipline to process input
const u8 *pchar buffer
const u8 *fTTY_NORMAL,TTY_BREAK, etc. flags buffersize_t countnumber of bytes to process
描述
Callers other than flush_to_ldisc() need to exclude the kworker from
concurrent use of the line discipline, see paste_selection().
Return
the number of bytes processed.
參數
struct tty_port *porttty port to push
描述
Queue a push of the terminal flip buffers to the line discipline. Can be called from IRQ/atomic context.
In the event of the queue being busy for flipping the work will be held off and retried later.
-
size_t tty_insert_flip_string_fixed_flag(struct tty_port *port, const u8 *chars, u8 flag, size_t size)¶
add characters to the tty buffer
參數
struct tty_port *porttty port
const u8 *charscharacters
u8 flagflag value for each character
size_t sizesize
描述
Queue a series of bytes to the tty buffering. All the characters passed are marked with the supplied flag.
Return
the number added.
-
size_t tty_insert_flip_string_flags(struct tty_port *port, const u8 *chars, const u8 *flags, size_t size)¶
add characters to the tty buffer
參數
struct tty_port *porttty port
const u8 *charscharacters
const u8 *flagsflag bytes
size_t sizesize
描述
Queue a series of bytes to the tty buffering. For each character the flags array indicates the status of the character.
Return
the number added.
-
size_t tty_insert_flip_char(struct tty_port *port, u8 ch, u8 flag)¶
add one character to the tty buffer
參數
struct tty_port *porttty port
u8 chcharacter
u8 flagflag byte
描述
Queue a single byte ch to the tty buffering, with an optional flag.
Other Functions¶
參數
struct tty_port *porttty port owning the flip buffer
Return
the # of bytes which can be written by the driver without reaching the buffer limit.
Note
this does not guarantee that memory is available to write the returned
# of bytes (use tty_prepare_flip_string() to pre-allocate if memory
guarantee is required).
參數
struct tty_port *porttty port to change
int limitmemory limit to set
描述
Change the tty buffer memory limit.
Must be called before the other tty buffer functions are used.
Buffer Locking¶
These are used only in special circumstances. Avoid them.
參數
struct tty_port *porttty port owning the flip buffer
描述
Guarantees safe use of the tty_ldisc_ops.receive_buf() method by excluding
the buffer work and any pending flush from using the flip buffer. Data can
continue to be added concurrently to the flip buffer from the driver side.
See also tty_buffer_unlock_exclusive().
參數
struct tty_port *porttty port owning the flip buffer
描述
The buffer work is restarted if there is data in the flip buffer.
See also tty_buffer_lock_exclusive().
Internal Functions¶
參數
struct tty_port *porttty port to free from
描述
Remove all the buffers pending on a tty whether queued with data or in the free ring. Must be called when the tty is no longer in use.
參數
struct tty_port *porttty port
size_t sizedesired size (characters)
描述
Allocate a new tty buffer to hold the desired number of characters. We round our buffers off in 256 character chunks to get better allocation behaviour.
Return
NULL if out of memory or the allocation would exceed the per
device queue.
參數
struct tty_port *porttty port owning the buffer
struct tty_buffer *bthe buffer to free
描述
Free a tty buffer, or add it to the free list according to our internal strategy.
-
void tty_buffer_flush(struct tty_struct *tty, struct tty_ldisc *ld)¶
flush full tty buffers
參數
struct tty_struct *ttytty to flush
struct tty_ldisc *ldoptional ldisc ptr (must be referenced)
描述
Flush all the buffers containing receive data. If ld != NULL, flush the
ldisc input buffer.
Locking: takes buffer lock to ensure single-threaded flip buffer 'consumer'.
-
int __tty_buffer_request_room(struct tty_port *port, size_t size, bool flags)¶
grow tty buffer if needed
參數
struct tty_port *porttty port
size_t sizesize desired
bool flagsbuffer has to store flags along character data
描述
Make at least size bytes of linear space available for the tty buffer.
Will change over to a new buffer if the current buffer is encoded as
TTY_NORMAL (so has no flags buffer) and the new buffer requires a flags
buffer.
Return
the size we managed to find.
-
void flush_to_ldisc(struct work_struct *work)¶
flush data from buffer to ldisc
參數
struct work_struct *worktty structure passed from work queue.
描述
This routine is called out of the software interrupt to flush data from the buffer chain to the line discipline.
The receive_buf() method is single threaded for each tty instance.
Locking: takes buffer lock to ensure single-threaded flip buffer 'consumer'.
-
int tty_insert_flip_string_and_push_buffer(struct tty_port *port, const u8 *chars, size_t size)¶
add characters to the tty buffer and push
參數
struct tty_port *porttty port
const u8 *charscharacters
size_t sizesize
描述
The function combines tty_insert_flip_string() and tty_flip_buffer_push()
with the exception of properly holding the port->lock.
To be used only internally (by pty currently).
Return
the number added.
參數
struct tty_port *porttty port to initialise
描述
Set up the initial state of the buffer management for a tty device. Must be called before the other tty buffer functions are used.