blob: 27552507564ed9adc610ea8f89d1c650fa9497cb [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>
Hou Zhiqiang4862c6f2024-08-01 11:59:55 +08006 * Copyright 2024 NXP
Simon Glass9e8ff542015-04-28 20:25:11 -06007 */
8
Simon Glass9e8ff542015-04-28 20:25:11 -06009#include <command.h>
10#include <cpu.h>
Simon Glass1ab16922022-07-31 12:28:48 -060011#include <display_options.h>
Simon Glass9e8ff542015-04-28 20:25:11 -060012#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
Hou Zhiqiang4862c6f2024-08-01 11:59:55 +080022static struct udevice *cpu_find_device(unsigned long cpu_id)
23{
24 struct udevice *dev;
25
26 for (uclass_first_device(UCLASS_CPU, &dev); dev;
27 uclass_next_device(&dev)) {
28 if (cpu_id == dev_seq(dev))
29 return dev;
30 }
31
32 return NULL;
33}
34
Simon Glass9e8ff542015-04-28 20:25:11 -060035static int print_cpu_list(bool detail)
36{
37 struct udevice *dev;
Simon Glass9e8ff542015-04-28 20:25:11 -060038 char buf[100];
Simon Glass9e8ff542015-04-28 20:25:11 -060039
Álvaro Fernández Rojas31845052017-04-25 00:39:17 +020040 for (uclass_first_device(UCLASS_CPU, &dev);
41 dev;
42 uclass_next_device(&dev)) {
Simon Glassb75b15b2020-12-03 16:55:23 -070043 struct cpu_plat *plat = dev_get_parent_plat(dev);
Simon Glass9e8ff542015-04-28 20:25:11 -060044 struct cpu_info info;
Álvaro Fernández Rojas31845052017-04-25 00:39:17 +020045 bool first = true;
46 int ret, i;
Simon Glass9e8ff542015-04-28 20:25:11 -060047
48 ret = cpu_get_desc(dev, buf, sizeof(buf));
Simon Glass75e534b2020-12-16 21:20:07 -070049 printf("%3d: %-10s %s\n", dev_seq(dev), dev->name,
Simon Glass9e8ff542015-04-28 20:25:11 -060050 ret ? "<no description>" : buf);
51 if (!detail)
52 continue;
53 ret = cpu_get_info(dev, &info);
54 if (ret) {
55 printf("\t(no detail available");
56 if (ret != -ENOSYS)
Álvaro Fernández Rojas31845052017-04-25 00:39:17 +020057 printf(": err=%d", ret);
Simon Glass9e8ff542015-04-28 20:25:11 -060058 printf(")\n");
59 continue;
60 }
61 printf("\tID = %d, freq = ", plat->cpu_id);
62 print_freq(info.cpu_freq, "");
Simon Glass9e8ff542015-04-28 20:25:11 -060063 for (i = 0; i < CPU_FEAT_COUNT; i++) {
64 if (info.features & (1 << i)) {
65 printf("%s%s", first ? ": " : ", ",
66 cpu_feature_name[i]);
67 first = false;
68 }
69 }
70 printf("\n");
Álvaro Fernández Rojas31845052017-04-25 00:39:17 +020071 if (info.features & (1 << CPU_FEAT_UCODE))
Simon Glass8d374cd2016-03-06 19:27:49 -070072 printf("\tMicrocode version %#x\n",
73 plat->ucode_version);
Simon Glass8d374cd2016-03-06 19:27:49 -070074 if (info.features & (1 << CPU_FEAT_DEVICE_ID))
75 printf("\tDevice ID %#lx\n", plat->device_id);
Simon Glass9e8ff542015-04-28 20:25:11 -060076 }
77
78 return 0;
79}
80
Simon Glassed38aef2020-05-10 11:40:03 -060081static int do_cpu_list(struct cmd_tbl *cmdtp, int flag, int argc,
Álvaro Fernández Rojas31845052017-04-25 00:39:17 +020082 char *const argv[])
Simon Glass9e8ff542015-04-28 20:25:11 -060083{
84 if (print_cpu_list(false))
85 return CMD_RET_FAILURE;
86
87 return 0;
88}
89
Simon Glassed38aef2020-05-10 11:40:03 -060090static int do_cpu_detail(struct cmd_tbl *cmdtp, int flag, int argc,
Simon Glass9e8ff542015-04-28 20:25:11 -060091 char *const argv[])
92{
93 if (print_cpu_list(true))
94 return CMD_RET_FAILURE;
95
96 return 0;
97}
98
Hou Zhiqiang4862c6f2024-08-01 11:59:55 +080099static int do_cpu_release(struct cmd_tbl *cmdtp, int flag, int argc,
100 char *const argv[])
101{
102 struct udevice *dev;
103 unsigned long cpu_id;
104 unsigned long long boot_addr;
105
106 if (argc != 3)
107 return CMD_RET_USAGE;
108
109 cpu_id = dectoul(argv[1], NULL);
110 dev = cpu_find_device(cpu_id);
111 if (!dev)
112 return CMD_RET_FAILURE;
113
114 boot_addr = simple_strtoull(argv[2], NULL, 16);
115
116 if (cpu_release_core(dev, boot_addr))
117 return CMD_RET_FAILURE;
118
119 return 0;
120}
121
Tom Rini03f146c2023-10-07 15:13:08 -0400122U_BOOT_LONGHELP(cpu,
Simon Glass9e8ff542015-04-28 20:25:11 -0600123 "list - list available CPUs\n"
Hou Zhiqiang4862c6f2024-08-01 11:59:55 +0800124 "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");
Ovidiu Panait344e3332022-05-31 21:14:22 +0300127
128U_BOOT_CMD_WITH_SUBCMDS(cpu, "display information about CPUs", cpu_help_text,
129 U_BOOT_SUBCMD_MKENT(list, 1, 1, do_cpu_list),
Hou Zhiqiang4862c6f2024-08-01 11:59:55 +0800130 U_BOOT_SUBCMD_MKENT(detail, 1, 0, do_cpu_detail),
131 U_BOOT_SUBCMD_MKENT(release, 3, 0, do_cpu_release));