From 16ce01b0d8414a7250fcf142a966ff22c153e85f Mon Sep 17 00:00:00 2001 From: Stefan Reinauer Date: Fri, 28 Jan 2011 08:05:54 +0000 Subject: This patch gets usbdebug console working in romstage. - actually hook up usbdebug in printk/print_ for romstage - make usbdebug.c more similar to the Linux kernel version it was originally derived from. - increase retries and timing for usbdebug init (at least one chipset seems to need this) - src/pc80/usbdebug_serial.c is not needed - some small console cleanups Signed-off-by: Stefan Reinauer Acked-by: Patrick Georgi git-svn-id: svn://svn.coreboot.org/coreboot/trunk@6315 2b7e53f0-3cfb-0310-b3e9-8179ed1497e1 --- src/arch/x86/lib/printk_init.c | 21 ++-- src/include/console/console.h | 4 +- src/include/usbdebug.h | 14 +-- src/lib/Makefile.inc | 2 + src/lib/usbdebug.c | 219 ++++++++++++++++++++++++----------------- src/pc80/Makefile.inc | 1 - src/pc80/usbdebug_serial.c | 57 ----------- 7 files changed, 151 insertions(+), 167 deletions(-) delete mode 100644 src/pc80/usbdebug_serial.c (limited to 'src') diff --git a/src/arch/x86/lib/printk_init.c b/src/arch/x86/lib/printk_init.c index 2f7f751832..e8a926356e 100644 --- a/src/arch/x86/lib/printk_init.c +++ b/src/arch/x86/lib/printk_init.c @@ -19,23 +19,30 @@ #include #include +#if CONFIG_CONSOLE_SERIAL8250 #include - +#endif +#if CONFIG_USBDEBUG +#include +#endif #if CONFIG_CONSOLE_NE2K #include #endif static void console_tx_byte(unsigned char byte) { -#if CONFIG_CONSOLE_NE2K -#ifdef __PRE_RAM__ - ne2k_append_data(&byte, 1, CONFIG_CONSOLE_NE2K_IO_PORT); -#endif -#endif if (byte == '\n') - uart8250_tx_byte(CONFIG_TTYS0_BASE, '\r'); + console_tx_byte('\r'); +#if CONFIG_CONSOLE_SERIAL8250 uart8250_tx_byte(CONFIG_TTYS0_BASE, byte); +#endif +#if CONFIG_USBDEBUG + usbdebug_tx_byte(byte); +#endif +#if CONFIG_CONSOLE_NE2K + ne2k_append_data(&byte, 1, CONFIG_CONSOLE_NE2K_IO_PORT); +#endif } int do_printk(int msg_level, const char *fmt, ...) diff --git a/src/include/console/console.h b/src/include/console/console.h index b2811e4547..004ff44bca 100644 --- a/src/include/console/console.h +++ b/src/include/console/console.h @@ -149,6 +149,7 @@ int do_printk(int msg_level, const char *fmt, ...) __attribute__((format(printf, #define print_info_hex32(HEX) printk(BIOS_INFO, "%08x", (HEX)) #define print_debug_hex32(HEX) printk(BIOS_DEBUG, "%08x", (HEX)) #define print_spew_hex32(HEX) printk(BIOS_SPEW, "%08x", (HEX)) + #else /* __ROMCC__ */ @@ -357,9 +358,6 @@ static void print_spew(const char *str) { __console_tx_string(BIOS_SPEW, str); } #define print_spew_hex32(HEX) __console_tx_hex32(BIOS_SPEW, HEX) #endif -#endif - -#ifdef __ROMCC__ /* if included by romcc, include the sources, too. romcc can't use prototypes */ #include #include diff --git a/src/include/usbdebug.h b/src/include/usbdebug.h index 710675f4d4..281ccde826 100644 --- a/src/include/usbdebug.h +++ b/src/include/usbdebug.h @@ -27,22 +27,18 @@ struct ehci_debug_info { void *ehci_caps; void *ehci_regs; void *ehci_debug; - unsigned devnum; - unsigned endpoint_out; - unsigned endpoint_in; + u32 devnum; + u32 endpoint_out; + u32 endpoint_in; }; int dbgp_bulk_write_x(struct ehci_debug_info *dbg_info, const char *bytes, int size); int dbgp_bulk_read_x(struct ehci_debug_info *dbg_info, void *data, int size); -int dbgp_control_msg(struct ehci_dbg_port *ehci_debug, unsigned devnum, int requesttype, int request, - int value, int index, void *data, int size); -int ehci_wait_for_port(struct ehci_regs *ehci_regs, int port); void set_ehci_base(unsigned ehci_base); -void set_ehci_debug(unsigned ehci_deug); +void set_ehci_debug(unsigned ehci_debug); unsigned get_ehci_debug(void); void set_debug_port(unsigned port); -void early_usbdebug_init(void); -void usbdebug_ram_tx_byte(unsigned char data); +int early_usbdebug_init(void); void usbdebug_tx_byte(unsigned char data); #endif diff --git a/src/lib/Makefile.inc b/src/lib/Makefile.inc index d5e76ade1d..307423dba4 100644 --- a/src/lib/Makefile.inc +++ b/src/lib/Makefile.inc @@ -26,8 +26,10 @@ romstage-$(CONFIG_CACHE_AS_RAM) += ramtest.c #romstage-y += lzmadecode.c romstage-$(CONFIG_CONSOLE_NE2K) += ne2k.c romstage-$(CONFIG_CONSOLE_NE2K) += compute_ip_checksum.c + driver-$(CONFIG_CONSOLE_NE2K) += ne2k.c +romstage-$(CONFIG_USBDEBUG) += usbdebug.c ramstage-$(CONFIG_USBDEBUG) += usbdebug.c ramstage-$(CONFIG_BOOTSPLASH) += jpeg.c diff --git a/src/lib/usbdebug.c b/src/lib/usbdebug.c index c108fa3d3f..d022d2f345 100644 --- a/src/lib/usbdebug.c +++ b/src/lib/usbdebug.c @@ -2,6 +2,7 @@ * This file is part of the coreboot project. * * Copyright (C) 2006 Eric Biederman (ebiederm@xmission.com) + * Copyright (C) 2007 AMD * * 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 @@ -17,20 +18,24 @@ * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA, 02110-1301 USA */ -#if !defined(__ROMCC__) +#include #include -#else -#if CONFIG_CACHE_AS_RAM==0 -#define printk(BIOS_DEBUG, fmt, arg...) do {} while(0) -#endif -#endif - #include +#include #include #include #include +// Does not work if we want early printk to do usb debug, too.. +#define DBGP_DEBUG 0 +#if DBGP_DEBUG +# define dbgp_printk(fmt_arg...) printk(BIOS_DEBUG, fmt_arg) +#else +#define dbgp_printk(fmt_arg...) do {} while(0) +#endif + + #define USB_DEBUG_DEVNUM 127 #define DBGP_DATA_TOGGLE 0x8800 @@ -78,16 +83,18 @@ static int dbgp_wait_until_complete(struct ehci_dbg_port *ehci_debug) { - unsigned ctrl; + u32 ctrl; int loop = 0x100000; + do { ctrl = read32((unsigned long)&ehci_debug->control); /* Stop when the transaction is finished */ if (ctrl & DBGP_DONE) break; - } while(--loop>0); + } while (--loop > 0); - if (!loop) return -1000; + if (!loop) + return -1; /* Now that we have observed the completed transaction, * clear the done bit. @@ -96,15 +103,6 @@ static int dbgp_wait_until_complete(struct ehci_dbg_port *ehci_debug) return (ctrl & DBGP_ERROR) ? -DBGP_ERRCODE(ctrl) : DBGP_LEN(ctrl); } -static void dbgp_mdelay(int ms) -{ - int i; - while (ms--) { - for (i = 0; i < 1000; i++) - inb(0x80); - } -} - static void dbgp_breath(void) { /* Sleep to give the debug port a chance to breathe */ @@ -112,10 +110,10 @@ static void dbgp_breath(void) static int dbgp_wait_until_done(struct ehci_dbg_port *ehci_debug, unsigned ctrl) { - unsigned pids, lpid; + u32 pids, lpid; int ret; - int loop = 3; + retry: write32((unsigned long)&ehci_debug->control, ctrl | DBGP_GO); ret = dbgp_wait_until_complete(ehci_debug); @@ -133,7 +131,8 @@ retry: /* If I get a NACK reissue the transmission */ if (lpid == USB_PID_NAK) { - if (--loop > 0) goto retry; + if (--loop > 0) + goto retry; } return ret; @@ -142,8 +141,9 @@ retry: static void dbgp_set_data(struct ehci_dbg_port *ehci_debug, const void *buf, int size) { const unsigned char *bytes = buf; - unsigned lo, hi; + u32 lo, hi; int i; + lo = hi = 0; for (i = 0; i < 4 && i < size; i++) lo |= bytes[i] << (8*i); @@ -156,8 +156,9 @@ static void dbgp_set_data(struct ehci_dbg_port *ehci_debug, const void *buf, int static void dbgp_get_data(struct ehci_dbg_port *ehci_debug, void *buf, int size) { unsigned char *bytes = buf; - unsigned lo, hi; + u32 lo, hi; int i; + lo = read32((unsigned long)&ehci_debug->data03); hi = read32((unsigned long)&ehci_debug->data47); for (i = 0; i < 4 && i < size; i++) @@ -166,10 +167,12 @@ static void dbgp_get_data(struct ehci_dbg_port *ehci_debug, void *buf, int size) bytes[i] = (hi >> (8*(i - 4))) & 0xff; } -static int dbgp_bulk_write(struct ehci_dbg_port *ehci_debug, unsigned devnum, unsigned endpoint, const char *bytes, int size) +static int dbgp_bulk_write(struct ehci_dbg_port *ehci_debug, + unsigned devnum, unsigned endpoint, const char *bytes, int size) { - unsigned pids, addr, ctrl; + u32 pids, addr, ctrl; int ret; + if (size > DBGP_MAX_PACKET) return -1; @@ -188,20 +191,20 @@ static int dbgp_bulk_write(struct ehci_dbg_port *ehci_debug, unsigned devnum, un write32((unsigned long)&ehci_debug->pids, pids); ret = dbgp_wait_until_done(ehci_debug, ctrl); - if (ret < 0) { - return ret; - } + return ret; } int dbgp_bulk_write_x(struct ehci_debug_info *dbg_info, const char *bytes, int size) { - return dbgp_bulk_write(dbg_info->ehci_debug, dbg_info->devnum, dbg_info->endpoint_out, bytes, size); + return dbgp_bulk_write(dbg_info->ehci_debug, dbg_info->devnum, + dbg_info->endpoint_out, bytes, size); } -static int dbgp_bulk_read(struct ehci_dbg_port *ehci_debug, unsigned devnum, unsigned endpoint, void *data, int size) +static int dbgp_bulk_read(struct ehci_dbg_port *ehci_debug, unsigned devnum, + unsigned endpoint, void *data, int size) { - unsigned pids, addr, ctrl; + u32 pids, addr, ctrl; int ret; if (size > DBGP_MAX_PACKET) @@ -222,34 +225,48 @@ static int dbgp_bulk_read(struct ehci_dbg_port *ehci_debug, unsigned devnum, uns ret = dbgp_wait_until_done(ehci_debug, ctrl); if (ret < 0) return ret; + if (size > ret) size = ret; dbgp_get_data(ehci_debug, data, size); return ret; } + int dbgp_bulk_read_x(struct ehci_debug_info *dbg_info, void *data, int size) { - return dbgp_bulk_read(dbg_info->ehci_debug, dbg_info->devnum, dbg_info->endpoint_in, data, size); + return dbgp_bulk_read(dbg_info->ehci_debug, dbg_info->devnum, + dbg_info->endpoint_in, data, size); +} + +#ifdef __PRE_RAM__ +static void dbgp_mdelay(int ms) +{ + int i; + + while (ms--) { + for (i = 0; i < 1000; i++) + inb(0x80); + } } -int dbgp_control_msg(struct ehci_dbg_port *ehci_debug, unsigned devnum, int requesttype, int request, - int value, int index, void *data, int size) +static int dbgp_control_msg(struct ehci_dbg_port *ehci_debug, unsigned devnum, int requesttype, + int request, int value, int index, void *data, int size) { - unsigned pids, addr, ctrl; + u32 pids, addr, ctrl; struct usb_ctrlrequest req; int read; int ret; read = (requesttype & USB_DIR_IN) != 0; - if (size > (read?DBGP_MAX_PACKET:0)) + if (size > (read ? DBGP_MAX_PACKET:0)) return -1; /* Compute the control message */ req.bRequestType = requesttype; req.bRequest = request; - req.wValue = value; - req.wIndex = index; - req.wLength = size; + req.wValue = cpu_to_le16(value); + req.wIndex = cpu_to_le16(index); + req.wLength = cpu_to_le16(size); pids = DBGP_PID_SET(USB_PID_DATA0, USB_PID_SETUP); addr = DBGP_EPADDR(devnum, 0); @@ -275,8 +292,8 @@ int dbgp_control_msg(struct ehci_dbg_port *ehci_debug, unsigned devnum, int requ static int ehci_reset_port(struct ehci_regs *ehci_regs, int port) { - unsigned portsc; - unsigned delay_time, delay_ms; + u32 portsc; + u32 delay_time, delay_ms; int loop; /* Reset the usb debug port */ @@ -308,23 +325,24 @@ static int ehci_reset_port(struct ehci_regs *ehci_regs, int port) /* Device went away? */ if (!(portsc & PORT_CONNECT)) - return -107;//-ENOTCONN; + return -1; //-ENOTCONN; /* bomb out completely if something weird happend */ if ((portsc & PORT_CSC)) - return -22;//-EINVAL; + return -2; //-EINVAL; /* If we've finished resetting, then break out of the loop */ if (!(portsc & PORT_RESET) && (portsc & PORT_PE)) return 0; } - return -16;//-EBUSY; + return -3; //-EBUSY; } -int ehci_wait_for_port(struct ehci_regs *ehci_regs, int port) +static int ehci_wait_for_port(struct ehci_regs *ehci_regs, int port) { - unsigned status; + u32 status; int ret, reps; + for (reps = 0; reps < 3; reps++) { dbgp_mdelay(100); status = read32((unsigned long)&ehci_regs->status); @@ -334,44 +352,33 @@ int ehci_wait_for_port(struct ehci_regs *ehci_regs, int port) return 0; } } - return -107; //-ENOTCONN; + return -1; //-ENOTCONN; } -#define DBGP_DEBUG 1 -#if DBGP_DEBUG -# define dbgp_printk(fmt_arg...) printk(BIOS_DEBUG, fmt_arg) -#else -#define dbgp_printk(fmt_arg...) do {} while(0) -#endif - -#ifdef __PRE_RAM__ -static void usbdebug_init(unsigned ehci_bar, unsigned offset, struct ehci_debug_info *info) +static int usbdebug_init(unsigned ehci_bar, unsigned offset, struct ehci_debug_info *info) { struct ehci_caps *ehci_caps; struct ehci_regs *ehci_regs; struct ehci_dbg_port *ehci_debug; unsigned dbgp_endpoint_out; unsigned dbgp_endpoint_in; + struct usb_debug_descriptor dbgp_desc; - unsigned ctrl, devnum; - int ret; + u32 cmd, ctrl, status, portsc, hcs_params; + u32 debug_port, new_debug_port = 0, n_ports; + u32 devnum; + int ret, i; int loop; - - unsigned cmd, status, portsc, hcs_params, debug_port, n_ports, new_debug_port; - int i; - unsigned port_map_tried; - - unsigned playtimes = 3; + int port_map_tried; + int playtimes = 3; ehci_caps = (struct ehci_caps *)ehci_bar; - ehci_regs = (struct ehci_regs *)(ehci_bar + HC_LENGTH(read32((unsigned long)&ehci_caps->hc_capbase))); + ehci_regs = (struct ehci_regs *)(ehci_bar + + HC_LENGTH(read32((unsigned long)&ehci_caps->hc_capbase))); ehci_debug = (struct ehci_dbg_port *)(ehci_bar + offset); - info->ehci_debug = (void *)0; - new_debug_port = 0; - try_next_time: port_map_tried = 0; @@ -384,34 +391,36 @@ try_next_port: dbgp_printk("debug_port: %d\n", debug_port); dbgp_printk("n_ports: %d\n", n_ports); -#if 1 for (i = 1; i <= n_ports; i++) { portsc = read32((unsigned long)&ehci_regs->port_status[i-1]); dbgp_printk("PORTSC #%d: %08x\n", i, portsc); } -#endif - if(port_map_tried && (new_debug_port!=debug_port)) { + if(port_map_tried && (new_debug_port != debug_port)) { if(--playtimes) { set_debug_port(debug_port); goto try_next_time; } - return; + return -1; } + loop = 100; /* Reset the EHCI controller */ - loop = 10; cmd = read32((unsigned long)&ehci_regs->command); cmd |= CMD_RESET; write32((unsigned long)&ehci_regs->command, cmd); do { + dbgp_mdelay(10); cmd = read32((unsigned long)&ehci_regs->command); } while ((cmd & CMD_RESET) && (--loop > 0)); - if(!loop) + if(!loop) { dbgp_printk("Could not reset EHCI controller.\n"); - else + // on some systems it works without succeeding here. + // return -2; + } else { dbgp_printk("EHCI controller reset successfully.\n"); + } /* Claim ownership, but do not enable yet */ ctrl = read32((unsigned long)&ehci_debug->control); @@ -419,7 +428,7 @@ try_next_port: ctrl &= ~(DBGP_ENABLED | DBGP_INUSE); write32((unsigned long)&ehci_debug->control, ctrl); - /* Start the ehci running */ + /* Start EHCI controller */ cmd = read32((unsigned long)&ehci_regs->command); cmd &= ~(CMD_LRESET | CMD_IAAD | CMD_PSE | CMD_ASE | CMD_RESET); cmd |= CMD_RUN; @@ -431,12 +440,13 @@ try_next_port: /* Wait until the controller is no longer halted */ loop = 10; do { + dbgp_mdelay(10); status = read32((unsigned long)&ehci_regs->status); - } while ((status & STS_HALT) && (--loop>0)); + } while ((status & STS_HALT) && (--loop > 0)); if(!loop) { dbgp_printk("EHCI could not be started.\n"); - return; + return -3; } dbgp_printk("EHCI started.\n"); @@ -456,6 +466,7 @@ try_next_port: if ((ctrl & DBGP_CLAIM) != DBGP_CLAIM) { dbgp_printk("No device in EHCI debug port.\n"); write32((unsigned long)&ehci_debug->control, ctrl & ~DBGP_CLAIM); + ret = -4; goto err; } dbgp_printk("EHCI debug port enabled.\n"); @@ -478,10 +489,12 @@ try_next_port: } if (devnum > 127) { dbgp_printk("Could not find attached debug device.\n"); + ret = -5; goto err; } if (ret < 0) { dbgp_printk("Attached device is not a debug device.\n"); + ret = -6; goto err; } dbgp_endpoint_out = dbgp_desc.bDebugOutEndpoint; @@ -491,10 +504,11 @@ try_next_port: if (devnum != USB_DEBUG_DEVNUM) { ret = dbgp_control_msg(ehci_debug, devnum, USB_DIR_OUT | USB_TYPE_STANDARD | USB_RECIP_DEVICE, - USB_REQ_SET_ADDRESS, USB_DEBUG_DEVNUM, 0, (void *)0, 0); + USB_REQ_SET_ADDRESS, USB_DEBUG_DEVNUM, 0, NULL, 0); if (ret < 0) { dbgp_printk("Could not move attached device to %d.\n", USB_DEBUG_DEVNUM); + ret = -7; goto err; } devnum = USB_DEBUG_DEVNUM; @@ -504,18 +518,19 @@ try_next_port: /* Enable the debug interface */ ret = dbgp_control_msg(ehci_debug, USB_DEBUG_DEVNUM, USB_DIR_OUT | USB_TYPE_STANDARD | USB_RECIP_DEVICE, - USB_REQ_SET_FEATURE, USB_DEVICE_DEBUG_MODE, 0, (void *)0, 0); + USB_REQ_SET_FEATURE, USB_DEVICE_DEBUG_MODE, 0, NULL, 0); if (ret < 0) { dbgp_printk("Could not enable EHCI debug device.\n"); + ret = -8; goto err; } dbgp_printk("EHCI debug interface enabled.\n"); - /* Perform a small write to get the even/odd data state in sync - */ - ret = dbgp_bulk_write(ehci_debug, USB_DEBUG_DEVNUM, dbgp_endpoint_out, " ",1); + /* Perform a small write to get the even/odd data state in sync */ + ret = dbgp_bulk_write(ehci_debug, USB_DEBUG_DEVNUM, dbgp_endpoint_out, "USB\r\n",5); if (ret < 0) { dbgp_printk("dbgp_bulk_write failed: %d\n", ret); + ret = -9; goto err; } dbgp_printk("Test write done\n"); @@ -527,26 +542,50 @@ try_next_port: info->endpoint_out = dbgp_endpoint_out; info->endpoint_in = dbgp_endpoint_in; - return; + return 0; err: /* Things didn't work so remove my claim */ ctrl = read32((unsigned long)&ehci_debug->control); ctrl &= ~(DBGP_CLAIM | DBGP_OUT); write32((unsigned long)(unsigned long)&ehci_debug->control, ctrl); + //return ret; next_debug_port: - port_map_tried |= (1<<(debug_port-1)); - if(port_map_tried != ((1<ehci_debug) { + dbgp_bulk_write_x(dbg_info, (char*)&data, 1); + } +} +#endif diff --git a/src/pc80/Makefile.inc b/src/pc80/Makefile.inc index 0dc78bb6d0..659d2e225a 100644 --- a/src/pc80/Makefile.inc +++ b/src/pc80/Makefile.inc @@ -5,7 +5,6 @@ ramstage-$(CONFIG_UDELAY_IO) += udelay_io.c ramstage-y += keyboard.c romstage-$(CONFIG_USE_OPTION_TABLE) += mc146818rtc_early.c -romstage-$(CONFIG_USBDEBUG) += usbdebug_serial.c subdirs-y += vga $(obj)/pc80/mc146818rtc.ramstage.o : $(OPTION_TABLE_H) diff --git a/src/pc80/usbdebug_serial.c b/src/pc80/usbdebug_serial.c deleted file mode 100644 index a330ea6695..0000000000 --- a/src/pc80/usbdebug_serial.c +++ /dev/null @@ -1,57 +0,0 @@ -/* - * This file is part of the coreboot project. - * - * Copyright (C) 2007 AMD - * Written by Yinghai Lu for AMD. - * - * 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 "../lib/usbdebug.c" -#include -#include - -void early_usbdebug_init(void) -{ - struct ehci_debug_info *dbg_info = (struct ehci_debug_info *) - (CONFIG_DCACHE_RAM_BASE + CONFIG_DCACHE_RAM_SIZE - sizeof(struct ehci_debug_info)); - - usbdebug_init(CONFIG_EHCI_BAR, CONFIG_EHCI_DEBUG_OFFSET, dbg_info); -} - -void usbdebug_tx_byte(unsigned char data) -{ - struct ehci_debug_info *dbg_info; - - /* "Find" dbg_info structure in Cache */ - dbg_info = (struct ehci_debug_info *) - (CONFIG_DCACHE_RAM_BASE + CONFIG_DCACHE_RAM_SIZE - sizeof(struct ehci_debug_info)); - - if (dbg_info->ehci_debug) { - dbgp_bulk_write_x(dbg_info, (char*)&data, 1); - } -} - -void usbdebug_ram_tx_byte(unsigned char data) -{ - struct ehci_debug_info *dbg_info; - - /* "Find" dbg_info structure in RAM */ - dbg_info = (struct ehci_debug_info *) - ((CONFIG_RAMTOP) - sizeof(struct ehci_debug_info)); - - if (dbg_info->ehci_debug) { - dbgp_bulk_write_x(dbg_info, (char*)&data, 1); - } -} -- cgit v1.2.3