Kyösti Mälkki (kyosti.malkki@gmail.com) just uploaded a new patch set to gerrit, which you can find at http://review.coreboot.org/3625
-gerrit
commit 133f0200ee178d5ffd24d89b8f3fbd237738707f Author: Kyösti Mälkki kyosti.malkki@gmail.com Date: Sat Jul 6 11:56:49 2013 +0300
usbdebug: Move ehci_debug_info allocation
Move ehci_debug_info allocation from console to lib, as console code was only built for ramstage.
Implement dbgp_ehci_info() to return the EHCI context. Alias this as dbgp_console_pipe() to return the console stream context.
Change-Id: Id6cc07d62953f0466df61eeb159e22b0e3287d4e Signed-off-by: Kyösti Mälkki kyosti.malkki@gmail.com --- src/arch/x86/lib/romstage_console.c | 4 +-- src/console/console.c | 3 +- src/console/usbdebug_console.c | 30 +++++++++--------- src/include/usbdebug.h | 5 +-- src/lib/usbdebug.c | 47 +++++++++++++++-------------- src/northbridge/intel/sandybridge/raminit.c | 2 +- 6 files changed, 46 insertions(+), 45 deletions(-)
diff --git a/src/arch/x86/lib/romstage_console.c b/src/arch/x86/lib/romstage_console.c index 2013bb7..7b581e2 100644 --- a/src/arch/x86/lib/romstage_console.c +++ b/src/arch/x86/lib/romstage_console.c @@ -48,7 +48,7 @@ void console_tx_byte(unsigned char byte) uart8250_tx_byte(CONFIG_TTYS0_BASE, byte); #endif #if CONFIG_USBDEBUG - usbdebug_tx_byte(0, byte); + usbdebug_tx_byte(dbgp_console_pipe(), byte); #endif #if CONFIG_CONSOLE_NE2K ne2k_append_data(&byte, 1, CONFIG_CONSOLE_NE2K_IO_PORT); @@ -73,7 +73,7 @@ void console_tx_flush(void) ne2k_transmit(CONFIG_CONSOLE_NE2K_IO_PORT); #endif #if CONFIG_USBDEBUG - usbdebug_tx_flush(0); + usbdebug_tx_flush(dbgp_console_pipe()); #endif }
diff --git a/src/console/console.c b/src/console/console.c index 2f7de02..a24336b 100644 --- a/src/console/console.c +++ b/src/console/console.c @@ -104,8 +104,7 @@ void console_init(void) #if CONFIG_EARLY_CONSOLE
#if CONFIG_USBDEBUG - enable_usbdebug(CONFIG_USBDEBUG_DEFAULT_PORT); - early_usbdebug_init(); + usbdebug_init(); #endif #if CONFIG_CONSOLE_SERIAL uart_init(); diff --git a/src/console/usbdebug_console.c b/src/console/usbdebug_console.c index 3db8444..80d7bfc 100644 --- a/src/console/usbdebug_console.c +++ b/src/console/usbdebug_console.c @@ -24,27 +24,28 @@ #include <device/pci.h> #include <pc80/mc146818rtc.h>
-static struct ehci_debug_info dbg_info; static struct device_operations *ehci_drv_ops; static struct device_operations ehci_dbg_ops;
static void usbdebug_re_enable(unsigned ehci_base) { + struct ehci_debug_info *dbg_info = dbgp_ehci_info(); unsigned diff;
- if (!dbg_info.ehci_debug) + if (!dbg_info->ehci_debug) return;
diff = (unsigned)dbg_info.ehci_caps - ehci_base; - dbg_info.ehci_regs -= diff; - dbg_info.ehci_debug -= diff; - dbg_info.ehci_caps = (void*)ehci_base; - dbg_info.ehci_info = &dbg_info; + dbg_info->ehci_regs -= diff; + dbg_info->ehci_debug -= diff; + dbg_info->ehci_caps = (void*)ehci_base; + dbg_info->ehci_info = dbg_info; }
static void usbdebug_disable(void) { - dbg_info.ehci_info = NULL; + struct ehci_debug_info *dbg_info = dbgp_ehci_info(); + dbg_info->ehci_info = NULL; }
static void pci_ehci_set_resources(struct device *dev) @@ -82,35 +83,32 @@ void pci_ehci_read_resources(struct device *dev)
static void dbgp_init(void) { -#if !CONFIG_EARLY_CONSOLE - enable_usbdebug(CONFIG_USBDEBUG_DEFAULT_PORT); -#endif - usbdebug_init(CONFIG_EHCI_BAR, CONFIG_EHCI_DEBUG_OFFSET, &dbg_info); + usbdebug_init(); }
static void dbgp_tx_byte(unsigned char data) { - usbdebug_tx_byte(&dbg_info, data); + usbdebug_tx_byte(dbgp_console_pipe(), data); }
static unsigned char dbgp_rx_byte(void) { unsigned char data = 0xff;
- if (dbg_info.ehci_info) - dbgp_bulk_read_x(&dbg_info, &data, 1); + if (dbgp_console_pipe()->ehci_info) + dbgp_bulk_read_x(dbgp_console_pipe(), &data, 1);
return data; }
static void dbgp_tx_flush(void) { - usbdebug_tx_flush(&dbg_info); + usbdebug_tx_flush(dbgp_console_pipe()); }
static int dbgp_tst_byte(void) { - return (int)dbg_info.ehci_info; + return !!(int)dbgp_console_pipe()->ehci_info; }
static const struct console_driver usbdebug_direct_console __console = { diff --git a/src/include/usbdebug.h b/src/include/usbdebug.h index 9ffaf51..eaeaa72 100644 --- a/src/include/usbdebug.h +++ b/src/include/usbdebug.h @@ -57,8 +57,9 @@ void enable_usbdebug(unsigned int port); 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); void set_debug_port(unsigned port); -int early_usbdebug_init(void); +int usbdebug_init(void); +struct ehci_debug_info *dbgp_ehci_info(void); +#define dbgp_console_pipe dbgp_ehci_info void usbdebug_tx_byte(struct ehci_debug_info *info, unsigned char data); void usbdebug_tx_flush(struct ehci_debug_info *info); -int usbdebug_init(unsigned ehci_bar, unsigned offset, struct ehci_debug_info *info); #endif diff --git a/src/lib/usbdebug.c b/src/lib/usbdebug.c index a0d3387..97d083b 100644 --- a/src/lib/usbdebug.c +++ b/src/lib/usbdebug.c @@ -86,6 +86,10 @@ #define DBGP_MAX_PACKET 8 #define DBGP_LOOPS 1000
+#if !defined(__PRE_RAM__) && !defined(__SMM__) +static struct ehci_debug_info glob_dbg_info; +#endif + static int dbgp_wait_until_complete(struct ehci_dbg_port *ehci_debug) { u32 ctrl; @@ -361,8 +365,7 @@ static int ehci_wait_for_port(struct ehci_regs *ehci_regs, int port) return -1; //-ENOTCONN; }
- -int 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; @@ -575,22 +578,8 @@ next_debug_port: return -10; }
-int 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)); - - return usbdebug_init(CONFIG_EHCI_BAR, CONFIG_EHCI_DEBUG_OFFSET, dbg_info); -} - void usbdebug_tx_byte(struct ehci_debug_info *dbg_info, unsigned char data) { - if (!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_info) { dbg_info->buf[dbg_info->bufidx++] = data; if (dbg_info->bufidx >= 8) { @@ -602,14 +591,28 @@ void usbdebug_tx_byte(struct ehci_debug_info *dbg_info, unsigned char data)
void usbdebug_tx_flush(struct ehci_debug_info *dbg_info) { - if (!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_info && dbg_info->bufidx > 0) { dbgp_bulk_write_x(dbg_info, dbg_info->buf, dbg_info->bufidx); dbg_info->bufidx = 0; } } + +struct ehci_debug_info *dbgp_ehci_info(void) +{ +#if __PRE_RAM__ + /* "Find" dbg_info structure in Cache */ + return (struct ehci_debug_info *) + (CONFIG_DCACHE_RAM_BASE + CONFIG_DCACHE_RAM_SIZE - sizeof(struct ehci_debug_info)); +#else + return &glob_dbg_info; +#endif +} + +int usbdebug_init(void) +{ + struct ehci_debug_info *dbg_info = dbgp_ehci_info(); +#if defined(__PRE_RAM__) || !CONFIG_EARLY_CONSOLE + enable_usbdebug(CONFIG_USBDEBUG_DEFAULT_PORT); +#endif + return usbdebug_init_(CONFIG_EHCI_BAR, CONFIG_EHCI_DEBUG_OFFSET, dbg_info); +} diff --git a/src/northbridge/intel/sandybridge/raminit.c b/src/northbridge/intel/sandybridge/raminit.c index 78eedb8..3eb2fb3 100644 --- a/src/northbridge/intel/sandybridge/raminit.c +++ b/src/northbridge/intel/sandybridge/raminit.c @@ -278,7 +278,7 @@ void sdram_initialize(struct pei_data *pei_data)
#if CONFIG_USBDEBUG /* mrc.bin reconfigures USB, so reinit it to have debug */ - early_usbdebug_init(); + usbdebug_init(); #endif
/* For reference print the System Agent version