1 // SPDX-License-Identifier: GPL-2.0+
3 * Copyright (c) 2015 Google, Inc
4 * Written by Simon Glass <sjg@chromium.org>
5 * Copyright (c) 2017 Álvaro Fernández Rojas <noltari@gmail.com>
11 #include <display_options.h>
15 static const char *cpu_feature_name
[CPU_FEAT_COUNT
] = {
22 static struct udevice
*cpu_find_device(unsigned long cpu_id
)
26 for (uclass_first_device(UCLASS_CPU
, &dev
); dev
;
27 uclass_next_device(&dev
)) {
28 if (cpu_id
== dev_seq(dev
))
35 static int print_cpu_list(bool detail
)
40 for (uclass_first_device(UCLASS_CPU
, &dev
);
42 uclass_next_device(&dev
)) {
43 struct cpu_plat
*plat
= dev_get_parent_plat(dev
);
48 ret
= cpu_get_desc(dev
, buf
, sizeof(buf
));
49 printf("%3d: %-10s %s\n", dev_seq(dev
), dev
->name
,
50 ret
? "<no description>" : buf
);
53 ret
= cpu_get_info(dev
, &info
);
55 printf("\t(no detail available");
57 printf(": err=%d", ret
);
61 printf("\tID = %d, freq = ", plat
->cpu_id
);
62 print_freq(info
.cpu_freq
, "");
63 for (i
= 0; i
< CPU_FEAT_COUNT
; i
++) {
64 if (info
.features
& (1 << i
)) {
65 printf("%s%s", first
? ": " : ", ",
71 if (info
.features
& (1 << CPU_FEAT_UCODE
))
72 printf("\tMicrocode version %#x\n",
74 if (info
.features
& (1 << CPU_FEAT_DEVICE_ID
))
75 printf("\tDevice ID %#lx\n", plat
->device_id
);
81 static int do_cpu_list(struct cmd_tbl
*cmdtp
, int flag
, int argc
,
84 if (print_cpu_list(false))
85 return CMD_RET_FAILURE
;
90 static int do_cpu_detail(struct cmd_tbl
*cmdtp
, int flag
, int argc
,
93 if (print_cpu_list(true))
94 return CMD_RET_FAILURE
;
99 static int do_cpu_release(struct cmd_tbl
*cmdtp
, int flag
, int argc
,
103 unsigned long cpu_id
;
104 unsigned long long boot_addr
;
107 return CMD_RET_USAGE
;
109 cpu_id
= dectoul(argv
[1], NULL
);
110 dev
= cpu_find_device(cpu_id
);
112 return CMD_RET_FAILURE
;
114 boot_addr
= simple_strtoull(argv
[2], NULL
, 16);
116 if (cpu_release_core(dev
, boot_addr
))
117 return CMD_RET_FAILURE
;
123 "list - list available CPUs\n"
124 "cpu detail - show CPU detail\n"
125 "cpu release <core ID> <addr> - Release CPU <core ID> at <addr>\n"
126 " <core ID>: the sequence number in list subcommand outputs");
128 U_BOOT_CMD_WITH_SUBCMDS(cpu
, "display information about CPUs", cpu_help_text
,
129 U_BOOT_SUBCMD_MKENT(list
, 1, 1, do_cpu_list
),
130 U_BOOT_SUBCMD_MKENT(detail
, 1, 0, do_cpu_detail
),
131 U_BOOT_SUBCMD_MKENT(release
, 3, 0, do_cpu_release
));