blob: c3e229f00abc72d2aee589e790750a7e9063b5cc [file] [log] [blame]
Simon Glass8e2fac02015-04-28 20:25:11 -06001/*
2 * Copyright (c) 2015 Google, Inc
3 * Written by Simon Glass <sjg@chromium.org>
4 *
5 * SPDX-License-Identifier: GPL-2.0+
6 */
7
8#include <common.h>
9#include <command.h>
10#include <cpu.h>
11#include <dm.h>
12
13static const char *cpu_feature_name[CPU_FEAT_COUNT] = {
14 "L1 cache",
15 "MMU",
16};
17
18static int print_cpu_list(bool detail)
19{
20 struct udevice *dev;
21 struct uclass *uc;
22 char buf[100];
23 int ret;
24
25 ret = uclass_get(UCLASS_CPU, &uc);
26 if (ret) {
27 printf("Cannot find CPU uclass\n");
28 return ret;
29 }
30 uclass_foreach_dev(dev, uc) {
31 struct cpu_platdata *plat = dev_get_parent_platdata(dev);
32 struct cpu_info info;
33 bool first;
34 int i;
35
36 ret = cpu_get_desc(dev, buf, sizeof(buf));
37 printf("%3d: %-10s %s\n", dev->seq, dev->name,
38 ret ? "<no description>" : buf);
39 if (!detail)
40 continue;
41 ret = cpu_get_info(dev, &info);
42 if (ret) {
43 printf("\t(no detail available");
44 if (ret != -ENOSYS)
45 printf(": err=%d\n", ret);
46 printf(")\n");
47 continue;
48 }
49 printf("\tID = %d, freq = ", plat->cpu_id);
50 print_freq(info.cpu_freq, "");
51 first = true;
52 for (i = 0; i < CPU_FEAT_COUNT; i++) {
53 if (info.features & (1 << i)) {
54 printf("%s%s", first ? ": " : ", ",
55 cpu_feature_name[i]);
56 first = false;
57 }
58 }
59 printf("\n");
60 }
61
62 return 0;
63}
64
65static int do_cpu_list(cmd_tbl_t *cmdtp, int flag, int argc, char *const argv[])
66{
67 if (print_cpu_list(false))
68 return CMD_RET_FAILURE;
69
70 return 0;
71}
72
73static int do_cpu_detail(cmd_tbl_t *cmdtp, int flag, int argc,
74 char *const argv[])
75{
76 if (print_cpu_list(true))
77 return CMD_RET_FAILURE;
78
79 return 0;
80}
81
82static cmd_tbl_t cmd_cpu_sub[] = {
83 U_BOOT_CMD_MKENT(list, 2, 1, do_cpu_list, "", ""),
84 U_BOOT_CMD_MKENT(detail, 4, 0, do_cpu_detail, "", ""),
85};
86
87/*
88 * Process a cpu sub-command
89 */
90static int do_cpu(cmd_tbl_t *cmdtp, int flag, int argc,
91 char * const argv[])
92{
93 cmd_tbl_t *c = NULL;
94
95 /* Strip off leading 'cpu' command argument */
96 argc--;
97 argv++;
98
99 if (argc)
100 c = find_cmd_tbl(argv[0], cmd_cpu_sub, ARRAY_SIZE(cmd_cpu_sub));
101
102 if (c)
103 return c->cmd(cmdtp, flag, argc, argv);
104 else
105 return CMD_RET_USAGE;
106}
107
108U_BOOT_CMD(
109 cpu, 2, 1, do_cpu,
110 "display information about CPUs",
111 "list - list available CPUs\n"
112 "cpu detail - show CPU detail"
113);