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 DEFINE_SPINLOCK(memcons_lock
);
31 static size_t write (const char *buf
, size_t len
)
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
;
45 spin_unlock_irqrestore (memcons_lock
, flags
);
47 memcpy (point
, buf
, len
);
53 /* Low-level console. */
55 static void memcons_write (struct console
*co
, const char *buf
, unsigned len
)
58 len
-= write (buf
, len
);
61 static struct tty_driver
*tty_driver
;
63 static struct tty_driver
*memcons_device (struct console
*co
, int *index
)
69 static struct console memcons
=
72 .write
= memcons_write
,
73 .device
= memcons_device
,
74 .flags
= CON_PRINTBUFFER
,
78 void memcons_setup (void)
80 register_console (&memcons
);
81 printk (KERN_INFO
"Console: static memory buffer (memcons)\n");
84 /* Higher level TTY interface. */
86 int memcons_tty_open (struct tty_struct
*tty
, struct file
*filp
)
91 int memcons_tty_write (struct tty_struct
*tty
, const unsigned char *buf
, int len
)
93 return write (buf
, len
);
96 int memcons_tty_write_room (struct tty_struct
*tty
)
98 return &memcons_output_end
- (memcons_output
+ memcons_offs
);
101 int memcons_tty_chars_in_buffer (struct tty_struct
*tty
)
103 /* We have no buffer. */
107 static const struct tty_operations ops
= {
108 .open
= memcons_tty_open
,
109 .write
= memcons_tty_write
,
110 .write_room
= memcons_tty_write_room
,
111 .chars_in_buffer
= memcons_tty_chars_in_buffer
,
114 int __init
memcons_tty_init (void)
117 struct tty_driver
*driver
= alloc_tty_driver(1);
121 driver
->name
= "memcons";
122 driver
->major
= TTY_MAJOR
;
123 driver
->minor_start
= 64;
124 driver
->type
= TTY_DRIVER_TYPE_SYSCONS
;
125 driver
->init_termios
= tty_std_termios
;
126 tty_set_operations(driver
, &ops
);
127 err
= tty_register_driver(driver
);
129 put_tty_driver(driver
);
135 __initcall (memcons_tty_init
);