Tom Rini | 10e4779 | 2018-05-06 17:58:06 -0400 | [diff] [blame] | 1 | // SPDX-License-Identifier: GPL-2.0+ |
Simon Glass | 9e8ff54 | 2015-04-28 20:25:11 -0600 | [diff] [blame] | 2 | /* |
| 3 | * Copyright (c) 2015 Google, Inc |
| 4 | * Written by Simon Glass <sjg@chromium.org> |
Álvaro Fernández Rojas | 3184505 | 2017-04-25 00:39:17 +0200 | [diff] [blame] | 5 | * Copyright (c) 2017 Álvaro Fernández Rojas <noltari@gmail.com> |
Simon Glass | 9e8ff54 | 2015-04-28 20:25:11 -0600 | [diff] [blame] | 6 | */ |
| 7 | |
| 8 | #include <common.h> |
| 9 | #include <command.h> |
| 10 | #include <cpu.h> |
| 11 | #include <dm.h> |
Bin Meng | b891f78 | 2015-06-12 14:52:18 +0800 | [diff] [blame] | 12 | #include <errno.h> |
Simon Glass | 9e8ff54 | 2015-04-28 20:25:11 -0600 | [diff] [blame] | 13 | |
| 14 | static const char *cpu_feature_name[CPU_FEAT_COUNT] = { |
| 15 | "L1 cache", |
| 16 | "MMU", |
Simon Glass | 8d374cd | 2016-03-06 19:27:49 -0700 | [diff] [blame] | 17 | "Microcode", |
Álvaro Fernández Rojas | 696cedf | 2017-04-25 00:39:13 +0200 | [diff] [blame] | 18 | "Device ID", |
Simon Glass | 9e8ff54 | 2015-04-28 20:25:11 -0600 | [diff] [blame] | 19 | }; |
| 20 | |
| 21 | static int print_cpu_list(bool detail) |
| 22 | { |
| 23 | struct udevice *dev; |
Simon Glass | 9e8ff54 | 2015-04-28 20:25:11 -0600 | [diff] [blame] | 24 | char buf[100]; |
Simon Glass | 9e8ff54 | 2015-04-28 20:25:11 -0600 | [diff] [blame] | 25 | |
Álvaro Fernández Rojas | 3184505 | 2017-04-25 00:39:17 +0200 | [diff] [blame] | 26 | for (uclass_first_device(UCLASS_CPU, &dev); |
| 27 | dev; |
| 28 | uclass_next_device(&dev)) { |
Simon Glass | b75b15b | 2020-12-03 16:55:23 -0700 | [diff] [blame] | 29 | struct cpu_plat *plat = dev_get_parent_plat(dev); |
Simon Glass | 9e8ff54 | 2015-04-28 20:25:11 -0600 | [diff] [blame] | 30 | struct cpu_info info; |
Álvaro Fernández Rojas | 3184505 | 2017-04-25 00:39:17 +0200 | [diff] [blame] | 31 | bool first = true; |
| 32 | int ret, i; |
Simon Glass | 9e8ff54 | 2015-04-28 20:25:11 -0600 | [diff] [blame] | 33 | |
| 34 | ret = cpu_get_desc(dev, buf, sizeof(buf)); |
Simon Glass | 75e534b | 2020-12-16 21:20:07 -0700 | [diff] [blame^] | 35 | printf("%3d: %-10s %s\n", dev_seq(dev), dev->name, |
Simon Glass | 9e8ff54 | 2015-04-28 20:25:11 -0600 | [diff] [blame] | 36 | ret ? "<no description>" : buf); |
| 37 | if (!detail) |
| 38 | continue; |
| 39 | ret = cpu_get_info(dev, &info); |
| 40 | if (ret) { |
| 41 | printf("\t(no detail available"); |
| 42 | if (ret != -ENOSYS) |
Álvaro Fernández Rojas | 3184505 | 2017-04-25 00:39:17 +0200 | [diff] [blame] | 43 | printf(": err=%d", ret); |
Simon Glass | 9e8ff54 | 2015-04-28 20:25:11 -0600 | [diff] [blame] | 44 | printf(")\n"); |
| 45 | continue; |
| 46 | } |
| 47 | printf("\tID = %d, freq = ", plat->cpu_id); |
| 48 | print_freq(info.cpu_freq, ""); |
Simon Glass | 9e8ff54 | 2015-04-28 20:25:11 -0600 | [diff] [blame] | 49 | for (i = 0; i < CPU_FEAT_COUNT; i++) { |
| 50 | if (info.features & (1 << i)) { |
| 51 | printf("%s%s", first ? ": " : ", ", |
| 52 | cpu_feature_name[i]); |
| 53 | first = false; |
| 54 | } |
| 55 | } |
| 56 | printf("\n"); |
Álvaro Fernández Rojas | 3184505 | 2017-04-25 00:39:17 +0200 | [diff] [blame] | 57 | if (info.features & (1 << CPU_FEAT_UCODE)) |
Simon Glass | 8d374cd | 2016-03-06 19:27:49 -0700 | [diff] [blame] | 58 | printf("\tMicrocode version %#x\n", |
| 59 | plat->ucode_version); |
Simon Glass | 8d374cd | 2016-03-06 19:27:49 -0700 | [diff] [blame] | 60 | if (info.features & (1 << CPU_FEAT_DEVICE_ID)) |
| 61 | printf("\tDevice ID %#lx\n", plat->device_id); |
Simon Glass | 9e8ff54 | 2015-04-28 20:25:11 -0600 | [diff] [blame] | 62 | } |
| 63 | |
| 64 | return 0; |
| 65 | } |
| 66 | |
Simon Glass | ed38aef | 2020-05-10 11:40:03 -0600 | [diff] [blame] | 67 | static int do_cpu_list(struct cmd_tbl *cmdtp, int flag, int argc, |
Álvaro Fernández Rojas | 3184505 | 2017-04-25 00:39:17 +0200 | [diff] [blame] | 68 | char *const argv[]) |
Simon Glass | 9e8ff54 | 2015-04-28 20:25:11 -0600 | [diff] [blame] | 69 | { |
| 70 | if (print_cpu_list(false)) |
| 71 | return CMD_RET_FAILURE; |
| 72 | |
| 73 | return 0; |
| 74 | } |
| 75 | |
Simon Glass | ed38aef | 2020-05-10 11:40:03 -0600 | [diff] [blame] | 76 | static int do_cpu_detail(struct cmd_tbl *cmdtp, int flag, int argc, |
Simon Glass | 9e8ff54 | 2015-04-28 20:25:11 -0600 | [diff] [blame] | 77 | char *const argv[]) |
| 78 | { |
| 79 | if (print_cpu_list(true)) |
| 80 | return CMD_RET_FAILURE; |
| 81 | |
| 82 | return 0; |
| 83 | } |
| 84 | |
Simon Glass | ed38aef | 2020-05-10 11:40:03 -0600 | [diff] [blame] | 85 | static struct cmd_tbl cmd_cpu_sub[] = { |
Simon Glass | 9e8ff54 | 2015-04-28 20:25:11 -0600 | [diff] [blame] | 86 | U_BOOT_CMD_MKENT(list, 2, 1, do_cpu_list, "", ""), |
| 87 | U_BOOT_CMD_MKENT(detail, 4, 0, do_cpu_detail, "", ""), |
| 88 | }; |
| 89 | |
| 90 | /* |
| 91 | * Process a cpu sub-command |
| 92 | */ |
Simon Glass | ed38aef | 2020-05-10 11:40:03 -0600 | [diff] [blame] | 93 | static int do_cpu(struct cmd_tbl *cmdtp, int flag, int argc, |
| 94 | char *const argv[]) |
Simon Glass | 9e8ff54 | 2015-04-28 20:25:11 -0600 | [diff] [blame] | 95 | { |
Simon Glass | ed38aef | 2020-05-10 11:40:03 -0600 | [diff] [blame] | 96 | struct cmd_tbl *c = NULL; |
Simon Glass | 9e8ff54 | 2015-04-28 20:25:11 -0600 | [diff] [blame] | 97 | |
| 98 | /* Strip off leading 'cpu' command argument */ |
| 99 | argc--; |
| 100 | argv++; |
| 101 | |
| 102 | if (argc) |
Álvaro Fernández Rojas | 3184505 | 2017-04-25 00:39:17 +0200 | [diff] [blame] | 103 | c = find_cmd_tbl(argv[0], cmd_cpu_sub, |
| 104 | ARRAY_SIZE(cmd_cpu_sub)); |
Simon Glass | 9e8ff54 | 2015-04-28 20:25:11 -0600 | [diff] [blame] | 105 | |
| 106 | if (c) |
| 107 | return c->cmd(cmdtp, flag, argc, argv); |
| 108 | else |
| 109 | return CMD_RET_USAGE; |
| 110 | } |
| 111 | |
| 112 | U_BOOT_CMD( |
| 113 | cpu, 2, 1, do_cpu, |
| 114 | "display information about CPUs", |
| 115 | "list - list available CPUs\n" |
| 116 | "cpu detail - show CPU detail" |
| 117 | ); |