diff options
author | Kyösti Mälkki <kyosti.malkki@gmail.com> | 2017-09-07 19:16:27 +0300 |
---|---|---|
committer | Kyösti Mälkki <kyosti.malkki@gmail.com> | 2017-09-14 12:26:18 +0000 |
commit | d07f377872d1d229a8a9cc1d4a2c66f535e95fe3 (patch) | |
tree | 622725e971f7cb800e202f601db5741da40a4a22 /src | |
parent | 08231833232d9cf80072e77c3f039a303bd6ffbb (diff) |
usbdebug: Fix init and add support for postcar
It was originally designed such that if usbdebug_init() was called
before cbmem_initialize(), it would fetch the already-initialized
state from CBMEM. This changed when cbmem_find() behaviour changed
to require cbmem_initialize() to be called first. As a result,
ramstage had to reinitialize all of the EHCI controller and USB
endpoints on entry. This was slow, specially with AMD hardware
where one can scan USB ports to probe for the debug dongle.
For postcar and ramstage, move usbdebug entry such that it is
triggered from CBMEM_INIT_HOOK instead of console_init().
Side-effect of this is usbdebug console shows 'coreboot-xxx ...
starting...' line only for romstage.
Initialisation for usbdebug is never done in postcar. If you have
USBDEBUG_IN_ROMSTAGE=n, postcar will not have console output on
usb either.
While at it, fix also some other __PRE_RAM__ cases to ENV_ROMSTAGE
and alike.
Change-Id: If8ab973321a801abc5529f3ff68c5dccae9512ad
Signed-off-by: Kyösti Mälkki <kyosti.malkki@gmail.com>
Reviewed-on: https://review.coreboot.org/21443
Tested-by: build bot (Jenkins) <no-reply@coreboot.org>
Reviewed-by: Aaron Durbin <adurbin@chromium.org>
Diffstat (limited to 'src')
-rw-r--r-- | src/drivers/usb/Makefile.inc | 1 | ||||
-rw-r--r-- | src/drivers/usb/ehci_debug.c | 81 | ||||
-rw-r--r-- | src/drivers/usb/pci_ehci.c | 4 | ||||
-rw-r--r-- | src/include/console/usb.h | 3 |
4 files changed, 55 insertions, 34 deletions
diff --git a/src/drivers/usb/Makefile.inc b/src/drivers/usb/Makefile.inc index ff9a12462b..6c46f045a5 100644 --- a/src/drivers/usb/Makefile.inc +++ b/src/drivers/usb/Makefile.inc @@ -1,3 +1,4 @@ romstage-$(CONFIG_USBDEBUG_IN_ROMSTAGE) += ehci_debug.c pci_ehci.c console.c gadget.c +postcar-$(CONFIG_USBDEBUG_IN_ROMSTAGE) += ehci_debug.c console.c ramstage-$(CONFIG_USBDEBUG) += ehci_debug.c pci_ehci.c console.c gadget.c diff --git a/src/drivers/usb/ehci_debug.c b/src/drivers/usb/ehci_debug.c index 9491a8ffbe..fcc52230c9 100644 --- a/src/drivers/usb/ehci_debug.c +++ b/src/drivers/usb/ehci_debug.c @@ -599,13 +599,11 @@ next_debug_port: return -10; } -#if IS_ENABLED(CONFIG_DEBUG_USBDEBUG) static int dbgp_enabled(void) { struct dbgp_pipe *globals = &dbgp_ehci_info()->ep_pipe[DBGP_SETUP_EP0]; return (globals->status & DBGP_EP_ENABLED); } -#endif int dbgp_try_get(struct dbgp_pipe *pipe) { @@ -624,7 +622,7 @@ void dbgp_put(struct dbgp_pipe *pipe) pipe->status &= ~DBGP_EP_BUSY; } -#if !defined(__PRE_RAM__) && !defined(__SMM__) +#if ENV_RAMSTAGE void usbdebug_re_enable(unsigned ehci_base) { struct ehci_debug_info *dbg_info = dbgp_ehci_info(); @@ -650,36 +648,55 @@ void usbdebug_disable(void) #endif -#if !defined(__PRE_RAM__) && !defined(__SMM__) -static int get_usbdebug_from_cbmem(struct ehci_debug_info *info) +static int usbdebug_hw_init(void) { - struct ehci_debug_info *dbg_info_cbmem; + struct ehci_debug_info *dbg_info = dbgp_ehci_info(); + unsigned int ehci_base, dbg_offset; - dbg_info_cbmem = cbmem_find(CBMEM_ID_EHCI_DEBUG); - if (dbg_info_cbmem == NULL) + if (ehci_debug_hw_enable(&ehci_base, &dbg_offset)) return -1; - - memcpy(info, dbg_info_cbmem, sizeof (*info)); - printk(BIOS_DEBUG, "EHCI debug port found in CBMEM.\n"); - - return 0; + return usbdebug_init_(ehci_base, dbg_offset, dbg_info); } -#elif defined(__PRE_RAM__) static void migrate_ehci_debug(int is_recovery) { - struct ehci_debug_info *dbg_info = dbgp_ehci_info(); struct ehci_debug_info *dbg_info_cbmem; - - dbg_info_cbmem = cbmem_add(CBMEM_ID_EHCI_DEBUG, sizeof(*dbg_info)); - if (dbg_info_cbmem == NULL) + int rv; + + if (ENV_ROMSTAGE) { + /* Move state from CAR to CBMEM. */ + struct ehci_debug_info *dbg_info = dbgp_ehci_info(); + dbg_info_cbmem = cbmem_add(CBMEM_ID_EHCI_DEBUG, + sizeof(*dbg_info)); + if (dbg_info_cbmem == NULL) + return; + memcpy(dbg_info_cbmem, dbg_info, sizeof(*dbg_info)); + car_set_var(glob_dbg_info_p, dbg_info_cbmem); return; + } + + if (IS_ENABLED(CONFIG_USBDEBUG_IN_ROMSTAGE)) { + /* Use state in CBMEM. */ + dbg_info_cbmem = cbmem_find(CBMEM_ID_EHCI_DEBUG); + if (dbg_info_cbmem) + car_set_var(glob_dbg_info_p, dbg_info_cbmem); + } + + /* Redo full init in ramstage if state claims we + * are still not enabled. Should never happen. */ + rv = dbgp_enabled() ? 0 : -1; + if (!ENV_POSTCAR && rv < 0) + rv = usbdebug_hw_init(); - memcpy(dbg_info_cbmem, dbg_info, sizeof(*dbg_info)); - car_set_var(glob_dbg_info_p, dbg_info_cbmem); + if (rv < 0) + printk(BIOS_DEBUG, "usbdebug: Failed hardware init\n"); + else + printk(BIOS_DEBUG, "usbdebug: " ENV_STRING " starting...\n"); } + ROMSTAGE_CBMEM_INIT_HOOK(migrate_ehci_debug); -#endif +POSTCAR_CBMEM_INIT_HOOK(migrate_ehci_debug); +RAMSTAGE_CBMEM_INIT_HOOK(migrate_ehci_debug); int dbgp_ep_is_active(struct dbgp_pipe *pipe) { @@ -696,16 +713,18 @@ struct dbgp_pipe *dbgp_console_input(void) return &dbgp_ehci_info()->ep_pipe[DBGP_CONSOLE_EPIN]; } -int usbdebug_init(void) +void usbdebug_init(void) { - struct ehci_debug_info *dbg_info = dbgp_ehci_info(); - unsigned int ehci_base, dbg_offset; + /* USB console init is done early in romstage, yet delayed to + * CBMEM_INIT_HOOKs for postcar and ramstage as we recover state + * from CBMEM. + */ + if (IS_ENABLED(CONFIG_USBDEBUG_IN_ROMSTAGE) && ENV_ROMSTAGE) + usbdebug_hw_init(); -#if !defined(__PRE_RAM__) && !defined(__SMM__) - if (!get_usbdebug_from_cbmem(dbg_info)) - return 0; -#endif - if (ehci_debug_hw_enable(&ehci_base, &dbg_offset)) - return -1; - return usbdebug_init_(ehci_base, dbg_offset, dbg_info); + /* USB console init is done early in ramstage if it was + * not done in romstage, this does not require CBMEM. + */ + if (!IS_ENABLED(CONFIG_USBDEBUG_IN_ROMSTAGE) && ENV_RAMSTAGE) + usbdebug_hw_init(); } diff --git a/src/drivers/usb/pci_ehci.c b/src/drivers/usb/pci_ehci.c index 73c709cdd8..3bdeeebadc 100644 --- a/src/drivers/usb/pci_ehci.c +++ b/src/drivers/usb/pci_ehci.c @@ -25,7 +25,7 @@ #include "ehci_debug.h" #include "ehci.h" -#if !defined(__PRE_RAM__) && !defined(__SMM__) +#if ENV_RAMSTAGE static struct device_operations *ehci_drv_ops; static struct device_operations ehci_dbg_ops; #endif @@ -81,7 +81,7 @@ void ehci_debug_select_port(unsigned int port) pci_ehci_dbg_set_port(dbg_dev, port); } -#if !defined(__PRE_RAM__) && !defined(__SMM__) +#if ENV_RAMSTAGE static void pci_ehci_set_resources(struct device *dev) { struct resource *res; diff --git a/src/include/console/usb.h b/src/include/console/usb.h index c67144d039..78956d7936 100644 --- a/src/include/console/usb.h +++ b/src/include/console/usb.h @@ -20,7 +20,7 @@ #include <rules.h> #include <stdint.h> -int usbdebug_init(void); +void usbdebug_init(void); void usb_tx_byte(int idx, unsigned char data); void usb_tx_flush(int idx); @@ -29,6 +29,7 @@ int usb_can_rx_byte(int idx); #define __CONSOLE_USB_ENABLE__ (IS_ENABLED(CONFIG_CONSOLE_USB) && \ ((ENV_ROMSTAGE && IS_ENABLED(CONFIG_USBDEBUG_IN_ROMSTAGE)) || \ + (ENV_POSTCAR && IS_ENABLED(CONFIG_USBDEBUG_IN_ROMSTAGE)) || \ ENV_RAMSTAGE)) #define USB_PIPE_FOR_CONSOLE 0 |