blob: a09736e1bb91852e8c452c04b3721b45edaecaf8 [file] [log] [blame]
Tom Rini83d290c2018-05-06 17:58:06 -04001// SPDX-License-Identifier: GPL-2.0+
Simon Glass8e2fac02015-04-28 20:25:11 -06002/*
3 * Copyright (c) 2015 Google, Inc
4 * Written by Simon Glass <sjg@chromium.org>
Álvaro Fernández Rojas320eca52017-04-25 00:39:17 +02005 * Copyright (c) 2017 Álvaro Fernández Rojas <noltari@gmail.com>
Simon Glass8e2fac02015-04-28 20:25:11 -06006 */
7
8#include <common.h>
9#include <command.h>
10#include <cpu.h>
Simon Glass4e4bf942022-07-31 12:28:48 -060011#include <display_options.h>
Simon Glass8e2fac02015-04-28 20:25:11 -060012#include <dm.h>
Bin Meng166c3982015-06-12 14:52:18 +080013#include <errno.h>
Simon Glass8e2fac02015-04-28 20:25:11 -060014
15static const char *cpu_feature_name[CPU_FEAT_COUNT] = {
16 "L1 cache",
17 "MMU",
Simon Glass740d5d32016-03-06 19:27:49 -070018 "Microcode",
Álvaro Fernández Rojas22c2c172017-04-25 00:39:13 +020019 "Device ID",
Simon Glass8e2fac02015-04-28 20:25:11 -060020};
21
22static int print_cpu_list(bool detail)
23{
24 struct udevice *dev;
Simon Glass8e2fac02015-04-28 20:25:11 -060025 char buf[100];
Simon Glass8e2fac02015-04-28 20:25:11 -060026
Álvaro Fernández Rojas320eca52017-04-25 00:39:17 +020027 for (uclass_first_device(UCLASS_CPU, &dev);
28 dev;
29 uclass_next_device(&dev)) {
Simon Glass8a8d24b2020-12-03 16:55:23 -070030 struct cpu_plat *plat = dev_get_parent_plat(dev);
Simon Glass8e2fac02015-04-28 20:25:11 -060031 struct cpu_info info;
Álvaro Fernández Rojas320eca52017-04-25 00:39:17 +020032 bool first = true;
33 int ret, i;
Simon Glass8e2fac02015-04-28 20:25:11 -060034
35 ret = cpu_get_desc(dev, buf, sizeof(buf));
Simon Glass8b85dfc2020-12-16 21:20:07 -070036 printf("%3d: %-10s %s\n", dev_seq(dev), dev->name,
Simon Glass8e2fac02015-04-28 20:25:11 -060037 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 Rojas320eca52017-04-25 00:39:17 +020044 printf(": err=%d", ret);
Simon Glass8e2fac02015-04-28 20:25:11 -060045 printf(")\n");
46 continue;
47 }
48 printf("\tID = %d, freq = ", plat->cpu_id);
49 print_freq(info.cpu_freq, "");
Simon Glass8e2fac02015-04-28 20:25:11 -060050 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 Rojas320eca52017-04-25 00:39:17 +020058 if (info.features & (1 << CPU_FEAT_UCODE))
Simon Glass740d5d32016-03-06 19:27:49 -070059 printf("\tMicrocode version %#x\n",
60 plat->ucode_version);
Simon Glass740d5d32016-03-06 19:27:49 -070061 if (info.features & (1 << CPU_FEAT_DEVICE_ID))
62 printf("\tDevice ID %#lx\n", plat->device_id);
Simon Glass8e2fac02015-04-28 20:25:11 -060063 }
64
65 return 0;
66}
67
Simon Glass09140112020-05-10 11:40:03 -060068static int do_cpu_list(struct cmd_tbl *cmdtp, int flag, int argc,
Álvaro Fernández Rojas320eca52017-04-25 00:39:17 +020069 char *const argv[])
Simon Glass8e2fac02015-04-28 20:25:11 -060070{
71 if (print_cpu_list(false))
72 return CMD_RET_FAILURE;
73
74 return 0;
75}
76
Simon Glass09140112020-05-10 11:40:03 -060077static int do_cpu_detail(struct cmd_tbl *cmdtp, int flag, int argc,
Simon Glass8e2fac02015-04-28 20:25:11 -060078 char *const argv[])
79{
80 if (print_cpu_list(true))
81 return CMD_RET_FAILURE;
82
83 return 0;
84}
85
Ovidiu Panait15c924a2022-05-31 21:14:22 +030086#if CONFIG_IS_ENABLED(SYS_LONGHELP)
87static char cpu_help_text[] =
Simon Glass8e2fac02015-04-28 20:25:11 -060088 "list - list available CPUs\n"
89 "cpu detail - show CPU detail"
Ovidiu Panait15c924a2022-05-31 21:14:22 +030090 ;
91#endif
92
93U_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));