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>
This commit is contained in:
Kyösti Mälkki 2014-02-09 23:35:39 +02:00
parent 411bf97c22
commit 8cde852ecf
4 changed files with 90 additions and 63 deletions

View File

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

64
src/drivers/usb/console.c Normal file
View File

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

View File

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

View File

@ -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_ */