x86: Add a cpuid command

It is useful to obtain the results of cpuid queries, so add a command
for this.

Signed-off-by: Simon Glass <sjg@chromium.org>
This commit is contained in:
Simon Glass 2024-08-27 19:44:28 -06:00
parent ecf31113f1
commit 557767f802
6 changed files with 130 additions and 1 deletions

View file

@ -1,7 +1,7 @@
# SPDX-License-Identifier: GPL-2.0+
obj-$(CONFIG_CMD_CBSYSINFO) += cbsysinfo.o
obj-y += mtrr.o
obj-y += cpuid.o mtrr.o
obj-$(CONFIG_CMD_EXCEPTION) += exception.o
obj-$(CONFIG_USE_HOB) += hob.o
obj-$(CONFIG_HAVE_FSP) += fsp.o

37
cmd/x86/cpuid.c Normal file
View file

@ -0,0 +1,37 @@
// SPDX-License-Identifier: GPL-2.0+
/*
* The 'cpuid' command provides access to the CPU's cpuid information
*
* Copyright 2024 Google, LLC
* Written by Simon Glass <sjg@chromium.org>
*/
#include <command.h>
#include <vsprintf.h>
#include <asm/cpu.h>
static int do_cpuid(struct cmd_tbl *cmdtp, int flag, int argc,
char *const argv[])
{
struct cpuid_result res;
ulong op;
if (argc < 2)
return CMD_RET_USAGE;
op = hextoul(argv[1], NULL);
res = cpuid(op);
printf("eax %08x\n", res.eax);
printf("ebx %08x\n", res.ebx);
printf("ecx %08x\n", res.ecx);
printf("edx %08x\n", res.edx);
return 0;
}
U_BOOT_LONGHELP(cpuid, "Show CPU Identification information");
U_BOOT_CMD(
cpuid, 2, 1, do_cpuid,
"cpuid <op>", cpuid_help_text
);

68
doc/usage/cmd/cpuid.rst Normal file
View file

@ -0,0 +1,68 @@
.. SPDX-License-Identifier: GPL-2.0+
.. index::
single: cpuid (command)
cpuid command
=============
Synopsis
--------
::
cpuid <op>
Description
-----------
The cpuid command requests CPU-identification information on x86 CPUs. The
operation <op> selects what information is returned. Up to four 32-bit registers
can be update (eax-edx) depending on the operation.
Configuration
-------------
The cpuid command is only available on x86.
Return value
------------
The return value $? is 0 (true).
Example
-------
::
=> cpuid 1
eax 00060fb1
ebx 00040800
ecx 80002001
edx 178bfbfd
This shows checking for 64-bit 'long' mode::
=> cpuid 80000000
eax 8000000a
ebx 68747541
ecx 444d4163
edx 69746e65
=> cpuid 80000001
eax 00060fb1
ebx 00000000
ecx 00000007
edx 2193fbfd # Bit 29 is set in edx, so long mode is available
On a 32-bit-only CPU::
=> cpuid 80000000
eax 80000004
ebx 756e6547
ecx 6c65746e
edx 49656e69
=> cpuid 80000001
eax 00000663
ebx 00000000
ecx 00000000
edx 00000000 # Bit 29 is not set in edx, so long mode is not available

View file

@ -52,6 +52,7 @@ Shell commands
cmd/conitrace
cmd/cp
cmd/cpu
cmd/cpuid
cmd/cyclic
cmd/dm
cmd/ebtupdate

View file

@ -12,6 +12,7 @@ ifdef CONFIG_CONSOLE_RECORD
obj-$(CONFIG_CMD_PAUSE) += test_pause.o
endif
obj-y += exit.o mem.o
obj-$(CONFIG_X86) += cpuid.o
obj-$(CONFIG_CMD_ADDRMAP) += addrmap.o
obj-$(CONFIG_CMD_BDI) += bdinfo.o
obj-$(CONFIG_CMD_FDT) += fdt.o

22
test/cmd/cpuid.c Normal file
View file

@ -0,0 +1,22 @@
// SPDX-License-Identifier: GPL-2.0+
/*
* Tests for cpuid command
*
* Copyright 2024 Google LLC
* Written by Simon Glass <sjg@chromium.org>
*/
#include <test/cmd.h>
#include <test/ut.h>
static int cmd_test_cpuid(struct unit_test_state *uts)
{
ut_assertok(run_commandf("cpuid 1"));
ut_assert_nextline("eax 00060fb1");
ut_assert_nextline("ebx 00000800");
ut_assert_nextline("ecx 80002001");
ut_assert_nextline("edx 078bfbfd");
return 0;
}
CMD_TEST(cmd_test_cpuid, UTF_CONSOLE);