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>
This commit is contained in:
Kyösti Mälkki 2017-09-07 19:16:27 +03:00
parent 0823183323
commit d07f377872
4 changed files with 62 additions and 41 deletions

View File

@ -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

View File

@ -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)
{
struct ehci_debug_info *dbg_info_cbmem;
dbg_info_cbmem = cbmem_find(CBMEM_ID_EHCI_DEBUG);
if (dbg_info_cbmem == NULL)
return -1;
memcpy(info, dbg_info_cbmem, sizeof (*info));
printk(BIOS_DEBUG, "EHCI debug port found in CBMEM.\n");
return 0;
}
#elif defined(__PRE_RAM__)
static void migrate_ehci_debug(int is_recovery)
static int usbdebug_hw_init(void)
{
struct ehci_debug_info *dbg_info = dbgp_ehci_info();
struct ehci_debug_info *dbg_info_cbmem;
unsigned int ehci_base, dbg_offset;
dbg_info_cbmem = cbmem_add(CBMEM_ID_EHCI_DEBUG, sizeof(*dbg_info));
if (ehci_debug_hw_enable(&ehci_base, &dbg_offset))
return -1;
return usbdebug_init_(ehci_base, dbg_offset, dbg_info);
}
static void migrate_ehci_debug(int is_recovery)
{
struct ehci_debug_info *dbg_info_cbmem;
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();
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();
}

View File

@ -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;

View File

@ -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