Commit | Line | Data |
---|---|---|
83d290c5 | 1 | // SPDX-License-Identifier: GPL-2.0+ |
8e2fac05 SG |
2 | /* |
3 | * Copyright (c) 2015 Google, Inc | |
4 | * Written by Simon Glass <sjg@chromium.org> | |
320eca5c | 5 | * Copyright (c) 2017 Álvaro Fernández Rojas <noltari@gmail.com> |
476fb4d8 | 6 | * Copyright 2024 NXP |
8e2fac05 SG |
7 | */ |
8 | ||
8e2fac05 SG |
9 | #include <command.h> |
10 | #include <cpu.h> | |
4e4bf944 | 11 | #include <display_options.h> |
8e2fac05 | 12 | #include <dm.h> |
166c3984 | 13 | #include <errno.h> |
8e2fac05 SG |
14 | |
15 | static const char *cpu_feature_name[CPU_FEAT_COUNT] = { | |
16 | "L1 cache", | |
17 | "MMU", | |
740d5d34 | 18 | "Microcode", |
22c2c179 | 19 | "Device ID", |
8e2fac05 SG |
20 | }; |
21 | ||
476fb4d8 HZ |
22 | static 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 | ||
8e2fac05 SG |
35 | static int print_cpu_list(bool detail) |
36 | { | |
37 | struct udevice *dev; | |
8e2fac05 | 38 | char buf[100]; |
8e2fac05 | 39 | |
320eca5c ÁFR |
40 | for (uclass_first_device(UCLASS_CPU, &dev); |
41 | dev; | |
42 | uclass_next_device(&dev)) { | |
8a8d24bd | 43 | struct cpu_plat *plat = dev_get_parent_plat(dev); |
8e2fac05 | 44 | struct cpu_info info; |
320eca5c ÁFR |
45 | bool first = true; |
46 | int ret, i; | |
8e2fac05 SG |
47 | |
48 | ret = cpu_get_desc(dev, buf, sizeof(buf)); | |
8b85dfc6 | 49 | printf("%3d: %-10s %s\n", dev_seq(dev), dev->name, |
8e2fac05 SG |
50 | 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) | |
320eca5c | 57 | printf(": err=%d", ret); |
8e2fac05 SG |
58 | printf(")\n"); |
59 | continue; | |
60 | } | |
61 | printf("\tID = %d, freq = ", plat->cpu_id); | |
62 | print_freq(info.cpu_freq, ""); | |
8e2fac05 SG |
63 | 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"); | |
320eca5c | 71 | if (info.features & (1 << CPU_FEAT_UCODE)) |
740d5d34 SG |
72 | printf("\tMicrocode version %#x\n", |
73 | plat->ucode_version); | |
740d5d34 SG |
74 | if (info.features & (1 << CPU_FEAT_DEVICE_ID)) |
75 | printf("\tDevice ID %#lx\n", plat->device_id); | |
8e2fac05 SG |
76 | } |
77 | ||
78 | return 0; | |
79 | } | |
80 | ||
09140113 | 81 | static int do_cpu_list(struct cmd_tbl *cmdtp, int flag, int argc, |
320eca5c | 82 | char *const argv[]) |
8e2fac05 SG |
83 | { |
84 | if (print_cpu_list(false)) | |
85 | return CMD_RET_FAILURE; | |
86 | ||
87 | return 0; | |
88 | } | |
89 | ||
09140113 | 90 | static int do_cpu_detail(struct cmd_tbl *cmdtp, int flag, int argc, |
8e2fac05 SG |
91 | char *const argv[]) |
92 | { | |
93 | if (print_cpu_list(true)) | |
94 | return CMD_RET_FAILURE; | |
95 | ||
96 | return 0; | |
97 | } | |
98 | ||
476fb4d8 HZ |
99 | static 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 | ||
3616218b | 122 | U_BOOT_LONGHELP(cpu, |
8e2fac05 | 123 | "list - list available CPUs\n" |
476fb4d8 HZ |
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"); | |
15c924a7 OP |
127 | |
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), | |
476fb4d8 HZ |
130 | U_BOOT_SUBCMD_MKENT(detail, 1, 0, do_cpu_detail), |
131 | U_BOOT_SUBCMD_MKENT(release, 3, 0, do_cpu_release)); |