blob: 311a0d3d93af2302224e9b9d6b76614643a23a67 [file] [log] [blame]
Linus Torvalds1da177e2005-04-16 15:20:36 -07001/*
2 * Copyright (C) 2001, 2002 Jeff Dike (jdike@karaya.com)
3 * Licensed under the GPL
4 */
5
6#ifndef __LINE_H__
7#define __LINE_H__
8
9#include "linux/list.h"
10#include "linux/workqueue.h"
11#include "linux/tty.h"
12#include "linux/interrupt.h"
Paolo 'Blaisorblade' Giarrussob97b77c2005-05-01 08:58:56 -070013#include "linux/spinlock.h"
Jeff Diked79a5802007-02-10 01:43:52 -080014#include "linux/mutex.h"
Linus Torvalds1da177e2005-04-16 15:20:36 -070015#include "chan_user.h"
16#include "mconsole_kern.h"
17
Jeff Diked5c9ffc2007-02-10 01:44:08 -080018/* There's only one modifiable field in this - .mc.list */
Linus Torvalds1da177e2005-04-16 15:20:36 -070019struct line_driver {
Jeff Diked5c9ffc2007-02-10 01:44:08 -080020 const char *name;
21 const char *device_name;
22 const short major;
23 const short minor_start;
24 const short type;
25 const short subtype;
26 const int read_irq;
27 const char *read_irq_name;
28 const int write_irq;
29 const char *write_irq_name;
Linus Torvalds1da177e2005-04-16 15:20:36 -070030 struct mc_device mc;
31};
32
33struct line {
Jeff Dike165dc592006-01-06 00:18:57 -080034 struct tty_struct *tty;
Jeff Diked79a5802007-02-10 01:43:52 -080035 spinlock_t count_lock;
36 int valid;
37
Linus Torvalds1da177e2005-04-16 15:20:36 -070038 char *init_str;
39 int init_pri;
40 struct list_head chan_list;
Jeff Diked79a5802007-02-10 01:43:52 -080041
Paolo 'Blaisorblade' Giarrussob97b77c2005-05-01 08:58:56 -070042 /*This lock is actually, mostly, local to*/
43 spinlock_t lock;
Jeff Diked79a5802007-02-10 01:43:52 -080044 int throttled;
Paolo 'Blaisorblade' Giarrussob97b77c2005-05-01 08:58:56 -070045 /* Yes, this is a real circular buffer.
46 * XXX: And this should become a struct kfifo!
47 *
48 * buffer points to a buffer allocated on demand, of length
49 * LINE_BUFSIZE, head to the start of the ring, tail to the end.*/
Linus Torvalds1da177e2005-04-16 15:20:36 -070050 char *buffer;
51 char *head;
52 char *tail;
Paolo 'Blaisorblade' Giarrussob97b77c2005-05-01 08:58:56 -070053
Linus Torvalds1da177e2005-04-16 15:20:36 -070054 int sigio;
Andrew Mortona2ce7742006-12-06 20:31:36 -080055 struct delayed_work task;
Jeff Dike5e7672e2006-09-27 01:50:33 -070056 const struct line_driver *driver;
Linus Torvalds1da177e2005-04-16 15:20:36 -070057 int have_irq;
58};
59
60#define LINE_INIT(str, d) \
Jeff Dike5563d722008-05-12 14:01:54 -070061 { .count_lock = __SPIN_LOCK_UNLOCKED((str).count_lock), \
Jeff Diked79a5802007-02-10 01:43:52 -080062 .init_str = str, \
Al Viro4d338e12006-03-31 02:30:15 -080063 .init_pri = INIT_STATIC, \
64 .valid = 1, \
Jeff Dike5563d722008-05-12 14:01:54 -070065 .lock = __SPIN_LOCK_UNLOCKED((str).lock), \
Al Viro4d338e12006-03-31 02:30:15 -080066 .driver = d }
Linus Torvalds1da177e2005-04-16 15:20:36 -070067
Linus Torvalds1da177e2005-04-16 15:20:36 -070068extern void line_close(struct tty_struct *tty, struct file * filp);
Jeff Dike1f801712006-01-06 00:18:55 -080069extern int line_open(struct line *lines, struct tty_struct *tty);
Jeff Diked571cd12006-01-06 00:18:53 -080070extern int line_setup(struct line *lines, unsigned int sizeof_lines,
Jeff Dikef28169d2007-02-10 01:43:53 -080071 char *init, char **error_out);
Jeff Diked50084a2006-01-06 00:18:50 -080072extern int line_write(struct tty_struct *tty, const unsigned char *buf,
73 int len);
WANG Cong3168cb92008-05-06 20:42:33 -070074extern int line_put_char(struct tty_struct *tty, unsigned char ch);
Alan Cox606d0992006-12-08 02:38:45 -080075extern void line_set_termios(struct tty_struct *tty, struct ktermios * old);
Linus Torvalds1da177e2005-04-16 15:20:36 -070076extern int line_chars_in_buffer(struct tty_struct *tty);
Paolo 'Blaisorblade' Giarrussob97b77c2005-05-01 08:58:56 -070077extern void line_flush_buffer(struct tty_struct *tty);
78extern void line_flush_chars(struct tty_struct *tty);
Linus Torvalds1da177e2005-04-16 15:20:36 -070079extern int line_write_room(struct tty_struct *tty);
80extern int line_ioctl(struct tty_struct *tty, struct file * file,
81 unsigned int cmd, unsigned long arg);
Jeff Dikee4dcee82006-01-06 00:18:58 -080082extern void line_throttle(struct tty_struct *tty);
83extern void line_unthrottle(struct tty_struct *tty);
Paolo 'Blaisorblade' Giarrussob97b77c2005-05-01 08:58:56 -070084
Linus Torvalds1da177e2005-04-16 15:20:36 -070085extern char *add_xterm_umid(char *base);
Jeff Dike165dc592006-01-06 00:18:57 -080086extern int line_setup_irq(int fd, int input, int output, struct line *line,
87 void *data);
Linus Torvalds1da177e2005-04-16 15:20:36 -070088extern void line_close_chan(struct line *line);
Jeff Diked5c9ffc2007-02-10 01:44:08 -080089extern struct tty_driver *register_lines(struct line_driver *line_driver,
90 const struct tty_operations *driver,
91 struct line *lines, int nlines);
Jeff Dike1f801712006-01-06 00:18:55 -080092extern void lines_init(struct line *lines, int nlines, struct chan_opts *opts);
Linus Torvalds1da177e2005-04-16 15:20:36 -070093extern void close_lines(struct line *lines, int nlines);
Paolo 'Blaisorblade' Giarrussob97b77c2005-05-01 08:58:56 -070094
Jeff Diked50084a2006-01-06 00:18:50 -080095extern int line_config(struct line *lines, unsigned int sizeof_lines,
Jeff Dikef28169d2007-02-10 01:43:53 -080096 char *str, const struct chan_opts *opts,
97 char **error_out);
Jeff Dike29d56cf2005-06-25 14:55:25 -070098extern int line_id(char **str, int *start_out, int *end_out);
Jeff Dikef28169d2007-02-10 01:43:53 -080099extern int line_remove(struct line *lines, unsigned int sizeof_lines, int n,
100 char **error_out);
Jeff Diked50084a2006-01-06 00:18:50 -0800101extern int line_get_config(char *dev, struct line *lines,
102 unsigned int sizeof_lines, char *str,
Linus Torvalds1da177e2005-04-16 15:20:36 -0700103 int size, char **error_out);
104
105#endif