Commit aca8e5a3 authored by Richard Henderson's avatar Richard Henderson Committed by Richard Henderson

[ALPHA] New SRM console driver.

From Jeff Wiedemeier:

How about this.. This version no longer piggy backs on ttyS0 (it
actually doesn't touch any files outside arch/alpha/kernel at all). It
does use a dynamic major for the tty piece of the driver. From
userspace, /dev/console is ok for most uses, but because of the 'noctty
= 1' at tty_tio.c:1329 (in the IS_SYSCONS_DEV section) using
/dev/console cannot result in a controlling tty so some things, like
'resize' and bash job control don't work. For those uses, however, it's
easy enough to parse /proc/devices on the way up to get the major number
and create the specific device for the tty side of the driver.

I made a distinction in kernel options as well. "srmcons" specifically
requests the early prints (as before) and "console=srm" requests the
full driver, including the early prints. The two options can be
combined with "console=srm" behavior resulting. The other change is that
if "console=srm" is specified, I don't unregister_srm_console before
console_init any more - that only happens in the "srmcons" case. That
way preferred console selection remains stable and "console=srm" doesn't
result in the early messages being repeated when the driver
re-registers. The use of "srmcons_allowed" is also eliminated due to the
"srmcons" vs. "console=srm" distinction.
parent 31aa02a3
...@@ -35,8 +35,13 @@ obj-y += err_titan.o err_marvel.o ...@@ -35,8 +35,13 @@ obj-y += err_titan.o err_marvel.o
obj-y += es1888.o smc37c669.o smc37c93x.o ns87312.o gct.o obj-y += es1888.o smc37c669.o smc37c93x.o ns87312.o gct.o
obj-y += srmcons.o
else else
# Misc support
obj-$(CONFIG_ALPHA_SRM) += srmcons.o
# Core logic support # Core logic support
obj-$(CONFIG_ALPHA_APECS) += core_apecs.o obj-$(CONFIG_ALPHA_APECS) += core_apecs.o
obj-$(CONFIG_ALPHA_CIA) += core_cia.o obj-$(CONFIG_ALPHA_CIA) += core_cia.o
......
...@@ -110,8 +110,15 @@ extern unsigned long wildfire_node_mem_size(int); ...@@ -110,8 +110,15 @@ extern unsigned long wildfire_node_mem_size(int);
extern unsigned long srm_hae; extern unsigned long srm_hae;
extern int boot_cpuid; extern int boot_cpuid;
extern int srmcons_output; extern int srmcons_output;
/* srmcons.c */
#if defined(CONFIG_ALPHA_GENERIC) || defined(CONFIG_ALPHA_SRM)
extern void register_srm_console(void); extern void register_srm_console(void);
extern void unregister_srm_console(void); extern void unregister_srm_console(void);
#else
#define register_srm_console()
#define unregister_srm_console()
#endif
/* smp.c */ /* smp.c */
extern void setup_smp(void); extern void setup_smp(void);
......
...@@ -82,7 +82,10 @@ int boot_cpuid; ...@@ -82,7 +82,10 @@ int boot_cpuid;
* called before console_init(), so we put "unregister" code * called before console_init(), so we put "unregister" code
* there to prevent schizophrenic console behavior later... ;-} * there to prevent schizophrenic console behavior later... ;-}
* *
* By default, OFF; set it with a bootcommand arg of "srmcons". * By default, OFF; set it with a bootcommand arg of "srmcons" or
* "console=srm". The meaning of these two args is:
* "srmcons" - early callback prints
* "console=srm" - full callback based console, including early prints
*/ */
int srmcons_output = 0; int srmcons_output = 0;
...@@ -464,57 +467,6 @@ page_is_ram(unsigned long pfn) ...@@ -464,57 +467,6 @@ page_is_ram(unsigned long pfn)
#undef PFN_PHYS #undef PFN_PHYS
#undef PFN_MAX #undef PFN_MAX
#if defined(CONFIG_ALPHA_GENERIC) || defined(CONFIG_ALPHA_SRM)
/*
* Manage the SRM callbacks as a "console".
*/
static struct console srmcons;
void __init register_srm_console(void)
{
register_console(&srmcons);
}
void __init unregister_srm_console(void)
{
unregister_console(&srmcons);
}
static void srm_console_write(struct console *co, const char *s,
unsigned count)
{
srm_printk(s);
}
static kdev_t srm_console_device(struct console *c)
{
/* Huh? */
return mk_kdev(TTY_MAJOR, 64 + c->index);
}
static int __init srm_console_setup(struct console *co, char *options)
{
return 1;
}
static struct console srmcons = {
.name = "srm0",
.write = srm_console_write,
.device = srm_console_device,
.setup = srm_console_setup,
.flags = CON_PRINTBUFFER | CON_ENABLED, /* fake it out */
.index = -1,
};
#else
void __init register_srm_console(void)
{
}
void __init unregister_srm_console(void)
{
}
#endif
void __init void __init
setup_arch(char **cmdline_p) setup_arch(char **cmdline_p)
{ {
...@@ -577,7 +529,11 @@ setup_arch(char **cmdline_p) ...@@ -577,7 +529,11 @@ setup_arch(char **cmdline_p)
continue; continue;
} }
if (strncmp(p, "srmcons", 7) == 0) { if (strncmp(p, "srmcons", 7) == 0) {
srmcons_output = 1; srmcons_output |= 1;
continue;
}
if (strncmp(p, "console=srm", 11) == 0) {
srmcons_output |= 2;
continue; continue;
} }
if (strncmp(p, "gartsize=", 9) == 0) { if (strncmp(p, "gartsize=", 9) == 0) {
...@@ -593,6 +549,13 @@ setup_arch(char **cmdline_p) ...@@ -593,6 +549,13 @@ setup_arch(char **cmdline_p)
/* If we want SRM console printk echoing early, do it now. */ /* If we want SRM console printk echoing early, do it now. */
if (alpha_using_srm && srmcons_output) { if (alpha_using_srm && srmcons_output) {
register_srm_console(); register_srm_console();
/*
* If "console=srm" was specified, clear the srmcons_output
* flag now so that time.c won't unregister_srm_console
*/
if (srmcons_output & 2)
srmcons_output = 0;
} }
#ifdef CONFIG_MAGIC_SYSRQ #ifdef CONFIG_MAGIC_SYSRQ
......
/*
* linux/arch/alpha/kernel/srmcons.c
*
* Callback based driver for SRM Console console device.
* (TTY driver and console driver)
*/
#include <linux/config.h>
#include <linux/kernel.h>
#include <linux/init.h>
#include <linux/console.h>
#include <linux/delay.h>
#include <linux/mm.h>
#include <linux/slab.h>
#include <linux/spinlock.h>
#include <linux/timer.h>
#include <linux/tty.h>
#include <linux/tty_driver.h>
#include <linux/tty_flip.h>
#include <asm/console.h>
#include <asm/uaccess.h>
static spinlock_t srmcons_callback_lock = SPIN_LOCK_UNLOCKED;
static int srm_is_registered_console = 0;
/*
* The TTY driver
*/
#define MAX_SRM_CONSOLE_DEVICES 1 /* only support 1 console device */
static int srmcons_refcount;
static struct tty_struct *srmcons_table[MAX_SRM_CONSOLE_DEVICES];
static struct termios *srmcons_termios[MAX_SRM_CONSOLE_DEVICES];
static struct termios *srmcons_termios_locked[MAX_SRM_CONSOLE_DEVICES];
struct srmcons_private {
struct tty_struct *tty;
struct timer_list timer;
spinlock_t lock;
};
typedef union _srmcons_result {
struct {
unsigned long c :61;
unsigned long status :3;
} bits;
long as_long;
} srmcons_result;
/* called with callback_lock held */
static int
srmcons_do_receive_chars(struct tty_struct *tty)
{
srmcons_result result;
int count = 0, loops = 0;
do {
result.as_long = callback_getc(0);
if (result.bits.status < 2) {
tty_insert_flip_char(tty, (char)result.bits.c, 0);
count++;
}
} while((result.bits.status & 1) && (++loops < 10));
if (count)
tty_schedule_flip(tty);
return count;
}
static void
srmcons_receive_chars(unsigned long data)
{
struct srmcons_private *srmconsp = (struct srmcons_private *)data;
unsigned long flags;
int incr = 10;
local_irq_save(flags);
if (spin_trylock(&srmcons_callback_lock)) {
if (!srmcons_do_receive_chars(srmconsp->tty))
incr = 100;
spin_unlock(&srmcons_callback_lock);
}
spin_lock(&srmconsp->lock);
if (srmconsp->tty) {
srmconsp->timer.expires = jiffies + incr;
add_timer(&srmconsp->timer);
}
spin_unlock(&srmconsp->lock);
local_irq_restore(flags);
}
/* called with callback_lock held */
static int
srmcons_do_write(struct tty_struct *tty, const unsigned char *buf, int count)
{
unsigned char *str_cr = "\r";
long c, remaining = count;
srmcons_result result;
unsigned char *cur;
int need_cr;
for (cur = (unsigned char *)buf; remaining > 0; ) {
need_cr = 0;
/*
* Break it up into reasonable size chunks to allow a chance
* for input to get in
*/
for (c = 0; c < min_t(long, 128L, remaining) && !need_cr; c++)
if (cur[c] == '\n')
need_cr = 1;
while (c > 0) {
result.as_long = callback_puts(0, cur, c);
c -= result.bits.c;
remaining -= result.bits.c;
cur += result.bits.c;
/*
* Check for pending input iff a tty was provided
*/
if (tty)
srmcons_do_receive_chars(tty);
}
while (need_cr) {
result.as_long = callback_puts(0, str_cr, 1);
if (result.bits.c > 0)
need_cr = 0;
}
}
return count;
}
static int
srmcons_write(struct tty_struct *tty, int from_user,
const unsigned char *buf, int count)
{
unsigned long flags;
if (from_user) {
unsigned char tmp[512];
int ret = 0;
size_t c;
while ((c = count) > 0) {
if (c > sizeof(tmp))
c = sizeof(tmp);
c -= copy_from_user(tmp, buf, c);
if (!c) {
printk("%s: EFAULT (count %d)\n",
__FUNCTION__, count);
return -EFAULT;
}
spin_lock_irqsave(&srmcons_callback_lock, flags);
srmcons_do_write(tty, tmp, c);
spin_unlock_irqrestore(&srmcons_callback_lock, flags);
buf += c;
count -= c;
ret += c;
}
return ret;
}
spin_lock_irqsave(&srmcons_callback_lock, flags);
srmcons_do_write(tty, buf, count);
spin_unlock_irqrestore(&srmcons_callback_lock, flags);
return count;
}
static int
srmcons_write_room(struct tty_struct *tty)
{
return 512;
}
static int
srmcons_chars_in_buffer(struct tty_struct *tty)
{
return 0;
}
static int
srmcons_get_private_struct(struct srmcons_private **ps)
{
static struct srmcons_private *srmconsp = NULL;
static spinlock_t srmconsp_lock = SPIN_LOCK_UNLOCKED;
unsigned long flags;
int retval = 0;
spin_lock_irqsave(&srmconsp_lock, flags);
do {
if (srmconsp != NULL) {
*ps = srmconsp;
break;
}
srmconsp = kmalloc(sizeof(*srmconsp), GFP_KERNEL);
if (srmconsp == NULL) {
retval = -ENOMEM;
break;
}
srmconsp->tty = NULL;
srmconsp->lock = SPIN_LOCK_UNLOCKED;
init_timer(&srmconsp->timer);
*ps = srmconsp;
} while(0);
spin_unlock_irqrestore(&srmconsp_lock, flags);
return retval;
}
static int
srmcons_open(struct tty_struct *tty, struct file *filp)
{
struct srmcons_private *srmconsp;
unsigned long flags;
int retval;
retval = srmcons_get_private_struct(&srmconsp);
if (retval)
return retval;
spin_lock_irqsave(&srmconsp->lock, flags);
if (!srmconsp->tty) {
tty->driver_data = srmconsp;
srmconsp->tty = tty;
srmconsp->timer.function = srmcons_receive_chars;
srmconsp->timer.data = (unsigned long)srmconsp;
srmconsp->timer.expires = jiffies + 10;
add_timer(&srmconsp->timer);
}
spin_unlock_irqrestore(&srmconsp->lock, flags);
return 0;
}
static void
srmcons_close(struct tty_struct *tty, struct file *filp)
{
struct srmcons_private *srmconsp = tty->driver_data;
unsigned long flags;
spin_lock_irqsave(&srmconsp->lock, flags);
if (tty->count == 1) {
srmconsp->tty = NULL;
del_timer(&srmconsp->timer);
}
spin_unlock_irqrestore(&srmconsp->lock, flags);
}
static struct tty_driver srmcons_driver = {
.driver_name = "srm",
.name = "srm",
.magic = TTY_DRIVER_MAGIC,
.major = 0, /* dynamic */
.minor_start = 0,
.num = MAX_SRM_CONSOLE_DEVICES,
.type = TTY_DRIVER_TYPE_SYSTEM,
.subtype = SYSTEM_TYPE_SYSCONS,
.table = srmcons_table,
.termios = srmcons_termios,
.termios_locked = srmcons_termios_locked,
.refcount = &srmcons_refcount,
.open = srmcons_open,
.close = srmcons_close,
.write = srmcons_write,
.write_room = srmcons_write_room,
.chars_in_buffer= srmcons_chars_in_buffer,
};
static int __init
srmcons_init(void)
{
if (srm_is_registered_console) {
srmcons_driver.init_termios = tty_std_termios;
return tty_register_driver(&srmcons_driver);
}
return -ENODEV;
}
module_init(srmcons_init);
/*
* The console driver
*/
static void
srm_console_write(struct console *co, const char *s, unsigned count)
{
unsigned long flags;
spin_lock_irqsave(&srmcons_callback_lock, flags);
srmcons_do_write(NULL, s, count);
spin_unlock_irqrestore(&srmcons_callback_lock, flags);
}
static kdev_t
srm_console_device(struct console *co)
{
return mk_kdev(srmcons_driver.major,
srmcons_driver.minor_start + co->index);
}
static int __init
srm_console_setup(struct console *co, char *options)
{
return 0;
}
static struct console srmcons = {
.name = "srm",
.write = srm_console_write,
.device = srm_console_device,
.setup = srm_console_setup,
.flags = CON_PRINTBUFFER,
.index = -1,
};
void __init
register_srm_console(void)
{
if (!srm_is_registered_console) {
callback_open_console();
register_console(&srmcons);
srm_is_registered_console = 1;
}
}
void __init
unregister_srm_console(void)
{
if (srm_is_registered_console) {
callback_close_console();
unregister_console(&srmcons);
srm_is_registered_console = 0;
}
}
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment