2005-04-17 00:20:36 +02:00
|
|
|
#include <linux/console.h>
|
|
|
|
#include <linux/kernel.h>
|
|
|
|
#include <linux/init.h>
|
|
|
|
#include <linux/string.h>
|
2006-07-10 13:44:13 +02:00
|
|
|
#include <linux/screen_info.h>
|
2005-04-17 00:20:36 +02:00
|
|
|
#include <asm/io.h>
|
|
|
|
#include <asm/processor.h>
|
2005-09-12 18:49:24 +02:00
|
|
|
#include <asm/fcntl.h>
|
2005-04-17 00:20:36 +02:00
|
|
|
|
|
|
|
/* Simple VGA output */
|
|
|
|
|
|
|
|
#ifdef __i386__
|
2005-06-23 09:08:24 +02:00
|
|
|
#include <asm/setup.h>
|
2005-04-17 00:20:36 +02:00
|
|
|
#define VGABASE (__ISA_IO_base + 0xb8000)
|
|
|
|
#else
|
2005-06-23 09:08:24 +02:00
|
|
|
#include <asm/bootsetup.h>
|
2005-04-17 00:20:36 +02:00
|
|
|
#define VGABASE ((void __iomem *)0xffffffff800b8000UL)
|
|
|
|
#endif
|
|
|
|
|
2005-06-23 09:08:24 +02:00
|
|
|
static int max_ypos = 25, max_xpos = 80;
|
2006-03-23 11:59:41 +01:00
|
|
|
static int current_ypos = 25, current_xpos = 0;
|
2005-04-17 00:20:36 +02:00
|
|
|
|
|
|
|
static void early_vga_write(struct console *con, const char *str, unsigned n)
|
|
|
|
{
|
|
|
|
char c;
|
|
|
|
int i, k, j;
|
|
|
|
|
|
|
|
while ((c = *str++) != '\0' && n-- > 0) {
|
2006-03-23 11:59:43 +01:00
|
|
|
if (current_ypos >= max_ypos) {
|
2005-04-17 00:20:36 +02:00
|
|
|
/* scroll 1 line up */
|
2006-03-23 11:59:43 +01:00
|
|
|
for (k = 1, j = 0; k < max_ypos; k++, j++) {
|
|
|
|
for (i = 0; i < max_xpos; i++) {
|
|
|
|
writew(readw(VGABASE+2*(max_xpos*k+i)),
|
|
|
|
VGABASE + 2*(max_xpos*j + i));
|
2005-04-17 00:20:36 +02:00
|
|
|
}
|
|
|
|
}
|
2006-03-23 11:59:43 +01:00
|
|
|
for (i = 0; i < max_xpos; i++)
|
|
|
|
writew(0x720, VGABASE + 2*(max_xpos*j + i));
|
|
|
|
current_ypos = max_ypos-1;
|
2005-04-17 00:20:36 +02:00
|
|
|
}
|
|
|
|
if (c == '\n') {
|
|
|
|
current_xpos = 0;
|
|
|
|
current_ypos++;
|
|
|
|
} else if (c != '\r') {
|
|
|
|
writew(((0x7 << 8) | (unsigned short) c),
|
2006-03-23 11:59:43 +01:00
|
|
|
VGABASE + 2*(max_xpos*current_ypos +
|
2005-04-17 00:20:36 +02:00
|
|
|
current_xpos++));
|
2006-03-23 11:59:43 +01:00
|
|
|
if (current_xpos >= max_xpos) {
|
2005-04-17 00:20:36 +02:00
|
|
|
current_xpos = 0;
|
|
|
|
current_ypos++;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
static struct console early_vga_console = {
|
|
|
|
.name = "earlyvga",
|
|
|
|
.write = early_vga_write,
|
|
|
|
.flags = CON_PRINTBUFFER,
|
|
|
|
.index = -1,
|
|
|
|
};
|
|
|
|
|
2006-03-24 12:18:05 +01:00
|
|
|
/* Serial functions loosely based on a similar package from Klaus P. Gerlicher */
|
2005-04-17 00:20:36 +02:00
|
|
|
|
2005-05-01 17:59:29 +02:00
|
|
|
static int early_serial_base = 0x3f8; /* ttyS0 */
|
2005-04-17 00:20:36 +02:00
|
|
|
|
|
|
|
#define XMTRDY 0x20
|
|
|
|
|
|
|
|
#define DLAB 0x80
|
|
|
|
|
|
|
|
#define TXR 0 /* Transmit register (WRITE) */
|
|
|
|
#define RXR 0 /* Receive register (READ) */
|
|
|
|
#define IER 1 /* Interrupt Enable */
|
|
|
|
#define IIR 2 /* Interrupt ID */
|
|
|
|
#define FCR 2 /* FIFO control */
|
|
|
|
#define LCR 3 /* Line control */
|
|
|
|
#define MCR 4 /* Modem control */
|
|
|
|
#define LSR 5 /* Line Status */
|
|
|
|
#define MSR 6 /* Modem Status */
|
|
|
|
#define DLL 0 /* Divisor Latch Low */
|
|
|
|
#define DLH 1 /* Divisor latch High */
|
|
|
|
|
2006-03-24 12:18:05 +01:00
|
|
|
static int early_serial_putc(unsigned char ch)
|
|
|
|
{
|
|
|
|
unsigned timeout = 0xffff;
|
|
|
|
while ((inb(early_serial_base + LSR) & XMTRDY) == 0 && --timeout)
|
2005-04-17 00:20:36 +02:00
|
|
|
cpu_relax();
|
|
|
|
outb(ch, early_serial_base + TXR);
|
|
|
|
return timeout ? 0 : -1;
|
2006-03-24 12:18:05 +01:00
|
|
|
}
|
2005-04-17 00:20:36 +02:00
|
|
|
|
|
|
|
static void early_serial_write(struct console *con, const char *s, unsigned n)
|
|
|
|
{
|
2006-03-24 12:18:05 +01:00
|
|
|
while (*s && n-- > 0) {
|
|
|
|
early_serial_putc(*s);
|
|
|
|
if (*s == '\n')
|
|
|
|
early_serial_putc('\r');
|
|
|
|
s++;
|
|
|
|
}
|
|
|
|
}
|
2005-04-17 00:20:36 +02:00
|
|
|
|
|
|
|
#define DEFAULT_BAUD 9600
|
|
|
|
|
|
|
|
static __init void early_serial_init(char *s)
|
|
|
|
{
|
2006-03-24 12:18:05 +01:00
|
|
|
unsigned char c;
|
2005-04-17 00:20:36 +02:00
|
|
|
unsigned divisor;
|
|
|
|
unsigned baud = DEFAULT_BAUD;
|
|
|
|
char *e;
|
|
|
|
|
|
|
|
if (*s == ',')
|
|
|
|
++s;
|
|
|
|
|
|
|
|
if (*s) {
|
2006-03-24 12:18:05 +01:00
|
|
|
unsigned port;
|
2005-04-17 00:20:36 +02:00
|
|
|
if (!strncmp(s,"0x",2)) {
|
|
|
|
early_serial_base = simple_strtoul(s, &e, 16);
|
|
|
|
} else {
|
|
|
|
static int bases[] = { 0x3f8, 0x2f8 };
|
|
|
|
|
|
|
|
if (!strncmp(s,"ttyS",4))
|
|
|
|
s += 4;
|
|
|
|
port = simple_strtoul(s, &e, 10);
|
|
|
|
if (port > 1 || s == e)
|
|
|
|
port = 0;
|
|
|
|
early_serial_base = bases[port];
|
|
|
|
}
|
|
|
|
s += strcspn(s, ",");
|
|
|
|
if (*s == ',')
|
|
|
|
s++;
|
|
|
|
}
|
|
|
|
|
|
|
|
outb(0x3, early_serial_base + LCR); /* 8n1 */
|
|
|
|
outb(0, early_serial_base + IER); /* no interrupt */
|
|
|
|
outb(0, early_serial_base + FCR); /* no fifo */
|
|
|
|
outb(0x3, early_serial_base + MCR); /* DTR + RTS */
|
|
|
|
|
|
|
|
if (*s) {
|
2006-03-24 12:18:05 +01:00
|
|
|
baud = simple_strtoul(s, &e, 0);
|
|
|
|
if (baud == 0 || s == e)
|
2005-04-17 00:20:36 +02:00
|
|
|
baud = DEFAULT_BAUD;
|
2006-03-24 12:18:05 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
divisor = 115200 / baud;
|
|
|
|
c = inb(early_serial_base + LCR);
|
|
|
|
outb(c | DLAB, early_serial_base + LCR);
|
|
|
|
outb(divisor & 0xff, early_serial_base + DLL);
|
|
|
|
outb((divisor >> 8) & 0xff, early_serial_base + DLH);
|
2005-04-17 00:20:36 +02:00
|
|
|
outb(c & ~DLAB, early_serial_base + LCR);
|
|
|
|
}
|
|
|
|
|
|
|
|
static struct console early_serial_console = {
|
|
|
|
.name = "earlyser",
|
|
|
|
.write = early_serial_write,
|
|
|
|
.flags = CON_PRINTBUFFER,
|
|
|
|
.index = -1,
|
|
|
|
};
|
|
|
|
|
2005-09-12 18:49:24 +02:00
|
|
|
/* Console interface to a host file on AMD's SimNow! */
|
|
|
|
|
|
|
|
static int simnow_fd;
|
|
|
|
|
|
|
|
enum {
|
|
|
|
MAGIC1 = 0xBACCD00A,
|
|
|
|
MAGIC2 = 0xCA110000,
|
|
|
|
XOPEN = 5,
|
|
|
|
XWRITE = 4,
|
|
|
|
};
|
|
|
|
|
|
|
|
static noinline long simnow(long cmd, long a, long b, long c)
|
|
|
|
{
|
|
|
|
long ret;
|
|
|
|
asm volatile("cpuid" :
|
|
|
|
"=a" (ret) :
|
|
|
|
"b" (a), "c" (b), "d" (c), "0" (MAGIC1), "D" (cmd + MAGIC2));
|
|
|
|
return ret;
|
|
|
|
}
|
|
|
|
|
|
|
|
void __init simnow_init(char *str)
|
|
|
|
{
|
|
|
|
char *fn = "klog";
|
|
|
|
if (*str == '=')
|
|
|
|
fn = ++str;
|
|
|
|
/* error ignored */
|
|
|
|
simnow_fd = simnow(XOPEN, (unsigned long)fn, O_WRONLY|O_APPEND|O_CREAT, 0644);
|
|
|
|
}
|
|
|
|
|
|
|
|
static void simnow_write(struct console *con, const char *s, unsigned n)
|
|
|
|
{
|
|
|
|
simnow(XWRITE, simnow_fd, (unsigned long)s, n);
|
|
|
|
}
|
|
|
|
|
|
|
|
static struct console simnow_console = {
|
|
|
|
.name = "simnow",
|
|
|
|
.write = simnow_write,
|
|
|
|
.flags = CON_PRINTBUFFER,
|
|
|
|
.index = -1,
|
|
|
|
};
|
|
|
|
|
2005-04-17 00:20:36 +02:00
|
|
|
/* Direct interface for emergencies */
|
|
|
|
struct console *early_console = &early_vga_console;
|
|
|
|
static int early_console_initialized = 0;
|
|
|
|
|
|
|
|
void early_printk(const char *fmt, ...)
|
2006-03-24 12:18:05 +01:00
|
|
|
{
|
|
|
|
char buf[512];
|
|
|
|
int n;
|
2005-04-17 00:20:36 +02:00
|
|
|
va_list ap;
|
|
|
|
|
2006-03-24 12:18:05 +01:00
|
|
|
va_start(ap,fmt);
|
2005-04-17 00:20:36 +02:00
|
|
|
n = vscnprintf(buf,512,fmt,ap);
|
|
|
|
early_console->write(early_console,buf,n);
|
2006-03-24 12:18:05 +01:00
|
|
|
va_end(ap);
|
|
|
|
}
|
2005-04-17 00:20:36 +02:00
|
|
|
|
2006-01-11 22:47:03 +01:00
|
|
|
static int __initdata keep_early;
|
2005-04-17 00:20:36 +02:00
|
|
|
|
2006-09-26 10:52:32 +02:00
|
|
|
static int __init setup_early_printk(char *buf)
|
2006-03-24 12:18:05 +01:00
|
|
|
{
|
2006-09-26 10:52:32 +02:00
|
|
|
if (!buf)
|
|
|
|
return 0;
|
2005-04-17 00:20:36 +02:00
|
|
|
|
|
|
|
if (early_console_initialized)
|
2006-09-26 10:52:32 +02:00
|
|
|
return 0;
|
|
|
|
early_console_initialized = 1;
|
2005-04-17 00:20:36 +02:00
|
|
|
|
2006-09-26 10:52:32 +02:00
|
|
|
if (!strcmp(buf,"keep"))
|
2006-03-24 12:18:05 +01:00
|
|
|
keep_early = 1;
|
2005-04-17 00:20:36 +02:00
|
|
|
|
2006-03-24 12:18:05 +01:00
|
|
|
if (!strncmp(buf, "serial", 6)) {
|
2005-04-17 00:20:36 +02:00
|
|
|
early_serial_init(buf + 6);
|
|
|
|
early_console = &early_serial_console;
|
2006-03-24 12:18:05 +01:00
|
|
|
} else if (!strncmp(buf, "ttyS", 4)) {
|
2005-04-17 00:20:36 +02:00
|
|
|
early_serial_init(buf);
|
2006-03-24 12:18:05 +01:00
|
|
|
early_console = &early_serial_console;
|
2005-06-23 09:08:24 +02:00
|
|
|
} else if (!strncmp(buf, "vga", 3)
|
|
|
|
&& SCREEN_INFO.orig_video_isVGA == 1) {
|
|
|
|
max_xpos = SCREEN_INFO.orig_video_cols;
|
|
|
|
max_ypos = SCREEN_INFO.orig_video_lines;
|
2006-03-23 11:59:42 +01:00
|
|
|
current_ypos = SCREEN_INFO.orig_y;
|
2006-03-24 12:18:05 +01:00
|
|
|
early_console = &early_vga_console;
|
2005-09-12 18:49:24 +02:00
|
|
|
} else if (!strncmp(buf, "simnow", 6)) {
|
|
|
|
simnow_init(buf + 6);
|
|
|
|
early_console = &simnow_console;
|
|
|
|
keep_early = 1;
|
2005-04-17 00:20:36 +02:00
|
|
|
}
|
2006-03-24 12:18:05 +01:00
|
|
|
register_console(early_console);
|
2005-04-17 00:20:36 +02:00
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
2006-09-26 10:52:32 +02:00
|
|
|
early_param("earlyprintk", setup_early_printk);
|
|
|
|
|
2005-04-17 00:20:36 +02:00
|
|
|
void __init disable_early_printk(void)
|
2006-03-24 12:18:05 +01:00
|
|
|
{
|
2005-04-17 00:20:36 +02:00
|
|
|
if (!early_console_initialized || !early_console)
|
|
|
|
return;
|
|
|
|
if (!keep_early) {
|
|
|
|
printk("disabling early console\n");
|
|
|
|
unregister_console(early_console);
|
|
|
|
early_console_initialized = 0;
|
2006-03-24 12:18:05 +01:00
|
|
|
} else {
|
2005-04-17 00:20:36 +02:00
|
|
|
printk("keeping early console\n");
|
|
|
|
}
|
2006-03-24 12:18:05 +01:00
|
|
|
}
|
2005-04-17 00:20:36 +02:00
|
|
|
|