mirror of
https://gitlab.com/qemu-project/openbios.git
synced 2024-02-13 08:34:06 +08:00
Move serial console functions to obio.c
git-svn-id: svn://coreboot.org/openbios/openbios-devel@317 f158a5a8-5612-0410-a976-696ce0be7e32
This commit is contained in:
@@ -12,124 +12,6 @@
|
|||||||
|
|
||||||
#ifdef CONFIG_DEBUG_CONSOLE
|
#ifdef CONFIG_DEBUG_CONSOLE
|
||||||
|
|
||||||
/* ******************************************************************
|
|
||||||
* serial console functions
|
|
||||||
* ****************************************************************** */
|
|
||||||
|
|
||||||
#ifdef CONFIG_DEBUG_CONSOLE_SERIAL
|
|
||||||
|
|
||||||
static volatile unsigned char *kbd_dev, *serial_dev;
|
|
||||||
|
|
||||||
#define CTRL(port) serial_dev[(port) * 2 + 0]
|
|
||||||
#define DATA(port) serial_dev[(port) * 2 + 2]
|
|
||||||
|
|
||||||
/* Conversion routines to/from brg time constants from/to bits
|
|
||||||
* per second.
|
|
||||||
*/
|
|
||||||
#define BRG_TO_BPS(brg, freq) ((freq) / 2 / ((brg) + 2))
|
|
||||||
#define BPS_TO_BRG(bps, freq) ((((freq) + (bps)) / (2 * (bps))) - 2)
|
|
||||||
|
|
||||||
#define ZS_CLOCK 4915200 /* Zilog input clock rate. */
|
|
||||||
#define ZS_CLOCK_DIVISOR 16 /* Divisor this driver uses. */
|
|
||||||
|
|
||||||
/* Write Register 3 */
|
|
||||||
#define RxENAB 0x1 /* Rx Enable */
|
|
||||||
#define Rx8 0xc0 /* Rx 8 Bits/Character */
|
|
||||||
|
|
||||||
/* Write Register 4 */
|
|
||||||
#define SB1 0x4 /* 1 stop bit/char */
|
|
||||||
#define X16CLK 0x40 /* x16 clock mode */
|
|
||||||
|
|
||||||
/* Write Register 5 */
|
|
||||||
#define RTS 0x2 /* RTS */
|
|
||||||
#define TxENAB 0x8 /* Tx Enable */
|
|
||||||
#define Tx8 0x60 /* Tx 8 bits/character */
|
|
||||||
#define DTR 0x80 /* DTR */
|
|
||||||
|
|
||||||
/* Write Register 14 (Misc control bits) */
|
|
||||||
#define BRENAB 1 /* Baud rate generator enable */
|
|
||||||
#define BRSRC 2 /* Baud rate generator source */
|
|
||||||
|
|
||||||
/* Read Register 0 */
|
|
||||||
#define Rx_CH_AV 0x1 /* Rx Character Available */
|
|
||||||
|
|
||||||
static int uart_charav(int port)
|
|
||||||
{
|
|
||||||
return ((CTRL(port) & Rx_CH_AV) != 0);
|
|
||||||
}
|
|
||||||
|
|
||||||
static char uart_getchar(int port)
|
|
||||||
{
|
|
||||||
while (!uart_charav(port))
|
|
||||||
;
|
|
||||||
return DATA(port) & 0177;
|
|
||||||
}
|
|
||||||
|
|
||||||
static void uart_putchar(int port, unsigned char c)
|
|
||||||
{
|
|
||||||
if (!serial_dev)
|
|
||||||
return;
|
|
||||||
|
|
||||||
if (c == '\n')
|
|
||||||
uart_putchar(port, '\r');
|
|
||||||
while (!(CTRL(port) & 4))
|
|
||||||
;
|
|
||||||
DATA(port) = c;
|
|
||||||
}
|
|
||||||
|
|
||||||
static void uart_init_line(int port, unsigned long baud)
|
|
||||||
{
|
|
||||||
CTRL(port) = 4; // reg 4
|
|
||||||
CTRL(port) = SB1 | X16CLK; // no parity, async, 1 stop bit, 16x
|
|
||||||
// clock
|
|
||||||
|
|
||||||
baud = BPS_TO_BRG(baud, ZS_CLOCK / ZS_CLOCK_DIVISOR);
|
|
||||||
|
|
||||||
CTRL(port) = 12; // reg 12
|
|
||||||
CTRL(port) = baud & 0xff;
|
|
||||||
CTRL(port) = 13; // reg 13
|
|
||||||
CTRL(port) = (baud >> 8) & 0xff;
|
|
||||||
CTRL(port) = 14; // reg 14
|
|
||||||
CTRL(port) = BRSRC | BRENAB;
|
|
||||||
|
|
||||||
CTRL(port) = 3; // reg 3
|
|
||||||
CTRL(port) = RxENAB | Rx8; // enable rx, 8 bits/char
|
|
||||||
|
|
||||||
CTRL(port) = 5; // reg 5
|
|
||||||
CTRL(port) = RTS | TxENAB | Tx8 | DTR; // enable tx, 8 bits/char,
|
|
||||||
// set RTS & DTR
|
|
||||||
|
|
||||||
}
|
|
||||||
|
|
||||||
int uart_init(uint64_t port, unsigned long speed)
|
|
||||||
{
|
|
||||||
int line;
|
|
||||||
|
|
||||||
serial_dev = map_io(port & ~7ULL, 2 * 4);
|
|
||||||
serial_dev += port & 7ULL;
|
|
||||||
line = port & 3ULL;
|
|
||||||
uart_init_line(line, speed);
|
|
||||||
|
|
||||||
return -1;
|
|
||||||
}
|
|
||||||
|
|
||||||
static void serial_putchar(int c)
|
|
||||||
{
|
|
||||||
uart_putchar(CONFIG_SERIAL_PORT, (unsigned char) (c & 0xff));
|
|
||||||
}
|
|
||||||
|
|
||||||
static void serial_cls(void)
|
|
||||||
{
|
|
||||||
serial_putchar(27);
|
|
||||||
serial_putchar('[');
|
|
||||||
serial_putchar('H');
|
|
||||||
serial_putchar(27);
|
|
||||||
serial_putchar('[');
|
|
||||||
serial_putchar('J');
|
|
||||||
}
|
|
||||||
|
|
||||||
#endif
|
|
||||||
|
|
||||||
/* ******************************************************************
|
/* ******************************************************************
|
||||||
* simple polling video/keyboard console functions
|
* simple polling video/keyboard console functions
|
||||||
* ****************************************************************** */
|
* ****************************************************************** */
|
||||||
@@ -175,79 +57,6 @@ void tcx_init(uint64_t base)
|
|||||||
console_init();
|
console_init();
|
||||||
}
|
}
|
||||||
|
|
||||||
void kbd_init(uint64_t base)
|
|
||||||
{
|
|
||||||
kbd_dev = map_io(base, 2 * 4);
|
|
||||||
kbd_dev += 4;
|
|
||||||
}
|
|
||||||
|
|
||||||
static const unsigned char sunkbd_keycode[128] = {
|
|
||||||
0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
|
|
||||||
0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
|
|
||||||
'1', '2', '3', '4', '5', '6', '7', '8', '9', '0', '-', '=', 0, 8,
|
|
||||||
0, 0, 0, 0, 0, 0, 0, 0, 0, 9,
|
|
||||||
'q', 'w', 'e', 'r', 't', 'y', 'u', 'i', 'o', 'p', '[', ']',
|
|
||||||
0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
|
|
||||||
'a', 's', 'd', 'f', 'g', 'h', 'j', 'k', 'l', ';', '\'', '\\', 13,
|
|
||||||
0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
|
|
||||||
'z', 'x', 'c', 'v', 'b', 'n', 'm', ',', '.', '/',
|
|
||||||
0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
|
|
||||||
' ',
|
|
||||||
};
|
|
||||||
|
|
||||||
static const unsigned char sunkbd_keycode_shifted[128] = {
|
|
||||||
0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
|
|
||||||
0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
|
|
||||||
'!', '@', '#', '$', '%', '^', '&', '*', '(', ')', '_', '+', 0, 8,
|
|
||||||
0, 0, 0, 0, 0, 0, 0, 0, 0, 9,
|
|
||||||
'Q', 'W', 'E', 'R', 'T', 'Y', 'U', 'I', 'O', 'P', '{', '}',
|
|
||||||
0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
|
|
||||||
'A', 'S', 'D', 'F', 'G', 'H', 'J', 'K', 'L', ':', '"', '|', 13,
|
|
||||||
0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
|
|
||||||
'Z', 'X', 'C', 'V', 'B', 'N', 'M', '<', '>', '?',
|
|
||||||
0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
|
|
||||||
' ',
|
|
||||||
};
|
|
||||||
|
|
||||||
static int shiftstate;
|
|
||||||
|
|
||||||
int
|
|
||||||
keyboard_dataready(void)
|
|
||||||
{
|
|
||||||
return ((kbd_dev[0] & 1) == 1);
|
|
||||||
}
|
|
||||||
|
|
||||||
unsigned char
|
|
||||||
keyboard_readdata(void)
|
|
||||||
{
|
|
||||||
unsigned char ch;
|
|
||||||
|
|
||||||
while (!keyboard_dataready()) { }
|
|
||||||
|
|
||||||
do {
|
|
||||||
ch = kbd_dev[2] & 0xff;
|
|
||||||
if (ch == 99)
|
|
||||||
shiftstate |= 1;
|
|
||||||
else if (ch == 110)
|
|
||||||
shiftstate |= 2;
|
|
||||||
else if (ch == 227)
|
|
||||||
shiftstate &= ~1;
|
|
||||||
else if (ch == 238)
|
|
||||||
shiftstate &= ~2;
|
|
||||||
//printk("getch: %d\n", ch);
|
|
||||||
}
|
|
||||||
while ((ch & 0x80) == 0 || ch == 238 || ch == 227); // Wait for key release
|
|
||||||
//printk("getch rel: %d\n", ch);
|
|
||||||
ch &= 0x7f;
|
|
||||||
if (shiftstate)
|
|
||||||
ch = sunkbd_keycode_shifted[ch];
|
|
||||||
else
|
|
||||||
ch = sunkbd_keycode[ch];
|
|
||||||
//printk("getch xlate: %d\n", ch);
|
|
||||||
|
|
||||||
return ch;
|
|
||||||
}
|
|
||||||
|
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
/* ******************************************************************
|
/* ******************************************************************
|
||||||
|
|||||||
@@ -22,7 +22,6 @@ int openbios(void);
|
|||||||
/* console.c */
|
/* console.c */
|
||||||
extern unsigned char *vmem;
|
extern unsigned char *vmem;
|
||||||
#ifdef CONFIG_DEBUG_CONSOLE
|
#ifdef CONFIG_DEBUG_CONSOLE
|
||||||
extern int uart_init(uint64_t port, unsigned long speed);
|
|
||||||
extern void video_init(void);
|
extern void video_init(void);
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
|
|||||||
181
drivers/obio.c
181
drivers/obio.c
@@ -111,33 +111,119 @@ ob_intr(int intr)
|
|||||||
fword("property");
|
fword("property");
|
||||||
}
|
}
|
||||||
|
|
||||||
// XXX move all arch/sparc32/console.c stuff here
|
/* ******************************************************************
|
||||||
#define CTRL(addr) (*(char *)(addr))
|
* serial console functions
|
||||||
#define DATA(addr) (*(char *)(addr + 2))
|
* ****************************************************************** */
|
||||||
|
|
||||||
|
static volatile unsigned char *kbd_dev, *serial_dev;
|
||||||
|
|
||||||
|
#define CTRL(port) serial_dev[(port) * 2 + 0]
|
||||||
|
#define DATA(port) serial_dev[(port) * 2 + 2]
|
||||||
|
|
||||||
|
/* Conversion routines to/from brg time constants from/to bits
|
||||||
|
* per second.
|
||||||
|
*/
|
||||||
|
#define BRG_TO_BPS(brg, freq) ((freq) / 2 / ((brg) + 2))
|
||||||
|
#define BPS_TO_BRG(bps, freq) ((((freq) + (bps)) / (2 * (bps))) - 2)
|
||||||
|
|
||||||
|
#define ZS_CLOCK 4915200 /* Zilog input clock rate. */
|
||||||
|
#define ZS_CLOCK_DIVISOR 16 /* Divisor this driver uses. */
|
||||||
|
|
||||||
|
/* Write Register 3 */
|
||||||
|
#define RxENAB 0x1 /* Rx Enable */
|
||||||
|
#define Rx8 0xc0 /* Rx 8 Bits/Character */
|
||||||
|
|
||||||
|
/* Write Register 4 */
|
||||||
|
#define SB1 0x4 /* 1 stop bit/char */
|
||||||
|
#define X16CLK 0x40 /* x16 clock mode */
|
||||||
|
|
||||||
|
/* Write Register 5 */
|
||||||
|
#define RTS 0x2 /* RTS */
|
||||||
|
#define TxENAB 0x8 /* Tx Enable */
|
||||||
|
#define Tx8 0x60 /* Tx 8 bits/character */
|
||||||
|
#define DTR 0x80 /* DTR */
|
||||||
|
|
||||||
|
/* Write Register 14 (Misc control bits) */
|
||||||
|
#define BRENAB 1 /* Baud rate generator enable */
|
||||||
|
#define BRSRC 2 /* Baud rate generator source */
|
||||||
|
|
||||||
/* Read Register 0 */
|
/* Read Register 0 */
|
||||||
#define Rx_CH_AV 0x1 /* Rx Character Available */
|
#define Rx_CH_AV 0x1 /* Rx Character Available */
|
||||||
#define Tx_BUF_EMP 0x4 /* Tx Buffer empty */
|
#define Tx_BUF_EMP 0x4 /* Tx Buffer empty */
|
||||||
|
|
||||||
static int uart_charav(int port)
|
int uart_charav(int port)
|
||||||
{
|
{
|
||||||
return (CTRL(port) & Rx_CH_AV) != 0;
|
return (CTRL(port) & Rx_CH_AV) != 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
static char uart_getchar(int port)
|
char uart_getchar(int port)
|
||||||
{
|
{
|
||||||
while (!uart_charav(port));
|
while (!uart_charav(port))
|
||||||
|
;
|
||||||
return DATA(port) & 0177;
|
return DATA(port) & 0177;
|
||||||
}
|
}
|
||||||
|
|
||||||
static void uart_putchar(int port, unsigned char c)
|
static void uart_putchar(int port, unsigned char c)
|
||||||
{
|
{
|
||||||
if (c == '\n')
|
if (!serial_dev)
|
||||||
uart_putchar(port, '\r');
|
return;
|
||||||
while (!(CTRL(port) & Tx_BUF_EMP));
|
|
||||||
|
|
||||||
DATA(port) = c;
|
if (c == '\n')
|
||||||
|
uart_putchar(port, '\r');
|
||||||
|
while (!(CTRL(port) & Tx_BUF_EMP))
|
||||||
|
;
|
||||||
|
DATA(port) = c;
|
||||||
|
}
|
||||||
|
|
||||||
|
static void uart_init_line(int port, unsigned long baud)
|
||||||
|
{
|
||||||
|
CTRL(port) = 4; // reg 4
|
||||||
|
CTRL(port) = SB1 | X16CLK; // no parity, async, 1 stop bit, 16x
|
||||||
|
// clock
|
||||||
|
|
||||||
|
baud = BPS_TO_BRG(baud, ZS_CLOCK / ZS_CLOCK_DIVISOR);
|
||||||
|
|
||||||
|
CTRL(port) = 12; // reg 12
|
||||||
|
CTRL(port) = baud & 0xff;
|
||||||
|
CTRL(port) = 13; // reg 13
|
||||||
|
CTRL(port) = (baud >> 8) & 0xff;
|
||||||
|
CTRL(port) = 14; // reg 14
|
||||||
|
CTRL(port) = BRSRC | BRENAB;
|
||||||
|
|
||||||
|
CTRL(port) = 3; // reg 3
|
||||||
|
CTRL(port) = RxENAB | Rx8; // enable rx, 8 bits/char
|
||||||
|
|
||||||
|
CTRL(port) = 5; // reg 5
|
||||||
|
CTRL(port) = RTS | TxENAB | Tx8 | DTR; // enable tx, 8 bits/char,
|
||||||
|
// set RTS & DTR
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
int uart_init(uint64_t port, unsigned long speed)
|
||||||
|
{
|
||||||
|
int line;
|
||||||
|
|
||||||
|
serial_dev = map_io(port & ~7ULL, 2 * 4);
|
||||||
|
serial_dev += port & 7ULL;
|
||||||
|
line = port & 3ULL;
|
||||||
|
uart_init_line(line, speed);
|
||||||
|
|
||||||
|
return -1;
|
||||||
|
}
|
||||||
|
|
||||||
|
void serial_putchar(int c)
|
||||||
|
{
|
||||||
|
uart_putchar(CONFIG_SERIAL_PORT, (unsigned char) (c & 0xff));
|
||||||
|
}
|
||||||
|
|
||||||
|
void serial_cls(void)
|
||||||
|
{
|
||||||
|
serial_putchar(27);
|
||||||
|
serial_putchar('[');
|
||||||
|
serial_putchar('H');
|
||||||
|
serial_putchar(27);
|
||||||
|
serial_putchar('[');
|
||||||
|
serial_putchar('J');
|
||||||
}
|
}
|
||||||
|
|
||||||
/* ( addr len -- actual ) */
|
/* ( addr len -- actual ) */
|
||||||
@@ -161,6 +247,79 @@ zs_read(unsigned long *address)
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void kbd_init(uint64_t base)
|
||||||
|
{
|
||||||
|
kbd_dev = map_io(base, 2 * 4);
|
||||||
|
kbd_dev += 4;
|
||||||
|
}
|
||||||
|
|
||||||
|
static const unsigned char sunkbd_keycode[128] = {
|
||||||
|
0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
|
||||||
|
0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
|
||||||
|
'1', '2', '3', '4', '5', '6', '7', '8', '9', '0', '-', '=', 0, 8,
|
||||||
|
0, 0, 0, 0, 0, 0, 0, 0, 0, 9,
|
||||||
|
'q', 'w', 'e', 'r', 't', 'y', 'u', 'i', 'o', 'p', '[', ']',
|
||||||
|
0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
|
||||||
|
'a', 's', 'd', 'f', 'g', 'h', 'j', 'k', 'l', ';', '\'', '\\', 13,
|
||||||
|
0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
|
||||||
|
'z', 'x', 'c', 'v', 'b', 'n', 'm', ',', '.', '/',
|
||||||
|
0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
|
||||||
|
' ',
|
||||||
|
};
|
||||||
|
|
||||||
|
static const unsigned char sunkbd_keycode_shifted[128] = {
|
||||||
|
0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
|
||||||
|
0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
|
||||||
|
'!', '@', '#', '$', '%', '^', '&', '*', '(', ')', '_', '+', 0, 8,
|
||||||
|
0, 0, 0, 0, 0, 0, 0, 0, 0, 9,
|
||||||
|
'Q', 'W', 'E', 'R', 'T', 'Y', 'U', 'I', 'O', 'P', '{', '}',
|
||||||
|
0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
|
||||||
|
'A', 'S', 'D', 'F', 'G', 'H', 'J', 'K', 'L', ':', '"', '|', 13,
|
||||||
|
0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
|
||||||
|
'Z', 'X', 'C', 'V', 'B', 'N', 'M', '<', '>', '?',
|
||||||
|
0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
|
||||||
|
' ',
|
||||||
|
};
|
||||||
|
|
||||||
|
static int shiftstate;
|
||||||
|
|
||||||
|
int
|
||||||
|
keyboard_dataready(void)
|
||||||
|
{
|
||||||
|
return ((kbd_dev[0] & 1) == 1);
|
||||||
|
}
|
||||||
|
|
||||||
|
unsigned char
|
||||||
|
keyboard_readdata(void)
|
||||||
|
{
|
||||||
|
unsigned char ch;
|
||||||
|
|
||||||
|
while (!keyboard_dataready()) { }
|
||||||
|
|
||||||
|
do {
|
||||||
|
ch = kbd_dev[2] & 0xff;
|
||||||
|
if (ch == 99)
|
||||||
|
shiftstate |= 1;
|
||||||
|
else if (ch == 110)
|
||||||
|
shiftstate |= 2;
|
||||||
|
else if (ch == 227)
|
||||||
|
shiftstate &= ~1;
|
||||||
|
else if (ch == 238)
|
||||||
|
shiftstate &= ~2;
|
||||||
|
//printk("getch: %d\n", ch);
|
||||||
|
}
|
||||||
|
while ((ch & 0x80) == 0 || ch == 238 || ch == 227); // Wait for key release
|
||||||
|
//printk("getch rel: %d\n", ch);
|
||||||
|
ch &= 0x7f;
|
||||||
|
if (shiftstate)
|
||||||
|
ch = sunkbd_keycode_shifted[ch];
|
||||||
|
else
|
||||||
|
ch = sunkbd_keycode[ch];
|
||||||
|
//printk("getch xlate: %d\n", ch);
|
||||||
|
|
||||||
|
return ch;
|
||||||
|
}
|
||||||
|
|
||||||
/* ( addr len -- actual ) */
|
/* ( addr len -- actual ) */
|
||||||
static void
|
static void
|
||||||
zs_read_keyboard(void)
|
zs_read_keyboard(void)
|
||||||
|
|||||||
@@ -59,6 +59,11 @@ int ob_obio_init(uint64_t slavio_base, unsigned long fd_offset,
|
|||||||
unsigned long aux1_offset, unsigned long aux2_offset);
|
unsigned long aux1_offset, unsigned long aux2_offset);
|
||||||
int start_cpu(unsigned int pc, unsigned int context_ptr, unsigned int context,
|
int start_cpu(unsigned int pc, unsigned int context_ptr, unsigned int context,
|
||||||
int cpu);
|
int cpu);
|
||||||
|
void serial_putchar(int c);
|
||||||
|
int uart_charav(int port);
|
||||||
|
char uart_getchar(int port);
|
||||||
|
void serial_cls(void);
|
||||||
|
int uart_init(uint64_t port, unsigned long speed);
|
||||||
|
|
||||||
/* drivers/iommu.c */
|
/* drivers/iommu.c */
|
||||||
extern struct mem cmem;
|
extern struct mem cmem;
|
||||||
|
|||||||
Reference in New Issue
Block a user