]>
Commit | Line | Data |
---|---|---|
83d290c5 | 1 | // SPDX-License-Identifier: GPL-2.0+ |
8e2fac05 SG |
2 | /* |
3 | * Copyright (c) 2015 Google, Inc | |
4 | * Written by Simon Glass <[email protected]> | |
320eca5c | 5 | * Copyright (c) 2017 Álvaro Fernández Rojas <[email protected]> |
8e2fac05 SG |
6 | */ |
7 | ||
8 | #include <common.h> | |
9 | #include <command.h> | |
10 | #include <cpu.h> | |
4e4bf944 | 11 | #include <display_options.h> |
8e2fac05 | 12 | #include <dm.h> |
166c3984 | 13 | #include <errno.h> |
8e2fac05 SG |
14 | |
15 | static const char *cpu_feature_name[CPU_FEAT_COUNT] = { | |
16 | "L1 cache", | |
17 | "MMU", | |
740d5d34 | 18 | "Microcode", |
22c2c179 | 19 | "Device ID", |
8e2fac05 SG |
20 | }; |
21 | ||
22 | static int print_cpu_list(bool detail) | |
23 | { | |
24 | struct udevice *dev; | |
8e2fac05 | 25 | char buf[100]; |
8e2fac05 | 26 | |
320eca5c ÁFR |
27 | for (uclass_first_device(UCLASS_CPU, &dev); |
28 | dev; | |
29 | uclass_next_device(&dev)) { | |
8a8d24bd | 30 | struct cpu_plat *plat = dev_get_parent_plat(dev); |
8e2fac05 | 31 | struct cpu_info info; |
320eca5c ÁFR |
32 | bool first = true; |
33 | int ret, i; | |
8e2fac05 SG |
34 | |
35 | ret = cpu_get_desc(dev, buf, sizeof(buf)); | |
8b85dfc6 | 36 | printf("%3d: %-10s %s\n", dev_seq(dev), dev->name, |
8e2fac05 SG |
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) | |
320eca5c | 44 | printf(": err=%d", ret); |
8e2fac05 SG |
45 | printf(")\n"); |
46 | continue; | |
47 | } | |
48 | printf("\tID = %d, freq = ", plat->cpu_id); | |
49 | print_freq(info.cpu_freq, ""); | |
8e2fac05 SG |
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"); | |
320eca5c | 58 | if (info.features & (1 << CPU_FEAT_UCODE)) |
740d5d34 SG |
59 | printf("\tMicrocode version %#x\n", |
60 | plat->ucode_version); | |
740d5d34 SG |
61 | if (info.features & (1 << CPU_FEAT_DEVICE_ID)) |
62 | printf("\tDevice ID %#lx\n", plat->device_id); | |
8e2fac05 SG |
63 | } |
64 | ||
65 | return 0; | |
66 | } | |
67 | ||
09140113 | 68 | static int do_cpu_list(struct cmd_tbl *cmdtp, int flag, int argc, |
320eca5c | 69 | char *const argv[]) |
8e2fac05 SG |
70 | { |
71 | if (print_cpu_list(false)) | |
72 | return CMD_RET_FAILURE; | |
73 | ||
74 | return 0; | |
75 | } | |
76 | ||
09140113 | 77 | static int do_cpu_detail(struct cmd_tbl *cmdtp, int flag, int argc, |
8e2fac05 SG |
78 | char *const argv[]) |
79 | { | |
80 | if (print_cpu_list(true)) | |
81 | return CMD_RET_FAILURE; | |
82 | ||
83 | return 0; | |
84 | } | |
85 | ||
5b4d810d | 86 | #if IS_ENABLED(CONFIG_SYS_LONGHELP) |
15c924a7 | 87 | static char cpu_help_text[] = |
8e2fac05 SG |
88 | "list - list available CPUs\n" |
89 | "cpu detail - show CPU detail" | |
15c924a7 OP |
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)); |