]> git.dujemihanovic.xyz Git - u-boot.git/commitdiff
x86: Add a cpuid command
authorSimon Glass <sjg@chromium.org>
Wed, 28 Aug 2024 01:44:28 +0000 (19:44 -0600)
committerSimon Glass <sjg@chromium.org>
Fri, 18 Oct 2024 20:10:21 +0000 (14:10 -0600)
It is useful to obtain the results of cpuid queries, so add a command
for this.

Signed-off-by: Simon Glass <sjg@chromium.org>
cmd/x86/Makefile
cmd/x86/cpuid.c [new file with mode: 0644]
doc/usage/cmd/cpuid.rst [new file with mode: 0644]
doc/usage/index.rst
test/cmd/Makefile
test/cmd/cpuid.c [new file with mode: 0644]

index b1f39d3bfde52d9b4685807177b04f6907e3f243..1648907ac2da1294e2ecd2eae96137f0aec41e97 100644 (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
diff --git a/cmd/x86/cpuid.c b/cmd/x86/cpuid.c
new file mode 100644 (file)
index 0000000..222754b
--- /dev/null
@@ -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
+);
diff --git a/doc/usage/cmd/cpuid.rst b/doc/usage/cmd/cpuid.rst
new file mode 100644 (file)
index 0000000..cccf926
--- /dev/null
@@ -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
index fcce125a611de2aae4a57c49b863cd9092101be4..d2b187b0118cce298d231f6b6b174ee18449d11f 100644 (file)
@@ -52,6 +52,7 @@ Shell commands
    cmd/conitrace
    cmd/cp
    cmd/cpu
+   cmd/cpuid
    cmd/cyclic
    cmd/dm
    cmd/ebtupdate
index dbee9b26405667e1bae6d4ad295df3dceeee1254..302c748389bd3b6ec8d4d31b6fd63ec2daab87c6 100644 (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
diff --git a/test/cmd/cpuid.c b/test/cmd/cpuid.c
new file mode 100644 (file)
index 0000000..e07f5fd
--- /dev/null
@@ -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);