x86: Add msr command

It is useful to obtain the results of MSR queries as well as to update
MSR registers, so add a command these tasks.

Signed-off-by: Simon Glass <sjg@chromium.org>
diff --git a/cmd/x86/Makefile b/cmd/x86/Makefile
index 1648907..9252152 100644
--- a/cmd/x86/Makefile
+++ b/cmd/x86/Makefile
@@ -1,7 +1,7 @@
 # SPDX-License-Identifier: GPL-2.0+
 
 obj-$(CONFIG_CMD_CBSYSINFO) += cbsysinfo.o
-obj-y += cpuid.o mtrr.o
+obj-y += cpuid.o msr.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/msr.c b/cmd/x86/msr.c
new file mode 100644
index 0000000..3cb70d1
--- /dev/null
+++ b/cmd/x86/msr.c
@@ -0,0 +1,52 @@
+// 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/msr.h>
+
+static int do_read(struct cmd_tbl *cmdtp, int flag, int argc,
+		   char *const argv[])
+{
+	struct msr_t msr;
+	ulong op;
+
+	if (argc < 2)
+		return CMD_RET_USAGE;
+
+	op = hextoul(argv[1], NULL);
+	msr = msr_read(op);
+	printf("%08x %08x\n", msr.hi, msr.lo);
+
+	return 0;
+}
+
+static int do_write(struct cmd_tbl *cmdtp, int flag, int argc,
+		    char *const argv[])
+{
+	struct msr_t msr;
+	ulong op;
+
+	if (argc < 4)
+		return CMD_RET_USAGE;
+
+	op = hextoul(argv[1], NULL);
+	msr.hi = hextoul(argv[2], NULL);
+	msr.lo = hextoul(argv[3], NULL);
+	msr_write(op, msr);
+
+	return 0;
+}
+
+U_BOOT_LONGHELP(msr,
+	"read <op>         - read a machine-status register (MSR) as <hi 32-bits> <lo 32-bits>\n"
+	"write <op< <hi> <lo>  - write an MSR");
+
+U_BOOT_CMD_WITH_SUBCMDS(msr, "Machine Status Registers", msr_help_text,
+	U_BOOT_CMD_MKENT(read, CONFIG_SYS_MAXARGS, 1, do_read, "", ""),
+	U_BOOT_CMD_MKENT(write, CONFIG_SYS_MAXARGS, 1, do_write, "", ""));