hv:Reshuffle console/uart code

The current hierarchy :
  CONSOLE --> SERIAL -->UART DRIVER
This patch remove SERIAL layer, that is console will
call UART driver directly, change it to:
  CONSOLE  --> UART DRIVER
Remove some related data structures and registration and callback.
Cleanup vuart.c

Signed-off-by: Mingqiang Chi <mingqiang.chi@intel.com>
Acked-by: Eddie Dong <eddie.dong@intel.com>
This commit is contained in:
Mingqiang Chi
2018-07-27 16:23:09 +08:00
committed by lijinxia
parent b7436272e7
commit ae3004028b
12 changed files with 192 additions and 540 deletions

View File

@@ -5,169 +5,52 @@
*/
#include <hypervisor.h>
#include "serial_internal.h"
#include "uart16550.h"
static spinlock_t lock;
static uint32_t serial_handle = SERIAL_INVALID_HANDLE;
struct hv_timer console_timer;
#define CONSOLE_KICK_TIMER_TIMEOUT 40 /* timeout is 40ms*/
uint32_t get_serial_handle(void)
{
return serial_handle;
}
static void print_char(char x)
{
(void)serial_puts(serial_handle, &x, 1);
if (x == '\n') {
(void)serial_puts(serial_handle, "\r", 1);
}
}
void console_init(void)
{
spinlock_init(&lock);
serial_handle = serial_open("STDIO");
uart16550_init();
}
int console_putc(int ch)
void console_putc(const char *ch)
{
int res = -1;
spinlock_obtain(&lock);
if (serial_handle != SERIAL_INVALID_HANDLE) {
print_char(ch);
res = 0;
}
spinlock_release(&lock);
return res;
(void)uart16550_puts(ch, 1);
}
int console_puts(const char *s_arg)
int console_write(const char *s, size_t len)
{
const char *s = s_arg;
int res = -1;
const char *p;
spinlock_obtain(&lock);
if (serial_handle != SERIAL_INVALID_HANDLE) {
res = 0;
while ((*s) != 0) {
/* start output at the beginning of the string search
* for end of string or '\n'
*/
p = s;
while ((*p != 0) && *p != '\n') {
++p;
}
/* write all characters up to p */
(void)serial_puts(serial_handle, s, p - s);
res += p - s;
if (*p == '\n') {
print_char('\n');
++p;
res += 2;
}
/* continue at position p */
s = p;
}
}
spinlock_release(&lock);
return res;
return uart16550_puts(s, len);
}
int console_write(const char *s_arg, size_t len)
char console_getc(void)
{
const char *s = s_arg;
int res = -1;
const char *e;
const char *p;
spinlock_obtain(&lock);
if (serial_handle != SERIAL_INVALID_HANDLE) {
/* calculate pointer to the end of the string */
e = s + len;
res = 0;
/* process all characters */
while (s != e) {
/* search for '\n' or the end of the string */
p = s;
while ((p != e) && (*p != '\n')) {
++p;
}
/* write all characters processed so far */
(void)serial_puts(serial_handle, s, p - s);
res += p - s;
/* write '\n' if end of string is not reached */
if (p != e) {
print_char('\n');
++p;
res += 2;
}
/* continue at next position */
s = p;
}
}
spinlock_release(&lock);
return res;
}
static void console_read(void)
{
spinlock_obtain(&lock);
if (serial_handle != SERIAL_INVALID_HANDLE) {
/* Get all the data available in the RX FIFO */
(void)serial_get_rx_data(serial_handle);
}
spinlock_release(&lock);
return uart16550_getc();
}
static void console_handler(void)
{
/* Dump the RX FIFO to a circular buffer */
console_read();
struct vuart *vu;
/* serial Console Rx operation */
vuart_console_rx_chars(serial_handle);
/* serial Console Tx operation */
vuart_console_tx_chars();
shell_kick_session();
vu = vuart_console_active();
if (vu != NULL) {
/* serial Console Rx operation */
vuart_console_rx_chars(vu);
/* serial Console Tx operation */
vuart_console_tx_chars(vu);
} else {
shell_kick_session();
}
}
static int console_timer_callback(__unused void *data)
{
/* Kick HV-Shell and Uart-Console tasks */
console_handler();
return 0;
}
@@ -175,12 +58,6 @@ void console_setup_timer(void)
{
uint64_t period_in_cycle, fire_tsc;
if (serial_handle == SERIAL_INVALID_HANDLE) {
pr_err("%s: no uart, not need setup console timer",
__func__);
return;
}
period_in_cycle = CYCLES_PER_MS * CONSOLE_KICK_TIMER_TIMEOUT;
fire_tsc = rdtsc() + period_in_cycle;
initialize_timer(&console_timer,