Skip to content

Commit ace23b5

Browse files
lifeixjren1
authored andcommitted
hv: shell: add cpuid command
Add cpuid shell command for test Signed-off-by: Li, Fei1 <fei1.li@intel.com>
1 parent c83bcde commit ace23b5

File tree

3 files changed

+44
-0
lines changed

3 files changed

+44
-0
lines changed

hypervisor/debug/shell_internal.c

Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1040,6 +1040,34 @@ int shell_set_loglevel(struct shell *p_shell, int argc, char **argv)
10401040
return status;
10411041
}
10421042

1043+
int shell_cpuid(struct shell *p_shell, int argc, char **argv)
1044+
{
1045+
char str[MAX_STR_SIZE] = {0};
1046+
uint32_t leaf, subleaf = 0;
1047+
uint32_t eax, ebx, ecx, edx;
1048+
1049+
if (argc == 2) {
1050+
leaf = strtoul(argv[1], NULL, 16);
1051+
} else if (argc == 3) {
1052+
leaf = strtoul(argv[1], NULL, 16);
1053+
subleaf = strtoul(argv[2], NULL, 16);
1054+
} else {
1055+
shell_puts(p_shell,
1056+
"Please enter correct cmd with "
1057+
"cpuid <leaf> [subleaf]\r\n");
1058+
return -EINVAL;
1059+
}
1060+
1061+
cpuid_subleaf(leaf, subleaf, &eax, &ebx, &ecx, &edx);
1062+
snprintf(str, MAX_STR_SIZE,
1063+
"cpuid leaf: 0x%x, subleaf: 0x%x, 0x%x:0x%x:0x%x:0x%x\r\n",
1064+
leaf, subleaf, eax, ebx, ecx, edx);
1065+
1066+
shell_puts(p_shell, str);
1067+
1068+
return 0;
1069+
}
1070+
10431071
int shell_terminate_serial(struct shell *p_shell)
10441072
{
10451073
/* Shell shouldn't own the serial port handle anymore. */

hypervisor/debug/shell_internal.h

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -149,6 +149,10 @@ struct shell_cmd {
149149
#define SHELL_CMD_SET_LOG_LVL_PARAM "<console_loglevel> [mem_loglevel]"
150150
#define SHELL_CMD_SET_LOG_LVL_HELP "Set loglevel [0-6]"
151151

152+
#define SHELL_CMD_CPUID "cpuid"
153+
#define SHELL_CMD_CPUID_PARAM "<leaf> [subleaf]"
154+
#define SHELL_CMD_CPUID_HELP "cpuid leaf [subleaf], in hexadecimal"
155+
152156

153157
/* Global function prototypes */
154158
int shell_show_req_info(struct shell *p_shell, int argc, char **argv);
@@ -172,6 +176,7 @@ int shell_show_vmexit_profile(struct shell *p_shell, int argc, char **argv);
172176
int shell_dump_logbuf(struct shell *p_shell, int argc, char **argv);
173177
int shell_get_loglevel(struct shell *p_shell, int argc, char **argv);
174178
int shell_set_loglevel(struct shell *p_shell, int argc, char **argv);
179+
int shell_cpuid(struct shell *p_shell, int argc, char **argv);
175180
struct shell_cmd *shell_find_cmd(struct shell *p_shell, const char *cmd);
176181
int shell_process_cmd(struct shell *p_shell, char *p_input_line);
177182
int shell_terminate_serial(struct shell *p_shell);

hypervisor/debug/shell_public.c

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -356,6 +356,17 @@ int shell_init(void)
356356
pr_err("Error: Command \"%s\" registration failed.",
357357
SHELL_CMD_SET_LOG_LVL);
358358
}
359+
360+
status = shell_register_cmd(serial_session,
361+
SHELL_CMD_CPUID,
362+
SHELL_CMD_CPUID_PARAM,
363+
SHELL_CMD_CPUID_HELP,
364+
shell_cpuid);
365+
366+
if (status != 0) {
367+
pr_err("Error: Command \"%s\" registration failed.",
368+
SHELL_CMD_CPUID);
369+
}
359370
}
360371

361372
return status;

0 commit comments

Comments
 (0)