blob: 3cb70d1f89a865125b299f40e8c5782dbb784e9f [file] [log] [blame]
Simon Glass18c2ccc2024-08-27 19:44:29 -06001// SPDX-License-Identifier: GPL-2.0+
2/*
3 * The 'cpuid' command provides access to the CPU's cpuid information
4 *
5 * Copyright 2024 Google, LLC
6 * Written by Simon Glass <sjg@chromium.org>
7 */
8
9#include <command.h>
10#include <vsprintf.h>
11#include <asm/msr.h>
12
13static int do_read(struct cmd_tbl *cmdtp, int flag, int argc,
14 char *const argv[])
15{
16 struct msr_t msr;
17 ulong op;
18
19 if (argc < 2)
20 return CMD_RET_USAGE;
21
22 op = hextoul(argv[1], NULL);
23 msr = msr_read(op);
24 printf("%08x %08x\n", msr.hi, msr.lo);
25
26 return 0;
27}
28
29static int do_write(struct cmd_tbl *cmdtp, int flag, int argc,
30 char *const argv[])
31{
32 struct msr_t msr;
33 ulong op;
34
35 if (argc < 4)
36 return CMD_RET_USAGE;
37
38 op = hextoul(argv[1], NULL);
39 msr.hi = hextoul(argv[2], NULL);
40 msr.lo = hextoul(argv[3], NULL);
41 msr_write(op, msr);
42
43 return 0;
44}
45
46U_BOOT_LONGHELP(msr,
47 "read <op> - read a machine-status register (MSR) as <hi 32-bits> <lo 32-bits>\n"
48 "write <op< <hi> <lo> - write an MSR");
49
50U_BOOT_CMD_WITH_SUBCMDS(msr, "Machine Status Registers", msr_help_text,
51 U_BOOT_CMD_MKENT(read, CONFIG_SYS_MAXARGS, 1, do_read, "", ""),
52 U_BOOT_CMD_MKENT(write, CONFIG_SYS_MAXARGS, 1, do_write, "", ""));