From c61db6ffa0589a14975a93ee9d2206ec7eb1ee7b Mon Sep 17 00:00:00 2001 From: Conghui Chen Date: Mon, 29 Apr 2019 14:37:58 +0800 Subject: [PATCH] HV: vuart: remove console related code from vuart Move the console related code from dm/vuart.c to debug/console.c as console is not supported in release version. Tracked-On: #2987 Signed-off-by: Conghui Chen Acked-by: Eddie Dong --- hypervisor/debug/console.c | 66 +++++++++++++++++++++++ hypervisor/dm/vuart.c | 85 +++++++----------------------- hypervisor/include/debug/console.h | 4 +- hypervisor/include/dm/vuart.h | 8 +-- 4 files changed, 90 insertions(+), 73 deletions(-) diff --git a/hypervisor/debug/console.c b/hypervisor/debug/console.c index 697d76d47..7bc05fd55 100644 --- a/hypervisor/debug/console.c +++ b/hypervisor/debug/console.c @@ -11,10 +11,15 @@ #include #include #include +#include +#include struct hv_timer console_timer; #define CONSOLE_KICK_TIMER_TIMEOUT 40UL /* timeout is 40ms*/ +/* Switching key combinations for shell and uart console */ +#define GUEST_CONSOLE_TO_HV_SWITCH_KEY 0 /* CTRL + SPACE */ +uint16_t console_vmid = ACRN_INVALID_VMID; void console_init(void) { @@ -37,6 +42,67 @@ char console_getc(void) return uart16550_getc(); } +/* + * @post return != NULL + */ +struct acrn_vuart *vm_console_vuart(struct acrn_vm *vm) +{ + return &vm->vuart[0]; +} + +/** + * @pre vu != NULL + * @pre vu->active == true + */ +void vuart_console_rx_chars(struct acrn_vuart *vu) +{ + char ch = -1; + + /* Get data from physical uart */ + ch = uart16550_getc(); + + if (ch == GUEST_CONSOLE_TO_HV_SWITCH_KEY) { + /* Switch the console */ + console_vmid = ACRN_INVALID_VMID; + printf("\r\n\r\n ---Entering ACRN SHELL---\r\n"); + } + if (ch != -1) { + vuart_putchar(vu, ch); + vuart_toggle_intr(vu); + } + +} + +/** + * @pre vu != NULL + */ +void vuart_console_tx_chars(struct acrn_vuart *vu) +{ + char c; + + while ((c = vuart_getchar(vu)) != -1) { + printf("%c", c); + } +} + +struct acrn_vuart *vuart_console_active(void) +{ + struct acrn_vm *vm = NULL; + struct acrn_vuart *vu = NULL; + + if (console_vmid < CONFIG_MAX_VM_NUM) { + vm = get_vm_from_vmid(console_vmid); + if (is_valid_vm(vm)) { + vu = vm_console_vuart(vm); + } else { + /* Console vm is invalid, switch back to HV-Shell */ + console_vmid = ACRN_INVALID_VMID; + } + } + + return (vu && vu->active) ? vu : NULL; +} + static void console_timer_callback(__unused void *data) { struct acrn_vuart *vu; diff --git a/hypervisor/dm/vuart.c b/hypervisor/dm/vuart.c index f85f8358e..6ff4513c8 100644 --- a/hypervisor/dm/vuart.c +++ b/hypervisor/dm/vuart.c @@ -43,8 +43,6 @@ static uint16_t vuart_com_base = CONFIG_COM_BASE; #define vuart_lock(vu) spinlock_obtain(&((vu)->lock)) #define vuart_unlock(vu) spinlock_release(&((vu)->lock)) -uint16_t console_vmid = ACRN_INVALID_VMID; - static inline void fifo_reset(struct fifo *fifo) { fifo->rindex = 0U; @@ -83,6 +81,23 @@ static inline uint32_t fifo_numchars(const struct fifo *fifo) return fifo->num; } +void vuart_putchar(struct acrn_vuart *vu, char ch) +{ + vuart_lock(vu); + fifo_putchar(&vu->rxfifo, ch); + vuart_unlock(vu); +} + +char vuart_getchar(struct acrn_vuart *vu) +{ + char c; + + vuart_lock(vu); + c = fifo_getchar(&vu->txfifo); + vuart_unlock(vu); + return c; +} + static inline void vuart_fifo_init(struct acrn_vuart *vu) { vu->txfifo.buf = vu->vuart_tx_buf; @@ -129,19 +144,11 @@ struct acrn_vuart *find_vuart_by_port(struct acrn_vm *vm, uint16_t offset) return ret_vu; } -/* - * @post return != NULL - */ -struct acrn_vuart *vm_console_vuart(struct acrn_vm *vm) -{ - return &vm->vuart[0]; -} - /* * Toggle the COM port's intr pin depending on whether or not we have an * interrupt condition to report to the processor. */ -static void vuart_toggle_intr(const struct acrn_vuart *vu) +void vuart_toggle_intr(const struct acrn_vuart *vu) { uint8_t intr_reason; union ioapic_rte rte; @@ -384,58 +391,6 @@ static bool vuart_register_io_handler(struct acrn_vm *vm, uint16_t port_base, ui return ret; } -/** - * @pre vu != NULL - */ -void vuart_console_tx_chars(struct acrn_vuart *vu) -{ - vuart_lock(vu); - while (fifo_numchars(&vu->txfifo) > 0U) { - printf("%c", fifo_getchar(&vu->txfifo)); - } - vuart_unlock(vu); -} - -/** - * @pre vu != NULL - * @pre vu->active == true - */ -void vuart_console_rx_chars(struct acrn_vuart *vu) -{ - char ch = -1; - - vuart_lock(vu); - /* Get data from physical uart */ - ch = uart16550_getc(); - - if (ch == GUEST_CONSOLE_TO_HV_SWITCH_KEY) { - /* Switch the console */ - console_vmid = ACRN_INVALID_VMID; - printf("\r\n\r\n ---Entering ACRN SHELL---\r\n"); - } - if (ch != -1) { - fifo_putchar(&vu->rxfifo, ch); - vuart_toggle_intr(vu); - } - - vuart_unlock(vu); -} - -struct acrn_vuart *vuart_console_active(void) -{ - struct acrn_vm *vm = NULL; - struct acrn_vuart *vu = NULL; - - if (console_vmid < CONFIG_MAX_VM_NUM) { - vm = get_vm_from_vmid(console_vmid); - if (is_valid_vm(vm)) { - vu = vm_console_vuart(vm); - } - } - - return (vu && vu->active) ? vu : NULL; -} - static void vuart_setup(struct acrn_vm *vm, struct vuart_config *vu_config, uint16_t vuart_idx) { @@ -541,10 +496,6 @@ void vuart_deinit(struct acrn_vm *vm) { uint8_t i; - /* reset console_vmid to switch back to hypervisor console */ - if (console_vmid == vm->vm_id) - console_vmid = ACRN_INVALID_VMID; - for (i = 0; i < MAX_VUART_NUM_PER_VM; i++) { vm->vuart[i].active = false; if (vm->vuart[i].target_vu) diff --git a/hypervisor/include/debug/console.h b/hypervisor/include/debug/console.h index f029445d5..9819c1a41 100644 --- a/hypervisor/include/debug/console.h +++ b/hypervisor/include/debug/console.h @@ -7,8 +7,7 @@ #ifndef CONSOLE_H #define CONSOLE_H -/* Switching key combinations for shell and uart console */ -#define GUEST_CONSOLE_TO_HV_SWITCH_KEY 0 /* CTRL + SPACE */ +#include /** Initializes the console module. * @@ -39,5 +38,6 @@ void console_setup_timer(void); void suspend_console(void); void resume_console(void); +struct acrn_vuart *vm_console_vuart(struct acrn_vm *vm); #endif /* CONSOLE_H */ diff --git a/hypervisor/include/dm/vuart.h b/hypervisor/include/dm/vuart.h index 2d5c62a02..0cf8c6590 100644 --- a/hypervisor/include/dm/vuart.h +++ b/hypervisor/include/dm/vuart.h @@ -81,12 +81,12 @@ struct acrn_vuart { spinlock_t lock; /* protects all softc elements */ }; -struct acrn_vuart *vm_console_vuart(struct acrn_vm *vm); void vuart_init(struct acrn_vm *vm, struct vuart_config *vu_config); void vuart_deinit(struct acrn_vm *vm); -struct acrn_vuart *vuart_console_active(void); -void vuart_console_tx_chars(struct acrn_vuart *vu); -void vuart_console_rx_chars(struct acrn_vuart *vu); + +void vuart_putchar(struct acrn_vuart *vu, char ch); +char vuart_getchar(struct acrn_vuart *vu); +void vuart_toggle_intr(const struct acrn_vuart *vu); bool is_vuart_intx(struct acrn_vm *vm, uint32_t intx_pin); void vuart_set_property(const char *vuart_info);