![]() |
|
|||
0001 /* SPDX-License-Identifier: GPL-2.0 */ 0002 #ifndef _LINUX_TTY_LDISC_H 0003 #define _LINUX_TTY_LDISC_H 0004 0005 struct tty_struct; 0006 0007 #include <linux/fs.h> 0008 #include <linux/wait.h> 0009 #include <linux/atomic.h> 0010 #include <linux/list.h> 0011 #include <linux/lockdep.h> 0012 #include <linux/seq_file.h> 0013 0014 /* 0015 * the semaphore definition 0016 */ 0017 struct ld_semaphore { 0018 atomic_long_t count; 0019 raw_spinlock_t wait_lock; 0020 unsigned int wait_readers; 0021 struct list_head read_wait; 0022 struct list_head write_wait; 0023 #ifdef CONFIG_DEBUG_LOCK_ALLOC 0024 struct lockdep_map dep_map; 0025 #endif 0026 }; 0027 0028 void __init_ldsem(struct ld_semaphore *sem, const char *name, 0029 struct lock_class_key *key); 0030 0031 #define init_ldsem(sem) \ 0032 do { \ 0033 static struct lock_class_key __key; \ 0034 \ 0035 __init_ldsem((sem), #sem, &__key); \ 0036 } while (0) 0037 0038 0039 int ldsem_down_read(struct ld_semaphore *sem, long timeout); 0040 int ldsem_down_read_trylock(struct ld_semaphore *sem); 0041 int ldsem_down_write(struct ld_semaphore *sem, long timeout); 0042 int ldsem_down_write_trylock(struct ld_semaphore *sem); 0043 void ldsem_up_read(struct ld_semaphore *sem); 0044 void ldsem_up_write(struct ld_semaphore *sem); 0045 0046 #ifdef CONFIG_DEBUG_LOCK_ALLOC 0047 int ldsem_down_read_nested(struct ld_semaphore *sem, int subclass, 0048 long timeout); 0049 int ldsem_down_write_nested(struct ld_semaphore *sem, int subclass, 0050 long timeout); 0051 #else 0052 # define ldsem_down_read_nested(sem, subclass, timeout) \ 0053 ldsem_down_read(sem, timeout) 0054 # define ldsem_down_write_nested(sem, subclass, timeout) \ 0055 ldsem_down_write(sem, timeout) 0056 #endif 0057 0058 /** 0059 * struct tty_ldisc_ops - ldisc operations 0060 * 0061 * @name: name of this ldisc rendered in /proc/tty/ldiscs 0062 * @num: ``N_*`` number (%N_TTY, %N_HDLC, ...) reserved to this ldisc 0063 * 0064 * @open: [TTY] ``int ()(struct tty_struct *tty)`` 0065 * 0066 * This function is called when the line discipline is associated with the 0067 * @tty. No other call into the line discipline for this tty will occur 0068 * until it completes successfully. It should initialize any state needed 0069 * by the ldisc, and set @tty->receive_room to the maximum amount of data 0070 * the line discipline is willing to accept from the driver with a single 0071 * call to @receive_buf(). Returning an error will prevent the ldisc from 0072 * being attached. 0073 * 0074 * Can sleep. 0075 * 0076 * @close: [TTY] ``void ()(struct tty_struct *tty)`` 0077 * 0078 * This function is called when the line discipline is being shutdown, 0079 * either because the @tty is being closed or because the @tty is being 0080 * changed to use a new line discipline. At the point of execution no 0081 * further users will enter the ldisc code for this tty. 0082 * 0083 * Can sleep. 0084 * 0085 * @flush_buffer: [TTY] ``void ()(struct tty_struct *tty)`` 0086 * 0087 * This function instructs the line discipline to clear its buffers of any 0088 * input characters it may have queued to be delivered to the user mode 0089 * process. It may be called at any point between open and close. 0090 * 0091 * @read: [TTY] ``ssize_t ()(struct tty_struct *tty, struct file *file, 0092 * unsigned char *buf, size_t nr)`` 0093 * 0094 * This function is called when the user requests to read from the @tty. 0095 * The line discipline will return whatever characters it has buffered up 0096 * for the user. If this function is not defined, the user will receive 0097 * an %EIO error. Multiple read calls may occur in parallel and the ldisc 0098 * must deal with serialization issues. 0099 * 0100 * Can sleep. 0101 * 0102 * @write: [TTY] ``ssize_t ()(struct tty_struct *tty, struct file *file, 0103 * const unsigned char *buf, size_t nr)`` 0104 * 0105 * This function is called when the user requests to write to the @tty. 0106 * The line discipline will deliver the characters to the low-level tty 0107 * device for transmission, optionally performing some processing on the 0108 * characters first. If this function is not defined, the user will 0109 * receive an %EIO error. 0110 * 0111 * Can sleep. 0112 * 0113 * @ioctl: [TTY] ``int ()(struct tty_struct *tty, unsigned int cmd, 0114 * unsigned long arg)`` 0115 * 0116 * This function is called when the user requests an ioctl which is not 0117 * handled by the tty layer or the low-level tty driver. It is intended 0118 * for ioctls which affect line discpline operation. Note that the search 0119 * order for ioctls is (1) tty layer, (2) tty low-level driver, (3) line 0120 * discpline. So a low-level driver can "grab" an ioctl request before 0121 * the line discpline has a chance to see it. 0122 * 0123 * @compat_ioctl: [TTY] ``int ()(struct tty_struct *tty, unsigned int cmd, 0124 * unsigned long arg)`` 0125 * 0126 * Process ioctl calls from 32-bit process on 64-bit system. 0127 * 0128 * Note that only ioctls that are neither "pointer to compatible 0129 * structure" nor tty-generic. Something private that takes an integer or 0130 * a pointer to wordsize-sensitive structure belongs here, but most of 0131 * ldiscs will happily leave it %NULL. 0132 * 0133 * @set_termios: [TTY] ``void ()(struct tty_struct *tty, struct ktermios *old)`` 0134 * 0135 * This function notifies the line discpline that a change has been made 0136 * to the termios structure. 0137 * 0138 * @poll: [TTY] ``int ()(struct tty_struct *tty, struct file *file, 0139 * struct poll_table_struct *wait)`` 0140 * 0141 * This function is called when a user attempts to select/poll on a @tty 0142 * device. It is solely the responsibility of the line discipline to 0143 * handle poll requests. 0144 * 0145 * @hangup: [TTY] ``void ()(struct tty_struct *tty)`` 0146 * 0147 * Called on a hangup. Tells the discipline that it should cease I/O to 0148 * the tty driver. The driver should seek to perform this action quickly 0149 * but should wait until any pending driver I/O is completed. No further 0150 * calls into the ldisc code will occur. 0151 * 0152 * Can sleep. 0153 * 0154 * @receive_buf: [DRV] ``void ()(struct tty_struct *tty, 0155 * const unsigned char *cp, const char *fp, int count)`` 0156 * 0157 * This function is called by the low-level tty driver to send characters 0158 * received by the hardware to the line discpline for processing. @cp is 0159 * a pointer to the buffer of input character received by the device. @fp 0160 * is a pointer to an array of flag bytes which indicate whether a 0161 * character was received with a parity error, etc. @fp may be %NULL to 0162 * indicate all data received is %TTY_NORMAL. 0163 * 0164 * @write_wakeup: [DRV] ``void ()(struct tty_struct *tty)`` 0165 * 0166 * This function is called by the low-level tty driver to signal that line 0167 * discpline should try to send more characters to the low-level driver 0168 * for transmission. If the line discpline does not have any more data to 0169 * send, it can just return. If the line discipline does have some data to 0170 * send, please arise a tasklet or workqueue to do the real data transfer. 0171 * Do not send data in this hook, it may lead to a deadlock. 0172 * 0173 * @dcd_change: [DRV] ``void ()(struct tty_struct *tty, unsigned int status)`` 0174 * 0175 * Tells the discipline that the DCD pin has changed its status. Used 0176 * exclusively by the %N_PPS (Pulse-Per-Second) line discipline. 0177 * 0178 * @receive_buf2: [DRV] ``int ()(struct tty_struct *tty, 0179 * const unsigned char *cp, const char *fp, int count)`` 0180 * 0181 * This function is called by the low-level tty driver to send characters 0182 * received by the hardware to the line discpline for processing. @cp is a 0183 * pointer to the buffer of input character received by the device. @fp 0184 * is a pointer to an array of flag bytes which indicate whether a 0185 * character was received with a parity error, etc. @fp may be %NULL to 0186 * indicate all data received is %TTY_NORMAL. If assigned, prefer this 0187 * function for automatic flow control. 0188 * 0189 * @lookahead_buf: [DRV] ``void ()(struct tty_struct *tty, 0190 * const unsigned char *cp, const char *fp, int count)`` 0191 * 0192 * This function is called by the low-level tty driver for characters 0193 * not eaten by ->receive_buf() or ->receive_buf2(). It is useful for 0194 * processing high-priority characters such as software flow-control 0195 * characters that could otherwise get stuck into the intermediate 0196 * buffer until tty has room to receive them. Ldisc must be able to 0197 * handle later a ->receive_buf() or ->receive_buf2() call for the 0198 * same characters (e.g. by skipping the actions for high-priority 0199 * characters already handled by ->lookahead_buf()). 0200 * 0201 * @owner: module containting this ldisc (for reference counting) 0202 * 0203 * This structure defines the interface between the tty line discipline 0204 * implementation and the tty routines. The above routines can be defined. 0205 * Unless noted otherwise, they are optional, and can be filled in with a %NULL 0206 * pointer. 0207 * 0208 * Hooks marked [TTY] are invoked from the TTY core, the [DRV] ones from the 0209 * tty_driver side. 0210 */ 0211 struct tty_ldisc_ops { 0212 char *name; 0213 int num; 0214 0215 /* 0216 * The following routines are called from above. 0217 */ 0218 int (*open)(struct tty_struct *tty); 0219 void (*close)(struct tty_struct *tty); 0220 void (*flush_buffer)(struct tty_struct *tty); 0221 ssize_t (*read)(struct tty_struct *tty, struct file *file, 0222 unsigned char *buf, size_t nr, 0223 void **cookie, unsigned long offset); 0224 ssize_t (*write)(struct tty_struct *tty, struct file *file, 0225 const unsigned char *buf, size_t nr); 0226 int (*ioctl)(struct tty_struct *tty, unsigned int cmd, 0227 unsigned long arg); 0228 int (*compat_ioctl)(struct tty_struct *tty, unsigned int cmd, 0229 unsigned long arg); 0230 void (*set_termios)(struct tty_struct *tty, struct ktermios *old); 0231 __poll_t (*poll)(struct tty_struct *tty, struct file *file, 0232 struct poll_table_struct *wait); 0233 void (*hangup)(struct tty_struct *tty); 0234 0235 /* 0236 * The following routines are called from below. 0237 */ 0238 void (*receive_buf)(struct tty_struct *tty, const unsigned char *cp, 0239 const char *fp, int count); 0240 void (*write_wakeup)(struct tty_struct *tty); 0241 void (*dcd_change)(struct tty_struct *tty, unsigned int status); 0242 int (*receive_buf2)(struct tty_struct *tty, const unsigned char *cp, 0243 const char *fp, int count); 0244 void (*lookahead_buf)(struct tty_struct *tty, const unsigned char *cp, 0245 const unsigned char *fp, unsigned int count); 0246 0247 struct module *owner; 0248 }; 0249 0250 struct tty_ldisc { 0251 struct tty_ldisc_ops *ops; 0252 struct tty_struct *tty; 0253 }; 0254 0255 #define MODULE_ALIAS_LDISC(ldisc) \ 0256 MODULE_ALIAS("tty-ldisc-" __stringify(ldisc)) 0257 0258 extern const struct seq_operations tty_ldiscs_seq_ops; 0259 0260 struct tty_ldisc *tty_ldisc_ref(struct tty_struct *); 0261 void tty_ldisc_deref(struct tty_ldisc *); 0262 struct tty_ldisc *tty_ldisc_ref_wait(struct tty_struct *); 0263 0264 void tty_ldisc_flush(struct tty_struct *tty); 0265 0266 int tty_register_ldisc(struct tty_ldisc_ops *new_ldisc); 0267 void tty_unregister_ldisc(struct tty_ldisc_ops *ldisc); 0268 int tty_set_ldisc(struct tty_struct *tty, int disc); 0269 0270 #endif /* _LINUX_TTY_LDISC_H */
[ Source navigation ] | [ Diff markup ] | [ Identifier search ] | [ general search ] |
This page was automatically generated by the 2.1.0 LXR engine. The LXR team |
![]() ![]() |