29 #include <linux/kernel.h>
31 #include <linux/list.h>
32 #include <linux/module.h>
35 #include <linux/tty.h>
37 #include <linux/sched.h>
41 #include <linux/slab.h>
42 #include <linux/serial_core.h>
44 #include <asm/uaccess.h>
55 #define HVC_CLOSE_WAIT (HZ/100)
65 #define __ALIGNED__ __attribute__((__aligned__(sizeof(long))))
71 static int hvc_kicked;
73 static int hvc_init(
void);
75 #ifdef CONFIG_MAGIC_SYSRQ
76 static int sysrq_pressed;
93 static int last_hvc = -1;
105 spin_lock(&hvc_structs_lock);
109 if (hp->
index == index) {
110 tty_port_get(&hp->
port);
111 spin_unlock_irqrestore(&hp->
lock, flags);
112 spin_unlock(&hvc_structs_lock);
115 spin_unlock_irqrestore(&hp->
lock, flags);
119 spin_unlock(&hvc_structs_lock);
139 static void hvc_console_print(
struct console *co,
const char *
b,
143 unsigned i = 0,
n = 0;
144 int r, donecr = 0, index = co->
index;
151 if (vtermnos[index] == -1)
154 while (count > 0 || i > 0) {
155 if (count > 0 && i <
sizeof(
c)) {
156 if (b[
n] ==
'\n' && !donecr) {
182 if (vtermnos[c->
index] == -1)
194 if (vtermnos[co->
index] == -1)
200 static struct console hvc_console = {
202 .write = hvc_console_print,
203 .device = hvc_console_device,
204 .setup = hvc_console_setup,
224 static int __init hvc_console_init(
void)
237 spin_lock(&hvc_structs_lock);
241 spin_unlock_irqrestore(&hp->
lock, flags);
243 spin_unlock(&hvc_structs_lock);
248 static void hvc_check_console(
int index)
258 if (index == hvc_console.
index)
275 if (vtermnos[index] != -1)
279 hp = hvc_get_by_index(index);
289 if (last_hvc < index)
293 hvc_check_console(index);
307 static void hvc_unthrottle(
struct tty_struct *tty)
318 if (!(hp = hvc_get_by_index(tty->
index)))
341 if (hp->
port.count++ > 0) {
342 spin_unlock_irqrestore(&hp->
port.lock, flags);
346 spin_unlock_irqrestore(&hp->
port.lock, flags);
350 if (hp->
ops->notifier_add)
351 rc = hp->
ops->notifier_add(hp, hp->
data);
363 printk(
KERN_ERR "hvc_open: request_irq failed with rc %d.\n", rc);
391 if (--hp->
port.count == 0) {
392 spin_unlock_irqrestore(&hp->
port.lock, flags);
396 if (hp->
ops->notifier_del)
397 hp->
ops->notifier_del(hp, hp->
data);
409 if (hp->
port.count < 0)
412 spin_unlock_irqrestore(&hp->
port.lock, flags);
416 static void hvc_cleanup(
struct tty_struct *tty)
423 static void hvc_hangup(
struct tty_struct *tty)
441 if (hp->
port.count <= 0) {
442 spin_unlock_irqrestore(&hp->
port.lock, flags);
447 spin_unlock_irqrestore(&hp->
port.lock, flags);
452 if (hp->
ops->notifier_hangup)
453 hp->
ops->notifier_hangup(hp, hp->
data);
466 if (n == 0 || n == -
EAGAIN) {
483 static int hvc_write(
struct tty_struct *tty,
const unsigned char *
buf,
int count)
487 int rsize, written = 0;
494 if (hp->
port.count <= 0)
513 spin_unlock_irqrestore(&hp->
lock, flags);
536 unsigned long hvc_flags;
548 spin_unlock_irqrestore(&hp->lock, hvc_flags);
559 static int hvc_write_room(
struct tty_struct *tty)
569 static int hvc_chars_in_buffer(
struct tty_struct *tty)
586 #define MIN_TIMEOUT (10)
587 #define MAX_TIMEOUT (2000)
590 #define HVC_POLL_READ 0x00000001
591 #define HVC_POLL_WRITE 0x00000002
596 int i,
n, poll_mask = 0;
600 int written_total = 0;
606 written_total = hvc_push(hp);
640 n = hp->
ops->get_chars(hp->
vtermno, buf, count);
644 spin_unlock_irqrestore(&hp->
lock, flags);
647 }
else if ( n == -
EAGAIN ) {
657 for (i = 0; i <
n; ++
i) {
658 #ifdef CONFIG_MAGIC_SYSRQ
662 if (buf[i] ==
'\x0f') {
665 sysrq_pressed = !sysrq_pressed;
668 }
else if (sysrq_pressed) {
675 tty_insert_flip_char(tty, buf[i], 0);
687 spin_unlock_irqrestore(&hp->
lock, flags);
724 static int khvcd(
void *
unused)
735 if (!cpus_are_in_xmon()) {
736 spin_lock(&hvc_structs_lock);
740 spin_unlock(&hvc_structs_lock);
751 timeout += (timeout >> 6) + 1;
762 static int hvc_tiocmget(
struct tty_struct *tty)
766 if (!hp || !hp->
ops->tiocmget)
768 return hp->
ops->tiocmget(hp);
771 static int hvc_tiocmset(
struct tty_struct *tty,
772 unsigned int set,
unsigned int clear)
776 if (!hp || !hp->
ops->tiocmset)
778 return hp->
ops->tiocmset(hp,
set, clear);
781 #ifdef CONFIG_CONSOLE_POLL
782 int hvc_poll_init(
struct tty_driver *driver,
int line,
char *options)
802 static void hvc_poll_put_char(
struct tty_driver *driver,
int line,
char ch)
815 .install = hvc_install,
818 .cleanup = hvc_cleanup,
820 .hangup = hvc_hangup,
821 .unthrottle = hvc_unthrottle,
822 .write_room = hvc_write_room,
823 .chars_in_buffer = hvc_chars_in_buffer,
824 .tiocmget = hvc_tiocmget,
825 .tiocmset = hvc_tiocmset,
826 #ifdef CONFIG_CONSOLE_POLL
827 .poll_init = hvc_poll_init,
828 .poll_get_char = hvc_poll_get_char,
829 .poll_put_char = hvc_poll_put_char,
834 .destruct = hvc_port_destruct,
846 int err = hvc_init();
851 hp = kzalloc(
ALIGN(
sizeof(*hp),
sizeof(
long)) + outbuf_size,
860 hp->
outbuf = &((
char *)hp)[
ALIGN(
sizeof(*hp),
sizeof(
long))];
863 hp->
port.ops = &hvc_port_ops;
867 spin_lock(&hvc_structs_lock);
874 if (vtermnos[i] == hp->
vtermno &&
875 cons_ops[i] == hp->
ops)
879 if (i >= MAX_NR_HVC_CONSOLES)
887 spin_unlock(&hvc_structs_lock);
890 hvc_check_console(i);
906 vtermnos[hp->
index] = -1;
913 spin_unlock_irqrestore(&hp->
lock, flags);
935 static int hvc_init(
void)
959 if (IS_ERR(hvc_task)) {
961 err = PTR_ERR(hvc_task);
991 static void __exit hvc_exit(
void)