summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorKyösti Mälkki <kyosti.malkki@gmail.com>2013-07-08 18:11:44 +0300
committerKyösti Mälkki <kyosti.malkki@gmail.com>2013-07-24 09:12:26 +0200
commit026ff3e436799b54daec8805dc574146793f4903 (patch)
tree9ae0ce9dcfb6dcbb848da6ae8fa5ab3f60cb3870
parentdcea700762bc97bd7fcabf2e960d47805129aeb1 (diff)
usbdebug: Split endpoint buffers
Refactor the structure to better support receive and another set of endpoints over usbdebug. Change-Id: Ib0f76afdf4e638363ff30c67010920142c58f250 Signed-off-by: Kyösti Mälkki <kyosti.malkki@gmail.com> Reviewed-on: http://review.coreboot.org/3726 Tested-by: build bot (Jenkins) Reviewed-by: Aaron Durbin <adurbin@google.com>
-rw-r--r--src/include/usbdebug.h31
-rw-r--r--src/lib/usbdebug.c95
2 files changed, 72 insertions, 54 deletions
diff --git a/src/include/usbdebug.h b/src/include/usbdebug.h
index 16077b0448..2728be0e4f 100644
--- a/src/include/usbdebug.h
+++ b/src/include/usbdebug.h
@@ -40,31 +40,18 @@ void pci_ehci_read_resources(struct device *dev);
#endif
#endif
-struct ehci_debug_info {
- void *ehci_caps;
- void *ehci_regs;
- void *ehci_debug;
- u32 devnum;
- u32 endpoint_out;
- u32 endpoint_in;
- char buf[8];
- 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)
+struct dbgp_pipe;
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 usbdebug_init(void);
-struct ehci_debug_info *dbgp_console_output(void);
-struct ehci_debug_info *dbgp_console_input(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_flush(struct ehci_debug_info *info);
+
+struct dbgp_pipe *dbgp_console_output(void);
+struct dbgp_pipe *dbgp_console_input(void);
+int dbgp_ep_is_active(struct dbgp_pipe *pipe);
+int dbgp_bulk_write_x(struct dbgp_pipe *pipe, const char *bytes, int size);
+int dbgp_bulk_read_x(struct dbgp_pipe *pipe, void *data, int size);
+void usbdebug_tx_byte(struct dbgp_pipe *pipe, unsigned char data);
+void usbdebug_tx_flush(struct dbgp_pipe *pipe);
#endif
diff --git a/src/lib/usbdebug.c b/src/lib/usbdebug.c
index b6c7f100c4..77bfd97677 100644
--- a/src/lib/usbdebug.c
+++ b/src/lib/usbdebug.c
@@ -29,6 +29,33 @@
#include <ehci.h>
#include <usbdebug.h>
+
+#define DBGP_EP_VALID (1<<0)
+#define DBGP_EP_ENABLED (1<<1)
+#define DBGP_EP_STATMASK (DBGP_EP_VALID | DBGP_EP_ENABLED)
+
+struct dbgp_pipe
+{
+ u8 endpoint;
+ u8 status;
+ u8 bufidx;
+ char buf[8];
+};
+
+#define DBGP_MAX_ENDPOINTS 4
+#define DBGP_CONSOLE_EPOUT 0
+#define DBGP_CONSOLE_EPIN 1
+
+struct ehci_debug_info {
+ u8 devnum;
+
+ void *ehci_caps;
+ void *ehci_regs;
+ void *ehci_debug;
+
+ struct dbgp_pipe ep_pipe[DBGP_MAX_ENDPOINTS];
+};
+
/* Set this to 1 to debug the start-up of EHCI debug port hardware. You need
* to modify console_init() to initialise some other console before usbdebug
* to receive the printk lines from here.
@@ -215,10 +242,11 @@ static int dbgp_bulk_write(struct ehci_dbg_port *ehci_debug,
return ret;
}
-int dbgp_bulk_write_x(struct ehci_debug_info *dbg_info, const char *bytes, int size)
+int dbgp_bulk_write_x(struct dbgp_pipe *pipe, const char *bytes, int size)
{
+ struct ehci_debug_info *dbg_info = dbgp_ehci_info();
return dbgp_bulk_write(dbg_info->ehci_debug, dbg_info->devnum,
- dbg_info->endpoint_out, bytes, size);
+ pipe->endpoint, bytes, size);
}
static int dbgp_bulk_read(struct ehci_dbg_port *ehci_debug, unsigned devnum,
@@ -252,10 +280,11 @@ static int dbgp_bulk_read(struct ehci_dbg_port *ehci_debug, unsigned devnum,
return ret;
}
-int dbgp_bulk_read_x(struct ehci_debug_info *dbg_info, void *data, int size)
+int dbgp_bulk_read_x(struct dbgp_pipe *pipe, void *data, int size)
{
+ struct ehci_debug_info *dbg_info = dbgp_ehci_info();
return dbgp_bulk_read(dbg_info->ehci_debug, dbg_info->devnum,
- dbg_info->endpoint_in, data, size, DBGP_LOOPS);
+ pipe->endpoint, data, size, DBGP_LOOPS);
}
static void dbgp_mdelay(int ms)
@@ -379,8 +408,6 @@ static int usbdebug_init_(unsigned ehci_bar, unsigned offset, struct ehci_debug_
struct ehci_caps *ehci_caps;
struct ehci_regs *ehci_regs;
struct ehci_dbg_port *ehci_debug;
- unsigned dbgp_endpoint_out;
- unsigned dbgp_endpoint_in;
struct usb_debug_descriptor dbgp_desc;
u32 cmd, ctrl, status, portsc, hcs_params;
@@ -396,8 +423,8 @@ static int usbdebug_init_(unsigned ehci_bar, unsigned offset, struct ehci_debug_
HC_LENGTH(read32((unsigned long)&ehci_caps->hc_capbase)));
ehci_debug = (struct ehci_dbg_port *)(ehci_bar + offset);
info->ehci_debug = (void *)0;
- info->bufidx = 0;
- info->status = 0;
+
+ memset(&info->ep_pipe, 0, sizeof (info->ep_pipe));
try_next_time:
port_map_tried = 0;
@@ -516,8 +543,6 @@ try_next_port:
ret = -6;
goto err;
}
- dbgp_endpoint_out = dbgp_desc.bDebugOutEndpoint;
- dbgp_endpoint_in = dbgp_desc.bDebugInEndpoint;
/* Move the device to 127 if it isn't already there */
if (devnum != USB_DEBUG_DEVNUM) {
@@ -546,7 +571,7 @@ try_next_port:
dbgp_printk("EHCI debug interface enabled.\n");
/* Perform a small write to get the even/odd data state in sync */
- ret = dbgp_bulk_write(ehci_debug, USB_DEBUG_DEVNUM, dbgp_endpoint_out, "USB\r\n",5);
+ ret = dbgp_bulk_write(ehci_debug, USB_DEBUG_DEVNUM, dbgp_desc.bDebugOutEndpoint, "USB\r\n",5);
if (ret < 0) {
dbgp_printk("dbgp_bulk_write failed: %d\n", ret);
ret = -9;
@@ -558,10 +583,11 @@ try_next_port:
info->ehci_regs = ehci_regs;
info->ehci_debug = ehci_debug;
info->devnum = devnum;
- info->endpoint_out = dbgp_endpoint_out;
- info->endpoint_in = dbgp_endpoint_in;
- info->status |= DBGP_EP_ENABLED | DBGP_EP_VALID;
+ info->ep_pipe[DBGP_CONSOLE_EPOUT].endpoint = dbgp_desc.bDebugOutEndpoint;
+ info->ep_pipe[DBGP_CONSOLE_EPIN].endpoint = dbgp_desc.bDebugInEndpoint;
+ info->ep_pipe[DBGP_CONSOLE_EPOUT].status |= DBGP_EP_ENABLED | DBGP_EP_VALID;
+ info->ep_pipe[DBGP_CONSOLE_EPIN].status |= DBGP_EP_ENABLED | DBGP_EP_VALID;
return 0;
err:
/* Things didn't work so remove my claim */
@@ -586,22 +612,22 @@ next_debug_port:
return -10;
}
-void usbdebug_tx_byte(struct ehci_debug_info *dbg_info, unsigned char data)
+void usbdebug_tx_byte(struct dbgp_pipe *pipe, unsigned char data)
{
- if (dbgp_is_ep_active(dbg_info)) {
- dbg_info->buf[dbg_info->bufidx++] = data;
- if (dbg_info->bufidx >= 8) {
- dbgp_bulk_write_x(dbg_info, dbg_info->buf, dbg_info->bufidx);
- dbg_info->bufidx = 0;
+ if (dbgp_ep_is_active(pipe)) {
+ pipe->buf[pipe->bufidx++] = data;
+ if (pipe->bufidx >= 8) {
+ dbgp_bulk_write_x(pipe, pipe->buf, pipe->bufidx);
+ pipe->bufidx = 0;
}
}
}
-void usbdebug_tx_flush(struct ehci_debug_info *dbg_info)
+void usbdebug_tx_flush(struct dbgp_pipe *pipe)
{
- if (dbgp_is_ep_active(dbg_info) && dbg_info->bufidx > 0) {
- dbgp_bulk_write_x(dbg_info, dbg_info->buf, dbg_info->bufidx);
- dbg_info->bufidx = 0;
+ if (dbgp_ep_is_active(pipe) && pipe->bufidx > 0) {
+ dbgp_bulk_write_x(pipe, pipe->buf, pipe->bufidx);
+ pipe->bufidx = 0;
}
}
@@ -610,6 +636,7 @@ static void usbdebug_re_enable(unsigned ehci_base)
{
struct ehci_debug_info *dbg_info = dbgp_ehci_info();
unsigned diff;
+ int i;
if (!dbg_info->ehci_debug)
return;
@@ -618,13 +645,17 @@ static void usbdebug_re_enable(unsigned ehci_base)
dbg_info->ehci_regs -= diff;
dbg_info->ehci_debug -= diff;
dbg_info->ehci_caps = (void*)ehci_base;
- dbg_info->status |= DBGP_EP_ENABLED;
+
+ for (i=0; i<DBGP_MAX_ENDPOINTS; i++)
+ dbg_info->ep_pipe[i].status |= DBGP_EP_ENABLED;
}
static void usbdebug_disable(void)
{
struct ehci_debug_info *dbg_info = dbgp_ehci_info();
- dbg_info->status &= ~DBGP_EP_ENABLED;
+ int i;
+ for (i=0; i<DBGP_MAX_ENDPOINTS; i++)
+ dbg_info->ep_pipe[i].status &= ~DBGP_EP_ENABLED;
}
static void pci_ehci_set_resources(struct device *dev)
@@ -661,19 +692,19 @@ void pci_ehci_read_resources(struct device *dev)
}
#endif
-int dbgp_ep_is_active(struct ehci_debug_info *dbg_info)
+int dbgp_ep_is_active(struct dbgp_pipe *pipe)
{
- return (dbg_info->status & DBGP_EP_STATMASK) == (DBGP_EP_VALID | DBGP_EP_ENABLED);
+ return (pipe->status & DBGP_EP_STATMASK) == (DBGP_EP_VALID | DBGP_EP_ENABLED);
}
-struct ehci_debug_info *dbgp_console_input(void)
+struct dbgp_pipe *dbgp_console_output(void)
{
- return dbgp_ehci_info();
+ return &dbgp_ehci_info()->ep_pipe[DBGP_CONSOLE_EPOUT];
}
-struct ehci_debug_info *dbgp_console_input(void)
+struct dbgp_pipe *dbgp_console_input(void)
{
- return dbgp_ehci_info();
+ return &dbgp_ehci_info()->ep_pipe[DBGP_CONSOLE_EPIN];
}
int usbdebug_init(void)