Skip to content

Commit 7ebc487

Browse files
mgcaowenlingz
authored andcommitted
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 <minggui.cao@intel.com> Acked-by: Eddie Dong <eddie.dong@intel.com>
1 parent a5ca305 commit 7ebc487

File tree

5 files changed

+79
-63
lines changed

5 files changed

+79
-63
lines changed

hypervisor/bsp/uefi/cmdline.c

Lines changed: 3 additions & 60 deletions
Original file line numberDiff line numberDiff line change
@@ -7,67 +7,8 @@
77
#include <hypervisor.h>
88
#include <multiboot.h>
99

10-
#define MAX_PORT 0x10000 /* port 0 - 64K */
11-
#define DEFAULT_UART_PORT 0x3F8
12-
1310
#define ACRN_DBG_PARSE 6
1411

15-
#define MAX_CMD_LEN 64
16-
17-
static const char * const cmd_list[] = {
18-
"uart=disabled", /* to disable uart */
19-
"uart=port@", /* like uart=port@0x3F8 */
20-
"uart=bdf@", /*like: uart=bdf@0:18.2, it is for ttyS2 */
21-
22-
/* format: vuart=ttySx@irqN, like vuart=ttyS1@irq6; better to unify
23-
* uart & vuart & SOS console the same one, and irq same with the native.
24-
* ttySx range (0-3), irqN (0-255)
25-
*/
26-
"vuart=ttyS",
27-
};
28-
29-
enum IDX_CMD {
30-
IDX_DISABLE_UART,
31-
IDX_PORT_UART,
32-
IDX_PCI_UART,
33-
IDX_SET_VUART,
34-
35-
IDX_MAX_CMD,
36-
};
37-
38-
static void handle_cmd(const char *cmd, int32_t len)
39-
{
40-
int32_t i;
41-
42-
for (i = 0; i < IDX_MAX_CMD; i++) {
43-
int32_t tmp = strnlen_s(cmd_list[i], MAX_CMD_LEN);
44-
45-
/*cmd prefix should be same with one in cmd_list */
46-
if (len < tmp)
47-
continue;
48-
49-
if (strncmp(cmd_list[i], cmd, tmp) != 0)
50-
continue;
51-
52-
if (i == IDX_DISABLE_UART) {
53-
/* set uart disabled*/
54-
uart16550_set_property(false, false, 0UL);
55-
} else if (i == IDX_PORT_UART) {
56-
uint64_t addr = strtoul_hex(cmd + tmp);
57-
if (addr > MAX_PORT) {
58-
addr = DEFAULT_UART_PORT;
59-
}
60-
61-
uart16550_set_property(true, true, addr);
62-
63-
} else if (i == IDX_PCI_UART) {
64-
uart16550_set_property(true, false, (uint64_t)(cmd+tmp));
65-
} else if (i == IDX_SET_VUART) {
66-
vuart_set_property(cmd+tmp);
67-
}
68-
}
69-
}
70-
7112
int32_t parse_hv_cmdline(void)
7213
{
7314
const char *start;
@@ -98,7 +39,9 @@ int32_t parse_hv_cmdline(void)
9839
while (*end != ' ' && *end)
9940
end++;
10041

101-
handle_cmd(start, end - start);
42+
if (!handle_dbg_cmd(start, end - start)) {
43+
/* if not handled by handle_dbg_cmd, it can be handled further */
44+
}
10245
start = end + 1;
10346

10447
} while (*end && *start);

hypervisor/debug/dbg_cmd.c

Lines changed: 74 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,74 @@
1+
/*
2+
* Copyright (C) 2018 Intel Corporation. All rights reserved.
3+
*
4+
* SPDX-License-Identifier: BSD-3-Clause
5+
*/
6+
7+
#include <hypervisor.h>
8+
9+
#define MAX_PORT 0x10000 /* port 0 - 64K */
10+
#define DEFAULT_UART_PORT 0x3F8
11+
12+
#define MAX_CMD_LEN 64
13+
14+
static const char * const cmd_list[] = {
15+
"uart=disabled", /* to disable uart */
16+
"uart=port@", /* like uart=port@0x3F8 */
17+
"uart=bdf@", /*like: uart=bdf@0:18.2, it is for ttyS2 */
18+
19+
/* format: vuart=ttySx@irqN, like vuart=ttyS1@irq6; better to unify
20+
* uart & vuart & SOS console the same one, and irq same with the native.
21+
* ttySx range (0-3), irqN (0-255)
22+
*/
23+
"vuart=ttyS",
24+
};
25+
26+
enum IDX_CMD_DBG {
27+
IDX_DISABLE_UART,
28+
IDX_PORT_UART,
29+
IDX_PCI_UART,
30+
IDX_SET_VUART,
31+
32+
IDX_MAX_CMD,
33+
};
34+
35+
bool handle_dbg_cmd(const char *cmd, int32_t len)
36+
{
37+
int32_t i;
38+
bool handled = false;
39+
40+
for (i = 0; i < IDX_MAX_CMD; i++) {
41+
int32_t tmp = strnlen_s(cmd_list[i], MAX_CMD_LEN);
42+
43+
/*cmd prefix should be same with one in cmd_list */
44+
if (len < tmp)
45+
continue;
46+
47+
if (strncmp(cmd_list[i], cmd, tmp) != 0)
48+
continue;
49+
50+
if (i == IDX_DISABLE_UART) {
51+
/* set uart disabled*/
52+
uart16550_set_property(false, false, 0UL);
53+
} else if (i == IDX_PORT_UART) {
54+
uint64_t addr = strtoul_hex(cmd + tmp);
55+
56+
if (addr > MAX_PORT) {
57+
addr = DEFAULT_UART_PORT;
58+
}
59+
60+
uart16550_set_property(true, true, addr);
61+
62+
} else if (i == IDX_PCI_UART) {
63+
uart16550_set_property(true, false, (uint64_t)(cmd+tmp));
64+
} else if (i == IDX_SET_VUART) {
65+
vuart_set_property(cmd+tmp);
66+
}
67+
}
68+
69+
if (i < IDX_MAX_CMD) {
70+
handled = true;
71+
}
72+
73+
return handled;
74+
}

hypervisor/include/debug/console.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -46,4 +46,5 @@ void shell_kick(void);
4646
void suspend_console(void);
4747
void resume_console(void);
4848

49+
bool handle_dbg_cmd(const char *cmd, int32_t len);
4950
#endif /* CONSOLE_H */

hypervisor/release/console.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,7 @@ void console_setup_timer(void) {}
2424
void suspend_console(void) {}
2525
void resume_console(void) {}
2626

27-
void uart16550_set_property(__unused bool enabled, __unused bool port_mapped, __unused uint64_t base_addr) {}
27+
bool handle_dbg_cmd(__unused const char *cmd, __unused int32_t len) { return false; }
2828
bool is_pci_dbg_uart(__unused union pci_bdf bdf_value) { return false; }
2929
bool is_dbg_uart_enabled(void) { return false; }
3030

hypervisor/release/vuart.c

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -20,5 +20,3 @@ bool hv_used_dbg_intx(__unused uint8_t intx_pin)
2020
{
2121
return false;
2222
}
23-
24-
void vuart_set_property(__unused const char *vuart_info) {}

0 commit comments

Comments
 (0)