diff options
author | Kyösti Mälkki <kyosti.malkki@gmail.com> | 2014-02-09 23:35:39 +0200 |
---|---|---|
committer | Kyösti Mälkki <kyosti.malkki@gmail.com> | 2014-02-12 21:55:56 +0100 |
commit | 8cde852ecf4dced16b342a2da31990e0caf8b92b (patch) | |
tree | f37df8457d5f2ccaca2ca959f41e2c2f45094c54 /src/drivers | |
parent | 411bf97c22dde9943b892a0969470d8b07b23e27 (diff) | |
download | coreboot-8cde852ecf4dced16b342a2da31990e0caf8b92b.tar.xz |
usbdebug: Split to USB host/device
Top-level interface to console over USB mut not require low-level
details of ECHI debug port internals.
Change-Id: If3ca3b1f479e3f20976cd4abd8f5e682a58d5650
Signed-off-by: Kyösti Mälkki <kyosti.malkki@gmail.com>
Reviewed-on: http://review.coreboot.org/5197
Tested-by: build bot (Jenkins)
Reviewed-by: Aaron Durbin <adurbin@google.com>
Diffstat (limited to 'src/drivers')
-rw-r--r-- | src/drivers/usb/Makefile.inc | 4 | ||||
-rw-r--r-- | src/drivers/usb/console.c | 64 | ||||
-rw-r--r-- | src/drivers/usb/ehci_debug.c | 63 | ||||
-rw-r--r-- | src/drivers/usb/ehci_debug.h | 22 |
4 files changed, 90 insertions, 63 deletions
diff --git a/src/drivers/usb/Makefile.inc b/src/drivers/usb/Makefile.inc index 043ebe15bb..bab6737101 100644 --- a/src/drivers/usb/Makefile.inc +++ b/src/drivers/usb/Makefile.inc @@ -1,3 +1,3 @@ -romstage-$(CONFIG_USBDEBUG_IN_ROMSTAGE) += ehci_debug.c pci_ehci.c +romstage-$(CONFIG_USBDEBUG_IN_ROMSTAGE) += ehci_debug.c pci_ehci.c console.c -ramstage-$(CONFIG_USBDEBUG) += ehci_debug.c pci_ehci.c +ramstage-$(CONFIG_USBDEBUG) += ehci_debug.c pci_ehci.c console.c diff --git a/src/drivers/usb/console.c b/src/drivers/usb/console.c new file mode 100644 index 0000000000..c47610a2a3 --- /dev/null +++ b/src/drivers/usb/console.c @@ -0,0 +1,64 @@ +/* + * 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 + * 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 <stddef.h> +#include <console/console.h> +#include <console/usb.h> +#include "ehci_debug.h" + +void usbdebug_tx_byte(struct dbgp_pipe *pipe, unsigned char data) +{ + if (!dbgp_try_get(pipe)) + return; + pipe->buf[pipe->bufidx++] = data; + if (pipe->bufidx >= 8) { + dbgp_bulk_write_x(pipe, pipe->buf, pipe->bufidx); + pipe->bufidx = 0; + } + dbgp_put(pipe); +} + +void usbdebug_tx_flush(struct dbgp_pipe *pipe) +{ + if (!dbgp_try_get(pipe)) + return; + if (pipe->bufidx > 0) { + dbgp_bulk_write_x(pipe, pipe->buf, pipe->bufidx); + pipe->bufidx = 0; + } + dbgp_put(pipe); +} + +unsigned char usbdebug_rx_byte(struct dbgp_pipe *pipe) +{ + unsigned char data = 0xff; + if (!dbgp_try_get(pipe)) + return 0xff; + while (pipe->bufidx >= pipe->buflen) { + pipe->buflen = 0; + pipe->bufidx = 0; + int count = dbgp_bulk_read_x(pipe, pipe->buf, 8); + if (count>0) + pipe->buflen = count; + } + data = pipe->buf[pipe->bufidx++]; + dbgp_put(pipe); + return data; +} diff --git a/src/drivers/usb/ehci_debug.c b/src/drivers/usb/ehci_debug.c index 26d61fbff3..b1ae27dbe9 100644 --- a/src/drivers/usb/ehci_debug.c +++ b/src/drivers/usb/ehci_debug.c @@ -31,25 +31,6 @@ #include "usb_ch9.h" #include "ehci.h" - -#define DBGP_EP_VALID (1<<0) -#define DBGP_EP_ENABLED (1<<1) -#define DBGP_EP_BUSY (1<<2) -#define DBGP_EP_STATMASK (DBGP_EP_VALID | DBGP_EP_ENABLED) - -struct dbgp_pipe -{ - u8 devnum; - u8 endpoint; - u8 pid; - u8 status; - int timeout; - - u8 bufidx; - u8 buflen; - char buf[8]; -}; - #define DBGP_MAX_ENDPOINTS 4 #define DBGP_SETUP_EP0 0 /* Compulsory endpoint 0. */ #define DBGP_CONSOLE_EPOUT 1 @@ -851,7 +832,7 @@ static int dbgp_enabled(void) } #endif -static int dbgp_try_get(struct dbgp_pipe *pipe) +int dbgp_try_get(struct dbgp_pipe *pipe) { struct dbgp_pipe *globals = &dbgp_ehci_info()->ep_pipe[DBGP_SETUP_EP0]; if (!dbgp_ep_is_active(pipe) || (globals->status & DBGP_EP_BUSY)) @@ -861,53 +842,13 @@ static int dbgp_try_get(struct dbgp_pipe *pipe) return 1; } -static void dbgp_put(struct dbgp_pipe *pipe) +void dbgp_put(struct dbgp_pipe *pipe) { struct dbgp_pipe *globals = &dbgp_ehci_info()->ep_pipe[DBGP_SETUP_EP0]; globals->status &= ~DBGP_EP_BUSY; pipe->status &= ~DBGP_EP_BUSY; } -void usbdebug_tx_byte(struct dbgp_pipe *pipe, unsigned char data) -{ - if (!dbgp_try_get(pipe)) - return; - pipe->buf[pipe->bufidx++] = data; - if (pipe->bufidx >= 8) { - dbgp_bulk_write_x(pipe, pipe->buf, pipe->bufidx); - pipe->bufidx = 0; - } - dbgp_put(pipe); -} - -void usbdebug_tx_flush(struct dbgp_pipe *pipe) -{ - if (!dbgp_try_get(pipe)) - return; - if (pipe->bufidx > 0) { - dbgp_bulk_write_x(pipe, pipe->buf, pipe->bufidx); - pipe->bufidx = 0; - } - dbgp_put(pipe); -} - -unsigned char usbdebug_rx_byte(struct dbgp_pipe *pipe) -{ - unsigned char data = 0xff; - if (!dbgp_try_get(pipe)) - return 0xff; - while (pipe->bufidx >= pipe->buflen) { - pipe->buflen = 0; - pipe->bufidx = 0; - int count = dbgp_bulk_read_x(pipe, pipe->buf, 8); - if (count>0) - pipe->buflen = count; - } - data = pipe->buf[pipe->bufidx++]; - dbgp_put(pipe); - return data; -} - #if !defined(__PRE_RAM__) && !defined(__SMM__) void usbdebug_re_enable(unsigned ehci_base) { diff --git a/src/drivers/usb/ehci_debug.h b/src/drivers/usb/ehci_debug.h index 462eb233cc..7cfac011e1 100644 --- a/src/drivers/usb/ehci_debug.h +++ b/src/drivers/usb/ehci_debug.h @@ -27,4 +27,26 @@ void usbdebug_disable(void); void ehci_debug_hw_enable(void); void ehci_debug_select_port(unsigned int port); + +#define DBGP_EP_VALID (1<<0) +#define DBGP_EP_ENABLED (1<<1) +#define DBGP_EP_BUSY (1<<2) +#define DBGP_EP_STATMASK (DBGP_EP_VALID | DBGP_EP_ENABLED) + +struct dbgp_pipe +{ + u8 devnum; + u8 endpoint; + u8 pid; + u8 status; + int timeout; + + u8 bufidx; + u8 buflen; + char buf[8]; +}; + +void dbgp_put(struct dbgp_pipe *pipe); +int dbgp_try_get(struct dbgp_pipe *pipe); + #endif /* _EHCI_DEBUG_H_ */ |