usbdebug: Refactor disable logic

Output to usbdebug console needs to be disabled until hardware is
initialized and while EHCI BAR is relocated. Add separate field
ehci_info to point to back to EHCI context when hardware is ready
to transfer data.

Change-Id: If7d441b561819ab8ae23ed9f3f320f7742ed231e
Signed-off-by: Kyösti Mälkki <kyosti.malkki@gmail.com>
Reviewed-on: http://review.coreboot.org/3624
Tested-by: build bot (Jenkins)
Reviewed-by: Aaron Durbin <adurbin@google.com>
This commit is contained in:
Kyösti Mälkki 2013-07-05 21:38:54 +03:00 committed by Stefan Reinauer
parent d686acd1a3
commit 4d409b5fc2
3 changed files with 27 additions and 28 deletions

View File

@ -28,7 +28,7 @@ static struct ehci_debug_info dbg_info;
static struct device_operations *ehci_drv_ops; static struct device_operations *ehci_drv_ops;
static struct device_operations ehci_dbg_ops; static struct device_operations ehci_dbg_ops;
void set_ehci_base(unsigned ehci_base) static void usbdebug_re_enable(unsigned ehci_base)
{ {
unsigned diff; unsigned diff;
@ -39,36 +39,28 @@ void set_ehci_base(unsigned ehci_base)
dbg_info.ehci_regs -= diff; dbg_info.ehci_regs -= diff;
dbg_info.ehci_debug -= diff; dbg_info.ehci_debug -= diff;
dbg_info.ehci_caps = (void*)ehci_base; dbg_info.ehci_caps = (void*)ehci_base;
dbg_info.status |= DBGP_EP_ENABLED;
} }
void set_ehci_debug(unsigned ehci_debug) static void usbdebug_disable(void)
{ {
dbg_info.ehci_debug = (void*)ehci_debug; dbg_info.status &= ~DBGP_EP_ENABLED;
}
unsigned get_ehci_debug(void)
{
return (unsigned)dbg_info.ehci_debug;
} }
static void pci_ehci_set_resources(struct device *dev) static void pci_ehci_set_resources(struct device *dev)
{ {
struct resource *res; struct resource *res;
u32 base;
u32 usb_debug;
printk(BIOS_DEBUG, "%s EHCI Debug Port hook triggered\n", dev_path(dev)); printk(BIOS_DEBUG, "%s EHCI Debug Port hook triggered\n", dev_path(dev));
usb_debug = get_ehci_debug(); usbdebug_disable();
set_ehci_debug(0);
if (ehci_drv_ops->set_resources) if (ehci_drv_ops->set_resources)
ehci_drv_ops->set_resources(dev); ehci_drv_ops->set_resources(dev);
res = find_resource(dev, EHCI_BAR_INDEX); res = find_resource(dev, EHCI_BAR_INDEX);
set_ehci_debug(usb_debug); if (!res)
if (!res) return; return;
base = res->base;
set_ehci_base(base); usbdebug_re_enable((u32)res->base);
report_resource_stored(dev, res, ""); report_resource_stored(dev, res, "");
printk(BIOS_DEBUG, "%s EHCI Debug Port relocated\n", dev_path(dev)); printk(BIOS_DEBUG, "%s EHCI Debug Port relocated\n", dev_path(dev));
} }
@ -105,7 +97,7 @@ static unsigned char dbgp_rx_byte(void)
{ {
unsigned char data = 0xff; unsigned char data = 0xff;
if (dbg_info.ehci_debug) if (dbgp_ep_is_active(&dbg_info))
dbgp_bulk_read_x(&dbg_info, &data, 1); dbgp_bulk_read_x(&dbg_info, &data, 1);
return data; return data;
@ -118,7 +110,7 @@ static void dbgp_tx_flush(void)
static int dbgp_tst_byte(void) static int dbgp_tst_byte(void)
{ {
return (int)dbg_info.ehci_debug; return dbgp_ep_is_active(&dbgp_info);
} }
static const struct console_driver usbdebug_direct_console __console = { static const struct console_driver usbdebug_direct_console __console = {

View File

@ -49,16 +49,20 @@ struct ehci_debug_info {
u32 endpoint_in; u32 endpoint_in;
char buf[8]; char buf[8];
u8 bufidx; u8 bufidx;
u8 status;
}; };
#define DBGP_EP_VALID (1<<0)
#define DBGP_EP_ENABLED (1<<1)
#define DBGP_EP_STATMASK (DBGP_EP_VALID | DBGP_EP_ENABLED)
void enable_usbdebug(unsigned int port); 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_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_bulk_read_x(struct ehci_debug_info *dbg_info, void *data, int size);
void set_ehci_base(unsigned ehci_base);
void set_ehci_debug(unsigned ehci_debug);
unsigned get_ehci_debug(void);
void set_debug_port(unsigned port); void set_debug_port(unsigned port);
int early_usbdebug_init(void); int early_usbdebug_init(void);
int dbgp_ep_is_active(struct ehci_debug_info *dbg_info);
void usbdebug_tx_byte(struct ehci_debug_info *info, unsigned char data); void usbdebug_tx_byte(struct ehci_debug_info *info, unsigned char data);
void usbdebug_tx_flush(struct ehci_debug_info *info); void usbdebug_tx_flush(struct ehci_debug_info *info);
int usbdebug_init(unsigned ehci_bar, unsigned offset, struct ehci_debug_info *info); int usbdebug_init(unsigned ehci_bar, unsigned offset, struct ehci_debug_info *info);

View File

@ -385,6 +385,7 @@ int usbdebug_init(unsigned ehci_bar, unsigned offset, struct ehci_debug_info *in
ehci_debug = (struct ehci_dbg_port *)(ehci_bar + offset); ehci_debug = (struct ehci_dbg_port *)(ehci_bar + offset);
info->ehci_debug = (void *)0; info->ehci_debug = (void *)0;
info->bufidx = 0; info->bufidx = 0;
info->status = 0;
try_next_time: try_next_time:
port_map_tried = 0; port_map_tried = 0;
@ -547,6 +548,7 @@ try_next_port:
info->devnum = devnum; info->devnum = devnum;
info->endpoint_out = dbgp_endpoint_out; info->endpoint_out = dbgp_endpoint_out;
info->endpoint_in = dbgp_endpoint_in; info->endpoint_in = dbgp_endpoint_in;
info->status |= DBGP_EP_ENABLED | DBGP_EP_VALID;
return 0; return 0;
err: err:
@ -582,35 +584,36 @@ int early_usbdebug_init(void)
void usbdebug_tx_byte(struct ehci_debug_info *dbg_info, unsigned char data) void usbdebug_tx_byte(struct ehci_debug_info *dbg_info, unsigned char data)
{ {
#if DBGP_DEBUG == 0
if (!dbg_info) { if (!dbg_info) {
/* "Find" dbg_info structure in Cache */ /* "Find" dbg_info structure in Cache */
dbg_info = (struct ehci_debug_info *) dbg_info = (struct ehci_debug_info *)
(CONFIG_DCACHE_RAM_BASE + CONFIG_DCACHE_RAM_SIZE - sizeof(struct ehci_debug_info)); (CONFIG_DCACHE_RAM_BASE + CONFIG_DCACHE_RAM_SIZE - sizeof(struct ehci_debug_info));
} }
if (dbg_info->ehci_debug) { if (dbgp_is_ep_active(dbg_info)) {
dbg_info->buf[dbg_info->bufidx++] = data; dbg_info->buf[dbg_info->bufidx++] = data;
if (dbg_info->bufidx >= 8) { if (dbg_info->bufidx >= 8) {
dbgp_bulk_write_x(dbg_info, dbg_info->buf, dbg_info->bufidx); dbgp_bulk_write_x(dbg_info, dbg_info->buf, dbg_info->bufidx);
dbg_info->bufidx = 0; dbg_info->bufidx = 0;
} }
} }
#endif
} }
void usbdebug_tx_flush(struct ehci_debug_info *dbg_info) void usbdebug_tx_flush(struct ehci_debug_info *dbg_info)
{ {
#if DBGP_DEBUG == 0
if (!dbg_info) { if (!dbg_info) {
/* "Find" dbg_info structure in Cache */ /* "Find" dbg_info structure in Cache */
dbg_info = (struct ehci_debug_info *) dbg_info = (struct ehci_debug_info *)
(CONFIG_DCACHE_RAM_BASE + CONFIG_DCACHE_RAM_SIZE - sizeof(struct ehci_debug_info)); (CONFIG_DCACHE_RAM_BASE + CONFIG_DCACHE_RAM_SIZE - sizeof(struct ehci_debug_info));
} }
if (dbg_info->ehci_debug && dbg_info->bufidx > 0) { if (dbgp_is_ep_active(dbg_info) && dbg_info->bufidx > 0) {
dbgp_bulk_write_x(dbg_info, dbg_info->buf, dbg_info->bufidx); dbgp_bulk_write_x(dbg_info, dbg_info->buf, dbg_info->bufidx);
dbg_info->bufidx = 0; dbg_info->bufidx = 0;
} }
#endif }
int dbgp_ep_is_active(struct ehci_debug_info *dbg_info)
{
return (dbg_info->status & DBGP_EP_STATMASK) == (DBGP_EP_VALID | DBGP_EP_ENABLED);
} }