Simon Glass | 18c2ccc | 2024-08-27 19:44:29 -0600 | [diff] [blame] | 1 | // 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 | |
| 13 | static 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 | |
| 29 | static 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 | |
| 46 | U_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 | |
| 50 | U_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, "", "")); |