blob: 6213c720cbf472371fd722f5e56673291f84693d [file] [log] [blame]
Simon Glass9e8ff542015-04-28 20:25:11 -06001/*
2 * Copyright (c) 2015 Google, Inc
3 * Written by Simon Glass <sjg@chromium.org>
Álvaro Fernández Rojas31845052017-04-25 00:39:17 +02004 * Copyright (c) 2017 Álvaro Fernández Rojas <noltari@gmail.com>
Simon Glass9e8ff542015-04-28 20:25:11 -06005 *
6 * SPDX-License-Identifier: GPL-2.0+
7 */
8
9#include <common.h>
10#include <command.h>
11#include <cpu.h>
12#include <dm.h>
Bin Mengb891f782015-06-12 14:52:18 +080013#include <errno.h>
Simon Glass9e8ff542015-04-28 20:25:11 -060014
15static const char *cpu_feature_name[CPU_FEAT_COUNT] = {
16 "L1 cache",
17 "MMU",
Simon Glass8d374cd2016-03-06 19:27:49 -070018 "Microcode",
Álvaro Fernández Rojas696cedf2017-04-25 00:39:13 +020019 "Device ID",
Simon Glass9e8ff542015-04-28 20:25:11 -060020};
21
22static int print_cpu_list(bool detail)
23{
24 struct udevice *dev;
Simon Glass9e8ff542015-04-28 20:25:11 -060025 char buf[100];
Simon Glass9e8ff542015-04-28 20:25:11 -060026
Álvaro Fernández Rojas31845052017-04-25 00:39:17 +020027 for (uclass_first_device(UCLASS_CPU, &dev);
28 dev;
29 uclass_next_device(&dev)) {
Simon Glass9e8ff542015-04-28 20:25:11 -060030 struct cpu_platdata *plat = dev_get_parent_platdata(dev);
31 struct cpu_info info;
Álvaro Fernández Rojas31845052017-04-25 00:39:17 +020032 bool first = true;
33 int ret, i;
Simon Glass9e8ff542015-04-28 20:25:11 -060034
35 ret = cpu_get_desc(dev, buf, sizeof(buf));
36 printf("%3d: %-10s %s\n", dev->seq, dev->name,
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 Rojas31845052017-04-25 00:39:17 +020044 printf(": err=%d", ret);
Simon Glass9e8ff542015-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 Glass9e8ff542015-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 Rojas31845052017-04-25 00:39:17 +020058 if (info.features & (1 << CPU_FEAT_UCODE))
Simon Glass8d374cd2016-03-06 19:27:49 -070059 printf("\tMicrocode version %#x\n",
60 plat->ucode_version);
Simon Glass8d374cd2016-03-06 19:27:49 -070061 if (info.features & (1 << CPU_FEAT_DEVICE_ID))
62 printf("\tDevice ID %#lx\n", plat->device_id);
Simon Glass9e8ff542015-04-28 20:25:11 -060063 }
64
65 return 0;
66}
67
Álvaro Fernández Rojas31845052017-04-25 00:39:17 +020068static int do_cpu_list(cmd_tbl_t *cmdtp, int flag, int argc,
69 char *const argv[])
Simon Glass9e8ff542015-04-28 20:25:11 -060070{
71 if (print_cpu_list(false))
72 return CMD_RET_FAILURE;
73
74 return 0;
75}
76
77static int do_cpu_detail(cmd_tbl_t *cmdtp, int flag, int argc,
78 char *const argv[])
79{
80 if (print_cpu_list(true))
81 return CMD_RET_FAILURE;
82
83 return 0;
84}
85
86static cmd_tbl_t cmd_cpu_sub[] = {
87 U_BOOT_CMD_MKENT(list, 2, 1, do_cpu_list, "", ""),
88 U_BOOT_CMD_MKENT(detail, 4, 0, do_cpu_detail, "", ""),
89};
90
91/*
92 * Process a cpu sub-command
93 */
94static int do_cpu(cmd_tbl_t *cmdtp, int flag, int argc,
Álvaro Fernández Rojas31845052017-04-25 00:39:17 +020095 char * const argv[])
Simon Glass9e8ff542015-04-28 20:25:11 -060096{
97 cmd_tbl_t *c = NULL;
98
99 /* Strip off leading 'cpu' command argument */
100 argc--;
101 argv++;
102
103 if (argc)
Álvaro Fernández Rojas31845052017-04-25 00:39:17 +0200104 c = find_cmd_tbl(argv[0], cmd_cpu_sub,
105 ARRAY_SIZE(cmd_cpu_sub));
Simon Glass9e8ff542015-04-28 20:25:11 -0600106
107 if (c)
108 return c->cmd(cmdtp, flag, argc, argv);
109 else
110 return CMD_RET_USAGE;
111}
112
113U_BOOT_CMD(
114 cpu, 2, 1, do_cpu,
115 "display information about CPUs",
116 "list - list available CPUs\n"
117 "cpu detail - show CPU detail"
118);