From 7ebc4877c8451050cbe16319f8c786138052bb11 Mon Sep 17 00:00:00 2001 From: Minggui Cao Date: Wed, 26 Dec 2018 16:39:35 +0800 Subject: [PATCH] HV: refine cmdline code, move parts into dbg_cmd move the debug related command handle into debug/dbg_cmd.c; so release build will not include that. Tracked-On: #2170 Signed-off-by: Minggui Cao Acked-by: Eddie Dong --- hypervisor/bsp/uefi/cmdline.c | 63 ++----------------------- hypervisor/debug/dbg_cmd.c | 74 ++++++++++++++++++++++++++++++ hypervisor/include/debug/console.h | 1 + hypervisor/release/console.c | 2 +- hypervisor/release/vuart.c | 2 - 5 files changed, 79 insertions(+), 63 deletions(-) create mode 100644 hypervisor/debug/dbg_cmd.c diff --git a/hypervisor/bsp/uefi/cmdline.c b/hypervisor/bsp/uefi/cmdline.c index 96f2ed11e..0c26fd2ce 100644 --- a/hypervisor/bsp/uefi/cmdline.c +++ b/hypervisor/bsp/uefi/cmdline.c @@ -7,67 +7,8 @@ #include #include -#define MAX_PORT 0x10000 /* port 0 - 64K */ -#define DEFAULT_UART_PORT 0x3F8 - #define ACRN_DBG_PARSE 6 -#define MAX_CMD_LEN 64 - -static const char * const cmd_list[] = { - "uart=disabled", /* to disable uart */ - "uart=port@", /* like uart=port@0x3F8 */ - "uart=bdf@", /*like: uart=bdf@0:18.2, it is for ttyS2 */ - - /* format: vuart=ttySx@irqN, like vuart=ttyS1@irq6; better to unify - * uart & vuart & SOS console the same one, and irq same with the native. - * ttySx range (0-3), irqN (0-255) - */ - "vuart=ttyS", -}; - -enum IDX_CMD { - IDX_DISABLE_UART, - IDX_PORT_UART, - IDX_PCI_UART, - IDX_SET_VUART, - - IDX_MAX_CMD, -}; - -static void handle_cmd(const char *cmd, int32_t len) -{ - int32_t i; - - for (i = 0; i < IDX_MAX_CMD; i++) { - int32_t tmp = strnlen_s(cmd_list[i], MAX_CMD_LEN); - - /*cmd prefix should be same with one in cmd_list */ - if (len < tmp) - continue; - - if (strncmp(cmd_list[i], cmd, tmp) != 0) - continue; - - if (i == IDX_DISABLE_UART) { - /* set uart disabled*/ - uart16550_set_property(false, false, 0UL); - } else if (i == IDX_PORT_UART) { - uint64_t addr = strtoul_hex(cmd + tmp); - if (addr > MAX_PORT) { - addr = DEFAULT_UART_PORT; - } - - uart16550_set_property(true, true, addr); - - } else if (i == IDX_PCI_UART) { - uart16550_set_property(true, false, (uint64_t)(cmd+tmp)); - } else if (i == IDX_SET_VUART) { - vuart_set_property(cmd+tmp); - } - } -} - int32_t parse_hv_cmdline(void) { const char *start; @@ -98,7 +39,9 @@ int32_t parse_hv_cmdline(void) while (*end != ' ' && *end) end++; - handle_cmd(start, end - start); + if (!handle_dbg_cmd(start, end - start)) { + /* if not handled by handle_dbg_cmd, it can be handled further */ + } start = end + 1; } while (*end && *start); diff --git a/hypervisor/debug/dbg_cmd.c b/hypervisor/debug/dbg_cmd.c new file mode 100644 index 000000000..d03b01a69 --- /dev/null +++ b/hypervisor/debug/dbg_cmd.c @@ -0,0 +1,74 @@ +/* + * Copyright (C) 2018 Intel Corporation. All rights reserved. + * + * SPDX-License-Identifier: BSD-3-Clause + */ + +#include + +#define MAX_PORT 0x10000 /* port 0 - 64K */ +#define DEFAULT_UART_PORT 0x3F8 + +#define MAX_CMD_LEN 64 + +static const char * const cmd_list[] = { + "uart=disabled", /* to disable uart */ + "uart=port@", /* like uart=port@0x3F8 */ + "uart=bdf@", /*like: uart=bdf@0:18.2, it is for ttyS2 */ + + /* format: vuart=ttySx@irqN, like vuart=ttyS1@irq6; better to unify + * uart & vuart & SOS console the same one, and irq same with the native. + * ttySx range (0-3), irqN (0-255) + */ + "vuart=ttyS", +}; + +enum IDX_CMD_DBG { + IDX_DISABLE_UART, + IDX_PORT_UART, + IDX_PCI_UART, + IDX_SET_VUART, + + IDX_MAX_CMD, +}; + +bool handle_dbg_cmd(const char *cmd, int32_t len) +{ + int32_t i; + bool handled = false; + + for (i = 0; i < IDX_MAX_CMD; i++) { + int32_t tmp = strnlen_s(cmd_list[i], MAX_CMD_LEN); + + /*cmd prefix should be same with one in cmd_list */ + if (len < tmp) + continue; + + if (strncmp(cmd_list[i], cmd, tmp) != 0) + continue; + + if (i == IDX_DISABLE_UART) { + /* set uart disabled*/ + uart16550_set_property(false, false, 0UL); + } else if (i == IDX_PORT_UART) { + uint64_t addr = strtoul_hex(cmd + tmp); + + if (addr > MAX_PORT) { + addr = DEFAULT_UART_PORT; + } + + uart16550_set_property(true, true, addr); + + } else if (i == IDX_PCI_UART) { + uart16550_set_property(true, false, (uint64_t)(cmd+tmp)); + } else if (i == IDX_SET_VUART) { + vuart_set_property(cmd+tmp); + } + } + + if (i < IDX_MAX_CMD) { + handled = true; + } + + return handled; +} diff --git a/hypervisor/include/debug/console.h b/hypervisor/include/debug/console.h index 2841ee5ea..6a0705d77 100644 --- a/hypervisor/include/debug/console.h +++ b/hypervisor/include/debug/console.h @@ -46,4 +46,5 @@ void shell_kick(void); void suspend_console(void); void resume_console(void); +bool handle_dbg_cmd(const char *cmd, int32_t len); #endif /* CONSOLE_H */ diff --git a/hypervisor/release/console.c b/hypervisor/release/console.c index 2d4f21176..1cd410a8a 100644 --- a/hypervisor/release/console.c +++ b/hypervisor/release/console.c @@ -24,7 +24,7 @@ void console_setup_timer(void) {} void suspend_console(void) {} void resume_console(void) {} -void uart16550_set_property(__unused bool enabled, __unused bool port_mapped, __unused uint64_t base_addr) {} +bool handle_dbg_cmd(__unused const char *cmd, __unused int32_t len) { return false; } bool is_pci_dbg_uart(__unused union pci_bdf bdf_value) { return false; } bool is_dbg_uart_enabled(void) { return false; } diff --git a/hypervisor/release/vuart.c b/hypervisor/release/vuart.c index b18638ad2..74926e615 100644 --- a/hypervisor/release/vuart.c +++ b/hypervisor/release/vuart.c @@ -20,5 +20,3 @@ bool hv_used_dbg_intx(__unused uint8_t intx_pin) { return false; } - -void vuart_set_property(__unused const char *vuart_info) {}