blob: 9e323069b9e8652f0291201052ffb24625f69747 [file] [log] [blame]
Tom Rini10e47792018-05-06 17:58:06 -04001// SPDX-License-Identifier: GPL-2.0+
Simon Glass9e8ff542015-04-28 20:25:11 -06002/*
3 * Copyright (c) 2015 Google, Inc
4 * Written by Simon Glass <sjg@chromium.org>
Álvaro Fernández Rojas31845052017-04-25 00:39:17 +02005 * Copyright (c) 2017 Álvaro Fernández Rojas <noltari@gmail.com>
Simon Glass9e8ff542015-04-28 20:25:11 -06006 */
7
Simon Glass9e8ff542015-04-28 20:25:11 -06008#include <command.h>
9#include <cpu.h>
Simon Glass1ab16922022-07-31 12:28:48 -060010#include <display_options.h>
Simon Glass9e8ff542015-04-28 20:25:11 -060011#include <dm.h>
Bin Mengb891f782015-06-12 14:52:18 +080012#include <errno.h>
Simon Glass9e8ff542015-04-28 20:25:11 -060013
14static const char *cpu_feature_name[CPU_FEAT_COUNT] = {
15 "L1 cache",
16 "MMU",
Simon Glass8d374cd2016-03-06 19:27:49 -070017 "Microcode",
Álvaro Fernández Rojas696cedf2017-04-25 00:39:13 +020018 "Device ID",
Simon Glass9e8ff542015-04-28 20:25:11 -060019};
20
21static int print_cpu_list(bool detail)
22{
23 struct udevice *dev;
Simon Glass9e8ff542015-04-28 20:25:11 -060024 char buf[100];
Simon Glass9e8ff542015-04-28 20:25:11 -060025
Álvaro Fernández Rojas31845052017-04-25 00:39:17 +020026 for (uclass_first_device(UCLASS_CPU, &dev);
27 dev;
28 uclass_next_device(&dev)) {
Simon Glassb75b15b2020-12-03 16:55:23 -070029 struct cpu_plat *plat = dev_get_parent_plat(dev);
Simon Glass9e8ff542015-04-28 20:25:11 -060030 struct cpu_info info;
Álvaro Fernández Rojas31845052017-04-25 00:39:17 +020031 bool first = true;
32 int ret, i;
Simon Glass9e8ff542015-04-28 20:25:11 -060033
34 ret = cpu_get_desc(dev, buf, sizeof(buf));
Simon Glass75e534b2020-12-16 21:20:07 -070035 printf("%3d: %-10s %s\n", dev_seq(dev), dev->name,
Simon Glass9e8ff542015-04-28 20:25:11 -060036 ret ? "<no description>" : buf);
37 if (!detail)
38 continue;
39 ret = cpu_get_info(dev, &info);
40 if (ret) {
41 printf("\t(no detail available");
42 if (ret != -ENOSYS)
Álvaro Fernández Rojas31845052017-04-25 00:39:17 +020043 printf(": err=%d", ret);
Simon Glass9e8ff542015-04-28 20:25:11 -060044 printf(")\n");
45 continue;
46 }
47 printf("\tID = %d, freq = ", plat->cpu_id);
48 print_freq(info.cpu_freq, "");
Simon Glass9e8ff542015-04-28 20:25:11 -060049 for (i = 0; i < CPU_FEAT_COUNT; i++) {
50 if (info.features & (1 << i)) {
51 printf("%s%s", first ? ": " : ", ",
52 cpu_feature_name[i]);
53 first = false;
54 }
55 }
56 printf("\n");
Álvaro Fernández Rojas31845052017-04-25 00:39:17 +020057 if (info.features & (1 << CPU_FEAT_UCODE))
Simon Glass8d374cd2016-03-06 19:27:49 -070058 printf("\tMicrocode version %#x\n",
59 plat->ucode_version);
Simon Glass8d374cd2016-03-06 19:27:49 -070060 if (info.features & (1 << CPU_FEAT_DEVICE_ID))
61 printf("\tDevice ID %#lx\n", plat->device_id);
Simon Glass9e8ff542015-04-28 20:25:11 -060062 }
63
64 return 0;
65}
66
Simon Glassed38aef2020-05-10 11:40:03 -060067static int do_cpu_list(struct cmd_tbl *cmdtp, int flag, int argc,
Álvaro Fernández Rojas31845052017-04-25 00:39:17 +020068 char *const argv[])
Simon Glass9e8ff542015-04-28 20:25:11 -060069{
70 if (print_cpu_list(false))
71 return CMD_RET_FAILURE;
72
73 return 0;
74}
75
Simon Glassed38aef2020-05-10 11:40:03 -060076static int do_cpu_detail(struct cmd_tbl *cmdtp, int flag, int argc,
Simon Glass9e8ff542015-04-28 20:25:11 -060077 char *const argv[])
78{
79 if (print_cpu_list(true))
80 return CMD_RET_FAILURE;
81
82 return 0;
83}
84
Tom Rini03f146c2023-10-07 15:13:08 -040085U_BOOT_LONGHELP(cpu,
Simon Glass9e8ff542015-04-28 20:25:11 -060086 "list - list available CPUs\n"
Tom Rini03f146c2023-10-07 15:13:08 -040087 "cpu detail - show CPU detail");
Ovidiu Panait344e3332022-05-31 21:14:22 +030088
89U_BOOT_CMD_WITH_SUBCMDS(cpu, "display information about CPUs", cpu_help_text,
90 U_BOOT_SUBCMD_MKENT(list, 1, 1, do_cpu_list),
91 U_BOOT_SUBCMD_MKENT(detail, 1, 0, do_cpu_detail));