2018-05-07 05:58:06 +08:00
|
|
|
// SPDX-License-Identifier: GPL-2.0+
|
2015-04-29 10:25:11 +08:00
|
|
|
/*
|
|
|
|
* Copyright (c) 2015 Google, Inc
|
|
|
|
* Written by Simon Glass <sjg@chromium.org>
|
2017-04-25 06:39:17 +08:00
|
|
|
* Copyright (c) 2017 Álvaro Fernández Rojas <noltari@gmail.com>
|
2015-04-29 10:25:11 +08:00
|
|
|
*/
|
|
|
|
|
|
|
|
#include <common.h>
|
|
|
|
#include <command.h>
|
|
|
|
#include <cpu.h>
|
2022-08-01 02:28:48 +08:00
|
|
|
#include <display_options.h>
|
2015-04-29 10:25:11 +08:00
|
|
|
#include <dm.h>
|
2015-06-12 14:52:18 +08:00
|
|
|
#include <errno.h>
|
2015-04-29 10:25:11 +08:00
|
|
|
|
|
|
|
static const char *cpu_feature_name[CPU_FEAT_COUNT] = {
|
|
|
|
"L1 cache",
|
|
|
|
"MMU",
|
2016-03-07 10:27:49 +08:00
|
|
|
"Microcode",
|
cmd: cpu: fix NULL cpu feature prints
Commit 740d5d3 added two new features but only one feature name,
which results in NULL prints when device_id feature is selected.
Before:
HG556a # cpu detail
-1: cpu@0 BCM6358A1
ID = 0, freq = 300 MHz: L1 cache, MMU, NULL
Device ID 0x2a010
-1: cpu@1 BCM6358A1
ID = 1, freq = 300 MHz: L1 cache, MMU, NULL
Device ID 0x2a010
After:
HG556a # cpu detail
-1: cpu@0 BCM6358A1
ID = 0, freq = 300 MHz: L1 cache, MMU, Device ID
Device ID 0x2a010
-1: cpu@1 BCM6358A1
ID = 1, freq = 300 MHz: L1 cache, MMU, Device ID
Device ID 0x2a010
Signed-off-by: Álvaro Fernández Rojas <noltari@gmail.com>
Reviewed-by: Simon Glass <sjg@chromium.org>
Reviewed-by: Tom Rini <trini@konsulko.com>
2017-04-25 06:39:13 +08:00
|
|
|
"Device ID",
|
2015-04-29 10:25:11 +08:00
|
|
|
};
|
|
|
|
|
|
|
|
static int print_cpu_list(bool detail)
|
|
|
|
{
|
|
|
|
struct udevice *dev;
|
|
|
|
char buf[100];
|
|
|
|
|
2017-04-25 06:39:17 +08:00
|
|
|
for (uclass_first_device(UCLASS_CPU, &dev);
|
|
|
|
dev;
|
|
|
|
uclass_next_device(&dev)) {
|
2020-12-04 07:55:23 +08:00
|
|
|
struct cpu_plat *plat = dev_get_parent_plat(dev);
|
2015-04-29 10:25:11 +08:00
|
|
|
struct cpu_info info;
|
2017-04-25 06:39:17 +08:00
|
|
|
bool first = true;
|
|
|
|
int ret, i;
|
2015-04-29 10:25:11 +08:00
|
|
|
|
|
|
|
ret = cpu_get_desc(dev, buf, sizeof(buf));
|
2020-12-17 12:20:07 +08:00
|
|
|
printf("%3d: %-10s %s\n", dev_seq(dev), dev->name,
|
2015-04-29 10:25:11 +08:00
|
|
|
ret ? "<no description>" : buf);
|
|
|
|
if (!detail)
|
|
|
|
continue;
|
|
|
|
ret = cpu_get_info(dev, &info);
|
|
|
|
if (ret) {
|
|
|
|
printf("\t(no detail available");
|
|
|
|
if (ret != -ENOSYS)
|
2017-04-25 06:39:17 +08:00
|
|
|
printf(": err=%d", ret);
|
2015-04-29 10:25:11 +08:00
|
|
|
printf(")\n");
|
|
|
|
continue;
|
|
|
|
}
|
|
|
|
printf("\tID = %d, freq = ", plat->cpu_id);
|
|
|
|
print_freq(info.cpu_freq, "");
|
|
|
|
for (i = 0; i < CPU_FEAT_COUNT; i++) {
|
|
|
|
if (info.features & (1 << i)) {
|
|
|
|
printf("%s%s", first ? ": " : ", ",
|
|
|
|
cpu_feature_name[i]);
|
|
|
|
first = false;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
printf("\n");
|
2017-04-25 06:39:17 +08:00
|
|
|
if (info.features & (1 << CPU_FEAT_UCODE))
|
2016-03-07 10:27:49 +08:00
|
|
|
printf("\tMicrocode version %#x\n",
|
|
|
|
plat->ucode_version);
|
|
|
|
if (info.features & (1 << CPU_FEAT_DEVICE_ID))
|
|
|
|
printf("\tDevice ID %#lx\n", plat->device_id);
|
2015-04-29 10:25:11 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
2020-05-11 01:40:03 +08:00
|
|
|
static int do_cpu_list(struct cmd_tbl *cmdtp, int flag, int argc,
|
2017-04-25 06:39:17 +08:00
|
|
|
char *const argv[])
|
2015-04-29 10:25:11 +08:00
|
|
|
{
|
|
|
|
if (print_cpu_list(false))
|
|
|
|
return CMD_RET_FAILURE;
|
|
|
|
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
2020-05-11 01:40:03 +08:00
|
|
|
static int do_cpu_detail(struct cmd_tbl *cmdtp, int flag, int argc,
|
2015-04-29 10:25:11 +08:00
|
|
|
char *const argv[])
|
|
|
|
{
|
|
|
|
if (print_cpu_list(true))
|
|
|
|
return CMD_RET_FAILURE;
|
|
|
|
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
2023-02-06 06:40:56 +08:00
|
|
|
#if IS_ENABLED(CONFIG_SYS_LONGHELP)
|
2022-06-01 02:14:22 +08:00
|
|
|
static char cpu_help_text[] =
|
2015-04-29 10:25:11 +08:00
|
|
|
"list - list available CPUs\n"
|
|
|
|
"cpu detail - show CPU detail"
|
2022-06-01 02:14:22 +08:00
|
|
|
;
|
|
|
|
#endif
|
|
|
|
|
|
|
|
U_BOOT_CMD_WITH_SUBCMDS(cpu, "display information about CPUs", cpu_help_text,
|
|
|
|
U_BOOT_SUBCMD_MKENT(list, 1, 1, do_cpu_list),
|
|
|
|
U_BOOT_SUBCMD_MKENT(detail, 1, 0, do_cpu_detail));
|