[PATCH 2/4] HV: refine shell.c & shell_priv.h


Yonghua Huang
 

- move local functions declarations to shell.c
- remove 'name' field in 'struct shell' as i/o
session s/w layer is deprecated.

Signed-off-by: Yonghua Huang <yonghua.huang@...>
---
hypervisor/debug/shell.c | 180 +++++++++++++++++++++++-------------------
hypervisor/debug/shell_priv.h | 52 +++---------
2 files changed, 109 insertions(+), 123 deletions(-)

diff --git a/hypervisor/debug/shell.c b/hypervisor/debug/shell.c
index a3976e6..22ef919 100644
--- a/hypervisor/debug/shell.c
+++ b/hypervisor/debug/shell.c
@@ -16,6 +16,22 @@
*/
#define SHELL_INPUT_LINE_OTHER(v) (((v) + 1U) % 2U)

+static int shell_cmd_help(__unused int argc, __unused char **argv);
+static int shell_list_vm(__unused int argc, __unused char **argv);
+static int shell_list_vcpu(__unused int argc, __unused char **argv);
+static int shell_vcpu_dumpreg(int argc, char **argv);
+static int shell_dumpmem(int argc, char **argv);
+static int shell_to_sos_console(int argc, char **argv);
+static int shell_show_cpu_int(__unused int argc, __unused char **argv);
+static int shell_show_ptdev_info(__unused int argc, __unused char **argv);
+static int shell_show_vioapic_info(int argc, char **argv);
+static int shell_show_ioapic_info(__unused int argc, __unused char **argv);
+static int shell_show_vmexit_profile(__unused int argc, __unused char **argv);
+static int shell_dump_logbuf(int argc, char **argv);
+static int shell_loglevel(int argc, char **argv);
+static int shell_cpuid(int argc, char **argv);
+static int shell_trigger_crash(int argc, char **argv);
+
static struct shell_cmd shell_cmds[] = {
{
.str = SHELL_CMD_HELP,
@@ -179,11 +195,32 @@ static int string_to_argv(char *argv_str, void *p_argv_mem,
return 0;
}

+static struct shell_cmd *shell_find_cmd(const char *cmd_str)
+{
+ uint32_t i;
+ struct shell_cmd *p_cmd = NULL;
+
+ for (i = 0U; i < p_shell->cmd_count; i++) {
+ p_cmd = &p_shell->shell_cmd[i];
+ if (strcmp(p_cmd->str, cmd_str) == 0) {
+ return p_cmd;
+ }
+ }
+ return NULL;
+}
+
static char shell_getc(void)
{
return console_getc();
}

+static void shell_puts(const char *string_ptr)
+{
+ /* Output the string */
+ (void)console_write(string_ptr, strnlen_s(string_ptr,
+ SHELL_STRING_MAX_LEN));
+}
+
static void shell_handle_special_char(uint8_t ch)
{
switch (ch) {
@@ -289,6 +326,51 @@ static bool shell_input_line(void)
return done;
}

+static int shell_process_cmd(char *p_input_line)
+{
+ int status = -EINVAL;
+ struct shell_cmd *p_cmd;
+ char cmd_argv_str[SHELL_CMD_MAX_LEN + 1U];
+ int cmd_argv_mem[sizeof(char *) * ((SHELL_CMD_MAX_LEN + 1U) / 2U)];
+ int cmd_argc;
+ char **cmd_argv;
+
+ /* Copy the input line INTo an argument string to become part of the
+ * argument vector.
+ */
+ (void)strcpy_s(&cmd_argv_str[0], SHELL_CMD_MAX_LEN, p_input_line);
+ cmd_argv_str[SHELL_CMD_MAX_LEN] = 0;
+
+ /* Build the argv vector from the string. The first argument in the
+ * resulting vector will be the command string itself.
+ */
+
+ /* NOTE: This process is destructive to the argument string! */
+
+ (void) string_to_argv(&cmd_argv_str[0],
+ (void *) &cmd_argv_mem[0],
+ sizeof(cmd_argv_mem), (void *)&cmd_argc, &cmd_argv);
+
+ /* Determine if there is a command to process. */
+ if (cmd_argc != 0) {
+ /* See if command is in cmds supported */
+ p_cmd = shell_find_cmd(cmd_argv[0]);
+ if (p_cmd == NULL) {
+ shell_puts("\r\nError: Invalid command.\r\n");
+ return -EINVAL;
+ }
+
+ status = p_cmd->fcn(cmd_argc, &cmd_argv[0]);
+ if (status == -EINVAL) {
+ shell_puts("\r\nError: Invalid parameters.\r\n");
+ } else if (status != 0) {
+ shell_puts("\r\nCommand launch failed.\r\n");
+ }
+ }
+
+ return status;
+}
+
static int shell_process(void)
{
int status;
@@ -323,19 +405,6 @@ static int shell_process(void)
return status;
}

-struct shell_cmd *shell_find_cmd(const char *cmd_str)
-{
- uint32_t i;
- struct shell_cmd *p_cmd = NULL;
-
- for (i = 0U; i < p_shell->cmd_count; i++) {
- p_cmd = &p_shell->shell_cmd[i];
- if (strcmp(p_cmd->str, cmd_str) == 0) {
- return p_cmd;
- }
- }
- return NULL;
-}

void shell_kick(void)
{
@@ -363,58 +432,12 @@ void shell_kick(void)
}
}

-int shell_process_cmd(char *p_input_line)
-{
- int status = -EINVAL;
- struct shell_cmd *p_cmd;
- char cmd_argv_str[SHELL_CMD_MAX_LEN + 1U];
- int cmd_argv_mem[sizeof(char *) * ((SHELL_CMD_MAX_LEN + 1U) / 2U)];
- int cmd_argc;
- char **cmd_argv;
-
- /* Copy the input line INTo an argument string to become part of the
- * argument vector.
- */
- (void)strcpy_s(&cmd_argv_str[0], SHELL_CMD_MAX_LEN, p_input_line);
- cmd_argv_str[SHELL_CMD_MAX_LEN] = 0;
-
- /* Build the argv vector from the string. The first argument in the
- * resulting vector will be the command string itself.
- */
-
- /* NOTE: This process is destructive to the argument string! */
-
- (void) string_to_argv(&cmd_argv_str[0],
- (void *) &cmd_argv_mem[0],
- sizeof(cmd_argv_mem), (void *)&cmd_argc, &cmd_argv);
-
- /* Determine if there is a command to process. */
- if (cmd_argc != 0) {
- /* See if command is in cmds supported */
- p_cmd = shell_find_cmd(cmd_argv[0]);
- if (p_cmd == NULL) {
- shell_puts("\r\nError: Invalid command.\r\n");
- return -EINVAL;
- }
-
- status = p_cmd->fcn(cmd_argc, &cmd_argv[0]);
- if (status == -EINVAL) {
- shell_puts("\r\nError: Invalid parameters.\r\n");
- } else if (status != 0) {
- shell_puts("\r\nCommand launch failed.\r\n");
- }
- }
-
- return status;
-}

void shell_init(void)
{
p_shell->shell_cmd = shell_cmds;
p_shell->cmd_count = ARRAY_SIZE(shell_cmds);

- (void)strcpy_s((void *)p_shell->name, SHELL_NAME_MAX_LEN, "Serial");
-
/* Zero fill the input buffer */
(void)memset((void *)p_shell->input_line[p_shell->input_line_active], 0U,
SHELL_CMD_MAX_LEN + 1U);
@@ -422,7 +445,7 @@ void shell_init(void)

#define SHELL_ROWS 10
#define MAX_INDENT_LEN 16
-int shell_cmd_help(__unused int argc, __unused char **argv)
+static int shell_cmd_help(__unused int argc, __unused char **argv)
{
int spaces = 0;
struct shell_cmd *p_cmd = NULL;
@@ -496,7 +519,7 @@ int shell_cmd_help(__unused int argc, __unused char **argv)
return 0;
}

-int shell_list_vm(__unused int argc, __unused char **argv)
+static int shell_list_vm(__unused int argc, __unused char **argv)
{
char temp_str[MAX_STR_SIZE];
struct list_head *pos;
@@ -534,7 +557,7 @@ int shell_list_vm(__unused int argc, __unused char **argv)
return 0;
}

-int shell_list_vcpu(__unused int argc, __unused char **argv)
+static int shell_list_vcpu(__unused int argc, __unused char **argv)
{
char temp_str[MAX_STR_SIZE];
struct list_head *pos;
@@ -584,7 +607,7 @@ int shell_list_vcpu(__unused int argc, __unused char **argv)
}

#define DUMPREG_SP_SIZE 32
-int shell_vcpu_dumpreg(int argc, char **argv)
+static int shell_vcpu_dumpreg(int argc, char **argv)
{
int status = 0;
uint16_t vm_id;
@@ -702,7 +725,7 @@ int shell_vcpu_dumpreg(int argc, char **argv)
}

#define MAX_MEMDUMP_LEN (32U*8U)
-int shell_dumpmem(int argc, char **argv)
+static int shell_dumpmem(int argc, char **argv)
{
uint64_t addr;
uint64_t *ptr;
@@ -746,7 +769,7 @@ int shell_dumpmem(int argc, char **argv)
return 0;
}

-int shell_to_sos_console(__unused int argc, __unused char **argv)
+static int shell_to_sos_console(__unused int argc, __unused char **argv)
{
char temp_str[TEMP_STR_SIZE];
uint16_t guest_no = 0U;
@@ -782,7 +805,7 @@ int shell_to_sos_console(__unused int argc, __unused char **argv)
return 0;
}

-int shell_show_cpu_int(__unused int argc, __unused char **argv)
+static int shell_show_cpu_int(__unused int argc, __unused char **argv)
{
char *temp_str = alloc_page();

@@ -798,7 +821,7 @@ int shell_show_cpu_int(__unused int argc, __unused char **argv)
return 0;
}

-int shell_show_ptdev_info(__unused int argc, __unused char **argv)
+static int shell_show_ptdev_info(__unused int argc, __unused char **argv)
{
char *temp_str = alloc_page();

@@ -814,7 +837,7 @@ int shell_show_ptdev_info(__unused int argc, __unused char **argv)
return 0;
}

-int shell_show_vioapic_info(int argc, char **argv)
+static int shell_show_vioapic_info(int argc, char **argv)
{
char *temp_str = alloc_page();
uint16_t vmid;
@@ -842,7 +865,7 @@ int shell_show_vioapic_info(int argc, char **argv)
return -EINVAL;
}

-int shell_show_ioapic_info(__unused int argc, __unused char **argv)
+static int shell_show_ioapic_info(__unused int argc, __unused char **argv)
{
char *temp_str = alloc_pages(2U);

@@ -858,7 +881,7 @@ int shell_show_ioapic_info(__unused int argc, __unused char **argv)
return 0;
}

-int shell_show_vmexit_profile(__unused int argc, __unused char **argv)
+static int shell_show_vmexit_profile(__unused int argc, __unused char **argv)
{
char *temp_str = alloc_pages(2U);

@@ -874,7 +897,7 @@ int shell_show_vmexit_profile(__unused int argc, __unused char **argv)
return 0;
}

-int shell_dump_logbuf(int argc, char **argv)
+static int shell_dump_logbuf(int argc, char **argv)
{
uint16_t pcpu_id;
int val;
@@ -891,7 +914,7 @@ int shell_dump_logbuf(int argc, char **argv)
return -EINVAL;
}

-int shell_loglevel(int argc, char **argv)
+static int shell_loglevel(int argc, char **argv)
{
char str[MAX_STR_SIZE] = {0};

@@ -912,7 +935,7 @@ int shell_loglevel(int argc, char **argv)
return 0;
}

-int shell_cpuid(int argc, char **argv)
+static int shell_cpuid(int argc, char **argv)
{
char str[MAX_STR_SIZE] = {0};
uint32_t leaf, subleaf = 0;
@@ -939,7 +962,7 @@ int shell_cpuid(int argc, char **argv)
return 0;
}

-int shell_trigger_crash(int argc, char **argv)
+static int shell_trigger_crash(int argc, char **argv)
{
char str[MAX_STR_SIZE] = {0};

@@ -951,12 +974,3 @@ int shell_trigger_crash(int argc, char **argv)

return 0;
}
-
-void shell_puts(const char *string_ptr)
-{
- /* Output the string */
- (void)console_write(string_ptr, strnlen_s(string_ptr,
- SHELL_STRING_MAX_LEN));
-}
-
-
diff --git a/hypervisor/debug/shell_priv.h b/hypervisor/debug/shell_priv.h
index 404bac0..159254e 100644
--- a/hypervisor/debug/shell_priv.h
+++ b/hypervisor/debug/shell_priv.h
@@ -4,31 +4,17 @@
* SPDX-License-Identifier: BSD-3-Clause
*/

-#ifndef SHELL_INTER_H
-#define SHELL_INTER_H
+#ifndef SHELL_PRIV_H
+#define SHELL_PRIV_H

#include <spinlock.h>

-struct shell;
-
-
#define SHELL_CMD_MAX_LEN 100U
#define SHELL_NAME_MAX_LEN 50
#define SHELL_PARA_MAX_LEN 64
#define SHELL_HELP_MAX_LEN 256
#define SHELL_STRING_MAX_LEN (CPU_PAGE_SIZE << 2)

-/* Shell Control Block */
-struct shell_cmd;
-struct shell {
- char input_line[2][SHELL_CMD_MAX_LEN + 1U]; /* current & last */
- char name[SHELL_NAME_MAX_LEN]; /* Session name */
- uint32_t input_line_len; /* Length of current input line */
- uint32_t input_line_active; /* Active input line index */
- struct shell_cmd *shell_cmd; /* cmds supported */
- uint32_t cmd_count; /* Count of cmds supported */
-};
-
/* Shell Command Function */
typedef int (*shell_cmd_fn_t)(int argc, char **argv);

@@ -41,6 +27,15 @@ struct shell_cmd {

};

+/* Shell Control Block */
+struct shell {
+ char input_line[2][SHELL_CMD_MAX_LEN + 1U]; /* current & last */
+ uint32_t input_line_len; /* Length of current input line */
+ uint32_t input_line_active; /* Active input line index */
+ struct shell_cmd *shell_cmd; /* cmds supported */
+ uint32_t cmd_count; /* Count of cmds supported */
+};
+
/* Shell Command list with parameters and help description */
#define SHELL_CMD_HELP "help"
#define SHELL_CMD_HELP_PARAM NULL
@@ -101,27 +96,4 @@ struct shell_cmd {
#define SHELL_CMD_CPUID "cpuid"
#define SHELL_CMD_CPUID_PARAM "<leaf> [subleaf]"
#define SHELL_CMD_CPUID_HELP "cpuid leaf [subleaf], in hexadecimal"
-
-/* Global function prototypes */
-int shell_show_req_info(__unused int argc, __unused char **argv);
-int shell_cmd_help(__unused int argc, __unused char **argv);
-int shell_list_vm(__unused int argc, __unused char **argv);
-int shell_list_vcpu(__unused int argc, __unused char **argv);
-int shell_vcpu_dumpreg(int argc, char **argv);
-int shell_dumpmem(int argc, char **argv);
-int shell_to_sos_console(int argc, char **argv);
-int shell_show_cpu_int(__unused int argc, __unused char **argv);
-int shell_show_ptdev_info(__unused int argc, __unused char **argv);
-int shell_reboot(__unused int argc, __unused char **argv);
-int shell_show_vioapic_info(int argc, char **argv);
-int shell_show_ioapic_info(__unused int argc, __unused char **argv);
-int shell_show_vmexit_profile(__unused int argc, __unused char **argv);
-int shell_dump_logbuf(int argc, char **argv);
-int shell_loglevel(int argc, char **argv);
-int shell_cpuid(int argc, char **argv);
-struct shell_cmd *shell_find_cmd(const char *cmd_str);
-int shell_process_cmd(char *p_input_line);
-void shell_puts(const char *string_ptr);
-int shell_trigger_crash(int argc, char **argv);
-
-#endif /* SHELL_INTER_H */
+#endif /* SHELL_PRIV_H */
--
2.7.4

Join acrn-dev@lists.projectacrn.org to automatically receive all group messages.