Tom Rini | 83d290c | 2018-05-06 17:58:06 -0400 | [diff] [blame] | 1 | // SPDX-License-Identifier: GPL-2.0+ |
Simon Glass | 8e2fac0 | 2015-04-28 20:25:11 -0600 | [diff] [blame] | 2 | /* |
| 3 | * Copyright (c) 2015 Google, Inc |
| 4 | * Written by Simon Glass <sjg@chromium.org> |
Álvaro Fernández Rojas | 320eca5 | 2017-04-25 00:39:17 +0200 | [diff] [blame] | 5 | * Copyright (c) 2017 Álvaro Fernández Rojas <noltari@gmail.com> |
Simon Glass | 8e2fac0 | 2015-04-28 20:25:11 -0600 | [diff] [blame] | 6 | */ |
| 7 | |
| 8 | #include <common.h> |
| 9 | #include <command.h> |
| 10 | #include <cpu.h> |
Simon Glass | 4e4bf94 | 2022-07-31 12:28:48 -0600 | [diff] [blame] | 11 | #include <display_options.h> |
Simon Glass | 8e2fac0 | 2015-04-28 20:25:11 -0600 | [diff] [blame] | 12 | #include <dm.h> |
Bin Meng | 166c398 | 2015-06-12 14:52:18 +0800 | [diff] [blame] | 13 | #include <errno.h> |
Simon Glass | 8e2fac0 | 2015-04-28 20:25:11 -0600 | [diff] [blame] | 14 | |
| 15 | static const char *cpu_feature_name[CPU_FEAT_COUNT] = { |
| 16 | "L1 cache", |
| 17 | "MMU", |
Simon Glass | 740d5d3 | 2016-03-06 19:27:49 -0700 | [diff] [blame] | 18 | "Microcode", |
Álvaro Fernández Rojas | 22c2c17 | 2017-04-25 00:39:13 +0200 | [diff] [blame] | 19 | "Device ID", |
Simon Glass | 8e2fac0 | 2015-04-28 20:25:11 -0600 | [diff] [blame] | 20 | }; |
| 21 | |
| 22 | static int print_cpu_list(bool detail) |
| 23 | { |
| 24 | struct udevice *dev; |
Simon Glass | 8e2fac0 | 2015-04-28 20:25:11 -0600 | [diff] [blame] | 25 | char buf[100]; |
Simon Glass | 8e2fac0 | 2015-04-28 20:25:11 -0600 | [diff] [blame] | 26 | |
Álvaro Fernández Rojas | 320eca5 | 2017-04-25 00:39:17 +0200 | [diff] [blame] | 27 | for (uclass_first_device(UCLASS_CPU, &dev); |
| 28 | dev; |
| 29 | uclass_next_device(&dev)) { |
Simon Glass | 8a8d24b | 2020-12-03 16:55:23 -0700 | [diff] [blame] | 30 | struct cpu_plat *plat = dev_get_parent_plat(dev); |
Simon Glass | 8e2fac0 | 2015-04-28 20:25:11 -0600 | [diff] [blame] | 31 | struct cpu_info info; |
Álvaro Fernández Rojas | 320eca5 | 2017-04-25 00:39:17 +0200 | [diff] [blame] | 32 | bool first = true; |
| 33 | int ret, i; |
Simon Glass | 8e2fac0 | 2015-04-28 20:25:11 -0600 | [diff] [blame] | 34 | |
| 35 | ret = cpu_get_desc(dev, buf, sizeof(buf)); |
Simon Glass | 8b85dfc | 2020-12-16 21:20:07 -0700 | [diff] [blame] | 36 | printf("%3d: %-10s %s\n", dev_seq(dev), dev->name, |
Simon Glass | 8e2fac0 | 2015-04-28 20:25:11 -0600 | [diff] [blame] | 37 | ret ? "<no description>" : buf); |
| 38 | if (!detail) |
| 39 | continue; |
| 40 | ret = cpu_get_info(dev, &info); |
| 41 | if (ret) { |
| 42 | printf("\t(no detail available"); |
| 43 | if (ret != -ENOSYS) |
Álvaro Fernández Rojas | 320eca5 | 2017-04-25 00:39:17 +0200 | [diff] [blame] | 44 | printf(": err=%d", ret); |
Simon Glass | 8e2fac0 | 2015-04-28 20:25:11 -0600 | [diff] [blame] | 45 | printf(")\n"); |
| 46 | continue; |
| 47 | } |
| 48 | printf("\tID = %d, freq = ", plat->cpu_id); |
| 49 | print_freq(info.cpu_freq, ""); |
Simon Glass | 8e2fac0 | 2015-04-28 20:25:11 -0600 | [diff] [blame] | 50 | for (i = 0; i < CPU_FEAT_COUNT; i++) { |
| 51 | if (info.features & (1 << i)) { |
| 52 | printf("%s%s", first ? ": " : ", ", |
| 53 | cpu_feature_name[i]); |
| 54 | first = false; |
| 55 | } |
| 56 | } |
| 57 | printf("\n"); |
Álvaro Fernández Rojas | 320eca5 | 2017-04-25 00:39:17 +0200 | [diff] [blame] | 58 | if (info.features & (1 << CPU_FEAT_UCODE)) |
Simon Glass | 740d5d3 | 2016-03-06 19:27:49 -0700 | [diff] [blame] | 59 | printf("\tMicrocode version %#x\n", |
| 60 | plat->ucode_version); |
Simon Glass | 740d5d3 | 2016-03-06 19:27:49 -0700 | [diff] [blame] | 61 | if (info.features & (1 << CPU_FEAT_DEVICE_ID)) |
| 62 | printf("\tDevice ID %#lx\n", plat->device_id); |
Simon Glass | 8e2fac0 | 2015-04-28 20:25:11 -0600 | [diff] [blame] | 63 | } |
| 64 | |
| 65 | return 0; |
| 66 | } |
| 67 | |
Simon Glass | 0914011 | 2020-05-10 11:40:03 -0600 | [diff] [blame] | 68 | static int do_cpu_list(struct cmd_tbl *cmdtp, int flag, int argc, |
Álvaro Fernández Rojas | 320eca5 | 2017-04-25 00:39:17 +0200 | [diff] [blame] | 69 | char *const argv[]) |
Simon Glass | 8e2fac0 | 2015-04-28 20:25:11 -0600 | [diff] [blame] | 70 | { |
| 71 | if (print_cpu_list(false)) |
| 72 | return CMD_RET_FAILURE; |
| 73 | |
| 74 | return 0; |
| 75 | } |
| 76 | |
Simon Glass | 0914011 | 2020-05-10 11:40:03 -0600 | [diff] [blame] | 77 | static int do_cpu_detail(struct cmd_tbl *cmdtp, int flag, int argc, |
Simon Glass | 8e2fac0 | 2015-04-28 20:25:11 -0600 | [diff] [blame] | 78 | char *const argv[]) |
| 79 | { |
| 80 | if (print_cpu_list(true)) |
| 81 | return CMD_RET_FAILURE; |
| 82 | |
| 83 | return 0; |
| 84 | } |
| 85 | |
Simon Glass | 5b4d810 | 2023-02-05 15:40:56 -0700 | [diff] [blame] | 86 | #if IS_ENABLED(CONFIG_SYS_LONGHELP) |
Ovidiu Panait | 15c924a | 2022-05-31 21:14:22 +0300 | [diff] [blame] | 87 | static char cpu_help_text[] = |
Simon Glass | 8e2fac0 | 2015-04-28 20:25:11 -0600 | [diff] [blame] | 88 | "list - list available CPUs\n" |
| 89 | "cpu detail - show CPU detail" |
Ovidiu Panait | 15c924a | 2022-05-31 21:14:22 +0300 | [diff] [blame] | 90 | ; |
| 91 | #endif |
| 92 | |
| 93 | U_BOOT_CMD_WITH_SUBCMDS(cpu, "display information about CPUs", cpu_help_text, |
| 94 | U_BOOT_SUBCMD_MKENT(list, 1, 1, do_cpu_list), |
| 95 | U_BOOT_SUBCMD_MKENT(detail, 1, 0, do_cpu_detail)); |