Version:
~ [ 0.6-2.3.46 ] ~
Architecture:
~ [ um ] ~
** Warning: Cannot open xref database.
1 #include "linux/posix_types.h"
2 #include "linux/tty.h"
3 #include "linux/types.h"
4 #include "linux/major.h"
5 #include "linux/kdev_t.h"
6 #include "linux/console.h"
7 #include "linux/string.h"
8 #include "linux/sched.h"
9 #include "linux/init.h"
10 #include "linux/interrupt.h"
11 #include "asm/current.h"
12 #include "asm/softirq.h"
13 #include "stdio_console.h"
14 #include "user_util.h"
15 #include "kern_util.h"
16
17 #define MAX_TTYS (8)
18
19 static struct tty_driver console_driver;
20 static struct tty_struct *console_table[MAX_TTYS];
21 static struct termios *console_termios[MAX_TTYS];
22 static struct termios *console_termios_locked[MAX_TTYS];
23 static int vt_fds[MAX_TTYS];
24 static int console_refcount;
25
26 DECLARE_MUTEX(stdio_sem);
27
28 static int con_open(struct tty_struct * tty, struct file * filp)
29 {
30 int line;
31
32 line = MINOR(tty->device) - tty->driver.minor_start;
33 if(line != 0){
34 down(&stdio_sem);
35 if(vt_fds[line] == 0){
36 vt_fds[line] = open_vt(line);
37 add_input_request(INPUT_NEW_FD, vt_fds[line], stdio_rcv_proc);
38 }
39 up(&stdio_sem);
40 }
41 return(0);
42 }
43
44 static int con_write(struct tty_struct * tty, int from_user,
45 const unsigned char *buf, int count)
46 {
47 int line;
48
49 line = MINOR(tty->device) - tty->driver.minor_start;
50 stdio_write(vt_fds[line], buf, count);
51 return(count);
52 }
53
54 static int write_room(struct tty_struct * tty)
55 {
56 return(1024);
57 }
58
59 static void set_termios(struct tty_struct *tty, struct termios * old)
60 {
61 }
62
63 static int chars_in_buffer(struct tty_struct *tty)
64 {
65 return(0);
66 }
67
68 DECLARE_TASKLET_DISABLED(input_tasklet, input_handler, 0);
69
70 int stdio_init(void)
71 {
72 printk("Initializing stdio console driver\n");
73 memset(&console_driver, 0, sizeof(struct tty_driver));
74 console_driver.magic = TTY_DRIVER_MAGIC;
75 console_driver.driver_name = "stdio console";
76 console_driver.name = "tty";
77 console_driver.major = TTY_MAJOR;
78 console_driver.minor_start = 0;
79 console_driver.num = 8;
80 console_driver.type = TTY_DRIVER_TYPE_CONSOLE;
81 console_driver.subtype = SYSTEM_TYPE_CONSOLE;
82 console_driver.init_termios = tty_std_termios;
83 console_driver.init_termios.c_oflag |= OCRNL;
84 console_driver.flags = TTY_DRIVER_REAL_RAW;
85 console_driver.refcount = &console_refcount;
86 console_driver.table = console_table;
87 console_driver.termios = console_termios;
88 console_driver.termios_locked = console_termios_locked;
89
90 console_driver.open = con_open;
91 console_driver.close = NULL;
92 console_driver.write = con_write;
93 console_driver.put_char = NULL;
94 console_driver.flush_chars = NULL;
95 console_driver.write_room = write_room;
96 console_driver.chars_in_buffer = chars_in_buffer;
97 console_driver.flush_buffer = NULL;
98 console_driver.ioctl = NULL;
99 console_driver.throttle = NULL;
100 console_driver.unthrottle = NULL;
101 console_driver.send_xchar = NULL;
102 console_driver.set_termios = set_termios;
103 console_driver.stop = NULL;
104 console_driver.start = NULL;
105 console_driver.hangup = NULL;
106 console_driver.break_ctl = NULL;
107 console_driver.wait_until_sent = NULL;
108 console_driver.read_proc = NULL;
109 if (tty_register_driver(&console_driver))
110 panic("Couldn't register console driver\n");
111 setup_fd(0);
112 tasklet_enable(&input_tasklet);
113 add_input_request(INPUT_NEW_FD, 0, stdio_rcv_proc);
114 return(0);
115 }
116
117 __initcall(stdio_init);
118
119 static void console_write(struct console *console, const char *string,
120 unsigned len)
121 {
122 stdio_write(console->index, string, len);
123 }
124
125 static kdev_t console_device(struct console *c)
126 {
127 return MKDEV(TTY_MAJOR, c->index);
128 }
129
130 static int console_setup(struct console *co, char *options)
131 {
132 return(0);
133 }
134
135 static struct console stdiocons = {
136 "tty",
137 console_write,
138 NULL,
139 console_device,
140 NULL,
141 NULL,
142 console_setup,
143 CON_PRINTBUFFER,
144 -1,
145 0,
146 NULL
147 };
148
149 void stdio_console_init(void)
150 {
151 register_console(&stdiocons);
152 }
153
154 void stdio_receive_char(int fd, char ch)
155 {
156 struct tty_struct *tty;
157 int i;
158
159 for(i=0;i<MAX_TTYS;i++){
160 if(vt_fds[i] == fd) break;
161 }
162 if(i == MAX_TTYS){
163 printk("Input received on unknown terminal - fd = %d\n", fd);
164 return;
165 }
166 tty = console_table[i];
167 if(tty == NULL) return;
168 if(tty->flip.count >= TTY_FLIPBUF_SIZE) return;
169 tty->flip.count++;
170 *tty->flip.flag_buf_ptr++ = 0;
171 *tty->flip.char_buf_ptr++ = ch;
172 tty_flip_buffer_push(tty);
173 }
174
This page was automatically generated by the
LXR engine.
Visit the LXR main site for more
information.