Merge with Linux 2.5.48.
[linux-2.6/linux-mips.git] / arch / v850 / kernel / memcons.c
blobbd6c2fb1f09bee7551e4de684eb824aa05a21531
1 /*
2 * arch/v850/kernel/memcons.c -- Console I/O to a memory buffer
4 * Copyright (C) 2001,02 NEC Corporation
5 * Copyright (C) 2001,02 Miles Bader <miles@gnu.org>
7 * This file is subject to the terms and conditions of the GNU General
8 * Public License. See the file COPYING in the main directory of this
9 * archive for more details.
11 * Written by Miles Bader <miles@gnu.org>
14 #include <linux/kernel.h>
15 #include <linux/console.h>
16 #include <linux/tty.h>
17 #include <linux/tty_driver.h>
18 #include <linux/init.h>
20 /* If this device is enabled, the linker map should define start and
21 end points for its buffer. */
22 extern char memcons_output[], memcons_output_end;
24 /* Current offset into the buffer. */
25 static unsigned long memcons_offs = 0;
27 /* Spinlock protecting memcons_offs. */
28 static spinlock_t memcons_lock = SPIN_LOCK_UNLOCKED;
31 static size_t write (const char *buf, size_t len)
33 int flags;
34 char *point;
36 spin_lock_irqsave (memcons_lock, flags);
38 point = memcons_output + memcons_offs;
39 if (point + len >= &memcons_output_end) {
40 len = &memcons_output_end - point;
41 memcons_offs = 0;
42 } else
43 memcons_offs += len;
45 spin_unlock_irqrestore (memcons_lock, flags);
47 memcpy (point, buf, len);
49 return len;
53 /* Low-level console. */
55 static void memcons_write (struct console *co, const char *buf, unsigned len)
57 while (len > 0)
58 len -= write (buf, len);
61 static kdev_t memcons_device (struct console *co)
63 return MKDEV (TTY_MAJOR, 64 + co->index);
66 static struct console memcons =
68 .name = "memcons",
69 .write = memcons_write,
70 .device = memcons_device,
71 .flags = CON_PRINTBUFFER,
72 .index = -1,
75 void memcons_setup (void)
77 register_console (&memcons);
78 printk (KERN_INFO "Console: static memory buffer (memcons)\n");
81 /* Higher level TTY interface. */
83 static struct tty_struct *tty_table[1] = { 0 };
84 static struct termios *tty_termios[1] = { 0 };
85 static struct termios *tty_termios_locked[1] = { 0 };
86 static struct tty_driver tty_driver = { 0 };
87 static int tty_ref_count = 0;
89 int memcons_tty_open (struct tty_struct *tty, struct file *filp)
91 return 0;
94 int memcons_tty_write (struct tty_struct *tty, int from_user,
95 const unsigned char *buf, int len)
97 return write (buf, len);
100 int memcons_tty_write_room (struct tty_struct *tty)
102 return &memcons_output_end - (memcons_output + memcons_offs);
105 int memcons_tty_chars_in_buffer (struct tty_struct *tty)
107 /* We have no buffer. */
108 return 0;
111 int __init memcons_tty_init (void)
113 tty_driver.name = "memcons";
114 tty_driver.major = TTY_MAJOR;
115 tty_driver.minor_start = 64;
116 tty_driver.num = 1;
117 tty_driver.type = TTY_DRIVER_TYPE_SYSCONS;
119 tty_driver.refcount = &tty_ref_count;
121 tty_driver.table = tty_table;
122 tty_driver.termios = tty_termios;
123 tty_driver.termios_locked = tty_termios_locked;
125 tty_driver.init_termios = tty_std_termios;
127 tty_driver.open = memcons_tty_open;
128 tty_driver.write = memcons_tty_write;
129 tty_driver.write_room = memcons_tty_write_room;
130 tty_driver.chars_in_buffer = memcons_tty_chars_in_buffer;
132 tty_register_driver (&tty_driver);
134 __initcall (memcons_tty_init);