From b19bf330cfbaed0609b3f4794361f2c781299f53 Mon Sep 17 00:00:00 2001 From: Stefan Reinauer Date: Fri, 23 Feb 2007 13:55:28 +0000 Subject: [PATCH] * add config options for serial port and speed * add license header to console/vtxprintf.c and arch/x86/serial.c * clean out dead code from console/vtxprintf.c * adapt arch/x86/serial.c to CONFIG_ stuff * actually include config.h in CFLAGS Signed-off-by: Stefan Reinauer Acked-by: Ronald G. Minnich git-svn-id: svn://coreboot.org/repository/LinuxBIOSv3@104 f3766cd6-281f-0410-b1cd-43a5c92072e9 --- Makefile | 2 + arch/x86/cachemain.c | 11 +++- arch/x86/serial.c | 146 +++++++++++++++++-------------------------- console/Kconfig | 49 +++++++++++++++ console/vtxprintf.c | 50 +++++---------- lib/mem.c | 2 - 6 files changed, 134 insertions(+), 126 deletions(-) diff --git a/Makefile b/Makefile index df32beb6be..cbda0ad7fb 100644 --- a/Makefile +++ b/Makefile @@ -60,6 +60,8 @@ Q := @ CPPFLAGS := $(LINUXBIOSINCLUDE) +CFLAGS += $(LINUXBIOSINCLUDE) + export src obj KERNELVERSION ifeq ($(strip $(have_dotconfig)),) diff --git a/arch/x86/cachemain.c b/arch/x86/cachemain.c index f13d5019ef..e2597b627c 100644 --- a/arch/x86/cachemain.c +++ b/arch/x86/cachemain.c @@ -61,10 +61,17 @@ static void enable_rom(void) void stage1_main(u32 bist) { int ret; - struct mem_file archive; + struct mem_file archive, result; int elfboot_mem(struct lb_memory *mem, void *where, int size); /* HACK -- fake memory table for now */ - struct lb_memory mem = {LB_TAG_MEMORY, 1, .map = { {0, 32*1024*1024, LB_MEM_RAM}}}; + struct lb_memory mem = { + .tag = LB_TAG_MEMORY, + .size = 1, + .map = { + { .start = 0, .size = (32*1024*1024), .type = LB_MEM_RAM} + } + }; + struct mem_file result; post_code(0x02); diff --git a/arch/x86/serial.c b/arch/x86/serial.c index 2ad1b4f666..ec8d4d1511 100644 --- a/arch/x86/serial.c +++ b/arch/x86/serial.c @@ -1,110 +1,82 @@ +/* + * serial.c -- uart init function + * + * Copright (C) 2007 coresystems GmbH + * Copright (C) 2007 Ronald G. Minnich + * + * This program is free software; you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation; version 2 of the License. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program; if not, write to the Free Software + * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA, 02110-1301 USA + * + */ + #include -#include /* Base Address */ -#ifndef TTYS0_BASE -#define TTYS0_BASE 0x3f8 +#if defined(CONFIG_CONSOLE_SERIAL_COM1) +#define TTYSx_BASE 0x3f8 +#elif defined(CONFIG_CONSOLE_SERIAL_COM2) +#define TTYSx_BASE 0x2f8 +#else +#define TTYSx_BASE 0x3f8 +#warning no serial port set #endif -#ifndef TTYS0_BAUD -#define TTYS0_BAUD 115200 +#if defined(CONFIG_CONSOLE_SERIAL_115200) +#define TTYSx_BAUD 115200 +#elif defined(CONFIG_CONSOLE_SERIAL_57600) +#define TTYSx_BAUD 57600 +#elif defined(CONFIG_CONSOLE_SERIAL_38400) +#define TTYSx_BAUD 38400 +#elif defined(CONFIG_CONSOLE_SERIAL_19200) +#define TTYSx_BAUD 19200 +#elif defined(CONFIG_CONSOLE_SERIAL_9600) +#define TTYSx_BAUD 9600 +#else // default +#define TTYSx_BAUD 115200 +#warning no serial speed set #endif -#if ((115200%TTYS0_BAUD) != 0) +#if ((115200%TTYSx_BAUD) != 0) #error Bad ttys0 baud rate #endif -#define TTYS0_DIV (115200/TTYS0_BAUD) +#define TTYSx_DIV (115200/TTYSx_BAUD) /* Line Control Settings */ -#ifndef TTYS0_LCS +#ifndef TTYSx_LCS /* Set 8bit, 1 stop bit, no parity */ -#define TTYS0_LCS 0x3 +#define TTYSx_LCS 0x3 #endif -#define UART_LCS TTYS0_LCS +#define UART_LCS TTYSx_LCS -#if CONFIG_USE_INIT == 0 - -/* Data */ -#define UART_RBR 0x00 -#define UART_TBR 0x00 - -/* Control */ -#define UART_IER 0x01 -#define UART_IIR 0x02 -#define UART_FCR 0x02 -#define UART_LCR 0x03 -#define UART_MCR 0x04 -#define UART_DLL 0x00 -#define UART_DLM 0x01 - -/* Status */ -#define UART_LSR 0x05 -#define UART_MSR 0x06 -#define UART_SCR 0x07 - -static int uart_can_tx_byte(void) -{ - return inb(TTYS0_BASE + UART_LSR) & 0x20; -} - -static void uart_wait_to_tx_byte(void) -{ - while(!uart_can_tx_byte()) - ; -} - -static void uart_wait_until_sent(void) -{ - while(!(inb(TTYS0_BASE + UART_LSR) & 0x40)) - ; -} - -static void uart_tx_byte(unsigned char data) -{ - uart_wait_to_tx_byte(); - outb(data, TTYS0_BASE + UART_TBR); - /* Make certain the data clears the fifos */ - uart_wait_until_sent(); -} +void uart8250_init(unsigned base_port, unsigned divisor, unsigned lcs); void uart_init(void) { - /* disable interrupts */ - outb(0x0, TTYS0_BASE + UART_IER); - /* enable fifo's */ - outb(0x01, TTYS0_BASE + UART_FCR); - /* Set Baud Rate Divisor to 12 ==> 115200 Baud */ - outb(0x80 | UART_LCS, TTYS0_BASE + UART_LCR); -#if USE_OPTION_TABLE == 1 - static const unsigned char divisor[] = { 1,2,3,6,12,24,48,96 }; - unsigned ttys0_div, ttys0_index; - ttys0_index = read_option(CMOS_VSTART_baud_rate, CMOS_VLEN_baud_rate, 0); - ttys0_index &= 7; - ttys0_div = divisor[ttys0_index]; - outb(ttys0_div & 0xff, TTYS0_BASE + UART_DLL); - outb(0, TTYS0_BASE + UART_DLM); -#else - outb(TTYS0_DIV & 0xFF, TTYS0_BASE + UART_DLL); - outb((TTYS0_DIV >> 8) & 0xFF, TTYS0_BASE + UART_DLM); -#endif - outb(UART_LCS, TTYS0_BASE + UART_LCR); -} -#else -extern void uart8250_init(unsigned base_port, unsigned divisor, unsigned lcs); -void uart_init(void) -{ -#if USE_OPTION_TABLE == 1 + unsigned ttysx_div; +#if 0 + unsigned ttysx_index; static const unsigned char divisor[] = { 1,2,3,6,12,24,48,96 }; - unsigned ttys0_div, ttys0_index; - ttys0_index = read_option(CMOS_VSTART_baud_rate, CMOS_VLEN_baud_rate, 0); - ttys0_index &= 7; - ttys0_div = divisor[ttys0_index]; - uart8250_init(TTYS0_BASE, ttys0_div, UART_LCS); + + // read CMOS settings? + ttysx_index = read_option(CMOS_VSTART_baud_rate, CMOS_VLEN_baud_rate, 0); + ttysx_index &= 7; + ttysx_div = divisor[ttysx_index]; #else - uart8250_init(TTYS0_BASE, TTYS0_DIV, UART_LCS); -#endif -} + ttysx_div = TTYSx_DIV; #endif + uart8250_init(TTYSx_BASE, ttysx_div, UART_LCS); +} + diff --git a/console/Kconfig b/console/Kconfig index c8833b810e..2382e7a15d 100644 --- a/console/Kconfig +++ b/console/Kconfig @@ -10,6 +10,55 @@ config CONSOLE_SERIAL ---help--- Send LinuxBIOS output to serial console +choice + prompt "Serial console COM port" + default CONSOLE_SERIAL_COM1 + depends CONSOLE_SERIAL + +config CONSOLE_SERIAL_COM1 + bool "COM1/ttyS0" + ---help--- + Serial console on COM1. + +config CONSOLE_SERIAL_COM2 + bool "COM2/ttyS1" + ---help--- + Serial console on COM2. + +endchoice + +choice + prompt "Serial console speed" + default CONSOLE_SERIAL_115200 + depends CONSOLE_SERIAL + +config CONSOLE_SERIAL_115200 + bool "115200 bps" + ---help--- + Set speed to 115200 bps. + +config CONSOLE_SERIAL_57600 + bool "57600 bps" + ---help--- + Set speed to 57600 bps. + +config CONSOLE_SERIAL_38400 + bool "38400 bps" + ---help--- + Set speed to 38400 bps. + +config CONSOLE_SERIAL_19200 + bool "19200 bps" + ---help--- + Set speed to 19200 bps. + +config CONSOLE_SERIAL_9600 + bool "9600 bps" + ---help--- + Set speed to 9600 bps. + +endchoice + config CONSOLE_VGA boolean "Support VGA console" diff --git a/console/vtxprintf.c b/console/vtxprintf.c index 9ffc1f21dc..3d31da507f 100644 --- a/console/vtxprintf.c +++ b/console/vtxprintf.c @@ -1,3 +1,18 @@ +/* + * This program is free software; you can redistribute it and/or modify + * it under the terms of the GNU General Public License version 2 as + * published by the Free Software Foundation. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program; if not, write to the Free Software + * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA + */ + /* vtxprintf.c, from * linux/lib/vsprintf.c * @@ -6,47 +21,12 @@ #include #include - #include -/* haha, don't need ctype.c */ #define isdigit(c) ((c) >= '0' && (c) <= '9') #define is_digit isdigit #define isxdigit(c) (((c) >= '0' && (c) <= '9') || ((c) >= 'a' && (c) <= 'f') || ((c) >= 'A' && (c) <= 'F')) -static unsigned long simple_strtoul(const char *cp,char **endp,unsigned int base) -{ - unsigned long result = 0,value; - - if (!base) { - base = 10; - if (*cp == '0') { - base = 8; - cp++; - if ((*cp == 'x') && isxdigit(cp[1])) { - cp++; - base = 16; - } - } - } - while (isxdigit(*cp) && (value = isdigit(*cp) ? *cp-'0' : (islower(*cp) - ? toupper(*cp) : *cp)-'A'+10) < base) { - result = result*base + value; - cp++; - } - if (endp) - *endp = (char *)cp; - return result; -} - -static long simple_strtol(const char *cp,char **endp,unsigned int base) -{ - if(*cp=='-') - return -simple_strtoul(cp+1,endp,base); - return simple_strtoul(cp,endp,base); -} - - static int skip_atoi(const char **s) { int i=0; diff --git a/lib/mem.c b/lib/mem.c index ba4c60ca35..afe3590bbb 100644 --- a/lib/mem.c +++ b/lib/mem.c @@ -1,10 +1,8 @@ /* * mem -- simple routines that have no optimizations for anything - * * * Copright (C) 2007 Ronald G. Minnich * - * * This program is free software; you can redistribute it and/or modify * it under the terms of the GNU General Public License as published by * the Free Software Foundation; version 2 of the License.